proxy

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package proxy provides a gateway that implements ToolGateway by serializing requests over a connection (for cross-process/container communication).

Index

Constants

This section is empty.

Variables

View Source
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 New

func New(cfg Config) *Gateway

New creates a new proxy gateway with the given configuration.

func (*Gateway) Close

func (g *Gateway) Close() error

Close closes the underlying connection.

func (*Gateway) DeliverResponse

func (g *Gateway) DeliverResponse(msg Message) error

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

func (g *Gateway) ListNamespaces(ctx context.Context) ([]string, error)

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.

func (*Gateway) RunTool

func (g *Gateway) RunTool(ctx context.Context, id string, args map[string]any) (run.RunResult, error)

RunTool sends a run tool request over the connection.

func (*Gateway) SearchTools

func (g *Gateway) SearchTools(ctx context.Context, query string, limit int) ([]index.Summary, error)

SearchTools sends a search 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"
)

Jump to

Keyboard shortcuts

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