From 08ee8ca8d3ec0f73b7031f0d7ce60e2088d61e85 Mon Sep 17 00:00:00 2001 From: lzt404 <2596933790@qq.com> Date: Tue, 8 Sep 2026 12:31:32 +0800 Subject: [PATCH] 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 --- src-tauri/src/agents/configuration.rs | 4 +++- src-tauri/src/tests/agent_configuration.rs | 8 +++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src-tauri/src/agents/configuration.rs b/src-tauri/src/agents/configuration.rs index e917ce6..4ee1d60 100644 --- a/src-tauri/src/agents/configuration.rs +++ b/src-tauri/src/agents/configuration.rs @@ -2856,6 +2856,9 @@ fn build_zcode_config( }) .collect::>(); 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)); diff --git a/src-tauri/src/tests/agent_configuration.rs b/src-tauri/src/tests/agent_configuration.rs index ae8b4a8..928a6db 100644 --- a/src-tauri/src/tests/agent_configuration.rs +++ b/src-tauri/src/tests/agent_configuration.rs @@ -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!(