Skip to content

Commit 5f6f2be

Browse files
committed
feat: add GLM Coding Plan toggle for Z AI provider
- Add zaiUseGlmCodingPlan field to provider settings schema - Update ZAiHandler to route requests through coding plan endpoints when enabled - Add UI toggle in Z AI settings with appropriate labels and descriptions - Add comprehensive tests for the new functionality - Add English translation keys for the new toggle This allows users with a Z AI GLM Coding Plan to use their plan instead of API credits
1 parent 94b4511 commit 5f6f2be

File tree

5 files changed

+49
-2
lines changed

5 files changed

+49
-2
lines changed

packages/types/src/provider-settings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ const sambaNovaSchema = apiModelIdProviderModelSchema.extend({
311311
const zaiSchema = apiModelIdProviderModelSchema.extend({
312312
zaiApiKey: z.string().optional(),
313313
zaiApiLine: z.union([z.literal("china"), z.literal("international")]).optional(),
314+
zaiUseGlmCodingPlan: z.boolean().optional(),
314315
})
315316

316317
const fireworksSchema = apiModelIdProviderModelSchema.extend({

src/api/providers/__tests__/zai.spec.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ describe("ZAiHandler", () => {
4444
expect(OpenAI).toHaveBeenCalledWith(expect.objectContaining({ baseURL: "https://api.z.ai/api/paas/v4" }))
4545
})
4646

47+
it("should use the international GLM Coding Plan URL when toggle is enabled", () => {
48+
new ZAiHandler({ zaiApiKey: "test-zai-api-key", zaiApiLine: "international", zaiUseGlmCodingPlan: true })
49+
expect(OpenAI).toHaveBeenCalledWith(
50+
expect.objectContaining({ baseURL: "https://api.z.ai/api/coding/paas/v4" }),
51+
)
52+
})
53+
4754
it("should use the provided API key for international", () => {
4855
const zaiApiKey = "test-zai-api-key"
4956
new ZAiHandler({ zaiApiKey, zaiApiLine: "international" })
@@ -81,6 +88,13 @@ describe("ZAiHandler", () => {
8188
)
8289
})
8390

91+
it("should use the China GLM Coding Plan URL when toggle is enabled", () => {
92+
new ZAiHandler({ zaiApiKey: "test-zai-api-key", zaiApiLine: "china", zaiUseGlmCodingPlan: true })
93+
expect(OpenAI).toHaveBeenCalledWith(
94+
expect.objectContaining({ baseURL: "https://open.bigmodel.cn/api/coding/paas/v4" }),
95+
)
96+
})
97+
8498
it("should use the provided API key for China", () => {
8599
const zaiApiKey = "test-zai-api-key"
86100
new ZAiHandler({ zaiApiKey, zaiApiLine: "china" })
@@ -120,6 +134,16 @@ describe("ZAiHandler", () => {
120134
new ZAiHandler({ zaiApiLine: "international" })
121135
expect(OpenAI).toHaveBeenCalledWith(expect.objectContaining({ apiKey: "not-provided" }))
122136
})
137+
138+
it("should use standard URL when GLM Coding Plan toggle is false", () => {
139+
new ZAiHandler({ zaiApiKey: "test-zai-api-key", zaiApiLine: "international", zaiUseGlmCodingPlan: false })
140+
expect(OpenAI).toHaveBeenCalledWith(expect.objectContaining({ baseURL: "https://api.z.ai/api/paas/v4" }))
141+
})
142+
143+
it("should use standard URL when GLM Coding Plan toggle is undefined", () => {
144+
new ZAiHandler({ zaiApiKey: "test-zai-api-key", zaiApiLine: "international" })
145+
expect(OpenAI).toHaveBeenCalledWith(expect.objectContaining({ baseURL: "https://api.z.ai/api/paas/v4" }))
146+
})
123147
})
124148

125149
describe("API Methods", () => {

src/api/providers/zai.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,20 @@ export class ZAiHandler extends BaseOpenAiCompatibleProvider<InternationalZAiMod
1818
const models = isChina ? mainlandZAiModels : internationalZAiModels
1919
const defaultModelId = isChina ? mainlandZAiDefaultModelId : internationalZAiDefaultModelId
2020

21+
// Determine the base URL based on region and GLM Coding Plan toggle
22+
let baseURL: string
23+
if (options.zaiUseGlmCodingPlan) {
24+
// Use coding plan endpoints
25+
baseURL = isChina ? "https://open.bigmodel.cn/api/coding/paas/v4" : "https://api.z.ai/api/coding/paas/v4"
26+
} else {
27+
// Use standard endpoints
28+
baseURL = isChina ? "https://open.bigmodel.cn/api/paas/v4" : "https://api.z.ai/api/paas/v4"
29+
}
30+
2131
super({
2232
...options,
2333
providerName: "Z AI",
24-
baseURL: isChina ? "https://open.bigmodel.cn/api/paas/v4" : "https://api.z.ai/api/paas/v4",
34+
baseURL,
2535
apiKey: options.zaiApiKey ?? "not-provided",
2636
defaultProviderModelId: defaultModelId,
2737
providerModels: models,

webview-ui/src/components/settings/providers/ZAi.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useCallback } from "react"
2-
import { VSCodeTextField, VSCodeDropdown, VSCodeOption } from "@vscode/webview-ui-toolkit/react"
2+
import { VSCodeTextField, VSCodeDropdown, VSCodeOption, VSCodeCheckbox } from "@vscode/webview-ui-toolkit/react"
33

44
import type { ProviderSettings } from "@roo-code/types"
55

@@ -71,6 +71,16 @@ export const ZAi = ({ apiConfiguration, setApiConfigurationField }: ZAiProps) =>
7171
</VSCodeButtonLink>
7272
)}
7373
</div>
74+
<div>
75+
<VSCodeCheckbox
76+
checked={apiConfiguration?.zaiUseGlmCodingPlan || false}
77+
onChange={(e: any) => setApiConfigurationField("zaiUseGlmCodingPlan", e.target.checked)}>
78+
{t("settings:providers.zaiUseGlmCodingPlan")}
79+
</VSCodeCheckbox>
80+
<div className="text-xs text-vscode-descriptionForeground mt-1">
81+
{t("settings:providers.zaiUseGlmCodingPlanDescription")}
82+
</div>
83+
</div>
7484
</>
7585
)
7686
}

webview-ui/src/i18n/locales/en/settings.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,8 @@
294294
"getZaiApiKey": "Get Z AI API Key",
295295
"zaiEntrypoint": "Z AI Entrypoint",
296296
"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.",
297+
"zaiUseGlmCodingPlan": "Use GLM Coding Plan",
298+
"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.",
297299
"geminiApiKey": "Gemini API Key",
298300
"getGroqApiKey": "Get Groq API Key",
299301
"groqApiKey": "Groq API Key",

0 commit comments

Comments
 (0)