Files
9router/open-sse/utils/reasoningContentInjector.js
decolua e9ae21a723 # v0.4.66 (2026-05-29)
## Features
- Add Qoder provider: device-flow OAuth, COSY signing, WAF-bypass body encoding, live model catalog, dashboard quota tracker, 11 models (#1372)
- Add new models: Claude Opus 4.8 (Claude Code), GPT 5.4 Mini (Codex)

## Fixes
- DeepSeek thinking mode: echo `reasoning_content` back on follow-up/tool-call turns so OpenCode-free and custom providers no longer 400 with "reasoning_content must be passed back" (#1543)
- Reasoning injector: match deepseek/kimi model ids case-insensitively (covers custom providers using capitalized model names)
- OpenCode suggested-models: include free models without the `-free` suffix, e.g. `big-pickle` (#1535)

## Improvements
- Codex: trim sunset models, keep gpt-5.5 / gpt-5.4 / gpt-5.3-codex family, add gpt-5.4-mini
- volcengine-ark: refresh model list (add DeepSeek-V4-Flash/Pro, drop EOL entries)
- Lower stream stall timeout 35s → 30s for faster hang detection
2026-05-29 17:48:01 +07:00

78 lines
2.2 KiB
JavaScript

// Some thinking-mode providers (DeepSeek, Kimi, ...) require reasoning_content
// to be echoed back on assistant messages. Clients in OpenAI format don't send it,
// so we inject a non-empty placeholder to satisfy upstream validation.
const PLACEHOLDER = " ";
// Provider-level rules: keyed by executor.provider
const PROVIDER_RULES = {
deepseek: { scope: "all" }
};
// Model-level rules: matched by predicate against model id
const MODEL_RULES = [
{ match: m => /^kimi-/i.test(m || ""), scope: "toolCalls" },
{ match: m => /deepseek/i.test(m || ""), scope: "all" }
];
const DEEPSEEK_V4_PRO = "deepseek-v4-pro";
const DEEPSEEK_V4_PRO_ALIASES = {
[`${DEEPSEEK_V4_PRO}-max`]: {
thinkingType: "enabled",
reasoningEffort: "max"
},
[`${DEEPSEEK_V4_PRO}-none`]: {
thinkingType: "disabled",
reasoningEffort: null
}
};
function shouldInject(message, scope) {
if (message?.role !== "assistant") return false;
const rc = message.reasoning_content;
if (typeof rc === "string" && rc.length > 0) return false;
if (scope === "toolCalls") return Array.isArray(message.tool_calls) && message.tool_calls.length > 0;
return true;
}
function applyRule(body, rule) {
if (!rule || !body?.messages) return body;
const messages = body.messages.map(m =>
shouldInject(m, rule.scope) ? { ...m, reasoning_content: PLACEHOLDER } : m
);
return { ...body, messages };
}
function applyDeepSeekV4ProAlias({ provider, model, body }) {
const alias = DEEPSEEK_V4_PRO_ALIASES[model];
if (provider !== "deepseek" || !alias || !body) return body;
const nextBody = {
...body,
model: DEEPSEEK_V4_PRO,
extra_body: {
...(body.extra_body || {}),
thinking: {
...(body.extra_body?.thinking || {}),
type: alias.thinkingType
}
}
};
if (alias.reasoningEffort) {
nextBody.reasoning_effort = alias.reasoningEffort;
} else {
delete nextBody.reasoning_effort;
}
return nextBody;
}
export function injectReasoningContent({ provider, model, body }) {
const providerRule = PROVIDER_RULES[provider];
const modelRule = MODEL_RULES.find(r => r.match(model));
const rule = providerRule || modelRule;
const nextBody = applyDeepSeekV4ProAlias({ provider, model, body });
return applyRule(nextBody, rule);
}