bridge

package
v1.394.0 Latest Latest
Warning

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

Go to latest
Published: May 9, 2026 License: MIT Imports: 13 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

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

func New(client *acp.Client, sessionId string, verbose 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.

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) 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

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