acp

package
v0.0.366 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package acp implements the client side of Agent Client Protocol v1.

Index

Constants

View Source
const ProtocolVersion1 = 1

Variables

View Source
var ErrFrameTooLarge = errors.New("ACP frame exceeds maximum size")

Functions

This section is empty.

Types

type AgentCapabilities

type AgentCapabilities struct {
	LoadSession         bool                `json:"loadSession"`
	PromptCapabilities  PromptCapabilities  `json:"promptCapabilities"`
	MCPCapabilities     MCPCapabilities     `json:"mcpCapabilities"`
	SessionCapabilities SessionCapabilities `json:"sessionCapabilities"`
	Meta                json.RawMessage     `json:"_meta,omitempty"`
}

type AuthMethod

type AuthMethod struct {
	ID          string          `json:"id"`
	Name        string          `json:"name"`
	Description string          `json:"description,omitempty"`
	Type        string          `json:"type,omitempty"`
	Meta        json.RawMessage `json:"_meta,omitempty"`
}

type AuthenticateRequest

type AuthenticateRequest struct {
	MethodID string          `json:"methodId"`
	Meta     json.RawMessage `json:"_meta,omitempty"`
}

type CancelSessionRequest

type CancelSessionRequest struct {
	SessionID string          `json:"sessionId"`
	Meta      json.RawMessage `json:"_meta,omitempty"`
}

type Client

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

Client provides typed ACP v1 client operations over a Connection.

func NewClient

func NewClient(conn *Connection) *Client

func (*Client) Authenticate

func (c *Client) Authenticate(ctx context.Context, request AuthenticateRequest) error

func (*Client) CancelSession

func (c *Client) CancelSession(ctx context.Context, sessionID string) error

func (*Client) CloseSession

func (c *Client) CloseSession(ctx context.Context, request CloseSessionRequest) error

func (*Client) Connection

func (c *Client) Connection() *Connection

func (*Client) Initialize

func (c *Client) Initialize(ctx context.Context, request InitializeRequest) (InitializeResponse, error)

func (*Client) LoadSession

func (c *Client) LoadSession(ctx context.Context, request LoadSessionRequest) (LoadSessionResponse, error)

func (*Client) NewSession

func (c *Client) NewSession(ctx context.Context, request NewSessionRequest) (NewSessionResponse, error)

func (*Client) Prompt

func (c *Client) Prompt(ctx context.Context, request PromptRequest) (PromptResponse, error)

func (*Client) ResumeSession

func (c *Client) ResumeSession(ctx context.Context, request ResumeSessionRequest) (ResumeSessionResponse, error)

type ClientCapabilities

type ClientCapabilities struct {
	FileSystem FileSystemCapabilities `json:"fs"`
	Terminal   bool                   `json:"terminal"`
	Meta       json.RawMessage        `json:"_meta,omitempty"`
}

type CloseSessionRequest

type CloseSessionRequest struct {
	SessionID string          `json:"sessionId"`
	Meta      json.RawMessage `json:"_meta,omitempty"`
}

type Connection

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

Connection is a bidirectional ACP v1 JSON-RPC connection. It does not own or close the supplied streams; subprocess owners remain responsible for doing so.

func NewConnection

func NewConnection(reader io.Reader, writer io.Writer, handler Handler, options Options) *Connection

NewConnection starts an ACP connection over newline-delimited JSON streams.

func (*Connection) Call

func (c *Connection) Call(ctx context.Context, method string, params, result any) error

Call invokes an ACP method and decodes its result. Calls may run concurrently.

func (*Connection) Done

func (c *Connection) Done() <-chan struct{}

Done closes when the transport can no longer process messages.

func (*Connection) Err

func (c *Connection) Err() error

Err returns the terminal transport or protocol error, if any.

func (*Connection) Notify

func (c *Connection) Notify(ctx context.Context, method string, params any) error

Notify sends an ACP notification.

type ContentBlock

type ContentBlock struct {
	Type     string          `json:"type"`
	Text     string          `json:"text,omitempty"`
	Data     string          `json:"data,omitempty"`
	MimeType string          `json:"mimeType,omitempty"`
	URI      string          `json:"uri,omitempty"`
	Name     string          `json:"name,omitempty"`
	Resource json.RawMessage `json:"resource,omitempty"`
	Meta     json.RawMessage `json:"_meta,omitempty"`
}

type EnvVariable

type EnvVariable struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

type FileSystemCapabilities

type FileSystemCapabilities struct {
	ReadTextFile  bool `json:"readTextFile"`
	WriteTextFile bool `json:"writeTextFile"`
}

type Handler

type Handler interface {
	HandleNotification(ctx context.Context, method string, params json.RawMessage)
	HandleRequest(ctx context.Context, method string, params json.RawMessage) (any, *RPCError)
}

