From 23256cd6daa4b03541d0b195919cc7f195af3181 Mon Sep 17 00:00:00 2001 From: Roo Code Date: Fri, 30 Jan 2026 16:22:33 +0000 Subject: [PATCH] feat: add thinking mode support for GLM-4.6 and GLM-4.6V models - Add supportsReasoningEffort to GLM-4.6 and GLM-4.6V model definitions - Update GLM detection logic to recognize GLM-4.6/4.6V thinking support - Update Z.ai provider to handle thinking mode for all GLM models with reasoning - Update tests to reflect GLM-4.6/4.6V thinking support Addresses issue #11071 where Z.ai documentation shows GLM-4.6 and GLM-4.6V support thinking mode, but this was not reflected in the codebase. --- packages/types/src/providers/zai.ts | 12 ++++++++++++ .../__tests__/glm-model-detection.spec.ts | 19 +++++++++++++++---- .../providers/utils/glm-model-detection.ts | 8 ++++++-- src/api/providers/zai.ts | 16 ++++++++-------- 4 files changed, 41 insertions(+), 14 deletions(-) diff --git a/packages/types/src/providers/zai.ts b/packages/types/src/providers/zai.ts index 41a6a808ca..0fc175deb9 100644 --- a/packages/types/src/providers/zai.ts +++ b/packages/types/src/providers/zai.ts @@ -86,6 +86,9 @@ export const internationalZAiModels = { contextWindow: 131_072, supportsImages: true, supportsPromptCache: true, + supportsReasoningEffort: ["disable", "medium"], + reasoningEffort: "medium", + preserveReasoning: true, inputPrice: 0.3, outputPrice: 0.9, cacheWritesPrice: 0, @@ -98,6 +101,9 @@ export const internationalZAiModels = { contextWindow: 200_000, supportsImages: false, supportsPromptCache: true, + supportsReasoningEffort: ["disable", "medium"], + reasoningEffort: "medium", + preserveReasoning: true, inputPrice: 0.6, outputPrice: 2.2, cacheWritesPrice: 0, @@ -259,6 +265,9 @@ export const mainlandZAiModels = { contextWindow: 204_800, supportsImages: false, supportsPromptCache: true, + supportsReasoningEffort: ["disable", "medium"], + reasoningEffort: "medium", + preserveReasoning: true, inputPrice: 0.29, outputPrice: 1.14, cacheWritesPrice: 0, @@ -310,6 +319,9 @@ export const mainlandZAiModels = { contextWindow: 131_072, supportsImages: true, supportsPromptCache: true, + supportsReasoningEffort: ["disable", "medium"], + reasoningEffort: "medium", + preserveReasoning: true, inputPrice: 0.15, outputPrice: 0.45, cacheWritesPrice: 0, diff --git a/src/api/providers/utils/__tests__/glm-model-detection.spec.ts b/src/api/providers/utils/__tests__/glm-model-detection.spec.ts index 78f134e9fa..dfcbe3a8ab 100644 --- a/src/api/providers/utils/__tests__/glm-model-detection.spec.ts +++ b/src/api/providers/utils/__tests__/glm-model-detection.spec.ts @@ -130,17 +130,28 @@ describe("GLM Model Detection", () => { }) describe("thinking support detection", () => { - it("should detect thinking support for GLM-4.7", () => { + it("should detect thinking support for GLM-4.7 variants", () => { expect(detectGlmModel("glm-4.7").supportsThinking).toBe(true) expect(detectGlmModel("glm-4.7-flash").supportsThinking).toBe(true) expect(detectGlmModel("GLM-4.7-FlashX").supportsThinking).toBe(true) }) - it("should NOT detect thinking support for GLM-4.5 and GLM-4.6", () => { + it("should detect thinking support for GLM-4.6 base model", () => { + expect(detectGlmModel("glm-4.6").supportsThinking).toBe(true) + }) + + it("should detect thinking support for GLM-4.6V vision variants", () => { + expect(detectGlmModel("glm-4.6v").supportsThinking).toBe(true) + expect(detectGlmModel("GLM-4.6V").supportsThinking).toBe(true) + expect(detectGlmModel("glm-4.6v-flash").supportsThinking).toBe(true) + expect(detectGlmModel("glm-4.6v-flashx").supportsThinking).toBe(true) + }) + + it("should NOT detect thinking support for GLM-4.5 variants", () => { expect(detectGlmModel("glm-4.5").supportsThinking).toBe(false) - expect(detectGlmModel("glm-4.6").supportsThinking).toBe(false) expect(detectGlmModel("glm-4.5-air").supportsThinking).toBe(false) - expect(detectGlmModel("glm-4.6v").supportsThinking).toBe(false) + expect(detectGlmModel("glm-4.5-flash").supportsThinking).toBe(false) + expect(detectGlmModel("glm-4.5v").supportsThinking).toBe(false) }) }) diff --git a/src/api/providers/utils/glm-model-detection.ts b/src/api/providers/utils/glm-model-detection.ts index dddd2da281..ac7c3a538f 100644 --- a/src/api/providers/utils/glm-model-detection.ts +++ b/src/api/providers/utils/glm-model-detection.ts @@ -138,8 +138,12 @@ export function detectGlmModel(modelId: string): GlmModelConfig { variant = "x" } - // GLM-4.7 has built-in thinking support - const supportsThinking = version === "4.7" + // GLM-4.6, GLM-4.6V, and GLM-4.7 have built-in thinking support + // For GLM-4.6, only the base model and vision variants support thinking + const supportsThinking = + version === "4.7" || + (version === "4.6" && + (variant === "base" || variant === "v" || variant === "v-flash" || variant === "v-flashx")) // Generate display name let displayName = `GLM-${version !== "unknown" ? version : "4.x"}` diff --git a/src/api/providers/zai.ts b/src/api/providers/zai.ts index a2e3740c56..7e9a362c68 100644 --- a/src/api/providers/zai.ts +++ b/src/api/providers/zai.ts @@ -40,9 +40,9 @@ export class ZAiHandler extends BaseOpenAiCompatibleProvider { } /** - * Override createStream to handle GLM-4.7's thinking mode. - * GLM-4.7 has thinking enabled by default in the API, so we need to - * explicitly send { type: "disabled" } when the user turns off reasoning. + * Override createStream to handle thinking mode for GLM models. + * GLM-4.6, GLM-4.6V, and GLM-4.7 have thinking enabled by default in the API, + * so we need to explicitly send { type: "disabled" } when the user turns off reasoning. */ protected override createStream( systemPrompt: string, @@ -52,11 +52,11 @@ export class ZAiHandler extends BaseOpenAiCompatibleProvider { ) { const { id: modelId, info } = this.getModel() - // Check if this is a GLM-4.7 model with thinking support - const isThinkingModel = modelId === "glm-4.7" && Array.isArray(info.supportsReasoningEffort) + // Check if this is a GLM model with thinking support (GLM-4.6, GLM-4.6V, GLM-4.7) + const isThinkingModel = Array.isArray(info.supportsReasoningEffort) if (isThinkingModel) { - // For GLM-4.7, thinking is ON by default in the API. + // For GLM thinking models, thinking is ON by default in the API. // We need to explicitly disable it when reasoning is off. const useReasoning = shouldUseReasoningEffort({ model: info, settings: this.options }) @@ -69,7 +69,7 @@ export class ZAiHandler extends BaseOpenAiCompatibleProvider { } /** - * Creates a stream with explicit thinking control for GLM-4.7 + * Creates a stream with explicit thinking control for GLM thinking models (4.6, 4.6V, 4.7) */ private createStreamWithThinking( systemPrompt: string, @@ -99,7 +99,7 @@ export class ZAiHandler extends BaseOpenAiCompatibleProvider { messages: [{ role: "system", content: systemPrompt }, ...convertedMessages], stream: true, stream_options: { include_usage: true }, - // For GLM-4.7: thinking is ON by default, so we explicitly disable when needed + // For GLM thinking models: thinking is ON by default, so we explicitly disable when needed thinking: useReasoning ? { type: "enabled" } : { type: "disabled" }, tools: this.convertToolsForOpenAI(metadata?.tools), tool_choice: metadata?.tool_choice,