protocol

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Current version: 0.2.2

Index

Constants

View Source
const (
	// -32700: Invalid JSON payload
	ErrCodeParseError = -32700

	// -32600: Invalid JSON-RPC Request
	ErrCodeInvalidRequest = -32600

	// -32601: Method not found
	ErrCodeMethodNotFound = -32601

	// -32602: Invalid method parameters
	ErrCodeInvalidParams = -32602

	// -32603: Internal server error
	ErrCodeInternalError = -32603

	// -32000 to -32099: Reserved for server-defined errors (A2A-specific)
	ErrCodeServerErrorStart = -32099
	ErrCodeServerErrorEnd   = -32000
)

JSON-RPC 2.0 standard error codes (per A2A specification)

Variables

This section is empty.

Functions

func FreePort

func FreePort() (port int, err error)

Types

type AgentCapabilities

type AgentCapabilities struct {
	Streaming              *bool            `json:"streaming,omitempty"`
	PushNotifications      *bool            `json:"pushNotifications,omitempty"`
	StateTransitionHistory *bool            `json:"stateTransitionHistory,omitempty"`
	Extensions             []AgentExtension `json:"extensions,omitempty"`
}

type AgentCard

type AgentCard struct {
	Name                              string                `json:"name"`
	Description                       string                `json:"description"`
	URL                               string                `json:"url"`
	IconURL                           *string               `json:"iconUrl,omitempty"`
	Provider                          *AgentProvider        `json:"provider,omitempty"`
	Version                           string                `json:"version"`
	DocumentationURL                  *string               `json:"documentationUrl,omitempty"`
	Capabilities                      AgentCapabilities     `json:"capabilities"`
	SecuritySchemes                   map[string]string     `json:"securitySchemes,omitempty"`
	Security                          []map[string][]string `json:"security,omitempty"`
	DefaultInputModes                 []string              `json:"defaultInputModes"`
	DefaultOutputModes                []string              `json:"defaultOutputModes"`
	Skills                            []AgentSkill          `json:"skills"`
	SupportsAuthenticatedExtendedCard *bool                 `json:"supportsAuthenticatedExtendedCard,omitempty"`
}

type AgentCardBuilder

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

func Card

func Card() *AgentCardBuilder

func (*AgentCardBuilder) Build

func (b *AgentCardBuilder) Build() AgentCard

func (*AgentCardBuilder) Capabilities

func (b *AgentCardBuilder) Capabilities(capabilities AgentCapabilities) *AgentCardBuilder

func (*AgentCardBuilder) DefaultInputModes

func (b *AgentCardBuilder) DefaultInputModes(modes []string) *AgentCardBuilder

func (*AgentCardBuilder) DefaultOutputModes

func (b *AgentCardBuilder) DefaultOutputModes(modes []string) *AgentCardBuilder

func (*AgentCardBuilder) Description

func (b *AgentCardBuilder) Description(desc string) *AgentCardBuilder

func (*AgentCardBuilder) DocumentationURL

func (b *AgentCardBuilder) DocumentationURL(url string) *AgentCardBuilder

func (*AgentCardBuilder) Name

func (b *AgentCardBuilder) Name(name string) *AgentCardBuilder

func (*AgentCardBuilder) Provider

func (b *AgentCardBuilder) Provider(provider AgentProvider) *AgentCardBuilder

func (*AgentCardBuilder) Skill

func (b *AgentCardBuilder) Skill(id, name, description string) *AgentCardBuilder

func (*AgentCardBuilder) Skills

func (b *AgentCardBuilder) Skills(skills []AgentSkill) *AgentCardBuilder

func (*AgentCardBuilder) URL

func (*AgentCardBuilder) Version

func (b *AgentCardBuilder) Version(version string) *AgentCardBuilder

type AgentExtension

type AgentExtension struct {
	URI         string                 `json:"uri"`
	Description *string                `json:"description,omitempty"`
	Required    *bool                  `json:"required,omitempty"`
	Params      map[string]interface{} `json:"params,omitempty"`
}

