chore: update yaml tag for tools (#2356)

Update yaml tag in tools from `kind` to `type`.

Upcoming PRs: 
* Update config in `/tests` and `/docs`

Will resolve other unit tests failure in the final PR to keep things
simpler.
This commit is contained in:
Yuan Teoh
2026-01-26 17:53:37 -08:00
committed by Yuan Teoh
parent 83ebaf20b7
commit 474e480b2c
369 changed files with 4707 additions and 5752 deletions

View File

@@ -27,11 +27,11 @@ import (
"github.com/googleapis/genai-toolbox/internal/util/parameters"
)
const kind string = "sqlite-execute-sql"
const resourceType string = "sqlite-execute-sql"
func init() {
if !tools.Register(kind, newConfig) {
panic(fmt.Sprintf("tool type %q already registered", kind))
if !tools.Register(resourceType, newConfig) {
panic(fmt.Sprintf("tool type %q already registered", resourceType))
}
}
@@ -50,7 +50,7 @@ type compatibleSource interface {
type Config struct {
Name string `yaml:"name" validate:"required"`
Type string `yaml:"kind" validate:"required"`
Type string `yaml:"type" validate:"required"`
Source string `yaml:"source" validate:"required"`
Description string `yaml:"description" validate:"required"`
AuthRequired []string `yaml:"authRequired"`
@@ -60,7 +60,7 @@ type Config struct {
var _ tools.ToolConfig = Config{}
func (cfg Config) ToolConfigType() string {
return kind
return resourceType
}
func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error) {
@@ -107,7 +107,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
if err != nil {
return nil, fmt.Errorf("error getting logger: %s", err)
}
logger.DebugContext(ctx, fmt.Sprintf("executing `%s` tool query: %s", kind, sql))
logger.DebugContext(ctx, fmt.Sprintf("executing `%s` tool query: %s", resourceType, sql))
return source.RunSQL(ctx, sql, nil)
}

View File

@@ -17,7 +17,6 @@ package sqliteexecutesql_test
import (
"testing"
yaml "github.com/goccy/go-yaml"
"github.com/google/go-cmp/cmp"
"github.com/googleapis/genai-toolbox/internal/server"
"github.com/googleapis/genai-toolbox/internal/testutils"
@@ -38,14 +37,14 @@ func TestParseFromYamlExecuteSql(t *testing.T) {
{
desc: "basic example",
in: `
tools:
example_tool:
kind: sqlite-execute-sql
source: my-instance
description: some description
authRequired:
- my-google-auth-service
- other-auth-service
kind: tools
name: example_tool
type: sqlite-execute-sql
source: my-instance
description: some description
authRequired:
- my-google-auth-service
- other-auth-service
`,
want: server.ToolConfigs{
"example_tool": sqliteexecutesql.Config{
@@ -60,15 +59,12 @@ func TestParseFromYamlExecuteSql(t *testing.T) {
}
for _, tc := range tcs {
t.Run(tc.desc, func(t *testing.T) {
got := struct {
Tools server.ToolConfigs `yaml:"tools"`
}{}
// Parse contents
err := yaml.UnmarshalContext(ctx, testutils.FormatYaml(tc.in), &got)
_, _, _, got, _, _, err := server.UnmarshalResourceConfig(ctx, testutils.FormatYaml(tc.in))
if err != nil {
t.Fatalf("unable to unmarshal: %s", err)
}
if diff := cmp.Diff(tc.want, got.Tools); diff != "" {
if diff := cmp.Diff(tc.want, got); diff != "" {
t.Fatalf("incorrect parse: diff %v", diff)
}
})