From 2566bfaa614f1378d7efb3fb05fbe987c863f967 Mon Sep 17 00:00:00 2001 From: Roo Code Date: Thu, 12 Feb 2026 13:09:49 +0000 Subject: [PATCH] feat: add GLM-5 model support to Z.ai provider --- packages/types/src/providers/zai.ts | 30 +++++++ src/api/providers/__tests__/zai.spec.ts | 100 ++++++++++++++++++++++++ src/api/providers/zai.ts | 4 +- 3 files changed, 132 insertions(+), 2 deletions(-) diff --git a/packages/types/src/providers/zai.ts b/packages/types/src/providers/zai.ts index 41a6a808ca0..69f90f232a5 100644 --- a/packages/types/src/providers/zai.ts +++ b/packages/types/src/providers/zai.ts @@ -120,6 +120,21 @@ export const internationalZAiModels = { description: "GLM-4.7 is Zhipu's latest model with built-in thinking capabilities enabled by default. It provides enhanced reasoning for complex tasks while maintaining fast response times.", }, + "glm-5": { + maxTokens: 16_384, + contextWindow: 202_752, + supportsImages: false, + supportsPromptCache: true, + supportsReasoningEffort: ["disable", "medium"], + reasoningEffort: "medium", + preserveReasoning: true, + inputPrice: 0.6, + outputPrice: 2.2, + cacheWritesPrice: 0, + cacheReadsPrice: 0.11, + description: + "GLM-5 is Zhipu's next-generation model with a 202k context window and built-in thinking capabilities. It delivers state-of-the-art reasoning, coding, and agentic performance.", + }, "glm-4.7-flash": { maxTokens: 16_384, contextWindow: 200_000, @@ -281,6 +296,21 @@ export const mainlandZAiModels = { description: "GLM-4.7 is Zhipu's latest model with built-in thinking capabilities enabled by default. It provides enhanced reasoning for complex tasks while maintaining fast response times.", }, + "glm-5": { + maxTokens: 16_384, + contextWindow: 202_752, + supportsImages: false, + supportsPromptCache: true, + supportsReasoningEffort: ["disable", "medium"], + reasoningEffort: "medium", + preserveReasoning: true, + inputPrice: 0.29, + outputPrice: 1.14, + cacheWritesPrice: 0, + cacheReadsPrice: 0.057, + description: + "GLM-5 is Zhipu's next-generation model with a 202k context window and built-in thinking capabilities. It delivers state-of-the-art reasoning, coding, and agentic performance.", + }, "glm-4.7-flash": { maxTokens: 16_384, contextWindow: 204_800, diff --git a/src/api/providers/__tests__/zai.spec.ts b/src/api/providers/__tests__/zai.spec.ts index 789915d6eff..7703f31786e 100644 --- a/src/api/providers/__tests__/zai.spec.ts +++ b/src/api/providers/__tests__/zai.spec.ts @@ -121,6 +121,22 @@ describe("ZAiHandler", () => { expect(model.info.preserveReasoning).toBe(true) }) + it("should return GLM-5 international model with thinking support", () => { + const testModelId: InternationalZAiModelId = "glm-5" + const handlerWithModel = new ZAiHandler({ + apiModelId: testModelId, + zaiApiKey: "test-zai-api-key", + zaiApiLine: "international_coding", + }) + const model = handlerWithModel.getModel() + expect(model.id).toBe(testModelId) + expect(model.info).toEqual(internationalZAiModels[testModelId]) + expect(model.info.contextWindow).toBe(202_752) + expect(model.info.supportsReasoningEffort).toEqual(["disable", "medium"]) + expect(model.info.reasoningEffort).toBe("medium") + expect(model.info.preserveReasoning).toBe(true) + }) + it("should return GLM-4.5v international model with vision support", () => { const testModelId: InternationalZAiModelId = "glm-4.5v" const handlerWithModel = new ZAiHandler({ @@ -203,6 +219,22 @@ describe("ZAiHandler", () => { expect(model.info.reasoningEffort).toBe("medium") expect(model.info.preserveReasoning).toBe(true) }) + + it("should return GLM-5 China model with thinking support", () => { + const testModelId: MainlandZAiModelId = "glm-5" + const handlerWithModel = new ZAiHandler({ + apiModelId: testModelId, + zaiApiKey: "test-zai-api-key", + zaiApiLine: "china_coding", + }) + const model = handlerWithModel.getModel() + expect(model.id).toBe(testModelId) + expect(model.info).toEqual(mainlandZAiModels[testModelId]) + expect(model.info.contextWindow).toBe(202_752) + expect(model.info.supportsReasoningEffort).toEqual(["disable", "medium"]) + expect(model.info.reasoningEffort).toBe("medium") + expect(model.info.preserveReasoning).toBe(true) + }) }) describe("International API", () => { @@ -508,6 +540,74 @@ describe("ZAiHandler", () => { }) }) + describe("GLM-5 Thinking Mode", () => { + it("should enable thinking by default for GLM-5 (default reasoningEffort is medium)", async () => { + const handlerWithModel = new ZAiHandler({ + apiModelId: "glm-5", + zaiApiKey: "test-zai-api-key", + zaiApiLine: "international_coding", + }) + + async function* mockFullStream() { + yield { type: "text-delta", text: "response" } + } + + mockStreamText.mockReturnValue({ + fullStream: mockFullStream(), + usage: Promise.resolve({ inputTokens: 0, outputTokens: 0 }), + }) + + const stream = handlerWithModel.createMessage("system prompt", []) + for await (const _chunk of stream) { + // drain + } + + expect(mockStreamText).toHaveBeenCalledWith( + expect.objectContaining({ + providerOptions: { + zhipu: { + thinking: { type: "enabled" }, + }, + }, + }), + ) + }) + + it("should disable thinking for GLM-5 when reasoningEffort is set to disable", async () => { + const handlerWithModel = new ZAiHandler({ + apiModelId: "glm-5", + zaiApiKey: "test-zai-api-key", + zaiApiLine: "international_coding", + enableReasoningEffort: true, + reasoningEffort: "disable", + }) + + async function* mockFullStream() { + yield { type: "text-delta", text: "response" } + } + + mockStreamText.mockReturnValue({ + fullStream: mockFullStream(), + usage: Promise.resolve({ inputTokens: 0, outputTokens: 0 }), + }) + + const stream = handlerWithModel.createMessage("system prompt", []) + for await (const _chunk of stream) { + // drain + } + + expect(mockStreamText).toHaveBeenCalledWith( + expect.objectContaining({ + providerOptions: { + zhipu: { + thinking: { type: "disabled" }, + }, + }, + }), + ) + }) + }) + describe("completePrompt", () => { it("should complete a prompt using generateText", async () => { mockGenerateText.mockResolvedValue({ diff --git a/src/api/providers/zai.ts b/src/api/providers/zai.ts index 033c398fab6..d052de842d7 100644 --- a/src/api/providers/zai.ts +++ b/src/api/providers/zai.ts @@ -115,8 +115,8 @@ export class ZAiHandler extends BaseProvider implements SingleCompletionHandler toolChoice: mapToolChoice(metadata?.tool_choice), } - // GLM-4.7 thinking mode: pass thinking parameter via providerOptions - const isThinkingModel = modelId === "glm-4.7" && Array.isArray(info.supportsReasoningEffort) + // Thinking mode: pass thinking parameter via providerOptions for models that support it (e.g. GLM-4.7, GLM-5) + const isThinkingModel = Array.isArray(info.supportsReasoningEffort) if (isThinkingModel) { const useReasoning = shouldUseReasoningEffort({ model: info, settings: this.options })