nandi/oripublic Fork 0
f5c963af3c1597c0274ce4a99705dbd92a7d1cba
Commits
Clone
git clone https://git.rickub.com/nandi/ori.git
git clone ssh://git@rickub.com/nandi/ori.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

forked from bots-garden/ori

protocol.go · 107 lines · 4.5 KBGo Blame HistoryRaw
✨ Introduce new feature(s): ACP web client — Go backend (agent, bridge, httpserver, mockagent) + React SPA (Zed-like agent panel), tests, quality gate PASS 2434cc7 k33g yesterday1package bridge
2
3import "encoding/json"
4
5// This file is the wire contract between the SPA and the backend, over a
6// WebSocket carrying one JSON message per text frame. ACP payloads (session
7// updates, permission requests) are relayed verbatim so the frontend works
8// with the protocol's own shapes, documented at
9// https://agentclientprotocol.com.
10
11// Incoming message types (browser → server).
12const (
✨ Workspace panel, selectors, previews, desktop app, sandbox template, resizable file tree, light/dark theme 76d62ac k33g yesterday13 // IncomingPrompt starts a turn: {"type":"prompt","text":"...","attachments":[...]}.
✨ Introduce new feature(s): ACP web client — Go backend (agent, bridge, httpserver, mockagent) + React SPA (Zed-like agent panel), tests, quality gate PASS 2434cc7 k33g yesterday14 IncomingPrompt = "prompt"
15 // IncomingCancel interrupts the current turn: {"type":"cancel"}.
16 IncomingCancel = "cancel"
17 // IncomingPermissionResponse answers a permission request:
18 // {"type":"permission_response","requestId":"...","optionId":"..."} or
19 // {"type":"permission_response","requestId":"...","cancelled":true}.
20 IncomingPermissionResponse = "permission_response"
21)
22
23// Outgoing message types (server → browser).
24const (
25 // OutgoingHello is sent once per connection with the session state.
26 OutgoingHello = "hello"
27 // OutgoingUserMessage echoes the prompt that started a turn, so every
28 // client (and every reconnection replay) renders the user's side of the
29 // conversation from the same source of truth as the agent's side.
30 OutgoingUserMessage = "user_message"
31 // OutgoingSessionUpdate relays one ACP session/update notification;
32 // its "update" field is the raw ACP SessionUpdate object.
33 OutgoingSessionUpdate = "session_update"
34 // OutgoingPermissionRequest relays an ACP permission request; its
35 // "request" field is the raw ACP RequestPermissionRequest object.
36 OutgoingPermissionRequest = "permission_request"
37 // OutgoingPermissionResolved tells every client a permission request
38 // was answered (so open dialogs close everywhere).
39 OutgoingPermissionResolved = "permission_resolved"
40 // OutgoingTurnStarted marks the start of a prompt turn.
41 OutgoingTurnStarted = "turn_started"
42 // OutgoingTurnEnded marks the end of a turn, with its stop reason.
43 OutgoingTurnEnded = "turn_ended"
44 // OutgoingError carries a human-readable error message.
45 OutgoingError = "error"
46)
47
✨ Workspace panel, selectors, previews, desktop app, sandbox template, resizable file tree, light/dark theme 76d62ac k33g yesterday48// Attachment is a workspace file the user mentioned in a prompt (with the
49// "@" selector). The server turns it into an ACP resource_link content block
50// so the agent can open the file, while the "@name" mention stays visible in
51// the prompt text.
52type Attachment struct {
53 // Path is the file path, absolute or relative to the workspace root.
54 Path string `json:"path"`
55 // Name is the label shown for the file (the relative path in the UI);
56 // it defaults to Path.
57 Name string `json:"name,omitempty"`
58}
59
✨ Introduce new feature(s): ACP web client — Go backend (agent, bridge, httpserver, mockagent) + React SPA (Zed-like agent panel), tests, quality gate PASS 2434cc7 k33g yesterday60// Incoming is a message sent by the browser.
61type Incoming struct {
62 Type string `json:"type"`
63 // Text is the prompt text (IncomingPrompt).
64 Text string `json:"text,omitempty"`
✨ Workspace panel, selectors, previews, desktop app, sandbox template, resizable file tree, light/dark theme 76d62ac k33g yesterday65 // Attachments are the files mentioned in the prompt (IncomingPrompt).
66 Attachments []Attachment `json:"attachments,omitempty"`
✨ Introduce new feature(s): ACP web client — Go backend (agent, bridge, httpserver, mockagent) + React SPA (Zed-like agent panel), tests, quality gate PASS 2434cc7 k33g yesterday67 // RequestId identifies the permission request being answered.
68 RequestId string `json:"requestId,omitempty"`
69 // OptionId is the chosen ACP permission option.
70 OptionId string `json:"optionId,omitempty"`
71 // Cancelled dismisses the permission request instead of choosing.
72 Cancelled bool `json:"cancelled,omitempty"`
73}
74
75// Outgoing is a message sent to the browser.
76type Outgoing struct {
77 Type string `json:"type"`
78 // SessionId is set on OutgoingHello.
79 SessionId string `json:"sessionId,omitempty"`
80 // TurnActive is set on OutgoingHello: true while a prompt turn runs.
81 TurnActive bool `json:"turnActive,omitempty"`
82 // Update is the raw ACP SessionUpdate (OutgoingSessionUpdate).
83 Update json.RawMessage `json:"update,omitempty"`
84 // RequestId identifies a permission request across messages.
85 RequestId string `json:"requestId,omitempty"`
86 // Request is the raw ACP RequestPermissionRequest (OutgoingPermissionRequest).
87 Request json.RawMessage `json:"request,omitempty"`
88 // Text is the user's prompt text (OutgoingUserMessage).
89 Text string `json:"text,omitempty"`
✨ Workspace panel, selectors, previews, desktop app, sandbox template, resizable file tree, light/dark theme 76d62ac k33g yesterday90 // Attachments are the files the prompt mentioned (OutgoingUserMessage).
91 Attachments []Attachment `json:"attachments,omitempty"`
✨ Introduce new feature(s): ACP web client — Go backend (agent, bridge, httpserver, mockagent) + React SPA (Zed-like agent panel), tests, quality gate PASS 2434cc7 k33g yesterday92 // StopReason is the ACP stop reason (OutgoingTurnEnded).
93 StopReason string `json:"stopReason,omitempty"`
94 // Message is a human-readable error (OutgoingError).
95 Message string `json:"message,omitempty"`
96}
97
98// encode marshals an Outgoing message; the bridge treats a marshalling
99// failure as a programming error and panics, because every field is
100// marshal-safe by construction.
101func encode(msg Outgoing) []byte {
102 raw, err := json.Marshal(msg)
103 if err != nil {
104 panic(err)
105 }
106 return raw
107}