jsonrpc

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CodeParseError     = -32700
	CodeInvalidRequest = -32600
	CodeMethodNotFound = -32601
	CodeInvalidParams  = -32602
	CodeInternalError  = -32603
)

Standard JSON-RPC 2.0 error codes.

View Source
const (
	CodeEvalNotFound     = -32000
	CodeValidationFailed = -32001
	CodeRunFailed        = -32002
)

Application-specific error codes.

Variables

This section is empty.

Functions

func RegisterHandlers

func RegisterHandlers(registry *MethodRegistry, hctx *HandlerContext)

RegisterHandlers registers all eval/task/run method handlers.

Types

type Error

type Error struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Data    any    `json:"data,omitempty"`
}

Error represents a JSON-RPC 2.0 error.

func ErrEvalNotFound

func ErrEvalNotFound(path string) *Error

func ErrInternalError

func ErrInternalError(data any) *Error

func ErrInvalidParams

func ErrInvalidParams(data any) *Error

func ErrInvalidRequest

func ErrInvalidRequest(data any) *Error

func ErrMethodNotFound

func ErrMethodNotFound(method string) *Error

func ErrParseError

func ErrParseError(data any) *Error

func ErrRunFailed

func ErrRunFailed(data any) *Error

func ErrValidationFailed

func ErrValidationFailed(data any) *Error

func (*Error) Error

func (e *Error) Error() string

type EvalGetParams

type EvalGetParams struct {
	Path string `json:"path"`
}

type EvalGetResult

type EvalGetResult struct {
	Name        string          `json:"name"`
	Description string          `json:"description,omitempty"`
	SkillName   string          `json:"skill,omitempty"`
	Config      models.Config   `json:"config"`
	Tasks       []string        `json:"tasks"`
	Graders     []GraderSummary `json:"graders"`
}

type EvalListParams

type EvalListParams struct {
	Dir string `json:"dir"`
}

type EvalListResult

type EvalListResult struct {
	Evals []EvalSummary `json:"evals"`
}

type EvalRunParams

type EvalRunParams struct {
	Path       string `json:"path"`
	ContextDir string `json:"context_dir,omitempty"`
}

type EvalRunResult

type EvalRunResult struct {
	RunID string `json:"run_id"`
}

type EvalSummary

type EvalSummary struct {
	Path      string `json:"path"`
	Name      string `json:"name"`
	SkillName string `json:"skill,omitempty"`
}

type EvalValidateParams

type EvalValidateParams struct {
	Path string `json:"path"`
}

type EvalValidateResult

type EvalValidateResult struct {
	Valid  bool     `json:"valid"`
	Errors []string `json:"errors,omitempty"`
}

type GraderSummary

type GraderSummary struct {
	Name string `json:"name"`
	Type string `json:"type"`
}

type Handler

type Handler func(ctx context.Context, params json.RawMessage) (any, *Error)

Handler processes a JSON-RPC request and returns a result or error.

type HandlerContext

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

HandlerContext provides shared state for method handlers.

func NewHandlerContext

func NewHandlerContext() *HandlerContext

NewHandlerContext creates a new handler context.

type MethodRegistry

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

MethodRegistry maps method names to handlers.

func NewMethodRegistry

func NewMethodRegistry() *MethodRegistry

NewMethodRegistry creates an empty registry.

func (*MethodRegistry) Lookup

func (r *MethodRegistry) Lookup(method string) Handler

Lookup returns the handler for a method, or nil if not found.

func (*MethodRegistry) Methods

func (r *MethodRegistry) Methods() []string

Methods returns all registered method names.

func (*MethodRegistry) Register

func (r *MethodRegistry) Register(method string, handler Handler)

Register adds a handler for a method name.

type Notification

type Notification struct {
	JSONRPC string `json:"jsonrpc"`
	Method  string `json:"method"`
	Params  any    `json:"params,omitempty"`
}

Notification represents a server-initiated JSON-RPC 2.0 notification (no ID).

type Request

type Request struct {
	JSONRPC string          `json:"jsonrpc"`
	Method  string          `json:"method"`
	Params  json.RawMessage `json:"params,omitempty"`
	ID      json.RawMessage `json:"id"`
}

Request represents a JSON-RPC 2.0 request.

type Response

type Response struct {
	JSONRPC string          `json:"jsonrpc"`
	Result  any             `json:"result,omitempty"`
	Error   *Error          `json:"error,omitempty"`
	ID      json.RawMessage `json:"id"`
}

Response represents a JSON-RPC 2.0 response.

type RunCancelParams

type RunCancelParams struct {
	RunID string `json:"run_id"`
}

type RunCancelResult

type RunCancelResult struct {
	Canceled bool `json:"canceled"`
}

type RunState

type RunState struct {
	ID     string `json:"id"`
	Status string `json:"status"` // "running", "completed", "failed", "canceled"
	Error  string `json:"error,omitempty"`
}

RunState tracks the status of an eval run.

type RunStatusParams

type RunStatusParams struct {
	RunID string `json:"run_id"`
}

type Server

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

Server handles JSON-RPC 2.0 requests over a Transport.

func NewServer

func NewServer(registry *MethodRegistry, logger *slog.Logger) *Server

NewServer creates a JSON-RPC server with the given method registry.

func (*Server) ServeStdio

func (s *Server) ServeStdio(stdin io.Reader, stdout io.Writer)

ServeStdio runs the server on stdin/stdout.

func (*Server) ServeTransport

func (s *Server) ServeTransport(t *Transport)

ServeTransport reads requests from the transport and writes responses. It runs until the transport's reader returns io.EOF or a read error.

type TCPListener

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

TCPListener listens for TCP connections and serves each with the given server.

func NewTCPListener

func NewTCPListener(addr string, server *Server) (*TCPListener, error)

NewTCPListener creates a TCP listener on the given address.

func (*TCPListener) Addr

func (tl *TCPListener) Addr() net.Addr

Addr returns the listener's network address.

func (*TCPListener) Close

func (tl *TCPListener) Close() error

Close shuts down the TCP listener.

func (*TCPListener) Serve

func (tl *TCPListener) Serve() error

Serve accepts connections in a loop. It blocks until the listener is closed.

type TaskGetParams

type TaskGetParams struct {
	Path   string `json:"path"`
	TaskID string `json:"task_id"`
}

type TaskListParams

type TaskListParams struct {
	Path string `json:"path"`
}

type TaskListResult

type TaskListResult struct {
	Tasks []TaskSummary `json:"tasks"`
}

type TaskSummary

type TaskSummary struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

type Transport

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

Transport reads requests and writes responses over a byte stream.

func NewTransport

func NewTransport(r io.Reader, w io.Writer) *Transport

NewTransport wraps an io.Reader and io.Writer as a JSON-RPC transport. Each JSON message is expected to be a single line terminated by newline.

func (*Transport) ReadRequest

func (t *Transport) ReadRequest() (*Request, []byte, error)

ReadRequest reads one JSON-RPC request (newline-delimited JSON). It also returns the raw JSON bytes so callers can inspect the original payload.

func (*Transport) WriteNotification

func (t *Transport) WriteNotification(notif *Notification) error

WriteNotification sends a JSON-RPC notification (newline-delimited).

func (*Transport) WriteResponse

func (t *Transport) WriteResponse(resp *Response) error

WriteResponse sends a JSON-RPC response (newline-delimited).

Jump to

Keyboard shortcuts

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