type AgentProvider

type AgentProvider struct {
	Organization string `json:"organization"`
	URL          string `json:"url"`
}

type AgentSkill

type AgentSkill struct {
	ID          string   `json:"id"`
	Name        string   `json:"name"`
	Description string   `json:"description"`
	Tags        []string `json:"tags"`
	Examples    []string `json:"examples,omitempty"`
	InputModes  []string `json:"inputModes,omitempty"`
	OutputModes []string `json:"outputModes,omitempty"`
}

type Artifact

type Artifact struct {
	ArtifactID  string           `json:"artifactId"`            // Required: unique identifier
	Name        *string          `json:"name,omitempty"`        // Optional: human-readable name
	Description *string          `json:"description,omitempty"` // Optional: human-readable description
	Parts       []map[string]any `json:"parts"`                 // Required: parts (can be refined later)
	Metadata    map[string]any   `json:"metadata,omitempty"`    // Optional: extension metadata
	Extensions  []string         `json:"extensions,omitempty"`  // Optional: contributed extension URIs
}

type Client

type Client interface {
	SendMessage(question MessageSendParams) (*JSONRPCResponse, error)
	StreamMessage()
	GetTask()
	CancelTask()
}

func NewCustomClient

func NewCustomClient(url string) Client

type CustomClient

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

func (*CustomClient) CancelTask

func (c *CustomClient) CancelTask()

func (*CustomClient) GetTask

func (c *CustomClient) GetTask()

func (*CustomClient) SendMessage

func (c *CustomClient) SendMessage(params MessageSendParams) (*JSONRPCResponse, error)

func (*CustomClient) StreamMessage

func (c *CustomClient) StreamMessage()

type CustomServer

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

func (*CustomServer) Close

func (c *CustomServer) Close() error

func (*CustomServer) SetHandler

func (serv *CustomServer) SetHandler(handler MessageHandler)

func (*CustomServer) Start

func (c *CustomServer) Start(ready chan<- struct{}) error

type DataPart

type DataPart struct {
	Kind PartKind       `json:"kind"` // Must be "data"
	Data map[string]any `json:"data"` // Required structured content
}

func (*DataPart) PartKind

func (p *DataPart) PartKind() PartKind

type FilePart

type FilePart struct {
	Kind PartKind `json:"kind"` // Must be "file"
	File any      `json:"file"` // Can be FileWithBytes or FileWithUri
}

func NewFileBytes

func NewFileBytes(data []byte) *FilePart

func NewFileURI

func NewFileURI(uri string) *FilePart

func (*FilePart) PartKind

func (p *FilePart) PartKind() PartKind

func (*FilePart) UnmarshalJSON

func (p *FilePart) UnmarshalJSON(data []byte) error

type FileWithBytes

type FileWithBytes struct {
	Bytes string `json:"bytes"` // Required: base64-encoded content
}

type FileWithURI

type FileWithURI struct {
	URI string `json:"uri"` // Required: URI to the file
}

type JSONRPCError

type JSONRPCError struct {
	Code    int    `json:"code"`           // Error code indicating the type of error
	Message string `json:"message"`        // Short description of the error
	Data    any    `json:"data,omitempty"` // Optional additional information (any type)
}

type JSONRPCRequest

type JSONRPCRequest struct {
	JSONRPC string `json:"jsonrpc"`          // MUST be "2.0"
	Method  string `json:"method"`           // e.g., "message/send"
	Params  any    `json:"params,omitempty"` // Can be any structured value (typically an object)
	ID      any    `json:"id,omitempty"`     // string, number (int), or nil
}

type JSONRPCResponse

type JSONRPCResponse struct {
	JSONRPC string        `json:"jsonrpc"`          // MUST be "2.0"
	ID      any           `json:"id"`               // Same type as in request (string, int, or null)
	Result  any           `json:"result,omitempty"` // Present only on success
	Error   *JSONRPCError `json:"error,omitempty"`  // Present only on failure
}

