tools

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsAuthorized added in v0.0.4

func IsAuthorized(authRequiredSources []string, verifiedAuthSources []string) bool

Helper function that returns if a tool invocation request is authorized

func IsValidName

func IsValidName(s string) bool

Types

type ArrayParameter

type ArrayParameter struct {
	CommonParameter `yaml:",inline"`
	Items           Parameter `yaml:"items"`
}

ArrayParameter is a parameter representing the "array" type.

func NewArrayParameter

func NewArrayParameter(name, desc string, items Parameter) *ArrayParameter

NewArrayParameter is a convenience function for initializing a ArrayParameter.

func NewArrayParameterWithAuth added in v0.0.4

func NewArrayParameterWithAuth(name, desc string, items Parameter, authSources []ParamAuthSource) *ArrayParameter

NewArrayParameterWithAuth is a convenience function for initializing a ArrayParameter with a list of ParamAuthSource.

func (*ArrayParameter) GetAuthSources added in v0.0.4

func (p *ArrayParameter) GetAuthSources() []ParamAuthSource

func (*ArrayParameter) Parse

func (p *ArrayParameter) Parse(v any) (any, error)

func (*ArrayParameter) UnmarshalYAML

func (p *ArrayParameter) UnmarshalYAML(unmarshal func(interface{}) error) error

type BooleanParameter

type BooleanParameter struct {
	CommonParameter `yaml:",inline"`
}

BooleanParameter is a parameter representing the "boolean" type.

func NewBooleanParameter

func NewBooleanParameter(name, desc string) *BooleanParameter

NewBooleanParameter is a convenience function for initializing a BooleanParameter.

func NewBooleanParameterWithAuth added in v0.0.4

func NewBooleanParameterWithAuth(name, desc string, authSources []ParamAuthSource) *BooleanParameter

NewBooleanParameterWithAuth is a convenience function for initializing a BooleanParameter with a list of ParamAuthSource.

func (*BooleanParameter) GetAuthSources added in v0.0.4

func (p *BooleanParameter) GetAuthSources() []ParamAuthSource

func (*BooleanParameter) Parse

func (p *BooleanParameter) Parse(v any) (any, error)

type CommonParameter

type CommonParameter struct {
	Name        string            `yaml:"name"`
	Type        string            `yaml:"type"`
	Desc        string            `yaml:"description"`
	AuthSources []ParamAuthSource `yaml:"authSources"`
}

CommonParameter are default fields that are emebdding in most Parameter implementations. Embedding this stuct will give the object Name() and Type() functions.

func (*CommonParameter) GetName

func (p *CommonParameter) GetName() string

GetName returns the name specified for the Parameter.

func (*CommonParameter) GetType

func (p *CommonParameter) GetType() string

GetType returns the type specified for the Parameter.

func (*CommonParameter) Manifest

func (p *CommonParameter) Manifest() ParameterManifest

GetType returns the type specified for the Parameter.

type FloatParameter

type FloatParameter struct {
	CommonParameter `yaml:",inline"`
}

FloatParameter is a parameter representing the "float" type.

func NewFloatParameter

func NewFloatParameter(name, desc string) *FloatParameter

NewFloatParameter is a convenience function for initializing a FloatParameter.

func NewFloatParameterWithAuth added in v0.0.4

func NewFloatParameterWithAuth(name, desc string, authSources []ParamAuthSource) *FloatParameter

NewFloatParameterWithAuth is a convenience function for initializing a FloatParameter with a list of ParamAuthSource.

func (*FloatParameter) GetAuthSources added in v0.0.4

func (p *FloatParameter) GetAuthSources() []ParamAuthSource

func (*FloatParameter) Parse

func (p *FloatParameter) Parse(v any) (any, error)

type IntParameter

type IntParameter struct {
	CommonParameter `yaml:",inline"`
}

IntParameter is a parameter representing the "int" type.

func NewIntParameter

func NewIntParameter(name, desc string) *IntParameter

NewIntParameter is a convenience function for initializing a IntParameter.

func NewIntParameterWithAuth added in v0.0.4

func NewIntParameterWithAuth(name, desc string, authSources []ParamAuthSource) *IntParameter

NewIntParameterWithAuth is a convenience function for initializing a IntParameter with a list of ParamAuthSource.

func (*IntParameter) GetAuthSources added in v0.0.4

func (p *IntParameter) GetAuthSources() []ParamAuthSource

func (*IntParameter) Parse

func (p *IntParameter) Parse(v any) (any, error)

type Manifest added in v0.0.2

type Manifest struct {
	Description string              `json:"description"`
	Parameters  []ParameterManifest `json:"parameters"`
}

Manifest is the representation of tools sent to Client SDKs.

type ParamAuthSource added in v0.0.4

