@squadbase/connectors 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +259 -259
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -942,7 +942,94 @@ var mysqlConnector = new ConnectorPlugin({
|
|
|
942
942
|
}
|
|
943
943
|
});
|
|
944
944
|
|
|
945
|
+
// src/connectors/bigquery/tools/list-projects.ts
|
|
946
|
+
import { z as z5 } from "zod";
|
|
947
|
+
|
|
948
|
+
// src/connectors/bigquery/parameters.ts
|
|
949
|
+
var parameters5 = {
|
|
950
|
+
serviceAccountKeyJsonBase64: new ParameterDefinition({
|
|
951
|
+
slug: "service-account-key-json-base64",
|
|
952
|
+
name: "Google Cloud Service Account JSON",
|
|
953
|
+
description: "The service account JSON key used to authenticate with Google Cloud Platform. Ensure that the service account has the necessary permissions to access the required resources.",
|
|
954
|
+
envVarBaseKey: "BIGQUERY_SERVICE_ACCOUNT_JSON_BASE64",
|
|
955
|
+
type: "base64EncodedJson",
|
|
956
|
+
secret: true,
|
|
957
|
+
required: true
|
|
958
|
+
}),
|
|
959
|
+
projectId: new ParameterDefinition({
|
|
960
|
+
slug: "project-id",
|
|
961
|
+
name: "Google Cloud Project ID",
|
|
962
|
+
description: "The ID of the Google Cloud project where resources will be managed.",
|
|
963
|
+
envVarBaseKey: "BIGQUERY_PROJECT_ID",
|
|
964
|
+
type: "text",
|
|
965
|
+
secret: false,
|
|
966
|
+
required: false
|
|
967
|
+
})
|
|
968
|
+
};
|
|
969
|
+
|
|
970
|
+
// src/connectors/bigquery/tools/list-projects.ts
|
|
971
|
+
var inputSchema5 = z5.object({
|
|
972
|
+
toolUseIntent: z5.string().optional().describe(
|
|
973
|
+
"Brief description of what you intend to accomplish with this tool call"
|
|
974
|
+
),
|
|
975
|
+
connectionId: z5.string().describe("ID of the BigQuery connection to use")
|
|
976
|
+
});
|
|
977
|
+
var outputSchema5 = z5.discriminatedUnion("success", [
|
|
978
|
+
z5.object({
|
|
979
|
+
success: z5.literal(true),
|
|
980
|
+
projects: z5.array(
|
|
981
|
+
z5.object({
|
|
982
|
+
projectId: z5.string(),
|
|
983
|
+
friendlyName: z5.string()
|
|
984
|
+
})
|
|
985
|
+
)
|
|
986
|
+
}),
|
|
987
|
+
z5.object({
|
|
988
|
+
success: z5.literal(false),
|
|
989
|
+
error: z5.string()
|
|
990
|
+
})
|
|
991
|
+
]);
|
|
992
|
+
var listProjectsTool = new ConnectorTool({
|
|
993
|
+
name: "listProjects",
|
|
994
|
+
description: `List GCP projects accessible with the service account credentials. Returns project IDs and friendly names.`,
|
|
995
|
+
inputSchema: inputSchema5,
|
|
996
|
+
outputSchema: outputSchema5,
|
|
997
|
+
async execute({ connectionId }, connections) {
|
|
998
|
+
const connection = connections.find((c) => c.id === connectionId);
|
|
999
|
+
if (!connection) {
|
|
1000
|
+
return {
|
|
1001
|
+
success: false,
|
|
1002
|
+
error: `Connection ${connectionId} not found`
|
|
1003
|
+
};
|
|
1004
|
+
}
|
|
1005
|
+
try {
|
|
1006
|
+
const serviceAccountJsonBase64 = parameters5.serviceAccountKeyJsonBase64.getValue(connection);
|
|
1007
|
+
const credentials = JSON.parse(
|
|
1008
|
+
Buffer.from(serviceAccountJsonBase64, "base64").toString("utf-8")
|
|
1009
|
+
);
|
|
1010
|
+
const { GoogleAuth } = await import("google-auth-library");
|
|
1011
|
+
const auth = new GoogleAuth({
|
|
1012
|
+
credentials,
|
|
1013
|
+
scopes: ["https://www.googleapis.com/auth/bigquery"]
|
|
1014
|
+
});
|
|
1015
|
+
const client = await auth.getClient();
|
|
1016
|
+
const res = await client.request({
|
|
1017
|
+
url: "https://bigquery.googleapis.com/bigquery/v2/projects"
|
|
1018
|
+
});
|
|
1019
|
+
const projects = (res.data.projects ?? []).map((p) => ({
|
|
1020
|
+
projectId: p.projectReference?.projectId ?? "",
|
|
1021
|
+
friendlyName: p.friendlyName ?? p.projectReference?.projectId ?? ""
|
|
1022
|
+
})).filter((p) => p.projectId !== "");
|
|
1023
|
+
return { success: true, projects };
|
|
1024
|
+
} catch (err) {
|
|
1025
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
1026
|
+
return { success: false, error: msg };
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
});
|
|
1030
|
+
|
|
945
1031
|
// src/connectors/bigquery/setup.ts
|
|
1032
|
+
var listProjectsToolName = `bigquery_${listProjectsTool.name}`;
|
|
946
1033
|
var bigquerySetup = new ConnectorSetup({
|
|
947
1034
|
ja: `## BigQuery \u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u624B\u9806
|
|
948
1035
|
|
|
@@ -950,8 +1037,8 @@ var bigquerySetup = new ConnectorSetup({
|
|
|
950
1037
|
|
|
951
1038
|
### \u624B\u9806
|
|
952
1039
|
|
|
953
|
-
#### \u30B9\u30C6\u30C3\
|
|
954
|
-
1. \`
|
|
1040
|
+
#### \u30B9\u30C6\u30C3\u30D71: \u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u9078\u629E
|
|
1041
|
+
1. \`${listProjectsToolName}\` \u3092\u547C\u3073\u51FA\u3057\u3066\u3001\u30B5\u30FC\u30D3\u30B9\u30A2\u30AB\u30A6\u30F3\u30C8\u304C\u30A2\u30AF\u30BB\u30B9\u53EF\u80FD\u306AGCP\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u4E00\u89A7\u3092\u53D6\u5F97\u3059\u308B
|
|
955
1042
|
2. \u7D50\u679C\u306B\u5FDC\u3058\u3066\u5206\u5C90:
|
|
956
1043
|
- **\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u304C2\u3064\u4EE5\u4E0A**: \`askUserQuestion\`\uFF08multiSelect: false\uFF09\u3067\u30E6\u30FC\u30B6\u30FC\u306B\u63D0\u793A\u3057\u3001\u4F7F\u7528\u3059\u308B\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u3092\u9078\u629E\u3055\u305B\u308B\u3002\u9078\u629E\u80A2\u306E label \u306F \`\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u540D (id: \u30D7\u30ED\u30B8\u30A7\u30AF\u30C8ID)\` \u306E\u5F62\u5F0F\u306B\u3059\u308B
|
|
957
1044
|
- **\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u304C1\u3064\u3060\u3051**: askUserQuestion \u306F\u4F7F\u308F\u305A\u81EA\u52D5\u63A1\u7528\u3002\u300C\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8 X \u3092\u81EA\u52D5\u9078\u629E\u3057\u307E\u3057\u305F\u300D\u30681\u6587\u3060\u3051\u66F8\u304F
|
|
@@ -959,23 +1046,22 @@ var bigquerySetup = new ConnectorSetup({
|
|
|
959
1046
|
- \`parameterSlug\`: \`"project-id"\`
|
|
960
1047
|
- \`value\`: \u30D7\u30ED\u30B8\u30A7\u30AF\u30C8ID
|
|
961
1048
|
- \`displayValue\`: \`"\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u540D (id: \u30D7\u30ED\u30B8\u30A7\u30AF\u30C8ID)"\`
|
|
962
|
-
4. \u7D9A\u884C\u30E1\u30C3\u30BB\u30FC\u30B8\u3092\u53D7\u3051\u53D6\u3063\u305F\u3089\u3001\u30B9\u30C6\u30C3\
|
|
1049
|
+
4. \u7D9A\u884C\u30E1\u30C3\u30BB\u30FC\u30B8\u3092\u53D7\u3051\u53D6\u3063\u305F\u3089\u3001\u30B9\u30C6\u30C3\u30D72\u306B\u9032\u3080
|
|
963
1050
|
|
|
964
|
-
#### \u30B9\u30C6\u30C3\
|
|
1051
|
+
#### \u30B9\u30C6\u30C3\u30D72: \u30C7\u30FC\u30BF\u30BB\u30C3\u30C8\u9078\u629E
|
|
965
1052
|
1. \`SELECT schema_name FROM INFORMATION_SCHEMA.SCHEMATA\` \u3092\u5B9F\u884C\u3057\u3066\u30C7\u30FC\u30BF\u30BB\u30C3\u30C8\u4E00\u89A7\u3092\u53D6\u5F97\u3059\u308B
|
|
966
1053
|
2. \u7D50\u679C\u306B\u5FDC\u3058\u3066\u5206\u5C90:
|
|
967
1054
|
- **\u30C7\u30FC\u30BF\u30BB\u30C3\u30C8\u304C2\u3064\u4EE5\u4E0A**: \`askUserQuestion\`\uFF08multiSelect: true\uFF09\u3067\u30E6\u30FC\u30B6\u30FC\u306B\u63D0\u793A\u3057\u3001\u4F7F\u7528\u3059\u308B\u30C7\u30FC\u30BF\u30BB\u30C3\u30C8\u3092\u9078\u629E\u3055\u305B\u308B
|
|
968
1055
|
- **\u30C7\u30FC\u30BF\u30BB\u30C3\u30C8\u304C1\u3064\u3060\u3051**: askUserQuestion \u306F\u4F7F\u308F\u305A\u81EA\u52D5\u63A1\u7528\u3002\u300C\u30C7\u30FC\u30BF\u30BB\u30C3\u30C8 X \u3092\u81EA\u52D5\u9078\u629E\u3057\u307E\u3057\u305F\u300D\u30681\u6587\u3060\u3051\u66F8\u304F
|
|
969
1056
|
|
|
970
|
-
#### \u30B9\u30C6\u30C3\
|
|
1057
|
+
#### \u30B9\u30C6\u30C3\u30D73: \u30C6\u30FC\u30D6\u30EB\u9078\u629E
|
|
971
1058
|
3. \u9078\u629E\u3055\u308C\u305F\u30C7\u30FC\u30BF\u30BB\u30C3\u30C8\u306B\u5BFE\u3057\u3066 \`SELECT table_name FROM \\\`{project}.{dataset}.INFORMATION_SCHEMA.TABLES\\\`\` \u3092\u5B9F\u884C\u3057\u3066\u30C6\u30FC\u30D6\u30EB\u4E00\u89A7\u3092\u53D6\u5F97\u3059\u308B\uFF08\u8907\u6570\u30C7\u30FC\u30BF\u30BB\u30C3\u30C8\u306E\u5834\u5408\u306F UNION ALL \u3067\u4E00\u62EC\u53D6\u5F97\uFF09
|
|
972
1059
|
4. \u7D50\u679C\u306B\u5FDC\u3058\u3066\u5206\u5C90:
|
|
973
1060
|
- **\u30C6\u30FC\u30D6\u30EB\u304C2\u3064\u4EE5\u4E0A**: \`askUserQuestion\`\uFF08multiSelect: true\uFF09\u3067\u30E6\u30FC\u30B6\u30FC\u306B\u63D0\u793A\u3057\u3001\u4F7F\u7528\u3059\u308B\u30C6\u30FC\u30D6\u30EB\u3092\u9078\u629E\u3055\u305B\u308B\u3002description \u306B\u306F\u30C7\u30FC\u30BF\u30BB\u30C3\u30C8\u540D\u3092\u8A18\u8F09\u3059\u308B
|
|
974
1061
|
- **\u30C6\u30FC\u30D6\u30EB\u304C1\u3064\u3060\u3051**: askUserQuestion \u306F\u4F7F\u308F\u305A\u81EA\u52D5\u63A1\u7528
|
|
975
1062
|
|
|
976
|
-
#### \u30B9\u30C6\u30C3\
|
|
1063
|
+
#### \u30B9\u30C6\u30C3\u30D74: \u4FDD\u5B58
|
|
977
1064
|
5. \`updateConnectionContext\` \u3067\u4EE5\u4E0B\u3092\u4FDD\u5B58\u3059\u308B:
|
|
978
|
-
- \`project\`: BigQuery\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8ID
|
|
979
1065
|
- \`dataset\`: \u9078\u629E\u3055\u308C\u305F\u30C7\u30FC\u30BF\u30BB\u30C3\u30C8\u540D\uFF08\u8907\u6570\u306E\u5834\u5408\u306F\u30AB\u30F3\u30DE\u533A\u5207\u308A\uFF09
|
|
980
1066
|
- \`tables\`: \u9078\u629E\u3055\u308C\u305F\u30C6\u30FC\u30D6\u30EB\u540D\uFF08\u8907\u6570\u306E\u5834\u5408\u306F\u30AB\u30F3\u30DE\u533A\u5207\u308A\uFF09
|
|
981
1067
|
- \`note\`: \u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u5185\u5BB9\u306E\u7C21\u5358\u306A\u8AAC\u660E
|
|
@@ -993,8 +1079,8 @@ Follow these steps to set up the BigQuery connection.
|
|
|
993
1079
|
|
|
994
1080
|
### Steps
|
|
995
1081
|
|
|
996
|
-
#### Step
|
|
997
|
-
1. Call \`
|
|
1082
|
+
#### Step 1: Project Selection
|
|
1083
|
+
1. Call \`${listProjectsToolName}\` to get the list of GCP projects accessible with the service account credentials
|
|
998
1084
|
2. Branch based on results:
|
|
999
1085
|
- **2 or more projects**: Present them to the user via \`askUserQuestion\` (multiSelect: false) and let them select a project. Format option labels as \`Project Name (id: project-id)\`
|
|
1000
1086
|
- **Exactly 1 project**: Do NOT call askUserQuestion. Auto-select it. Just write "Auto-selected project X" in one sentence
|
|
@@ -1002,23 +1088,22 @@ Follow these steps to set up the BigQuery connection.
|
|
|
1002
1088
|
- \`parameterSlug\`: \`"project-id"\`
|
|
1003
1089
|
- \`value\`: the project ID
|
|
1004
1090
|
- \`displayValue\`: \`"Project Name (id: project-id)"\`
|
|
1005
|
-
4. After receiving the continuation message, proceed to Step
|
|
1091
|
+
4. After receiving the continuation message, proceed to Step 2
|
|
1006
1092
|
|
|
1007
|
-
#### Step
|
|
1093
|
+
#### Step 2: Dataset Selection
|
|
1008
1094
|
1. Run \`SELECT schema_name FROM INFORMATION_SCHEMA.SCHEMATA\` to get the list of datasets
|
|
1009
1095
|
2. Branch based on results:
|
|
1010
1096
|
- **2 or more datasets**: Present them to the user via \`askUserQuestion\` (multiSelect: true) and let them select which datasets to use
|
|
1011
1097
|
- **Exactly 1 dataset**: Do NOT call askUserQuestion. Auto-select it. Just write "Auto-selected dataset X" in one sentence
|
|
1012
1098
|
|
|
1013
|
-
#### Step
|
|
1099
|
+
#### Step 3: Table Selection
|
|
1014
1100
|
3. For the selected dataset(s), run \`SELECT table_name FROM \\\`{project}.{dataset}.INFORMATION_SCHEMA.TABLES\\\`\` to get the table list (use UNION ALL for multiple datasets)
|
|
1015
1101
|
4. Branch based on results:
|
|
1016
1102
|
- **2 or more tables**: Present them to the user via \`askUserQuestion\` (multiSelect: true) and let them select which tables to use. Include the dataset name in the description
|
|
1017
1103
|
- **Exactly 1 table**: Do NOT call askUserQuestion. Auto-select it
|
|
1018
1104
|
|
|
1019
|
-
#### Step
|
|
1105
|
+
#### Step 4: Save
|
|
1020
1106
|
5. Call \`updateConnectionContext\` to save:
|
|
1021
|
-
- \`project\`: BigQuery project ID
|
|
1022
1107
|
- \`dataset\`: Selected dataset name(s) (comma-separated if multiple)
|
|
1023
1108
|
- \`tables\`: Selected table name(s) (comma-separated if multiple)
|
|
1024
1109
|
- \`note\`: Brief description of the setup
|
|
@@ -1032,50 +1117,28 @@ Follow these steps to set up the BigQuery connection.
|
|
|
1032
1117
|
- Skip unnecessary explanations and proceed efficiently`
|
|
1033
1118
|
});
|
|
1034
1119
|
|
|
1035
|
-
// src/connectors/bigquery/parameters.ts
|
|
1036
|
-
var parameters5 = {
|
|
1037
|
-
serviceAccountKeyJsonBase64: new ParameterDefinition({
|
|
1038
|
-
slug: "service-account-key-json-base64",
|
|
1039
|
-
name: "Google Cloud Service Account JSON",
|
|
1040
|
-
description: "The service account JSON key used to authenticate with Google Cloud Platform. Ensure that the service account has the necessary permissions to access the required resources.",
|
|
1041
|
-
envVarBaseKey: "BIGQUERY_SERVICE_ACCOUNT_JSON_BASE64",
|
|
1042
|
-
type: "base64EncodedJson",
|
|
1043
|
-
secret: true,
|
|
1044
|
-
required: true
|
|
1045
|
-
}),
|
|
1046
|
-
projectId: new ParameterDefinition({
|
|
1047
|
-
slug: "project-id",
|
|
1048
|
-
name: "Google Cloud Project ID",
|
|
1049
|
-
description: "The ID of the Google Cloud project where resources will be managed.",
|
|
1050
|
-
envVarBaseKey: "BIGQUERY_PROJECT_ID",
|
|
1051
|
-
type: "text",
|
|
1052
|
-
secret: false,
|
|
1053
|
-
required: false
|
|
1054
|
-
})
|
|
1055
|
-
};
|
|
1056
|
-
|
|
1057
1120
|
// src/connectors/bigquery/tools/execute-query.ts
|
|
1058
|
-
import { z as
|
|
1121
|
+
import { z as z6 } from "zod";
|
|
1059
1122
|
var MAX_ROWS5 = 500;
|
|
1060
|
-
var
|
|
1061
|
-
toolUseIntent:
|
|
1123
|
+
var inputSchema6 = z6.object({
|
|
1124
|
+
toolUseIntent: z6.string().optional().describe(
|
|
1062
1125
|
"Brief description of what you intend to accomplish with this tool call"
|
|
1063
1126
|
),
|
|
1064
|
-
connectionId:
|
|
1065
|
-
sql:
|
|
1127
|
+
connectionId: z6.string().describe("ID of the BigQuery connection to use"),
|
|
1128
|
+
sql: z6.string().describe(
|
|
1066
1129
|
"BigQuery SQL (GoogleSQL) query. Use backtick-quoted fully qualified names `project.dataset.table` for table references."
|
|
1067
1130
|
)
|
|
1068
1131
|
});
|
|
1069
|
-
var
|
|
1070
|
-
|
|
1071
|
-
success:
|
|
1072
|
-
rowCount:
|
|
1073
|
-
truncated:
|
|
1074
|
-
rows:
|
|
1132
|
+
var outputSchema6 = z6.discriminatedUnion("success", [
|
|
1133
|
+
z6.object({
|
|
1134
|
+
success: z6.literal(true),
|
|
1135
|
+
rowCount: z6.number(),
|
|
1136
|
+
truncated: z6.boolean(),
|
|
1137
|
+
rows: z6.array(z6.record(z6.string(), z6.unknown()))
|
|
1075
1138
|
}),
|
|
1076
|
-
|
|
1077
|
-
success:
|
|
1078
|
-
error:
|
|
1139
|
+
z6.object({
|
|
1140
|
+
success: z6.literal(false),
|
|
1141
|
+
error: z6.string()
|
|
1079
1142
|
})
|
|
1080
1143
|
]);
|
|
1081
1144
|
var executeQueryTool5 = new ConnectorTool({
|
|
@@ -1083,8 +1146,8 @@ var executeQueryTool5 = new ConnectorTool({
|
|
|
1083
1146
|
description: `Execute SQL against BigQuery. Returns up to ${MAX_ROWS5} rows.
|
|
1084
1147
|
Use for: schema exploration (INFORMATION_SCHEMA), data sampling, analytical queries.
|
|
1085
1148
|
Avoid loading large amounts of data; always include LIMIT in queries.`,
|
|
1086
|
-
inputSchema:
|
|
1087
|
-
outputSchema:
|
|
1149
|
+
inputSchema: inputSchema6,
|
|
1150
|
+
outputSchema: outputSchema6,
|
|
1088
1151
|
async execute({ connectionId, sql }, connections) {
|
|
1089
1152
|
const connection = connections.find((c) => c.id === connectionId);
|
|
1090
1153
|
if (!connection) {
|
|
@@ -1121,68 +1184,6 @@ Avoid loading large amounts of data; always include LIMIT in queries.`,
|
|
|
1121
1184
|
}
|
|
1122
1185
|
});
|
|
1123
1186
|
|
|
1124
|
-
// src/connectors/bigquery/tools/list-projects.ts
|
|
1125
|
-
import { z as z6 } from "zod";
|
|
1126
|
-
var inputSchema6 = z6.object({
|
|
1127
|
-
toolUseIntent: z6.string().optional().describe(
|
|
1128
|
-
"Brief description of what you intend to accomplish with this tool call"
|
|
1129
|
-
),
|
|
1130
|
-
connectionId: z6.string().describe("ID of the BigQuery connection to use")
|
|
1131
|
-
});
|
|
1132
|
-
var outputSchema6 = z6.discriminatedUnion("success", [
|
|
1133
|
-
z6.object({
|
|
1134
|
-
success: z6.literal(true),
|
|
1135
|
-
projects: z6.array(
|
|
1136
|
-
z6.object({
|
|
1137
|
-
projectId: z6.string(),
|
|
1138
|
-
friendlyName: z6.string()
|
|
1139
|
-
})
|
|
1140
|
-
)
|
|
1141
|
-
}),
|
|
1142
|
-
z6.object({
|
|
1143
|
-
success: z6.literal(false),
|
|
1144
|
-
error: z6.string()
|
|
1145
|
-
})
|
|
1146
|
-
]);
|
|
1147
|
-
var listProjectsTool = new ConnectorTool({
|
|
1148
|
-
name: "listProjects",
|
|
1149
|
-
description: `List GCP projects accessible with the service account credentials. Returns project IDs and friendly names.`,
|
|
1150
|
-
inputSchema: inputSchema6,
|
|
1151
|
-
outputSchema: outputSchema6,
|
|
1152
|
-
async execute({ connectionId }, connections) {
|
|
1153
|
-
const connection = connections.find((c) => c.id === connectionId);
|
|
1154
|
-
if (!connection) {
|
|
1155
|
-
return {
|
|
1156
|
-
success: false,
|
|
1157
|
-
error: `Connection ${connectionId} not found`
|
|
1158
|
-
};
|
|
1159
|
-
}
|
|
1160
|
-
try {
|
|
1161
|
-
const serviceAccountJsonBase64 = parameters5.serviceAccountKeyJsonBase64.getValue(connection);
|
|
1162
|
-
const credentials = JSON.parse(
|
|
1163
|
-
Buffer.from(serviceAccountJsonBase64, "base64").toString("utf-8")
|
|
1164
|
-
);
|
|
1165
|
-
const { GoogleAuth } = await import("google-auth-library");
|
|
1166
|
-
const auth = new GoogleAuth({
|
|
1167
|
-
credentials,
|
|
1168
|
-
scopes: ["https://www.googleapis.com/auth/bigquery"]
|
|
1169
|
-
});
|
|
1170
|
-
const client = await auth.getClient();
|
|
1171
|
-
const res = await client.request({
|
|
1172
|
-
url: "https://bigquery.googleapis.com/bigquery/v2/projects"
|
|
1173
|
-
});
|
|
1174
|
-
const projects = (res.data.projects ?? []).map((p) => ({
|
|
1175
|
-
projectId: p.projectReference?.projectId ?? "",
|
|
1176
|
-
friendlyName: p.friendlyName ?? p.projectReference?.projectId ?? ""
|
|
1177
|
-
})).filter((p) => p.projectId !== "");
|
|
1178
|
-
return { success: true, projects };
|
|
1179
|
-
} catch (err) {
|
|
1180
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
1181
|
-
return { success: false, error: msg };
|
|
1182
|
-
}
|
|
1183
|
-
}
|
|
1184
|
-
});
|
|
1185
|
-
|
|
1186
1187
|
// src/connectors/bigquery/index.ts
|
|
1187
1188
|
var tools5 = { executeQuery: executeQueryTool5, listProjects: listProjectsTool };
|
|
1188
1189
|
var bigqueryConnector = new ConnectorPlugin({
|
|
@@ -1218,7 +1219,115 @@ var bigqueryConnector = new ConnectorPlugin({
|
|
|
1218
1219
|
}
|
|
1219
1220
|
});
|
|
1220
1221
|
|
|
1222
|
+
// src/connectors/bigquery-oauth/tools/list-projects.ts
|
|
1223
|
+
import { z as z7 } from "zod";
|
|
1224
|
+
var REQUEST_TIMEOUT_MS = 6e4;
|
|
1225
|
+
var cachedToken = null;
|
|
1226
|
+
async function getProxyToken(config) {
|
|
1227
|
+
if (cachedToken && cachedToken.expiresAt > Date.now() + 6e4) {
|
|
1228
|
+
return cachedToken.token;
|
|
1229
|
+
}
|
|
1230
|
+
const url = `${config.appApiBaseUrl}/v0/database/${config.projectId}/environment/${config.environmentId}/oauth-request-proxy-token`;
|
|
1231
|
+
const res = await fetch(url, {
|
|
1232
|
+
method: "POST",
|
|
1233
|
+
headers: {
|
|
1234
|
+
"Content-Type": "application/json",
|
|
1235
|
+
"x-api-key": config.appApiKey,
|
|
1236
|
+
"project-id": config.projectId
|
|
1237
|
+
},
|
|
1238
|
+
body: JSON.stringify({
|
|
1239
|
+
sandboxId: config.sandboxId,
|
|
1240
|
+
issuedBy: "coding-agent"
|
|
1241
|
+
})
|
|
1242
|
+
});
|
|
1243
|
+
if (!res.ok) {
|
|
1244
|
+
const errorText = await res.text().catch(() => res.statusText);
|
|
1245
|
+
throw new Error(`Failed to get proxy token: HTTP ${res.status} ${errorText}`);
|
|
1246
|
+
}
|
|
1247
|
+
const data = await res.json();
|
|
1248
|
+
cachedToken = {
|
|
1249
|
+
token: data.token,
|
|
1250
|
+
expiresAt: new Date(data.expiresAt).getTime()
|
|
1251
|
+
};
|
|
1252
|
+
return data.token;
|
|
1253
|
+
}
|
|
1254
|
+
var inputSchema7 = z7.object({
|
|
1255
|
+
toolUseIntent: z7.string().optional().describe(
|
|
1256
|
+
"Brief description of what you intend to accomplish with this tool call"
|
|
1257
|
+
),
|
|
1258
|
+
connectionId: z7.string().describe("ID of the BigQuery OAuth connection to use")
|
|
1259
|
+
});
|
|
1260
|
+
var outputSchema7 = z7.discriminatedUnion("success", [
|
|
1261
|
+
z7.object({
|
|
1262
|
+
success: z7.literal(true),
|
|
1263
|
+
projects: z7.array(
|
|
1264
|
+
z7.object({
|
|
1265
|
+
projectId: z7.string(),
|
|
1266
|
+
friendlyName: z7.string()
|
|
1267
|
+
})
|
|
1268
|
+
)
|
|
1269
|
+
}),
|
|
1270
|
+
z7.object({
|
|
1271
|
+
success: z7.literal(false),
|
|
1272
|
+
error: z7.string()
|
|
1273
|
+
})
|
|
1274
|
+
]);
|
|
1275
|
+
var listProjectsTool2 = new ConnectorTool({
|
|
1276
|
+
name: "listProjects",
|
|
1277
|
+
description: `List GCP projects accessible with the current OAuth credentials. Returns project IDs and friendly names.`,
|
|
1278
|
+
inputSchema: inputSchema7,
|
|
1279
|
+
outputSchema: outputSchema7,
|
|
1280
|
+
async execute({ connectionId }, connections, config) {
|
|
1281
|
+
const connection = connections.find((c) => c.id === connectionId);
|
|
1282
|
+
if (!connection) {
|
|
1283
|
+
return {
|
|
1284
|
+
success: false,
|
|
1285
|
+
error: `Connection ${connectionId} not found`
|
|
1286
|
+
};
|
|
1287
|
+
}
|
|
1288
|
+
console.log(
|
|
1289
|
+
`[connector-query] bigquery-oauth/${connection.name}: listProjects`
|
|
1290
|
+
);
|
|
1291
|
+
try {
|
|
1292
|
+
const token = await getProxyToken(config.oauthProxy);
|
|
1293
|
+
const proxyUrl = `https://${config.oauthProxy.sandboxId}.${config.oauthProxy.previewBaseDomain}/_sqcore/connections/${connectionId}/request`;
|
|
1294
|
+
const controller = new AbortController();
|
|
1295
|
+
const timeout = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
|
|
1296
|
+
try {
|
|
1297
|
+
const response = await fetch(proxyUrl, {
|
|
1298
|
+
method: "POST",
|
|
1299
|
+
headers: {
|
|
1300
|
+
"Content-Type": "application/json",
|
|
1301
|
+
Authorization: `Bearer ${token}`
|
|
1302
|
+
},
|
|
1303
|
+
body: JSON.stringify({
|
|
1304
|
+
url: "https://bigquery.googleapis.com/bigquery/v2/projects",
|
|
1305
|
+
method: "GET"
|
|
1306
|
+
}),
|
|
1307
|
+
signal: controller.signal
|
|
1308
|
+
});
|
|
1309
|
+
const data = await response.json();
|
|
1310
|
+
if (!response.ok) {
|
|
1311
|
+
const errorMessage = typeof data?.error === "string" ? data.error : typeof data?.message === "string" ? data.message : `HTTP ${response.status} ${response.statusText}`;
|
|
1312
|
+
return { success: false, error: errorMessage };
|
|
1313
|
+
}
|
|
1314
|
+
const projects = (data.projects ?? []).map((p) => ({
|
|
1315
|
+
projectId: p.projectReference?.projectId ?? "",
|
|
1316
|
+
friendlyName: p.friendlyName ?? p.projectReference?.projectId ?? ""
|
|
1317
|
+
})).filter((p) => p.projectId !== "");
|
|
1318
|
+
return { success: true, projects };
|
|
1319
|
+
} finally {
|
|
1320
|
+
clearTimeout(timeout);
|
|
1321
|
+
}
|
|
1322
|
+
} catch (err) {
|
|
1323
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
1324
|
+
return { success: false, error: msg };
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1327
|
+
});
|
|
1328
|
+
|
|
1221
1329
|
// src/connectors/bigquery-oauth/setup.ts
|
|
1330
|
+
var listProjectsToolName2 = `bigquery-oauth_${listProjectsTool2.name}`;
|
|
1222
1331
|
var bigquerySetup2 = new ConnectorSetup({
|
|
1223
1332
|
ja: `## BigQuery \u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u624B\u9806
|
|
1224
1333
|
|
|
@@ -1226,8 +1335,8 @@ var bigquerySetup2 = new ConnectorSetup({
|
|
|
1226
1335
|
|
|
1227
1336
|
### \u624B\u9806
|
|
1228
1337
|
|
|
1229
|
-
#### \u30B9\u30C6\u30C3\
|
|
1230
|
-
1. \`
|
|
1338
|
+
#### \u30B9\u30C6\u30C3\u30D71: \u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u9078\u629E
|
|
1339
|
+
1. \`${listProjectsToolName2}\` \u3092\u547C\u3073\u51FA\u3057\u3066\u3001OAuth\u3067\u30A2\u30AF\u30BB\u30B9\u53EF\u80FD\u306AGCP\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u4E00\u89A7\u3092\u53D6\u5F97\u3059\u308B
|
|
1231
1340
|
2. \u7D50\u679C\u306B\u5FDC\u3058\u3066\u5206\u5C90:
|
|
1232
1341
|
- **\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u304C2\u3064\u4EE5\u4E0A**: \`askUserQuestion\`\uFF08multiSelect: false\uFF09\u3067\u30E6\u30FC\u30B6\u30FC\u306B\u63D0\u793A\u3057\u3001\u4F7F\u7528\u3059\u308B\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u3092\u9078\u629E\u3055\u305B\u308B\u3002\u9078\u629E\u80A2\u306E label \u306F \`\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u540D (id: \u30D7\u30ED\u30B8\u30A7\u30AF\u30C8ID)\` \u306E\u5F62\u5F0F\u306B\u3059\u308B
|
|
1233
1342
|
- **\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u304C1\u3064\u3060\u3051**: askUserQuestion \u306F\u4F7F\u308F\u305A\u81EA\u52D5\u63A1\u7528\u3002\u300C\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8 X \u3092\u81EA\u52D5\u9078\u629E\u3057\u307E\u3057\u305F\u300D\u30681\u6587\u3060\u3051\u66F8\u304F
|
|
@@ -1235,23 +1344,22 @@ var bigquerySetup2 = new ConnectorSetup({
|
|
|
1235
1344
|
- \`parameterSlug\`: \`"project-id"\`
|
|
1236
1345
|
- \`value\`: \u30D7\u30ED\u30B8\u30A7\u30AF\u30C8ID
|
|
1237
1346
|
- \`displayValue\`: \`"\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u540D (id: \u30D7\u30ED\u30B8\u30A7\u30AF\u30C8ID)"\`
|
|
1238
|
-
4. \u7D9A\u884C\u30E1\u30C3\u30BB\u30FC\u30B8\u3092\u53D7\u3051\u53D6\u3063\u305F\u3089\u3001\u30B9\u30C6\u30C3\
|
|
1347
|
+
4. \u7D9A\u884C\u30E1\u30C3\u30BB\u30FC\u30B8\u3092\u53D7\u3051\u53D6\u3063\u305F\u3089\u3001\u30B9\u30C6\u30C3\u30D72\u306B\u9032\u3080
|
|
1239
1348
|
|
|
1240
|
-
#### \u30B9\u30C6\u30C3\
|
|
1349
|
+
#### \u30B9\u30C6\u30C3\u30D72: \u30C7\u30FC\u30BF\u30BB\u30C3\u30C8\u9078\u629E
|
|
1241
1350
|
1. \`SELECT schema_name FROM INFORMATION_SCHEMA.SCHEMATA\` \u3092\u5B9F\u884C\u3057\u3066\u30C7\u30FC\u30BF\u30BB\u30C3\u30C8\u4E00\u89A7\u3092\u53D6\u5F97\u3059\u308B
|
|
1242
1351
|
2. \u7D50\u679C\u306B\u5FDC\u3058\u3066\u5206\u5C90:
|
|
1243
1352
|
- **\u30C7\u30FC\u30BF\u30BB\u30C3\u30C8\u304C2\u3064\u4EE5\u4E0A**: \`askUserQuestion\`\uFF08multiSelect: true\uFF09\u3067\u30E6\u30FC\u30B6\u30FC\u306B\u63D0\u793A\u3057\u3001\u4F7F\u7528\u3059\u308B\u30C7\u30FC\u30BF\u30BB\u30C3\u30C8\u3092\u9078\u629E\u3055\u305B\u308B
|
|
1244
1353
|
- **\u30C7\u30FC\u30BF\u30BB\u30C3\u30C8\u304C1\u3064\u3060\u3051**: askUserQuestion \u306F\u4F7F\u308F\u305A\u81EA\u52D5\u63A1\u7528\u3002\u300C\u30C7\u30FC\u30BF\u30BB\u30C3\u30C8 X \u3092\u81EA\u52D5\u9078\u629E\u3057\u307E\u3057\u305F\u300D\u30681\u6587\u3060\u3051\u66F8\u304F
|
|
1245
1354
|
|
|
1246
|
-
#### \u30B9\u30C6\u30C3\
|
|
1355
|
+
#### \u30B9\u30C6\u30C3\u30D73: \u30C6\u30FC\u30D6\u30EB\u9078\u629E
|
|
1247
1356
|
3. \u9078\u629E\u3055\u308C\u305F\u30C7\u30FC\u30BF\u30BB\u30C3\u30C8\u306B\u5BFE\u3057\u3066 \`SELECT table_name FROM \\\`{project}.{dataset}.INFORMATION_SCHEMA.TABLES\\\`\` \u3092\u5B9F\u884C\u3057\u3066\u30C6\u30FC\u30D6\u30EB\u4E00\u89A7\u3092\u53D6\u5F97\u3059\u308B\uFF08\u8907\u6570\u30C7\u30FC\u30BF\u30BB\u30C3\u30C8\u306E\u5834\u5408\u306F UNION ALL \u3067\u4E00\u62EC\u53D6\u5F97\uFF09
|
|
1248
1357
|
4. \u7D50\u679C\u306B\u5FDC\u3058\u3066\u5206\u5C90:
|
|
1249
1358
|
- **\u30C6\u30FC\u30D6\u30EB\u304C2\u3064\u4EE5\u4E0A**: \`askUserQuestion\`\uFF08multiSelect: true\uFF09\u3067\u30E6\u30FC\u30B6\u30FC\u306B\u63D0\u793A\u3057\u3001\u4F7F\u7528\u3059\u308B\u30C6\u30FC\u30D6\u30EB\u3092\u9078\u629E\u3055\u305B\u308B\u3002description \u306B\u306F\u30C7\u30FC\u30BF\u30BB\u30C3\u30C8\u540D\u3092\u8A18\u8F09\u3059\u308B
|
|
1250
1359
|
- **\u30C6\u30FC\u30D6\u30EB\u304C1\u3064\u3060\u3051**: askUserQuestion \u306F\u4F7F\u308F\u305A\u81EA\u52D5\u63A1\u7528
|
|
1251
1360
|
|
|
1252
|
-
#### \u30B9\u30C6\u30C3\
|
|
1361
|
+
#### \u30B9\u30C6\u30C3\u30D74: \u4FDD\u5B58
|
|
1253
1362
|
5. \`updateConnectionContext\` \u3067\u4EE5\u4E0B\u3092\u4FDD\u5B58\u3059\u308B:
|
|
1254
|
-
- \`project\`: BigQuery\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8ID
|
|
1255
1363
|
- \`dataset\`: \u9078\u629E\u3055\u308C\u305F\u30C7\u30FC\u30BF\u30BB\u30C3\u30C8\u540D\uFF08\u8907\u6570\u306E\u5834\u5408\u306F\u30AB\u30F3\u30DE\u533A\u5207\u308A\uFF09
|
|
1256
1364
|
- \`tables\`: \u9078\u629E\u3055\u308C\u305F\u30C6\u30FC\u30D6\u30EB\u540D\uFF08\u8907\u6570\u306E\u5834\u5408\u306F\u30AB\u30F3\u30DE\u533A\u5207\u308A\uFF09
|
|
1257
1365
|
- \`note\`: \u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u5185\u5BB9\u306E\u7C21\u5358\u306A\u8AAC\u660E
|
|
@@ -1269,8 +1377,8 @@ Follow these steps to set up the BigQuery connection.
|
|
|
1269
1377
|
|
|
1270
1378
|
### Steps
|
|
1271
1379
|
|
|
1272
|
-
#### Step
|
|
1273
|
-
1. Call \`
|
|
1380
|
+
#### Step 1: Project Selection
|
|
1381
|
+
1. Call \`${listProjectsToolName2}\` to get the list of GCP projects accessible with the OAuth credentials
|
|
1274
1382
|
2. Branch based on results:
|
|
1275
1383
|
- **2 or more projects**: Present them to the user via \`askUserQuestion\` (multiSelect: false) and let them select a project. Format option labels as \`Project Name (id: project-id)\`
|
|
1276
1384
|
- **Exactly 1 project**: Do NOT call askUserQuestion. Auto-select it. Just write "Auto-selected project X" in one sentence
|
|
@@ -1278,23 +1386,22 @@ Follow these steps to set up the BigQuery connection.
|
|
|
1278
1386
|
- \`parameterSlug\`: \`"project-id"\`
|
|
1279
1387
|
- \`value\`: the project ID
|
|
1280
1388
|
- \`displayValue\`: \`"Project Name (id: project-id)"\`
|
|
1281
|
-
4. After receiving the continuation message, proceed to Step
|
|
1389
|
+
4. After receiving the continuation message, proceed to Step 2
|
|
1282
1390
|
|
|
1283
|
-
#### Step
|
|
1391
|
+
#### Step 2: Dataset Selection
|
|
1284
1392
|
1. Run \`SELECT schema_name FROM INFORMATION_SCHEMA.SCHEMATA\` to get the list of datasets
|
|
1285
1393
|
2. Branch based on results:
|
|
1286
1394
|
- **2 or more datasets**: Present them to the user via \`askUserQuestion\` (multiSelect: true) and let them select which datasets to use
|
|
1287
1395
|
- **Exactly 1 dataset**: Do NOT call askUserQuestion. Auto-select it. Just write "Auto-selected dataset X" in one sentence
|
|
1288
1396
|
|
|
1289
|
-
#### Step
|
|
1397
|
+
#### Step 3: Table Selection
|
|
1290
1398
|
3. For the selected dataset(s), run \`SELECT table_name FROM \\\`{project}.{dataset}.INFORMATION_SCHEMA.TABLES\\\`\` to get the table list (use UNION ALL for multiple datasets)
|
|
1291
1399
|
4. Branch based on results:
|
|
1292
1400
|
- **2 or more tables**: Present them to the user via \`askUserQuestion\` (multiSelect: true) and let them select which tables to use. Include the dataset name in the description
|
|
1293
1401
|
- **Exactly 1 table**: Do NOT call askUserQuestion. Auto-select it
|
|
1294
1402
|
|
|
1295
|
-
#### Step
|
|
1403
|
+
#### Step 4: Save
|
|
1296
1404
|
5. Call \`updateConnectionContext\` to save:
|
|
1297
|
-
- \`project\`: BigQuery project ID
|
|
1298
1405
|
- \`dataset\`: Selected dataset name(s) (comma-separated if multiple)
|
|
1299
1406
|
- \`tables\`: Selected table name(s) (comma-separated if multiple)
|
|
1300
1407
|
- \`note\`: Brief description of the setup
|
|
@@ -1322,13 +1429,13 @@ var parameters6 = {
|
|
|
1322
1429
|
};
|
|
1323
1430
|
|
|
1324
1431
|
// src/connectors/bigquery-oauth/tools/execute-query.ts
|
|
1325
|
-
import { z as
|
|
1432
|
+
import { z as z8 } from "zod";
|
|
1326
1433
|
var MAX_ROWS6 = 500;
|
|
1327
|
-
var
|
|
1328
|
-
var
|
|
1329
|
-
async function
|
|
1330
|
-
if (
|
|
1331
|
-
return
|
|
1434
|
+
var REQUEST_TIMEOUT_MS2 = 6e4;
|
|
1435
|
+
var cachedToken2 = null;
|
|
1436
|
+
async function getProxyToken2(config) {
|
|
1437
|
+
if (cachedToken2 && cachedToken2.expiresAt > Date.now() + 6e4) {
|
|
1438
|
+
return cachedToken2.token;
|
|
1332
1439
|
}
|
|
1333
1440
|
const url = `${config.appApiBaseUrl}/v0/database/${config.projectId}/environment/${config.environmentId}/oauth-request-proxy-token`;
|
|
1334
1441
|
const res = await fetch(url, {
|
|
@@ -1348,31 +1455,31 @@ async function getProxyToken(config) {
|
|
|
1348
1455
|
throw new Error(`Failed to get proxy token: HTTP ${res.status} ${errorText}`);
|
|
1349
1456
|
}
|
|
1350
1457
|
const data = await res.json();
|
|
1351
|
-
|
|
1458
|
+
cachedToken2 = {
|
|
1352
1459
|
token: data.token,
|
|
1353
1460
|
expiresAt: new Date(data.expiresAt).getTime()
|
|
1354
1461
|
};
|
|
1355
1462
|
return data.token;
|
|
1356
1463
|
}
|
|
1357
|
-
var
|
|
1358
|
-
toolUseIntent:
|
|
1464
|
+
var inputSchema8 = z8.object({
|
|
1465
|
+
toolUseIntent: z8.string().optional().describe(
|
|
1359
1466
|
"Brief description of what you intend to accomplish with this tool call"
|
|
1360
1467
|
),
|
|
1361
|
-
connectionId:
|
|
1362
|
-
sql:
|
|
1468
|
+
connectionId: z8.string().describe("ID of the BigQuery OAuth connection to use"),
|
|
1469
|
+
sql: z8.string().describe(
|
|
1363
1470
|
"BigQuery SQL (GoogleSQL) query. Use backtick-quoted fully qualified names `project.dataset.table` for table references."
|
|
1364
1471
|
)
|
|
1365
1472
|
});
|
|
1366
|
-
var
|
|
1367
|
-
|
|
1368
|
-
success:
|
|
1369
|
-
rowCount:
|
|
1370
|
-
truncated:
|
|
1371
|
-
rows:
|
|
1473
|
+
var outputSchema8 = z8.discriminatedUnion("success", [
|
|
1474
|
+
z8.object({
|
|
1475
|
+
success: z8.literal(true),
|
|
1476
|
+
rowCount: z8.number(),
|
|
1477
|
+
truncated: z8.boolean(),
|
|
1478
|
+
rows: z8.array(z8.record(z8.string(), z8.unknown()))
|
|
1372
1479
|
}),
|
|
1373
|
-
|
|
1374
|
-
success:
|
|
1375
|
-
error:
|
|
1480
|
+
z8.object({
|
|
1481
|
+
success: z8.literal(false),
|
|
1482
|
+
error: z8.string()
|
|
1376
1483
|
})
|
|
1377
1484
|
]);
|
|
1378
1485
|
function parseQueryResponse(data) {
|
|
@@ -1393,8 +1500,8 @@ var executeQueryTool6 = new ConnectorTool({
|
|
|
1393
1500
|
description: `Execute SQL against BigQuery via OAuth. Returns up to ${MAX_ROWS6} rows.
|
|
1394
1501
|
Use for: schema exploration (INFORMATION_SCHEMA), data sampling, analytical queries.
|
|
1395
1502
|
Avoid loading large amounts of data; always include LIMIT in queries.`,
|
|
1396
|
-
inputSchema:
|
|
1397
|
-
outputSchema:
|
|
1503
|
+
inputSchema: inputSchema8,
|
|
1504
|
+
outputSchema: outputSchema8,
|
|
1398
1505
|
async execute({ connectionId, sql }, connections, config) {
|
|
1399
1506
|
const connection = connections.find((c) => c.id === connectionId);
|
|
1400
1507
|
if (!connection) {
|
|
@@ -1408,11 +1515,11 @@ Avoid loading large amounts of data; always include LIMIT in queries.`,
|
|
|
1408
1515
|
`[connector-query] bigquery-oauth/${connection.name}: ${sql}`
|
|
1409
1516
|
);
|
|
1410
1517
|
try {
|
|
1411
|
-
const token = await
|
|
1518
|
+
const token = await getProxyToken2(config.oauthProxy);
|
|
1412
1519
|
const proxyUrl = `https://${config.oauthProxy.sandboxId}.${config.oauthProxy.previewBaseDomain}/_sqcore/connections/${connectionId}/request`;
|
|
1413
1520
|
const queryUrl = `https://bigquery.googleapis.com/bigquery/v2/projects/${gcpProjectId}/queries`;
|
|
1414
1521
|
const controller = new AbortController();
|
|
1415
|
-
const timeout = setTimeout(() => controller.abort(),
|
|
1522
|
+
const timeout = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS2);
|
|
1416
1523
|
try {
|
|
1417
1524
|
const response = await fetch(proxyUrl, {
|
|
1418
1525
|
method: "POST",
|
|
@@ -1450,113 +1557,6 @@ Avoid loading large amounts of data; always include LIMIT in queries.`,
|
|
|
1450
1557
|
}
|
|
1451
1558
|
});
|
|
1452
1559
|
|
|
1453
|
-
// src/connectors/bigquery-oauth/tools/list-projects.ts
|
|
1454
|
-
import { z as z8 } from "zod";
|
|
1455
|
-
var REQUEST_TIMEOUT_MS2 = 6e4;
|
|
1456
|
-
var cachedToken2 = null;
|
|
1457
|
-
async function getProxyToken2(config) {
|
|
1458
|
-
if (cachedToken2 && cachedToken2.expiresAt > Date.now() + 6e4) {
|
|
1459
|
-
return cachedToken2.token;
|
|
1460
|
-
}
|
|
1461
|
-
const url = `${config.appApiBaseUrl}/v0/database/${config.projectId}/environment/${config.environmentId}/oauth-request-proxy-token`;
|
|
1462
|
-
const res = await fetch(url, {
|
|
1463
|
-
method: "POST",
|
|
1464
|
-
headers: {
|
|
1465
|
-
"Content-Type": "application/json",
|
|
1466
|
-
"x-api-key": config.appApiKey,
|
|
1467
|
-
"project-id": config.projectId
|
|
1468
|
-
},
|
|
1469
|
-
body: JSON.stringify({
|
|
1470
|
-
sandboxId: config.sandboxId,
|
|
1471
|
-
issuedBy: "coding-agent"
|
|
1472
|
-
})
|
|
1473
|
-
});
|
|
1474
|
-
if (!res.ok) {
|
|
1475
|
-
const errorText = await res.text().catch(() => res.statusText);
|
|
1476
|
-
throw new Error(`Failed to get proxy token: HTTP ${res.status} ${errorText}`);
|
|
1477
|
-
}
|
|
1478
|
-
const data = await res.json();
|
|
1479
|
-
cachedToken2 = {
|
|
1480
|
-
token: data.token,
|
|
1481
|
-
expiresAt: new Date(data.expiresAt).getTime()
|
|
1482
|
-
};
|
|
1483
|
-
return data.token;
|
|
1484
|
-
}
|
|
1485
|
-
var inputSchema8 = z8.object({
|
|
1486
|
-
toolUseIntent: z8.string().optional().describe(
|
|
1487
|
-
"Brief description of what you intend to accomplish with this tool call"
|
|
1488
|
-
),
|
|
1489
|
-
connectionId: z8.string().describe("ID of the BigQuery OAuth connection to use")
|
|
1490
|
-
});
|
|
1491
|
-
var outputSchema8 = z8.discriminatedUnion("success", [
|
|
1492
|
-
z8.object({
|
|
1493
|
-
success: z8.literal(true),
|
|
1494
|
-
projects: z8.array(
|
|
1495
|
-
z8.object({
|
|
1496
|
-
projectId: z8.string(),
|
|
1497
|
-
friendlyName: z8.string()
|
|
1498
|
-
})
|
|
1499
|
-
)
|
|
1500
|
-
}),
|
|
1501
|
-
z8.object({
|
|
1502
|
-
success: z8.literal(false),
|
|
1503
|
-
error: z8.string()
|
|
1504
|
-
})
|
|
1505
|
-
]);
|
|
1506
|
-
var listProjectsTool2 = new ConnectorTool({
|
|
1507
|
-
name: "listProjects",
|
|
1508
|
-
description: `List GCP projects accessible with the current OAuth credentials. Returns project IDs and friendly names.`,
|
|
1509
|
-
inputSchema: inputSchema8,
|
|
1510
|
-
outputSchema: outputSchema8,
|
|
1511
|
-
async execute({ connectionId }, connections, config) {
|
|
1512
|
-
const connection = connections.find((c) => c.id === connectionId);
|
|
1513
|
-
if (!connection) {
|
|
1514
|
-
return {
|
|
1515
|
-
success: false,
|
|
1516
|
-
error: `Connection ${connectionId} not found`
|
|
1517
|
-
};
|
|
1518
|
-
}
|
|
1519
|
-
console.log(
|
|
1520
|
-
`[connector-query] bigquery-oauth/${connection.name}: listProjects`
|
|
1521
|
-
);
|
|
1522
|
-
try {
|
|
1523
|
-
const token = await getProxyToken2(config.oauthProxy);
|
|
1524
|
-
const proxyUrl = `https://${config.oauthProxy.sandboxId}.${config.oauthProxy.previewBaseDomain}/_sqcore/connections/${connectionId}/request`;
|
|
1525
|
-
const controller = new AbortController();
|
|
1526
|
-
const timeout = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS2);
|
|
1527
|
-
try {
|
|
1528
|
-
const response = await fetch(proxyUrl, {
|
|
1529
|
-
method: "POST",
|
|
1530
|
-
headers: {
|
|
1531
|
-
"Content-Type": "application/json",
|
|
1532
|
-
Authorization: `Bearer ${token}`
|
|
1533
|
-
},
|
|
1534
|
-
body: JSON.stringify({
|
|
1535
|
-
url: "https://bigquery.googleapis.com/bigquery/v2/projects",
|
|
1536
|
-
method: "GET"
|
|
1537
|
-
}),
|
|
1538
|
-
signal: controller.signal
|
|
1539
|
-
});
|
|
1540
|
-
const data = await response.json();
|
|
1541
|
-
if (!response.ok) {
|
|
1542
|
-
const errorMessage = typeof data?.error === "string" ? data.error : typeof data?.message === "string" ? data.message : `HTTP ${response.status} ${response.statusText}`;
|
|
1543
|
-
return { success: false, error: errorMessage };
|
|
1544
|
-
}
|
|
1545
|
-
const projects = (data.projects ?? []).map((p) => ({
|
|
1546
|
-
projectId: p.projectReference?.projectId ?? "",
|
|
1547
|
-
friendlyName: p.friendlyName ?? p.projectReference?.projectId ?? ""
|
|
1548
|
-
})).filter((p) => p.projectId !== "");
|
|
1549
|
-
return { success: true, projects };
|
|
1550
|
-
} finally {
|
|
1551
|
-
clearTimeout(timeout);
|
|
1552
|
-
}
|
|
1553
|
-
} catch (err) {
|
|
1554
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
1555
|
-
return { success: false, error: msg };
|
|
1556
|
-
}
|
|
1557
|
-
}
|
|
1558
|
-
});
|
|
1559
|
-
|
|
1560
1560
|
// src/connectors/bigquery-oauth/index.ts
|
|
1561
1561
|
var tools6 = { executeQuery: executeQueryTool6, listProjects: listProjectsTool2 };
|
|
1562
1562
|
function parseQueryResponse2(data) {
|