jsonrpc

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

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

Documentation

Overview

Package jsonrpc is JSON-RPC 2.0 over newline-delimited JSON: ACP's stdio transport (ADR 0002), for KairoCode as an ACP agent and as an ACP client of other agents (ADR 0014).

Index

Constants

View Source
const (
	CodeParse          = -32700
	CodeInvalidRequest = -32600
	CodeMethodNotFound = -32601
	CodeInvalidParams  = -32602
	CodeInternal       = -32603
	// CodeCancelled answers a request cancelled with $/cancel_request.
	CodeCancelled = -32800
)

JSON-RPC error codes.

Variables

View Source
var ErrClosed = errors.New("jsonrpc: the connection is closed")

ErrClosed: the connection ended before the response came.

Functions

This section is empty.

Types

type Conn

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

Conn is a JSON-RPC connection over newline-delimited JSON (ACP's stdio transport). Requests from the other side are handled each in its own goroutine; ours wait for their responses.

func NewConn

func NewConn(w io.Writer) *Conn

func (*Conn) Call

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

Call sends a request and waits for its response into out. When ctx ends first, the request is cancelled ($/cancel_request) and ctx's error returned.

func (*Conn) Notify

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

Notify sends a notification.

func (*Conn) Serve

func (c *Conn) Serve(ctx context.Context, r io.Reader, h Handler) error

Serve reads messages from r until it ends or ctx does, giving requests and notifications to h. It returns once the requests it started have been answered.

type Error

type Error struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

func (*Error) Error

func (e *Error) Error() string

type Handler

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

Handler answers a request (its result, or an error) or takes a notification (the result is dropped).

type Message

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

Message is a JSON-RPC 2.0 message: a request (ID and Method), a notification (Method only) or a response (ID, and Result or Error).

type Then

type Then struct {
	Result any
	After  func()
}

Then is a result to answer with, and what to do once the answer is written: what the handler starts that may write to the peer (a request of its own) comes after its answer.

Jump to

Keyboard shortcuts

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