func (*JSONRPCResponse) UnmarshalJSON

func (r *JSONRPCResponse) UnmarshalJSON(data []byte) error

type Kind

type Kind string
const (
	KindTask    Kind = "task"
	KindMessage Kind = "message"
)

type Message

type Message struct {
	Role             string         `json:"role"`                       // "user" or "agent"
	Parts            Parts          `json:"parts"`                      // Required message content
	Metadata         map[string]any `json:"metadata,omitempty"`         // Optional extension metadata
	Extensions       []string       `json:"extensions,omitempty"`       // Optional list of extension URIs
	ReferenceTaskIDs []string       `json:"referenceTaskIds,omitempty"` // Optional task references
	MessageID        string         `json:"messageId"`                  // Required message ID
	TaskID           *string        `json:"taskId,omitempty"`           // Optional task ID
	ContextID        *string        `json:"contextId,omitempty"`        // Optional context ID
	Kind             Kind           `json:"kind"`                       // Must be "message"
}

func LogRequest

func LogRequest(message *Message) (*Message, error)

type MessageBuilder

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

func NewMessageBuilder

func NewMessageBuilder() *MessageBuilder

func (*MessageBuilder) Build

func (b *MessageBuilder) Build() Message

func (*MessageBuilder) ContextID

func (b *MessageBuilder) ContextID(contextID string) *MessageBuilder

func (*MessageBuilder) Extensions

func (b *MessageBuilder) Extensions(ext ...string) *MessageBuilder

func (*MessageBuilder) MessageID

func (b *MessageBuilder) MessageID(id string) *MessageBuilder

func (*MessageBuilder) MetadataField

func (b *MessageBuilder) MetadataField(key string, value any) *MessageBuilder

func (*MessageBuilder) Part

func (b *MessageBuilder) Part(part Part) *MessageBuilder

func (*MessageBuilder) ReferenceTaskIDs

func (b *MessageBuilder) ReferenceTaskIDs(ids ...string) *MessageBuilder

func (*MessageBuilder) Role

func (b *MessageBuilder) Role(role string) *MessageBuilder

func (*MessageBuilder) TaskID

func (b *MessageBuilder) TaskID(taskID string) *MessageBuilder

type MessageHandler

type MessageHandler func(message *Message) (*Message, error)

type MessageSendConfiguration

type MessageSendConfiguration struct {
	AcceptedOutputModes    []string                `json:"acceptedOutputModes"`              // Required
	HistoryLength          *int                    `json:"historyLength,omitempty"`          // Optional
	PushNotificationConfig *PushNotificationConfig `json:"pushNotificationConfig,omitempty"` // Optional
	Blocking               *bool                   `json:"blocking,omitempty"`               // Optional
}

type MessageSendParams

type MessageSendParams struct {
	Message       Message                   `json:"message"`                 // Required
	Configuration *MessageSendConfiguration `json:"configuration,omitempty"` // Optional
	Metadata      map[string]any            `json:"metadata,omitempty"`      // Optional key-value extension metadata
}

type MessageSendParamsBuilder

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

func NewMessageSendParamsBuilder

func NewMessageSendParamsBuilder() *MessageSendParamsBuilder

func (*MessageSendParamsBuilder) Build

func (*MessageSendParamsBuilder) Configuration

func (*MessageSendParamsBuilder) Message

func (*MessageSendParamsBuilder) Metadata

type Part

type Part interface {
	PartKind() PartKind
}

type PartKind

type PartKind string
const (
	PartKindText PartKind = "text"
	PartKindFile PartKind = "file"
	PartKindData PartKind = "data"
)

type Parts

type Parts []Part

func (*Parts) UnmarshalJSON

func (p *Parts) UnmarshalJSON(data []byte) error

type PushNotificationAuthenticationInfo

