From 474e480b2c7edef2bce59dfae0300ade5495a156 Mon Sep 17 00:00:00 2001 From: Yuan Teoh <45984206+Yuan325@users.noreply.github.com> Date: Mon, 26 Jan 2026 17:53:37 -0800 Subject: [PATCH] chore: update yaml tag for tools (#2356) Update yaml tag in tools from `kind` to `type`. Upcoming PRs: * Update config in `/tests` and `/docs` Will resolve other unit tests failure in the final PR to keep things simpler. --- .../alloydbcreatecluster.go | 14 +- .../alloydbcreatecluster_test.go | 34 +- .../alloydbcreateinstance.go | 14 +- .../alloydbcreateinstance_test.go | 34 +- .../alloydbcreateuser/alloydbcreateuser.go | 14 +- .../alloydbcreateuser_test.go | 34 +- .../alloydbgetcluster/alloydbgetcluster.go | 14 +- .../alloydbgetcluster_test.go | 38 +- .../alloydbgetinstance/alloydbgetinstance.go | 14 +- .../alloydbgetinstance_test.go | 38 +- .../alloydb/alloydbgetuser/alloydbgetuser.go | 14 +- .../alloydbgetuser/alloydbgetuser_test.go | 38 +- .../alloydblistclusters.go | 14 +- .../alloydblistclusters_test.go | 38 +- .../alloydblistinstances.go | 14 +- .../alloydblistinstances_test.go | 38 +- .../alloydblistusers/alloydblistusers.go | 14 +- .../alloydblistusers/alloydblistusers_test.go | 38 +- .../alloydbwaitforoperation.go | 14 +- .../alloydbwaitforoperation_test.go | 28 +- internal/tools/alloydbainl/alloydbainl.go | 10 +- .../tools/alloydbainl/alloydbainl_test.go | 86 ++- .../bigqueryanalyzecontribution.go | 12 +- .../bigqueryanalyzecontribution_test.go | 20 +- .../bigqueryconversationalanalytics.go | 12 +- .../bigqueryconversationalanalytics_test.go | 20 +- .../bigqueryexecutesql/bigqueryexecutesql.go | 14 +- .../bigqueryexecutesql_test.go | 20 +- .../bigqueryforecast/bigqueryforecast.go | 14 +- .../bigqueryforecast/bigqueryforecast_test.go | 20 +- .../bigquerygetdatasetinfo.go | 12 +- .../bigquerygetdatasetinfo_test.go | 20 +- .../bigquerygettableinfo.go | 12 +- .../bigquerygettableinfo_test.go | 20 +- .../bigquerylistdatasetids.go | 12 +- .../bigquerylistdatasetids_test.go | 20 +- .../bigquerylisttableids.go | 12 +- .../bigquerylisttableids_test.go | 20 +- .../bigquerysearchcatalog.go | 10 +- .../bigquerysearchcatalog_test.go | 20 +- .../tools/bigquery/bigquerysql/bigquerysql.go | 10 +- .../bigquery/bigquerysql/bigquerysql_test.go | 87 ++- internal/tools/bigtable/bigtable.go | 10 +- internal/tools/bigtable/bigtable_test.go | 83 ++- .../cassandra/cassandracql/cassandracql.go | 10 +- .../cassandracql/cassandracql_test.go | 126 +++-- .../clickhouseexecutesql.go | 2 +- .../clickhouseexecutesql_test.go | 21 +- .../clickhouselistdatabases.go | 2 +- .../clickhouselistdatabases_test.go | 21 +- .../clickhouselisttables.go | 2 +- .../clickhouselisttables_test.go | 21 +- .../clickhouse/clickhousesql/clickhousesql.go | 2 +- .../clickhousesql/clickhousesql_test.go | 40 +- internal/tools/cloudgda/cloudgda.go | 10 +- internal/tools/cloudgda/cloudgda_test.go | 59 +-- .../cloudhealthcarefhirfetchpage.go | 10 +- .../cloudhealthcarefhirfetchpage_test.go | 18 +- .../cloudhealthcarefhirpatienteverything.go | 12 +- ...oudhealthcarefhirpatienteverything_test.go | 18 +- .../cloudhealthcarefhirpatientsearch.go | 12 +- .../cloudhealthcarefhirpatientsearch_test.go | 18 +- .../cloudhealthcaregetdataset.go | 10 +- .../cloudhealthcaregetdataset_test.go | 18 +- .../cloudhealthcaregetdicomstore.go | 12 +- .../cloudhealthcaregetdicomstore_test.go | 18 +- .../cloudhealthcaregetdicomstoremetrics.go | 12 +- ...loudhealthcaregetdicomstoremetrics_test.go | 18 +- .../cloudhealthcaregetfhirresource.go | 12 +- .../cloudhealthcaregetfhirresource_test.go | 18 +- .../cloudhealthcaregetfhirstore.go | 12 +- .../cloudhealthcaregetfhirstore_test.go | 18 +- .../cloudhealthcaregetfhirstoremetrics.go | 12 +- ...cloudhealthcaregetfhirstoremetrics_test.go | 18 +- .../cloudhealthcarelistdicomstores.go | 10 +- .../cloudhealthcarelistdicomstores_test.go | 18 +- .../cloudhealthcarelistfhirstores.go | 10 +- .../cloudhealthcarelistfhirstores_test.go | 18 +- ...healthcareretrieverendereddicominstance.go | 12 +- ...hcareretrieverendereddicominstance_test.go | 18 +- .../cloudhealthcaresearchdicominstances.go | 12 +- ...loudhealthcaresearchdicominstances_test.go | 18 +- .../cloudhealthcaresearchdicomseries.go | 12 +- .../cloudhealthcaresearchdicomseries_test.go | 18 +- .../cloudhealthcaresearchdicomstudies.go | 12 +- .../cloudhealthcaresearchdicomstudies_test.go | 18 +- .../tools/cloudmonitoring/cloudmonitoring.go | 10 +- .../cloudmonitoring/cloudmonitoring_test.go | 75 ++- .../cloudsqlcloneinstance.go | 14 +- .../cloudsqlcloneinstance_test.go | 19 +- .../cloudsqlcreatebackup.go | 14 +- .../cloudsqlcreatebackup_test.go | 19 +- .../cloudsqlcreatedatabase.go | 14 +- .../cloudsqlcreatedatabase_test.go | 19 +- .../cloudsqlcreateusers.go | 14 +- .../cloudsqlcreateusers_test.go | 19 +- .../cloudsqlgetinstances.go | 14 +- .../cloudsqlgetinstances_test.go | 19 +- .../cloudsqllistdatabases.go | 14 +- .../cloudsqllistdatabases_test.go | 19 +- .../cloudsqllistinstances.go | 14 +- .../cloudsqllistinstances_test.go | 19 +- .../cloudsqlwaitforoperation.go | 14 +- .../cloudsqlwaitforoperation_test.go | 27 +- .../cloudsqlmssqlcreateinstance.go | 14 +- .../cloudsqlmssqlcreateinstance_test.go | 19 +- .../cloudsqlmysqlcreateinstance.go | 14 +- .../cloudsqlmysqlcreateinstance_test.go | 19 +- .../cloudsqlpgcreateinstances.go | 14 +- .../cloudsqlpgcreateinstances_test.go | 19 +- .../cloudsqlpgupgradeprecheck.go | 12 +- .../cloudsqlpgupgradeprecheck_test.go | 33 +- internal/tools/couchbase/couchbase.go | 10 +- internal/tools/couchbase/couchbase_test.go | 104 ++-- .../dataformcompilelocal.go | 10 +- .../dataformcompilelocal_test.go | 17 +- .../dataplexlookupentry.go | 10 +- .../dataplexlookupentry_test.go | 69 ++- .../dataplexsearchaspecttypes.go | 10 +- .../dataplexsearchaspecttypes_test.go | 21 +- .../dataplexsearchentries.go | 10 +- .../dataplexsearchentries_test.go | 21 +- internal/tools/dgraph/dgraph.go | 10 +- internal/tools/dgraph/dgraph_test.go | 41 +- .../elasticsearchesql/elasticsearchesql.go | 10 +- .../elasticsearchesql_test.go | 48 +- .../firebirdexecutesql/firebirdexecutesql.go | 12 +- .../firebirdexecutesql_test.go | 24 +- .../tools/firebird/firebirdsql/firebirdsql.go | 10 +- .../firebird/firebirdsql/firebirdsql_test.go | 97 ++-- .../firestoreadddocuments.go | 10 +- .../firestoreadddocuments_test.go | 84 ++- .../firestoredeletedocuments.go | 10 +- .../firestoredeletedocuments_test.go | 83 ++- .../firestoregetdocuments.go | 10 +- .../firestoregetdocuments_test.go | 83 ++- .../firestoregetrules/firestoregetrules.go | 10 +- .../firestoregetrules_test.go | 83 ++- .../firestorelistcollections.go | 10 +- .../firestorelistcollections_test.go | 83 ++- .../firestorequery/firestorequery.go | 12 +- .../firestorequery/firestorequery_test.go | 498 +++++++++--------- .../firestorequerycollection.go | 12 +- .../firestorequerycollection_test.go | 82 ++- .../firestoreupdatedocument.go | 10 +- .../firestoreupdatedocument_test.go | 69 +-- .../firestorevalidaterules.go | 10 +- .../firestorevalidaterules_test.go | 83 ++- internal/tools/http/http.go | 12 +- internal/tools/http/http_test.go | 193 ++++--- .../lookeradddashboardelement.go | 10 +- .../lookeradddashboardelement_test.go | 37 +- .../lookeradddashboardfilter.go | 10 +- .../lookeradddashboardfilter_test.go | 37 +- .../lookerconversationalanalytics.go | 14 +- .../lookerconversationalanalytics_test.go | 19 +- .../lookercreateprojectfile.go | 10 +- .../lookercreateprojectfile_test.go | 37 +- .../lookerdeleteprojectfile.go | 10 +- .../lookerdeleteprojectfile_test.go | 37 +- .../looker/lookerdevmode/lookerdevmode.go | 10 +- .../lookerdevmode/lookerdevmode_test.go | 37 +- .../lookergenerateembedurl.go | 10 +- .../lookergenerateembedurl_test.go | 37 +- .../lookergetconnectiondatabases.go | 10 +- .../lookergetconnectiondatabases_test.go | 37 +- .../lookergetconnections.go | 10 +- .../lookergetconnections_test.go | 37 +- .../lookergetconnectionschemas.go | 10 +- .../lookergetconnectionschemas_test.go | 37 +- .../lookergetconnectiontablecolumns.go | 10 +- .../lookergetconnectiontablecolumns_test.go | 37 +- .../lookergetconnectiontables.go | 10 +- .../lookergetconnectiontables_test.go | 37 +- .../lookergetdashboards.go | 10 +- .../lookergetdashboards_test.go | 37 +- .../lookergetdimensions.go | 10 +- .../lookergetdimensions_test.go | 37 +- .../lookergetexplores/lookergetexplores.go | 10 +- .../lookergetexplores_test.go | 37 +- .../lookergetfilters/lookergetfilters.go | 10 +- .../lookergetfilters/lookergetfilters_test.go | 37 +- .../looker/lookergetlooks/lookergetlooks.go | 10 +- .../lookergetlooks/lookergetlooks_test.go | 37 +- .../lookergetmeasures/lookergetmeasures.go | 10 +- .../lookergetmeasures_test.go | 37 +- .../looker/lookergetmodels/lookergetmodels.go | 10 +- .../lookergetmodels/lookergetmodels_test.go | 37 +- .../lookergetparameters.go | 10 +- .../lookergetparameters_test.go | 37 +- .../lookergetprojectfile.go | 10 +- .../lookergetprojectfile_test.go | 38 +- .../lookergetprojectfiles.go | 10 +- .../lookergetprojectfiles_test.go | 37 +- .../lookergetprojects/lookergetprojects.go | 10 +- .../lookergetprojects_test.go | 39 +- .../lookerhealthanalyze.go | 10 +- .../lookerhealthanalyze_test.go | 37 +- .../lookerhealthpulse/lookerhealthpulse.go | 10 +- .../lookerhealthpulse_test.go | 37 +- .../lookerhealthvacuum/lookerhealthvacuum.go | 10 +- .../lookerhealthvacuum_test.go | 37 +- .../lookermakedashboard.go | 10 +- .../lookermakedashboard_test.go | 41 +- .../looker/lookermakelook/lookermakelook.go | 10 +- .../lookermakelook/lookermakelook_test.go | 39 +- .../tools/looker/lookerquery/lookerquery.go | 10 +- .../looker/lookerquery/lookerquery_test.go | 39 +- .../looker/lookerquerysql/lookerquerysql.go | 10 +- .../lookerquerysql/lookerquerysql_test.go | 37 +- .../looker/lookerqueryurl/lookerqueryurl.go | 10 +- .../lookerqueryurl/lookerqueryurl_test.go | 37 +- .../lookerrundashboard/lookerrundashboard.go | 10 +- .../lookerrundashboard_test.go | 37 +- .../looker/lookerrunlook/lookerrunlook.go | 10 +- .../lookerrunlook/lookerrunlook_test.go | 37 +- .../lookerupdateprojectfile.go | 10 +- .../lookerupdateprojectfile_test.go | 37 +- .../mindsdbexecutesql/mindsdbexecutesql.go | 10 +- .../mindsdbexecutesql_test.go | 24 +- .../tools/mindsdb/mindsdbsql/mindsdbsql.go | 10 +- .../mindsdb/mindsdbsql/mindsdbsql_test.go | 113 ++-- .../mongodbaggregate/mongodbaggregate.go | 10 +- .../mongodbaggregate/mongodbaggregate_test.go | 60 +-- .../mongodbdeletemany/mongodbdeletemany.go | 10 +- .../mongodbdeletemany_test.go | 59 +-- .../mongodbdeleteone/mongodbdeleteone.go | 10 +- .../mongodbdeleteone/mongodbdeleteone_test.go | 59 +-- .../tools/mongodb/mongodbfind/mongodbfind.go | 10 +- .../mongodb/mongodbfind/mongodbfind_test.go | 71 ++- .../mongodb/mongodbfindone/mongodbfindone.go | 10 +- .../mongodbfindone/mongodbfindone_test.go | 65 +-- .../mongodbinsertmany/mongodbinsertmany.go | 10 +- .../mongodbinsertmany_test.go | 75 ++- .../mongodbinsertone/mongodbinsertone.go | 10 +- .../mongodbinsertone/mongodbinsertone_test.go | 77 ++- .../mongodbupdatemany/mongodbupdatemany.go | 10 +- .../mongodbupdatemany_test.go | 173 +++--- .../mongodbupdateone/mongodbupdateone.go | 10 +- .../mongodbupdateone/mongodbupdateone_test.go | 157 +++--- .../mssql/mssqlexecutesql/mssqlexecutesql.go | 12 +- .../mssqlexecutesql/mssqlexecutesql_test.go | 24 +- .../mssql/mssqllisttables/mssqllisttables.go | 10 +- .../mssqllisttables/mssqllisttables_test.go | 24 +- internal/tools/mssql/mssqlsql/mssqlsql.go | 10 +- .../tools/mssql/mssqlsql/mssqlsql_test.go | 113 ++-- .../mysql/mysqlexecutesql/mysqlexecutesql.go | 12 +- .../mysqlexecutesql/mysqlexecutesql_test.go | 24 +- .../mysqlgetqueryplan/mysqlgetqueryplan.go | 12 +- .../mysqlgetqueryplan_test.go | 24 +- .../mysqllistactivequeries.go | 16 +- .../mysqllistactivequeries_test.go | 24 +- .../mysqllisttablefragmentation.go | 12 +- .../mysqllisttablefragmentation_test.go | 24 +- .../mysql/mysqllisttables/mysqllisttables.go | 10 +- .../mysqllisttables/mysqllisttables_test.go | 24 +- .../mysqllisttablesmissinguniqueindexes.go | 12 +- ...ysqllisttablesmissinguniqueindexes_test.go | 24 +- internal/tools/mysql/mysqlsql/mysqlsql.go | 10 +- .../tools/mysql/mysqlsql/mysqlsql_test.go | 113 ++-- .../tools/neo4j/neo4jcypher/neo4jcypher.go | 10 +- .../neo4j/neo4jcypher/neo4jcypher_test.go | 36 +- .../neo4jexecutecypher/neo4jexecutecypher.go | 10 +- .../neo4jexecutecypher_test.go | 42 +- .../tools/neo4j/neo4jschema/neo4jschema.go | 14 +- .../neo4j/neo4jschema/neo4jschema_test.go | 36 +- .../oceanbaseexecutesql.go | 10 +- .../oceanbaseexecutesql_test.go | 24 +- .../oceanbase/oceanbasesql/oceanbasesql.go | 10 +- .../oceanbasesql/oceanbasesql_test.go | 28 +- .../oracleexecutesql/oracleexecutesql.go | 12 +- .../oracleexecutesql/oracleexecutesql_test.go | 34 +- internal/tools/oracle/oraclesql/oraclesql.go | 10 +- .../tools/oracle/oraclesql/oraclesql_test.go | 38 +- .../postgresdatabaseoverview.go | 10 +- .../postgresdatabaseoverview_test.go | 34 +- .../postgresexecutesql/postgresexecutesql.go | 12 +- .../postgresexecutesql_test.go | 24 +- .../postgresgetcolumncardinality.go | 10 +- .../postgresgetcolumncardinality_test.go | 34 +- .../postgreslistactivequeries.go | 10 +- .../postgreslistactivequeries_test.go | 35 +- .../postgreslistavailableextensions.go | 10 +- .../postgreslistavailableextensions_test.go | 35 +- .../postgreslistdatabasestats.go | 10 +- .../postgreslistdatabasestats_test.go | 35 +- .../postgreslistindexes.go | 10 +- .../postgreslistindexes_test.go | 34 +- .../postgreslistinstalledextensions.go | 10 +- .../postgreslistinstalledextensions_test.go | 34 +- .../postgreslistlocks/postgreslistlocks.go | 10 +- .../postgreslistlocks_test.go | 34 +- .../postgreslistpgsettings.go | 10 +- .../postgreslistpgsettings_test.go | 35 +- .../postgreslistpublicationtables.go | 10 +- .../postgreslistpublicationtables_test.go | 35 +- .../postgreslistquerystats.go | 10 +- .../postgreslistquerystats_test.go | 35 +- .../postgreslistroles/postgreslistroles.go | 10 +- .../postgreslistroles_test.go | 35 +- .../postgreslistschemas.go | 10 +- .../postgreslistschemas_test.go | 35 +- .../postgreslistsequences.go | 10 +- .../postgreslistsequences_test.go | 35 +- .../postgresliststoredprocedure.go | 33 +- .../postgresliststoredprocedure_test.go | 35 +- .../postgreslisttables/postgreslisttables.go | 10 +- .../postgreslisttables_test.go | 24 +- .../postgreslisttablespaces.go | 10 +- .../postgreslisttablespaces_test.go | 34 +- .../postgreslisttablestats.go | 10 +- .../postgreslisttablestats_test.go | 35 +- .../postgreslisttriggers.go | 10 +- .../postgreslisttriggers_test.go | 34 +- .../postgreslistviews/postgreslistviews.go | 10 +- .../postgreslistviews_test.go | 34 +- .../postgreslongrunningtransactions.go | 10 +- .../postgreslongrunningtransactions_test.go | 35 +- .../postgresreplicationstats.go | 10 +- .../postgresreplicationstats_test.go | 34 +- .../tools/postgres/postgressql/postgressql.go | 10 +- .../postgres/postgressql/postgressql_test.go | 97 ++-- internal/tools/redis/redis.go | 10 +- internal/tools/redis/redis_test.go | 33 +- .../serverlessspark/createbatch/config.go | 4 +- .../serverlesssparkcancelbatch.go | 10 +- .../serverlesssparkcancelbatch_test.go | 18 +- .../serverlesssparkcreatepysparkbatch.go | 8 +- .../serverlesssparkcreatesparkbatch.go | 8 +- .../serverlesssparkgetbatch.go | 10 +- .../serverlesssparkgetbatch_test.go | 18 +- .../serverlesssparklistbatches.go | 10 +- .../serverlesssparklistbatches_test.go | 18 +- .../serverlessspark/testutils/testutils.go | 82 ++- .../singlestoreexecutesql.go | 14 +- .../singlestoreexecutesql_test.go | 27 +- .../singlestoresql/singlestoresql.go | 12 +- .../singlestoresql/singlestoresql_test.go | 139 ++--- .../snowflakeexecutesql.go | 12 +- .../snowflakeexecutesql_test.go | 33 +- .../snowflake/snowflakesql/snowflakesql.go | 10 +- .../snowflakesql/snowflakesql_test.go | 37 +- .../spannerexecutesql/spannerexecutesql.go | 12 +- .../spannerexecutesql_test.go | 30 +- .../spannerlistgraphs/spannerlistgraphs.go | 10 +- .../spannerlistgraphs_test.go | 42 +- .../spannerlisttables/spannerlisttables.go | 10 +- .../spannerlisttables_test.go | 42 +- .../tools/spanner/spannersql/spanner_test.go | 129 +++-- .../tools/spanner/spannersql/spannersql.go | 10 +- .../sqliteexecutesql/sqliteexecutesql.go | 12 +- .../sqliteexecutesql/sqliteexecutesql_test.go | 24 +- internal/tools/sqlite/sqlitesql/sqlitesql.go | 10 +- .../tools/sqlite/sqlitesql/sqlitesql_test.go | 113 ++-- .../tidb/tidbexecutesql/tidbexecutesql.go | 12 +- .../tidbexecutesql/tidbexecutesql_test.go | 24 +- internal/tools/tidb/tidbsql/tidbsql.go | 10 +- internal/tools/tidb/tidbsql/tidbsql_test.go | 113 ++-- internal/tools/tools.go | 22 +- .../trino/trinoexecutesql/trinoexecutesql.go | 10 +- .../trinoexecutesql/trinoexecutesql_test.go | 25 +- internal/tools/trino/trinosql/trinosql.go | 10 +- .../tools/trino/trinosql/trinosql_test.go | 127 +++-- internal/tools/utility/wait/wait.go | 10 +- internal/tools/utility/wait/wait_test.go | 23 +- internal/tools/valkey/valkey.go | 10 +- internal/tools/valkey/valkey_test.go | 33 +- internal/tools/yugabytedbsql/yugabytedbsql.go | 10 +- .../tools/yugabytedbsql/yugabytedbsql_test.go | 127 ++--- 369 files changed, 4707 insertions(+), 5752 deletions(-) diff --git a/internal/tools/alloydb/alloydbcreatecluster/alloydbcreatecluster.go b/internal/tools/alloydb/alloydbcreatecluster/alloydbcreatecluster.go index 52d8696152..ba8b89d0d7 100644 --- a/internal/tools/alloydb/alloydbcreatecluster/alloydbcreatecluster.go +++ b/internal/tools/alloydb/alloydbcreatecluster/alloydbcreatecluster.go @@ -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() diff --git a/internal/tools/alloydb/alloydbcreatecluster/alloydbcreatecluster_test.go b/internal/tools/alloydb/alloydbcreatecluster/alloydbcreatecluster_test.go index d682552df9..2daed2e625 100644 --- a/internal/tools/alloydb/alloydbcreatecluster/alloydbcreatecluster_test.go +++ b/internal/tools/alloydb/alloydbcreatecluster/alloydbcreatecluster_test.go @@ -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) } }) diff --git a/internal/tools/alloydb/alloydbcreateinstance/alloydbcreateinstance.go b/internal/tools/alloydb/alloydbcreateinstance/alloydbcreateinstance.go index 0fd45bbf98..42b96158eb 100644 --- a/internal/tools/alloydb/alloydbcreateinstance/alloydbcreateinstance.go +++ b/internal/tools/alloydb/alloydbcreateinstance/alloydbcreateinstance.go @@ -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() diff --git a/internal/tools/alloydb/alloydbcreateinstance/alloydbcreateinstance_test.go b/internal/tools/alloydb/alloydbcreateinstance/alloydbcreateinstance_test.go index ed98529898..820492d825 100644 --- a/internal/tools/alloydb/alloydbcreateinstance/alloydbcreateinstance_test.go +++ b/internal/tools/alloydb/alloydbcreateinstance/alloydbcreateinstance_test.go @@ -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) } }) diff --git a/internal/tools/alloydb/alloydbcreateuser/alloydbcreateuser.go b/internal/tools/alloydb/alloydbcreateuser/alloydbcreateuser.go index 1187f1b56b..8fba0235fe 100644 --- a/internal/tools/alloydb/alloydbcreateuser/alloydbcreateuser.go +++ b/internal/tools/alloydb/alloydbcreateuser/alloydbcreateuser.go @@ -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() diff --git a/internal/tools/alloydb/alloydbcreateuser/alloydbcreateuser_test.go b/internal/tools/alloydb/alloydbcreateuser/alloydbcreateuser_test.go index 9200a98fdd..234a9d35b8 100644 --- a/internal/tools/alloydb/alloydbcreateuser/alloydbcreateuser_test.go +++ b/internal/tools/alloydb/alloydbcreateuser/alloydbcreateuser_test.go @@ -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) } }) diff --git a/internal/tools/alloydb/alloydbgetcluster/alloydbgetcluster.go b/internal/tools/alloydb/alloydbgetcluster/alloydbgetcluster.go index 164f538aac..436c95e129 100644 --- a/internal/tools/alloydb/alloydbgetcluster/alloydbgetcluster.go +++ b/internal/tools/alloydb/alloydbgetcluster/alloydbgetcluster.go @@ -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() diff --git a/internal/tools/alloydb/alloydbgetcluster/alloydbgetcluster_test.go b/internal/tools/alloydb/alloydbgetcluster/alloydbgetcluster_test.go index ce8bf99794..7ae2d11fee 100644 --- a/internal/tools/alloydb/alloydbgetcluster/alloydbgetcluster_test.go +++ b/internal/tools/alloydb/alloydbgetcluster/alloydbgetcluster_test.go @@ -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) } }) diff --git a/internal/tools/alloydb/alloydbgetinstance/alloydbgetinstance.go b/internal/tools/alloydb/alloydbgetinstance/alloydbgetinstance.go index 6c9994eb90..b849b12a06 100644 --- a/internal/tools/alloydb/alloydbgetinstance/alloydbgetinstance.go +++ b/internal/tools/alloydb/alloydbgetinstance/alloydbgetinstance.go @@ -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() diff --git a/internal/tools/alloydb/alloydbgetinstance/alloydbgetinstance_test.go b/internal/tools/alloydb/alloydbgetinstance/alloydbgetinstance_test.go index f37c5c867a..498934fdfd 100644 --- a/internal/tools/alloydb/alloydbgetinstance/alloydbgetinstance_test.go +++ b/internal/tools/alloydb/alloydbgetinstance/alloydbgetinstance_test.go @@ -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) } }) diff --git a/internal/tools/alloydb/alloydbgetuser/alloydbgetuser.go b/internal/tools/alloydb/alloydbgetuser/alloydbgetuser.go index b90d6b4d5b..775dab4f94 100644 --- a/internal/tools/alloydb/alloydbgetuser/alloydbgetuser.go +++ b/internal/tools/alloydb/alloydbgetuser/alloydbgetuser.go @@ -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() diff --git a/internal/tools/alloydb/alloydbgetuser/alloydbgetuser_test.go b/internal/tools/alloydb/alloydbgetuser/alloydbgetuser_test.go index 06dc4a4879..f601dc30d2 100644 --- a/internal/tools/alloydb/alloydbgetuser/alloydbgetuser_test.go +++ b/internal/tools/alloydb/alloydbgetuser/alloydbgetuser_test.go @@ -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) } }) diff --git a/internal/tools/alloydb/alloydblistclusters/alloydblistclusters.go b/internal/tools/alloydb/alloydblistclusters/alloydblistclusters.go index 6c5307478d..154b953c0b 100644 --- a/internal/tools/alloydb/alloydblistclusters/alloydblistclusters.go +++ b/internal/tools/alloydb/alloydblistclusters/alloydblistclusters.go @@ -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() diff --git a/internal/tools/alloydb/alloydblistclusters/alloydblistclusters_test.go b/internal/tools/alloydb/alloydblistclusters/alloydblistclusters_test.go index e0a2e9534e..17429df5de 100644 --- a/internal/tools/alloydb/alloydblistclusters/alloydblistclusters_test.go +++ b/internal/tools/alloydb/alloydblistclusters/alloydblistclusters_test.go @@ -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) } }) diff --git a/internal/tools/alloydb/alloydblistinstances/alloydblistinstances.go b/internal/tools/alloydb/alloydblistinstances/alloydblistinstances.go index 2cbc500946..fe7b18c915 100644 --- a/internal/tools/alloydb/alloydblistinstances/alloydblistinstances.go +++ b/internal/tools/alloydb/alloydblistinstances/alloydblistinstances.go @@ -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() diff --git a/internal/tools/alloydb/alloydblistinstances/alloydblistinstances_test.go b/internal/tools/alloydb/alloydblistinstances/alloydblistinstances_test.go index 28b55bace5..c1f95b964a 100644 --- a/internal/tools/alloydb/alloydblistinstances/alloydblistinstances_test.go +++ b/internal/tools/alloydb/alloydblistinstances/alloydblistinstances_test.go @@ -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) } }) diff --git a/internal/tools/alloydb/alloydblistusers/alloydblistusers.go b/internal/tools/alloydb/alloydblistusers/alloydblistusers.go index 11641f737e..49901d1c25 100644 --- a/internal/tools/alloydb/alloydblistusers/alloydblistusers.go +++ b/internal/tools/alloydb/alloydblistusers/alloydblistusers.go @@ -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() diff --git a/internal/tools/alloydb/alloydblistusers/alloydblistusers_test.go b/internal/tools/alloydb/alloydblistusers/alloydblistusers_test.go index 33a3b0fec2..6c92fcab53 100644 --- a/internal/tools/alloydb/alloydblistusers/alloydblistusers_test.go +++ b/internal/tools/alloydb/alloydblistusers/alloydblistusers_test.go @@ -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) } }) diff --git a/internal/tools/alloydb/alloydbwaitforoperation/alloydbwaitforoperation.go b/internal/tools/alloydb/alloydbwaitforoperation/alloydbwaitforoperation.go index 371050273b..43d0566610 100644 --- a/internal/tools/alloydb/alloydbwaitforoperation/alloydbwaitforoperation.go +++ b/internal/tools/alloydb/alloydbwaitforoperation/alloydbwaitforoperation.go @@ -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() diff --git a/internal/tools/alloydb/alloydbwaitforoperation/alloydbwaitforoperation_test.go b/internal/tools/alloydb/alloydbwaitforoperation/alloydbwaitforoperation_test.go index 90a9f94c4b..ad9961f1b6 100644 --- a/internal/tools/alloydb/alloydbwaitforoperation/alloydbwaitforoperation_test.go +++ b/internal/tools/alloydb/alloydbwaitforoperation/alloydbwaitforoperation_test.go @@ -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) } }) diff --git a/internal/tools/alloydbainl/alloydbainl.go b/internal/tools/alloydbainl/alloydbainl.go index 3fa2824ae4..3c6d02a4e4 100644 --- a/internal/tools/alloydbainl/alloydbainl.go +++ b/internal/tools/alloydbainl/alloydbainl.go @@ -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) { diff --git a/internal/tools/alloydbainl/alloydbainl_test.go b/internal/tools/alloydbainl/alloydbainl_test.go index 076d627d3c..42dc54fa2f 100644 --- a/internal/tools/alloydbainl/alloydbainl_test.go +++ b/internal/tools/alloydbainl/alloydbainl_test.go @@ -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) } }) diff --git a/internal/tools/bigquery/bigqueryanalyzecontribution/bigqueryanalyzecontribution.go b/internal/tools/bigquery/bigqueryanalyzecontribution/bigqueryanalyzecontribution.go index bbe97f451b..d74a47e38c 100644 --- a/internal/tools/bigquery/bigqueryanalyzecontribution/bigqueryanalyzecontribution.go +++ b/internal/tools/bigquery/bigqueryanalyzecontribution/bigqueryanalyzecontribution.go @@ -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() diff --git a/internal/tools/bigquery/bigqueryanalyzecontribution/bigqueryanalyzecontribution_test.go b/internal/tools/bigquery/bigqueryanalyzecontribution/bigqueryanalyzecontribution_test.go index 1aaa16e524..ceaa41035e 100644 --- a/internal/tools/bigquery/bigqueryanalyzecontribution/bigqueryanalyzecontribution_test.go +++ b/internal/tools/bigquery/bigqueryanalyzecontribution/bigqueryanalyzecontribution_test.go @@ -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) } }) diff --git a/internal/tools/bigquery/bigqueryconversationalanalytics/bigqueryconversationalanalytics.go b/internal/tools/bigquery/bigqueryconversationalanalytics/bigqueryconversationalanalytics.go index 103d066699..45a601baff 100644 --- a/internal/tools/bigquery/bigqueryconversationalanalytics/bigqueryconversationalanalytics.go +++ b/internal/tools/bigquery/bigqueryconversationalanalytics/bigqueryconversationalanalytics.go @@ -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() diff --git a/internal/tools/bigquery/bigqueryconversationalanalytics/bigqueryconversationalanalytics_test.go b/internal/tools/bigquery/bigqueryconversationalanalytics/bigqueryconversationalanalytics_test.go index 746eda1cca..153d656e5b 100644 --- a/internal/tools/bigquery/bigqueryconversationalanalytics/bigqueryconversationalanalytics_test.go +++ b/internal/tools/bigquery/bigqueryconversationalanalytics/bigqueryconversationalanalytics_test.go @@ -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) } }) diff --git a/internal/tools/bigquery/bigqueryexecutesql/bigqueryexecutesql.go b/internal/tools/bigquery/bigqueryexecutesql/bigqueryexecutesql.go index 7d790ed339..db73477d79 100644 --- a/internal/tools/bigquery/bigqueryexecutesql/bigqueryexecutesql.go +++ b/internal/tools/bigquery/bigqueryexecutesql/bigqueryexecutesql.go @@ -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) } diff --git a/internal/tools/bigquery/bigqueryexecutesql/bigqueryexecutesql_test.go b/internal/tools/bigquery/bigqueryexecutesql/bigqueryexecutesql_test.go index 2604264635..e341cee0ac 100644 --- a/internal/tools/bigquery/bigqueryexecutesql/bigqueryexecutesql_test.go +++ b/internal/tools/bigquery/bigqueryexecutesql/bigqueryexecutesql_test.go @@ -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) } }) diff --git a/internal/tools/bigquery/bigqueryforecast/bigqueryforecast.go b/internal/tools/bigquery/bigqueryforecast/bigqueryforecast.go index ffede41e5f..1963f08f4b 100644 --- a/internal/tools/bigquery/bigqueryforecast/bigqueryforecast.go +++ b/internal/tools/bigquery/bigqueryforecast/bigqueryforecast.go @@ -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) } diff --git a/internal/tools/bigquery/bigqueryforecast/bigqueryforecast_test.go b/internal/tools/bigquery/bigqueryforecast/bigqueryforecast_test.go index 6f6b7fcff5..0257668e36 100644 --- a/internal/tools/bigquery/bigqueryforecast/bigqueryforecast_test.go +++ b/internal/tools/bigquery/bigqueryforecast/bigqueryforecast_test.go @@ -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) } }) diff --git a/internal/tools/bigquery/bigquerygetdatasetinfo/bigquerygetdatasetinfo.go b/internal/tools/bigquery/bigquerygetdatasetinfo/bigquerygetdatasetinfo.go index c633c2365e..da756f00fa 100644 --- a/internal/tools/bigquery/bigquerygetdatasetinfo/bigquerygetdatasetinfo.go +++ b/internal/tools/bigquery/bigquerygetdatasetinfo/bigquerygetdatasetinfo.go @@ -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() diff --git a/internal/tools/bigquery/bigquerygetdatasetinfo/bigquerygetdatasetinfo_test.go b/internal/tools/bigquery/bigquerygetdatasetinfo/bigquerygetdatasetinfo_test.go index 53fac7a5f0..5a18b9fe1f 100644 --- a/internal/tools/bigquery/bigquerygetdatasetinfo/bigquerygetdatasetinfo_test.go +++ b/internal/tools/bigquery/bigquerygetdatasetinfo/bigquerygetdatasetinfo_test.go @@ -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) } }) diff --git a/internal/tools/bigquery/bigquerygettableinfo/bigquerygettableinfo.go b/internal/tools/bigquery/bigquerygettableinfo/bigquerygettableinfo.go index 72fc770668..62c45f8fdb 100644 --- a/internal/tools/bigquery/bigquerygettableinfo/bigquerygettableinfo.go +++ b/internal/tools/bigquery/bigquerygettableinfo/bigquerygettableinfo.go @@ -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() diff --git a/internal/tools/bigquery/bigquerygettableinfo/bigquerygettableinfo_test.go b/internal/tools/bigquery/bigquerygettableinfo/bigquerygettableinfo_test.go index 7b7e4f9f0d..c196ff3a0c 100644 --- a/internal/tools/bigquery/bigquerygettableinfo/bigquerygettableinfo_test.go +++ b/internal/tools/bigquery/bigquerygettableinfo/bigquerygettableinfo_test.go @@ -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) } }) diff --git a/internal/tools/bigquery/bigquerylistdatasetids/bigquerylistdatasetids.go b/internal/tools/bigquery/bigquerylistdatasetids/bigquerylistdatasetids.go index c4fba00f7d..78ac0708d4 100644 --- a/internal/tools/bigquery/bigquerylistdatasetids/bigquerylistdatasetids.go +++ b/internal/tools/bigquery/bigquerylistdatasetids/bigquerylistdatasetids.go @@ -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 diff --git a/internal/tools/bigquery/bigquerylistdatasetids/bigquerylistdatasetids_test.go b/internal/tools/bigquery/bigquerylistdatasetids/bigquerylistdatasetids_test.go index 6d7ba9c0bc..21de3f9918 100644 --- a/internal/tools/bigquery/bigquerylistdatasetids/bigquerylistdatasetids_test.go +++ b/internal/tools/bigquery/bigquerylistdatasetids/bigquerylistdatasetids_test.go @@ -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) } }) diff --git a/internal/tools/bigquery/bigquerylisttableids/bigquerylisttableids.go b/internal/tools/bigquery/bigquerylisttableids/bigquerylisttableids.go index 634ea6b64c..9f9214ea1c 100644 --- a/internal/tools/bigquery/bigquerylisttableids/bigquerylisttableids.go +++ b/internal/tools/bigquery/bigquerylisttableids/bigquerylisttableids.go @@ -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() diff --git a/internal/tools/bigquery/bigquerylisttableids/bigquerylisttableids_test.go b/internal/tools/bigquery/bigquerylisttableids/bigquerylisttableids_test.go index 64461cc718..7056764ccc 100644 --- a/internal/tools/bigquery/bigquerylisttableids/bigquerylisttableids_test.go +++ b/internal/tools/bigquery/bigquerylisttableids/bigquerylisttableids_test.go @@ -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) } }) diff --git a/internal/tools/bigquery/bigquerysearchcatalog/bigquerysearchcatalog.go b/internal/tools/bigquery/bigquerysearchcatalog/bigquerysearchcatalog.go index 54e6042ec9..65304d6b8b 100644 --- a/internal/tools/bigquery/bigquerysearchcatalog/bigquerysearchcatalog.go +++ b/internal/tools/bigquery/bigquerysearchcatalog/bigquerysearchcatalog.go @@ -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) { diff --git a/internal/tools/bigquery/bigquerysearchcatalog/bigquerysearchcatalog_test.go b/internal/tools/bigquery/bigquerysearchcatalog/bigquerysearchcatalog_test.go index 893cedf02b..bb218a9cd1 100644 --- a/internal/tools/bigquery/bigquerysearchcatalog/bigquerysearchcatalog_test.go +++ b/internal/tools/bigquery/bigquerysearchcatalog/bigquerysearchcatalog_test.go @@ -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) } }) diff --git a/internal/tools/bigquery/bigquerysql/bigquerysql.go b/internal/tools/bigquery/bigquerysql/bigquerysql.go index 716bdaa4b0..a74504d823 100644 --- a/internal/tools/bigquery/bigquerysql/bigquerysql.go +++ b/internal/tools/bigquery/bigquerysql/bigquerysql.go @@ -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) { diff --git a/internal/tools/bigquery/bigquerysql/bigquerysql_test.go b/internal/tools/bigquery/bigquerysql/bigquerysql_test.go index 8a04682225..d646facad2 100644 --- a/internal/tools/bigquery/bigquerysql/bigquerysql_test.go +++ b/internal/tools/bigquery/bigquerysql/bigquerysql_test.go @@ -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) } }) } - } diff --git a/internal/tools/bigtable/bigtable.go b/internal/tools/bigtable/bigtable.go index fb8acec653..3f74e228aa 100644 --- a/internal/tools/bigtable/bigtable.go +++ b/internal/tools/bigtable/bigtable.go @@ -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) { diff --git a/internal/tools/bigtable/bigtable_test.go b/internal/tools/bigtable/bigtable_test.go index 756174fa3b..7344e9fa21 100644 --- a/internal/tools/bigtable/bigtable_test.go +++ b/internal/tools/bigtable/bigtable_test.go @@ -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) } }) diff --git a/internal/tools/cassandra/cassandracql/cassandracql.go b/internal/tools/cassandra/cassandracql/cassandracql.go index 3618aa8a19..fe81a043bd 100644 --- a/internal/tools/cassandra/cassandracql/cassandracql.go +++ b/internal/tools/cassandra/cassandracql/cassandracql.go @@ -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. diff --git a/internal/tools/cassandra/cassandracql/cassandracql_test.go b/internal/tools/cassandra/cassandracql/cassandracql_test.go index 4b7a69c686..bcf6e128be 100644 --- a/internal/tools/cassandra/cassandracql/cassandracql_test.go +++ b/internal/tools/cassandra/cassandracql/cassandracql_test.go @@ -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) } }) diff --git a/internal/tools/clickhouse/clickhouseexecutesql/clickhouseexecutesql.go b/internal/tools/clickhouse/clickhouseexecutesql/clickhouseexecutesql.go index 4f95db2253..f2428b50f8 100644 --- a/internal/tools/clickhouse/clickhouseexecutesql/clickhouseexecutesql.go +++ b/internal/tools/clickhouse/clickhouseexecutesql/clickhouseexecutesql.go @@ -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"` diff --git a/internal/tools/clickhouse/clickhouseexecutesql/clickhouseexecutesql_test.go b/internal/tools/clickhouse/clickhouseexecutesql/clickhouseexecutesql_test.go index f623db3c04..47e5da5279 100644 --- a/internal/tools/clickhouse/clickhouseexecutesql/clickhouseexecutesql_test.go +++ b/internal/tools/clickhouse/clickhouseexecutesql/clickhouseexecutesql_test.go @@ -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) } }) diff --git a/internal/tools/clickhouse/clickhouselistdatabases/clickhouselistdatabases.go b/internal/tools/clickhouse/clickhouselistdatabases/clickhouselistdatabases.go index a4e0f75f72..b988dda6a4 100644 --- a/internal/tools/clickhouse/clickhouselistdatabases/clickhouselistdatabases.go +++ b/internal/tools/clickhouse/clickhouselistdatabases/clickhouselistdatabases.go @@ -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"` diff --git a/internal/tools/clickhouse/clickhouselistdatabases/clickhouselistdatabases_test.go b/internal/tools/clickhouse/clickhouselistdatabases/clickhouselistdatabases_test.go index c821d221b3..4f02cd5bfc 100644 --- a/internal/tools/clickhouse/clickhouselistdatabases/clickhouselistdatabases_test.go +++ b/internal/tools/clickhouse/clickhouselistdatabases/clickhouselistdatabases_test.go @@ -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) } }) diff --git a/internal/tools/clickhouse/clickhouselisttables/clickhouselisttables.go b/internal/tools/clickhouse/clickhouselisttables/clickhouselisttables.go index 821305abe7..25f92762e5 100644 --- a/internal/tools/clickhouse/clickhouselisttables/clickhouselisttables.go +++ b/internal/tools/clickhouse/clickhouselisttables/clickhouselisttables.go @@ -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"` diff --git a/internal/tools/clickhouse/clickhouselisttables/clickhouselisttables_test.go b/internal/tools/clickhouse/clickhouselisttables/clickhouselisttables_test.go index 9d841fb25a..cfe2952f27 100644 --- a/internal/tools/clickhouse/clickhouselisttables/clickhouselisttables_test.go +++ b/internal/tools/clickhouse/clickhouselisttables/clickhouselisttables_test.go @@ -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) } }) diff --git a/internal/tools/clickhouse/clickhousesql/clickhousesql.go b/internal/tools/clickhouse/clickhousesql/clickhousesql.go index 732f6ac0fe..87a3388d96 100644 --- a/internal/tools/clickhouse/clickhousesql/clickhousesql.go +++ b/internal/tools/clickhouse/clickhousesql/clickhousesql.go @@ -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"` diff --git a/internal/tools/clickhouse/clickhousesql/clickhousesql_test.go b/internal/tools/clickhouse/clickhousesql/clickhousesql_test.go index 3dbe0a3d06..e7f38a1f6b 100644 --- a/internal/tools/clickhouse/clickhousesql/clickhousesql_test.go +++ b/internal/tools/clickhouse/clickhousesql/clickhousesql_test.go @@ -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) } }) diff --git a/internal/tools/cloudgda/cloudgda.go b/internal/tools/cloudgda/cloudgda.go index df6bde00a6..87afa6fbbf 100644 --- a/internal/tools/cloudgda/cloudgda.go +++ b/internal/tools/cloudgda/cloudgda.go @@ -26,7 +26,7 @@ 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" // Guidance is the tool guidance string. const Guidance = `Tool guidance: @@ -44,8 +44,8 @@ Usage guidance: 2. If ` + "`natural_language_answer`" + ` is produced, use ` + "`intent_explanation`" + ` and ` + "`generated_query`" + ` to see if you need to clarify any assumptions for the 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)) } } @@ -65,7 +65,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"` @@ -78,7 +78,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) { diff --git a/internal/tools/cloudgda/cloudgda_test.go b/internal/tools/cloudgda/cloudgda_test.go index 1df8382c75..d5e73658ea 100644 --- a/internal/tools/cloudgda/cloudgda_test.go +++ b/internal/tools/cloudgda/cloudgda_test.go @@ -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 diff --git a/internal/tools/cloudhealthcare/cloudhealthcarefhirfetchpage/cloudhealthcarefhirfetchpage.go b/internal/tools/cloudhealthcare/cloudhealthcarefhirfetchpage/cloudhealthcarefhirfetchpage.go index de3e3cc29f..83e0e2b679 100644 --- a/internal/tools/cloudhealthcare/cloudhealthcarefhirfetchpage/cloudhealthcarefhirfetchpage.go +++ b/internal/tools/cloudhealthcare/cloudhealthcarefhirfetchpage/cloudhealthcarefhirfetchpage.go @@ -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) { diff --git a/internal/tools/cloudhealthcare/cloudhealthcarefhirfetchpage/cloudhealthcarefhirfetchpage_test.go b/internal/tools/cloudhealthcare/cloudhealthcarefhirfetchpage/cloudhealthcarefhirfetchpage_test.go index c655f8c81d..1b5d6816bc 100644 --- a/internal/tools/cloudhealthcare/cloudhealthcarefhirfetchpage/cloudhealthcarefhirfetchpage_test.go +++ b/internal/tools/cloudhealthcare/cloudhealthcarefhirfetchpage/cloudhealthcarefhirfetchpage_test.go @@ -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) } }) diff --git a/internal/tools/cloudhealthcare/cloudhealthcarefhirpatienteverything/cloudhealthcarefhirpatienteverything.go b/internal/tools/cloudhealthcare/cloudhealthcarefhirpatienteverything/cloudhealthcarefhirpatienteverything.go index f313393d76..01c2b081f5 100644 --- a/internal/tools/cloudhealthcare/cloudhealthcarefhirpatienteverything/cloudhealthcarefhirpatienteverything.go +++ b/internal/tools/cloudhealthcare/cloudhealthcarefhirpatienteverything/cloudhealthcarefhirpatienteverything.go @@ -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") diff --git a/internal/tools/cloudhealthcare/cloudhealthcarefhirpatienteverything/cloudhealthcarefhirpatienteverything_test.go b/internal/tools/cloudhealthcare/cloudhealthcarefhirpatienteverything/cloudhealthcarefhirpatienteverything_test.go index e749c4369a..d6caf089ff 100644 --- a/internal/tools/cloudhealthcare/cloudhealthcarefhirpatienteverything/cloudhealthcarefhirpatienteverything_test.go +++ b/internal/tools/cloudhealthcare/cloudhealthcarefhirpatienteverything/cloudhealthcarefhirpatienteverything_test.go @@ -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) } }) diff --git a/internal/tools/cloudhealthcare/cloudhealthcarefhirpatientsearch/cloudhealthcarefhirpatientsearch.go b/internal/tools/cloudhealthcare/cloudhealthcarefhirpatientsearch/cloudhealthcarefhirpatientsearch.go index 6b3cb61067..b2b99a5e6b 100644 --- a/internal/tools/cloudhealthcare/cloudhealthcarefhirpatientsearch/cloudhealthcarefhirpatientsearch.go +++ b/internal/tools/cloudhealthcare/cloudhealthcarefhirpatientsearch/cloudhealthcarefhirpatientsearch.go @@ -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{ diff --git a/internal/tools/cloudhealthcare/cloudhealthcarefhirpatientsearch/cloudhealthcarefhirpatientsearch_test.go b/internal/tools/cloudhealthcare/cloudhealthcarefhirpatientsearch/cloudhealthcarefhirpatientsearch_test.go index 3a69341092..1d59af3b23 100644 --- a/internal/tools/cloudhealthcare/cloudhealthcarefhirpatientsearch/cloudhealthcarefhirpatientsearch_test.go +++ b/internal/tools/cloudhealthcare/cloudhealthcarefhirpatientsearch/cloudhealthcarefhirpatientsearch_test.go @@ -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) } }) diff --git a/internal/tools/cloudhealthcare/cloudhealthcaregetdataset/cloudhealthcaregetdataset.go b/internal/tools/cloudhealthcare/cloudhealthcaregetdataset/cloudhealthcaregetdataset.go index 0f2252c3a8..65b9a05fd1 100644 --- a/internal/tools/cloudhealthcare/cloudhealthcaregetdataset/cloudhealthcaregetdataset.go +++ b/internal/tools/cloudhealthcare/cloudhealthcaregetdataset/cloudhealthcaregetdataset.go @@ -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) { diff --git a/internal/tools/cloudhealthcare/cloudhealthcaregetdataset/cloudhealthcaregetdataset_test.go b/internal/tools/cloudhealthcare/cloudhealthcaregetdataset/cloudhealthcaregetdataset_test.go index f88c0681ad..e36b6b5d2d 100644 --- a/internal/tools/cloudhealthcare/cloudhealthcaregetdataset/cloudhealthcaregetdataset_test.go +++ b/internal/tools/cloudhealthcare/cloudhealthcaregetdataset/cloudhealthcaregetdataset_test.go @@ -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) } }) diff --git a/internal/tools/cloudhealthcare/cloudhealthcaregetdicomstore/cloudhealthcaregetdicomstore.go b/internal/tools/cloudhealthcare/cloudhealthcaregetdicomstore/cloudhealthcaregetdicomstore.go index 282938100e..29bd01a421 100644 --- a/internal/tools/cloudhealthcare/cloudhealthcaregetdicomstore/cloudhealthcaregetdicomstore.go +++ b/internal/tools/cloudhealthcare/cloudhealthcaregetdicomstore/cloudhealthcaregetdicomstore.go @@ -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{} diff --git a/internal/tools/cloudhealthcare/cloudhealthcaregetdicomstore/cloudhealthcaregetdicomstore_test.go b/internal/tools/cloudhealthcare/cloudhealthcaregetdicomstore/cloudhealthcaregetdicomstore_test.go index 8bebc02657..37ba8923e2 100644 --- a/internal/tools/cloudhealthcare/cloudhealthcaregetdicomstore/cloudhealthcaregetdicomstore_test.go +++ b/internal/tools/cloudhealthcare/cloudhealthcaregetdicomstore/cloudhealthcaregetdicomstore_test.go @@ -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) } }) diff --git a/internal/tools/cloudhealthcare/cloudhealthcaregetdicomstoremetrics/cloudhealthcaregetdicomstoremetrics.go b/internal/tools/cloudhealthcare/cloudhealthcaregetdicomstoremetrics/cloudhealthcaregetdicomstoremetrics.go index 79684c2b9f..9d8f3ec33c 100644 --- a/internal/tools/cloudhealthcare/cloudhealthcaregetdicomstoremetrics/cloudhealthcaregetdicomstoremetrics.go +++ b/internal/tools/cloudhealthcare/cloudhealthcaregetdicomstoremetrics/cloudhealthcaregetdicomstoremetrics.go @@ -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{} diff --git a/internal/tools/cloudhealthcare/cloudhealthcaregetdicomstoremetrics/cloudhealthcaregetdicomstoremetrics_test.go b/internal/tools/cloudhealthcare/cloudhealthcaregetdicomstoremetrics/cloudhealthcaregetdicomstoremetrics_test.go index 8613826580..f421a42a73 100644 --- a/internal/tools/cloudhealthcare/cloudhealthcaregetdicomstoremetrics/cloudhealthcaregetdicomstoremetrics_test.go +++ b/internal/tools/cloudhealthcare/cloudhealthcaregetdicomstoremetrics/cloudhealthcaregetdicomstoremetrics_test.go @@ -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) } }) diff --git a/internal/tools/cloudhealthcare/cloudhealthcaregetfhirresource/cloudhealthcaregetfhirresource.go b/internal/tools/cloudhealthcare/cloudhealthcaregetfhirresource/cloudhealthcaregetfhirresource.go index 02dd943671..7bf73c85c8 100644 --- a/internal/tools/cloudhealthcare/cloudhealthcaregetfhirresource/cloudhealthcaregetfhirresource.go +++ b/internal/tools/cloudhealthcare/cloudhealthcaregetfhirresource/cloudhealthcaregetfhirresource.go @@ -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).") diff --git a/internal/tools/cloudhealthcare/cloudhealthcaregetfhirresource/cloudhealthcaregetfhirresource_test.go b/internal/tools/cloudhealthcare/cloudhealthcaregetfhirresource/cloudhealthcaregetfhirresource_test.go index 0639e9b5cf..a1ec0fd5c8 100644 --- a/internal/tools/cloudhealthcare/cloudhealthcaregetfhirresource/cloudhealthcaregetfhirresource_test.go +++ b/internal/tools/cloudhealthcare/cloudhealthcaregetfhirresource/cloudhealthcaregetfhirresource_test.go @@ -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) } }) diff --git a/internal/tools/cloudhealthcare/cloudhealthcaregetfhirstore/cloudhealthcaregetfhirstore.go b/internal/tools/cloudhealthcare/cloudhealthcaregetfhirstore/cloudhealthcaregetfhirstore.go index 2276fef283..6eb03c6928 100644 --- a/internal/tools/cloudhealthcare/cloudhealthcaregetfhirstore/cloudhealthcaregetfhirstore.go +++ b/internal/tools/cloudhealthcare/cloudhealthcaregetfhirstore/cloudhealthcaregetfhirstore.go @@ -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{} diff --git a/internal/tools/cloudhealthcare/cloudhealthcaregetfhirstore/cloudhealthcaregetfhirstore_test.go b/internal/tools/cloudhealthcare/cloudhealthcaregetfhirstore/cloudhealthcaregetfhirstore_test.go index 9b934fe95e..007b186f3b 100644 --- a/internal/tools/cloudhealthcare/cloudhealthcaregetfhirstore/cloudhealthcaregetfhirstore_test.go +++ b/internal/tools/cloudhealthcare/cloudhealthcaregetfhirstore/cloudhealthcaregetfhirstore_test.go @@ -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) } }) diff --git a/internal/tools/cloudhealthcare/cloudhealthcaregetfhirstoremetrics/cloudhealthcaregetfhirstoremetrics.go b/internal/tools/cloudhealthcare/cloudhealthcaregetfhirstoremetrics/cloudhealthcaregetfhirstoremetrics.go index 638ac96af6..2eb086e5fe 100644 --- a/internal/tools/cloudhealthcare/cloudhealthcaregetfhirstoremetrics/cloudhealthcaregetfhirstoremetrics.go +++ b/internal/tools/cloudhealthcare/cloudhealthcaregetfhirstoremetrics/cloudhealthcaregetfhirstoremetrics.go @@ -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{} diff --git a/internal/tools/cloudhealthcare/cloudhealthcaregetfhirstoremetrics/cloudhealthcaregetfhirstoremetrics_test.go b/internal/tools/cloudhealthcare/cloudhealthcaregetfhirstoremetrics/cloudhealthcaregetfhirstoremetrics_test.go index 55e4df69be..36964ab7d9 100644 --- a/internal/tools/cloudhealthcare/cloudhealthcaregetfhirstoremetrics/cloudhealthcaregetfhirstoremetrics_test.go +++ b/internal/tools/cloudhealthcare/cloudhealthcaregetfhirstoremetrics/cloudhealthcaregetfhirstoremetrics_test.go @@ -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) } }) diff --git a/internal/tools/cloudhealthcare/cloudhealthcarelistdicomstores/cloudhealthcarelistdicomstores.go b/internal/tools/cloudhealthcare/cloudhealthcarelistdicomstores/cloudhealthcarelistdicomstores.go index fa2f06873e..f786e89bd6 100644 --- a/internal/tools/cloudhealthcare/cloudhealthcarelistdicomstores/cloudhealthcarelistdicomstores.go +++ b/internal/tools/cloudhealthcare/cloudhealthcarelistdicomstores/cloudhealthcarelistdicomstores.go @@ -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) { diff --git a/internal/tools/cloudhealthcare/cloudhealthcarelistdicomstores/cloudhealthcarelistdicomstores_test.go b/internal/tools/cloudhealthcare/cloudhealthcarelistdicomstores/cloudhealthcarelistdicomstores_test.go index 2e2f479adb..6967f346f1 100644 --- a/internal/tools/cloudhealthcare/cloudhealthcarelistdicomstores/cloudhealthcarelistdicomstores_test.go +++ b/internal/tools/cloudhealthcare/cloudhealthcarelistdicomstores/cloudhealthcarelistdicomstores_test.go @@ -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) } }) diff --git a/internal/tools/cloudhealthcare/cloudhealthcarelistfhirstores/cloudhealthcarelistfhirstores.go b/internal/tools/cloudhealthcare/cloudhealthcarelistfhirstores/cloudhealthcarelistfhirstores.go index 8ba2bdf034..42121b2e58 100644 --- a/internal/tools/cloudhealthcare/cloudhealthcarelistfhirstores/cloudhealthcarelistfhirstores.go +++ b/internal/tools/cloudhealthcare/cloudhealthcarelistfhirstores/cloudhealthcarelistfhirstores.go @@ -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) { diff --git a/internal/tools/cloudhealthcare/cloudhealthcarelistfhirstores/cloudhealthcarelistfhirstores_test.go b/internal/tools/cloudhealthcare/cloudhealthcarelistfhirstores/cloudhealthcarelistfhirstores_test.go index 78c6226eab..70414613ea 100644 --- a/internal/tools/cloudhealthcare/cloudhealthcarelistfhirstores/cloudhealthcarelistfhirstores_test.go +++ b/internal/tools/cloudhealthcare/cloudhealthcarelistfhirstores/cloudhealthcarelistfhirstores_test.go @@ -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) } }) diff --git a/internal/tools/cloudhealthcare/cloudhealthcareretrieverendereddicominstance/cloudhealthcareretrieverendereddicominstance.go b/internal/tools/cloudhealthcare/cloudhealthcareretrieverendereddicominstance/cloudhealthcareretrieverendereddicominstance.go index 1d6657a786..3c5651d90b 100644 --- a/internal/tools/cloudhealthcare/cloudhealthcareretrieverendereddicominstance/cloudhealthcareretrieverendereddicominstance.go +++ b/internal/tools/cloudhealthcare/cloudhealthcareretrieverendereddicominstance/cloudhealthcareretrieverendereddicominstance.go @@ -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{ diff --git a/internal/tools/cloudhealthcare/cloudhealthcareretrieverendereddicominstance/cloudhealthcareretrieverendereddicominstance_test.go b/internal/tools/cloudhealthcare/cloudhealthcareretrieverendereddicominstance/cloudhealthcareretrieverendereddicominstance_test.go index 9146306a54..adf6005529 100644 --- a/internal/tools/cloudhealthcare/cloudhealthcareretrieverendereddicominstance/cloudhealthcareretrieverendereddicominstance_test.go +++ b/internal/tools/cloudhealthcare/cloudhealthcareretrieverendereddicominstance/cloudhealthcareretrieverendereddicominstance_test.go @@ -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) } }) diff --git a/internal/tools/cloudhealthcare/cloudhealthcaresearchdicominstances/cloudhealthcaresearchdicominstances.go b/internal/tools/cloudhealthcare/cloudhealthcaresearchdicominstances/cloudhealthcaresearchdicominstances.go index 245aac6c98..959b2c0cf4 100644 --- a/internal/tools/cloudhealthcare/cloudhealthcaresearchdicominstances/cloudhealthcaresearchdicominstances.go +++ b/internal/tools/cloudhealthcare/cloudhealthcaresearchdicominstances/cloudhealthcaresearchdicominstances.go @@ -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{ diff --git a/internal/tools/cloudhealthcare/cloudhealthcaresearchdicominstances/cloudhealthcaresearchdicominstances_test.go b/internal/tools/cloudhealthcare/cloudhealthcaresearchdicominstances/cloudhealthcaresearchdicominstances_test.go index 7353bfb7c3..83a3ff5de3 100644 --- a/internal/tools/cloudhealthcare/cloudhealthcaresearchdicominstances/cloudhealthcaresearchdicominstances_test.go +++ b/internal/tools/cloudhealthcare/cloudhealthcaresearchdicominstances/cloudhealthcaresearchdicominstances_test.go @@ -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) } }) diff --git a/internal/tools/cloudhealthcare/cloudhealthcaresearchdicomseries/cloudhealthcaresearchdicomseries.go b/internal/tools/cloudhealthcare/cloudhealthcaresearchdicomseries/cloudhealthcaresearchdicomseries.go index d44c1d5d85..de7ac1fb51 100644 --- a/internal/tools/cloudhealthcare/cloudhealthcaresearchdicomseries/cloudhealthcaresearchdicomseries.go +++ b/internal/tools/cloudhealthcare/cloudhealthcaresearchdicomseries/cloudhealthcaresearchdicomseries.go @@ -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{ diff --git a/internal/tools/cloudhealthcare/cloudhealthcaresearchdicomseries/cloudhealthcaresearchdicomseries_test.go b/internal/tools/cloudhealthcare/cloudhealthcaresearchdicomseries/cloudhealthcaresearchdicomseries_test.go index dfb8a16e80..e46eb0cb0f 100644 --- a/internal/tools/cloudhealthcare/cloudhealthcaresearchdicomseries/cloudhealthcaresearchdicomseries_test.go +++ b/internal/tools/cloudhealthcare/cloudhealthcaresearchdicomseries/cloudhealthcaresearchdicomseries_test.go @@ -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) } }) diff --git a/internal/tools/cloudhealthcare/cloudhealthcaresearchdicomstudies/cloudhealthcaresearchdicomstudies.go b/internal/tools/cloudhealthcare/cloudhealthcaresearchdicomstudies/cloudhealthcaresearchdicomstudies.go index e6f7ebbbc0..752914aee8 100644 --- a/internal/tools/cloudhealthcare/cloudhealthcaresearchdicomstudies/cloudhealthcaresearchdicomstudies.go +++ b/internal/tools/cloudhealthcare/cloudhealthcaresearchdicomstudies/cloudhealthcaresearchdicomstudies.go @@ -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{ diff --git a/internal/tools/cloudhealthcare/cloudhealthcaresearchdicomstudies/cloudhealthcaresearchdicomstudies_test.go b/internal/tools/cloudhealthcare/cloudhealthcaresearchdicomstudies/cloudhealthcaresearchdicomstudies_test.go index 9cad7cffe4..6415eaedd2 100644 --- a/internal/tools/cloudhealthcare/cloudhealthcaresearchdicomstudies/cloudhealthcaresearchdicomstudies_test.go +++ b/internal/tools/cloudhealthcare/cloudhealthcaresearchdicomstudies/cloudhealthcaresearchdicomstudies_test.go @@ -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) } }) diff --git a/internal/tools/cloudmonitoring/cloudmonitoring.go b/internal/tools/cloudmonitoring/cloudmonitoring.go index e2e3339c02..46fb119ac7 100644 --- a/internal/tools/cloudmonitoring/cloudmonitoring.go +++ b/internal/tools/cloudmonitoring/cloudmonitoring.go @@ -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) { diff --git a/internal/tools/cloudmonitoring/cloudmonitoring_test.go b/internal/tools/cloudmonitoring/cloudmonitoring_test.go index aa86f7e073..30b143444e 100644 --- a/internal/tools/cloudmonitoring/cloudmonitoring_test.go +++ b/internal/tools/cloudmonitoring/cloudmonitoring_test.go @@ -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") } diff --git a/internal/tools/cloudsql/cloudsqlcloneinstance/cloudsqlcloneinstance.go b/internal/tools/cloudsql/cloudsqlcloneinstance/cloudsqlcloneinstance.go index 8cb07d5a70..bee4fde3fd 100644 --- a/internal/tools/cloudsql/cloudsqlcloneinstance/cloudsqlcloneinstance.go +++ b/internal/tools/cloudsql/cloudsqlcloneinstance/cloudsqlcloneinstance.go @@ -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() diff --git a/internal/tools/cloudsql/cloudsqlcloneinstance/cloudsqlcloneinstance_test.go b/internal/tools/cloudsql/cloudsqlcloneinstance/cloudsqlcloneinstance_test.go index cf8473ecbc..2cb93c60b1 100644 --- a/internal/tools/cloudsql/cloudsqlcloneinstance/cloudsqlcloneinstance_test.go +++ b/internal/tools/cloudsql/cloudsqlcloneinstance/cloudsqlcloneinstance_test.go @@ -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) } }) diff --git a/internal/tools/cloudsql/cloudsqlcreatebackup/cloudsqlcreatebackup.go b/internal/tools/cloudsql/cloudsqlcreatebackup/cloudsqlcreatebackup.go index 5a00ef74fb..6401f273b0 100644 --- a/internal/tools/cloudsql/cloudsqlcreatebackup/cloudsqlcreatebackup.go +++ b/internal/tools/cloudsql/cloudsqlcreatebackup/cloudsqlcreatebackup.go @@ -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() diff --git a/internal/tools/cloudsql/cloudsqlcreatebackup/cloudsqlcreatebackup_test.go b/internal/tools/cloudsql/cloudsqlcreatebackup/cloudsqlcreatebackup_test.go index e71eeaa79a..3136729817 100644 --- a/internal/tools/cloudsql/cloudsqlcreatebackup/cloudsqlcreatebackup_test.go +++ b/internal/tools/cloudsql/cloudsqlcreatebackup/cloudsqlcreatebackup_test.go @@ -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) } }) diff --git a/internal/tools/cloudsql/cloudsqlcreatedatabase/cloudsqlcreatedatabase.go b/internal/tools/cloudsql/cloudsqlcreatedatabase/cloudsqlcreatedatabase.go index a2e6269d93..265e4c85dc 100644 --- a/internal/tools/cloudsql/cloudsqlcreatedatabase/cloudsqlcreatedatabase.go +++ b/internal/tools/cloudsql/cloudsqlcreatedatabase/cloudsqlcreatedatabase.go @@ -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() diff --git a/internal/tools/cloudsql/cloudsqlcreatedatabase/cloudsqlcreatedatabase_test.go b/internal/tools/cloudsql/cloudsqlcreatedatabase/cloudsqlcreatedatabase_test.go index c7d0aefe44..7986d05850 100644 --- a/internal/tools/cloudsql/cloudsqlcreatedatabase/cloudsqlcreatedatabase_test.go +++ b/internal/tools/cloudsql/cloudsqlcreatedatabase/cloudsqlcreatedatabase_test.go @@ -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) } }) diff --git a/internal/tools/cloudsql/cloudsqlcreateusers/cloudsqlcreateusers.go b/internal/tools/cloudsql/cloudsqlcreateusers/cloudsqlcreateusers.go index efd5bea5be..bd0d9c0a87 100644 --- a/internal/tools/cloudsql/cloudsqlcreateusers/cloudsqlcreateusers.go +++ b/internal/tools/cloudsql/cloudsqlcreateusers/cloudsqlcreateusers.go @@ -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() diff --git a/internal/tools/cloudsql/cloudsqlcreateusers/cloudsqlcreateusers_test.go b/internal/tools/cloudsql/cloudsqlcreateusers/cloudsqlcreateusers_test.go index 075d877c81..6ea0ed59c1 100644 --- a/internal/tools/cloudsql/cloudsqlcreateusers/cloudsqlcreateusers_test.go +++ b/internal/tools/cloudsql/cloudsqlcreateusers/cloudsqlcreateusers_test.go @@ -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) } }) diff --git a/internal/tools/cloudsql/cloudsqlgetinstances/cloudsqlgetinstances.go b/internal/tools/cloudsql/cloudsqlgetinstances/cloudsqlgetinstances.go index dfeee543bb..81b6e91dea 100644 --- a/internal/tools/cloudsql/cloudsqlgetinstances/cloudsqlgetinstances.go +++ b/internal/tools/cloudsql/cloudsqlgetinstances/cloudsqlgetinstances.go @@ -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() diff --git a/internal/tools/cloudsql/cloudsqlgetinstances/cloudsqlgetinstances_test.go b/internal/tools/cloudsql/cloudsqlgetinstances/cloudsqlgetinstances_test.go index 17200fc757..249f4e2015 100644 --- a/internal/tools/cloudsql/cloudsqlgetinstances/cloudsqlgetinstances_test.go +++ b/internal/tools/cloudsql/cloudsqlgetinstances/cloudsqlgetinstances_test.go @@ -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) } }) diff --git a/internal/tools/cloudsql/cloudsqllistdatabases/cloudsqllistdatabases.go b/internal/tools/cloudsql/cloudsqllistdatabases/cloudsqllistdatabases.go index 216e61e7a0..637dc21505 100644 --- a/internal/tools/cloudsql/cloudsqllistdatabases/cloudsqllistdatabases.go +++ b/internal/tools/cloudsql/cloudsqllistdatabases/cloudsqllistdatabases.go @@ -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() diff --git a/internal/tools/cloudsql/cloudsqllistdatabases/cloudsqllistdatabases_test.go b/internal/tools/cloudsql/cloudsqllistdatabases/cloudsqllistdatabases_test.go index d3d5f39773..4717110f73 100644 --- a/internal/tools/cloudsql/cloudsqllistdatabases/cloudsqllistdatabases_test.go +++ b/internal/tools/cloudsql/cloudsqllistdatabases/cloudsqllistdatabases_test.go @@ -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) } }) diff --git a/internal/tools/cloudsql/cloudsqllistinstances/cloudsqllistinstances.go b/internal/tools/cloudsql/cloudsqllistinstances/cloudsqllistinstances.go index e9344e60e3..5c5146b91d 100644 --- a/internal/tools/cloudsql/cloudsqllistinstances/cloudsqllistinstances.go +++ b/internal/tools/cloudsql/cloudsqllistinstances/cloudsqllistinstances.go @@ -25,11 +25,11 @@ import ( "github.com/googleapis/genai-toolbox/internal/util/parameters" ) -const kind string = "cloud-sql-list-instances" +const resourceType string = "cloud-sql-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 { // Config defines the configuration for the list-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. @@ -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() diff --git a/internal/tools/cloudsql/cloudsqllistinstances/cloudsqllistinstances_test.go b/internal/tools/cloudsql/cloudsqllistinstances/cloudsqllistinstances_test.go index 092a928f0f..0ef4ce1b6e 100644 --- a/internal/tools/cloudsql/cloudsqllistinstances/cloudsqllistinstances_test.go +++ b/internal/tools/cloudsql/cloudsqllistinstances/cloudsqllistinstances_test.go @@ -17,7 +17,6 @@ package cloudsqllistinstances 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" @@ -36,11 +35,11 @@ func TestParseFromYaml(t *testing.T) { { desc: "basic example", in: ` - tools: - list-my-instances: - kind: cloud-sql-list-instances - description: some description - source: some-source + kind: tools + name: list-my-instances + type: cloud-sql-list-instances + description: some description + source: some-source `, want: server.ToolConfigs{ "list-my-instances": Config{ @@ -55,15 +54,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) } }) diff --git a/internal/tools/cloudsql/cloudsqlwaitforoperation/cloudsqlwaitforoperation.go b/internal/tools/cloudsql/cloudsqlwaitforoperation/cloudsqlwaitforoperation.go index d166f4ee5c..cf7f1d93f8 100644 --- a/internal/tools/cloudsql/cloudsqlwaitforoperation/cloudsqlwaitforoperation.go +++ b/internal/tools/cloudsql/cloudsqlwaitforoperation/cloudsqlwaitforoperation.go @@ -27,7 +27,7 @@ import ( "google.golang.org/api/sqladmin/v1" ) -const kind string = "cloud-sql-wait-for-operation" +const resourceType string = "cloud-sql-wait-for-operation" var cloudSQLConnectionMessageTemplate = `Your Cloud SQL resource is ready. @@ -71,8 +71,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)) } } @@ -94,7 +94,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 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() diff --git a/internal/tools/cloudsql/cloudsqlwaitforoperation/cloudsqlwaitforoperation_test.go b/internal/tools/cloudsql/cloudsqlwaitforoperation/cloudsqlwaitforoperation_test.go index c0dd0b816b..994cd87bb4 100644 --- a/internal/tools/cloudsql/cloudsqlwaitforoperation/cloudsqlwaitforoperation_test.go +++ b/internal/tools/cloudsql/cloudsqlwaitforoperation/cloudsqlwaitforoperation_test.go @@ -17,7 +17,6 @@ package cloudsqlwaitforoperation_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,15 +36,15 @@ func TestParseFromYaml(t *testing.T) { { desc: "basic example", in: ` - tools: - wait-for-thing: - kind: cloud-sql-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: cloud-sql-wait-for-operation + source: some-source + description: some description + delay: 1s + maxDelay: 5s + multiplier: 1.5 + maxRetries: 5 `, want: server.ToolConfigs{ "wait-for-thing": cloudsqlwaitforoperation.Config{ @@ -64,15 +63,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) } }) diff --git a/internal/tools/cloudsqlmssql/cloudsqlmssqlcreateinstance/cloudsqlmssqlcreateinstance.go b/internal/tools/cloudsqlmssql/cloudsqlmssqlcreateinstance/cloudsqlmssqlcreateinstance.go index 9dc0c7cf5b..009146ed06 100644 --- a/internal/tools/cloudsqlmssql/cloudsqlmssqlcreateinstance/cloudsqlmssqlcreateinstance.go +++ b/internal/tools/cloudsqlmssql/cloudsqlmssqlcreateinstance/cloudsqlmssqlcreateinstance.go @@ -27,11 +27,11 @@ import ( "google.golang.org/api/sqladmin/v1" ) -const kind string = "cloud-sql-mssql-create-instance" +const resourceType string = "cloud-sql-mssql-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)) } } @@ -52,7 +52,7 @@ type compatibleSource interface { // Config defines the configuration for the create-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"` @@ -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() diff --git a/internal/tools/cloudsqlmssql/cloudsqlmssqlcreateinstance/cloudsqlmssqlcreateinstance_test.go b/internal/tools/cloudsqlmssql/cloudsqlmssqlcreateinstance/cloudsqlmssqlcreateinstance_test.go index 31f58fad18..01928e87cd 100644 --- a/internal/tools/cloudsqlmssql/cloudsqlmssqlcreateinstance/cloudsqlmssqlcreateinstance_test.go +++ b/internal/tools/cloudsqlmssql/cloudsqlmssqlcreateinstance/cloudsqlmssqlcreateinstance_test.go @@ -17,7 +17,6 @@ package cloudsqlmssqlcreateinstance_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-instance-tool: - kind: cloud-sql-mssql-create-instance - description: a test description - source: a-source + kind: tools + name: create-instance-tool + type: cloud-sql-mssql-create-instance + description: a test description + source: a-source `, want: server.ToolConfigs{ "create-instance-tool": cloudsqlmssqlcreateinstance.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) } }) diff --git a/internal/tools/cloudsqlmysql/cloudsqlmysqlcreateinstance/cloudsqlmysqlcreateinstance.go b/internal/tools/cloudsqlmysql/cloudsqlmysqlcreateinstance/cloudsqlmysqlcreateinstance.go index 1e470e18ba..49c58228ad 100644 --- a/internal/tools/cloudsqlmysql/cloudsqlmysqlcreateinstance/cloudsqlmysqlcreateinstance.go +++ b/internal/tools/cloudsqlmysql/cloudsqlmysqlcreateinstance/cloudsqlmysqlcreateinstance.go @@ -27,11 +27,11 @@ import ( sqladmin "google.golang.org/api/sqladmin/v1" ) -const kind string = "cloud-sql-mysql-create-instance" +const resourceType string = "cloud-sql-mysql-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)) } } @@ -52,7 +52,7 @@ type compatibleSource interface { // Config defines the configuration for the create-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"` @@ -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() diff --git a/internal/tools/cloudsqlmysql/cloudsqlmysqlcreateinstance/cloudsqlmysqlcreateinstance_test.go b/internal/tools/cloudsqlmysql/cloudsqlmysqlcreateinstance/cloudsqlmysqlcreateinstance_test.go index e471d33347..88b4ea087d 100644 --- a/internal/tools/cloudsqlmysql/cloudsqlmysqlcreateinstance/cloudsqlmysqlcreateinstance_test.go +++ b/internal/tools/cloudsqlmysql/cloudsqlmysqlcreateinstance/cloudsqlmysqlcreateinstance_test.go @@ -17,7 +17,6 @@ package cloudsqlmysqlcreateinstance_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-instance-tool: - kind: cloud-sql-mysql-create-instance - description: a test description - source: a-source + kind: tools + name: create-instance-tool + type: cloud-sql-mysql-create-instance + description: a test description + source: a-source `, want: server.ToolConfigs{ "create-instance-tool": cloudsqlmysqlcreateinstance.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) } }) diff --git a/internal/tools/cloudsqlpg/cloudsqlpgcreateinstances/cloudsqlpgcreateinstances.go b/internal/tools/cloudsqlpg/cloudsqlpgcreateinstances/cloudsqlpgcreateinstances.go index 028bab861d..2b02f3df8f 100644 --- a/internal/tools/cloudsqlpg/cloudsqlpgcreateinstances/cloudsqlpgcreateinstances.go +++ b/internal/tools/cloudsqlpg/cloudsqlpgcreateinstances/cloudsqlpgcreateinstances.go @@ -27,11 +27,11 @@ import ( sqladmin "google.golang.org/api/sqladmin/v1" ) -const kind string = "cloud-sql-postgres-create-instance" +const resourceType string = "cloud-sql-postgres-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)) } } @@ -52,7 +52,7 @@ type compatibleSource interface { // Config defines the configuration for the create-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"` @@ -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() diff --git a/internal/tools/cloudsqlpg/cloudsqlpgcreateinstances/cloudsqlpgcreateinstances_test.go b/internal/tools/cloudsqlpg/cloudsqlpgcreateinstances/cloudsqlpgcreateinstances_test.go index 03076f52c9..12dca82574 100644 --- a/internal/tools/cloudsqlpg/cloudsqlpgcreateinstances/cloudsqlpgcreateinstances_test.go +++ b/internal/tools/cloudsqlpg/cloudsqlpgcreateinstances/cloudsqlpgcreateinstances_test.go @@ -17,7 +17,6 @@ package cloudsqlpgcreateinstances_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-instance-tool: - kind: cloud-sql-postgres-create-instance - description: a test description - source: a-source + kind: tools + name: create-instance-tool + type: cloud-sql-postgres-create-instance + description: a test description + source: a-source `, want: server.ToolConfigs{ "create-instance-tool": cloudsqlpgcreateinstances.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) } }) diff --git a/internal/tools/cloudsqlpg/cloudsqlpgupgradeprecheck/cloudsqlpgupgradeprecheck.go b/internal/tools/cloudsqlpg/cloudsqlpgupgradeprecheck/cloudsqlpgupgradeprecheck.go index 4acd4a6d7c..80e6c5d39e 100644 --- a/internal/tools/cloudsqlpg/cloudsqlpgupgradeprecheck/cloudsqlpgupgradeprecheck.go +++ b/internal/tools/cloudsqlpg/cloudsqlpgupgradeprecheck/cloudsqlpgupgradeprecheck.go @@ -27,11 +27,11 @@ import ( sqladmin "google.golang.org/api/sqladmin/v1" ) -const kind string = "postgres-upgrade-precheck" +const resourceType string = "postgres-upgrade-precheck" 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 { // Config defines the configuration for the precheck-upgrade 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"` @@ -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. diff --git a/internal/tools/cloudsqlpg/cloudsqlpgupgradeprecheck/cloudsqlpgupgradeprecheck_test.go b/internal/tools/cloudsqlpg/cloudsqlpgupgradeprecheck/cloudsqlpgupgradeprecheck_test.go index 42ffc4037b..790676cd70 100644 --- a/internal/tools/cloudsqlpg/cloudsqlpgupgradeprecheck/cloudsqlpgupgradeprecheck_test.go +++ b/internal/tools/cloudsqlpg/cloudsqlpgupgradeprecheck/cloudsqlpgupgradeprecheck_test.go @@ -17,7 +17,6 @@ package cloudsqlpgupgradeprecheck_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,13 +36,13 @@ func TestParseFromYaml(t *testing.T) { { desc: "basic precheck example", in: ` - tools: - precheck-upgrade-tool: - kind: postgres-upgrade-precheck - description: a precheck test description - source: some-admin-source - authRequired: - - https://www.googleapis.com/auth/cloud-platform + kind: tools + name: precheck-upgrade-tool + type: postgres-upgrade-precheck + description: a precheck test description + source: some-admin-source + authRequired: + - https://www.googleapis.com/auth/cloud-platform `, want: server.ToolConfigs{ "precheck-upgrade-tool": cloudsqlpgupgradeprecheck.Config{ @@ -58,11 +57,11 @@ func TestParseFromYaml(t *testing.T) { { desc: "precheck example with no auth", in: ` - tools: - precheck-upgrade-tool-no-auth: - kind: postgres-upgrade-precheck - description: a precheck test description no auth - source: other-admin-source + kind: tools + name: precheck-upgrade-tool-no-auth + type: postgres-upgrade-precheck + description: a precheck test description no auth + source: other-admin-source `, want: server.ToolConfigs{ "precheck-upgrade-tool-no-auth": cloudsqlpgupgradeprecheck.Config{ @@ -77,15 +76,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 (-want +got):\n%s", diff) } }) diff --git a/internal/tools/couchbase/couchbase.go b/internal/tools/couchbase/couchbase.go index 3123b1c85b..a9ec0209ab 100644 --- a/internal/tools/couchbase/couchbase.go +++ b/internal/tools/couchbase/couchbase.go @@ -26,11 +26,11 @@ import ( "github.com/googleapis/genai-toolbox/internal/util/parameters" ) -const kind string = "couchbase-sql" +const resourceType string = "couchbase-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) { diff --git a/internal/tools/couchbase/couchbase_test.go b/internal/tools/couchbase/couchbase_test.go index 1ccc6d3555..554c871c0d 100644 --- a/internal/tools/couchbase/couchbase_test.go +++ b/internal/tools/couchbase/couchbase_test.go @@ -20,13 +20,16 @@ import ( "github.com/googleapis/genai-toolbox/internal/tools/couchbase" "github.com/googleapis/genai-toolbox/internal/util/parameters" - 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" ) -func TestParseFromYamlCouchbase(t *testing.T) { +func TestParseFromYaml(t *testing.T) { + ctx, err := testutils.ContextWithNewLogger() + if err != nil { + t.Fatalf("unexpected error: %s", err) + } tcs := []struct { desc string in string @@ -35,17 +38,17 @@ func TestParseFromYamlCouchbase(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: couchbase-sql - source: my-couchbase-instance - description: some tool description - statement: | - select * from hotel WHERE name = $hotel; - parameters: - - name: hotel - type: string - description: hotel parameter description + kind: tools + name: example_tool + type: couchbase-sql + source: my-couchbase-instance + description: some tool description + statement: | + select * from hotel WHERE name = $hotel; + parameters: + - name: hotel + type: string + description: hotel parameter description `, want: server.ToolConfigs{ "example_tool": couchbase.Config{ @@ -61,59 +64,24 @@ func TestParseFromYamlCouchbase(t *testing.T) { }, }, }, - } - for _, tc := range tcs { - t.Run(tc.desc, func(t *testing.T) { - got := struct { - Tools server.ToolConfigs `yaml:"tools"` - }{} - - // Create a context with a logger - ctx, err := testutils.ContextWithNewLogger() - if err != nil { - t.Fatalf("unable to create context with logger: %s", err) - } - - // Parse contents with context - err = yaml.UnmarshalContext(ctx, testutils.FormatYaml(tc.in), &got) - if err != nil { - t.Fatalf("unable to unmarshal: %s", err) - } - if diff := cmp.Diff(tc.want, got.Tools); diff != "" { - t.Fatalf("incorrect parse: diff %v", diff) - } - }) - } -} - -func TestParseFromYamlWithTemplateMssql(t *testing.T) { - ctx, err := testutils.ContextWithNewLogger() - if err != nil { - t.Fatalf("unexpected error: %s", err) - } - tcs := []struct { - desc string - in string - want server.ToolConfigs - }{ { - desc: "basic example", + desc: "with template", in: ` - tools: - example_tool: - kind: couchbase-sql - source: my-couchbase-instance - description: some tool description - statement: | - select * from {{.tableName}} WHERE name = $hotel; - parameters: - - name: hotel - type: string - description: hotel parameter description - templateParameters: - - name: tableName - type: string - description: The table to select hotels from. + kind: tools + name: example_tool + type: couchbase-sql + source: my-couchbase-instance + description: some tool description + statement: | + select * from {{.tableName}} WHERE name = $hotel; + parameters: + - name: hotel + type: string + description: hotel parameter description + templateParameters: + - name: tableName + type: string + description: The table to select hotels from. `, want: server.ToolConfigs{ "example_tool": couchbase.Config{ @@ -135,15 +103,11 @@ func TestParseFromYamlWithTemplateMssql(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) } }) diff --git a/internal/tools/dataform/dataformcompilelocal/dataformcompilelocal.go b/internal/tools/dataform/dataformcompilelocal/dataformcompilelocal.go index 1ce39c4567..6d523532c9 100644 --- a/internal/tools/dataform/dataformcompilelocal/dataformcompilelocal.go +++ b/internal/tools/dataform/dataformcompilelocal/dataformcompilelocal.go @@ -27,11 +27,11 @@ import ( "github.com/googleapis/genai-toolbox/internal/util/parameters" ) -const kind string = "dataform-compile-local" +const resourceType string = "dataform-compile-local" 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)) } } @@ -45,7 +45,7 @@ func newConfig(ctx context.Context, name string, decoder *yaml.Decoder) (tools.T 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" validate:"required"` AuthRequired []string `yaml:"authRequired"` } @@ -53,7 +53,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) { diff --git a/internal/tools/dataform/dataformcompilelocal/dataformcompilelocal_test.go b/internal/tools/dataform/dataformcompilelocal/dataformcompilelocal_test.go index 75dcf3841a..89cb950aea 100644 --- a/internal/tools/dataform/dataformcompilelocal/dataformcompilelocal_test.go +++ b/internal/tools/dataform/dataformcompilelocal/dataformcompilelocal_test.go @@ -17,7 +17,6 @@ package dataformcompilelocal_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,10 +36,10 @@ func TestParseFromYamlDataformCompile(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: dataform-compile-local - description: some description + kind: tools + name: example_tool + type: dataform-compile-local + description: some description `, want: server.ToolConfigs{ "example_tool": dataformcompilelocal.Config{ @@ -54,15 +53,11 @@ func TestParseFromYamlDataformCompile(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) } }) diff --git a/internal/tools/dataplex/dataplexlookupentry/dataplexlookupentry.go b/internal/tools/dataplex/dataplexlookupentry/dataplexlookupentry.go index bfac7f5afd..008defefcf 100644 --- a/internal/tools/dataplex/dataplexlookupentry/dataplexlookupentry.go +++ b/internal/tools/dataplex/dataplexlookupentry/dataplexlookupentry.go @@ -26,11 +26,11 @@ import ( "github.com/googleapis/genai-toolbox/internal/util/parameters" ) -const kind string = "dataplex-lookup-entry" +const resourceType string = "dataplex-lookup-entry" 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)) } } @@ -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"` 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) { diff --git a/internal/tools/dataplex/dataplexlookupentry/dataplexlookupentry_test.go b/internal/tools/dataplex/dataplexlookupentry/dataplexlookupentry_test.go index 25c6a755f7..514125d512 100644 --- a/internal/tools/dataplex/dataplexlookupentry/dataplexlookupentry_test.go +++ b/internal/tools/dataplex/dataplexlookupentry/dataplexlookupentry_test.go @@ -17,7 +17,6 @@ package dataplexlookupentry_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,12 +37,12 @@ func TestParseFromYamlDataplexLookupEntry(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: dataplex-lookup-entry - source: my-instance - description: some description - `, + kind: tools + name: example_tool + type: dataplex-lookup-entry + source: my-instance + description: some description + `, want: server.ToolConfigs{ "example_tool": dataplexlookupentry.Config{ Name: "example_tool", @@ -57,30 +56,30 @@ func TestParseFromYamlDataplexLookupEntry(t *testing.T) { { desc: "advanced example", in: ` - tools: - example_tool: - kind: dataplex-lookup-entry - source: my-instance - description: some description - parameters: - - name: name - type: string - description: some name description - - name: view - type: string - description: some view description - - name: aspectTypes - type: array - description: some aspect types description - default: [] - items: - name: aspectType - type: string - description: some aspect type description - - name: entry - type: string - description: some entry description - `, + kind: tools + name: example_tool + type: dataplex-lookup-entry + source: my-instance + description: some description + parameters: + - name: name + type: string + description: some name description + - name: view + type: string + description: some view description + - name: aspectTypes + type: array + description: some aspect types description + default: [] + items: + name: aspectType + type: string + description: some aspect type description + - name: entry + type: string + description: some entry description + `, want: server.ToolConfigs{ "example_tool": dataplexlookupentry.Config{ Name: "example_tool", @@ -100,18 +99,14 @@ func TestParseFromYamlDataplexLookupEntry(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) } }) } - } diff --git a/internal/tools/dataplex/dataplexsearchaspecttypes/dataplexsearchaspecttypes.go b/internal/tools/dataplex/dataplexsearchaspecttypes/dataplexsearchaspecttypes.go index f361c4e4bc..014b4db58b 100644 --- a/internal/tools/dataplex/dataplexsearchaspecttypes/dataplexsearchaspecttypes.go +++ b/internal/tools/dataplex/dataplexsearchaspecttypes/dataplexsearchaspecttypes.go @@ -26,11 +26,11 @@ import ( "github.com/googleapis/genai-toolbox/internal/util/parameters" ) -const kind string = "dataplex-search-aspect-types" +const resourceType string = "dataplex-search-aspect-types" 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)) } } @@ -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"` AuthRequired []string `yaml:"authRequired"` @@ -58,7 +58,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) { diff --git a/internal/tools/dataplex/dataplexsearchaspecttypes/dataplexsearchaspecttypes_test.go b/internal/tools/dataplex/dataplexsearchaspecttypes/dataplexsearchaspecttypes_test.go index 78ed24bbc4..cb081ca45f 100644 --- a/internal/tools/dataplex/dataplexsearchaspecttypes/dataplexsearchaspecttypes_test.go +++ b/internal/tools/dataplex/dataplexsearchaspecttypes/dataplexsearchaspecttypes_test.go @@ -17,7 +17,6 @@ package dataplexsearchaspecttypes_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 TestParseFromYamlDataplexSearchAspectTypes(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: dataplex-search-aspect-types - source: my-instance - description: some description - `, + kind: tools + name: example_tool + type: dataplex-search-aspect-types + source: my-instance + description: some description + `, want: server.ToolConfigs{ "example_tool": dataplexsearchaspecttypes.Config{ Name: "example_tool", @@ -56,18 +55,14 @@ func TestParseFromYamlDataplexSearchAspectTypes(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) } }) } - } diff --git a/internal/tools/dataplex/dataplexsearchentries/dataplexsearchentries.go b/internal/tools/dataplex/dataplexsearchentries/dataplexsearchentries.go index 41bc3c13e1..6696bf4ab1 100644 --- a/internal/tools/dataplex/dataplexsearchentries/dataplexsearchentries.go +++ b/internal/tools/dataplex/dataplexsearchentries/dataplexsearchentries.go @@ -26,11 +26,11 @@ import ( "github.com/googleapis/genai-toolbox/internal/util/parameters" ) -const kind string = "dataplex-search-entries" +const resourceType string = "dataplex-search-entries" 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)) } } @@ -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"` AuthRequired []string `yaml:"authRequired"` @@ -58,7 +58,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) { diff --git a/internal/tools/dataplex/dataplexsearchentries/dataplexsearchentries_test.go b/internal/tools/dataplex/dataplexsearchentries/dataplexsearchentries_test.go index ae149f9cca..e8b80883ac 100644 --- a/internal/tools/dataplex/dataplexsearchentries/dataplexsearchentries_test.go +++ b/internal/tools/dataplex/dataplexsearchentries/dataplexsearchentries_test.go @@ -17,7 +17,6 @@ package dataplexsearchentries_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 TestParseFromYamlDataplexSearchEntries(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: dataplex-search-entries - source: my-instance - description: some description - `, + kind: tools + name: example_tool + type: dataplex-search-entries + source: my-instance + description: some description + `, want: server.ToolConfigs{ "example_tool": dataplexsearchentries.Config{ Name: "example_tool", @@ -56,18 +55,14 @@ func TestParseFromYamlDataplexSearchEntries(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) } }) } - } diff --git a/internal/tools/dgraph/dgraph.go b/internal/tools/dgraph/dgraph.go index d3fadcd84b..5ca872e574 100644 --- a/internal/tools/dgraph/dgraph.go +++ b/internal/tools/dgraph/dgraph.go @@ -26,11 +26,11 @@ import ( "github.com/googleapis/genai-toolbox/internal/util/parameters" ) -const kind string = "dgraph-dql" +const resourceType string = "dgraph-dql" 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"` @@ -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) { diff --git a/internal/tools/dgraph/dgraph_test.go b/internal/tools/dgraph/dgraph_test.go index f0ef6a9167..08ea32e2e4 100644 --- a/internal/tools/dgraph/dgraph_test.go +++ b/internal/tools/dgraph/dgraph_test.go @@ -17,7 +17,6 @@ package dgraph_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,15 +36,15 @@ func TestParseFromYamlDgraph(t *testing.T) { { desc: "basic query example", in: ` - tools: - example_tool: - kind: dgraph-dql - source: my-dgraph-instance - description: some tool description - isQuery: true - timeout: 20s - statement: | - query {q(func: eq(email, "example@email.com")) {email}} + kind: tools + name: example_tool + type: dgraph-dql + source: my-dgraph-instance + description: some tool description + isQuery: true + timeout: 20s + statement: | + query {q(func: eq(email, "example@email.com")) {email}} `, want: server.ToolConfigs{ "example_tool": dgraph.Config{ @@ -63,13 +62,13 @@ func TestParseFromYamlDgraph(t *testing.T) { { desc: "basic mutation example", in: ` - tools: - example_tool: - kind: dgraph-dql - source: my-dgraph-instance - description: some tool description - statement: | - mutation {set { _:a "a@email.com" . _:b "b@email.com" .}} + kind: tools + name: example_tool + type: dgraph-dql + source: my-dgraph-instance + description: some tool description + statement: | + mutation {set { _:a "a@email.com" . _:b "b@email.com" .}} `, want: server.ToolConfigs{ "example_tool": dgraph.Config{ @@ -85,15 +84,11 @@ func TestParseFromYamlDgraph(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) } }) diff --git a/internal/tools/elasticsearch/elasticsearchesql/elasticsearchesql.go b/internal/tools/elasticsearch/elasticsearchesql/elasticsearchesql.go index b5f857184d..bb6f72a98b 100644 --- a/internal/tools/elasticsearch/elasticsearchesql/elasticsearchesql.go +++ b/internal/tools/elasticsearch/elasticsearchesql/elasticsearchesql.go @@ -28,11 +28,11 @@ import ( "github.com/googleapis/genai-toolbox/internal/tools" ) -const kind string = "elasticsearch-esql" +const resourceType string = "elasticsearch-esql" 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)) } } @@ -43,7 +43,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" validate:"required"` @@ -56,7 +56,7 @@ type Config struct { var _ tools.ToolConfig = Config{} func (c Config) ToolConfigType() string { - return kind + return resourceType } func newConfig(ctx context.Context, name string, decoder *yaml.Decoder) (tools.ToolConfig, error) { diff --git a/internal/tools/elasticsearch/elasticsearchesql/elasticsearchesql_test.go b/internal/tools/elasticsearch/elasticsearchesql/elasticsearchesql_test.go index 27e8abfdb7..aca93acdb4 100644 --- a/internal/tools/elasticsearch/elasticsearchesql/elasticsearchesql_test.go +++ b/internal/tools/elasticsearch/elasticsearchesql/elasticsearchesql_test.go @@ -17,7 +17,6 @@ package elasticsearchesql 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,14 +36,14 @@ func TestParseFromYamlElasticsearchEsql(t *testing.T) { { desc: "basic search example", in: ` - tools: - example_tool: - kind: elasticsearch-esql - source: my-elasticsearch-instance - description: Elasticsearch ES|QL tool - query: | - FROM my-index - | KEEP first_name, last_name + kind: tools + name: example_tool + type: elasticsearch-esql + source: my-elasticsearch-instance + description: Elasticsearch ES|QL tool + query: | + FROM my-index + | KEEP first_name, last_name `, want: server.ToolConfigs{ "example_tool": Config{ @@ -60,18 +59,18 @@ func TestParseFromYamlElasticsearchEsql(t *testing.T) { { desc: "search with customizable limit parameter", in: ` - tools: - example_tool: - kind: elasticsearch-esql - source: my-elasticsearch-instance - description: Elasticsearch ES|QL tool with customizable limit - parameters: - - name: limit - type: integer - description: Limit the number of results - query: | - FROM my-index - | LIMIT ?limit + kind: tools + name: example_tool + type: elasticsearch-esql + source: my-elasticsearch-instance + description: Elasticsearch ES|QL tool with customizable limit + parameters: + - name: limit + type: integer + description: Limit the number of results + query: | + FROM my-index + | LIMIT ?limit `, want: server.ToolConfigs{ "example_tool": Config{ @@ -91,15 +90,12 @@ func TestParseFromYamlElasticsearchEsql(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) } }) diff --git a/internal/tools/firebird/firebirdexecutesql/firebirdexecutesql.go b/internal/tools/firebird/firebirdexecutesql/firebirdexecutesql.go index 28335904e5..9ef586d3ab 100644 --- a/internal/tools/firebird/firebirdexecutesql/firebirdexecutesql.go +++ b/internal/tools/firebird/firebirdexecutesql/firebirdexecutesql.go @@ -27,11 +27,11 @@ import ( "github.com/googleapis/genai-toolbox/internal/util/parameters" ) -const kind string = "firebird-execute-sql" +const resourceType string = "firebird-execute-sql" func init() { - if !tools.Register(kind, newConfig) { - panic(fmt.Sprintf("tool type %q already registered", kind)) + if !tools.Register(resourceType, newConfig) { + panic(fmt.Sprintf("tool type %q already registered", resourceType)) } } @@ -50,7 +50,7 @@ type compatibleSource interface { type Config struct { Name string `yaml:"name" validate:"required"` - Type string `yaml:"kind" validate:"required"` + Type string `yaml:"type" validate:"required"` Source string `yaml:"source" validate:"required"` Description string `yaml:"description" validate:"required"` AuthRequired []string `yaml:"authRequired"` @@ -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) { @@ -107,7 +107,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para if err != nil { return nil, fmt.Errorf("error getting logger: %s", err) } - logger.DebugContext(ctx, fmt.Sprintf("executing `%s` tool query: %s", kind, sql)) + logger.DebugContext(ctx, fmt.Sprintf("executing `%s` tool query: %s", resourceType, sql)) return source.RunSQL(ctx, sql, nil) } diff --git a/internal/tools/firebird/firebirdexecutesql/firebirdexecutesql_test.go b/internal/tools/firebird/firebirdexecutesql/firebirdexecutesql_test.go index 2afb4bb2ab..b91e68eb19 100644 --- a/internal/tools/firebird/firebirdexecutesql/firebirdexecutesql_test.go +++ b/internal/tools/firebird/firebirdexecutesql/firebirdexecutesql_test.go @@ -17,7 +17,6 @@ package firebirdexecutesql_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,14 +36,14 @@ func TestParseFromYamlExecuteSql(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: firebird-execute-sql - source: my-instance - description: some description - authRequired: - - my-google-auth-service - - other-auth-service + kind: tools + name: example_tool + type: firebird-execute-sql + source: my-instance + description: some description + authRequired: + - my-google-auth-service + - other-auth-service `, want: server.ToolConfigs{ "example_tool": firebirdexecutesql.Config{ @@ -59,15 +58,12 @@ func TestParseFromYamlExecuteSql(t *testing.T) { } for _, tc := range tcs { t.Run(tc.desc, func(t *testing.T) { - got := struct { - Tools server.ToolConfigs `yaml:"tools"` - }{} // Parse contents - err := yaml.UnmarshalContext(ctx, testutils.FormatYaml(tc.in), &got) + _, _, _, got, _, _, err := server.UnmarshalResourceConfig(ctx, testutils.FormatYaml(tc.in)) if err != nil { t.Fatalf("unable to unmarshal: %s", err) } - if diff := cmp.Diff(tc.want, got.Tools); diff != "" { + if diff := cmp.Diff(tc.want, got); diff != "" { t.Fatalf("incorrect parse: diff %v", diff) } }) diff --git a/internal/tools/firebird/firebirdsql/firebirdsql.go b/internal/tools/firebird/firebirdsql/firebirdsql.go index ecf9eaa99a..a20eb28784 100644 --- a/internal/tools/firebird/firebirdsql/firebirdsql.go +++ b/internal/tools/firebird/firebirdsql/firebirdsql.go @@ -27,11 +27,11 @@ import ( "github.com/googleapis/genai-toolbox/internal/util/parameters" ) -const kind string = "firebird-sql" +const resourceType string = "firebird-sql" func init() { - if !tools.Register(kind, newConfig) { - panic(fmt.Sprintf("tool type %q already registered", kind)) + if !tools.Register(resourceType, newConfig) { + panic(fmt.Sprintf("tool type %q already registered", resourceType)) } } @@ -50,7 +50,7 @@ type compatibleSource interface { type Config struct { Name string `yaml:"name" validate:"required"` - Type string `yaml:"kind" validate:"required"` + Type string `yaml:"type" validate:"required"` Source string `yaml:"source" validate:"required"` Description string `yaml:"description" validate:"required"` Statement string `yaml:"statement" 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) { diff --git a/internal/tools/firebird/firebirdsql/firebirdsql_test.go b/internal/tools/firebird/firebirdsql/firebirdsql_test.go index 2d9ddbcfe1..e329d237ac 100644 --- a/internal/tools/firebird/firebirdsql/firebirdsql_test.go +++ b/internal/tools/firebird/firebirdsql/firebirdsql_test.go @@ -17,7 +17,6 @@ package firebirdsql_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,25 +37,25 @@ func TestParseFromYamlFirebird(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: firebird-sql - source: my-fdb-instance - description: some description - statement: | - SELECT * FROM SQL_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 + name: example_tool + type: firebird-sql + source: my-fdb-instance + description: some description + statement: | + SELECT * FROM SQL_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": firebirdsql.Config{ @@ -77,15 +76,12 @@ func TestParseFromYamlFirebird(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) } }) @@ -106,28 +102,28 @@ func TestParseFromYamlWithTemplateParamsFirebird(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: firebird-sql - source: my-fdb-instance - description: some description - statement: | - SELECT * FROM SQL_STATEMENT; - parameters: - - name: name - 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: firebird-sql + source: my-fdb-instance + description: some description + statement: | + SELECT * FROM SQL_STATEMENT; + parameters: + - name: name + 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": firebirdsql.Config{ @@ -150,15 +146,12 @@ func TestParseFromYamlWithTemplateParamsFirebird(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) } }) diff --git a/internal/tools/firestore/firestoreadddocuments/firestoreadddocuments.go b/internal/tools/firestore/firestoreadddocuments/firestoreadddocuments.go index 8a0a47bbd6..201151b6e8 100644 --- a/internal/tools/firestore/firestoreadddocuments/firestoreadddocuments.go +++ b/internal/tools/firestore/firestoreadddocuments/firestoreadddocuments.go @@ -27,14 +27,14 @@ import ( "github.com/googleapis/genai-toolbox/internal/util/parameters" ) -const kind string = "firestore-add-documents" +const resourceType string = "firestore-add-documents" const collectionPathKey string = "collectionPath" const documentDataKey string = "documentData" const returnDocumentDataKey string = "returnData" 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)) } } @@ -53,7 +53,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"` @@ -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) { diff --git a/internal/tools/firestore/firestoreadddocuments/firestoreadddocuments_test.go b/internal/tools/firestore/firestoreadddocuments/firestoreadddocuments_test.go index c9009b5e8d..62ad017c7d 100644 --- a/internal/tools/firestore/firestoreadddocuments/firestoreadddocuments_test.go +++ b/internal/tools/firestore/firestoreadddocuments/firestoreadddocuments_test.go @@ -17,7 +17,6 @@ package firestoreadddocuments_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 TestParseFromYamlFirestoreAddDocuments(t *testing.T) { { desc: "basic example", in: ` - tools: - add_docs_tool: - kind: firestore-add-documents - source: my-firestore-instance - description: Add documents to Firestore collections + kind: tools + name: add_docs_tool + type: firestore-add-documents + source: my-firestore-instance + description: Add documents to Firestore collections `, want: server.ToolConfigs{ "add_docs_tool": firestoreadddocuments.Config{ @@ -56,14 +55,14 @@ func TestParseFromYamlFirestoreAddDocuments(t *testing.T) { { desc: "with auth requirements", in: ` - tools: - secure_add_docs: - kind: firestore-add-documents - source: prod-firestore - description: Add documents with authentication - authRequired: - - google-auth-service - - api-key-service + kind: tools + name: secure_add_docs + type: firestore-add-documents + source: prod-firestore + description: Add documents with authentication + authRequired: + - google-auth-service + - api-key-service `, want: server.ToolConfigs{ "secure_add_docs": firestoreadddocuments.Config{ @@ -78,15 +77,11 @@ func TestParseFromYamlFirestoreAddDocuments(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) } }) @@ -99,24 +94,28 @@ func TestParseFromYamlMultipleTools(t *testing.T) { t.Fatalf("unexpected error: %s", err) } in := ` - tools: - add_user_docs: - kind: firestore-add-documents - source: users-firestore - description: Add user documents - authRequired: - - user-auth - add_product_docs: - kind: firestore-add-documents - source: products-firestore - description: Add product documents - add_order_docs: - kind: firestore-add-documents - source: orders-firestore - description: Add order documents - authRequired: - - user-auth - - admin-auth + kind: tools + name: add_user_docs + type: firestore-add-documents + source: users-firestore + description: Add user documents + authRequired: + - user-auth +--- + kind: tools + name: add_product_docs + type: firestore-add-documents + source: products-firestore + description: Add product documents +--- + kind: tools + name: add_order_docs + type: firestore-add-documents + source: orders-firestore + description: Add order documents + authRequired: + - user-auth + - admin-auth ` want := server.ToolConfigs{ "add_user_docs": firestoreadddocuments.Config{ @@ -141,16 +140,11 @@ func TestParseFromYamlMultipleTools(t *testing.T) { AuthRequired: []string{"user-auth", "admin-auth"}, }, } - - got := struct { - Tools server.ToolConfigs `yaml:"tools"` - }{} - // Parse contents - err = yaml.UnmarshalContext(ctx, testutils.FormatYaml(in), &got) + _, _, _, got, _, _, err := server.UnmarshalResourceConfig(ctx, testutils.FormatYaml(in)) if err != nil { t.Fatalf("unable to unmarshal: %s", err) } - if diff := cmp.Diff(want, got.Tools); diff != "" { + if diff := cmp.Diff(want, got); diff != "" { t.Fatalf("incorrect parse: diff %v", diff) } } diff --git a/internal/tools/firestore/firestoredeletedocuments/firestoredeletedocuments.go b/internal/tools/firestore/firestoredeletedocuments/firestoredeletedocuments.go index 4e45dad7f7..c969b39430 100644 --- a/internal/tools/firestore/firestoredeletedocuments/firestoredeletedocuments.go +++ b/internal/tools/firestore/firestoredeletedocuments/firestoredeletedocuments.go @@ -27,12 +27,12 @@ import ( "github.com/googleapis/genai-toolbox/internal/util/parameters" ) -const kind string = "firestore-delete-documents" +const resourceType string = "firestore-delete-documents" const documentPathsKey string = "documentPaths" 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) { diff --git a/internal/tools/firestore/firestoredeletedocuments/firestoredeletedocuments_test.go b/internal/tools/firestore/firestoredeletedocuments/firestoredeletedocuments_test.go index 6a9e438b55..fe02e2d6c2 100644 --- a/internal/tools/firestore/firestoredeletedocuments/firestoredeletedocuments_test.go +++ b/internal/tools/firestore/firestoredeletedocuments/firestoredeletedocuments_test.go @@ -17,7 +17,6 @@ package firestoredeletedocuments_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 TestParseFromYamlFirestoreDeleteDocuments(t *testing.T) { { desc: "basic example", in: ` - tools: - delete_docs_tool: - kind: firestore-delete-documents - source: my-firestore-instance - description: Delete documents from Firestore by paths + kind: tools + name: delete_docs_tool + type: firestore-delete-documents + source: my-firestore-instance + description: Delete documents from Firestore by paths `, want: server.ToolConfigs{ "delete_docs_tool": firestoredeletedocuments.Config{ @@ -56,14 +55,14 @@ func TestParseFromYamlFirestoreDeleteDocuments(t *testing.T) { { desc: "with auth requirements", in: ` - tools: - secure_delete_docs: - kind: firestore-delete-documents - source: prod-firestore - description: Delete documents with authentication - authRequired: - - google-auth-service - - api-key-service + kind: tools + name: secure_delete_docs + type: firestore-delete-documents + source: prod-firestore + description: Delete documents with authentication + authRequired: + - google-auth-service + - api-key-service `, want: server.ToolConfigs{ "secure_delete_docs": firestoredeletedocuments.Config{ @@ -78,15 +77,11 @@ func TestParseFromYamlFirestoreDeleteDocuments(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) } }) @@ -99,24 +94,28 @@ func TestParseFromYamlMultipleTools(t *testing.T) { t.Fatalf("unexpected error: %s", err) } in := ` - tools: - delete_user_docs: - kind: firestore-delete-documents - source: users-firestore - description: Delete user documents - authRequired: - - user-auth - delete_product_docs: - kind: firestore-delete-documents - source: products-firestore - description: Delete product documents - delete_order_docs: - kind: firestore-delete-documents - source: orders-firestore - description: Delete order documents - authRequired: - - user-auth - - admin-auth + kind: tools + name: delete_user_docs + type: firestore-delete-documents + source: users-firestore + description: Delete user documents + authRequired: + - user-auth +--- + kind: tools + name: delete_product_docs + type: firestore-delete-documents + source: products-firestore + description: Delete product documents +--- + kind: tools + name: delete_order_docs + type: firestore-delete-documents + source: orders-firestore + description: Delete order documents + authRequired: + - user-auth + - admin-auth ` want := server.ToolConfigs{ "delete_user_docs": firestoredeletedocuments.Config{ @@ -142,15 +141,11 @@ func TestParseFromYamlMultipleTools(t *testing.T) { }, } - got := struct { - Tools server.ToolConfigs `yaml:"tools"` - }{} - // Parse contents - err = yaml.UnmarshalContext(ctx, testutils.FormatYaml(in), &got) + _, _, _, got, _, _, err := server.UnmarshalResourceConfig(ctx, testutils.FormatYaml(in)) if err != nil { t.Fatalf("unable to unmarshal: %s", err) } - if diff := cmp.Diff(want, got.Tools); diff != "" { + if diff := cmp.Diff(want, got); diff != "" { t.Fatalf("incorrect parse: diff %v", diff) } } diff --git a/internal/tools/firestore/firestoregetdocuments/firestoregetdocuments.go b/internal/tools/firestore/firestoregetdocuments/firestoregetdocuments.go index e7aa326d1e..7bcc815a4c 100644 --- a/internal/tools/firestore/firestoregetdocuments/firestoregetdocuments.go +++ b/internal/tools/firestore/firestoregetdocuments/firestoregetdocuments.go @@ -27,12 +27,12 @@ import ( "github.com/googleapis/genai-toolbox/internal/util/parameters" ) -const kind string = "firestore-get-documents" +const resourceType string = "firestore-get-documents" const documentPathsKey string = "documentPaths" 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) { diff --git a/internal/tools/firestore/firestoregetdocuments/firestoregetdocuments_test.go b/internal/tools/firestore/firestoregetdocuments/firestoregetdocuments_test.go index 3b8dfb57a5..5a44b9d687 100644 --- a/internal/tools/firestore/firestoregetdocuments/firestoregetdocuments_test.go +++ b/internal/tools/firestore/firestoregetdocuments/firestoregetdocuments_test.go @@ -17,7 +17,6 @@ package firestoregetdocuments_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 TestParseFromYamlFirestoreGetDocuments(t *testing.T) { { desc: "basic example", in: ` - tools: - get_docs_tool: - kind: firestore-get-documents - source: my-firestore-instance - description: Retrieve documents from Firestore by paths + kind: tools + name: get_docs_tool + type: firestore-get-documents + source: my-firestore-instance + description: Retrieve documents from Firestore by paths `, want: server.ToolConfigs{ "get_docs_tool": firestoregetdocuments.Config{ @@ -56,14 +55,14 @@ func TestParseFromYamlFirestoreGetDocuments(t *testing.T) { { desc: "with auth requirements", in: ` - tools: - secure_get_docs: - kind: firestore-get-documents - source: prod-firestore - description: Get documents with authentication - authRequired: - - google-auth-service - - api-key-service + kind: tools + name: secure_get_docs + type: firestore-get-documents + source: prod-firestore + description: Get documents with authentication + authRequired: + - google-auth-service + - api-key-service `, want: server.ToolConfigs{ "secure_get_docs": firestoregetdocuments.Config{ @@ -78,15 +77,11 @@ func TestParseFromYamlFirestoreGetDocuments(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) } }) @@ -99,24 +94,28 @@ func TestParseFromYamlMultipleTools(t *testing.T) { t.Fatalf("unexpected error: %s", err) } in := ` - tools: - get_user_docs: - kind: firestore-get-documents - source: users-firestore - description: Get user documents - authRequired: - - user-auth - get_product_docs: - kind: firestore-get-documents - source: products-firestore - description: Get product documents - get_order_docs: - kind: firestore-get-documents - source: orders-firestore - description: Get order documents - authRequired: - - user-auth - - admin-auth + kind: tools + name: get_user_docs + type: firestore-get-documents + source: users-firestore + description: Get user documents + authRequired: + - user-auth +--- + kind: tools + name: get_product_docs + type: firestore-get-documents + source: products-firestore + description: Get product documents +--- + kind: tools + name: get_order_docs + type: firestore-get-documents + source: orders-firestore + description: Get order documents + authRequired: + - user-auth + - admin-auth ` want := server.ToolConfigs{ "get_user_docs": firestoregetdocuments.Config{ @@ -142,15 +141,11 @@ func TestParseFromYamlMultipleTools(t *testing.T) { }, } - got := struct { - Tools server.ToolConfigs `yaml:"tools"` - }{} - // Parse contents - err = yaml.UnmarshalContext(ctx, testutils.FormatYaml(in), &got) + _, _, _, got, _, _, err := server.UnmarshalResourceConfig(ctx, testutils.FormatYaml(in)) if err != nil { t.Fatalf("unable to unmarshal: %s", err) } - if diff := cmp.Diff(want, got.Tools); diff != "" { + if diff := cmp.Diff(want, got); diff != "" { t.Fatalf("incorrect parse: diff %v", diff) } } diff --git a/internal/tools/firestore/firestoregetrules/firestoregetrules.go b/internal/tools/firestore/firestoregetrules/firestoregetrules.go index 84723dd8b6..b8108fa089 100644 --- a/internal/tools/firestore/firestoregetrules/firestoregetrules.go +++ b/internal/tools/firestore/firestoregetrules/firestoregetrules.go @@ -26,11 +26,11 @@ import ( "google.golang.org/api/firebaserules/v1" ) -const kind string = "firestore-get-rules" +const resourceType string = "firestore-get-rules" 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) { diff --git a/internal/tools/firestore/firestoregetrules/firestoregetrules_test.go b/internal/tools/firestore/firestoregetrules/firestoregetrules_test.go index 43a80a7bc0..c4a7dfb6bb 100644 --- a/internal/tools/firestore/firestoregetrules/firestoregetrules_test.go +++ b/internal/tools/firestore/firestoregetrules/firestoregetrules_test.go @@ -17,7 +17,6 @@ package firestoregetrules_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 TestParseFromYamlFirestoreGetRules(t *testing.T) { { desc: "basic example", in: ` - tools: - get_rules_tool: - kind: firestore-get-rules - source: my-firestore-instance - description: Retrieves the active Firestore security rules for the current project + kind: tools + name: get_rules_tool + type: firestore-get-rules + source: my-firestore-instance + description: Retrieves the active Firestore security rules for the current project `, want: server.ToolConfigs{ "get_rules_tool": firestoregetrules.Config{ @@ -56,14 +55,14 @@ func TestParseFromYamlFirestoreGetRules(t *testing.T) { { desc: "with auth requirements", in: ` - tools: - secure_get_rules: - kind: firestore-get-rules - source: prod-firestore - description: Get Firestore security rules with authentication - authRequired: - - google-auth-service - - admin-service + kind: tools + name: secure_get_rules + type: firestore-get-rules + source: prod-firestore + description: Get Firestore security rules with authentication + authRequired: + - google-auth-service + - admin-service `, want: server.ToolConfigs{ "secure_get_rules": firestoregetrules.Config{ @@ -78,15 +77,11 @@ func TestParseFromYamlFirestoreGetRules(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) } }) @@ -99,24 +94,28 @@ func TestParseFromYamlMultipleTools(t *testing.T) { t.Fatalf("unexpected error: %s", err) } in := ` - tools: - get_dev_rules: - kind: firestore-get-rules - source: dev-firestore - description: Get development Firestore rules - authRequired: - - dev-auth - get_staging_rules: - kind: firestore-get-rules - source: staging-firestore - description: Get staging Firestore rules - get_prod_rules: - kind: firestore-get-rules - source: prod-firestore - description: Get production Firestore rules - authRequired: - - prod-auth - - admin-auth + kind: tools + name: get_dev_rules + type: firestore-get-rules + source: dev-firestore + description: Get development Firestore rules + authRequired: + - dev-auth +--- + kind: tools + name: get_staging_rules + type: firestore-get-rules + source: staging-firestore + description: Get staging Firestore rules +--- + kind: tools + name: get_prod_rules + type: firestore-get-rules + source: prod-firestore + description: Get production Firestore rules + authRequired: + - prod-auth + - admin-auth ` want := server.ToolConfigs{ "get_dev_rules": firestoregetrules.Config{ @@ -142,15 +141,11 @@ func TestParseFromYamlMultipleTools(t *testing.T) { }, } - got := struct { - Tools server.ToolConfigs `yaml:"tools"` - }{} - // Parse contents - err = yaml.UnmarshalContext(ctx, testutils.FormatYaml(in), &got) + _, _, _, got, _, _, err := server.UnmarshalResourceConfig(ctx, testutils.FormatYaml(in)) if err != nil { t.Fatalf("unable to unmarshal: %s", err) } - if diff := cmp.Diff(want, got.Tools); diff != "" { + if diff := cmp.Diff(want, got); diff != "" { t.Fatalf("incorrect parse: diff %v", diff) } } diff --git a/internal/tools/firestore/firestorelistcollections/firestorelistcollections.go b/internal/tools/firestore/firestorelistcollections/firestorelistcollections.go index c3f0253979..7b4f93e3bf 100644 --- a/internal/tools/firestore/firestorelistcollections/firestorelistcollections.go +++ b/internal/tools/firestore/firestorelistcollections/firestorelistcollections.go @@ -27,12 +27,12 @@ import ( "github.com/googleapis/genai-toolbox/internal/util/parameters" ) -const kind string = "firestore-list-collections" +const resourceType string = "firestore-list-collections" const parentPathKey string = "parentPath" 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) { diff --git a/internal/tools/firestore/firestorelistcollections/firestorelistcollections_test.go b/internal/tools/firestore/firestorelistcollections/firestorelistcollections_test.go index 3f33b11d1b..1b8b374a8e 100644 --- a/internal/tools/firestore/firestorelistcollections/firestorelistcollections_test.go +++ b/internal/tools/firestore/firestorelistcollections/firestorelistcollections_test.go @@ -17,7 +17,6 @@ package firestorelistcollections_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 TestParseFromYamlFirestoreListCollections(t *testing.T) { { desc: "basic example", in: ` - tools: - list_collections_tool: - kind: firestore-list-collections - source: my-firestore-instance - description: List collections in Firestore + kind: tools + name: list_collections_tool + type: firestore-list-collections + source: my-firestore-instance + description: List collections in Firestore `, want: server.ToolConfigs{ "list_collections_tool": firestorelistcollections.Config{ @@ -56,14 +55,14 @@ func TestParseFromYamlFirestoreListCollections(t *testing.T) { { desc: "with auth requirements", in: ` - tools: - secure_list_collections: - kind: firestore-list-collections - source: prod-firestore - description: List collections with authentication - authRequired: - - google-auth-service - - api-key-service + kind: tools + name: secure_list_collections + type: firestore-list-collections + source: prod-firestore + description: List collections with authentication + authRequired: + - google-auth-service + - api-key-service `, want: server.ToolConfigs{ "secure_list_collections": firestorelistcollections.Config{ @@ -78,15 +77,11 @@ func TestParseFromYamlFirestoreListCollections(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) } }) @@ -99,24 +94,28 @@ func TestParseFromYamlMultipleTools(t *testing.T) { t.Fatalf("unexpected error: %s", err) } in := ` - tools: - list_user_collections: - kind: firestore-list-collections - source: users-firestore - description: List user-related collections - authRequired: - - user-auth - list_product_collections: - kind: firestore-list-collections - source: products-firestore - description: List product-related collections - list_admin_collections: - kind: firestore-list-collections - source: admin-firestore - description: List administrative collections - authRequired: - - user-auth - - admin-auth + kind: tools + name: list_user_collections + type: firestore-list-collections + source: users-firestore + description: List user-related collections + authRequired: + - user-auth +--- + kind: tools + name: list_product_collections + type: firestore-list-collections + source: products-firestore + description: List product-related collections +--- + kind: tools + name: list_admin_collections + type: firestore-list-collections + source: admin-firestore + description: List administrative collections + authRequired: + - user-auth + - admin-auth ` want := server.ToolConfigs{ "list_user_collections": firestorelistcollections.Config{ @@ -142,15 +141,11 @@ func TestParseFromYamlMultipleTools(t *testing.T) { }, } - got := struct { - Tools server.ToolConfigs `yaml:"tools"` - }{} - // Parse contents - err = yaml.UnmarshalContext(ctx, testutils.FormatYaml(in), &got) + _, _, _, got, _, _, err := server.UnmarshalResourceConfig(ctx, testutils.FormatYaml(in)) if err != nil { t.Fatalf("unable to unmarshal: %s", err) } - if diff := cmp.Diff(want, got.Tools); diff != "" { + if diff := cmp.Diff(want, got); diff != "" { t.Fatalf("incorrect parse: diff %v", diff) } } diff --git a/internal/tools/firestore/firestorequery/firestorequery.go b/internal/tools/firestore/firestorequery/firestorequery.go index 7c7e879a22..b815fda43e 100644 --- a/internal/tools/firestore/firestorequery/firestorequery.go +++ b/internal/tools/firestore/firestorequery/firestorequery.go @@ -32,13 +32,13 @@ import ( // Constants for tool configuration const ( - kind = "firestore-query" + resourceType = "firestore-query" defaultLimit = 100 ) 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,7 +60,7 @@ type compatibleSource interface { // Config represents the configuration for the Firestore query 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" validate:"required"` AuthRequired []string `yaml:"authRequired"` @@ -80,9 +80,9 @@ type Config struct { // validate interface var _ tools.ToolConfig = Config{} -// ToolConfigType returns the kind of tool configuration +// ToolConfigType returns the type of tool configuration func (cfg Config) ToolConfigType() string { - return kind + return resourceType } // Initialize creates a new Tool instance from the configuration diff --git a/internal/tools/firestore/firestorequery/firestorequery_test.go b/internal/tools/firestore/firestorequery/firestorequery_test.go index 7a8d27d853..380b1b26d1 100644 --- a/internal/tools/firestore/firestorequery/firestorequery_test.go +++ b/internal/tools/firestore/firestorequery/firestorequery_test.go @@ -17,7 +17,6 @@ package firestorequery_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 TestParseFromYamlFirestoreQuery(t *testing.T) { { desc: "basic example with parameterized collection path", in: ` - tools: - query_users_tool: - kind: firestore-query - source: my-firestore-instance - description: Query users collection with parameterized path - collectionPath: "users/{{.userId}}/documents" - parameters: - - name: userId - type: string - description: The user ID to query documents for - required: true + kind: tools + name: query_users_tool + type: firestore-query + source: my-firestore-instance + description: Query users collection with parameterized path + collectionPath: "users/{{.userId}}/documents" + parameters: + - name: userId + type: string + description: The user ID to query documents for + required: true `, want: server.ToolConfigs{ "query_users_tool": firestorequery.Config{ @@ -67,28 +66,28 @@ func TestParseFromYamlFirestoreQuery(t *testing.T) { { desc: "with parameterized filters", in: ` - tools: - query_products_tool: - kind: firestore-query - source: prod-firestore - description: Query products with dynamic filters - collectionPath: "products" - filters: | - { - "and": [ - {"field": "category", "op": "==", "value": {"stringValue": "{{.category}}"}}, - {"field": "price", "op": "<=", "value": {"doubleValue": {{.maxPrice}}}} - ] - } - parameters: - - name: category - type: string - description: Product category to filter by - required: true - - name: maxPrice - type: float - description: Maximum price for products - required: true + kind: tools + name: query_products_tool + type: firestore-query + source: prod-firestore + description: Query products with dynamic filters + collectionPath: "products" + filters: | + { + "and": [ + {"field": "category", "op": "==", "value": {"stringValue": "{{.category}}"}}, + {"field": "price", "op": "<=", "value": {"doubleValue": {{.maxPrice}}}} + ] + } + parameters: + - name: category + type: string + description: Product category to filter by + required: true + - name: maxPrice + type: float + description: Maximum price for products + required: true `, want: server.ToolConfigs{ "query_products_tool": firestorequery.Config{ @@ -98,10 +97,10 @@ func TestParseFromYamlFirestoreQuery(t *testing.T) { Description: "Query products with dynamic filters", CollectionPath: "products", Filters: `{ - "and": [ - {"field": "category", "op": "==", "value": {"stringValue": "{{.category}}"}}, - {"field": "price", "op": "<=", "value": {"doubleValue": {{.maxPrice}}}} - ] + "and": [ + {"field": "category", "op": "==", "value": {"stringValue": "{{.category}}"}}, + {"field": "price", "op": "<=", "value": {"doubleValue": {{.maxPrice}}}} + ] } `, AuthRequired: []string{}, @@ -115,25 +114,25 @@ func TestParseFromYamlFirestoreQuery(t *testing.T) { { desc: "with select fields and orderBy", in: ` - tools: - query_orders_tool: - kind: firestore-query - source: orders-firestore - description: Query orders with field selection - collectionPath: "orders" - select: - - orderId - - customerName - - totalAmount - orderBy: - field: "{{.sortField}}" - direction: "DESCENDING" - limit: 50 - parameters: - - name: sortField - type: string - description: Field to sort by - required: true + kind: tools + name: query_orders_tool + type: firestore-query + source: orders-firestore + description: Query orders with field selection + collectionPath: "orders" + select: + - orderId + - customerName + - totalAmount + orderBy: + field: "{{.sortField}}" + direction: "DESCENDING" + limit: 50 + parameters: + - name: sortField + type: string + description: Field to sort by + required: true `, want: server.ToolConfigs{ "query_orders_tool": firestorequery.Config{ @@ -158,41 +157,41 @@ func TestParseFromYamlFirestoreQuery(t *testing.T) { { desc: "with auth requirements and complex filters", in: ` - tools: - secure_query_tool: - kind: firestore-query - source: secure-firestore - description: Query with authentication and complex filters - collectionPath: "{{.collection}}" - filters: | - { - "or": [ - { - "and": [ - {"field": "status", "op": "==", "value": {"stringValue": "{{.status}}"}}, - {"field": "priority", "op": ">=", "value": {"integerValue": "{{.minPriority}}"}} - ] - }, - {"field": "urgent", "op": "==", "value": {"booleanValue": true}} - ] - } - analyzeQuery: true - authRequired: - - google-auth-service - - api-key-service - parameters: - - name: collection - type: string - description: Collection name to query - required: true - - name: status - type: string - description: Status to filter by - required: true - - name: minPriority - type: integer - description: Minimum priority level - default: 1 + kind: tools + name: secure_query_tool + type: firestore-query + source: secure-firestore + description: Query with authentication and complex filters + collectionPath: "{{.collection}}" + filters: | + { + "or": [ + { + "and": [ + {"field": "status", "op": "==", "value": {"stringValue": "{{.status}}"}}, + {"field": "priority", "op": ">=", "value": {"integerValue": "{{.minPriority}}"}} + ] + }, + {"field": "urgent", "op": "==", "value": {"booleanValue": true}} + ] + } + analyzeQuery: true + authRequired: + - google-auth-service + - api-key-service + parameters: + - name: collection + type: string + description: Collection name to query + required: true + - name: status + type: string + description: Status to filter by + required: true + - name: minPriority + type: integer + description: Minimum priority level + default: 1 `, want: server.ToolConfigs{ "secure_query_tool": firestorequery.Config{ @@ -202,15 +201,15 @@ func TestParseFromYamlFirestoreQuery(t *testing.T) { Description: "Query with authentication and complex filters", CollectionPath: "{{.collection}}", Filters: `{ - "or": [ - { - "and": [ - {"field": "status", "op": "==", "value": {"stringValue": "{{.status}}"}}, - {"field": "priority", "op": ">=", "value": {"integerValue": "{{.minPriority}}"}} - ] - }, - {"field": "urgent", "op": "==", "value": {"booleanValue": true}} - ] + "or": [ + { + "and": [ + {"field": "status", "op": "==", "value": {"stringValue": "{{.status}}"}}, + {"field": "priority", "op": ">=", "value": {"integerValue": "{{.minPriority}}"}} + ] + }, + {"field": "urgent", "op": "==", "value": {"booleanValue": true}} + ] } `, AnalyzeQuery: true, @@ -226,49 +225,49 @@ func TestParseFromYamlFirestoreQuery(t *testing.T) { { desc: "with Firestore native JSON value types and template parameters", in: ` - tools: - query_with_typed_values: - kind: firestore-query - source: typed-firestore - description: Query with Firestore native JSON value types - collectionPath: "countries" - filters: | - { - "or": [ - {"field": "continent", "op": "==", "value": {"stringValue": "{{.continent}}"}}, - { - "and": [ - {"field": "area", "op": ">", "value": {"integerValue": "2000000"}}, - {"field": "area", "op": "<", "value": {"integerValue": "3000000"}}, - {"field": "population", "op": ">=", "value": {"integerValue": "{{.minPopulation}}"}}, - {"field": "gdp", "op": ">", "value": {"doubleValue": {{.minGdp}}}}, - {"field": "isActive", "op": "==", "value": {"booleanValue": {{.isActive}}}}, - {"field": "lastUpdated", "op": ">=", "value": {"timestampValue": "{{.startDate}}"}} - ] - } - ] - } - parameters: - - name: continent - type: string - description: Continent to filter by - required: true - - name: minPopulation - type: string - description: Minimum population as string - required: true - - name: minGdp - type: float - description: Minimum GDP value - required: true - - name: isActive - type: boolean - description: Filter by active status - required: true - - name: startDate - type: string - description: Start date in RFC3339 format - required: true + kind: tools + name: query_with_typed_values + type: firestore-query + source: typed-firestore + description: Query with Firestore native JSON value types + collectionPath: "countries" + filters: | + { + "or": [ + {"field": "continent", "op": "==", "value": {"stringValue": "{{.continent}}"}}, + { + "and": [ + {"field": "area", "op": ">", "value": {"integerValue": "2000000"}}, + {"field": "area", "op": "<", "value": {"integerValue": "3000000"}}, + {"field": "population", "op": ">=", "value": {"integerValue": "{{.minPopulation}}"}}, + {"field": "gdp", "op": ">", "value": {"doubleValue": {{.minGdp}}}}, + {"field": "isActive", "op": "==", "value": {"booleanValue": {{.isActive}}}}, + {"field": "lastUpdated", "op": ">=", "value": {"timestampValue": "{{.startDate}}"}} + ] + } + ] + } + parameters: + - name: continent + type: string + description: Continent to filter by + required: true + - name: minPopulation + type: string + description: Minimum population as string + required: true + - name: minGdp + type: float + description: Minimum GDP value + required: true + - name: isActive + type: boolean + description: Filter by active status + required: true + - name: startDate + type: string + description: Start date in RFC3339 format + required: true `, want: server.ToolConfigs{ "query_with_typed_values": firestorequery.Config{ @@ -278,19 +277,19 @@ func TestParseFromYamlFirestoreQuery(t *testing.T) { Description: "Query with Firestore native JSON value types", CollectionPath: "countries", Filters: `{ - "or": [ - {"field": "continent", "op": "==", "value": {"stringValue": "{{.continent}}"}}, - { - "and": [ - {"field": "area", "op": ">", "value": {"integerValue": "2000000"}}, - {"field": "area", "op": "<", "value": {"integerValue": "3000000"}}, - {"field": "population", "op": ">=", "value": {"integerValue": "{{.minPopulation}}"}}, - {"field": "gdp", "op": ">", "value": {"doubleValue": {{.minGdp}}}}, - {"field": "isActive", "op": "==", "value": {"booleanValue": {{.isActive}}}}, - {"field": "lastUpdated", "op": ">=", "value": {"timestampValue": "{{.startDate}}"}} - ] - } - ] + "or": [ + {"field": "continent", "op": "==", "value": {"stringValue": "{{.continent}}"}}, + { + "and": [ + {"field": "area", "op": ">", "value": {"integerValue": "2000000"}}, + {"field": "area", "op": "<", "value": {"integerValue": "3000000"}}, + {"field": "population", "op": ">=", "value": {"integerValue": "{{.minPopulation}}"}}, + {"field": "gdp", "op": ">", "value": {"doubleValue": {{.minGdp}}}}, + {"field": "isActive", "op": "==", "value": {"booleanValue": {{.isActive}}}}, + {"field": "lastUpdated", "op": ">=", "value": {"timestampValue": "{{.startDate}}"}} + ] + } + ] } `, AuthRequired: []string{}, @@ -307,15 +306,12 @@ func TestParseFromYamlFirestoreQuery(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) } }) @@ -328,89 +324,93 @@ func TestParseFromYamlMultipleQueryTools(t *testing.T) { t.Fatalf("unexpected error: %s", err) } in := ` - tools: - query_user_posts: - kind: firestore-query - source: social-firestore - description: Query user posts with filtering - collectionPath: "users/{{.userId}}/posts" - filters: | - { - "and": [ - {"field": "visibility", "op": "==", "value": {"stringValue": "{{.visibility}}"}}, - {"field": "createdAt", "op": ">=", "value": {"timestampValue": "{{.startDate}}"}} - ] - } - select: - - title - - content - - likes - orderBy: - field: createdAt - direction: "{{.sortOrder}}" - limit: 20 - parameters: - - name: userId - type: string - description: User ID whose posts to query - required: true - - name: visibility - type: string - description: Post visibility (public, private, friends) - required: true - - name: startDate - type: string - description: Start date for posts - required: true - - name: sortOrder - type: string - description: Sort order (ASCENDING or DESCENDING) - default: "DESCENDING" - query_inventory: - kind: firestore-query - source: inventory-firestore - description: Query inventory items - collectionPath: "warehouses/{{.warehouseId}}/inventory" - filters: | - { - "field": "quantity", "op": "<", "value": {"integerValue": "{{.threshold}}"}} - parameters: - - name: warehouseId - type: string - description: Warehouse ID to check inventory - required: true - - name: threshold - type: integer - description: Quantity threshold for low stock - required: true - query_transactions: - kind: firestore-query - source: finance-firestore - description: Query financial transactions - collectionPath: "accounts/{{.accountId}}/transactions" - filters: | - { - "or": [ - {"field": "type", "op": "==", "value": {"stringValue": "{{.transactionType}}"}}, - {"field": "amount", "op": ">", "value": {"doubleValue": {{.minAmount}}}} - ] - } - analyzeQuery: true - authRequired: - - finance-auth - parameters: - - name: accountId - type: string - description: Account ID for transactions - required: true - - name: transactionType - type: string - description: Type of transaction - default: "all" - - name: minAmount - type: float - description: Minimum transaction amount - default: 0 + kind: tools + name: query_user_posts + type: firestore-query + source: social-firestore + description: Query user posts with filtering + collectionPath: "users/{{.userId}}/posts" + filters: | + { + "and": [ + {"field": "visibility", "op": "==", "value": {"stringValue": "{{.visibility}}"}}, + {"field": "createdAt", "op": ">=", "value": {"timestampValue": "{{.startDate}}"}} + ] + } + select: + - title + - content + - likes + orderBy: + field: createdAt + direction: "{{.sortOrder}}" + limit: 20 + parameters: + - name: userId + type: string + description: User ID whose posts to query + required: true + - name: visibility + type: string + description: Post visibility (public, private, friends) + required: true + - name: startDate + type: string + description: Start date for posts + required: true + - name: sortOrder + type: string + description: Sort order (ASCENDING or DESCENDING) + default: "DESCENDING" +--- + kind: tools + name: query_inventory + type: firestore-query + source: inventory-firestore + description: Query inventory items + collectionPath: "warehouses/{{.warehouseId}}/inventory" + filters: | + { + "field": "quantity", "op": "<", "value": {"integerValue": "{{.threshold}}"}} + parameters: + - name: warehouseId + type: string + description: Warehouse ID to check inventory + required: true + - name: threshold + type: integer + description: Quantity threshold for low stock + required: true +--- + kind: tools + name: query_transactions + type: firestore-query + source: finance-firestore + description: Query financial transactions + collectionPath: "accounts/{{.accountId}}/transactions" + filters: | + { + "or": [ + {"field": "type", "op": "==", "value": {"stringValue": "{{.transactionType}}"}}, + {"field": "amount", "op": ">", "value": {"doubleValue": {{.minAmount}}}} + ] + } + analyzeQuery: true + authRequired: + - finance-auth + parameters: + - name: accountId + type: string + description: Account ID for transactions + required: true + - name: transactionType + type: string + description: Type of transaction + default: "all" + - name: minAmount + type: float + description: Minimum transaction amount + default: 0 ` want := server.ToolConfigs{ "query_user_posts": firestorequery.Config{ @@ -478,15 +478,11 @@ func TestParseFromYamlMultipleQueryTools(t *testing.T) { }, } - got := struct { - Tools server.ToolConfigs `yaml:"tools"` - }{} - // Parse contents - err = yaml.UnmarshalContext(ctx, testutils.FormatYaml(in), &got) + _, _, _, got, _, _, err := server.UnmarshalResourceConfig(ctx, testutils.FormatYaml(in)) if err != nil { t.Fatalf("unable to unmarshal: %s", err) } - if diff := cmp.Diff(want, got.Tools); diff != "" { + if diff := cmp.Diff(want, got); diff != "" { t.Fatalf("incorrect parse: diff %v", diff) } } diff --git a/internal/tools/firestore/firestorequerycollection/firestorequerycollection.go b/internal/tools/firestore/firestorequerycollection/firestorequerycollection.go index 688a4c0eeb..172b4bd394 100644 --- a/internal/tools/firestore/firestorequerycollection/firestorequerycollection.go +++ b/internal/tools/firestore/firestorequerycollection/firestorequerycollection.go @@ -31,7 +31,7 @@ import ( // Constants for tool configuration const ( - kind = "firestore-query-collection" + resourceType = "firestore-query-collection" defaultLimit = 100 defaultAnalyze = false maxFilterLength = 100 // Maximum filters to prevent abuse @@ -73,8 +73,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)) } } @@ -96,7 +96,7 @@ type compatibleSource interface { // Config represents the configuration for the Firestore query collection 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" validate:"required"` AuthRequired []string `yaml:"authRequired"` @@ -105,9 +105,9 @@ type Config struct { // validate interface var _ tools.ToolConfig = Config{} -// ToolConfigType returns the kind of tool configuration +// ToolConfigType returns the type of tool configuration func (cfg Config) ToolConfigType() string { - return kind + return resourceType } // Initialize creates a new Tool instance from the configuration diff --git a/internal/tools/firestore/firestorequerycollection/firestorequerycollection_test.go b/internal/tools/firestore/firestorequerycollection/firestorequerycollection_test.go index a35c863276..450ad18016 100644 --- a/internal/tools/firestore/firestorequerycollection/firestorequerycollection_test.go +++ b/internal/tools/firestore/firestorequerycollection/firestorequerycollection_test.go @@ -17,7 +17,6 @@ package firestorequerycollection_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 TestParseFromYamlFirestoreQueryCollection(t *testing.T) { { desc: "basic example", in: ` - tools: - query_users_tool: - kind: firestore-query-collection - source: my-firestore-instance - description: Query users collection with filters and ordering + kind: tools + name: query_users_tool + type: firestore-query-collection + source: my-firestore-instance + description: Query users collection with filters and ordering `, want: server.ToolConfigs{ "query_users_tool": firestorequerycollection.Config{ @@ -56,14 +55,14 @@ func TestParseFromYamlFirestoreQueryCollection(t *testing.T) { { desc: "with auth requirements", in: ` - tools: - secure_query_tool: - kind: firestore-query-collection - source: prod-firestore - description: Query collections with authentication - authRequired: - - google-auth-service - - api-key-service + kind: tools + name: secure_query_tool + type: firestore-query-collection + source: prod-firestore + description: Query collections with authentication + authRequired: + - google-auth-service + - api-key-service `, want: server.ToolConfigs{ "secure_query_tool": firestorequerycollection.Config{ @@ -78,15 +77,12 @@ func TestParseFromYamlFirestoreQueryCollection(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) } }) @@ -99,24 +95,28 @@ func TestParseFromYamlMultipleTools(t *testing.T) { t.Fatalf("unexpected error: %s", err) } in := ` - tools: - query_users: - kind: firestore-query-collection - source: users-firestore - description: Query user documents with filtering - authRequired: - - user-auth - query_products: - kind: firestore-query-collection - source: products-firestore - description: Query product catalog - query_orders: - kind: firestore-query-collection - source: orders-firestore - description: Query customer orders with complex filters - authRequired: - - user-auth - - admin-auth + kind: tools + name: query_users + type: firestore-query-collection + source: users-firestore + description: Query user documents with filtering + authRequired: + - user-auth +--- + kind: tools + name: query_products + type: firestore-query-collection + source: products-firestore + description: Query product catalog +--- + kind: tools + name: query_orders + type: firestore-query-collection + source: orders-firestore + description: Query customer orders with complex filters + authRequired: + - user-auth + - admin-auth ` want := server.ToolConfigs{ "query_users": firestorequerycollection.Config{ @@ -142,15 +142,11 @@ func TestParseFromYamlMultipleTools(t *testing.T) { }, } - got := struct { - Tools server.ToolConfigs `yaml:"tools"` - }{} - // Parse contents - err = yaml.UnmarshalContext(ctx, testutils.FormatYaml(in), &got) + _, _, _, got, _, _, err := server.UnmarshalResourceConfig(ctx, testutils.FormatYaml(in)) if err != nil { t.Fatalf("unable to unmarshal: %s", err) } - if diff := cmp.Diff(want, got.Tools); diff != "" { + if diff := cmp.Diff(want, got); diff != "" { t.Fatalf("incorrect parse: diff %v", diff) } } diff --git a/internal/tools/firestore/firestoreupdatedocument/firestoreupdatedocument.go b/internal/tools/firestore/firestoreupdatedocument/firestoreupdatedocument.go index d0fdea8217..86c5231780 100644 --- a/internal/tools/firestore/firestoreupdatedocument/firestoreupdatedocument.go +++ b/internal/tools/firestore/firestoreupdatedocument/firestoreupdatedocument.go @@ -28,15 +28,15 @@ import ( "github.com/googleapis/genai-toolbox/internal/util/parameters" ) -const kind string = "firestore-update-document" +const resourceType string = "firestore-update-document" const documentPathKey string = "documentPath" const documentDataKey string = "documentData" const updateMaskKey string = "updateMask" const returnDocumentDataKey string = "returnData" 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)) } } @@ -55,7 +55,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"` @@ -65,7 +65,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) { diff --git a/internal/tools/firestore/firestoreupdatedocument/firestoreupdatedocument_test.go b/internal/tools/firestore/firestoreupdatedocument/firestoreupdatedocument_test.go index 8a68aa30b1..73d3b0e803 100644 --- a/internal/tools/firestore/firestoreupdatedocument/firestoreupdatedocument_test.go +++ b/internal/tools/firestore/firestoreupdatedocument/firestoreupdatedocument_test.go @@ -19,10 +19,11 @@ 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" firestoreds "github.com/googleapis/genai-toolbox/internal/sources/firestore" + "github.com/googleapis/genai-toolbox/internal/testutils" "github.com/googleapis/genai-toolbox/internal/tools" "github.com/googleapis/genai-toolbox/internal/util/parameters" ) @@ -31,59 +32,65 @@ func TestNewConfig(t *testing.T) { tests := []struct { name string yaml string - want Config + want server.ToolConfigs wantErr bool }{ { name: "valid config", yaml: ` -name: test-update-document -kind: firestore-update-document -source: test-firestore -description: Update a document in Firestore -authRequired: - - google-oauth -`, - want: Config{ - Name: "test-update-document", - Type: "firestore-update-document", - Source: "test-firestore", - Description: "Update a document in Firestore", - AuthRequired: []string{"google-oauth"}, + kind: tools + name: test-update-document + type: firestore-update-document + source: test-firestore + description: Update a document in Firestore + authRequired: + - google-oauth + `, + want: server.ToolConfigs{ + "test-update-document": Config{ + Name: "test-update-document", + Type: "firestore-update-document", + Source: "test-firestore", + Description: "Update a document in Firestore", + AuthRequired: []string{"google-oauth"}, + }, }, wantErr: false, }, { name: "minimal config", yaml: ` -name: test-update-document -kind: firestore-update-document -source: test-firestore -description: Update a document -`, - want: Config{ - Name: "test-update-document", - Type: "firestore-update-document", - Source: "test-firestore", - Description: "Update a document", + kind: tools + name: test-update-document + type: firestore-update-document + source: test-firestore + description: Update a document + `, + want: server.ToolConfigs{ + "test-update-document": Config{ + Name: "test-update-document", + Type: "firestore-update-document", + Source: "test-firestore", + Description: "Update a document", + AuthRequired: []string{}, + }, }, wantErr: false, }, { name: "invalid yaml", yaml: ` -name: test-update-document -kind: [invalid -`, + kind: tools + name: test-update-document + type: [invalid + `, wantErr: true, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - decoder := yaml.NewDecoder(strings.NewReader(tt.yaml)) - got, err := newConfig(context.Background(), "test-update-document", decoder) - + _, _, _, got, _, _, err := server.UnmarshalResourceConfig(context.Background(), testutils.FormatYaml(tt.yaml)) if tt.wantErr { if err == nil { t.Fatalf("expected error but got none") diff --git a/internal/tools/firestore/firestorevalidaterules/firestorevalidaterules.go b/internal/tools/firestore/firestorevalidaterules/firestorevalidaterules.go index 44215641b9..0cb36c1303 100644 --- a/internal/tools/firestore/firestorevalidaterules/firestorevalidaterules.go +++ b/internal/tools/firestore/firestorevalidaterules/firestorevalidaterules.go @@ -26,7 +26,7 @@ import ( "google.golang.org/api/firebaserules/v1" ) -const kind string = "firestore-validate-rules" +const resourceType string = "firestore-validate-rules" // Parameter keys const ( @@ -34,8 +34,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)) } } @@ -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) { diff --git a/internal/tools/firestore/firestorevalidaterules/firestorevalidaterules_test.go b/internal/tools/firestore/firestorevalidaterules/firestorevalidaterules_test.go index ae89e481aa..f454bb5e35 100644 --- a/internal/tools/firestore/firestorevalidaterules/firestorevalidaterules_test.go +++ b/internal/tools/firestore/firestorevalidaterules/firestorevalidaterules_test.go @@ -17,7 +17,6 @@ package firestorevalidaterules_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 TestParseFromYamlFirestoreValidateRules(t *testing.T) { { desc: "basic example", in: ` - tools: - validate_rules_tool: - kind: firestore-validate-rules - source: my-firestore-instance - description: Validate Firestore security rules + kind: tools + name: validate_rules_tool + type: firestore-validate-rules + source: my-firestore-instance + description: Validate Firestore security rules `, want: server.ToolConfigs{ "validate_rules_tool": firestorevalidaterules.Config{ @@ -56,14 +55,14 @@ func TestParseFromYamlFirestoreValidateRules(t *testing.T) { { desc: "with auth requirements", in: ` - tools: - secure_validate_rules: - kind: firestore-validate-rules - source: prod-firestore - description: Validate rules with authentication - authRequired: - - google-auth-service - - api-key-service + kind: tools + name: secure_validate_rules + type: firestore-validate-rules + source: prod-firestore + description: Validate rules with authentication + authRequired: + - google-auth-service + - api-key-service `, want: server.ToolConfigs{ "secure_validate_rules": firestorevalidaterules.Config{ @@ -78,15 +77,11 @@ func TestParseFromYamlFirestoreValidateRules(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) } }) @@ -99,24 +94,28 @@ func TestParseFromYamlMultipleTools(t *testing.T) { t.Fatalf("unexpected error: %s", err) } in := ` - tools: - validate_dev_rules: - kind: firestore-validate-rules - source: dev-firestore - description: Validate development environment rules - authRequired: - - dev-auth - validate_staging_rules: - kind: firestore-validate-rules - source: staging-firestore - description: Validate staging environment rules - validate_prod_rules: - kind: firestore-validate-rules - source: prod-firestore - description: Validate production environment rules - authRequired: - - prod-auth - - admin-auth + kind: tools + name: validate_dev_rules + type: firestore-validate-rules + source: dev-firestore + description: Validate development environment rules + authRequired: + - dev-auth +--- + kind: tools + name: validate_staging_rules + type: firestore-validate-rules + source: staging-firestore + description: Validate staging environment rules +--- + kind: tools + name: validate_prod_rules + type: firestore-validate-rules + source: prod-firestore + description: Validate production environment rules + authRequired: + - prod-auth + - admin-auth ` want := server.ToolConfigs{ "validate_dev_rules": firestorevalidaterules.Config{ @@ -142,15 +141,11 @@ func TestParseFromYamlMultipleTools(t *testing.T) { }, } - got := struct { - Tools server.ToolConfigs `yaml:"tools"` - }{} - // Parse contents - err = yaml.UnmarshalContext(ctx, testutils.FormatYaml(in), &got) + _, _, _, got, _, _, err := server.UnmarshalResourceConfig(ctx, testutils.FormatYaml(in)) if err != nil { t.Fatalf("unable to unmarshal: %s", err) } - if diff := cmp.Diff(want, got.Tools); diff != "" { + if diff := cmp.Diff(want, got); diff != "" { t.Fatalf("incorrect parse: diff %v", diff) } } diff --git a/internal/tools/http/http.go b/internal/tools/http/http.go index ed6ff1ffce..400505c0d5 100644 --- a/internal/tools/http/http.go +++ b/internal/tools/http/http.go @@ -32,11 +32,11 @@ import ( "github.com/googleapis/genai-toolbox/internal/util/parameters" ) -const kind string = "http" +const resourceType string = "http" 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"` @@ -75,7 +75,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) { @@ -88,7 +88,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 kind must be `http`", kind) + return nil, fmt.Errorf("invalid source for %q tool: source type must be `http`", resourceType) } // Combine Source and Tool headers. diff --git a/internal/tools/http/http_test.go b/internal/tools/http/http_test.go index 812ff53dba..2cdb756ee7 100644 --- a/internal/tools/http/http_test.go +++ b/internal/tools/http/http_test.go @@ -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/testutils" @@ -39,14 +38,14 @@ func TestParseFromYamlHTTP(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: http - source: my-instance - method: GET - description: some description - path: search - `, + kind: tools + name: example_tool + type: http + source: my-instance + method: GET + description: some description + path: search + `, want: server.ToolConfigs{ "example_tool": http.Config{ Name: "example_tool", @@ -62,49 +61,49 @@ func TestParseFromYamlHTTP(t *testing.T) { { desc: "advanced example", in: ` - tools: - example_tool: - kind: http - source: my-instance - method: GET - path: "{{.pathParam}}?name=alice&pet=cat" - description: some description - authRequired: - - my-google-auth-service - - other-auth-service - queryParams: - - name: country - type: string - description: some description - authServices: - - name: my-google-auth-service - field: user_id - - name: other-auth-service - field: user_id - pathParams: - - name: pathParam - type: string - description: path param - requestBody: | - { - "age": {{.age}}, - "city": "{{.city}}", - "food": {{.food}} - } - bodyParams: - - name: age - type: integer - description: age num - - name: city - type: string - description: city string - headers: - Authorization: API_KEY - Content-Type: application/json - headerParams: - - name: Language - type: string - description: language string + kind: tools + name: example_tool + type: http + source: my-instance + method: GET + path: "{{.pathParam}}?name=alice&pet=cat" + description: some description + authRequired: + - my-google-auth-service + - other-auth-service + queryParams: + - name: country + type: string + description: some description + authServices: + - name: my-google-auth-service + field: user_id + - name: other-auth-service + field: user_id + pathParams: + - name: pathParam + type: string + description: path param + requestBody: | + { + "age": {{.age}}, + "city": "{{.city}}", + "food": {{.food}} + } + bodyParams: + - name: age + type: integer + description: age num + - name: city + type: string + description: city string + headers: + Authorization: API_KEY + Content-Type: application/json + headerParams: + - name: Language + type: string + description: language string `, want: server.ToolConfigs{ "example_tool": http.Config{ @@ -140,15 +139,11 @@ func TestParseFromYamlHTTP(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) } }) @@ -169,55 +164,51 @@ func TestFailParseFromYamlHTTP(t *testing.T) { { desc: "Invalid method", in: ` - tools: - example_tool: - kind: http - source: my-instance - method: GOT - path: "search?name=alice&pet=cat" - description: some description - authRequired: - - my-google-auth-service - - other-auth-service - queryParams: - - name: country - type: string - description: some description - authServices: - - name: my-google-auth-service - field: user_id - - name: other-auth-service - field: user_id - requestBody: | - { - "age": {{.age}}, - "city": "{{.city}}" - } - bodyParams: - - name: age - type: integer - description: age num - - name: city - type: string - description: city string - headers: - Authorization: API_KEY - Content-Type: application/json - headerParams: - - name: Language - type: string - description: language string + kind: tools + name: example_tool + type: http + source: my-instance + method: GOT + path: "search?name=alice&pet=cat" + description: some description + authRequired: + - my-google-auth-service + - other-auth-service + queryParams: + - name: country + type: string + description: some description + authServices: + - name: my-google-auth-service + field: user_id + - name: other-auth-service + field: user_id + requestBody: | + { + "age": {{.age}}, + "city": "{{.city}}" + } + bodyParams: + - name: age + type: integer + description: age num + - name: city + type: string + description: city string + headers: + Authorization: API_KEY + Content-Type: application/json + headerParams: + - name: Language + type: string + description: language string `, err: `GOT is not a valid http method`, }, } 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") } diff --git a/internal/tools/looker/lookeradddashboardelement/lookeradddashboardelement.go b/internal/tools/looker/lookeradddashboardelement/lookeradddashboardelement.go index 886804ad38..b4f0a7e5c7 100644 --- a/internal/tools/looker/lookeradddashboardelement/lookeradddashboardelement.go +++ b/internal/tools/looker/lookeradddashboardelement/lookeradddashboardelement.go @@ -29,11 +29,11 @@ import ( v4 "github.com/looker-open-source/sdk-codegen/go/sdk/v4" ) -const kind string = "looker-add-dashboard-element" +const resourceType string = "looker-add-dashboard-element" 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"` @@ -65,7 +65,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) { diff --git a/internal/tools/looker/lookeradddashboardelement/lookeradddashboardelement_test.go b/internal/tools/looker/lookeradddashboardelement/lookeradddashboardelement_test.go index 0adfe6fa29..0c55ee0f9d 100644 --- a/internal/tools/looker/lookeradddashboardelement/lookeradddashboardelement_test.go +++ b/internal/tools/looker/lookeradddashboardelement/lookeradddashboardelement_test.go @@ -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/testutils" @@ -38,11 +37,11 @@ func TestParseFromYamlLookerAddDashboardElement(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: looker-add-dashboard-element - source: my-instance - description: some description + kind: tools + name: example_tool + type: looker-add-dashboard-element + source: my-instance + description: some description `, want: server.ToolConfigs{ "example_tool": lkr.Config{ @@ -57,15 +56,12 @@ func TestParseFromYamlLookerAddDashboardElement(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) } }) @@ -86,23 +82,20 @@ func TestFailParseFromYamlLookerAddDashboardElement(t *testing.T) { { desc: "Invalid method", in: ` - tools: - example_tool: - kind: looker-add-dashboard-element - source: my-instance - method: GOT - description: some description + kind: tools + name: example_tool + type: looker-add-dashboard-element + source: my-instance + method: GOT + description: some description `, - err: "unable to parse tool \"example_tool\" as kind \"looker-add-dashboard-element\": [4:1] unknown field \"method\"\n 1 | authRequired: []\n 2 | description: some description\n 3 | kind: looker-add-dashboard-element\n> 4 | method: GOT\n ^\n 5 | source: my-instance", + err: "error unmarshaling tools: unable to parse tool \"example_tool\" as type \"looker-add-dashboard-element\": [3:1] unknown field \"method\"\n 1 | authRequired: []\n 2 | description: some description\n> 3 | method: GOT\n ^\n 4 | name: example_tool\n 5 | source: my-instance\n 6 | type: looker-add-dashboard-element", }, } 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") } diff --git a/internal/tools/looker/lookeradddashboardfilter/lookeradddashboardfilter.go b/internal/tools/looker/lookeradddashboardfilter/lookeradddashboardfilter.go index 7f004b410a..ed4366f09f 100644 --- a/internal/tools/looker/lookeradddashboardfilter/lookeradddashboardfilter.go +++ b/internal/tools/looker/lookeradddashboardfilter/lookeradddashboardfilter.go @@ -28,11 +28,11 @@ import ( v4 "github.com/looker-open-source/sdk-codegen/go/sdk/v4" ) -const kind string = "looker-add-dashboard-filter" +const resourceType string = "looker-add-dashboard-filter" 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)) } } @@ -53,7 +53,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) { diff --git a/internal/tools/looker/lookeradddashboardfilter/lookeradddashboardfilter_test.go b/internal/tools/looker/lookeradddashboardfilter/lookeradddashboardfilter_test.go index c493a14b04..0f95161b67 100644 --- a/internal/tools/looker/lookeradddashboardfilter/lookeradddashboardfilter_test.go +++ b/internal/tools/looker/lookeradddashboardfilter/lookeradddashboardfilter_test.go @@ -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/testutils" @@ -38,11 +37,11 @@ func TestParseFromYamlLookerAddDashboardFilter(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: looker-add-dashboard-filter - source: my-instance - description: some description + kind: tools + name: example_tool + type: looker-add-dashboard-filter + source: my-instance + description: some description `, want: server.ToolConfigs{ "example_tool": lkr.Config{ @@ -57,15 +56,12 @@ func TestParseFromYamlLookerAddDashboardFilter(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) } }) @@ -86,23 +82,20 @@ func TestFailParseFromYamlLookerAddDashboardFilter(t *testing.T) { { desc: "Invalid method", in: ` - tools: - example_tool: - kind: looker-add-dashboard-filter - source: my-instance - method: GOT - description: some description + kind: tools + name: example_tool + type: looker-add-dashboard-filter + source: my-instance + method: GOT + description: some description `, - err: "unable to parse tool \"example_tool\" as kind \"looker-add-dashboard-filter\": [4:1] unknown field \"method\"\n 1 | authRequired: []\n 2 | description: some description\n 3 | kind: looker-add-dashboard-filter\n> 4 | method: GOT\n ^\n 5 | source: my-instance", + err: "error unmarshaling tools: unable to parse tool \"example_tool\" as type \"looker-add-dashboard-filter\": [3:1] unknown field \"method\"\n 1 | authRequired: []\n 2 | description: some description\n> 3 | method: GOT\n ^\n 4 | name: example_tool\n 5 | source: my-instance\n 6 | type: looker-add-dashboard-filter", }, } 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") } diff --git a/internal/tools/looker/lookerconversationalanalytics/lookerconversationalanalytics.go b/internal/tools/looker/lookerconversationalanalytics/lookerconversationalanalytics.go index 996725d884..c586127e0c 100644 --- a/internal/tools/looker/lookerconversationalanalytics/lookerconversationalanalytics.go +++ b/internal/tools/looker/lookerconversationalanalytics/lookerconversationalanalytics.go @@ -34,7 +34,7 @@ import ( "golang.org/x/oauth2" ) -const kind string = "looker-conversational-analytics" +const resourceType string = "looker-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. @@ -42,8 +42,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)) } } @@ -126,7 +126,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"` @@ -137,7 +137,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) { @@ -150,11 +150,11 @@ 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) } if s.GoogleCloudProject() == "" { - return nil, fmt.Errorf("project must be defined for source to use with %q tool", kind) + return nil, fmt.Errorf("project must be defined for source to use with %q tool", resourceType) } userQueryParameter := parameters.NewStringParameter("user_query_with_context", "The user's question, potentially including conversation history and system instructions for context.") diff --git a/internal/tools/looker/lookerconversationalanalytics/lookerconversationalanalytics_test.go b/internal/tools/looker/lookerconversationalanalytics/lookerconversationalanalytics_test.go index 5d7d4a22d1..9e0fdb26ed 100644 --- a/internal/tools/looker/lookerconversationalanalytics/lookerconversationalanalytics_test.go +++ b/internal/tools/looker/lookerconversationalanalytics/lookerconversationalanalytics_test.go @@ -17,7 +17,6 @@ package lookerconversationalanalytics_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 TestParseFromYamlLookerConversationalAnalytics(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: looker-conversational-analytics - source: my-instance - description: some description + kind: tools + name: example_tool + type: looker-conversational-analytics + source: my-instance + description: some description `, want: server.ToolConfigs{ "example_tool": lookerconversationalanalytics.Config{ @@ -56,15 +55,11 @@ func TestParseFromYamlLookerConversationalAnalytics(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) } }) diff --git a/internal/tools/looker/lookercreateprojectfile/lookercreateprojectfile.go b/internal/tools/looker/lookercreateprojectfile/lookercreateprojectfile.go index c6477b3529..6329bf117d 100644 --- a/internal/tools/looker/lookercreateprojectfile/lookercreateprojectfile.go +++ b/internal/tools/looker/lookercreateprojectfile/lookercreateprojectfile.go @@ -28,11 +28,11 @@ import ( v4 "github.com/looker-open-source/sdk-codegen/go/sdk/v4" ) -const kind string = "looker-create-project-file" +const resourceType string = "looker-create-project-file" 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)) } } @@ -53,7 +53,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) { diff --git a/internal/tools/looker/lookercreateprojectfile/lookercreateprojectfile_test.go b/internal/tools/looker/lookercreateprojectfile/lookercreateprojectfile_test.go index 5840057626..d8a90fa390 100644 --- a/internal/tools/looker/lookercreateprojectfile/lookercreateprojectfile_test.go +++ b/internal/tools/looker/lookercreateprojectfile/lookercreateprojectfile_test.go @@ -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/testutils" @@ -38,11 +37,11 @@ func TestParseFromYamlLookerCreateProjectFile(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: looker-create-project-file - source: my-instance - description: some description + kind: tools + name: example_tool + type: looker-create-project-file + source: my-instance + description: some description `, want: server.ToolConfigs{ "example_tool": lkr.Config{ @@ -57,15 +56,12 @@ func TestParseFromYamlLookerCreateProjectFile(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) } }) @@ -86,23 +82,20 @@ func TestFailParseFromYamlLookerCreateProjectFile(t *testing.T) { { desc: "Invalid method", in: ` - tools: - example_tool: - kind: looker-create-project-file - source: my-instance - method: GOT - description: some description + kind: tools + name: example_tool + type: looker-create-project-file + source: my-instance + method: GOT + description: some description `, - err: "unable to parse tool \"example_tool\" as kind \"looker-create-project-file\": [4:1] unknown field \"method\"\n 1 | authRequired: []\n 2 | description: some description\n 3 | kind: looker-create-project-file\n> 4 | method: GOT\n ^\n 5 | source: my-instance", + err: "error unmarshaling tools: unable to parse tool \"example_tool\" as type \"looker-create-project-file\": [3:1] unknown field \"method\"\n 1 | authRequired: []\n 2 | description: some description\n> 3 | method: GOT\n ^\n 4 | name: example_tool\n 5 | source: my-instance\n 6 | type: looker-create-project-file", }, } 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") } diff --git a/internal/tools/looker/lookerdeleteprojectfile/lookerdeleteprojectfile.go b/internal/tools/looker/lookerdeleteprojectfile/lookerdeleteprojectfile.go index 418466d7e8..8fc3c3e9e8 100644 --- a/internal/tools/looker/lookerdeleteprojectfile/lookerdeleteprojectfile.go +++ b/internal/tools/looker/lookerdeleteprojectfile/lookerdeleteprojectfile.go @@ -28,11 +28,11 @@ import ( v4 "github.com/looker-open-source/sdk-codegen/go/sdk/v4" ) -const kind string = "looker-delete-project-file" +const resourceType string = "looker-delete-project-file" 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)) } } @@ -53,7 +53,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) { diff --git a/internal/tools/looker/lookerdeleteprojectfile/lookerdeleteprojectfile_test.go b/internal/tools/looker/lookerdeleteprojectfile/lookerdeleteprojectfile_test.go index 5ae4836635..16f226a9f5 100644 --- a/internal/tools/looker/lookerdeleteprojectfile/lookerdeleteprojectfile_test.go +++ b/internal/tools/looker/lookerdeleteprojectfile/lookerdeleteprojectfile_test.go @@ -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/testutils" @@ -38,11 +37,11 @@ func TestParseFromYamlLookerDeleteProjectFile(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: looker-delete-project-file - source: my-instance - description: some description + kind: tools + name: example_tool + type: looker-delete-project-file + source: my-instance + description: some description `, want: server.ToolConfigs{ "example_tool": lkr.Config{ @@ -57,15 +56,12 @@ func TestParseFromYamlLookerDeleteProjectFile(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) } }) @@ -86,23 +82,20 @@ func TestFailParseFromYamlLookerDeleteProjectFile(t *testing.T) { { desc: "Invalid method", in: ` - tools: - example_tool: - kind: looker-delete-project-file - source: my-instance - method: GOT - description: some description + kind: tools + name: example_tool + type: looker-delete-project-file + source: my-instance + method: GOT + description: some description `, - err: "unable to parse tool \"example_tool\" as kind \"looker-delete-project-file\": [4:1] unknown field \"method\"\n 1 | authRequired: []\n 2 | description: some description\n 3 | kind: looker-delete-project-file\n> 4 | method: GOT\n ^\n 5 | source: my-instance", + err: "error unmarshaling tools: unable to parse tool \"example_tool\" as type \"looker-delete-project-file\": [3:1] unknown field \"method\"\n 1 | authRequired: []\n 2 | description: some description\n> 3 | method: GOT\n ^\n 4 | name: example_tool\n 5 | source: my-instance\n 6 | type: looker-delete-project-file", }, } 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") } diff --git a/internal/tools/looker/lookerdevmode/lookerdevmode.go b/internal/tools/looker/lookerdevmode/lookerdevmode.go index 5f989efcf9..e4caa9c834 100644 --- a/internal/tools/looker/lookerdevmode/lookerdevmode.go +++ b/internal/tools/looker/lookerdevmode/lookerdevmode.go @@ -28,11 +28,11 @@ import ( v4 "github.com/looker-open-source/sdk-codegen/go/sdk/v4" ) -const kind string = "looker-dev-mode" +const resourceType string = "looker-dev-mode" 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)) } } @@ -53,7 +53,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) { diff --git a/internal/tools/looker/lookerdevmode/lookerdevmode_test.go b/internal/tools/looker/lookerdevmode/lookerdevmode_test.go index cb4eb58ec4..961bb5cb40 100644 --- a/internal/tools/looker/lookerdevmode/lookerdevmode_test.go +++ b/internal/tools/looker/lookerdevmode/lookerdevmode_test.go @@ -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/testutils" @@ -38,11 +37,11 @@ func TestParseFromYamlLookerDevMode(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: looker-dev-mode - source: my-instance - description: some description + kind: tools + name: example_tool + type: looker-dev-mode + source: my-instance + description: some description `, want: server.ToolConfigs{ "example_tool": lkr.Config{ @@ -57,15 +56,12 @@ func TestParseFromYamlLookerDevMode(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) } }) @@ -86,23 +82,20 @@ func TestFailParseFromYamlLookerDevMode(t *testing.T) { { desc: "Invalid method", in: ` - tools: - example_tool: - kind: looker-dev-mode - source: my-instance - method: GOT - description: some description + kind: tools + name: example_tool + type: looker-dev-mode + source: my-instance + method: GOT + description: some description `, - err: "unable to parse tool \"example_tool\" as kind \"looker-dev-mode\": [4:1] unknown field \"method\"\n 1 | authRequired: []\n 2 | description: some description\n 3 | kind: looker-dev-mode\n> 4 | method: GOT\n ^\n 5 | source: my-instance", + err: "error unmarshaling tools: unable to parse tool \"example_tool\" as type \"looker-dev-mode\": [3:1] unknown field \"method\"\n 1 | authRequired: []\n 2 | description: some description\n> 3 | method: GOT\n ^\n 4 | name: example_tool\n 5 | source: my-instance\n 6 | type: looker-dev-mode", }, } 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") } diff --git a/internal/tools/looker/lookergenerateembedurl/lookergenerateembedurl.go b/internal/tools/looker/lookergenerateembedurl/lookergenerateembedurl.go index 3988e4ea3d..afa35ae3d3 100644 --- a/internal/tools/looker/lookergenerateembedurl/lookergenerateembedurl.go +++ b/internal/tools/looker/lookergenerateembedurl/lookergenerateembedurl.go @@ -29,11 +29,11 @@ import ( v4 "github.com/looker-open-source/sdk-codegen/go/sdk/v4" ) -const kind string = "looker-generate-embed-url" +const resourceType string = "looker-generate-embed-url" 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)) } } @@ -55,7 +55,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) { diff --git a/internal/tools/looker/lookergenerateembedurl/lookergenerateembedurl_test.go b/internal/tools/looker/lookergenerateembedurl/lookergenerateembedurl_test.go index e0bffd1863..08aeba23d5 100644 --- a/internal/tools/looker/lookergenerateembedurl/lookergenerateembedurl_test.go +++ b/internal/tools/looker/lookergenerateembedurl/lookergenerateembedurl_test.go @@ -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/testutils" @@ -38,11 +37,11 @@ func TestParseFromYamlLookerGenerateEmbedUrl(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: looker-generate-embed-url - source: my-instance - description: some description + kind: tools + name: example_tool + type: looker-generate-embed-url + source: my-instance + description: some description `, want: server.ToolConfigs{ "example_tool": lkr.Config{ @@ -57,15 +56,11 @@ func TestParseFromYamlLookerGenerateEmbedUrl(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) } }) @@ -85,23 +80,19 @@ func TestFailParseFromYamlLookerGenerateEmbedUrl(t *testing.T) { { desc: "Invalid field", in: ` - tools: - example_tool: - kind: looker-generate-embed-url - source: my-instance - description: some description - invalid_field: "should not be here" + kind: tools + name: example_tool + type: looker-generate-embed-url + source: my-instance + description: some description + invalid_field: "should not be here" `, err: "unknown field", }, } 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") } diff --git a/internal/tools/looker/lookergetconnectiondatabases/lookergetconnectiondatabases.go b/internal/tools/looker/lookergetconnectiondatabases/lookergetconnectiondatabases.go index 46b6058974..6fb8be8fc1 100644 --- a/internal/tools/looker/lookergetconnectiondatabases/lookergetconnectiondatabases.go +++ b/internal/tools/looker/lookergetconnectiondatabases/lookergetconnectiondatabases.go @@ -27,11 +27,11 @@ import ( v4 "github.com/looker-open-source/sdk-codegen/go/sdk/v4" ) -const kind string = "looker-get-connection-databases" +const resourceType string = "looker-get-connection-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)) } } @@ -52,7 +52,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"` @@ -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) { diff --git a/internal/tools/looker/lookergetconnectiondatabases/lookergetconnectiondatabases_test.go b/internal/tools/looker/lookergetconnectiondatabases/lookergetconnectiondatabases_test.go index 5969479572..6f137e85dc 100644 --- a/internal/tools/looker/lookergetconnectiondatabases/lookergetconnectiondatabases_test.go +++ b/internal/tools/looker/lookergetconnectiondatabases/lookergetconnectiondatabases_test.go @@ -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/testutils" @@ -38,11 +37,11 @@ func TestParseFromYamlLookerGetConnectionDatabases(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: looker-get-connection-databases - source: my-instance - description: some description + kind: tools + name: example_tool + type: looker-get-connection-databases + source: my-instance + description: some description `, want: server.ToolConfigs{ "example_tool": lkr.Config{ @@ -57,15 +56,12 @@ func TestParseFromYamlLookerGetConnectionDatabases(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) } }) @@ -86,23 +82,20 @@ func TestFailParseFromYamlLookerGetConnectionDatabases(t *testing.T) { { desc: "Invalid method", in: ` - tools: - example_tool: - kind: looker-get-connection-databases - source: my-instance - method: GOT - description: some description + kind: tools + name: example_tool + type: looker-get-connection-databases + source: my-instance + method: GOT + description: some description `, - err: "unable to parse tool \"example_tool\" as kind \"looker-get-connection-databases\": [4:1] unknown field \"method\"\n 1 | authRequired: []\n 2 | description: some description\n 3 | kind: looker-get-connection-databases\n> 4 | method: GOT\n ^\n 5 | source: my-instance", + err: "error unmarshaling tools: unable to parse tool \"example_tool\" as type \"looker-get-connection-databases\": [3:1] unknown field \"method\"\n 1 | authRequired: []\n 2 | description: some description\n> 3 | method: GOT\n ^\n 4 | name: example_tool\n 5 | source: my-instance\n 6 | type: looker-get-connection-databases", }, } 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") } diff --git a/internal/tools/looker/lookergetconnections/lookergetconnections.go b/internal/tools/looker/lookergetconnections/lookergetconnections.go index 2bde4707e1..4f09505567 100644 --- a/internal/tools/looker/lookergetconnections/lookergetconnections.go +++ b/internal/tools/looker/lookergetconnections/lookergetconnections.go @@ -28,11 +28,11 @@ import ( v4 "github.com/looker-open-source/sdk-codegen/go/sdk/v4" ) -const kind string = "looker-get-connections" +const resourceType string = "looker-get-connections" 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)) } } @@ -53,7 +53,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) { diff --git a/internal/tools/looker/lookergetconnections/lookergetconnections_test.go b/internal/tools/looker/lookergetconnections/lookergetconnections_test.go index 2f161bb05d..0e7cc03777 100644 --- a/internal/tools/looker/lookergetconnections/lookergetconnections_test.go +++ b/internal/tools/looker/lookergetconnections/lookergetconnections_test.go @@ -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/testutils" @@ -38,11 +37,11 @@ func TestParseFromYamlLookerGetConnections(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: looker-get-connections - source: my-instance - description: some description + kind: tools + name: example_tool + type: looker-get-connections + source: my-instance + description: some description `, want: server.ToolConfigs{ "example_tool": lkr.Config{ @@ -57,15 +56,12 @@ func TestParseFromYamlLookerGetConnections(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) } }) @@ -86,23 +82,20 @@ func TestFailParseFromYamlLookerGetConnections(t *testing.T) { { desc: "Invalid method", in: ` - tools: - example_tool: - kind: looker-get-connections - source: my-instance - method: GOT - description: some description + kind: tools + name: example_tool + type: looker-get-connections + source: my-instance + method: GOT + description: some description `, - err: "unable to parse tool \"example_tool\" as kind \"looker-get-connections\": [4:1] unknown field \"method\"\n 1 | authRequired: []\n 2 | description: some description\n 3 | kind: looker-get-connections\n> 4 | method: GOT\n ^\n 5 | source: my-instance", + err: "error unmarshaling tools: unable to parse tool \"example_tool\" as type \"looker-get-connections\": [3:1] unknown field \"method\"\n 1 | authRequired: []\n 2 | description: some description\n> 3 | method: GOT\n ^\n 4 | name: example_tool\n 5 | source: my-instance\n 6 | type: looker-get-connections", }, } 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") } diff --git a/internal/tools/looker/lookergetconnectionschemas/lookergetconnectionschemas.go b/internal/tools/looker/lookergetconnectionschemas/lookergetconnectionschemas.go index f91e511369..8dfe430ec2 100644 --- a/internal/tools/looker/lookergetconnectionschemas/lookergetconnectionschemas.go +++ b/internal/tools/looker/lookergetconnectionschemas/lookergetconnectionschemas.go @@ -27,11 +27,11 @@ import ( v4 "github.com/looker-open-source/sdk-codegen/go/sdk/v4" ) -const kind string = "looker-get-connection-schemas" +const resourceType string = "looker-get-connection-schemas" 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 { 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"` @@ -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) { diff --git a/internal/tools/looker/lookergetconnectionschemas/lookergetconnectionschemas_test.go b/internal/tools/looker/lookergetconnectionschemas/lookergetconnectionschemas_test.go index db1c24c64d..c0e7207517 100644 --- a/internal/tools/looker/lookergetconnectionschemas/lookergetconnectionschemas_test.go +++ b/internal/tools/looker/lookergetconnectionschemas/lookergetconnectionschemas_test.go @@ -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/testutils" @@ -38,11 +37,11 @@ func TestParseFromYamlLookerGetConnectionSchemas(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: looker-get-connection-schemas - source: my-instance - description: some description + kind: tools + name: example_tool + type: looker-get-connection-schemas + source: my-instance + description: some description `, want: server.ToolConfigs{ "example_tool": lkr.Config{ @@ -57,15 +56,12 @@ func TestParseFromYamlLookerGetConnectionSchemas(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) } }) @@ -86,23 +82,20 @@ func TestFailParseFromYamlLookerGetConnectionSchemas(t *testing.T) { { desc: "Invalid method", in: ` - tools: - example_tool: - kind: looker-get-connection-schemas - source: my-instance - method: GOT - description: some description + kind: tools + name: example_tool + type: looker-get-connection-schemas + source: my-instance + method: GOT + description: some description `, - err: "unable to parse tool \"example_tool\" as kind \"looker-get-connection-schemas\": [4:1] unknown field \"method\"\n 1 | authRequired: []\n 2 | description: some description\n 3 | kind: looker-get-connection-schemas\n> 4 | method: GOT\n ^\n 5 | source: my-instance", + err: "error unmarshaling tools: unable to parse tool \"example_tool\" as type \"looker-get-connection-schemas\": [3:1] unknown field \"method\"\n 1 | authRequired: []\n 2 | description: some description\n> 3 | method: GOT\n ^\n 4 | name: example_tool\n 5 | source: my-instance\n 6 | type: looker-get-connection-schemas", }, } 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") } diff --git a/internal/tools/looker/lookergetconnectiontablecolumns/lookergetconnectiontablecolumns.go b/internal/tools/looker/lookergetconnectiontablecolumns/lookergetconnectiontablecolumns.go index d29e3a23a1..a0102b4e8c 100644 --- a/internal/tools/looker/lookergetconnectiontablecolumns/lookergetconnectiontablecolumns.go +++ b/internal/tools/looker/lookergetconnectiontablecolumns/lookergetconnectiontablecolumns.go @@ -28,11 +28,11 @@ import ( v4 "github.com/looker-open-source/sdk-codegen/go/sdk/v4" ) -const kind string = "looker-get-connection-table-columns" +const resourceType string = "looker-get-connection-table-columns" 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)) } } @@ -53,7 +53,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) { diff --git a/internal/tools/looker/lookergetconnectiontablecolumns/lookergetconnectiontablecolumns_test.go b/internal/tools/looker/lookergetconnectiontablecolumns/lookergetconnectiontablecolumns_test.go index e1acae589f..c01a8ce8d1 100644 --- a/internal/tools/looker/lookergetconnectiontablecolumns/lookergetconnectiontablecolumns_test.go +++ b/internal/tools/looker/lookergetconnectiontablecolumns/lookergetconnectiontablecolumns_test.go @@ -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/testutils" @@ -38,11 +37,11 @@ func TestParseFromYamlLookerGetConnectionTableColumns(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: looker-get-connection-table-columns - source: my-instance - description: some description + kind: tools + name: example_tool + type: looker-get-connection-table-columns + source: my-instance + description: some description `, want: server.ToolConfigs{ "example_tool": lkr.Config{ @@ -57,15 +56,12 @@ func TestParseFromYamlLookerGetConnectionTableColumns(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) } }) @@ -86,23 +82,20 @@ func TestFailParseFromYamlLookerGetConnectionTableColumns(t *testing.T) { { desc: "Invalid method", in: ` - tools: - example_tool: - kind: looker-get-connection-table-columns - source: my-instance - method: GOT - description: some description + kind: tools + name: example_tool + type: looker-get-connection-table-columns + source: my-instance + method: GOT + description: some description `, - err: "unable to parse tool \"example_tool\" as kind \"looker-get-connection-table-columns\": [4:1] unknown field \"method\"\n 1 | authRequired: []\n 2 | description: some description\n 3 | kind: looker-get-connection-table-columns\n> 4 | method: GOT\n ^\n 5 | source: my-instance", + err: "error unmarshaling tools: unable to parse tool \"example_tool\" as type \"looker-get-connection-table-columns\": [3:1] unknown field \"method\"\n 1 | authRequired: []\n 2 | description: some description\n> 3 | method: GOT\n ^\n 4 | name: example_tool\n 5 | source: my-instance\n 6 | type: looker-get-connection-table-columns", }, } 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") } diff --git a/internal/tools/looker/lookergetconnectiontables/lookergetconnectiontables.go b/internal/tools/looker/lookergetconnectiontables/lookergetconnectiontables.go index d65fb760cd..cd98118335 100644 --- a/internal/tools/looker/lookergetconnectiontables/lookergetconnectiontables.go +++ b/internal/tools/looker/lookergetconnectiontables/lookergetconnectiontables.go @@ -28,11 +28,11 @@ import ( v4 "github.com/looker-open-source/sdk-codegen/go/sdk/v4" ) -const kind string = "looker-get-connection-tables" +const resourceType string = "looker-get-connection-tables" 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)) } } @@ -53,7 +53,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) { diff --git a/internal/tools/looker/lookergetconnectiontables/lookergetconnectiontables_test.go b/internal/tools/looker/lookergetconnectiontables/lookergetconnectiontables_test.go index 187b959259..0267accaf5 100644 --- a/internal/tools/looker/lookergetconnectiontables/lookergetconnectiontables_test.go +++ b/internal/tools/looker/lookergetconnectiontables/lookergetconnectiontables_test.go @@ -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/testutils" @@ -38,11 +37,11 @@ func TestParseFromYamlLookerGetConnectionTables(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: looker-get-connection-tables - source: my-instance - description: some description + kind: tools + name: example_tool + type: looker-get-connection-tables + source: my-instance + description: some description `, want: server.ToolConfigs{ "example_tool": lkr.Config{ @@ -57,15 +56,12 @@ func TestParseFromYamlLookerGetConnectionTables(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) } }) @@ -86,23 +82,20 @@ func TestFailParseFromYamlLookerGetConnectionTables(t *testing.T) { { desc: "Invalid method", in: ` - tools: - example_tool: - kind: looker-get-connection-tables - source: my-instance - method: GOT - description: some description + kind: tools + name: example_tool + type: looker-get-connection-tables + source: my-instance + method: GOT + description: some description `, - err: "unable to parse tool \"example_tool\" as kind \"looker-get-connection-tables\": [4:1] unknown field \"method\"\n 1 | authRequired: []\n 2 | description: some description\n 3 | kind: looker-get-connection-tables\n> 4 | method: GOT\n ^\n 5 | source: my-instance", + err: "error unmarshaling tools: unable to parse tool \"example_tool\" as type \"looker-get-connection-tables\": [3:1] unknown field \"method\"\n 1 | authRequired: []\n 2 | description: some description\n> 3 | method: GOT\n ^\n 4 | name: example_tool\n 5 | source: my-instance\n 6 | type: looker-get-connection-tables", }, } 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") } diff --git a/internal/tools/looker/lookergetdashboards/lookergetdashboards.go b/internal/tools/looker/lookergetdashboards/lookergetdashboards.go index 70bf701844..17ff2a087a 100644 --- a/internal/tools/looker/lookergetdashboards/lookergetdashboards.go +++ b/internal/tools/looker/lookergetdashboards/lookergetdashboards.go @@ -28,11 +28,11 @@ import ( v4 "github.com/looker-open-source/sdk-codegen/go/sdk/v4" ) -const kind string = "looker-get-dashboards" +const resourceType string = "looker-get-dashboards" 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)) } } @@ -53,7 +53,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) { diff --git a/internal/tools/looker/lookergetdashboards/lookergetdashboards_test.go b/internal/tools/looker/lookergetdashboards/lookergetdashboards_test.go index a9e5cd74d0..83e2e8f9c5 100644 --- a/internal/tools/looker/lookergetdashboards/lookergetdashboards_test.go +++ b/internal/tools/looker/lookergetdashboards/lookergetdashboards_test.go @@ -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/testutils" @@ -38,11 +37,11 @@ func TestParseFromYamlLookerGetDashboards(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: looker-get-dashboards - source: my-instance - description: some description + kind: tools + name: example_tool + type: looker-get-dashboards + source: my-instance + description: some description `, want: server.ToolConfigs{ "example_tool": lkr.Config{ @@ -57,15 +56,12 @@ func TestParseFromYamlLookerGetDashboards(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) } }) @@ -86,23 +82,20 @@ func TestFailParseFromYamlLookerGetDashboards(t *testing.T) { { desc: "Invalid method", in: ` - tools: - example_tool: - kind: looker-get-dashboards - source: my-instance - method: GOT - description: some description + kind: tools + name: example_tool + type: looker-get-dashboards + source: my-instance + method: GOT + description: some description `, - err: "unable to parse tool \"example_tool\" as kind \"looker-get-dashboards\": [4:1] unknown field \"method\"\n 1 | authRequired: []\n 2 | description: some description\n 3 | kind: looker-get-dashboards\n> 4 | method: GOT\n ^\n 5 | source: my-instance", + err: "error unmarshaling tools: unable to parse tool \"example_tool\" as type \"looker-get-dashboards\": [3:1] unknown field \"method\"\n 1 | authRequired: []\n 2 | description: some description\n> 3 | method: GOT\n ^\n 4 | name: example_tool\n 5 | source: my-instance\n 6 | type: looker-get-dashboards", }, } 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") } diff --git a/internal/tools/looker/lookergetdimensions/lookergetdimensions.go b/internal/tools/looker/lookergetdimensions/lookergetdimensions.go index e7f8c9a58f..33e3ffa1ee 100644 --- a/internal/tools/looker/lookergetdimensions/lookergetdimensions.go +++ b/internal/tools/looker/lookergetdimensions/lookergetdimensions.go @@ -29,11 +29,11 @@ import ( v4 "github.com/looker-open-source/sdk-codegen/go/sdk/v4" ) -const kind string = "looker-get-dimensions" +const resourceType string = "looker-get-dimensions" 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)) } } @@ -55,7 +55,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) { diff --git a/internal/tools/looker/lookergetdimensions/lookergetdimensions_test.go b/internal/tools/looker/lookergetdimensions/lookergetdimensions_test.go index ca79a2a996..5d63e5d074 100644 --- a/internal/tools/looker/lookergetdimensions/lookergetdimensions_test.go +++ b/internal/tools/looker/lookergetdimensions/lookergetdimensions_test.go @@ -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/testutils" @@ -38,11 +37,11 @@ func TestParseFromYamlLookerGetDimensions(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: looker-get-dimensions - source: my-instance - description: some description + kind: tools + name: example_tool + type: looker-get-dimensions + source: my-instance + description: some description `, want: server.ToolConfigs{ "example_tool": lkr.Config{ @@ -57,15 +56,12 @@ func TestParseFromYamlLookerGetDimensions(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) } }) @@ -86,23 +82,20 @@ func TestFailParseFromYamlLookerGetDimensions(t *testing.T) { { desc: "Invalid method", in: ` - tools: - example_tool: - kind: looker-get-dimensions - source: my-instance - method: GOT - description: some description + kind: tools + name: example_tool + type: looker-get-dimensions + source: my-instance + method: GOT + description: some description `, - err: "unable to parse tool \"example_tool\" as kind \"looker-get-dimensions\": [4:1] unknown field \"method\"\n 1 | authRequired: []\n 2 | description: some description\n 3 | kind: looker-get-dimensions\n> 4 | method: GOT\n ^\n 5 | source: my-instance", + err: "error unmarshaling tools: unable to parse tool \"example_tool\" as type \"looker-get-dimensions\": [3:1] unknown field \"method\"\n 1 | authRequired: []\n 2 | description: some description\n> 3 | method: GOT\n ^\n 4 | name: example_tool\n 5 | source: my-instance\n 6 | type: looker-get-dimensions", }, } 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") } diff --git a/internal/tools/looker/lookergetexplores/lookergetexplores.go b/internal/tools/looker/lookergetexplores/lookergetexplores.go index f17ad3779c..71b6e65c4a 100644 --- a/internal/tools/looker/lookergetexplores/lookergetexplores.go +++ b/internal/tools/looker/lookergetexplores/lookergetexplores.go @@ -28,11 +28,11 @@ import ( v4 "github.com/looker-open-source/sdk-codegen/go/sdk/v4" ) -const kind string = "looker-get-explores" +const resourceType string = "looker-get-explores" 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"` @@ -65,7 +65,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) { diff --git a/internal/tools/looker/lookergetexplores/lookergetexplores_test.go b/internal/tools/looker/lookergetexplores/lookergetexplores_test.go index 5b5b979e62..4e3aa50795 100644 --- a/internal/tools/looker/lookergetexplores/lookergetexplores_test.go +++ b/internal/tools/looker/lookergetexplores/lookergetexplores_test.go @@ -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/testutils" @@ -38,11 +37,11 @@ func TestParseFromYamlLookerGetExplores(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: looker-get-explores - source: my-instance - description: some description + kind: tools + name: example_tool + type: looker-get-explores + source: my-instance + description: some description `, want: server.ToolConfigs{ "example_tool": lkr.Config{ @@ -57,15 +56,12 @@ func TestParseFromYamlLookerGetExplores(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) } }) @@ -86,23 +82,20 @@ func TestFailParseFromYamlLookerGetFilters(t *testing.T) { { desc: "Invalid method", in: ` - tools: - example_tool: - kind: looker-get-explores - source: my-instance - method: GOT - description: some description + kind: tools + name: example_tool + type: looker-get-explores + source: my-instance + method: GOT + description: some description `, - err: "unable to parse tool \"example_tool\" as kind \"looker-get-explores\": [4:1] unknown field \"method\"\n 1 | authRequired: []\n 2 | description: some description\n 3 | kind: looker-get-explores\n> 4 | method: GOT\n ^\n 5 | source: my-instance", + err: "error unmarshaling tools: unable to parse tool \"example_tool\" as type \"looker-get-explores\": [3:1] unknown field \"method\"\n 1 | authRequired: []\n 2 | description: some description\n> 3 | method: GOT\n ^\n 4 | name: example_tool\n 5 | source: my-instance\n 6 | type: looker-get-explores", }, } 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") } diff --git a/internal/tools/looker/lookergetfilters/lookergetfilters.go b/internal/tools/looker/lookergetfilters/lookergetfilters.go index 4928954464..1fe143cf46 100644 --- a/internal/tools/looker/lookergetfilters/lookergetfilters.go +++ b/internal/tools/looker/lookergetfilters/lookergetfilters.go @@ -29,11 +29,11 @@ import ( v4 "github.com/looker-open-source/sdk-codegen/go/sdk/v4" ) -const kind string = "looker-get-filters" +const resourceType string = "looker-get-filters" 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)) } } @@ -55,7 +55,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) { diff --git a/internal/tools/looker/lookergetfilters/lookergetfilters_test.go b/internal/tools/looker/lookergetfilters/lookergetfilters_test.go index b899a009cb..76b3ab19db 100644 --- a/internal/tools/looker/lookergetfilters/lookergetfilters_test.go +++ b/internal/tools/looker/lookergetfilters/lookergetfilters_test.go @@ -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/testutils" @@ -38,11 +37,11 @@ func TestParseFromYamlLookerGetFilters(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: looker-get-filters - source: my-instance - description: some description + kind: tools + name: example_tool + type: looker-get-filters + source: my-instance + description: some description `, want: server.ToolConfigs{ "example_tool": lkr.Config{ @@ -57,15 +56,12 @@ func TestParseFromYamlLookerGetFilters(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) } }) @@ -86,23 +82,20 @@ func TestFailParseFromYamlLookerGetFilters(t *testing.T) { { desc: "Invalid method", in: ` - tools: - example_tool: - kind: looker-get-filters - source: my-instance - method: GOT - description: some description + kind: tools + name: example_tool + type: looker-get-filters + source: my-instance + method: GOT + description: some description `, - err: "unable to parse tool \"example_tool\" as kind \"looker-get-filters\": [4:1] unknown field \"method\"\n 1 | authRequired: []\n 2 | description: some description\n 3 | kind: looker-get-filters\n> 4 | method: GOT\n ^\n 5 | source: my-instance", + err: "error unmarshaling tools: unable to parse tool \"example_tool\" as type \"looker-get-filters\": [3:1] unknown field \"method\"\n 1 | authRequired: []\n 2 | description: some description\n> 3 | method: GOT\n ^\n 4 | name: example_tool\n 5 | source: my-instance\n 6 | type: looker-get-filters", }, } 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") } diff --git a/internal/tools/looker/lookergetlooks/lookergetlooks.go b/internal/tools/looker/lookergetlooks/lookergetlooks.go index 91fe0c9f1a..9e3d6c1a88 100644 --- a/internal/tools/looker/lookergetlooks/lookergetlooks.go +++ b/internal/tools/looker/lookergetlooks/lookergetlooks.go @@ -28,11 +28,11 @@ import ( v4 "github.com/looker-open-source/sdk-codegen/go/sdk/v4" ) -const kind string = "looker-get-looks" +const resourceType string = "looker-get-looks" 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)) } } @@ -53,7 +53,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) { diff --git a/internal/tools/looker/lookergetlooks/lookergetlooks_test.go b/internal/tools/looker/lookergetlooks/lookergetlooks_test.go index 34d9b56885..56320498eb 100644 --- a/internal/tools/looker/lookergetlooks/lookergetlooks_test.go +++ b/internal/tools/looker/lookergetlooks/lookergetlooks_test.go @@ -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/testutils" @@ -38,11 +37,11 @@ func TestParseFromYamlLookerGetLooks(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: looker-get-looks - source: my-instance - description: some description + kind: tools + name: example_tool + type: looker-get-looks + source: my-instance + description: some description `, want: server.ToolConfigs{ "example_tool": lkr.Config{ @@ -57,15 +56,12 @@ func TestParseFromYamlLookerGetLooks(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) } }) @@ -86,23 +82,20 @@ func TestFailParseFromYamlLookerGetLooks(t *testing.T) { { desc: "Invalid method", in: ` - tools: - example_tool: - kind: looker-get-looks - source: my-instance - method: GOT - description: some description + kind: tools + name: example_tool + type: looker-get-looks + source: my-instance + method: GOT + description: some description `, - err: "unable to parse tool \"example_tool\" as kind \"looker-get-looks\": [4:1] unknown field \"method\"\n 1 | authRequired: []\n 2 | description: some description\n 3 | kind: looker-get-looks\n> 4 | method: GOT\n ^\n 5 | source: my-instance", + err: "error unmarshaling tools: unable to parse tool \"example_tool\" as type \"looker-get-looks\": [3:1] unknown field \"method\"\n 1 | authRequired: []\n 2 | description: some description\n> 3 | method: GOT\n ^\n 4 | name: example_tool\n 5 | source: my-instance\n 6 | type: looker-get-looks", }, } 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") } diff --git a/internal/tools/looker/lookergetmeasures/lookergetmeasures.go b/internal/tools/looker/lookergetmeasures/lookergetmeasures.go index 84e8e2b1f0..2a2662668f 100644 --- a/internal/tools/looker/lookergetmeasures/lookergetmeasures.go +++ b/internal/tools/looker/lookergetmeasures/lookergetmeasures.go @@ -29,11 +29,11 @@ import ( v4 "github.com/looker-open-source/sdk-codegen/go/sdk/v4" ) -const kind string = "looker-get-measures" +const resourceType string = "looker-get-measures" 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)) } } @@ -55,7 +55,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) { diff --git a/internal/tools/looker/lookergetmeasures/lookergetmeasures_test.go b/internal/tools/looker/lookergetmeasures/lookergetmeasures_test.go index b47a64e103..cb29d86f85 100644 --- a/internal/tools/looker/lookergetmeasures/lookergetmeasures_test.go +++ b/internal/tools/looker/lookergetmeasures/lookergetmeasures_test.go @@ -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/testutils" @@ -38,11 +37,11 @@ func TestParseFromYamlLookerGetMeasures(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: looker-get-measures - source: my-instance - description: some description + kind: tools + name: example_tool + type: looker-get-measures + source: my-instance + description: some description `, want: server.ToolConfigs{ "example_tool": lkr.Config{ @@ -57,15 +56,12 @@ func TestParseFromYamlLookerGetMeasures(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) } }) @@ -86,23 +82,20 @@ func TestFailParseFromYamlLookerGetMeasures(t *testing.T) { { desc: "Invalid method", in: ` - tools: - example_tool: - kind: looker-get-measures - source: my-instance - method: GOT - description: some description + kind: tools + name: example_tool + type: looker-get-measures + source: my-instance + method: GOT + description: some description `, - err: "unable to parse tool \"example_tool\" as kind \"looker-get-measures\": [4:1] unknown field \"method\"\n 1 | authRequired: []\n 2 | description: some description\n 3 | kind: looker-get-measures\n> 4 | method: GOT\n ^\n 5 | source: my-instance", + err: "error unmarshaling tools: unable to parse tool \"example_tool\" as type \"looker-get-measures\": [3:1] unknown field \"method\"\n 1 | authRequired: []\n 2 | description: some description\n> 3 | method: GOT\n ^\n 4 | name: example_tool\n 5 | source: my-instance\n 6 | type: looker-get-measures", }, } 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") } diff --git a/internal/tools/looker/lookergetmodels/lookergetmodels.go b/internal/tools/looker/lookergetmodels/lookergetmodels.go index 2c2bfc6819..d085191328 100644 --- a/internal/tools/looker/lookergetmodels/lookergetmodels.go +++ b/internal/tools/looker/lookergetmodels/lookergetmodels.go @@ -28,11 +28,11 @@ import ( v4 "github.com/looker-open-source/sdk-codegen/go/sdk/v4" ) -const kind string = "looker-get-models" +const resourceType string = "looker-get-models" 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"` @@ -65,7 +65,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) { diff --git a/internal/tools/looker/lookergetmodels/lookergetmodels_test.go b/internal/tools/looker/lookergetmodels/lookergetmodels_test.go index fe24406e38..742d004599 100644 --- a/internal/tools/looker/lookergetmodels/lookergetmodels_test.go +++ b/internal/tools/looker/lookergetmodels/lookergetmodels_test.go @@ -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/testutils" @@ -38,11 +37,11 @@ func TestParseFromYamlLookerGetModels(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: looker-get-models - source: my-instance - description: some description + kind: tools + name: example_tool + type: looker-get-models + source: my-instance + description: some description `, want: server.ToolConfigs{ "example_tool": lkr.Config{ @@ -57,15 +56,12 @@ func TestParseFromYamlLookerGetModels(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) } }) @@ -86,23 +82,20 @@ func TestFailParseFromYamlLookerGetModels(t *testing.T) { { desc: "Invalid method", in: ` - tools: - example_tool: - kind: looker-get-models - source: my-instance - method: GOT - description: some description + kind: tools + name: example_tool + type: looker-get-models + source: my-instance + method: GOT + description: some description `, - err: "unable to parse tool \"example_tool\" as kind \"looker-get-models\": [4:1] unknown field \"method\"\n 1 | authRequired: []\n 2 | description: some description\n 3 | kind: looker-get-models\n> 4 | method: GOT\n ^\n 5 | source: my-instance", + err: "error unmarshaling tools: unable to parse tool \"example_tool\" as type \"looker-get-models\": [3:1] unknown field \"method\"\n 1 | authRequired: []\n 2 | description: some description\n> 3 | method: GOT\n ^\n 4 | name: example_tool\n 5 | source: my-instance\n 6 | type: looker-get-models", }, } 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") } diff --git a/internal/tools/looker/lookergetparameters/lookergetparameters.go b/internal/tools/looker/lookergetparameters/lookergetparameters.go index a3ea51484c..a3f73719bb 100644 --- a/internal/tools/looker/lookergetparameters/lookergetparameters.go +++ b/internal/tools/looker/lookergetparameters/lookergetparameters.go @@ -29,11 +29,11 @@ import ( v4 "github.com/looker-open-source/sdk-codegen/go/sdk/v4" ) -const kind string = "looker-get-parameters" +const resourceType string = "looker-get-parameters" 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)) } } @@ -55,7 +55,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) { diff --git a/internal/tools/looker/lookergetparameters/lookergetparameters_test.go b/internal/tools/looker/lookergetparameters/lookergetparameters_test.go index 113d93b68d..6c54db6e16 100644 --- a/internal/tools/looker/lookergetparameters/lookergetparameters_test.go +++ b/internal/tools/looker/lookergetparameters/lookergetparameters_test.go @@ -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/testutils" @@ -38,11 +37,11 @@ func TestParseFromYamlLookerGetParameters(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: looker-get-parameters - source: my-instance - description: some description + kind: tools + name: example_tool + type: looker-get-parameters + source: my-instance + description: some description `, want: server.ToolConfigs{ "example_tool": lkr.Config{ @@ -57,15 +56,12 @@ func TestParseFromYamlLookerGetParameters(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) } }) @@ -86,23 +82,20 @@ func TestFailParseFromYamlLookerGetParameters(t *testing.T) { { desc: "Invalid method", in: ` - tools: - example_tool: - kind: looker-get-parameters - source: my-instance - method: GOT - description: some description + kind: tools + name: example_tool + type: looker-get-parameters + source: my-instance + method: GOT + description: some description `, - err: "unable to parse tool \"example_tool\" as kind \"looker-get-parameters\": [4:1] unknown field \"method\"\n 1 | authRequired: []\n 2 | description: some description\n 3 | kind: looker-get-parameters\n> 4 | method: GOT\n ^\n 5 | source: my-instance", + err: "error unmarshaling tools: unable to parse tool \"example_tool\" as type \"looker-get-parameters\": [3:1] unknown field \"method\"\n 1 | authRequired: []\n 2 | description: some description\n> 3 | method: GOT\n ^\n 4 | name: example_tool\n 5 | source: my-instance\n 6 | type: looker-get-parameters", }, } 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") } diff --git a/internal/tools/looker/lookergetprojectfile/lookergetprojectfile.go b/internal/tools/looker/lookergetprojectfile/lookergetprojectfile.go index 82df7f2f44..1b8dfce940 100644 --- a/internal/tools/looker/lookergetprojectfile/lookergetprojectfile.go +++ b/internal/tools/looker/lookergetprojectfile/lookergetprojectfile.go @@ -29,11 +29,11 @@ import ( v4 "github.com/looker-open-source/sdk-codegen/go/sdk/v4" ) -const kind string = "looker-get-project-file" +const resourceType string = "looker-get-project-file" 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"` @@ -65,7 +65,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) { diff --git a/internal/tools/looker/lookergetprojectfile/lookergetprojectfile_test.go b/internal/tools/looker/lookergetprojectfile/lookergetprojectfile_test.go index 4d6d25bd1a..d3d5c9382e 100644 --- a/internal/tools/looker/lookergetprojectfile/lookergetprojectfile_test.go +++ b/internal/tools/looker/lookergetprojectfile/lookergetprojectfile_test.go @@ -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/testutils" @@ -38,11 +37,11 @@ func TestParseFromYamlLookerGetProjectFile(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: looker-get-project-file - source: my-instance - description: some description + kind: tools + name: example_tool + type: looker-get-project-file + source: my-instance + description: some description `, want: server.ToolConfigs{ "example_tool": lkr.Config{ @@ -57,15 +56,12 @@ func TestParseFromYamlLookerGetProjectFile(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) } }) @@ -86,23 +82,19 @@ func TestFailParseFromYamlLookerGetProjectFile(t *testing.T) { { desc: "Invalid method", in: ` - tools: - example_tool: - kind: looker-get-project-file - source: my-instance - method: GOT - description: some description + kind: tools + name: example_tool + type: looker-get-project-file + source: my-instance + method: GOT + description: some description `, - err: "unable to parse tool \"example_tool\" as kind \"looker-get-project-file\": [4:1] unknown field \"method\"\n 1 | authRequired: []\n 2 | description: some description\n 3 | kind: looker-get-project-file\n> 4 | method: GOT\n ^\n 5 | source: my-instance", + err: "error unmarshaling tools: unable to parse tool \"example_tool\" as type \"looker-get-project-file\": [3:1] unknown field \"method\"\n 1 | authRequired: []\n 2 | description: some description\n> 3 | method: GOT\n ^\n 4 | name: example_tool\n 5 | source: my-instance\n 6 | type: looker-get-project-file", }, } 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") } diff --git a/internal/tools/looker/lookergetprojectfiles/lookergetprojectfiles.go b/internal/tools/looker/lookergetprojectfiles/lookergetprojectfiles.go index 85c1b2534c..2e165a7128 100644 --- a/internal/tools/looker/lookergetprojectfiles/lookergetprojectfiles.go +++ b/internal/tools/looker/lookergetprojectfiles/lookergetprojectfiles.go @@ -28,11 +28,11 @@ import ( v4 "github.com/looker-open-source/sdk-codegen/go/sdk/v4" ) -const kind string = "looker-get-project-files" +const resourceType string = "looker-get-project-files" 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)) } } @@ -53,7 +53,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) { diff --git a/internal/tools/looker/lookergetprojectfiles/lookergetprojectfiles_test.go b/internal/tools/looker/lookergetprojectfiles/lookergetprojectfiles_test.go index dd7eb873d6..319b3f8461 100644 --- a/internal/tools/looker/lookergetprojectfiles/lookergetprojectfiles_test.go +++ b/internal/tools/looker/lookergetprojectfiles/lookergetprojectfiles_test.go @@ -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/testutils" @@ -38,11 +37,11 @@ func TestParseFromYamlLookerGetProjectFiles(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: looker-get-project-files - source: my-instance - description: some description + kind: tools + name: example_tool + type: looker-get-project-files + source: my-instance + description: some description `, want: server.ToolConfigs{ "example_tool": lkr.Config{ @@ -57,15 +56,12 @@ func TestParseFromYamlLookerGetProjectFiles(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) } }) @@ -86,23 +82,20 @@ func TestFailParseFromYamlLookerGetProjectFiles(t *testing.T) { { desc: "Invalid method", in: ` - tools: - example_tool: - kind: looker-get-project-files - source: my-instance - method: GOT - description: some description + kind: tools + name: example_tool + type: looker-get-project-files + source: my-instance + method: GOT + description: some description `, - err: "unable to parse tool \"example_tool\" as kind \"looker-get-project-files\": [4:1] unknown field \"method\"\n 1 | authRequired: []\n 2 | description: some description\n 3 | kind: looker-get-project-files\n> 4 | method: GOT\n ^\n 5 | source: my-instance", + err: "error unmarshaling tools: unable to parse tool \"example_tool\" as type \"looker-get-project-files\": [3:1] unknown field \"method\"\n 1 | authRequired: []\n 2 | description: some description\n> 3 | method: GOT\n ^\n 4 | name: example_tool\n 5 | source: my-instance\n 6 | type: looker-get-project-files", }, } 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") } diff --git a/internal/tools/looker/lookergetprojects/lookergetprojects.go b/internal/tools/looker/lookergetprojects/lookergetprojects.go index 697b85f44a..c39bff06c4 100644 --- a/internal/tools/looker/lookergetprojects/lookergetprojects.go +++ b/internal/tools/looker/lookergetprojects/lookergetprojects.go @@ -28,11 +28,11 @@ import ( v4 "github.com/looker-open-source/sdk-codegen/go/sdk/v4" ) -const kind string = "looker-get-projects" +const resourceType string = "looker-get-projects" 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)) } } @@ -53,7 +53,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) { diff --git a/internal/tools/looker/lookergetprojects/lookergetprojects_test.go b/internal/tools/looker/lookergetprojects/lookergetprojects_test.go index 137291bda9..b390257457 100644 --- a/internal/tools/looker/lookergetprojects/lookergetprojects_test.go +++ b/internal/tools/looker/lookergetprojects/lookergetprojects_test.go @@ -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/testutils" @@ -38,11 +37,11 @@ func TestParseFromYamlLookerGetProjects(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: looker-get-projects - source: my-instance - description: some description + kind: tools + name: example_tool + type: looker-get-projects + source: my-instance + description: some description `, want: server.ToolConfigs{ "example_tool": lkr.Config{ @@ -57,15 +56,11 @@ func TestParseFromYamlLookerGetProjects(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) } }) @@ -86,23 +81,19 @@ func TestFailParseFromYamlLookerGetProjecProjects(t *testing.T) { { desc: "Invalid method", in: ` - tools: - example_tool: - kind: looker-get-projects - source: my-instance - method: GOT - description: some description + kind: tools + name: example_tool + type: looker-get-projects + source: my-instance + method: GOT + description: some description `, - err: "unable to parse tool \"example_tool\" as kind \"looker-get-projects\": [4:1] unknown field \"method\"\n 1 | authRequired: []\n 2 | description: some description\n 3 | kind: looker-get-projects\n> 4 | method: GOT\n ^\n 5 | source: my-instance", + err: "error unmarshaling tools: unable to parse tool \"example_tool\" as type \"looker-get-projects\": [3:1] unknown field \"method\"\n 1 | authRequired: []\n 2 | description: some description\n> 3 | method: GOT\n ^\n 4 | name: example_tool\n 5 | source: my-instance\n 6 | type: looker-get-projects", }, } 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") } diff --git a/internal/tools/looker/lookerhealthanalyze/lookerhealthanalyze.go b/internal/tools/looker/lookerhealthanalyze/lookerhealthanalyze.go index 530eb11c1b..1fb8b70cd3 100644 --- a/internal/tools/looker/lookerhealthanalyze/lookerhealthanalyze.go +++ b/internal/tools/looker/lookerhealthanalyze/lookerhealthanalyze.go @@ -34,11 +34,11 @@ import ( // ================================================================================================================= // START MCP SERVER CORE LOGIC // ================================================================================================================= -const kind string = "looker-health-analyze" +const resourceType string = "looker-health-analyze" 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"` @@ -70,7 +70,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) { diff --git a/internal/tools/looker/lookerhealthanalyze/lookerhealthanalyze_test.go b/internal/tools/looker/lookerhealthanalyze/lookerhealthanalyze_test.go index 2ef69c92eb..52d0af8c89 100644 --- a/internal/tools/looker/lookerhealthanalyze/lookerhealthanalyze_test.go +++ b/internal/tools/looker/lookerhealthanalyze/lookerhealthanalyze_test.go @@ -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/testutils" @@ -38,11 +37,11 @@ func TestParseFromYamlLookerHealthAnalyze(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: looker-health-analyze - source: my-instance - description: some description + kind: tools + name: example_tool + type: looker-health-analyze + source: my-instance + description: some description `, want: server.ToolConfigs{ "example_tool": lha.Config{ @@ -57,15 +56,11 @@ func TestParseFromYamlLookerHealthAnalyze(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) } }) @@ -85,22 +80,18 @@ func TestFailParseFromYamlLookerHealthAnalyze(t *testing.T) { { desc: "Invalid field", in: ` - tools: - example_tool: - kind: looker-health-analyze - source: my-instance - invalid_field: true + kind: tools + name: example_tool + type: looker-health-analyze + source: my-instance + invalid_field: true `, - err: "unable to parse tool \"example_tool\" as kind \"looker-health-analyze\": [2:1] unknown field \"invalid_field\"", + err: "unable to parse tool \"example_tool\" as type \"looker-health-analyze\": [2:1] unknown field \"invalid_field\"", }, } 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") } diff --git a/internal/tools/looker/lookerhealthpulse/lookerhealthpulse.go b/internal/tools/looker/lookerhealthpulse/lookerhealthpulse.go index f6887b6c2c..9b9e2a39e4 100644 --- a/internal/tools/looker/lookerhealthpulse/lookerhealthpulse.go +++ b/internal/tools/looker/lookerhealthpulse/lookerhealthpulse.go @@ -34,11 +34,11 @@ import ( // ================================================================================================================= // START MCP SERVER CORE LOGIC // ================================================================================================================= -const kind string = "looker-health-pulse" +const resourceType string = "looker-health-pulse" 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"` @@ -70,7 +70,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) { diff --git a/internal/tools/looker/lookerhealthpulse/lookerhealthpulse_test.go b/internal/tools/looker/lookerhealthpulse/lookerhealthpulse_test.go index 6e635205b7..7ef3779bbd 100644 --- a/internal/tools/looker/lookerhealthpulse/lookerhealthpulse_test.go +++ b/internal/tools/looker/lookerhealthpulse/lookerhealthpulse_test.go @@ -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/testutils" @@ -38,11 +37,11 @@ func TestParseFromYamlLookerHealthPulse(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: looker-health-pulse - source: my-instance - description: some description + kind: tools + name: example_tool + type: looker-health-pulse + source: my-instance + description: some description `, want: server.ToolConfigs{ "example_tool": lhp.Config{ @@ -57,15 +56,11 @@ func TestParseFromYamlLookerHealthPulse(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) } }) @@ -85,22 +80,18 @@ func TestFailParseFromYamlLookerHealthPulse(t *testing.T) { { desc: "Invalid field", in: ` - tools: - example_tool: - kind: looker-health-pulse - source: my-instance - invalid_field: true + kind: tools + name: example_tool + type: looker-health-pulse + source: my-instance + invalid_field: true `, - err: "unable to parse tool \"example_tool\" as kind \"looker-health-pulse\": [2:1] unknown field \"invalid_field\"", + err: "unable to parse tool \"example_tool\" as type \"looker-health-pulse\": [2:1] unknown field \"invalid_field\"", }, } 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") } diff --git a/internal/tools/looker/lookerhealthvacuum/lookerhealthvacuum.go b/internal/tools/looker/lookerhealthvacuum/lookerhealthvacuum.go index 93b7f0f53f..1d0eb2c10d 100644 --- a/internal/tools/looker/lookerhealthvacuum/lookerhealthvacuum.go +++ b/internal/tools/looker/lookerhealthvacuum/lookerhealthvacuum.go @@ -34,11 +34,11 @@ import ( // ================================================================================================================= // START MCP SERVER CORE LOGIC // ================================================================================================================= -const kind string = "looker-health-vacuum" +const resourceType string = "looker-health-vacuum" 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"` @@ -70,7 +70,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) { diff --git a/internal/tools/looker/lookerhealthvacuum/lookerhealthvacuum_test.go b/internal/tools/looker/lookerhealthvacuum/lookerhealthvacuum_test.go index c2864ca8f7..7da00fc980 100644 --- a/internal/tools/looker/lookerhealthvacuum/lookerhealthvacuum_test.go +++ b/internal/tools/looker/lookerhealthvacuum/lookerhealthvacuum_test.go @@ -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/testutils" @@ -38,11 +37,11 @@ func TestParseFromYamlLookerHealthVacuum(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: looker-health-vacuum - source: my-instance - description: some description + kind: tools + name: example_tool + type: looker-health-vacuum + source: my-instance + description: some description `, want: server.ToolConfigs{ "example_tool": lhv.Config{ @@ -57,15 +56,11 @@ func TestParseFromYamlLookerHealthVacuum(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) } }) @@ -85,22 +80,18 @@ func TestFailParseFromYamlLookerHealthVacuum(t *testing.T) { { desc: "Invalid field", in: ` - tools: - example_tool: - kind: looker-health-vacuum - source: my-instance - invalid_field: true + kind: tools + name: example_tool + type: looker-health-vacuum + source: my-instance + invalid_field: true `, - err: "unable to parse tool \"example_tool\" as kind \"looker-health-vacuum\": [2:1] unknown field \"invalid_field\"", + err: "unable to parse tool \"example_tool\" as type \"looker-health-vacuum\": [2:1] unknown field \"invalid_field\"", }, } 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") } diff --git a/internal/tools/looker/lookermakedashboard/lookermakedashboard.go b/internal/tools/looker/lookermakedashboard/lookermakedashboard.go index 2bdbfa062e..8f07ab962e 100644 --- a/internal/tools/looker/lookermakedashboard/lookermakedashboard.go +++ b/internal/tools/looker/lookermakedashboard/lookermakedashboard.go @@ -30,11 +30,11 @@ import ( v4 "github.com/looker-open-source/sdk-codegen/go/sdk/v4" ) -const kind string = "looker-make-dashboard" +const resourceType string = "looker-make-dashboard" 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)) } } @@ -55,7 +55,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) { diff --git a/internal/tools/looker/lookermakedashboard/lookermakedashboard_test.go b/internal/tools/looker/lookermakedashboard/lookermakedashboard_test.go index 05fbe6103d..ef332cb1f6 100644 --- a/internal/tools/looker/lookermakedashboard/lookermakedashboard_test.go +++ b/internal/tools/looker/lookermakedashboard/lookermakedashboard_test.go @@ -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/testutils" @@ -38,12 +37,12 @@ func TestParseFromYamlLookerMakeDashboard(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: looker-make-dashboard - source: my-instance - description: some description - `, + kind: tools + name: example_tool + type: looker-make-dashboard + source: my-instance + description: some description + `, want: server.ToolConfigs{ "example_tool": lkr.Config{ Name: "example_tool", @@ -57,15 +56,11 @@ func TestParseFromYamlLookerMakeDashboard(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) } }) @@ -86,23 +81,19 @@ func TestFailParseFromYamlMakeDashboard(t *testing.T) { { desc: "Invalid method", in: ` - tools: - example_tool: - kind: looker-make-dashboard - source: my-instance - method: GOT - description: some description + kind: tools + name: example_tool + type: looker-make-dashboard + source: my-instance + method: GOT + description: some description `, - err: "unable to parse tool \"example_tool\" as kind \"looker-make-dashboard\": [4:1] unknown field \"method\"\n 1 | authRequired: []\n 2 | description: some description\n 3 | kind: looker-make-dashboard\n> 4 | method: GOT\n ^\n 5 | source: my-instance", + err: "error unmarshaling tools: unable to parse tool \"example_tool\" as type \"looker-make-dashboard\": [3:1] unknown field \"method\"\n 1 | authRequired: []\n 2 | description: some description\n> 3 | method: GOT\n ^\n 4 | name: example_tool\n 5 | source: my-instance\n 6 | type: looker-make-dashboard", }, } 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") } diff --git a/internal/tools/looker/lookermakelook/lookermakelook.go b/internal/tools/looker/lookermakelook/lookermakelook.go index 748a5255e1..6a8f58f478 100644 --- a/internal/tools/looker/lookermakelook/lookermakelook.go +++ b/internal/tools/looker/lookermakelook/lookermakelook.go @@ -31,11 +31,11 @@ import ( v4 "github.com/looker-open-source/sdk-codegen/go/sdk/v4" ) -const kind string = "looker-make-look" +const resourceType string = "looker-make-look" 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"` @@ -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) { diff --git a/internal/tools/looker/lookermakelook/lookermakelook_test.go b/internal/tools/looker/lookermakelook/lookermakelook_test.go index c0cf31821c..38e06a9aee 100644 --- a/internal/tools/looker/lookermakelook/lookermakelook_test.go +++ b/internal/tools/looker/lookermakelook/lookermakelook_test.go @@ -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/testutils" @@ -38,11 +37,11 @@ func TestParseFromYamlLookerMakeLook(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: looker-make-look - source: my-instance - description: some description + kind: tools + name: example_tool + type: looker-make-look + source: my-instance + description: some description `, want: server.ToolConfigs{ "example_tool": lkr.Config{ @@ -57,15 +56,11 @@ func TestParseFromYamlLookerMakeLook(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) } }) @@ -86,23 +81,19 @@ func TestFailParseFromYamlLookerMakeLook(t *testing.T) { { desc: "Invalid method", in: ` - tools: - example_tool: - kind: looker-make-look - source: my-instance - method: GOT - description: some description + kind: tools + name: example_tool + type: looker-make-look + source: my-instance + method: GOT + description: some description `, - err: "unable to parse tool \"example_tool\" as kind \"looker-make-look\": [4:1] unknown field \"method\"\n 1 | authRequired: []\n 2 | description: some description\n 3 | kind: looker-make-look\n> 4 | method: GOT\n ^\n 5 | source: my-instance", + err: "error unmarshaling tools: unable to parse tool \"example_tool\" as type \"looker-make-look\": [3:1] unknown field \"method\"\n 1 | authRequired: []\n 2 | description: some description\n> 3 | method: GOT\n ^\n 4 | name: example_tool\n 5 | source: my-instance\n 6 | type: looker-make-look", }, } 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") } diff --git a/internal/tools/looker/lookerquery/lookerquery.go b/internal/tools/looker/lookerquery/lookerquery.go index 1da8cd4fc0..b1336c63cd 100644 --- a/internal/tools/looker/lookerquery/lookerquery.go +++ b/internal/tools/looker/lookerquery/lookerquery.go @@ -30,11 +30,11 @@ import ( v4 "github.com/looker-open-source/sdk-codegen/go/sdk/v4" ) -const kind string = "looker-query" +const resourceType string = "looker-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)) } } @@ -55,7 +55,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) { diff --git a/internal/tools/looker/lookerquery/lookerquery_test.go b/internal/tools/looker/lookerquery/lookerquery_test.go index cec149233d..1e30a96da4 100644 --- a/internal/tools/looker/lookerquery/lookerquery_test.go +++ b/internal/tools/looker/lookerquery/lookerquery_test.go @@ -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/testutils" @@ -38,11 +37,11 @@ func TestParseFromYamlLookerQuery(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: looker-query - source: my-instance - description: some description + kind: tools + name: example_tool + type: looker-query + source: my-instance + description: some description `, want: server.ToolConfigs{ "example_tool": lkr.Config{ @@ -57,15 +56,11 @@ func TestParseFromYamlLookerQuery(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) } }) @@ -86,23 +81,19 @@ func TestFailParseFromYamlLookerQuery(t *testing.T) { { desc: "Invalid method", in: ` - tools: - example_tool: - kind: looker-query - source: my-instance - method: GOT - description: some description + kind: tools + name: example_tool + type: looker-query + source: my-instance + method: GOT + description: some description `, - err: "unable to parse tool \"example_tool\" as kind \"looker-query\": [4:1] unknown field \"method\"\n 1 | authRequired: []\n 2 | description: some description\n 3 | kind: looker-query\n> 4 | method: GOT\n ^\n 5 | source: my-instance", + err: "error unmarshaling tools: unable to parse tool \"example_tool\" as type \"looker-query\": [3:1] unknown field \"method\"\n 1 | authRequired: []\n 2 | description: some description\n> 3 | method: GOT\n ^\n 4 | name: example_tool\n 5 | source: my-instance\n 6 | type: looker-query", }, } 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") } diff --git a/internal/tools/looker/lookerquerysql/lookerquerysql.go b/internal/tools/looker/lookerquerysql/lookerquerysql.go index 2b17bb1b9a..3f9d0831af 100644 --- a/internal/tools/looker/lookerquerysql/lookerquerysql.go +++ b/internal/tools/looker/lookerquerysql/lookerquerysql.go @@ -29,11 +29,11 @@ import ( v4 "github.com/looker-open-source/sdk-codegen/go/sdk/v4" ) -const kind string = "looker-query-sql" +const resourceType string = "looker-query-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)) } } @@ -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"` @@ -65,7 +65,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) { diff --git a/internal/tools/looker/lookerquerysql/lookerquerysql_test.go b/internal/tools/looker/lookerquerysql/lookerquerysql_test.go index 55906adae2..6a49f36bbe 100644 --- a/internal/tools/looker/lookerquerysql/lookerquerysql_test.go +++ b/internal/tools/looker/lookerquerysql/lookerquerysql_test.go @@ -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/testutils" @@ -38,11 +37,11 @@ func TestParseFromYamlLookerQuerySql(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: looker-query-sql - source: my-instance - description: some description + kind: tools + name: example_tool + type: looker-query-sql + source: my-instance + description: some description `, want: server.ToolConfigs{ "example_tool": lkr.Config{ @@ -57,15 +56,12 @@ func TestParseFromYamlLookerQuerySql(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) } }) @@ -86,23 +82,20 @@ func TestFailParseFromYamlLookerQuerySql(t *testing.T) { { desc: "Invalid method", in: ` - tools: - example_tool: - kind: looker-query-sql - source: my-instance - method: GOT - description: some description + kind: tools + name: example_tool + type: looker-query-sql + source: my-instance + method: GOT + description: some description `, - err: "unable to parse tool \"example_tool\" as kind \"looker-query-sql\": [4:1] unknown field \"method\"\n 1 | authRequired: []\n 2 | description: some description\n 3 | kind: looker-query-sql\n> 4 | method: GOT\n ^\n 5 | source: my-instance", + err: "error unmarshaling tools: unable to parse tool \"example_tool\" as type \"looker-query-sql\": [3:1] unknown field \"method\"\n 1 | authRequired: []\n 2 | description: some description\n> 3 | method: GOT\n ^\n 4 | name: example_tool\n 5 | source: my-instance\n 6 | type: looker-query-sql", }, } 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") } diff --git a/internal/tools/looker/lookerqueryurl/lookerqueryurl.go b/internal/tools/looker/lookerqueryurl/lookerqueryurl.go index 5442ebbac1..c0ce37f072 100644 --- a/internal/tools/looker/lookerqueryurl/lookerqueryurl.go +++ b/internal/tools/looker/lookerqueryurl/lookerqueryurl.go @@ -29,11 +29,11 @@ import ( v4 "github.com/looker-open-source/sdk-codegen/go/sdk/v4" ) -const kind string = "looker-query-url" +const resourceType string = "looker-query-url" 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"` @@ -65,7 +65,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) { diff --git a/internal/tools/looker/lookerqueryurl/lookerqueryurl_test.go b/internal/tools/looker/lookerqueryurl/lookerqueryurl_test.go index 071db1c46f..e98838f913 100644 --- a/internal/tools/looker/lookerqueryurl/lookerqueryurl_test.go +++ b/internal/tools/looker/lookerqueryurl/lookerqueryurl_test.go @@ -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/testutils" @@ -38,11 +37,11 @@ func TestParseFromYamlLookerQueryUrl(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: looker-query-url - source: my-instance - description: some description + kind: tools + name: example_tool + type: looker-query-url + source: my-instance + description: some description `, want: server.ToolConfigs{ "example_tool": lkr.Config{ @@ -57,15 +56,12 @@ func TestParseFromYamlLookerQueryUrl(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) } }) @@ -86,23 +82,20 @@ func TestFailParseFromYamlLookerQueryUrl(t *testing.T) { { desc: "Invalid method", in: ` - tools: - example_tool: - kind: looker-query-url - source: my-instance - method: GOT - description: some description + kind: tools + name: example_tool + type: looker-query-url + source: my-instance + method: GOT + description: some description `, - err: "unable to parse tool \"example_tool\" as kind \"looker-query-url\": [4:1] unknown field \"method\"\n 1 | authRequired: []\n 2 | description: some description\n 3 | kind: looker-query-url\n> 4 | method: GOT\n ^\n 5 | source: my-instance", + err: "error unmarshaling tools: unable to parse tool \"example_tool\" as type \"looker-query-url\": [3:1] unknown field \"method\"\n 1 | authRequired: []\n 2 | description: some description\n> 3 | method: GOT\n ^\n 4 | name: example_tool\n 5 | source: my-instance\n 6 | type: looker-query-url", }, } 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") } diff --git a/internal/tools/looker/lookerrundashboard/lookerrundashboard.go b/internal/tools/looker/lookerrundashboard/lookerrundashboard.go index 81c621da86..4ce4d70826 100644 --- a/internal/tools/looker/lookerrundashboard/lookerrundashboard.go +++ b/internal/tools/looker/lookerrundashboard/lookerrundashboard.go @@ -31,11 +31,11 @@ import ( v4 "github.com/looker-open-source/sdk-codegen/go/sdk/v4" ) -const kind string = "looker-run-dashboard" +const resourceType string = "looker-run-dashboard" 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"` @@ -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) { diff --git a/internal/tools/looker/lookerrundashboard/lookerrundashboard_test.go b/internal/tools/looker/lookerrundashboard/lookerrundashboard_test.go index cef2619b02..20b55ce433 100644 --- a/internal/tools/looker/lookerrundashboard/lookerrundashboard_test.go +++ b/internal/tools/looker/lookerrundashboard/lookerrundashboard_test.go @@ -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/testutils" @@ -38,11 +37,11 @@ func TestParseFromYamlLookerRunDashboard(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: looker-run-dashboard - source: my-instance - description: some description + kind: tools + name: example_tool + type: looker-run-dashboard + source: my-instance + description: some description `, want: server.ToolConfigs{ "example_tool": lkr.Config{ @@ -57,15 +56,12 @@ func TestParseFromYamlLookerRunDashboard(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) } }) @@ -86,23 +82,20 @@ func TestFailParseFromYamlLookerRunDashboard(t *testing.T) { { desc: "Invalid method", in: ` - tools: - example_tool: - kind: looker-run-dashboard - source: my-instance - method: GOT - description: some description + kind: tools + name: example_tool + type: looker-run-dashboard + source: my-instance + method: GOT + description: some description `, - err: "unable to parse tool \"example_tool\" as kind \"looker-run-dashboard\": [4:1] unknown field \"method\"\n 1 | authRequired: []\n 2 | description: some description\n 3 | kind: looker-run-dashboard\n> 4 | method: GOT\n ^\n 5 | source: my-instance", + err: "error unmarshaling tools: unable to parse tool \"example_tool\" as type \"looker-run-dashboard\": [3:1] unknown field \"method\"\n 1 | authRequired: []\n 2 | description: some description\n> 3 | method: GOT\n ^\n 4 | name: example_tool\n 5 | source: my-instance\n 6 | type: looker-run-dashboard", }, } 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") } diff --git a/internal/tools/looker/lookerrunlook/lookerrunlook.go b/internal/tools/looker/lookerrunlook/lookerrunlook.go index 6db9cd88a3..8c7fd5357b 100644 --- a/internal/tools/looker/lookerrunlook/lookerrunlook.go +++ b/internal/tools/looker/lookerrunlook/lookerrunlook.go @@ -30,11 +30,11 @@ import ( v4 "github.com/looker-open-source/sdk-codegen/go/sdk/v4" ) -const kind string = "looker-run-look" +const resourceType string = "looker-run-look" 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)) } } @@ -55,7 +55,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) { diff --git a/internal/tools/looker/lookerrunlook/lookerrunlook_test.go b/internal/tools/looker/lookerrunlook/lookerrunlook_test.go index bff1f9d830..ea4076b843 100644 --- a/internal/tools/looker/lookerrunlook/lookerrunlook_test.go +++ b/internal/tools/looker/lookerrunlook/lookerrunlook_test.go @@ -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/testutils" @@ -38,11 +37,11 @@ func TestParseFromYamlLookerRunLook(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: looker-run-look - source: my-instance - description: some description + kind: tools + name: example_tool + type: looker-run-look + source: my-instance + description: some description `, want: server.ToolConfigs{ "example_tool": lkr.Config{ @@ -57,15 +56,12 @@ func TestParseFromYamlLookerRunLook(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) } }) @@ -86,23 +82,20 @@ func TestFailParseFromYamlLookerRunLook(t *testing.T) { { desc: "Invalid method", in: ` - tools: - example_tool: - kind: looker-run-look - source: my-instance - method: GOT - description: some description + kind: tools + name: example_tool + type: looker-run-look + source: my-instance + method: GOT + description: some description `, - err: "unable to parse tool \"example_tool\" as kind \"looker-run-look\": [4:1] unknown field \"method\"\n 1 | authRequired: []\n 2 | description: some description\n 3 | kind: looker-run-look\n> 4 | method: GOT\n ^\n 5 | source: my-instance", + err: "error unmarshaling tools: unable to parse tool \"example_tool\" as type \"looker-run-look\": [3:1] unknown field \"method\"\n 1 | authRequired: []\n 2 | description: some description\n> 3 | method: GOT\n ^\n 4 | name: example_tool\n 5 | source: my-instance\n 6 | type: looker-run-look", }, } 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") } diff --git a/internal/tools/looker/lookerupdateprojectfile/lookerupdateprojectfile.go b/internal/tools/looker/lookerupdateprojectfile/lookerupdateprojectfile.go index 002739ff51..b8ba74e4b1 100644 --- a/internal/tools/looker/lookerupdateprojectfile/lookerupdateprojectfile.go +++ b/internal/tools/looker/lookerupdateprojectfile/lookerupdateprojectfile.go @@ -28,11 +28,11 @@ import ( v4 "github.com/looker-open-source/sdk-codegen/go/sdk/v4" ) -const kind string = "looker-update-project-file" +const resourceType string = "looker-update-project-file" 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 { } 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"` @@ -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) { diff --git a/internal/tools/looker/lookerupdateprojectfile/lookerupdateprojectfile_test.go b/internal/tools/looker/lookerupdateprojectfile/lookerupdateprojectfile_test.go index 8b7e0ecfe7..2d7064bbb2 100644 --- a/internal/tools/looker/lookerupdateprojectfile/lookerupdateprojectfile_test.go +++ b/internal/tools/looker/lookerupdateprojectfile/lookerupdateprojectfile_test.go @@ -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/testutils" @@ -38,11 +37,11 @@ func TestParseFromYamlLookerUpdateProjectFile(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: looker-update-project-file - source: my-instance - description: some description + kind: tools + name: example_tool + type: looker-update-project-file + source: my-instance + description: some description `, want: server.ToolConfigs{ "example_tool": lkr.Config{ @@ -57,15 +56,12 @@ func TestParseFromYamlLookerUpdateProjectFile(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) } }) @@ -86,23 +82,20 @@ func TestFailParseFromYamlLookerUpdateProjectFile(t *testing.T) { { desc: "Invalid method", in: ` - tools: - example_tool: - kind: looker-update-project-file - source: my-instance - method: GOT - description: some description + kind: tools + name: example_tool + type: looker-update-project-file + source: my-instance + method: GOT + description: some description `, - err: "unable to parse tool \"example_tool\" as kind \"looker-update-project-file\": [4:1] unknown field \"method\"\n 1 | authRequired: []\n 2 | description: some description\n 3 | kind: looker-update-project-file\n> 4 | method: GOT\n ^\n 5 | source: my-instance", + err: "error unmarshaling tools: unable to parse tool \"example_tool\" as type \"looker-update-project-file\": [3:1] unknown field \"method\"\n 1 | authRequired: []\n 2 | description: some description\n> 3 | method: GOT\n ^\n 4 | name: example_tool\n 5 | source: my-instance\n 6 | type: looker-update-project-file", }, } 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") } diff --git a/internal/tools/mindsdb/mindsdbexecutesql/mindsdbexecutesql.go b/internal/tools/mindsdb/mindsdbexecutesql/mindsdbexecutesql.go index 352531aa97..a6388163e1 100644 --- a/internal/tools/mindsdb/mindsdbexecutesql/mindsdbexecutesql.go +++ b/internal/tools/mindsdb/mindsdbexecutesql/mindsdbexecutesql.go @@ -26,11 +26,11 @@ import ( "github.com/googleapis/genai-toolbox/internal/util/parameters" ) -const kind string = "mindsdb-execute-sql" +const resourceType string = "mindsdb-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)) } } @@ -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) { diff --git a/internal/tools/mindsdb/mindsdbexecutesql/mindsdbexecutesql_test.go b/internal/tools/mindsdb/mindsdbexecutesql/mindsdbexecutesql_test.go index d376731b6b..db59ec7c54 100644 --- a/internal/tools/mindsdb/mindsdbexecutesql/mindsdbexecutesql_test.go +++ b/internal/tools/mindsdb/mindsdbexecutesql/mindsdbexecutesql_test.go @@ -17,7 +17,6 @@ package mindsdbexecutesql_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,14 +36,14 @@ func TestParseFromYamlExecuteSql(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: mindsdb-execute-sql - source: my-instance - description: some description - authRequired: - - my-google-auth-service - - other-auth-service + kind: tools + name: example_tool + type: mindsdb-execute-sql + source: my-instance + description: some description + authRequired: + - my-google-auth-service + - other-auth-service `, want: server.ToolConfigs{ "example_tool": mindsdbexecutesql.Config{ @@ -59,15 +58,12 @@ func TestParseFromYamlExecuteSql(t *testing.T) { } for _, tc := range tcs { t.Run(tc.desc, func(t *testing.T) { - got := struct { - Tools server.ToolConfigs `yaml:"tools"` - }{} // Parse contents - err := yaml.UnmarshalContext(ctx, testutils.FormatYaml(tc.in), &got) + _, _, _, got, _, _, err := server.UnmarshalResourceConfig(ctx, testutils.FormatYaml(tc.in)) if err != nil { t.Fatalf("unable to unmarshal: %s", err) } - if diff := cmp.Diff(tc.want, got.Tools); diff != "" { + if diff := cmp.Diff(tc.want, got); diff != "" { t.Fatalf("incorrect parse: diff %v", diff) } }) diff --git a/internal/tools/mindsdb/mindsdbsql/mindsdbsql.go b/internal/tools/mindsdb/mindsdbsql/mindsdbsql.go index 414d992fe2..c936a9edc3 100644 --- a/internal/tools/mindsdb/mindsdbsql/mindsdbsql.go +++ b/internal/tools/mindsdb/mindsdbsql/mindsdbsql.go @@ -26,11 +26,11 @@ import ( "github.com/googleapis/genai-toolbox/internal/util/parameters" ) -const kind string = "mindsdb-sql" +const resourceType string = "mindsdb-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) { diff --git a/internal/tools/mindsdb/mindsdbsql/mindsdbsql_test.go b/internal/tools/mindsdb/mindsdbsql/mindsdbsql_test.go index ad96f53418..d203797196 100644 --- a/internal/tools/mindsdb/mindsdbsql/mindsdbsql_test.go +++ b/internal/tools/mindsdb/mindsdbsql/mindsdbsql_test.go @@ -17,7 +17,6 @@ package mindsdbsql_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,25 +37,25 @@ func TestParseFromYamlmindsdbsql(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: mindsdb-sql - source: my-mindsdbsql-instance - description: some description - statement: | - SELECT * FROM SQL_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 + name: example_tool + type: mindsdb-sql + source: my-mindsdbsql-instance + description: some description + statement: | + SELECT * FROM SQL_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": mindsdbsql.Config{ @@ -77,15 +76,12 @@ func TestParseFromYamlmindsdbsql(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) } }) @@ -105,36 +101,36 @@ func TestParseFromYamlWithTemplateParamsmindsdbsql(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: mindsdb-sql - source: my-mindsdbsql-instance - description: some description - statement: | - SELECT * FROM SQL_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: 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: mindsdb-sql + source: my-mindsdbsql-instance + description: some description + statement: | + SELECT * FROM SQL_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: 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": mindsdbsql.Config{ @@ -159,15 +155,12 @@ func TestParseFromYamlWithTemplateParamsmindsdbsql(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) } }) diff --git a/internal/tools/mongodb/mongodbaggregate/mongodbaggregate.go b/internal/tools/mongodb/mongodbaggregate/mongodbaggregate.go index 08346eeb11..4fe6ad9939 100644 --- a/internal/tools/mongodb/mongodbaggregate/mongodbaggregate.go +++ b/internal/tools/mongodb/mongodbaggregate/mongodbaggregate.go @@ -27,11 +27,11 @@ import ( "github.com/googleapis/genai-toolbox/internal/tools" ) -const kind string = "mongodb-aggregate" +const resourceType string = "mongodb-aggregate" 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"` AuthRequired []string `yaml:"authRequired" validate:"required"` Description string `yaml:"description" validate:"required"` @@ -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) { diff --git a/internal/tools/mongodb/mongodbaggregate/mongodbaggregate_test.go b/internal/tools/mongodb/mongodbaggregate/mongodbaggregate_test.go index 24a6a186f2..a9adf7f272 100644 --- a/internal/tools/mongodb/mongodbaggregate/mongodbaggregate_test.go +++ b/internal/tools/mongodb/mongodbaggregate/mongodbaggregate_test.go @@ -21,7 +21,6 @@ import ( "github.com/googleapis/genai-toolbox/internal/tools/mongodb/mongodbaggregate" "github.com/googleapis/genai-toolbox/internal/util/parameters" - 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" @@ -40,20 +39,20 @@ func TestParseFromYamlMongoQuery(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: mongodb-aggregate - source: my-instance - description: some description - database: test_db - collection: test_coll - readOnly: true - pipelinePayload: | - [{ $match: { name: {{json .name}} }}] - pipelineParams: - - name: name - type: string - description: small description + kind: tools + name: example_tool + type: mongodb-aggregate + source: my-instance + description: some description + database: test_db + collection: test_coll + readOnly: true + pipelinePayload: | + [{ $match: { name: {{json .name}} }}] + pipelineParams: + - name: name + type: string + description: small description `, want: server.ToolConfigs{ "example_tool": mongodbaggregate.Config{ @@ -81,15 +80,12 @@ func TestParseFromYamlMongoQuery(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) } }) @@ -110,25 +106,21 @@ func TestFailParseFromYamlMongoQuery(t *testing.T) { { desc: "Invalid method", in: ` - tools: - example_tool: - kind: mongodb-aggregate - source: my-instance - description: some description - collection: test_coll - pipelinePayload: | - [{ $match: { name : {{json .name}} }}] + kind: tools + name: example_tool + type: mongodb-aggregate + source: my-instance + description: some description + collection: test_coll + pipelinePayload: | + [{ $match: { name : {{json .name}} }}] `, - err: `unable to parse tool "example_tool" as kind "mongodb-aggregate"`, + err: `unable to parse tool "example_tool" as type "mongodb-aggregate"`, }, } 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") } diff --git a/internal/tools/mongodb/mongodbdeletemany/mongodbdeletemany.go b/internal/tools/mongodb/mongodbdeletemany/mongodbdeletemany.go index cb1fc27eb9..b1ec64c4af 100644 --- a/internal/tools/mongodb/mongodbdeletemany/mongodbdeletemany.go +++ b/internal/tools/mongodb/mongodbdeletemany/mongodbdeletemany.go @@ -27,11 +27,11 @@ import ( "github.com/googleapis/genai-toolbox/internal/tools" ) -const kind string = "mongodb-delete-many" +const resourceType string = "mongodb-delete-many" 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"` AuthRequired []string `yaml:"authRequired" validate:"required"` Description string `yaml:"description" validate:"required"` @@ -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) { diff --git a/internal/tools/mongodb/mongodbdeletemany/mongodbdeletemany_test.go b/internal/tools/mongodb/mongodbdeletemany/mongodbdeletemany_test.go index ea8e9bfd3b..af9ee4933e 100644 --- a/internal/tools/mongodb/mongodbdeletemany/mongodbdeletemany_test.go +++ b/internal/tools/mongodb/mongodbdeletemany/mongodbdeletemany_test.go @@ -21,7 +21,6 @@ import ( "github.com/googleapis/genai-toolbox/internal/tools/mongodb/mongodbdeletemany" "github.com/googleapis/genai-toolbox/internal/util/parameters" - 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" @@ -40,19 +39,19 @@ func TestParseFromYamlMongoQuery(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: mongodb-delete-many - source: my-instance - description: some description - database: test_db - collection: test_coll - filterPayload: | - { name: {{json .name}} } - filterParams: - - name: name - type: string - description: small description + kind: tools + name: example_tool + type: mongodb-delete-many + source: my-instance + description: some description + database: test_db + collection: test_coll + filterPayload: | + { name: {{json .name}} } + filterParams: + - name: name + type: string + description: small description `, want: server.ToolConfigs{ "example_tool": mongodbdeletemany.Config{ @@ -79,15 +78,11 @@ func TestParseFromYamlMongoQuery(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) } }) @@ -108,25 +103,21 @@ func TestFailParseFromYamlMongoQuery(t *testing.T) { { desc: "Invalid method", in: ` - tools: - example_tool: - kind: mongodb-delete-many - source: my-instance - description: some description - collection: test_coll - filterPayload: | - { name : {{json .name}} } + kind: tools + name: example_tool + type: mongodb-delete-many + source: my-instance + description: some description + collection: test_coll + filterPayload: | + { name : {{json .name}} } `, - err: `unable to parse tool "example_tool" as kind "mongodb-delete-many"`, + err: `unable to parse tool "example_tool" as type "mongodb-delete-many"`, }, } 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") } diff --git a/internal/tools/mongodb/mongodbdeleteone/mongodbdeleteone.go b/internal/tools/mongodb/mongodbdeleteone/mongodbdeleteone.go index b56b12b694..4310d74be7 100644 --- a/internal/tools/mongodb/mongodbdeleteone/mongodbdeleteone.go +++ b/internal/tools/mongodb/mongodbdeleteone/mongodbdeleteone.go @@ -27,11 +27,11 @@ import ( "github.com/googleapis/genai-toolbox/internal/tools" ) -const kind string = "mongodb-delete-one" +const resourceType string = "mongodb-delete-one" 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"` AuthRequired []string `yaml:"authRequired" validate:"required"` Description string `yaml:"description" validate:"required"` @@ -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) { diff --git a/internal/tools/mongodb/mongodbdeleteone/mongodbdeleteone_test.go b/internal/tools/mongodb/mongodbdeleteone/mongodbdeleteone_test.go index 12119afd07..3f395c6315 100644 --- a/internal/tools/mongodb/mongodbdeleteone/mongodbdeleteone_test.go +++ b/internal/tools/mongodb/mongodbdeleteone/mongodbdeleteone_test.go @@ -21,7 +21,6 @@ import ( "github.com/googleapis/genai-toolbox/internal/tools/mongodb/mongodbdeleteone" "github.com/googleapis/genai-toolbox/internal/util/parameters" - 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" @@ -40,19 +39,19 @@ func TestParseFromYamlMongoQuery(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: mongodb-delete-one - source: my-instance - description: some description - database: test_db - collection: test_coll - filterPayload: | - { name: {{json .name}} } - filterParams: - - name: name - type: string - description: small description + kind: tools + name: example_tool + type: mongodb-delete-one + source: my-instance + description: some description + database: test_db + collection: test_coll + filterPayload: | + { name: {{json .name}} } + filterParams: + - name: name + type: string + description: small description `, want: server.ToolConfigs{ "example_tool": mongodbdeleteone.Config{ @@ -79,15 +78,11 @@ func TestParseFromYamlMongoQuery(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) } }) @@ -108,25 +103,21 @@ func TestFailParseFromYamlMongoQuery(t *testing.T) { { desc: "Invalid method", in: ` - tools: - example_tool: - kind: mongodb-delete-one - source: my-instance - description: some description - collection: test_coll - filterPayload: | - { name : {{json .name}} } + kind: tools + name: example_tool + type: mongodb-delete-one + source: my-instance + description: some description + collection: test_coll + filterPayload: | + { name : {{json .name}} } `, - err: `unable to parse tool "example_tool" as kind "mongodb-delete-one"`, + err: `unable to parse tool "example_tool" as type "mongodb-delete-one"`, }, } 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") } diff --git a/internal/tools/mongodb/mongodbfind/mongodbfind.go b/internal/tools/mongodb/mongodbfind/mongodbfind.go index ca5c820b14..3714b377e5 100644 --- a/internal/tools/mongodb/mongodbfind/mongodbfind.go +++ b/internal/tools/mongodb/mongodbfind/mongodbfind.go @@ -30,11 +30,11 @@ import ( "github.com/googleapis/genai-toolbox/internal/tools" ) -const kind string = "mongodb-find" +const resourceType string = "mongodb-find" 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)) } } @@ -53,7 +53,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"` AuthRequired []string `yaml:"authRequired" validate:"required"` Description string `yaml:"description" validate:"required"` @@ -72,7 +72,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) { diff --git a/internal/tools/mongodb/mongodbfind/mongodbfind_test.go b/internal/tools/mongodb/mongodbfind/mongodbfind_test.go index 3217421a2f..dcc2591414 100644 --- a/internal/tools/mongodb/mongodbfind/mongodbfind_test.go +++ b/internal/tools/mongodb/mongodbfind/mongodbfind_test.go @@ -21,7 +21,6 @@ import ( "github.com/googleapis/genai-toolbox/internal/tools/mongodb/mongodbfind" "github.com/googleapis/genai-toolbox/internal/util/parameters" - 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" @@ -40,25 +39,25 @@ func TestParseFromYamlMongoQuery(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: mongodb-find - source: my-instance - description: some description - database: test_db - collection: test_coll - filterPayload: | - { name: {{json .name}} } - filterParams: - - name: name - type: string - description: small description - projectPayload: | - { name: 1, age: 1 } - projectParams: [] - sortPayload: | - { timestamp: -1 } - sortParams: [] + kind: tools + name: example_tool + type: mongodb-find + source: my-instance + description: some description + database: test_db + collection: test_coll + filterPayload: | + { name: {{json .name}} } + filterParams: + - name: name + type: string + description: small description + projectPayload: | + { name: 1, age: 1 } + projectParams: [] + sortPayload: | + { timestamp: -1 } + sortParams: [] `, want: server.ToolConfigs{ "example_tool": mongodbfind.Config{ @@ -89,15 +88,11 @@ func TestParseFromYamlMongoQuery(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) } }) @@ -118,25 +113,21 @@ func TestFailParseFromYamlMongoQuery(t *testing.T) { { desc: "Invalid method", in: ` - tools: - example_tool: - kind: mongodb-find - source: my-instance - description: some description - collection: test_coll - filterPayload: | - { name : {{json .name}} } + kind: tools + name: example_tool + type: mongodb-find + source: my-instance + description: some description + collection: test_coll + filterPayload: | + { name : {{json .name}} } `, - err: `unable to parse tool "example_tool" as kind "mongodb-find"`, + err: `unable to parse tool "example_tool" as type "mongodb-find"`, }, } 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") } diff --git a/internal/tools/mongodb/mongodbfindone/mongodbfindone.go b/internal/tools/mongodb/mongodbfindone/mongodbfindone.go index 87131d9319..53daa9fcca 100644 --- a/internal/tools/mongodb/mongodbfindone/mongodbfindone.go +++ b/internal/tools/mongodb/mongodbfindone/mongodbfindone.go @@ -29,11 +29,11 @@ import ( "github.com/googleapis/genai-toolbox/internal/tools" ) -const kind string = "mongodb-find-one" +const resourceType string = "mongodb-find-one" 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 { 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"` AuthRequired []string `yaml:"authRequired" validate:"required"` Description string `yaml:"description" validate:"required"` @@ -68,7 +68,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) { diff --git a/internal/tools/mongodb/mongodbfindone/mongodbfindone_test.go b/internal/tools/mongodb/mongodbfindone/mongodbfindone_test.go index 4aa909d60f..ce23e01e11 100644 --- a/internal/tools/mongodb/mongodbfindone/mongodbfindone_test.go +++ b/internal/tools/mongodb/mongodbfindone/mongodbfindone_test.go @@ -21,7 +21,6 @@ import ( "github.com/googleapis/genai-toolbox/internal/tools/mongodb/mongodbfindone" "github.com/googleapis/genai-toolbox/internal/util/parameters" - 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" @@ -40,22 +39,22 @@ func TestParseFromYamlMongoQuery(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: mongodb-find-one - source: my-instance - description: some description - database: test_db - collection: test_coll - filterPayload: | - { name: {{json .name}} } - filterParams: - - name: name - type: string - description: small description - projectPayload: | - { name: 1, age: 1 } - projectParams: [] + kind: tools + name: example_tool + type: mongodb-find-one + source: my-instance + description: some description + database: test_db + collection: test_coll + filterPayload: | + { name: {{json .name}} } + filterParams: + - name: name + type: string + description: small description + projectPayload: | + { name: 1, age: 1 } + projectParams: [] `, want: server.ToolConfigs{ "example_tool": mongodbfindone.Config{ @@ -84,15 +83,11 @@ func TestParseFromYamlMongoQuery(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) } }) @@ -113,25 +108,21 @@ func TestFailParseFromYamlMongoQuery(t *testing.T) { { desc: "Invalid method", in: ` - tools: - example_tool: - kind: mongodb-find-one - source: my-instance - description: some description - collection: test_coll - filterPayload: | - { name : {{json .name}} } + kind: tools + name: example_tool + type: mongodb-find-one + source: my-instance + description: some description + collection: test_coll + filterPayload: | + { name : {{json .name}} } `, - err: `unable to parse tool "example_tool" as kind "mongodb-find-one"`, + err: `unable to parse tool "example_tool" as type "mongodb-find-one"`, }, } 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") } diff --git a/internal/tools/mongodb/mongodbinsertmany/mongodbinsertmany.go b/internal/tools/mongodb/mongodbinsertmany/mongodbinsertmany.go index 4c2f4fdfa9..21ab0f4bdb 100644 --- a/internal/tools/mongodb/mongodbinsertmany/mongodbinsertmany.go +++ b/internal/tools/mongodb/mongodbinsertmany/mongodbinsertmany.go @@ -26,13 +26,13 @@ import ( "go.mongodb.org/mongo-driver/mongo" ) -const kind string = "mongodb-insert-many" +const resourceType string = "mongodb-insert-many" const paramDataKey = "data" 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"` AuthRequired []string `yaml:"authRequired" validate:"required"` Description string `yaml:"description" validate:"required"` @@ -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) { diff --git a/internal/tools/mongodb/mongodbinsertmany/mongodbinsertmany_test.go b/internal/tools/mongodb/mongodbinsertmany/mongodbinsertmany_test.go index 895e5c62ce..e965e056d9 100644 --- a/internal/tools/mongodb/mongodbinsertmany/mongodbinsertmany_test.go +++ b/internal/tools/mongodb/mongodbinsertmany/mongodbinsertmany_test.go @@ -20,7 +20,6 @@ import ( "github.com/googleapis/genai-toolbox/internal/tools/mongodb/mongodbinsertmany" - 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" @@ -39,13 +38,13 @@ func TestParseFromYamlMongoQuery(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: mongodb-insert-many - source: my-instance - description: some description - database: test_db - collection: test_coll + kind: tools + name: example_tool + type: mongodb-insert-many + source: my-instance + description: some description + database: test_db + collection: test_coll `, want: server.ToolConfigs{ "example_tool": mongodbinsertmany.Config{ @@ -63,14 +62,14 @@ func TestParseFromYamlMongoQuery(t *testing.T) { { desc: "true canonical", in: ` - tools: - example_tool: - kind: mongodb-insert-many - source: my-instance - description: some description - database: test_db - collection: test_coll - canonical: true + kind: tools + name: example_tool + type: mongodb-insert-many + source: my-instance + description: some description + database: test_db + collection: test_coll + canonical: true `, want: server.ToolConfigs{ "example_tool": mongodbinsertmany.Config{ @@ -88,14 +87,14 @@ func TestParseFromYamlMongoQuery(t *testing.T) { { desc: "false canonical", in: ` - tools: - example_tool: - kind: mongodb-insert-many - source: my-instance - description: some description - database: test_db - collection: test_coll - canonical: false + kind: tools + name: example_tool + type: mongodb-insert-many + source: my-instance + description: some description + database: test_db + collection: test_coll + canonical: false `, want: server.ToolConfigs{ "example_tool": mongodbinsertmany.Config{ @@ -113,15 +112,11 @@ func TestParseFromYamlMongoQuery(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) } }) @@ -142,23 +137,19 @@ func TestFailParseFromYamlMongoQuery(t *testing.T) { { desc: "Invalid method", in: ` - tools: - example_tool: - kind: mongodb-insert-many - source: my-instance - description: some description - collection: test_coll + kind: tools + name: example_tool + type: mongodb-insert-many + source: my-instance + description: some description + collection: test_coll `, - err: `unable to parse tool "example_tool" as kind "mongodb-insert-many"`, + err: `unable to parse tool "example_tool" as type "mongodb-insert-many"`, }, } 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") } diff --git a/internal/tools/mongodb/mongodbinsertone/mongodbinsertone.go b/internal/tools/mongodb/mongodbinsertone/mongodbinsertone.go index b044de37e7..35eff4b52a 100644 --- a/internal/tools/mongodb/mongodbinsertone/mongodbinsertone.go +++ b/internal/tools/mongodb/mongodbinsertone/mongodbinsertone.go @@ -26,13 +26,13 @@ import ( "go.mongodb.org/mongo-driver/mongo" ) -const kind string = "mongodb-insert-one" +const resourceType string = "mongodb-insert-one" const dataParamsKey = "data" 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"` AuthRequired []string `yaml:"authRequired" validate:"required"` Description string `yaml:"description" validate:"required"` @@ -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) { diff --git a/internal/tools/mongodb/mongodbinsertone/mongodbinsertone_test.go b/internal/tools/mongodb/mongodbinsertone/mongodbinsertone_test.go index 32ee276ad9..ace38f2d78 100644 --- a/internal/tools/mongodb/mongodbinsertone/mongodbinsertone_test.go +++ b/internal/tools/mongodb/mongodbinsertone/mongodbinsertone_test.go @@ -20,7 +20,6 @@ import ( "github.com/googleapis/genai-toolbox/internal/tools/mongodb/mongodbinsertone" - 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" @@ -39,13 +38,13 @@ func TestParseFromYamlMongoQuery(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: mongodb-insert-one - source: my-instance - description: some description - database: test_db - collection: test_coll + kind: tools + name: example_tool + type: mongodb-insert-one + source: my-instance + description: some description + database: test_db + collection: test_coll `, want: server.ToolConfigs{ "example_tool": mongodbinsertone.Config{ @@ -63,14 +62,14 @@ func TestParseFromYamlMongoQuery(t *testing.T) { { desc: "true canonical", in: ` - tools: - example_tool: - kind: mongodb-insert-one - source: my-instance - description: some description - database: test_db - collection: test_coll - canonical: true + kind: tools + name: example_tool + type: mongodb-insert-one + source: my-instance + description: some description + database: test_db + collection: test_coll + canonical: true `, want: server.ToolConfigs{ "example_tool": mongodbinsertone.Config{ @@ -88,14 +87,14 @@ func TestParseFromYamlMongoQuery(t *testing.T) { { desc: "false canonical", in: ` - tools: - example_tool: - kind: mongodb-insert-one - source: my-instance - description: some description - database: test_db - collection: test_coll - canonical: false + kind: tools + name: example_tool + type: mongodb-insert-one + source: my-instance + description: some description + database: test_db + collection: test_coll + canonical: false `, want: server.ToolConfigs{ "example_tool": mongodbinsertone.Config{ @@ -113,15 +112,11 @@ func TestParseFromYamlMongoQuery(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) } }) @@ -142,24 +137,20 @@ func TestFailParseFromYamlMongoQuery(t *testing.T) { { desc: "Invalid method", in: ` - tools: - example_tool: - kind: mongodb-insert-one - source: my-instance - description: some description - collection: test_coll - canonical: true + kind: tools + name: example_tool + type: mongodb-insert-one + source: my-instance + description: some description + collection: test_coll + canonical: true `, - err: `unable to parse tool "example_tool" as kind "mongodb-insert-one"`, + err: `unable to parse tool "example_tool" as type "mongodb-insert-one"`, }, } 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") } diff --git a/internal/tools/mongodb/mongodbupdatemany/mongodbupdatemany.go b/internal/tools/mongodb/mongodbupdatemany/mongodbupdatemany.go index f4b94f4dc0..b71c1899c1 100644 --- a/internal/tools/mongodb/mongodbupdatemany/mongodbupdatemany.go +++ b/internal/tools/mongodb/mongodbupdatemany/mongodbupdatemany.go @@ -26,11 +26,11 @@ import ( "go.mongodb.org/mongo-driver/mongo" ) -const kind string = "mongodb-update-many" +const resourceType string = "mongodb-update-many" 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"` AuthRequired []string `yaml:"authRequired" validate:"required"` Description string `yaml:"description" validate:"required"` @@ -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) { diff --git a/internal/tools/mongodb/mongodbupdatemany/mongodbupdatemany_test.go b/internal/tools/mongodb/mongodbupdatemany/mongodbupdatemany_test.go index 690abb6e2d..f3fcf468d5 100644 --- a/internal/tools/mongodb/mongodbupdatemany/mongodbupdatemany_test.go +++ b/internal/tools/mongodb/mongodbupdatemany/mongodbupdatemany_test.go @@ -21,7 +21,6 @@ import ( "github.com/googleapis/genai-toolbox/internal/tools/mongodb/mongodbupdatemany" "github.com/googleapis/genai-toolbox/internal/util/parameters" - 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" @@ -40,25 +39,25 @@ func TestParseFromYamlMongoQuery(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: mongodb-update-many - source: my-instance - description: some description - database: test_db - collection: test_coll - filterPayload: | - { name: {{json .name}} } - filterParams: - - name: name - type: string - description: small description - updatePayload: | - { $set: { name: {{json .name}} } } - updateParams: - - name: name - type: string - description: small description + kind: tools + name: example_tool + type: mongodb-update-many + source: my-instance + description: some description + database: test_db + collection: test_coll + filterPayload: | + { name: {{json .name}} } + filterParams: + - name: name + type: string + description: small description + updatePayload: | + { $set: { name: {{json .name}} } } + updateParams: + - name: name + type: string + description: small description `, want: server.ToolConfigs{ "example_tool": mongodbupdatemany.Config{ @@ -96,26 +95,26 @@ func TestParseFromYamlMongoQuery(t *testing.T) { { desc: "true canonical", in: ` - tools: - example_tool: - kind: mongodb-update-many - source: my-instance - description: some description - database: test_db - collection: test_coll - filterPayload: | - { name: {{json .name}} } - filterParams: - - name: name - type: string - description: small description - canonical: true - updatePayload: | - { $set: { name: {{json .name}} } } - updateParams: - - name: name - type: string - description: small description + kind: tools + name: example_tool + type: mongodb-update-many + source: my-instance + description: some description + database: test_db + collection: test_coll + filterPayload: | + { name: {{json .name}} } + filterParams: + - name: name + type: string + description: small description + canonical: true + updatePayload: | + { $set: { name: {{json .name}} } } + updateParams: + - name: name + type: string + description: small description `, want: server.ToolConfigs{ "example_tool": mongodbupdatemany.Config{ @@ -153,26 +152,26 @@ func TestParseFromYamlMongoQuery(t *testing.T) { { desc: "false canonical", in: ` - tools: - example_tool: - kind: mongodb-update-many - source: my-instance - description: some description - database: test_db - collection: test_coll - filterPayload: | - { name: {{json .name}} } - filterParams: - - name: name - type: string - description: small description - canonical: false - updatePayload: | - { $set: { name: {{json .name}} } } - updateParams: - - name: name - type: string - description: small description + kind: tools + name: example_tool + type: mongodb-update-many + source: my-instance + description: some description + database: test_db + collection: test_coll + filterPayload: | + { name: {{json .name}} } + filterParams: + - name: name + type: string + description: small description + canonical: false + updatePayload: | + { $set: { name: {{json .name}} } } + updateParams: + - name: name + type: string + description: small description `, want: server.ToolConfigs{ "example_tool": mongodbupdatemany.Config{ @@ -210,15 +209,11 @@ func TestParseFromYamlMongoQuery(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) } }) @@ -239,36 +234,32 @@ func TestFailParseFromYamlMongoQuery(t *testing.T) { { desc: "Invalid method", in: ` - tools: - example_tool: - kind: mongodb-update-many - source: my-instance - description: some description - collection: test_coll - filterPayload: | - { name : {{json .name}} } - filterParams: - - name: name - type: string - description: small description - canonical: true - updatePayload: | - { $set: { name: {{json .name}} } } - updateParams: - - name: data - type: string - description: the content in json + kind: tools + name: example_tool + type: mongodb-update-many + source: my-instance + description: some description + collection: test_coll + filterPayload: | + { name : {{json .name}} } + filterParams: + - name: name + type: string + description: small description + canonical: true + updatePayload: | + { $set: { name: {{json .name}} } } + updateParams: + - name: data + type: string + description: the content in json `, - err: `unable to parse tool "example_tool" as kind "mongodb-update-many"`, + err: `unable to parse tool "example_tool" as type "mongodb-update-many"`, }, } 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") } diff --git a/internal/tools/mongodb/mongodbupdateone/mongodbupdateone.go b/internal/tools/mongodb/mongodbupdateone/mongodbupdateone.go index 5ff4d21aad..ca8fe06acb 100644 --- a/internal/tools/mongodb/mongodbupdateone/mongodbupdateone.go +++ b/internal/tools/mongodb/mongodbupdateone/mongodbupdateone.go @@ -26,11 +26,11 @@ import ( "go.mongodb.org/mongo-driver/mongo" ) -const kind string = "mongodb-update-one" +const resourceType string = "mongodb-update-one" 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"` AuthRequired []string `yaml:"authRequired" validate:"required"` Description string `yaml:"description" validate:"required"` @@ -68,7 +68,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) { diff --git a/internal/tools/mongodb/mongodbupdateone/mongodbupdateone_test.go b/internal/tools/mongodb/mongodbupdateone/mongodbupdateone_test.go index 6fd539f936..87202485f7 100644 --- a/internal/tools/mongodb/mongodbupdateone/mongodbupdateone_test.go +++ b/internal/tools/mongodb/mongodbupdateone/mongodbupdateone_test.go @@ -21,7 +21,6 @@ import ( "github.com/googleapis/genai-toolbox/internal/tools/mongodb/mongodbupdateone" "github.com/googleapis/genai-toolbox/internal/util/parameters" - 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" @@ -40,26 +39,26 @@ func TestParseFromYamlMongoQuery(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: mongodb-update-one - source: my-instance - description: some description - database: test_db - collection: test_coll - filterPayload: | - { name: {{json .name}} } - filterParams: - - name: name - type: string - description: small description - updatePayload: | - { $set : { item: {{json .item}} } } - updateParams: - - name: item - type: string - description: small description - upsert: true + kind: tools + name: example_tool + type: mongodb-update-one + source: my-instance + description: some description + database: test_db + collection: test_coll + filterPayload: | + { name: {{json .name}} } + filterParams: + - name: name + type: string + description: small description + updatePayload: | + { $set : { item: {{json .item}} } } + updateParams: + - name: item + type: string + description: small description + upsert: true `, want: server.ToolConfigs{ "example_tool": mongodbupdateone.Config{ @@ -98,27 +97,27 @@ func TestParseFromYamlMongoQuery(t *testing.T) { { desc: "false canonical", in: ` - tools: - example_tool: - kind: mongodb-update-one - source: my-instance - description: some description - database: test_db - collection: test_coll - filterPayload: | - { name: {{json .name}} } - filterParams: - - name: name - type: string - description: small description - updatePayload: | - { $set : { item: {{json .item}} } } - updateParams: - - name: item - type: string - description: small description - canonical: false - upsert: true + kind: tools + name: example_tool + type: mongodb-update-one + source: my-instance + description: some description + database: test_db + collection: test_coll + filterPayload: | + { name: {{json .name}} } + filterParams: + - name: name + type: string + description: small description + updatePayload: | + { $set : { item: {{json .item}} } } + updateParams: + - name: item + type: string + description: small description + canonical: false + upsert: true `, want: server.ToolConfigs{ "example_tool": mongodbupdateone.Config{ @@ -157,27 +156,27 @@ func TestParseFromYamlMongoQuery(t *testing.T) { { desc: "true canonical", in: ` - tools: - example_tool: - kind: mongodb-update-one - source: my-instance - description: some description - database: test_db - collection: test_coll - filterPayload: | - { name: {{json .name}} } - filterParams: - - name: name - type: string - description: small description - updatePayload: | - { $set : { item: {{json .item}} } } - updateParams: - - name: item - type: string - description: small description - canonical: true - upsert: true + kind: tools + name: example_tool + type: mongodb-update-one + source: my-instance + description: some description + database: test_db + collection: test_coll + filterPayload: | + { name: {{json .name}} } + filterParams: + - name: name + type: string + description: small description + updatePayload: | + { $set : { item: {{json .item}} } } + updateParams: + - name: item + type: string + description: small description + canonical: true + upsert: true `, want: server.ToolConfigs{ "example_tool": mongodbupdateone.Config{ @@ -216,15 +215,11 @@ func TestParseFromYamlMongoQuery(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) } }) @@ -245,24 +240,20 @@ func TestFailParseFromYamlMongoQuery(t *testing.T) { { desc: "Invalid method", in: ` - tools: - example_tool: - kind: mongodb-update-one - source: my-instance - description: some description - collection: test_coll - filterPayload: | - { name : {{json .name}} }`, - err: `unable to parse tool "example_tool" as kind "mongodb-update-one"`, + kind: tools + name: example_tool + type: mongodb-update-one + source: my-instance + description: some description + collection: test_coll + filterPayload: | + { name : {{json .name}} }`, + err: `unable to parse tool "example_tool" as type "mongodb-update-one"`, }, } 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") } diff --git a/internal/tools/mssql/mssqlexecutesql/mssqlexecutesql.go b/internal/tools/mssql/mssqlexecutesql/mssqlexecutesql.go index 78439878d8..1ec97970c1 100644 --- a/internal/tools/mssql/mssqlexecutesql/mssqlexecutesql.go +++ b/internal/tools/mssql/mssqlexecutesql/mssqlexecutesql.go @@ -27,11 +27,11 @@ import ( "github.com/googleapis/genai-toolbox/internal/util/parameters" ) -const kind string = "mssql-execute-sql" +const resourceType string = "mssql-execute-sql" func init() { - if !tools.Register(kind, newConfig) { - panic(fmt.Sprintf("tool type %q already registered", kind)) + if !tools.Register(resourceType, newConfig) { + panic(fmt.Sprintf("tool type %q already registered", resourceType)) } } @@ -50,7 +50,7 @@ type compatibleSource interface { type Config struct { Name string `yaml:"name" validate:"required"` - Type string `yaml:"kind" validate:"required"` + Type string `yaml:"type" validate:"required"` Source string `yaml:"source" validate:"required"` Description string `yaml:"description" validate:"required"` AuthRequired []string `yaml:"authRequired"` @@ -60,7 +60,7 @@ type Config struct { var _ tools.ToolConfig = Config{} func (cfg Config) ToolConfigType() string { - return kind + return resourceType } func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error) { @@ -106,7 +106,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para if err != nil { return nil, fmt.Errorf("error getting logger: %s", err) } - logger.DebugContext(ctx, fmt.Sprintf("executing `%s` tool query: %s", kind, sql)) + logger.DebugContext(ctx, fmt.Sprintf("executing `%s` tool query: %s", resourceType, sql)) return source.RunSQL(ctx, sql, nil) } diff --git a/internal/tools/mssql/mssqlexecutesql/mssqlexecutesql_test.go b/internal/tools/mssql/mssqlexecutesql/mssqlexecutesql_test.go index 57f9dfe70b..560be13cad 100644 --- a/internal/tools/mssql/mssqlexecutesql/mssqlexecutesql_test.go +++ b/internal/tools/mssql/mssqlexecutesql/mssqlexecutesql_test.go @@ -17,7 +17,6 @@ package mssqlexecutesql_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,14 +36,14 @@ func TestParseFromYamlExecuteSql(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: mssql-execute-sql - source: my-instance - description: some description - authRequired: - - my-google-auth-service - - other-auth-service + kind: tools + name: example_tool + type: mssql-execute-sql + source: my-instance + description: some description + authRequired: + - my-google-auth-service + - other-auth-service `, want: server.ToolConfigs{ "example_tool": mssqlexecutesql.Config{ @@ -59,15 +58,12 @@ func TestParseFromYamlExecuteSql(t *testing.T) { } for _, tc := range tcs { t.Run(tc.desc, func(t *testing.T) { - got := struct { - Tools server.ToolConfigs `yaml:"tools"` - }{} // Parse contents - err := yaml.UnmarshalContext(ctx, testutils.FormatYaml(tc.in), &got) + _, _, _, got, _, _, err := server.UnmarshalResourceConfig(ctx, testutils.FormatYaml(tc.in)) if err != nil { t.Fatalf("unable to unmarshal: %s", err) } - if diff := cmp.Diff(tc.want, got.Tools); diff != "" { + if diff := cmp.Diff(tc.want, got); diff != "" { t.Fatalf("incorrect parse: diff %v", diff) } }) diff --git a/internal/tools/mssql/mssqllisttables/mssqllisttables.go b/internal/tools/mssql/mssqllisttables/mssqllisttables.go index 23b38ad363..26d7d4e1a9 100644 --- a/internal/tools/mssql/mssqllisttables/mssqllisttables.go +++ b/internal/tools/mssql/mssqllisttables/mssqllisttables.go @@ -26,7 +26,7 @@ import ( "github.com/googleapis/genai-toolbox/internal/util/parameters" ) -const kind string = "mssql-list-tables" +const resourceType string = "mssql-list-tables" const listTablesStatement = ` WITH table_info AS ( @@ -278,8 +278,8 @@ const listTablesStatement = ` ` 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)) } } @@ -298,7 +298,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"` @@ -308,7 +308,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) { diff --git a/internal/tools/mssql/mssqllisttables/mssqllisttables_test.go b/internal/tools/mssql/mssqllisttables/mssqllisttables_test.go index adaff0aed4..1da6d18eae 100644 --- a/internal/tools/mssql/mssqllisttables/mssqllisttables_test.go +++ b/internal/tools/mssql/mssqllisttables/mssqllisttables_test.go @@ -17,7 +17,6 @@ package mssqllisttables_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,14 +36,14 @@ func TestParseFromYamlmssqlListTables(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: mssql-list-tables - source: my-mssql-instance - description: some description - authRequired: - - my-google-auth-service - - other-auth-service + kind: tools + name: example_tool + type: mssql-list-tables + source: my-mssql-instance + description: some description + authRequired: + - my-google-auth-service + - other-auth-service `, want: server.ToolConfigs{ "example_tool": mssqllisttables.Config{ @@ -59,15 +58,12 @@ func TestParseFromYamlmssqlListTables(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) } }) diff --git a/internal/tools/mssql/mssqlsql/mssqlsql.go b/internal/tools/mssql/mssqlsql/mssqlsql.go index e5ca143f83..b1d78324d3 100644 --- a/internal/tools/mssql/mssqlsql/mssqlsql.go +++ b/internal/tools/mssql/mssqlsql/mssqlsql.go @@ -27,11 +27,11 @@ import ( "github.com/googleapis/genai-toolbox/internal/util/parameters" ) -const kind string = "mssql-sql" +const resourceType string = "mssql-sql" func init() { - if !tools.Register(kind, newConfig) { - panic(fmt.Sprintf("tool type %q already registered", kind)) + if !tools.Register(resourceType, newConfig) { + panic(fmt.Sprintf("tool type %q already registered", resourceType)) } } @@ -50,7 +50,7 @@ type compatibleSource interface { type Config struct { Name string `yaml:"name" validate:"required"` - Type string `yaml:"kind" validate:"required"` + Type string `yaml:"type" validate:"required"` Source string `yaml:"source" validate:"required"` Description string `yaml:"description" validate:"required"` Statement string `yaml:"statement" 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) { diff --git a/internal/tools/mssql/mssqlsql/mssqlsql_test.go b/internal/tools/mssql/mssqlsql/mssqlsql_test.go index f08a6b8ade..043b97f0ce 100644 --- a/internal/tools/mssql/mssqlsql/mssqlsql_test.go +++ b/internal/tools/mssql/mssqlsql/mssqlsql_test.go @@ -17,7 +17,6 @@ package mssqlsql_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,25 +37,25 @@ func TestParseFromYamlMssql(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: mssql-sql - source: my-instance - description: some description - statement: | - SELECT * FROM SQL_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 + name: example_tool + type: mssql-sql + source: my-instance + description: some description + statement: | + SELECT * FROM SQL_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": mssqlsql.Config{ @@ -77,15 +76,12 @@ func TestParseFromYamlMssql(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) } }) @@ -105,36 +101,36 @@ func TestParseFromYamlWithTemplateMssql(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: mssql-sql - source: my-instance - description: some description - statement: | - SELECT * FROM SQL_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: 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: mssql-sql + source: my-instance + description: some description + statement: | + SELECT * FROM SQL_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: 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": mssqlsql.Config{ @@ -159,15 +155,12 @@ func TestParseFromYamlWithTemplateMssql(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) } }) diff --git a/internal/tools/mysql/mysqlexecutesql/mysqlexecutesql.go b/internal/tools/mysql/mysqlexecutesql/mysqlexecutesql.go index 6c1a143250..4583959131 100644 --- a/internal/tools/mysql/mysqlexecutesql/mysqlexecutesql.go +++ b/internal/tools/mysql/mysqlexecutesql/mysqlexecutesql.go @@ -27,11 +27,11 @@ import ( "github.com/googleapis/genai-toolbox/internal/util/parameters" ) -const kind string = "mysql-execute-sql" +const resourceType string = "mysql-execute-sql" func init() { - if !tools.Register(kind, newConfig) { - panic(fmt.Sprintf("tool type %q already registered", kind)) + if !tools.Register(resourceType, newConfig) { + panic(fmt.Sprintf("tool type %q already registered", resourceType)) } } @@ -50,7 +50,7 @@ type compatibleSource interface { type Config struct { Name string `yaml:"name" validate:"required"` - Type string `yaml:"kind" validate:"required"` + Type string `yaml:"type" validate:"required"` Source string `yaml:"source" validate:"required"` Description string `yaml:"description" validate:"required"` AuthRequired []string `yaml:"authRequired"` @@ -60,7 +60,7 @@ type Config struct { var _ tools.ToolConfig = Config{} func (cfg Config) ToolConfigType() string { - return kind + return resourceType } func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error) { @@ -106,7 +106,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para if err != nil { return nil, fmt.Errorf("error getting logger: %s", err) } - logger.DebugContext(ctx, fmt.Sprintf("executing `%s` tool query: %s", kind, sql)) + logger.DebugContext(ctx, fmt.Sprintf("executing `%s` tool query: %s", resourceType, sql)) return source.RunSQL(ctx, sql, nil) } diff --git a/internal/tools/mysql/mysqlexecutesql/mysqlexecutesql_test.go b/internal/tools/mysql/mysqlexecutesql/mysqlexecutesql_test.go index 08cbbc84f1..43b4324728 100644 --- a/internal/tools/mysql/mysqlexecutesql/mysqlexecutesql_test.go +++ b/internal/tools/mysql/mysqlexecutesql/mysqlexecutesql_test.go @@ -17,7 +17,6 @@ package mysqlexecutesql_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,14 +36,14 @@ func TestParseFromYamlExecuteSql(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: mysql-execute-sql - source: my-instance - description: some description - authRequired: - - my-google-auth-service - - other-auth-service + kind: tools + name: example_tool + type: mysql-execute-sql + source: my-instance + description: some description + authRequired: + - my-google-auth-service + - other-auth-service `, want: server.ToolConfigs{ "example_tool": mysqlexecutesql.Config{ @@ -59,15 +58,12 @@ func TestParseFromYamlExecuteSql(t *testing.T) { } for _, tc := range tcs { t.Run(tc.desc, func(t *testing.T) { - got := struct { - Tools server.ToolConfigs `yaml:"tools"` - }{} // Parse contents - err := yaml.UnmarshalContext(ctx, testutils.FormatYaml(tc.in), &got) + _, _, _, got, _, _, err := server.UnmarshalResourceConfig(ctx, testutils.FormatYaml(tc.in)) if err != nil { t.Fatalf("unable to unmarshal: %s", err) } - if diff := cmp.Diff(tc.want, got.Tools); diff != "" { + if diff := cmp.Diff(tc.want, got); diff != "" { t.Fatalf("incorrect parse: diff %v", diff) } }) diff --git a/internal/tools/mysql/mysqlgetqueryplan/mysqlgetqueryplan.go b/internal/tools/mysql/mysqlgetqueryplan/mysqlgetqueryplan.go index 0970ff3f49..64750efc3c 100644 --- a/internal/tools/mysql/mysqlgetqueryplan/mysqlgetqueryplan.go +++ b/internal/tools/mysql/mysqlgetqueryplan/mysqlgetqueryplan.go @@ -29,11 +29,11 @@ import ( "github.com/googleapis/genai-toolbox/internal/util/parameters" ) -const kind string = "mysql-get-query-plan" +const resourceType string = "mysql-get-query-plan" 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 { 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"` @@ -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) { @@ -108,7 +108,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)) query := fmt.Sprintf("EXPLAIN FORMAT=JSON %s", sql) result, err := source.RunSQL(ctx, query, nil) diff --git a/internal/tools/mysql/mysqlgetqueryplan/mysqlgetqueryplan_test.go b/internal/tools/mysql/mysqlgetqueryplan/mysqlgetqueryplan_test.go index b26adb41ca..43ed82aa35 100644 --- a/internal/tools/mysql/mysqlgetqueryplan/mysqlgetqueryplan_test.go +++ b/internal/tools/mysql/mysqlgetqueryplan/mysqlgetqueryplan_test.go @@ -17,7 +17,6 @@ package mysqlgetqueryplan_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,14 +36,14 @@ func TestParseFromYamlGetQueryPlan(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: mysql-get-query-plan - source: my-instance - description: some description - authRequired: - - my-google-auth-service - - other-auth-service + kind: tools + name: example_tool + type: mysql-get-query-plan + source: my-instance + description: some description + authRequired: + - my-google-auth-service + - other-auth-service `, want: server.ToolConfigs{ "example_tool": mysqlgetqueryplan.Config{ @@ -59,15 +58,12 @@ func TestParseFromYamlGetQueryPlan(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) } }) diff --git a/internal/tools/mysql/mysqllistactivequeries/mysqllistactivequeries.go b/internal/tools/mysql/mysqllistactivequeries/mysqllistactivequeries.go index 0ff1731745..6b78fb9dcd 100644 --- a/internal/tools/mysql/mysqllistactivequeries/mysqllistactivequeries.go +++ b/internal/tools/mysql/mysqllistactivequeries/mysqllistactivequeries.go @@ -29,7 +29,7 @@ import ( "github.com/googleapis/genai-toolbox/internal/util/parameters" ) -const kind string = "mysql-list-active-queries" +const resourceType string = "mysql-list-active-queries" const listActiveQueriesStatementMySQL = ` SELECT @@ -94,8 +94,8 @@ const listActiveQueriesStatementCloudSQLMySQL = ` ` 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)) } } @@ -114,7 +114,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"` @@ -124,7 +124,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) { @@ -136,7 +136,7 @@ func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error) // verify the source is compatible _, 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) } allParameters := parameters.Parameters{ @@ -153,7 +153,7 @@ func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error) case cloudsqlmysql.SourceType: statement = listActiveQueriesStatementCloudSQLMySQL default: - return nil, fmt.Errorf("unsupported source kind: %s", cfg.Source) + return nil, fmt.Errorf("unsupported source type: %s", cfg.Source) } // finish tool setup t := Tool{ @@ -199,7 +199,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, t.statement)) + logger.DebugContext(ctx, fmt.Sprintf("executing `%s` tool query: %s", resourceType, t.statement)) return source.RunSQL(ctx, t.statement, []any{duration, duration, limit}) } diff --git a/internal/tools/mysql/mysqllistactivequeries/mysqllistactivequeries_test.go b/internal/tools/mysql/mysqllistactivequeries/mysqllistactivequeries_test.go index fcde501e31..5351981f38 100644 --- a/internal/tools/mysql/mysqllistactivequeries/mysqllistactivequeries_test.go +++ b/internal/tools/mysql/mysqllistactivequeries/mysqllistactivequeries_test.go @@ -17,7 +17,6 @@ package mysqllistactivequeries_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,14 +36,14 @@ func TestParseFromYamlExecuteSql(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: mysql-list-active-queries - source: my-instance - description: some description - authRequired: - - my-google-auth-service - - other-auth-service + kind: tools + name: example_tool + type: mysql-list-active-queries + source: my-instance + description: some description + authRequired: + - my-google-auth-service + - other-auth-service `, want: server.ToolConfigs{ "example_tool": mysqllistactivequeries.Config{ @@ -59,15 +58,12 @@ func TestParseFromYamlExecuteSql(t *testing.T) { } for _, tc := range tcs { t.Run(tc.desc, func(t *testing.T) { - got := struct { - Tools server.ToolConfigs `yaml:"tools"` - }{} // Parse contents - err := yaml.UnmarshalContext(ctx, testutils.FormatYaml(tc.in), &got) + _, _, _, got, _, _, err := server.UnmarshalResourceConfig(ctx, testutils.FormatYaml(tc.in)) if err != nil { t.Fatalf("unable to unmarshal: %s", err) } - if diff := cmp.Diff(tc.want, got.Tools); diff != "" { + if diff := cmp.Diff(tc.want, got); diff != "" { t.Fatalf("incorrect parse: diff %v", diff) } }) diff --git a/internal/tools/mysql/mysqllisttablefragmentation/mysqllisttablefragmentation.go b/internal/tools/mysql/mysqllisttablefragmentation/mysqllisttablefragmentation.go index 1f6a46c6ee..56be84e867 100644 --- a/internal/tools/mysql/mysqllisttablefragmentation/mysqllisttablefragmentation.go +++ b/internal/tools/mysql/mysqllisttablefragmentation/mysqllisttablefragmentation.go @@ -27,7 +27,7 @@ import ( "github.com/googleapis/genai-toolbox/internal/util/parameters" ) -const kind string = "mysql-list-table-fragmentation" +const resourceType string = "mysql-list-table-fragmentation" const listTableFragmentationStatement = ` SELECT @@ -52,8 +52,8 @@ const listTableFragmentationStatement = ` ` 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)) } } @@ -72,7 +72,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"` @@ -82,7 +82,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) { @@ -144,7 +144,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, listTableFragmentationStatement)) + logger.DebugContext(ctx, fmt.Sprintf("executing `%s` tool query: %s", resourceType, listTableFragmentationStatement)) sliceParams := []any{table_schema, table_schema, table_name, table_name, data_free_threshold_bytes, limit} return source.RunSQL(ctx, listTableFragmentationStatement, sliceParams) } diff --git a/internal/tools/mysql/mysqllisttablefragmentation/mysqllisttablefragmentation_test.go b/internal/tools/mysql/mysqllisttablefragmentation/mysqllisttablefragmentation_test.go index 1a23f34f77..07867ae8b1 100644 --- a/internal/tools/mysql/mysqllisttablefragmentation/mysqllisttablefragmentation_test.go +++ b/internal/tools/mysql/mysqllisttablefragmentation/mysqllisttablefragmentation_test.go @@ -17,7 +17,6 @@ package mysqllisttablefragmentation_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,14 +36,14 @@ func TestParseFromYamlExecuteSql(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: mysql-list-table-fragmentation - source: my-instance - description: some description - authRequired: - - my-google-auth-service - - other-auth-service + kind: tools + name: example_tool + type: mysql-list-table-fragmentation + source: my-instance + description: some description + authRequired: + - my-google-auth-service + - other-auth-service `, want: server.ToolConfigs{ "example_tool": mysqllisttablefragmentation.Config{ @@ -59,15 +58,12 @@ func TestParseFromYamlExecuteSql(t *testing.T) { } for _, tc := range tcs { t.Run(tc.desc, func(t *testing.T) { - got := struct { - Tools server.ToolConfigs `yaml:"tools"` - }{} // Parse contents - err := yaml.UnmarshalContext(ctx, testutils.FormatYaml(tc.in), &got) + _, _, _, got, _, _, err := server.UnmarshalResourceConfig(ctx, testutils.FormatYaml(tc.in)) if err != nil { t.Fatalf("unable to unmarshal: %s", err) } - if diff := cmp.Diff(tc.want, got.Tools); diff != "" { + if diff := cmp.Diff(tc.want, got); diff != "" { t.Fatalf("incorrect parse: diff %v", diff) } }) diff --git a/internal/tools/mysql/mysqllisttables/mysqllisttables.go b/internal/tools/mysql/mysqllisttables/mysqllisttables.go index fb5592e496..84e22fd19a 100644 --- a/internal/tools/mysql/mysqllisttables/mysqllisttables.go +++ b/internal/tools/mysql/mysqllisttables/mysqllisttables.go @@ -26,7 +26,7 @@ import ( "github.com/googleapis/genai-toolbox/internal/util/parameters" ) -const kind string = "mysql-list-tables" +const resourceType string = "mysql-list-tables" const listTablesStatement = ` SELECT @@ -182,8 +182,8 @@ const listTablesStatement = ` ` 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)) } } @@ -202,7 +202,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"` @@ -212,7 +212,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) { diff --git a/internal/tools/mysql/mysqllisttables/mysqllisttables_test.go b/internal/tools/mysql/mysqllisttables/mysqllisttables_test.go index 643c914fda..5112d88ed9 100644 --- a/internal/tools/mysql/mysqllisttables/mysqllisttables_test.go +++ b/internal/tools/mysql/mysqllisttables/mysqllisttables_test.go @@ -17,7 +17,6 @@ package mysqllisttables_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,14 +36,14 @@ func TestParseFromYamlMySQLListTables(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: mysql-list-tables - source: my-mysql-instance - description: some description - authRequired: - - my-google-auth-service - - other-auth-service + kind: tools + name: example_tool + type: mysql-list-tables + source: my-mysql-instance + description: some description + authRequired: + - my-google-auth-service + - other-auth-service `, want: server.ToolConfigs{ "example_tool": mysqllisttables.Config{ @@ -59,15 +58,12 @@ func TestParseFromYamlMySQLListTables(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) } }) diff --git a/internal/tools/mysql/mysqllisttablesmissinguniqueindexes/mysqllisttablesmissinguniqueindexes.go b/internal/tools/mysql/mysqllisttablesmissinguniqueindexes/mysqllisttablesmissinguniqueindexes.go index eb1fb4522a..4c6210163f 100644 --- a/internal/tools/mysql/mysqllisttablesmissinguniqueindexes/mysqllisttablesmissinguniqueindexes.go +++ b/internal/tools/mysql/mysqllisttablesmissinguniqueindexes/mysqllisttablesmissinguniqueindexes.go @@ -27,7 +27,7 @@ import ( "github.com/googleapis/genai-toolbox/internal/util/parameters" ) -const kind string = "mysql-list-tables-missing-unique-indexes" +const resourceType string = "mysql-list-tables-missing-unique-indexes" const listTablesMissingUniqueIndexesStatement = ` SELECT @@ -53,8 +53,8 @@ const listTablesMissingUniqueIndexesStatement = ` ` 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) { @@ -135,7 +135,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, listTablesMissingUniqueIndexesStatement)) + logger.DebugContext(ctx, fmt.Sprintf("executing `%s` tool query: %s", resourceType, listTablesMissingUniqueIndexesStatement)) return source.RunSQL(ctx, listTablesMissingUniqueIndexesStatement, []any{table_schema, table_schema, limit}) } diff --git a/internal/tools/mysql/mysqllisttablesmissinguniqueindexes/mysqllisttablesmissinguniqueindexes_test.go b/internal/tools/mysql/mysqllisttablesmissinguniqueindexes/mysqllisttablesmissinguniqueindexes_test.go index 7a9c1e96ac..3c1f0715cb 100644 --- a/internal/tools/mysql/mysqllisttablesmissinguniqueindexes/mysqllisttablesmissinguniqueindexes_test.go +++ b/internal/tools/mysql/mysqllisttablesmissinguniqueindexes/mysqllisttablesmissinguniqueindexes_test.go @@ -17,7 +17,6 @@ package mysqllisttablesmissinguniqueindexes_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,14 +36,14 @@ func TestParseFromYamlExecuteSql(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: mysql-list-tables-missing-unique-indexes - source: my-instance - description: some description - authRequired: - - my-google-auth-service - - other-auth-service + kind: tools + name: example_tool + type: mysql-list-tables-missing-unique-indexes + source: my-instance + description: some description + authRequired: + - my-google-auth-service + - other-auth-service `, want: server.ToolConfigs{ "example_tool": mysqllisttablesmissinguniqueindexes.Config{ @@ -59,15 +58,12 @@ func TestParseFromYamlExecuteSql(t *testing.T) { } for _, tc := range tcs { t.Run(tc.desc, func(t *testing.T) { - got := struct { - Tools server.ToolConfigs `yaml:"tools"` - }{} // Parse contents - err := yaml.UnmarshalContext(ctx, testutils.FormatYaml(tc.in), &got) + _, _, _, got, _, _, err := server.UnmarshalResourceConfig(ctx, testutils.FormatYaml(tc.in)) if err != nil { t.Fatalf("unable to unmarshal: %s", err) } - if diff := cmp.Diff(tc.want, got.Tools); diff != "" { + if diff := cmp.Diff(tc.want, got); diff != "" { t.Fatalf("incorrect parse: diff %v", diff) } }) diff --git a/internal/tools/mysql/mysqlsql/mysqlsql.go b/internal/tools/mysql/mysqlsql/mysqlsql.go index a6c9965126..21d059699e 100644 --- a/internal/tools/mysql/mysqlsql/mysqlsql.go +++ b/internal/tools/mysql/mysqlsql/mysqlsql.go @@ -26,11 +26,11 @@ import ( "github.com/googleapis/genai-toolbox/internal/util/parameters" ) -const kind string = "mysql-sql" +const resourceType string = "mysql-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) { diff --git a/internal/tools/mysql/mysqlsql/mysqlsql_test.go b/internal/tools/mysql/mysqlsql/mysqlsql_test.go index 449fd7c269..d825720de0 100644 --- a/internal/tools/mysql/mysqlsql/mysqlsql_test.go +++ b/internal/tools/mysql/mysqlsql/mysqlsql_test.go @@ -17,7 +17,6 @@ package mysqlsql_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,25 +37,25 @@ func TestParseFromYamlMySQL(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: mysql-sql - source: my-mysql-instance - description: some description - statement: | - SELECT * FROM SQL_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 + name: example_tool + type: mysql-sql + source: my-mysql-instance + description: some description + statement: | + SELECT * FROM SQL_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": mysqlsql.Config{ @@ -77,15 +76,12 @@ func TestParseFromYamlMySQL(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) } }) @@ -105,36 +101,36 @@ func TestParseFromYamlWithTemplateParamsMySQL(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: mysql-sql - source: my-mysql-instance - description: some description - statement: | - SELECT * FROM SQL_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: 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: mysql-sql + source: my-mysql-instance + description: some description + statement: | + SELECT * FROM SQL_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: 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": mysqlsql.Config{ @@ -159,15 +155,12 @@ func TestParseFromYamlWithTemplateParamsMySQL(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) } }) diff --git a/internal/tools/neo4j/neo4jcypher/neo4jcypher.go b/internal/tools/neo4j/neo4jcypher/neo4jcypher.go index e72afebfab..0e1119bda3 100644 --- a/internal/tools/neo4j/neo4jcypher/neo4jcypher.go +++ b/internal/tools/neo4j/neo4jcypher/neo4jcypher.go @@ -26,11 +26,11 @@ import ( "github.com/googleapis/genai-toolbox/internal/util/parameters" ) -const kind string = "neo4j-cypher" +const resourceType string = "neo4j-cypher" 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"` @@ -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) { diff --git a/internal/tools/neo4j/neo4jcypher/neo4jcypher_test.go b/internal/tools/neo4j/neo4jcypher/neo4jcypher_test.go index 1f3e86d431..d20cb1822c 100644 --- a/internal/tools/neo4j/neo4jcypher/neo4jcypher_test.go +++ b/internal/tools/neo4j/neo4jcypher/neo4jcypher_test.go @@ -17,7 +17,6 @@ package neo4jcypher 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,20 +36,20 @@ func TestParseFromYamlNeo4j(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: neo4j-cypher - source: my-neo4j-instance - description: some tool description - authRequired: - - my-google-auth-service - - other-auth-service - statement: | - MATCH (c:Country) WHERE c.name = $country RETURN c.id as id; - parameters: - - name: country - type: string - description: country parameter description + kind: tools + name: example_tool + type: neo4j-cypher + source: my-neo4j-instance + description: some tool description + authRequired: + - my-google-auth-service + - other-auth-service + statement: | + MATCH (c:Country) WHERE c.name = $country RETURN c.id as id; + parameters: + - name: country + type: string + description: country parameter description `, want: server.ToolConfigs{ "example_tool": Config{ @@ -69,15 +68,12 @@ func TestParseFromYamlNeo4j(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) } }) diff --git a/internal/tools/neo4j/neo4jexecutecypher/neo4jexecutecypher.go b/internal/tools/neo4j/neo4jexecutecypher/neo4jexecutecypher.go index 6a06aaf53d..0d78d224a4 100644 --- a/internal/tools/neo4j/neo4jexecutecypher/neo4jexecutecypher.go +++ b/internal/tools/neo4j/neo4jexecutecypher/neo4jexecutecypher.go @@ -25,11 +25,11 @@ import ( "github.com/googleapis/genai-toolbox/internal/util/parameters" ) -const kind string = "neo4j-execute-cypher" +const resourceType string = "neo4j-execute-cypher" 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)) } } @@ -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"` ReadOnly bool `yaml:"readOnly"` @@ -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) { diff --git a/internal/tools/neo4j/neo4jexecutecypher/neo4jexecutecypher_test.go b/internal/tools/neo4j/neo4jexecutecypher/neo4jexecutecypher_test.go index ae19ee6335..d45a7ba3d4 100644 --- a/internal/tools/neo4j/neo4jexecutecypher/neo4jexecutecypher_test.go +++ b/internal/tools/neo4j/neo4jexecutecypher/neo4jexecutecypher_test.go @@ -17,7 +17,6 @@ package neo4jexecutecypher 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" @@ -36,14 +35,14 @@ func TestParseFromYamlNeo4j(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: neo4j-execute-cypher - source: my-neo4j-instance - description: some tool description - authRequired: - - my-google-auth-service - - other-auth-service + kind: tools + name: example_tool + type: neo4j-execute-cypher + source: my-neo4j-instance + description: some tool description + authRequired: + - my-google-auth-service + - other-auth-service `, want: server.ToolConfigs{ "example_tool": Config{ @@ -58,15 +57,15 @@ func TestParseFromYamlNeo4j(t *testing.T) { { desc: "readonly example", in: ` - tools: - example_tool: - kind: neo4j-execute-cypher - source: my-neo4j-instance - description: some tool description - readOnly: true - authRequired: - - my-google-auth-service - - other-auth-service + kind: tools + name: example_tool + type: neo4j-execute-cypher + source: my-neo4j-instance + description: some tool description + readOnly: true + authRequired: + - my-google-auth-service + - other-auth-service `, want: server.ToolConfigs{ "example_tool": Config{ @@ -82,15 +81,12 @@ func TestParseFromYamlNeo4j(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) } }) diff --git a/internal/tools/neo4j/neo4jschema/neo4jschema.go b/internal/tools/neo4j/neo4jschema/neo4jschema.go index 0eab5a231b..ce56dce55c 100644 --- a/internal/tools/neo4j/neo4jschema/neo4jschema.go +++ b/internal/tools/neo4j/neo4jschema/neo4jschema.go @@ -31,13 +31,13 @@ import ( "github.com/neo4j/neo4j-go-driver/v5/neo4j" ) -// kind defines the unique identifier for this tool. -const kind string = "neo4j-schema" +// type defines the unique identifier for this tool. +const resourceType string = "neo4j-schema" // init registers the tool with the application's tool registry when the package is initialized. 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)) } } @@ -62,7 +62,7 @@ type compatibleSource interface { // These settings are typically read from a YAML file. 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"` @@ -72,9 +72,9 @@ type Config struct { // Statically verify that Config implements the tools.ToolConfig interface. var _ tools.ToolConfig = Config{} -// ToolConfigType returns the kind of this tool configuration. +// ToolConfigType returns the type of this tool configuration. func (cfg Config) ToolConfigType() string { - return kind + return resourceType } // Initialize sets up the tool with its dependencies and returns a ready-to-use Tool instance. diff --git a/internal/tools/neo4j/neo4jschema/neo4jschema_test.go b/internal/tools/neo4j/neo4jschema/neo4jschema_test.go index a93af1d765..850e237245 100644 --- a/internal/tools/neo4j/neo4jschema/neo4jschema_test.go +++ b/internal/tools/neo4j/neo4jschema/neo4jschema_test.go @@ -18,7 +18,6 @@ package neo4jschema 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" @@ -39,14 +38,14 @@ func TestParseFromYamlNeo4j(t *testing.T) { { desc: "basic example with default cache expiration", in: ` - tools: - example_tool: - kind: neo4j-schema - source: my-neo4j-instance - description: some tool description - authRequired: - - my-google-auth-service - - other-auth-service + kind: tools + name: example_tool + type: neo4j-schema + source: my-neo4j-instance + description: some tool description + authRequired: + - my-google-auth-service + - other-auth-service `, want: server.ToolConfigs{ "example_tool": Config{ @@ -62,12 +61,12 @@ func TestParseFromYamlNeo4j(t *testing.T) { { desc: "cache expire minutes set explicitly", in: ` - tools: - example_tool: - kind: neo4j-schema - source: my-neo4j-instance - description: some tool description - cacheExpireMinutes: 30 + kind: tools + name: example_tool + type: neo4j-schema + source: my-neo4j-instance + description: some tool description + cacheExpireMinutes: 30 `, want: server.ToolConfigs{ "example_tool": Config{ @@ -83,15 +82,12 @@ func TestParseFromYamlNeo4j(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) } }) diff --git a/internal/tools/oceanbase/oceanbaseexecutesql/oceanbaseexecutesql.go b/internal/tools/oceanbase/oceanbaseexecutesql/oceanbaseexecutesql.go index bfabfc4ece..411a6a81e7 100644 --- a/internal/tools/oceanbase/oceanbaseexecutesql/oceanbaseexecutesql.go +++ b/internal/tools/oceanbase/oceanbaseexecutesql/oceanbaseexecutesql.go @@ -26,11 +26,11 @@ import ( "github.com/googleapis/genai-toolbox/internal/util/parameters" ) -const kind string = "oceanbase-execute-sql" +const resourceType string = "oceanbase-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)) } } @@ -41,7 +41,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 @@ func newConfig(ctx context.Context, name string, decoder *yaml.Decoder) (tools.T } func (cfg Config) ToolConfigType() string { - return kind + return resourceType } func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error) { diff --git a/internal/tools/oceanbase/oceanbaseexecutesql/oceanbaseexecutesql_test.go b/internal/tools/oceanbase/oceanbaseexecutesql/oceanbaseexecutesql_test.go index a419b1f3cf..7b7f36e7a3 100644 --- a/internal/tools/oceanbase/oceanbaseexecutesql/oceanbaseexecutesql_test.go +++ b/internal/tools/oceanbase/oceanbaseexecutesql/oceanbaseexecutesql_test.go @@ -17,7 +17,6 @@ package oceanbaseexecutesql_test import ( "testing" - yaml "github.com/goccy/go-yaml" "github.com/google/go-cmp/cmp" "github.com/googleapis/genai-toolbox/internal/server" "github.com/googleapis/genai-toolbox/internal/testutils" @@ -38,14 +37,14 @@ func TestParseFromYamlExecuteSql(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: oceanbase-execute-sql - source: my-instance - description: some description - authRequired: - - my-google-auth-service - - other-auth-service + kind: tools + name: example_tool + type: oceanbase-execute-sql + source: my-instance + description: some description + authRequired: + - my-google-auth-service + - other-auth-service `, want: server.ToolConfigs{ "example_tool": oceanbaseexecutesql.Config{ @@ -60,15 +59,12 @@ func TestParseFromYamlExecuteSql(t *testing.T) { } for _, tc := range tcs { t.Run(tc.desc, func(t *testing.T) { - got := struct { - Tools server.ToolConfigs `yaml:"tools"` - }{} // Parse contents - err := yaml.UnmarshalContext(ctx, testutils.FormatYaml(tc.in), &got) + _, _, _, got, _, _, err := server.UnmarshalResourceConfig(ctx, testutils.FormatYaml(tc.in)) if err != nil { t.Fatalf("unable to unmarshal: %s", err) } - if diff := cmp.Diff(tc.want, got.Tools); diff != "" { + if diff := cmp.Diff(tc.want, got); diff != "" { t.Fatalf("incorrect parse: diff %v", diff) } }) diff --git a/internal/tools/oceanbase/oceanbasesql/oceanbasesql.go b/internal/tools/oceanbase/oceanbasesql/oceanbasesql.go index 290a36f76c..fe7ea42e1b 100644 --- a/internal/tools/oceanbase/oceanbasesql/oceanbasesql.go +++ b/internal/tools/oceanbase/oceanbasesql/oceanbasesql.go @@ -26,11 +26,11 @@ import ( "github.com/googleapis/genai-toolbox/internal/util/parameters" ) -const kind string = "oceanbase-sql" +const resourceType string = "oceanbase-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)) } } @@ -41,7 +41,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 @@ func newConfig(ctx context.Context, name string, decoder *yaml.Decoder) (tools.T } func (cfg Config) ToolConfigType() string { - return kind + return resourceType } func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error) { diff --git a/internal/tools/oceanbase/oceanbasesql/oceanbasesql_test.go b/internal/tools/oceanbase/oceanbasesql/oceanbasesql_test.go index c787687f3c..2df6c04ba1 100644 --- a/internal/tools/oceanbase/oceanbasesql/oceanbasesql_test.go +++ b/internal/tools/oceanbase/oceanbasesql/oceanbasesql_test.go @@ -17,7 +17,6 @@ package oceanbasesql_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" @@ -39,16 +38,16 @@ func TestParseFromYamlOceanBaseSql(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: oceanbase-sql - source: my-instance - description: some description - statement: select * from t where id = ? - parameters: - - name: id - type: string - description: id param + kind: tools + name: example_tool + type: oceanbase-sql + source: my-instance + description: some description + statement: select * from t where id = ? + parameters: + - name: id + type: string + description: id param `, want: server.ToolConfigs{ "example_tool": oceanbasesql.Config{ @@ -67,15 +66,12 @@ func TestParseFromYamlOceanBaseSql(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) } }) diff --git a/internal/tools/oracle/oracleexecutesql/oracleexecutesql.go b/internal/tools/oracle/oracleexecutesql/oracleexecutesql.go index cb0cc53683..224c6e9d90 100644 --- a/internal/tools/oracle/oracleexecutesql/oracleexecutesql.go +++ b/internal/tools/oracle/oracleexecutesql/oracleexecutesql.go @@ -15,11 +15,11 @@ import ( "github.com/googleapis/genai-toolbox/internal/util/parameters" ) -const kind string = "oracle-execute-sql" +const resourceType string = "oracle-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)) } } @@ -38,7 +38,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"` @@ -48,7 +48,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) { @@ -94,7 +94,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, "executing `%s` tool query: %s", kind, sqlParam) + logger.DebugContext(ctx, "executing `%s` tool query: %s", resourceType, sqlParam) return source.RunSQL(ctx, sqlParam, nil) } diff --git a/internal/tools/oracle/oracleexecutesql/oracleexecutesql_test.go b/internal/tools/oracle/oracleexecutesql/oracleexecutesql_test.go index 9c8db8e8fa..1d416ca087 100644 --- a/internal/tools/oracle/oracleexecutesql/oracleexecutesql_test.go +++ b/internal/tools/oracle/oracleexecutesql/oracleexecutesql_test.go @@ -5,7 +5,6 @@ package oracleexecutesql_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" @@ -25,13 +24,13 @@ func TestParseFromYamlOracleExecuteSql(t *testing.T) { { desc: "basic example with auth", in: ` - tools: - run_adhoc_query: - kind: oracle-execute-sql - source: my-oracle-instance - description: Executes arbitrary SQL statements like INSERT or UPDATE. - authRequired: - - my-google-auth-service + kind: tools + name: run_adhoc_query + type: oracle-execute-sql + source: my-oracle-instance + description: Executes arbitrary SQL statements like INSERT or UPDATE. + authRequired: + - my-google-auth-service `, want: server.ToolConfigs{ "run_adhoc_query": oracleexecutesql.Config{ @@ -46,11 +45,11 @@ func TestParseFromYamlOracleExecuteSql(t *testing.T) { { desc: "example without authRequired", in: ` - tools: - run_simple_update: - kind: oracle-execute-sql - source: db-dev - description: Runs a simple update operation. + kind: tools + name: run_simple_update + type: oracle-execute-sql + source: db-dev + description: Runs a simple update operation. `, want: server.ToolConfigs{ "run_simple_update": oracleexecutesql.Config{ @@ -65,15 +64,12 @@ func TestParseFromYamlOracleExecuteSql(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) } }) diff --git a/internal/tools/oracle/oraclesql/oraclesql.go b/internal/tools/oracle/oraclesql/oraclesql.go index 3180b4d61e..9696002297 100644 --- a/internal/tools/oracle/oraclesql/oraclesql.go +++ b/internal/tools/oracle/oraclesql/oraclesql.go @@ -14,11 +14,11 @@ import ( "github.com/googleapis/genai-toolbox/internal/util/parameters" ) -const kind string = "oracle-sql" +const resourceType string = "oracle-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)) } } @@ -37,7 +37,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"` @@ -50,7 +50,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) { diff --git a/internal/tools/oracle/oraclesql/oraclesql_test.go b/internal/tools/oracle/oraclesql/oraclesql_test.go index b6e8becf42..190afc2594 100644 --- a/internal/tools/oracle/oraclesql/oraclesql_test.go +++ b/internal/tools/oracle/oraclesql/oraclesql_test.go @@ -4,7 +4,6 @@ package oraclesql_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" @@ -24,14 +23,14 @@ func TestParseFromYamlOracleSql(t *testing.T) { { desc: "basic example with statement and auth", in: ` - tools: - get_user_by_id: - kind: oracle-sql - source: my-oracle-instance - description: Retrieves user details by ID. - statement: "SELECT id, name, email FROM users WHERE id = :1" - authRequired: - - my-google-auth-service + kind: tools + name: get_user_by_id + type: oracle-sql + source: my-oracle-instance + description: Retrieves user details by ID. + statement: "SELECT id, name, email FROM users WHERE id = :1" + authRequired: + - my-google-auth-service `, want: server.ToolConfigs{ "get_user_by_id": oraclesql.Config{ @@ -47,12 +46,12 @@ func TestParseFromYamlOracleSql(t *testing.T) { { desc: "example with parameters and template parameters", in: ` - tools: - get_orders: - kind: oracle-sql - source: db-prod - description: Gets orders for a customer with optional filtering. - statement: "SELECT * FROM ${SCHEMA}.ORDERS WHERE customer_id = :customer_id AND status = :status" + kind: tools + name: get_orders + type: oracle-sql + source: db-prod + description: Gets orders for a customer with optional filtering. + statement: "SELECT * FROM ${SCHEMA}.ORDERS WHERE customer_id = :customer_id AND status = :status" `, want: server.ToolConfigs{ "get_orders": oraclesql.Config{ @@ -68,15 +67,12 @@ func TestParseFromYamlOracleSql(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) } }) diff --git a/internal/tools/postgres/postgresdatabaseoverview/postgresdatabaseoverview.go b/internal/tools/postgres/postgresdatabaseoverview/postgresdatabaseoverview.go index 33e576b058..dd9da738bc 100644 --- a/internal/tools/postgres/postgresdatabaseoverview/postgresdatabaseoverview.go +++ b/internal/tools/postgres/postgresdatabaseoverview/postgresdatabaseoverview.go @@ -26,7 +26,7 @@ import ( "github.com/jackc/pgx/v5/pgxpool" ) -const kind string = "postgres-database-overview" +const resourceType string = "postgres-database-overview" const databaseOverviewStatement = ` SELECT @@ -43,8 +43,8 @@ const databaseOverviewStatement = ` ` 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"` 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) { diff --git a/internal/tools/postgres/postgresdatabaseoverview/postgresdatabaseoverview_test.go b/internal/tools/postgres/postgresdatabaseoverview/postgresdatabaseoverview_test.go index 360ff95058..77c455733a 100644 --- a/internal/tools/postgres/postgresdatabaseoverview/postgresdatabaseoverview_test.go +++ b/internal/tools/postgres/postgresdatabaseoverview/postgresdatabaseoverview_test.go @@ -17,7 +17,6 @@ package postgresdatabaseoverview_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,14 +36,14 @@ func TestParseFromYamlPostgresDatabaseOverview(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: postgres-database-overview - source: my-postgres-instance - description: some description - authRequired: - - my-google-auth-service - - other-auth-service + kind: tools + name: example_tool + type: postgres-database-overview + source: my-postgres-instance + description: some description + authRequired: + - my-google-auth-service + - other-auth-service `, want: server.ToolConfigs{ "example_tool": postgresdatabaseoverview.Config{ @@ -59,11 +58,11 @@ func TestParseFromYamlPostgresDatabaseOverview(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: postgres-database-overview - source: my-postgres-instance - description: some description + kind: tools + name: example_tool + type: postgres-database-overview + source: my-postgres-instance + description: some description `, want: server.ToolConfigs{ "example_tool": postgresdatabaseoverview.Config{ @@ -78,15 +77,12 @@ func TestParseFromYamlPostgresDatabaseOverview(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) } }) diff --git a/internal/tools/postgres/postgresexecutesql/postgresexecutesql.go b/internal/tools/postgres/postgresexecutesql/postgresexecutesql.go index 99054636f6..b30c08ac89 100644 --- a/internal/tools/postgres/postgresexecutesql/postgresexecutesql.go +++ b/internal/tools/postgres/postgresexecutesql/postgresexecutesql.go @@ -27,11 +27,11 @@ import ( "github.com/jackc/pgx/v5/pgxpool" ) -const kind string = "postgres-execute-sql" +const resourceType string = "postgres-execute-sql" func init() { - if !tools.Register(kind, newConfig) { - panic(fmt.Sprintf("tool type %q already registered", kind)) + if !tools.Register(resourceType, newConfig) { + panic(fmt.Sprintf("tool type %q already registered", resourceType)) } } @@ -50,7 +50,7 @@ type compatibleSource interface { type Config struct { Name string `yaml:"name" validate:"required"` - Type string `yaml:"kind" validate:"required"` + Type string `yaml:"type" validate:"required"` Source string `yaml:"source" validate:"required"` Description string `yaml:"description" validate:"required"` AuthRequired []string `yaml:"authRequired"` @@ -60,7 +60,7 @@ type Config struct { var _ tools.ToolConfig = Config{} func (cfg Config) ToolConfigType() string { - return kind + return resourceType } func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error) { @@ -105,7 +105,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para if err != nil { return nil, fmt.Errorf("error getting logger: %s", err) } - logger.DebugContext(ctx, fmt.Sprintf("executing `%s` tool query: %s", kind, sql)) + logger.DebugContext(ctx, fmt.Sprintf("executing `%s` tool query: %s", resourceType, sql)) return source.RunSQL(ctx, sql, nil) } diff --git a/internal/tools/postgres/postgresexecutesql/postgresexecutesql_test.go b/internal/tools/postgres/postgresexecutesql/postgresexecutesql_test.go index ff122d044c..9d4c61e929 100644 --- a/internal/tools/postgres/postgresexecutesql/postgresexecutesql_test.go +++ b/internal/tools/postgres/postgresexecutesql/postgresexecutesql_test.go @@ -17,7 +17,6 @@ package postgresexecutesql_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,14 +36,14 @@ func TestParseFromYamlExecuteSql(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: postgres-execute-sql - source: my-instance - description: some description - authRequired: - - my-google-auth-service - - other-auth-service + kind: tools + name: example_tool + type: postgres-execute-sql + source: my-instance + description: some description + authRequired: + - my-google-auth-service + - other-auth-service `, want: server.ToolConfigs{ "example_tool": postgresexecutesql.Config{ @@ -59,15 +58,12 @@ func TestParseFromYamlExecuteSql(t *testing.T) { } for _, tc := range tcs { t.Run(tc.desc, func(t *testing.T) { - got := struct { - Tools server.ToolConfigs `yaml:"tools"` - }{} // Parse contents - err := yaml.UnmarshalContext(ctx, testutils.FormatYaml(tc.in), &got) + _, _, _, got, _, _, err := server.UnmarshalResourceConfig(ctx, testutils.FormatYaml(tc.in)) if err != nil { t.Fatalf("unable to unmarshal: %s", err) } - if diff := cmp.Diff(tc.want, got.Tools); diff != "" { + if diff := cmp.Diff(tc.want, got); diff != "" { t.Fatalf("incorrect parse: diff %v", diff) } }) diff --git a/internal/tools/postgres/postgresgetcolumncardinality/postgresgetcolumncardinality.go b/internal/tools/postgres/postgresgetcolumncardinality/postgresgetcolumncardinality.go index 239124d1ac..97abbe5a6b 100644 --- a/internal/tools/postgres/postgresgetcolumncardinality/postgresgetcolumncardinality.go +++ b/internal/tools/postgres/postgresgetcolumncardinality/postgresgetcolumncardinality.go @@ -26,7 +26,7 @@ import ( "github.com/jackc/pgx/v5/pgxpool" ) -const kind string = "postgres-get-column-cardinality" +const resourceType string = "postgres-get-column-cardinality" const getColumnCardinality = ` SELECT @@ -48,8 +48,8 @@ const getColumnCardinality = ` ` 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)) } } @@ -68,7 +68,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"` @@ -78,7 +78,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) { diff --git a/internal/tools/postgres/postgresgetcolumncardinality/postgresgetcolumncardinality_test.go b/internal/tools/postgres/postgresgetcolumncardinality/postgresgetcolumncardinality_test.go index 0b23948710..c9eef23c26 100644 --- a/internal/tools/postgres/postgresgetcolumncardinality/postgresgetcolumncardinality_test.go +++ b/internal/tools/postgres/postgresgetcolumncardinality/postgresgetcolumncardinality_test.go @@ -17,7 +17,6 @@ package postgresgetcolumncardinality_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,14 +36,14 @@ func TestParseFromYamlPostgresGetColumnCardinality(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: postgres-get-column-cardinality - source: my-postgres-instance - description: some description - authRequired: - - my-google-auth-service - - other-auth-service + kind: tools + name: example_tool + type: postgres-get-column-cardinality + source: my-postgres-instance + description: some description + authRequired: + - my-google-auth-service + - other-auth-service `, want: server.ToolConfigs{ "example_tool": postgresgetcolumncardinality.Config{ @@ -59,11 +58,11 @@ func TestParseFromYamlPostgresGetColumnCardinality(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: postgres-get-column-cardinality - source: my-postgres-instance - description: some description + kind: tools + name: example_tool + type: postgres-get-column-cardinality + source: my-postgres-instance + description: some description `, want: server.ToolConfigs{ "example_tool": postgresgetcolumncardinality.Config{ @@ -78,15 +77,12 @@ func TestParseFromYamlPostgresGetColumnCardinality(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) } }) diff --git a/internal/tools/postgres/postgreslistactivequeries/postgreslistactivequeries.go b/internal/tools/postgres/postgreslistactivequeries/postgreslistactivequeries.go index 76fbd86ad1..3a07e08cc2 100644 --- a/internal/tools/postgres/postgreslistactivequeries/postgreslistactivequeries.go +++ b/internal/tools/postgres/postgreslistactivequeries/postgreslistactivequeries.go @@ -26,7 +26,7 @@ import ( "github.com/jackc/pgx/v5/pgxpool" ) -const kind string = "postgres-list-active-queries" +const resourceType string = "postgres-list-active-queries" const listActiveQueriesStatement = ` SELECT @@ -52,8 +52,8 @@ const listActiveQueriesStatement = ` ` 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)) } } @@ -72,7 +72,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"` @@ -82,7 +82,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) { diff --git a/internal/tools/postgres/postgreslistactivequeries/postgreslistactivequeries_test.go b/internal/tools/postgres/postgreslistactivequeries/postgreslistactivequeries_test.go index dadbda1c4b..1cf079d0d8 100644 --- a/internal/tools/postgres/postgreslistactivequeries/postgreslistactivequeries_test.go +++ b/internal/tools/postgres/postgreslistactivequeries/postgreslistactivequeries_test.go @@ -17,7 +17,6 @@ package postgreslistactivequeries_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,14 +36,14 @@ func TestParseFromYamlPostgresListTables(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: postgres-list-active-queries - source: my-postgres-instance - description: some description - authRequired: - - my-google-auth-service - - other-auth-service + kind: tools + name: example_tool + type: postgres-list-active-queries + source: my-postgres-instance + description: some description + authRequired: + - my-google-auth-service + - other-auth-service `, want: server.ToolConfigs{ "example_tool": postgreslistactivequeries.Config{ @@ -59,11 +58,11 @@ func TestParseFromYamlPostgresListTables(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: postgres-list-active-queries - source: my-postgres-instance - description: some description + kind: tools + name: example_tool + type: postgres-list-active-queries + source: my-postgres-instance + description: some description `, want: server.ToolConfigs{ "example_tool": postgreslistactivequeries.Config{ @@ -78,15 +77,11 @@ func TestParseFromYamlPostgresListTables(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) } }) diff --git a/internal/tools/postgres/postgreslistavailableextensions/postgreslistavailableextensions.go b/internal/tools/postgres/postgreslistavailableextensions/postgreslistavailableextensions.go index 66864c54c6..77d71bdb83 100644 --- a/internal/tools/postgres/postgreslistavailableextensions/postgreslistavailableextensions.go +++ b/internal/tools/postgres/postgreslistavailableextensions/postgreslistavailableextensions.go @@ -26,7 +26,7 @@ import ( "github.com/jackc/pgx/v5/pgxpool" ) -const kind string = "postgres-list-available-extensions" +const resourceType string = "postgres-list-available-extensions" const listAvailableExtensionsQuery = ` SELECT @@ -39,8 +39,8 @@ const listAvailableExtensionsQuery = ` ` 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) { diff --git a/internal/tools/postgres/postgreslistavailableextensions/postgreslistavailableextensions_test.go b/internal/tools/postgres/postgreslistavailableextensions/postgreslistavailableextensions_test.go index 51ecdebba0..2a45d2b502 100644 --- a/internal/tools/postgres/postgreslistavailableextensions/postgreslistavailableextensions_test.go +++ b/internal/tools/postgres/postgreslistavailableextensions/postgreslistavailableextensions_test.go @@ -17,7 +17,6 @@ package postgreslistavailableextensions_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,14 +36,14 @@ func TestParseFromYamlPostgres(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: postgres-list-available-extensions - source: my-pg-instance - description: "some description" - authRequired: - - my-google-auth-service - - other-auth-service + kind: tools + name: example_tool + type: postgres-list-available-extensions + source: my-pg-instance + description: "some description" + authRequired: + - my-google-auth-service + - other-auth-service `, want: server.ToolConfigs{ "example_tool": postgreslistavailableextensions.Config{ @@ -59,11 +58,11 @@ func TestParseFromYamlPostgres(t *testing.T) { { desc: "basic example without authRequired", in: ` - tools: - example_tool: - kind: postgres-list-available-extensions - source: my-pg-instance - description: "some description" + kind: tools + name: example_tool + type: postgres-list-available-extensions + source: my-pg-instance + description: "some description" `, want: server.ToolConfigs{ "example_tool": postgreslistavailableextensions.Config{ @@ -78,15 +77,11 @@ func TestParseFromYamlPostgres(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) } }) diff --git a/internal/tools/postgres/postgreslistdatabasestats/postgreslistdatabasestats.go b/internal/tools/postgres/postgreslistdatabasestats/postgreslistdatabasestats.go index e997b1c4dd..95c9f6c22c 100644 --- a/internal/tools/postgres/postgreslistdatabasestats/postgreslistdatabasestats.go +++ b/internal/tools/postgres/postgreslistdatabasestats/postgreslistdatabasestats.go @@ -26,7 +26,7 @@ import ( "github.com/jackc/pgx/v5/pgxpool" ) -const kind string = "postgres-list-database-stats" +const resourceType string = "postgres-list-database-stats" // SQL query to list database statistics const listDatabaseStats = ` @@ -96,8 +96,8 @@ const listDatabaseStats = ` ` 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)) } } @@ -116,7 +116,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"` @@ -126,7 +126,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) { diff --git a/internal/tools/postgres/postgreslistdatabasestats/postgreslistdatabasestats_test.go b/internal/tools/postgres/postgreslistdatabasestats/postgreslistdatabasestats_test.go index 1833dc13c0..d90211e9e4 100644 --- a/internal/tools/postgres/postgreslistdatabasestats/postgreslistdatabasestats_test.go +++ b/internal/tools/postgres/postgreslistdatabasestats/postgreslistdatabasestats_test.go @@ -17,7 +17,6 @@ package postgreslistdatabasestats_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,14 +36,14 @@ func TestParseFromYamlPostgresListDatabaseStats(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: postgres-list-database-stats - source: my-postgres-instance - description: some description - authRequired: - - my-google-auth-service - - other-auth-service + kind: tools + name: example_tool + type: postgres-list-database-stats + source: my-postgres-instance + description: some description + authRequired: + - my-google-auth-service + - other-auth-service `, want: server.ToolConfigs{ "example_tool": postgreslistdatabasestats.Config{ @@ -59,11 +58,11 @@ func TestParseFromYamlPostgresListDatabaseStats(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: postgres-list-database-stats - source: my-postgres-instance - description: some description + kind: tools + name: example_tool + type: postgres-list-database-stats + source: my-postgres-instance + description: some description `, want: server.ToolConfigs{ "example_tool": postgreslistdatabasestats.Config{ @@ -78,15 +77,11 @@ func TestParseFromYamlPostgresListDatabaseStats(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) } }) diff --git a/internal/tools/postgres/postgreslistindexes/postgreslistindexes.go b/internal/tools/postgres/postgreslistindexes/postgreslistindexes.go index 4ffaf6fa5c..d74d1bf0a5 100644 --- a/internal/tools/postgres/postgreslistindexes/postgreslistindexes.go +++ b/internal/tools/postgres/postgreslistindexes/postgreslistindexes.go @@ -26,7 +26,7 @@ import ( "github.com/jackc/pgx/v5/pgxpool" ) -const kind string = "postgres-list-indexes" +const resourceType string = "postgres-list-indexes" const listIndexesStatement = ` WITH IndexDetails AS ( @@ -75,8 +75,8 @@ const listIndexesStatement = ` ` 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 { 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"` @@ -105,7 +105,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) { diff --git a/internal/tools/postgres/postgreslistindexes/postgreslistindexes_test.go b/internal/tools/postgres/postgreslistindexes/postgreslistindexes_test.go index 72f69b3094..7c0da6e6a1 100644 --- a/internal/tools/postgres/postgreslistindexes/postgreslistindexes_test.go +++ b/internal/tools/postgres/postgreslistindexes/postgreslistindexes_test.go @@ -17,7 +17,6 @@ package postgreslistindexes_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,14 +36,14 @@ func TestParseFromYamlPostgresListIndexes(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: postgres-list-indexes - source: my-postgres-instance - description: some description - authRequired: - - my-google-auth-service - - other-auth-service + kind: tools + name: example_tool + type: postgres-list-indexes + source: my-postgres-instance + description: some description + authRequired: + - my-google-auth-service + - other-auth-service `, want: server.ToolConfigs{ "example_tool": postgreslistindexes.Config{ @@ -59,11 +58,11 @@ func TestParseFromYamlPostgresListIndexes(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: postgres-list-indexes - source: my-postgres-instance - description: some description + kind: tools + name: example_tool + type: postgres-list-indexes + source: my-postgres-instance + description: some description `, want: server.ToolConfigs{ "example_tool": postgreslistindexes.Config{ @@ -78,15 +77,12 @@ func TestParseFromYamlPostgresListIndexes(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) } }) diff --git a/internal/tools/postgres/postgreslistinstalledextensions/postgreslistinstalledextensions.go b/internal/tools/postgres/postgreslistinstalledextensions/postgreslistinstalledextensions.go index e110fb683b..7322b778ba 100644 --- a/internal/tools/postgres/postgreslistinstalledextensions/postgreslistinstalledextensions.go +++ b/internal/tools/postgres/postgreslistinstalledextensions/postgreslistinstalledextensions.go @@ -26,7 +26,7 @@ import ( "github.com/jackc/pgx/v5/pgxpool" ) -const kind string = "postgres-list-installed-extensions" +const resourceType string = "postgres-list-installed-extensions" const listAvailableExtensionsQuery = ` SELECT @@ -50,8 +50,8 @@ const listAvailableExtensionsQuery = ` ` 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)) } } @@ -70,7 +70,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"` @@ -80,7 +80,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) { diff --git a/internal/tools/postgres/postgreslistinstalledextensions/postgreslistinstalledextensions_test.go b/internal/tools/postgres/postgreslistinstalledextensions/postgreslistinstalledextensions_test.go index abb2baf5e6..5ca5dbe3c0 100644 --- a/internal/tools/postgres/postgreslistinstalledextensions/postgreslistinstalledextensions_test.go +++ b/internal/tools/postgres/postgreslistinstalledextensions/postgreslistinstalledextensions_test.go @@ -17,7 +17,6 @@ package postgreslistinstalledextensions_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,14 +36,14 @@ func TestParseFromYamlPostgres(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: postgres-list-installed-extensions - source: my-pg-instance - description: "some description" - authRequired: - - my-google-auth-service - - other-auth-service + kind: tools + name: example_tool + type: postgres-list-installed-extensions + source: my-pg-instance + description: "some description" + authRequired: + - my-google-auth-service + - other-auth-service `, want: server.ToolConfigs{ "example_tool": postgreslistinstalledextensions.Config{ @@ -59,11 +58,11 @@ func TestParseFromYamlPostgres(t *testing.T) { { desc: "basic example without authRequired", in: ` - tools: - example_tool: - kind: postgres-list-installed-extensions - source: my-pg-instance - description: "some description" + kind: tools + name: example_tool + type: postgres-list-installed-extensions + source: my-pg-instance + description: "some description" `, want: server.ToolConfigs{ "example_tool": postgreslistinstalledextensions.Config{ @@ -78,15 +77,12 @@ func TestParseFromYamlPostgres(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) } }) diff --git a/internal/tools/postgres/postgreslistlocks/postgreslistlocks.go b/internal/tools/postgres/postgreslistlocks/postgreslistlocks.go index c36b6d2119..ef6e269838 100644 --- a/internal/tools/postgres/postgreslistlocks/postgreslistlocks.go +++ b/internal/tools/postgres/postgreslistlocks/postgreslistlocks.go @@ -26,7 +26,7 @@ import ( "github.com/jackc/pgx/v5/pgxpool" ) -const kind string = "postgres-list-locks" +const resourceType string = "postgres-list-locks" const listLocks = ` SELECT @@ -50,8 +50,8 @@ const listLocks = ` ` 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)) } } @@ -70,7 +70,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"` @@ -80,7 +80,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) { diff --git a/internal/tools/postgres/postgreslistlocks/postgreslistlocks_test.go b/internal/tools/postgres/postgreslistlocks/postgreslistlocks_test.go index 324d63a859..d34352e484 100644 --- a/internal/tools/postgres/postgreslistlocks/postgreslistlocks_test.go +++ b/internal/tools/postgres/postgreslistlocks/postgreslistlocks_test.go @@ -17,7 +17,6 @@ package postgreslistlocks_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,14 +36,14 @@ func TestParseFromYamlPostgresListLocks(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: postgres-list-locks - source: my-postgres-instance - description: some description - authRequired: - - my-google-auth-service - - other-auth-service + kind: tools + name: example_tool + type: postgres-list-locks + source: my-postgres-instance + description: some description + authRequired: + - my-google-auth-service + - other-auth-service `, want: server.ToolConfigs{ "example_tool": postgreslistlocks.Config{ @@ -59,11 +58,11 @@ func TestParseFromYamlPostgresListLocks(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: postgres-list-locks - source: my-postgres-instance - description: some description + kind: tools + name: example_tool + type: postgres-list-locks + source: my-postgres-instance + description: some description `, want: server.ToolConfigs{ "example_tool": postgreslistlocks.Config{ @@ -78,15 +77,12 @@ func TestParseFromYamlPostgresListLocks(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) } }) diff --git a/internal/tools/postgres/postgreslistpgsettings/postgreslistpgsettings.go b/internal/tools/postgres/postgreslistpgsettings/postgreslistpgsettings.go index 1670fbc11e..76a5ab452e 100644 --- a/internal/tools/postgres/postgreslistpgsettings/postgreslistpgsettings.go +++ b/internal/tools/postgres/postgreslistpgsettings/postgreslistpgsettings.go @@ -26,7 +26,7 @@ import ( "github.com/jackc/pgx/v5/pgxpool" ) -const kind string = "postgres-list-pg-settings" +const resourceType string = "postgres-list-pg-settings" const listPgSettingsStatement = ` SELECT @@ -48,8 +48,8 @@ const listPgSettingsStatement = ` ` 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)) } } @@ -68,7 +68,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"` @@ -78,7 +78,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) { diff --git a/internal/tools/postgres/postgreslistpgsettings/postgreslistpgsettings_test.go b/internal/tools/postgres/postgreslistpgsettings/postgreslistpgsettings_test.go index b38ee67b96..eb98a8e370 100644 --- a/internal/tools/postgres/postgreslistpgsettings/postgreslistpgsettings_test.go +++ b/internal/tools/postgres/postgreslistpgsettings/postgreslistpgsettings_test.go @@ -17,7 +17,6 @@ package postgreslistpgsettings_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,14 +36,14 @@ func TestParseFromYamlPostgreslistPgSettings(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: postgres-list-pg-settings - source: my-postgres-instance - description: some description - authRequired: - - my-google-auth-service - - other-auth-service + kind: tools + name: example_tool + type: postgres-list-pg-settings + source: my-postgres-instance + description: some description + authRequired: + - my-google-auth-service + - other-auth-service `, want: server.ToolConfigs{ "example_tool": postgreslistpgsettings.Config{ @@ -59,11 +58,11 @@ func TestParseFromYamlPostgreslistPgSettings(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: postgres-list-pg-settings - source: my-postgres-instance - description: some description + kind: tools + name: example_tool + type: postgres-list-pg-settings + source: my-postgres-instance + description: some description `, want: server.ToolConfigs{ "example_tool": postgreslistpgsettings.Config{ @@ -78,15 +77,11 @@ func TestParseFromYamlPostgreslistPgSettings(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) } }) diff --git a/internal/tools/postgres/postgreslistpublicationtables/postgreslistpublicationtables.go b/internal/tools/postgres/postgreslistpublicationtables/postgreslistpublicationtables.go index 3b2f2cc1c4..2effbe51bc 100644 --- a/internal/tools/postgres/postgreslistpublicationtables/postgreslistpublicationtables.go +++ b/internal/tools/postgres/postgreslistpublicationtables/postgreslistpublicationtables.go @@ -26,7 +26,7 @@ import ( "github.com/jackc/pgx/v5/pgxpool" ) -const kind string = "postgres-list-publication-tables" +const resourceType string = "postgres-list-publication-tables" const listPublicationTablesStatement = ` WITH @@ -59,8 +59,8 @@ const listPublicationTablesStatement = ` ` 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)) } } @@ -79,7 +79,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"` @@ -89,7 +89,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) { diff --git a/internal/tools/postgres/postgreslistpublicationtables/postgreslistpublicationtables_test.go b/internal/tools/postgres/postgreslistpublicationtables/postgreslistpublicationtables_test.go index a2e8cfb03e..96e4db1b95 100644 --- a/internal/tools/postgres/postgreslistpublicationtables/postgreslistpublicationtables_test.go +++ b/internal/tools/postgres/postgreslistpublicationtables/postgreslistpublicationtables_test.go @@ -17,7 +17,6 @@ package postgreslistpublicationtables_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,14 +36,14 @@ func TestParseFromYamlPostgresListPublicationTables(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: postgres-list-publication-tables - source: my-postgres-instance - description: some description - authRequired: - - my-google-auth-service - - other-auth-service + kind: tools + name: example_tool + type: postgres-list-publication-tables + source: my-postgres-instance + description: some description + authRequired: + - my-google-auth-service + - other-auth-service `, want: server.ToolConfigs{ "example_tool": postgreslistpublicationtables.Config{ @@ -59,11 +58,11 @@ func TestParseFromYamlPostgresListPublicationTables(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: postgres-list-publication-tables - source: my-postgres-instance - description: some description + kind: tools + name: example_tool + type: postgres-list-publication-tables + source: my-postgres-instance + description: some description `, want: server.ToolConfigs{ "example_tool": postgreslistpublicationtables.Config{ @@ -78,15 +77,11 @@ func TestParseFromYamlPostgresListPublicationTables(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) } }) diff --git a/internal/tools/postgres/postgreslistquerystats/postgreslistquerystats.go b/internal/tools/postgres/postgreslistquerystats/postgreslistquerystats.go index 6b6d14c25e..a978b94e02 100644 --- a/internal/tools/postgres/postgreslistquerystats/postgreslistquerystats.go +++ b/internal/tools/postgres/postgreslistquerystats/postgreslistquerystats.go @@ -26,7 +26,7 @@ import ( "github.com/jackc/pgx/v5/pgxpool" ) -const kind string = "postgres-list-query-stats" +const resourceType string = "postgres-list-query-stats" const listQueryStats = ` SELECT @@ -49,8 +49,8 @@ const listQueryStats = ` ` 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)) } } @@ -69,7 +69,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"` @@ -79,7 +79,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) { diff --git a/internal/tools/postgres/postgreslistquerystats/postgreslistquerystats_test.go b/internal/tools/postgres/postgreslistquerystats/postgreslistquerystats_test.go index 528e6a6d2d..694a780d80 100644 --- a/internal/tools/postgres/postgreslistquerystats/postgreslistquerystats_test.go +++ b/internal/tools/postgres/postgreslistquerystats/postgreslistquerystats_test.go @@ -17,7 +17,6 @@ package postgreslistquerystats_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,14 +36,14 @@ func TestParseFromYamlPostgresListQueryStats(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: postgres-list-query-stats - source: my-postgres-instance - description: some description - authRequired: - - my-google-auth-service - - other-auth-service + kind: tools + name: example_tool + type: postgres-list-query-stats + source: my-postgres-instance + description: some description + authRequired: + - my-google-auth-service + - other-auth-service `, want: server.ToolConfigs{ "example_tool": postgreslistquerystats.Config{ @@ -59,11 +58,11 @@ func TestParseFromYamlPostgresListQueryStats(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: postgres-list-query-stats - source: my-postgres-instance - description: some description + kind: tools + name: example_tool + type: postgres-list-query-stats + source: my-postgres-instance + description: some description `, want: server.ToolConfigs{ "example_tool": postgreslistquerystats.Config{ @@ -78,15 +77,11 @@ func TestParseFromYamlPostgresListQueryStats(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) } }) diff --git a/internal/tools/postgres/postgreslistroles/postgreslistroles.go b/internal/tools/postgres/postgreslistroles/postgreslistroles.go index d4de0606d4..a4058047e2 100644 --- a/internal/tools/postgres/postgreslistroles/postgreslistroles.go +++ b/internal/tools/postgres/postgreslistroles/postgreslistroles.go @@ -26,7 +26,7 @@ import ( "github.com/jackc/pgx/v5/pgxpool" ) -const kind string = "postgres-list-roles" +const resourceType string = "postgres-list-roles" const listRolesStatement = ` WITH RoleDetails AS ( @@ -71,8 +71,8 @@ const listRolesStatement = ` ` 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)) } } @@ -91,7 +91,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"` @@ -101,7 +101,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) { diff --git a/internal/tools/postgres/postgreslistroles/postgreslistroles_test.go b/internal/tools/postgres/postgreslistroles/postgreslistroles_test.go index 7a29e662a4..1d3c89f056 100644 --- a/internal/tools/postgres/postgreslistroles/postgreslistroles_test.go +++ b/internal/tools/postgres/postgreslistroles/postgreslistroles_test.go @@ -17,7 +17,6 @@ package postgreslistroles_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,14 +36,14 @@ func TestParseFromYamlPostgresListRoles(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: postgres-list-roles - source: my-postgres-instance - description: some description - authRequired: - - my-google-auth-service - - other-auth-service + kind: tools + name: example_tool + type: postgres-list-roles + source: my-postgres-instance + description: some description + authRequired: + - my-google-auth-service + - other-auth-service `, want: server.ToolConfigs{ "example_tool": postgreslistroles.Config{ @@ -59,11 +58,11 @@ func TestParseFromYamlPostgresListRoles(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: postgres-list-roles - source: my-postgres-instance - description: some description + kind: tools + name: example_tool + type: postgres-list-roles + source: my-postgres-instance + description: some description `, want: server.ToolConfigs{ "example_tool": postgreslistroles.Config{ @@ -78,15 +77,11 @@ func TestParseFromYamlPostgresListRoles(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) } }) diff --git a/internal/tools/postgres/postgreslistschemas/postgreslistschemas.go b/internal/tools/postgres/postgreslistschemas/postgreslistschemas.go index ae839a9b23..de7757b072 100644 --- a/internal/tools/postgres/postgreslistschemas/postgreslistschemas.go +++ b/internal/tools/postgres/postgreslistschemas/postgreslistschemas.go @@ -26,7 +26,7 @@ import ( "github.com/jackc/pgx/v5/pgxpool" ) -const kind string = "postgres-list-schemas" +const resourceType string = "postgres-list-schemas" const listSchemasStatement = ` WITH @@ -83,8 +83,8 @@ const listSchemasStatement = ` ` 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)) } } @@ -103,7 +103,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"` @@ -113,7 +113,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) { diff --git a/internal/tools/postgres/postgreslistschemas/postgreslistschemas_test.go b/internal/tools/postgres/postgreslistschemas/postgreslistschemas_test.go index c610ed523e..62332b7e7d 100644 --- a/internal/tools/postgres/postgreslistschemas/postgreslistschemas_test.go +++ b/internal/tools/postgres/postgreslistschemas/postgreslistschemas_test.go @@ -17,7 +17,6 @@ package postgreslistschemas_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,14 +36,14 @@ func TestParseFromYamlPostgreslistSchemas(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: postgres-list-schemas - source: my-postgres-instance - description: some description - authRequired: - - my-google-auth-service - - other-auth-service + kind: tools + name: example_tool + type: postgres-list-schemas + source: my-postgres-instance + description: some description + authRequired: + - my-google-auth-service + - other-auth-service `, want: server.ToolConfigs{ "example_tool": postgreslistschemas.Config{ @@ -59,11 +58,11 @@ func TestParseFromYamlPostgreslistSchemas(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: postgres-list-schemas - source: my-postgres-instance - description: some description + kind: tools + name: example_tool + type: postgres-list-schemas + source: my-postgres-instance + description: some description `, want: server.ToolConfigs{ "example_tool": postgreslistschemas.Config{ @@ -78,15 +77,11 @@ func TestParseFromYamlPostgreslistSchemas(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) } }) diff --git a/internal/tools/postgres/postgreslistsequences/postgreslistsequences.go b/internal/tools/postgres/postgreslistsequences/postgreslistsequences.go index 588745adeb..dac0afee43 100644 --- a/internal/tools/postgres/postgreslistsequences/postgreslistsequences.go +++ b/internal/tools/postgres/postgreslistsequences/postgreslistsequences.go @@ -26,7 +26,7 @@ import ( "github.com/jackc/pgx/v5/pgxpool" ) -const kind string = "postgres-list-sequences" +const resourceType string = "postgres-list-sequences" const listSequencesStatement = ` SELECT @@ -49,8 +49,8 @@ const listSequencesStatement = ` ` 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)) } } @@ -69,7 +69,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"` @@ -79,7 +79,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) { diff --git a/internal/tools/postgres/postgreslistsequences/postgreslistsequences_test.go b/internal/tools/postgres/postgreslistsequences/postgreslistsequences_test.go index 496e639d2e..5491eec275 100644 --- a/internal/tools/postgres/postgreslistsequences/postgreslistsequences_test.go +++ b/internal/tools/postgres/postgreslistsequences/postgreslistsequences_test.go @@ -17,7 +17,6 @@ package postgreslistsequences_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,14 +36,14 @@ func TestParseFromYamlPostgresListSequences(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: postgres-list-sequences - source: my-postgres-instance - description: some description - authRequired: - - my-google-auth-service - - other-auth-service + kind: tools + name: example_tool + type: postgres-list-sequences + source: my-postgres-instance + description: some description + authRequired: + - my-google-auth-service + - other-auth-service `, want: server.ToolConfigs{ "example_tool": postgreslistsequences.Config{ @@ -59,11 +58,11 @@ func TestParseFromYamlPostgresListSequences(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: postgres-list-sequences - source: my-postgres-instance - description: some description + kind: tools + name: example_tool + type: postgres-list-sequences + source: my-postgres-instance + description: some description `, want: server.ToolConfigs{ "example_tool": postgreslistsequences.Config{ @@ -78,15 +77,11 @@ func TestParseFromYamlPostgresListSequences(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) } }) diff --git a/internal/tools/postgres/postgresliststoredprocedure/postgresliststoredprocedure.go b/internal/tools/postgres/postgresliststoredprocedure/postgresliststoredprocedure.go index e5fe3dc718..80fafb5420 100644 --- a/internal/tools/postgres/postgresliststoredprocedure/postgresliststoredprocedure.go +++ b/internal/tools/postgres/postgresliststoredprocedure/postgresliststoredprocedure.go @@ -29,7 +29,7 @@ import ( "github.com/jackc/pgx/v5/pgxpool" ) -const kind string = "postgres-list-stored-procedure" +const resourceType string = "postgres-list-stored-procedure" const listStoredProcedure = ` SELECT @@ -53,8 +53,8 @@ const listStoredProcedure = ` ` 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)) } } @@ -79,7 +79,7 @@ var compatibleSources = [...]string{alloydbpg.SourceType, cloudsqlpg.SourceType, 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"` @@ -89,7 +89,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) { @@ -102,7 +102,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 kind must be one of %q", kind, compatibleSources) + return nil, fmt.Errorf("invalid source for %q tool: source type must be one of %q", resourceType, compatibleSources) } allParameters := parameters.Parameters{ @@ -120,11 +120,9 @@ func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error) // finish tool setup return Tool{ - name: cfg.Name, - kind: cfg.Type, - authRequired: cfg.AuthRequired, - allParams: allParameters, - pool: s.PostgresPool(), + Config: cfg, + allParams: allParameters, + pool: s.PostgresPool(), manifest: tools.Manifest{ Description: cfg.Description, Parameters: paramManifest, @@ -139,13 +137,10 @@ var _ tools.Tool = Tool{} type Tool struct { Config - name string `yaml:"name"` - kind string `yaml:"kind"` - authRequired []string `yaml:"authRequired"` - allParams parameters.Parameters `yaml:"allParams"` - pool *pgxpool.Pool - manifest tools.Manifest - mcpManifest tools.McpManifest + allParams parameters.Parameters `yaml:"allParams"` + pool *pgxpool.Pool + manifest tools.Manifest + mcpManifest tools.McpManifest } func (t Tool) ToConfig() tools.ToolConfig { @@ -202,7 +197,7 @@ func (t Tool) McpManifest() tools.McpManifest { } func (t Tool) Authorized(verifiedAuthServices []string) bool { - return tools.IsAuthorized(t.authRequired, verifiedAuthServices) + return tools.IsAuthorized(t.AuthRequired, verifiedAuthServices) } func (t Tool) RequiresClientAuthorization(resourceMgr tools.SourceProvider) (bool, error) { diff --git a/internal/tools/postgres/postgresliststoredprocedure/postgresliststoredprocedure_test.go b/internal/tools/postgres/postgresliststoredprocedure/postgresliststoredprocedure_test.go index 34821c2380..63593bd0ec 100644 --- a/internal/tools/postgres/postgresliststoredprocedure/postgresliststoredprocedure_test.go +++ b/internal/tools/postgres/postgresliststoredprocedure/postgresliststoredprocedure_test.go @@ -17,7 +17,6 @@ package postgresliststoredprocedure_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,14 +36,14 @@ func TestParseFromYamlPostgresListStoredProcedure(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: postgres-list-stored-procedure - source: my-postgres-instance - description: some description - authRequired: - - my-google-auth-service - - other-auth-service + kind: tools + name: example_tool + type: postgres-list-stored-procedure + source: my-postgres-instance + description: some description + authRequired: + - my-google-auth-service + - other-auth-service `, want: server.ToolConfigs{ "example_tool": postgresliststoredprocedure.Config{ @@ -59,11 +58,11 @@ func TestParseFromYamlPostgresListStoredProcedure(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: postgres-list-stored-procedure - source: my-postgres-instance - description: some description + kind: tools + name: example_tool + type: postgres-list-stored-procedure + source: my-postgres-instance + description: some description `, want: server.ToolConfigs{ "example_tool": postgresliststoredprocedure.Config{ @@ -78,15 +77,11 @@ func TestParseFromYamlPostgresListStoredProcedure(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) } }) diff --git a/internal/tools/postgres/postgreslisttables/postgreslisttables.go b/internal/tools/postgres/postgreslisttables/postgreslisttables.go index 389a7eb13c..980ff79d47 100644 --- a/internal/tools/postgres/postgreslisttables/postgreslisttables.go +++ b/internal/tools/postgres/postgreslisttables/postgreslisttables.go @@ -26,7 +26,7 @@ import ( "github.com/jackc/pgx/v5/pgxpool" ) -const kind string = "postgres-list-tables" +const resourceType string = "postgres-list-tables" const listTablesStatement = ` WITH desired_relkinds AS ( @@ -107,8 +107,8 @@ const listTablesStatement = ` ` 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)) } } @@ -127,7 +127,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"` @@ -137,7 +137,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) { diff --git a/internal/tools/postgres/postgreslisttables/postgreslisttables_test.go b/internal/tools/postgres/postgreslisttables/postgreslisttables_test.go index 907244af3d..fdb66825c9 100644 --- a/internal/tools/postgres/postgreslisttables/postgreslisttables_test.go +++ b/internal/tools/postgres/postgreslisttables/postgreslisttables_test.go @@ -17,7 +17,6 @@ package postgreslisttables_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,14 +36,14 @@ func TestParseFromYamlPostgresListTables(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: postgres-list-tables - source: my-postgres-instance - description: some description - authRequired: - - my-google-auth-service - - other-auth-service + kind: tools + name: example_tool + type: postgres-list-tables + source: my-postgres-instance + description: some description + authRequired: + - my-google-auth-service + - other-auth-service `, want: server.ToolConfigs{ "example_tool": postgreslisttables.Config{ @@ -59,15 +58,12 @@ func TestParseFromYamlPostgresListTables(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) } }) diff --git a/internal/tools/postgres/postgreslisttablespaces/postgreslisttablespaces.go b/internal/tools/postgres/postgreslisttablespaces/postgreslisttablespaces.go index e532434539..995fb2cb01 100644 --- a/internal/tools/postgres/postgreslisttablespaces/postgreslisttablespaces.go +++ b/internal/tools/postgres/postgreslisttablespaces/postgreslisttablespaces.go @@ -26,7 +26,7 @@ import ( "github.com/jackc/pgx/v5/pgxpool" ) -const kind string = "postgres-list-tablespaces" +const resourceType string = "postgres-list-tablespaces" const listTableSpacesStatement = ` WITH @@ -55,8 +55,8 @@ const listTableSpacesStatement = ` ` 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)) } } @@ -75,7 +75,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"` @@ -85,7 +85,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) { diff --git a/internal/tools/postgres/postgreslisttablespaces/postgreslisttablespaces_test.go b/internal/tools/postgres/postgreslisttablespaces/postgreslisttablespaces_test.go index f97b89a797..88e134221a 100644 --- a/internal/tools/postgres/postgreslisttablespaces/postgreslisttablespaces_test.go +++ b/internal/tools/postgres/postgreslisttablespaces/postgreslisttablespaces_test.go @@ -17,7 +17,6 @@ package postgreslisttablespaces_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,14 +36,14 @@ func TestParseFromYamlPostgresListTablespaces(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: postgres-list-tablespaces - source: my-postgres-instance - description: some description - authRequired: - - my-google-auth-service - - other-auth-service + kind: tools + name: example_tool + type: postgres-list-tablespaces + source: my-postgres-instance + description: some description + authRequired: + - my-google-auth-service + - other-auth-service `, want: server.ToolConfigs{ "example_tool": postgreslisttablespaces.Config{ @@ -59,11 +58,11 @@ func TestParseFromYamlPostgresListTablespaces(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: postgres-list-tablespaces - source: my-postgres-instance - description: some description + kind: tools + name: example_tool + type: postgres-list-tablespaces + source: my-postgres-instance + description: some description `, want: server.ToolConfigs{ "example_tool": postgreslisttablespaces.Config{ @@ -78,15 +77,12 @@ func TestParseFromYamlPostgresListTablespaces(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) } }) diff --git a/internal/tools/postgres/postgreslisttablestats/postgreslisttablestats.go b/internal/tools/postgres/postgreslisttablestats/postgreslisttablestats.go index 4b002d93ca..7d3988f944 100644 --- a/internal/tools/postgres/postgreslisttablestats/postgreslisttablestats.go +++ b/internal/tools/postgres/postgreslisttablestats/postgreslisttablestats.go @@ -26,7 +26,7 @@ import ( "github.com/jackc/pgx/v5/pgxpool" ) -const kind string = "postgres-list-table-stats" +const resourceType string = "postgres-list-table-stats" const listTableStats = ` WITH table_stats AS ( @@ -76,8 +76,8 @@ const listTableStats = ` ` 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)) } } @@ -96,7 +96,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"` @@ -106,7 +106,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) { diff --git a/internal/tools/postgres/postgreslisttablestats/postgreslisttablestats_test.go b/internal/tools/postgres/postgreslisttablestats/postgreslisttablestats_test.go index df65f7f713..c0c71c4924 100644 --- a/internal/tools/postgres/postgreslisttablestats/postgreslisttablestats_test.go +++ b/internal/tools/postgres/postgreslisttablestats/postgreslisttablestats_test.go @@ -17,7 +17,6 @@ package postgreslisttablestats_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,14 +36,14 @@ func TestParseFromYamlPostgresListTableStats(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: postgres-list-table-stats - source: my-postgres-instance - description: some description - authRequired: - - my-google-auth-service - - other-auth-service + kind: tools + name: example_tool + type: postgres-list-table-stats + source: my-postgres-instance + description: some description + authRequired: + - my-google-auth-service + - other-auth-service `, want: server.ToolConfigs{ "example_tool": postgreslisttablestats.Config{ @@ -59,11 +58,11 @@ func TestParseFromYamlPostgresListTableStats(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: postgres-list-table-stats - source: my-postgres-instance - description: some description + kind: tools + name: example_tool + type: postgres-list-table-stats + source: my-postgres-instance + description: some description `, want: server.ToolConfigs{ "example_tool": postgreslisttablestats.Config{ @@ -78,15 +77,11 @@ func TestParseFromYamlPostgresListTableStats(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) } }) diff --git a/internal/tools/postgres/postgreslisttriggers/postgreslisttriggers.go b/internal/tools/postgres/postgreslisttriggers/postgreslisttriggers.go index d73b8521c0..eb593dc6f1 100644 --- a/internal/tools/postgres/postgreslisttriggers/postgreslisttriggers.go +++ b/internal/tools/postgres/postgreslisttriggers/postgreslisttriggers.go @@ -26,7 +26,7 @@ import ( "github.com/jackc/pgx/v5/pgxpool" ) -const kind string = "postgres-list-triggers" +const resourceType string = "postgres-list-triggers" const listTriggersStatement = ` WITH @@ -75,8 +75,8 @@ const listTriggersStatement = ` ` 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 { 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"` @@ -105,7 +105,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) { diff --git a/internal/tools/postgres/postgreslisttriggers/postgreslisttriggers_test.go b/internal/tools/postgres/postgreslisttriggers/postgreslisttriggers_test.go index 55f9e475bd..ecec935040 100644 --- a/internal/tools/postgres/postgreslisttriggers/postgreslisttriggers_test.go +++ b/internal/tools/postgres/postgreslisttriggers/postgreslisttriggers_test.go @@ -17,7 +17,6 @@ package postgreslisttriggers_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,14 +36,14 @@ func TestParseFromYamlPostgreslistTriggers(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: postgres-list-triggers - source: my-postgres-instance - description: some description - authRequired: - - my-google-auth-service - - other-auth-service + kind: tools + name: example_tool + type: postgres-list-triggers + source: my-postgres-instance + description: some description + authRequired: + - my-google-auth-service + - other-auth-service `, want: server.ToolConfigs{ "example_tool": postgreslisttriggers.Config{ @@ -59,11 +58,11 @@ func TestParseFromYamlPostgreslistTriggers(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: postgres-list-triggers - source: my-postgres-instance - description: some description + kind: tools + name: example_tool + type: postgres-list-triggers + source: my-postgres-instance + description: some description `, want: server.ToolConfigs{ "example_tool": postgreslisttriggers.Config{ @@ -78,15 +77,12 @@ func TestParseFromYamlPostgreslistTriggers(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) } }) diff --git a/internal/tools/postgres/postgreslistviews/postgreslistviews.go b/internal/tools/postgres/postgreslistviews/postgreslistviews.go index 6099a94d37..c09ba6af35 100644 --- a/internal/tools/postgres/postgreslistviews/postgreslistviews.go +++ b/internal/tools/postgres/postgreslistviews/postgreslistviews.go @@ -26,7 +26,7 @@ import ( "github.com/jackc/pgx/v5/pgxpool" ) -const kind string = "postgres-list-views" +const resourceType string = "postgres-list-views" const listViewsStatement = ` WITH list_views AS ( @@ -50,8 +50,8 @@ const listViewsStatement = ` ` 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)) } } @@ -70,7 +70,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"` @@ -80,7 +80,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) { diff --git a/internal/tools/postgres/postgreslistviews/postgreslistviews_test.go b/internal/tools/postgres/postgreslistviews/postgreslistviews_test.go index 2b601c8c93..660a77a431 100644 --- a/internal/tools/postgres/postgreslistviews/postgreslistviews_test.go +++ b/internal/tools/postgres/postgreslistviews/postgreslistviews_test.go @@ -17,7 +17,6 @@ package postgreslistviews_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,14 +36,14 @@ func TestParseFromYamlPostgresListViews(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: postgres-list-views - source: my-postgres-instance - description: some description - authRequired: - - my-google-auth-service - - other-auth-service + kind: tools + name: example_tool + type: postgres-list-views + source: my-postgres-instance + description: some description + authRequired: + - my-google-auth-service + - other-auth-service `, want: server.ToolConfigs{ "example_tool": postgreslistviews.Config{ @@ -59,11 +58,11 @@ func TestParseFromYamlPostgresListViews(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: postgres-list-views - source: my-postgres-instance - description: some description + kind: tools + name: example_tool + type: postgres-list-views + source: my-postgres-instance + description: some description `, want: server.ToolConfigs{ "example_tool": postgreslistviews.Config{ @@ -78,15 +77,12 @@ func TestParseFromYamlPostgresListViews(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) } }) diff --git a/internal/tools/postgres/postgreslongrunningtransactions/postgreslongrunningtransactions.go b/internal/tools/postgres/postgreslongrunningtransactions/postgreslongrunningtransactions.go index ebbf5bff52..5b436f303a 100644 --- a/internal/tools/postgres/postgreslongrunningtransactions/postgreslongrunningtransactions.go +++ b/internal/tools/postgres/postgreslongrunningtransactions/postgreslongrunningtransactions.go @@ -26,7 +26,7 @@ import ( "github.com/jackc/pgx/v5/pgxpool" ) -const kind string = "postgres-long-running-transactions" +const resourceType string = "postgres-long-running-transactions" const longRunningTransactions = ` SELECT @@ -57,8 +57,8 @@ const longRunningTransactions = ` ` 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)) } } @@ -77,7 +77,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"` @@ -87,7 +87,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) { diff --git a/internal/tools/postgres/postgreslongrunningtransactions/postgreslongrunningtransactions_test.go b/internal/tools/postgres/postgreslongrunningtransactions/postgreslongrunningtransactions_test.go index aa6f0fe828..58fc3c8454 100644 --- a/internal/tools/postgres/postgreslongrunningtransactions/postgreslongrunningtransactions_test.go +++ b/internal/tools/postgres/postgreslongrunningtransactions/postgreslongrunningtransactions_test.go @@ -17,7 +17,6 @@ package postgreslongrunningtransactions_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,14 +36,14 @@ func TestParseFromYamlPostgresLongRunningTransactions(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: postgres-long-running-transactions - source: my-postgres-instance - description: some description - authRequired: - - my-google-auth-service - - other-auth-service + kind: tools + name: example_tool + type: postgres-long-running-transactions + source: my-postgres-instance + description: some description + authRequired: + - my-google-auth-service + - other-auth-service `, want: server.ToolConfigs{ "example_tool": postgreslongrunningtransactions.Config{ @@ -59,11 +58,11 @@ func TestParseFromYamlPostgresLongRunningTransactions(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: postgres-long-running-transactions - source: my-postgres-instance - description: some description + kind: tools + name: example_tool + type: postgres-long-running-transactions + source: my-postgres-instance + description: some description `, want: server.ToolConfigs{ "example_tool": postgreslongrunningtransactions.Config{ @@ -78,15 +77,11 @@ func TestParseFromYamlPostgresLongRunningTransactions(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) } }) diff --git a/internal/tools/postgres/postgresreplicationstats/postgresreplicationstats.go b/internal/tools/postgres/postgresreplicationstats/postgresreplicationstats.go index eb78952db9..0252a55c11 100644 --- a/internal/tools/postgres/postgresreplicationstats/postgresreplicationstats.go +++ b/internal/tools/postgres/postgresreplicationstats/postgresreplicationstats.go @@ -26,7 +26,7 @@ import ( "github.com/jackc/pgx/v5/pgxpool" ) -const kind string = "postgres-replication-stats" +const resourceType string = "postgres-replication-stats" const replicationStats = ` SELECT @@ -47,8 +47,8 @@ const replicationStats = ` ` 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)) } } @@ -67,7 +67,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"` @@ -77,7 +77,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) { diff --git a/internal/tools/postgres/postgresreplicationstats/postgresreplicationstats_test.go b/internal/tools/postgres/postgresreplicationstats/postgresreplicationstats_test.go index 428d5731b8..87952ecee6 100644 --- a/internal/tools/postgres/postgresreplicationstats/postgresreplicationstats_test.go +++ b/internal/tools/postgres/postgresreplicationstats/postgresreplicationstats_test.go @@ -17,7 +17,6 @@ package postgresreplicationstats_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,14 +36,14 @@ func TestParseFromYamlPostgresReplicationStats(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: postgres-replication-stats - source: my-postgres-instance - description: some description - authRequired: - - my-google-auth-service - - other-auth-service + kind: tools + name: example_tool + type: postgres-replication-stats + source: my-postgres-instance + description: some description + authRequired: + - my-google-auth-service + - other-auth-service `, want: server.ToolConfigs{ "example_tool": postgresreplicationstats.Config{ @@ -59,11 +58,11 @@ func TestParseFromYamlPostgresReplicationStats(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: postgres-replication-stats - source: my-postgres-instance - description: some description + kind: tools + name: example_tool + type: postgres-replication-stats + source: my-postgres-instance + description: some description `, want: server.ToolConfigs{ "example_tool": postgresreplicationstats.Config{ @@ -78,15 +77,12 @@ func TestParseFromYamlPostgresReplicationStats(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) } }) diff --git a/internal/tools/postgres/postgressql/postgressql.go b/internal/tools/postgres/postgressql/postgressql.go index 7876591c3b..167e8e0d0e 100644 --- a/internal/tools/postgres/postgressql/postgressql.go +++ b/internal/tools/postgres/postgressql/postgressql.go @@ -26,11 +26,11 @@ import ( "github.com/jackc/pgx/v5/pgxpool" ) -const kind string = "postgres-sql" +const resourceType string = "postgres-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) { diff --git a/internal/tools/postgres/postgressql/postgressql_test.go b/internal/tools/postgres/postgressql/postgressql_test.go index 2e22e64bc4..76d8b88f76 100644 --- a/internal/tools/postgres/postgressql/postgressql_test.go +++ b/internal/tools/postgres/postgressql/postgressql_test.go @@ -17,7 +17,6 @@ package postgressql_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,25 +37,25 @@ func TestParseFromYamlPostgres(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: postgres-sql - source: my-pg-instance - description: some description - statement: | - SELECT * FROM SQL_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 + name: example_tool + type: postgres-sql + source: my-pg-instance + description: some description + statement: | + SELECT * FROM SQL_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": postgressql.Config{ @@ -77,15 +76,12 @@ func TestParseFromYamlPostgres(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) } }) @@ -106,28 +102,28 @@ func TestParseFromYamlWithTemplateParamsPostgres(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: postgres-sql - source: my-pg-instance - description: some description - statement: | - SELECT * FROM SQL_STATEMENT; - parameters: - - name: name - 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: postgres-sql + source: my-pg-instance + description: some description + statement: | + SELECT * FROM SQL_STATEMENT; + parameters: + - name: name + 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": postgressql.Config{ @@ -150,15 +146,12 @@ func TestParseFromYamlWithTemplateParamsPostgres(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) } }) diff --git a/internal/tools/redis/redis.go b/internal/tools/redis/redis.go index a48ae0c4e2..b282761d61 100644 --- a/internal/tools/redis/redis.go +++ b/internal/tools/redis/redis.go @@ -25,11 +25,11 @@ import ( "github.com/googleapis/genai-toolbox/internal/util/parameters" ) -const kind string = "redis" +const resourceType string = "redis" 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)) } } @@ -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"` Commands [][]string `yaml:"commands" validate:"required"` @@ -60,7 +60,7 @@ type Config struct { var _ tools.ToolConfig = Config{} func (cfg Config) ToolConfigType() string { - return kind + return resourceType } func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error) { diff --git a/internal/tools/redis/redis_test.go b/internal/tools/redis/redis_test.go index 7c3c477e96..88b50d8274 100644 --- a/internal/tools/redis/redis_test.go +++ b/internal/tools/redis/redis_test.go @@ -17,7 +17,6 @@ package redis_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 TestParseFromYamlRedis(t *testing.T) { { desc: "basic example", in: ` - tools: - redis_tool: - kind: redis - source: my-redis-instance - description: some description - commands: - - [SET, greeting, "hello, {{.name}}"] - - [GET, id] - parameters: - - name: name - type: string - description: user name + kind: tools + name: redis_tool + type: redis + source: my-redis-instance + description: some description + commands: + - [SET, greeting, "hello, {{.name}}"] + - [GET, id] + parameters: + - name: name + type: string + description: user name `, want: server.ToolConfigs{ "redis_tool": redis.Config{ @@ -68,15 +67,11 @@ func TestParseFromYamlRedis(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) } }) diff --git a/internal/tools/serverlessspark/createbatch/config.go b/internal/tools/serverlessspark/createbatch/config.go index 2616ff794d..229ddef936 100644 --- a/internal/tools/serverlessspark/createbatch/config.go +++ b/internal/tools/serverlessspark/createbatch/config.go @@ -43,7 +43,7 @@ type compatibleSource interface { // Initialize implementation. 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"` RuntimeConfig *dataprocpb.RuntimeConfig `yaml:"runtimeConfig"` @@ -56,7 +56,7 @@ func NewConfig(ctx context.Context, name string, decoder *yaml.Decoder) (Config, // conversion for RuntimeConfig and EnvironmentConfig. var ymlCfg struct { Name string `yaml:"name"` - Type string `yaml:"kind"` + Type string `yaml:"type"` Source string `yaml:"source"` Description string `yaml:"description"` RuntimeConfig any `yaml:"runtimeConfig"` diff --git a/internal/tools/serverlessspark/serverlesssparkcancelbatch/serverlesssparkcancelbatch.go b/internal/tools/serverlessspark/serverlesssparkcancelbatch/serverlesssparkcancelbatch.go index 2acbc91999..a0cc87d222 100644 --- a/internal/tools/serverlessspark/serverlesssparkcancelbatch/serverlesssparkcancelbatch.go +++ b/internal/tools/serverlessspark/serverlesssparkcancelbatch/serverlesssparkcancelbatch.go @@ -27,11 +27,11 @@ import ( "github.com/googleapis/genai-toolbox/internal/util/parameters" ) -const kind = "serverless-spark-cancel-batch" +const resourceType = "serverless-spark-cancel-batch" 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"` AuthRequired []string `yaml:"authRequired"` @@ -61,7 +61,7 @@ var _ tools.ToolConfig = Config{} // ToolConfigType returns the unique name for this tool. func (cfg Config) ToolConfigType() string { - return kind + return resourceType } // Initialize creates a new Tool instance. diff --git a/internal/tools/serverlessspark/serverlesssparkcancelbatch/serverlesssparkcancelbatch_test.go b/internal/tools/serverlessspark/serverlesssparkcancelbatch/serverlesssparkcancelbatch_test.go index 43278f1d37..463fbf33e1 100644 --- a/internal/tools/serverlessspark/serverlesssparkcancelbatch/serverlesssparkcancelbatch_test.go +++ b/internal/tools/serverlessspark/serverlesssparkcancelbatch/serverlesssparkcancelbatch_test.go @@ -17,7 +17,6 @@ package serverlesssparkcancelbatch_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: - example_tool: - kind: serverless-spark-cancel-batch - source: my-instance - description: some description + kind: tools + name: example_tool + type: serverless-spark-cancel-batch + source: my-instance + description: some description `, want: server.ToolConfigs{ "example_tool": serverlesssparkcancelbatch.Config{ @@ -56,15 +55,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"` - }{} - err := yaml.UnmarshalContext(ctx, testutils.FormatYaml(tc.in), &got, yaml.Strict()) + _, _, _, 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) } }) diff --git a/internal/tools/serverlessspark/serverlesssparkcreatepysparkbatch/serverlesssparkcreatepysparkbatch.go b/internal/tools/serverlessspark/serverlesssparkcreatepysparkbatch/serverlesssparkcreatepysparkbatch.go index c7ae185237..c0801059f8 100644 --- a/internal/tools/serverlessspark/serverlesssparkcreatepysparkbatch/serverlesssparkcreatepysparkbatch.go +++ b/internal/tools/serverlessspark/serverlesssparkcreatepysparkbatch/serverlesssparkcreatepysparkbatch.go @@ -26,11 +26,11 @@ import ( "github.com/googleapis/genai-toolbox/internal/util/parameters" ) -const kind = "serverless-spark-create-pyspark-batch" +const resourceType = "serverless-spark-create-pyspark-batch" 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 @@ var _ tools.ToolConfig = Config{} // ToolConfigType returns the unique name for this tool. func (cfg Config) ToolConfigType() string { - return kind + return resourceType } // Initialize creates a new Tool instance. diff --git a/internal/tools/serverlessspark/serverlesssparkcreatesparkbatch/serverlesssparkcreatesparkbatch.go b/internal/tools/serverlessspark/serverlesssparkcreatesparkbatch/serverlesssparkcreatesparkbatch.go index 91d6e811ba..403ea1573a 100644 --- a/internal/tools/serverlessspark/serverlesssparkcreatesparkbatch/serverlesssparkcreatesparkbatch.go +++ b/internal/tools/serverlessspark/serverlesssparkcreatesparkbatch/serverlesssparkcreatesparkbatch.go @@ -26,11 +26,11 @@ import ( "github.com/googleapis/genai-toolbox/internal/util/parameters" ) -const kind = "serverless-spark-create-spark-batch" +const resourceType = "serverless-spark-create-spark-batch" 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 @@ var _ tools.ToolConfig = Config{} // ToolConfigType returns the unique name for this tool. func (cfg Config) ToolConfigType() string { - return kind + return resourceType } // Initialize creates a new Tool instance. diff --git a/internal/tools/serverlessspark/serverlesssparkgetbatch/serverlesssparkgetbatch.go b/internal/tools/serverlessspark/serverlesssparkgetbatch/serverlesssparkgetbatch.go index 0f1229a696..0a83779302 100644 --- a/internal/tools/serverlessspark/serverlesssparkgetbatch/serverlesssparkgetbatch.go +++ b/internal/tools/serverlessspark/serverlesssparkgetbatch/serverlesssparkgetbatch.go @@ -27,11 +27,11 @@ import ( "github.com/googleapis/genai-toolbox/internal/util/parameters" ) -const kind = "serverless-spark-get-batch" +const resourceType = "serverless-spark-get-batch" 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"` AuthRequired []string `yaml:"authRequired"` @@ -61,7 +61,7 @@ var _ tools.ToolConfig = Config{} // ToolConfigType returns the unique name for this tool. func (cfg Config) ToolConfigType() string { - return kind + return resourceType } // Initialize creates a new Tool instance. diff --git a/internal/tools/serverlessspark/serverlesssparkgetbatch/serverlesssparkgetbatch_test.go b/internal/tools/serverlessspark/serverlesssparkgetbatch/serverlesssparkgetbatch_test.go index 67b7df94c3..e47ec519fb 100644 --- a/internal/tools/serverlessspark/serverlesssparkgetbatch/serverlesssparkgetbatch_test.go +++ b/internal/tools/serverlessspark/serverlesssparkgetbatch/serverlesssparkgetbatch_test.go @@ -17,7 +17,6 @@ package serverlesssparkgetbatch_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: - example_tool: - kind: serverless-spark-get-batch - source: my-instance - description: some description + kind: tools + name: example_tool + type: serverless-spark-get-batch + source: my-instance + description: some description `, want: server.ToolConfigs{ "example_tool": serverlesssparkgetbatch.Config{ @@ -56,15 +55,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"` - }{} - err := yaml.UnmarshalContext(ctx, testutils.FormatYaml(tc.in), &got, yaml.Strict()) + _, _, _, 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) } }) diff --git a/internal/tools/serverlessspark/serverlesssparklistbatches/serverlesssparklistbatches.go b/internal/tools/serverlessspark/serverlesssparklistbatches/serverlesssparklistbatches.go index 94fc755778..b23a7ec63d 100644 --- a/internal/tools/serverlessspark/serverlesssparklistbatches/serverlesssparklistbatches.go +++ b/internal/tools/serverlessspark/serverlesssparklistbatches/serverlesssparklistbatches.go @@ -26,11 +26,11 @@ import ( "github.com/googleapis/genai-toolbox/internal/util/parameters" ) -const kind = "serverless-spark-list-batches" +const resourceType = "serverless-spark-list-batches" 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"` AuthRequired []string `yaml:"authRequired"` @@ -60,7 +60,7 @@ var _ tools.ToolConfig = Config{} // ToolConfigType returns the unique name for this tool. func (cfg Config) ToolConfigType() string { - return kind + return resourceType } // Initialize creates a new Tool instance. diff --git a/internal/tools/serverlessspark/serverlesssparklistbatches/serverlesssparklistbatches_test.go b/internal/tools/serverlessspark/serverlesssparklistbatches/serverlesssparklistbatches_test.go index 6093c5a811..5b465baaa4 100644 --- a/internal/tools/serverlessspark/serverlesssparklistbatches/serverlesssparklistbatches_test.go +++ b/internal/tools/serverlessspark/serverlesssparklistbatches/serverlesssparklistbatches_test.go @@ -17,7 +17,6 @@ package serverlesssparklistbatches_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: - example_tool: - kind: serverless-spark-list-batches - source: my-instance - description: some description + kind: tools + name: example_tool + type: serverless-spark-list-batches + source: my-instance + description: some description `, want: server.ToolConfigs{ "example_tool": serverlesssparklistbatches.Config{ @@ -56,15 +55,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"` - }{} - err := yaml.UnmarshalContext(ctx, testutils.FormatYaml(tc.in), &got, yaml.Strict()) + _, _, _, 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) } }) diff --git a/internal/tools/serverlessspark/testutils/testutils.go b/internal/tools/serverlessspark/testutils/testutils.go index bb0d8c8e32..d9ff086445 100644 --- a/internal/tools/serverlessspark/testutils/testutils.go +++ b/internal/tools/serverlessspark/testutils/testutils.go @@ -20,7 +20,6 @@ import ( "testing" dataproc "cloud.google.com/go/dataproc/v2/apiv1/dataprocpb" - "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" @@ -30,7 +29,7 @@ import ( ) // RunParseFromYAMLTests runs a suite of tests for parsing tool configurations from YAML. -func RunParseFromYAMLTests(t *testing.T, kind string, newConfig func(c createbatch.Config) tools.ToolConfig) { +func RunParseFromYAMLTests(t *testing.T, resourceType string, newConfig func(c createbatch.Config) tools.ToolConfig) { t.Helper() ctx, err := testutils.ContextWithNewLogger() if err != nil { @@ -46,16 +45,16 @@ func RunParseFromYAMLTests(t *testing.T, kind string, newConfig func(c createbat { desc: "basic example", in: fmt.Sprintf(` - tools: - example_tool: - kind: %s - source: my-instance - description: some description - `, kind), + kind: tools + name: example_tool + type: %s + source: my-instance + description: some description + `, resourceType), want: server.ToolConfigs{ "example_tool": newConfig(createbatch.Config{ Name: "example_tool", - Type: kind, + Type: resourceType, Source: "my-instance", Description: "some description", AuthRequired: []string{}, @@ -65,22 +64,22 @@ func RunParseFromYAMLTests(t *testing.T, kind string, newConfig func(c createbat { desc: "detailed config", in: fmt.Sprintf(` - tools: - example_tool: - kind: %s - source: my-instance - description: some description - runtimeConfig: - properties: - "spark.driver.memory": "1g" - environmentConfig: - executionConfig: - networkUri: "my-network" - `, kind), + kind: tools + name: example_tool + type: %s + source: my-instance + description: some description + runtimeConfig: + properties: + "spark.driver.memory": "1g" + environmentConfig: + executionConfig: + networkUri: "my-network" + `, resourceType), want: server.ToolConfigs{ "example_tool": newConfig(createbatch.Config{ Name: "example_tool", - Type: kind, + Type: resourceType, Source: "my-instance", Description: "some description", RuntimeConfig: &dataproc.RuntimeConfig{ @@ -98,36 +97,33 @@ func RunParseFromYAMLTests(t *testing.T, kind string, newConfig func(c createbat { desc: "invalid runtime config", in: fmt.Sprintf(` - tools: - example_tool: - kind: %s - source: my-instance - description: some description - runtimeConfig: - invalidField: true - `, kind), + kind: tools + name: example_tool + type: %s + source: my-instance + description: some description + runtimeConfig: + invalidField: true + `, resourceType), wantErr: "unmarshal runtimeConfig", }, { desc: "invalid environment config", in: fmt.Sprintf(` - tools: - example_tool: - kind: %s - source: my-instance - description: some description - environmentConfig: - invalidField: true - `, kind), + kind: tools + name: example_tool + type: %s + source: my-instance + description: some description + environmentConfig: + invalidField: true + `, resourceType), wantErr: "unmarshal environmentConfig", }, } 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, yaml.Strict()) + _, _, _, got, _, _, err := server.UnmarshalResourceConfig(ctx, testutils.FormatYaml(tc.in)) if tc.wantErr != "" { if err == nil { t.Fatal("expected error, got nil") @@ -141,7 +137,7 @@ func RunParseFromYAMLTests(t *testing.T, kind string, newConfig func(c createbat t.Fatalf("unable to unmarshal: %s", err) } - if diff := cmp.Diff(tc.want, got.Tools, protocmp.Transform()); diff != "" { + if diff := cmp.Diff(tc.want, got, protocmp.Transform()); diff != "" { t.Fatalf("incorrect parse: diff %v", diff) } }) diff --git a/internal/tools/singlestore/singlestoreexecutesql/singlestoreexecutesql.go b/internal/tools/singlestore/singlestoreexecutesql/singlestoreexecutesql.go index 48b7abd2e1..2e75eeb7e8 100644 --- a/internal/tools/singlestore/singlestoreexecutesql/singlestoreexecutesql.go +++ b/internal/tools/singlestore/singlestoreexecutesql/singlestoreexecutesql.go @@ -27,11 +27,11 @@ import ( "github.com/googleapis/genai-toolbox/internal/util/parameters" ) -const kind string = "singlestore-execute-sql" +const resourceType string = "singlestore-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)) } } @@ -51,7 +51,7 @@ type compatibleSource interface { // Config represents the configuration for the singlestore-execute-sql 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" validate:"required"` AuthRequired []string `yaml:"authRequired"` @@ -60,9 +60,9 @@ type Config struct { // validate interface var _ tools.ToolConfig = Config{} -// ToolConfigType returns the kind of the tool configuration. +// ToolConfigType returns the type of the tool configuration. func (cfg Config) ToolConfigType() string { - return kind + return resourceType } // Initialize sets up the Tool using the provided sources map. @@ -115,7 +115,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, "executing `%s` tool query: %s", kind, sql) + logger.DebugContext(ctx, "executing `%s` tool query: %s", resourceType, sql) return source.RunSQL(ctx, sql, nil) } diff --git a/internal/tools/singlestore/singlestoreexecutesql/singlestoreexecutesql_test.go b/internal/tools/singlestore/singlestoreexecutesql/singlestoreexecutesql_test.go index df27e46890..208a369342 100644 --- a/internal/tools/singlestore/singlestoreexecutesql/singlestoreexecutesql_test.go +++ b/internal/tools/singlestore/singlestoreexecutesql/singlestoreexecutesql_test.go @@ -17,14 +17,13 @@ package singlestoreexecutesql_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" "github.com/googleapis/genai-toolbox/internal/tools/singlestore/singlestoreexecutesql" ) -func TestParseFromYamlExecuteSql(t *testing.T) { +func TestParseFromYaml(t *testing.T) { ctx, err := testutils.ContextWithNewLogger() if err != nil { t.Fatalf("unexpected error: %s", err) @@ -37,14 +36,14 @@ func TestParseFromYamlExecuteSql(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: singlestore-execute-sql - source: my-instance - description: some description - authRequired: - - my-google-auth-service - - other-auth-service + kind: tools + name: example_tool + type: singlestore-execute-sql + source: my-instance + description: some description + authRequired: + - my-google-auth-service + - other-auth-service `, want: server.ToolConfigs{ "example_tool": singlestoreexecutesql.Config{ @@ -59,15 +58,11 @@ func TestParseFromYamlExecuteSql(t *testing.T) { } for _, tc := range tcs { t.Run(tc.desc, func(t *testing.T) { - got := struct { - Tools server.ToolConfigs `yaml:"tools"` - }{} - // Parse contents - err := yaml.UnmarshalContext(ctx, testutils.FormatYaml(tc.in), &got) + _, _, _, got, _, _, err := server.UnmarshalResourceConfig(ctx, testutils.FormatYaml(tc.in)) if err != nil { t.Fatalf("unable to unmarshal: %s", err) } - if diff := cmp.Diff(tc.want, got.Tools); diff != "" { + if diff := cmp.Diff(tc.want, got); diff != "" { t.Fatalf("incorrect parse: diff %v", diff) } }) diff --git a/internal/tools/singlestore/singlestoresql/singlestoresql.go b/internal/tools/singlestore/singlestoresql/singlestoresql.go index 50051ea211..8cf45afcb1 100644 --- a/internal/tools/singlestore/singlestoresql/singlestoresql.go +++ b/internal/tools/singlestore/singlestoresql/singlestoresql.go @@ -26,11 +26,11 @@ import ( "github.com/googleapis/genai-toolbox/internal/util/parameters" ) -const kind string = "singlestore-sql" +const resourceType string = "singlestore-sql" func init() { - if !tools.Register(kind, newConfig) { - panic(fmt.Sprintf("tool type %q already registered", kind)) + if !tools.Register(resourceType, newConfig) { + panic(fmt.Sprintf("tool type %q already registered", resourceType)) } } @@ -50,7 +50,7 @@ type compatibleSource interface { // Config defines the configuration for a SingleStore SQL 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" validate:"required"` Statement string `yaml:"statement" validate:"required"` @@ -62,9 +62,9 @@ type Config struct { // validate interface var _ tools.ToolConfig = Config{} -// ToolConfigType returns the kind of the tool configuration. +// ToolConfigType returns the type of the tool configuration. func (cfg Config) ToolConfigType() string { - return kind + return resourceType } // Initialize sets up and returns a new Tool instance based on the provided configuration and available sources. diff --git a/internal/tools/singlestore/singlestoresql/singlestoresql_test.go b/internal/tools/singlestore/singlestoresql/singlestoresql_test.go index f65a147487..e6204d8552 100644 --- a/internal/tools/singlestore/singlestoresql/singlestoresql_test.go +++ b/internal/tools/singlestore/singlestoresql/singlestoresql_test.go @@ -17,7 +17,6 @@ package singlestoresql_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" @@ -25,7 +24,7 @@ import ( "github.com/googleapis/genai-toolbox/internal/util/parameters" ) -func TestParseFromYamlSingleStore(t *testing.T) { +func TestParseFromYaml(t *testing.T) { ctx, err := testutils.ContextWithNewLogger() if err != nil { t.Fatalf("unexpected error: %s", err) @@ -38,25 +37,25 @@ func TestParseFromYamlSingleStore(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: singlestore-sql - source: my-singlestore-instance - description: some description - statement: | - SELECT * FROM SQL_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 + name: example_tool + type: singlestore-sql + source: my-singlestore-instance + description: some description + statement: | + SELECT * FROM SQL_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": singlestoresql.Config{ @@ -74,67 +73,39 @@ func TestParseFromYamlSingleStore(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) - if err != nil { - t.Fatalf("unable to unmarshal: %s", err) - } - if diff := cmp.Diff(tc.want, got.Tools); diff != "" { - t.Fatalf("incorrect parse: diff %v", diff) - } - }) - } -} - -func TestParseFromYamlWithTemplateParamsSingleStore(t *testing.T) { - ctx, err := testutils.ContextWithNewLogger() - if err != nil { - t.Fatalf("unexpected error: %s", err) - } - tcs := []struct { - desc string - in string - want server.ToolConfigs - }{ { - desc: "basic example", + desc: "with template params", in: ` - tools: - example_tool: - kind: singlestore-sql - source: my-singlestore-instance - description: some description - statement: | - SELECT * FROM SQL_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: 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: singlestore-sql + source: my-singlestore-instance + description: some description + statement: | + SELECT * FROM SQL_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: 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": singlestoresql.Config{ @@ -159,15 +130,11 @@ func TestParseFromYamlWithTemplateParamsSingleStore(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) } }) diff --git a/internal/tools/snowflake/snowflakeexecutesql/snowflakeexecutesql.go b/internal/tools/snowflake/snowflakeexecutesql/snowflakeexecutesql.go index 1ac6eb6fe0..3e954ed38a 100644 --- a/internal/tools/snowflake/snowflakeexecutesql/snowflakeexecutesql.go +++ b/internal/tools/snowflake/snowflakeexecutesql/snowflakeexecutesql.go @@ -27,11 +27,11 @@ import ( "github.com/jmoiron/sqlx" ) -const kind string = "snowflake-execute-sql" +const resourceType string = "snowflake-execute-sql" func init() { - if !tools.Register(kind, newConfig) { - panic(fmt.Sprintf("tool type %q already registered", kind)) + if !tools.Register(resourceType, newConfig) { + panic(fmt.Sprintf("tool type %q already registered", resourceType)) } } @@ -50,7 +50,7 @@ type compatibleSource interface { type Config struct { Name string `yaml:"name" validate:"required"` - Type string `yaml:"kind" validate:"required"` + Type string `yaml:"type" validate:"required"` Source string `yaml:"source" validate:"required"` Description string `yaml:"description" validate:"required"` AuthRequired []string `yaml:"authRequired"` @@ -60,7 +60,7 @@ type Config struct { var _ tools.ToolConfig = Config{} func (cfg Config) ToolConfigType() string { - return kind + return resourceType } func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error) { @@ -106,7 +106,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para if err != nil { return nil, fmt.Errorf("error getting logger: %s", err) } - logger.DebugContext(ctx, fmt.Sprintf("executing `%s` tool query: %s", kind, sql)) + logger.DebugContext(ctx, fmt.Sprintf("executing `%s` tool query: %s", resourceType, sql)) return source.RunSQL(ctx, sql, nil) } diff --git a/internal/tools/snowflake/snowflakeexecutesql/snowflakeexecutesql_test.go b/internal/tools/snowflake/snowflakeexecutesql/snowflakeexecutesql_test.go index c6513c6097..9805012701 100644 --- a/internal/tools/snowflake/snowflakeexecutesql/snowflakeexecutesql_test.go +++ b/internal/tools/snowflake/snowflakeexecutesql/snowflakeexecutesql_test.go @@ -17,7 +17,6 @@ package snowflakeexecutesql_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: - my-snowflake-tool: - kind: snowflake-execute-sql - source: my-snowflake-source - description: Execute SQL on Snowflake + kind: tools + name: my-snowflake-tool + type: snowflake-execute-sql + source: my-snowflake-source + description: Execute SQL on Snowflake `, want: server.ToolConfigs{ "my-snowflake-tool": snowflakeexecutesql.Config{ @@ -56,15 +55,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) } }) @@ -84,21 +80,18 @@ func TestFailParseFromYaml(t *testing.T) { { desc: "missing required field", in: ` - tools: - my-snowflake-tool: - kind: snowflake-execute-sql - source: my-snowflake-source + kind: tools + name: my-snowflake-tool + type: snowflake-execute-sql + source: my-snowflake-source `, - err: "unable to parse tool \"my-snowflake-tool\" as kind \"snowflake-execute-sql\": Key: 'Config.Description' Error:Field validation for 'Description' failed on the 'required' tag", + err: "error unmarshaling tools: unable to parse tool \"my-snowflake-tool\" as type \"snowflake-execute-sql\": 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") } diff --git a/internal/tools/snowflake/snowflakesql/snowflakesql.go b/internal/tools/snowflake/snowflakesql/snowflakesql.go index 3591907202..f51d808c68 100644 --- a/internal/tools/snowflake/snowflakesql/snowflakesql.go +++ b/internal/tools/snowflake/snowflakesql/snowflakesql.go @@ -26,11 +26,11 @@ import ( "github.com/jmoiron/sqlx" ) -const kind string = "snowflake-sql" +const resourceType string = "snowflake-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) { diff --git a/internal/tools/snowflake/snowflakesql/snowflakesql_test.go b/internal/tools/snowflake/snowflakesql/snowflakesql_test.go index 969634ed85..520cae3207 100644 --- a/internal/tools/snowflake/snowflakesql/snowflakesql_test.go +++ b/internal/tools/snowflake/snowflakesql/snowflakesql_test.go @@ -17,7 +17,6 @@ package snowflakesql_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: - my-snowflake-tool: - kind: snowflake-sql - source: my-snowflake-source - description: Execute parameterized SQL on Snowflake - statement: SELECT * FROM my_table WHERE id = $1 + kind: tools + name: my-snowflake-tool + type: snowflake-sql + source: my-snowflake-source + description: Execute parameterized SQL on Snowflake + statement: SELECT * FROM my_table WHERE id = $1 `, want: server.ToolConfigs{ "my-snowflake-tool": snowflakesql.Config{ @@ -60,15 +59,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) } }) @@ -88,22 +84,19 @@ func TestFailParseFromYaml(t *testing.T) { { desc: "missing required field", in: ` - tools: - my-snowflake-tool: - kind: snowflake-sql - source: my-snowflake-source - description: Execute parameterized SQL on Snowflake + kind: tools + name: my-snowflake-tool + type: snowflake-sql + source: my-snowflake-source + description: Execute parameterized SQL on Snowflake `, - err: "unable to parse tool \"my-snowflake-tool\" as kind \"snowflake-sql\": Key: 'Config.Statement' Error:Field validation for 'Statement' failed on the 'required' tag", + err: "error unmarshaling tools: unable to parse tool \"my-snowflake-tool\" as type \"snowflake-sql\": Key: 'Config.Statement' Error:Field validation for 'Statement' 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") } diff --git a/internal/tools/spanner/spannerexecutesql/spannerexecutesql.go b/internal/tools/spanner/spannerexecutesql/spannerexecutesql.go index 38a3a4059d..093fe2a8e9 100644 --- a/internal/tools/spanner/spannerexecutesql/spannerexecutesql.go +++ b/internal/tools/spanner/spannerexecutesql/spannerexecutesql.go @@ -27,11 +27,11 @@ import ( "github.com/googleapis/genai-toolbox/internal/util/parameters" ) -const kind string = "spanner-execute-sql" +const resourceType string = "spanner-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)) } } @@ -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"` @@ -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) { @@ -108,7 +108,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, t.ReadOnly, sql, nil) } diff --git a/internal/tools/spanner/spannerexecutesql/spannerexecutesql_test.go b/internal/tools/spanner/spannerexecutesql/spannerexecutesql_test.go index 1a42ee97b7..76e98e8346 100644 --- a/internal/tools/spanner/spannerexecutesql/spannerexecutesql_test.go +++ b/internal/tools/spanner/spannerexecutesql/spannerexecutesql_test.go @@ -17,7 +17,6 @@ package spannerexecutesql_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 TestParseFromYamlExecuteSql(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: spanner-execute-sql - source: my-spanner-instance - description: some description + kind: tools + name: example_tool + type: spanner-execute-sql + source: my-spanner-instance + description: some description `, want: server.ToolConfigs{ "example_tool": spannerexecutesql.Config{ @@ -57,12 +56,12 @@ func TestParseFromYamlExecuteSql(t *testing.T) { { desc: "read only set to true", in: ` - tools: - example_tool: - kind: spanner-execute-sql - source: my-spanner-instance - description: some description - readOnly: true + kind: tools + name: example_tool + type: spanner-execute-sql + source: my-spanner-instance + description: some description + readOnly: true `, want: server.ToolConfigs{ "example_tool": spannerexecutesql.Config{ @@ -78,15 +77,12 @@ func TestParseFromYamlExecuteSql(t *testing.T) { } for _, tc := range tcs { t.Run(tc.desc, func(t *testing.T) { - got := struct { - Tools server.ToolConfigs `yaml:"tools"` - }{} // Parse contents - err := yaml.UnmarshalContext(ctx, testutils.FormatYaml(tc.in), &got) + _, _, _, got, _, _, err := server.UnmarshalResourceConfig(ctx, testutils.FormatYaml(tc.in)) if err != nil { t.Fatalf("unable to unmarshal: %s", err) } - if diff := cmp.Diff(tc.want, got.Tools); diff != "" { + if diff := cmp.Diff(tc.want, got); diff != "" { t.Fatalf("incorrect parse: diff %v", diff) } }) diff --git a/internal/tools/spanner/spannerlistgraphs/spannerlistgraphs.go b/internal/tools/spanner/spannerlistgraphs/spannerlistgraphs.go index 23b7bfea59..eb69fcee7e 100644 --- a/internal/tools/spanner/spannerlistgraphs/spannerlistgraphs.go +++ b/internal/tools/spanner/spannerlistgraphs/spannerlistgraphs.go @@ -27,11 +27,11 @@ import ( "github.com/googleapis/genai-toolbox/internal/util/parameters" ) -const kind string = "spanner-list-graphs" +const resourceType string = "spanner-list-graphs" 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"` 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) { diff --git a/internal/tools/spanner/spannerlistgraphs/spannerlistgraphs_test.go b/internal/tools/spanner/spannerlistgraphs/spannerlistgraphs_test.go index 905fe3b38a..1dbdd8caad 100644 --- a/internal/tools/spanner/spannerlistgraphs/spannerlistgraphs_test.go +++ b/internal/tools/spanner/spannerlistgraphs/spannerlistgraphs_test.go @@ -17,7 +17,6 @@ package spannerlistgraphs_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 TestParseFromYamlListGraphs(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: spanner-list-graphs - source: my-spanner-instance - description: Lists graphs in the database + kind: tools + name: example_tool + type: spanner-list-graphs + source: my-spanner-instance + description: Lists graphs in the database `, want: server.ToolConfigs{ "example_tool": spannerlistgraphs.Config{ @@ -56,14 +55,14 @@ func TestParseFromYamlListGraphs(t *testing.T) { { desc: "with auth required", in: ` - tools: - example_tool: - kind: spanner-list-graphs - source: my-spanner-instance - description: Lists graphs in the database - authRequired: - - auth1 - - auth2 + kind: tools + name: example_tool + type: spanner-list-graphs + source: my-spanner-instance + description: Lists graphs in the database + authRequired: + - auth1 + - auth2 `, want: server.ToolConfigs{ "example_tool": spannerlistgraphs.Config{ @@ -78,10 +77,10 @@ func TestParseFromYamlListGraphs(t *testing.T) { { desc: "minimal config", in: ` - tools: - example_tool: - kind: spanner-list-graphs - source: my-spanner-instance + kind: tools + name: example_tool + type: spanner-list-graphs + source: my-spanner-instance `, want: server.ToolConfigs{ "example_tool": spannerlistgraphs.Config{ @@ -96,15 +95,12 @@ func TestParseFromYamlListGraphs(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) } }) diff --git a/internal/tools/spanner/spannerlisttables/spannerlisttables.go b/internal/tools/spanner/spannerlisttables/spannerlisttables.go index 5551afd784..7afd8d5d77 100644 --- a/internal/tools/spanner/spannerlisttables/spannerlisttables.go +++ b/internal/tools/spanner/spannerlisttables/spannerlisttables.go @@ -27,11 +27,11 @@ import ( "github.com/googleapis/genai-toolbox/internal/util/parameters" ) -const kind string = "spanner-list-tables" +const resourceType string = "spanner-list-tables" 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"` 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) { diff --git a/internal/tools/spanner/spannerlisttables/spannerlisttables_test.go b/internal/tools/spanner/spannerlisttables/spannerlisttables_test.go index 2a12ba8b36..0bc6fce5cd 100644 --- a/internal/tools/spanner/spannerlisttables/spannerlisttables_test.go +++ b/internal/tools/spanner/spannerlisttables/spannerlisttables_test.go @@ -17,7 +17,6 @@ package spannerlisttables_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 TestParseFromYamlListTables(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: spanner-list-tables - source: my-spanner-instance - description: Lists tables in the database + kind: tools + name: example_tool + type: spanner-list-tables + source: my-spanner-instance + description: Lists tables in the database `, want: server.ToolConfigs{ "example_tool": spannerlisttables.Config{ @@ -56,14 +55,14 @@ func TestParseFromYamlListTables(t *testing.T) { { desc: "with auth required", in: ` - tools: - example_tool: - kind: spanner-list-tables - source: my-spanner-instance - description: Lists tables in the database - authRequired: - - auth1 - - auth2 + kind: tools + name: example_tool + type: spanner-list-tables + source: my-spanner-instance + description: Lists tables in the database + authRequired: + - auth1 + - auth2 `, want: server.ToolConfigs{ "example_tool": spannerlisttables.Config{ @@ -78,10 +77,10 @@ func TestParseFromYamlListTables(t *testing.T) { { desc: "minimal config", in: ` - tools: - example_tool: - kind: spanner-list-tables - source: my-spanner-instance + kind: tools + name: example_tool + type: spanner-list-tables + source: my-spanner-instance `, want: server.ToolConfigs{ "example_tool": spannerlisttables.Config{ @@ -96,15 +95,12 @@ func TestParseFromYamlListTables(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) } }) diff --git a/internal/tools/spanner/spannersql/spanner_test.go b/internal/tools/spanner/spannersql/spanner_test.go index c261c4e53d..227c21b68a 100644 --- a/internal/tools/spanner/spannersql/spanner_test.go +++ b/internal/tools/spanner/spannersql/spanner_test.go @@ -17,7 +17,6 @@ package spannersql_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 TestParseFromYamlSpanner(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: spanner-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: spanner-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": spannersql.Config{ @@ -67,18 +66,18 @@ func TestParseFromYamlSpanner(t *testing.T) { { desc: "read only set to true", in: ` - tools: - example_tool: - kind: spanner-sql - source: my-pg-instance - description: some description - readOnly: true - statement: | - SELECT * FROM SQL_STATEMENT; - parameters: - - name: country - type: string - description: some description + kind: tools + name: example_tool + type: spanner-sql + source: my-pg-instance + description: some description + readOnly: true + statement: | + SELECT * FROM SQL_STATEMENT; + parameters: + - name: country + type: string + description: some description `, want: server.ToolConfigs{ "example_tool": spannersql.Config{ @@ -98,15 +97,12 @@ func TestParseFromYamlSpanner(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) } }) @@ -127,28 +123,28 @@ func TestParseFromYamlWithTemplateParamsSpanner(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: spanner-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: spanner-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": spannersql.Config{ @@ -171,18 +167,18 @@ func TestParseFromYamlWithTemplateParamsSpanner(t *testing.T) { { desc: "read only set to true", in: ` - tools: - example_tool: - kind: spanner-sql - source: my-pg-instance - description: some description - readOnly: true - statement: | - SELECT * FROM SQL_STATEMENT; - parameters: - - name: country - type: string - description: some description + kind: tools + name: example_tool + type: spanner-sql + source: my-pg-instance + description: some description + readOnly: true + statement: | + SELECT * FROM SQL_STATEMENT; + parameters: + - name: country + type: string + description: some description `, want: server.ToolConfigs{ "example_tool": spannersql.Config{ @@ -202,15 +198,12 @@ func TestParseFromYamlWithTemplateParamsSpanner(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) } }) diff --git a/internal/tools/spanner/spannersql/spannersql.go b/internal/tools/spanner/spannersql/spannersql.go index 5bd8b9c622..b0359e0969 100644 --- a/internal/tools/spanner/spannersql/spannersql.go +++ b/internal/tools/spanner/spannersql/spannersql.go @@ -27,11 +27,11 @@ import ( "github.com/googleapis/genai-toolbox/internal/util/parameters" ) -const kind string = "spanner-sql" +const resourceType string = "spanner-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)) } } @@ -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"` Statement string `yaml:"statement" validate:"required"` @@ -65,7 +65,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) { diff --git a/internal/tools/sqlite/sqliteexecutesql/sqliteexecutesql.go b/internal/tools/sqlite/sqliteexecutesql/sqliteexecutesql.go index 3fc76657c6..6d5e7a7e4a 100644 --- a/internal/tools/sqlite/sqliteexecutesql/sqliteexecutesql.go +++ b/internal/tools/sqlite/sqliteexecutesql/sqliteexecutesql.go @@ -27,11 +27,11 @@ import ( "github.com/googleapis/genai-toolbox/internal/util/parameters" ) -const kind string = "sqlite-execute-sql" +const resourceType string = "sqlite-execute-sql" func init() { - if !tools.Register(kind, newConfig) { - panic(fmt.Sprintf("tool type %q already registered", kind)) + if !tools.Register(resourceType, newConfig) { + panic(fmt.Sprintf("tool type %q already registered", resourceType)) } } @@ -50,7 +50,7 @@ type compatibleSource interface { type Config struct { Name string `yaml:"name" validate:"required"` - Type string `yaml:"kind" validate:"required"` + Type string `yaml:"type" validate:"required"` Source string `yaml:"source" validate:"required"` Description string `yaml:"description" validate:"required"` AuthRequired []string `yaml:"authRequired"` @@ -60,7 +60,7 @@ type Config struct { var _ tools.ToolConfig = Config{} func (cfg Config) ToolConfigType() string { - return kind + return resourceType } func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error) { @@ -107,7 +107,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para if err != nil { return nil, fmt.Errorf("error getting logger: %s", err) } - logger.DebugContext(ctx, fmt.Sprintf("executing `%s` tool query: %s", kind, sql)) + logger.DebugContext(ctx, fmt.Sprintf("executing `%s` tool query: %s", resourceType, sql)) return source.RunSQL(ctx, sql, nil) } diff --git a/internal/tools/sqlite/sqliteexecutesql/sqliteexecutesql_test.go b/internal/tools/sqlite/sqliteexecutesql/sqliteexecutesql_test.go index 0745da1308..f45402c86d 100644 --- a/internal/tools/sqlite/sqliteexecutesql/sqliteexecutesql_test.go +++ b/internal/tools/sqlite/sqliteexecutesql/sqliteexecutesql_test.go @@ -17,7 +17,6 @@ package sqliteexecutesql_test import ( "testing" - yaml "github.com/goccy/go-yaml" "github.com/google/go-cmp/cmp" "github.com/googleapis/genai-toolbox/internal/server" "github.com/googleapis/genai-toolbox/internal/testutils" @@ -38,14 +37,14 @@ func TestParseFromYamlExecuteSql(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: sqlite-execute-sql - source: my-instance - description: some description - authRequired: - - my-google-auth-service - - other-auth-service + kind: tools + name: example_tool + type: sqlite-execute-sql + source: my-instance + description: some description + authRequired: + - my-google-auth-service + - other-auth-service `, want: server.ToolConfigs{ "example_tool": sqliteexecutesql.Config{ @@ -60,15 +59,12 @@ func TestParseFromYamlExecuteSql(t *testing.T) { } for _, tc := range tcs { t.Run(tc.desc, func(t *testing.T) { - got := struct { - Tools server.ToolConfigs `yaml:"tools"` - }{} // Parse contents - err := yaml.UnmarshalContext(ctx, testutils.FormatYaml(tc.in), &got) + _, _, _, got, _, _, err := server.UnmarshalResourceConfig(ctx, testutils.FormatYaml(tc.in)) if err != nil { t.Fatalf("unable to unmarshal: %s", err) } - if diff := cmp.Diff(tc.want, got.Tools); diff != "" { + if diff := cmp.Diff(tc.want, got); diff != "" { t.Fatalf("incorrect parse: diff %v", diff) } }) diff --git a/internal/tools/sqlite/sqlitesql/sqlitesql.go b/internal/tools/sqlite/sqlitesql/sqlitesql.go index 45f83ae5ef..5611ddecbd 100644 --- a/internal/tools/sqlite/sqlitesql/sqlitesql.go +++ b/internal/tools/sqlite/sqlitesql/sqlitesql.go @@ -26,11 +26,11 @@ import ( "github.com/googleapis/genai-toolbox/internal/util/parameters" ) -const kind string = "sqlite-sql" +const resourceType string = "sqlite-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) { diff --git a/internal/tools/sqlite/sqlitesql/sqlitesql_test.go b/internal/tools/sqlite/sqlitesql/sqlitesql_test.go index c7716d69f3..6aa2968534 100644 --- a/internal/tools/sqlite/sqlitesql/sqlitesql_test.go +++ b/internal/tools/sqlite/sqlitesql/sqlitesql_test.go @@ -17,7 +17,6 @@ package sqlitesql_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" @@ -39,25 +38,25 @@ func TestParseFromYamlSQLite(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: sqlite-sql - source: my-sqlite-instance - description: some description - statement: | - SELECT * FROM SQL_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 + name: example_tool + type: sqlite-sql + source: my-sqlite-instance + description: some description + statement: | + SELECT * FROM SQL_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": sqlitesql.Config{ @@ -78,15 +77,12 @@ func TestParseFromYamlSQLite(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) } }) @@ -107,36 +103,36 @@ func TestParseFromYamlWithTemplateSqlite(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: sqlite-sql - source: my-sqlite-db - description: some description - statement: | - SELECT * FROM SQL_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: 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: sqlite-sql + source: my-sqlite-db + description: some description + statement: | + SELECT * FROM SQL_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: 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": sqlitesql.Config{ @@ -161,15 +157,12 @@ func TestParseFromYamlWithTemplateSqlite(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) } }) diff --git a/internal/tools/tidb/tidbexecutesql/tidbexecutesql.go b/internal/tools/tidb/tidbexecutesql/tidbexecutesql.go index 3878b1b663..0089a4e642 100644 --- a/internal/tools/tidb/tidbexecutesql/tidbexecutesql.go +++ b/internal/tools/tidb/tidbexecutesql/tidbexecutesql.go @@ -27,11 +27,11 @@ import ( "github.com/googleapis/genai-toolbox/internal/util/parameters" ) -const kind string = "tidb-execute-sql" +const resourceType string = "tidb-execute-sql" func init() { - if !tools.Register(kind, newConfig) { - panic(fmt.Sprintf("tool type %q already registered", kind)) + if !tools.Register(resourceType, newConfig) { + panic(fmt.Sprintf("tool type %q already registered", resourceType)) } } @@ -50,7 +50,7 @@ type compatibleSource interface { type Config struct { Name string `yaml:"name" validate:"required"` - Type string `yaml:"kind" validate:"required"` + Type string `yaml:"type" validate:"required"` Source string `yaml:"source" validate:"required"` Description string `yaml:"description" validate:"required"` AuthRequired []string `yaml:"authRequired"` @@ -60,7 +60,7 @@ type Config struct { var _ tools.ToolConfig = Config{} func (cfg Config) ToolConfigType() string { - return kind + return resourceType } func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error) { @@ -106,7 +106,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para if err != nil { return nil, fmt.Errorf("error getting logger: %s", err) } - logger.DebugContext(ctx, fmt.Sprintf("executing `%s` tool query: %s", kind, sql)) + logger.DebugContext(ctx, fmt.Sprintf("executing `%s` tool query: %s", resourceType, sql)) return source.RunSQL(ctx, sql, nil) } diff --git a/internal/tools/tidb/tidbexecutesql/tidbexecutesql_test.go b/internal/tools/tidb/tidbexecutesql/tidbexecutesql_test.go index 4112386a11..a8742d373b 100644 --- a/internal/tools/tidb/tidbexecutesql/tidbexecutesql_test.go +++ b/internal/tools/tidb/tidbexecutesql/tidbexecutesql_test.go @@ -17,7 +17,6 @@ package tidbexecutesql_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,14 +36,14 @@ func TestParseFromYamlExecuteSql(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: tidb-execute-sql - source: my-instance - description: some description - authRequired: - - my-google-auth-service - - other-auth-service + kind: tools + name: example_tool + type: tidb-execute-sql + source: my-instance + description: some description + authRequired: + - my-google-auth-service + - other-auth-service `, want: server.ToolConfigs{ "example_tool": tidbexecutesql.Config{ @@ -59,15 +58,12 @@ func TestParseFromYamlExecuteSql(t *testing.T) { } for _, tc := range tcs { t.Run(tc.desc, func(t *testing.T) { - got := struct { - Tools server.ToolConfigs `yaml:"tools"` - }{} // Parse contents - err := yaml.UnmarshalContext(ctx, testutils.FormatYaml(tc.in), &got) + _, _, _, got, _, _, err := server.UnmarshalResourceConfig(ctx, testutils.FormatYaml(tc.in)) if err != nil { t.Fatalf("unable to unmarshal: %s", err) } - if diff := cmp.Diff(tc.want, got.Tools); diff != "" { + if diff := cmp.Diff(tc.want, got); diff != "" { t.Fatalf("incorrect parse: diff %v", diff) } }) diff --git a/internal/tools/tidb/tidbsql/tidbsql.go b/internal/tools/tidb/tidbsql/tidbsql.go index 6a9295e94f..1d5998a1bf 100644 --- a/internal/tools/tidb/tidbsql/tidbsql.go +++ b/internal/tools/tidb/tidbsql/tidbsql.go @@ -26,11 +26,11 @@ import ( "github.com/googleapis/genai-toolbox/internal/util/parameters" ) -const kind string = "tidb-sql" +const resourceType string = "tidb-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) { diff --git a/internal/tools/tidb/tidbsql/tidbsql_test.go b/internal/tools/tidb/tidbsql/tidbsql_test.go index aa1d2b0328..65ae5a83aa 100644 --- a/internal/tools/tidb/tidbsql/tidbsql_test.go +++ b/internal/tools/tidb/tidbsql/tidbsql_test.go @@ -17,7 +17,6 @@ package tidbsql_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,25 +37,25 @@ func TestParseFromYamlTiDB(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: tidb-sql - source: my-tidb-instance - description: some description - statement: | - SELECT * FROM SQL_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 + name: example_tool + type: tidb-sql + source: my-tidb-instance + description: some description + statement: | + SELECT * FROM SQL_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": tidbsql.Config{ @@ -77,15 +76,12 @@ func TestParseFromYamlTiDB(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) } }) @@ -105,36 +101,36 @@ func TestParseFromYamlWithTemplateParamsTiDB(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: tidb-sql - source: my-tidb-instance - description: some description - statement: | - SELECT * FROM SQL_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: 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: tidb-sql + source: my-tidb-instance + description: some description + statement: | + SELECT * FROM SQL_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: 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": tidbsql.Config{ @@ -159,15 +155,12 @@ func TestParseFromYamlWithTemplateParamsTiDB(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) } }) diff --git a/internal/tools/tools.go b/internal/tools/tools.go index 6eec101679..2776d9724e 100644 --- a/internal/tools/tools.go +++ b/internal/tools/tools.go @@ -36,28 +36,28 @@ var toolRegistry = make(map[string]ToolConfigFactory) // Register allows individual tool packages to register their configuration // factory function. This is typically called from an init() function in the -// tool's package. It associates a 'kind' string with a function that can +// tool's package. It associates a 'type' string with a function that can // produce the specific ToolConfig type. It returns true if the registration was -// successful, and false if a tool with the same kind was already registered. -func Register(kind string, factory ToolConfigFactory) bool { - if _, exists := toolRegistry[kind]; exists { - // Tool with this kind already exists, do not overwrite. +// successful, and false if a tool with the same type was already registered. +func Register(resourceType string, factory ToolConfigFactory) bool { + if _, exists := toolRegistry[resourceType]; exists { + // Tool with this type already exists, do not overwrite. return false } - toolRegistry[kind] = factory + toolRegistry[resourceType] = factory return true } -// DecodeConfig looks up the registered factory for the given kind and uses it +// DecodeConfig looks up the registered factory for the given type and uses it // to decode the tool configuration. -func DecodeConfig(ctx context.Context, kind string, name string, decoder *yaml.Decoder) (ToolConfig, error) { - factory, found := toolRegistry[kind] +func DecodeConfig(ctx context.Context, resourceType string, name string, decoder *yaml.Decoder) (ToolConfig, error) { + factory, found := toolRegistry[resourceType] if !found { - return nil, fmt.Errorf("unknown tool type: %q", kind) + return nil, fmt.Errorf("unknown tool type: %q", resourceType) } toolConfig, err := factory(ctx, name, decoder) if err != nil { - return nil, fmt.Errorf("unable to parse tool %q as kind %q: %w", name, kind, err) + return nil, fmt.Errorf("unable to parse tool %q as type %q: %w", name, resourceType, err) } return toolConfig, nil } diff --git a/internal/tools/trino/trinoexecutesql/trinoexecutesql.go b/internal/tools/trino/trinoexecutesql/trinoexecutesql.go index a7e274e2fd..283b01a71c 100644 --- a/internal/tools/trino/trinoexecutesql/trinoexecutesql.go +++ b/internal/tools/trino/trinoexecutesql/trinoexecutesql.go @@ -26,11 +26,11 @@ import ( "github.com/googleapis/genai-toolbox/internal/util/parameters" ) -const kind string = "trino-execute-sql" +const resourceType string = "trino-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)) } } @@ -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) { diff --git a/internal/tools/trino/trinoexecutesql/trinoexecutesql_test.go b/internal/tools/trino/trinoexecutesql/trinoexecutesql_test.go index 6a40a32b68..372654d0ee 100644 --- a/internal/tools/trino/trinoexecutesql/trinoexecutesql_test.go +++ b/internal/tools/trino/trinoexecutesql/trinoexecutesql_test.go @@ -17,7 +17,6 @@ package trinoexecutesql_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,14 +36,14 @@ func TestParseFromYamlTrinoExecuteSQL(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: trino-execute-sql - source: my-trino-instance - description: some description - authRequired: - - my-google-auth-service - - other-auth-service + kind: tools + name: example_tool + type: trino-execute-sql + source: my-trino-instance + description: some description + authRequired: + - my-google-auth-service + - other-auth-service `, want: server.ToolConfigs{ "example_tool": trinoexecutesql.Config{ @@ -59,15 +58,11 @@ func TestParseFromYamlTrinoExecuteSQL(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) } }) diff --git a/internal/tools/trino/trinosql/trinosql.go b/internal/tools/trino/trinosql/trinosql.go index 00f7adb9ca..31abaee758 100644 --- a/internal/tools/trino/trinosql/trinosql.go +++ b/internal/tools/trino/trinosql/trinosql.go @@ -26,11 +26,11 @@ import ( "github.com/googleapis/genai-toolbox/internal/util/parameters" ) -const kind string = "trino-sql" +const resourceType string = "trino-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) { diff --git a/internal/tools/trino/trinosql/trinosql_test.go b/internal/tools/trino/trinosql/trinosql_test.go index 4d55f5186b..50908a9350 100644 --- a/internal/tools/trino/trinosql/trinosql_test.go +++ b/internal/tools/trino/trinosql/trinosql_test.go @@ -17,7 +17,6 @@ package trinosql_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,25 +37,25 @@ func TestParseFromYamlTrino(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: trino-sql - source: my-trino-instance - description: some description - statement: | - SELECT * FROM catalog.schema.table WHERE id = ?; - authRequired: - - my-google-auth-service - - other-auth-service - parameters: - - name: id - type: string - description: ID to filter by - authServices: - - name: my-google-auth-service - field: user_id - - name: other-auth-service - field: user_id + kind: tools + name: example_tool + type: trino-sql + source: my-trino-instance + description: some description + statement: | + SELECT * FROM catalog.schema.table WHERE id = ?; + authRequired: + - my-google-auth-service + - other-auth-service + parameters: + - name: id + type: string + description: ID to filter by + authServices: + - name: my-google-auth-service + field: user_id + - name: other-auth-service + field: user_id `, want: server.ToolConfigs{ "example_tool": trinosql.Config{ @@ -77,15 +76,11 @@ func TestParseFromYamlTrino(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) } }) @@ -105,42 +100,42 @@ func TestParseFromYamlWithTemplateParamsTrino(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: trino-sql - source: my-trino-instance - description: some description - statement: | - SELECT * FROM {{ .catalog }}.{{ .schema }}.{{ .tableName }} WHERE country = ?; - 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: catalog - type: string - description: The catalog to query from. - - name: schema - type: string - description: The schema to query from. - - name: tableName - type: string - description: The table to select data 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: trino-sql + source: my-trino-instance + description: some description + statement: | + SELECT * FROM {{ .catalog }}.{{ .schema }}.{{ .tableName }} WHERE country = ?; + 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: catalog + type: string + description: The catalog to query from. + - name: schema + type: string + description: The schema to query from. + - name: tableName + type: string + description: The table to select data 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": trinosql.Config{ @@ -167,15 +162,11 @@ func TestParseFromYamlWithTemplateParamsTrino(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) } }) diff --git a/internal/tools/utility/wait/wait.go b/internal/tools/utility/wait/wait.go index 14b1bc9624..3a7a8f3c33 100644 --- a/internal/tools/utility/wait/wait.go +++ b/internal/tools/utility/wait/wait.go @@ -26,11 +26,11 @@ import ( "github.com/googleapis/genai-toolbox/internal/util/parameters" ) -const kind string = "wait" +const resourceType string = "wait" 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)) } } @@ -44,7 +44,7 @@ func newConfig(ctx context.Context, name string, decoder *yaml.Decoder) (tools.T 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" validate:"required"` Timeout string `yaml:"timeout" validate:"required"` AuthRequired []string `yaml:"authRequired"` @@ -53,7 +53,7 @@ type Config struct { var _ tools.ToolConfig = Config{} func (cfg Config) ToolConfigType() string { - return kind + return resourceType } func (cfg Config) Initialize(_ map[string]sources.Source) (tools.Tool, error) { diff --git a/internal/tools/utility/wait/wait_test.go b/internal/tools/utility/wait/wait_test.go index 4d3a01c913..fb3db875cd 100644 --- a/internal/tools/utility/wait/wait_test.go +++ b/internal/tools/utility/wait/wait_test.go @@ -17,7 +17,6 @@ package wait_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,13 +37,13 @@ func TestParseFromYamlWait(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: wait - description: some description - timeout: 10s - authRequired: - - my-google-auth-service + kind: tools + name: example_tool + type: wait + description: some description + timeout: 10s + authRequired: + - my-google-auth-service `, want: server.ToolConfigs{ "example_tool": wait.Config{ @@ -59,15 +58,11 @@ func TestParseFromYamlWait(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) } }) diff --git a/internal/tools/valkey/valkey.go b/internal/tools/valkey/valkey.go index f14e5f1b24..01ec22203e 100644 --- a/internal/tools/valkey/valkey.go +++ b/internal/tools/valkey/valkey.go @@ -25,11 +25,11 @@ import ( "github.com/valkey-io/valkey-go" ) -const kind string = "valkey" +const resourceType string = "valkey" 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)) } } @@ -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"` Commands [][]string `yaml:"commands" validate:"required"` @@ -60,7 +60,7 @@ type Config struct { var _ tools.ToolConfig = Config{} func (cfg Config) ToolConfigType() string { - return kind + return resourceType } func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error) { diff --git a/internal/tools/valkey/valkey_test.go b/internal/tools/valkey/valkey_test.go index 3ae44a4afa..2bafe4c3d1 100644 --- a/internal/tools/valkey/valkey_test.go +++ b/internal/tools/valkey/valkey_test.go @@ -17,7 +17,6 @@ package valkey_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 TestParseFromYamlvalkey(t *testing.T) { { desc: "basic example", in: ` - tools: - valkey_tool: - kind: valkey - source: my-valkey-instance - description: some description - commands: - - [SET, greeting, "hello, {{.name}}"] - - [GET, id] - parameters: - - name: name - type: string - description: user name + kind: tools + name: valkey_tool + type: valkey + source: my-valkey-instance + description: some description + commands: + - [SET, greeting, "hello, {{.name}}"] + - [GET, id] + parameters: + - name: name + type: string + description: user name `, want: server.ToolConfigs{ "valkey_tool": valkey.Config{ @@ -68,15 +67,11 @@ func TestParseFromYamlvalkey(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) } }) diff --git a/internal/tools/yugabytedbsql/yugabytedbsql.go b/internal/tools/yugabytedbsql/yugabytedbsql.go index 52e8cbb76e..2c3706f7fa 100644 --- a/internal/tools/yugabytedbsql/yugabytedbsql.go +++ b/internal/tools/yugabytedbsql/yugabytedbsql.go @@ -26,11 +26,11 @@ import ( "github.com/yugabyte/pgx/v5/pgxpool" ) -const kind string = "yugabytedb-sql" +const resourceType string = "yugabytedb-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) { diff --git a/internal/tools/yugabytedbsql/yugabytedbsql_test.go b/internal/tools/yugabytedbsql/yugabytedbsql_test.go index 16f6be8f33..24ff000153 100644 --- a/internal/tools/yugabytedbsql/yugabytedbsql_test.go +++ b/internal/tools/yugabytedbsql/yugabytedbsql_test.go @@ -17,7 +17,6 @@ package yugabytedbsql_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,25 +37,25 @@ func TestParseFromYamlYugabyteDBSQL(t *testing.T) { { desc: "basic valid config", in: ` - tools: - hotel_search: - kind: yugabytedb-sql - source: yb-source - description: search hotels by city - statement: | - SELECT * FROM hotels WHERE city = $1; - authRequired: - - auth-service-a - - auth-service-b - parameters: - - name: city - type: string - description: city name - authServices: - - name: auth-service-a - field: user_id - - name: auth-service-b - field: user_id + kind: tools + name: hotel_search + type: yugabytedb-sql + source: yb-source + description: search hotels by city + statement: | + SELECT * FROM hotels WHERE city = $1; + authRequired: + - auth-service-a + - auth-service-b + parameters: + - name: city + type: string + description: city name + authServices: + - name: auth-service-a + field: user_id + - name: auth-service-b + field: user_id `, want: server.ToolConfigs{ "hotel_search": yugabytedbsql.Config{ @@ -81,14 +80,11 @@ func TestParseFromYamlYugabyteDBSQL(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) } }) @@ -107,32 +103,29 @@ func TestFailParseFromYamlYugabyteDBSQL(t *testing.T) { { desc: "missing required field (statement)", in: ` - tools: - tool1: - kind: yugabytedb-sql - source: yb-source - description: incomplete config + kind: tools + name: tool1 + type: yugabytedb-sql + source: yb-source + description: incomplete config `, }, { desc: "unknown field (foo)", in: ` - tools: - tool2: - kind: yugabytedb-sql - source: yb-source - description: test - statement: SELECT 1; - foo: bar + kind: tools + name: tool2 + type: yugabytedb-sql + source: yb-source + description: test + statement: SELECT 1; + foo: bar `, }, } for _, tc := range cases { t.Run(tc.desc, func(t *testing.T) { - cfg := struct { - Tools server.ToolConfigs `yaml:"tools"` - }{} - err := yaml.UnmarshalContext(ctx, testutils.FormatYaml(tc.in), &cfg) + _, _, _, _, _, _, err := server.UnmarshalResourceConfig(ctx, testutils.FormatYaml(tc.in)) if err == nil { t.Fatalf("expected error but got none") } @@ -153,28 +146,28 @@ func TestParseFromYamlWithTemplateParamsYugabyteDB(t *testing.T) { { desc: "basic example", in: ` - tools: - example_tool: - kind: yugabytedb-sql - source: my-yb-instance - description: some description - statement: | - SELECT * FROM SQL_STATEMENT; - parameters: - - name: name - 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: yugabytedb-sql + source: my-yb-instance + description: some description + statement: | + SELECT * FROM SQL_STATEMENT; + parameters: + - name: name + 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": yugabytedbsql.Config{ @@ -197,15 +190,11 @@ func TestParseFromYamlWithTemplateParamsYugabyteDB(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) } })