chat: add the Codex backend
Store a chat's harness with its operator session, expose chat_backends and a backend choice in New chat, and route each session through a manager. The Codex adapter uses the App Server's Unix WebSocket for threads, turns, history, questions and interrupt; OpenCode remains the default and Claude is not advertised until its sidecar and login are wired.
This commit is contained in:
@@ -7,7 +7,6 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"git.a-wan.net/alan/pipelines/internal/opencode"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
)
|
||||
|
||||
@@ -72,6 +71,7 @@ func handleChatSessions(ctx context.Context, request protocol.Message, broker ch
|
||||
}
|
||||
session.Directory = operator.Directory
|
||||
session.Tag = operator.Tag
|
||||
session.Backend = operator.Backend
|
||||
session.CreatedAt = operator.CreatedAt
|
||||
session.UpdatedAt = operator.UpdatedAt
|
||||
// The closed state comes from the registry, so every client sees the same
|
||||
@@ -107,11 +107,15 @@ func handleChatCreate(ctx context.Context, request protocol.Message, broker chat
|
||||
title := ""
|
||||
directory := ""
|
||||
operationID := ""
|
||||
backend := "opencode"
|
||||
ephemeral := false
|
||||
if request.ChatCreate != nil {
|
||||
title = strings.TrimSpace(request.ChatCreate.Title)
|
||||
directory = strings.TrimSpace(request.ChatCreate.Directory)
|
||||
operationID = strings.TrimSpace(request.ChatCreate.OperationID)
|
||||
if value := strings.TrimSpace(request.ChatCreate.Backend); value != "" {
|
||||
backend = value
|
||||
}
|
||||
ephemeral = request.ChatCreate.Ephemeral
|
||||
}
|
||||
// Legacy clients did not carry a durable create identity. Give each received
|
||||
@@ -146,7 +150,15 @@ func handleChatCreate(ctx context.Context, request protocol.Message, broker chat
|
||||
chatCreateConflictError(request, err, write)
|
||||
return
|
||||
}
|
||||
session, err = broker.Create(ctx, title, resolved)
|
||||
if creator, ok := broker.(chatCreateBackend); ok {
|
||||
session, err = creator.CreateBackend(ctx, title, resolved, backend)
|
||||
} else {
|
||||
if backend != "opencode" {
|
||||
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: "chat backend " + backend + " is not available"})
|
||||
return
|
||||
}
|
||||
session, err = broker.Create(ctx, title, resolved)
|
||||
}
|
||||
if err != nil {
|
||||
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: err.Error()})
|
||||
return
|
||||
@@ -199,6 +211,10 @@ func handleChatCreate(ctx context.Context, request protocol.Message, broker chat
|
||||
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: "session " + session.ID + " was created but could not be recorded: " + err.Error()})
|
||||
return
|
||||
}
|
||||
if err := registry.SetOperatorSessionBackend(ctx, session.ID, backend); err != nil {
|
||||
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: "session " + session.ID + " was recorded but its backend could not be saved: " + err.Error()})
|
||||
return
|
||||
}
|
||||
if err := registry.AdvanceChatCreate(ctx, operationID, "recording", "recorded"); err != nil {
|
||||
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: "session " + session.ID + " was recorded but durable bootstrap state could not be saved: " + err.Error()})
|
||||
return
|
||||
@@ -209,6 +225,7 @@ func handleChatCreate(ctx context.Context, request protocol.Message, broker chat
|
||||
}
|
||||
session.Directory = resolved
|
||||
session.Tag = protocol.ChatSessionTagOperator
|
||||
session.Backend = backend
|
||||
response := protocol.Message{Type: protocol.ChatCreate, ID: request.ID, ChatSession: &session}
|
||||
// The same registry row is echoed on the list field so a client can splice it
|
||||
// into chat_sessions without a re-list. An ephemeral create has no listed row
|
||||
@@ -250,7 +267,7 @@ func handleChatAdopt(ctx context.Context, request protocol.Message, broker chatB
|
||||
return
|
||||
}
|
||||
id := strings.TrimSpace(request.ChatAdopt.SessionID)
|
||||
if !opencode.ValidSessionID(id) {
|
||||
if !validChatSessionID(id) {
|
||||
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: "a valid OpenCode session id is required"})
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user