parameters

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeString = "string"
	TypeInt    = "integer"
	TypeFloat  = "float"
	TypeBool   = "boolean"
	TypeArray  = "array"
	TypeMap    = "map"
)

Variables

This section is empty.

Functions

func CheckDuplicateParameters

func CheckDuplicateParameters(ps Parameters) error

CheckDuplicateParameters verify there are no duplicate parameter names

func CheckParamRequired

func CheckParamRequired(required bool, defaultV any) bool

CheckParamRequired checks if a parameter is required based on the required and default field.

func ConvertAnySliceToTyped

func ConvertAnySliceToTyped(s []any, itemType string) (any, error)

ConvertAnySliceToTyped a []any to typed slice ([]string, []int, []float etc.)

func ConvertArrayParamToString

func ConvertArrayParamToString(param any) (string, error)

helper function to convert a string array parameter to a comma separated string

func MatchStringOrRegex

func MatchStringOrRegex(input, target any) bool

MatchStringOrRegex checks if the input matches the target

func PopulateTemplate

func PopulateTemplate(templateName, templateString string, data map[string]any) (string, error)

PopulateTemplate populate a Go template with no custom formatters

func PopulateTemplateWithFunc

func PopulateTemplateWithFunc(templateName, templateString string, data map[string]any, funcMap template.FuncMap) (string, error)

PopulateTemplateWithFunc populate a Go template with provided functions

func PopulateTemplateWithJSON

func PopulateTemplateWithJSON(templateName, templateString string, data map[string]any) (string, error)

PopulateTemplateWithJSON populate a Go template with a custom `json` array formatter

func ProcessParameters

func ProcessParameters(templateParams Parameters, params Parameters) (Parameters, []ParameterManifest, error)

ProcessParameters concatenate templateParameters and parameters from a tool. It returns a list of concatenated parameters, concatenated Toolbox manifest, and concatenated MCP Manifest.

func ResolveTemplateParams

func ResolveTemplateParams(templateParams Parameters, originalStatement string, paramsMap map[string]any) (string, error)

Types

type ArrayParameter

type ArrayParameter struct {
	CommonParameter `yaml:",inline"`
	Default         *[]any    `yaml:"default"`
	Items           Parameter `yaml:"items"`
}

ArrayParameter is a parameter representing the "array" type.

func NewArrayParameter

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

func (*ArrayParameter) GetAuthServices

func (p *ArrayParameter) GetAuthServices() []ParamAuthService

func (*ArrayParameter) GetDefault

func (p *ArrayParameter) GetDefault() any

func (*ArrayParameter) GetItems

func (p *ArrayParameter) GetItems() Parameter

func (*ArrayParameter) IsAllowedValues

func (p *ArrayParameter) IsAllowedValues(v []any) bool

func (*ArrayParameter) IsExcludedValues

func (p *ArrayParameter) IsExcludedValues(v []any) bool

func (*ArrayParameter) Manifest

func (p *ArrayParameter) Manifest() ParameterManifest

Manifest returns the manifest for the ArrayParameter.

func (*ArrayParameter) McpManifest

func (p *ArrayParameter) McpManifest() (ParameterMcpManifest, []string)

McpManifest returns the MCP manifest for the ArrayParameter.

func (*ArrayParameter) Parse

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

func (*ArrayParameter) UnmarshalYAML

func (p *ArrayParameter) UnmarshalYAML(ctx context.Context, unmarshal func(interface{}) error) error

type ArrayParameterOption added in v1.6.0

type ArrayParameterOption func(*ArrayParameter)

NewArrayParameter is a convenience function for initializing a ArrayParameter.

func WithArrayAllowedValues added in v1.6.0

func WithArrayAllowedValues(v []any) ArrayParameterOption

func WithArrayAuth added in v1.6.0

func WithArrayAuth(v []ParamAuthService) ArrayParameterOption

func WithArrayDefault added in v1.6.0

func WithArrayDefault(v []any) ArrayParameterOption

func WithArrayExcludedValues added in v1.6.0

func WithArrayExcludedValues(v []any) ArrayParameterOption

func WithArrayRequired added in v1.6.0

func WithArrayRequired(v bool) ArrayParameterOption

type BooleanParameter

type BooleanParameter struct {
	CommonParameter `yaml:",inline"`
	Default         *bool `yaml:"default"`
}

BooleanParameter is a parameter representing the "boolean" type.

func NewBooleanParameter

func NewBooleanParameter(name string, desc string, opts ...BooleanParameterOption) *BooleanParameter

