web: shared chat stars, pipeline mini graphs and agent questions
- Persist chat stars in the operator-session registry (chat_star) so every browser/device shows the same Starred group; migrate old local stars once. - Add a compact pipeline graph shape to list responses and draw a lightweight list miniature; replace the cryptic id/version line with the stage count. - Surface OpenCode form questions as a chat card (chat_answer), replay a pending form to late subscribers, and notify for background questions. - Make the mobile dock's Search cell equal to every destination, keep the tab row visible with 100svh, and let Source use the full pane height. - Let a fresh sign-in auto-connect to its own origin; use a Lax session cookie with Expires so Remember me survives app/link launches. - Keep shipped starters and the skill agnostic: no repository paths, project areas or personal device commands; add Diagnose/Fix and Research starters. - Refresh the installed skill and document the new browser conventions.
This commit is contained in:
@@ -46,6 +46,13 @@ type chatPromptWithMessageID interface {
|
||||
PromptWithMessageID(context.Context, string, string, string) error
|
||||
}
|
||||
|
||||
// chatAnswerer is the optional form-answer surface. Test brokers and older
|
||||
// backends need not implement it; a broker that does not answers chat_answer
|
||||
// with a clear error rather than pretending the question was delivered.
|
||||
type chatAnswerer interface {
|
||||
Answer(context.Context, protocol.ChatAnswerRequest) error
|
||||
}
|
||||
|
||||
type chatShellOutputReader interface {
|
||||
ShellOutput(ctx context.Context, query protocol.ChatShellOutputQuery) (protocol.ChatShellOutputPage, error)
|
||||
}
|
||||
@@ -83,6 +90,7 @@ type operatorRegistry interface {
|
||||
// session (which has no operator_sessions row).
|
||||
CloseOperatorSession(ctx context.Context, sessionID string) error
|
||||
ReopenOperatorSession(ctx context.Context, sessionID string) error
|
||||
SetOperatorSessionStar(ctx context.Context, sessionID string, starred bool) error
|
||||
}
|
||||
|
||||
var chatTokenSequence atomic.Uint64
|
||||
@@ -121,6 +129,9 @@ func handleChat(ctx context.Context, request protocol.Message, broker chatBroker
|
||||
case protocol.ChatReply:
|
||||
handleChatSimple(ctx, request, broker, hub, write)
|
||||
return true
|
||||
case protocol.ChatAnswer:
|
||||
handleChatAnswer(ctx, request, broker, write)
|
||||
return true
|
||||
case protocol.ChatSessions:
|
||||
handleChatSessions(ctx, request, broker, hub, registry, write)
|
||||
return true
|
||||
@@ -139,6 +150,9 @@ func handleChat(ctx context.Context, request protocol.Message, broker chatBroker
|
||||
case protocol.ChatReopen:
|
||||
handleChatReopen(ctx, request, registry, write)
|
||||
return true
|
||||
case protocol.ChatStar:
|
||||
handleChatStar(ctx, request, registry, write)
|
||||
return true
|
||||
case protocol.ChatShells:
|
||||
handleChatShells(ctx, request, broker, registry, write)
|
||||
return true
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.a-wan.net/alan/pipelines/internal/opencode"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
)
|
||||
|
||||
// handleChatAnswer replies to one OpenCode form, which is how the agent's
|
||||
// question tool resumes: the tool call is paused inside form.created until a
|
||||
// client answers. It validates the session/form ids before calling the broker,
|
||||
// so a malformed answer cannot reach another session. The resulting
|
||||
// form.replied/form.cancelled event arrives on the ordinary chat_event stream
|
||||
// and clears the card on every watching client.
|
||||
func handleChatAnswer(ctx context.Context, request protocol.Message, broker chatBroker, write func(protocol.Message) error) {
|
||||
if broker == nil {
|
||||
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: "chat is not configured on this server"})
|
||||
return
|
||||
}
|
||||
answer := request.ChatAnswer
|
||||
if answer == nil {
|
||||
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: "a chat_answer payload is required"})
|
||||
return
|
||||
}
|
||||
if !opencode.ValidSessionID(answer.SessionID) {
|
||||
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: "a valid OpenCode session id is required"})
|
||||
return
|
||||
}
|
||||
if answer.FormID == "" {
|
||||
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: "a form id is required"})
|
||||
return
|
||||
}
|
||||
if len(answer.Answers) == 0 {
|
||||
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: "at least one answer is required"})
|
||||
return
|
||||
}
|
||||
answerer, ok := broker.(chatAnswerer)
|
||||
if !ok {
|
||||
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: "this chat backend cannot answer questions"})
|
||||
return
|
||||
}
|
||||
if err := answerer.Answer(ctx, *answer); err != nil {
|
||||
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: err.Error()})
|
||||
return
|
||||
}
|
||||
_ = write(protocol.Message{Type: protocol.ChatAnswer, ID: request.ID})
|
||||
}
|
||||
@@ -140,5 +140,9 @@ func chatSessionFromOperator(session pipeline.OperatorSession) protocol.ChatSess
|
||||
out.Closed = true
|
||||
out.ClosedAt = session.ClosedAt
|
||||
}
|
||||
if session.StarredAt > 0 {
|
||||
out.Starred = true
|
||||
out.StarredAt = session.StarredAt
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
@@ -157,6 +157,25 @@ func (h *chatHub) applyLocked(frame protocol.ChatEventFrame) {
|
||||
}
|
||||
turn.applyShell(frame.Shell)
|
||||
return
|
||||
case protocol.ChatEventForm:
|
||||
// A form/question likewise carries no message id. Keep the pending form
|
||||
// for a late subscriber; a resolved or cancelled form removes it.
|
||||
if frame.Form == nil || frame.Form.ID == "" {
|
||||
return
|
||||
}
|
||||
if room := h.rooms[frame.SessionID]; room != nil {
|
||||
next := room.forms[:0]
|
||||
for _, form := range room.forms {
|
||||
if form.ID != frame.Form.ID {
|
||||
next = append(next, form)
|
||||
}
|
||||
}
|
||||
room.forms = next
|
||||
if !frame.Form.Resolved && !frame.Form.Cancelled && len(room.forms) < 8 {
|
||||
room.forms = append(room.forms, *frame.Form)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
if frame.MessageID == "" {
|
||||
return
|
||||
|
||||
@@ -137,7 +137,10 @@ type chatRoom struct {
|
||||
// pending holds the room's unresolved approval requests, in the order they
|
||||
// were raised, replayed to a client that attaches after they were raised. A
|
||||
// request is removed once it is resolved.
|
||||
pending []protocol.ChatPermissionFrame
|
||||
pending []protocol.ChatPermissionFrame
|
||||
// forms holds the room's unresolved question/form frames so a client that
|
||||
// attaches after the agent asked still renders the question.
|
||||
forms []protocol.ChatForm
|
||||
pollerStarted bool
|
||||
wake chan struct{}
|
||||
turnDone chan struct{}
|
||||
@@ -548,6 +551,18 @@ func (h *chatHub) submitPrompt(sessionID string, p *chatQueuedPrompt) (queued bo
|
||||
// pendingFrames returns a copy of the room's unresolved approval requests so a
|
||||
// client that attaches after they were raised can be shown every one of them. It
|
||||
// returns nil when the room holds none.
|
||||
func (h *chatHub) pendingForms(sessionID string) []protocol.ChatForm {
|
||||
h.mu.Lock()
|
||||
defer h.mu.Unlock()
|
||||
room := h.rooms[sessionID]
|
||||
if room == nil || len(room.forms) == 0 {
|
||||
return nil
|
||||
}
|
||||
forms := make([]protocol.ChatForm, len(room.forms))
|
||||
copy(forms, room.forms)
|
||||
return forms
|
||||
}
|
||||
|
||||
func (h *chatHub) pendingFrames(sessionID string) []protocol.ChatPermissionFrame {
|
||||
h.mu.Lock()
|
||||
defer h.mu.Unlock()
|
||||
|
||||
@@ -80,6 +80,8 @@ func handleChatSessions(ctx context.Context, request protocol.Message, broker ch
|
||||
// clients may watch and write one session.
|
||||
session.Closed = operator.ClosedAt > 0
|
||||
session.ClosedAt = operator.ClosedAt
|
||||
session.Starred = operator.StarredAt > 0
|
||||
session.StarredAt = operator.StarredAt
|
||||
response.ChatSessions = append(response.ChatSessions, session)
|
||||
}
|
||||
_ = write(response)
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.a-wan.net/alan/pipelines/internal/opencode"
|
||||
"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 || !opencode.ValidSessionID(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},
|
||||
})
|
||||
}
|
||||
@@ -132,6 +132,16 @@ func handleChatSubscribe(request protocol.Message, broker chatBroker, hub *chatH
|
||||
frame := pending
|
||||
sub.send(protocol.Message{Type: protocol.ChatPermission, ChatPermission: &frame})
|
||||
}
|
||||
// Replay a question/form the agent raised before this client attached, so a
|
||||
// reload or another device still sees the paused tool call.
|
||||
for _, form := range hub.pendingForms(query.SessionID) {
|
||||
pending := form
|
||||
sub.send(protocol.Message{Type: protocol.ChatEvent, ChatEvent: &protocol.ChatEventFrame{
|
||||
SessionID: query.SessionID,
|
||||
Kind: protocol.ChatEventForm,
|
||||
Form: &pending,
|
||||
}})
|
||||
}
|
||||
// Replay the background processes still running, so a device that attaches
|
||||
// after they started (a reconnect, or a chat opened from another device)
|
||||
// shows them rather than nothing until they exit. The message snapshot cannot
|
||||
|
||||
Reference in New Issue
Block a user