Documentation
¶
Index ¶
- Constants
- func RegisterHandlers(registry *MethodRegistry, hctx *HandlerContext)
- type Error
- func ErrEvalNotFound(path string) *Error
- func ErrInternalError(data any) *Error
- func ErrInvalidParams(data any) *Error
- func ErrInvalidRequest(data any) *Error
- func ErrMethodNotFound(method string) *Error
- func ErrParseError(data any) *Error
- func ErrRunFailed(data any) *Error
- func ErrValidationFailed(data any) *Error
- type EvalGetParams
- type EvalGetResult
- type EvalListParams
- type EvalListResult
- type EvalRunParams
- type EvalRunResult
- type EvalSummary
- type EvalValidateParams
- type EvalValidateResult
- type GraderSummary
- type Handler
- type HandlerContext
- type MethodRegistry
- type Notification
- type Request
- type Response
- type RunCancelParams
- type RunCancelResult
- type RunState
- type RunStatusParams
- type Server
- type TCPListener
- type TaskGetParams
- type TaskListParams
- type TaskListResult
- type TaskSummary
- type Transport
Constants ¶
const ( CodeParseError = -32700 CodeInvalidRequest = -32600 CodeMethodNotFound = -32601 CodeInvalidParams = -32602 CodeInternalError = -32603 )
Standard JSON-RPC 2.0 error codes.
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 ErrInternalError ¶
func ErrInvalidParams ¶
func ErrInvalidRequest ¶
func ErrMethodNotFound ¶
func ErrParseError ¶
func ErrRunFailed ¶
func ErrValidationFailed ¶
type EvalGetParams ¶
type EvalGetParams struct {
Path string `json:"path"`
}
type EvalGetResult ¶
type EvalListParams ¶
type EvalListParams struct {
Dir string `json:"dir"`
}
type EvalListResult ¶
type EvalListResult struct {
Evals []EvalSummary `json:"evals"`
}
type EvalRunParams ¶
type EvalRunResult ¶
type EvalRunResult struct {
RunID string `json:"run_id"`
}
type EvalSummary ¶
type EvalValidateParams ¶
type EvalValidateParams struct {
Path string `json:"path"`
}
type EvalValidateResult ¶
type GraderSummary ¶
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 ¶
ServeStdio runs the server on stdin/stdout.
func (*Server) ServeTransport ¶
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) Serve ¶
func (tl *TCPListener) Serve() error
Serve accepts connections in a loop. It blocks until the listener is closed.
type TaskGetParams ¶
type TaskListParams ¶
type TaskListParams struct {
Path string `json:"path"`
}
type TaskListResult ¶
type TaskListResult struct {
Tasks []TaskSummary `json:"tasks"`
}
type TaskSummary ¶
type Transport ¶
type Transport struct {
// contains filtered or unexported fields
}
Transport reads requests and writes responses over a byte stream.
func NewTransport ¶
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 ¶
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 ¶
WriteResponse sends a JSON-RPC response (newline-delimited).