@squadbase/connectors 0.0.2 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@squadbase/connectors",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "Squadbase Connectors",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -9,23 +9,18 @@
9
9
  ".": {
10
10
  "types": "./dist/index.d.ts",
11
11
  "default": "./dist/index.js"
12
- },
13
- "./ui": {
14
- "types": "./dist/index.ui.d.ts",
15
- "default": "./dist/index.ui.js"
16
12
  }
17
13
  },
18
14
  "files": [
19
15
  "dist"
20
16
  ],
17
+ "publishConfig": {
18
+ "access": "public"
19
+ },
21
20
  "repository": {
22
21
  "type": "git",
23
22
  "url": "https://github.com/squadbase/squadbase-connectors"
24
23
  },
25
- "publishConfig": {
26
- "access": "public",
27
- "registry": "https://registry.npmjs.org/"
28
- },
29
24
  "scripts": {
30
25
  "build": "tsup",
31
26
  "add-connector": "tsx scripts/add-connector.ts",
@@ -37,34 +32,33 @@
37
32
  },
38
33
  "peerDependencies": {
39
34
  "ai": "^6.0.0",
40
- "react": "^18.0.0 || ^19.0.0",
41
- "zod": "^3.19.0"
35
+ "zod": "^3.19.0 || ^4.0.0"
42
36
  },
43
37
  "peerDependenciesMeta": {
44
38
  "ai": {
45
39
  "optional": true
46
- },
47
- "react": {
48
- "optional": true
49
40
  }
50
41
  },
51
42
  "devDependencies": {
43
+ "@aws-sdk/client-athena": "^3.1007.0",
44
+ "@aws-sdk/client-redshift-data": "^3.1007.0",
45
+ "@databricks/sql": "^1.13.0",
46
+ "@google-cloud/bigquery": "^8.1.1",
52
47
  "@kintone/rest-api-client": "^6.1.1",
53
48
  "@squadbase/dashboard-types": "2.0.77",
54
49
  "@types/node": "^20.19.6",
55
50
  "@types/pg": "^8.16.0",
56
- "@types/react": "^19.2.14",
57
51
  "ai": "^6.0.116",
58
52
  "dotenv-cli": "^11.0.0",
53
+ "google-auth-library": "^10.6.1",
54
+ "mysql2": "^3.19.1",
59
55
  "pg": "^8.18.0",
60
- "react": "^19.2.4",
61
56
  "snowflake-sdk": "^2.3.4",
62
- "strip-json-comments": "^5.0.3",
63
57
  "tsup": "^8.5.1",
64
58
  "tsx": "^4.19.2",
65
59
  "typescript": "^5.3.3",
66
60
  "vitest": "^4.0.18",
67
- "zod": "^3.19.1"
61
+ "zod": "^4.3.6"
68
62
  },
