From c200d6fdae9e13e7741e81a91c0cb14fd0852db5 Mon Sep 17 00:00:00 2001 From: eric8810 Date: Sun, 29 Nov 2026 01:53:18 +0800 Subject: [PATCH 1/9] test(provider): pin the service tier capability contract A serviceTier declaration means the model offers the tiers it lists, so `supported: true` must state a usable set: non-empty `options` and a `default` among them. The flow test reads both `provider.refresh` and `provider.management` for a declaration with options, one without any, one with an empty list, one that is unsupported, and one whose default is outside its options, then checks which tiers `provider.preferences.update` accepts. Refs #2248 --- crates/dim-app-server/tests/provider_flow.rs | 177 ++++++++++++++++++ docs/design/appserver/provider-management.md | 8 + .../design/appserver/provider-management.md | 6 + 3 files changed, 191 insertions(+) diff --git a/crates/dim-app-server/tests/provider_flow.rs b/crates/dim-app-server/tests/provider_flow.rs index 6df0099fa6..e42afa92e8 100644 --- a/crates/dim-app-server/tests/provider_flow.rs +++ b/crates/dim-app-server/tests/provider_flow.rs @@ -1364,6 +1364,14 @@ fn declared_efforts( .and_then(|reasoning| reasoning.effort_options.clone()) } +/// A model's service-tier capability as a client reads it, in the shape the +/// public reply carries. +fn published_tier( + metadata: Option<&dim_app_server::model_catalog::ModelMetadata>, +) -> Option { + Some(serde_json::to_value(metadata?.service_tier.as_ref()?).unwrap()) +} + /// The effort list one bundled row declares for `id`. fn bundled_efforts(catalog: &BundledCatalog, provider_id: &str, id: &str) -> Vec { catalog @@ -1503,6 +1511,38 @@ impl ServedListing { ) } + /// The service tier `id` publishes, as the refresh reply reports it. + fn served_tier(&self, id: &str) -> Option { + published_tier( + self.catalog + .models + .iter() + .find(|model| model.id == id) + .unwrap() + .metadata + .as_ref(), + ) + } + + /// The same, as `provider.management` reports it from the stored record. + async fn tier_read_back(&self, id: &str) -> Option { + let management = self + .provider + .management(LISTED.into(), None, &self.cancel) + .await + .unwrap(); + let models = management.providers[0].models.as_ref().unwrap(); + published_tier( + models + .iter() + .find(|model| model.model.model_id == id) + .unwrap() + .model + .metadata + .as_ref(), + ) + } + async fn close(self) { self.root.shutdown().await.unwrap(); self.server.abort(); @@ -1707,6 +1747,143 @@ async fn a_saved_effort_is_validated_against_the_listings_levels() { listing.close().await; } +/// A service-tier declaration is a capability, not a hint: `supported: true` +/// states a usable set, and a declaration whose options nothing enumerates is +/// unavailable, so a client never offers a tier the model does not accept +/// (#2248). +#[tokio::test] +async fn a_service_tier_declaration_states_only_a_usable_set() { + let function = |id: &str, service_tier: Value| { + json!({ + "id": id, + "limit": {"context": 128000, "output": 16384}, + "serviceTier": service_tier + }) + }; + let listing = ServedListing::refreshed(json!([ + function( + "tier-declared", + json!({"supported": true, "default": "default", "options": ["default", "priority"]}) + ), + function("tier-unenumerated", json!(true)), + function( + "tier-empty-options", + json!({"supported": true, "default": "priority", "options": []}) + ), + function("tier-off", json!(false)), + function( + "tier-default-outside", + json!({"supported": true, "default": "flex", "options": ["default", "priority"]}) + ), + function("gpt-5.5", json!(true)), + ])) + .await; + let declared = json!({"supported": true, "default": "default", "options": ["default", "priority"]}); + assert_eq!(listing.served_tier("tier-declared"), Some(declared.clone())); + assert_eq!( + listing.tier_read_back("tier-declared").await, + Some(declared.clone()), + "the edit-view read states the same capability as the catalog" + ); + for id in ["tier-unenumerated", "tier-empty-options", "tier-off"] { + assert_eq!( + listing.served_tier(id), + Some(json!({"supported": false})), + "{id} states no usable set" + ); + assert_eq!( + listing.tier_read_back(id).await, + Some(json!({"supported": false})), + "{id} states no usable set in the edit-view read either" + ); + } + assert_eq!( + listing.served_tier("tier-default-outside"), + Some(declared.clone()), + "a default outside the options gives way to one of them" + ); + assert_eq!( + listing.served_tier("gpt-5.5"), + Some(declared.clone()), + "the identified row enumerates the options a listing names none of" + ); + + let accepted = listing + .provider + .update_preferences( + LISTED.into(), + listing.catalog.version, + "tier-declared".into(), + serde_json::from_value(json!({"serviceTier":{"action":"set","value":"priority"}})) + .unwrap(), + &listing.cancel, + ) + .await + .unwrap(); + assert_eq!( + accepted.preferences["tier-declared"].service_tier.as_deref(), + Some("priority"), + "an offered tier is accepted" + ); + for (id, tier) in [ + ("tier-unenumerated", "priority"), + ("tier-empty-options", "priority"), + ("tier-off", "default"), + ("tier-default-outside", "flex"), + ] { + let refused = listing + .provider + .update_preferences( + LISTED.into(), + accepted.info.version.unwrap(), + id.into(), + serde_json::from_value(json!({"serviceTier":{"action":"set","value":tier}})) + .unwrap(), + &listing.cancel, + ) + .await; + assert!( + matches!(refused, Err(ProviderError::InvalidConfig(_))), + "{id} refuses the tier {tier} it does not offer: {refused:?}" + ); + } + let accepted = listing + .provider + .update_preferences( + LISTED.into(), + accepted.info.version.unwrap(), + "tier-default-outside".into(), + serde_json::from_value(json!({"serviceTier":{"action":"set","value":"priority"}})) + .unwrap(), + &listing.cancel, + ) + .await + .unwrap(); + assert_eq!( + accepted.preferences["tier-default-outside"].service_tier.as_deref(), + Some("priority"), + "the options a declaration keeps are still offered" + ); + let accepted = listing + .provider + .update_preferences( + LISTED.into(), + accepted.info.version.unwrap(), + "gpt-5.5".into(), + serde_json::from_value(json!({"serviceTier":{"action":"set","value":"priority"}})) + .unwrap(), + &listing.cancel, + ) + .await + .unwrap(); + assert_eq!( + accepted.preferences["gpt-5.5"].service_tier.as_deref(), + Some("priority"), + "the identified row's options are the model's own" + ); + listing.close().await; +} + #[tokio::test] async fn a_declared_output_limit_at_or_above_the_window_adopts_a_derived_allowance() { use axum::http::StatusCode; diff --git a/docs/design/appserver/provider-management.md b/docs/design/appserver/provider-management.md index 3a3ede7538..da67882413 100644 --- a/docs/design/appserver/provider-management.md +++ b/docs/design/appserver/provider-management.md @@ -557,6 +557,14 @@ options, not those choices. Descriptor edits, route changes and refresh never automatically delete unsupported saved fields. Explicit adoption reports the rejected saved preferences; the user can set or clear each field explicitly. +A service-tier declaration is a capability, not a hint: `supported: true` states +a usable set, so `options` is non-empty and `default`, when present, is one of +them. A declaration whose options neither the descriptor nor the row it is +identified with enumerates is `supported: false` with no `default` and no +`options`, and the preference patch then refuses every tier. A declared +`default` outside the options gives way to the option named `default`, else the +first one, so a supported declaration always names a tier it offers. + Existing `delete` keeps its builtin-disable/custom-delete behavior. `models.edit` keeps `ModelEdit` and adds `endpoint: {action:"set",value:NewApiEndpoint} | {action:"clear"}` for static New API models only, restricted to §6's executable subset. diff --git a/docs/zh/design/appserver/provider-management.md b/docs/zh/design/appserver/provider-management.md index 09fc16f10e..45392a13b6 100644 --- a/docs/zh/design/appserver/provider-management.md +++ b/docs/zh/design/appserver/provider-management.md @@ -321,6 +321,12 @@ driver、auth、默认模型只读。custom 的 driverKind/auth 创建后同样 描述、路由编辑和刷新都不自动删除不再受支持的用户偏好。显式采用失败时标明保存的偏好, 由用户分别设置或清除字段。 +serviceTier 声明是能力而非提示:`supported:true` 表示一套可用的档位,因此 `options` 非空, +若给出 `default` 它必属于该集合。描述本身与为之识别出的行都无法枚举选项的声明为 +`supported:false`,且不带 `default` 与 `options`,此时偏好 patch 拒绝任何档位。集合之外的 +`default` 让位于名为 `default` 的选项,没有该选项则让位于第一个,因此 supported 的声明 +总是给出一个它提供的档位。 + 已有 delete 保持内置禁用/自定义删除。models.edit 保留 `ModelEdit`,只为静态 New API 模型增加 `endpoint:{action:"set",value:NewApiEndpoint}|{action:"clear"}`,限 §6 可执行子集。 override 优先,clear 回到发现结果,不删除 metadata;未知上游字符串仅作描述。 From 59ea001b55946fffcd471506a56808e70de2e35b Mon Sep 17 00:00:00 2001 From: eric8810 Date: Sun, 29 Nov 2026 02:00:27 +0800 Subject: [PATCH 2/9] fix(provider): make serviceTier options authoritative `ModelServiceTier` now states one of two shapes: a usable set, with non-empty `options` and a `default` among them, or no capability at all. `usable()` resolves a declaration to that shape, and the two entry builders of the catalog read apply it after identification: `project` covers the descriptors a listing or an account catalog supplies, and `effective_models` covers the entries a record serves. Identification still fills a declaration that names no options of its own before the capability is read, so a model whose catalog row enumerates its tiers keeps them. `provider.management` therefore no longer advertises a supported tier set with nothing to offer, and `preferences.update` keeps refusing every tier such a model does not offer. No new state is introduced: an unenumerable declaration simply reads as unsupported. Fixes #2248 --- crates/dim-agent-types/src/model.rs | 30 ++++++ crates/dim-app-server/src/model_catalog.rs | 13 +++ .../tests/model_catalog_flow.rs | 92 ++++++++++++++++++- crates/dim-app-server/tests/provider_flow.rs | 23 ----- 4 files changed, 133 insertions(+), 25 deletions(-) diff --git a/crates/dim-agent-types/src/model.rs b/crates/dim-agent-types/src/model.rs index 21dff424c0..fcc2d8bd4b 100644 --- a/crates/dim-agent-types/src/model.rs +++ b/crates/dim-agent-types/src/model.rs @@ -248,6 +248,36 @@ pub struct ModelServiceTier { pub options: Vec, } +impl ModelServiceTier { + /// The capability this declaration states: `supported` means a usable set. + /// A declaration that supports tiers without listing any is unavailable, + /// and a declared default outside the options gives way to the option + /// named `default`, else the first one. + pub fn usable(self) -> Self { + let Self { + supported, + default, + options, + } = self; + if !supported || options.is_empty() { + return Self { + supported: false, + default: None, + options: Vec::new(), + }; + } + let default = default + .filter(|default| options.contains(default)) + .or_else(|| options.iter().find(|option| *option == "default").cloned()) + .or_else(|| options.first().cloned()); + Self { + supported: true, + default, + options, + } + } +} + #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase", deny_unknown_fields)] pub struct ModelCapabilitySnapshot { diff --git a/crates/dim-app-server/src/model_catalog.rs b/crates/dim-app-server/src/model_catalog.rs index 0bfd2d0add..239da161e8 100644 --- a/crates/dim-app-server/src/model_catalog.rs +++ b/crates/dim-app-server/src/model_catalog.rs @@ -95,6 +95,15 @@ impl ModelEntry { .get("max_context_window")? .as_u64() } + + /// The entry as a catalog read serves it: its service-tier declaration + /// states a usable set or no capability at all. Identification fills a + /// declaration that lists no options first, so this runs after a merge. + fn resolve_service_tier(&mut self) { + if let Some(metadata) = self.metadata.as_mut() { + metadata.service_tier = metadata.service_tier.take().map(ModelServiceTier::usable); + } + } } /// The editable surface excludes model identity, lookup diagnostics and raw @@ -624,6 +633,7 @@ impl BundledCatalog { if !limits_valid(&entry.capabilities) { return Err(ProjectionError::InvalidLimits); } + entry.resolve_service_tier(); Ok(entry) } @@ -890,6 +900,9 @@ impl BundledCatalog { model.capabilities.context_window = Some(window); } } + for model in &mut models { + model.resolve_service_tier(); + } models } diff --git a/crates/dim-app-server/tests/model_catalog_flow.rs b/crates/dim-app-server/tests/model_catalog_flow.rs index b18d2d6054..09cc63c8bd 100644 --- a/crates/dim-app-server/tests/model_catalog_flow.rs +++ b/crates/dim-app-server/tests/model_catalog_flow.rs @@ -1,6 +1,6 @@ use dim_app_server::model_catalog::{ - BundledCatalog, CatalogCapabilities, ModelEdit, ModelEntry, ModelIdentification, ModelSource, - ProviderProjection, infer_capability_edits, rebase_override, + BundledCatalog, CatalogCapabilities, ModelEdit, ModelEntry, ModelIdentification, ModelServiceTier, + ModelSource, ProviderProjection, infer_capability_edits, rebase_override, }; use serde::{Deserialize, Serialize}; use serde_json::json; @@ -216,6 +216,88 @@ fn media_lookup_and_explicit_capabilities_survive_editing() { assert_eq!(edited.metadata, model.metadata); } +/// A service-tier declaration is a capability: `supported: true` states a +/// usable set, and a declaration that names none of its own is filled by the +/// row it is identified with before the capability is read (#2248). +#[test] +fn a_service_tier_declaration_states_only_a_usable_set() { + let catalog = BundledCatalog::load().unwrap(); + let codex = ProviderProjection { + provider_id: "openai-codex".into(), + ..Default::default() + }; + let declared = Some(json!({"supported": true, "default": "default", "options": ["default", "priority"]})); + assert_eq!( + tier(&bundled(&catalog, "openai-codex", "gpt-5.5")), + declared, + "the row states the set this case reads" + ); + let filled = catalog + .project(&codex, &json!({"id": "gpt-5.5", "serviceTier": true})) + .unwrap(); + assert_eq!( + tier(&filled), + declared, + "the row a declaration is identified with enumerates its options" + ); + let mut stored = catalog.project(&codex, &json!({"id": "gpt-5.5"})).unwrap(); + stored.metadata.get_or_insert_default().service_tier = Some(ModelServiceTier { + supported: true, + default: None, + options: Vec::new(), + }); + let effective = catalog.effective_models(&codex, &[stored], &[]); + assert_eq!( + tier(&effective[0]), + declared, + "a stored declaration is filled the same way" + ); + + let custom = ProviderProjection { + provider_id: "custom".into(), + source: Some(ModelSource::Custom), + ..Default::default() + }; + for declaration in [ + json!(true), + json!({"supported": true, "options": []}), + json!({"supported": true, "default": "priority", "options": []}), + json!(false), + ] { + let entry = catalog + .project( + &custom, + &json!({"id": "zzzz-private-tier", "serviceTier": declaration}), + ) + .unwrap(); + assert_eq!( + tier(&entry), + Some(json!({"supported": false})), + "a declaration whose options nothing enumerates is no capability: {declaration}" + ); + let effective = catalog.effective_models(&custom, &[entry], &[]); + assert_eq!( + tier(&effective[0]), + Some(json!({"supported": false})), + "the effective entry states the same capability: {declaration}" + ); + } + let outside = catalog + .project( + &custom, + &json!({ + "id": "zzzz-private-tier", + "serviceTier": {"supported": true, "default": "flex", "options": ["default", "priority"]} + }), + ) + .unwrap(); + assert_eq!( + tier(&outside), + Some(json!({"supported": true, "default": "default", "options": ["default", "priority"]})), + "a default outside the options gives way to one of them" + ); +} + #[test] fn visible_edits_preserve_hidden_fields_and_update_legacy_media_readers() { let catalog = BundledCatalog::load().unwrap(); @@ -820,6 +902,12 @@ fn bundled(catalog: &BundledCatalog, provider_id: &str, model_id: &str) -> Model .clone() } +/// The service-tier capability a model entry states, in the shape a reply +/// carries. +fn tier(entry: &ModelEntry) -> Option { + Some(serde_json::to_value(entry.metadata.as_ref()?.service_tier.as_ref()?).unwrap()) +} + /// The identification an entry earned. fn identification(entry: &ModelEntry) -> &ModelIdentification { entry diff --git a/crates/dim-app-server/tests/provider_flow.rs b/crates/dim-app-server/tests/provider_flow.rs index e42afa92e8..5da589cf9e 100644 --- a/crates/dim-app-server/tests/provider_flow.rs +++ b/crates/dim-app-server/tests/provider_flow.rs @@ -1775,7 +1775,6 @@ async fn a_service_tier_declaration_states_only_a_usable_set() { "tier-default-outside", json!({"supported": true, "default": "flex", "options": ["default", "priority"]}) ), - function("gpt-5.5", json!(true)), ])) .await; let declared = json!({"supported": true, "default": "default", "options": ["default", "priority"]}); @@ -1802,11 +1801,6 @@ async fn a_service_tier_declaration_states_only_a_usable_set() { Some(declared.clone()), "a default outside the options gives way to one of them" ); - assert_eq!( - listing.served_tier("gpt-5.5"), - Some(declared.clone()), - "the identified row enumerates the options a listing names none of" - ); let accepted = listing .provider @@ -1864,23 +1858,6 @@ async fn a_service_tier_declaration_states_only_a_usable_set() { Some("priority"), "the options a declaration keeps are still offered" ); - let accepted = listing - .provider - .update_preferences( - LISTED.into(), - accepted.info.version.unwrap(), - "gpt-5.5".into(), - serde_json::from_value(json!({"serviceTier":{"action":"set","value":"priority"}})) - .unwrap(), - &listing.cancel, - ) - .await - .unwrap(); - assert_eq!( - accepted.preferences["gpt-5.5"].service_tier.as_deref(), - Some("priority"), - "the identified row's options are the model's own" - ); listing.close().await; } From ba5eddad893964cc3e115179e2c00f6f1f6900ed Mon Sep 17 00:00:00 2001 From: eric8810 Date: Sun, 29 Nov 2026 02:03:07 +0800 Subject: [PATCH 3/9] style(provider): apply rustfmt to the service tier tests --- crates/dim-app-server/tests/model_catalog_flow.rs | 7 ++++--- crates/dim-app-server/tests/provider_flow.rs | 11 ++++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/crates/dim-app-server/tests/model_catalog_flow.rs b/crates/dim-app-server/tests/model_catalog_flow.rs index 09cc63c8bd..a01642ab5c 100644 --- a/crates/dim-app-server/tests/model_catalog_flow.rs +++ b/crates/dim-app-server/tests/model_catalog_flow.rs @@ -1,6 +1,6 @@ use dim_app_server::model_catalog::{ - BundledCatalog, CatalogCapabilities, ModelEdit, ModelEntry, ModelIdentification, ModelServiceTier, - ModelSource, ProviderProjection, infer_capability_edits, rebase_override, + BundledCatalog, CatalogCapabilities, ModelEdit, ModelEntry, ModelIdentification, + ModelServiceTier, ModelSource, ProviderProjection, infer_capability_edits, rebase_override, }; use serde::{Deserialize, Serialize}; use serde_json::json; @@ -226,7 +226,8 @@ fn a_service_tier_declaration_states_only_a_usable_set() { provider_id: "openai-codex".into(), ..Default::default() }; - let declared = Some(json!({"supported": true, "default": "default", "options": ["default", "priority"]})); + let declared = + Some(json!({"supported": true, "default": "default", "options": ["default", "priority"]})); assert_eq!( tier(&bundled(&catalog, "openai-codex", "gpt-5.5")), declared, diff --git a/crates/dim-app-server/tests/provider_flow.rs b/crates/dim-app-server/tests/provider_flow.rs index 5da589cf9e..418cb6fce4 100644 --- a/crates/dim-app-server/tests/provider_flow.rs +++ b/crates/dim-app-server/tests/provider_flow.rs @@ -1777,7 +1777,8 @@ async fn a_service_tier_declaration_states_only_a_usable_set() { ), ])) .await; - let declared = json!({"supported": true, "default": "default", "options": ["default", "priority"]}); + let declared = + json!({"supported": true, "default": "default", "options": ["default", "priority"]}); assert_eq!(listing.served_tier("tier-declared"), Some(declared.clone())); assert_eq!( listing.tier_read_back("tier-declared").await, @@ -1815,7 +1816,9 @@ async fn a_service_tier_declaration_states_only_a_usable_set() { .await .unwrap(); assert_eq!( - accepted.preferences["tier-declared"].service_tier.as_deref(), + accepted.preferences["tier-declared"] + .service_tier + .as_deref(), Some("priority"), "an offered tier is accepted" ); @@ -1854,7 +1857,9 @@ async fn a_service_tier_declaration_states_only_a_usable_set() { .await .unwrap(); assert_eq!( - accepted.preferences["tier-default-outside"].service_tier.as_deref(), + accepted.preferences["tier-default-outside"] + .service_tier + .as_deref(), Some("priority"), "the options a declaration keeps are still offered" ); From 1cae2e615f8fe636cd4ac7c83d094398a1eaf1eb Mon Sep 17 00:00:00 2001 From: eric8810 Date: Sun, 29 Nov 2026 02:08:06 +0800 Subject: [PATCH 4/9] fix(provider): resolve the account catalog's service tier on read An account catalog's model entry reaches the record through the account provider's own reply, not through the descriptor projection, so the capability read had to resolve it as well. `ProviderRecord::effective_models` is the one derivation its catalog, management view and whole-set write read, so the resolution lives there: a stored declaration that lists no options reads as unavailable, and an older record written before this rule stays readable. Refs #2248 --- crates/dim-app-server/src/model_catalog.rs | 2 +- crates/dim-app-server/src/provider.rs | 1 + .../tests/managed_provider_flow.rs | 121 +++++++++++++++++- 3 files changed, 119 insertions(+), 5 deletions(-) diff --git a/crates/dim-app-server/src/model_catalog.rs b/crates/dim-app-server/src/model_catalog.rs index 239da161e8..143cf9355a 100644 --- a/crates/dim-app-server/src/model_catalog.rs +++ b/crates/dim-app-server/src/model_catalog.rs @@ -99,7 +99,7 @@ impl ModelEntry { /// The entry as a catalog read serves it: its service-tier declaration /// states a usable set or no capability at all. Identification fills a /// declaration that lists no options first, so this runs after a merge. - fn resolve_service_tier(&mut self) { + pub(crate) fn resolve_service_tier(&mut self) { if let Some(metadata) = self.metadata.as_mut() { metadata.service_tier = metadata.service_tier.take().map(ModelServiceTier::usable); } diff --git a/crates/dim-app-server/src/provider.rs b/crates/dim-app-server/src/provider.rs index f0e653ccfc..b41f25a8c2 100644 --- a/crates/dim-app-server/src/provider.rs +++ b/crates/dim-app-server/src/provider.rs @@ -578,6 +578,7 @@ impl ProviderRecord { None => source.entry.clone(), }; bundled.identify_entry(&projection, &mut entry); + entry.resolve_service_tier(); let missing_limits = entry.capabilities.missing_limits(); let unavailable = if source.excluded_from_every_use() { // A stored limits reason is the weaker derived fact and diff --git a/crates/dim-app-server/tests/managed_provider_flow.rs b/crates/dim-app-server/tests/managed_provider_flow.rs index d48ae2f1d9..0df6ee20dd 100644 --- a/crates/dim-app-server/tests/managed_provider_flow.rs +++ b/crates/dim-app-server/tests/managed_provider_flow.rs @@ -57,6 +57,8 @@ struct Fixture { observe_entered: Notify, observe_resume: Notify, empty_catalog: AtomicBool, + /// The service tier the fixture's catalog states for its model. + service_tier: Mutex>, /// The account transitions this provider reports, when it reports them. watch: Mutex>>>, /// Account reads, which an installed watch must make unnecessary. @@ -230,15 +232,18 @@ impl ManagedProvider for Provider { } fn catalog(&self, _: &str, _: CancellationToken) -> ManagedFuture { let empty = self.0.empty_catalog.load(Ordering::SeqCst); + let service_tier = self.0.service_tier.lock().unwrap().clone(); Box::pin(async move { let models = if empty { vec![] } else { + let mut entry = dim_app_server::model_catalog::BundledCatalog::load() + .unwrap() + .model("deepseek", "deepseek-v4-flash") + .unwrap(); + entry.metadata.get_or_insert_default().service_tier = service_tier; vec![dim_app_server::managed_provider::ManagedModel { - entry: dim_app_server::model_catalog::BundledCatalog::load() - .unwrap() - .model("deepseek", "deepseek-v4-flash") - .unwrap(), + entry, protocol: ModelProtocol::OpenaiCompatible, unavailable_reason: None, zdr: false, @@ -1018,3 +1023,111 @@ async fn model_pages_survive_refresh_removal_and_an_unbound_empty_account() { .await .expect("model page operations settle across refresh and unbind"); } + +/// An account catalog's service-tier declaration is a capability too: a +/// supported declaration with no options reads as unavailable, and the +/// preference write refuses every tier of it (#2248). +#[tokio::test(flavor = "multi_thread", worker_threads = 4)] +async fn an_account_catalogs_service_tier_states_only_a_usable_set() { + use dim_app_server::model_catalog::ModelServiceTier; + use dim_app_server::provider::{ProviderError, ProviderPlugin, ProviderService}; + + tokio::time::timeout(std::time::Duration::from_secs(30), async { + let directory = tempfile::tempdir().unwrap(); + let home = directory.path().canonicalize().unwrap(); + let (root, fixture, _, _) = setup().await; + let catalog = dim_app_server::catalog(); + let build = rutis_loader::resolve::Build::default(); + let names = dim_agent_runtime::Names::copy(&catalog, &build); + let dependencies = [ + root.plugin( + dim_agent_capabilities::file_storage::FileStoragePlugin::new(vec![home.clone()]), + ), + root.plugin(dim_app_server::storage::SqliteStoragePlugin::new( + home.join("native.sqlite"), + )), + root.plugin( + dim_app_server::codex_oauth::OpenAICodexOAuthPlugin::new(&names, 0).unwrap(), + ), + root.plugin(dim_app_server::grok_oauth::GrokOAuthPlugin::new(&names, 0).unwrap()), + root.plugin(dim_agent_aimux::AimuxPlugin::default()), + ]; + for dependency in &dependencies { + active(dependency).await; + } + active(&root.plugin(ProviderPlugin::new(&names).unwrap())).await; + let provider = root.get::().unwrap(); + let cancel = CancellationToken::new(); + let tier = |provider: &Arc, id: &str, cancel: &CancellationToken| { + let model = provider.clone(); + let id = id.to_owned(); + let cancel = cancel.clone(); + async move { + let management = model + .management("fixture".into(), Some(id.clone()), &cancel) + .await + .unwrap(); + let entry = &management.providers[0].models.as_ref().unwrap()[0]; + serde_json::to_value(entry.model.metadata.as_ref().unwrap().service_tier.as_ref()) + .unwrap() + } + }; + + *fixture.service_tier.lock().unwrap() = Some(ModelServiceTier { + supported: true, + default: None, + options: Vec::new(), + }); + let catalog = provider.refresh("fixture".into(), &cancel).await.unwrap(); + let id = catalog.models[0].id.clone(); + assert_eq!( + tier(&provider, &id, &cancel).await, + json!({"supported": false}), + "an account declaration with no options states no capability" + ); + let refused = provider + .update_preferences( + "fixture".into(), + catalog.version, + id.clone(), + serde_json::from_value(json!({"serviceTier":{"action":"set","value":"default"}})) + .unwrap(), + &cancel, + ) + .await; + assert!( + matches!(refused, Err(ProviderError::InvalidConfig(_))), + "no tier is offered: {refused:?}" + ); + + *fixture.service_tier.lock().unwrap() = Some(ModelServiceTier { + supported: true, + default: Some("flex".into()), + options: vec!["priority".into(), "flex".into()], + }); + let catalog = provider.refresh("fixture".into(), &cancel).await.unwrap(); + assert_eq!( + tier(&provider, &id, &cancel).await, + json!({"supported": true, "default": "flex", "options": ["priority", "flex"]}), + "the declared default is kept because it is one of the options" + ); + let accepted = provider + .update_preferences( + "fixture".into(), + catalog.version, + id.clone(), + serde_json::from_value(json!({"serviceTier":{"action":"set","value":"priority"}})) + .unwrap(), + &cancel, + ) + .await + .unwrap(); + assert_eq!( + accepted.preferences[&id].service_tier.as_deref(), + Some("priority") + ); + root.shutdown().await.unwrap(); + }) + .await + .expect("the account catalog's service tier settles"); +} From f123183bea207c8d5a8b552b800933899eee8ad0 Mon Sep 17 00:00:00 2001 From: eric8810 Date: Sun, 29 Nov 2026 02:28:04 +0800 Subject: [PATCH 5/9] fix(provider): leave an unnamed service tier default unnamed A supported declaration that names no default does not gain one: the adoption of such a model sends no tier, exactly as before. Only a default the options do not offer is replaced, by the option named `default`, else the first one, so a named default is always one the model offers. The projection still states a default for a catalog declaration by its own rule, so a catalog model keeps adopting the tier it declares. Refs #2248 --- crates/dim-agent-types/src/model.rs | 19 +++++++++++++------ docs/design/appserver/provider-management.md | 12 ++++++------ .../design/appserver/provider-management.md | 6 +++--- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/crates/dim-agent-types/src/model.rs b/crates/dim-agent-types/src/model.rs index fcc2d8bd4b..6a26cf36cc 100644 --- a/crates/dim-agent-types/src/model.rs +++ b/crates/dim-agent-types/src/model.rs @@ -251,8 +251,10 @@ pub struct ModelServiceTier { impl ModelServiceTier { /// The capability this declaration states: `supported` means a usable set. /// A declaration that supports tiers without listing any is unavailable, - /// and a declared default outside the options gives way to the option - /// named `default`, else the first one. + /// and a default the options do not offer gives way to the option named + /// `default`, else the first one, so a named default is always one the + /// model offers. A declaration that names no default keeps none, exactly + /// as one that lists no options has none to offer. pub fn usable(self) -> Self { let Self { supported, @@ -266,10 +268,15 @@ impl ModelServiceTier { options: Vec::new(), }; } - let default = default - .filter(|default| options.contains(default)) - .or_else(|| options.iter().find(|option| *option == "default").cloned()) - .or_else(|| options.first().cloned()); + let default = match default { + Some(default) if options.contains(&default) => Some(default), + Some(_) => options + .iter() + .find(|option| *option == "default") + .cloned() + .or_else(|| options.first().cloned()), + None => None, + }; Self { supported: true, default, diff --git a/docs/design/appserver/provider-management.md b/docs/design/appserver/provider-management.md index da67882413..b909883098 100644 --- a/docs/design/appserver/provider-management.md +++ b/docs/design/appserver/provider-management.md @@ -558,12 +558,12 @@ automatically delete unsupported saved fields. Explicit adoption reports the rejected saved preferences; the user can set or clear each field explicitly. A service-tier declaration is a capability, not a hint: `supported: true` states -a usable set, so `options` is non-empty and `default`, when present, is one of -them. A declaration whose options neither the descriptor nor the row it is -identified with enumerates is `supported: false` with no `default` and no -`options`, and the preference patch then refuses every tier. A declared -`default` outside the options gives way to the option named `default`, else the -first one, so a supported declaration always names a tier it offers. +a usable set, so `options` is non-empty and a `default` is one of them when the +declaration names one. A declaration whose options neither the descriptor nor +the row it is identified with enumerates is `supported: false` with no +`default` and no `options`, and the preference patch then refuses every tier. A +`default` the options do not offer gives way to the option named `default`, else +the first one; a declaration that names no default offers none at adoption. Existing `delete` keeps its builtin-disable/custom-delete behavior. `models.edit` keeps `ModelEdit` and adds `endpoint: {action:"set",value:NewApiEndpoint} | diff --git a/docs/zh/design/appserver/provider-management.md b/docs/zh/design/appserver/provider-management.md index 45392a13b6..7156278a32 100644 --- a/docs/zh/design/appserver/provider-management.md +++ b/docs/zh/design/appserver/provider-management.md @@ -322,10 +322,10 @@ driver、auth、默认模型只读。custom 的 driverKind/auth 创建后同样 由用户分别设置或清除字段。 serviceTier 声明是能力而非提示:`supported:true` 表示一套可用的档位,因此 `options` 非空, -若给出 `default` 它必属于该集合。描述本身与为之识别出的行都无法枚举选项的声明为 +声明给出 `default` 时它必属于该集合。描述本身与为之识别出的行都无法枚举选项的声明为 `supported:false`,且不带 `default` 与 `options`,此时偏好 patch 拒绝任何档位。集合之外的 -`default` 让位于名为 `default` 的选项,没有该选项则让位于第一个,因此 supported 的声明 -总是给出一个它提供的档位。 +`default` 让位于名为 `default` 的选项,没有该选项则让位于第一个;未声明 `default` 的声明 +在采用时也不给出默认档位。 已有 delete 保持内置禁用/自定义删除。models.edit 保留 `ModelEdit`,只为静态 New API 模型增加 `endpoint:{action:"set",value:NewApiEndpoint}|{action:"clear"}`,限 §6 可执行子集。 From 84652ae897d79e8c35641501826f95c6d337f244 Mon Sep 17 00:00:00 2001 From: eric8810 Date: Sun, 29 Nov 2026 02:52:45 +0800 Subject: [PATCH 6/9] fix(provider): advertise only the tiers a route can send Four behaviors kept the advertised set from being authoritative: - `service_tier()` states only what the declaration says. An empty scalar names no declaration, an empty option is no tier, and an object that names no default keeps none; the parser no longer picks a default for it, so an untouched adoption sends no tier. - `ModelServiceTier::usable()` applies the same set to a typed entry: an empty or repeated option drops, and a default the options do not offer is not stated rather than replaced by another tier. - A route whose protocol cannot send `serviceTier` states no capability, so an Anthropic model no longer offers a tier its own write refuses. `expresses_service_tier` is the read-side rule the write gate matches. - The declaration stays unresolved wherever it is stored: `project` and `BundledCatalog::effective_models` no longer collapse it, so a row identified later can still enumerate its options, while an explicit `supported: false` still suppresses them. The reads that serve a capability resolve with the route's protocol. Refs #2248 --- crates/dim-agent-types/src/model.rs | 44 ++--- crates/dim-app-server/src/model_catalog.rs | 65 +++++--- crates/dim-app-server/src/provider.rs | 7 +- .../src/provider/preferences.rs | 11 ++ crates/dim-app-server/src/provider/startup.rs | 3 +- .../tests/model_catalog_flow.rs | 58 +++++-- crates/dim-app-server/tests/provider_flow.rs | 157 ++++++++++++++++-- docs/design/appserver/provider-management.md | 9 +- .../design/appserver/provider-management.md | 7 +- 9 files changed, 275 insertions(+), 86 deletions(-) diff --git a/crates/dim-agent-types/src/model.rs b/crates/dim-agent-types/src/model.rs index 6a26cf36cc..66ebfb4000 100644 --- a/crates/dim-agent-types/src/model.rs +++ b/crates/dim-agent-types/src/model.rs @@ -1,5 +1,6 @@ use crate::*; use serde::{Deserialize, Serialize}; +use std::collections::HashSet; use std::sync::Arc; #[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] @@ -249,37 +250,40 @@ pub struct ModelServiceTier { } impl ModelServiceTier { + /// A declaration that offers nothing: no tiers, and no default. + pub fn unavailable() -> Self { + Self { + supported: false, + default: None, + options: Vec::new(), + } + } + /// The capability this declaration states: `supported` means a usable set. - /// A declaration that supports tiers without listing any is unavailable, - /// and a default the options do not offer gives way to the option named - /// `default`, else the first one, so a named default is always one the - /// model offers. A declaration that names no default keeps none, exactly - /// as one that lists no options has none to offer. + /// An option is a tier name, so surrounding space is dropped and an empty + /// one is no tier; a declaration left with none is unavailable. A default + /// the options do not offer is dropped, because it names no tier the model + /// offers and another value would be a choice nobody declared, and a + /// declaration that names no default keeps none. pub fn usable(self) -> Self { let Self { supported, default, options, } = self; + let mut seen = HashSet::new(); + let options: Vec = options + .into_iter() + .map(|option| option.trim().to_owned()) + .filter(|option| !option.is_empty() && seen.insert(option.clone())) + .collect(); if !supported || options.is_empty() { - return Self { - supported: false, - default: None, - options: Vec::new(), - }; + return Self::unavailable(); } - let default = match default { - Some(default) if options.contains(&default) => Some(default), - Some(_) => options - .iter() - .find(|option| *option == "default") - .cloned() - .or_else(|| options.first().cloned()), - None => None, - }; + let default = default.map(|default| default.trim().to_owned()); Self { supported: true, - default, + default: default.filter(|default| options.contains(default)), options, } } diff --git a/crates/dim-app-server/src/model_catalog.rs b/crates/dim-app-server/src/model_catalog.rs index 143cf9355a..d5464bad46 100644 --- a/crates/dim-app-server/src/model_catalog.rs +++ b/crates/dim-app-server/src/model_catalog.rs @@ -96,13 +96,27 @@ impl ModelEntry { .as_u64() } - /// The entry as a catalog read serves it: its service-tier declaration - /// states a usable set or no capability at all. Identification fills a - /// declaration that lists no options first, so this runs after a merge. - pub(crate) fn resolve_service_tier(&mut self) { - if let Some(metadata) = self.metadata.as_mut() { - metadata.service_tier = metadata.service_tier.take().map(ModelServiceTier::usable); - } + /// The entry as a catalog read serves it on `protocol`: its service-tier + /// declaration states a usable set, or no capability at all when the route + /// cannot send a tier. Identification fills a declaration that lists no + /// options first, so this runs after a merge. + pub(crate) fn resolve_service_tier( + &mut self, + protocol: Option, + ) { + let Some(metadata) = self.metadata.as_mut() else { + return; + }; + let Some(tier) = metadata.service_tier.take() else { + return; + }; + metadata.service_tier = Some( + if protocol.is_some_and(crate::provider::expresses_service_tier) { + tier.usable() + } else { + ModelServiceTier::unavailable() + }, + ); } } @@ -633,7 +647,6 @@ impl BundledCatalog { if !limits_valid(&entry.capabilities) { return Err(ProjectionError::InvalidLimits); } - entry.resolve_service_tier(); Ok(entry) } @@ -900,9 +913,6 @@ impl BundledCatalog { model.capabilities.context_window = Some(window); } } - for model in &mut models { - model.resolve_service_tier(); - } models } @@ -1728,11 +1738,7 @@ fn project_reasoning( } fn service_tier(value: Option<&Value>, raw: &Map) -> Option { if value == Some(&Value::Bool(false)) { - return Some(ModelServiceTier { - supported: false, - default: None, - options: vec![], - }); + return Some(ModelServiceTier::unavailable()); } let extra = raw.get("extra_capabilities"); let direct = raw.get("serviceTier").or_else(|| raw.get("service_tier")); @@ -1740,16 +1746,21 @@ fn service_tier(value: Option<&Value>, raw: &Map) -> Option, raw: &Map) -> Option source.entry.clone(), }; bundled.identify_entry(&projection, &mut entry); - entry.resolve_service_tier(); + entry.resolve_service_tier(Some(source.protocol)); let missing_limits = entry.capabilities.missing_limits(); let unavailable = if source.excluded_from_every_use() { // A stored limits reason is the weaker derived fact and @@ -1178,6 +1179,10 @@ fn static_entries_with_overrides( .chain(&record.user_models) .any(|m| m.model_id == entry.model_id) }) + .map(|mut entry| { + entry.resolve_service_tier(record.routes.get(&entry.model_id).copied()); + entry + }) .collect() } diff --git a/crates/dim-app-server/src/provider/preferences.rs b/crates/dim-app-server/src/provider/preferences.rs index 01da7aeb74..183d073149 100644 --- a/crates/dim-app-server/src/provider/preferences.rs +++ b/crates/dim-app-server/src/provider/preferences.rs @@ -1,6 +1,17 @@ use dim_agent_capabilities::host::{ModelProtocol, adopted_preferences, reasoning_config}; use dim_agent_types::*; +/// Whether `protocol` can send a service-tier preference at all. A declaration +/// the protocol cannot express is not a capability a client may offer. +pub(crate) fn expresses_service_tier(protocol: ModelProtocol) -> bool { + matches!( + protocol, + ModelProtocol::OpenaiChat + | ModelProtocol::OpenaiResponses + | ModelProtocol::OpenaiCompatible + ) +} + /// The base configuration an adoption starts from: `base` with the model's /// declared default reasoning effort and service tier applied. /// diff --git a/crates/dim-app-server/src/provider/startup.rs b/crates/dim-app-server/src/provider/startup.rs index 4f200c6a10..57b7ead156 100644 --- a/crates/dim-app-server/src/provider/startup.rs +++ b/crates/dim-app-server/src/provider/startup.rs @@ -341,10 +341,11 @@ impl ProviderService { .collect(), ..Default::default() }; - let entry = self + let mut entry = self .bundled .project(&projection, &descriptor) .map_err(failure)?; + entry.resolve_service_tier(Some(source.api_format)); let mut snapshot = match previous { Some(model) => model.capability_snapshot.clone().ok_or_else(|| failure("Model capabilities are not adopted"))?, None => ModelCapabilitySnapshot { diff --git a/crates/dim-app-server/tests/model_catalog_flow.rs b/crates/dim-app-server/tests/model_catalog_flow.rs index a01642ab5c..8fdeaa6da0 100644 --- a/crates/dim-app-server/tests/model_catalog_flow.rs +++ b/crates/dim-app-server/tests/model_catalog_flow.rs @@ -216,11 +216,12 @@ fn media_lookup_and_explicit_capabilities_survive_editing() { assert_eq!(edited.metadata, model.metadata); } -/// A service-tier declaration is a capability: `supported: true` states a -/// usable set, and a declaration that names none of its own is filled by the -/// row it is identified with before the capability is read (#2248). +/// A service-tier declaration is kept as the model states it — `supported` +/// plus the options and default it names — so a row identified later can +/// still enumerate it, and a declaration that names no option is never +/// silently read as an explicit denial (#2248). #[test] -fn a_service_tier_declaration_states_only_a_usable_set() { +fn a_service_tier_declaration_keeps_the_set_it_states() { let catalog = BundledCatalog::load().unwrap(); let codex = ProviderProjection { provider_id: "openai-codex".into(), @@ -259,11 +260,17 @@ fn a_service_tier_declaration_states_only_a_usable_set() { source: Some(ModelSource::Custom), ..Default::default() }; - for declaration in [ - json!(true), - json!({"supported": true, "options": []}), - json!({"supported": true, "default": "priority", "options": []}), - json!(false), + for (declaration, kept) in [ + (json!(true), json!({"supported": true})), + ( + json!({"supported": true, "options": []}), + json!({"supported": true}), + ), + ( + json!({"supported": true, "default": "priority", "options": []}), + json!({"supported": true, "default": "priority"}), + ), + (json!(false), json!({"supported": false})), ] { let entry = catalog .project( @@ -273,14 +280,14 @@ fn a_service_tier_declaration_states_only_a_usable_set() { .unwrap(); assert_eq!( tier(&entry), - Some(json!({"supported": false})), - "a declaration whose options nothing enumerates is no capability: {declaration}" + Some(kept.clone()), + "the declaration is kept as stated: {declaration}" ); let effective = catalog.effective_models(&custom, &[entry], &[]); assert_eq!( tier(&effective[0]), - Some(json!({"supported": false})), - "the effective entry states the same capability: {declaration}" + Some(kept), + "nothing enumerates the declaration, so it stays unresolved: {declaration}" ); } let outside = catalog @@ -294,8 +301,29 @@ fn a_service_tier_declaration_states_only_a_usable_set() { .unwrap(); assert_eq!( tier(&outside), - Some(json!({"supported": true, "default": "default", "options": ["default", "priority"]})), - "a default outside the options gives way to one of them" + Some(json!({"supported": true, "default": "flex", "options": ["default", "priority"]})), + "a declared default is kept as stated until a read resolves it" + ); + + for declaration in [json!(""), json!(" ")] { + let entry = catalog + .project( + &custom, + &json!({"id": "zzzz-private-tier", "serviceTier": declaration}), + ) + .unwrap(); + assert_eq!(tier(&entry), None, "an empty tier names no declaration"); + } + let trimmed = catalog + .project( + &custom, + &json!({"id": "zzzz-private-tier", "serviceTier": {"supported": true, "options": ["", " priority "]}}), + ) + .unwrap(); + assert_eq!( + tier(&trimmed), + Some(json!({"supported": true, "options": ["priority"]})), + "an empty option is not a tier, and a stated one is trimmed" ); } diff --git a/crates/dim-app-server/tests/provider_flow.rs b/crates/dim-app-server/tests/provider_flow.rs index 418cb6fce4..cba10e1f67 100644 --- a/crates/dim-app-server/tests/provider_flow.rs +++ b/crates/dim-app-server/tests/provider_flow.rs @@ -1765,12 +1765,21 @@ async fn a_service_tier_declaration_states_only_a_usable_set() { "tier-declared", json!({"supported": true, "default": "default", "options": ["default", "priority"]}) ), + function( + "tier-options-only", + json!({"supported": true, "options": ["default", "priority"]}) + ), function("tier-unenumerated", json!(true)), function( "tier-empty-options", json!({"supported": true, "default": "priority", "options": []}) ), + function( + "tier-empty-option", + json!({"supported": true, "options": [""]}) + ), function("tier-off", json!(false)), + function("tier-blank", json!("")), function( "tier-default-outside", json!({"supported": true, "default": "flex", "options": ["default", "priority"]}) @@ -1779,13 +1788,29 @@ async fn a_service_tier_declaration_states_only_a_usable_set() { .await; let declared = json!({"supported": true, "default": "default", "options": ["default", "priority"]}); + let options_only = json!({"supported": true, "options": ["default", "priority"]}); assert_eq!(listing.served_tier("tier-declared"), Some(declared.clone())); assert_eq!( listing.tier_read_back("tier-declared").await, Some(declared.clone()), "the edit-view read states the same capability as the catalog" ); - for id in ["tier-unenumerated", "tier-empty-options", "tier-off"] { + assert_eq!( + listing.served_tier("tier-options-only"), + Some(options_only.clone()), + "a declaration that names no default keeps none" + ); + assert_eq!( + listing.served_tier("tier-default-outside"), + Some(options_only.clone()), + "a default outside the options is not stated as another tier" + ); + for id in [ + "tier-unenumerated", + "tier-empty-options", + "tier-empty-option", + "tier-off", + ] { assert_eq!( listing.served_tier(id), Some(json!({"supported": false})), @@ -1798,9 +1823,30 @@ async fn a_service_tier_declaration_states_only_a_usable_set() { ); } assert_eq!( - listing.served_tier("tier-default-outside"), - Some(declared.clone()), - "a default outside the options gives way to one of them" + listing.served_tier("tier-blank"), + None, + "an empty tier is no declaration at all" + ); + let stored: Value = serde_json::from_str(&stored_record_json(&listing.home, LISTED)).unwrap(); + let stored_tier = |id: &str| { + stored["models"] + .as_array() + .unwrap() + .iter() + .find(|model| model["modelId"] == id) + .and_then(|model| model.get("metadata")) + .and_then(|metadata| metadata.get("serviceTier")) + .cloned() + }; + assert_eq!( + stored_tier("tier-unenumerated"), + Some(json!({"supported": true})), + "the record keeps the unresolved declaration so a later row can enumerate it" + ); + assert_eq!( + stored_tier("tier-off"), + Some(json!({"supported": false})), + "an explicit denial stays a denial" ); let accepted = listing @@ -1825,8 +1871,10 @@ async fn a_service_tier_declaration_states_only_a_usable_set() { for (id, tier) in [ ("tier-unenumerated", "priority"), ("tier-empty-options", "priority"), + ("tier-empty-option", "priority"), ("tier-off", "default"), ("tier-default-outside", "flex"), + ("tier-options-only", "flex"), ] { let refused = listing .provider @@ -1844,24 +1892,97 @@ async fn a_service_tier_declaration_states_only_a_usable_set() { "{id} refuses the tier {tier} it does not offer: {refused:?}" ); } - let accepted = listing + let mut version = accepted.info.version.unwrap(); + for id in ["tier-default-outside", "tier-options-only"] { + let accepted = listing + .provider + .update_preferences( + LISTED.into(), + version, + id.into(), + serde_json::from_value(json!({"serviceTier":{"action":"set","value":"priority"}})) + .unwrap(), + &listing.cancel, + ) + .await + .unwrap(); + version = accepted.info.version.unwrap(); + assert_eq!( + accepted.preferences[id].service_tier.as_deref(), + Some("priority"), + "the options a declaration keeps are still offered: {id}" + ); + } + + let mut typed = model("tier-typed", 900); + typed.metadata = Some( + serde_json::from_value(json!({ + "serviceTier":{"supported":true,"default":"flex","options":[""," priority "]} + })) + .unwrap(), + ); + listing .provider - .update_preferences( - LISTED.into(), - accepted.info.version.unwrap(), - "tier-default-outside".into(), - serde_json::from_value(json!({"serviceTier":{"action":"set","value":"priority"}})) - .unwrap(), - &listing.cancel, - ) + .create_model(LISTED.into(), version, typed, &listing.cancel) .await .unwrap(); assert_eq!( - accepted.preferences["tier-default-outside"] - .service_tier - .as_deref(), - Some("priority"), - "the options a declaration keeps are still offered" + listing.tier_read_back("tier-typed").await, + Some(json!({"supported": true, "options": ["priority"]})), + "a typed entry is held to the same set: no empty option, no unoffered default" + ); + + let mut anthropic = input( + "00000000-0000-4000-8000-0000000000a1", + "https://api.anthropic.example/v1", + StaticAuth::ApiKey { + header_name: "x-api-key".into(), + prefix: String::new(), + }, + Some("fixture-key"), + "tiers", + 900, + ); + anthropic.connection.driver_kind = "anthropic".into(); + let mut entry = model("anthropic-tier", 900); + entry.metadata = Some( + serde_json::from_value(json!({ + "serviceTier":{"supported":true,"default":"priority","options":["priority"]} + })) + .unwrap(), + ); + anthropic.models = vec![entry]; + listing + .provider + .create(anthropic, &listing.cancel) + .await + .unwrap(); + let id = "00000000-0000-4000-8000-0000000000a1"; + let view = listing + .provider + .management(id.into(), None, &listing.cancel) + .await + .unwrap(); + assert_eq!( + published_tier( + view.providers[0].models.as_ref().unwrap()[0] + .model + .metadata + .as_ref(), + ), + Some(json!({"supported": false})), + "a protocol that cannot send a tier offers none" + ); + let catalog = listing + .provider + .catalog_for(id.into(), &listing.cancel) + .await + .unwrap() + .unwrap(); + assert_eq!( + published_tier(catalog.models[0].metadata.as_ref()), + Some(json!({"supported": false})), + "the catalog states the same capability as the edit-view read" ); listing.close().await; } diff --git a/docs/design/appserver/provider-management.md b/docs/design/appserver/provider-management.md index b909883098..97881997a4 100644 --- a/docs/design/appserver/provider-management.md +++ b/docs/design/appserver/provider-management.md @@ -561,9 +561,12 @@ A service-tier declaration is a capability, not a hint: `supported: true` states a usable set, so `options` is non-empty and a `default` is one of them when the declaration names one. A declaration whose options neither the descriptor nor the row it is identified with enumerates is `supported: false` with no -`default` and no `options`, and the preference patch then refuses every tier. A -`default` the options do not offer gives way to the option named `default`, else -the first one; a declaration that names no default offers none at adoption. +`default` and no `options`, and the preference patch then refuses every tier. +An option is a tier name, so an empty one is no option, and a declared default +the options do not offer is not stated; a declaration that names no default +keeps none, and an adoption of such a model sends no tier until a preference +names one. A route whose protocol cannot send a service tier states no +capability either, so every option a reply advertises is one that route accepts. Existing `delete` keeps its builtin-disable/custom-delete behavior. `models.edit` keeps `ModelEdit` and adds `endpoint: {action:"set",value:NewApiEndpoint} | diff --git a/docs/zh/design/appserver/provider-management.md b/docs/zh/design/appserver/provider-management.md index 7156278a32..ae354d0f9d 100644 --- a/docs/zh/design/appserver/provider-management.md +++ b/docs/zh/design/appserver/provider-management.md @@ -323,9 +323,10 @@ driver、auth、默认模型只读。custom 的 driverKind/auth 创建后同样 serviceTier 声明是能力而非提示:`supported:true` 表示一套可用的档位,因此 `options` 非空, 声明给出 `default` 时它必属于该集合。描述本身与为之识别出的行都无法枚举选项的声明为 -`supported:false`,且不带 `default` 与 `options`,此时偏好 patch 拒绝任何档位。集合之外的 -`default` 让位于名为 `default` 的选项,没有该选项则让位于第一个;未声明 `default` 的声明 -在采用时也不给出默认档位。 +`supported:false`,且不带 `default` 与 `options`,此时偏好 patch 拒绝任何档位。选项即档位名, +空串不构成选项,集合之外的 `default` 不予声明;未声明 `default` 的声明也不得到默认档位, +采用这类模型时在偏好指定档位之前不发送档位。协议无法发送 serviceTier 的路由同样不声明 +能力,因此回复通告的每个选项都是该路由接受的。 已有 delete 保持内置禁用/自定义删除。models.edit 保留 `ModelEdit`,只为静态 New API 模型增加 `endpoint:{action:"set",value:NewApiEndpoint}|{action:"clear"}`,限 §6 可执行子集。 From fe0c78913d20ac0c8d18606189e4e54387876715 Mon Sep 17 00:00:00 2001 From: eric8810 Date: Sun, 29 Nov 2026 03:28:10 +0800 Subject: [PATCH 7/9] fix(provider): resolve the probe reply's service tier `provider.probe` answers with the discover output, the projected entries themselves, so a listing that declares a tier without enumerating it came back as `{supported: true}` with nothing to offer. The probe now resolves each listed entry with the route the connection's driver gives it, the same rule the static management read and the startup admission apply; discover keeps the declaration unresolved for the record it writes. Refs #2248 --- crates/dim-app-server/src/provider/editing.rs | 14 ++++- crates/dim-app-server/tests/provider_flow.rs | 55 ++++++++++++++++++- 2 files changed, 63 insertions(+), 6 deletions(-) diff --git a/crates/dim-app-server/src/provider/editing.rs b/crates/dim-app-server/src/provider/editing.rs index 689da9dcc1..caaf520d22 100644 --- a/crates/dim-app-server/src/provider/editing.rs +++ b/crates/dim-app-server/src/provider/editing.rs @@ -364,9 +364,17 @@ impl ProviderService { }; validate_static_record(&id, &mut record) .map_err(|error| ProviderError::InvalidConfig(error.to_string()))?; - Ok(ProbeResult { - models: owner.discover(&id, &record, &cancel).await?, - }) + let mut models = owner.discover(&id, &record, &cancel).await?; + let routes = drivers::routes( + &record.driver_kind, + &models, + &record.endpoint_types, + &record.endpoint_overrides, + )?; + for model in &mut models { + model.resolve_service_tier(routes.get(&model.model_id).copied()); + } + Ok(ProbeResult { models }) }) }) .await diff --git a/crates/dim-app-server/tests/provider_flow.rs b/crates/dim-app-server/tests/provider_flow.rs index cba10e1f67..a1a2358e68 100644 --- a/crates/dim-app-server/tests/provider_flow.rs +++ b/crates/dim-app-server/tests/provider_flow.rs @@ -1385,6 +1385,13 @@ fn bundled_efforts(catalog: &BundledCatalog, provider_id: &str, id: &str) -> Vec const LISTED: &str = "00000000-0000-4000-8000-000000000022"; +/// One listing request a served fixture answers: the request and where its +/// reply goes. +type ListingRequest = ( + axum::http::Uri, + tokio::sync::oneshot::Sender<(axum::http::StatusCode, Json)>, +); + /// One served listing and the Provider that listed it, closed by the case. struct ServedListing { provider: Arc, @@ -1392,6 +1399,8 @@ struct ServedListing { root: Ctx, server: tokio::task::JoinHandle<()>, home: PathBuf, + base: String, + requests: tokio::sync::mpsc::Receiver, cancel: CancellationToken, } @@ -1404,8 +1413,7 @@ impl ServedListing { routing::get, }; use tokio::sync::{mpsc, oneshot}; - type Exchange = (Uri, oneshot::Sender<(StatusCode, Json)>); - let (send, mut requests) = mpsc::channel::(8); + let (send, mut requests) = mpsc::channel::(8); let app = Router::new().route( "/{*path}", get(move |uri: Uri| { @@ -1475,10 +1483,24 @@ impl ServedListing { root, server, home, + base, + requests, cancel, } } + /// Answers one more listing the Provider asks for after the refresh, such + /// as a probe. + async fn serve(&mut self, models: Value) { + self.requests + .recv() + .await + .unwrap() + .1 + .send((axum::http::StatusCode::OK, Json(json!({ "data": models })))) + .unwrap(); + } + /// The efforts `id` offers, as the refresh reply reports them. fn served(&self, id: &str) -> Option> { declared_efforts( @@ -1760,7 +1782,7 @@ async fn a_service_tier_declaration_states_only_a_usable_set() { "serviceTier": service_tier }) }; - let listing = ServedListing::refreshed(json!([ + let mut listing = ServedListing::refreshed(json!([ function( "tier-declared", json!({"supported": true, "default": "default", "options": ["default", "priority"]}) @@ -1932,6 +1954,33 @@ async fn a_service_tier_declaration_states_only_a_usable_set() { "a typed entry is held to the same set: no empty option, no unoffered default" ); + let probe = { + let provider = listing.provider.clone(); + let cancel = listing.cancel.clone(); + let input = serde_json::from_value(json!({ + "providerId": "00000000-0000-4000-8000-0000000000a2", + "connection": { + "driverKind": "openai-compatible", + "auth": {"type": "bearer"}, + "baseUrl": format!("{}/v1", listing.base), + "credential": {"action": "set", "value": "probe-key"} + } + })) + .unwrap(); + tokio::spawn(async move { provider.probe(input, &cancel).await }) + }; + listing + .serve( + json!([{"id":"probe-tier","limit":{"context":9000,"output":900},"serviceTier":true}]), + ) + .await; + let probed = probe.await.unwrap().unwrap(); + assert_eq!( + published_tier(probed.models[0].metadata.as_ref()), + Some(json!({"supported": false})), + "a probe reply states only what the connection's route accepts" + ); + let mut anthropic = input( "00000000-0000-4000-8000-0000000000a1", "https://api.anthropic.example/v1", From b9a4b853a1910815b4688e066685e8526ab89b86 Mon Sep 17 00:00:00 2001 From: eric8810 Date: Sun, 29 Nov 2026 03:47:02 +0800 Subject: [PATCH 8/9] fix(provider): keep a service tier declaration through the route Three cases still offered, hid, or lost a declaration the source made: - A model that declares no limits cannot build a capability, so the preference patch refuses every tier of it; the read now states no capability for it either, instead of advertising choices the write cannot save. - Identification filled the row's default into a declaration that stated its own options but no default, so an untouched adoption selected a tier the model never named. Only a declaration that states no options of its own takes the row's set, and it takes the row's default with it. - A provider created from a probe preview stored the capability the preview stated, which drops a declaration the connection's route cannot send. Create recovers the declaration from the listing item the entry was projected from, so a capable route serves the choices and an incapable one keeps them for a later route without a refresh. Refs #2248 --- crates/dim-app-server/src/model_catalog.rs | 41 +++++++++---- crates/dim-app-server/src/provider/editing.rs | 1 + crates/dim-app-server/src/provider/models.rs | 1 + .../tests/model_catalog_flow.rs | 11 ++++ crates/dim-app-server/tests/provider_flow.rs | 61 ++++++++++++++----- docs/design/appserver/provider-management.md | 14 +++-- .../design/appserver/provider-management.md | 8 ++- 7 files changed, 102 insertions(+), 35 deletions(-) diff --git a/crates/dim-app-server/src/model_catalog.rs b/crates/dim-app-server/src/model_catalog.rs index d5464bad46..c1e55b4759 100644 --- a/crates/dim-app-server/src/model_catalog.rs +++ b/crates/dim-app-server/src/model_catalog.rs @@ -98,25 +98,40 @@ impl ModelEntry { /// The entry as a catalog read serves it on `protocol`: its service-tier /// declaration states a usable set, or no capability at all when the route - /// cannot send a tier. Identification fills a declaration that lists no + /// cannot send a tier or the model declares no limits and so has no + /// capability to adopt. Identification fills a declaration that lists no /// options first, so this runs after a merge. pub(crate) fn resolve_service_tier( &mut self, protocol: Option, ) { + let adoptable = protocol.is_some_and(crate::provider::expresses_service_tier) + && self.capabilities.missing_limits().is_empty(); let Some(metadata) = self.metadata.as_mut() else { return; }; let Some(tier) = metadata.service_tier.take() else { return; }; - metadata.service_tier = Some( - if protocol.is_some_and(crate::provider::expresses_service_tier) { - tier.usable() - } else { - ModelServiceTier::unavailable() - }, - ); + metadata.service_tier = Some(if adoptable { + tier.usable() + } else { + ModelServiceTier::unavailable() + }); + } + + /// A model a client creates out of a served entry arrives as the read + /// stated it, which is the capability its route offered, not the + /// declaration the source made. The listing's own item is still in `raw`, + /// so the entry a record stores keeps what the source stated and a later + /// route can serve it. + pub(crate) fn restore_service_tier(&mut self) { + let Some(metadata) = self.metadata.as_mut() else { + return; + }; + if let Some(declared) = service_tier(None, &metadata.raw) { + metadata.service_tier = Some(declared); + } } } @@ -1225,13 +1240,15 @@ fn merge_entry(mut current: ModelEntry, fallback: &ModelEntry, explicit: &[Strin (r, _) => r.clone(), }; match (&mut cm.service_tier, &fm.service_tier) { - (Some(tier), Some(fallback)) if tier.supported => { + (Some(tier), Some(fallback)) if tier.supported && tier.options.is_empty() => { + // A declaration that states no set of its own is unresolved, so + // the row fills both what it offers and its default. One that + // states its own set keeps that set, and names a default only + // when it named one itself. + tier.options = fallback.options.clone(); if tier.default.is_none() { tier.default = fallback.default.clone(); } - if tier.options.is_empty() { - tier.options = fallback.options.clone(); - } } (None, fallback) => cm.service_tier = fallback.clone(), _ => {} diff --git a/crates/dim-app-server/src/provider/editing.rs b/crates/dim-app-server/src/provider/editing.rs index caaf520d22..0e724a5d5f 100644 --- a/crates/dim-app-server/src/provider/editing.rs +++ b/crates/dim-app-server/src/provider/editing.rs @@ -403,6 +403,7 @@ impl ProviderService { // carry it into the record. for model in &mut models { model.normalized_override = false; + model.restore_service_tier(); if model.capabilities.context_window.is_some() { declare(model, "contextWindow"); } diff --git a/crates/dim-app-server/src/provider/models.rs b/crates/dim-app-server/src/provider/models.rs index 4663d290a9..962af0eeee 100644 --- a/crates/dim-app-server/src/provider/models.rs +++ b/crates/dim-app-server/src/provider/models.rs @@ -249,6 +249,7 @@ impl ProviderService { // override writes carry (#2189) is not the client's to // state. model.normalized_override = false; + model.restore_service_tier(); if model.capabilities.context_window.is_some() { declare(&mut model, "contextWindow"); } diff --git a/crates/dim-app-server/tests/model_catalog_flow.rs b/crates/dim-app-server/tests/model_catalog_flow.rs index 8fdeaa6da0..f3e8945a68 100644 --- a/crates/dim-app-server/tests/model_catalog_flow.rs +++ b/crates/dim-app-server/tests/model_catalog_flow.rs @@ -254,6 +254,17 @@ fn a_service_tier_declaration_keeps_the_set_it_states() { declared, "a stored declaration is filled the same way" ); + let own_set = catalog + .project( + &codex, + &json!({"id": "gpt-5.5", "serviceTier": {"supported": true, "options": ["priority"]}}), + ) + .unwrap(); + assert_eq!( + tier(&own_set), + Some(json!({"supported": true, "options": ["priority"]})), + "a declaration that states its own set keeps it, and names no default it did not state" + ); let custom = ProviderProjection { provider_id: "custom".into(), diff --git a/crates/dim-app-server/tests/provider_flow.rs b/crates/dim-app-server/tests/provider_flow.rs index a1a2358e68..8850267d86 100644 --- a/crates/dim-app-server/tests/provider_flow.rs +++ b/crates/dim-app-server/tests/provider_flow.rs @@ -1806,6 +1806,10 @@ async fn a_service_tier_declaration_states_only_a_usable_set() { "tier-default-outside", json!({"supported": true, "default": "flex", "options": ["default", "priority"]}) ), + json!({ + "id": "tier-no-limits", + "serviceTier": {"supported": true, "default": "priority", "options": ["priority"]} + }), ])) .await; let declared = @@ -1832,6 +1836,7 @@ async fn a_service_tier_declaration_states_only_a_usable_set() { "tier-empty-options", "tier-empty-option", "tier-off", + "tier-no-limits", ] { assert_eq!( listing.served_tier(id), @@ -1897,6 +1902,7 @@ async fn a_service_tier_declaration_states_only_a_usable_set() { ("tier-off", "default"), ("tier-default-outside", "flex"), ("tier-options-only", "flex"), + ("tier-no-limits", "priority"), ] { let refused = listing .provider @@ -1960,8 +1966,8 @@ async fn a_service_tier_declaration_states_only_a_usable_set() { let input = serde_json::from_value(json!({ "providerId": "00000000-0000-4000-8000-0000000000a2", "connection": { - "driverKind": "openai-compatible", - "auth": {"type": "bearer"}, + "driverKind": "anthropic", + "auth": {"type": "api_key", "headerName": "x-api-key", "prefix": ""}, "baseUrl": format!("{}/v1", listing.base), "credential": {"action": "set", "value": "probe-key"} } @@ -1969,10 +1975,13 @@ async fn a_service_tier_declaration_states_only_a_usable_set() { .unwrap(); tokio::spawn(async move { provider.probe(input, &cancel).await }) }; + let declared_set = json!({"supported":true,"default":"flex","options":["priority","flex"]}); listing - .serve( - json!([{"id":"probe-tier","limit":{"context":9000,"output":900},"serviceTier":true}]), - ) + .serve(json!([{ + "id": "probe-tier", + "limit": {"context": 9000, "output": 900}, + "serviceTier": declared_set + }])) .await; let probed = probe.await.unwrap().unwrap(); assert_eq!( @@ -1981,8 +1990,33 @@ async fn a_service_tier_declaration_states_only_a_usable_set() { "a probe reply states only what the connection's route accepts" ); + // The Web form sends the probe's models into create. The declaration the + // listing made is recovered from the item the entry was projected from, so + // a route that can send it serves the choices and one that cannot keeps + // them for a later route instead of storing a denial. + let mut capable = input( + "00000000-0000-4000-8000-0000000000a3", + &format!("{}/v1", listing.base), + StaticAuth::Bearer, + Some("probe-key"), + "tiers", + 900, + ); + capable.models = probed.models.clone(); + let created = listing + .provider + .create(capable, &listing.cancel) + .await + .unwrap(); + assert_eq!( + published_tier(created.models.as_ref().unwrap()[0].model.metadata.as_ref()), + Some(declared_set.clone()), + "a saved probe preview keeps the declaration its route can send" + ); + + let id = "00000000-0000-4000-8000-0000000000a1"; let mut anthropic = input( - "00000000-0000-4000-8000-0000000000a1", + id, "https://api.anthropic.example/v1", StaticAuth::ApiKey { header_name: "x-api-key".into(), @@ -1993,20 +2027,12 @@ async fn a_service_tier_declaration_states_only_a_usable_set() { 900, ); anthropic.connection.driver_kind = "anthropic".into(); - let mut entry = model("anthropic-tier", 900); - entry.metadata = Some( - serde_json::from_value(json!({ - "serviceTier":{"supported":true,"default":"priority","options":["priority"]} - })) - .unwrap(), - ); - anthropic.models = vec![entry]; + anthropic.models = probed.models.clone(); listing .provider .create(anthropic, &listing.cancel) .await .unwrap(); - let id = "00000000-0000-4000-8000-0000000000a1"; let view = listing .provider .management(id.into(), None, &listing.cancel) @@ -2033,6 +2059,11 @@ async fn a_service_tier_declaration_states_only_a_usable_set() { Some(json!({"supported": false})), "the catalog states the same capability as the edit-view read" ); + let stored: Value = serde_json::from_str(&stored_record_json(&listing.home, id)).unwrap(); + assert_eq!( + stored["models"][0]["metadata"]["serviceTier"], declared_set, + "the record keeps the declaration a capable route can serve later" + ); listing.close().await; } diff --git a/docs/design/appserver/provider-management.md b/docs/design/appserver/provider-management.md index 97881997a4..37cceea7ad 100644 --- a/docs/design/appserver/provider-management.md +++ b/docs/design/appserver/provider-management.md @@ -562,11 +562,15 @@ a usable set, so `options` is non-empty and a `default` is one of them when the declaration names one. A declaration whose options neither the descriptor nor the row it is identified with enumerates is `supported: false` with no `default` and no `options`, and the preference patch then refuses every tier. -An option is a tier name, so an empty one is no option, and a declared default -the options do not offer is not stated; a declaration that names no default -keeps none, and an adoption of such a model sends no tier until a preference -names one. A route whose protocol cannot send a service tier states no -capability either, so every option a reply advertises is one that route accepts. +An option is a tier name, so an empty one is no option. A declaration that +states its own options keeps them and names a default only when it named one +itself; a default the options do not offer is not stated, and an adoption of +such a model sends no tier until a preference names one. A route whose protocol +cannot send a service tier, or a model that declares no limits and so cannot be +adopted, states no capability either, so every option a reply advertises is one +that route accepts. A probe is a preview of that capability: the declaration it +hides is still the source's, so saving it keeps the declaration and a later +route that can send tiers serves it without a refresh. Existing `delete` keeps its builtin-disable/custom-delete behavior. `models.edit` keeps `ModelEdit` and adds `endpoint: {action:"set",value:NewApiEndpoint} | diff --git a/docs/zh/design/appserver/provider-management.md b/docs/zh/design/appserver/provider-management.md index ae354d0f9d..13bf07fff1 100644 --- a/docs/zh/design/appserver/provider-management.md +++ b/docs/zh/design/appserver/provider-management.md @@ -324,9 +324,11 @@ driver、auth、默认模型只读。custom 的 driverKind/auth 创建后同样 serviceTier 声明是能力而非提示:`supported:true` 表示一套可用的档位,因此 `options` 非空, 声明给出 `default` 时它必属于该集合。描述本身与为之识别出的行都无法枚举选项的声明为 `supported:false`,且不带 `default` 与 `options`,此时偏好 patch 拒绝任何档位。选项即档位名, -空串不构成选项,集合之外的 `default` 不予声明;未声明 `default` 的声明也不得到默认档位, -采用这类模型时在偏好指定档位之前不发送档位。协议无法发送 serviceTier 的路由同样不声明 -能力,因此回复通告的每个选项都是该路由接受的。 +空串不构成选项。自行列出选项的声明保留该集合,且只在它自己声明了 `default` 时才给出默认; +集合之外的 `default` 不予声明,采用这类模型时在偏好指定档位之前不发送档位。协议无法发送 +serviceTier 的路由、以及未声明上限因此无法采用(adopt)的模型同样不声明能力,因此回复通告 +的每个选项都是该路由接受的。probe 是该能力的预览:它隐藏的声明仍属于源,保存预览保留该声明, +后续能发送档位的路由无需刷新即可提供它。 已有 delete 保持内置禁用/自定义删除。models.edit 保留 `ModelEdit`,只为静态 New API 模型增加 `endpoint:{action:"set",value:NewApiEndpoint}|{action:"clear"}`,限 §6 可执行子集。 From b973763f2e66f3156df09e9b5f4a952a7dbb8ea3 Mon Sep 17 00:00:00 2001 From: eric8810 Date: Sun, 29 Nov 2026 04:10:49 +0800 Subject: [PATCH 9/9] fix(provider): keep the declaration through edits and the Web form The edit path reads the entries it clones from, so resolving a capability there wrote the route-filtered tier into the stored user model or override: a rename on Anthropic lost the declaration a later capable route could serve. `static_entries` keeps the declaration again; the catalog read and `provider.management` resolve it for their own replies. The Web decoder dropped `metadata.raw`, which is where a created model's declaration is recovered from, so a create built by the Web form stored a filtered tier too. The decoder keeps the raw metadata and a tier's declared default, and a decoder test pins the round trip. Refs #2248 --- crates/dim-app-server/src/provider.rs | 7 ++--- crates/dim-app-server/src/provider/view.rs | 3 +- crates/dim-app-server/tests/provider_flow.rs | 32 +++++++++++++++++++- web/src/rpc/management.test.mjs | 29 ++++++++++++++++++ web/src/rpc/management.ts | 5 +-- 5 files changed, 67 insertions(+), 9 deletions(-) create mode 100644 web/src/rpc/management.test.mjs diff --git a/crates/dim-app-server/src/provider.rs b/crates/dim-app-server/src/provider.rs index 469973c848..5a9eb928f5 100644 --- a/crates/dim-app-server/src/provider.rs +++ b/crates/dim-app-server/src/provider.rs @@ -1179,10 +1179,6 @@ fn static_entries_with_overrides( .chain(&record.user_models) .any(|m| m.model_id == entry.model_id) }) - .map(|mut entry| { - entry.resolve_service_tier(record.routes.get(&entry.model_id).copied()); - entry - }) .collect() } @@ -1276,7 +1272,8 @@ fn static_models_from_entries( entries .into_iter() .zip(names) - .map(|(entry, name)| { + .map(|(mut entry, name)| { + entry.resolve_service_tier(record.routes.get(&entry.model_id).copied()); let missing_limits = entry.capabilities.missing_limits(); let status_unavailable = matches!(entry.status, crate::model_catalog::ModelStatus::Unavailable); diff --git a/crates/dim-app-server/src/provider/view.rs b/crates/dim-app-server/src/provider/view.rs index f1824994b0..f57a73288b 100644 --- a/crates/dim-app-server/src/provider/view.rs +++ b/crates/dim-app-server/src/provider/view.rs @@ -251,7 +251,8 @@ impl ProviderService { let models = entries .into_iter() .zip(catalog) - .map(|(model, effective)| { + .map(|(mut model, effective)| { + model.resolve_service_tier(effective.endpoint); let user = record .user_models .iter() diff --git a/crates/dim-app-server/tests/provider_flow.rs b/crates/dim-app-server/tests/provider_flow.rs index 8850267d86..8f8782c970 100644 --- a/crates/dim-app-server/tests/provider_flow.rs +++ b/crates/dim-app-server/tests/provider_flow.rs @@ -2028,7 +2028,7 @@ async fn a_service_tier_declaration_states_only_a_usable_set() { ); anthropic.connection.driver_kind = "anthropic".into(); anthropic.models = probed.models.clone(); - listing + let created = listing .provider .create(anthropic, &listing.cancel) .await @@ -2059,11 +2059,41 @@ async fn a_service_tier_declaration_states_only_a_usable_set() { Some(json!({"supported": false})), "the catalog states the same capability as the edit-view read" ); + listing + .provider + .update_model_config( + id.into(), + created.info.version.unwrap(), + "probe-tier".into(), + Some(serde_json::from_value(json!({"displayName":"Renamed"})).unwrap()), + &listing.cancel, + ) + .await + .unwrap(); let stored: Value = serde_json::from_str(&stored_record_json(&listing.home, id)).unwrap(); assert_eq!( stored["models"][0]["metadata"]["serviceTier"], declared_set, "the record keeps the declaration a capable route can serve later" ); + assert_eq!( + stored["modelConfigOverrides"][0]["metadata"]["serviceTier"], declared_set, + "an edit on a route that cannot send tiers keeps the declaration too" + ); + let view = listing + .provider + .management(id.into(), None, &listing.cancel) + .await + .unwrap(); + assert_eq!( + published_tier( + view.providers[0].models.as_ref().unwrap()[0] + .model + .metadata + .as_ref(), + ), + Some(json!({"supported": false})), + "the renamed model still states only what its route can send" + ); listing.close().await; } diff --git a/web/src/rpc/management.test.mjs b/web/src/rpc/management.test.mjs new file mode 100644 index 0000000000..0417182f23 --- /dev/null +++ b/web/src/rpc/management.test.mjs @@ -0,0 +1,29 @@ +import assert from "node:assert/strict" +import { registerHooks } from "node:module" +import test from "node:test" + +registerHooks({ + resolve(specifier, context, next) { + try { + return next(specifier, context) + } catch (error) { + if ((specifier.startsWith("./") || specifier.startsWith("../")) && !specifier.endsWith(".ts")) { + return next(`${specifier}.ts`, context) + } + throw error + } + }, +}) + +const { readProbe } = await import("./management.ts") + +test("a probe model keeps the listing declaration a create sends back", () => { + const raw = { id: "probe-tier", serviceTier: { supported: true, default: "priority", options: ["priority", "flex"] } } + const [model] = readProbe({ models: [{ + modelId: "probe-tier", displayName: "Probe", status: "active", + capabilities: { modalities: ["text"], toolCalling: true, streaming: true, structuredOutput: true, vision: false, audio: false, reasoning: false, contextWindow: 9000, maxOutputTokens: 900 }, + metadata: { serviceTier: { supported: false, default: "priority", options: ["priority"] }, raw }, + }] }) + assert.deepEqual(model.metadata.serviceTier, { supported: false, default: "priority", options: ["priority"] }) + assert.deepEqual(model.metadata.raw, raw, "a create sends the listing item back so the server can restore its declaration") +}) diff --git a/web/src/rpc/management.ts b/web/src/rpc/management.ts index bcc3dc10d6..4fc6e90ba7 100644 --- a/web/src/rpc/management.ts +++ b/web/src/rpc/management.ts @@ -12,7 +12,7 @@ export type ModelIdentification = { export type ModelEntry = { modelId: string; displayName: string; status: string capabilities: { modalities: string[]; toolCalling: boolean; streaming: boolean; structuredOutput: boolean; vision: boolean; audio: boolean; reasoning: boolean; contextWindow?: number; maxOutputTokens?: number } - metadata?: { reasoning?: { supported: boolean; effortOptions?: string[] }; serviceTier?: { supported: boolean; options: string[] }; identification?: ModelIdentification; matchedProviderId?: string; matchedModelId?: string } + metadata?: { reasoning?: { supported: boolean; effortOptions?: string[] }; serviceTier?: { supported: boolean; default?: string; options: string[] }; identification?: ModelIdentification; matchedProviderId?: string; matchedModelId?: string; raw?: Json } } export type ManagementModel = { model: ModelEntry; source: string; enabled: boolean; endpoint: string | null; endpointOverride?: string; alias?: string; catalogName?: string; unavailableReason: string | null; missingLimits: string[]; actions: string[] } export type ManagementInfo = { @@ -84,7 +84,8 @@ export function readModelEntry(value: unknown): ModelEntry { const m = object(item) return { reasoning: optional(m.reasoning, (item) => { const r = object(item); return { supported: boolean(r.supported), effortOptions: optional(r.effortOptions, (v) => list(v, string)) } }), - serviceTier: optional(m.serviceTier, (item) => { const s = object(item); return { supported: boolean(s.supported), options: s.options === undefined ? [] : list(s.options, string) } }), + serviceTier: optional(m.serviceTier, (item) => { const s = object(item); return { supported: boolean(s.supported), default: optional(s.default, string), options: s.options === undefined ? [] : list(s.options, string) } }), + raw: optional(m.raw, (item) => object(item)), matchedProviderId: optional(m.matchedProviderId, string), matchedModelId: optional(m.matchedModelId, string), identification: optional(m.identification, (item) => {