bridge

package
v1.467.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 12, 2026 License: MIT Imports: 15 Imported by: 0

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

View Source
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) Cancel added in v1.390.0

func (b *Bridge) Cancel(ctx context.Context) error

Cancel cancels the current agent turn.

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

func (b *Bridge) Run(ctx context.Context)

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) SessionID added in v1.390.0

func (b *Bridge) SessionID() string

SessionID returns the ACP session ID.

func (*Bridge) Status added in v1.392.0

func (b *Bridge) Status() string

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

func (b *Bridge) SubscribeStatus() (<-chan string, func())

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)

func NewServer

func NewServer(b *Bridge, verbose bool) *Server

NewServer creates a new HTTP transport server backed by the given Bridge.

func (*Server) Start

func (s *Server) Start(ctx context.Context, addr string) error

Start starts the HTTP server on the given address (e.g. ":3284"). It blocks until ctx is cancelled.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL