Files
OmniRoute/open-sse/utils/reasoningRuleContext.ts
Jan Leon f1e7148c19 fix(routing): preserve reasoning overrides across transports and fallbacks (#13556)
Merged. The failure mode was concrete — a matched reasoning rule dropped on native Responses/Anthropic paths, model-suffix/account defaults, or fallback preparation, and `_omnirouteReasoningRule` leaking upstream as `Unsupported parameter` — and the fix is carried in the request-local credential context through dispatch, refreshed credentials and fallbacks, with forced effort winning over defaults and client-forged markers dropped at ingress. The 11-case integration suite exercises the real routing/translation modules.

Validated as a combined board first (this PR merged with the 4 siblings of the JxnLexn wave on the release tip): eslint with the frozen suppressions, typecheck:core, check:open-sse-typecheck, complexity, cognitive-complexity, changelog-integrity, docs-sync, migration-numbering, provider-consistency and a duplicate-identifier audit all green, plus 77 passing / 0 failing focused node:test cases across the test files the wave touches. The wave's i18n fill (new keys carried to all 66 locales), free-tier doc counts and file-size rebaseline land in one follow-up PR right after the wave, as with #13904.

Thank you — and for keeping this a runtime-only change with the editor and service-tier work in their own PRs.
2026-09-16 17:01:51 -03:00

29 lines
1.0 KiB
TypeScript

// Request-local execution metadata, not a provider credential or a wire field.
// Symbol keys survive credential object spreads but cannot be supplied through JSON.
const FORCED_EFFORT = Symbol.for("omniroute.forcedReasoningEffort");
const EFFORTS = new Set(["none", "low", "medium", "high", "xhigh", "max", "ultra"]);
export function withReasoningRuleContext<T>(credentials: T, directive: unknown): T {
if (
!credentials ||
typeof credentials !== "object" ||
!directive ||
typeof directive !== "object"
)
return credentials;
const rule = directive as Record<string, unknown>;
if (
!rule.id ||
rule.effortMode !== "force" ||
typeof rule.targetEffort !== "string" ||
!EFFORTS.has(rule.targetEffort)
)
return credentials;
return { ...credentials, [FORCED_EFFORT]: rule.targetEffort };
}
export function getForcedReasoningEffort(credentials: unknown): string | undefined {
if (!credentials || typeof credentials !== "object") return undefined;
return (credentials as { [FORCED_EFFORT]?: string })[FORCED_EFFORT];
}