Help us shape the future of Go! Take the 2026 Go Developer Survey

client

package
v0.34.0 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: Apache-2.0 Imports: 16 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type A2AClient

type A2AClient interface {
	// Agent discovery
	GetAgentCard(ctx context.Context) (*types.AgentCard, error)
	GetAuthenticatedExtendedCard(ctx context.Context, params types.GetExtendedAgentCardRequest) (*types.JSONRPCSuccessResponse, error)
	GetHealth(ctx context.Context) (*HealthResponse, error)

	// Task operations
	SendTask(ctx context.Context, params types.SendMessageRequest) (*types.JSONRPCSuccessResponse, error)
	SendTaskStreaming(ctx context.Context, params types.SendMessageRequest) (<-chan types.JSONRPCSuccessResponse, error)
	GetTask(ctx context.Context, params types.GetTaskRequest) (*types.JSONRPCSuccessResponse, error)
	ListTasks(ctx context.Context, params types.ListTasksRequest) (*types.JSONRPCSuccessResponse, error)
	CancelTask(ctx context.Context, params types.CancelTaskRequest) (*types.JSONRPCSuccessResponse, error)
	ResubscribeTask(ctx context.Context, params types.SubscribeToTaskRequest) (<-chan types.JSONRPCSuccessResponse, error)

	// Push notification configuration
	SetTaskPushNotificationConfig(ctx context.Context, params types.TaskPushNotificationConfig) (*types.JSONRPCSuccessResponse, error)
	GetTaskPushNotificationConfig(ctx context.Context, params types.GetTaskPushNotificationConfigRequest) (*types.JSONRPCSuccessResponse, error)
	ListTaskPushNotificationConfig(ctx context.Context, params types.ListTaskPushNotificationConfigsRequest) (*types.JSONRPCSuccessResponse, error)
	DeleteTaskPushNotificationConfig(ctx context.Context, params types.DeleteTaskPushNotificationConfigRequest) (*types.JSONRPCSuccessResponse, error)

	// Configuration
	SetTimeout(timeout time.Duration)
	SetHTTPClient(client *http.Client)
	GetBaseURL() string

	// Logger configuration
	SetLogger(logger *zap.Logger)
	GetLogger() *zap.Logger

	// Artifact utilities
	GetArtifactHelper() *ArtifactHelper
}

A2AClient defines the interface for an A2A protocol client

func NewClient

func NewClient(baseURL string) A2AClient

NewClient creates a new A2A client with default configuration

func NewClientWithConfig

func NewClientWithConfig(config *Config) A2AClient

NewClientWithConfig creates a new A2A client with custom configuration

func NewClientWithLogger

func NewClientWithLogger(baseURL string, logger *zap.Logger) A2AClient

NewClientWithLogger creates a new A2A client with a custom logger

type ArtifactHelper added in v0.10.0

type ArtifactHelper struct{}

ArtifactHelper provides utility functions for working with artifacts in client responses

func NewArtifactHelper added in v0.10.0

func NewArtifactHelper() *ArtifactHelper

NewArtifactHelper creates a new client-side artifact helper instance

func (*ArtifactHelper) DownloadAllArtifacts added in v0.13.1

func (ah *ArtifactHelper) DownloadAllArtifacts(ctx context.Context, task *types.Task, config *DownloadConfig) ([]*DownloadResult, error)

DownloadAllArtifacts downloads all files from all artifacts in a task

func (*ArtifactHelper) DownloadArtifact added in v0.13.1

func (ah *ArtifactHelper) DownloadArtifact(ctx context.Context, artifact *types.Artifact, config *DownloadConfig) ([]*DownloadResult, error)

DownloadArtifact downloads all files from an artifact

func (*ArtifactHelper) DownloadFileData added in v0.13.1

func (ah *ArtifactHelper) DownloadFileData(ctx context.Context, fileData FileData, config *DownloadConfig) (*DownloadResult, error)

