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 ¶
- 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) Subscribe() (<-chan json.RawMessage, func())
- func (b *Bridge) SubscribeStatus() (<-chan string, func())
- type Server
Constants ¶
This section is empty.
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) Subscribe ¶
func (b *Bridge) Subscribe() (<-chan json.RawMessage, func())
Subscribe returns a channel of raw JSON-RPC messages and a cancel function. The cancel function must be called when the subscriber disconnects.
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)