Send mid-turn chat prompts to the harness and queue the rest durably on the server
Claude Code (stream-json stdin) and Codex (turn/steer pinned to the active turn) receive a prompt sent while a turn runs immediately. Other harnesses (OpenCode) get a durable chat_prompt_queue row owned by the session: it survives the last client detaching and a server restart, is delivered in order when the turn ends with or without a client, and is deduplicated by operation id. chat_subscribe carries the queue, chat_queue frames report delivered/removed/failed changes, and chat_unqueue removes a waiting prompt.
This commit is contained in:
@@ -69,6 +69,16 @@ const (
|
||||
// body is a ChatQuery naming the session and the response echoes the request
|
||||
// id once the subscription is attached.
|
||||
ChatSubscribe = "chat_subscribe"
|
||||
// ChatQueue is pushed to every client watching a session whenever its
|
||||
// server-side prompt queue changes (a prompt queued, delivered, removed or
|
||||
// refused by the harness). The chat_subscribe reply carries the same body so
|
||||
// a reloaded client draws the queued prompts the server still holds.
|
||||
ChatQueue = "chat_queue"
|
||||
// ChatUnqueue removes one prompt the server still holds in a session's
|
||||
// queue, named by its operation id. Its body is ChatUnqueueRequest and the
|
||||
// reply carries the updated queue in ChatQueue. A prompt already delivered
|
||||
// to the harness is no longer removable and is refused.
|
||||
ChatUnqueue = "chat_unqueue"
|
||||
// ChatDirectories is the request/response type for the operator's directory
|
||||
// choices: the home directory plus the directories of previous operator
|
||||
// sessions, most recently used first, deduplicated and bounded. It is a
|
||||
@@ -354,6 +364,37 @@ type ChatPromptRequest struct {
|
||||
Attachments []ChatAttachment `json:"attachments,omitempty"`
|
||||
}
|
||||
|
||||
// ChatQueuedPrompt is one prompt the server holds for a session until its
|
||||
// harness finishes the turn in flight. It is durable: it survives the sending
|
||||
// client disconnecting and a server restart, and is delivered in order.
|
||||
type ChatQueuedPrompt struct {
|
||||
OperationID string `json:"operation_id"`
|
||||
MessageID string `json:"message_id"`
|
||||
NativeMessageID string `json:"native_message_id,omitempty"`
|
||||
Text string `json:"text"`
|
||||
Client string `json:"client,omitempty"`
|
||||
Attachments []ChatPart `json:"attachments,omitempty"`
|
||||
QueuedAt int64 `json:"queued_at,omitempty"`
|
||||
}
|
||||
|
||||
// ChatQueueFrame is a session's current server-side prompt queue, in delivery
|
||||
// order. Delivered, Removed or Failed name the operation whose change produced
|
||||
// the frame; Error carries the harness refusal for Failed.
|
||||
type ChatQueueFrame struct {
|
||||
SessionID string `json:"session_id"`
|
||||
Prompts []ChatQueuedPrompt `json:"prompts"`
|
||||
Delivered string `json:"delivered,omitempty"`
|
||||
Removed string `json:"removed,omitempty"`
|
||||
Failed string `json:"failed,omitempty"`
|
||||
Error string `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
// ChatUnqueueRequest names one queued prompt to remove.
|
||||
type ChatUnqueueRequest struct {
|
||||
SessionID string `json:"session_id"`
|
||||
OperationID string `json:"operation_id"`
|
||||
}
|
||||
|
||||
// ChatAttachment is one browser attachment carried by a chat prompt. Data is
|
||||
// standard base64 (no data: prefix); Name is a display name and Mime is the
|
||||
// browser's content type. The server derives the on-disk name and never trusts
|
||||
|
||||
@@ -221,6 +221,11 @@ type Message struct {
|
||||
// accepted into the session's queue instead of being sent immediately.
|
||||
ChatSubscribe *ChatQuery `json:"chat_subscribe,omitempty"`
|
||||
ChatQueued bool `json:"chat_queued,omitempty"`
|
||||
// ChatQueue is the session's server-held prompt queue: pushed as a
|
||||
// chat_queue frame when it changes and carried by the chat_subscribe and
|
||||
// chat_unqueue replies.
|
||||
ChatQueue *ChatQueueFrame `json:"chat_queue,omitempty"`
|
||||
ChatUnqueue *ChatUnqueueRequest `json:"chat_unqueue,omitempty"`
|
||||
// ChatDirectories carries the operator's directory choices on a
|
||||
// chat_directories response (home first, then recent operator-session
|
||||
// directories, deduplicated and bounded). Additive/omitempty so older peers
|
||||
|
||||
Reference in New Issue
Block a user