Compare commits

...

2 Commits

Author SHA1 Message Date
Yuan Teoh
87c5953b75 chore: update yaml for tests 2026-01-22 17:18:57 -08:00
Yuan Teoh
7f0c49a4df chore: update yaml tag for tools 2026-01-22 17:11:12 -08:00
425 changed files with 5204 additions and 6254 deletions

View File

@@ -25,11 +25,11 @@ import (
"github.com/googleapis/genai-toolbox/internal/util/parameters"
)
const kind string = "alloydb-create-cluster"
const resourceType string = "alloydb-create-cluster"
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 {
// Configuration for the create-cluster tool.
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"`
AuthRequired []string `yaml:"authRequired"`
@@ -59,9 +59,9 @@ type Config struct {
// validate interface
var _ tools.ToolConfig = Config{}
// ToolConfigType returns the kind of the tool.
// ToolConfigType returns the type of the tool.
func (cfg Config) ToolConfigType() string {
return kind
return resourceType
}
// Initialize initializes the tool from the configuration.
@@ -73,7 +73,7 @@ func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error)
s, ok := rawS.(compatibleSource)
if !ok {
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", kind, cfg.Source)
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", resourceType, cfg.Source)
}
project := s.GetDefaultProject()

View File

@@ -17,7 +17,6 @@ package alloydbcreatecluster_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"
@@ -37,11 +36,11 @@ func TestParseFromYaml(t *testing.T) {
{
desc: "basic example",
in: `
tools:
create-my-cluster:
kind: alloydb-create-cluster
source: my-alloydb-admin-source
description: some description
kind: tools
name: create-my-cluster
type: alloydb-create-cluster
source: my-alloydb-admin-source
description: some description
`,
want: server.ToolConfigs{
"create-my-cluster": alloydbcreatecluster.Config{
@@ -56,14 +55,14 @@ func TestParseFromYaml(t *testing.T) {
{
desc: "with auth required",
in: `
tools:
create-my-cluster-auth:
kind: alloydb-create-cluster
source: my-alloydb-admin-source
description: some description
authRequired:
- my-google-auth-service
- other-auth-service
kind: tools
name: create-my-cluster-auth
type: alloydb-create-cluster
source: my-alloydb-admin-source
description: some description
authRequired:
- my-google-auth-service
- other-auth-service
`,
want: server.ToolConfigs{
"create-my-cluster-auth": alloydbcreatecluster.Config{
@@ -78,15 +77,12 @@ func TestParseFromYaml(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)
}
})

View File

@@ -25,11 +25,11 @@ import (
"github.com/googleapis/genai-toolbox/internal/util/parameters"
)
const kind string = "alloydb-create-instance"
const resourceType string = "alloydb-create-instance"
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 {
// Configuration for the create-instance tool.
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"`
AuthRequired []string `yaml:"authRequired"`
@@ -59,9 +59,9 @@ type Config struct {
// validate interface
var _ tools.ToolConfig = Config{}
// ToolConfigType returns the kind of the tool.
// ToolConfigType returns the type of the tool.
func (cfg Config) ToolConfigType() string {
return kind
return resourceType
}
// Initialize initializes the tool from the configuration.
@@ -73,7 +73,7 @@ func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error)
s, ok := rawS.(compatibleSource)
if !ok {
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", kind, cfg.Source)
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", resourceType, cfg.Source)
}
project := s.GetDefaultProject()

View File

@@ -17,7 +17,6 @@ package alloydbcreateinstance_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"
@@ -37,11 +36,11 @@ func TestParseFromYaml(t *testing.T) {
{
desc: "basic example",
in: `
tools:
create-my-instance:
kind: alloydb-create-instance
source: my-alloydb-admin-source
description: some description
kind: tools
name: create-my-instance
type: alloydb-create-instance
source: my-alloydb-admin-source
description: some description
`,
want: server.ToolConfigs{
"create-my-instance": alloydbcreateinstance.Config{
@@ -56,14 +55,14 @@ func TestParseFromYaml(t *testing.T) {
{
desc: "with auth required",
in: `
tools:
create-my-instance-auth:
kind: alloydb-create-instance
source: my-alloydb-admin-source
description: some description
authRequired:
- my-google-auth-service
- other-auth-service
kind: tools
name: create-my-instance-auth
type: alloydb-create-instance
source: my-alloydb-admin-source
description: some description
authRequired:
- my-google-auth-service
- other-auth-service
`,
want: server.ToolConfigs{
"create-my-instance-auth": alloydbcreateinstance.Config{
@@ -78,15 +77,12 @@ func TestParseFromYaml(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)
}
})

View File

@@ -25,11 +25,11 @@ import (
"github.com/googleapis/genai-toolbox/internal/util/parameters"
)
const kind string = "alloydb-create-user"
const resourceType string = "alloydb-create-user"
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 {
// Configuration for the create-user tool.
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"`
AuthRequired []string `yaml:"authRequired"`
@@ -59,9 +59,9 @@ type Config struct {
// validate interface
var _ tools.ToolConfig = Config{}
// ToolConfigType returns the kind of the tool.
// ToolConfigType returns the type of the tool.
func (cfg Config) ToolConfigType() string {
return kind
return resourceType
}
// Initialize initializes the tool from the configuration.
@@ -73,7 +73,7 @@ func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error)
s, ok := rawS.(compatibleSource)
if !ok {
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", kind, cfg.Source)
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", resourceType, cfg.Source)
}
project := s.GetDefaultProject()

View File

@@ -17,7 +17,6 @@ package alloydbcreateuser_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"
@@ -37,11 +36,11 @@ func TestParseFromYaml(t *testing.T) {
{
desc: "basic example",
in: `
tools:
create-my-user:
kind: alloydb-create-user
source: my-alloydb-admin-source
description: some description
kind: tools
name: create-my-user
type: alloydb-create-user
source: my-alloydb-admin-source
description: some description
`,
want: server.ToolConfigs{
"create-my-user": alloydbcreateuser.Config{
@@ -56,14 +55,14 @@ func TestParseFromYaml(t *testing.T) {
{
desc: "with auth required",
in: `
tools:
create-my-user-auth:
kind: alloydb-create-user
source: my-alloydb-admin-source
description: some description
authRequired:
- my-google-auth-service
- other-auth-service
kind: tools
name: create-my-user-auth
type: alloydb-create-user
source: my-alloydb-admin-source
description: some description
authRequired:
- my-google-auth-service
- other-auth-service
`,
want: server.ToolConfigs{
"create-my-user-auth": alloydbcreateuser.Config{
@@ -78,15 +77,12 @@ func TestParseFromYaml(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)
}
})

View File

@@ -25,11 +25,11 @@ import (
"github.com/googleapis/genai-toolbox/internal/util/parameters"
)
const kind string = "alloydb-get-cluster"
const resourceType string = "alloydb-get-cluster"
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 {
// Configuration for the get-cluster tool.
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"`
AuthRequired []string `yaml:"authRequired"`
@@ -60,9 +60,9 @@ type Config struct {
// validate interface
var _ tools.ToolConfig = Config{}
// ToolConfigType returns the kind of the tool.
// ToolConfigType returns the type of the tool.
func (cfg Config) ToolConfigType() string {
return kind
return resourceType
}
// Initialize initializes the tool from the configuration.
@@ -74,7 +74,7 @@ func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error)
s, ok := rawS.(compatibleSource)
if !ok {
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", kind, cfg.Source)
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", resourceType, cfg.Source)
}
project := s.GetDefaultProject()

View File

@@ -17,7 +17,6 @@ package alloydbgetcluster_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"
@@ -37,12 +36,12 @@ func TestParseFromYaml(t *testing.T) {
{
desc: "basic example",
in: `
tools:
get-my-cluster:
kind: alloydb-get-cluster
source: my-alloydb-admin-source
description: some description
`,
kind: tools
name: get-my-cluster
type: alloydb-get-cluster
source: my-alloydb-admin-source
description: some description
`,
want: server.ToolConfigs{
"get-my-cluster": alloydbgetcluster.Config{
Name: "get-my-cluster",
@@ -56,15 +55,15 @@ func TestParseFromYaml(t *testing.T) {
{
desc: "with auth required",
in: `
tools:
get-my-cluster-auth:
kind: alloydb-get-cluster
source: my-alloydb-admin-source
description: some description
authRequired:
- my-google-auth-service
- other-auth-service
`,
kind: tools
name: get-my-cluster-auth
type: alloydb-get-cluster
source: my-alloydb-admin-source
description: some description
authRequired:
- my-google-auth-service
- other-auth-service
`,
want: server.ToolConfigs{
"get-my-cluster-auth": alloydbgetcluster.Config{
Name: "get-my-cluster-auth",
@@ -78,15 +77,12 @@ func TestParseFromYaml(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)
}
})

View File

@@ -25,11 +25,11 @@ import (
"github.com/googleapis/genai-toolbox/internal/util/parameters"
)
const kind string = "alloydb-get-instance"
const resourceType string = "alloydb-get-instance"
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 {
// Configuration for the get-instance tool.
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"`
AuthRequired []string `yaml:"authRequired"`
@@ -60,9 +60,9 @@ type Config struct {
// validate interface
var _ tools.ToolConfig = Config{}
// ToolConfigType returns the kind of the tool.
// ToolConfigType returns the type of the tool.
func (cfg Config) ToolConfigType() string {
return kind
return resourceType
}
// Initialize initializes the tool from the configuration.
@@ -74,7 +74,7 @@ func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error)
s, ok := rawS.(compatibleSource)
if !ok {
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", kind, cfg.Source)
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", resourceType, cfg.Source)
}
project := s.GetDefaultProject()

View File

@@ -17,7 +17,6 @@ package alloydbgetinstance_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"
@@ -37,12 +36,12 @@ func TestParseFromYaml(t *testing.T) {
{
desc: "basic example",
in: `
tools:
get-my-instance:
kind: alloydb-get-instance
source: my-alloydb-admin-source
description: some description
`,
kind: tools
name: get-my-instance
type: alloydb-get-instance
source: my-alloydb-admin-source
description: some description
`,
want: server.ToolConfigs{
"get-my-instance": alloydbgetinstance.Config{
Name: "get-my-instance",
@@ -56,15 +55,15 @@ func TestParseFromYaml(t *testing.T) {
{
desc: "with auth required",
in: `
tools:
get-my-instance-auth:
kind: alloydb-get-instance
source: my-alloydb-admin-source
description: some description
authRequired:
- my-google-auth-service
- other-auth-service
`,
kind: tools
name: get-my-instance-auth
type: alloydb-get-instance
source: my-alloydb-admin-source
description: some description
authRequired:
- my-google-auth-service
- other-auth-service
`,
want: server.ToolConfigs{
"get-my-instance-auth": alloydbgetinstance.Config{
Name: "get-my-instance-auth",
@@ -78,15 +77,12 @@ func TestParseFromYaml(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)
}
})

View File

@@ -25,11 +25,11 @@ import (
"github.com/googleapis/genai-toolbox/internal/util/parameters"
)
const kind string = "alloydb-get-user"
const resourceType string = "alloydb-get-user"
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 {
// Configuration for the get-user tool.
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"`
AuthRequired []string `yaml:"authRequired"`
@@ -60,9 +60,9 @@ type Config struct {
// validate interface
var _ tools.ToolConfig = Config{}
// ToolConfigType returns the kind of the tool.
// ToolConfigType returns the type of the tool.
func (cfg Config) ToolConfigType() string {
return kind
return resourceType
}
// Initialize initializes the tool from the configuration.
@@ -74,7 +74,7 @@ func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error)
s, ok := rawS.(compatibleSource)
if !ok {
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", kind, cfg.Source)
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", resourceType, cfg.Source)
}
project := s.GetDefaultProject()

View File

@@ -17,7 +17,6 @@ package alloydbgetuser_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"
@@ -37,12 +36,12 @@ func TestParseFromYaml(t *testing.T) {
{
desc: "basic example",
in: `
tools:
get-my-user:
kind: alloydb-get-user
source: my-alloydb-admin-source
description: some description
`,
kind: tools
name: get-my-user
type: alloydb-get-user
source: my-alloydb-admin-source
description: some description
`,
want: server.ToolConfigs{
"get-my-user": alloydbgetuser.Config{
Name: "get-my-user",
@@ -56,15 +55,15 @@ func TestParseFromYaml(t *testing.T) {
{
desc: "with auth required",
in: `
tools:
get-my-user-auth:
kind: alloydb-get-user
source: my-alloydb-admin-source
description: some description
authRequired:
- my-google-auth-service
- other-auth-service
`,
kind: tools
name: get-my-user-auth
type: alloydb-get-user
source: my-alloydb-admin-source
description: some description
authRequired:
- my-google-auth-service
- other-auth-service
`,
want: server.ToolConfigs{
"get-my-user-auth": alloydbgetuser.Config{
Name: "get-my-user-auth",
@@ -78,15 +77,12 @@ func TestParseFromYaml(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)
}
})

View File

@@ -25,11 +25,11 @@ import (
"github.com/googleapis/genai-toolbox/internal/util/parameters"
)
const kind string = "alloydb-list-clusters"
const resourceType string = "alloydb-list-clusters"
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 {
// Configuration for the list-clusters tool.
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"`
AuthRequired []string `yaml:"authRequired"`
@@ -60,9 +60,9 @@ type Config struct {
// validate interface
var _ tools.ToolConfig = Config{}
// ToolConfigType returns the kind of the tool.
// ToolConfigType returns the type of the tool.
func (cfg Config) ToolConfigType() string {
return kind
return resourceType
}
// Initialize initializes the tool from the configuration.
@@ -74,7 +74,7 @@ func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error)
s, ok := rawS.(compatibleSource)
if !ok {
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", kind, cfg.Source)
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", resourceType, cfg.Source)
}
project := s.GetDefaultProject()

View File

@@ -17,7 +17,6 @@ package alloydblistclusters_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"
@@ -37,12 +36,12 @@ func TestParseFromYaml(t *testing.T) {
{
desc: "basic example",
in: `
tools:
list-my-clusters:
kind: alloydb-list-clusters
source: my-alloydb-admin-source
description: some description
`,
kind: tools
name: list-my-clusters
type: alloydb-list-clusters
source: my-alloydb-admin-source
description: some description
`,
want: server.ToolConfigs{
"list-my-clusters": alloydblistclusters.Config{
Name: "list-my-clusters",
@@ -56,15 +55,15 @@ func TestParseFromYaml(t *testing.T) {
{
desc: "with auth required",
in: `
tools:
list-my-clusters-auth:
kind: alloydb-list-clusters
source: my-alloydb-admin-source
description: some description
authRequired:
- my-google-auth-service
- other-auth-service
`,
kind: tools
name: list-my-clusters-auth
type: alloydb-list-clusters
source: my-alloydb-admin-source
description: some description
authRequired:
- my-google-auth-service
- other-auth-service
`,
want: server.ToolConfigs{
"list-my-clusters-auth": alloydblistclusters.Config{
Name: "list-my-clusters-auth",
@@ -78,15 +77,12 @@ func TestParseFromYaml(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)
}
})

View File

@@ -25,11 +25,11 @@ import (
"github.com/googleapis/genai-toolbox/internal/util/parameters"
)
const kind string = "alloydb-list-instances"
const resourceType string = "alloydb-list-instances"
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 {
// Configuration for the list-instances tool.
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"`
AuthRequired []string `yaml:"authRequired"`
@@ -60,9 +60,9 @@ type Config struct {
// validate interface
var _ tools.ToolConfig = Config{}
// ToolConfigType returns the kind of the tool.
// ToolConfigType returns the type of the tool.
func (cfg Config) ToolConfigType() string {
return kind
return resourceType
}
// Initialize initializes the tool from the configuration.
@@ -74,7 +74,7 @@ func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error)
s, ok := rawS.(compatibleSource)
if !ok {
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", kind, cfg.Source)
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", resourceType, cfg.Source)
}
project := s.GetDefaultProject()

View File

@@ -17,7 +17,6 @@ package alloydblistinstances_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"
@@ -37,12 +36,12 @@ func TestParseFromYaml(t *testing.T) {
{
desc: "basic example",
in: `
tools:
list-my-instances:
kind: alloydb-list-instances
source: my-alloydb-admin-source
description: some description
`,
kind: tools
name: list-my-instances
type: alloydb-list-instances
source: my-alloydb-admin-source
description: some description
`,
want: server.ToolConfigs{
"list-my-instances": alloydblistinstances.Config{
Name: "list-my-instances",
@@ -56,15 +55,15 @@ func TestParseFromYaml(t *testing.T) {
{
desc: "with auth required",
in: `
tools:
list-my-instances-auth:
kind: alloydb-list-instances
source: my-alloydb-admin-source
description: some description
authRequired:
- my-google-auth-service
- other-auth-service
`,
kind: tools
name: list-my-instances-auth
type: alloydb-list-instances
source: my-alloydb-admin-source
description: some description
authRequired:
- my-google-auth-service
- other-auth-service
`,
want: server.ToolConfigs{
"list-my-instances-auth": alloydblistinstances.Config{
Name: "list-my-instances-auth",
@@ -78,15 +77,12 @@ func TestParseFromYaml(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)
}
})

View File

@@ -25,11 +25,11 @@ import (
"github.com/googleapis/genai-toolbox/internal/util/parameters"
)
const kind string = "alloydb-list-users"
const resourceType string = "alloydb-list-users"
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 {
// Configuration for the list-users tool.
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"`
AuthRequired []string `yaml:"authRequired"`
@@ -60,9 +60,9 @@ type Config struct {
// validate interface
var _ tools.ToolConfig = Config{}
// ToolConfigType returns the kind of the tool.
// ToolConfigType returns the type of the tool.
func (cfg Config) ToolConfigType() string {
return kind
return resourceType
}
// Initialize initializes the tool from the configuration.
@@ -74,7 +74,7 @@ func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error)
s, ok := rawS.(compatibleSource)
if !ok {
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", kind, cfg.Source)
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", resourceType, cfg.Source)
}
project := s.GetDefaultProject()

View File

@@ -17,7 +17,6 @@ package alloydblistusers_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"
@@ -37,12 +36,12 @@ func TestParseFromYaml(t *testing.T) {
{
desc: "basic example",
in: `
tools:
list-my-users:
kind: alloydb-list-users
source: my-alloydb-admin-source
description: some description
`,
kind: tools
name: list-my-users
type: alloydb-list-users
source: my-alloydb-admin-source
description: some description
`,
want: server.ToolConfigs{
"list-my-users": alloydblistusers.Config{
Name: "list-my-users",
@@ -56,15 +55,15 @@ func TestParseFromYaml(t *testing.T) {
{
desc: "with auth required",
in: `
tools:
list-my-users-auth:
kind: alloydb-list-users
source: my-alloydb-admin-source
description: some description
authRequired:
- my-google-auth-service
- other-auth-service
`,
kind: tools
name: list-my-users-auth
type: alloydb-list-users
source: my-alloydb-admin-source
description: some description
authRequired:
- my-google-auth-service
- other-auth-service
`,
want: server.ToolConfigs{
"list-my-users-auth": alloydblistusers.Config{
Name: "list-my-users-auth",
@@ -78,15 +77,12 @@ func TestParseFromYaml(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)
}
})

View File

@@ -27,7 +27,7 @@ import (
"github.com/googleapis/genai-toolbox/internal/util/parameters"
)
const kind string = "alloydb-wait-for-operation"
const resourceType string = "alloydb-wait-for-operation"
var alloyDBConnectionMessageTemplate = `Your AlloyDB resource is ready.
@@ -73,8 +73,8 @@ Please refer to the official documentation for guidance on deploying the toolbox
`
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))
}
}
@@ -95,7 +95,7 @@ type compatibleSource interface {
// Config defines the configuration for the wait-for-operation tool.
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"`
AuthRequired []string `yaml:"authRequired"`
@@ -110,9 +110,9 @@ type Config struct {
// validate interface
var _ tools.ToolConfig = Config{}
// ToolConfigType returns the kind of the tool.
// ToolConfigType returns the type of the tool.
func (cfg Config) ToolConfigType() string {
return kind
return resourceType
}
// Initialize initializes the tool from the configuration.
@@ -124,7 +124,7 @@ func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error)
s, ok := rawS.(compatibleSource)
if !ok {
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", kind, cfg.Source)
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", resourceType, cfg.Source)
}
project := s.GetDefaultProject()

View File

@@ -17,7 +17,6 @@ package alloydbwaitforoperation_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"
@@ -37,16 +36,16 @@ func TestParseFromYaml(t *testing.T) {
{
desc: "basic example",
in: `
tools:
wait-for-thing:
kind: alloydb-wait-for-operation
source: some-source
description: some description
delay: 1s
maxDelay: 5s
multiplier: 1.5
maxRetries: 5
`,
kind: tools
name: wait-for-thing
type: alloydb-wait-for-operation
source: some-source
description: some description
delay: 1s
maxDelay: 5s
multiplier: 1.5
maxRetries: 5
`,
want: server.ToolConfigs{
"wait-for-thing": alloydbwaitforoperation.Config{
Name: "wait-for-thing",
@@ -64,15 +63,12 @@ func TestParseFromYaml(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)
}
})

View File

@@ -27,11 +27,11 @@ import (
"github.com/jackc/pgx/v5/pgxpool"
)
const kind string = "alloydb-ai-nl"
const resourceType string = "alloydb-ai-nl"
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"`
NLConfig string `yaml:"nlConfig" validate:"required"`
@@ -62,7 +62,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) {

View File

@@ -17,7 +17,6 @@ package alloydbainl_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,22 +37,22 @@ func TestParseFromYamlAlloyDBNLA(t *testing.T) {
{
desc: "basic example",
in: `
tools:
example_tool:
kind: alloydb-ai-nl
source: my-alloydb-instance
description: AlloyDB natural language query tool
nlConfig: 'my_nl_config'
authRequired:
- my-google-auth-service
nlConfigParameters:
- name: user_id
type: string
description: user_id to use
authServices:
- name: my-google-auth-service
field: sub
`,
kind: tools
name: example_tool
type: alloydb-ai-nl
source: my-alloydb-instance
description: AlloyDB natural language query tool
nlConfig: 'my_nl_config'
authRequired:
- my-google-auth-service
nlConfigParameters:
- name: user_id
type: string
description: user_id to use
authServices:
- name: my-google-auth-service
field: sub
`,
want: server.ToolConfigs{
"example_tool": alloydbainl.Config{
Name: "example_tool",
@@ -72,29 +71,29 @@ func TestParseFromYamlAlloyDBNLA(t *testing.T) {
{
desc: "with multiple parameters",
in: `
tools:
complex_tool:
kind: alloydb-ai-nl
source: my-alloydb-instance
description: AlloyDB natural language query tool with multiple parameters
nlConfig: 'complex_nl_config'
authRequired:
- my-google-auth-service
- other-auth-service
nlConfigParameters:
- name: user_id
type: string
description: user_id to use
authServices:
- name: my-google-auth-service
field: sub
- name: user_email
type: string
description: user_email to use
authServices:
- name: my-google-auth-service
field: user_email
`,
kind: tools
name: complex_tool
type: alloydb-ai-nl
source: my-alloydb-instance
description: AlloyDB natural language query tool with multiple parameters
nlConfig: 'complex_nl_config'
authRequired:
- my-google-auth-service
- other-auth-service
nlConfigParameters:
- name: user_id
type: string
description: user_id to use
authServices:
- name: my-google-auth-service
field: sub
- name: user_email
type: string
description: user_email to use
authServices:
- name: my-google-auth-service
field: user_email
`,
want: server.ToolConfigs{
"complex_tool": alloydbainl.Config{
Name: "complex_tool",
@@ -115,15 +114,12 @@ func TestParseFromYamlAlloyDBNLA(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)
}
})

View File

@@ -31,11 +31,11 @@ import (
bigqueryrestapi "google.golang.org/api/bigquery/v2"
)
const kind string = "bigquery-analyze-contribution"
const resourceType string = "bigquery-analyze-contribution"
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))
}
}
@@ -59,7 +59,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"`
@@ -69,7 +69,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) {
@@ -82,7 +82,7 @@ func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error)
// verify the source is compatible
s, ok := rawS.(compatibleSource)
if !ok {
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", kind, cfg.Source)
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", resourceType, cfg.Source)
}
allowedDatasets := s.BigQueryAllowedDatasets()

View File

@@ -17,7 +17,6 @@ package bigqueryanalyzecontribution_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"
@@ -37,12 +36,12 @@ func TestParseFromYamlBigQueryAnalyzeContribution(t *testing.T) {
{
desc: "basic example",
in: `
tools:
example_tool:
kind: bigquery-analyze-contribution
source: my-instance
description: some description
`,
kind: tools
name: example_tool
type: bigquery-analyze-contribution
source: my-instance
description: some description
`,
want: server.ToolConfigs{
"example_tool": bigqueryanalyzecontribution.Config{
Name: "example_tool",
@@ -56,15 +55,12 @@ func TestParseFromYamlBigQueryAnalyzeContribution(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)
}
})

View File

@@ -33,7 +33,7 @@ import (
"golang.org/x/oauth2"
)
const kind string = "bigquery-conversational-analytics"
const resourceType string = "bigquery-conversational-analytics"
const instructions = `**INSTRUCTIONS - FOLLOW THESE RULES:**
1. **CONTENT:** Your answer should present the supporting data and then provide a conclusion based on that data.
@@ -41,8 +41,8 @@ const instructions = `**INSTRUCTIONS - FOLLOW THESE RULES:**
3. **NO CHARTS:** You are STRICTLY FORBIDDEN from generating any charts, graphs, images, or any other form of visualization.`
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))
}
}
@@ -107,7 +107,7 @@ type CAPayload struct {
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"`
@@ -117,7 +117,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) {
@@ -130,7 +130,7 @@ func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error)
// verify the source is compatible
s, ok := rawS.(compatibleSource)
if !ok {
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", kind, cfg.Source)
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", resourceType, cfg.Source)
}
allowedDatasets := s.BigQueryAllowedDatasets()

View File

@@ -17,7 +17,6 @@ package bigqueryconversationalanalytics_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"
@@ -37,12 +36,12 @@ func TestParseFromYamlBigQueryConversationalAnalytics(t *testing.T) {
{
desc: "basic example",
in: `
tools:
example_tool:
kind: bigquery-conversational-analytics
source: my-instance
description: some description
`,
kind: tools
name: example_tool
type: bigquery-conversational-analytics
source: my-instance
description: some description
`,
want: server.ToolConfigs{
"example_tool": bigqueryconversationalanalytics.Config{
Name: "example_tool",
@@ -56,15 +55,12 @@ func TestParseFromYamlBigQueryConversationalAnalytics(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)
}
})

View File

@@ -32,11 +32,11 @@ import (
bigqueryrestapi "google.golang.org/api/bigquery/v2"
)
const kind string = "bigquery-execute-sql"
const resourceType string = "bigquery-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))
}
}
@@ -61,7 +61,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"`
@@ -71,7 +71,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) {
@@ -84,7 +84,7 @@ func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error)
// verify the source is compatible
s, ok := rawS.(compatibleSource)
if !ok {
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", kind, cfg.Source)
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", resourceType, cfg.Source)
}
var sqlDescriptionBuilder strings.Builder
@@ -277,7 +277,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, bqClient, sql, statementType, nil, connProps)
}

View File

@@ -17,7 +17,6 @@ package bigqueryexecutesql_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"
@@ -37,12 +36,12 @@ func TestParseFromYamlBigQueryExecuteSql(t *testing.T) {
{
desc: "basic example",
in: `
tools:
example_tool:
kind: bigquery-execute-sql
source: my-instance
description: some description
`,
kind: tools
name: example_tool
type: bigquery-execute-sql
source: my-instance
description: some description
`,
want: server.ToolConfigs{
"example_tool": bigqueryexecutesql.Config{
Name: "example_tool",
@@ -56,15 +55,12 @@ func TestParseFromYamlBigQueryExecuteSql(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)
}
})

View File

@@ -31,11 +31,11 @@ import (
bigqueryrestapi "google.golang.org/api/bigquery/v2"
)
const kind string = "bigquery-forecast"
const resourceType string = "bigquery-forecast"
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))
}
}
@@ -59,7 +59,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"`
@@ -69,7 +69,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) {
@@ -82,7 +82,7 @@ func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error)
// verify the source is compatible
s, ok := rawS.(compatibleSource)
if !ok {
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", kind, cfg.Source)
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", resourceType, cfg.Source)
}
allowedDatasets := s.BigQueryAllowedDatasets()
@@ -266,7 +266,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, bqClient, sql, "SELECT", nil, connProps)
}

View File

@@ -17,7 +17,6 @@ package bigqueryforecast_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"
@@ -37,12 +36,12 @@ func TestParseFromYamlBigQueryForecast(t *testing.T) {
{
desc: "basic example",
in: `
tools:
example_tool:
kind: bigquery-forecast
source: my-instance
description: some description
`,
kind: tools
name: example_tool
type: bigquery-forecast
source: my-instance
description: some description
`,
want: server.ToolConfigs{
"example_tool": bigqueryforecast.Config{
Name: "example_tool",
@@ -56,15 +55,12 @@ func TestParseFromYamlBigQueryForecast(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)
}
})

View File

@@ -28,13 +28,13 @@ import (
bigqueryrestapi "google.golang.org/api/bigquery/v2"
)
const kind string = "bigquery-get-dataset-info"
const resourceType string = "bigquery-get-dataset-info"
const projectKey string = "project"
const datasetKey string = "dataset"
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))
}
}
@@ -56,7 +56,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"`
@@ -66,7 +66,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) {
@@ -79,7 +79,7 @@ func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error)
// verify the source is compatible
s, ok := rawS.(compatibleSource)
if !ok {
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", kind, cfg.Source)
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", resourceType, cfg.Source)
}
defaultProjectID := s.BigQueryProject()

View File

@@ -17,7 +17,6 @@ package bigquerygetdatasetinfo_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"
@@ -37,12 +36,12 @@ func TestParseFromYamlBigQueryGetDatasetInfo(t *testing.T) {
{
desc: "basic example",
in: `
tools:
example_tool:
kind: bigquery-get-dataset-info
source: my-instance
description: some description
`,
kind: tools
name: example_tool
type: bigquery-get-dataset-info
source: my-instance
description: some description
`,
want: server.ToolConfigs{
"example_tool": bigquerygetdatasetinfo.Config{
Name: "example_tool",
@@ -56,15 +55,12 @@ func TestParseFromYamlBigQueryGetDatasetInfo(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)
}
})

View File

@@ -28,14 +28,14 @@ import (
bigqueryrestapi "google.golang.org/api/bigquery/v2"
)
const kind string = "bigquery-get-table-info"
const resourceType string = "bigquery-get-table-info"
const projectKey string = "project"
const datasetKey string = "dataset"
const tableKey string = "table"
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))
}
}
@@ -57,7 +57,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"`
@@ -67,7 +67,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) {
@@ -80,7 +80,7 @@ func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error)
// verify the source is compatible
s, ok := rawS.(compatibleSource)
if !ok {
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", kind, cfg.Source)
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", resourceType, cfg.Source)
}
defaultProjectID := s.BigQueryProject()

View File

@@ -17,7 +17,6 @@ package bigquerygettableinfo_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"
@@ -37,12 +36,12 @@ func TestParseFromYamlBigQueryGetTableInfo(t *testing.T) {
{
desc: "basic example",
in: `
tools:
example_tool:
kind: bigquery-get-table-info
source: my-instance
description: some description
`,
kind: tools
name: example_tool
type: bigquery-get-table-info
source: my-instance
description: some description
`,
want: server.ToolConfigs{
"example_tool": bigquerygettableinfo.Config{
Name: "example_tool",
@@ -56,15 +55,12 @@ func TestParseFromYamlBigQueryGetTableInfo(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)
}
})

View File

@@ -28,12 +28,12 @@ import (
"google.golang.org/api/iterator"
)
const kind string = "bigquery-list-dataset-ids"
const resourceType string = "bigquery-list-dataset-ids"
const projectKey string = "project"
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))
}
}
@@ -54,7 +54,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"`
@@ -64,7 +64,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) {
@@ -77,7 +77,7 @@ func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error)
// verify the source is compatible
s, ok := rawS.(compatibleSource)
if !ok {
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", kind, cfg.Source)
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", resourceType, cfg.Source)
}
var projectParameter parameters.Parameter

View File

@@ -17,7 +17,6 @@ package bigquerylistdatasetids_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"
@@ -37,12 +36,12 @@ func TestParseFromYamlBigQueryListDatasetIds(t *testing.T) {
{
desc: "basic example",
in: `
tools:
example_tool:
kind: bigquery-list-dataset-ids
source: my-instance
description: some description
`,
kind: tools
name: example_tool
type: bigquery-list-dataset-ids
source: my-instance
description: some description
`,
want: server.ToolConfigs{
"example_tool": bigquerylistdatasetids.Config{
Name: "example_tool",
@@ -56,15 +55,12 @@ func TestParseFromYamlBigQueryListDatasetIds(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)
}
})

View File

@@ -29,13 +29,13 @@ import (
"google.golang.org/api/iterator"
)
const kind string = "bigquery-list-table-ids"
const resourceType string = "bigquery-list-table-ids"
const projectKey string = "project"
const datasetKey string = "dataset"
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))
}
}
@@ -57,7 +57,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"`
@@ -67,7 +67,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) {
@@ -80,7 +80,7 @@ func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error)
// verify the source is compatible
s, ok := rawS.(compatibleSource)
if !ok {
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", kind, cfg.Source)
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", resourceType, cfg.Source)
}
defaultProjectID := s.BigQueryProject()

View File

@@ -17,7 +17,6 @@ package bigquerylisttableids_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"
@@ -37,12 +36,12 @@ func TestParseFromYamlBigQueryListTableIds(t *testing.T) {
{
desc: "basic example",
in: `
tools:
example_tool:
kind: bigquery-list-table-ids
source: my-instance
description: some description
`,
kind: tools
name: example_tool
type: bigquery-list-table-ids
source: my-instance
description: some description
`,
want: server.ToolConfigs{
"example_tool": bigquerylisttableids.Config{
Name: "example_tool",
@@ -56,15 +55,12 @@ func TestParseFromYamlBigQueryListTableIds(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)
}
})

View File

@@ -30,11 +30,11 @@ import (
"google.golang.org/api/iterator"
)
const kind string = "bigquery-search-catalog"
const resourceType string = "bigquery-search-catalog"
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))
}
}
@@ -54,7 +54,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"`
AuthRequired []string `yaml:"authRequired"`
@@ -64,7 +64,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) {

View File

@@ -17,7 +17,6 @@ package bigquerysearchcatalog_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"
@@ -37,12 +36,12 @@ func TestParseFromYamlBigQuerySearch(t *testing.T) {
{
desc: "basic example",
in: `
tools:
example_tool:
kind: bigquery-search-catalog
source: my-instance
description: some description
`,
kind: tools
name: example_tool
type: bigquery-search-catalog
source: my-instance
description: some description
`,
want: server.ToolConfigs{
"example_tool": bigquerysearchcatalog.Config{
Name: "example_tool",
@@ -56,15 +55,12 @@ func TestParseFromYamlBigQuerySearch(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)
}
})

View File

@@ -31,11 +31,11 @@ import (
bigqueryrestapi "google.golang.org/api/bigquery/v2"
)
const kind string = "bigquery-sql"
const resourceType string = "bigquery-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))
}
}
@@ -56,7 +56,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"`
Statement string `yaml:"statement" validate:"required"`
@@ -69,7 +69,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) {

View File

@@ -17,7 +17,6 @@ package bigquerysql_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,18 +37,18 @@ func TestParseFromYamlBigQuery(t *testing.T) {
{
desc: "basic example",
in: `
tools:
example_tool:
kind: bigquery-sql
source: my-instance
description: some description
statement: |
SELECT * FROM SQL_STATEMENT;
parameters:
- name: country
type: string
description: some description
`,
kind: tools
name: example_tool
type: bigquery-sql
source: my-instance
description: some description
statement: |
SELECT * FROM SQL_STATEMENT;
parameters:
- name: country
type: string
description: some description
`,
want: server.ToolConfigs{
"example_tool": bigquerysql.Config{
Name: "example_tool",
@@ -67,20 +66,16 @@ func TestParseFromYamlBigQuery(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)
}
})
}
}
func TestParseFromYamlWithTemplateBigQuery(t *testing.T) {
@@ -96,29 +91,29 @@ func TestParseFromYamlWithTemplateBigQuery(t *testing.T) {
{
desc: "basic example",
in: `
tools:
example_tool:
kind: bigquery-sql
source: my-instance
description: some description
statement: |
SELECT * FROM SQL_STATEMENT;
parameters:
- name: country
type: string
description: some description
templateParameters:
- name: tableName
type: string
description: The table to select hotels from.
- name: fieldArray
type: array
description: The columns to return for the query.
items:
name: column
type: string
description: A column name that will be returned from the query.
`,
kind: tools
name: example_tool
type: bigquery-sql
source: my-instance
description: some description
statement: |
SELECT * FROM SQL_STATEMENT;
parameters:
- name: country
type: string
description: some description
templateParameters:
- name: tableName
type: string
description: The table to select hotels from.
- name: fieldArray
type: array
description: The columns to return for the query.
items:
name: column
type: string
description: A column name that will be returned from the query.
`,
want: server.ToolConfigs{
"example_tool": bigquerysql.Config{
Name: "example_tool",
@@ -140,18 +135,14 @@ func TestParseFromYamlWithTemplateBigQuery(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)
}
})
}
}

View File

@@ -26,11 +26,11 @@ import (
"github.com/googleapis/genai-toolbox/internal/util/parameters"
)
const kind string = "bigtable-sql"
const resourceType string = "bigtable-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))
}
}
@@ -49,7 +49,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"`
Statement string `yaml:"statement" validate:"required"`
@@ -62,7 +62,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) {

View File

@@ -17,7 +17,6 @@ package bigtable_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,17 +37,17 @@ func TestParseFromYamlBigtable(t *testing.T) {
{
desc: "basic example",
in: `
tools:
example_tool:
kind: bigtable-sql
source: my-pg-instance
description: some description
statement: |
SELECT * FROM SQL_STATEMENT;
parameters:
- name: country
type: string
description: some description
kind: tools
name: example_tool
type: bigtable-sql
source: my-pg-instance
description: some description
statement: |
SELECT * FROM SQL_STATEMENT;
parameters:
- name: country
type: string
description: some description
`,
want: server.ToolConfigs{
"example_tool": bigtable.Config{
@@ -67,15 +66,11 @@ func TestParseFromYamlBigtable(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)
}
})
@@ -96,28 +91,28 @@ func TestParseFromYamlWithTemplateBigtable(t *testing.T) {
{
desc: "basic example",
in: `
tools:
example_tool:
kind: bigtable-sql
source: my-pg-instance
description: some description
statement: |
SELECT * FROM SQL_STATEMENT;
parameters:
- name: country
type: string
description: some description
templateParameters:
- name: tableName
type: string
description: The table to select hotels from.
- name: fieldArray
type: array
description: The columns to return for the query.
items:
name: column
type: string
description: A column name that will be returned from the query.
kind: tools
name: example_tool
type: bigtable-sql
source: my-pg-instance
description: some description
statement: |
SELECT * FROM SQL_STATEMENT;
parameters:
- name: country
type: string
description: some description
templateParameters:
- name: tableName
type: string
description: The table to select hotels from.
- name: fieldArray
type: array
description: The columns to return for the query.
items:
name: column
type: string
description: A column name that will be returned from the query.
`,
want: server.ToolConfigs{
"example_tool": bigtable.Config{
@@ -140,15 +135,11 @@ func TestParseFromYamlWithTemplateBigtable(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)
}
})

View File

@@ -26,11 +26,11 @@ import (
"github.com/googleapis/genai-toolbox/internal/util/parameters"
)
const kind string = "cassandra-cql"
const resourceType string = "cassandra-cql"
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))
}
}
@@ -49,7 +49,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"`
Statement string `yaml:"statement" validate:"required"`
@@ -62,7 +62,7 @@ var _ tools.ToolConfig = Config{}
// ToolConfigType implements tools.ToolConfig.
func (c Config) ToolConfigType() string {
return kind
return resourceType
}
// Initialize implements tools.ToolConfig.

View File

@@ -17,7 +17,6 @@ package cassandracql_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,26 +37,26 @@ func TestParseFromYamlCassandra(t *testing.T) {
{
desc: "basic example",
in: `
tools:
example_tool:
kind: cassandra-cql
source: my-cassandra-instance
description: some description
statement: |
SELECT * FROM CQL_STATEMENT;
authRequired:
- my-google-auth-service
- other-auth-service
parameters:
- name: country
type: string
description: some description
authServices:
- name: my-google-auth-service
field: user_id
- name: other-auth-service
field: user_id
`,
kind: tools
type: cassandra-cql
name: example_tool
source: my-cassandra-instance
description: some description
statement: |
SELECT * FROM CQL_STATEMENT;
authRequired:
- my-google-auth-service
- other-auth-service
parameters:
- name: country
type: string
description: some description
authServices:
- name: my-google-auth-service
field: user_id
- name: other-auth-service
field: user_id
`,
want: server.ToolConfigs{
"example_tool": cassandracql.Config{
Name: "example_tool",
@@ -77,37 +76,37 @@ func TestParseFromYamlCassandra(t *testing.T) {
{
desc: "with template parameters",
in: `
tools:
example_tool:
kind: cassandra-cql
source: my-cassandra-instance
description: some description
statement: |
SELECT * FROM CQL_STATEMENT;
authRequired:
- my-google-auth-service
- other-auth-service
parameters:
- name: country
type: string
description: some description
authServices:
- name: my-google-auth-service
field: user_id
- name: other-auth-service
field: user_id
templateParameters:
- name: tableName
type: string
description: some description.
- name: fieldArray
type: array
description: The columns to return for the query.
items:
name: column
type: string
description: A column name that will be returned from the query.
`,
kind: tools
type: cassandra-cql
name: example_tool
source: my-cassandra-instance
description: some description
statement: |
SELECT * FROM CQL_STATEMENT;
authRequired:
- my-google-auth-service
- other-auth-service
parameters:
- name: country
type: string
description: some description
authServices:
- name: my-google-auth-service
field: user_id
- name: other-auth-service
field: user_id
templateParameters:
- name: tableName
type: string
description: some description.
- name: fieldArray
type: array
description: The columns to return for the query.
items:
name: column
type: string
description: A column name that will be returned from the query.
`,
want: server.ToolConfigs{
"example_tool": cassandracql.Config{
Name: "example_tool",
@@ -131,14 +130,14 @@ func TestParseFromYamlCassandra(t *testing.T) {
{
desc: "without optional fields",
in: `
tools:
example_tool:
kind: cassandra-cql
source: my-cassandra-instance
description: some description
statement: |
SELECT * FROM CQL_STATEMENT;
`,
kind: tools
type: cassandra-cql
name: example_tool
source: my-cassandra-instance
description: some description
statement: |
SELECT * FROM CQL_STATEMENT;
`,
want: server.ToolConfigs{
"example_tool": cassandracql.Config{
Name: "example_tool",
@@ -155,15 +154,12 @@ func TestParseFromYamlCassandra(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)
}
})

View File

@@ -47,7 +47,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"`

View File

@@ -17,7 +17,6 @@ package clickhouse
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"
@@ -36,12 +35,12 @@ func TestParseFromYamlClickHouseExecuteSQL(t *testing.T) {
{
desc: "basic example",
in: `
tools:
example_tool:
kind: clickhouse-execute-sql
source: my-instance
description: some description
`,
kind: tools
name: example_tool
type: clickhouse-execute-sql
source: my-instance
description: some description
`,
want: server.ToolConfigs{
"example_tool": Config{
Name: "example_tool",
@@ -55,14 +54,12 @@ func TestParseFromYamlClickHouseExecuteSQL(t *testing.T) {
}
for _, tc := range tcs {
t.Run(tc.desc, func(t *testing.T) {
got := struct {
Tools server.ToolConfigs `yaml:"tools"`
}{}
err := yaml.UnmarshalContext(ctx, testutils.FormatYaml(tc.in), &got)
// Parse contents
_, _, _, 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)
}
})

View File

@@ -47,7 +47,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"`

View File

@@ -17,7 +17,6 @@ package clickhouse
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"
@@ -44,12 +43,12 @@ func TestParseFromYamlClickHouseListDatabases(t *testing.T) {
{
desc: "basic example",
in: `
tools:
example_tool:
kind: clickhouse-list-databases
source: my-instance
description: some description
`,
kind: tools
name: example_tool
type: clickhouse-list-databases
source: my-instance
description: some description
`,
want: server.ToolConfigs{
"example_tool": Config{
Name: "example_tool",
@@ -63,14 +62,12 @@ func TestParseFromYamlClickHouseListDatabases(t *testing.T) {
}
for _, tc := range tcs {
t.Run(tc.desc, func(t *testing.T) {
got := struct {
Tools server.ToolConfigs `yaml:"tools"`
}{}
err := yaml.UnmarshalContext(ctx, testutils.FormatYaml(tc.in), &got)
// Parse contents
_, _, _, 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)
}
})

View File

@@ -48,7 +48,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"`

View File

@@ -17,7 +17,6 @@ package clickhouse
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"
@@ -44,12 +43,12 @@ func TestParseFromYamlClickHouseListTables(t *testing.T) {
{
desc: "basic example",
in: `
tools:
example_tool:
kind: clickhouse-list-tables
source: my-instance
description: some description
`,
kind: tools
name: example_tool
type: clickhouse-list-tables
source: my-instance
description: some description
`,
want: server.ToolConfigs{
"example_tool": Config{
Name: "example_tool",
@@ -63,14 +62,12 @@ func TestParseFromYamlClickHouseListTables(t *testing.T) {
}
for _, tc := range tcs {
t.Run(tc.desc, func(t *testing.T) {
got := struct {
Tools server.ToolConfigs `yaml:"tools"`
}{}
err := yaml.UnmarshalContext(ctx, testutils.FormatYaml(tc.in), &got)
// Parse contents
_, _, _, 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)
}
})

View File

@@ -47,7 +47,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"`
Statement string `yaml:"statement" validate:"required"`

View File

@@ -17,7 +17,6 @@ package clickhouse
import (
"testing"
"github.com/goccy/go-yaml"
"github.com/google/go-cmp/cmp"
"github.com/googleapis/genai-toolbox/internal/server"
"github.com/googleapis/genai-toolbox/internal/sources"
@@ -47,12 +46,12 @@ func TestParseFromYamlClickHouseSQL(t *testing.T) {
{
desc: "basic example",
in: `
tools:
example_tool:
kind: clickhouse-sql
source: my-instance
description: some description
statement: SELECT 1
kind: tools
name: example_tool
type: clickhouse-sql
source: my-instance
description: some description
statement: SELECT 1
`,
want: server.ToolConfigs{
"example_tool": Config{
@@ -68,16 +67,16 @@ func TestParseFromYamlClickHouseSQL(t *testing.T) {
{
desc: "with parameters",
in: `
tools:
param_tool:
kind: clickhouse-sql
source: test-source
description: Test ClickHouse tool
statement: SELECT * FROM test_table WHERE id = $1
parameters:
- name: id
type: string
description: Test ID
kind: tools
name: param_tool
type: clickhouse-sql
source: test-source
description: Test ClickHouse tool
statement: SELECT * FROM test_table WHERE id = $1
parameters:
- name: id
type: string
description: Test ID
`,
want: server.ToolConfigs{
"param_tool": Config{
@@ -96,14 +95,11 @@ func TestParseFromYamlClickHouseSQL(t *testing.T) {
}
for _, tc := range tcs {
t.Run(tc.desc, func(t *testing.T) {
got := struct {
Tools server.ToolConfigs `yaml:"tools"`
}{}
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)
}
})

View File

@@ -26,11 +26,11 @@ import (
"github.com/googleapis/genai-toolbox/internal/util/parameters"
)
const kind string = "cloud-gemini-data-analytics-query"
const resourceType string = "cloud-gemini-data-analytics-query"
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"`
Location string `yaml:"location" validate:"required"`
@@ -63,7 +63,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) {

View File

@@ -23,7 +23,6 @@ import (
"net/http/httptest"
"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/server/resources"
@@ -36,6 +35,10 @@ import (
)
func TestParseFromYaml(t *testing.T) {
ctx, err := testutils.ContextWithNewLogger()
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
t.Parallel()
tcs := []struct {
desc string
@@ -45,25 +48,25 @@ func TestParseFromYaml(t *testing.T) {
{
desc: "basic example",
in: `
tools:
my-gda-query-tool:
kind: cloud-gemini-data-analytics-query
source: gda-api-source
description: Test Description
location: us-central1
context:
datasourceReferences:
spannerReference:
databaseReference:
projectId: "cloud-db-nl2sql"
region: "us-central1"
instanceId: "evalbench"
databaseId: "financial"
engine: "GOOGLE_SQL"
agentContextReference:
contextSetId: "projects/cloud-db-nl2sql/locations/us-east1/contextSets/bdf_gsql_gemini_all_templates"
generationOptions:
generateQueryResult: true
kind: tools
name: my-gda-query-tool
type: cloud-gemini-data-analytics-query
source: gda-api-source
description: Test Description
location: us-central1
context:
datasourceReferences:
spannerReference:
databaseReference:
projectId: "cloud-db-nl2sql"
region: "us-central1"
instanceId: "evalbench"
databaseId: "financial"
engine: "GOOGLE_SQL"
agentContextReference:
contextSetId: "projects/cloud-db-nl2sql/locations/us-east1/contextSets/bdf_gsql_gemini_all_templates"
generationOptions:
generateQueryResult: true
`,
want: map[string]tools.ToolConfig{
"my-gda-query-tool": cloudgdatool.Config{
@@ -100,16 +103,12 @@ func TestParseFromYaml(t *testing.T) {
tc := tc
t.Run(tc.desc, func(t *testing.T) {
t.Parallel()
got := struct {
Tools server.ToolConfigs `yaml:"tools"`
}{}
// Parse contents
err := yaml.Unmarshal(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 !cmp.Equal(tc.want, got.Tools) {
t.Fatalf("incorrect parse: want %v, got %v", tc.want, got.Tools)
if !cmp.Equal(tc.want, got) {
t.Fatalf("incorrect parse: want %v, got %v", tc.want, got)
}
})
}
@@ -135,13 +134,13 @@ func (rt *authRoundTripper) RoundTrip(req *http.Request) (*http.Response, error)
}
type mockSource struct {
kind string
Type string
client *http.Client // Can be used to inject a specific client
baseURL string // BaseURL is needed to implement sources.Source.BaseURL
config cloudgdasrc.Config // to return from ToConfig
}
func (m *mockSource) SourceType() string { return m.kind }
func (m *mockSource) SourceType() string { return m.Type }
func (m *mockSource) ToConfig() sources.SourceConfig { return m.config }
func (m *mockSource) GetClient(ctx context.Context, token string) (*http.Client, error) {
if m.client != nil {
@@ -189,7 +188,7 @@ func TestInitialize(t *testing.T) {
}
// Add an incompatible source for testing
srcs["incompatible-source"] = &mockSource{kind: "another-kind"}
srcs["incompatible-source"] = &mockSource{Type: "another-type"}
for _, tc := range tcs {
tc := tc

View File

@@ -25,14 +25,14 @@ import (
"github.com/googleapis/genai-toolbox/internal/util/parameters"
)
const kind string = "cloud-healthcare-fhir-fetch-page"
const resourceType string = "cloud-healthcare-fhir-fetch-page"
const (
pageURLKey = "pageURL"
)
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))
}
}
@@ -51,7 +51,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"`
@@ -61,7 +61,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) {

View File

@@ -17,7 +17,6 @@ package fhirfetchpage_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"
@@ -37,11 +36,11 @@ func TestParseFromYamlHealthcareFHIRFetchPage(t *testing.T) {
{
desc: "basic example",
in: `
tools:
example_tool:
kind: cloud-healthcare-fhir-fetch-page
source: my-instance
description: some description
kind: tools
name: example_tool
type: cloud-healthcare-fhir-fetch-page
source: my-instance
description: some description
`,
want: server.ToolConfigs{
"example_tool": fhirfetchpage.Config{
@@ -56,15 +55,12 @@ func TestParseFromYamlHealthcareFHIRFetchPage(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)
}
})

View File

@@ -28,7 +28,7 @@ import (
"google.golang.org/api/googleapi"
)
const kind string = "cloud-healthcare-fhir-patient-everything"
const resourceType string = "cloud-healthcare-fhir-patient-everything"
const (
patientIDKey = "patientID"
typeFilterKey = "resourceTypesFilter"
@@ -36,8 +36,8 @@ const (
)
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))
}
}
@@ -57,7 +57,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"`
@@ -67,7 +67,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) {
@@ -80,7 +80,7 @@ func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error)
// verify the source is compatible
s, ok := rawS.(compatibleSource)
if !ok {
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", kind, cfg.Source)
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", resourceType, cfg.Source)
}
idParameter := parameters.NewStringParameter(patientIDKey, "The ID of the patient FHIR resource for which the information is required")

View File

@@ -17,7 +17,6 @@ package fhirpatienteverything_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"
@@ -37,11 +36,11 @@ func TestParseFromYamlHealthcareFHIRPatientEverything(t *testing.T) {
{
desc: "basic example",
in: `
tools:
example_tool:
kind: cloud-healthcare-fhir-patient-everything
source: my-instance
description: some description
kind: tools
name: example_tool
type: cloud-healthcare-fhir-patient-everything
source: my-instance
description: some description
`,
want: server.ToolConfigs{
"example_tool": fhirpatienteverything.Config{
@@ -56,15 +55,12 @@ func TestParseFromYamlHealthcareFHIRPatientEverything(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)
}
})

View File

@@ -28,7 +28,7 @@ import (
"google.golang.org/api/googleapi"
)
const kind string = "cloud-healthcare-fhir-patient-search"
const resourceType string = "cloud-healthcare-fhir-patient-search"
const (
activeKey = "active"
cityKey = "city"
@@ -52,8 +52,8 @@ const (
)
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))
}
}
@@ -73,7 +73,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"`
@@ -83,7 +83,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) {
@@ -96,7 +96,7 @@ func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error)
// verify the source is compatible
s, ok := rawS.(compatibleSource)
if !ok {
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", kind, cfg.Source)
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", resourceType, cfg.Source)
}
params := parameters.Parameters{

View File

@@ -17,7 +17,6 @@ package fhirpatientsearch_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"
@@ -37,11 +36,11 @@ func TestParseFromYamlHealthcareFHIRPatientSearch(t *testing.T) {
{
desc: "basic example",
in: `
tools:
example_tool:
kind: cloud-healthcare-fhir-patient-search
source: my-instance
description: some description
kind: tools
name: example_tool
type: cloud-healthcare-fhir-patient-search
source: my-instance
description: some description
`,
want: server.ToolConfigs{
"example_tool": fhirpatientsearch.Config{
@@ -56,15 +55,12 @@ func TestParseFromYamlHealthcareFHIRPatientSearch(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)
}
})

View File

@@ -26,11 +26,11 @@ import (
"google.golang.org/api/healthcare/v1"
)
const kind string = "cloud-healthcare-get-dataset"
const resourceType string = "cloud-healthcare-get-dataset"
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))
}
}
@@ -49,7 +49,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"`
@@ -59,7 +59,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) {

View File

@@ -17,7 +17,6 @@ package gethealthcaredataset_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"
@@ -37,11 +36,11 @@ func TestParseFromYamlGetHealthcareDataset(t *testing.T) {
{
desc: "basic example",
in: `
tools:
example_tool:
kind: cloud-healthcare-get-dataset
source: my-instance
description: some description
kind: tools
name: example_tool
type: cloud-healthcare-get-dataset
source: my-instance
description: some description
`,
want: server.ToolConfigs{
"example_tool": getdataset.Config{
@@ -56,15 +55,12 @@ func TestParseFromYamlGetHealthcareDataset(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)
}
})

View File

@@ -27,11 +27,11 @@ import (
"google.golang.org/api/healthcare/v1"
)
const kind string = "cloud-healthcare-get-dicom-store"
const resourceType string = "cloud-healthcare-get-dicom-store"
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))
}
}
@@ -51,7 +51,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"`
@@ -61,7 +61,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) {
@@ -74,7 +74,7 @@ func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error)
// verify the source is compatible
s, ok := rawS.(compatibleSource)
if !ok {
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", kind, cfg.Source)
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", resourceType, cfg.Source)
}
params := parameters.Parameters{}

View File

@@ -17,7 +17,6 @@ package getdicomstore_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"
@@ -37,11 +36,11 @@ func TestParseFromYamlHealthcareGetDICOMStore(t *testing.T) {
{
desc: "basic example",
in: `
tools:
example_tool:
kind: cloud-healthcare-get-dicom-store
source: my-instance
description: some description
kind: tools
name: example_tool
type: cloud-healthcare-get-dicom-store
source: my-instance
description: some description
`,
want: server.ToolConfigs{
"example_tool": getdicomstore.Config{
@@ -56,15 +55,12 @@ func TestParseFromYamlHealthcareGetDICOMStore(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)
}
})

View File

@@ -27,11 +27,11 @@ import (
"google.golang.org/api/healthcare/v1"
)
const kind string = "cloud-healthcare-get-dicom-store-metrics"
const resourceType string = "cloud-healthcare-get-dicom-store-metrics"
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))
}
}
@@ -51,7 +51,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"`
@@ -61,7 +61,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) {
@@ -74,7 +74,7 @@ func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error)
// verify the source is compatible
s, ok := rawS.(compatibleSource)
if !ok {
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", kind, cfg.Source)
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", resourceType, cfg.Source)
}
params := parameters.Parameters{}

View File

@@ -17,7 +17,6 @@ package getdicomstoremetrics_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"
@@ -37,11 +36,11 @@ func TestParseFromYamlHealthcareGetDICOMStoreMetrics(t *testing.T) {
{
desc: "basic example",
in: `
tools:
example_tool:
kind: cloud-healthcare-get-dicom-store-metrics
source: my-instance
description: some description
kind: tools
name: example_tool
type: cloud-healthcare-get-dicom-store-metrics
source: my-instance
description: some description
`,
want: server.ToolConfigs{
"example_tool": getdicomstoremetrics.Config{
@@ -56,15 +55,12 @@ func TestParseFromYamlHealthcareGetDICOMStoreMetrics(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)
}
})

View File

@@ -26,15 +26,15 @@ import (
"github.com/googleapis/genai-toolbox/internal/util/parameters"
)
const kind string = "cloud-healthcare-get-fhir-resource"
const resourceType string = "cloud-healthcare-get-fhir-resource"
const (
typeKey = "resourceType"
idKey = "resourceID"
)
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))
}
}
@@ -54,7 +54,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"`
@@ -64,7 +64,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) {
@@ -77,7 +77,7 @@ func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error)
// verify the source is compatible
s, ok := rawS.(compatibleSource)
if !ok {
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", kind, cfg.Source)
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", resourceType, cfg.Source)
}
typeParameter := parameters.NewStringParameter(typeKey, "The FHIR resource type to retrieve (e.g., Patient, Observation).")

View File

@@ -17,7 +17,6 @@ package getfhirresource_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"
@@ -37,11 +36,11 @@ func TestParseFromYamlHealthcareGetFHIRResource(t *testing.T) {
{
desc: "basic example",
in: `
tools:
example_tool:
kind: cloud-healthcare-get-fhir-resource
source: my-instance
description: some description
kind: tools
name: example_tool
type: cloud-healthcare-get-fhir-resource
source: my-instance
description: some description
`,
want: server.ToolConfigs{
"example_tool": getfhirresource.Config{
@@ -56,15 +55,12 @@ func TestParseFromYamlHealthcareGetFHIRResource(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)
}
})

View File

@@ -27,11 +27,11 @@ import (
"google.golang.org/api/healthcare/v1"
)
const kind string = "cloud-healthcare-get-fhir-store"
const resourceType string = "cloud-healthcare-get-fhir-store"
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))
}
}
@@ -51,7 +51,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"`
@@ -61,7 +61,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) {
@@ -74,7 +74,7 @@ func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error)
// verify the source is compatible
s, ok := rawS.(compatibleSource)
if !ok {
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", kind, cfg.Source)
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", resourceType, cfg.Source)
}
params := parameters.Parameters{}

View File

@@ -17,7 +17,6 @@ package getfhirstore_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"
@@ -37,11 +36,11 @@ func TestParseFromYamlHealthcareGetFHIRStore(t *testing.T) {
{
desc: "basic example",
in: `
tools:
example_tool:
kind: cloud-healthcare-get-fhir-store
source: my-instance
description: some description
kind: tools
name: example_tool
type: cloud-healthcare-get-fhir-store
source: my-instance
description: some description
`,
want: server.ToolConfigs{
"example_tool": getfhirstore.Config{
@@ -56,15 +55,12 @@ func TestParseFromYamlHealthcareGetFHIRStore(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)
}
})

View File

@@ -27,11 +27,11 @@ import (
"google.golang.org/api/healthcare/v1"
)
const kind string = "cloud-healthcare-get-fhir-store-metrics"
const resourceType string = "cloud-healthcare-get-fhir-store-metrics"
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))
}
}
@@ -51,7 +51,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"`
@@ -61,7 +61,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) {
@@ -74,7 +74,7 @@ func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error)
// verify the source is compatible
s, ok := rawS.(compatibleSource)
if !ok {
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", kind, cfg.Source)
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", resourceType, cfg.Source)
}
params := parameters.Parameters{}

View File

@@ -17,7 +17,6 @@ package getfhirstoremetrics_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"
@@ -37,11 +36,11 @@ func TestParseFromYamlHealthcareGetFHIRStoreMetrics(t *testing.T) {
{
desc: "basic example",
in: `
tools:
example_tool:
kind: cloud-healthcare-get-fhir-store-metrics
source: my-instance
description: some description
kind: tools
name: example_tool
type: cloud-healthcare-get-fhir-store-metrics
source: my-instance
description: some description
`,
want: server.ToolConfigs{
"example_tool": getfhirstoremetrics.Config{
@@ -56,15 +55,12 @@ func TestParseFromYamlHealthcareGetFHIRStoreMetrics(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)
}
})

View File

@@ -26,11 +26,11 @@ import (
"google.golang.org/api/healthcare/v1"
)
const kind string = "cloud-healthcare-list-dicom-stores"
const resourceType string = "cloud-healthcare-list-dicom-stores"
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))
}
}
@@ -49,7 +49,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"`
@@ -59,7 +59,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) {

View File

@@ -17,7 +17,6 @@ package listdicomstores_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"
@@ -37,11 +36,11 @@ func TestParseFromYamlHealthcareListDICOMStores(t *testing.T) {
{
desc: "basic example",
in: `
tools:
example_tool:
kind: cloud-healthcare-list-dicom-stores
source: my-instance
description: some description
kind: tools
name: example_tool
type: cloud-healthcare-list-dicom-stores
source: my-instance
description: some description
`,
want: server.ToolConfigs{
"example_tool": listdicomstores.Config{
@@ -56,15 +55,12 @@ func TestParseFromYamlHealthcareListDICOMStores(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)
}
})

View File

@@ -26,11 +26,11 @@ import (
"google.golang.org/api/healthcare/v1"
)
const kind string = "cloud-healthcare-list-fhir-stores"
const resourceType string = "cloud-healthcare-list-fhir-stores"
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))
}
}
@@ -49,7 +49,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"`
@@ -59,7 +59,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) {

View File

@@ -17,7 +17,6 @@ package listfhirstores_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"
@@ -37,11 +36,11 @@ func TestParseFromYamlHealthcareListFHIRStores(t *testing.T) {
{
desc: "basic example",
in: `
tools:
example_tool:
kind: cloud-healthcare-list-fhir-stores
source: my-instance
description: some description
kind: tools
name: example_tool
type: cloud-healthcare-list-fhir-stores
source: my-instance
description: some description
`,
want: server.ToolConfigs{
"example_tool": listfhirstores.Config{
@@ -56,15 +55,12 @@ func TestParseFromYamlHealthcareListFHIRStores(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)
}
})

View File

@@ -26,7 +26,7 @@ import (
"github.com/googleapis/genai-toolbox/internal/util/parameters"
)
const kind string = "cloud-healthcare-retrieve-rendered-dicom-instance"
const resourceType string = "cloud-healthcare-retrieve-rendered-dicom-instance"
const (
studyInstanceUIDKey = "StudyInstanceUID"
seriesInstanceUIDKey = "SeriesInstanceUID"
@@ -35,8 +35,8 @@ const (
)
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))
}
}
@@ -56,7 +56,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"`
@@ -66,7 +66,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) {
@@ -79,7 +79,7 @@ func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error)
// verify the source is compatible
s, ok := rawS.(compatibleSource)
if !ok {
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", kind, cfg.Source)
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", resourceType, cfg.Source)
}
params := parameters.Parameters{

View File

@@ -17,7 +17,6 @@ package retrieverendereddicominstance_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"
@@ -37,11 +36,11 @@ func TestParseFromYamlHealthcareRetrieveRenderedDICOMInstance(t *testing.T) {
{
desc: "basic example",
in: `
tools:
example_tool:
kind: cloud-healthcare-retrieve-rendered-dicom-instance
source: my-instance
description: some description
kind: tools
name: example_tool
type: cloud-healthcare-retrieve-rendered-dicom-instance
source: my-instance
description: some description
`,
want: server.ToolConfigs{
"example_tool": retrieverendereddicominstance.Config{
@@ -56,15 +55,12 @@ func TestParseFromYamlHealthcareRetrieveRenderedDICOMInstance(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)
}
})

View File

@@ -28,7 +28,7 @@ import (
"google.golang.org/api/googleapi"
)
const kind string = "cloud-healthcare-search-dicom-instances"
const resourceType string = "cloud-healthcare-search-dicom-instances"
const (
studyInstanceUIDKey = "StudyInstanceUID"
patientNameKey = "PatientName"
@@ -42,8 +42,8 @@ const (
)
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))
}
}
@@ -63,7 +63,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"`
@@ -73,7 +73,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) {
@@ -86,7 +86,7 @@ func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error)
// verify the source is compatible
s, ok := rawS.(compatibleSource)
if !ok {
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", kind, cfg.Source)
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", resourceType, cfg.Source)
}
params := parameters.Parameters{

View File

@@ -17,7 +17,6 @@ package searchdicominstances_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"
@@ -37,11 +36,11 @@ func TestParseFromYamlHealthcareSearchDICOMInstances(t *testing.T) {
{
desc: "basic example",
in: `
tools:
example_tool:
kind: cloud-healthcare-search-dicom-instances
source: my-instance
description: some description
kind: tools
name: example_tool
type: cloud-healthcare-search-dicom-instances
source: my-instance
description: some description
`,
want: server.ToolConfigs{
"example_tool": searchdicominstances.Config{
@@ -56,15 +55,12 @@ func TestParseFromYamlHealthcareSearchDICOMInstances(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)
}
})

View File

@@ -27,7 +27,7 @@ import (
"google.golang.org/api/googleapi"
)
const kind string = "cloud-healthcare-search-dicom-series"
const resourceType string = "cloud-healthcare-search-dicom-series"
const (
studyInstanceUIDKey = "StudyInstanceUID"
patientNameKey = "PatientName"
@@ -40,8 +40,8 @@ const (
)
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))
}
}
@@ -61,7 +61,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"`
@@ -71,7 +71,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) {
@@ -84,7 +84,7 @@ func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error)
// verify the source is compatible
s, ok := rawS.(compatibleSource)
if !ok {
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", kind, cfg.Source)
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", resourceType, cfg.Source)
}
params := parameters.Parameters{

View File

@@ -17,7 +17,6 @@ package searchdicomseries_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"
@@ -37,11 +36,11 @@ func TestParseFromYamlHealthcareSearchDICOMSeries(t *testing.T) {
{
desc: "basic example",
in: `
tools:
example_tool:
kind: cloud-healthcare-search-dicom-series
source: my-instance
description: some description
kind: tools
name: example_tool
type: cloud-healthcare-search-dicom-series
source: my-instance
description: some description
`,
want: server.ToolConfigs{
"example_tool": searchdicomseries.Config{
@@ -56,15 +55,12 @@ func TestParseFromYamlHealthcareSearchDICOMSeries(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)
}
})

View File

@@ -27,7 +27,7 @@ import (
"google.golang.org/api/googleapi"
)
const kind string = "cloud-healthcare-search-dicom-studies"
const resourceType string = "cloud-healthcare-search-dicom-studies"
const (
studyInstanceUIDKey = "StudyInstanceUID"
patientNameKey = "PatientName"
@@ -38,8 +38,8 @@ const (
)
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))
}
}
@@ -59,7 +59,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"`
@@ -69,7 +69,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) {
@@ -82,7 +82,7 @@ func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error)
// verify the source is compatible
s, ok := rawS.(compatibleSource)
if !ok {
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", kind, cfg.Source)
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", resourceType, cfg.Source)
}
params := parameters.Parameters{

View File

@@ -17,7 +17,6 @@ package searchdicomstudies_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"
@@ -37,11 +36,11 @@ func TestParseFromYamlHealthcareSearchDICOMStudies(t *testing.T) {
{
desc: "basic example",
in: `
tools:
example_tool:
kind: cloud-healthcare-search-dicom-studies
source: my-instance
description: some description
kind: tools
name: example_tool
type: cloud-healthcare-search-dicom-studies
source: my-instance
description: some description
`,
want: server.ToolConfigs{
"example_tool": searchdicomstudies.Config{
@@ -56,15 +55,12 @@ func TestParseFromYamlHealthcareSearchDICOMStudies(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)
}
})

View File

@@ -26,11 +26,11 @@ import (
"github.com/googleapis/genai-toolbox/internal/util/parameters"
)
const kind string = "cloud-monitoring-query-prometheus"
const resourceType string = "cloud-monitoring-query-prometheus"
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))
}
}
@@ -49,7 +49,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"`
@@ -59,7 +59,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) {

View File

@@ -18,7 +18,6 @@ import (
"strings"
"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/sources"
@@ -29,7 +28,7 @@ import (
"github.com/googleapis/genai-toolbox/internal/util/parameters"
)
// mockIncompatibleSource is a source of a different kind to test error paths.
// mockIncompatibleSource is a source of a different type to test error paths.
type mockIncompatibleSource struct{ sources.Source }
func TestInitialize(t *testing.T) {
@@ -122,12 +121,12 @@ func TestParseFromYamlCloudMonitoring(t *testing.T) {
{
desc: "basic example",
in: `
tools:
example_tool:
kind: cloud-monitoring-query-prometheus
source: my-instance
description: some description
`,
kind: tools
name: example_tool
type: cloud-monitoring-query-prometheus
source: my-instance
description: some description
`,
want: server.ToolConfigs{
"example_tool": cloudmonitoring.Config{
Name: "example_tool",
@@ -141,14 +140,14 @@ func TestParseFromYamlCloudMonitoring(t *testing.T) {
{
desc: "advanced example",
in: `
tools:
example_tool:
kind: cloud-monitoring-query-prometheus
source: my-instance
description: some description
authRequired:
- my-google-auth-service
- other-auth-service
kind: tools
name: example_tool
type: cloud-monitoring-query-prometheus
source: my-instance
description: some description
authRequired:
- my-google-auth-service
- other-auth-service
`,
want: server.ToolConfigs{
"example_tool": cloudmonitoring.Config{
@@ -163,15 +162,11 @@ func TestParseFromYamlCloudMonitoring(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, cmp.AllowUnexported(cloudmonitoring.Config{})); diff != "" {
if diff := cmp.Diff(tc.want, got, cmp.AllowUnexported(cloudmonitoring.Config{})); diff != "" {
t.Fatalf("incorrect parse: diff %v", diff)
}
})
@@ -189,44 +184,40 @@ func TestFailParseFromYamlCloudMonitoring(t *testing.T) {
err string
}{
{
desc: "Invalid kind",
desc: "Invalid type",
in: `
tools:
example_tool:
kind: invalid-kind
source: my-instance
description: some description
kind: tools
name: example_tool
type: invalid-type
source: my-instance
description: some description
`,
err: `unknown tool type: "invalid-kind"`,
err: `unknown tool type: "invalid-type"`,
},
{
desc: "missing source",
in: `
tools:
example_tool:
kind: cloud-monitoring-query-prometheus
description: some description
kind: tools
name: example_tool
type: cloud-monitoring-query-prometheus
description: some description
`,
err: `Key: 'Config.Source' Error:Field validation for 'Source' failed on the 'required' tag`,
},
{
desc: "missing description",
in: `
tools:
example_tool:
kind: cloud-monitoring-query-prometheus
source: my-instance
kind: tools
name: example_tool
type: cloud-monitoring-query-prometheus
source: my-instance
`,
err: `Key: 'Config.Description' Error:Field validation for 'Description' failed on the 'required' tag`,
},
}
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)
_, _, _, _, _, _, err := server.UnmarshalResourceConfig(ctx, testutils.FormatYaml(tc.in))
if err == nil {
t.Fatalf("expect parsing to fail")
}

View File

@@ -26,11 +26,11 @@ import (
sqladmin "google.golang.org/api/sqladmin/v1"
)
const kind string = "cloud-sql-clone-instance"
const resourceType string = "cloud-sql-clone-instance"
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))
}
}
@@ -52,7 +52,7 @@ type compatibleSource interface {
// Config defines the configuration for the clone-instance tool.
type Config struct {
Name string `yaml:"name" validate:"required"`
Type string `yaml:"kind" validate:"required"`
Type string `yaml:"type" validate:"required"`
Description string `yaml:"description"`
Source string `yaml:"source" validate:"required"`
AuthRequired []string `yaml:"authRequired"`
@@ -61,9 +61,9 @@ type Config struct {
// validate interface
var _ tools.ToolConfig = Config{}
// ToolConfigType returns the kind of the tool.
// ToolConfigType returns the type of the tool.
func (cfg Config) ToolConfigType() string {
return kind
return resourceType
}
// Initialize initializes the tool from the configuration.
@@ -74,7 +74,7 @@ func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error)
}
s, ok := rawS.(compatibleSource)
if !ok {
return nil, fmt.Errorf("invalid source for %q tool: source kind must be `cloud-sql-admin`", kind)
return nil, fmt.Errorf("invalid source for %q tool: source type must be `cloud-sql-admin`", resourceType)
}
project := s.GetDefaultProject()

View File

@@ -18,7 +18,6 @@ import (
//"context"
"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,11 +37,11 @@ func TestParseFromYaml(t *testing.T) {
{
desc: "basic example",
in: `
tools:
clone-instance-tool:
kind: cloud-sql-clone-instance
description: a test description
source: a-source
kind: tools
name: clone-instance-tool
type: cloud-sql-clone-instance
description: a test description
source: a-source
`,
want: server.ToolConfigs{
"clone-instance-tool": cloudsqlcloneinstance.Config{
@@ -57,15 +56,11 @@ func TestParseFromYaml(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)
}
})

View File

@@ -26,7 +26,7 @@ import (
"google.golang.org/api/sqladmin/v1"
)
const kind string = "cloud-sql-create-backup"
const resourceType string = "cloud-sql-create-backup"
var _ tools.ToolConfig = Config{}
@@ -40,15 +40,15 @@ type compatibleSource interface {
// Config defines the configuration for the create-backup tool.
type Config struct {
Name string `yaml:"name" validate:"required"`
Type string `yaml:"kind" validate:"required"`
Type string `yaml:"type" validate:"required"`
Description string `yaml:"description"`
Source string `yaml:"source" validate:"required"`
AuthRequired []string `yaml:"authRequired"`
}
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))
}
}
@@ -60,9 +60,9 @@ func newConfig(ctx context.Context, name string, decoder *yaml.Decoder) (tools.T
return actual, nil
}
// ToolConfigType returns the kind of the tool.
// ToolConfigType returns the type of the tool.
func (cfg Config) ToolConfigType() string {
return kind
return resourceType
}
// Initialize initializes the tool from the configuration.
@@ -73,7 +73,7 @@ func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error)
}
s, ok := rawS.(compatibleSource)
if !ok {
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", kind, cfg.Source)
return nil, fmt.Errorf("invalid source for %q tool: source %q not compatible", resourceType, cfg.Source)
}
project := s.GetDefaultProject()

View File

@@ -17,7 +17,6 @@ package cloudsqlcreatebackup_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"
@@ -37,11 +36,11 @@ func TestParseFromYaml(t *testing.T) {
{
desc: "basic example",
in: `
tools:
create-backup-tool:
kind: cloud-sql-create-backup
description: a test description
source: a-source
kind: tools
name: create-backup-tool
type: cloud-sql-create-backup
description: a test description
source: a-source
`,
want: server.ToolConfigs{
"create-backup-tool": cloudsqlcreatebackup.Config{
@@ -56,15 +55,11 @@ func TestParseFromYaml(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)
}
})

View File

@@ -25,11 +25,11 @@ import (
"github.com/googleapis/genai-toolbox/internal/util/parameters"
)
const kind string = "cloud-sql-create-database"
const resourceType string = "cloud-sql-create-database"
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 {
// Config defines the configuration for the create-database tool.
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"`
AuthRequired []string `yaml:"authRequired"`
@@ -59,9 +59,9 @@ type Config struct {
// validate interface
var _ tools.ToolConfig = Config{}
// ToolConfigType returns the kind of the tool.
// ToolConfigType returns the type of the tool.
func (cfg Config) ToolConfigType() string {
return kind
return resourceType
}
// Initialize initializes the tool from the configuration.
@@ -72,7 +72,7 @@ func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error)
}
s, ok := rawS.(compatibleSource)
if !ok {
return nil, fmt.Errorf("invalid source for %q tool: source kind must be `cloud-sql-admin`", kind)
return nil, fmt.Errorf("invalid source for %q tool: source type must be `cloud-sql-admin`", resourceType)
}
project := s.GetDefaultProject()

View File

@@ -17,7 +17,6 @@ package cloudsqlcreatedatabase_test
import (
"testing"
"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"
@@ -37,11 +36,11 @@ func TestParseFromYaml(t *testing.T) {
{
desc: "basic example",
in: `
tools:
create-database:
kind: cloud-sql-create-database
source: my-source
description: some description
kind: tools
name: create-database
type: cloud-sql-create-database
source: my-source
description: some description
`,
want: server.ToolConfigs{
"create-database": cloudsqlcreatedatabase.Config{
@@ -56,15 +55,11 @@ func TestParseFromYaml(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)
}
})

View File

@@ -25,11 +25,11 @@ import (
"github.com/googleapis/genai-toolbox/internal/util/parameters"
)
const kind string = "cloud-sql-create-users"
const resourceType string = "cloud-sql-create-users"
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 {
// Config defines the configuration for the create-user tool.
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"`
AuthRequired []string `yaml:"authRequired"`
@@ -59,9 +59,9 @@ type Config struct {
// validate interface
var _ tools.ToolConfig = Config{}
// ToolConfigType returns the kind of the tool.
// ToolConfigType returns the type of the tool.
func (cfg Config) ToolConfigType() string {
return kind
return resourceType
}
// Initialize initializes the tool from the configuration.
@@ -72,7 +72,7 @@ func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error)
}
s, ok := rawS.(compatibleSource)
if !ok {
return nil, fmt.Errorf("invalid source for %q tool: source kind must be `cloud-sql-admin`", kind)
return nil, fmt.Errorf("invalid source for %q tool: source type must be `cloud-sql-admin`", resourceType)
}
project := s.GetDefaultProject()

View File

@@ -17,7 +17,6 @@ package cloudsqlcreateusers_test
import (
"testing"
"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"
@@ -37,11 +36,11 @@ func TestParseFromYaml(t *testing.T) {
{
desc: "basic example",
in: `
tools:
create-user:
kind: cloud-sql-create-users
source: my-source
description: some description
kind: tools
name: create-user
type: cloud-sql-create-users
source: my-source
description: some description
`,
want: server.ToolConfigs{
"create-user": cloudsqlcreateusers.Config{
@@ -56,15 +55,11 @@ func TestParseFromYaml(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)
}
})

View File

@@ -25,11 +25,11 @@ import (
"github.com/googleapis/genai-toolbox/internal/util/parameters"
)
const kind string = "cloud-sql-get-instance"
const resourceType string = "cloud-sql-get-instance"
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 {
// Config defines the configuration for the get-instances tool.
type Config struct {
Name string `yaml:"name" validate:"required"`
Type string `yaml:"kind" validate:"required"`
Type string `yaml:"type" validate:"required"`
Description string `yaml:"description"`
Source string `yaml:"source" validate:"required"`
AuthRequired []string `yaml:"authRequired"`
@@ -59,9 +59,9 @@ type Config struct {
// validate interface
var _ tools.ToolConfig = Config{}
// ToolConfigType returns the kind of the tool.
// ToolConfigType returns the type of the tool.
func (cfg Config) ToolConfigType() string {
return kind
return resourceType
}
// Initialize initializes the tool from the configuration.
@@ -73,7 +73,7 @@ func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error)
s, ok := rawS.(compatibleSource)
if !ok {
return nil, fmt.Errorf("invalid source for %q tool: source kind must be `cloud-sql-admin`", kind)
return nil, fmt.Errorf("invalid source for %q tool: source type must be `cloud-sql-admin`", resourceType)
}
project := s.GetDefaultProject()

View File

@@ -17,7 +17,6 @@ package cloudsqlgetinstances_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"
@@ -37,11 +36,11 @@ func TestParseFromYaml(t *testing.T) {
{
desc: "basic example",
in: `
tools:
get-instances:
kind: cloud-sql-get-instance
description: "A tool to get cloud sql instances"
source: "my-gcp-source"
kind: tools
name: get-instances
type: cloud-sql-get-instance
description: "A tool to get cloud sql instances"
source: "my-gcp-source"
`,
want: server.ToolConfigs{
"get-instances": cloudsqlgetinstances.Config{
@@ -56,15 +55,11 @@ func TestParseFromYaml(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)
}
})

View File

@@ -25,11 +25,11 @@ import (
"github.com/googleapis/genai-toolbox/internal/util/parameters"
)
const kind string = "cloud-sql-list-databases"
const resourceType string = "cloud-sql-list-databases"
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 {
// Config defines the configuration for the list-databases tool.
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"`
AuthRequired []string `yaml:"authRequired"`
@@ -59,9 +59,9 @@ type Config struct {
// validate interface
var _ tools.ToolConfig = Config{}
// ToolConfigType returns the kind of the tool.
// ToolConfigType returns the type of the tool.
func (cfg Config) ToolConfigType() string {
return kind
return resourceType
}
// Initialize initializes the tool from the configuration.
@@ -72,7 +72,7 @@ func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error)
}
s, ok := rawS.(compatibleSource)
if !ok {
return nil, fmt.Errorf("invalid source for %q tool: source kind must be `cloud-sql-admin`", kind)
return nil, fmt.Errorf("invalid source for %q tool: source type must be `cloud-sql-admin`", resourceType)
}
project := s.GetDefaultProject()

View File

@@ -17,7 +17,6 @@ package cloudsqllistdatabases_test
import (
"testing"
"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"
@@ -37,11 +36,11 @@ func TestParseFromYaml(t *testing.T) {
{
desc: "basic example",
in: `
tools:
list-my-databases:
kind: cloud-sql-list-databases
description: some description
source: some-source
kind: tools
name: list-my-databases
type: cloud-sql-list-databases
description: some description
source: some-source
`,
want: server.ToolConfigs{
"list-my-databases": cloudsqllistdatabases.Config{
@@ -56,15 +55,11 @@ func TestParseFromYaml(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)
}
})

Some files were not shown because too many files have changed in this diff Show More