rpc

package
v0.144.4 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: Apache-2.0 Imports: 14 Imported by: 1

Documentation

Overview

Package rpc provides a minimal JSON-RPC client tailored to the Codex app-server. It intentionally implements only the subset needed for Codex. For general-purpose JSON-RPC support, consider using a dedicated library.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultStderr

func DefaultStderr() io.Writer

DefaultStderr returns a safe default for spawned processes.

Types

type Client

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

Client manages JSON-RPC requests over a Transport.

func NewClient

func NewClient(transport Transport, options ClientOptions) *Client

NewClient creates a JSON-RPC client over a Transport.

func (*Client) AccountLoginCancel

Client implements ClientRequests using JSON-RPC.

func (*Client) AccountLoginStart

func (c *Client) AccountLoginStart(ctx context.Context, params protocol.LoginAccountParams) (*protocol.LoginAccountResponse, error)

func (*Client) AccountLogout

func (c *Client) AccountLogout(ctx context.Context) (*protocol.LogoutAccountResponse, error)

func (*Client) AccountRateLimitsRead

func (c *Client) AccountRateLimitsRead(ctx context.Context) (*protocol.GetAccountRateLimitsResponse, error)

func (*Client) AccountRead

func (*Client) AccountUsageRead

func (c *Client) AccountUsageRead(ctx context.Context) (*protocol.GetAccountTokenUsageResponse, error)

func (*Client) AccountWorkspaceMessagesRead

func (c *Client) AccountWorkspaceMessagesRead(ctx context.Context) (*protocol.GetWorkspaceMessagesResponse, error)

func (*Client) AppList

func (*Client) Call

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

Call sends a JSON-RPC request and decodes the response into result.

func (*Client) Close

func (c *Client) Close() error

Close shuts down the client and transport.

func (*Client) CommandExec

func (*Client) CommandExecWrite

func (*Client) ConfigBatchWrite

func (*Client) ConfigMcpServerReload

func (c *Client) ConfigMcpServerReload(ctx context.Context) (*protocol.McpServerRefreshResponse, error)

func (*Client) ConfigRead

func (*Client) ConfigRequirementsRead

func (c *Client) ConfigRequirementsRead(ctx context.Context) (*protocol.ConfigRequirementsReadResponse, error)

func (*Client) ConfigValueWrite

func (*Client) ExternalAgentConfigImportReadHistories

func (c *Client) ExternalAgentConfigImportReadHistories(ctx context.Context) (*protocol.ExternalAgentConfigImportHistoriesReadResponse, error)

func (*Client) FeedbackUpload

func (*Client) FsCopy

func (*Client) FsGetMetadata

func (*Client) FsReadDirectory

func (*Client) FsReadFile

func (*Client) FsRemove

func (*Client) FsUnwatch

func (*Client) FsWatch

func (*Client) FsWriteFile

func (*Client) FuzzyFileSearch

func (*Client) HooksList

func (*Client) Initialize

func (*Client) MarketplaceAdd

func (*Client) McpServerResourceRead

func (c *Client) McpServerResourceRead(ctx context.Context, params protocol.McpResourceReadParams) (*protocol.McpResourceReadResponse, error)

func (*Client) ModelList

func (*Client) Notify

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

Notify sends a JSON-RPC notification.

func (*Client) PluginInstall

func (*Client) PluginInstalled

func (*Client) PluginList

func (*Client) PluginRead

func (*Client) PluginShareList

func (*Client) PluginShareSave

func (*Client) PluginSkillRead

func (*Client) PluginUninstall

func (*Client) ReviewStart

func (*Client) SetRequestHandler

func (c *Client) SetRequestHandler(handler ServerRequestHandler)

SetRequestHandler replaces the server request handler.

func (*Client) SkillsList

func (*Client) SubscribeNotifications

func (c *Client) SubscribeNotifications(buffer int) *NotificationIterator

SubscribeNotifications creates an iterator over server notifications.