DownloadFileData downloads a FileData object to disk

func (*ArtifactHelper) ExtractArtifactUpdateFromStreamEvent added in v0.10.0

func (ah *ArtifactHelper) ExtractArtifactUpdateFromStreamEvent(eventData any) (*types.TaskArtifactUpdateEvent, bool)

ExtractArtifactUpdateFromStreamEvent extracts an artifact update event from a streaming event, accepting an artifactUpdate stream response or the bare event in typed or decoded form.

func (*ArtifactHelper) ExtractArtifactsFromTask added in v0.10.0

func (ah *ArtifactHelper) ExtractArtifactsFromTask(task *types.Task) []types.Artifact

ExtractArtifactsFromTask extracts all artifacts from a task

func (*ArtifactHelper) ExtractDataFromArtifact added in v0.10.0

func (ah *ArtifactHelper) ExtractDataFromArtifact(artifact *types.Artifact) []map[string]any

ExtractDataFromArtifact extracts structured data from an artifact

func (*ArtifactHelper) ExtractFileDataFromArtifact added in v0.10.0

func (ah *ArtifactHelper) ExtractFileDataFromArtifact(artifact *types.Artifact) ([]FileData, error)

ExtractFileDataFromArtifact extracts file data from an artifact

func (*ArtifactHelper) ExtractTaskFromResponse added in v0.10.0

func (ah *ArtifactHelper) ExtractTaskFromResponse(response *types.JSONRPCSuccessResponse) (*types.Task, error)

ExtractTaskFromResponse extracts a task from a JSON-RPC response, accepting both the wrapped SendMessage/stream results and the bare task returned by GetTask.

func (*ArtifactHelper) ExtractTextFromArtifact added in v0.10.0

func (ah *ArtifactHelper) ExtractTextFromArtifact(artifact *types.Artifact) []string

ExtractTextFromArtifact extracts all text content from an artifact

func (*ArtifactHelper) FilterArtifactsByName added in v0.10.0

func (ah *ArtifactHelper) FilterArtifactsByName(task *types.Task, namePattern string) []types.Artifact

FilterArtifactsByName returns artifacts that match a name pattern (case-insensitive)

func (*ArtifactHelper) GetArtifactByID added in v0.10.0

func (ah *ArtifactHelper) GetArtifactByID(task *types.Task, artifactID string) (*types.Artifact, bool)

GetArtifactByID retrieves a specific artifact by its ID from a task

func (*ArtifactHelper) GetArtifactCount added in v0.10.0

func (ah *ArtifactHelper) GetArtifactCount(task *types.Task) int

GetArtifactCount returns the number of artifacts in a task

func (*ArtifactHelper) GetArtifactSummary added in v0.10.0

func (ah *ArtifactHelper) GetArtifactSummary(task *types.Task) map[string]int

GetArtifactSummary returns a summary of artifacts by type

func (*ArtifactHelper) GetArtifactsByType added in v0.10.0

func (ah *ArtifactHelper) GetArtifactsByType(task *types.Task, partKind string) []types.Artifact

GetArtifactsByType retrieves all artifacts containing parts of a specific type

func (*ArtifactHelper) GetDataArtifacts added in v0.10.0

func (ah *ArtifactHelper) GetDataArtifacts(task *types.Task) []types.Artifact

GetDataArtifacts retrieves all artifacts that contain data parts

func (*ArtifactHelper) GetFileArtifacts added in v0.10.0

func (ah *ArtifactHelper) GetFileArtifacts(task *types.Task) []types.Artifact

GetFileArtifacts retrieves all artifacts that contain file parts

func (*ArtifactHelper) GetTextArtifacts added in v0.10.0

func (ah *ArtifactHelper) GetTextArtifacts(task *types.Task) []types.Artifact

GetTextArtifacts retrieves all artifacts that contain text parts

