a4c191a416
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.
53 lines
2.3 KiB
Go
53 lines
2.3 KiB
Go
package server
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"unicode/utf8"
|
|
|
|
"git.a-wan.net/alan/pipelines/internal/protocol"
|
|
)
|
|
|
|
// chatTitleLimit bounds a shared chat title. The UI disables Save on a blank
|
|
// value; the server enforces the same rule so a direct client cannot erase a
|
|
// title or store an unbounded string.
|
|
const chatTitleLimit = 200
|
|
|
|
// handleChatRename records the operator's shared chat title. The operator-session
|
|
// registry's title overrides OpenCode's own title in chat_sessions, so every
|
|
// browser and device lists the same name. The OpenCode session, its transcript
|
|
// and its generated title are untouched, and a session that is not an operator
|
|
// chat is refused before anything is written.
|
|
func handleChatRename(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
|
|
}
|
|
rename := request.ChatRename
|
|
if rename == nil || !validChatSessionID(rename.SessionID) {
|
|
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: "a valid OpenCode session id is required"})
|
|
return
|
|
}
|
|
title := strings.TrimSpace(rename.Title)
|
|
if title == "" {
|
|
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: "a chat title with usable text is required"})
|
|
return
|
|
}
|
|
if utf8.RuneCountInString(title) > chatTitleLimit {
|
|
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: "a chat title must be at most 200 characters"})
|
|
return
|
|
}
|
|
if _, found, err := registry.OperatorSession(ctx, rename.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 " + rename.SessionID + " is not an operator chat session"})
|
|
return
|
|
}
|
|
if err := registry.SetOperatorSessionTitle(ctx, rename.SessionID, title); err != nil {
|
|
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: err.Error()})
|
|
return
|
|
}
|
|
echoOperatorSession(ctx, request, rename.SessionID, protocol.ChatRename, registry, changes, clientID, write)
|
|
}
|