func (*Client) ThreadArchive

func (*Client) ThreadDelete

func (*Client) ThreadFork

func (*Client) ThreadGoalClear

func (*Client) ThreadGoalGet

func (*Client) ThreadGoalSet

func (*Client) ThreadList

func (*Client) ThreadLoadedList

func (*Client) ThreadNameSet

func (*Client) ThreadRead

func (*Client) ThreadResume

func (*Client) ThreadRollback

func (*Client) ThreadStart

func (*Client) ThreadUnarchive

func (*Client) TurnInterrupt

func (*Client) TurnStart

func (*Client) TurnSteer

func (*Client) WindowsSandboxReadiness

func (c *Client) WindowsSandboxReadiness(ctx context.Context) (*protocol.WindowsSandboxReadinessResponse, error)

type ClientOptions

type ClientOptions struct {
	Logger         *slog.Logger
	RequestHandler ServerRequestHandler
}

type ClientRequests

type ClientRequests interface {
	AccountLoginCancel(ctx context.Context, params protocol.CancelLoginAccountParams) (*protocol.CancelLoginAccountResponse, error)
	AccountLoginStart(ctx context.Context, params protocol.LoginAccountParams) (*protocol.LoginAccountResponse, error)
	AccountLogout(ctx context.Context) (*protocol.LogoutAccountResponse, error)
	AccountRateLimitResetCreditConsume(ctx context.Context, params protocol.ConsumeAccountRateLimitResetCreditParams) (*protocol.ConsumeAccountRateLimitResetCreditResponse, error)
	AccountRateLimitsRead(ctx context.Context) (*protocol.GetAccountRateLimitsResponse, error)
	AccountRead(ctx context.Context, params protocol.GetAccountParams) (*protocol.GetAccountResponse, error)
	AccountSendAddCreditsNudgeEmail(ctx context.Context, params protocol.SendAddCreditsNudgeEmailParams) (*protocol.SendAddCreditsNudgeEmailResponse, error)
	AccountUsageRead(ctx context.Context) (*protocol.GetAccountTokenUsageResponse, error)
	AccountWorkspaceMessagesRead(ctx context.Context) (*protocol.GetWorkspaceMessagesResponse, error)
	AppList(ctx context.Context, params protocol.AppsListParams) (*protocol.AppsListResponse, error)
	CommandExec(ctx context.Context, params protocol.CommandExecParams) (*protocol.CommandExecResponse, error)
	CommandExecResize(ctx context.Context, params protocol.CommandExecResizeParams) (*protocol.CommandExecResizeResponse, error)
	CommandExecTerminate(ctx context.Context, params protocol.CommandExecTerminateParams) (*protocol.CommandExecTerminateResponse, error)
	CommandExecWrite(ctx context.Context, params protocol.CommandExecWriteParams) (*protocol.CommandExecWriteResponse, error)
	ConfigBatchWrite(ctx context.Context, params protocol.ConfigBatchWriteParams) (*protocol.ConfigWriteResponse, error)
	ConfigMcpServerReload(ctx context.Context) (*protocol.McpServerRefreshResponse, error)
	ConfigRead(ctx context.Context, params protocol.ConfigReadParams) (*protocol.ConfigReadResponse, error)
	ConfigValueWrite(ctx context.Context, params protocol.ConfigValueWriteParams) (*protocol.ConfigWriteResponse, error)
	ConfigRequirementsRead(ctx context.Context) (*protocol.ConfigRequirementsReadResponse, error)
	ExperimentalFeatureEnablementSet(ctx context.Context, params protocol.ExperimentalFeatureEnablementSetParams) (*protocol.ExperimentalFeatureEnablementSetResponse, error)
	ExperimentalFeatureList(ctx context.Context, params protocol.ExperimentalFeatureListParams) (*protocol.ExperimentalFeatureListResponse, error)
	ExternalAgentConfigDetect(ctx context.Context, params protocol.ExternalAgentConfigDetectParams) (*protocol.ExternalAgentConfigDetectResponse, error)
	ExternalAgentConfigImport(ctx context.Context, params protocol.ExternalAgentConfigImportParams) (*protocol.ExternalAgentConfigImportResponse, error)
	ExternalAgentConfigImportReadHistories(ctx context.Context) (*protocol.ExternalAgentConfigImportHistoriesReadResponse, error)
	FeedbackUpload(ctx context.Context, params protocol.FeedbackUploadParams) (*protocol.FeedbackUploadResponse, error)
	FsCopy(ctx context.Context, params protocol.FsCopyParams) (*protocol.FsCopyResponse, error)
	FsCreateDirectory(ctx context.Context, params protocol.FsCreateDirectoryParams) (*protocol.FsCreateDirectoryResponse, error)
	FsGetMetadata(ctx context.Context, params protocol.FsGetMetadataParams) (*protocol.FsGetMetadataResponse, error)
	FsReadDirectory(ctx context.Context, params protocol.FsReadDirectoryParams) (*protocol.FsReadDirectoryResponse, error)
	FsReadFile(ctx context.Context, params protocol.FsReadFileParams) (*protocol.FsReadFileResponse, error)
	FsRemove(ctx context.Context, params protocol.FsRemoveParams) (*protocol.FsRemoveResponse, error)
	FsUnwatch(ctx context.Context, params protocol.FsUnwatchParams) (*protocol.FsUnwatchResponse, error)
	FsWatch(ctx context.Context, params protocol.FsWatchParams) (*protocol.FsWatchResponse, error)
	FsWriteFile(ctx context.Context, params protocol.FsWriteFileParams) (*protocol.FsWriteFileResponse, error)
	FuzzyFileSearch(ctx context.Context, params protocol.FuzzyFileSearchParams) (*protocol.FuzzyFileSearchResponse, error)
	HooksList(ctx context.Context, params protocol.HooksListParams) (*protocol.HooksListResponse, error)
	Initialize(ctx context.Context, params protocol.InitializeParams) (*protocol.InitializeResponse, error)
	MarketplaceAdd(ctx context.Context, params protocol.MarketplaceAddParams) (*protocol.MarketplaceAddResponse, error)
	MarketplaceRemove(ctx context.Context, params protocol.MarketplaceRemoveParams) (*protocol.MarketplaceRemoveResponse, error)
	MarketplaceUpgrade(ctx context.Context, params protocol.MarketplaceUpgradeParams) (*protocol.MarketplaceUpgradeResponse, error)
	McpServerOauthLogin(ctx context.Context, params protocol.McpServerOauthLoginParams) (*protocol.McpServerOauthLoginResponse, error)
	McpServerResourceRead(ctx context.Context, params protocol.McpResourceReadParams) (*protocol.McpResourceReadResponse, error)
	McpServerToolCall(ctx context.Context, params protocol.McpServerToolCallParams) (*protocol.McpServerToolCallResponse, error)
	McpServerStatusList(ctx context.Context, params protocol.ListMcpServerStatusParams) (*protocol.ListMcpServerStatusResponse, error)
	ModelList(ctx context.Context, params protocol.ModelListParams) (*protocol.ModelListResponse, error)
	ModelProviderCapabilitiesRead(ctx context.Context, params protocol.ModelProviderCapabilitiesReadParams) (*protocol.ModelProviderCapabilitiesReadResponse, error)
	PermissionProfileList(ctx context.Context, params protocol.PermissionProfileListParams) (*protocol.PermissionProfileListResponse, error)
	PluginInstall(ctx context.Context, params protocol.PluginInstallParams) (*protocol.PluginInstallResponse, error)
	PluginInstalled(ctx context.Context, params protocol.PluginInstalledParams) (*protocol.PluginInstalledResponse, error)
	PluginList(ctx context.Context, params protocol.PluginListParams) (*protocol.PluginListResponse, error)
	PluginRead(ctx context.Context, params protocol.PluginReadParams) (*protocol.PluginReadResponse, error)
	PluginShareCheckout(ctx context.Context, params protocol.PluginShareCheckoutParams) (*protocol.PluginShareCheckoutResponse, error)
	PluginShareDelete(ctx context.Context, params protocol.PluginShareDeleteParams) (*protocol.PluginShareDeleteResponse, error)
	PluginShareList(ctx context.Context, params protocol.PluginShareListParams) (*protocol.PluginShareListResponse, error)
	PluginShareSave(ctx context.Context, params protocol.PluginShareSaveParams) (*protocol.PluginShareSaveResponse, error)
	PluginShareUpdateTargets(ctx context.Context, params protocol.PluginShareUpdateTargetsParams) (*protocol.PluginShareUpdateTargetsResponse, error)
	PluginSkillRead(ctx context.Context, params protocol.PluginSkillReadParams) (*protocol.PluginSkillReadResponse, error)
	PluginUninstall(ctx context.Context, params protocol.PluginUninstallParams) (*protocol.PluginUninstallResponse, error)
	ReviewStart(ctx context.Context, params protocol.ReviewStartParams) (*protocol.ReviewStartResponse, error)
	SkillsConfigWrite(ctx context.Context, params protocol.SkillsConfigWriteParams) (*protocol.SkillsConfigWriteResponse, error)
	SkillsExtraRootsSet(ctx context.Context, params protocol.SkillsExtraRootsSetParams) (*protocol.SkillsExtraRootsSetResponse, error)
	SkillsList(ctx context.Context, params protocol.SkillsListParams) (*protocol.SkillsListResponse, error)
	ThreadApproveGuardianDeniedAction(ctx context.Context, params protocol.ThreadApproveGuardianDeniedActionParams) (*protocol.ThreadApproveGuardianDeniedActionResponse, error)
	ThreadArchive(ctx context.Context, params protocol.ThreadArchiveParams) (*protocol.ThreadArchiveResponse, error)
	ThreadCompactStart(ctx context.Context, params protocol.ThreadCompactStartParams) (*protocol.ThreadCompactStartResponse, error)
	ThreadDelete(ctx context.Context, params protocol.ThreadDeleteParams) (*protocol.ThreadDeleteResponse, error)
	ThreadFork(ctx context.Context, params protocol.ThreadForkParams) (*protocol.ThreadForkResponse, error)
	ThreadGoalClear(ctx context.Context, params protocol.ThreadGoalClearParams) (*protocol.ThreadGoalClearResponse, error)
	ThreadGoalGet(ctx context.Context, params protocol.ThreadGoalGetParams) (*protocol.ThreadGoalGetResponse, error)
	ThreadGoalSet(ctx context.Context, params protocol.ThreadGoalSetParams) (*protocol.ThreadGoalSetResponse, error)
	ThreadInjectItems(ctx context.Context, params protocol.ThreadInjectItemsParams) (*protocol.ThreadInjectItemsResponse, error)
	ThreadList(ctx context.Context, params protocol.ThreadListParams) (*protocol.ThreadListResponse, error)
	ThreadLoadedList(ctx context.Context, params protocol.ThreadLoadedListParams) (*protocol.ThreadLoadedListResponse, error)
	ThreadMetadataUpdate(ctx context.Context, params protocol.ThreadMetadataUpdateParams) (*protocol.ThreadMetadataUpdateResponse, error)
	ThreadNameSet(ctx context.Context, params protocol.ThreadSetNameParams) (*protocol.ThreadSetNameResponse, error)
	ThreadRead(ctx context.Context, params protocol.ThreadReadParams) (*protocol.ThreadReadResponse, error)
	ThreadResume(ctx context.Context, params protocol.ThreadResumeParams) (*protocol.ThreadResumeResponse, error)
	ThreadRollback(ctx context.Context, params protocol.ThreadRollbackParams) (*protocol.ThreadRollbackResponse, error)
	ThreadShellCommand(ctx context.Context, params protocol.ThreadShellCommandParams) (*protocol.ThreadShellCommandResponse, error)
	ThreadStart(ctx context.Context, params protocol.ThreadStartParams) (*protocol.ThreadStartResponse, error)
	ThreadUnarchive(ctx context.Context, params protocol.ThreadUnarchiveParams) (*protocol.ThreadUnarchiveResponse, error)
	ThreadUnsubscribe(ctx context.Context, params protocol.ThreadUnsubscribeParams) (*protocol.ThreadUnsubscribeResponse, error)
	TurnInterrupt(ctx context.Context, params protocol.TurnInterruptParams) (*protocol.TurnInterruptResponse, error)
	TurnStart(ctx context.Context, params protocol.TurnStartParams) (*protocol.TurnStartResponse, error)
	TurnSteer(ctx context.Context, params protocol.TurnSteerParams) (*protocol.TurnSteerResponse, error)
	WindowsSandboxReadiness(ctx context.Context) (*protocol.WindowsSandboxReadinessResponse, error)
	WindowsSandboxSetupStart(ctx context.Context, params protocol.WindowsSandboxSetupStartParams) (*protocol.WindowsSandboxSetupStartResponse, error)
}