Handler receives requests and notifications initiated by the ACP agent.

type Header struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

type Implementation

type Implementation struct {
	Name    string `json:"name"`
	Title   string `json:"title,omitempty"`
	Version string `json:"version"`
}

type InitializeRequest

type InitializeRequest struct {
	ProtocolVersion    int                `json:"protocolVersion"`
	ClientCapabilities ClientCapabilities `json:"clientCapabilities"`
	ClientInfo         *Implementation    `json:"clientInfo,omitempty"`
	Meta               json.RawMessage    `json:"_meta,omitempty"`
}

type InitializeResponse

type InitializeResponse struct {
	ProtocolVersion   int               `json:"protocolVersion"`
	AgentCapabilities AgentCapabilities `json:"agentCapabilities"`
	AuthMethods       []AuthMethod      `json:"authMethods"`
	AgentInfo         *Implementation   `json:"agentInfo,omitempty"`
	Meta              json.RawMessage   `json:"_meta,omitempty"`
}

type LoadSessionRequest

type LoadSessionRequest struct {
	SessionID             string          `json:"sessionId"`
	CWD                   string          `json:"cwd"`
	MCPServers            []MCPServer     `json:"mcpServers"`
	AdditionalDirectories []string        `json:"additionalDirectories,omitempty"`
	Meta                  json.RawMessage `json:"_meta,omitempty"`
}

type LoadSessionResponse

type LoadSessionResponse struct {
	Modes         json.RawMessage `json:"modes,omitempty"`
	ConfigOptions json.RawMessage `json:"configOptions,omitempty"`
	Meta          json.RawMessage `json:"_meta,omitempty"`
}

type MCPCapabilities

type MCPCapabilities struct {
	HTTP bool `json:"http"`
	SSE  bool `json:"sse"`
}

type MCPServer

type MCPServer struct {
	Type    string        `json:"type,omitempty"`
	Name    string        `json:"name"`
	Command string        `json:"command,omitempty"`
	Args    []string      `json:"args,omitempty"`
	Env     []EnvVariable `json:"env,omitempty"`
	URL     string        `json:"url,omitempty"`
	Headers []Header      `json:"headers,omitempty"`
}

MCPServer represents either the baseline stdio transport or a capability- gated HTTP/SSE transport.

type NewSessionRequest

type NewSessionRequest struct {
	CWD                   string          `json:"cwd"`
	MCPServers            []MCPServer     `json:"mcpServers"`
	AdditionalDirectories []string        `json:"additionalDirectories,omitempty"`
	Meta                  json.RawMessage `json:"_meta,omitempty"`
}

type NewSessionResponse

type NewSessionResponse struct {
	SessionID     string          `json:"sessionId"`
	Modes         json.RawMessage `json:"modes,omitempty"`
	ConfigOptions json.RawMessage `json:"configOptions,omitempty"`
	Meta          json.RawMessage `json:"_meta,omitempty"`
}

type Options

type Options struct {
	MaxFrameBytes int
}

Options configures a Connection.

type PromptCapabilities

type PromptCapabilities struct {
	Image           bool `json:"image"`
	Audio           bool `json:"audio"`
	EmbeddedContext bool `json:"embeddedContext"`
}

type PromptRequest

type PromptRequest struct {
	SessionID string          `json:"sessionId"`
	Prompt    []ContentBlock  `json:"prompt"`
	Meta      json.RawMessage `json:"_meta,omitempty"`
}

type PromptResponse

type PromptResponse struct {
	StopReason string          `json:"stopReason"`
	Meta       json.RawMessage `json:"_meta,omitempty"`
}

type RPCError

type RPCError struct {
	Code    int             `json:"code"`
	Message string          `json:"message"`
	Data    json.RawMessage `json:"data,omitempty"`
}

RPCError is a JSON-RPC error returned by either ACP endpoint.

func MethodNotFound

func MethodNotFound(method string) *RPCError

MethodNotFound creates the standard JSON-RPC method-not-found response.

func (*RPCError) Error

func (e *RPCError) Error() string

type ResumeSessionRequest

type ResumeSessionRequest = LoadSessionRequest

type ResumeSessionResponse

type ResumeSessionResponse = LoadSessionResponse

type SessionCapabilities

type SessionCapabilities struct {
	Resume                json.RawMessage `json:"resume,omitempty"`
	Close                 json.RawMessage `json:"close,omitempty"`
	List                  json.RawMessage `json:"list,omitempty"`
	Delete                json.RawMessage `json:"delete,omitempty"`
	AdditionalDirectories json.RawMessage `json:"additionalDirectories,omitempty"`
}

func (SessionCapabilities) SupportsClose

func (c SessionCapabilities) SupportsClose() bool

func (SessionCapabilities) SupportsResume

func (c SessionCapabilities) SupportsResume() bool

Jump to

Keyboard shortcuts

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