Documentation
¶
Overview ¶
Package proxy provides a gateway that implements ToolGateway by serializing requests over a connection (for cross-process/container communication).
Index ¶
- Variables
- type Codec
- type Config
- type Connection
- type Gateway
- func (g *Gateway) Close() error
- func (g *Gateway) DeliverResponse(msg Message) error
- func (g *Gateway) DescribeTool(ctx context.Context, id string, level tooldoc.DetailLevel) (tooldoc.ToolDoc, error)
- func (g *Gateway) ListNamespaces(ctx context.Context) ([]string, error)
- func (g *Gateway) ListToolExamples(ctx context.Context, id string, maxExamples int) ([]tooldoc.ToolExample, error)
- func (g *Gateway) RunChain(ctx context.Context, steps []run.ChainStep) (run.RunResult, []run.StepResult, error)
- func (g *Gateway) RunTool(ctx context.Context, id string, args map[string]any) (run.RunResult, error)
- func (g *Gateway) SearchTools(ctx context.Context, query string, limit int) ([]index.Summary, error)
- type Message
- type MessageType
Constants ¶
This section is empty.
Variables ¶
var ( ErrConnectionClosed = errors.New("connection closed") ErrTimeout = errors.New("request timeout") ErrProtocol = errors.New("protocol error") )
Errors for proxy gateway operations.
Functions ¶
This section is empty.
Types ¶
type Codec ¶
type Codec interface {
// Encode encodes a message to bytes.
Encode(msg Message) ([]byte, error)
// Decode decodes bytes to a message.
Decode(data []byte) (Message, error)
}
Codec defines the interface for message serialization.
Contract: - Concurrency: implementations must be safe for concurrent use. - Errors: Encode/Decode must return errors for invalid data.
type Config ¶
type Config struct {
// Connection is the underlying connection to use.
Connection Connection
// Codec is the message codec to use. If nil, JSON is used.
Codec Codec
}
Config configures a proxy gateway.
type Connection ¶
type Connection interface {
// Send sends a message and waits for acknowledgment.
Send(ctx context.Context, msg Message) error
// Receive waits for and returns the next message.
Receive(ctx context.Context) (Message, error)
// Close closes the connection.
Close() error
}
Connection defines the interface for sending and receiving messages.
Contract: - Concurrency: implementations must be safe for concurrent use. - Context: Send/Receive must honor cancellation/deadlines. - Errors: return ErrConnectionClosed when closed.
type Gateway ¶
type Gateway struct {
// contains filtered or unexported fields
}
Gateway implements ToolGateway by serializing requests over a connection. This is used when the gateway needs to communicate across process boundaries, such as when code runs in a Docker container.
func (*Gateway) DeliverResponse ¶
DeliverResponse delivers a response to a pending request. This is called by the connection handler when a response is received.
func (*Gateway) DescribeTool ¶
func (g *Gateway) DescribeTool(ctx context.Context, id string, level tooldoc.DetailLevel) (tooldoc.ToolDoc, error)
DescribeTool sends a describe tool request over the connection.
func (*Gateway) ListNamespaces ¶
ListNamespaces sends a list namespaces request over the connection.
func (*Gateway) ListToolExamples ¶
func (g *Gateway) ListToolExamples(ctx context.Context, id string, maxExamples int) ([]tooldoc.ToolExample, error)
ListToolExamples sends a list examples request over the connection.
func (*Gateway) RunChain ¶
func (g *Gateway) RunChain(ctx context.Context, steps []run.ChainStep) (run.RunResult, []run.StepResult, error)
RunChain sends a run chain request over the connection.
type Message ¶
type Message struct {
Type MessageType `json:"type"`
ID string `json:"id"`
Payload map[string]any `json:"payload,omitempty"`
}
Message is the wire protocol envelope for gateway operations.
type MessageType ¶
type MessageType string
MessageType identifies the type of protocol message.
const ( // Request message types MsgSearchTools MessageType = "search_tools" MsgListNamespaces MessageType = "list_namespaces" MsgDescribeTool MessageType = "describe_tool" MsgListToolExamples MessageType = "list_tool_examples" MsgRunTool MessageType = "run_tool" MsgRunChain MessageType = "run_chain" // Response message type MsgResponse MessageType = "response" MsgError MessageType = "error" )