Files
pipelines/internal/server/chat_star.go
T
alan a4c191a416 Chats: a shared highlight colour per chat, pushed live with star and rename
chat_color {session_id, color|null} stores a palette name (red, orange,
amber, green, teal, blue, purple, pink) on the operator-session row; rows
and replies carry it as color. Colour, star and rename changes are pushed
to every other connection as chat_session_changed.
2026-11-03 10:53:38 +00:00

44 lines
2.0 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, changes *chatSessionChanges, clientID string, 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
}
echoOperatorSession(ctx, request, sessionID, protocol.ChatStar, registry, changes, clientID, write)
}