acputil

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 19 Imported by: ? 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

Index

Constants

View Source
const (
	// Frame the connection cannot take as a request, such as one longer than its line limit
	CodeInvalidRequest = -32600
	// Request for a method the peer does not serve, or an unstable one it was not opened for
	CodeMethodNotFound = -32601
	// Request whose params do not decode into the method's request type
	CodeInvalidParams = -32602
	// Failure inside the handler of a request
	CodeInternalError = -32603
)

JSON-RPC error codes the connection and router answer with

View Source
const (
	// Request opening the connection: protocol version and capabilities
	MethodInitialize = "initialize"
	// Request running one of the auth methods initialize advertised
	MethodAuthenticate = "authenticate"
	// Request creating a session
	MethodSessionNew = "session/new"
	// Request loading a session and replaying its history
	MethodSessionLoad = "session/load"
	// Request listing sessions
	MethodSessionList = "session/list"
	// Request closing a session, part of the unstable protocol
	MethodSessionClose = "session/close"
	// Request forking a session, part of the unstable protocol
	MethodSessionFork = "session/fork"
	// Request resuming a session without replaying its history, part of the unstable protocol
	MethodSessionResume = "session/resume"
	// Request running one prompt turn
	MethodSessionPrompt = "session/prompt"
	// Notification cancelling the running prompt turn
	MethodSessionCancel = "session/cancel"
	// Request switching the session mode
	MethodSessionSetMode = "session/set_mode"
	// Request switching the session model, part of the unstable protocol
	MethodSessionSetModel = "session/set_model"
	// Request setting a session config option
	MethodSessionSetConfigOption = "session/set_config_option"
)

Methods an agent serves

View Source
const (
	// Notification reporting a session update
	MethodSessionUpdate = "session/update"
	// Request asking the user to permit a tool call
	MethodSessionRequestPermission = "session/request_permission"
	// Request reading a text file through the client
	MethodFSReadTextFile = "fs/read_text_file"
	// Request writing a text file through the client
	MethodFSWriteTextFile = "fs/write_text_file"
	// Request starting a command in a client terminal
	MethodTerminalCreate = "terminal/create"
	// Request reading the output of a client terminal
	MethodTerminalOutput = "terminal/output"
	// Request releasing a client terminal
	MethodTerminalRelease = "terminal/release"
	// Request waiting for the command of a client terminal to exit
	MethodTerminalWaitForExit = "terminal/wait_for_exit"
	// Request killing the command of a client terminal
	MethodTerminalKill = "terminal/kill"
)

Methods a client serves

View Source
const DefaultLineLimit = 50 << 20

Line limit a connection starts with, 50 MiB so prompts carrying images fit in one frame

View Source
const DefaultShutdownGrace = 5 * time.Second

Time RunAgent gives running handlers to return once it has closed the connection, unless ShutdownGrace sets another

View Source
const ProtocolVersion = 1

Protocol version this package speaks

Variables

View Source
var ErrConnectionClosed = errors.New("acp connection closed")

Reported by requests on a connection that is closed or whose input ended, and wrapped around the reason the input ended

View Source
var ErrFrameTooLong = errors.New("acp frame longer than the line limit")

Reported, wrapped with the limit, by a request whose reply was longer than the connection's line limit, and given as the reason a request that long was refused

Functions

func AfterResponse

func AfterResponse(ctx context.Context, fn func())

Runs fn on its own goroutine once the reply of the request ctx belongs to is written, at once when ctx belongs to no request

func RunAgent

func RunAgent(ctx context.Context, agent any, w io.Writer, r io.Reader, opts ...Option) error

Serves agent on w and r, standard output and input for nil ones, until the client's input ends, reading fails or ctx is done; then closes the connection, which cancels every handler's context, and waits up to the shutdown grace for running handlers to return: any still running after it are logged, named in the error and left to finish on their own

func WithResponseScope

func WithResponseScope(ctx context.Context) (context.Context, func())

Request scope under ctx and the flush that runs what AfterResponse scheduled in it; a scope never flushed holds its callbacks back

Types

type AgentCapabilities

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

What an agent supports: loading sessions, MCP transports, prompt content and session methods

type AgentMessageChunk

type AgentMessageChunk struct {
	Meta      *jsonutil.Object `json:"_meta,omitempty"`
	Content   ContentBlock     `json:"content"`
	MessageID *string          `json:"messageId,omitempty"`
}

Chunk of the agent's reply

func UpdateAgentMessageText

func UpdateAgentMessageText(text string) *AgentMessageChunk

Agent message chunk of plain text

func (AgentMessageChunk) MarshalJSON

func (c AgentMessageChunk) MarshalJSON() ([]byte, error)

JSON object of the chunk with sessionUpdate "agent_message_chunk"

func (*AgentMessageChunk) UnmarshalJSON

func (c *AgentMessageChunk) UnmarshalJSON(data []byte) error

Fills the chunk from its JSON object, which must carry content

type AgentPlanUpdate

type AgentPlanUpdate struct {
	Meta    *jsonutil.Object `json:"_meta,omitempty"`
	Entries []PlanEntry      `json:"entries"`
}

The agent's whole plan, replacing the one reported before

func UpdatePlan

func UpdatePlan(entries []PlanEntry) *AgentPlanUpdate

Plan update of the given entries

func (AgentPlanUpdate) MarshalJSON

func (u AgentPlanUpdate) MarshalJSON() ([]byte, error)

JSON object of the plan with sessionUpdate "plan"

func (*AgentPlanUpdate) UnmarshalJSON

func (u *AgentPlanUpdate) UnmarshalJSON(data []byte) error

Fills the plan from its JSON object, which must carry entries

type AgentSideConnection

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

Agent end of a connection: serves the agent's methods and makes the calls an agent makes to its client

func NewAgentSideConnection

func NewAgentSideConnection(agent any, w io.Writer, r io.Reader, opts ...Option) *AgentSideConnection

Connection serving agent over r and w, its OnConnect hook called before any frame is read

func (*AgentSideConnection) Close

func (c *AgentSideConnection) Close() error

Closes the underlying connection without waiting for running handlers, so a handler may call it

func (*AgentSideConnection) Conn

func (c *AgentSideConnection) Conn() *Connection

Underlying JSON-RPC connection

func (*AgentSideConnection) CreateTerminal

Starts a command in a client terminal

func (*AgentSideConnection) ExtMethod

func (c *AgentSideConnection) ExtMethod(ctx context.Context, name string, params any) (any, error)

Sends the extension request "_" + name and waits for its result, decoded with objects as *jsonutil.Object

func (*AgentSideConnection) ExtNotification

func (c *AgentSideConnection) ExtNotification(ctx context.Context, name string, params any) error

Sends the extension notification "_" + name

func (*AgentSideConnection) KillTerminal

func (c *AgentSideConnection) KillTerminal(ctx context.Context, sessionID, terminalID string, meta *jsonutil.Object) (*KillTerminalResponse, error)

Kills the command of a client terminal, nil when its result is not an object

func (*AgentSideConnection) Listen

func (c *AgentSideConnection) Listen(ctx context.Context) error

Serves the client until its input ends, reading fails or ctx is done

func (*AgentSideConnection) ReadTextFile

func (c *AgentSideConnection) ReadTextFile(ctx context.Context, path, sessionID string, limit, line *int, meta *jsonutil.Object) (*ReadTextFileResponse, error)

Reads a text file through the client, from line and at most limit lines when they are set

func (*AgentSideConnection) ReleaseTerminal

func (c *AgentSideConnection) ReleaseTerminal(ctx context.Context, sessionID, terminalID string, meta *jsonutil.Object) (*ReleaseTerminalResponse, error)

Releases a client terminal, nil when its result is not an object

func (*AgentSideConnection) RequestPermission

func (c *AgentSideConnection) RequestPermission(ctx context.Context, options []PermissionOption, sessionID string, toolCall *ToolCallUpdate, meta *jsonutil.Object) (*RequestPermissionResponse, error)

Asks the client to have the user choose one of the options for a tool call

func (*AgentSideConnection) SessionUpdate

func (c *AgentSideConnection) SessionUpdate(ctx context.Context, sessionID string, update SessionUpdate, meta *jsonutil.Object) error

Sends a session/update notification

func (*AgentSideConnection) TerminalOutput

func (c *AgentSideConnection) TerminalOutput(ctx context.Context, sessionID, terminalID string, meta *jsonutil.Object) (*TerminalOutputResponse, error)

Output of a client terminal so far

func (*AgentSideConnection) WaitForTerminalExit

func (c *AgentSideConnection) WaitForTerminalExit(ctx context.Context, sessionID, terminalID string, meta *jsonutil.Object) (*WaitForTerminalExitResponse, error)

Waits for the command of a client terminal to exit

func (*AgentSideConnection) WriteTextFile

func (c *AgentSideConnection) WriteTextFile(ctx context.Context, content, path, sessionID string, meta *jsonutil.Object) (*WriteTextFileResponse, error)

