chore: move parameters to internal/util (#1907)

To facilitate the transition of moving invocation implementation to
Source, we will have to move parameter to `internal/util`. This approach
is crucial because certain parameters may not be fully resolvable
pre-implementation. Since both `internal/sources` and `internal/tools`
will need access to `parameters`, it will be more relevant to move
parameters implementation to utils.
This commit is contained in:
Yuan Teoh
2025-11-13 13:37:12 -08:00
committed by GitHub
parent 897c63dcea
commit 4aabb4aaca
232 changed files with 3441 additions and 3269 deletions

View File

@@ -23,6 +23,7 @@ import (
"github.com/googleapis/genai-toolbox/internal/sources"
"github.com/googleapis/genai-toolbox/internal/sources/cloudsqladmin"
"github.com/googleapis/genai-toolbox/internal/tools"
"github.com/googleapis/genai-toolbox/internal/util/parameters"
sqladmin "google.golang.org/api/sqladmin/v1"
)
@@ -71,19 +72,19 @@ func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error)
}
project := s.DefaultProject
var projectParam tools.Parameter
var projectParam parameters.Parameter
if project != "" {
projectParam = tools.NewStringParameterWithDefault("project", project, "The GCP project ID. This is pre-configured; do not ask for it unless the user explicitly provides a different one.")
projectParam = parameters.NewStringParameterWithDefault("project", project, "The GCP project ID. This is pre-configured; do not ask for it unless the user explicitly provides a different one.")
} else {
projectParam = tools.NewStringParameter("project", "The project ID")
projectParam = parameters.NewStringParameter("project", "The project ID")
}
allParameters := tools.Parameters{
allParameters := parameters.Parameters{
projectParam,
tools.NewStringParameter("name", "The name of the instance"),
tools.NewStringParameterWithDefault("databaseVersion", "POSTGRES_17", "The database version for Postgres. If not specified, defaults to the latest available version (e.g., POSTGRES_17)."),
tools.NewStringParameter("rootPassword", "The root password for the instance"),
tools.NewStringParameterWithDefault("editionPreset", "Development", "The edition of the instance. Can be `Production` or `Development`. This determines the default machine type and availability. Defaults to `Development`."),
parameters.NewStringParameter("name", "The name of the instance"),
parameters.NewStringParameterWithDefault("databaseVersion", "POSTGRES_17", "The database version for Postgres. If not specified, defaults to the latest available version (e.g., POSTGRES_17)."),
parameters.NewStringParameter("rootPassword", "The root password for the instance"),
parameters.NewStringParameterWithDefault("editionPreset", "Development", "The edition of the instance. Can be `Production` or `Development`. This determines the default machine type and availability. Defaults to `Development`."),
}
paramManifest := allParameters.Manifest()
@@ -112,13 +113,13 @@ type Tool struct {
AuthRequired []string `yaml:"authRequired"`
Source *cloudsqladmin.Source
AllParams tools.Parameters `yaml:"allParams"`
AllParams parameters.Parameters `yaml:"allParams"`
manifest tools.Manifest
mcpManifest tools.McpManifest
}
// Invoke executes the tool's logic.
func (t Tool) Invoke(ctx context.Context, params tools.ParamValues, accessToken tools.AccessToken) (any, error) {
func (t Tool) Invoke(ctx context.Context, params parameters.ParamValues, accessToken tools.AccessToken) (any, error) {
paramsMap := params.AsMap()
project, ok := paramsMap["project"].(string)
@@ -182,8 +183,8 @@ func (t Tool) Invoke(ctx context.Context, params tools.ParamValues, accessToken
}
// ParseParams parses the parameters for the tool.
func (t Tool) ParseParams(data map[string]any, claims map[string]map[string]any) (tools.ParamValues, error) {
return tools.ParseParams(t.AllParams, data, claims)
func (t Tool) ParseParams(data map[string]any, claims map[string]map[string]any) (parameters.ParamValues, error) {
return parameters.ParseParams(t.AllParams, data, claims)
}
// Manifest returns the tool's manifest.