func (*ArtifactHelper) HasArtifacts added in v0.10.0

func (ah *ArtifactHelper) HasArtifacts(task *types.Task) bool

HasArtifacts returns true if the task contains any artifacts

type Client

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

Client represents an A2A protocol client

func (*Client) CancelTask

CancelTask cancels a task via the `CancelTask` JSON-RPC method.

func (*Client) DeleteTaskPushNotificationConfig added in v0.18.0

func (c *Client) DeleteTaskPushNotificationConfig(ctx context.Context, params types.DeleteTaskPushNotificationConfigRequest) (*types.JSONRPCSuccessResponse, error)

DeleteTaskPushNotificationConfig deletes a push notification configuration for a task via the `DeleteTaskPushNotificationConfig` JSON-RPC method.

func (*Client) GetAgentCard

func (c *Client) GetAgentCard(ctx context.Context) (*types.AgentCard, error)

GetAgentCard retrieves the agent card information via HTTP GET to .well-known/agent-card.json

func (*Client) GetArtifactHelper added in v0.10.0

func (c *Client) GetArtifactHelper() *ArtifactHelper

GetArtifactHelper returns the artifact helper for extracting artifacts from responses

func (*Client) GetAuthenticatedExtendedCard added in v0.18.0

func (c *Client) GetAuthenticatedExtendedCard(ctx context.Context, params types.GetExtendedAgentCardRequest) (*types.JSONRPCSuccessResponse, error)

GetAuthenticatedExtendedCard fetches the authenticated/extended agent card via the `GetExtendedAgentCard` JSON-RPC method. Unlike GetAgentCard (which hits the public HTTP endpoint), this call goes through the JSON-RPC route and is subject to the server's authentication middleware.

func (*Client) GetBaseURL

func (c *Client) GetBaseURL() string

GetBaseURL returns the base URL of the client

func (*Client) GetConfig

func (c *Client) GetConfig() Config

GetConfig returns a copy of the client configuration

func (*Client) GetHealth

func (c *Client) GetHealth(ctx context.Context) (*HealthResponse, error)

GetHealth retrieves the health status of the agent via HTTP GET to /health

func (*Client) GetLogger

func (c *Client) GetLogger() *zap.Logger

GetLogger returns the current logger

func (*Client) GetTask

GetTask retrieves a task via the `GetTask` JSON-RPC method.

func (*Client) GetTaskPushNotificationConfig added in v0.18.0

func (c *Client) GetTaskPushNotificationConfig(ctx context.Context, params types.GetTaskPushNotificationConfigRequest) (*types.JSONRPCSuccessResponse, error)

GetTaskPushNotificationConfig retrieves the push notification configuration for a task via the `GetTaskPushNotificationConfig` JSON-RPC method.

func (*Client) ListTaskPushNotificationConfig added in v0.18.0

func (c *Client) ListTaskPushNotificationConfig(ctx context.Context, params types.ListTaskPushNotificationConfigsRequest) (*types.JSONRPCSuccessResponse, error)

ListTaskPushNotificationConfig lists push notification configurations for a task via the `ListTaskPushNotificationConfigs` JSON-RPC method.

func (*Client) ListTasks

ListTasks lists the agent's tasks via the `ListTasks` JSON-RPC method.

func (*Client) RemoveHeader

func (c *Client) RemoveHeader(key string)

RemoveHeader removes a custom header

func (*Client) ResubscribeTask added in v0.18.0

func (c *Client) ResubscribeTask(ctx context.Context, params types.SubscribeToTaskRequest) (<-chan types.JSONRPCSuccessResponse, error)

ResubscribeTask re-subscribes to a streaming task via the `SubscribeToTask` JSON-RPC method, returning a channel of streaming responses. The channel is closed when the stream ends (either because the server sent `[DONE]`, the response body closed, or the supplied context was cancelled).

func (*Client) SendTask

SendTask sends a message to the agent via the `SendMessage` JSON-RPC method.

