Files
alan 06001697c8 Add per-chat thinking levels for Codex, Claude Code and OpenCode
Codex: model/list supportedReasoningEfforts per model, turn/start effort,
thread reasoningEffort as the current level. Claude Code: initialize
supportedEffortLevels, apply_flag_settings effortLevel at the next turn
start. OpenCode v2: model variants via the session model endpoint.
chat_effort sets a level; rows and chat_models carry the levels; Codex and
Claude levels persist in operator_sessions.chat_effort and are re-applied
before every turn.
2026-11-09 20:07:41 +00:00

60 lines
1.6 KiB
Go

package codex
import (
"context"
"errors"
"strings"
"git.a-wan.net/alan/pipelines/internal/protocol"
)
// Efforts reports the reasoning efforts model/list advertises for the row's
// model (session.Model, already the saved next-turn model) and its default.
// A model the catalog does not list, or one without efforts, has none.
func (c *Chat) Efforts(ctx context.Context, session protocol.ChatSession) ([]protocol.ChatEffort, string, error) {
model := strings.TrimSpace(session.Model)
if model == "" {
return nil, "", nil
}
catalog, err := c.catalog(ctx)
if err != nil {
return nil, "", err
}
for _, entry := range catalog {
if entry.ID == model {
return append([]protocol.ChatEffort(nil), entry.Efforts...), entry.DefaultEffort, nil
}
}
return nil, "", nil
}
// SetEffort records the thread's reasoning effort; it is sent as turn/start's
// effort, which Codex keeps for the thread's later turns too. "" sends none.
// The server has validated the level against the model's catalog entry.
func (c *Chat) SetEffort(_ context.Context, id, effort string) error {
if strings.TrimSpace(id) == "" {
return errors.New("a Codex thread id is required")
}
c.mu.Lock()
defer c.mu.Unlock()
if c.efforts == nil {
c.efforts = map[string]string{}
}
if effort == "" {
delete(c.efforts, id)
return nil
}
c.efforts[id] = effort
return nil
}
// applyEffort adds the thread's chosen effort to turn/start params.
func (c *Chat) applyEffort(id string, params map[string]any) {
c.mu.Lock()
effort := c.efforts[id]
c.mu.Unlock()
if effort != "" {
params["effort"] = effort
}
}