fix(zcode): remove incompatible npm provider field
Stop writing the OpenCode-specific npm field and clean up values left by earlier versions when synchronizing ZCode configuration. Add regression coverage for both app and CLI configs. Closes #231
This commit is contained in:
1 parent
8c0eae2c34
commit
08ee8ca8d3
2 files changed
+10
-2
No files matched your search
@@ -2856,6 +2856,9 @@ fn build_zcode_config(
|
||||
})
|
||||
.collect::<serde_json::Map<_, _>>();
|
||||
let managed_provider = ensure_json_object_entry(providers, MANAGED_AGENT_PROVIDER_ID);
|
||||
// `npm` is an OpenCode provider field. ZCode treats it as an incompatible
|
||||
// provider definition, so also remove values written by earlier versions.
|
||||
managed_provider.remove("npm");
|
||||
managed_provider.insert("enabled".to_string(), serde_json::json!(true));
|
||||
managed_provider.insert("name".to_string(), serde_json::json!("EasyCLIProxyAPI"));
|
||||
managed_provider.insert("source".to_string(), serde_json::json!("custom"));
|
||||
@@ -2865,7 +2868,6 @@ fn build_zcode_config(
|
||||
"apiFormat".to_string(),
|
||||
serde_json::json!("anthropic-messages"),
|
||||
);
|
||||
managed_provider.insert("npm".to_string(), serde_json::json!("@ai-sdk/anthropic"));
|
||||
let options = ensure_json_object_entry(managed_provider, "options");
|
||||
options.insert("baseURL".to_string(), serde_json::json!(base_url));
|
||||
options.insert("apiKey".to_string(), serde_json::json!(api_key));
|
||||
|
||||
@@ -910,7 +910,7 @@ fn zcode_agent_config_preserves_other_providers_and_uses_anthropic_messages() {
|
||||
models[1].context_window = Some(272_000);
|
||||
let rendered = build_zcode_agent_config(
|
||||
Some(
|
||||
r#"{"locale":"zh-CN","provider":{"other":{"kind":"openai"},"cpa-gui":{"custom":"keep","options":{"timeout":30}}}}"#,
|
||||
r#"{"locale":"zh-CN","provider":{"other":{"kind":"openai"},"cpa-gui":{"custom":"keep","npm":"@ai-sdk/anthropic","options":{"timeout":30}}}}"#,
|
||||
),
|
||||
"http://127.0.0.1:8317",
|
||||
DEFAULT_API_KEY,
|
||||
@@ -939,6 +939,9 @@ fn zcode_agent_config_preserves_other_providers_and_uses_anthropic_messages() {
|
||||
value["provider"][MANAGED_AGENT_PROVIDER_ID]["apiFormat"],
|
||||
"anthropic-messages"
|
||||
);
|
||||
assert!(value["provider"][MANAGED_AGENT_PROVIDER_ID]
|
||||
.get("npm")
|
||||
.is_none());
|
||||
assert_eq!(
|
||||
value["provider"][MANAGED_AGENT_PROVIDER_ID]["options"]["baseURL"],
|
||||
"http://127.0.0.1:8317"
|
||||
@@ -1000,6 +1003,9 @@ fn zcode_cli_config_sets_main_model_and_both_configs_must_match() {
|
||||
assert_eq!(cli_value["model"]["main"], "cpa-gui/gpt-test");
|
||||
assert_eq!(cli_value["model"]["lite"], "other/lite");
|
||||
assert_eq!(cli_value["plugins"]["keep"], true);
|
||||
assert!(cli_value["provider"][MANAGED_AGENT_PROVIDER_ID]
|
||||
.get("npm")
|
||||
.is_none());
|
||||
fs::write(&paths[0], app_config).unwrap();
|
||||
fs::write(&paths[1], &cli_config).unwrap();
|
||||
assert_eq!(
|
||||
|
||||
Reference in new issue
Block a user