ClientRequests exposes typed JSON-RPC calls supported by the app-server.

type ConnTransport

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

ConnTransport wraps an io.ReadWriteCloser.

func NewConnTransport

func NewConnTransport(conn io.ReadWriteCloser) *ConnTransport

NewConnTransport wraps the connection in a Transport.

func (*ConnTransport) Close

func (t *ConnTransport) Close() error

Close closes the connection.

func (*ConnTransport) ReadLine

func (t *ConnTransport) ReadLine() (string, error)

ReadLine reads a line from the connection.

func (*ConnTransport) WriteLine

func (t *ConnTransport) WriteLine(line string) error

WriteLine writes a line to the connection.

type JSONRPCError

type JSONRPCError struct {
	ID    RequestID         `json:"id"`
	Error JSONRPCErrorError `json:"error"`
}

JSONRPCError represents a JSON-RPC error response.

type JSONRPCErrorError

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

JSONRPCErrorError describes the error payload.

type JSONRPCNotification

type JSONRPCNotification struct {
	Method string          `json:"method"`
	Params json.RawMessage `json:"params,omitempty"`
}

JSONRPCNotification represents a JSON-RPC notification.

type JSONRPCRequest

type JSONRPCRequest struct {
	ID     RequestID       `json:"id"`
	Method string          `json:"method"`
	Params json.RawMessage `json:"params,omitempty"`
}

