Documentation
¶
Overview ¶
Package bridge provides a minimal HTTP transport layer for the Agent Client Protocol (ACP). Instead of translating ACP messages to a proprietary format, it relays JSON-RPC 2.0 messages directly over HTTP: POST /rpc (client→agent) and GET /sse (agent→client).
Index ¶
- Constants
- type Bridge
- func (b *Bridge) Cancel(ctx context.Context) error
- func (b *Bridge) HandleReply(id int64, result json.RawMessage) error
- func (b *Bridge) Messages() []json.RawMessage
- func (b *Bridge) Run(ctx context.Context)
- func (b *Bridge) SendPrompt(clientID json.RawMessage, text string) error
- func (b *Bridge) SessionID() string
- func (b *Bridge) Status() string
- func (b *Bridge) SubscribeFrom(lastEventID int) (<-chan json.RawMessage, []json.RawMessage, int, func())
- func (b *Bridge) SubscribeStatus() (<-chan string, func())
- type Server
Constants ¶
const SubscribeFromCurrent = -2
SubscribeFromCurrent is a sentinel value for SubscribeFrom that means "subscribe from the current position without replaying any history". Use this when the caller obtains history separately (e.g. GET /messages).
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bridge ¶
type Bridge struct {
// contains filtered or unexported fields
}
Bridge connects an ACP client to HTTP SSE subscribers via raw JSON-RPC 2.0 messages. It does not translate ACP semantics – it reconstructs JSON-RPC envelopes from the parsed events that acp.Client exposes and broadcasts them to subscribers.
func New ¶
New creates a Bridge backed by the given ACP client. sessionId must be the id returned by acp.Client.SessionID() after session/new.
func (*Bridge) HandleReply ¶ added in v1.390.0
func (b *Bridge) HandleReply(id int64, result json.RawMessage) error
HandleReply routes a JSON-RPC result from the HTTP client to a pending agent-initiated request (e.g. session/request_permission). id is the integer id the bridge assigned when it emitted the agent request.
func (*Bridge) Messages ¶ added in v1.390.0
func (b *Bridge) Messages() []json.RawMessage
Messages returns a snapshot of all broadcasted JSON-RPC messages since the bridge started. Callers can use this to replay history for reconnecting clients.
func (*Bridge) Run ¶
Run starts the event loop. It blocks until ctx is cancelled. Call this in a goroutine before starting the HTTP server.
func (*Bridge) SendPrompt ¶ added in v1.390.0
func (b *Bridge) SendPrompt(clientID json.RawMessage, text string) error
SendPrompt sends a session/prompt request to the ACP agent. clientID is the raw JSON-RPC id from the HTTP client; the result (or error) is emitted via SSE with that same id so the client can correlate the response.
func (*Bridge) Status ¶ added in v1.392.0
Status returns the current agent status ("running" or "stable").
func (*Bridge) SubscribeFrom ¶ added in v1.397.0
func (b *Bridge) SubscribeFrom(lastEventID int) (<-chan json.RawMessage, []json.RawMessage, int, func())
SubscribeFrom subscribes to new messages and atomically returns a snapshot of history starting from lastEventID+1. This prevents race conditions where messages could be missed between fetching history and subscribing to the live channel.
Pass SubscribeFromCurrent as lastEventID to subscribe from the current position without replaying any history (useful when history is fetched via GET /messages).
Callers must invoke the returned cancel function when done. The returned nextIdx is the history index that the first channel message will have.
func (*Bridge) SubscribeStatus ¶ added in v1.392.0
SubscribeStatus returns a channel that receives status strings whenever the agent status changes, and a cancel function that must be called on disconnect.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is a minimal HTTP transport for ACP. It exposes three endpoints that mirror the ACP JSON-RPC 2.0 protocol over HTTP:
GET /session – session info (sessionId, status) POST /rpc – JSON-RPC 2.0 messages from HTTP client to ACP agent GET /sse – SSE stream of JSON-RPC 2.0 messages from ACP agent to HTTP client GET /health – health check (for compatibility)