Writes a text file through the client, nil when its result is not an object

type AgentThoughtChunk

type AgentThoughtChunk struct {
	Meta      *jsonutil.Object `json:"_meta,omitempty"`
	Content   ContentBlock     `json:"content"`
	MessageID *string          `json:"messageId,omitempty"`
}

Chunk of the agent's reasoning

func UpdateAgentThoughtText

func UpdateAgentThoughtText(text string) *AgentThoughtChunk

Agent thought chunk of plain text

func (AgentThoughtChunk) MarshalJSON

func (c AgentThoughtChunk) MarshalJSON() ([]byte, error)

JSON object of the chunk with sessionUpdate "agent_thought_chunk"

func (*AgentThoughtChunk) UnmarshalJSON

func (c *AgentThoughtChunk) UnmarshalJSON(data []byte) error

Fills the chunk from its JSON object, which must carry content

type AllowedOutcome

type AllowedOutcome struct {
	Meta     *jsonutil.Object `json:"_meta,omitempty"`
	OptionID string           `json:"optionId"`
}

Outcome naming the option the user selected

func (AllowedOutcome) MarshalJSON

func (o AllowedOutcome) MarshalJSON() ([]byte, error)

JSON object of the outcome with outcome "selected"

func (*AllowedOutcome) UnmarshalJSON

func (o *AllowedOutcome) UnmarshalJSON(data []byte) error

Fills the outcome from its JSON object, which must carry optionId

type Annotations

type Annotations struct {
	Meta *jsonutil.Object `json:"_meta,omitempty"`
	// Roles the content is meant for, assistant or user
	Audience     []string `json:"audience,omitzero"`
	LastModified *string  `json:"lastModified,omitempty"`
	Priority     *float64 `json:"priority,omitempty"`
}

Audience, priority and modification time hints of a content block

type AudioContentBlock

type AudioContentBlock struct {
	Meta        *jsonutil.Object `json:"_meta,omitempty"`
	Annotations *Annotations     `json:"annotations,omitempty"`
	Data        string           `json:"data"`
	MimeType    string           `json:"mimeType"`
}

Base64 audio data with its MIME type

func (AudioContentBlock) MarshalJSON

func (b AudioContentBlock) MarshalJSON() ([]byte, error)

JSON object of the block with type "audio"

func (*AudioContentBlock) UnmarshalJSON

func (b *AudioContentBlock) UnmarshalJSON(data []byte) error

Fills the block from its JSON object, which must carry data and mimeType

type AuthCapabilities

type AuthCapabilities struct {
	Meta     *jsonutil.Object `json:"_meta,omitempty"`
	Terminal *bool            `json:"terminal,omitempty"`
}

Auth features a client supports

type AuthEnvVar

type AuthEnvVar struct {
	Meta     *jsonutil.Object `json:"_meta,omitempty"`
	Label    *string          `json:"label,omitempty"`
	Name     string           `json:"name"`
	Optional *bool            `json:"optional,omitempty"`
	Secret   *bool            `json:"secret,omitempty"`
}

Environment variable an env var sign-in sets

func (*AuthEnvVar) UnmarshalJSON

func (v *AuthEnvVar) UnmarshalJSON(data []byte) error

Fills the variable from its JSON object, which must carry name

type AuthMethod

type AuthMethod interface {
	// contains filtered or unexported methods
}

Way a user signs in to the agent: *AuthMethodAgent, *EnvVarAuthMethod or *TerminalAuthMethod

type AuthMethodAgent

type AuthMethodAgent struct {
	Meta        *jsonutil.Object `json:"_meta,omitempty"`
	Description *string          `json:"description,omitempty"`
	ID          string           `json:"id"`
	Name        string           `json:"name"`
}

Sign-in the agent runs itself when the client calls authenticate

func (*AuthMethodAgent) UnmarshalJSON

func (m *AuthMethodAgent) UnmarshalJSON(data []byte) error

Fills the method from its JSON object, which must carry id and name

type AuthenticateRequest

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

Params of authenticate: the auth method to run

func (*AuthenticateRequest) UnmarshalJSON

func (r *AuthenticateRequest) UnmarshalJSON(data []byte) error

Fills the request from its JSON object, which must carry methodId

type AuthenticateResponse

type AuthenticateResponse struct {
	Meta *jsonutil.Object `json:"_meta,omitempty"`
}

Result of authenticate

type Authenticator

type Authenticator interface {
	Authenticate(ctx context.Context, req *AuthenticateRequest) (*AuthenticateResponse, error)
}

Agent method answering authenticate, a nil response sent as an empty object

type AvailableCommand

type AvailableCommand struct {
	Meta        *jsonutil.Object          `json:"_meta,omitempty"`
	Description string                    `json:"description"`
	Input       *UnstructuredCommandInput `json:"input,omitempty"`
	Name        string                    `json:"name"`
}

Slash command the agent offers

func (*AvailableCommand) UnmarshalJSON

func (c *AvailableCommand) UnmarshalJSON(data []byte) error

Fills the command from its JSON object, which must carry description and name

type AvailableCommandsUpdate

type AvailableCommandsUpdate struct {
	Meta              *jsonutil.Object   `json:"_meta,omitempty"`
	AvailableCommands []AvailableCommand `json:"availableCommands"`
}

Commands the agent offers in the session, replacing those reported before

func (AvailableCommandsUpdate) MarshalJSON

func (u AvailableCommandsUpdate) MarshalJSON() ([]byte, error)

JSON object of the commands with sessionUpdate "available_commands_update"

func (*AvailableCommandsUpdate) UnmarshalJSON

func (u *AvailableCommandsUpdate) UnmarshalJSON(data []byte) error

Fills the update from its JSON object, which must carry availableCommands

type BlobResourceContents

type BlobResourceContents struct {
	Meta     *jsonutil.Object `json:"_meta,omitempty"`
	Blob     string           `json:"blob"`
	MimeType *string          `json:"mimeType,omitempty"`
	URI      string           `json:"uri"`
}

Base64 binary contents of a resource

func (*BlobResourceContents) UnmarshalJSON

func (r *BlobResourceContents) UnmarshalJSON(data []byte) error

Fills the contents from their JSON object, which must carry blob and uri

type CancelNotification

type CancelNotification struct {
	Meta      *jsonutil.Object `json:"_meta,omitempty"`
	SessionID string           `json:"sessionId"`
}

Params of session/cancel

func (*CancelNotification) UnmarshalJSON

func (n *CancelNotification) UnmarshalJSON(data []byte) error

Fills the notification from its JSON object, which must carry sessionId

type Canceller

type Canceller interface {
	Cancel(ctx context.Context, req *CancelNotification) error
}

Agent method receiving session/cancel

type ClientCapabilities

type ClientCapabilities struct {
	Meta     *jsonutil.Object        `json:"_meta,omitempty"`
	Auth     *AuthCapabilities       `json:"auth,omitempty"`
	FS       *FileSystemCapabilities `json:"fs,omitempty"`
	Terminal *bool                   `json:"terminal,omitempty"`
}

What a client supports: auth, file system and terminal calls

type CloseSessionRequest

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

Params of session/close

func (*CloseSessionRequest) UnmarshalJSON

func (r *CloseSessionRequest) UnmarshalJSON(data []byte) error

Fills the request from its JSON object, which must carry sessionId

type CloseSessionResponse

type CloseSessionResponse struct {
	Meta *jsonutil.Object `json:"_meta,omitempty"`
}

Result of session/close

type ConfigOptionSetter

type ConfigOptionSetter interface {
	SetConfigOption(ctx context.Context, req *SetConfigOptionParams) (*SetSessionConfigOptionResponse, error)
}

Agent method answering session/set_config_option for boolean and select options alike, a nil response sent as an empty object

type ConfigOptionUpdate

type ConfigOptionUpdate struct {
	Meta          *jsonutil.Object      `json:"_meta,omitempty"`
	ConfigOptions []SessionConfigOption `json:"configOptions"`
}

Every config option of the session after one of them changed

func (ConfigOptionUpdate) MarshalJSON

func (u ConfigOptionUpdate) MarshalJSON() ([]byte, error)

JSON object of the update with sessionUpdate "config_option_update"

func (*ConfigOptionUpdate) UnmarshalJSON

func (u *ConfigOptionUpdate) UnmarshalJSON(data []byte) error

Fills the update from its JSON object, which must carry configOptions

type Connection

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

JSON-RPC 2.0 connection exchanging one JSON object per line; safe for concurrent use

func NewConnection

func NewConnection(handler Handler, w io.Writer, r io.Reader, opts ...Option) *Connection

Connection calling handler for the frames it reads from r and writing its own frames to w; frames are read once Serve runs

func (*Connection) AddObserver

func (c *Connection) AddObserver(observer StreamObserver)

Registers a callback that receives every frame read or written from now on

func (*Connection) Close

func (c *Connection) Close() error

