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) LatestUserPromptIndex() int
- func (b *Bridge) Messages() []json.RawMessage
- func (b *Bridge) MessagesForUserPromptIndex(index int) ([]json.RawMessage, bool)
- func (b *Bridge) Run(ctx context.Context)
- func (b *Bridge) SendPrompt(clientID json.RawMessage, prompt []acp.ContentBlock) error
- func (b *Bridge) SessionID() string
- func (b *Bridge) SessionRuntimeInfo() acp.SessionRuntimeInfo
- func (b *Bridge) SetSessionConfigOption(ctx context.Context, configId, value string) (acp.SessionSetConfigOptionResult, error)
- 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())
- func (b *Bridge) UserPromptCount() int
- func (b *Bridge) UserPromptInfos() []UserPromptInfo
- type Server
- type UserPromptInfo
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 ¶
func New(client *acp.Client, sessionId string, verbose bool, outputFile string, autoApprove bool) *Bridge
New creates a Bridge backed by the given ACP client. sessionId must be the id returned by acp.Client.SessionID() after session/new. outputFile, when non-empty, is a path where completed agent messages are appended in acp-posts JSONL format for consumption by the acp-posts Slack integration. autoApprove, when true, automatically approves all permission requests without broadcasting them to the UI (equivalent to always selecting the first option).
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) LatestUserPromptIndex ¶ added in v1.498.0
LatestUserPromptIndex returns the index of the most recent user prompt, or -1 when no user prompt exists yet.
func (*Bridge) Messages ¶ added in v1.390.0
func (b *Bridge) Messages() []json.RawMessage
Messages returns a snapshot of broadcasted JSON-RPC messages from the last user message onward. This keeps GET /messages focused on the current turn, including large tool output produced after the user's most recent prompt.
func (*Bridge) MessagesForUserPromptIndex ¶ added in v1.498.0
func (b *Bridge) MessagesForUserPromptIndex(index int) ([]json.RawMessage, bool)
MessagesForUserPromptIndex returns messages from the given user prompt index up to (but not including) the next user prompt, or the end of history when index is the latest prompt.
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, prompt []acp.ContentBlock) 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) SessionRuntimeInfo ¶ added in v1.470.0
func (b *Bridge) SessionRuntimeInfo() acp.SessionRuntimeInfo
SessionRuntimeInfo returns the runtime information reported by the ACP agent.
func (*Bridge) SetSessionConfigOption ¶ added in v1.471.0
func (b *Bridge) SetSessionConfigOption(ctx context.Context, configId, value string) (acp.SessionSetConfigOptionResult, error)
SetSessionConfigOption forwards a session/set_config_option request to the ACP agent. The result is also emitted as a config_option_update notification so live UI clients observe the same configuration state that the HTTP caller receives.
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.
func (*Bridge) UserPromptCount ¶ added in v1.498.0
UserPromptCount returns the number of user prompts recorded in history.
func (*Bridge) UserPromptInfos ¶ added in v1.498.0
func (b *Bridge) UserPromptInfos() []UserPromptInfo
UserPromptInfos returns metadata for every user prompt in conversation order.
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)
type UserPromptInfo ¶ added in v1.498.0
UserPromptInfo describes one user prompt turn for GET /messages metadata.