import { REASONING_EFFORTS, type ReasoningEffort } from '../config/reasoningEffort.js'; /** * `/effort [档位|auto]` 的纯解析(可单测)。只改当前 Session 的运行时 provider, * 与 `/model` 同语义:不写回 config.json,进程重启后恢复配置里的值。 * * - `/effort` → 显示当前档位与可选项 * - `/effort high` → 切到该档位 * - `/effort auto` → 不再发送该参数,沿用服务端对该模型的默认强度(也认 default / unset / off 以外的别名见下) * * 档位取值是各家文档出现过的并集,具体某个模型接不接受由服务端裁决:被拒绝时 client.ts * 会去掉参数重发并告警,所以这里不替用户猜"这个模型支持哪几档"。 */ export type EffortCommand = | { matched: false } | { matched: true; action: 'show' } | { matched: true; action: 'set'; effort: ReasoningEffort | null } | { matched: true; action: 'invalid'; input: string }; const CLEAR_WORDS = new Set(['auto', 'default', 'unset', 'reset']); export function parseEffortCommand(input: string): EffortCommand { const match = /^\/effort(?:\s+(\S+))?\s*$/i.exec(input.trim()); if (!match) return { matched: false }; const arg = match[1]?.toLowerCase(); if (!arg) return { matched: true, action: 'show' }; if (CLEAR_WORDS.has(arg)) return { matched: true, action: 'set', effort: null }; if ((REASONING_EFFORTS as readonly string[]).includes(arg)) { return { matched: true, action: 'set', effort: arg as ReasoningEffort }; } return { matched: true, action: 'invalid', input: arg }; } export function effortChoicesText(): string { return `${REASONING_EFFORTS.join(' / ')} / auto`; }