Stops the connection at once: no further frame is read or handled, every handler's context is cancelled and every request waiting for a reply fails with ErrConnectionClosed; it does not wait for running handlers, so any goroutine may call it, a handler included, and Shutdown is the call that waits

func (*Connection) SendNotification

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

Sends a notification

func (*Connection) SendRequest

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

Sends a request and waits for its result, decoded with objects as *jsonutil.Object; a *RequestError when the peer answers with an error

func (*Connection) Serve

func (c *Connection) Serve(ctx context.Context) error

Reads and dispatches frames until the input ends, reading fails, ctx is done or the connection closes, then fails the requests still waiting for a reply; nil at the end of the input. Handlers still running go on: Close cancels them, Shutdown also waits for them. A reader blocked in Read keeps the goroutine reading it until that Read returns

func (*Connection) Shutdown

func (c *Connection) Shutdown(ctx context.Context) error

Closes the connection, then waits until every running handler has returned or ctx is done; handlers still running then are logged by method and run time, named in the error, which wraps ctx's, and left to finish on their own. A handler calls Close instead: Shutdown would wait for that handler itself

type Connector

type Connector interface {
	OnConnect(conn *AgentSideConnection)
}

Agent hook given the connection it is served on before any frame is read

type ContentBlock

type ContentBlock interface {
	// contains filtered or unexported methods
}

Content of a prompt, a message chunk or a tool call: *TextContentBlock, *ImageContentBlock, *AudioContentBlock, *ResourceContentBlock or *EmbeddedResourceContentBlock

type ContentToolCallContent

type ContentToolCallContent struct {
	Meta    *jsonutil.Object `json:"_meta,omitempty"`
	Content ContentBlock     `json:"content"`
}

Content block a tool call shows

func ToolContent

func ToolContent(block ContentBlock) *ContentToolCallContent

Tool call content showing a content block

func (ContentToolCallContent) MarshalJSON

func (c ContentToolCallContent) MarshalJSON() ([]byte, error)

JSON object of the content with type "content"

func (*ContentToolCallContent) UnmarshalJSON

func (c *ContentToolCallContent) UnmarshalJSON(data []byte) error

Fills the content from its JSON object, which must carry content

type Cost

type Cost struct {
	Amount   float64 `json:"amount"`
	Currency string  `json:"currency"`
}

Amount of money in a currency

func (*Cost) UnmarshalJSON

func (c *Cost) UnmarshalJSON(data []byte) error

Fills the cost from its JSON object, which must carry amount and currency

type CreateTerminalRequest

type CreateTerminalRequest struct {
	Meta    *jsonutil.Object `json:"_meta,omitempty"`
	Args    []string         `json:"args,omitzero"`
	Command string           `json:"command"`
	Cwd     *string          `json:"cwd,omitempty"`
	Env     []EnvVariable    `json:"env,omitzero"`
	// Most output bytes the client keeps, the oldest dropped first
	OutputByteLimit *int   `json:"outputByteLimit,omitempty"`
	SessionID       string `json:"sessionId"`
}

Params of terminal/create: the command to run in a client terminal

func (*CreateTerminalRequest) UnmarshalJSON

func (r *CreateTerminalRequest) UnmarshalJSON(data []byte) error

Fills the request from its JSON object, which must carry command and sessionId

type CreateTerminalResponse

type CreateTerminalResponse struct {
	Meta       *jsonutil.Object `json:"_meta,omitempty"`
	TerminalID string           `json:"terminalId"`
}

Result of terminal/create

func (*CreateTerminalResponse) UnmarshalJSON

func (r *CreateTerminalResponse) UnmarshalJSON(data []byte) error

Fills the response from its JSON object, which must carry terminalId

type CurrentModeUpdate

type CurrentModeUpdate struct {
	Meta          *jsonutil.Object `json:"_meta,omitempty"`
	CurrentModeID string           `json:"currentModeId"`
}

Mode the session switched to

func (CurrentModeUpdate) MarshalJSON

func (u CurrentModeUpdate) MarshalJSON() ([]byte, error)

JSON object of the update with sessionUpdate "current_mode_update"

func (*CurrentModeUpdate) UnmarshalJSON

func (u *CurrentModeUpdate) UnmarshalJSON(data []byte) error

Fills the update from its JSON object, which must carry currentModeId

type DeniedOutcome

type DeniedOutcome struct{}

Outcome of a request the cancellation of the prompt turn ended

func (DeniedOutcome) MarshalJSON

func (o DeniedOutcome) MarshalJSON() ([]byte, error)

JSON object of the outcome with outcome "cancelled"

type EmbeddedResourceContentBlock

type EmbeddedResourceContentBlock struct {
	Meta        *jsonutil.Object `json:"_meta,omitempty"`
	Annotations *Annotations     `json:"annotations,omitempty"`
	Resource    ResourceContents `json:"resource"`
}

Resource whose contents travel inside the message

func (EmbeddedResourceContentBlock) MarshalJSON

func (b EmbeddedResourceContentBlock) MarshalJSON() ([]byte, error)

JSON object of the block with type "resource"

func (*EmbeddedResourceContentBlock) UnmarshalJSON

func (b *EmbeddedResourceContentBlock) UnmarshalJSON(data []byte) error

Fills the block from its JSON object, which must carry resource, decoded by whether it holds text or blob

type EnvVarAuthMethod

type EnvVarAuthMethod struct {
	Meta        *jsonutil.Object `json:"_meta,omitempty"`
	Description *string          `json:"description,omitempty"`
	ID          string           `json:"id"`
	Link        *string          `json:"link,omitempty"`
	Name        string           `json:"name"`
	Vars        []AuthEnvVar     `json:"vars"`
}

Sign-in through environment variables the client sets before starting the agent

func (EnvVarAuthMethod) MarshalJSON

func (m EnvVarAuthMethod) MarshalJSON() ([]byte, error)

JSON object of the method with type "env_var"

func (*EnvVarAuthMethod) UnmarshalJSON

func (m *EnvVarAuthMethod) UnmarshalJSON(data []byte) error

Fills the method from its JSON object, which must carry id, name and vars

type EnvVariable

type EnvVariable struct {
	Meta  *jsonutil.Object `json:"_meta,omitempty"`
	Name  string           `json:"name"`
	Value string           `json:"value"`
}

Environment variable of a command

func (*EnvVariable) UnmarshalJSON

func (v *EnvVariable) UnmarshalJSON(data []byte) error

Fills the variable from its JSON object, which must carry name and value

type ExtensionMethodHandler

type ExtensionMethodHandler interface {
	ExtMethod(ctx context.Context, name string, params json.RawMessage) (any, error)
}

Agent method answering extension requests, those whose method starts with an underscore, given the name after it and the params object

type ExtensionNotificationHandler

type ExtensionNotificationHandler interface {
	ExtNotification(ctx context.Context, name string, params json.RawMessage) error
}

Agent method receiving extension notifications, given the name after the underscore and the params object

type FileEditToolCallContent

type FileEditToolCallContent struct {
	Meta    *jsonutil.Object `json:"_meta,omitempty"`
	NewText string           `json:"newText"`
	OldText *string          `json:"oldText,omitempty"`
	Path    string           `json:"path"`
}

File edit a tool call makes: the new text and, for a file that exists, the old text

func ToolDiffContent

func ToolDiffContent(path, newText string, oldText *string) *FileEditToolCallContent

Diff tool call content of a file, the old text left out when nil

func (FileEditToolCallContent) MarshalJSON

func (c FileEditToolCallContent) MarshalJSON() ([]byte, error)

JSON object of the edit with type "diff"

func (*FileEditToolCallContent) UnmarshalJSON

func (c *FileEditToolCallContent) UnmarshalJSON(data []byte) error

Fills the edit from its JSON object, which must carry newText and path

type FileSystemCapabilities

type FileSystemCapabilities struct {
	Meta          *jsonutil.Object `json:"_meta,omitempty"`
	ReadTextFile  *bool            `json:"readTextFile,omitempty"`
	WriteTextFile *bool            `json:"writeTextFile,omitempty"`
}

File system calls a client serves

type ForkSessionRequest

type ForkSessionRequest struct {
	Meta       *jsonutil.Object `json:"_meta,omitempty"`
	Cwd        string           `json:"cwd"`
	MCPServers []MCPServer      `json:"mcpServers,omitzero"`
	SessionID  string           `json:"sessionId"`
}

Params of session/fork: the session to fork, the working directory and the MCP servers the client offers

func (*ForkSessionRequest) UnmarshalJSON

func (r *ForkSessionRequest) UnmarshalJSON(data []byte) error

Fills the request from its JSON object, which must carry cwd and sessionId

type ForkSessionResponse

type ForkSessionResponse struct {
	Meta          *jsonutil.Object      `json:"_meta,omitempty"`
	ConfigOptions []SessionConfigOption `json:"configOptions,omitzero"`
	Models        *SessionModelState    `json:"models,omitempty"`
	Modes         *SessionModeState     `json:"modes,omitempty"`
	SessionID     string                `json:"sessionId"`
}

