Skip to content

Commit 22cc758

Browse files
feat(opencode): expose High/Max thinking variants for GLM-5.2 (anomalyco#32446)
Co-authored-by: Aiden Cline <aidenpcline@gmail.com>
1 parent 0b7ec51 commit 22cc758

2 files changed

Lines changed: 119 additions & 1 deletion

File tree

packages/opencode/src/provider/transform.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,9 @@ export function variants(model: Provider.Model): Record<string, Record<string, a
666666
if (!model.capabilities.reasoning) return {}
667667

668668
const id = model.id.toLowerCase()
669+
const glm52 = ["glm-5.2", "glm-5-2", "glm-5p2"].some(
670+
(name) => id.includes(name) || model.api.id.toLowerCase().includes(name),
671+
)
669672
if (
670673
model.api.id.toLowerCase().includes("minimax-m3") &&
671674
["@ai-sdk/anthropic", "@ai-sdk/openai-compatible"].includes(model.api.npm)
@@ -677,13 +680,32 @@ export function variants(model: Provider.Model): Record<string, Record<string, a
677680
}
678681
const adaptiveThinkingOmitted = anthropicOmitsThinking(model.api.id)
679682
const adaptiveEfforts = anthropicAdaptiveEfforts(model.api.id)
683+
if (glm52 && model.api.npm === "@openrouter/ai-sdk-provider") {
684+
// OpenRouter maps xhigh to GLM-5.2's native max effort.
685+
return {
686+
high: { reasoning: { effort: "high" } },
687+
xhigh: { reasoning: { effort: "xhigh" } },
688+
}
689+
}
690+
if (glm52 && model.api.npm === "@ai-sdk/openai-compatible") {
691+
return {
692+
high: { reasoningEffort: "high" },
693+
max: { reasoningEffort: "max" },
694+
}
695+
}
696+
if (glm52 && model.api.npm === "@ai-sdk/anthropic") {
697+
return {
698+
high: { effort: "high" },
699+
max: { effort: "max" },
700+
}
701+
}
680702
if (
681703
id.includes("deepseek-chat") ||
682704
id.includes("deepseek-reasoner") ||
683705
id.includes("deepseek-r1") ||
684706
id.includes("deepseek-v3") ||
685707
id.includes("minimax") ||
686-
id.includes("glm") ||
708+
(id.includes("glm") && !glm52) ||
687709
id.includes("kimi") ||
688710
id.includes("k2p") ||
689711
id.includes("qwen") ||

packages/opencode/test/provider/transform.test.ts

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2895,6 +2895,102 @@ describe("ProviderTransform.variants", () => {
28952895
expect(result).toEqual({})
28962896
})
28972897

2898+
test("glm-5.2 returns native effort variants for openai-compatible providers", () => {
2899+
const model = createMockModel({
2900+
id: "zhipuai/glm-5.2",
2901+
providerID: "zhipuai",
2902+
api: {
2903+
id: "glm-5.2",
2904+
url: "https://open.bigmodel.cn/api/paas/v4",
2905+
npm: "@ai-sdk/openai-compatible",
2906+
},
2907+
})
2908+
expect(ProviderTransform.variants(model)).toEqual({
2909+
high: { reasoningEffort: "high" },
2910+
max: { reasoningEffort: "max" },
2911+
})
2912+
})
2913+
2914+
test("recognizes GLM-5.2 provider model IDs", () => {
2915+
for (const id of ["accounts/fireworks/models/glm-5p2", "zai-org-glm-5-2", "umans-glm-5.2"]) {
2916+
const model = createMockModel({
2917+
id: `test/${id}`,
2918+
api: {
2919+
id,
2920+
url: "https://api.test.com",
2921+
npm: "@ai-sdk/openai-compatible",
2922+
},
2923+
})
2924+
expect(ProviderTransform.variants(model)).toEqual({
2925+
high: { reasoningEffort: "high" },
2926+
max: { reasoningEffort: "max" },
2927+
})
2928+
}
2929+
})
2930+
2931+
test("recognizes GLM-5.2 from the API ID when the configured model ID is an alias", () => {
2932+
const model = createMockModel({
2933+
id: "custom/my-glm",
2934+
api: {
2935+
id: "accounts/fireworks/models/glm-5p2",
2936+
url: "https://api.fireworks.ai/inference/v1",
2937+
npm: "@ai-sdk/openai-compatible",
2938+
},
2939+
})
2940+
expect(ProviderTransform.variants(model)).toEqual({
2941+
high: { reasoningEffort: "high" },
2942+
max: { reasoningEffort: "max" },
2943+
})
2944+
})
2945+
2946+
test("glm-5.2 returns openrouter effort variants for openrouter", () => {
2947+
const model = createMockModel({
2948+
id: "openrouter/z-ai/glm-5.2",
2949+
providerID: "openrouter",
2950+
api: {
2951+
id: "z-ai/glm-5.2",
2952+
url: "https://openrouter.ai/api/v1",
2953+
npm: "@openrouter/ai-sdk-provider",
2954+
},
2955+
})
2956+
expect(ProviderTransform.variants(model)).toEqual({
2957+
high: { reasoning: { effort: "high" } },
2958+
xhigh: { reasoning: { effort: "xhigh" } },
2959+
})
2960+
})
2961+
2962+
test("glm-5.2 returns effort variants for anthropic-compatible providers", () => {
2963+
const model = createMockModel({
2964+
id: "zai-coding-plan/glm-5.2",
2965+
providerID: "zai-coding-plan",
2966+
api: {
2967+
id: "glm-5.2",
2968+
url: "https://api.z.ai/api/anthropic",
2969+
npm: "@ai-sdk/anthropic",
2970+
},
2971+
})
2972+
expect(ProviderTransform.variants(model)).toEqual({
2973+
high: { effort: "high" },
2974+
max: { effort: "max" },
2975+
})
2976+
})
2977+
2978+
test("glm-5.2 falls back to provider defaults for other packages", () => {
2979+
const model = createMockModel({
2980+
id: "test/glm-5.2",
2981+
api: {
2982+
id: "glm-5.2",
2983+
url: "https://api.test.com",
2984+
npm: "@ai-sdk/amazon-bedrock",
2985+
},
2986+
})
2987+
expect(ProviderTransform.variants(model)).toEqual({
2988+
low: { reasoningConfig: { type: "enabled", maxReasoningEffort: "low" } },
2989+
medium: { reasoningConfig: { type: "enabled", maxReasoningEffort: "medium" } },
2990+
high: { reasoningConfig: { type: "enabled", maxReasoningEffort: "high" } },
2991+
})
2992+
})
2993+
28982994
test("mistral models with reasoning support return variants", () => {
28992995
const model = createMockModel({
29002996
id: "mistral/mistral-small-latest",

0 commit comments

Comments
 (0)