acp

package
v0.1.60 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: Apache-2.0 Imports: 19 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package acp implements the Agent Client Protocol transport shared by native harnesses.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Capabilities

func Capabilities() agent.Capabilities

func Configure

func Configure(ctx context.Context, c *Client, session Session, model, mode string) error

func MCPServers

func MCPServers(raw json.RawMessage, env map[string]string) ([]json.RawMessage, error)

MCPServers accepts the canonical named map and existing native ACP arrays.

func Permission

func Permission(req Message, name string) *agent.Interaction

func PermissionReply

func PermissionReply(req Message, in agent.Inbound) (any, error)

func Prompt

func Prompt(in agent.TurnInput, images bool) ([]map[string]any, error)

func Run

func RunSession

func RunSession(ctx context.Context, c *Client, f Flavor, in agent.TurnInput, emit agent.Emit) (agent.TurnResult, error)

func SetModel

func SetModel(ctx context.Context, c *Client, session Session, model string, setup bool) error

SetModel prefers the negotiated stable config-option interface. Older ACP agents expose the model setter alongside their availableModels response.

func Validate

func Validate(in agent.TurnInput) error

Types

type Adapter

type Adapter struct {
	Flavor      Flavor
	Spec        toolchain.Spec
	Entry       agent.CatalogEntry
	Caps        agent.Capabilities
	Schema      agent.SettingsSchema
	AuthFactory func(agent.CredStore) agent.AuthModule
}

Adapter is the common ACP surface. Native differences belong to Flavor, SettingsSchema and AuthFactory, never to a product or the orchestrator.

func (Adapter) Auth

func (a Adapter) Auth(store agent.CredStore) agent.AuthModule

func (Adapter) Capabilities

func (a Adapter) Capabilities() agent.Capabilities

func (Adapter) ConfigPath

func (a Adapter) ConfigPath() string

func (Adapter) Doctor

func (a Adapter) Doctor(ctx context.Context) []agent.Check

func (Adapter) History

func (a Adapter) History(q agent.HistoryQuery) ([]agent.Message, error)

func (Adapter) ID

func (a Adapter) ID() string

func (Adapter) InstallSteps

func (a Adapter) InstallSteps() []agent.Step

func (Adapter) Meta

func (a Adapter) Meta() agent.CatalogEntry

func (Adapter) Models

func (a Adapter) Models(env map[string]string) ([]agent.ModelInfo, error)

func (Adapter) Notifications

func (a Adapter) Notifications() agent.NotificationSpec

func (Adapter) RunStream

func (a Adapter) RunStream(ctx context.Context, in agent.TurnInput, emit agent.Emit) (agent.TurnResult, error)

func (Adapter) Settings

func (a Adapter) Settings() agent.SettingsSchema

func (Adapter) Toolchain

func (a Adapter) Toolchain() toolchain.Spec

func (Adapter) VersionCommand

func (a Adapter) VersionCommand() string

type Client

type Client struct {
	Notifications chan Message
	Requests      chan Message
	// contains filtered or unexported fields
}

func NewClient

func NewClient(in io.WriteCloser, out io.Reader) *Client

func NewClientWithOutput

func NewClientWithOutput(in io.WriteCloser, out io.Reader, output func(string)) *Client

NewClientWithOutput permits a provider's login process to report a URL on a non-protocol stdout line. Payloads are not logged or persisted by the transport.

func (*Client) Call

func (c *Client) Call(ctx context.Context, method string, params any) (json.RawMessage, error)

func (*Client) CallStarted

func (c *Client) CallStarted(ctx context.Context, method string, params any, started chan<- struct{}) (json.RawMessage, error)

CallStarted reports successful submission before the caller may send cancel. Native cancellation cannot overtake its prompt on the shared writer.

func (*Client) Close

func (c *Client) Close()

func (*Client) Notify

func (c *Client) Notify(method string, params any) error

func (*Client) Reject

func (c *Client) Reject(id json.RawMessage, code int, message string) error

func (*Client) Respond

func (c *Client) Respond(id json.RawMessage, result any) error

func (*Client) Setup

func (c *Client) Setup(ctx context.Context, method string, params any) (json.RawMessage, error)

Session setup can replay an arbitrarily long transcript before replying. Consume that replay while awaiting the response, without treating it as output from the new prompt. The reader queues notifications before delivering the response, so draining the remaining queue establishes the prompt boundary.

type ConfigOption

