This commit is contained in:
decolua
2026-06-15 18:18:04 +07:00
parent 8ab5af0052
commit b282f05549
66 changed files with 2328 additions and 213 deletions

View File

@@ -1,26 +1,50 @@
// Concern: reasoning_effort ↔ provider-native thinking config.
// Each provider expresses "how much to think" differently — centralize the maps here.
// Streaming reasoning delta shape lives in reasoning.js; this file is request-side config only.
// Central source of truth for level↔budget maps (web-standard values).
// Provider-specific application lives in thinkingUnified.js; this file is maps-only.
// OpenAI reasoning_effort → Claude thinking.budget_tokens
const EFFORT_TO_BUDGET = { none: 0, low: 4096, medium: 8192, high: 16384, xhigh: 32768 };
// Discrete effort levels, ordered low→high.
export const EFFORT_LEVELS = ["minimal", "low", "medium", "high", "xhigh", "max"];
// Returns budget_tokens for a reasoning_effort, or undefined if unknown effort.
// 0 means "no thinking" (caller skips enabling); undefined means "effort not recognized".
// 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 EFFORT_TO_BUDGET[String(effort).toLowerCase()];
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" (closest to off).
// Gemini 3 cannot fully disable thinking; "none"/"off" map to "minimal".
export function effortToThinkingLevel(effort) {
const e = String(effort).toLowerCase().trim();
return e === "none" || e === "off" ? "minimal" : e;
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).
// Returns null when budget <= 0 (no reasoning).
export function budgetToEffort(budget) {
if (!budget || budget <= 0) return null;
if (budget <= 2048) return "low";