Files
OmniRoute/open-sse/services/cloudCodeThinking.ts
Rouzbeh† c92bd40b88 perf(proxy): implement non-blocking async proxy log batching and performance optimizations (A, B, C, D) (#11182)
Validated on the combined batch board + this branch: perf-a-b-c-d + account-fallback-service 93/93, gates + typecheck clean. Owner approved the full bundle including item A (async proxy-log batching, 1s/100-item flush with an unref'd timer — reviewed the implementation: flush helper exists for shutdown wiring, buffered logs are the accepted tradeoff). B (lazy modals), C (O(1) alias maps), D (pre-compiled regex — this is also the entire content of #11187, being closed as subsumed) ride along. Conflict with the tip was only stale provider-count docs. Thank you @rqzbeh!
2026-08-23 01:07:32 -03:00

71 lines
2.1 KiB
TypeScript

import { getModelSpec } from "../../src/shared/constants/modelSpecs.ts";
const CLOUD_CODE_REASONING_UNSUPPORTED_PATTERNS = [/^claude-/i, /^gpt-oss-/i, /^tab_/i];
function isRecord(value: unknown): value is Record<string, unknown> {
return !!value && typeof value === "object" && !Array.isArray(value);
}
const PREFIX_TRIM_RE = /^(?:models\/|antigravity\/)+/i;
function normalizeCloudCodeModel(model: string): string {
return String(model || "").trim().replace(PREFIX_TRIM_RE, "");
}
function stripGeminiThinkingConfig(value: unknown): unknown {
if (!isRecord(value)) return value;
if (!("thinkingConfig" in value) && !("thinking_config" in value)) return value;
const next = { ...value };
delete next.thinkingConfig;
delete next.thinking_config;
return next;
}
/**
* @deprecated This function will be removed in v4.0, reasoning configuration processing has migrated to translateRequest
*/
export function shouldStripCloudCodeThinking(provider: string, model: string): boolean {
if (!provider || !model) return false;
const normalizedModel = normalizeCloudCodeModel(model);
if (CLOUD_CODE_REASONING_UNSUPPORTED_PATTERNS.some((pattern) => pattern.test(normalizedModel))) {
return true;
}
const spec = getModelSpec(normalizedModel);
if (typeof spec?.supportsThinking === "boolean") {
return !spec.supportsThinking;
}
return false;
}
/**
* @deprecated This function will be removed in v4.0, reasoning configuration processing has migrated to translateRequest
*/
export function stripCloudCodeThinkingConfig(
body: Record<string, unknown>
): Record<string, unknown> {
const next = { ...body };
delete next.reasoning_effort;
delete next.reasoning;
delete next.thinking;
if ("generationConfig" in next) {
next.generationConfig = stripGeminiThinkingConfig(next.generationConfig);
}
if (isRecord(next.request)) {
const request = { ...next.request };
delete request.reasoning_effort;
delete request.reasoning;
delete request.thinking;
if ("generationConfig" in request) {
request.generationConfig = stripGeminiThinkingConfig(request.generationConfig);
}
next.request = request;
}
return next;
}