mirror of
https://github.com/googleapis/genai-toolbox.git
synced 2026-02-04 20:25:05 -05:00
update more tools
This commit is contained in:
@@ -162,7 +162,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
resp, err := source.CreateCluster(ctx, project, location, network, user, password, clusterID, string(accessToken))
|
||||
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
|
||||
@@ -168,7 +168,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
|
||||
resp, err := source.CreateInstance(ctx, project, location, cluster, instanceID, instanceType, displayName, nodeCount, string(accessToken))
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -173,7 +173,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
}
|
||||
resp, err := source.CreateUser(ctx, userType, password, roles, string(accessToken), project, location, cluster, userID)
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
|
||||
resp, err := source.GetCluster(ctx, project, location, cluster, string(accessToken))
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -148,7 +148,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
|
||||
resp, err := source.GetInstance(ctx, project, location, cluster, instance, string(accessToken))
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -148,7 +148,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
|
||||
resp, err := source.GetUsers(ctx, project, location, cluster, user, string(accessToken))
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -138,7 +138,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
|
||||
resp, err := source.ListCluster(ctx, project, location, string(accessToken))
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
|
||||
resp, err := source.ListInstance(ctx, project, location, cluster, string(accessToken))
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
|
||||
resp, err := source.ListUsers(ctx, project, location, cluster, string(accessToken))
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -253,7 +253,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
|
||||
op, err := source.GetOperations(ctx, project, location, operation, alloyDBConnectionMessageTemplate, delay, string(accessToken))
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
if op != nil {
|
||||
return op, nil
|
||||
|
||||
@@ -218,7 +218,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
}
|
||||
dryRunJob, err := bqutil.DryRunQuery(ctx, restService, source.BigQueryClient().Project(), source.BigQueryClient().Location, inputData, nil, connProps)
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
statementType := dryRunJob.Statistics.Query.StatementType
|
||||
if statementType != "SELECT" {
|
||||
@@ -283,15 +283,15 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
}
|
||||
createModelJob, err := createModelQuery.Run(ctx)
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
|
||||
status, err := createModelJob.Wait(ctx)
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
if err := status.Err(); err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
|
||||
// Determine the session ID to use for subsequent queries.
|
||||
@@ -310,7 +310,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
|
||||
resp, err := source.RunSQL(ctx, bqClient, getInsightsSQL, "SELECT", nil, connProps)
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -195,7 +195,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
}
|
||||
dryRunJob, err := bqutil.DryRunQuery(ctx, restService, source.BigQueryClient().Project(), source.BigQueryClient().Location, historyData, nil, connProps)
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
statementType := dryRunJob.Statistics.Query.StatementType
|
||||
if statementType != "SELECT" {
|
||||
@@ -271,7 +271,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
|
||||
resp, err := source.RunSQL(ctx, bqClient, sql, "SELECT", nil, connProps)
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
|
||||
metadata, err := dsHandle.Metadata(ctx)
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
|
||||
return metadata, nil
|
||||
|
||||
@@ -163,7 +163,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
|
||||
metadata, err := tableHandle.Metadata(ctx)
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
|
||||
return metadata, nil
|
||||
|
||||
@@ -151,7 +151,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
|
||||
// Remove leading and trailing quotes
|
||||
|
||||
@@ -161,7 +161,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
|
||||
// Remove leading and trailing quotes
|
||||
|
||||
@@ -248,7 +248,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
entrySource := entry.DataplexEntry.GetEntrySource()
|
||||
resp := Response{
|
||||
|
||||
@@ -206,13 +206,13 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
|
||||
dryRunJob, err := bqutil.DryRunQuery(ctx, restService, bqClient.Project(), bqClient.Location, newStatement, lowLevelParams, connProps)
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
|
||||
statementType := dryRunJob.Statistics.Query.StatementType
|
||||
resp, err := source.RunSQL(ctx, bqClient, newStatement, statementType, highLevelParams, connProps)
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
|
||||
resp, err := source.RunSQL(ctx, newStatement, t.Parameters, newParams)
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -160,7 +160,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
|
||||
resp, err := source.RunQuery(ctx, tokenStr, bodyBytes)
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
resp, err := source.FHIRFetchPage(ctx, url, tokenStr)
|
||||
if err != nil {
|
||||
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -168,7 +168,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
|
||||
resp, err := source.FHIRPatientEverything(storeID, patientID, tokenStr, opts)
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -239,7 +239,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
}
|
||||
resp, err := source.FHIRPatientSearch(storeID, tokenStr, opts)
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
}
|
||||
resp, err := source.GetDataset(tokenStr)
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
}
|
||||
resp, err := source.GetDICOMStore(storeID, tokenStr)
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
}
|
||||
resp, err := source.GetDICOMStoreMetrics(storeID, tokenStr)
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
}
|
||||
resp, err := source.GetFHIRResource(storeID, resType, resID, tokenStr)
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
}
|
||||
resp, err := source.GetFHIRStore(storeID, tokenStr)
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
}
|
||||
resp, err := source.GetFHIRStoreMetrics(storeID, tokenStr)
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
}
|
||||
resp, err := source.ListDICOMStores(tokenStr)
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
}
|
||||
resp, err := source.ListFHIRStores(tokenStr)
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -154,7 +154,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
}
|
||||
resp, err := source.RetrieveRenderedDICOMInstance(storeID, study, series, sop, frame, tokenStr)
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -180,7 +180,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
}
|
||||
resp, err := source.SearchDICOM(t.Type, storeID, dicomWebPath, tokenStr, opts)
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
}
|
||||
resp, err := source.SearchDICOM(t.Type, storeID, dicomWebPath, tokenStr, opts)
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -149,7 +149,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
dicomWebPath := "studies"
|
||||
resp, err := source.SearchDICOM(t.Type, storeID, dicomWebPath, tokenStr, opts)
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
|
||||
resp, err := source.ListLogNames(ctx, limit, tokenString)
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
|
||||
resp, err := source.ListResourceTypes(ctx, tokenString)
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -175,7 +175,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
|
||||
resp, err := source.QueryLogs(ctx, queryParams, tokenString)
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
}
|
||||
resp, err := source.RunQuery(projectID, query)
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
|
||||
resp, err := source.CloneInstance(ctx, project, sourceInstanceName, destinationInstanceName, pointInTime, preferredZone, preferredSecondaryZone, string(accessToken))
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
|
||||
resp, err := source.InsertBackupRun(ctx, project, instance, location, description, string(accessToken))
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
}
|
||||
resp, err := source.CreateDatabase(ctx, name, project, instance, string(accessToken))
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -146,7 +146,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
password, _ := paramsMap["password"].(string)
|
||||
resp, err := source.CreateUsers(ctx, project, instance, name, password, iamUser, string(accessToken))
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
}
|
||||
resp, err := source.GetInstance(ctx, projectId, instanceId, string(accessToken))
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
}
|
||||
resp, err := source.ListDatabase(ctx, project, instance, string(accessToken))
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
}
|
||||
resp, err := source.ListInstance(ctx, project, string(accessToken))
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -146,7 +146,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
|
||||
resp, err := source.RestoreBackup(ctx, targetProject, targetInstance, sourceProject, sourceInstance, backupID, string(accessToken))
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -234,7 +234,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
|
||||
service, err := source.GetService(ctx, string(accessToken))
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
|
||||
delay := t.Delay
|
||||
@@ -252,7 +252,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
|
||||
op, err := source.GetWaitForOperations(ctx, service, project, operationID, cloudSQLConnectionMessageTemplate, delay)
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
} else if op != nil {
|
||||
return op, nil
|
||||
}
|
||||
|
||||
@@ -170,7 +170,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
}
|
||||
resp, err := source.CreateInstance(ctx, project, name, dbVersion, rootPassword, settings, string(accessToken))
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
|
||||
resp, err := source.CreateInstance(ctx, project, name, dbVersion, rootPassword, settings, string(accessToken))
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
}
|
||||
resp, err := source.CreateInstance(ctx, project, name, dbVersion, rootPassword, settings, string(accessToken))
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
|
||||
service, err := source.GetService(ctx, string(accessToken))
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
|
||||
reqBody := &sqladmin.InstancesPreCheckMajorVersionUpgradeRequest{
|
||||
@@ -170,7 +170,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
call := service.Instances.PreCheckMajorVersionUpgrade(project, instanceName, reqBody).Context(ctx)
|
||||
op, err := call.Do()
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
|
||||
const pollTimeout = 20 * time.Second
|
||||
@@ -179,7 +179,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
for time.Now().Before(cutoffTime) {
|
||||
currentOp, err := service.Operations.Get(project, op.Name).Context(ctx).Do()
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
|
||||
if currentOp.Status == "DONE" {
|
||||
|
||||
@@ -129,7 +129,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
aspectTypes := aspectTypeSlice.([]string)
|
||||
resp, err := source.LookupEntry(ctx, name, view, aspectTypes, entry)
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
}
|
||||
resp, err := source.SearchAspectTypes(ctx, query, pageSize, orderBy)
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
}
|
||||
resp, err := source.SearchEntries(ctx, query, pageSize, orderBy)
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
}
|
||||
resp, err := source.AddDocuments(ctx, collectionPath, documentData, returnData)
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
}
|
||||
resp, err := source.DeleteDocuments(ctx, documentPaths)
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
}
|
||||
resp, err := source.GetDocuments(ctx, documentPaths)
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
}
|
||||
resp, err := source.GetRules(ctx)
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
}
|
||||
resp, err := source.ListCollections(ctx, parentPath)
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -217,12 +217,12 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
// Build the query
|
||||
query, err := source.BuildQuery(collectionPath, filter, selectFields, orderByField, orderByDirection, limit, t.AnalyzeQuery)
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
// Execute the query and return results
|
||||
resp, err := source.ExecuteQuery(ctx, query, t.AnalyzeQuery)
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -272,11 +272,11 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
// Build the query
|
||||
query, err := source.BuildQuery(queryParams.CollectionPath, filter, nil, orderByField, orderByDirection, queryParams.Limit, queryParams.AnalyzeQuery)
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
resp, err := source.ExecuteQuery(ctx, query, queryParams.AnalyzeQuery)
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -225,7 +225,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
}
|
||||
resp, err := source.UpdateDocument(ctx, documentPath, updates, documentData, returnData)
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
}
|
||||
resp, err := source.ValidateRules(ctx, sourceParam)
|
||||
if err != nil {
|
||||
return nil, util.ProecessGcpError(err)
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -343,6 +343,13 @@ func (t *analyzeTool) models(ctx context.Context, project, model string) ([]map[
|
||||
exploreCount = len(*m.Explores)
|
||||
}
|
||||
|
||||
if m.ProjectName == nil {
|
||||
return nil, util.NewAgentError("model project name is nil", nil)
|
||||
}
|
||||
if m.Name == nil {
|
||||
return nil, util.NewAgentError("model name is nil", nil)
|
||||
}
|
||||
|
||||
results = append(results, map[string]interface{}{
|
||||
"Project": *m.ProjectName,
|
||||
"Model": *m.Name,
|
||||
@@ -354,7 +361,7 @@ func (t *analyzeTool) models(ctx context.Context, project, model string) ([]map[
|
||||
return results, nil
|
||||
}
|
||||
|
||||
func (t *analyzeTool) getUsedModels(ctx context.Context) (map[string]int, error) {
|
||||
func (t *analyzeTool) getUsedModels(ctx context.Context) (map[string]int, util.ToolboxError) {
|
||||
limit := "5000"
|
||||
query := &v4.WriteQuery{
|
||||
Model: "system__activity",
|
||||
@@ -370,22 +377,30 @@ func (t *analyzeTool) getUsedModels(ctx context.Context) (map[string]int, error)
|
||||
}
|
||||
raw, err := lookercommon.RunInlineQuery(ctx, t.SdkClient, query, "json", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, util.NewClientServerError(fmt.Sprintf("error running inline query for used models: %v", err), http.StatusInternalServerError, err)
|
||||
}
|
||||
|
||||
var data []map[string]interface{}
|
||||
_ = json.Unmarshal([]byte(raw), &data)
|
||||
if err := json.Unmarshal([]byte(raw), &data); err != nil {
|
||||
return nil, util.NewClientServerError(fmt.Sprintf("error unmarshaling used models data: %v", err), http.StatusInternalServerError, err)
|
||||
}
|
||||
|
||||
results := make(map[string]int)
|
||||
for _, row := range data {
|
||||
model, _ := row["query.model"].(string)
|
||||
count, _ := row["history.query_run_count"].(float64)
|
||||
model, ok := row["query.model"].(string)
|
||||
if !ok {
|
||||
return nil, util.NewAgentError("error casting 'query.model' in used models data", nil)
|
||||
}
|
||||
count, ok := row["history.query_run_count"].(float64)
|
||||
if !ok {
|
||||
return nil, util.NewAgentError("error casting 'history.query_run_count' in used models data", nil)
|
||||
}
|
||||
results[model] = int(count)
|
||||
}
|
||||
return results, nil
|
||||
}
|
||||
|
||||
func (t *analyzeTool) getUsedExploreFields(ctx context.Context, model, explore string) (map[string]int, error) {
|
||||
func (t *analyzeTool) getUsedExploreFields(ctx context.Context, model, explore string) (map[string]int, util.ToolboxError) {
|
||||
limit := "5000"
|
||||
query := &v4.WriteQuery{
|
||||
Model: "system__activity",
|
||||
@@ -402,19 +417,30 @@ func (t *analyzeTool) getUsedExploreFields(ctx context.Context, model, explore s
|
||||
}
|
||||
raw, err := lookercommon.RunInlineQuery(ctx, t.SdkClient, query, "json", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, util.NewClientServerError(fmt.Sprintf("error running inline query for used explore fields: %v", err), http.StatusInternalServerError, err)
|
||||
}
|
||||
|
||||
var data []map[string]interface{}
|
||||
_ = json.Unmarshal([]byte(raw), &data)
|
||||
if err := json.Unmarshal([]byte(raw), &data); err != nil {
|
||||
return nil, util.NewClientServerError(fmt.Sprintf("error unmarshaling used explore fields data: %v", err), http.StatusInternalServerError, err)
|
||||
}
|
||||
|
||||
results := make(map[string]int)
|
||||
fieldRegex := regexp.MustCompile(`(\w+\.\w+)`)
|
||||
|
||||
for _, row := range data {
|
||||
count, _ := row["history.query_run_count"].(float64)
|
||||
formattedFields, _ := row["query.formatted_fields"].(string)
|
||||
filters, _ := row["query.filters"].(string)
|
||||
count, ok := row["history.query_run_count"].(float64)
|
||||
if !ok {
|
||||
return nil, util.NewAgentError("error casting 'history.query_run_count' in used explore fields data", nil)
|
||||
}
|
||||
formattedFields, ok := row["query.formatted_fields"].(string)
|
||||
if !ok {
|
||||
return nil, util.NewAgentError("error casting 'query.formatted_fields' in used explore fields data", nil)
|
||||
}
|
||||
filters, ok := row["query.filters"].(string)
|
||||
if !ok {
|
||||
return nil, util.NewAgentError("error casting 'query.filters' in used explore fields data", nil)
|
||||
}
|
||||
|
||||
usedFields := make(map[string]bool)
|
||||
|
||||
@@ -432,21 +458,24 @@ func (t *analyzeTool) getUsedExploreFields(ctx context.Context, model, explore s
|
||||
return results, nil
|
||||
}
|
||||
|
||||
func (t *analyzeTool) explores(ctx context.Context, model, explore string) ([]map[string]interface{}, error) {
|
||||
func (t *analyzeTool) explores(ctx context.Context, model, explore string) ([]map[string]interface{}, util.ToolboxError) {
|
||||
logger, err := util.LoggerFromContext(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to get logger from ctx: %s", err)
|
||||
return nil, util.NewClientServerError("unable to get logger from ctx", http.StatusInternalServerError, err)
|
||||
}
|
||||
logger.InfoContext(ctx, "Analyzing explores...")
|
||||
|
||||
lookmlModels, err := t.SdkClient.AllLookmlModels(v4.RequestAllLookmlModels{}, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error fetching LookML models: %w", err)
|
||||
return nil, util.NewClientServerError(fmt.Sprintf("error fetching LookML models: %v", err), http.StatusInternalServerError, err)
|
||||
}
|
||||
|
||||
var results []map[string]interface{}
|
||||
for _, m := range lookmlModels {
|
||||
if model != "" && (m.Name == nil || *m.Name != model) {
|
||||
if m.Name == nil {
|
||||
return nil, util.NewAgentError("model name is nil", nil)
|
||||
}
|
||||
if model != "" && *m.Name != model {
|
||||
continue
|
||||
}
|
||||
if m.Explores == nil {
|
||||
@@ -454,10 +483,10 @@ func (t *analyzeTool) explores(ctx context.Context, model, explore string) ([]ma
|
||||
}
|
||||
|
||||
for _, e := range *m.Explores {
|
||||
if explore != "" && (e.Name == nil || *e.Name != explore) {
|
||||
continue
|
||||
}
|
||||
if e.Name == nil {
|
||||
return nil, util.NewAgentError("explore name is nil", nil)
|
||||
}
|
||||
if explore != "" && *e.Name != explore {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -475,6 +504,12 @@ func (t *analyzeTool) explores(ctx context.Context, model, explore string) ([]ma
|
||||
|
||||
fieldCount := 0
|
||||
if exploreDetail.Fields != nil {
|
||||
if exploreDetail.Fields.Dimensions == nil {
|
||||
return nil, util.NewAgentError("explore dimensions are nil", nil)
|
||||
}
|
||||
if exploreDetail.Fields.Measures == nil {
|
||||
return nil, util.NewAgentError("explore measures are nil", nil)
|
||||
}
|
||||
fieldCount = len(*exploreDetail.Fields.Dimensions) + len(*exploreDetail.Fields.Measures)
|
||||
}
|
||||
|
||||
@@ -491,12 +526,30 @@ func (t *analyzeTool) explores(ctx context.Context, model, explore string) ([]ma
|
||||
|
||||
allFields := []string{}
|
||||
if exploreDetail.Fields != nil {
|
||||
if exploreDetail.Fields.Dimensions == nil {
|
||||
return nil, util.NewAgentError("explore dimensions are nil", nil)
|
||||
}
|
||||
for _, d := range *exploreDetail.Fields.Dimensions {
|
||||
if d.Hidden == nil {
|
||||
return nil, util.NewAgentError("dimension hidden status is nil", nil)
|
||||
}
|
||||
if d.Name == nil {
|
||||
return nil, util.NewAgentError("dimension name is nil", nil)
|
||||
}
|
||||
if !*d.Hidden {
|
||||
allFields = append(allFields, *d.Name)
|
||||
}
|
||||
}
|
||||
if exploreDetail.Fields.Measures == nil {
|
||||
return nil, util.NewAgentError("explore measures are nil", nil)
|
||||
}
|
||||
for _, ms := range *exploreDetail.Fields.Measures {
|
||||
if ms.Hidden == nil {
|
||||
return nil, util.NewAgentError("measure hidden status is nil", nil)
|
||||
}
|
||||
if ms.Name == nil {
|
||||
return nil, util.NewAgentError("measure name is nil", nil)
|
||||
}
|
||||
if !*ms.Hidden {
|
||||
allFields = append(allFields, *ms.Name)
|
||||
}
|
||||
@@ -517,6 +570,9 @@ func (t *analyzeTool) explores(ctx context.Context, model, explore string) ([]ma
|
||||
joinStats[join] += queryCount
|
||||
}
|
||||
for _, join := range *exploreDetail.Joins {
|
||||
if join.Name == nil {
|
||||
return nil, util.NewAgentError("join name is nil", nil)
|
||||
}
|
||||
if _, ok := joinStats[*join.Name]; !ok {
|
||||
joinStats[*join.Name] = 0
|
||||
}
|
||||
@@ -548,22 +604,32 @@ func (t *analyzeTool) explores(ctx context.Context, model, explore string) ([]ma
|
||||
|
||||
rawQueryCount, err := lookercommon.RunInlineQuery(ctx, t.SdkClient, queryCountQueryBody, "json", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, util.NewClientServerError(fmt.Sprintf("error running inline query for query count: %v", err), http.StatusInternalServerError, err)
|
||||
}
|
||||
queryCount := 0
|
||||
var data []map[string]interface{}
|
||||
_ = json.Unmarshal([]byte(rawQueryCount), &data)
|
||||
if err := json.Unmarshal([]byte(rawQueryCount), &data); err != nil {
|
||||
return nil, util.NewClientServerError(fmt.Sprintf("error unmarshaling query count data: %v", err), http.StatusInternalServerError, err)
|
||||
}
|
||||
if len(data) > 0 {
|
||||
if count, ok := data[0]["history.query_run_count"].(float64); ok {
|
||||
queryCount = int(count)
|
||||
} else {
|
||||
return nil, util.NewAgentError("error casting 'history.query_run_count' in query count data", nil)
|
||||
}
|
||||
}
|
||||
if e.Hidden == nil {
|
||||
return nil, util.NewAgentError("explore hidden status is nil", nil)
|
||||
}
|
||||
if e.Description == nil {
|
||||
return nil, util.NewAgentError("explore description is nil", nil)
|
||||
}
|
||||
|
||||
results = append(results, map[string]interface{}{
|
||||
"Model": *m.Name,
|
||||
"Explore": *e.Name,
|
||||
"Is Hidden": *e.Hidden,
|
||||
"Has Description": e.Description != nil && *e.Description != "",
|
||||
"Has Description": *e.Description != "",
|
||||
"# Joins": joinCount,
|
||||
"# Unused Joins": unusedJoinsCount,
|
||||
"# Unused Fields": unusedFieldsCount,
|
||||
|
||||
@@ -17,11 +17,13 @@ package createbatch
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
dataprocpb "cloud.google.com/go/dataproc/v2/apiv1/dataprocpb"
|
||||
"github.com/googleapis/genai-toolbox/internal/embeddingmodels"
|
||||
"github.com/googleapis/genai-toolbox/internal/sources"
|
||||
"github.com/googleapis/genai-toolbox/internal/tools"
|
||||
"github.com/googleapis/genai-toolbox/internal/util"
|
||||
"github.com/googleapis/genai-toolbox/internal/util/parameters"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
@@ -65,15 +67,18 @@ type Tool struct {
|
||||
Parameters parameters.Parameters
|
||||
}
|
||||
|
||||
func (t *Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, params parameters.ParamValues, accessToken tools.AccessToken) (any, error) {
|
||||
func (t *Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, params parameters.ParamValues, accessToken tools.AccessToken) (any, util.ToolboxError) {
|
||||
source, err := tools.GetCompatibleSource[compatibleSource](resourceMgr, t.Source, t.Name, t.Type)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, util.NewClientServerError("source used is not compatible with the tool", http.StatusInternalServerError, err)
|
||||
}
|
||||
|
||||
batch, err := t.Builder.BuildBatch(params)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to build batch: %w", err)
|
||||
if tbErr, ok := err.(util.ToolboxError); ok {
|
||||
return nil, tbErr
|
||||
}
|
||||
return nil, util.NewAgentError("failed to build batch", err)
|
||||
}
|
||||
|
||||
if t.RuntimeConfig != nil {
|
||||
@@ -92,11 +97,20 @@ func (t *Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, par
|
||||
}
|
||||
batch.RuntimeConfig.Version = version
|
||||
}
|
||||
return source.CreateBatch(ctx, batch)
|
||||
|
||||
resp, err := source.CreateBatch(ctx, batch)
|
||||
if err != nil {
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (t Tool) EmbedParams(ctx context.Context, paramValues parameters.ParamValues, embeddingModelsMap map[string]embeddingmodels.EmbeddingModel) (parameters.ParamValues, error) {
|
||||
return parameters.EmbedParams(ctx, t.Parameters, paramValues, embeddingModelsMap, nil)
|
||||
newParamValues, err := parameters.EmbedParams(ctx, t.Parameters, paramValues, embeddingModelsMap, nil)
|
||||
if err != nil {
|
||||
return nil, util.NewClientServerError(fmt.Sprintf("error embedding parameters: %v", err), http.StatusInternalServerError, err)
|
||||
}
|
||||
return newParamValues, nil
|
||||
}
|
||||
|
||||
func (t *Tool) Manifest() tools.Manifest {
|
||||
|
||||
@@ -17,6 +17,7 @@ package serverlesssparkcancelbatch
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
dataproc "cloud.google.com/go/dataproc/v2/apiv1"
|
||||
@@ -24,6 +25,7 @@ import (
|
||||
"github.com/googleapis/genai-toolbox/internal/embeddingmodels"
|
||||
"github.com/googleapis/genai-toolbox/internal/sources"
|
||||
"github.com/googleapis/genai-toolbox/internal/tools"
|
||||
"github.com/googleapis/genai-toolbox/internal/util"
|
||||
"github.com/googleapis/genai-toolbox/internal/util/parameters"
|
||||
)
|
||||
|
||||
@@ -99,20 +101,26 @@ type Tool struct {
|
||||
}
|
||||
|
||||
// Invoke executes the tool's operation.
|
||||
func (t *Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, params parameters.ParamValues, accessToken tools.AccessToken) (any, error) {
|
||||
func (t *Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, params parameters.ParamValues, accessToken tools.AccessToken) (any, util.ToolboxError) {
|
||||
source, err := tools.GetCompatibleSource[compatibleSource](resourceMgr, t.Source, t.Name, t.Type)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, util.NewClientServerError("source used is not compatible with the tool", http.StatusInternalServerError, err)
|
||||
}
|
||||
|
||||
paramMap := params.AsMap()
|
||||
operation, ok := paramMap["operation"].(string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("missing required parameter: operation")
|
||||
return nil, util.NewAgentError("missing required parameter: operation", nil)
|
||||
}
|
||||
if strings.Contains(operation, "/") {
|
||||
return nil, fmt.Errorf("operation must be a short operation name without '/': %s", operation)
|
||||
return nil, util.NewAgentError(fmt.Sprintf("operation must be a short operation name without '/': %s", operation), nil)
|
||||
}
|
||||
return source.CancelOperation(ctx, operation)
|
||||
|
||||
resp, err := source.CancelOperation(ctx, operation)
|
||||
if err != nil {
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (t Tool) EmbedParams(ctx context.Context, paramValues parameters.ParamValues, embeddingModelsMap map[string]embeddingmodels.EmbeddingModel) (parameters.ParamValues, error) {
|
||||
|
||||
@@ -17,6 +17,7 @@ package serverlesssparkgetbatch
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
dataproc "cloud.google.com/go/dataproc/v2/apiv1"
|
||||
@@ -24,6 +25,7 @@ import (
|
||||
"github.com/googleapis/genai-toolbox/internal/embeddingmodels"
|
||||
"github.com/googleapis/genai-toolbox/internal/sources"
|
||||
"github.com/googleapis/genai-toolbox/internal/tools"
|
||||
"github.com/googleapis/genai-toolbox/internal/util"
|
||||
"github.com/googleapis/genai-toolbox/internal/util/parameters"
|
||||
)
|
||||
|
||||
@@ -99,20 +101,25 @@ type Tool struct {
|
||||
}
|
||||
|
||||
// Invoke executes the tool's operation.
|
||||
func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, params parameters.ParamValues, accessToken tools.AccessToken) (any, error) {
|
||||
func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, params parameters.ParamValues, accessToken tools.AccessToken) (any, util.ToolboxError) {
|
||||
source, err := tools.GetCompatibleSource[compatibleSource](resourceMgr, t.Source, t.Name, t.Type)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, util.NewClientServerError("source used is not compatible with the tool", http.StatusInternalServerError, err)
|
||||
}
|
||||
paramMap := params.AsMap()
|
||||
name, ok := paramMap["name"].(string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("missing required parameter: name")
|
||||
return nil, util.NewAgentError("missing required parameter: name", nil)
|
||||
}
|
||||
if strings.Contains(name, "/") {
|
||||
return nil, fmt.Errorf("name must be a short batch name without '/': %s", name)
|
||||
return nil, util.NewAgentError(fmt.Sprintf("name must be a short batch name without '/': %s", name), nil)
|
||||
}
|
||||
return source.GetBatch(ctx, name)
|
||||
|
||||
resp, err := source.GetBatch(ctx, name)
|
||||
if err != nil {
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (t Tool) EmbedParams(ctx context.Context, paramValues parameters.ParamValues, embeddingModelsMap map[string]embeddingmodels.EmbeddingModel) (parameters.ParamValues, error) {
|
||||
|
||||
@@ -17,12 +17,14 @@ package serverlesssparklistbatches
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
dataproc "cloud.google.com/go/dataproc/v2/apiv1"
|
||||
"github.com/goccy/go-yaml"
|
||||
"github.com/googleapis/genai-toolbox/internal/embeddingmodels"
|
||||
"github.com/googleapis/genai-toolbox/internal/sources"
|
||||
"github.com/googleapis/genai-toolbox/internal/tools"
|
||||
"github.com/googleapis/genai-toolbox/internal/util"
|
||||
"github.com/googleapis/genai-toolbox/internal/util/parameters"
|
||||
)
|
||||
|
||||
@@ -100,23 +102,39 @@ type Tool struct {
|
||||
}
|
||||
|
||||
// Invoke executes the tool's operation.
|
||||
func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, params parameters.ParamValues, accessToken tools.AccessToken) (any, error) {
|
||||
func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, params parameters.ParamValues, accessToken tools.AccessToken) (any, util.ToolboxError) {
|
||||
source, err := tools.GetCompatibleSource[compatibleSource](resourceMgr, t.Source, t.Name, t.Type)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, util.NewClientServerError("source used is not compatible with the tool", http.StatusInternalServerError, err)
|
||||
}
|
||||
|
||||
paramMap := params.AsMap()
|
||||
var pageSize *int
|
||||
if ps, ok := paramMap["pageSize"]; ok && ps != nil {
|
||||
pageSizeV := ps.(int)
|
||||
pageSizeV, ok := ps.(int)
|
||||
if !ok {
|
||||
// Handle float64 case if unmarshaled from JSON usually
|
||||
if f, ok := ps.(float64); ok {
|
||||
pageSizeV = int(f)
|
||||
} else {
|
||||
return nil, util.NewAgentError("pageSize must be an integer", nil)
|
||||
}
|
||||
}
|
||||
|
||||
if pageSizeV <= 0 {
|
||||
return nil, fmt.Errorf("pageSize must be positive: %d", pageSizeV)
|
||||
return nil, util.NewAgentError(fmt.Sprintf("pageSize must be positive: %d", pageSizeV), nil)
|
||||
}
|
||||
pageSize = &pageSizeV
|
||||
}
|
||||
|
||||
pt, _ := paramMap["pageToken"].(string)
|
||||
filter, _ := paramMap["filter"].(string)
|
||||
return source.ListBatches(ctx, pageSize, pt, filter)
|
||||
|
||||
resp, err := source.ListBatches(ctx, pageSize, pt, filter)
|
||||
if err != nil {
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (t Tool) EmbedParams(ctx context.Context, paramValues parameters.ParamValues, embeddingModelsMap map[string]embeddingmodels.EmbeddingModel) (parameters.ParamValues, error) {
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
yaml "github.com/goccy/go-yaml"
|
||||
"github.com/googleapis/genai-toolbox/internal/embeddingmodels"
|
||||
@@ -98,25 +99,30 @@ func (t Tool) ToConfig() tools.ToolConfig {
|
||||
}
|
||||
|
||||
// Invoke executes the provided SQL query using the tool's database connection and returns the results.
|
||||
func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, params parameters.ParamValues, accessToken tools.AccessToken) (any, error) {
|
||||
func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, params parameters.ParamValues, accessToken tools.AccessToken) (any, util.ToolboxError) {
|
||||
source, err := tools.GetCompatibleSource[compatibleSource](resourceMgr, t.Source, t.Name, t.Type)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, util.NewClientServerError("source used is not compatible with the tool", http.StatusInternalServerError, err)
|
||||
}
|
||||
|
||||
paramsMap := params.AsMap()
|
||||
sql, ok := paramsMap["sql"].(string)
|
||||
sqlStr, ok := paramsMap["sql"].(string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unable to get cast %s", paramsMap["sql"])
|
||||
return nil, util.NewAgentError(fmt.Sprintf("unable to cast parameter 'sql' to string: %v", paramsMap["sql"]), nil)
|
||||
}
|
||||
|
||||
// Log the query executed for debugging.
|
||||
logger, err := util.LoggerFromContext(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error getting logger: %s", err)
|
||||
return nil, util.NewClientServerError("error getting logger", http.StatusInternalServerError, err)
|
||||
}
|
||||
logger.DebugContext(ctx, "executing `%s` tool query: %s", resourceType, sql)
|
||||
return source.RunSQL(ctx, sql, nil)
|
||||
logger.DebugContext(ctx, fmt.Sprintf("executing `%s` tool query: %s", resourceType, sqlStr))
|
||||
|
||||
resp, err := source.RunSQL(ctx, sqlStr, nil)
|
||||
if err != nil {
|
||||
return nil, util.ProcessGeneralError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (t Tool) EmbedParams(ctx context.Context, paramValues parameters.ParamValues, embeddingModelsMap map[string]embeddingmodels.EmbeddingModel) (parameters.ParamValues, error) {
|
||||
|
||||
@@ -18,11 +18,13 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
yaml "github.com/goccy/go-yaml"
|
||||
"github.com/googleapis/genai-toolbox/internal/embeddingmodels"
|
||||
"github.com/googleapis/genai-toolbox/internal/sources"
|
||||
"github.com/googleapis/genai-toolbox/internal/tools"
|
||||
"github.com/googleapis/genai-toolbox/internal/util"
|
||||
"github.com/googleapis/genai-toolbox/internal/util/parameters"
|
||||
)
|
||||
|
||||
@@ -126,25 +128,29 @@ func (t Tool) ToConfig() tools.ToolConfig {
|
||||
// Returns:
|
||||
// - A slice of maps, where each map represents a row with column names as keys.
|
||||
// - An error if template resolution, parameter extraction, query execution, or result processing fails.
|
||||
func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, params parameters.ParamValues, accessToken tools.AccessToken) (any, error) {
|
||||
func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, params parameters.ParamValues, accessToken tools.AccessToken) (any, util.ToolboxError) {
|
||||
source, err := tools.GetCompatibleSource[compatibleSource](resourceMgr, t.Source, t.Name, t.Type)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, util.NewClientServerError("source used is not compatible with the tool", http.StatusInternalServerError, err)
|
||||
}
|
||||
|
||||
paramsMap := params.AsMap()
|
||||
newStatement, err := parameters.ResolveTemplateParams(t.TemplateParameters, t.Statement, paramsMap)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to extract template params %w", err)
|
||||
return nil, util.NewAgentError("unable to extract template params", err)
|
||||
}
|
||||
|
||||
newParams, err := parameters.GetParams(t.Parameters, paramsMap)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to extract standard params %w", err)
|
||||
return nil, util.NewAgentError("unable to extract standard params", err)
|
||||
}
|
||||
|
||||
sliceParams := newParams.AsSlice()
|
||||
return source.RunSQL(ctx, newStatement, sliceParams)
|
||||
resp, err := source.RunSQL(ctx, newStatement, sliceParams)
|
||||
if err != nil {
|
||||
return nil, util.ProcessGeneralError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (t Tool) EmbedParams(ctx context.Context, paramValues parameters.ParamValues, embeddingModelsMap map[string]embeddingmodels.EmbeddingModel) (parameters.ParamValues, error) {
|
||||
|
||||
@@ -17,6 +17,7 @@ package snowflakeexecutesql
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
yaml "github.com/goccy/go-yaml"
|
||||
"github.com/googleapis/genai-toolbox/internal/embeddingmodels"
|
||||
@@ -89,26 +90,30 @@ type Tool struct {
|
||||
mcpManifest tools.McpManifest
|
||||
}
|
||||
|
||||
func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, params parameters.ParamValues, accessToken tools.AccessToken) (any, error) {
|
||||
func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, params parameters.ParamValues, accessToken tools.AccessToken) (any, util.ToolboxError) {
|
||||
source, err := tools.GetCompatibleSource[compatibleSource](resourceMgr, t.Source, t.Name, t.Type)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, util.NewClientServerError("source used is not compatible with the tool", http.StatusInternalServerError, err)
|
||||
}
|
||||
|
||||
mapParams := params.AsMap()
|
||||
sql, ok := mapParams["sql"].(string)
|
||||
sqlStr, ok := mapParams["sql"].(string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("invalid parameters: sql parameter is not a string")
|
||||
return nil, util.NewAgentError("invalid parameters: sql parameter is not a string", nil)
|
||||
}
|
||||
|
||||
// Log the query executed for debugging.
|
||||
logger, err := util.LoggerFromContext(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error getting logger: %s", err)
|
||||
return nil, util.NewClientServerError("error getting logger", http.StatusInternalServerError, err)
|
||||
}
|
||||
logger.DebugContext(ctx, fmt.Sprintf("executing `%s` tool query: %s", resourceType, sql))
|
||||
return source.RunSQL(ctx, sql, nil)
|
||||
logger.DebugContext(ctx, fmt.Sprintf("executing `%s` tool query: %s", resourceType, sqlStr))
|
||||
|
||||
resp, err := source.RunSQL(ctx, sqlStr, nil)
|
||||
if err != nil {
|
||||
return nil, util.ProcessGeneralError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (t Tool) EmbedParams(ctx context.Context, paramValues parameters.ParamValues, embeddingModelsMap map[string]embeddingmodels.EmbeddingModel) (parameters.ParamValues, error) {
|
||||
|
||||
@@ -17,11 +17,13 @@ package snowflakesql
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
yaml "github.com/goccy/go-yaml"
|
||||
"github.com/googleapis/genai-toolbox/internal/embeddingmodels"
|
||||
"github.com/googleapis/genai-toolbox/internal/sources"
|
||||
"github.com/googleapis/genai-toolbox/internal/tools"
|
||||
"github.com/googleapis/genai-toolbox/internal/util"
|
||||
"github.com/googleapis/genai-toolbox/internal/util/parameters"
|
||||
"github.com/jmoiron/sqlx"
|
||||
)
|
||||
@@ -93,25 +95,29 @@ type Tool struct {
|
||||
mcpManifest tools.McpManifest
|
||||
}
|
||||
|
||||
func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, params parameters.ParamValues, accessToken tools.AccessToken) (any, error) {
|
||||
func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, params parameters.ParamValues, accessToken tools.AccessToken) (any, util.ToolboxError) {
|
||||
source, err := tools.GetCompatibleSource[compatibleSource](resourceMgr, t.Source, t.Name, t.Type)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, util.NewClientServerError("source used is not compatible with the tool", http.StatusInternalServerError, err)
|
||||
}
|
||||
|
||||
paramsMap := params.AsMap()
|
||||
newStatement, err := parameters.ResolveTemplateParams(t.TemplateParameters, t.Statement, paramsMap)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to extract template params %w", err)
|
||||
return nil, util.NewAgentError("unable to extract template params", err)
|
||||
}
|
||||
|
||||
newParams, err := parameters.GetParams(t.Parameters, paramsMap)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to extract standard params %w", err)
|
||||
return nil, util.NewAgentError("unable to extract standard params", err)
|
||||
}
|
||||
|
||||
sliceParams := newParams.AsSlice()
|
||||
return source.RunSQL(ctx, newStatement, sliceParams)
|
||||
resp, err := source.RunSQL(ctx, newStatement, sliceParams)
|
||||
if err != nil {
|
||||
return nil, util.ProcessGeneralError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (t Tool) EmbedParams(ctx context.Context, paramValues parameters.ParamValues, embeddingModelsMap map[string]embeddingmodels.EmbeddingModel) (parameters.ParamValues, error) {
|
||||
|
||||
@@ -17,6 +17,7 @@ package spannerexecutesql
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"cloud.google.com/go/spanner"
|
||||
yaml "github.com/goccy/go-yaml"
|
||||
@@ -91,25 +92,29 @@ type Tool struct {
|
||||
mcpManifest tools.McpManifest
|
||||
}
|
||||
|
||||
func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, params parameters.ParamValues, accessToken tools.AccessToken) (any, error) {
|
||||
func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, params parameters.ParamValues, accessToken tools.AccessToken) (any, util.ToolboxError) {
|
||||
source, err := tools.GetCompatibleSource[compatibleSource](resourceMgr, t.Source, t.Name, t.Type)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, util.NewClientServerError("source used is not compatible with the tool", http.StatusInternalServerError, err)
|
||||
}
|
||||
|
||||
paramsMap := params.AsMap()
|
||||
sql, ok := paramsMap["sql"].(string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unable to get cast %s", paramsMap["sql"])
|
||||
return nil, util.NewAgentError(fmt.Sprintf("unable to get cast %s", paramsMap["sql"]), nil)
|
||||
}
|
||||
|
||||
// Log the query executed for debugging.
|
||||
logger, err := util.LoggerFromContext(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error getting logger: %s", err)
|
||||
return nil, util.NewClientServerError("error getting logger", http.StatusInternalServerError, err)
|
||||
}
|
||||
logger.DebugContext(ctx, fmt.Sprintf("executing `%s` tool query: %s", resourceType, sql))
|
||||
return source.RunSQL(ctx, t.ReadOnly, sql, nil)
|
||||
resp, err := source.RunSQL(ctx, t.ReadOnly, sql, nil)
|
||||
if err != nil {
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (t Tool) EmbedParams(ctx context.Context, paramValues parameters.ParamValues, embeddingModelsMap map[string]embeddingmodels.EmbeddingModel) (parameters.ParamValues, error) {
|
||||
|
||||
@@ -17,6 +17,7 @@ package spannerlistgraphs
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"cloud.google.com/go/spanner"
|
||||
@@ -24,6 +25,7 @@ import (
|
||||
"github.com/googleapis/genai-toolbox/internal/embeddingmodels"
|
||||
"github.com/googleapis/genai-toolbox/internal/sources"
|
||||
"github.com/googleapis/genai-toolbox/internal/tools"
|
||||
"github.com/googleapis/genai-toolbox/internal/util"
|
||||
"github.com/googleapis/genai-toolbox/internal/util/parameters"
|
||||
)
|
||||
|
||||
@@ -105,15 +107,15 @@ type Tool struct {
|
||||
mcpManifest tools.McpManifest
|
||||
}
|
||||
|
||||
func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, params parameters.ParamValues, accessToken tools.AccessToken) (any, error) {
|
||||
func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, params parameters.ParamValues, accessToken tools.AccessToken) (any, util.ToolboxError) {
|
||||
source, err := tools.GetCompatibleSource[compatibleSource](resourceMgr, t.Source, t.Name, t.Type)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, util.NewClientServerError("source used is not compatible with the tool", http.StatusInternalServerError, err)
|
||||
}
|
||||
|
||||
// Check dialect here at RUNTIME instead of startup
|
||||
if strings.ToLower(source.DatabaseDialect()) != "googlesql" {
|
||||
return nil, fmt.Errorf("operation not supported: The 'spanner-list-graphs' tool is only available for GoogleSQL dialect databases. Your current database dialect is '%s'", source.DatabaseDialect())
|
||||
return nil, util.NewAgentError(fmt.Sprintf("operation not supported: The 'spanner-list-graphs' tool is only available for GoogleSQL dialect databases. Your current database dialect is '%s'", source.DatabaseDialect()), nil)
|
||||
}
|
||||
|
||||
paramsMap := params.AsMap()
|
||||
@@ -128,7 +130,11 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
"graph_names": graphNames,
|
||||
"output_format": outputFormat,
|
||||
}
|
||||
return source.RunSQL(ctx, true, googleSQLStatement, stmtParams)
|
||||
resp, err := source.RunSQL(ctx, true, googleSQLStatement, stmtParams)
|
||||
if err != nil {
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (t Tool) EmbedParams(ctx context.Context, paramValues parameters.ParamValues, embeddingModelsMap map[string]embeddingmodels.EmbeddingModel) (parameters.ParamValues, error) {
|
||||
|
||||
@@ -17,6 +17,7 @@ package spannerlisttables
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"cloud.google.com/go/spanner"
|
||||
@@ -24,6 +25,7 @@ import (
|
||||
"github.com/googleapis/genai-toolbox/internal/embeddingmodels"
|
||||
"github.com/googleapis/genai-toolbox/internal/sources"
|
||||
"github.com/googleapis/genai-toolbox/internal/tools"
|
||||
"github.com/googleapis/genai-toolbox/internal/util"
|
||||
"github.com/googleapis/genai-toolbox/internal/util/parameters"
|
||||
)
|
||||
|
||||
@@ -117,10 +119,10 @@ func getStatement(dialect string) string {
|
||||
}
|
||||
}
|
||||
|
||||
func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, params parameters.ParamValues, accessToken tools.AccessToken) (any, error) {
|
||||
func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, params parameters.ParamValues, accessToken tools.AccessToken) (any, util.ToolboxError) {
|
||||
source, err := tools.GetCompatibleSource[compatibleSource](resourceMgr, t.Source, t.Name, t.Type)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, util.NewClientServerError("source used is not compatible with the tool", http.StatusInternalServerError, err)
|
||||
}
|
||||
|
||||
paramsMap := params.AsMap()
|
||||
@@ -131,8 +133,14 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
// Prepare parameters based on dialect
|
||||
var stmtParams map[string]interface{}
|
||||
|
||||
tableNames, _ := paramsMap["table_names"].(string)
|
||||
outputFormat, _ := paramsMap["output_format"].(string)
|
||||
tableNames, ok := paramsMap["table_names"].(string)
|
||||
if !ok {
|
||||
return nil, util.NewAgentError("unable to get cast table_names", nil)
|
||||
}
|
||||
outputFormat, ok := paramsMap["output_format"].(string)
|
||||
if !ok {
|
||||
return nil, util.NewAgentError("unable to get cast output_format", nil)
|
||||
}
|
||||
if outputFormat == "" {
|
||||
outputFormat = "detailed"
|
||||
}
|
||||
@@ -151,10 +159,14 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
"output_format": outputFormat,
|
||||
}
|
||||
default:
|
||||
return nil, fmt.Errorf("unsupported dialect: %s", source.DatabaseDialect())
|
||||
return nil, util.NewAgentError(fmt.Sprintf("unsupported dialect: %s", source.DatabaseDialect()), nil)
|
||||
}
|
||||
|
||||
return source.RunSQL(ctx, true, statement, stmtParams)
|
||||
resp, err := source.RunSQL(ctx, true, statement, stmtParams)
|
||||
if err != nil {
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (t Tool) EmbedParams(ctx context.Context, paramValues parameters.ParamValues, embeddingModelsMap map[string]embeddingmodels.EmbeddingModel) (parameters.ParamValues, error) {
|
||||
|
||||
@@ -17,6 +17,7 @@ package spannersql
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"cloud.google.com/go/spanner"
|
||||
@@ -24,6 +25,7 @@ import (
|
||||
"github.com/googleapis/genai-toolbox/internal/embeddingmodels"
|
||||
"github.com/googleapis/genai-toolbox/internal/sources"
|
||||
"github.com/googleapis/genai-toolbox/internal/tools"
|
||||
"github.com/googleapis/genai-toolbox/internal/util"
|
||||
"github.com/googleapis/genai-toolbox/internal/util/parameters"
|
||||
)
|
||||
|
||||
@@ -103,25 +105,25 @@ func getMapParams(params parameters.ParamValues, dialect string) (map[string]int
|
||||
case "postgresql":
|
||||
return params.AsMapByOrderedKeys(), nil
|
||||
default:
|
||||
return nil, fmt.Errorf("invalid dialect %s", dialect)
|
||||
return nil, util.NewAgentError(fmt.Sprintf("invalid dialect %s", dialect), nil)
|
||||
}
|
||||
}
|
||||
|
||||
func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, params parameters.ParamValues, accessToken tools.AccessToken) (any, error) {
|
||||
func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, params parameters.ParamValues, accessToken tools.AccessToken) (any, util.ToolboxError) {
|
||||
source, err := tools.GetCompatibleSource[compatibleSource](resourceMgr, t.Source, t.Name, t.Type)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, util.NewClientServerError("source used is not compatible with the tool", http.StatusInternalServerError, err)
|
||||
}
|
||||
|
||||
paramsMap := params.AsMap()
|
||||
newStatement, err := parameters.ResolveTemplateParams(t.TemplateParameters, t.Statement, paramsMap)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to extract template params %w", err)
|
||||
return nil, util.NewClientServerError(fmt.Sprintf("unable to extract template params: %v", err), http.StatusInternalServerError, err)
|
||||
}
|
||||
|
||||
newParams, err := parameters.GetParams(t.Parameters, paramsMap)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to extract standard params %w", err)
|
||||
return nil, util.NewClientServerError(fmt.Sprintf("unable to extract standard params: %v", err), http.StatusInternalServerError, err)
|
||||
}
|
||||
|
||||
for i, p := range t.Parameters {
|
||||
@@ -135,13 +137,13 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
case *parameters.ArrayParameter:
|
||||
arrayParamValue, ok := value.([]any)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unable to convert parameter `%s` to []any %w", name, err)
|
||||
return nil, util.NewClientServerError(fmt.Sprintf("unable to convert parameter `%s` to []any", name), http.StatusInternalServerError, err)
|
||||
}
|
||||
itemType := arrayParam.GetItems().GetType()
|
||||
var err error
|
||||
value, err = parameters.ConvertAnySliceToTyped(arrayParamValue, itemType)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to convert parameter `%s` from []any to typed slice: %w", name, err)
|
||||
var convertErr error
|
||||
value, convertErr = parameters.ConvertAnySliceToTyped(arrayParamValue, itemType)
|
||||
if convertErr != nil {
|
||||
return nil, util.NewClientServerError(fmt.Sprintf("unable to convert parameter `%s` from []any to typed slice: %v", name, convertErr), http.StatusInternalServerError, convertErr)
|
||||
}
|
||||
}
|
||||
newParams[i] = parameters.ParamValue{Name: name, Value: value}
|
||||
@@ -149,9 +151,14 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
|
||||
|
||||
mapParams, err := getMapParams(newParams, source.DatabaseDialect())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("fail to get map params: %w", err)
|
||||
return nil, util.NewAgentError("fail to get map params", err)
|
||||
}
|
||||
return source.RunSQL(ctx, t.ReadOnly, newStatement, mapParams)
|
||||
|
||||
resp, err := source.RunSQL(ctx, t.ReadOnly, newStatement, mapParams)
|
||||
if err != nil {
|
||||
return nil, util.ProcessGcpError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (t Tool) EmbedParams(ctx context.Context, paramValues parameters.ParamValues, embeddingModelsMap map[string]embeddingmodels.EmbeddingModel) (parameters.ParamValues, error) {
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
yaml "github.com/goccy/go-yaml"
|
||||
"github.com/googleapis/genai-toolbox/internal/embeddingmodels"
|
||||
@@ -88,27 +89,32 @@ type Tool struct {
|
||||
mcpManifest tools.McpManifest
|
||||
}
|
||||
|
||||
func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, params parameters.ParamValues, accessToken tools.AccessToken) (any, error) {
|
||||
func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, params parameters.ParamValues, accessToken tools.AccessToken) (any, util.ToolboxError) {
|
||||
source, err := tools.GetCompatibleSource[compatibleSource](resourceMgr, t.Source, t.Name, t.Type)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, util.NewClientServerError("source used is not compatible with the tool", http.StatusInternalServerError, err)
|
||||
}
|
||||
|
||||
sql, ok := params.AsMap()["sql"].(string)
|
||||
sqlStr, ok := params.AsMap()["sql"].(string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("missing or invalid 'sql' parameter")
|
||||
return nil, util.NewAgentError("missing or invalid 'sql' parameter", nil)
|
||||
}
|
||||
if sql == "" {
|
||||
return nil, fmt.Errorf("sql parameter cannot be empty")
|
||||
if sqlStr == "" {
|
||||
return nil, util.NewAgentError("sql parameter cannot be empty", nil)
|
||||
}
|
||||
|
||||
// Log the query executed for debugging.
|
||||
logger, err := util.LoggerFromContext(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error getting logger: %s", err)
|
||||
return nil, util.NewClientServerError("error getting logger", http.StatusInternalServerError, err)
|
||||
}
|
||||
logger.DebugContext(ctx, fmt.Sprintf("executing `%s` tool query: %s", resourceType, sql))
|
||||
return source.RunSQL(ctx, sql, nil)
|
||||
logger.DebugContext(ctx, fmt.Sprintf("executing `%s` tool query: %s", resourceType, sqlStr))
|
||||
|
||||
resp, err := source.RunSQL(ctx, sqlStr, nil)
|
||||
if err != nil {
|
||||
return nil, util.ProcessGeneralError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (t Tool) EmbedParams(ctx context.Context, paramValues parameters.ParamValues, embeddingModelsMap map[string]embeddingmodels.EmbeddingModel) (parameters.ParamValues, error) {
|
||||
|
||||
@@ -18,11 +18,13 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
yaml "github.com/goccy/go-yaml"
|
||||
"github.com/googleapis/genai-toolbox/internal/embeddingmodels"
|
||||
"github.com/googleapis/genai-toolbox/internal/sources"
|
||||
"github.com/googleapis/genai-toolbox/internal/tools"
|
||||
"github.com/googleapis/genai-toolbox/internal/util"
|
||||
"github.com/googleapis/genai-toolbox/internal/util/parameters"
|
||||
)
|
||||
|
||||
@@ -93,23 +95,27 @@ type Tool struct {
|
||||
mcpManifest tools.McpManifest
|
||||
}
|
||||
|
||||
func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, params parameters.ParamValues, accessToken tools.AccessToken) (any, error) {
|
||||
func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, params parameters.ParamValues, accessToken tools.AccessToken) (any, util.ToolboxError) {
|
||||
source, err := tools.GetCompatibleSource[compatibleSource](resourceMgr, t.Source, t.Name, t.Type)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, util.NewClientServerError("source used is not compatible with the tool", http.StatusInternalServerError, err)
|
||||
}
|
||||
|
||||
paramsMap := params.AsMap()
|
||||
newStatement, err := parameters.ResolveTemplateParams(t.TemplateParameters, t.Statement, paramsMap)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to extract template params %w", err)
|
||||
return nil, util.NewAgentError("unable to extract template params", err)
|
||||
}
|
||||
|
||||
newParams, err := parameters.GetParams(t.Parameters, paramsMap)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to extract standard params %w", err)
|
||||
return nil, util.NewAgentError("unable to extract standard params", err)
|
||||
}
|
||||
return source.RunSQL(ctx, newStatement, newParams.AsSlice())
|
||||
resp, err := source.RunSQL(ctx, newStatement, newParams.AsSlice())
|
||||
if err != nil {
|
||||
return nil, util.ProcessGeneralError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (t Tool) EmbedParams(ctx context.Context, paramValues parameters.ParamValues, embeddingModelsMap map[string]embeddingmodels.EmbeddingModel) (parameters.ParamValues, error) {
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
yaml "github.com/goccy/go-yaml"
|
||||
"github.com/googleapis/genai-toolbox/internal/embeddingmodels"
|
||||
@@ -89,25 +90,30 @@ type Tool struct {
|
||||
mcpManifest tools.McpManifest
|
||||
}
|
||||
|
||||
func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, params parameters.ParamValues, accessToken tools.AccessToken) (any, error) {
|
||||
func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, params parameters.ParamValues, accessToken tools.AccessToken) (any, util.ToolboxError) {
|
||||
source, err := tools.GetCompatibleSource[compatibleSource](resourceMgr, t.Source, t.Name, t.Type)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, util.NewClientServerError("source used is not compatible with the tool", http.StatusInternalServerError, err)
|
||||
}
|
||||
|
||||
paramsMap := params.AsMap()
|
||||
sql, ok := paramsMap["sql"].(string)
|
||||
sqlStr, ok := paramsMap["sql"].(string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unable to get cast %s", paramsMap["sql"])
|
||||
return nil, util.NewAgentError(fmt.Sprintf("unable to cast parameter 'sql' to string: %v", paramsMap["sql"]), nil)
|
||||
}
|
||||
|
||||
// Log the query executed for debugging.
|
||||
logger, err := util.LoggerFromContext(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error getting logger: %s", err)
|
||||
return nil, util.NewClientServerError("error getting logger", http.StatusInternalServerError, err)
|
||||
}
|
||||
logger.DebugContext(ctx, fmt.Sprintf("executing `%s` tool query: %s", resourceType, sql))
|
||||
return source.RunSQL(ctx, sql, nil)
|
||||
logger.DebugContext(ctx, fmt.Sprintf("executing `%s` tool query: %s", resourceType, sqlStr))
|
||||
|
||||
resp, err := source.RunSQL(ctx, sqlStr, nil)
|
||||
if err != nil {
|
||||
return nil, util.ProcessGeneralError(err)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (t Tool) EmbedParams(ctx context.Context, paramValues parameters.ParamValues, embeddingModelsMap map[string]embeddingmodels.EmbeddingModel) (parameters.ParamValues, error) {
|
||||
|
||||
@@ -18,11 +18,13 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
yaml "github.com/goccy/go-yaml"
|
||||
"github.com/googleapis/genai-toolbox/internal/embeddingmodels"
|
||||
"github.com/googleapis/genai-toolbox/internal/sources"
|
||||
"github.com/googleapis/genai-toolbox/internal/tools"
|
||||
"github.com/googleapis/genai-toolbox/internal/util"
|
||||
"github.com/googleapis/genai-toolbox/internal/util/parameters"
|
||||
)
|
||||
|
||||
@@ -93,25 +95,29 @@ type Tool struct {
|
||||
mcpManifest tools.McpManifest
|
||||
}
|
||||
|
||||
func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, params parameters.ParamValues, accessToken tools.AccessToken) (any, error) {
|
||||
func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, params parameters.ParamValues, accessToken tools.AccessToken) (any, util.ToolboxError) {
|
||||
source, err := tools.GetCompatibleSource[compatibleSource](resourceMgr, t.Source, t.Name, t.Type)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, util.NewClientServerError("source not compatible with this tool", http.StatusInternalServerError, err)
|
||||
}
|
||||
|
||||
paramsMap := params.AsMap()
|
||||
newStatement, err := parameters.ResolveTemplateParams(t.TemplateParameters, t.Statement, paramsMap)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to extract template params %w", err)
|
||||
return nil, util.NewAgentError("unable to extract template params", err)
|
||||
}
|
||||
|
||||
newParams, err := parameters.GetParams(t.Parameters, paramsMap)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to extract standard params %w", err)
|
||||
return nil, util.NewAgentError("unable to extract standard params", err)
|
||||
}
|
||||
|
||||
sliceParams := newParams.AsSlice()
|
||||
return source.RunSQL(ctx, newStatement, sliceParams)
|
||||
res, err := source.RunSQL(ctx, newStatement, sliceParams)
|
||||
if err != nil {
|
||||
return nil, util.ProcessGeneralError(err)
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (t Tool) EmbedParams(ctx context.Context, paramValues parameters.ParamValues, embeddingModelsMap map[string]embeddingmodels.EmbeddingModel) (parameters.ParamValues, error) {
|
||||
|
||||
@@ -18,11 +18,13 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
yaml "github.com/goccy/go-yaml"
|
||||
"github.com/googleapis/genai-toolbox/internal/embeddingmodels"
|
||||
"github.com/googleapis/genai-toolbox/internal/sources"
|
||||
"github.com/googleapis/genai-toolbox/internal/tools"
|
||||
"github.com/googleapis/genai-toolbox/internal/util"
|
||||
"github.com/googleapis/genai-toolbox/internal/util/parameters"
|
||||
)
|
||||
|
||||
@@ -88,18 +90,22 @@ type Tool struct {
|
||||
mcpManifest tools.McpManifest
|
||||
}
|
||||
|
||||
func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, params parameters.ParamValues, accessToken tools.AccessToken) (any, error) {
|
||||
func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, params parameters.ParamValues, accessToken tools.AccessToken) (any, util.ToolboxError) {
|
||||
source, err := tools.GetCompatibleSource[compatibleSource](resourceMgr, t.Source, t.Name, t.Type)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, util.NewClientServerError("source not compatible with this tool", http.StatusInternalServerError, err)
|
||||
}
|
||||
|
||||
sliceParams := params.AsSlice()
|
||||
sql, ok := sliceParams[0].(string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unable to cast sql parameter: %v", sliceParams[0])
|
||||
return nil, util.NewAgentError("unable to cast the `sql` input parameter into string", nil)
|
||||
}
|
||||
return source.RunSQL(ctx, sql, nil)
|
||||
res, err := source.RunSQL(ctx, sql, sliceParams)
|
||||
if err != nil {
|
||||
return nil, util.ProcessGeneralError(err)
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (t Tool) EmbedParams(ctx context.Context, paramValues parameters.ParamValues, embeddingModelsMap map[string]embeddingmodels.EmbeddingModel) (parameters.ParamValues, error) {
|
||||
|
||||
@@ -18,11 +18,13 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
yaml "github.com/goccy/go-yaml"
|
||||
"github.com/googleapis/genai-toolbox/internal/embeddingmodels"
|
||||
"github.com/googleapis/genai-toolbox/internal/sources"
|
||||
"github.com/googleapis/genai-toolbox/internal/tools"
|
||||
"github.com/googleapis/genai-toolbox/internal/util"
|
||||
"github.com/googleapis/genai-toolbox/internal/util/parameters"
|
||||
)
|
||||
|
||||
@@ -93,23 +95,27 @@ type Tool struct {
|
||||
mcpManifest tools.McpManifest
|
||||
}
|
||||
|
||||
func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, params parameters.ParamValues, accessToken tools.AccessToken) (any, error) {
|
||||
func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, params parameters.ParamValues, accessToken tools.AccessToken) (any, util.ToolboxError) {
|
||||
source, err := tools.GetCompatibleSource[compatibleSource](resourceMgr, t.Source, t.Name, t.Type)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, util.NewClientServerError("source not compatible with this tool", http.StatusInternalServerError, err)
|
||||
}
|
||||
|
||||
paramsMap := params.AsMap()
|
||||
newStatement, err := parameters.ResolveTemplateParams(t.TemplateParameters, t.Statement, paramsMap)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to extract template params %w", err)
|
||||
return nil, util.NewAgentError("unable to extract template params", err)
|
||||
}
|
||||
newParams, err := parameters.GetParams(t.Parameters, paramsMap)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to extract standard params %w", err)
|
||||
return nil, util.NewAgentError("unable to extract standard params", err)
|
||||
}
|
||||
sliceParams := newParams.AsSlice()
|
||||
return source.RunSQL(ctx, newStatement, sliceParams)
|
||||
res, err := source.RunSQL(ctx, newStatement, sliceParams)
|
||||
if err != nil {
|
||||
return nil, util.ProcessGeneralError(err)
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (t Tool) EmbedParams(ctx context.Context, paramValues parameters.ParamValues, embeddingModelsMap map[string]embeddingmodels.EmbeddingModel) (parameters.ParamValues, error) {
|
||||
|
||||
@@ -75,9 +75,9 @@ func NewClientServerError(msg string, code int, cause error) *ClientServerError
|
||||
return &ClientServerError{Msg: msg, Code: code, Cause: cause}
|
||||
}
|
||||
|
||||
// ProecessGcpError catches auth related errors and return 401/403 error codes
|
||||
// ProcessGcpError catches auth related errors in GCP requests results and return 401/403 error codes
|
||||
// Returns AgentError for all other errors
|
||||
func ProecessGcpError(err error) ToolboxError {
|
||||
func ProcessGcpError(err error) ToolboxError {
|
||||
var gErr *googleapi.Error
|
||||
if errors.As(err, &gErr) {
|
||||
if gErr.Code == 401 {
|
||||
|
||||
Reference in New Issue
Block a user