mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-31 04:12:10 +03:00
* fix(combo): strip boolean reasoning field for opencode-go providers opencode-go backed providers (ollama-cloud, opencode-go, opencode, opencode-zen) use a Go ChatCompletionRequest struct where the reasoning field is typed as openai.Reasoning (a structured type). When a client sends reasoning: true or reasoning: false — valid per the OpenAI API — the Go JSON decoder rejects it with: 400: json: cannot unmarshal bool into Go struct field ChatCompletionRequest.reasoning of type openai.Reasoning This strips the boolean reasoning field before forwarding to these providers, allowing the upstream to apply its own default reasoning behavior. Object/string forms are left untouched. Observed in production: 3 consecutive 400 errors from ollama-cloud/glm-5.2 in a 30-second window, each with the unmarshal error. * fix(opencode): add null/primitive guard in stripBooleanReasoning Adds defensive check for null, undefined, and non-object inputs as suggested in review. Added unit test coverage for these edge cases.
47 lines
1.9 KiB
TypeScript
47 lines
1.9 KiB
TypeScript
type JsonRecord = Record<string, unknown>;
|
|
|
|
/**
|
|
* Strip boolean `reasoning` for opencode-go based providers.
|
|
*
|
|
* Providers backed by the opencode-go backend (ollama-cloud, opencode-go,
|
|
* opencode, opencode-zen) use a Go ChatCompletionRequest struct where the
|
|
* `reasoning` field is typed as `openai.Reasoning` (a structured type, not
|
|
* a bool). When a client sends `reasoning: true` or `reasoning: false` —
|
|
* which is valid per the OpenAI API for enabling/disabling reasoning — the
|
|
* Go JSON decoder rejects it with:
|
|
*
|
|
* 400: json: cannot unmarshal bool into Go struct field
|
|
* ChatCompletionRequest.reasoning of type openai.Reasoning
|
|
*
|
|
* This strips the boolean `reasoning` field from the request body before it
|
|
* is forwarded to these providers, allowing the upstream to apply its own
|
|
* default reasoning behavior. If `reasoning` is already an object/string
|
|
* (matching the Go struct), it is left untouched.
|
|
*
|
|
* Related: services/mimoThinking.ts uses the same pattern for Xiaomi MiMo.
|
|
*/
|
|
|
|
const OPENCODE_GO_PROVIDERS = new Set(["ollama-cloud", "opencode-go", "opencode", "opencode-zen"]);
|
|
|
|
/** True when the provider is backed by the opencode-go backend. */
|
|
export function isOpencodeGoProvider(provider: string): boolean {
|
|
return OPENCODE_GO_PROVIDERS.has(provider);
|
|
}
|
|
|
|
/**
|
|
* Remove a boolean `reasoning` field from the request body.
|
|
* Returns the same object reference if no change is needed, or a shallow
|
|
* clone with the field removed.
|
|
*/
|
|
export function stripBooleanReasoning(body: JsonRecord): JsonRecord {
|
|
if (!body || typeof body !== "object") return body;
|
|
if (!("reasoning" in body)) return body;
|
|
const reasoning = body.reasoning;
|
|
// Only strip when reasoning is a boolean — object/string forms are valid
|
|
// for the Go struct and should be forwarded as-is.
|
|
if (typeof reasoning !== "boolean") return body;
|
|
const next = { ...body };
|
|
delete next.reasoning;
|
|
return next;
|
|
}
|