fix: codex thinking handling

This commit is contained in:
Ben Vargas 2026-01-05 11:40:44 -07:00 committed by Mario Zechner
parent 22870ae0c2
commit 02b72b49d5
23 changed files with 205 additions and 754 deletions

View file

@ -978,16 +978,12 @@ export class AgentSession {
/**
* Set thinking level.
* Clamps to model capabilities: "off" if no reasoning, "high" if xhigh unsupported.
* Clamps to model capabilities based on available thinking levels.
* Saves to session and settings.
*/
setThinkingLevel(level: ThinkingLevel): void {
let effectiveLevel = level;
if (!this.supportsThinking()) {
effectiveLevel = "off";
} else if (level === "xhigh" && !this.supportsXhighThinking()) {
effectiveLevel = "high";
}
const availableLevels = this.getAvailableThinkingLevels();
const effectiveLevel = availableLevels.includes(level) ? level : this._clampThinkingLevel(level, availableLevels);
this.agent.setThinkingLevel(effectiveLevel);
this.sessionManager.appendThinkingLevelChange(effectiveLevel);
this.settingsManager.setDefaultThinkingLevel(effectiveLevel);
@ -1013,6 +1009,14 @@ export class AgentSession {
* Get available thinking levels for current model.
*/
getAvailableThinkingLevels(): ThinkingLevel[] {
if (!this.supportsThinking()) return ["off"];
const modelLevels = this.model?.thinkingLevels;
if (modelLevels && modelLevels.length > 0) {
const withOff: ThinkingLevel[] = ["off", ...modelLevels];
return THINKING_LEVELS_WITH_XHIGH.filter((level) => withOff.includes(level));
}
return this.supportsXhighThinking() ? THINKING_LEVELS_WITH_XHIGH : THINKING_LEVELS;
}
@ -1030,6 +1034,24 @@ export class AgentSession {
return !!this.model?.reasoning;
}
private _clampThinkingLevel(level: ThinkingLevel, availableLevels: ThinkingLevel[]): ThinkingLevel {
const ordered = THINKING_LEVELS_WITH_XHIGH;
const available = new Set(availableLevels);
const requestedIndex = ordered.indexOf(level);
if (requestedIndex === -1) {
return availableLevels[0] ?? "off";
}
for (let i = requestedIndex; i < ordered.length; i++) {
const candidate = ordered[i];
if (available.has(candidate)) return candidate;
}
for (let i = requestedIndex - 1; i >= 0; i--) {
const candidate = ordered[i];
if (available.has(candidate)) return candidate;
}
return availableLevels[0] ?? "off";
}
// =========================================================================
// Queue Mode Management
// =========================================================================