feat(chat): persist safe Codex next-turn model selection

This commit is contained in:
2026-10-20 16:32:42 +01:00
parent d92fa60259
commit ed0abb976d
16 changed files with 682 additions and 27 deletions
+28 -8
View File
@@ -317,6 +317,12 @@ func (c *Chat) Prompt(ctx context.Context, id, text string) error {
// PromptWithMessageID carries the client's native user-message id so the
// optimistic browser bubble and the authoritative history item can reconcile.
func (c *Chat) PromptWithMessageID(ctx context.Context, id, text, messageID string) error {
return c.PromptWithMessageIDModel(ctx, id, text, messageID, "")
}
// PromptWithMessageIDModel applies a persisted per-chat choice at the explicit
// next-turn boundary. It does not resume a thread or edit global configuration.
func (c *Chat) PromptWithMessageIDModel(ctx context.Context, id, text, messageID, model string) error {
if strings.TrimSpace(text) == "" {
return errors.New("empty chat prompt")
}
@@ -327,6 +333,9 @@ func (c *Chat) PromptWithMessageID(ctx context.Context, id, text, messageID stri
if messageID != "" {
params["clientUserMessageId"] = messageID
}
if model != "" {
params["model"] = model
}
_, err := c.call(ctx, "turn/start", params)
return err
}
@@ -379,12 +388,20 @@ func (c *Chat) Create(ctx context.Context, title, directory string) (protocol.Ch
return protocol.ChatSession{}, err
}
var result struct {
Thread thread `json:"thread"`
Thread thread `json:"thread"`
Model string `json:"model"`
ModelProvider string `json:"modelProvider"`
}
if err := json.Unmarshal(raw, &result); err != nil {
return protocol.ChatSession{}, err
}
session := result.Thread.chatSession()
if session.Model == "" {
session.Model = result.Model
}
if session.ModelProvider == "" {
session.ModelProvider = result.ModelProvider
}
session.Backend = Backend
if strings.TrimSpace(title) != "" {
session.Title = strings.TrimSpace(title)
@@ -697,13 +714,15 @@ func stepFrame(threadID, status string) protocol.ChatEventFrame {
}
type thread struct {
ID string `json:"id"`
Name string `json:"name"`
Preview string `json:"preview"`
Cwd string `json:"cwd"`
CreatedAt int64 `json:"createdAt"`
UpdatedAt int64 `json:"updatedAt"`
Turns []turn `json:"turns"`
Model string `json:"model"`
ModelProvider string `json:"modelProvider"`
ID string `json:"id"`
Name string `json:"name"`
Preview string `json:"preview"`
Cwd string `json:"cwd"`
CreatedAt int64 `json:"createdAt"`
UpdatedAt int64 `json:"updatedAt"`
Turns []turn `json:"turns"`
}
type turn struct {
@@ -731,6 +750,7 @@ func (t thread) chatSession() protocol.ChatSession {
}
return protocol.ChatSession{
ID: t.ID, Title: title, Directory: t.Cwd,
Model: t.Model, ModelProvider: t.ModelProvider,
CreatedAt: t.CreatedAt * 1000, UpdatedAt: t.UpdatedAt * 1000,
}
}