jsonrpc

package
v1.0.0-alpha Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package jsonrpc provides JSON-RPC 2.0 protocol implementation for A2A.

Index

Constants

View Source
const (
	Version = "2.0"

	// HTTP headers
	ContentJSON = "application/json"

	// JSON-RPC method names per A2A spec §7
	MethodMessageSend          = "SendMessage"
	MethodMessageStream        = "SendStreamingMessage"
	MethodTasksGet             = "GetTask"
	MethodTasksList            = "ListTasks"
	MethodTasksCancel          = "CancelTask"
	MethodTasksResubscribe     = "SubscribeToTask"
	MethodPushConfigGet        = "GetTaskPushNotificationConfig"
	MethodPushConfigSet        = "CreateTaskPushNotificationConfig"
	MethodPushConfigList       = "ListTaskPushNotificationConfigs"
	MethodPushConfigDelete     = "DeleteTaskPushNotificationConfig"
	MethodGetExtendedAgentCard = "GetExtendedAgentCard"
)

JSON-RPC 2.0 protocol constants

Variables

This section is empty.

Functions

func IsValidID

func IsValidID(id any) bool

IsValidID checks if the given ID is valid for a JSON-RPC request.

Types

type ClientRequest

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

ClientRequest represents a JSON-RPC 2.0 client request.

type ClientResponse

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

ClientResponse represents a JSON-RPC 2.0 client response.

type Error

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

Error represents a JSON-RPC 2.0 error object. TODO(yarolegovich): Convert to transport-agnostic error format so Client can use errors.Is(err, a2a.ErrMethodNotFound). This needs to be implemented across all transports (currently not in grpc either).

func ToJSONRPCError

func ToJSONRPCError(err error) *Error

ToJSONRPCError converts an error to a JSON-RPC Error.

func (*Error) Error

func (e *Error) Error() string

Error implements the error interface for jsonrpcError.

func (*Error) ToA2AError

func (e *Error) ToA2AError() error

ToA2AError converts a JSON-RPC error to an a2a.Error.

type ServerRequest

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

ServerRequest represents a JSON-RPC 2.0 server request.

type ServerResponse

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

ServerResponse represents a JSON-RPC 2.0 server response.

Jump to

Keyboard shortcuts

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