Documentation
¶
Index ¶
- func GetGoogleIDToken(ctx context.Context, audience string) (string, error)
- func NewCustomTokenSource(provider func() string) oauth2.TokenSource
- type ClientOption
- type Float
- type Integer
- type ManifestSchema
- type ParameterSchema
- type ToolConfig
- type ToolOption
- func WithAuthTokenSource(authSourceName string, idToken oauth2.TokenSource) ToolOption
- func WithAuthTokenString(authSourceName string, idToken string) ToolOption
- func WithBindParamBool(name string, value bool) ToolOption
- func WithBindParamBoolArray(name string, value []bool) ToolOption
- func WithBindParamBoolArrayFunc(name string, fn func() ([]bool, error)) ToolOption
- func WithBindParamBoolFunc(name string, fn func() (bool, error)) ToolOption
- func WithBindParamFloat[T Float](name string, value T) ToolOption
- func WithBindParamFloatArray[T Float](name string, value []T) ToolOption
- func WithBindParamFloatArrayFunc[T Float](name string, fn func() ([]T, error)) ToolOption
- func WithBindParamFloatFunc[T Float](name string, fn func() (T, error)) ToolOption
- func WithBindParamInt[T Integer](name string, value T) ToolOption
- func WithBindParamIntArray[T Integer](name string, value []T) ToolOption
- func WithBindParamIntArrayFunc[T Integer](name string, fn func() ([]T, error)) ToolOption
- func WithBindParamIntFunc[T Integer](name string, fn func() (T, error)) ToolOption
- func WithBindParamString(name string, value string) ToolOption
- func WithBindParamStringArray(name string, value []string) ToolOption
- func WithBindParamStringArrayFunc(name string, fn func() ([]string, error)) ToolOption
- func WithBindParamStringFunc(name string, fn func() (string, error)) ToolOption
- func WithStrict(strict bool) ToolOption
- type ToolSchema
- type ToolboxClient
- type ToolboxTool
- func (tt *ToolboxTool) DescribeParameters() string
- func (tt *ToolboxTool) Description() string
- func (tt *ToolboxTool) InputSchema() ([]byte, error)
- func (tt *ToolboxTool) Invoke(ctx context.Context, input map[string]any) (any, error)
- func (tt *ToolboxTool) Name() string
- func (tt *ToolboxTool) Parameters() []ParameterSchema
- func (tt *ToolboxTool) ToolFrom(opts ...ToolOption) (*ToolboxTool, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetGoogleIDToken ¶
GetGoogleIDToken fetches a Google ID token for a specific audience.
Inputs:
- ctx: The context for the request, which can be used for cancellation or deadlines.
- audience: The recipient of the token, typically the URL of the secured service
Returns:
A string in the format "Bearer <token>" on success, or an error if the token could not be fetched.
func NewCustomTokenSource ¶
func NewCustomTokenSource(provider func() string) oauth2.TokenSource
This function converts a custom function that returns a string into an oauth2.TokenSource type.
Inputs:
- provider: A custom function that returns a token as a string.
Returns:
- An oauth2.TokenSource that wraps the custom function.
Types ¶
type ClientOption ¶
type ClientOption func(*ToolboxClient) error
ClientOption configures a ToolboxClient at creation time.
func WithClientHeaderString ¶
func WithClientHeaderString(headerName string, value string) ClientOption
WithClientHeaderString adds a static string value as a client-wide HTTP header.
func WithClientHeaderTokenSource ¶
func WithClientHeaderTokenSource(headerName string, value oauth2.TokenSource) ClientOption
WithClientHeaderTokenSource adds a dynamic client-wide HTTP header from a TokenSource.
func WithDefaultToolOptions ¶
func WithDefaultToolOptions(opts ...ToolOption) ClientOption
WithDefaultToolOptions provides default Options that will be applied to every tool loaded by this client.
func WithHTTPClient ¶
func WithHTTPClient(client *http.Client) ClientOption
WithHTTPClient provides a custom http.Client to the ToolboxClient.
type ManifestSchema ¶
type ManifestSchema struct { ServerVersion string `json:"serverVersion"` Tools map[string]ToolSchema `json:"tools"` }
Schema for the Toolbox manifest.
type ParameterSchema ¶
type ParameterSchema struct { Name string `json:"name"` Type string `json:"type"` Required bool `json:"required,omitempty"` Description string `json:"description"` AuthSources []string `json:"authSources,omitempty"` Items *ParameterSchema `json:"items,omitempty"` }
Schema for a tool parameter.
type ToolConfig ¶
type ToolConfig struct { AuthTokenSources map[string]oauth2.TokenSource BoundParams map[string]any Strict bool // contains filtered or unexported fields }
ToolConfig holds all configurable aspects for creating or deriving a tool.
type ToolOption ¶
type ToolOption func(*ToolConfig) error
ToolOption defines a single, universal type for a functional option that configures a tool.
func WithAuthTokenSource ¶
func WithAuthTokenSource(authSourceName string, idToken oauth2.TokenSource) ToolOption
WithAuthTokenSource provides an authentication token from a standard TokenSource.
func WithAuthTokenString ¶
func WithAuthTokenString(authSourceName string, idToken string) ToolOption
WithAuthTokenString provides a static string authentication token.
func WithBindParamBool ¶
func WithBindParamBool(name string, value bool) ToolOption
WithBindParamBool binds a static boolean value to a parameter.
func WithBindParamBoolArray ¶
func WithBindParamBoolArray(name string, value []bool) ToolOption
WithBindParamBoolArray binds a static slice of booleans to a parameter.
func WithBindParamBoolArrayFunc ¶
func WithBindParamBoolArrayFunc(name string, fn func() ([]bool, error)) ToolOption
WithBindParamBoolArrayFunc binds a function that returns a slice of booleans.
func WithBindParamBoolFunc ¶
func WithBindParamBoolFunc(name string, fn func() (bool, error)) ToolOption
WithBindParamBoolFunc binds a function that returns a boolean to a parameter.
func WithBindParamFloat ¶
func WithBindParamFloat[T Float](name string, value T) ToolOption
WithBindParamFloat binds a static float value to a parameter.
func WithBindParamFloatArray ¶
func WithBindParamFloatArray[T Float](name string, value []T) ToolOption
WithBindParamFloatArray binds a static slice of floats to a parameter.
func WithBindParamFloatArrayFunc ¶
func WithBindParamFloatArrayFunc[T Float](name string, fn func() ([]T, error)) ToolOption
WithBindParamFloatArrayFunc binds a function that returns a slice of floats.
func WithBindParamFloatFunc ¶
func WithBindParamFloatFunc[T Float](name string, fn func() (T, error)) ToolOption
WithBindParamFloatFunc binds a function that returns a float to a parameter.
func WithBindParamInt ¶
func WithBindParamInt[T Integer](name string, value T) ToolOption
WithBindParamInt binds a static integer value to a parameter.
func WithBindParamIntArray ¶
func WithBindParamIntArray[T Integer](name string, value []T) ToolOption
WithBindParamIntArray binds a static slice of integers to a parameter.
func WithBindParamIntArrayFunc ¶
func WithBindParamIntArrayFunc[T Integer](name string, fn func() ([]T, error)) ToolOption
WithBindParamIntArrayFunc binds a function that returns a slice of integers.
func WithBindParamIntFunc ¶
func WithBindParamIntFunc[T Integer](name string, fn func() (T, error)) ToolOption
WithBindParamIntFunc binds a function that returns an integer to a parameter.
func WithBindParamString ¶
func WithBindParamString(name string, value string) ToolOption
WithBindParamString binds a static string value to a parameter.
func WithBindParamStringArray ¶
func WithBindParamStringArray(name string, value []string) ToolOption
WithBindParamStringArray binds a static slice of strings to a parameter.
func WithBindParamStringArrayFunc ¶
func WithBindParamStringArrayFunc(name string, fn func() ([]string, error)) ToolOption
WithBindParamStringArrayFunc binds a function that returns a slice of strings.
func WithBindParamStringFunc ¶
func WithBindParamStringFunc(name string, fn func() (string, error)) ToolOption
WithBindParamStringFunc binds a function that returns a string to a parameter.
func WithStrict ¶
func WithStrict(strict bool) ToolOption
WithStrict provides an option to enable strict validation for LoadToolset.
type ToolSchema ¶
type ToolSchema struct { Description string `json:"description"` Parameters []ParameterSchema `json:"parameters"` AuthRequired []string `json:"authRequired,omitempty"` }
Schema for a tool.
type ToolboxClient ¶
type ToolboxClient struct {
// contains filtered or unexported fields
}
The synchronous interface for a Toolbox service client.
func NewToolboxClient ¶
func NewToolboxClient(url string, opts ...ClientOption) (*ToolboxClient, error)
NewToolboxClient creates and configures a new, immutable client for interacting with a Toolbox server.
Inputs:
- url: The base URL of the Toolbox server.
- opts: A variadic list of ClientOption functions to configure the client, such as setting a custom http.Client or default headers.
Returns:
A configured *ToolboxClient and a nil error on success, or a nil client and an error if configuration fails.
func (*ToolboxClient) LoadTool ¶
func (tc *ToolboxClient) LoadTool(name string, ctx context.Context, opts ...ToolOption) (*ToolboxTool, error)
LoadTool fetches a manifest for a single tool
Inputs:
- name: The specific name of the tool to load.
- ctx: The context to control the lifecycle of the request.
- opts: A variadic list of ToolOption functions to configure auth tokens or bind parameters for this tool.
Returns:
A configured *ToolboxTool and a nil error on success, or a nil tool and an error if loading or validation fails.
func (*ToolboxClient) LoadToolset ¶
func (tc *ToolboxClient) LoadToolset(name string, ctx context.Context, opts ...ToolOption) ([]*ToolboxTool, error)
LoadToolset fetches a manifest for a collection of tools.
Inputs:
- name: Name of the toolset to be loaded.Set this arg to "" to load the default toolset
- ctx: The context to control the lifecycle of the request.
- opts: A variadic list of ToolOption functions. These can include WithStrict and options for auth or bound params that may apply to tools in the set.
Returns:
A slice of configured *ToolboxTool and a nil error on success, or a nil slice and an error if loading or validation fails.
type ToolboxTool ¶
type ToolboxTool struct {
// contains filtered or unexported fields
}
ToolboxTool represents an immutable, universal definition of a Toolbox tool.
func (*ToolboxTool) DescribeParameters ¶
func (tt *ToolboxTool) DescribeParameters() string
DescribeParameters returns a single, human-readable string that describes all of the tool's unbound parameters, including their names, types, and descriptions.
Returns:
A formatted string of parameter descriptions, or an empty string if there are no unbound parameters.
func (*ToolboxTool) Description ¶
func (tt *ToolboxTool) Description() string
Description returns the tool's description.
func (*ToolboxTool) InputSchema ¶
func (tt *ToolboxTool) InputSchema() ([]byte, error)
InputSchema generates an OpenAPI JSON Schema for the tool's input parameters and returns it as raw bytes.
func (*ToolboxTool) Invoke ¶
Invoke executes the tool with the given input.
Inputs:
- ctx: The context to control the lifecycle of the API request.
- input: A map of parameter names to values provided by the user for this specific invocation.
Returns:
The result from the API call, which can be a structured object (from a JSON 'result' field) or a raw string. Returns an error if any step of the process fails.
func (*ToolboxTool) Parameters ¶
func (tt *ToolboxTool) Parameters() []ParameterSchema
Parameters returns the list of parameters that must be provided by a user at invocation time.
func (*ToolboxTool) ToolFrom ¶
func (tt *ToolboxTool) ToolFrom(opts ...ToolOption) (*ToolboxTool, error)
ToolFrom creates a new, more specialized tool from an existing one by applying additional options. This is useful for creating variations of a tool with different bound parameters without modifying the original and all provided options must be applicable.
Inputs:
- opts: A variadic list of ToolOption functions to further configure the new tool, such as binding more parameters.
Returns:
A new, specialized *ToolboxTool and a nil error, or a nil tool and an error if the new options are invalid or conflict with existing settings.