Spaces:
Running
Running
| /** | |
| * OpenAI reasoning_effort to Cloud Code thinking configuration. | |
| * Ported from llm-proxy-rotate AntigravityProvider._get_thinking_config(). | |
| */ | |
| export const VALID_REASONING_EFFORTS = new Set([ | |
| 'auto', | |
| 'disable', | |
| 'off', | |
| 'none', | |
| 'minimal', | |
| 'low', | |
| 'low_medium', | |
| 'medium', | |
| 'medium_high', | |
| 'high' | |
| ]); | |
| export function normalizeReasoningEffort(value) { | |
| if (value === undefined || value === null) return 'auto'; | |
| if (typeof value !== 'string') return 'auto'; | |
| const normalized = value.trim().toLowerCase() || 'auto'; | |
| return VALID_REASONING_EFFORTS.has(normalized) ? normalized : 'auto'; | |
| } | |
| /** Pro tier is encoded in SKU names like gemini-3.1-pro-high / gemini-3.1-pro-low. */ | |
| export function isGeminiProTierSku(modelName) { | |
| return /gemini-3(?:\.\d+)?-pro-(?:high|low)$/i.test(String(modelName || '')); | |
| } | |
| export function getReasoningThinkingConfig(modelName, reasoningEffort) { | |
| const model = String(modelName || '').toLowerCase(); | |
| const effort = normalizeReasoningEffort(reasoningEffort); | |
| // Tier SKUs already encode thinking level; extra thinkingConfig causes INVALID_ARGUMENT. | |
| if (isGeminiProTierSku(model)) { | |
| return null; | |
| } | |
| const isGemini3Flash = /gemini-3(?:\.\d+)?-[^/]*flash/.test(model); | |
| const isGemini3Pro = /gemini-3(?:\.\d+)?-[^/]*pro/.test(model); | |
| const isGemini25 = model.includes('gemini-2.5'); | |
| const isClaude = model.includes('claude'); | |
| if (!isGemini3Flash && !isGemini3Pro && !isGemini25 && !isClaude) { | |
| return null; | |
| } | |
| if (isGemini3Flash) { | |
| let thinkingLevel = 'high'; | |
| if (['disable', 'off', 'none'].includes(effort)) { | |
| thinkingLevel = 'minimal'; | |
| } else if (['minimal', 'low'].includes(effort)) { | |
| thinkingLevel = 'low'; | |
| } else if (['low_medium', 'medium'].includes(effort)) { | |
| thinkingLevel = 'medium'; | |
| } | |
| return { | |
| effort, | |
| mode: 'level', | |
| config: { | |
| includeThoughts: true, | |
| thinkingLevel | |
| } | |
| }; | |
| } | |
| if (isGemini3Pro) { | |
| const thinkingLevel = [ | |
| 'disable', 'off', 'none', 'minimal', 'low', 'low_medium' | |
| ].includes(effort) ? 'low' : 'high'; | |
| return { | |
| effort, | |
| mode: 'level', | |
| config: { | |
| includeThoughts: true, | |
| thinkingLevel | |
| } | |
| }; | |
| } | |
| if (['disable', 'off', 'none'].includes(effort)) { | |
| return { | |
| effort, | |
| mode: 'budget', | |
| config: isClaude | |
| ? { include_thoughts: false, thinking_budget: 0 } | |
| : { includeThoughts: false, thinkingBudget: 0 } | |
| }; | |
| } | |
| if (effort === 'auto') { | |
| return { | |
| effort, | |
| mode: 'budget', | |
| config: isClaude | |
| ? { include_thoughts: true, thinking_budget: -1 } | |
| : { includeThoughts: true, thinkingBudget: -1 } | |
| }; | |
| } | |
| const budgets = model.includes('gemini-2.5-flash') | |
| ? { | |
| minimal: 3072, | |
| low: 6144, | |
| low_medium: 9216, | |
| medium: 12288, | |
| medium_high: 18432, | |
| high: 24576 | |
| } | |
| : { | |
| minimal: 4096, | |
| low: 8192, | |
| low_medium: 12288, | |
| medium: 16384, | |
| medium_high: 24576, | |
| high: isClaude ? 31999 : 32768 | |
| }; | |
| return { | |
| effort, | |
| mode: 'budget', | |
| config: isClaude | |
| ? { include_thoughts: true, thinking_budget: budgets[effort] } | |
| : { includeThoughts: true, thinkingBudget: budgets[effort] } | |
| }; | |
| } | |