diff --git a/packages/types/src/provider-settings.ts b/packages/types/src/provider-settings.ts index 4dfeacbf07..c77ed2f90d 100644 --- a/packages/types/src/provider-settings.ts +++ b/packages/types/src/provider-settings.ts @@ -311,6 +311,7 @@ const sambaNovaSchema = apiModelIdProviderModelSchema.extend({ const zaiSchema = apiModelIdProviderModelSchema.extend({ zaiApiKey: z.string().optional(), zaiApiLine: z.union([z.literal("china"), z.literal("international")]).optional(), + zaiUseGlmCodingPlan: z.boolean().optional(), }) const fireworksSchema = apiModelIdProviderModelSchema.extend({ diff --git a/src/api/providers/__tests__/zai.spec.ts b/src/api/providers/__tests__/zai.spec.ts index a16aa9fcdf..7e17471a54 100644 --- a/src/api/providers/__tests__/zai.spec.ts +++ b/src/api/providers/__tests__/zai.spec.ts @@ -44,6 +44,13 @@ describe("ZAiHandler", () => { expect(OpenAI).toHaveBeenCalledWith(expect.objectContaining({ baseURL: "https://api.z.ai/api/paas/v4" })) }) + it("should use the international GLM Coding Plan URL when toggle is enabled", () => { + new ZAiHandler({ zaiApiKey: "test-zai-api-key", zaiApiLine: "international", zaiUseGlmCodingPlan: true }) + expect(OpenAI).toHaveBeenCalledWith( + expect.objectContaining({ baseURL: "https://api.z.ai/api/coding/paas/v4" }), + ) + }) + it("should use the provided API key for international", () => { const zaiApiKey = "test-zai-api-key" new ZAiHandler({ zaiApiKey, zaiApiLine: "international" }) @@ -81,6 +88,13 @@ describe("ZAiHandler", () => { ) }) + it("should use the China GLM Coding Plan URL when toggle is enabled", () => { + new ZAiHandler({ zaiApiKey: "test-zai-api-key", zaiApiLine: "china", zaiUseGlmCodingPlan: true }) + expect(OpenAI).toHaveBeenCalledWith( + expect.objectContaining({ baseURL: "https://open.bigmodel.cn/api/coding/paas/v4" }), + ) + }) + it("should use the provided API key for China", () => { const zaiApiKey = "test-zai-api-key" new ZAiHandler({ zaiApiKey, zaiApiLine: "china" }) @@ -120,6 +134,16 @@ describe("ZAiHandler", () => { new ZAiHandler({ zaiApiLine: "international" }) expect(OpenAI).toHaveBeenCalledWith(expect.objectContaining({ apiKey: "not-provided" })) }) + + it("should use standard URL when GLM Coding Plan toggle is false", () => { + new ZAiHandler({ zaiApiKey: "test-zai-api-key", zaiApiLine: "international", zaiUseGlmCodingPlan: false }) + expect(OpenAI).toHaveBeenCalledWith(expect.objectContaining({ baseURL: "https://api.z.ai/api/paas/v4" })) + }) + + it("should use standard URL when GLM Coding Plan toggle is undefined", () => { + new ZAiHandler({ zaiApiKey: "test-zai-api-key", zaiApiLine: "international" }) + expect(OpenAI).toHaveBeenCalledWith(expect.objectContaining({ baseURL: "https://api.z.ai/api/paas/v4" })) + }) }) describe("API Methods", () => { diff --git a/src/api/providers/zai.ts b/src/api/providers/zai.ts index e37e37f01b..46e44b5621 100644 --- a/src/api/providers/zai.ts +++ b/src/api/providers/zai.ts @@ -18,10 +18,20 @@ export class ZAiHandler extends BaseOpenAiCompatibleProvider )} +
+ setApiConfigurationField("zaiUseGlmCodingPlan", e.target.checked)}> + {t("settings:providers.zaiUseGlmCodingPlan")} + +
+ {t("settings:providers.zaiUseGlmCodingPlanDescription")} +
+
) } diff --git a/webview-ui/src/i18n/locales/en/settings.json b/webview-ui/src/i18n/locales/en/settings.json index 1be824b37e..f29e5e1eb3 100644 --- a/webview-ui/src/i18n/locales/en/settings.json +++ b/webview-ui/src/i18n/locales/en/settings.json @@ -294,6 +294,8 @@ "getZaiApiKey": "Get Z AI API Key", "zaiEntrypoint": "Z AI Entrypoint", "zaiEntrypointDescription": "Please select the appropriate API entrypoint based on your location. If you are in China, choose open.bigmodel.cn. Otherwise, choose api.z.ai.", + "zaiUseGlmCodingPlan": "Use GLM Coding Plan", + "zaiUseGlmCodingPlanDescription": "Route requests through GLM Coding Plan endpoints to use your plan instead of API credits. When plan limits are reached, disable this toggle to continue with API credits.", "geminiApiKey": "Gemini API Key", "getGroqApiKey": "Get Groq API Key", "groqApiKey": "Groq API Key",