client

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2025 License: MIT Imports: 14 Imported by: 1

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)
	GetHealth(ctx context.Context) (*HealthResponse, error)

	// Task operations
	SendTask(ctx context.Context, params types.MessageSendParams) (*types.JSONRPCSuccessResponse, error)
	SendTaskStreaming(ctx context.Context, params types.MessageSendParams) (<-chan types.JSONRPCSuccessResponse, error)
	GetTask(ctx context.Context, params types.TaskQueryParams) (*types.JSONRPCSuccessResponse, error)
	ListTasks(ctx context.Context, params types.TaskListParams) (*types.JSONRPCSuccessResponse, error)
	CancelTask(ctx context.Context, params types.TaskIdParams) (*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

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

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

func (c *Client) CancelTask(ctx context.Context, params types.TaskIdParams) (*types.JSONRPCSuccessResponse, error)

CancelTaskWithContext cancels a task with context support

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) 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

GetTaskWithContext retrieves the status of a task with context support

func (*Client) ListTasks

ListTasks retrieves a list of tasks from the agent

func (*Client) RemoveHeader

func (c *Client) RemoveHeader(key string)

RemoveHeader removes a custom header

func (*Client) SendTask

SendTask sends a task to the agent (primary interface following official A2A pattern)

func (*Client) SendTaskStreaming

func (c *Client) SendTaskStreaming(ctx context.Context, params types.MessageSendParams) (<-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) 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
	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