func (*BooleanParameter) GetAuthServices

func (p *BooleanParameter) GetAuthServices() []ParamAuthService

func (*BooleanParameter) GetDefault

func (p *BooleanParameter) GetDefault() any

func (*BooleanParameter) Manifest

func (p *BooleanParameter) Manifest() ParameterManifest

Manifest returns the manifest for the BooleanParameter.

func (*BooleanParameter) Parse

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

type BooleanParameterOption added in v1.6.0

type BooleanParameterOption func(*BooleanParameter)

NewBooleanParameter is a convenience function for initializing a BooleanParameter.

func WithBooleanAllowedValues added in v1.6.0

func WithBooleanAllowedValues(v []any) BooleanParameterOption

func WithBooleanAuth added in v1.6.0

func WithBooleanAuth(v []ParamAuthService) BooleanParameterOption

func WithBooleanDefault added in v1.6.0

func WithBooleanDefault(v bool) BooleanParameterOption

func WithBooleanExcludedValues added in v1.6.0

func WithBooleanExcludedValues(v []any) BooleanParameterOption

func WithBooleanRequired added in v1.6.0

func WithBooleanRequired(v bool) BooleanParameterOption

type CommonParameter

type CommonParameter struct {
	Name           string             `yaml:"name" validate:"required"`
	Type           string             `yaml:"type" validate:"required"`
	Desc           string             `yaml:"description" validate:"required"`
	Required       *bool              `yaml:"required"`
	AllowedValues  []any              `yaml:"allowedValues"`
	ExcludedValues []any              `yaml:"excludedValues"`
	AuthServices   []ParamAuthService `yaml:"authServices"`
	EmbeddedBy     string             `yaml:"embeddedBy"`
	ValueFromParam string             `yaml:"valueFromParam"`
}

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

func (*CommonParameter) GetAllowedValues

func (p *CommonParameter) GetAllowedValues() []any

GetAllowedValues returns the allowed values for the Parameter.

func (*CommonParameter) GetDesc added in v1.3.0

func (p *CommonParameter) GetDesc() string

GetDesc returns the description specified for the Parameter.

func (*CommonParameter) GetEmbeddedBy

func (p *CommonParameter) GetEmbeddedBy() string

GetEmbeddedBy returns the embedding model name for the Parameter.

func (*CommonParameter) GetExcludedValues

func (p *CommonParameter) GetExcludedValues() []any

GetExcludedValues returns the excluded values for the Parameter.

func (*CommonParameter) GetName

func (p *CommonParameter) GetName() string

GetName returns the name specified for the Parameter.

func (*CommonParameter) GetRequired

func (p *CommonParameter) GetRequired() bool

GetRequired returns the type specified for the Parameter.

func (*CommonParameter) GetType

func (p *CommonParameter) GetType() string

GetType returns the type specified for the Parameter.

func (*CommonParameter) GetValueFromParam

func (p *CommonParameter) GetValueFromParam() string

GetValueFromParam returns the param value to copy from.

func (*CommonParameter) IsAllowedValues

func (p *CommonParameter) IsAllowedValues(v any) bool

IsAllowedValues checks if the value is allowed.

func (*CommonParameter) IsExcludedValues

func (p *CommonParameter) IsExcludedValues(v any) bool

IsExcludedValues checks if the value is allowed.

func (*CommonParameter) McpManifest

func (p *CommonParameter) McpManifest() (ParameterMcpManifest, []string)

McpManifest returns the MCP manifest for the Parameter.

type FloatParameter

type FloatParameter struct {
	CommonParameter `yaml:",inline"`
	Default         *float64 `yaml:"default"`
	MinValue        *float64 `yaml:"minValue"`
	MaxValue        *float64 `yaml:"maxValue"`
}

FloatParameter is a parameter representing the "float" type.

func NewFloatParameter

func NewFloatParameter(name string, desc string, opts ...FloatParameterOption) *FloatParameter

func (*FloatParameter) GetAuthServices

func (p *FloatParameter) GetAuthServices() []ParamAuthService

func (*FloatParameter) GetDefault

func (p *FloatParameter) GetDefault() any

func (*FloatParameter) Manifest

func (p *FloatParameter) Manifest() ParameterManifest

Manifest returns the manifest for the FloatParameter.

func (*FloatParameter) McpManifest

func (p *FloatParameter) McpManifest() (ParameterMcpManifest, []string)

McpManifest returns the MCP manifest for the FloatParameter. json schema only allow numeric types of 'integer' and 'number'.

func (*FloatParameter) Parse

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

