Files
9router/open-sse/translator/concerns/thinking.js
T
2026-06-15 18:18:04 +07:00

54 lines
1.8 KiB
JavaScript

// Concern: reasoning_effort ↔ provider-native thinking config.
// Central source of truth for level↔budget maps (web-standard values).
// Provider-specific application lives in thinkingUnified.js; this file is maps-only.
// Discrete effort levels, ordered low→high.
export const EFFORT_LEVELS = ["minimal", "low", "medium", "high", "xhigh", "max"];
// Web-standard level → budget_tokens (Anthropic/Gemini docs).
export const LEVEL_TO_BUDGET = {
none: 0,
minimal: 512,
low: 1024,
medium: 8192,
high: 24576,
xhigh: 32768,
max: 128000,
};
// Returns budget_tokens for an effort level, or undefined if unknown.
// 0 means "no thinking"; undefined means "effort not recognized".
export function effortToBudget(effort) {
if (!effort) return undefined;
return LEVEL_TO_BUDGET[String(effort).toLowerCase()];
}
// OpenAI reasoning_effort → Gemini thinkingLevel (gemini-3 enum: minimal|low|medium|high).
// Gemini 3 cannot fully disable thinking; "none"/"off" map to "minimal".
export function effortToThinkingLevel(effort) {
const e = String(effort).toLowerCase().trim();
if (e === "none" || e === "off") return "minimal";
if (e === "xhigh" || e === "max") return "high";
return e;
}
// Numeric budget → nearest discrete level (reverse map via thresholds).
// Returns null when budget <= 0 (no reasoning).
export function budgetToLevel(budget) {
const b = Number(budget);
if (!b || b <= 0) return null;
if (b <= 768) return "minimal";
if (b <= 4096) return "low";
if (b <= 16384) return "medium";
if (b <= 28672) return "high";
return "xhigh";
}
// Gemini thinkingBudget (numeric) → OpenAI reasoning_effort (antigravity reverse map).
export function budgetToEffort(budget) {
if (!budget || budget <= 0) return null;
if (budget <= 2048) return "low";
if (budget <= 16384) return "medium";
return "high";
}