type ParamAuthSource struct {
	Name  string `yaml:"name"`
	Field string `yaml:"field"`
}

type ParamValue added in v0.0.3

type ParamValue struct {
	Name  string
	Value any
}

ParamValue represents the parameter's name and value.

type ParamValues added in v0.0.3

type ParamValues []ParamValue

ParamValues is an ordered list of ParamValue

func ParseParams

func ParseParams(ps Parameters, data map[string]any, claimsMap map[string]map[string]any) (ParamValues, error)

ParseParams is a helper function for parsing Parameters from an arbitraryJSON object.

func (ParamValues) AsMap added in v0.0.3

func (p ParamValues) AsMap() map[string]interface{}

AsMap returns a map of ParamValue's names to values.

func (ParamValues) AsMapByOrderedKeys added in v0.0.3

func (p ParamValues) AsMapByOrderedKeys() map[string]interface{}

AsMapByOrderedKeys returns a map of a key's position to it's value, as neccesary for Spanner PSQL. Example { $1 -> "value1", $2 -> "value2" }

func (ParamValues) AsMapWithDollarPrefix added in v0.1.0

func (p ParamValues) AsMapWithDollarPrefix() map[string]interface{}

AsMapWithDollarPrefix ensures all keys are prefixed with a dollar sign for Dgraph. Example: Input: {"role": "admin", "$age": 30} Output: {"$role": "admin", "$age": 30}

func (ParamValues) AsReversedMap added in v0.1.0

func (p ParamValues) AsReversedMap() map[any]string

AsReversedMap returns a map of ParamValue's values to names.

func (ParamValues) AsSlice added in v0.0.3

func (p ParamValues) AsSlice() []any

AsSlice returns a slice of the Param's values (in order).

type Parameter

type Parameter interface {
	// Note: It's typically not idiomatic to include "Get" in the function name,
	// but this is done to differentiate it from the fields in CommonParameter.
	GetName() string
	GetType() string
	GetAuthSources() []ParamAuthSource
	Parse(any) (any, error)
	Manifest() ParameterManifest
}

type ParameterManifest

type ParameterManifest struct {
	Name        string   `json:"name"`
	Type        string   `json:"type"`
	Description string   `json:"description"`
	AuthSources []string `json:"authSources"`
}

ParameterManifest represents parameters when served as part of a ToolManifest.

type Parameters

type Parameters []Parameter

Parameters is a type used to allow unmarshal a list of parameters

func (Parameters) Manifest added in v0.0.2

func (ps Parameters) Manifest() []ParameterManifest

func (*Parameters) UnmarshalYAML

func (c *Parameters) UnmarshalYAML(unmarshal func(interface{}) error) error

type ParseTypeError

type ParseTypeError struct {
	Name  string
	Type  string
	Value any
}

ParseTypeError is a custom error for incorrectly typed Parameters.

func (ParseTypeError) Error

func (e ParseTypeError) Error() string

type StringParameter

type StringParameter struct {
	CommonParameter `yaml:",inline"`
}

StringParameter is a parameter representing the "string" type.

func NewStringParameter

func NewStringParameter(name, desc string) *StringParameter

NewStringParameter is a convenience function for initializing a StringParameter.

func NewStringParameterWithAuth added in v0.0.4

func NewStringParameterWithAuth(name, desc string, authSources []ParamAuthSource) *StringParameter

NewStringParameterWithAuth is a convenience function for initializing a StringParameter with a list of ParamAuthSource.

func (*StringParameter) GetAuthSources added in v0.0.4

func (p *StringParameter) GetAuthSources() []ParamAuthSource

func (*StringParameter) Parse

func (p *StringParameter) Parse(v any) (any, error)

Parse casts the value "v" as a "string".

type Tool

type Tool interface {
	Invoke(ParamValues) ([]any, error)
	ParseParams(map[string]any, map[string]map[string]any) (ParamValues, error)
	Manifest() Manifest
	Authorized([]string) bool
}

type ToolConfig added in v0.0.2

type ToolConfig interface {
	ToolConfigKind() string
	Initialize(map[string]sources.Source) (Tool, error)
}

type Toolset

type Toolset struct {
	Name     string          `yaml:"name"`
	Tools    []*Tool         `yaml:",inline"`
	Manifest ToolsetManifest `yaml:",inline"`
}

type ToolsetConfig

type ToolsetConfig struct {
	Name      string   `yaml:"name"`
	ToolNames []string `yaml:",inline"`
}

func (ToolsetConfig) Initialize

func (t ToolsetConfig) Initialize(serverVersion string, toolsMap map[string]Tool) (Toolset, error)

type ToolsetManifest

type ToolsetManifest struct {
	ServerVersion string              `json:"serverVersion"`
	ToolsManifest map[string]Manifest `json:"tools"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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