type FloatParameterOption added in v1.6.0

type FloatParameterOption func(*FloatParameter)

NewFloatParameter is a convenience function for initializing a FloatParameter.

func WithFloatAllowedValues added in v1.6.0

func WithFloatAllowedValues(v []any) FloatParameterOption

func WithFloatAuth added in v1.6.0

func WithFloatAuth(v []ParamAuthService) FloatParameterOption

func WithFloatDefault added in v1.6.0

func WithFloatDefault(v float64) FloatParameterOption

func WithFloatExcludedValues added in v1.6.0

func WithFloatExcludedValues(v []any) FloatParameterOption

func WithFloatMaxValue added in v1.6.0

func WithFloatMaxValue(v *float64) FloatParameterOption

func WithFloatMinValue added in v1.6.0

func WithFloatMinValue(v *float64) FloatParameterOption

func WithFloatRequired added in v1.6.0

func WithFloatRequired(v bool) FloatParameterOption

type IntParameter

type IntParameter struct {
	CommonParameter `yaml:",inline"`
	Default         *int `yaml:"default"`
	MinValue        *int `yaml:"minValue"`
	MaxValue        *int `yaml:"maxValue"`
}

IntParameter is a parameter representing the "int" type.

func NewIntParameter

func NewIntParameter(name string, desc string, opts ...IntParameterOption) *IntParameter

func (*IntParameter) GetAuthServices

func (p *IntParameter) GetAuthServices() []ParamAuthService

func (*IntParameter) GetDefault

func (p *IntParameter) GetDefault() any

func (*IntParameter) Manifest

func (p *IntParameter) Manifest() ParameterManifest

Manifest returns the manifest for the IntParameter.

func (*IntParameter) Parse

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

type IntParameterOption added in v1.6.0

type IntParameterOption func(*IntParameter)

NewIntParameter is a convenience function for initializing a IntParameter.

func WithIntAllowedValues added in v1.6.0

func WithIntAllowedValues(v []any) IntParameterOption

func WithIntAuth added in v1.6.0

func WithIntAuth(v []ParamAuthService) IntParameterOption

func WithIntDefault added in v1.6.0

func WithIntDefault(v int) IntParameterOption

func WithIntExcludedValues added in v1.6.0

func WithIntExcludedValues(v []any) IntParameterOption

func WithIntMaxValue added in v1.6.0

func WithIntMaxValue(v *int) IntParameterOption

func WithIntMinValue added in v1.6.0

func WithIntMinValue(v *int) IntParameterOption

func WithIntRequired added in v1.6.0

func WithIntRequired(v bool) IntParameterOption

type MapParameter

type MapParameter struct {
	CommonParameter `yaml:",inline"`
	Default         *map[string]any `yaml:"default,omitempty"`
	ValueType       string          `yaml:"valueType,omitempty"`
}

MapParameter is a parameter representing a map with string keys. If ValueType is specified (e.g., "string"), values are validated against that type. If ValueType is empty, it is treated as a generic map[string]any.

func NewMapParameter

func NewMapParameter(name string, desc string, valueType string, opts ...MapParameterOption) *MapParameter

func (*MapParameter) GetAuthServices

func (p *MapParameter) GetAuthServices() []ParamAuthService

func (*MapParameter) GetDefault

func (p *MapParameter) GetDefault() any

func (*MapParameter) GetValueType

func (p *MapParameter) GetValueType() string

func (*MapParameter) IsAllowedValues

func (p *MapParameter) IsAllowedValues(v map[string]any) bool

func (*MapParameter) IsExcludedValues

func (p *MapParameter) IsExcludedValues(v map[string]any) bool

func (*MapParameter) Manifest

func (p *MapParameter) Manifest() ParameterManifest

Manifest returns the manifest for the MapParameter.

func (*MapParameter) McpManifest

func (p *MapParameter) McpManifest() (ParameterMcpManifest, []string)

McpManifest returns the MCP manifest for the MapParameter.

func (*MapParameter) Parse

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

Parse validates and parses an incoming value for the map parameter.

func (*MapParameter) UnmarshalYAML

func (p *MapParameter) UnmarshalYAML(ctx context.Context, unmarshal func(interface{}) error) error

UnmarshalYAML handles parsing the MapParameter from YAML input.

type MapParameterOption added in v1.6.0

type MapParameterOption func(*MapParameter)

NewMapParameter is a convenience function for initializing a MapParameter.

func WithMapAllowedValues added in v1.6.0

func WithMapAllowedValues(v []any) MapParameterOption

