File size: 2,202 Bytes
cd8bd0a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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);
}

function normalizeCloudCodeModel(model: string): string {
  return String(model || "")
    .trim()
    .replace(/^models\//i, "")
    .replace(/^(?:antigravity|gemini-cli)\//i, "");
}

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;
}