Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors
TypeScript a2aai-agentsai-gatewayanthropicclaudeclaude-codeclinecodexcopilotcursordeepseekfree-aigeminikimillm-gatewaymcpopenaiopenai-proxyqwentoken-saver
import { sharedSymbol } from "@/shared/utils/processSingleton";
// 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 = sharedSymbol("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];
}