From 99c0460846588d7b6f5c4a17b4d63be4264afff5 Mon Sep 17 00:00:00 2001 From: dreama <96614355+DreamFate@users.noreply.github.com> Date: Mon, 17 Aug 2026 19:06:23 +0800 Subject: [PATCH] feat(reasoning): expose GLM-5.3 thinking effort levels GLM-5.3 endpoints now accept effort levels (verified 2026-08-17): - /api/anthropic: adaptive thinking effort low/medium/high/max - /api/v1 (OpenAI Responses): all five levels natively - /api/paas/v4: reasoning_effort low/high/max (medium degrades to high) Replace the off/high-only toggle with a full profile following the GLM-5.2 template: adaptive-effort (anthropic), zai-thinking-effort (openai-completions) and openai-reasoning-effort (openai-responses). Drop the now-unused zai-toggle and anthropic-manual encodings. --- .../main/lib/adapters/pi-model-registry.ts | 12 ----- .../shared/src/types/reasoning-profile.ts | 45 ++++++++++++++----- 2 files changed, 33 insertions(+), 24 deletions(-) diff --git a/apps/electron/src/main/lib/adapters/pi-model-registry.ts b/apps/electron/src/main/lib/adapters/pi-model-registry.ts index f82cc3e33..161f2f292 100644 --- a/apps/electron/src/main/lib/adapters/pi-model-registry.ts +++ b/apps/electron/src/main/lib/adapters/pi-model-registry.ts @@ -122,18 +122,6 @@ function compilePiReasoningCapabilities( }, thinkingLevelMap, } - case 'zai-toggle': - return { - compat: { - supportsDeveloperRole: false, - supportsReasoningEffort: false, - thinkingFormat: 'zai', - zaiToolStream: true, - }, - thinkingLevelMap, - } - case 'anthropic-manual': - return { thinkingLevelMap } } } diff --git a/packages/shared/src/types/reasoning-profile.ts b/packages/shared/src/types/reasoning-profile.ts index 2fb584d44..f23d80dfe 100644 --- a/packages/shared/src/types/reasoning-profile.ts +++ b/packages/shared/src/types/reasoning-profile.ts @@ -40,8 +40,6 @@ export type ReasoningEncodingKind = | 'deepseek-output-effort' | 'openai-reasoning-effort' | 'zai-thinking-effort' - | 'zai-toggle' - | 'anthropic-manual' /** 每个产品等级映射为目标协议可接受的 effort 值。 */ export type ReasoningEffortMap = Partial> @@ -89,14 +87,33 @@ export interface ResolveReasoningProfileInput { const DEEPSEEK_V4_LEVELS = ['off', 'low', 'high', 'xhigh', 'max'] as const satisfies readonly AgentThinkingLevel[] const K3_LEVELS = ['off', 'low', 'high', 'max'] as const satisfies readonly AgentThinkingLevel[] const GLM_52_LEVELS = ['off', 'high', 'max'] as const satisfies readonly AgentThinkingLevel[] -const GLM_53_LEVELS = ['off', 'high'] as const satisfies readonly AgentThinkingLevel[] -/** GLM-5.3 官方端点只支持思考开关,不接受 reasoning_effort;其余档位必须从 UI 隐藏。 */ -const GLM_53_THINKING_LEVEL_MAP: ReasoningEffortMap = { +const GLM_53_LEVELS = ['off', 'low', 'medium', 'high', 'max'] as const satisfies readonly AgentThinkingLevel[] +// Verified against open.bigmodel.cn 2026-08-17: /api/anthropic accepts adaptive +// effort low/medium/high/max; /api/v1 (OpenAI Responses) accepts all five natively; +// /api/paas/v4 only accepts low/high/max, so medium degrades to high there. +const GLM_53_ANTHROPIC_EFFORT_MAP: ReasoningEffortMap = { minimal: null, - low: null, - medium: null, - xhigh: null, - max: null, + low: 'low', + medium: 'medium', + high: 'high', + xhigh: 'max', + max: 'max', +} +const GLM_53_OPENAI_EFFORT_MAP: ReasoningEffortMap = { + minimal: null, + low: 'low', + medium: 'high', + high: 'high', + xhigh: 'max', + max: 'max', +} +const GLM_53_RESPONSES_EFFORT_MAP: ReasoningEffortMap = { + minimal: 'minimal', + low: 'low', + medium: 'medium', + high: 'high', + xhigh: 'max', + max: 'max', } const OPENAI_STANDARD_LEVELS = ['off', 'low', 'medium', 'high', 'xhigh'] as const satisfies readonly AgentThinkingLevel[] const OPENAI_MAX_LEVELS = [...OPENAI_STANDARD_LEVELS, 'max'] as const satisfies readonly AgentThinkingLevel[] @@ -203,7 +220,10 @@ function normalizeGlm52Level(level: AgentThinkingLevel | undefined): AgentThinki } function normalizeGlm53Level(level: AgentThinkingLevel | undefined): AgentThinkingLevel { - return level === 'off' ? 'off' : 'high' + if (level === 'off') return 'off' + if (level === 'xhigh' || level === 'max') return 'max' + if (level === 'minimal') return 'low' + return level ?? 'high' } function normalizeOpenAIStandardLevel(level: AgentThinkingLevel | undefined): AgentThinkingLevel { @@ -255,8 +275,9 @@ const GLM_53_PROFILE: ReasoningProfile = { defaultLevel: 'high', normalize: normalizeGlm53Level, encodings: { - 'anthropic-messages': { kind: 'anthropic-manual', effortMap: GLM_53_THINKING_LEVEL_MAP }, - 'openai-completions': { kind: 'zai-toggle', effortMap: GLM_53_THINKING_LEVEL_MAP }, + 'anthropic-messages': { kind: 'adaptive-effort', effortMap: GLM_53_ANTHROPIC_EFFORT_MAP }, + 'openai-completions': { kind: 'zai-thinking-effort', effortMap: GLM_53_OPENAI_EFFORT_MAP }, + 'openai-responses': { kind: 'openai-reasoning-effort', effortMap: GLM_53_RESPONSES_EFFORT_MAP }, }, }