Result of session/fork: the new session with its models, modes and config options

func (*ForkSessionResponse) UnmarshalJSON

func (r *ForkSessionResponse) UnmarshalJSON(data []byte) error

Fills the response from its JSON object, which must carry sessionId

type HTTPHeader

type HTTPHeader struct {
	Meta  *jsonutil.Object `json:"_meta,omitempty"`
	Name  string           `json:"name"`
	Value string           `json:"value"`
}

HTTP header sent to an MCP server

func (*HTTPHeader) UnmarshalJSON

func (h *HTTPHeader) UnmarshalJSON(data []byte) error

Fills the header from its JSON object, which must carry name and value

type HTTPMCPServer

type HTTPMCPServer struct {
	Meta    *jsonutil.Object `json:"_meta,omitempty"`
	Headers []HTTPHeader     `json:"headers"`
	Name    string           `json:"name"`
	URL     string           `json:"url"`
}

MCP server reached over streamable HTTP

func (HTTPMCPServer) MarshalJSON

func (s HTTPMCPServer) MarshalJSON() ([]byte, error)

JSON object of the server with type "http"

func (*HTTPMCPServer) UnmarshalJSON

func (s *HTTPMCPServer) UnmarshalJSON(data []byte) error

Fills the server from its JSON object, which must carry headers, name and url

type Handler

type Handler func(ctx context.Context, method string, params json.RawMessage, notification bool) (any, error)

Function a connection calls for each incoming request and notification, params the raw JSON of the frame's params, nil when it has none; every call runs on its own goroutine, concurrently with the others and in no set order, under a context Close cancels; a request is answered with the result, or with the *RequestError in the error's chain, else an internal error carrying the error's text

type ImageContentBlock

type ImageContentBlock struct {
	Meta        *jsonutil.Object `json:"_meta,omitempty"`
	Annotations *Annotations     `json:"annotations,omitempty"`
	Data        string           `json:"data"`
	MimeType    string           `json:"mimeType"`
	URI         *string          `json:"uri,omitempty"`
}

Base64 image data with its MIME type

func (ImageContentBlock) MarshalJSON

func (b ImageContentBlock) MarshalJSON() ([]byte, error)

JSON object of the block with type "image"

func (*ImageContentBlock) UnmarshalJSON

func (b *ImageContentBlock) UnmarshalJSON(data []byte) error

Fills the block from its JSON object, which must carry data and mimeType

type Implementation

type Implementation struct {
	Meta    *jsonutil.Object `json:"_meta,omitempty"`
	Name    string           `json:"name"`
	Title   *string          `json:"title,omitempty"`
	Version string           `json:"version"`
}

Name, display title and version of a client or agent program

func (*Implementation) UnmarshalJSON

func (i *Implementation) UnmarshalJSON(data []byte) error

Fills the implementation from its JSON object, which must carry name and version

type InitializeRequest

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

Params of initialize: the protocol version the client speaks, its capabilities and who it is

func (*InitializeRequest) UnmarshalJSON

func (r *InitializeRequest) UnmarshalJSON(data []byte) error

Fills the request from its JSON object, which must carry protocolVersion: an integer, or a string from a client older than version 1

type InitializeResponse

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

Result of initialize: the protocol version the agent speaks, its capabilities, who it is and how a user signs in

func (*InitializeResponse) UnmarshalJSON

func (r *InitializeResponse) UnmarshalJSON(data []byte) error

Fills the response from its JSON object, which must carry protocolVersion: an integer, or a string from an agent older than version 1

type Initializer

type Initializer interface {
	Initialize(ctx context.Context, req *InitializeRequest) (*InitializeResponse, error)
}

Agent method answering initialize

type KillTerminalRequest

type KillTerminalRequest struct {
	Meta       *jsonutil.Object `json:"_meta,omitempty"`
	SessionID  string           `json:"sessionId"`
	TerminalID string           `json:"terminalId"`
}

Params of terminal/kill

func (*KillTerminalRequest) UnmarshalJSON

func (r *KillTerminalRequest) UnmarshalJSON(data []byte) error

Fills the request from its JSON object, which must carry sessionId and terminalId

type KillTerminalResponse

type KillTerminalResponse struct {
	Meta *jsonutil.Object `json:"_meta,omitempty"`
}

Result of terminal/kill

type ListSessionsRequest

type ListSessionsRequest struct {
	Meta   *jsonutil.Object `json:"_meta,omitempty"`
	Cursor *string          `json:"cursor,omitempty"`
	Cwd    *string          `json:"cwd,omitempty"`
}

Params of session/list: a page cursor and a working directory to filter by

type ListSessionsResponse

type ListSessionsResponse struct {
	Meta       *jsonutil.Object `json:"_meta,omitempty"`
	NextCursor *string          `json:"nextCursor,omitempty"`
	Sessions   []SessionInfo    `json:"sessions"`
}

Result of session/list: one page of sessions and the cursor of the next

func (*ListSessionsResponse) UnmarshalJSON

func (r *ListSessionsResponse) UnmarshalJSON(data []byte) error

Fills the response from its JSON object, which must carry sessions

type LoadSessionRequest

type LoadSessionRequest struct {
	Meta       *jsonutil.Object `json:"_meta,omitempty"`
	Cwd        string           `json:"cwd"`
	MCPServers []MCPServer      `json:"mcpServers"`
	SessionID  string           `json:"sessionId"`
}

Params of session/load: the session, the working directory and the MCP servers the client offers

func (*LoadSessionRequest) UnmarshalJSON

func (r *LoadSessionRequest) UnmarshalJSON(data []byte) error

Fills the request from its JSON object, which must carry cwd, mcpServers and sessionId

type LoadSessionResponse

type LoadSessionResponse struct {
	Meta          *jsonutil.Object      `json:"_meta,omitempty"`
	ConfigOptions []SessionConfigOption `json:"configOptions,omitzero"`
	Models        *SessionModelState    `json:"models,omitempty"`
	Modes         *SessionModeState     `json:"modes,omitempty"`
}

Result of session/load: the session's models, modes and config options

func (*LoadSessionResponse) UnmarshalJSON

func (r *LoadSessionResponse) UnmarshalJSON(data []byte) error

Fills the response from its JSON object

type MCPCapabilities

type MCPCapabilities struct {
	Meta *jsonutil.Object `json:"_meta,omitempty"`
	HTTP *bool            `json:"http,omitempty"`
	SSE  *bool            `json:"sse,omitempty"`
}

MCP transports an agent connects over besides stdio

type MCPServer

type MCPServer interface {
	// contains filtered or unexported methods
}

MCP server the client asks the agent to connect to: *StdioMCPServer, *HTTPMCPServer or *SSEMCPServer

type MissingFieldError

type MissingFieldError struct {
	// Type of the message, such as "PromptRequest"
	Type string
	// Wire name of the member, such as "sessionId"
	Field string
}

Decoding failure of a message that lacks a member the protocol requires, or holds null in it

func (*MissingFieldError) Error

func (e *MissingFieldError) Error() string

Which member is missing from which message, such as `missing required field "prompt" in PromptRequest`

type ModelInfo

type ModelInfo struct {
	Meta        *jsonutil.Object `json:"_meta,omitempty"`
	Description *string          `json:"description,omitempty"`
	ModelID     string           `json:"modelId"`
	Name        string           `json:"name"`
}

Model a session can use

func (*ModelInfo) UnmarshalJSON

func (m *ModelInfo) UnmarshalJSON(data []byte) error

Fills the model from its JSON object, which must carry modelId and name

type NewSessionRequest

type NewSessionRequest struct {
	Meta       *jsonutil.Object `json:"_meta,omitempty"`
	Cwd        string           `json:"cwd"`
	MCPServers []MCPServer      `json:"mcpServers"`
}

Params of session/new: the working directory and the MCP servers the client offers

func (*NewSessionRequest) UnmarshalJSON

func (r *NewSessionRequest) UnmarshalJSON(data []byte) error

Fills the request from its JSON object, which must carry cwd and mcpServers

type NewSessionResponse

type NewSessionResponse struct {
	Meta          *jsonutil.Object      `json:"_meta,omitempty"`
	ConfigOptions []SessionConfigOption `json:"configOptions,omitzero"`
	Models        *SessionModelState    `json:"models,omitempty"`
	Modes         *SessionModeState     `json:"modes,omitempty"`
	SessionID     string                `json:"sessionId"`
}

Result of session/new: the session with its models, modes and config options

func (*NewSessionResponse) UnmarshalJSON

func (r *NewSessionResponse) UnmarshalJSON(data []byte) error

Fills the response from its JSON object, which must carry sessionId

type Option

type Option func(*config)

Setting of a connection

func LineLimit

func LineLimit(n int) Option

Frames longer than n bytes are dropped without ending the connection: such a request is answered with an invalid request error and such a reply fails its request with ErrFrameTooLong; zero or less lifts the limit

func ShutdownGrace

