Files
OmniRoute/open-sse/services/qwenThinking.ts
diegosouzapw 48467bc514 feat(core): add db health checks and provider interoperability
Add automated SQLite health diagnostics with optional auto-repair,
startup and scheduled execution, authenticated API routes, an MCP tool,
and dashboard visibility for status and repair actions.

Improve provider compatibility by adding Cursor usage fetching and
v3.1.0 parity headers, introducing a per-connection Codex Responses
store opt-in with session fallback, fixing Codex non-stream combo and
SSE translation behavior, sanitizing Gemini googleSearch tool payloads
and Qwen thinking tool_choice handling, and hardening cleanup and call
log storage paths.
2026-04-13 13:11:30 -03:00

45 lines
1.1 KiB
TypeScript

type JsonRecord = Record<string, unknown>;
export function isQwenThinkingActive(body: JsonRecord): boolean {
const thinking = body.thinking;
if (thinking === true || body.enable_thinking === true) {
return true;
}
return (
typeof thinking === "object" &&
thinking !== null &&
!Array.isArray(thinking) &&
(thinking as JsonRecord).type === "enabled"
);
}
export function isQwenThinkingToolChoiceIncompatible(toolChoice: unknown): boolean {
return toolChoice === "required" || (typeof toolChoice === "object" && toolChoice !== null);
}
export function sanitizeQwenThinkingToolChoice(
body: JsonRecord,
providerLabel = "Qwen"
): JsonRecord {
if (!isQwenThinkingActive(body)) {
return body;
}
const toolChoice = body.tool_choice;
if (!isQwenThinkingToolChoiceIncompatible(toolChoice)) {
return body;
}
const toolChoiceLabel = typeof toolChoice === "string" ? toolChoice : "object";
console.warn(
`[${providerLabel}] Neutralizing incompatible tool_choice ${toolChoiceLabel} to "auto" (thinking mode active)`
);
return {
...body,
tool_choice: "auto",
};
}