JSONRPCRequest represents a JSON-RPC request.

func BuildClientRequest

func BuildClientRequest(method string, params any, id RequestID) (JSONRPCRequest, error)

BuildClientRequest builds a JSON-RPC request for a client method.

type JSONRPCResponse

type JSONRPCResponse struct {
	ID     RequestID       `json:"id"`
	Result json.RawMessage `json:"result"`
}

JSONRPCResponse represents a JSON-RPC response.

type Notification

type Notification struct {
	Method string
	Params any
	Raw    json.RawMessage
}

Notification represents a typed server notification.

func (Notification) UnmarshalParams

func (n Notification) UnmarshalParams(v any) error

UnmarshalParams decodes the raw notification params into v.

type NotificationIterator

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

NotificationIterator iterates notifications from the server.

func (*NotificationIterator) Close

func (it *NotificationIterator) Close()

Close unsubscribes the iterator.

func (*NotificationIterator) Next

Next returns the next notification or an error.

type RecordTransport

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

RecordTransport records all JSON-RPC traffic to a transcript.

func NewRecordTransport

func NewRecordTransport(transport Transport) *RecordTransport

NewRecordTransport wraps a transport and records traffic.

func NewRercordTransport

func NewRercordTransport(transport Transport) *RecordTransport

NewRercordTransport wraps a transport and records traffic.