func WithMapAuth added in v1.6.0

func WithMapAuth(v []ParamAuthService) MapParameterOption

func WithMapDefault added in v1.6.0

func WithMapDefault(v map[string]any) MapParameterOption

func WithMapExcludedValues added in v1.6.0

func WithMapExcludedValues(v []any) MapParameterOption

func WithMapRequired added in v1.6.0

func WithMapRequired(v bool) MapParameterOption

type ParamAuthService

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

type ParamValue

type ParamValue struct {
	Name  string
	Value any
}

ParamValue represents the parameter's name and value.

type ParamValues

type ParamValues []ParamValue

ParamValues is an ordered list of ParamValue

func EmbedParams

func EmbedParams(ctx context.Context, ps Parameters, paramValues ParamValues, embeddingModelsMap map[string]embeddingmodels.EmbeddingModel, formatter embeddingmodels.VectorFormatter) (ParamValues, error)

func GetParams

func GetParams(params Parameters, paramValuesMap map[string]any) (ParamValues, error)

GetParams return the ParamValues that are associated with the Parameters.

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

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

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

func (ParamValues) AsMapByOrderedKeys

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

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

func (ParamValues) AsMapWithDollarPrefix

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) AsSlice

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
	GetDesc() string
	GetType() string
	GetDefault() any
	GetRequired() bool
	GetAuthServices() []ParamAuthService
	GetEmbeddedBy() string
	GetValueFromParam() string
	Parse(any) (any, error)
	Manifest() ParameterManifest
	McpManifest() (ParameterMcpManifest, []string)
}

func ParseParameter

func ParseParameter(ctx context.Context, p map[string]any, paramType string) (Parameter, error)

ParseParameter parses a raw map into a Parameter object based on its "type" field.

type ParameterManifest

type ParameterManifest struct {
	Name                 string             `json:"name"`
	Type                 string             `json:"type"`
	Required             bool               `json:"required"`
	Description          string             `json:"description"`
	AuthServices         []string           `json:"authServices"`
	Items                *ParameterManifest `json:"items,omitempty"`
	Default              any                `json:"default,omitempty"`
	AdditionalProperties any                `json:"additionalProperties,omitempty"`
	EmbeddedBy           string             `json:"embeddedBy,omitempty"`
	ValueFromParam       string             `json:"valueFromParam,omitempty"`
}

ParameterManifest represents parameters when served as part of a ToolManifest.

type ParameterMcpManifest

type ParameterMcpManifest struct {
	Type                 string                `json:"type"`
	Description          string                `json:"description"`
	Items                *ParameterMcpManifest `json:"items,omitempty"`
	Default              any                   `json:"default,omitempty"`
	AdditionalProperties any                   `json:"additionalProperties,omitempty"`
}

ParameterMcpManifest represents properties when served as part of a ToolMcpManifest.

type Parameters

type Parameters []Parameter

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

func (Parameters) Manifest

func (ps Parameters) Manifest() []ParameterManifest

func (*Parameters) UnmarshalYAML

func (c *Parameters) UnmarshalYAML(ctx context.Context, 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"`
	Default         *string `yaml:"default"`
	Escape          *string `yaml:"escape"`
}

StringParameter is a parameter representing the "string" type.

func NewStringParameter

func NewStringParameter(name string, desc string, opts ...StringParameterOption) *StringParameter

func (*StringParameter) GetAuthServices

func (p *StringParameter) GetAuthServices() []ParamAuthService

func (*StringParameter) GetDefault

func (p *StringParameter) GetDefault() any

func (*StringParameter) Manifest

func (p *StringParameter) Manifest() ParameterManifest

Manifest returns the manifest for the StringParameter.

func (*StringParameter) Parse

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

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

type StringParameterOption added in v1.6.0

type StringParameterOption func(*StringParameter)

NewStringParameter is a convenience function for initializing a StringParameter.

func WithStringAllowedValues added in v1.6.0

func WithStringAllowedValues(v []any) StringParameterOption

func WithStringAuth added in v1.6.0

func WithStringAuth(v []ParamAuthService) StringParameterOption

func WithStringDefault added in v1.6.0

func WithStringDefault(v string) StringParameterOption

func WithStringEscape added in v1.6.0

func WithStringEscape(v string) StringParameterOption

func WithStringExcludedValues added in v1.6.0

func WithStringExcludedValues(v []any) StringParameterOption

func WithStringRequired added in v1.6.0

func WithStringRequired(v bool) StringParameterOption

Jump to

Keyboard shortcuts

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