Documentation
¶
Overview ¶
Package tool defines the interface for tools that can be executed by the upstream service.
Package tool is a generated GoMock package.
Index ¶
- Variables
- func ConvertMCPToolToProto(tool *mcp.Tool) (*pb.Tool, error)
- func ConvertProtoToMCPTool(pbTool *pb.Tool) (*mcp.Tool, error)
- func ConvertToolDefinitionToProto(toolDef *configv1.ToolDefinition, inputSchema, outputSchema *structpb.Struct) (*pb.Tool, error)
- func GetFullyQualifiedToolName(serviceID, methodName string) string
- func NewContextWithTool(ctx context.Context, t Tool) context.Context
- func ParseToolName(toolName string) (namespace string, tool string, err error)
- func ShouldExport(name string, policy *configv1.ExportPolicy) bool
- type Action
- type Callable
- type CallableTool
- type CommandTool
- type ExecutionFunc
- type ExecutionMiddleware
- type ExecutionRequest
- type GRPCTool
- type HTTPTool
- type LocalCommandTool
- type MCPServerProvider
- type MCPTool
- type Manager
- func (tm *Manager) AddMiddleware(middleware ExecutionMiddleware)
- func (tm *Manager) AddServiceInfo(serviceID string, info *ServiceInfo)
- func (tm *Manager) AddTool(tool Tool) error
- func (tm *Manager) ClearToolsForService(serviceID string)
- func (tm *Manager) ExecuteTool(ctx context.Context, req *ExecutionRequest) (any, error)
- func (tm *Manager) GetServiceInfo(serviceID string) (*ServiceInfo, bool)
- func (tm *Manager) GetTool(toolName string) (Tool, bool)
- func (tm *Manager) ListTools() []Tool
- func (tm *Manager) SetMCPServer(mcpServer MCPServerProvider)
- type ManagerInterface
- type MockManagerInterface
- func (m *MockManagerInterface) AddMiddleware(middleware ExecutionMiddleware)
- func (m *MockManagerInterface) AddServiceInfo(serviceID string, info *ServiceInfo)
- func (m *MockManagerInterface) AddTool(tool Tool) error
- func (m *MockManagerInterface) Clear()
- func (m *MockManagerInterface) ClearToolsForService(serviceID string)
- func (m *MockManagerInterface) EXPECT() *MockManagerInterfaceMockRecorder
- func (m *MockManagerInterface) ExecuteTool(ctx context.Context, req *ExecutionRequest) (any, error)
- func (m *MockManagerInterface) GetServiceInfo(serviceID string) (*ServiceInfo, bool)
- func (m *MockManagerInterface) GetTool(toolName string) (Tool, bool)
- func (m *MockManagerInterface) ListTools() []Tool
- func (m *MockManagerInterface) SetMCPServer(mcpServer MCPServerProvider)
- type MockManagerInterfaceMockRecorder
- func (mr *MockManagerInterfaceMockRecorder) AddMiddleware(middleware any) *gomock.Call
- func (mr *MockManagerInterfaceMockRecorder) AddServiceInfo(serviceID, info any) *gomock.Call
- func (mr *MockManagerInterfaceMockRecorder) AddTool(tool any) *gomock.Call
- func (mr *MockManagerInterfaceMockRecorder) Clear() *gomock.Call
- func (mr *MockManagerInterfaceMockRecorder) ClearToolsForService(serviceID any) *gomock.Call
- func (mr *MockManagerInterfaceMockRecorder) ExecuteTool(ctx, req any) *gomock.Call
- func (mr *MockManagerInterfaceMockRecorder) GetServiceInfo(serviceID any) *gomock.Call
- func (mr *MockManagerInterfaceMockRecorder) GetTool(toolName any) *gomock.Call
- func (mr *MockManagerInterfaceMockRecorder) ListTools() *gomock.Call
- func (mr *MockManagerInterfaceMockRecorder) SetMCPServer(mcpServer any) *gomock.Call
- type MockTool
- type OpenAPITool
- type PolicyHook
- type PostCallHook
- type PreCallHook
- type ServiceInfo
- type ServiceRegistry
- type SigningRoundTripper
- type Tool
- type WebhookHook
- type WebhookStatus
- type WebrtcTool
- type WebsocketTool
Constants ¶
This section is empty.
Variables ¶
var ErrToolNotFound = errors.New("unknown tool")
ErrToolNotFound is returned when a requested tool cannot be found.
Functions ¶
func ConvertMCPToolToProto ¶
ConvertMCPToolToProto transforms an *mcp.Tool, which uses a flexible schema representation, into a protobuf-defined *pb.Tool with a structured input schema. This is used to standardize tool definitions within the system.
func ConvertProtoToMCPTool ¶
ConvertProtoToMCPTool transforms a protobuf-defined *pb.Tool into an *mcp.Tool. This is the reverse of convertMCPToolToProto and is used when exposing internally defined tools to the outside world.
func ConvertToolDefinitionToProto ¶
func ConvertToolDefinitionToProto(toolDef *configv1.ToolDefinition, inputSchema, outputSchema *structpb.Struct) (*pb.Tool, error)
ConvertToolDefinitionToProto transforms a *configv1.ToolDefinition into a *pb.Tool.
func GetFullyQualifiedToolName ¶
GetFullyQualifiedToolName constructs a fully qualified tool name from a service ID and a method name, using the standard separator.
serviceID is the unique identifier of the service. methodName is the name of the tool/method within the service. It returns the combined, fully qualified tool name.
func NewContextWithTool ¶
NewContextWithTool creates a new context with the given tool.
func ParseToolName ¶
ParseToolName deconstructs a fully qualified tool name into its namespace (service ID) and the bare tool name. The expected format is "<namespace>/-/--<tool_name>". If the separator is not found, the entire input is treated as the tool name with an empty namespace.
toolName is the fully qualified tool name to parse. It returns the namespace, the bare tool name, and an error if the tool name is invalid (e.g., empty).
func ShouldExport ¶
func ShouldExport(name string, policy *configv1.ExportPolicy) bool
ShouldExport determines whether a named item (tool, prompt, or resource) should be exported based on the provided ExportPolicy.
Types ¶
type Callable ¶
type Callable interface {
Call(ctx context.Context, req *ExecutionRequest) (any, error)
}
Callable is an interface that represents a callable tool.
type CallableTool ¶
type CallableTool struct {
// contains filtered or unexported fields
}
CallableTool implements the Tool interface for a tool that is executed by a Callable.
func NewCallableTool ¶
func NewCallableTool(toolDef *configv1.ToolDefinition, serviceConfig *configv1.UpstreamServiceConfig, callable Callable, inputSchema, outputSchema *structpb.Struct) (*CallableTool, error)
NewCallableTool creates a new CallableTool.
func (*CallableTool) Callable ¶
func (t *CallableTool) Callable() Callable
Callable returns the underlying Callable of the tool.
func (*CallableTool) Execute ¶
func (t *CallableTool) Execute(ctx context.Context, req *ExecutionRequest) (any, error)
Execute handles the execution of the tool.
func (CallableTool) GetCacheConfig ¶
func (t CallableTool) GetCacheConfig() *configv1.CacheConfig
type CommandTool ¶
type CommandTool struct {
// contains filtered or unexported fields
}
CommandTool implements the Tool interface for a tool that is executed as a local command-line process. It maps tool inputs to command-line arguments and environment variables.
func (*CommandTool) Execute ¶
func (t *CommandTool) Execute(ctx context.Context, req *ExecutionRequest) (any, error)
Execute handles the execution of the command-line tool. It constructs a command with arguments and environment variables derived from the tool inputs, runs the command, and returns its output.
func (*CommandTool) GetCacheConfig ¶
func (t *CommandTool) GetCacheConfig() *configv1.CacheConfig
GetCacheConfig returns the cache configuration for the command-line tool.
func (*CommandTool) Tool ¶
func (t *CommandTool) Tool() *v1.Tool
Tool returns the protobuf definition of the command-line tool.
type ExecutionFunc ¶
type ExecutionFunc func(ctx context.Context, req *ExecutionRequest) (any, error)
ExecutionFunc represents the next middleware in the chain.
type ExecutionMiddleware ¶
type ExecutionMiddleware interface {
Execute(ctx context.Context, req *ExecutionRequest, next ExecutionFunc) (any, error)
}
ExecutionMiddleware defines the interface for tool execution middleware.
type ExecutionRequest ¶
type ExecutionRequest struct {
ToolName string
// ToolInputs is the raw JSON message of the tool inputs. It is used by
// tools that need to unmarshal the inputs into a specific struct.
ToolInputs json.RawMessage
// Arguments is a map of the tool inputs. It is used by tools that need to
// access the inputs as a map.
Arguments map[string]interface{}
}
ExecutionRequest represents a request to execute a specific tool, including its name and input arguments as a raw JSON message.
type GRPCTool ¶
type GRPCTool struct {
// contains filtered or unexported fields
}
GRPCTool implements the Tool interface for a tool that is exposed via a gRPC endpoint. It handles the marshalling of JSON inputs to protobuf messages and invoking the gRPC method.
func NewGRPCTool ¶
func NewGRPCTool(tool *v1.Tool, poolManager *pool.Manager, serviceID string, method protoreflect.MethodDescriptor, callDefinition *configv1.GrpcCallDefinition) *GRPCTool
NewGRPCTool creates a new GRPCTool.
tool is the protobuf definition of the tool. poolManager is used to get a gRPC client from the connection pool. serviceID identifies the specific gRPC service connection pool. method is the protobuf descriptor for the gRPC method to be called.
func (*GRPCTool) Execute ¶
Execute handles the execution of the gRPC tool. It retrieves a client from the pool, unmarshals the JSON input into a protobuf request message, invokes the gRPC method, and marshals the protobuf response back to JSON.
func (*GRPCTool) GetCacheConfig ¶
func (t *GRPCTool) GetCacheConfig() *configv1.CacheConfig
GetCacheConfig returns the cache configuration for the gRPC tool.
type HTTPTool ¶
type HTTPTool struct {
// contains filtered or unexported fields
}
HTTPTool implements the Tool interface for a tool exposed via an HTTP endpoint. It constructs and sends an HTTP request based on the tool definition and input, handling parameter mapping, authentication, and transformations.
func NewHTTPTool ¶
func NewHTTPTool(tool *v1.Tool, poolManager *pool.Manager, serviceID string, authenticator auth.UpstreamAuthenticator, callDefinition *configv1.HttpCallDefinition, cfg *configv1.ResilienceConfig) *HTTPTool
NewHTTPTool creates a new HTTPTool.
tool is the protobuf definition of the tool. poolManager is used to get an HTTP client from the connection pool. serviceID identifies the specific HTTP service connection pool. authenticator handles adding authentication credentials to the request. callDefinition contains the configuration for the HTTP call, such as parameter mappings and transformers.
func (*HTTPTool) Execute ¶
Execute handles the execution of the HTTP tool. It builds an HTTP request by mapping input parameters to the path, query, and body, applies any configured transformations, sends the request, and processes the response.
func (*HTTPTool) GetCacheConfig ¶
func (t *HTTPTool) GetCacheConfig() *configv1.CacheConfig
GetCacheConfig returns the cache configuration for the HTTP tool.
type LocalCommandTool ¶
type LocalCommandTool struct {
// contains filtered or unexported fields
}
LocalCommandTool implements the Tool interface for a tool that is executed as a local command-line process. It maps tool inputs to command-line arguments and environment variables.
func (*LocalCommandTool) Execute ¶
func (t *LocalCommandTool) Execute(ctx context.Context, req *ExecutionRequest) (any, error)
Execute handles the execution of the command-line tool. It constructs a command with arguments and environment variables derived from the tool inputs, runs the command, and returns its output.
func (*LocalCommandTool) GetCacheConfig ¶
func (t *LocalCommandTool) GetCacheConfig() *configv1.CacheConfig
GetCacheConfig returns the cache configuration for the command-line tool.
func (*LocalCommandTool) Tool ¶
func (t *LocalCommandTool) Tool() *v1.Tool
Tool returns the protobuf definition of the command-line tool.
type MCPServerProvider ¶
MCPServerProvider defines an interface for components that can provide an instance of an *mcp.Server. This is used to decouple the Manager from the concrete server implementation.
type MCPTool ¶
type MCPTool struct {
// contains filtered or unexported fields
}
MCPTool implements the Tool interface for a tool that is exposed via another MCP-compliant service. It acts as a proxy, forwarding the tool call to the downstream MCP service.
func NewMCPTool ¶
func NewMCPTool(tool *v1.Tool, client client.MCPClient, callDefinition *configv1.MCPCallDefinition) *MCPTool
NewMCPTool creates a new MCPTool.
tool is the protobuf definition of the tool. client is the MCP client used to communicate with the downstream service. callDefinition contains configuration for input/output transformations.
func (*MCPTool) Execute ¶
Execute handles the execution of the MCP tool. It forwards the tool call, including its name and arguments, to the downstream MCP service using the configured client and applies any necessary transformations to the request and response.
func (*MCPTool) GetCacheConfig ¶
func (t *MCPTool) GetCacheConfig() *configv1.CacheConfig
GetCacheConfig returns the cache configuration for the MCP tool.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager is a thread-safe manager for registering tooling.
func NewManager ¶
NewManager creates and returns a new, empty Manager.
func (*Manager) AddMiddleware ¶
func (tm *Manager) AddMiddleware(middleware ExecutionMiddleware)
AddMiddleware adds a middleware to the tool manager.
func (*Manager) AddServiceInfo ¶
func (tm *Manager) AddServiceInfo(serviceID string, info *ServiceInfo)
AddServiceInfo stores metadata about a service, indexed by its ID.
serviceID is the unique identifier for the service. info is the ServiceInfo struct containing the service's metadata.
func (*Manager) AddTool ¶
AddTool registers a new tool with the manager. It generates a unique tool ID and, if an MCP server is configured, registers a handler for the tool with the server.
tool is the tool to be added. It returns an error if the tool ID cannot be generated.
func (*Manager) ClearToolsForService ¶
ClearToolsForService removes all tools associated with a given service key from the manager. This is useful when a service is being re-registered or unregistered.
serviceID is the unique identifier for the service whose tools should be cleared.
func (*Manager) ExecuteTool ¶
ExecuteTool finds a tool by its name and executes it with the provided request context and inputs.
ctx is the context for the tool execution. req contains the name of the tool and its inputs. It returns the result of the execution or an error if the tool is not found or if the execution fails.
func (*Manager) GetServiceInfo ¶
func (tm *Manager) GetServiceInfo(serviceID string) (*ServiceInfo, bool)
GetServiceInfo retrieves the metadata for a service by its ID.
serviceID is the unique identifier for the service. It returns the ServiceInfo and a boolean indicating whether the service was found.
func (*Manager) GetTool ¶
GetTool retrieves a tool from the manager by its fully qualified name.
toolName is the name of the tool to retrieve. It returns the tool and a boolean indicating whether the tool was found.
func (*Manager) ListTools ¶
ListTools returns a slice containing all the tools currently registered with the manager.
func (*Manager) SetMCPServer ¶
func (tm *Manager) SetMCPServer(mcpServer MCPServerProvider)
SetMCPServer provides the Manager with a reference to the MCP server. This is necessary for registering tool handlers with the server.
type ManagerInterface ¶
type ManagerInterface interface {
AddTool(tool Tool) error
GetTool(toolName string) (Tool, bool)
ListTools() []Tool
ClearToolsForService(serviceID string)
ExecuteTool(ctx context.Context, req *ExecutionRequest) (any, error)
SetMCPServer(mcpServer MCPServerProvider)
AddMiddleware(middleware ExecutionMiddleware)
AddServiceInfo(serviceID string, info *ServiceInfo)
GetServiceInfo(serviceID string) (*ServiceInfo, bool)
}
ManagerInterface defines the interface for a tool manager.
type MockManagerInterface ¶
type MockManagerInterface struct {
// contains filtered or unexported fields
}
MockManagerInterface is a mock of ManagerInterface interface.
func NewMockManagerInterface ¶
func NewMockManagerInterface(ctrl *gomock.Controller) *MockManagerInterface
NewMockManagerInterface creates a new mock instance.
func (*MockManagerInterface) AddMiddleware ¶
func (m *MockManagerInterface) AddMiddleware(middleware ExecutionMiddleware)
AddMiddleware mocks base method.
func (*MockManagerInterface) AddServiceInfo ¶
func (m *MockManagerInterface) AddServiceInfo(serviceID string, info *ServiceInfo)
AddServiceInfo mocks base method.
func (*MockManagerInterface) AddTool ¶
func (m *MockManagerInterface) AddTool(tool Tool) error
AddTool mocks base method.
func (*MockManagerInterface) Clear ¶
func (m *MockManagerInterface) Clear()
Clear mocks base method.
func (*MockManagerInterface) ClearToolsForService ¶
func (m *MockManagerInterface) ClearToolsForService(serviceID string)
ClearToolsForService mocks base method.
func (*MockManagerInterface) EXPECT ¶
func (m *MockManagerInterface) EXPECT() *MockManagerInterfaceMockRecorder
EXPECT returns an object that allows the caller to indicate expected use.
func (*MockManagerInterface) ExecuteTool ¶
func (m *MockManagerInterface) ExecuteTool(ctx context.Context, req *ExecutionRequest) (any, error)
ExecuteTool mocks base method.
func (*MockManagerInterface) GetServiceInfo ¶
func (m *MockManagerInterface) GetServiceInfo(serviceID string) (*ServiceInfo, bool)
GetServiceInfo mocks base method.
func (*MockManagerInterface) GetTool ¶
func (m *MockManagerInterface) GetTool(toolName string) (Tool, bool)
GetTool mocks base method.
func (*MockManagerInterface) ListTools ¶
func (m *MockManagerInterface) ListTools() []Tool
ListTools mocks base method.
func (*MockManagerInterface) SetMCPServer ¶
func (m *MockManagerInterface) SetMCPServer(mcpServer MCPServerProvider)
SetMCPServer mocks base method.
type MockManagerInterfaceMockRecorder ¶
type MockManagerInterfaceMockRecorder struct {
// contains filtered or unexported fields
}
MockManagerInterfaceMockRecorder is the mock recorder for MockManagerInterface.
func (*MockManagerInterfaceMockRecorder) AddMiddleware ¶
func (mr *MockManagerInterfaceMockRecorder) AddMiddleware(middleware any) *gomock.Call
AddMiddleware indicates an expected call of AddMiddleware.
func (*MockManagerInterfaceMockRecorder) AddServiceInfo ¶
func (mr *MockManagerInterfaceMockRecorder) AddServiceInfo(serviceID, info any) *gomock.Call
AddServiceInfo indicates an expected call of AddServiceInfo.
func (*MockManagerInterfaceMockRecorder) AddTool ¶
func (mr *MockManagerInterfaceMockRecorder) AddTool(tool any) *gomock.Call
AddTool indicates an expected call of AddTool.
func (*MockManagerInterfaceMockRecorder) Clear ¶
func (mr *MockManagerInterfaceMockRecorder) Clear() *gomock.Call
Clear indicates an expected call of Clear.
func (*MockManagerInterfaceMockRecorder) ClearToolsForService ¶
func (mr *MockManagerInterfaceMockRecorder) ClearToolsForService(serviceID any) *gomock.Call
ClearToolsForService indicates an expected call of ClearToolsForService.
func (*MockManagerInterfaceMockRecorder) ExecuteTool ¶
func (mr *MockManagerInterfaceMockRecorder) ExecuteTool(ctx, req any) *gomock.Call
ExecuteTool indicates an expected call of ExecuteTool.
func (*MockManagerInterfaceMockRecorder) GetServiceInfo ¶
func (mr *MockManagerInterfaceMockRecorder) GetServiceInfo(serviceID any) *gomock.Call
GetServiceInfo indicates an expected call of GetServiceInfo.
func (*MockManagerInterfaceMockRecorder) GetTool ¶
func (mr *MockManagerInterfaceMockRecorder) GetTool(toolName any) *gomock.Call
GetTool indicates an expected call of GetTool.
func (*MockManagerInterfaceMockRecorder) ListTools ¶
func (mr *MockManagerInterfaceMockRecorder) ListTools() *gomock.Call
ListTools indicates an expected call of ListTools.
func (*MockManagerInterfaceMockRecorder) SetMCPServer ¶
func (mr *MockManagerInterfaceMockRecorder) SetMCPServer(mcpServer any) *gomock.Call
SetMCPServer indicates an expected call of SetMCPServer.
type MockTool ¶
type MockTool struct {
ToolFunc func() *v1.Tool
ExecuteFunc func(ctx context.Context, req *ExecutionRequest) (any, error)
GetCacheConfigFunc func() *configv1.CacheConfig
}
MockTool is a mock implementation of the Tool interface for testing purposes.
func (*MockTool) GetCacheConfig ¶
func (m *MockTool) GetCacheConfig() *configv1.CacheConfig
GetCacheConfig calls the mock GetCacheConfigFunc if set, otherwise returns nil.
type OpenAPITool ¶
type OpenAPITool struct {
// contains filtered or unexported fields
}
OpenAPITool implements the Tool interface for a tool defined in an OpenAPI specification. It constructs and sends an HTTP request based on the OpenAPI operation definition.
func NewOpenAPITool ¶
func NewOpenAPITool(tool *v1.Tool, client client.HTTPClient, parameterDefs map[string]string, method, url string, authenticator auth.UpstreamAuthenticator, callDefinition *configv1.OpenAPICallDefinition) *OpenAPITool
NewOpenAPITool creates a new OpenAPITool.
tool is the protobuf definition of the tool. client is the HTTP client used to make the request. parameterDefs maps parameter names to their location (e.g., "path", "query"). method is the HTTP method for the operation. url is the URL template for the endpoint. authenticator handles adding authentication credentials to the request. callDefinition contains configuration for input/output transformations.
func (*OpenAPITool) Execute ¶
func (t *OpenAPITool) Execute(ctx context.Context, req *ExecutionRequest) (any, error)
Execute handles the execution of the OpenAPI tool. It constructs an HTTP request based on the operation's method, URL, and parameter definitions, sends the request, and processes the response, applying transformations as needed.
func (*OpenAPITool) GetCacheConfig ¶
func (t *OpenAPITool) GetCacheConfig() *configv1.CacheConfig
GetCacheConfig returns the cache configuration for the OpenAPI tool.
func (*OpenAPITool) Tool ¶
func (t *OpenAPITool) Tool() *v1.Tool
Tool returns the protobuf definition of the OpenAPI tool.
type PolicyHook ¶
type PolicyHook struct {
// contains filtered or unexported fields
}
PolicyHook implements PreCallHook using CallPolicy.
func NewPolicyHook ¶
func NewPolicyHook(policy *configv1.CallPolicy) *PolicyHook
NewPolicyHook creates a new PolicyHook with the given call policy.
func (*PolicyHook) ExecutePre ¶
func (h *PolicyHook) ExecutePre( _ context.Context, req *ExecutionRequest, ) (Action, *ExecutionRequest, error)
ExecutePre executes the policy check before a tool is called.
type PostCallHook ¶
type PostCallHook interface {
// ExecutePost runs the hook. It returns the potentially modified result
// (or original if unchanged) and an error.
ExecutePost(ctx context.Context, req *ExecutionRequest, result any) (any, error)
}
PostCallHook defines the interface for hooks executed after a tool call.
type PreCallHook ¶
type PreCallHook interface {
// ExecutePre runs the hook. It returns an action (Allow/Deny),
// a potentially modified request (or nil if unchanged), and an error.
ExecutePre(ctx context.Context, req *ExecutionRequest) (Action, *ExecutionRequest, error)
}
PreCallHook defines the interface for hooks executed before a tool call.
type ServiceInfo ¶
type ServiceInfo struct {
Name string
Config *configv1.UpstreamServiceConfig
Fds *descriptorpb.FileDescriptorSet
// PreHooks are the cached pre-call hooks for the service.
PreHooks []PreCallHook
// PostHooks are the cached post-call hooks for the service.
PostHooks []PostCallHook
}
ServiceInfo holds metadata about a registered upstream service, including its configuration and any associated protobuf file descriptors.
type ServiceRegistry ¶
type ServiceRegistry interface {
GetTool(toolName string) (Tool, bool)
GetServiceInfo(serviceID string) (*ServiceInfo, bool)
}
ServiceRegistry defines an interface for a component that can look up tools and service information. It is used for dependency injection to decouple components from the main service registry.
type SigningRoundTripper ¶
type SigningRoundTripper struct {
// contains filtered or unexported fields
}
SigningRoundTripper signs the request body.
type Tool ¶
type Tool interface {
// Tool returns the protobuf definition of the tool.
Tool() *v1.Tool
// Execute runs the tool with the provided context and request, returning
// the result or an error.
Execute(ctx context.Context, req *ExecutionRequest) (any, error)
// GetCacheConfig returns the cache configuration for the tool.
GetCacheConfig() *configv1.CacheConfig
}
Tool is the fundamental interface for any executable tool in the system. Each implementation represents a different type of underlying service (e.g., gRPC, HTTP, command-line).
func GetFromContext ¶
GetFromContext retrieves a tool from the context.
func NewCommandTool ¶
func NewCommandTool( tool *v1.Tool, service *configv1.CommandLineUpstreamService, callDefinition *configv1.CommandLineCallDefinition, ) Tool
NewCommandTool creates a new CommandTool.
tool is the protobuf definition of the tool. command is the command to be executed.
func NewLocalCommandTool ¶
func NewLocalCommandTool( tool *v1.Tool, service *configv1.CommandLineUpstreamService, callDefinition *configv1.CommandLineCallDefinition, ) Tool
NewLocalCommandTool creates a new LocalCommandTool.
tool is the protobuf definition of the tool. command is the command to be executed.
type WebhookHook ¶
type WebhookHook struct {
// contains filtered or unexported fields
}
WebhookHook supports modification of requests and responses via external webhook using CloudEvents.
func NewWebhookHook ¶
func NewWebhookHook(config *configv1.WebhookConfig) *WebhookHook
NewWebhookHook creates a new WebhookHook.
func (*WebhookHook) ExecutePost ¶
func (h *WebhookHook) ExecutePost( ctx context.Context, req *ExecutionRequest, result any, ) (any, error)
ExecutePost executes the webhook notification after a tool is called.
func (*WebhookHook) ExecutePre ¶
func (h *WebhookHook) ExecutePre( ctx context.Context, req *ExecutionRequest, ) (Action, *ExecutionRequest, error)
ExecutePre executes the webhook notification before a tool is called.
type WebhookStatus ¶
WebhookStatus represents the status of a webhook response.
type WebrtcTool ¶
type WebrtcTool struct {
// contains filtered or unexported fields
}
WebrtcTool implements the Tool interface for a tool that is exposed via a WebRTC data channel. It handles the signaling and establishment of a peer connection to communicate with the remote service. This is useful for scenarios requiring low-latency, peer-to-peer communication directly from the server.
func NewWebrtcTool ¶
func NewWebrtcTool( tool *v1.Tool, poolManager *pool.Manager, serviceID string, authenticator auth.UpstreamAuthenticator, callDefinition *configv1.WebrtcCallDefinition, ) (*WebrtcTool, error)
NewWebrtcTool creates a new WebrtcTool.
tool is the protobuf definition of the tool. poolManager is used to get a client from the connection pool. serviceID identifies the specific service connection pool. authenticator handles adding authentication credentials to the signaling request. callDefinition contains the configuration for the WebRTC call, such as parameter mappings and transformers.
func (*WebrtcTool) Close ¶
func (t *WebrtcTool) Close() error
Close is a placeholder for any cleanup logic. Currently, it is a no-op as the peer connection is created and closed within the Execute method.
func (*WebrtcTool) Execute ¶
func (t *WebrtcTool) Execute(ctx context.Context, req *ExecutionRequest) (any, error)
Execute handles the execution of the WebRTC tool. It establishes a new peer connection, negotiates the session via an HTTP signaling server, sends the tool inputs over the data channel, and waits for a response.
func (*WebrtcTool) GetCacheConfig ¶
func (t *WebrtcTool) GetCacheConfig() *configv1.CacheConfig
GetCacheConfig returns the cache configuration for the WebRTC tool.
func (*WebrtcTool) Tool ¶
func (t *WebrtcTool) Tool() *v1.Tool
Tool returns the protobuf definition of the WebRTC tool.
type WebsocketTool ¶
type WebsocketTool struct {
// contains filtered or unexported fields
}
WebsocketTool implements the Tool interface for a tool exposed via a WebSocket connection. It handles sending and receiving messages over a persistent WebSocket connection managed by a connection pool.
func NewWebsocketTool ¶
func NewWebsocketTool( tool *v1.Tool, poolManager *pool.Manager, serviceID string, authenticator auth.UpstreamAuthenticator, callDefinition *configv1.WebsocketCallDefinition, ) *WebsocketTool
NewWebsocketTool creates a new WebsocketTool.
tool is the protobuf definition of the tool. poolManager is used to get a WebSocket client from the connection pool. serviceID identifies the specific WebSocket service connection pool. authenticator handles adding authentication credentials to the connection request. callDefinition contains the configuration for the WebSocket call, such as parameter mappings and transformers.
func (*WebsocketTool) Execute ¶
func (t *WebsocketTool) Execute(ctx context.Context, req *ExecutionRequest) (any, error)
Execute handles the execution of the WebSocket tool. It retrieves a connection from the pool, sends the tool inputs as a message, and waits for a single response message, which it then processes and returns.
func (*WebsocketTool) GetCacheConfig ¶
func (t *WebsocketTool) GetCacheConfig() *configv1.CacheConfig
GetCacheConfig returns the cache configuration for the WebSocket tool.
func (*WebsocketTool) Tool ¶
func (t *WebsocketTool) Tool() *v1.Tool
Tool returns the protobuf definition of the WebSocket tool.