func ShutdownGrace(d time.Duration) Option

Time RunAgent waits for running handlers to return after it closed the connection, before it reports the ones left; zero or less does not wait

func UnstableMethods

func UnstableMethods(on bool) Option

Whether an agent connection serves the methods of the unstable protocol instead of answering them with method not found

type PermissionOption

type PermissionOption struct {
	Meta *jsonutil.Object `json:"_meta,omitempty"`
	// allow_once, allow_always, reject_once or reject_always
	Kind     string `json:"kind"`
	Name     string `json:"name"`
	OptionID string `json:"optionId"`
}

One choice of a permission request

func (*PermissionOption) UnmarshalJSON

func (o *PermissionOption) UnmarshalJSON(data []byte) error

Fills the option from its JSON object, which must carry kind, name and optionId

type PermissionOutcome

type PermissionOutcome interface {
	// contains filtered or unexported methods
}

How a permission request ended: *AllowedOutcome or *DeniedOutcome

type PlanEntry

type PlanEntry struct {
	Meta    *jsonutil.Object `json:"_meta,omitempty"`
	Content string           `json:"content"`
	// high, medium or low
	Priority string `json:"priority"`
	// pending, in_progress or completed
	Status string `json:"status"`
}

One step of an agent plan

func NewPlanEntry

func NewPlanEntry(content, priority, status string) PlanEntry

Plan entry with content, priority and status

func (*PlanEntry) UnmarshalJSON

func (e *PlanEntry) UnmarshalJSON(data []byte) error

Fills the entry from its JSON object, which must carry content, priority and status

type PromptCapabilities

type PromptCapabilities struct {
	Meta            *jsonutil.Object `json:"_meta,omitempty"`
	Audio           *bool            `json:"audio,omitempty"`
	EmbeddedContext *bool            `json:"embeddedContext,omitempty"`
	Image           *bool            `json:"image,omitempty"`
}

Prompt content an agent accepts besides text and resource links

type PromptRequest

type PromptRequest struct {
	Meta      *jsonutil.Object `json:"_meta,omitempty"`
	MessageID *string          `json:"messageId,omitempty"`
	Prompt    []ContentBlock   `json:"prompt"`
	SessionID string           `json:"sessionId"`
}

Params of session/prompt: the user's message as content blocks

func (*PromptRequest) UnmarshalJSON

func (r *PromptRequest) UnmarshalJSON(data []byte) error

Fills the request from its JSON object, which must carry prompt and sessionId

type PromptResponse

type PromptResponse struct {
	Meta *jsonutil.Object `json:"_meta,omitempty"`
	// end_turn, max_tokens, max_turn_requests, refusal or cancelled
	StopReason    string  `json:"stopReason"`
	Usage         *Usage  `json:"usage,omitempty"`
	UserMessageID *string `json:"userMessageId,omitempty"`
}

Result of session/prompt: why the turn stopped and what it used

func (*PromptResponse) UnmarshalJSON

func (r *PromptResponse) UnmarshalJSON(data []byte) error

Fills the response from its JSON object, which must carry stopReason

type Prompter

type Prompter interface {
	Prompt(ctx context.Context, req *PromptRequest) (*PromptResponse, error)
}

Agent method answering session/prompt

type ReadTextFileRequest

type ReadTextFileRequest struct {
	Meta      *jsonutil.Object `json:"_meta,omitempty"`
	Limit     *int             `json:"limit,omitempty"`
	Line      *int             `json:"line,omitempty"`
	Path      string           `json:"path"`
	SessionID string           `json:"sessionId"`
}

Params of fs/read_text_file: the file and, optionally, the line to start at and how many lines to read

func (*ReadTextFileRequest) UnmarshalJSON

func (r *ReadTextFileRequest) UnmarshalJSON(data []byte) error

Fills the request from its JSON object, which must carry path and sessionId

type ReadTextFileResponse

type ReadTextFileResponse struct {
	Meta    *jsonutil.Object `json:"_meta,omitempty"`
	Content string           `json:"content"`
}

Result of fs/read_text_file

func (*ReadTextFileResponse) UnmarshalJSON

func (r *ReadTextFileResponse) UnmarshalJSON(data []byte) error

Fills the response from its JSON object, which must carry content

type ReleaseTerminalRequest

type ReleaseTerminalRequest struct {
	Meta       *jsonutil.Object `json:"_meta,omitempty"`
	SessionID  string           `json:"sessionId"`
	TerminalID string           `json:"terminalId"`
}

Params of terminal/release

func (*ReleaseTerminalRequest) UnmarshalJSON

func (r *ReleaseTerminalRequest) UnmarshalJSON(data []byte) error

Fills the request from its JSON object, which must carry sessionId and terminalId

type ReleaseTerminalResponse

type ReleaseTerminalResponse struct {
	Meta *jsonutil.Object `json:"_meta,omitempty"`
}

Result of terminal/release

type RequestError

type RequestError struct {
	Code    int
	Message string
	// Extra detail, nil when there is none; a *jsonutil.Object when it came from the wire as an object
	Data any
}

JSON-RPC error: returned by a handler and sent to the peer, or received in answer to a request; match it with errors.As

func InternalError

func InternalError(data any) *RequestError

Internal error carrying data

func InvalidParams

func InvalidParams(data any) *RequestError

Invalid params error carrying data

func MethodNotFound

func MethodNotFound(method string) *RequestError

Method not found error whose data is an object naming the method

func NewRequestError

func NewRequestError(code int, message string, data any) *RequestError

Error with the given code, message and data

func (*RequestError) Error

func (e *RequestError) Error() string

The message as the peer or the handler wrote it

type RequestPermissionRequest

type RequestPermissionRequest struct {
	Meta      *jsonutil.Object   `json:"_meta,omitempty"`
	Options   []PermissionOption `json:"options"`
	SessionID string             `json:"sessionId"`
	ToolCall  ToolCallUpdate     `json:"toolCall"`
}

Params of session/request_permission: the tool call and the options the user chooses from

func (*RequestPermissionRequest) UnmarshalJSON

func (r *RequestPermissionRequest) UnmarshalJSON(data []byte) error

Fills the request from its JSON object, which must carry options, sessionId and toolCall

type RequestPermissionResponse

type RequestPermissionResponse struct {
	Meta    *jsonutil.Object  `json:"_meta,omitempty"`
	Outcome PermissionOutcome `json:"outcome"`
}

Result of session/request_permission

func (*RequestPermissionResponse) UnmarshalJSON

func (r *RequestPermissionResponse) UnmarshalJSON(data []byte) error

Fills the response from its JSON object, which must carry outcome

type ResourceContentBlock

type ResourceContentBlock struct {
	Meta        *jsonutil.Object `json:"_meta,omitempty"`
	Annotations *Annotations     `json:"annotations,omitempty"`
	Description *string          `json:"description,omitempty"`
	MimeType    *string          `json:"mimeType,omitempty"`
	Name        string           `json:"name"`
	// Size in bytes
	Size  *int    `json:"size,omitempty"`
	Title *string `json:"title,omitempty"`
	URI   string  `json:"uri"`
}

Link to a resource the agent can read

func (ResourceContentBlock) MarshalJSON

func (b ResourceContentBlock) MarshalJSON() ([]byte, error)

JSON object of the block with type "resource_link"

func (*ResourceContentBlock) UnmarshalJSON

func (b *ResourceContentBlock) UnmarshalJSON(data []byte) error

Fills the block from its JSON object, which must carry name and uri

type ResourceContents

type ResourceContents interface {
	// contains filtered or unexported methods
}

Contents of an embedded resource: *TextResourceContents or *BlobResourceContents

type ResumeSessionRequest

type ResumeSessionRequest struct {
	Meta       *jsonutil.Object `json:"_meta,omitempty"`
	Cwd        string           `json:"cwd"`
	MCPServers []MCPServer      `json:"mcpServers,omitzero"`
	SessionID  string           `json:"sessionId"`
}

Params of session/resume: the session, the working directory and the MCP servers the client offers

func (*ResumeSessionRequest) UnmarshalJSON

func (r *ResumeSessionRequest) UnmarshalJSON(data []byte) error

Fills the request from its JSON object, which must carry cwd and sessionId

type ResumeSessionResponse

type ResumeSessionResponse struct {
	Meta          *jsonutil.Object      `json:"_meta,omitempty"`
	ConfigOptions []SessionConfigOption `json:"configOptions,omitzero"`
	Models        *SessionModelState    `json:"models,omitempty"`
	Modes         *SessionModeState     `json:"modes,omitempty"`
}

Result of session/resume: the session's models, modes and config options

func (*ResumeSessionResponse) UnmarshalJSON

func (r *ResumeSessionResponse) UnmarshalJSON(data []byte) error

Fills the response from its JSON object

type SSEMCPServer

type SSEMCPServer struct {
	Meta    *jsonutil.Object `json:"_meta,omitempty"`
	Headers []HTTPHeader     `json:"headers"`
	Name    string           `json:"name"`
	URL     string           `json:"url"`
}

