diff --git a/crates/ide-agent/src/native/copilot/models.rs b/crates/ide-agent/src/native/copilot/models.rs index 95154a2ad..d6d0ace9f 100644 --- a/crates/ide-agent/src/native/copilot/models.rs +++ b/crates/ide-agent/src/native/copilot/models.rs @@ -312,7 +312,7 @@ impl Settings { } /// Parses `models.list` + optional `models.listTokenPriceUnits` into catalog entries, -/// prepending `"auto"` when not already in the list. +/// prepending `"auto"` when direct models are present or Copilot advertises an enabled Auto tier. pub(super) fn parse_catalog(list: &Value, price_units: Option<&Value>) -> Vec { let units = parse_price_units(price_units); let raw = list @@ -322,7 +322,7 @@ pub(super) fn parse_catalog(list: &Value, price_units: Option<&Value>) -> Vec) -> Vec bool { + let Some(auto) = list.get("auto") else { return false }; + if auto.get("enabled").or_else(|| auto.pointer("/status/enabled")).and_then(Value::as_bool) == Some(false) { + return false; + } + let Some(tiers) = auto.get("tiers").and_then(Value::as_array) else { return auto.is_object() }; + tiers.is_empty() + || tiers.iter().any(|tier| { + tier.get("enabled").or_else(|| tier.pointer("/status/enabled")).and_then(Value::as_bool) != Some(false) + }) +} + fn parse_model(m: &Value, units: &HashMap) -> Option { let id = str_of(m, "id")?.to_owned(); if m.get("model_picker_enabled").and_then(Value::as_bool) == Some(false) diff --git a/crates/ide-agent/src/native/copilot/tests.rs b/crates/ide-agent/src/native/copilot/tests.rs index a4de2ca99..bc50f0ff7 100644 --- a/crates/ide-agent/src/native/copilot/tests.rs +++ b/crates/ide-agent/src/native/copilot/tests.rs @@ -110,6 +110,72 @@ fn sample_price_units() -> Value { }) } +#[test] +fn parses_an_enabled_auto_only_catalog() { + let list = json!({ + "models": [], + "auto": { + "defaultTier": "balance", + "tiers": [ + { + "id": "balance", + "displayName": "Standard", + "type": "auto", + "fusionTier": "standard", + "status": { "enabled": true, "pickerVisible": true } + }, + { + "id": "hydrafusion", + "displayName": "High", + "type": "fusion", + "fusionTier": "high", + "status": { + "enabled": false, + "pickerVisible": true, + "reason": "user_not_eligible" + } + }, + { + "id": "fast", + "displayName": "Fast", + "type": "auto", + "status": { "enabled": true, "pickerVisible": false } + } + ], + "providerId": "copilot" + }, + "imageModels": [] + }); + + let catalog = models::parse_catalog(&list, None); + assert_eq!(catalog.iter().map(|m| m.id.as_str()).collect::>(), ["auto"]); + assert_eq!(Settings::new(&catalog, &UserDefaults::default()).model, "auto"); + + let options = + config::parse_options(&models::config_options(&catalog, &Settings::new(&catalog, &UserDefaults::default()))); + let model = options.iter().find(|option| option.id == MODEL).unwrap(); + assert_eq!(model.current.as_deref(), Some("auto")); + assert_eq!(model.values.iter().map(|value| value.value.as_str()).collect::>(), ["auto"]); +} + +#[test] +fn rejects_an_auto_only_catalog_when_every_tier_is_disabled() { + let list = json!({ + "models": [], + "auto": { + "defaultTier": "balance", + "tiers": [ + { + "id": "balance", + "status": { "enabled": false, "pickerVisible": true } + } + ] + } + }); + + assert!(models::parse_catalog(&list, None).is_empty()); +} + #[test] fn parses_tiered_context_windows_pricing_and_uses_copilots_own_defaults() { let catalog = models::parse_catalog(&sample_models_list(), Some(&sample_price_units()));