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:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"sync/atomic"
|
||||
|
||||
@@ -92,6 +93,16 @@ type operatorRegistry interface {
|
||||
ReopenOperatorSession(ctx context.Context, sessionID string) error
|
||||
SetOperatorSessionStar(ctx context.Context, sessionID string, starred bool) error
|
||||
SetOperatorSessionTitle(ctx context.Context, sessionID, title string) error
|
||||
SetOperatorSessionBackend(ctx context.Context, sessionID, backend string) error
|
||||
}
|
||||
|
||||
// validChatSessionID accepts the opaque id shapes of the supported harnesses
|
||||
// (OpenCode ses_…, Codex/Claude UUIDs). The owning adapter still validates the
|
||||
// exact shape before any provider call; this only rejects clearly unsafe ids.
|
||||
var chatSessionIDPattern = regexp.MustCompile(`^(?:ses_[A-Za-z0-9_]+|[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$`)
|
||||
|
||||
func validChatSessionID(id string) bool {
|
||||
return len(id) <= 200 && chatSessionIDPattern.MatchString(id)
|
||||
}
|
||||
|
||||
var chatTokenSequence atomic.Uint64
|
||||
@@ -157,6 +168,9 @@ func handleChat(ctx context.Context, request protocol.Message, broker chatBroker
|
||||
case protocol.ChatRename:
|
||||
handleChatRename(ctx, request, registry, write)
|
||||
return true
|
||||
case protocol.ChatBackends:
|
||||
handleChatBackends(request, broker, write)
|
||||
return true
|
||||
case protocol.ChatShells:
|
||||
handleChatShells(ctx, request, broker, registry, write)
|
||||
return true
|
||||
|
||||
@@ -3,7 +3,6 @@ package server
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.a-wan.net/alan/pipelines/internal/opencode"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
)
|
||||
|
||||
@@ -23,7 +22,7 @@ func handleChatAnswer(ctx context.Context, request protocol.Message, broker chat
|
||||
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: "a chat_answer payload is required"})
|
||||
return
|
||||
}
|
||||
if !opencode.ValidSessionID(answer.SessionID) {
|
||||
if !validChatSessionID(answer.SessionID) {
|
||||
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: "a valid OpenCode session id is required"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
)
|
||||
|
||||
// handleChatBackends lists the installed chat harnesses. Older servers answer
|
||||
// with the empty field, which clients treat as OpenCode-only.
|
||||
func handleChatBackends(request protocol.Message, broker chatBroker, write func(protocol.Message) error) {
|
||||
backends := []string{"opencode"}
|
||||
if lister, ok := broker.(interface{ Backends() []string }); ok {
|
||||
backends = lister.Backends()
|
||||
}
|
||||
_ = write(protocol.Message{Type: protocol.ChatBackends, ID: request.ID, ChatBackends: backends})
|
||||
}
|
||||
|
||||
// chatCreateBackend is the optional create-with-backend surface implemented by
|
||||
// the multi-harness manager. A single-broker installation keeps using Create.
|
||||
type chatCreateBackend interface {
|
||||
CreateBackend(ctx context.Context, title, directory, backend string) (protocol.ChatSession, error)
|
||||
}
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"git.a-wan.net/alan/pipelines/internal/opencode"
|
||||
"git.a-wan.net/alan/pipelines/internal/pipeline"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
)
|
||||
@@ -28,7 +27,7 @@ func handleChatClose(ctx context.Context, request protocol.Message, broker chatB
|
||||
return
|
||||
}
|
||||
query := request.ChatQuery
|
||||
if query == nil || !opencode.ValidSessionID(query.SessionID) {
|
||||
if query == nil || !validChatSessionID(query.SessionID) {
|
||||
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: "a valid OpenCode session id is required"})
|
||||
return
|
||||
}
|
||||
@@ -88,7 +87,7 @@ func handleChatReopen(ctx context.Context, request protocol.Message, registry op
|
||||
return
|
||||
}
|
||||
query := request.ChatQuery
|
||||
if query == nil || !opencode.ValidSessionID(query.SessionID) {
|
||||
if query == nil || !validChatSessionID(query.SessionID) {
|
||||
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: "a valid OpenCode session id is required"})
|
||||
return
|
||||
}
|
||||
@@ -135,6 +134,7 @@ func chatSessionFromOperator(session pipeline.OperatorSession) protocol.ChatSess
|
||||
Tag: session.Tag,
|
||||
CreatedAt: session.CreatedAt,
|
||||
UpdatedAt: session.UpdatedAt,
|
||||
Backend: session.Backend,
|
||||
}
|
||||
if session.ClosedAt > 0 {
|
||||
out.Closed = true
|
||||
|
||||
@@ -4,13 +4,12 @@ import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"git.a-wan.net/alan/pipelines/internal/opencode"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
)
|
||||
|
||||
func handleChatMessages(ctx context.Context, request protocol.Message, broker chatBroker, hub *chatHub, write func(protocol.Message) error) {
|
||||
query := request.ChatQuery
|
||||
if query == nil || !opencode.ValidSessionID(query.SessionID) {
|
||||
if query == nil || !validChatSessionID(query.SessionID) {
|
||||
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: "a valid OpenCode session id is required"})
|
||||
return
|
||||
}
|
||||
@@ -39,7 +38,7 @@ func handleChatSimple(ctx context.Context, request protocol.Message, broker chat
|
||||
}
|
||||
if request.Type == protocol.ChatInterrupt {
|
||||
query := request.ChatQuery
|
||||
if query == nil || !opencode.ValidSessionID(query.SessionID) {
|
||||
if query == nil || !validChatSessionID(query.SessionID) {
|
||||
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: "a valid OpenCode session id is required"})
|
||||
return
|
||||
}
|
||||
@@ -51,7 +50,7 @@ func handleChatSimple(ctx context.Context, request protocol.Message, broker chat
|
||||
return
|
||||
}
|
||||
reply := request.ChatReply
|
||||
if reply == nil || !opencode.ValidSessionID(reply.SessionID) {
|
||||
if reply == nil || !validChatSessionID(reply.SessionID) {
|
||||
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: "a valid OpenCode session id is required"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -0,0 +1,292 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"sort"
|
||||
"sync"
|
||||
|
||||
"git.a-wan.net/alan/pipelines/internal/codex"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
)
|
||||
|
||||
// chatManager routes one session to the harness that owns it. OpenCode remains
|
||||
// the default; Codex is attached when its app-server control socket exists.
|
||||
// The operator registry is the durable record of the backend, so a restart does
|
||||
// not have to guess from a session id.
|
||||
type chatManager struct {
|
||||
opencode chatBroker
|
||||
codex chatBroker
|
||||
registry operatorRegistry
|
||||
|
||||
mu sync.Mutex
|
||||
cache map[string]string // session id -> backend
|
||||
}
|
||||
|
||||
func NewChatManager(ctx context.Context, open chatBroker, registry operatorRegistry) *chatManager {
|
||||
m := &chatManager{opencode: open, registry: registry, cache: map[string]string{}}
|
||||
if codex.Available() {
|
||||
client, err := codex.Open(ctx)
|
||||
if err == nil {
|
||||
m.codex = client
|
||||
}
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// Close releases the owned Codex client, if any.
|
||||
func (m *chatManager) Close() {
|
||||
if closer, ok := m.codex.(interface{ Close() }); ok {
|
||||
closer.Close()
|
||||
}
|
||||
}
|
||||
|
||||
// Backends lists the harnesses available for a new session.
|
||||
func (m *chatManager) Backends() []string {
|
||||
backends := []string{}
|
||||
if m.opencode != nil {
|
||||
backends = append(backends, "opencode")
|
||||
}
|
||||
if m.codex != nil {
|
||||
backends = append(backends, codex.Backend)
|
||||
}
|
||||
sort.Strings(backends)
|
||||
return backends
|
||||
}
|
||||
|
||||
func (m *chatManager) adapter(backend string) chatBroker {
|
||||
switch backend {
|
||||
case "", "opencode":
|
||||
return m.opencode
|
||||
case codex.Backend:
|
||||
return m.codex
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func (m *chatManager) backendFor(ctx context.Context, sessionID string) string {
|
||||
m.mu.Lock()
|
||||
backend := m.cache[sessionID]
|
||||
m.mu.Unlock()
|
||||
if backend != "" {
|
||||
return backend
|
||||
}
|
||||
if m.registry != nil {
|
||||
if row, found, err := m.registry.OperatorSession(ctx, sessionID); err == nil && found && row.Backend != "" {
|
||||
m.mu.Lock()
|
||||
m.cache[sessionID] = row.Backend
|
||||
m.mu.Unlock()
|
||||
return row.Backend
|
||||
}
|
||||
}
|
||||
return "opencode"
|
||||
}
|
||||
|
||||
func (m *chatManager) brokerFor(ctx context.Context, sessionID string) (chatBroker, error) {
|
||||
backend := m.backendFor(ctx, sessionID)
|
||||
adapter := m.adapter(backend)
|
||||
if adapter == nil {
|
||||
return nil, errors.New("chat backend " + backend + " is not available")
|
||||
}
|
||||
return adapter, nil
|
||||
}
|
||||
|
||||
// CreateBackend creates a session on the requested harness. An empty backend
|
||||
// keeps the OpenCode default.
|
||||
func (m *chatManager) CreateBackend(ctx context.Context, title, directory, backend string) (protocol.ChatSession, error) {
|
||||
if backend == "" {
|
||||
backend = "opencode"
|
||||
}
|
||||
adapter := m.adapter(backend)
|
||||
if adapter == nil {
|
||||
return protocol.ChatSession{}, errors.New("chat backend " + backend + " is not available")
|
||||
}
|
||||
session, err := adapter.Create(ctx, title, directory)
|
||||
if err != nil {
|
||||
return protocol.ChatSession{}, err
|
||||
}
|
||||
session.Backend = backend
|
||||
m.mu.Lock()
|
||||
m.cache[session.ID] = backend
|
||||
m.mu.Unlock()
|
||||
return session, nil
|
||||
}
|
||||
|
||||
func (m *chatManager) Create(ctx context.Context, title, directory string) (protocol.ChatSession, error) {
|
||||
return m.CreateBackend(ctx, title, directory, "opencode")
|
||||
}
|
||||
|
||||
func (m *chatManager) Prompt(ctx context.Context, sessionID, text string) error {
|
||||
adapter, err := m.brokerFor(ctx, sessionID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return adapter.Prompt(ctx, sessionID, text)
|
||||
}
|
||||
|
||||
func (m *chatManager) PromptWithMessageID(ctx context.Context, sessionID, text, messageID string) error {
|
||||
adapter, err := m.brokerFor(ctx, sessionID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if withID, ok := adapter.(chatPromptWithMessageID); ok {
|
||||
return withID.PromptWithMessageID(ctx, sessionID, text, messageID)
|
||||
}
|
||||
return adapter.Prompt(ctx, sessionID, text)
|
||||
}
|
||||
|
||||
func (m *chatManager) Stream(ctx context.Context, sessionID string, ready func(), emit func(protocol.ChatEventFrame) error) error {
|
||||
adapter, err := m.brokerFor(ctx, sessionID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return adapter.Stream(ctx, sessionID, ready, emit)
|
||||
}
|
||||
|
||||
func (m *chatManager) Interrupt(ctx context.Context, sessionID string) error {
|
||||
adapter, err := m.brokerFor(ctx, sessionID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return adapter.Interrupt(ctx, sessionID)
|
||||
}
|
||||
|
||||
func (m *chatManager) Messages(ctx context.Context, sessionID string, limit int, cursor string) (protocol.ChatHistoryPage, error) {
|
||||
adapter, err := m.brokerFor(ctx, sessionID)
|
||||
if err != nil {
|
||||
return protocol.ChatHistoryPage{}, err
|
||||
}
|
||||
return adapter.Messages(ctx, sessionID, limit, cursor)
|
||||
}
|
||||
|
||||
func (m *chatManager) Sessions(ctx context.Context) ([]protocol.ChatSession, error) {
|
||||
sessions := []protocol.ChatSession{}
|
||||
seen := map[string]bool{}
|
||||
for _, adapter := range []chatBroker{m.opencode, m.codex} {
|
||||
if adapter == nil {
|
||||
continue
|
||||
}
|
||||
list, err := adapter.Sessions(ctx)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
for _, session := range list {
|
||||
if session.ID == "" || seen[session.ID] {
|
||||
continue
|
||||
}
|
||||
seen[session.ID] = true
|
||||
sessions = append(sessions, session)
|
||||
}
|
||||
}
|
||||
// A backend that cannot enumerate its own store still has registry rows.
|
||||
// Resolve those individually so an older/restarted backend never silently
|
||||
// drops a chat from the list.
|
||||
if m.registry != nil {
|
||||
if rows, err := m.registry.OperatorSessions(ctx); err == nil {
|
||||
for _, row := range rows {
|
||||
if seen[row.ID] || row.Backend == "" || row.Backend == "opencode" {
|
||||
continue
|
||||
}
|
||||
adapter := m.adapter(row.Backend)
|
||||
if adapter == nil {
|
||||
continue
|
||||
}
|
||||
if session, found, err := adapter.Session(ctx, row.ID); err == nil && found {
|
||||
seen[row.ID] = true
|
||||
sessions = append(sessions, session)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return sessions, nil
|
||||
}
|
||||
|
||||
func (m *chatManager) Session(ctx context.Context, sessionID string) (protocol.ChatSession, bool, error) {
|
||||
adapter, err := m.brokerFor(ctx, sessionID)
|
||||
if err != nil {
|
||||
return protocol.ChatSession{}, false, err
|
||||
}
|
||||
return adapter.Session(ctx, sessionID)
|
||||
}
|
||||
|
||||
func (m *chatManager) Permissions(ctx context.Context, sessionID string) ([]protocol.ChatPermissionFrame, error) {
|
||||
adapter, err := m.brokerFor(ctx, sessionID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if permissions, ok := adapter.(interface {
|
||||
Permissions(context.Context, string) ([]protocol.ChatPermissionFrame, error)
|
||||
}); ok {
|
||||
return permissions.Permissions(ctx, sessionID)
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (m *chatManager) Shells(ctx context.Context, sessionID string) ([]protocol.ChatShell, error) {
|
||||
adapter, err := m.brokerFor(ctx, sessionID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if shells, ok := adapter.(interface {
|
||||
Shells(context.Context, string) ([]protocol.ChatShell, error)
|
||||
}); ok {
|
||||
return shells.Shells(ctx, sessionID)
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (m *chatManager) Reply(ctx context.Context, request protocol.ChatReplyRequest) error {
|
||||
adapter, err := m.brokerFor(ctx, request.SessionID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return adapter.Reply(ctx, request)
|
||||
}
|
||||
|
||||
func (m *chatManager) ActivateSkill(ctx context.Context, sessionID, skill string) error {
|
||||
// Skill bootstrap is an OpenCode chat concept. Other harnesses return from
|
||||
// create without a manager skill and must not fail the create.
|
||||
if m.backendFor(ctx, sessionID) != "opencode" {
|
||||
return nil
|
||||
}
|
||||
adapter, err := m.brokerFor(ctx, sessionID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return adapter.ActivateSkill(ctx, sessionID, skill)
|
||||
}
|
||||
|
||||
func (m *chatManager) Answer(ctx context.Context, request protocol.ChatAnswerRequest) error {
|
||||
adapter, err := m.brokerFor(ctx, request.SessionID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
answerer, ok := adapter.(chatAnswerer)
|
||||
if !ok {
|
||||
return errors.New("this chat backend cannot answer questions")
|
||||
}
|
||||
return answerer.Answer(ctx, request)
|
||||
}
|
||||
|
||||
func (m *chatManager) ShellOutput(ctx context.Context, query protocol.ChatShellOutputQuery) (protocol.ChatShellOutputPage, error) {
|
||||
adapter, err := m.brokerFor(ctx, query.SessionID)
|
||||
if err != nil {
|
||||
return protocol.ChatShellOutputPage{}, err
|
||||
}
|
||||
reader, ok := adapter.(chatShellOutputReader)
|
||||
if !ok {
|
||||
return protocol.ChatShellOutputPage{}, errors.New("this chat backend has no shell output")
|
||||
}
|
||||
return reader.ShellOutput(ctx, query)
|
||||
}
|
||||
|
||||
func (m *chatManager) ReleaseShells(sessionID string) {
|
||||
m.mu.Lock()
|
||||
backend := m.cache[sessionID]
|
||||
m.mu.Unlock()
|
||||
adapter := m.adapter(backend)
|
||||
if releaser, ok := adapter.(chatShellReleaser); ok {
|
||||
releaser.ReleaseShells(sessionID)
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
|
||||
"git.a-wan.net/alan/pipelines/internal/opencode"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
)
|
||||
|
||||
@@ -25,7 +24,7 @@ func handleChatRename(ctx context.Context, request protocol.Message, registry op
|
||||
return
|
||||
}
|
||||
rename := request.ChatRename
|
||||
if rename == nil || !opencode.ValidSessionID(rename.SessionID) {
|
||||
if rename == nil || !validChatSessionID(rename.SessionID) {
|
||||
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: "a valid OpenCode session id is required"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ func handleChatShells(ctx context.Context, request protocol.Message, broker chat
|
||||
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: "chat is not configured on this server"})
|
||||
return
|
||||
}
|
||||
if query == nil || !opencode.ValidSessionID(query.SessionID) {
|
||||
if query == nil || !validChatSessionID(query.SessionID) {
|
||||
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: "a valid OpenCode session id is required"})
|
||||
return
|
||||
}
|
||||
@@ -50,7 +50,7 @@ func handleChatShellOutput(ctx context.Context, request protocol.Message, broker
|
||||
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: "chat is not configured on this server"})
|
||||
return
|
||||
}
|
||||
if query == nil || !opencode.ValidSessionID(query.SessionID) || !validShellID(query.ShellID) || query.Cursor < 0 || query.Cursor > protocol.ChatShellOutputMaxCursor || query.Limit <= 0 || query.Limit > protocol.ChatShellOutputLimit {
|
||||
if query == nil || !validChatSessionID(query.SessionID) || !validShellID(query.ShellID) || query.Cursor < 0 || query.Cursor > protocol.ChatShellOutputMaxCursor || query.Limit <= 0 || query.Limit > protocol.ChatShellOutputLimit {
|
||||
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: "a valid bounded shell output query is required"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package server
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.a-wan.net/alan/pipelines/internal/opencode"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
)
|
||||
|
||||
@@ -20,7 +19,7 @@ func handleChatStar(ctx context.Context, request protocol.Message, registry oper
|
||||
return
|
||||
}
|
||||
query := request.ChatQuery
|
||||
if query == nil || !opencode.ValidSessionID(query.SessionID) {
|
||||
if query == nil || !validChatSessionID(query.SessionID) {
|
||||
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: "a valid OpenCode session id is required"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ func handleChatPrompt(ctx context.Context, request protocol.Message, broker chat
|
||||
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: "a chat prompt payload is required"})
|
||||
return
|
||||
}
|
||||
if !opencode.ValidSessionID(prompt.SessionID) {
|
||||
if !validChatSessionID(prompt.SessionID) {
|
||||
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: "a valid OpenCode session id is required"})
|
||||
return
|
||||
}
|
||||
@@ -104,7 +104,7 @@ func handleChatSubscribe(request protocol.Message, broker chatBroker, hub *chatH
|
||||
// subscribeRequest and docs/cli.md both use it), not the chat_query body the
|
||||
// other session-scoped commands carry.
|
||||
query := request.ChatSubscribe
|
||||
if query == nil || !opencode.ValidSessionID(query.SessionID) {
|
||||
if query == nil || !validChatSessionID(query.SessionID) {
|
||||
_ = 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