MCP server reached over server-sent events

func (SSEMCPServer) MarshalJSON

func (s SSEMCPServer) MarshalJSON() ([]byte, error)

JSON object of the server with type "sse"

func (*SSEMCPServer) UnmarshalJSON

func (s *SSEMCPServer) UnmarshalJSON(data []byte) error

Fills the server from its JSON object, which must carry headers, name and url

type SessionCapabilities

type SessionCapabilities struct {
	Meta   *jsonutil.Object           `json:"_meta,omitempty"`
	Close  *SessionCloseCapabilities  `json:"close,omitempty"`
	Fork   *SessionForkCapabilities   `json:"fork,omitempty"`
	List   *SessionListCapabilities   `json:"list,omitempty"`
	Resume *SessionResumeCapabilities `json:"resume,omitempty"`
}

Session methods an agent serves beyond the required ones, each present when served

type SessionCloseCapabilities

type SessionCloseCapabilities struct {
	Meta *jsonutil.Object `json:"_meta,omitempty"`
}

Marker that an agent serves session/close

type SessionCloser

type SessionCloser interface {
	CloseSession(ctx context.Context, req *CloseSessionRequest) (*CloseSessionResponse, error)
}

Agent method answering session/close, a nil response sent as an empty object

type SessionConfigOption

type SessionConfigOption interface {
	// contains filtered or unexported methods
}

Config option of a session: *SessionConfigOptionSelect or *SessionConfigOptionBoolean

type SessionConfigOptionBoolean

type SessionConfigOptionBoolean struct {
	CurrentValue bool             `json:"currentValue"`
	Meta         *jsonutil.Object `json:"_meta,omitempty"`
	Category     *string          `json:"category,omitempty"`
	Description  *string          `json:"description,omitempty"`
	ID           string           `json:"id"`
	Name         string           `json:"name"`
}

Config option switched on or off

func (SessionConfigOptionBoolean) MarshalJSON

func (o SessionConfigOptionBoolean) MarshalJSON() ([]byte, error)

JSON object of the option with type "boolean"

func (*SessionConfigOptionBoolean) UnmarshalJSON

func (o *SessionConfigOptionBoolean) UnmarshalJSON(data []byte) error

Fills the option from its JSON object, which must carry currentValue, id and name

type SessionConfigOptionSelect

type SessionConfigOptionSelect struct {
	CurrentValue string `json:"currentValue"`
	// Flat choices, written under options when Groups is nil
	Options []SessionConfigSelectOption `json:"-"`
	// Grouped choices, written under options in place of Options when not nil
	Groups      []SessionConfigSelectGroup `json:"-"`
	Meta        *jsonutil.Object           `json:"_meta,omitempty"`
	Category    *string                    `json:"category,omitempty"`
	Description *string                    `json:"description,omitempty"`
	ID          string                     `json:"id"`
	Name        string                     `json:"name"`
}

Config option holding one value out of a list of choices, flat or in groups

func (SessionConfigOptionSelect) MarshalJSON

func (o SessionConfigOptionSelect) MarshalJSON() ([]byte, error)

JSON object of the option with its choices under options and type "select"

func (*SessionConfigOptionSelect) UnmarshalJSON

func (o *SessionConfigOptionSelect) UnmarshalJSON(data []byte) error

Fills the option from its JSON object, which must carry currentValue, options, id and name; options whose first item names a group fill Groups, others Options

type SessionConfigSelectGroup

type SessionConfigSelectGroup struct {
	Meta    *jsonutil.Object            `json:"_meta,omitempty"`
	Group   string                      `json:"group"`
	Name    string                      `json:"name"`
	Options []SessionConfigSelectOption `json:"options"`
}

Named group of choices of a select config option

func (*SessionConfigSelectGroup) UnmarshalJSON

func (g *SessionConfigSelectGroup) UnmarshalJSON(data []byte) error

Fills the group from its JSON object, which must carry group, name and options

type SessionConfigSelectOption

type SessionConfigSelectOption struct {
	Meta        *jsonutil.Object `json:"_meta,omitempty"`
	Description *string          `json:"description,omitempty"`
	Name        string           `json:"name"`
	Value       string           `json:"value"`
}

One choice of a select config option

func (*SessionConfigSelectOption) UnmarshalJSON

func (o *SessionConfigSelectOption) UnmarshalJSON(data []byte) error

Fills the choice from its JSON object, which must carry name and value

type SessionCreator

type SessionCreator interface {
	NewSession(ctx context.Context, req *NewSessionRequest) (*NewSessionResponse, error)
}

Agent method answering session/new

type SessionForkCapabilities

type SessionForkCapabilities struct {
	Meta *jsonutil.Object `json:"_meta,omitempty"`
}

Marker that an agent serves session/fork

type SessionForker

type SessionForker interface {
	ForkSession(ctx context.Context, req *ForkSessionRequest) (*ForkSessionResponse, error)
}

Agent method answering session/fork

type SessionInfo

type SessionInfo struct {
	Meta      *jsonutil.Object `json:"_meta,omitempty"`
	Cwd       string           `json:"cwd"`
	SessionID string           `json:"sessionId"`
	Title     *string          `json:"title,omitempty"`
	UpdatedAt *string          `json:"updatedAt,omitempty"`
}

Session in a session list

func (*SessionInfo) UnmarshalJSON

func (s *SessionInfo) UnmarshalJSON(data []byte) error

Fills the session from its JSON object, which must carry cwd and sessionId

type SessionInfoUpdate

type SessionInfoUpdate struct {
	Meta      *jsonutil.Object `json:"_meta,omitempty"`
	Title     *string          `json:"title,omitempty"`
	UpdatedAt *string          `json:"updatedAt,omitempty"`
}

New title or update time of the session

func (SessionInfoUpdate) MarshalJSON

func (u SessionInfoUpdate) MarshalJSON() ([]byte, error)

JSON object of the update with sessionUpdate "session_info_update"

type SessionListCapabilities

type SessionListCapabilities struct {
	Meta *jsonutil.Object `json:"_meta,omitempty"`
}

Marker that an agent serves session/list

type SessionLister

type SessionLister interface {
	ListSessions(ctx context.Context, req *ListSessionsRequest) (*ListSessionsResponse, error)
}

Agent method answering session/list

type SessionLoader

type SessionLoader interface {
	LoadSession(ctx context.Context, req *LoadSessionRequest) (*LoadSessionResponse, error)
}

Agent method answering session/load, a nil response sent as an empty object

type SessionMode

type SessionMode struct {
	Meta        *jsonutil.Object `json:"_meta,omitempty"`
	Description *string          `json:"description,omitempty"`
	ID          string           `json:"id"`
	Name        string           `json:"name"`
}

Mode a session can run in

func (*SessionMode) UnmarshalJSON

func (m *SessionMode) UnmarshalJSON(data []byte) error

Fills the mode from its JSON object, which must carry id and name

type SessionModeSetter

type SessionModeSetter interface {
	SetSessionMode(ctx context.Context, req *SetSessionModeRequest) (*SetSessionModeResponse, error)
}

Agent method answering session/set_mode, a nil response sent as an empty object

type SessionModeState

type SessionModeState struct {
	Meta           *jsonutil.Object `json:"_meta,omitempty"`
	AvailableModes []SessionMode    `json:"availableModes"`
	CurrentModeID  string           `json:"currentModeId"`
}

Modes a session offers and the one it runs in

func (*SessionModeState) UnmarshalJSON

func (s *SessionModeState) UnmarshalJSON(data []byte) error

Fills the state from its JSON object, which must carry availableModes and currentModeId

type SessionModelSetter

type SessionModelSetter interface {
	SetSessionModel(ctx context.Context, req *SetSessionModelRequest) (*SetSessionModelResponse, error)
}

Agent method answering session/set_model, a nil response sent as an empty object

type SessionModelState

type SessionModelState struct {
	Meta            *jsonutil.Object `json:"_meta,omitempty"`
	AvailableModels []ModelInfo      `json:"availableModels"`
	CurrentModelID  string           `json:"currentModelId"`
}

Models a session offers and the one it uses

func (*SessionModelState) UnmarshalJSON

func (s *SessionModelState) UnmarshalJSON(data []byte) error

Fills the state from its JSON object, which must carry availableModels and currentModelId

type SessionNotification

type SessionNotification struct {
	Meta      *jsonutil.Object `json:"_meta,omitempty"`
	SessionID string           `json:"sessionId"`
	Update    SessionUpdate    `json:"update"`
}

Params of session/update: one update to one session

func (*SessionNotification) UnmarshalJSON

func (n *SessionNotification) UnmarshalJSON(data []byte) error

Fills the notification from its JSON object, which must carry sessionId and update

type SessionResumeCapabilities

type SessionResumeCapabilities struct {
	Meta *jsonutil.Object `json:"_meta,omitempty"`
}

Marker that an agent serves session/resume

type SessionResumer