type PushNotificationAuthenticationInfo struct {
	Schemes     []string `json:"schemes"`               // Required
	Credentials *string  `json:"credentials,omitempty"` // Optional
}

type PushNotificationConfig

type PushNotificationConfig struct {
	ID             *string                             `json:"id,omitempty"`             // Optional
	URL            string                              `json:"url"`                      // Required
	Token          *string                             `json:"token,omitempty"`          // Optional
	Authentication *PushNotificationAuthenticationInfo `json:"authentication,omitempty"` // Optional
}

type Server

type Server interface {
	Start(ready chan<- struct{}) error
	SetHandler(handler MessageHandler)
	Close() error
}

func NewCustomServer

func NewCustomServer(card AgentCard, port int) Server

func NewTrpcServer

func NewTrpcServer(card AgentCard, port int) (Server, error)

type Task

type Task struct {
	ID        string         `json:"id"`                  // Required: task ID
	ContextID string         `json:"contextId"`           // Required: contextual alignment
	Status    TaskStatus     `json:"status"`              // Required: current status
	History   []Message      `json:"history,omitempty"`   // Optional: message history
	Artifacts []Artifact     `json:"artifacts,omitempty"` // Optional: artifacts created
	Metadata  map[string]any `json:"metadata,omitempty"`  // Optional: extension metadata
	Kind      Kind           `json:"kind"`                // Required: must be "task"
}

type TaskPushNotificationConfig

type TaskPushNotificationConfig struct {
	TaskID                 string                 `json:"taskId"`                 // Required: task to configure or query
	PushNotificationConfig PushNotificationConfig `json:"pushNotificationConfig"` // Required: config to set or return
}

type TaskState

type TaskState string
const (
	// Task received by the server and acknowledged, but processing has not yet actively started.
	TaskStateSubmitted TaskState = "submitted"

	// Task is actively being processed by the agent.
	// Client may expect further updates or a terminal state.
	TaskStateWorking TaskState = "working"

	// Agent requires additional input from the client/user to proceed.
	// The task is effectively paused.
	TaskStateInputRequired TaskState = "input-required"

	// Task finished successfully.
	// Results are typically available in Task.artifacts or TaskStatus.message.
	TaskStateCompleted TaskState = "completed"

	// Task was canceled (e.g., by a tasks/cancel request or server-side policy).
	TaskStateCanceled TaskState = "canceled"

	// Task terminated due to an error during processing.
	// TaskStatus.message may contain error details.
	TaskStateFailed TaskState = "failed"

	// Task terminated due to rejection by remote agent.
	// TaskStatus.message may contain error details.
	TaskStateRejected TaskState = "rejected"

	// Agent requires additional authentication from the client/user to proceed.
	// The task is effectively paused.
	TaskStateAuthRequired TaskState = "auth-required"

	// TaskStateUnknown:
	// The state of the task cannot be determined (e.g., task ID is invalid, unknown, or has expired).
	TaskStateUnknown TaskState = "unknown"
)

type TaskStatus

type TaskStatus struct {
	State     TaskState `json:"state"`               // Required
	Message   *Message  `json:"message,omitempty"`   // Optional: additional status message
	Timestamp *string   `json:"timestamp,omitempty"` // Optional: ISO 8601 datetime string
}

type TextPart

type TextPart struct {
	Kind PartKind `json:"kind"` // Must be "text"
	Text string   `json:"text"` // Required text content
}

func NewText

func NewText(text string) *TextPart

func (*TextPart) PartKind

func (p *TextPart) PartKind() PartKind

type TrpcServer

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

func (*TrpcServer) Close

func (s *TrpcServer) Close() error

func (*TrpcServer) SetHandler

func (s *TrpcServer) SetHandler(handler MessageHandler)

func (*TrpcServer) Start

func (s *TrpcServer) Start(ready chan<- struct{}) error

Jump to

Keyboard shortcuts

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