Documentation
¶
Overview ¶
Package protocol defines the versioned JSON-RPC protocol shared by Kodelet control planes and workspace-bound runners.
Index ¶
- Constants
- Variables
- func RequestIDFromContext(ctx context.Context) string
- func SupportsVersion(versions []int, version int) bool
- type AgentDescriptor
- type ClientCapabilities
- type EnvironmentErrorParams
- type GoodbyeParams
- type HeartbeatParams
- type Host
- type ManifestChangedParams
- type Message
- type NotificationHandler
- type NotificationHandlerFunc
- type OperationCancelParams
- type Peer
- func (p *Peer) Call(ctx context.Context, method string, params any, result any) error
- func (p *Peer) CallTracked(ctx context.Context, method string, params any, result any, ...) error
- func (p *Peer) Close() error
- func (p *Peer) Done() <-chan struct{}
- func (p *Peer) Err() error
- func (p *Peer) Notify(ctx context.Context, method string, params any) error
- func (p *Peer) NotifyUpdate(method string, params any) error
- func (p *Peer) Shutdown(ctx context.Context, code int, reason string) error
- func (p *Peer) Start(parent context.Context) error
- func (p *Peer) TransportDone() <-chan struct{}
- type PeerConfig
- type RPCError
- type RPCErrorData
- type RegisterParams
- type RegisterResult
- type RequestHandler
- type RequestHandlerFunc
- type RunCancelParams
- type RunCloseParams
- type RunOpenParams
- type RunStatus
- type RunnerCapabilities
- type RunnerState
- type Workspace
Constants ¶
const ( // Version is the initial runner application protocol version. Version = 1 // JSONRPCVersion is the JSON-RPC wire version used by the runner protocol. JSONRPCVersion = "2.0" // Subprotocol is required during the WebSocket upgrade. Subprotocol = "kodelet.runner.v1.jsonrpc" // Endpoint is the control-plane WebSocket endpoint used by runners. Endpoint = "/api/runner/v1/connect" )
const ( MethodRunnerRegister = "runner.register" MethodRunnerHeartbeat = "runner.heartbeat" MethodRunnerManifestChanged = "runner.manifestChanged" MethodRunnerGoodbye = "runner.goodbye" MethodRunOpen = "run.open" MethodRunClose = "run.close" MethodRunCancel = "run.cancel" MethodRunEnvironmentError = "run.environmentError" MethodCommandExecute = "command.execute" MethodLifecycleDispatch = "lifecycle.dispatch" MethodToolExecute = "tool.execute" MethodToolUpdate = "tool.update" MethodUIInput = "ui.input" MethodUIConfirm = "ui.confirm" MethodUISelect = "ui.select" MethodUINotify = "ui.notify" MethodUIWidgetSet = "ui.widget.set" MethodUIWidgetFrame = "ui.widget.frame" MethodUIWidgetRemove = "ui.widget.remove" MethodUITranscriptAppend = "ui.transcript.append" MethodUISurfaceOpen = "ui.surface.open" MethodUISurfaceFrame = "ui.surface.frame" MethodUISurfaceClose = "ui.surface.close" MethodUISurfaceInput = "ui.surface.input" MethodUISurfaceResize = "ui.surface.resize" MethodOperationCancel = "operation.cancel" )
const ( ErrorCodeParseError = -32700 ErrorCodeInvalidRequest = -32600 ErrorCodeMethodNotFound = -32601 ErrorCodeInvalidParams = -32602 ErrorCodeInternal = -32603 ErrorCodeConflict = -32001 ErrorCodeStale = -32002 ErrorCodeBusy = -32003 )
const ( ErrorReasonRunnerNotFound = "runner_not_found" ErrorReasonRunNotActive = "run_not_active" ErrorReasonResultTooLarge = "result_too_large" )
Variables ¶
var ( // ErrPeerClosed is returned when an RPC operation targets a closed peer. ErrPeerClosed = errors.New("runner rpc peer is closed") // ErrPeerNotStarted is returned when an operation precedes Start. ErrPeerNotStarted = errors.New("runner rpc peer is not started") )
Functions ¶
func RequestIDFromContext ¶
RequestIDFromContext returns the wire request ID for an inbound RPC handler.
func SupportsVersion ¶
SupportsVersion reports whether a peer advertised a protocol version.
Types ¶
type AgentDescriptor ¶
type AgentDescriptor struct {
Provider string `json:"provider"`
Model string `json:"model"`
Profile string `json:"profile,omitempty"`
EnvironmentProfile string `json:"environmentProfile,omitempty"`
RecipeName string `json:"recipeName,omitempty"`
InvokedBy string `json:"invokedBy,omitempty"`
}
AgentDescriptor carries only provider-sensitive identifiers needed by runner resources.
type ClientCapabilities ¶
type ClientCapabilities struct {
InteractiveUI bool `json:"interactiveUI"`
PersistentSurfaces bool `json:"persistentSurfaces"`
}
ClientCapabilities describes the interactive client attached to a run.
type EnvironmentErrorParams ¶
EnvironmentErrorParams reports a runner-side asynchronous run failure.
type GoodbyeParams ¶
type GoodbyeParams struct {
RunnerID string `json:"runnerId"`
Generation int64 `json:"generation"`
Reason string `json:"reason,omitempty"`
}
GoodbyeParams reports an intentional runner disconnect.
type HeartbeatParams ¶
type HeartbeatParams struct {
RunnerID string `json:"runnerId"`
Generation int64 `json:"generation"`
State RunnerState `json:"state"`
ActiveRunID string `json:"activeRunId,omitempty"`
ActiveRunIDs []string `json:"activeRunIds,omitempty"`
ManifestDigest string `json:"manifestDigest,omitempty"`
}
HeartbeatParams reports application health separately from WebSocket liveness.
func (HeartbeatParams) NormalizedActiveRunIDs ¶
func (p HeartbeatParams) NormalizedActiveRunIDs() ([]string, error)
NormalizedActiveRunIDs returns the deterministic active-run set advertised by a heartbeat. ActiveRunID remains accepted for compatibility with singular-run runner clients.
func (HeartbeatParams) Validate ¶
func (p HeartbeatParams) Validate() error
Validate checks heartbeat identity and application state fields.
type Host ¶
type Host struct {
InstanceID string `json:"instanceId"`
Hostname string `json:"hostname"`
OS string `json:"os"`
Arch string `json:"arch"`
PID int `json:"pid,omitempty"`
}
Host describes one stable runner installation and its mutable display metadata.
type ManifestChangedParams ¶
type ManifestChangedParams struct {
RunnerID string `json:"runnerId"`
Generation int64 `json:"generation"`
ManifestDigest string `json:"manifestDigest"`
}
ManifestChangedParams reports an idle-manifest digest transition.
type Message ¶
type Message struct {
JSONRPC string `json:"jsonrpc"`
ID *string `json:"id,omitempty"`
Method string `json:"method,omitempty"`
Params json.RawMessage `json:"params,omitempty"`
Result json.RawMessage `json:"result,omitempty"`
Error *RPCError `json:"error,omitempty"`
}
Message is the small JSON-native envelope used for requests, responses, and notifications. Runner request identifiers are strings with an origin-specific prefix.
func DecodeMessage ¶
DecodeMessage decodes and validates one complete WebSocket text frame.
type NotificationHandler ¶
type NotificationHandler interface {
HandleNotification(ctx context.Context, method string, params json.RawMessage)
}
NotificationHandler handles notifications received from the remote peer.
type NotificationHandlerFunc ¶
type NotificationHandlerFunc func(context.Context, string, json.RawMessage)
NotificationHandlerFunc adapts a function to NotificationHandler.
func (NotificationHandlerFunc) HandleNotification ¶
func (f NotificationHandlerFunc) HandleNotification(ctx context.Context, method string, params json.RawMessage)
type OperationCancelParams ¶
type OperationCancelParams struct {
RequestID string `json:"requestId"`
}
OperationCancelParams cancels one in-flight JSON-RPC request by its wire ID.
type Peer ¶
type Peer struct {
// contains filtered or unexported fields
}
Peer owns one WebSocket reader, one writer, bounded outbound queues, and symmetric RPC correlation.
func NewPeer ¶
func NewPeer(conn *websocket.Conn, config PeerConfig) (*Peer, error)
NewPeer creates a dormant peer. Start must be called after handlers have been fully wired.
func (*Peer) CallTracked ¶
func (p *Peer) CallTracked(ctx context.Context, method string, params any, result any, onRequestID func(string)) error
CallTracked sends a request and synchronously exposes its wire ID before enqueueing it.
func (*Peer) Done ¶
func (p *Peer) Done() <-chan struct{}
Done closes after the transport and all in-flight handlers terminate.
func (*Peer) NotifyUpdate ¶
NotifyUpdate sends a replaceable low-priority notification. When the bounded queue is full, the oldest pending update is discarded in favor of this one.
func (*Peer) TransportDone ¶
func (p *Peer) TransportDone() <-chan struct{}
TransportDone closes as soon as the WebSocket transport terminates.
type PeerConfig ¶
type PeerConfig struct {
RequestPrefix string
Handler RequestHandler
Notifications NotificationHandler
ControlQueueSize int
UpdateQueueSize int
WriteWait time.Duration
ShutdownWait time.Duration
PongWait time.Duration
PingPeriod time.Duration
ReadLimit int64
WriteLimit int64
MaxConcurrentRequests int
MaxConcurrentControlRequests int
MaxConcurrentNotifications int
}
PeerConfig configures one symmetric JSON-RPC WebSocket peer.
type RPCError ¶
type RPCError struct {
Code int `json:"code"`
Message string `json:"message"`
Data any `json:"data,omitempty"`
}
RPCError is a JSON-RPC error object.
type RPCErrorData ¶
type RPCErrorData struct {
Reason string `json:"reason,omitempty"`
}
RPCErrorData carries stable machine-readable error details.
type RegisterParams ¶
type RegisterParams struct {
ProtocolVersions []int `json:"protocolVersions"`
RunnerID string `json:"runnerId,omitempty"`
DisplayName string `json:"displayName,omitempty"`
Host Host `json:"host"`
Workspace Workspace `json:"workspace"`
Capabilities RunnerCapabilities `json:"capabilities,omitempty"`
KodeletVersion string `json:"kodeletVersion"`
ManifestDigest string `json:"manifestDigest,omitempty"`
}
RegisterParams is the first request sent by a runner connection.
func (RegisterParams) Validate ¶
func (p RegisterParams) Validate() error
Validate checks registration identity and version negotiation fields.
type RegisterResult ¶
type RegisterResult struct {
RunnerID string `json:"runnerId"`
ProtocolVersion int `json:"protocolVersion"`
ConnectionID string `json:"connectionId"`
Generation int64 `json:"generation"`
HeartbeatIntervalMS int64 `json:"heartbeatIntervalMs"`
}
RegisterResult establishes the stable runner ID and live connection generation.
type RequestHandler ¶
type RequestHandler interface {
HandleRequest(ctx context.Context, method string, params json.RawMessage) (any, *RPCError)
}
RequestHandler handles requests received from the remote peer.
type RequestHandlerFunc ¶
RequestHandlerFunc adapts a function to RequestHandler.
func (RequestHandlerFunc) HandleRequest ¶
func (f RequestHandlerFunc) HandleRequest(ctx context.Context, method string, params json.RawMessage) (any, *RPCError)
type RunCancelParams ¶
RunCancelParams cancels active runner operations for one run.
type RunCloseParams ¶
type RunCloseParams struct {
RunID string `json:"runId"`
}
RunCloseParams releases a pinned run environment.
type RunOpenParams ¶
type RunOpenParams struct {
RunID string `json:"runId"`
ConversationID string `json:"conversationId"`
Agent AgentDescriptor `json:"agent"`
ClientCapabilities ClientCapabilities `json:"clientCapabilities"`
ReservedToolNames []string `json:"reservedToolNames"`
}
RunOpenParams asks a runner to pin one environment snapshot.
func (RunOpenParams) Validate ¶
func (p RunOpenParams) Validate() error
type RunStatus ¶
type RunStatus string
RunStatus is the durable-shape state machine shared by remote environments and the control plane.
type RunnerCapabilities ¶
type RunnerCapabilities struct {
ConcurrentRuns bool `json:"concurrentRuns,omitempty"`
}
RunnerCapabilities declares optional behavior supported by this runner process.
type RunnerState ¶
type RunnerState string
RunnerState is the application-level availability reported by heartbeats.
const ( RunnerStateIdle RunnerState = "idle" RunnerStateRunning RunnerState = "running" RunnerStateStopping RunnerState = "stopping" RunnerStateError RunnerState = "error" )