type SessionResumer interface {
	ResumeSession(ctx context.Context, req *ResumeSessionRequest) (*ResumeSessionResponse, error)
}

Agent method answering session/resume

type SessionUpdate

type SessionUpdate interface {
	// contains filtered or unexported methods
}

Change to a session the agent reports: *UserMessageChunk, *AgentMessageChunk, *AgentThoughtChunk, *ToolCallStart, *ToolCallProgress, *AgentPlanUpdate, *AvailableCommandsUpdate, *CurrentModeUpdate, *ConfigOptionUpdate, *SessionInfoUpdate or *UsageUpdate

type SetConfigOptionParams

type SetConfigOptionParams struct {
	Meta      *jsonutil.Object
	ConfigID  string
	SessionID string
	Value     any
}

Set config option request as an agent receives it, boolean and select alike: Value is a bool or a string

type SetSessionConfigOptionBooleanRequest

type SetSessionConfigOptionBooleanRequest struct {
	Meta      *jsonutil.Object `json:"_meta,omitempty"`
	ConfigID  string           `json:"configId"`
	SessionID string           `json:"sessionId"`
	Value     bool             `json:"value"`
}

Params of session/set_config_option for a boolean option

func (SetSessionConfigOptionBooleanRequest) MarshalJSON

func (r SetSessionConfigOptionBooleanRequest) MarshalJSON() ([]byte, error)

JSON object of the request with type "boolean" before its value

func (*SetSessionConfigOptionBooleanRequest) UnmarshalJSON

func (r *SetSessionConfigOptionBooleanRequest) UnmarshalJSON(data []byte) error

Fills the request from its JSON object, which must carry configId, sessionId and value

type SetSessionConfigOptionResponse

type SetSessionConfigOptionResponse struct {
	Meta          *jsonutil.Object      `json:"_meta,omitempty"`
	ConfigOptions []SessionConfigOption `json:"configOptions"`
}

Result of session/set_config_option: every config option of the session after the change

func (*SetSessionConfigOptionResponse) UnmarshalJSON

func (r *SetSessionConfigOptionResponse) UnmarshalJSON(data []byte) error

Fills the response from its JSON object, which must carry configOptions

type SetSessionConfigOptionSelectRequest

type SetSessionConfigOptionSelectRequest struct {
	Meta      *jsonutil.Object `json:"_meta,omitempty"`
	ConfigID  string           `json:"configId"`
	SessionID string           `json:"sessionId"`
	Value     string           `json:"value"`
}

Params of session/set_config_option for a select option

func (*SetSessionConfigOptionSelectRequest) UnmarshalJSON

func (r *SetSessionConfigOptionSelectRequest) UnmarshalJSON(data []byte) error

Fills the request from its JSON object, which must carry configId, sessionId and value

type SetSessionModeRequest

type SetSessionModeRequest struct {
	Meta      *jsonutil.Object `json:"_meta,omitempty"`
	ModeID    string           `json:"modeId"`
	SessionID string           `json:"sessionId"`
}

Params of session/set_mode

func (*SetSessionModeRequest) UnmarshalJSON

func (r *SetSessionModeRequest) UnmarshalJSON(data []byte) error

Fills the request from its JSON object, which must carry modeId and sessionId

type SetSessionModeResponse

type SetSessionModeResponse struct {
	Meta *jsonutil.Object `json:"_meta,omitempty"`
}

Result of session/set_mode

type SetSessionModelRequest

type SetSessionModelRequest struct {
	Meta      *jsonutil.Object `json:"_meta,omitempty"`
	ModelID   string           `json:"modelId"`
	SessionID string           `json:"sessionId"`
}

Params of session/set_model

func (*SetSessionModelRequest) UnmarshalJSON

func (r *SetSessionModelRequest) UnmarshalJSON(data []byte) error

Fills the request from its JSON object, which must carry modelId and sessionId

type SetSessionModelResponse

type SetSessionModelResponse struct {
	Meta *jsonutil.Object `json:"_meta,omitempty"`
}

Result of session/set_model

type StdioMCPServer

type StdioMCPServer struct {
	Meta    *jsonutil.Object `json:"_meta,omitempty"`
	Args    []string         `json:"args"`
	Command string           `json:"command"`
	Env     []EnvVariable    `json:"env"`
	Name    string           `json:"name"`
}

MCP server the agent starts as a command speaking over its standard input and output

func (*StdioMCPServer) UnmarshalJSON

func (s *StdioMCPServer) UnmarshalJSON(data []byte) error

Fills the server from its JSON object, which must carry args, command, env and name

type StreamDirection

type StreamDirection string

Direction of a frame a stream observer sees

const (
	// Frame read from the peer
	StreamIncoming StreamDirection = "incoming"
	// Frame written to the peer
	StreamOutgoing StreamDirection = "outgoing"
)

Directions of the frames a connection reads and writes

type StreamEvent

type StreamEvent struct {
	Direction StreamDirection
	// Method of a request or notification, empty for a reply
	Method string
	// JSON text of the frame without its line end, shared by every observer and not to be modified
	Frame json.RawMessage
}

One frame a connection read or wrote

func (StreamEvent) Message

func (e StreamEvent) Message() any

Frame decoded with objects as *jsonutil.Object, nil when it does not parse

type StreamObserver

type StreamObserver func(event StreamEvent)

Callback receiving every frame of a connection on the goroutine that read or wrote it, before an incoming frame is handled

type TerminalAuthMethod

type TerminalAuthMethod struct {
	Meta        *jsonutil.Object `json:"_meta,omitempty"`
	Args        []string         `json:"args,omitzero"`
	Description *string          `json:"description,omitempty"`
	Env         *jsonutil.Object `json:"env,omitempty"`
	ID          string           `json:"id"`
	Name        string           `json:"name"`
}

Sign-in through the agent's own command run in a terminal with extra arguments and environment

func (TerminalAuthMethod) MarshalJSON

func (m TerminalAuthMethod) MarshalJSON() ([]byte, error)

JSON object of the method with type "terminal"

func (*TerminalAuthMethod) UnmarshalJSON

func (m *TerminalAuthMethod) UnmarshalJSON(data []byte) error

Fills the method from its JSON object, which must carry id and name

type TerminalExitStatus

type TerminalExitStatus struct {
	Meta     *jsonutil.Object `json:"_meta,omitempty"`
	ExitCode *int             `json:"exitCode,omitempty"`
	Signal   *string          `json:"signal,omitempty"`
}

Exit code or signal a terminal command ended with

type TerminalOutputRequest

type TerminalOutputRequest struct {
	Meta       *jsonutil.Object `json:"_meta,omitempty"`
	SessionID  string           `json:"sessionId"`
	TerminalID string           `json:"terminalId"`
}

Params of terminal/output

func (*TerminalOutputRequest) UnmarshalJSON

func (r *TerminalOutputRequest) UnmarshalJSON(data []byte) error

Fills the request from its JSON object, which must carry sessionId and terminalId

type TerminalOutputResponse

type TerminalOutputResponse struct {
	Meta       *jsonutil.Object    `json:"_meta,omitempty"`
	ExitStatus *TerminalExitStatus `json:"exitStatus,omitempty"`
	Output     string              `json:"output"`
	Truncated  bool                `json:"truncated"`
}

Result of terminal/output: the output so far and, once the command ended, how it exited

func (*TerminalOutputResponse) UnmarshalJSON

func (r *TerminalOutputResponse) UnmarshalJSON(data []byte) error

Fills the response from its JSON object, which must carry output and truncated

type TerminalToolCallContent

type TerminalToolCallContent struct {
	Meta       *jsonutil.Object `json:"_meta,omitempty"`
	TerminalID string           `json:"terminalId"`
}

Client terminal whose output a tool call shows

func (TerminalToolCallContent) MarshalJSON

func (c TerminalToolCallContent) MarshalJSON() ([]byte, error)

JSON object of the terminal content with type "terminal"

func (*TerminalToolCallContent) UnmarshalJSON

func (c *TerminalToolCallContent) UnmarshalJSON(data []byte) error

Fills the terminal content from its JSON object, which must carry terminalId

type TextContentBlock

type TextContentBlock struct {
	Meta        *jsonutil.Object `json:"_meta,omitempty"`
	Annotations *Annotations     `json:"annotations,omitempty"`
	Text        string           `json:"text"`
}

Plain text

func TextBlock

func TextBlock(text string) *TextContentBlock

Text content block

func (TextContentBlock) MarshalJSON

func (b TextContentBlock) MarshalJSON() ([]byte, error)

JSON object of the block with type "text"

func (*TextContentBlock) UnmarshalJSON

func (b *TextContentBlock) UnmarshalJSON(data []byte) error

Fills the block from its JSON object, which must carry text

type TextResourceContents

type TextResourceContents struct {
	Meta     *jsonutil.Object `json:"_meta,omitempty"`
	MimeType *string          `json:"mimeType,omitempty"`
	Text     string           `json:"text"`
	URI      string           `json:"uri"`
}