func (*RecordTransport) Close

func (t *RecordTransport) Close() error

Close closes the underlying transport.

func (*RecordTransport) ReadLine

func (t *RecordTransport) ReadLine() (string, error)

ReadLine reads from the underlying transport and records the line.

func (*RecordTransport) Transcript

func (t *RecordTransport) Transcript() []TranscriptEntry

Transcript returns a copy of the recorded transcript.

func (*RecordTransport) WriteLine

func (t *RecordTransport) WriteLine(line string) error

WriteLine writes to the underlying transport and records the line.

type ReplayTransport

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

ReplayTransport replays a transcript of line-delimited JSON-RPC payloads. JSON writes are compared by value (after normalization) to tolerate key ordering differences.

func NewReplayTransport

func NewReplayTransport(transcript []TranscriptEntry) *ReplayTransport

NewReplayTransport creates a ReplayTransport for a transcript.

func (*ReplayTransport) Close

func (t *ReplayTransport) Close() error

Close stops the replay transport.

func (*ReplayTransport) ReadLine

func (t *ReplayTransport) ReadLine() (string, error)

ReadLine returns the next recorded read line.

func (*ReplayTransport) WriteLine

func (t *ReplayTransport) WriteLine(line string) error

WriteLine validates the next recorded write line.

type RequestID

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

