ff36e777c9
Enter inserts a newline and Ctrl/Cmd+Enter sends; slash commands still run on Enter. Chat renames are stored in the server registry so every device sees the same title, with a one-time upload of old local titles. The star no longer covers the row status, and shell frames patch the background bar in place so the composer stays mounted while streaming.
69 lines
2.7 KiB
Go
69 lines
2.7 KiB
Go
package server
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"unicode/utf8"
|
|
|
|
"git.a-wan.net/alan/pipelines/internal/opencode"
|
|
"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, 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 || !opencode.ValidSessionID(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
|
|
}
|
|
session, found, err := registry.OperatorSession(ctx, rename.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 " + rename.SessionID + " is no longer an operator session"})
|
|
return
|
|
}
|
|
wire := chatSessionFromOperator(session)
|
|
write(protocol.Message{
|
|
Type: protocol.ChatRename,
|
|
ID: request.ID,
|
|
ChatSession: &wire,
|
|
ChatSessions: []protocol.ChatSession{wire},
|
|
})
|
|
}
|