Text contents of a resource

func (*TextResourceContents) UnmarshalJSON

func (r *TextResourceContents) UnmarshalJSON(data []byte) error

Fills the contents from their JSON object, which must carry text and uri

type ToolCallContent

type ToolCallContent interface {
	// contains filtered or unexported methods
}

Content a tool call shows: *ContentToolCallContent, *FileEditToolCallContent or *TerminalToolCallContent

type ToolCallFields

type ToolCallFields struct {
	// Title of a progress update; a start takes its title as an argument
	Title     *string
	Kind      *string
	Status    *string
	Content   []ToolCallContent
	Locations []ToolCallLocation
	RawInput  any
	RawOutput any
}

Optional fields of a tool call start or progress update

type ToolCallLocation

type ToolCallLocation struct {
	Meta *jsonutil.Object `json:"_meta,omitempty"`
	Line *int             `json:"line,omitempty"`
	Path string           `json:"path"`
}

File a tool call reads or changes, with a line in it

func (*ToolCallLocation) UnmarshalJSON

func (l *ToolCallLocation) UnmarshalJSON(data []byte) error

Fills the location from its JSON object, which must carry path

type ToolCallProgress

type ToolCallProgress struct {
	Meta    *jsonutil.Object  `json:"_meta,omitempty"`
	Content []ToolCallContent `json:"content,omitzero"`
	// read, edit, delete, move, search, execute, think, fetch, switch_mode or other
	Kind      *string            `json:"kind,omitempty"`
	Locations []ToolCallLocation `json:"locations,omitzero"`
	RawInput  any                `json:"rawInput,omitempty"`
	RawOutput any                `json:"rawOutput,omitempty"`
	// pending, in_progress, completed or failed
	Status     *string `json:"status,omitempty"`
	Title      *string `json:"title,omitempty"`
	ToolCallID string  `json:"toolCallId"`
}

Change to the fields of a tool call already started, nil fields left as they were

func UpdateToolCall

func UpdateToolCall(toolCallID string, f ToolCallFields) *ToolCallProgress

Tool call progress update

func (ToolCallProgress) MarshalJSON

func (t ToolCallProgress) MarshalJSON() ([]byte, error)

JSON object of the progress with sessionUpdate "tool_call_update"

func (*ToolCallProgress) UnmarshalJSON

func (t *ToolCallProgress) UnmarshalJSON(data []byte) error

Fills the progress from its JSON object, which must carry toolCallId

type ToolCallStart

type ToolCallStart struct {
	Meta    *jsonutil.Object  `json:"_meta,omitempty"`
	Content []ToolCallContent `json:"content,omitzero"`
	// read, edit, delete, move, search, execute, think, fetch, switch_mode or other
	Kind      *string            `json:"kind,omitempty"`
	Locations []ToolCallLocation `json:"locations,omitzero"`
	RawInput  any                `json:"rawInput,omitempty"`
	RawOutput any                `json:"rawOutput,omitempty"`
	// pending, in_progress, completed or failed
	Status     *string `json:"status,omitempty"`
	Title      string  `json:"title"`
	ToolCallID string  `json:"toolCallId"`
}

Tool call the agent started

func StartToolCall

func StartToolCall(toolCallID, title string, f ToolCallFields) *ToolCallStart

Tool call start update

func (ToolCallStart) MarshalJSON

func (t ToolCallStart) MarshalJSON() ([]byte, error)

JSON object of the start with sessionUpdate "tool_call"

func (*ToolCallStart) UnmarshalJSON

func (t *ToolCallStart) UnmarshalJSON(data []byte) error

Fills the start from its JSON object, which must carry title and toolCallId

type ToolCallUpdate

type ToolCallUpdate struct {
	Meta    *jsonutil.Object  `json:"_meta,omitempty"`
	Content []ToolCallContent `json:"content,omitzero"`
	// read, edit, delete, move, search, execute, think, fetch, switch_mode or other
	Kind      *string            `json:"kind,omitempty"`
	Locations []ToolCallLocation `json:"locations,omitzero"`
	RawInput  any                `json:"rawInput,omitempty"`
	RawOutput any                `json:"rawOutput,omitempty"`
	// pending, in_progress, completed or failed
	Status     *string `json:"status,omitempty"`
	Title      *string `json:"title,omitempty"`
	ToolCallID string  `json:"toolCallId"`
}

Tool call as a permission request shows it

func (*ToolCallUpdate) UnmarshalJSON

func (t *ToolCallUpdate) UnmarshalJSON(data []byte) error

Fills the tool call from its JSON object, which must carry toolCallId

type UnknownVariantError

type UnknownVariantError struct {
	// Union type, such as "ContentBlock"
	Union string
	// Discriminator member, such as "type"
	Key string
	// Discriminator value found
	Value string
}

Decoding failure of a union value whose discriminator names a variant this package does not know

func (*UnknownVariantError) Error

func (e *UnknownVariantError) Error() string

The union, its discriminator and the value found, such as `unknown ContentBlock type "video"`

type UnstructuredCommandInput

type UnstructuredCommandInput struct {
	Meta *jsonutil.Object `json:"_meta,omitempty"`
	Hint string           `json:"hint"`
}

Free text a command takes, with the hint shown while it is empty

func (*UnstructuredCommandInput) UnmarshalJSON

func (i *UnstructuredCommandInput) UnmarshalJSON(data []byte) error

Fills the input from its JSON object, which must carry hint

type Usage

type Usage struct {
	CachedReadTokens  *int `json:"cachedReadTokens,omitempty"`
	CachedWriteTokens *int `json:"cachedWriteTokens,omitempty"`
	InputTokens       int  `json:"inputTokens"`
	OutputTokens      int  `json:"outputTokens"`
	ThoughtTokens     *int `json:"thoughtTokens,omitempty"`
	TotalTokens       int  `json:"totalTokens"`
}

Tokens a prompt turn used

func (*Usage) UnmarshalJSON

func (u *Usage) UnmarshalJSON(data []byte) error

Fills the usage from its JSON object, which must carry inputTokens, outputTokens and totalTokens

type UsageUpdate

type UsageUpdate struct {
	Meta *jsonutil.Object `json:"_meta,omitempty"`
	Cost *Cost            `json:"cost,omitempty"`
	// Tokens the context window holds
	Size int `json:"size"`
	// Tokens in use
	Used int `json:"used"`
}

Context window use of the session and what it cost so far

func (UsageUpdate) MarshalJSON

func (u UsageUpdate) MarshalJSON() ([]byte, error)

JSON object of the update with sessionUpdate "usage_update"

func (*UsageUpdate) UnmarshalJSON

func (u *UsageUpdate) UnmarshalJSON(data []byte) error

Fills the update from its JSON object, which must carry size and used

type UserMessageChunk

type UserMessageChunk struct {
	Meta      *jsonutil.Object `json:"_meta,omitempty"`
	Content   ContentBlock     `json:"content"`
	MessageID *string          `json:"messageId,omitempty"`
}

Chunk of a user message, replayed from history or echoed back

func (UserMessageChunk) MarshalJSON

func (c UserMessageChunk) MarshalJSON() ([]byte, error)

JSON object of the chunk with sessionUpdate "user_message_chunk"

func (*UserMessageChunk) UnmarshalJSON

func (c *UserMessageChunk) UnmarshalJSON(data []byte) error

Fills the chunk from its JSON object, which must carry content

type WaitForTerminalExitRequest

type WaitForTerminalExitRequest struct {
	Meta       *jsonutil.Object `json:"_meta,omitempty"`
	SessionID  string           `json:"sessionId"`
	TerminalID string           `json:"terminalId"`
}

Params of terminal/wait_for_exit

func (*WaitForTerminalExitRequest) UnmarshalJSON

func (r *WaitForTerminalExitRequest) UnmarshalJSON(data []byte) error

Fills the request from its JSON object, which must carry sessionId and terminalId

type WaitForTerminalExitResponse

type WaitForTerminalExitResponse struct {
	Meta     *jsonutil.Object `json:"_meta,omitempty"`
	ExitCode *int             `json:"exitCode,omitempty"`
	Signal   *string          `json:"signal,omitempty"`
}

Result of terminal/wait_for_exit: the exit code or signal the command ended with

type WriteTextFileRequest

type WriteTextFileRequest struct {
	Meta      *jsonutil.Object `json:"_meta,omitempty"`
	Content   string           `json:"content"`
	Path      string           `json:"path"`
	SessionID string           `json:"sessionId"`
}

Params of fs/write_text_file

func (*WriteTextFileRequest) UnmarshalJSON

func (r *WriteTextFileRequest) UnmarshalJSON(data []byte) error

Fills the request from its JSON object, which must carry content, path and sessionId

type WriteTextFileResponse

type WriteTextFileResponse struct {
	Meta *jsonutil.Object `json:"_meta,omitempty"`
}

Result of fs/write_text_file

Jump to

Keyboard shortcuts

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