69
63
  "engines": {
70
64
  "node": ">=18.0.0"
@@ -1,14 +0,0 @@
1
- import { ComponentType } from 'react';
2
-
3
- interface DynamicToolProps {
4
- toolName: string;
5
- state: string;
6
- input: unknown;
7
- output: unknown;
8
- errorText: string | undefined;
9
- onSuggest?: (prompt: string, newThread: boolean) => void;
10
- }
11
-
12
- declare function getToolComponent(connectorKey: string, toolName: string): ComponentType<DynamicToolProps> | undefined;
13
-
14
- export { getToolComponent };
package/dist/index.ui.js DELETED
@@ -1,387 +0,0 @@
1
- // src/connector-plugin.ts
2
- var ConnectorPlugin = class {
3
- slug;
4
- authType;
5
- name;
6
- description;
7
- iconUrl;
8
- order;
9
- parameters;
10
- releaseFlag;
11
- proxyPolicy;
12
- systemPrompt;
13
- tools;
14
- createClient;
15
- constructor(config) {
16
- this.slug = config.slug;
17
- this.authType = config.authType;
18
- this.name = config.name;
19
- this.description = config.description;
20
- this.iconUrl = config.iconUrl;
21
- this.order = config.order;
22
- this.parameters = config.parameters;
23
- this.releaseFlag = config.releaseFlag;
24
- this.proxyPolicy = config.proxyPolicy;
25
- this.systemPrompt = config.systemPrompt;
26
- this.tools = config.tools;
27
- this.createClient = config.createClient;
28
- }
29
- get connectorKey() {
30
- return this.authType ? `${this.slug}-${this.authType}` : this.slug;
31
- }
32
- };
33
-
34
- // src/auth-types.ts
35
- var AUTH_TYPES = {
36
- OAUTH: "oauth",
37
- API_KEY: "api-key",
38
- JWT: "jwt",
39
- SERVICE_ACCOUNT: "service-account",
40
- PAT: "pat"
41
- };
42
-
43
- // src/parameter-definition.ts
44
- var ParameterDefinition = class {
45
- slug;
46
- name;
47
- description;
48
- envVarBaseKey;
49
- type;
50
- secret;
51
- required;
52
- constructor(config) {
53
- this.slug = config.slug;
54
- this.name = config.name;
55
- this.description = config.description;
56
- this.envVarBaseKey = config.envVarBaseKey;
57
- this.type = config.type;
58
- this.secret = config.secret;
59
- this.required = config.required;
60
- }
61
- /**
62
- * Resolve a parameter value from a connection object (agent environment).
63
- */
64
- resolve(connection) {
65
- const param = connection.parameters.find((p) => p.slug === this.slug);
66
- if (!param || param.value == null) {
67
- throw new Error(
68
- `Parameter "${this.slug}" not found or has no value in connection "${connection.id}"`
69
- );
70
- }
71
- return param.value;
72
- }
73
- /**
74
- * Resolve the value of a connection parameter from environment variables (vite-server).
75
- */
76
- resolveEnvVar(entry, connectionId) {
77
- const envVarName = entry.envVars[this.slug];
78
- if (!envVarName) {
79
- throw new Error(
80
- `No env var mapping for parameter "${this.slug}" in connection "${connectionId}"`
81
- );
82
- }
83
- const value = process.env[envVarName];
84
- if (!value) {
85
- throw new Error(
86
- `Environment variable "${envVarName}" is not set (connection "${connectionId}", parameter "${this.slug}")`
87
- );
88
- }
89
- return value;
90
- }
91
- };
92
-
93
- // src/connectors/snowflake-pat/parameters.ts
94
- var parameters = {
95
- account: new ParameterDefinition({
96
- slug: "account",
97
- name: "Snowflake Account",
98
- description: "The Snowflake account identifier (e.g., xy12345.us-east-1).",
99
- envVarBaseKey: "SNOWFLAKE_ACCOUNT",
100
- type: "text",
101
- secret: false,
102
- required: true
103
- }),
104
- user: new ParameterDefinition({
105
- slug: "user",
106
- name: "Snowflake User",
107
- description: "The username for Snowflake authentication.",
108
- envVarBaseKey: "SNOWFLAKE_USER",
109
- type: "text",
110
- secret: false,
111
- required: true
112
- }),
113
- role: new ParameterDefinition({
114
- slug: "role",
115
- name: "Snowflake Role",
116
- description: "The role to use when connecting to Snowflake.",
117
- envVarBaseKey: "SNOWFLAKE_ROLE",
118
- type: "text",
119
- secret: false,
120
- required: true
121
- }),
122
- warehouse: new ParameterDefinition({
123
- slug: "warehouse",
124
- name: "Snowflake Warehouse",
125
- description: "The warehouse to use for executing queries.",
126
- envVarBaseKey: "SNOWFLAKE_WAREHOUSE",
127
- type: "text",
128
- secret: false,
129
- required: true
130
- }),
131
- pat: new ParameterDefinition({
132
- slug: "pat",
133
- name: "Personal Access Token",
134
- description: "Snowflake Personal Access Token (PAT) for authentication.",
135
- envVarBaseKey: "SNOWFLAKE_PASSWORD",
136
- type: "text",
137
- secret: true,
138
- required: true
139
- })
140
- };
141
-
142
- // src/connectors/snowflake-pat/tools/execute-query/tool.ts
143
- import { z } from "zod";
144
-
145
- // src/connector-tool.ts
146
- var ConnectorTool = class {
147
- name;
148
- description;
149
- inputSchema;
150
- outputSchema;
151
- _execute;
152
- constructor(config) {
153
- this.name = config.name;
154
- this.description = config.description;
155
- this.inputSchema = config.inputSchema;
156
- this.outputSchema = config.outputSchema;
157
- this._execute = config.execute;
158
- }
159
- createTool(connections, config) {
160
- return {
161
- description: this.description,
162
- inputSchema: this.inputSchema,
163
- outputSchema: this.outputSchema,
164
- execute: (input) => this._execute(input, connections, config)
165
- };
166
- }
167
- };
168
-
169
- // src/connectors/snowflake-pat/tools/execute-query/tool.ts
170
- var MAX_ROWS = 500;
171
- var QUERY_TIMEOUT_MS = 6e4;
172
- var inputSchema = z.object({
173
- toolUseIntent: z.string().optional().describe(
174
- "Brief description of what you intend to accomplish with this tool call"
175
- ),
176
- connectionId: z.string().describe("ID of the Snowflake connection to use"),
177
- sql: z.string().describe(
178
- "Snowflake SQL query. Use fully qualified names DB.SCHEMA.TABLE for table references."
179
- )
180
- });
181
- var outputSchema = z.discriminatedUnion("success", [
182
- z.object({
183
- success: z.literal(true),
184
- rowCount: z.number(),
185
- truncated: z.boolean(),
186
- rows: z.array(z.record(z.unknown()))
187
- }),
188
- z.object({
189
- success: z.literal(false),
190
- error: z.string()
191
- })
192
- ]);
193
- var executeQueryTool = new ConnectorTool({
194
- name: "executeQuery",
195
- description: `Execute SQL against Snowflake. Returns up to ${MAX_ROWS} rows.
196
- Use for: schema exploration (SHOW DATABASES/SCHEMAS/TABLES, DESCRIBE TABLE, INFORMATION_SCHEMA), data sampling, analytical queries.
197
- Avoid loading large amounts of data; always include LIMIT in queries.`,
198
- inputSchema,
199
- outputSchema,
200
- async execute({ connectionId, sql }, connections) {
201
- const connection = connections.find((c) => c.id === connectionId);
202
- if (!connection) {
203
- return {
204
- success: false,
205
- error: `Connection ${connectionId} not found`
206
- };
207
- }
208
- console.log(
209
- `[connector-query] snowflake-pat/${connection.name}: ${sql}`
210
- );
211
- try {
212
- const snowflake = (await import("snowflake-sdk")).default;
213
- snowflake.configure({ logLevel: "ERROR" });
214
- const account = parameters.account.resolve(connection);
215
- const user = parameters.user.resolve(connection);
216
- const role = parameters.role.resolve(connection);
217
- const warehouse = parameters.warehouse.resolve(connection);
218
- const password = parameters.pat.resolve(connection);
219
- const conn = snowflake.createConnection({
220
- account,
221
- username: user,
222
- role,
223
- warehouse,
224
- password
225
- });
226
- await new Promise((resolve, reject) => {
227
- conn.connect((err) => {
228
- if (err)
229
- reject(new Error(`Snowflake connect failed: ${err.message}`));
230
- else resolve();
231
- });
232
- });
233
- const allRows = await new Promise(
234
- (resolve, reject) => {
235
- const timeoutId = setTimeout(() => {
236
- reject(
237
- new Error(
238
- "Snowflake query timeout: query exceeded 60 seconds"
239
- )
240
- );
241
- }, QUERY_TIMEOUT_MS);
242
- conn.execute({
243
- sqlText: sql,
244
- complete: (err, _stmt, rows) => {
245
- clearTimeout(timeoutId);
246
- if (err)
247
- reject(new Error(`Snowflake query failed: ${err.message}`));
248
- else resolve(rows ?? []);
249
- }
250
- });
251
- }
252
- );
253
- conn.destroy((err) => {
254
- if (err)
255
- console.warn(
256
- `[connector-query] Snowflake destroy error: ${err.message}`
257
- );
258
- });
259
- const truncated = allRows.length > MAX_ROWS;
260
- return {
261
- success: true,
262
- rowCount: Math.min(allRows.length, MAX_ROWS),
263
- truncated,
264
- rows: allRows.slice(0, MAX_ROWS)
265
- };
266
- } catch (err) {
267
- const msg = err instanceof Error ? err.message : String(err);
268
- return { success: false, error: msg };
269
- }
270
- }
271
- });
272
-
273
- // src/connectors/snowflake-pat/index.ts
274
- var tools = [executeQueryTool];
275
- var snowflakePatConnector = new ConnectorPlugin({
276
- slug: "snowflake",
277
- authType: AUTH_TYPES.PAT,
278
- name: "Snowflake (PAT)",
279
- description: "Connect to Snowflake using a Personal Access Token (PAT).",
280
- iconUrl: "https://images.ctfassets.net/9ncizv60xc5y/6oyVtAcP3pMlXaOrts9unk/b7a9dc25d15c388b66e983041b855447/snowflake.svg",
281
- order: 11,
282
- parameters: Object.values(parameters),
283
- releaseFlag: { dev1: true, dev2: false, prod: false },
284
- systemPrompt: `## Snowflake SQL Notes
285
- - Use fully qualified names DB.SCHEMA.TABLE for table references
286
- - Schema exploration commands:
287
- - List databases: \`SHOW DATABASES\`
288
- - List schemas: \`SHOW SCHEMAS IN DATABASE db_name\`
289
- - List tables: \`SHOW TABLES IN SCHEMA db_name.schema_name\`
290
- - List columns: \`DESCRIBE TABLE db_name.schema_name.table_name\`
291
- - INFORMATION_SCHEMA is also available: \`SELECT * FROM db_name.INFORMATION_SCHEMA.TABLES\``,
292
- tools,
293
- createClient(entry, connectionId) {
294
- const account = parameters.account.resolveEnvVar(entry, connectionId);
295
- const user = parameters.user.resolveEnvVar(entry, connectionId);
296
- const role = parameters.role.resolveEnvVar(entry, connectionId);
297
- const warehouse = parameters.warehouse.resolveEnvVar(entry, connectionId);
298
- const password = parameters.pat.resolveEnvVar(entry, connectionId);
299
- return {
300
- async query(sql) {
301
- const snowflake = (await import("snowflake-sdk")).default;
302
- snowflake.configure({ logLevel: "ERROR" });
303
- const conn = snowflake.createConnection({
304
- account,
305
- username: user,
306
- role,
307
- warehouse,
308
- password
309
- });
310
- await new Promise((resolve, reject) => {
311
- conn.connect((err) => {
312
- if (err)
313
- reject(new Error(`Snowflake connect failed: ${err.message}`));
314
- else resolve();
315
- });
316
- });
317
- const rows = await new Promise(
318
- (resolve, reject) => {
319
- conn.execute({
320
- sqlText: sql,
321
- complete: (err, _stmt, rows2) => {
322
- if (err)
323
- reject(
324
- new Error(`Snowflake query failed: ${err.message}`)
325
- );
326
- else resolve(rows2 ?? []);
327
- }
328
- });
329
- }
330
- );
331
- conn.destroy((err) => {
332
- if (err)
333
- console.warn(
334
- `[connector-client] Snowflake destroy error: ${err.message}`
335
- );
336
- });
337
- return { rows };
338
- }
339
- };
340
- }
341
- });
342
-
343
- // src/connectors/snowflake-pat/tools/execute-query/ui.tsx
344
- import { jsx, jsxs } from "react/jsx-runtime";
345
- var ExecuteQueryToolComponent = ({
346
- state,
347
- input,
348
- output,
349
- errorText
350
- }) => {
351
- const inp = inputSchema.safeParse(input);
352
- const out = outputSchema.safeParse(output);
353
- const columns = out.success && out.data.success && out.data.rows.length > 0 ? Object.keys(out.data.rows[0]) : [];
354
- return /* @__PURE__ */ jsxs("div", { children: [
355
- inp.success && inp.data.sql && /* @__PURE__ */ jsx("pre", { style: { fontSize: 12, overflow: "auto", background: "#f5f5f5", padding: 8 }, children: /* @__PURE__ */ jsx("code", { children: inp.data.sql }) }),
356
- state === "output-available" && out.success && out.data.success && /* @__PURE__ */ jsxs("div", { style: { overflow: "auto" }, children: [
357
- /* @__PURE__ */ jsxs("table", { style: { fontSize: 12, borderCollapse: "collapse", width: "100%" }, children: [
358
- /* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsx("tr", { children: columns.map((col) => /* @__PURE__ */ jsx("th", { style: { borderBottom: "1px solid #ddd", padding: "4px 8px", textAlign: "left" }, children: col }, col)) }) }),
359
- /* @__PURE__ */ jsx("tbody", { children: out.data.rows.map((row, i) => /* @__PURE__ */ jsx("tr", { children: columns.map((col) => /* @__PURE__ */ jsx("td", { style: { borderBottom: "1px solid #eee", padding: "4px 8px" }, children: String(row[col] ?? "") }, col)) }, i)) })
360
- ] }),
361
- out.data.truncated && /* @__PURE__ */ jsxs("p", { style: { fontSize: 12, color: "#888" }, children: [
362
- "Showing ",
363
- out.data.rowCount,
364
- " rows (results truncated)"
365
- ] })
366
- ] }),
367
- out.success && !out.data.success && /* @__PURE__ */ jsx("p", { style: { fontSize: 12, color: "red" }, children: out.data.error }),
368
- errorText && /* @__PURE__ */ jsx("p", { style: { fontSize: 12, color: "red" }, children: errorText })
369
- ] });
370
- };
371
-
372
- // src/connectors/snowflake-pat/ui.ts
373
- var toolComponents = {
374
- executeQuery: ExecuteQueryToolComponent
375
- };
376
-
377
- // src/connectors/registry.ui.ts
378
- var registry = [
379
- { connector: snowflakePatConnector, components: toolComponents }
380
- ];
381
- function getToolComponent(connectorKey, toolName) {
382
- const entry = registry.find((e) => e.connector.connectorKey === connectorKey);
383
- return entry?.components[toolName];
384
- }
385
- export {
386
- getToolComponent
387
- };