bridge

package
v1.378.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package bridge translates between the ACP client and an agentapi-compatible HTTP interface (compatible with takutakahashi/claude-agentapi).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActionRequest

type ActionRequest struct {
	Type     ActionType        `json:"type"`
	Answers  map[string]string `json:"answers,omitempty"`  // answer_question
	Approved *bool             `json:"approved,omitempty"` // approve_plan
}

ActionRequest is the body for POST /action.

type ActionType

type ActionType string

ActionType names a pending action.

const (
	ActionTypeAnswerQuestion ActionType = "answer_question"
	ActionTypeApprovePlan    ActionType = "approve_plan"
	ActionTypeStopAgent      ActionType = "stop_agent"
)

type AgentErrorData

type AgentErrorData struct {
	Level   string    `json:"level"`
	Message string    `json:"message"`
	Time    time.Time `json:"time"`
}

AgentErrorData is the data for agent_error events.

type AgentStatus

type AgentStatus string

AgentStatus mirrors coder/agentapi status values.

const (
	AgentStatusRunning AgentStatus = "running"
	AgentStatusStable  AgentStatus = "stable"
)

type Bridge

type Bridge struct {
	// contains filtered or unexported fields
}

Bridge holds all state for bridging an ACP client to the agentapi HTTP interface.

func New

func New(client *acp.Client, verbose bool) *Bridge

New creates a Bridge backed by the given ACP client.

func (*Bridge) GetMessages

func (b *Bridge) GetMessages() []Message

GetMessages returns the current conversation history.

func (*Bridge) GetPendingActions

func (b *Bridge) GetPendingActions() PendingActionsResponse

GetPendingActions returns the list of actions waiting for a user response.

func (*Bridge) GetStatus

func (b *Bridge) GetStatus() StatusResponse

GetStatus returns the current agent status. AgentType is reported as "claude" so the frontend routes stop_agent via the /action endpoint (which the ACP bridge supports) rather than sending a raw Ctrl-C character (which the ACP bridge does not support).

func (*Bridge) Run

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

Run starts the background goroutines that consume ACP notifications and feed the bridge state. Call this in a goroutine; it blocks until ctx is done. The ctx is stored as the server context for use in background operations (e.g., ACP Prompt calls that outlive the HTTP request that triggered them).

func (*Bridge) SendMessage

func (b *Bridge) SendMessage(ctx context.Context, content string) error

SendMessage posts a user message to the ACP agent. It sets status to "running" immediately and returns; the status reverts to "stable" when the agent finishes (via a goroutine watching the Prompt call).

func (*Bridge) StopAgent

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

StopAgent cancels the current agent turn.

func (*Bridge) SubmitAction

func (b *Bridge) SubmitAction(ctx context.Context, req ActionRequest) error

SubmitAction processes a user response to a pending action.

func (*Bridge) Subscribe

func (b *Bridge) Subscribe() (<-chan Event, func())

Subscribe returns a channel that receives SSE events and a cancel function. On subscription, the subscriber immediately receives replayed events to reconstruct the current state.

type Event

type Event struct {
	Type EventType
	Data interface{}
}

Event is a single SSE event.

type EventType

type EventType string

EventType names the SSE event.

const (
	EventTypeMessageUpdate EventType = "message_update"
	EventTypeStatusChange  EventType = "status_change"
	EventTypeAgentError    EventType = "agent_error"
)

type Message

type Message struct {
	ID              int64       `json:"id"`
	Role            MessageRole `json:"role"`
	Content         string      `json:"content"`
	Time            time.Time   `json:"time"`
	Type            MessageType `json:"type"`
	ToolUseId       string      `json:"toolUseId,omitempty"`
	ParentToolUseId string      `json:"parentToolUseId,omitempty"`
	Status          string      `json:"status,omitempty"` // "success"|"error"
	Error           string      `json:"error,omitempty"`  // present when status=="error"
}

Message is an agentapi-compatible message entry.

type MessageRole

type MessageRole string

MessageRole mirrors takutakahashi/claude-agentapi message roles.

const (
	MessageRoleUser       MessageRole = "user"
	MessageRoleAssistant  MessageRole = "assistant"
	MessageRoleAgent      MessageRole = "agent"
	MessageRoleToolResult MessageRole = "tool_result"
)

type MessageType

type MessageType string

MessageType mirrors takutakahashi/claude-agentapi message types.

const (
	MessageTypeNormal   MessageType = "normal"
	MessageTypeQuestion MessageType = "question"
	MessageTypePlan     MessageType = "plan"
)

type MessageUpdateData

type MessageUpdateData = Message

MessageUpdateData is the data for message_update events. It sends the full Message object (matching takutakahashi/claude-agentapi format). The content key is "content" (not "message") as expected by the frontend.

type PendingAction

type PendingAction struct {
	Type      ActionType  `json:"type"`
	ToolUseId string      `json:"tool_use_id,omitempty"`
	Content   interface{} `json:"content,omitempty"`
}

PendingAction is an action waiting for the HTTP client to respond.

type PendingActionsResponse

type PendingActionsResponse struct {
	PendingActions []PendingAction `json:"pending_actions"`
}

PendingActionsResponse is the body for GET /action.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is an agentapi-compatible HTTP server backed by a Bridge. It exposes the following endpoints (compatible with takutakahashi/claude-agentapi):

GET  /health
GET  /status
GET  /messages
POST /message
GET  /events   (SSE)
GET  /action
POST /action

func NewServer

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

NewServer creates a new HTTP server wrapping 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.

type StatusChangeData

type StatusChangeData struct {
	Status    AgentStatus `json:"status"`
	AgentType string      `json:"agent_type"`
}

StatusChangeData is the data for status_change events.

type StatusResponse

type StatusResponse struct {
	AgentType string      `json:"agent_type"`
	Status    AgentStatus `json:"status"`
	Transport string      `json:"transport"`
}

StatusResponse mirrors coder/agentapi /status response.

Jump to

Keyboard shortcuts

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