2026-06-06 01:25:12 -04:00
|
|
|
// Some thinking-mode providers (DeepSeek, Kimi, MiniMax, ...) require reasoning_content
|
2026-04-28 22:34:24 -04:00
|
|
|
// 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.
|
2026-06-14 02:15:48 -04:00
|
|
|
import { PROVIDERS } from "../config/providers.js";
|
2026-04-28 22:34:24 -04:00
|
|
|
|
|
|
|
|
const PLACEHOLDER = " ";
|
|
|
|
|
|
2026-06-14 02:15:48 -04:00
|
|
|
// Provider-level rules derive from registry transport.reasoningInject (single source)
|
|
|
|
|
const providerRuleFor = (provider) => PROVIDERS[provider]?.reasoningInject;
|
2026-04-28 22:34:24 -04:00
|
|
|
|
|
|
|
|
// Model-level rules: matched by predicate against model id
|
|
|
|
|
const MODEL_RULES = [
|
# 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 06:48:01 -04:00
|
|
|
{ match: m => /^kimi-/i.test(m || ""), scope: "toolCalls" },
|
|
|
|
|
{ match: m => /deepseek/i.test(m || ""), scope: "all" }
|
2026-04-28 22:34:24 -04:00
|
|
|
];
|
|
|
|
|
|
2026-05-13 23:39:34 -04:00
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2026-04-28 22:34:24 -04:00
|
|
|
function shouldInject(message, scope) {
|
feat: add STT support, Gemini TTS, and expand usage tracking
- Speech-to-Text: full pipeline with sttCore handler, /v1/audio/transcriptions
endpoint, sttConfig for OpenAI, Gemini, Groq, Deepgram, AssemblyAI,
HuggingFace, NVIDIA Parakeet; new 9router-stt skill
- Gemini TTS: add gemini provider with 30 prebuilt voices and TTS_PROVIDER_CONFIG
- Usage: implement GLM (intl/cn) and MiniMax (intl/cn) quota fetchers; refactor
Gemini CLI usage to use retrieveUserQuota with per-model buckets
- Disabled models: lowdb-backed disabledModelsDb + /api/models/disabled route
- Header search: reusable Zustand store (headerSearchStore) wired into Header
- CLI tools: add Claude Cowork tool card and cowork-settings API
- Providers: introduce mediaPriority sorting in getProvidersByKind, add
Kimi K2.6, reorder hermes, drop qwen STT kind
- UI: expand media-providers/[kind]/[id] page (+314), enhance OAuthModal,
ModelSelectModal, ProviderTopology, ProxyPools, ProviderLimits
- Assets: refresh provider PNGs (alicode, byteplus, cloudflare-ai, nvidia,
ollama, vertex, volcengine-ark) and add aws-polly, fal-ai, jina-ai, recraft,
runwayml, stability-ai, topaz, black-forest-labs
2026-05-04 23:32:59 -04:00
|
|
|
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;
|
2026-04-28 22:34:24 -04:00
|
|
|
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 };
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-13 23:39:34 -04:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-28 22:34:24 -04:00
|
|
|
export function injectReasoningContent({ provider, model, body }) {
|
2026-06-14 02:15:48 -04:00
|
|
|
const providerRule = providerRuleFor(provider);
|
2026-04-28 22:34:24 -04:00
|
|
|
const modelRule = MODEL_RULES.find(r => r.match(model));
|
|
|
|
|
const rule = providerRule || modelRule;
|
2026-05-13 23:39:34 -04:00
|
|
|
const nextBody = applyDeepSeekV4ProAlias({ provider, model, body });
|
|
|
|
|
return applyRule(nextBody, rule);
|
2026-04-28 22:34:24 -04:00
|
|
|
}
|