Files
OmniRoute/open-sse/services/cloudCodeThinking.ts
Randi 293290e12a fix(cloud-code): scope thinking stripping to executor boundaries (#1401)
* fix(cloud-code): scope thinking stripping to executors

* fix(cloud-code): guard antigravity normalized body
2026-04-18 17:15:59 -03:00

45 lines
1.2 KiB
TypeScript

import { supportsReasoning } from "./modelCapabilities.ts";
function isRecord(value: unknown): value is Record<string, unknown> {
return !!value && typeof value === "object" && !Array.isArray(value);
}
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;
}
export function shouldStripCloudCodeThinking(provider: string, model: string): boolean {
if (!provider || !model) return false;
return !supportsReasoning(`${provider}/${model}`);
}
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 };
if ("generationConfig" in request) {
request.generationConfig = stripGeminiThinkingConfig(request.generationConfig);
}
next.request = request;
}
return next;
}