Files
pipelines/internal/server/chat_star.go
T
alan f7a3a49f94 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.
2026-10-20 12:10:39 +01:00

59 lines
2.3 KiB
Go

package server
import (
"context"
"git.a-wan.net/alan/pipelines/internal/protocol"
)
// handleChatStar records the operator's shared star for one operator chat
// session. It is a registry write, not a local preference: every browser and
// device lists the same Starred group, and starring never mutates the OpenCode
// session or its transcript. A session id that is not a recorded operator
// session is refused before anything is written, so a pipeline-owned run session
// is never touched. The request body is a ChatQuery carrying SessionID and the
// desired Starred value; the reply echoes the updated session.
func handleChatStar(ctx context.Context, request protocol.Message, registry operatorRegistry, write func(protocol.Message) error) {
if registry == nil {
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: "operator session registry is not configured on this server"})
return
}
query := request.ChatQuery
if query == nil || !validChatSessionID(query.SessionID) {
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: "a valid OpenCode session id is required"})
return
}
if query.Starred == nil {
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: "a starred state is required"})
return
}
sessionID := query.SessionID
if _, found, err := registry.OperatorSession(ctx, sessionID); err != nil {
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: err.Error()})
return
} else if !found {
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: "session " + sessionID + " is not an operator chat session"})
return
}
if err := registry.SetOperatorSessionStar(ctx, sessionID, *query.Starred); err != nil {
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: err.Error()})
return
}
session, found, err := registry.OperatorSession(ctx, sessionID)
if err != nil {
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: err.Error()})
return
}
if !found {
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: "session " + sessionID + " is no longer an operator session"})
return
}
wire := chatSessionFromOperator(session)
write(protocol.Message{
Type: protocol.ChatStar,
ID: request.ID,
ChatSession: &wire,
ChatSessions: []protocol.ChatSession{wire},
})
}