type ConfigOption struct {
	ID           string          `json:"id"`
	Name         string          `json:"name"`
	Category     string          `json:"category,omitempty"`
	Type         string          `json:"type"`
	CurrentValue string          `json:"currentValue"`
	Options      json.RawMessage `json:"options"`
}

type Flavor

type Flavor struct {
	ID, Name, Binary   string
	Args               func(agent.TurnInput) []string
	Validate           func(agent.TurnInput) error
	AuthMethod         func(Initialization, agent.TurnInput) string
	AuthMeta           map[string]any
	NewSessionMeta     func(agent.TurnInput) map[string]any
	ResumeMethod       string
	ResumeLatestMethod string
	Configure          func(context.Context, *Client, Session, agent.TurnInput) error
	Interaction        func(Message) *agent.Interaction
	Reply              func(Message, agent.Inbound) (any, error)
	Update             func(Message, *Stream)
	OnOutput           func(string)
	PromptID           func(json.RawMessage) string
	Completion         func(Message) (string, json.RawMessage)
	PromptMeta         func(agent.TurnInput) map[string]any
	Capabilities       func() agent.Capabilities
}

Flavor contains only provider differences. The shared runtime owns framing, process lifetime, sessions, permissions, streaming and terminal outcomes.

type Initialization

type Initialization struct {
	ProtocolVersion     int                            `json:"protocolVersion"`
	AgentInfo           struct{ Name, Version string } `json:"agentInfo"`
	AuthMethods         []struct{ ID, Name string }    `json:"authMethods"`
	DefaultAuthMethodID string                         `json:"defaultAuthMethodId"`
	Meta                struct {
		DefaultAuthMethodID string `json:"defaultAuthMethodId"`
		AgentVersion        string `json:"agentVersion"`
	} `json:"_meta"`
	AgentCapabilities struct {
		LoadSession         bool                                         `json:"loadSession"`
		PromptCapabilities  struct{ Image, Audio, EmbeddedContext bool } `json:"promptCapabilities"`
		SessionCapabilities struct{ Resume, Fork json.RawMessage }       `json:"sessionCapabilities"`
		MCPCapabilities     struct {
			HTTP bool `json:"http"`
			SSE  bool `json:"sse"`
		} `json:"mcpCapabilities"`
	} `json:"agentCapabilities"`
}

func Initialize

func Initialize(ctx context.Context, c *Client) (Initialization, error)

type Message

type Message struct {
	JSONRPC string          `json:"jsonrpc"`
	ID      json.RawMessage `json:"id"`
	Method  string          `json:"method"`
	Params  json.RawMessage `json:"params"`
	Result  json.RawMessage `json:"result"`
	Error   *RPCError       `json:"error"`
}

type Process

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

Process is one owned native process. Close drains normal termination, then kills only this process group if the provider will not stop after stdin EOF.

func Start

func Start(ctx context.Context, f Flavor, in agent.TurnInput) (*Process, error)

func (*Process) Close

func (p *Process) Close()

type RPCError

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

func (*RPCError) Error

func (e *RPCError) Error() string

type Session

type Session struct {
	ID     string `json:"sessionId"`
	Models struct {
		Current   string `json:"currentModelId"`
		Available []struct {
			ID   string `json:"modelId"`
			Name string `json:"name"`
		} `json:"availableModels"`
	} `json:"models"`
	Modes struct {
		Current   string                      `json:"currentModeId"`
		Available []struct{ ID, Name string } `json:"availableModes"`
	} `json:"modes"`
	ConfigOptions []ConfigOption `json:"configOptions"`
}

func AwaitModelOptions

func AwaitModelOptions(ctx context.Context, c *Client, session Session) (Session, error)

Some agents advertise model options in a notification immediately after the new/resume response. Setup must retain that evidence without replaying text.

type Stream

type Stream struct {
	SessionID string
	Text      string
	Usage     *agent.Usage
	Emit      agent.Emit

	Background agent.TaskTracker
	// contains filtered or unexported fields
}

Stream keeps native tool identity and cumulative partial updates. A running tool update is not a tool result, and omitted fields do not erase earlier data.

func NewStream

func NewStream(id string, emit agent.Emit) *Stream

func (*Stream) Finish

func (s *Stream) Finish(failed bool)

func (*Stream) Task

func (s *Stream) Task(task agent.TaskInfo, start bool)

func (*Stream) Update

func (s *Stream) Update(params json.RawMessage)

Jump to

Keyboard shortcuts

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