Skip to content

Commit 085bc7f

Browse files
authored
feat: add glm-5.2 support (#608)
* feat: add glm-5.2 support Introduces a Max reasoning-effort tier; High is the default and Max is opt-in. * i18n: add max reasoning-effort translations for all 17 non-English locales * fix(zai): fall back to model default when persisted reasoning effort is unsupported Persisted reasoning effort not offered by the current model now falls back to the model default instead of silently disabling reasoning. Also wraps create() in handleOpenAIError for consistency with the base class, and flags GLM-5.2 pricing as provisional (mirrors GLM-5.1).
1 parent abd17c4 commit 085bc7f

23 files changed

Lines changed: 259 additions & 15 deletions

File tree

.changeset/add-glm-5-2-support.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"zoo-code": minor
3+
---
4+
5+
Add GLM-5.2 support with High/Max `reasoning_effort` tiers. The default effort is High (deep reasoning stays opt-in), Max is selected only when the user explicitly picks it, and the parameter is omitted entirely when reasoning is disabled.

packages/types/src/model.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export type ReasoningEffortWithMinimal = z.infer<typeof reasoningEffortWithMinim
2323
* Extended Reasoning Effort (includes "none" and "minimal")
2424
* Note: "disable" is a UI/control value, not a value sent as effort
2525
*/
26-
export const reasoningEffortsExtended = ["none", "minimal", "low", "medium", "high", "xhigh"] as const
26+
export const reasoningEffortsExtended = ["none", "minimal", "low", "medium", "high", "xhigh", "max"] as const
2727

2828
export const reasoningEffortExtendedSchema = z.enum(reasoningEffortsExtended)
2929

@@ -32,7 +32,16 @@ export type ReasoningEffortExtended = z.infer<typeof reasoningEffortExtendedSche
3232
/**
3333
* Reasoning Effort user setting (includes "disable")
3434
*/
35-
export const reasoningEffortSettingValues = ["disable", "none", "minimal", "low", "medium", "high", "xhigh"] as const
35+
export const reasoningEffortSettingValues = [
36+
"disable",
37+
"none",
38+
"minimal",
39+
"low",
40+
"medium",
41+
"high",
42+
"xhigh",
43+
"max",
44+
] as const
3645
export const reasoningEffortSettingSchema = z.enum(reasoningEffortSettingValues)
3746

3847
/**
@@ -93,7 +102,7 @@ export const modelInfoSchema = z.object({
93102
defaultTemperature: z.number().optional(),
94103
requiredReasoningBudget: z.boolean().optional(),
95104
supportsReasoningEffort: z
96-
.union([z.boolean(), z.array(z.enum(["disable", "none", "minimal", "low", "medium", "high", "xhigh"]))])
105+
.union([z.boolean(), z.array(z.enum(["disable", "none", "minimal", "low", "medium", "high", "xhigh", "max"]))])
97106
.optional(),
98107
requiredReasoningEffort: z.boolean().optional(),
99108
preserveReasoning: z.boolean().optional(),

packages/types/src/providers/zai.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,23 @@ export const internationalZAiModels = {
153153
description:
154154
"GLM-5.1 is Zhipu's most capable model with a 200k context window, 128k max output, and built-in thinking capabilities. It delivers top-tier reasoning, coding, and agentic performance.",
155155
},
156+
"glm-5.2": {
157+
maxTokens: 131_072,
158+
contextWindow: 1_000_000,
159+
supportsImages: false,
160+
supportsPromptCache: true,
161+
supportsMaxTokens: true,
162+
supportsReasoningEffort: ["disable", "high", "max"],
163+
reasoningEffort: "high",
164+
preserveReasoning: true,
165+
// TODO: Pricing is from GLM-5.1, should update later.
166+
inputPrice: 1.4,
167+
outputPrice: 4.4,
168+
cacheWritesPrice: 0,
169+
cacheReadsPrice: 0.26,
170+
description:
171+
"GLM-5.2 is Zhipu's flagship model with a 1M context window, 128k max output, and dual thinking-effort modes (High/Max). It delivers top-tier long-context reasoning, coding, and agentic performance for extended engineering sessions.",
172+
},
156173
"glm-5-turbo": {
157174
maxTokens: 131_072,
158175
contextWindow: 202_752,
@@ -361,6 +378,23 @@ export const mainlandZAiModels = {
361378
description:
362379
"GLM-5.1 is Zhipu's most capable model with a 200k context window, 128k max output, and built-in thinking capabilities. It delivers top-tier reasoning, coding, and agentic performance.",
363380
},
381+
"glm-5.2": {
382+
maxTokens: 131_072,
383+
contextWindow: 1_000_000,
384+
supportsImages: false,
385+
supportsPromptCache: true,
386+
supportsMaxTokens: true,
387+
supportsReasoningEffort: ["disable", "high", "max"],
388+
reasoningEffort: "high",
389+
preserveReasoning: true,
390+
// TODO: Pricing is from GLM-5.1, should update later.
391+
inputPrice: 0.68,
392+
outputPrice: 2.28,
393+
cacheWritesPrice: 0,
394+
cacheReadsPrice: 0.13,
395+
description:
396+
"GLM-5.2 is Zhipu's flagship model with a 1M context window, 128k max output, and dual thinking-effort modes (High/Max). It delivers top-tier long-context reasoning, coding, and agentic performance for extended engineering sessions.",
397+
},
364398
"glm-5-turbo": {
365399
maxTokens: 131_072,
366400
contextWindow: 202_752,

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

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,27 @@ describe("ZAiHandler", () => {
118118
expect(model.info.supportsImages).toBe(false)
119119
})
120120

121+
it("should return GLM-5.2 international model with High/Max effort tiers and 1M context", () => {
122+
const testModelId: InternationalZAiModelId = "glm-5.2"
123+
const handlerWithModel = new ZAiHandler({
124+
apiModelId: testModelId,
125+
zaiApiKey: "test-zai-api-key",
126+
zaiApiLine: "international_coding",
127+
})
128+
const model = handlerWithModel.getModel()
129+
expect(model.id).toBe(testModelId)
130+
expect(model.info).toEqual(internationalZAiModels[testModelId])
131+
expect(model.info.contextWindow).toBe(1_000_000)
132+
expect(model.info.maxTokens).toBe(131_072)
133+
expect(model.info.supportsReasoningEffort).toEqual(["disable", "high", "max"])
134+
expect(model.info.reasoningEffort).toBe("high")
135+
expect(model.info.preserveReasoning).toBe(true)
136+
expect(model.info.supportsMaxTokens).toBe(true)
137+
expect(model.info.inputPrice).toBe(1.4)
138+
expect(model.info.outputPrice).toBe(4.4)
139+
expect(model.info.cacheReadsPrice).toBe(0.26)
140+
})
141+
121142
it("should return GLM-5-Turbo international model with thinking support", () => {
122143
const testModelId: InternationalZAiModelId = "glm-5-turbo"
123144
const handlerWithModel = new ZAiHandler({
@@ -233,6 +254,27 @@ describe("ZAiHandler", () => {
233254
expect(model.info.supportsImages).toBe(false)
234255
})
235256

257+
it("should return GLM-5.2 China model with High/Max effort tiers and 1M context", () => {
258+
const testModelId: MainlandZAiModelId = "glm-5.2"
259+
const handlerWithModel = new ZAiHandler({
260+
apiModelId: testModelId,
261+
zaiApiKey: "test-zai-api-key",
262+
zaiApiLine: "china_coding",
263+
})
264+
const model = handlerWithModel.getModel()
265+
expect(model.id).toBe(testModelId)
266+
expect(model.info).toEqual(mainlandZAiModels[testModelId])
267+
expect(model.info.contextWindow).toBe(1_000_000)
268+
expect(model.info.maxTokens).toBe(131_072)
269+
expect(model.info.supportsReasoningEffort).toEqual(["disable", "high", "max"])
270+
expect(model.info.reasoningEffort).toBe("high")
271+
expect(model.info.preserveReasoning).toBe(true)
272+
expect(model.info.supportsMaxTokens).toBe(true)
273+
expect(model.info.inputPrice).toBe(0.68)
274+
expect(model.info.outputPrice).toBe(2.28)
275+
expect(model.info.cacheReadsPrice).toBe(0.13)
276+
})
277+
236278
it("should return GLM-4.7 China model with thinking support", () => {
237279
const testModelId: MainlandZAiModelId = "glm-4.7"
238280
const handlerWithModel = new ZAiHandler({
@@ -575,6 +617,122 @@ describe("ZAiHandler", () => {
575617
)
576618
})
577619

620+
it("should send reasoning_effort:high by default for GLM-5.2 (model default)", async () => {
621+
const handlerWithModel = new ZAiHandler({
622+
apiModelId: "glm-5.2",
623+
zaiApiKey: "test-zai-api-key",
624+
zaiApiLine: "international_coding",
625+
// No reasoningEffort setting - should use model default (high)
626+
})
627+
628+
mockCreate.mockImplementationOnce(() => {
629+
return {
630+
[Symbol.asyncIterator]: () => ({
631+
async next() {
632+
return { done: true }
633+
},
634+
}),
635+
}
636+
})
637+
638+
const messageGenerator = handlerWithModel.createMessage("system prompt", [])
639+
await messageGenerator.next()
640+
641+
expect(mockCreate).toHaveBeenCalledWith(
642+
expect.objectContaining({
643+
model: "glm-5.2",
644+
thinking: { type: "enabled" },
645+
reasoning_effort: "high",
646+
}),
647+
)
648+
})
649+
650+
it("should send reasoning_effort:max for GLM-5.2 when reasoningEffort is set to max", async () => {
651+
const handlerWithModel = new ZAiHandler({
652+
apiModelId: "glm-5.2",
653+
zaiApiKey: "test-zai-api-key",
654+
zaiApiLine: "international_coding",
655+
reasoningEffort: "max",
656+
})
657+
658+
mockCreate.mockImplementationOnce(() => {
659+
return {
660+
[Symbol.asyncIterator]: () => ({
661+
async next() {
662+
return { done: true }
663+
},
664+
}),
665+
}
666+
})
667+
668+
const messageGenerator = handlerWithModel.createMessage("system prompt", [])
669+
await messageGenerator.next()
670+
671+
expect(mockCreate).toHaveBeenCalledWith(
672+
expect.objectContaining({
673+
model: "glm-5.2",
674+
thinking: { type: "enabled" },
675+
reasoning_effort: "max",
676+
}),
677+
)
678+
})
679+
680+
it("should omit reasoning_effort for GLM-5.2 when reasoningEffort is set to disable", async () => {
681+
const handlerWithModel = new ZAiHandler({
682+
apiModelId: "glm-5.2",
683+
zaiApiKey: "test-zai-api-key",
684+
zaiApiLine: "international_coding",
685+
reasoningEffort: "disable",
686+
})
687+
688+
mockCreate.mockImplementationOnce(() => {
689+
return {
690+
[Symbol.asyncIterator]: () => ({
691+
async next() {
692+
return { done: true }
693+
},
694+
}),
695+
}
696+
})
697+
698+
const messageGenerator = handlerWithModel.createMessage("system prompt", [])
699+
await messageGenerator.next()
700+
701+
const callArgs = mockCreate.mock.calls[0][0]
702+
expect(callArgs.thinking).toEqual({ type: "disabled" })
703+
expect(callArgs.reasoning_effort).toBeUndefined()
704+
})
705+
706+
it("should fall back to the model default effort when a persisted value is unsupported", async () => {
707+
const handlerWithModel = new ZAiHandler({
708+
apiModelId: "glm-5.2",
709+
zaiApiKey: "test-zai-api-key",
710+
zaiApiLine: "international_coding",
711+
reasoningEffort: "medium",
712+
})
713+
714+
mockCreate.mockImplementationOnce(() => {
715+
return {
716+
[Symbol.asyncIterator]: () => ({
717+
async next() {
718+
return { done: true }
719+
},
720+
}),
721+
}
722+
})
723+
724+
const messageGenerator = handlerWithModel.createMessage("system prompt", [])
725+
await messageGenerator.next()
726+
727+
expect(mockCreate).toHaveBeenCalledWith(
728+
expect.objectContaining({
729+
model: "glm-5.2",
730+
thinking: { type: "enabled" },
731+
reasoning_effort: "high",
732+
}),
733+
)
734+
})
735+
578736
it("should disable thinking for GLM-4.7 when reasoningEffort is set to disable", async () => {
579737
const handlerWithModel = new ZAiHandler({
580738
apiModelId: "glm-4.7",

src/api/providers/zai.ts

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,20 @@ import {
1111
zaiApiLineConfigs,
1212
} from "@roo-code/types"
1313

14-
import { type ApiHandlerOptions, getModelMaxOutputTokens, shouldUseReasoningEffort } from "../../shared/api"
14+
import { type ApiHandlerOptions, getModelMaxOutputTokens } from "../../shared/api"
1515
import { convertToZAiFormat } from "../transform/zai-format"
1616

1717
import type { ApiHandlerCreateMessageMetadata } from "../index"
1818
import { BaseOpenAiCompatibleProvider } from "./base-openai-compatible-provider"
19+
import { handleOpenAIError } from "./utils/openai-error-handler"
1920

20-
// Custom interface for Z.ai params to support thinking mode
21-
type ZAiChatCompletionParams = OpenAI.Chat.ChatCompletionCreateParamsStreaming & {
21+
// Custom interface for Z.ai params to support thinking mode and reasoning effort tiers.
22+
// Z.ai accepts the standard `reasoning_effort` ladder (none/minimal/low/medium/high/xhigh/max)
23+
// alongside the GLM-specific `thinking` toggle. Omit the OpenAI-typed `reasoning_effort` so we
24+
// can widen it to include provider-specific values such as "max".
25+
type ZAiChatCompletionParams = Omit<OpenAI.Chat.ChatCompletionCreateParamsStreaming, "reasoning_effort"> & {
2226
thinking?: { type: "enabled" | "disabled" }
27+
reasoning_effort?: "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max"
2328
}
2429

2530
export class ZAiHandler extends BaseOpenAiCompatibleProvider<string> {
@@ -56,12 +61,8 @@ export class ZAiHandler extends BaseOpenAiCompatibleProvider<string> {
5661
const isThinkingModel = Array.isArray(info.supportsReasoningEffort)
5762

5863
if (isThinkingModel) {
59-
// For GLM-4.7, thinking is ON by default in the API.
60-
// We need to explicitly disable it when reasoning is off.
61-
const useReasoning = shouldUseReasoningEffort({ model: info, settings: this.options })
62-
6364
// Create the stream with our custom thinking parameter
64-
return this.createStreamWithThinking(systemPrompt, messages, metadata, useReasoning)
65+
return this.createStreamWithThinking(systemPrompt, messages, metadata)
6566
}
6667

6768
// For non-thinking models, use the default behavior
@@ -75,10 +76,22 @@ export class ZAiHandler extends BaseOpenAiCompatibleProvider<string> {
7576
systemPrompt: string,
7677
messages: Anthropic.Messages.MessageParam[],
7778
metadata?: ApiHandlerCreateMessageMetadata,
78-
useReasoning?: boolean,
7979
) {
8080
const { id: model, info } = this.getModel()
8181

82+
// Fall back to the model default when the resolved effort isn't supported by the model.
83+
const supported = info.supportsReasoningEffort
84+
const raw =
85+
this.options.enableReasoningEffort === false
86+
? undefined
87+
: (this.options.reasoningEffort ?? info.reasoningEffort)
88+
const effort =
89+
raw && raw !== "disable" && Array.isArray(supported) && !supported.includes(raw)
90+
? info.reasoningEffort
91+
: raw
92+
const reasoningEffort = effort && effort !== "disable" ? effort : undefined
93+
const useReasoning = reasoningEffort !== undefined
94+
8295
const max_tokens =
8396
this.options.modelMaxTokens ||
8497
(getModelMaxOutputTokens({
@@ -103,11 +116,18 @@ export class ZAiHandler extends BaseOpenAiCompatibleProvider<string> {
103116
stream_options: { include_usage: true },
104117
// Thinking is ON by default for these models, so explicitly disable it when needed.
105118
thinking: useReasoning ? { type: "enabled" } : { type: "disabled" },
119+
reasoning_effort: reasoningEffort,
106120
tools: this.convertToolsForOpenAI(metadata?.tools),
107121
tool_choice: metadata?.tool_choice,
108122
parallel_tool_calls: metadata?.parallelToolCalls ?? true,
109123
}
110124

111-
return this.client.chat.completions.create(params)
125+
try {
126+
return this.client.chat.completions.create(
127+
params as OpenAI.Chat.Completions.ChatCompletionCreateParamsStreaming,
128+
)
129+
} catch (error) {
130+
throw handleOpenAIError(error, this.providerName)
131+
}
112132
}
113133
}

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

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,8 @@
620620
"low": "Low",
621621
"medium": "Medium",
622622
"high": "High",
623-
"xhigh": "Extra High"
623+
"xhigh": "Extra High",
624+
"max": "Max"
624625
},
625626
"verbosity": {
626627
"label": "Output Verbosity",

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

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)