func (*Client) SendTaskStreaming

func (c *Client) SendTaskStreaming(ctx context.Context, params types.SendMessageRequest) (<-chan types.JSONRPCSuccessResponse, error)

SendTaskStreaming sends a task and returns a channel for streaming events

func (*Client) SetHTTPClient

func (c *Client) SetHTTPClient(client *http.Client)

SetHTTPClient allows customizing the HTTP client

func (*Client) SetHeader

func (c *Client) SetHeader(key, value string)

SetHeader sets a custom header for all requests

func (*Client) SetLogger

func (c *Client) SetLogger(logger *zap.Logger)

SetLogger sets the logger for the client

func (*Client) SetMaxRetries

func (c *Client) SetMaxRetries(maxRetries int)

SetMaxRetries sets the maximum number of retry attempts

func (*Client) SetRetryDelay

func (c *Client) SetRetryDelay(delay time.Duration)

SetRetryDelay sets the delay between retry attempts

func (*Client) SetTaskPushNotificationConfig added in v0.18.0

func (c *Client) SetTaskPushNotificationConfig(ctx context.Context, params types.TaskPushNotificationConfig) (*types.JSONRPCSuccessResponse, error)

SetTaskPushNotificationConfig registers (or replaces) the push notification configuration attached to a task via the `CreateTaskPushNotificationConfig` JSON-RPC method.

func (*Client) SetTimeout

func (c *Client) SetTimeout(timeout time.Duration)

SetTimeout sets the timeout for HTTP requests

type Config

type Config struct {
	BaseURL    string
	Timeout    time.Duration
	HTTPClient *http.Client
	Transport  http.RoundTripper
	UserAgent  string
	Headers    map[string]string
	MaxRetries int
	RetryDelay time.Duration
	Logger     *zap.Logger
}

Config holds configuration options for the A2A client

func DefaultConfig

func DefaultConfig(baseURL string) *Config

DefaultConfig returns a default configuration

type DownloadConfig added in v0.13.1

type DownloadConfig struct {
	// OutputDir is the directory where files will be saved (default: current directory)
	OutputDir string
	// HTTPClient is the HTTP client to use for downloads (default: http.DefaultClient)
	HTTPClient *http.Client
	// OverwriteExisting allows overwriting existing files (default: false)
	OverwriteExisting bool
	// OrganizeByArtifactID creates subdirectories by artifact ID to prevent collisions (default: true)
	OrganizeByArtifactID bool
}

DownloadConfig holds configuration for downloading artifacts

type DownloadResult added in v0.13.1

type DownloadResult struct {
	// FileName is the name of the downloaded file
	FileName string
	// FilePath is the full path where the file was saved
	FilePath string
	// BytesWritten is the number of bytes written to disk
	BytesWritten int64
	// Error contains any error that occurred during download
	Error error
}

DownloadResult represents the result of a file download

type FileData added in v0.10.0

type FileData struct {
	Name     *string
	MIMEType *string
	Data     []byte
	URI      *string
}

FileData represents extracted file information from an artifact

func (*FileData) GetFileName added in v0.10.0

func (fd *FileData) GetFileName() string

GetFileName returns the file name or a default if none is set

func (*FileData) GetMIMEType added in v0.10.0

func (fd *FileData) GetMIMEType() string

GetMIMEType returns the MIME type or a default if none is set

func (*FileData) IsDataFile added in v0.10.0

func (fd *FileData) IsDataFile() bool

IsDataFile returns true if this file contains data (bytes), false if it's URI-based

func (*FileData) IsURIFile added in v0.10.0

func (fd *FileData) IsURIFile() bool

IsURIFile returns true if this file is URI-based, false if it contains data

type HealthResponse

type HealthResponse struct {
	Status string `json:"status"`
}

HealthResponse represents the response from the health endpoint

Directories

Path Synopsis
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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