RequestID represents a JSON-RPC request id (string or integer).

func NewIntRequestID

func NewIntRequestID(value int64) RequestID

NewIntRequestID creates an integer request id.

func NewStringRequestID

func NewStringRequestID(value string) RequestID

NewStringRequestID creates a string request id.

func (RequestID) IsZero

func (id RequestID) IsZero() bool

IsZero reports whether the id is unset.

func (RequestID) Key

func (id RequestID) Key() string

Key returns a stable string key for map usage.

func (RequestID) MarshalJSON

func (id RequestID) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (RequestID) String

func (id RequestID) String() string

String returns a printable representation.

func (*RequestID) UnmarshalJSON

func (id *RequestID) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

type RercordTransport

type RercordTransport = RecordTransport

RercordTransport is a misspelled alias for RecordTransport.

type ResponseError

type ResponseError struct {
	ID     RequestID
	Detail JSONRPCErrorError
}

ResponseError wraps a JSON-RPC error as a Go error.

func (*ResponseError) Error

func (err *ResponseError) Error() string

type ServerRequestHandler

ServerRequestHandler handles requests initiated by the app-server.

type StdioTransport

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

StdioTransport wraps a spawned process using stdin/stdout JSONL.

func SpawnStdio

func SpawnStdio(ctx context.Context, binary string, args []string, stderr io.Writer) (*StdioTransport, error)

SpawnStdio starts a command and uses its stdin/stdout for JSON-RPC.

func (*StdioTransport) Close

func (t *StdioTransport) Close() error

Close shuts down the process.

func (*StdioTransport) ReadLine

func (t *StdioTransport) ReadLine() (string, error)

ReadLine reads a single line from stdout.

func (*StdioTransport) WriteLine

func (t *StdioTransport) WriteLine(line string) error

WriteLine writes a single line to stdin.

type TranscriptDirection

type TranscriptDirection string

TranscriptDirection describes the direction of a recorded line.

const (
	TranscriptRead  TranscriptDirection = "read"
	TranscriptWrite TranscriptDirection = "write"
)

type TranscriptEntry

type TranscriptEntry struct {
	Direction TranscriptDirection `json:"direction"`
	Line      string              `json:"line"`
}

TranscriptEntry stores a single JSON-RPC line and its direction.

type Transport

type Transport interface {
	ReadLine() (string, error)
	WriteLine(line string) error
	Close() error
}

Transport reads and writes JSON-RPC lines.

Jump to

Keyboard shortcuts

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