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.
This commit is contained in:
2026-11-09 20:07:41 +00:00
parent 8ca5a1fdda
commit 06001697c8
25 changed files with 1306 additions and 23 deletions
+17 -1
View File
@@ -49,6 +49,10 @@ type Chat struct {
agents map[string]string
modelMu sync.Mutex
sessionModels map[string]sessionModelCache
// catalog caches /api/model for thinking levels (efforts.go).
catalogMu sync.Mutex
catalog []protocol.ChatModel
catalogAt time.Time
}
// NewChat brokers chat for one owned OpenCode endpoint. The connection must be
@@ -182,6 +186,9 @@ func (c *Chat) Models(ctx context.Context, _ string) ([]protocol.ChatModel, erro
Name string `json:"name"`
Enabled bool `json:"enabled"`
Status string `json:"status"`
Variants []struct {
ID string `json:"id"`
} `json:"variants"`
} `json:"data"`
}
if err := json.Unmarshal(data, &envelope); err != nil {
@@ -204,7 +211,13 @@ func (c *Chat) Models(ctx context.Context, _ string) ([]protocol.ChatModel, erro
if name == "" {
name = id
}
models = append(models, protocol.ChatModel{ID: id, Provider: provider, Name: name})
model := protocol.ChatModel{ID: id, Provider: provider, Name: name}
for _, variant := range item.Variants {
if variant.ID != "" && !protocol.HasChatEffort(model.Efforts, variant.ID) {
model.Efforts = append(model.Efforts, protocol.ChatEffort{ID: variant.ID, Name: protocol.ChatEffortName(variant.ID)})
}
}
models = append(models, model)
}
sort.Slice(models, func(i, j int) bool {
if models[i].Provider != models[j].Provider {
@@ -1686,6 +1699,8 @@ type nativeChatFile struct {
type nativeChatModel struct {
ID string `json:"id"`
ProviderID string `json:"providerID"`
// Variant is the session model's chosen variant (its thinking level).
Variant string `json:"variant"`
}
// nativeChatPart is one content element shared by both message envelopes. Raw
@@ -1908,6 +1923,7 @@ func chatSessionFields(record nativeChatSession) protocol.ChatSession {
Agent: record.Agent,
Model: record.Model.ID,
ModelProvider: record.Model.ProviderID,
Effort: record.Model.Variant,
Directory: record.Location.Directory,
ParentID: record.ParentID,
CreatedAt: record.Time.Created,