@squadbase/vite-server 0.1.11-dev.0c78963 → 0.1.12-dev.8860f37

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.
@@ -0,0 +1,879 @@
1
+ // ../connectors/src/parameter-definition.ts
2
+ var ParameterDefinition = class {
3
+ slug;
4
+ name;
5
+ description;
6
+ envVarBaseKey;
7
+ type;
8
+ secret;
9
+ required;
10
+ constructor(config) {
11
+ this.slug = config.slug;
12
+ this.name = config.name;
13
+ this.description = config.description;
14
+ this.envVarBaseKey = config.envVarBaseKey;
15
+ this.type = config.type;
16
+ this.secret = config.secret;
17
+ this.required = config.required;
18
+ }
19
+ /**
20
+ * Get the parameter value from a ConnectorConnectionObject.
21
+ */
22
+ getValue(connection2) {
23
+ const param = connection2.parameters.find(
24
+ (p) => p.parameterSlug === this.slug
25
+ );
26
+ if (!param || param.value == null) {
27
+ throw new Error(
28
+ `Parameter "${this.slug}" not found or has no value in connection "${connection2.id}"`
29
+ );
30
+ }
31
+ return param.value;
32
+ }
33
+ /**
34
+ * Try to get the parameter value. Returns undefined if not found (for optional params).
35
+ */
36
+ tryGetValue(connection2) {
37
+ const param = connection2.parameters.find(
38
+ (p) => p.parameterSlug === this.slug
39
+ );
40
+ if (!param || param.value == null) return void 0;
41
+ return param.value;
42
+ }
43
+ };
44
+
45
+ // ../connectors/src/connectors/tableau/parameters.ts
46
+ var parameters = {
47
+ serverUrl: new ParameterDefinition({
48
+ slug: "server-url",
49
+ name: "Tableau Server URL",
50
+ description: "Base URL of your Tableau Cloud / Server instance (no trailing slash). Examples: https://us-east-1.online.tableau.com, https://prod-useast-a.online.tableau.com, https://tableau.example.com.",
51
+ envVarBaseKey: "TABLEAU_SERVER_URL",
52
+ type: "text",
53
+ secret: false,
54
+ required: true
55
+ }),
56
+ siteContentUrl: new ParameterDefinition({
57
+ slug: "site-content-url",
58
+ name: "Site Content URL",
59
+ description: "The site's content URL (the value after '/site/' in the Tableau URL). On Tableau Cloud this is required (e.g. 'mycompany'). On Tableau Server the Default site uses an empty string \u2014 pass an empty string explicitly.",
60
+ envVarBaseKey: "TABLEAU_SITE_CONTENT_URL",
61
+ type: "text",
62
+ secret: false,
63
+ required: true
64
+ }),
65
+ patName: new ParameterDefinition({
66
+ slug: "pat-name",
67
+ name: "Personal Access Token Name",
68
+ description: "Name of the Personal Access Token (PAT) generated under Account Settings > Personal Access Tokens. The owning user's site role determines the API permissions.",
69
+ envVarBaseKey: "TABLEAU_PAT_NAME",
70
+ type: "text",
71
+ secret: false,
72
+ required: true
73
+ }),
74
+ patSecret: new ParameterDefinition({
75
+ slug: "pat-secret",
76
+ name: "Personal Access Token Secret",
77
+ description: "Secret value shown once when the PAT is created. Tokens expire after 15 days of inactivity (default) and must be rotated regularly.",
78
+ envVarBaseKey: "TABLEAU_PAT_SECRET",
79
+ type: "text",
80
+ secret: true,
81
+ required: true
82
+ }),
83
+ apiVersion: new ParameterDefinition({
84
+ slug: "api-version",
85
+ name: "REST API Version",
86
+ description: "Optional Tableau REST API version (e.g., '3.28'). Defaults to '3.28' which works with current Tableau Cloud and recent Tableau Server releases. Use the version listed at https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_concepts_versions.htm if you need to pin.",
87
+ envVarBaseKey: "TABLEAU_API_VERSION",
88
+ type: "text",
89
+ secret: false,
90
+ required: false
91
+ })
92
+ };
93
+
94
+ // ../connectors/src/connectors/tableau/sdk/index.ts
95
+ var DEFAULT_API_VERSION = "3.28";
96
+ function createClient(params) {
97
+ const serverUrl = params[parameters.serverUrl.slug];
98
+ const siteContentUrl = params[parameters.siteContentUrl.slug];
99
+ const patName = params[parameters.patName.slug];
100
+ const patSecret = params[parameters.patSecret.slug];
101
+ const apiVersion = params[parameters.apiVersion.slug] || DEFAULT_API_VERSION;
102
+ if (!serverUrl || siteContentUrl == null || !patName || !patSecret) {
103
+ throw new Error(
104
+ `tableau: missing required parameters: ${parameters.serverUrl.slug}, ${parameters.siteContentUrl.slug}, ${parameters.patName.slug}, ${parameters.patSecret.slug}`
105
+ );
106
+ }
107
+ const baseUrl = `${serverUrl.replace(/\/$/, "")}/api/${apiVersion}`;
108
+ let session = null;
109
+ async function signIn2() {
110
+ const res = await fetch(`${baseUrl}/auth/signin`, {
111
+ method: "POST",
112
+ headers: {
113
+ "Content-Type": "application/json",
114
+ Accept: "application/json"
115
+ },
116
+ body: JSON.stringify({
117
+ credentials: {
118
+ personalAccessTokenName: patName,
119
+ personalAccessTokenSecret: patSecret,
120
+ site: { contentUrl: siteContentUrl }
121
+ }
122
+ })
123
+ });
124
+ if (!res.ok) {
125
+ const body = await res.text();
126
+ throw new Error(`tableau: sign-in failed (${res.status}): ${body}`);
127
+ }
128
+ const data = await res.json();
129
+ return {
130
+ authToken: data.credentials.token,
131
+ siteId: data.credentials.site.id,
132
+ userId: data.credentials.user.id,
133
+ expiresAt: Date.now() + 30 * 60 * 1e3
134
+ };
135
+ }
136
+ async function ensureSession() {
137
+ if (session && session.expiresAt > Date.now() + 6e4) {
138
+ return session;
139
+ }
140
+ session = await signIn2();
141
+ return session;
142
+ }
143
+ async function request(path2, init) {
144
+ const s = await ensureSession();
145
+ const resolvedPath = path2.replace(/\{siteId\}/g, s.siteId).replace(/^([^/])/, "/$1");
146
+ const url = `${baseUrl}${resolvedPath}`;
147
+ const headers = new Headers(init?.headers);
148
+ headers.set("X-Tableau-Auth", s.authToken);
149
+ if (!headers.has("Accept")) headers.set("Accept", "application/json");
150
+ if (!headers.has("Content-Type") && init?.body) {
151
+ headers.set("Content-Type", "application/json");
152
+ }
153
+ return fetch(url, { ...init, headers });
154
+ }
155
+ async function getJson(path2) {
156
+ const res = await request(path2);
157
+ if (!res.ok) {
158
+ const body = await res.text();
159
+ throw new Error(`tableau: GET ${path2} failed (${res.status}): ${body}`);
160
+ }
161
+ return await res.json();
162
+ }
163
+ function buildListQuery(options) {
164
+ const qs = new URLSearchParams();
165
+ if (options?.pageSize != null) qs.set("pageSize", String(options.pageSize));
166
+ if (options?.pageNumber != null)
167
+ qs.set("pageNumber", String(options.pageNumber));
168
+ if (options?.filter) qs.set("filter", options.filter);
169
+ if (options?.sort) qs.set("sort", options.sort);
170
+ const query = qs.toString();
171
+ return query ? `?${query}` : "";
172
+ }
173
+ return {
174
+ request,
175
+ async getSession() {
176
+ const s = await ensureSession();
177
+ return { authToken: s.authToken, siteId: s.siteId, userId: s.userId };
178
+ },
179
+ async listProjects(options) {
180
+ return getJson(
181
+ `/sites/{siteId}/projects${buildListQuery(options)}`
182
+ );
183
+ },
184
+ async listWorkbooks(options) {
185
+ return getJson(
186
+ `/sites/{siteId}/workbooks${buildListQuery(options)}`
187
+ );
188
+ },
189
+ async listViewsForWorkbook(workbookId) {
190
+ return getJson(
191
+ `/sites/{siteId}/workbooks/${encodeURIComponent(workbookId)}/views`
192
+ );
193
+ },
194
+ async listDatasources(options) {
195
+ return getJson(
196
+ `/sites/{siteId}/datasources${buildListQuery(options)}`
197
+ );
198
+ },
199
+ async getViewData(viewId) {
200
+ const res = await request(
201
+ `/sites/{siteId}/views/${encodeURIComponent(viewId)}/data`,
202
+ { headers: { Accept: "*/*" } }
203
+ );
204
+ if (!res.ok) {
205
+ const body = await res.text();
206
+ throw new Error(
207
+ `tableau: getViewData failed (${res.status}): ${body}`
208
+ );
209
+ }
210
+ return res.text();
211
+ }
212
+ };
213
+ }
214
+
215
+ // ../connectors/src/connector-onboarding.ts
216
+ var ConnectorOnboarding = class {
217
+ /** Phase 1: Connection setup instructions (optional — some connectors don't need this) */
218
+ connectionSetupInstructions;
219
+ /** Phase 2: Data overview instructions */
220
+ dataOverviewInstructions;
221
+ constructor(config) {
222
+ this.connectionSetupInstructions = config.connectionSetupInstructions;
223
+ this.dataOverviewInstructions = config.dataOverviewInstructions;
224
+ }
225
+ getConnectionSetupPrompt(language) {
226
+ return this.connectionSetupInstructions?.[language] ?? null;
227
+ }
228
+ getDataOverviewInstructions(language) {
229
+ return this.dataOverviewInstructions[language];
230
+ }
231
+ };
232
+
233
+ // ../connectors/src/connector-tool.ts
234
+ var ConnectorTool = class {
235
+ name;
236
+ description;
237
+ inputSchema;
238
+ outputSchema;
239
+ _execute;
240
+ constructor(config) {
241
+ this.name = config.name;
242
+ this.description = config.description;
243
+ this.inputSchema = config.inputSchema;
244
+ this.outputSchema = config.outputSchema;
245
+ this._execute = config.execute;
246
+ }
247
+ createTool(connections, config) {
248
+ return {
249
+ description: this.description,
250
+ inputSchema: this.inputSchema,
251
+ outputSchema: this.outputSchema,
252
+ execute: (input) => this._execute(input, connections, config)
253
+ };
254
+ }
255
+ };
256
+
257
+ // ../connectors/src/connector-plugin.ts
258
+ var ConnectorPlugin = class _ConnectorPlugin {
259
+ slug;
260
+ authType;
261
+ name;
262
+ description;
263
+ iconUrl;
264
+ parameters;
265
+ releaseFlag;
266
+ proxyPolicy;
267
+ experimentalAttributes;
268
+ categories;
269
+ onboarding;
270
+ systemPrompt;
271
+ tools;
272
+ query;
273
+ checkConnection;
274
+ constructor(config) {
275
+ this.slug = config.slug;
276
+ this.authType = config.authType;
277
+ this.name = config.name;
278
+ this.description = config.description;
279
+ this.iconUrl = config.iconUrl;
280
+ this.parameters = config.parameters;
281
+ this.releaseFlag = config.releaseFlag;
282
+ this.proxyPolicy = config.proxyPolicy;
283
+ this.experimentalAttributes = config.experimentalAttributes;
284
+ this.categories = config.categories ?? [];
285
+ this.onboarding = config.onboarding;
286
+ this.systemPrompt = config.systemPrompt;
287
+ this.tools = config.tools;
288
+ this.query = config.query;
289
+ this.checkConnection = config.checkConnection;
290
+ }
291
+ get connectorKey() {
292
+ return _ConnectorPlugin.deriveKey(this.slug, this.authType);
293
+ }
294
+ /**
295
+ * Create tools for connections that belong to this connector.
296
+ * Filters connections by connectorKey internally.
297
+ * Returns tools keyed as `${connectorKey}_${toolName}`.
298
+ */
299
+ createTools(connections, config, opts) {
300
+ const myConnections = connections.filter(
301
+ (c) => _ConnectorPlugin.deriveKey(c.connector.slug, c.connector.authType) === this.connectorKey
302
+ );
303
+ const result = {};
304
+ for (const t of Object.values(this.tools)) {
305
+ const tool = t.createTool(myConnections, config);
306
+ const originalToModelOutput = tool.toModelOutput;
307
+ result[`${this.connectorKey}_${t.name}`] = {
308
+ ...tool,
309
+ toModelOutput: async (options) => {
310
+ if (!originalToModelOutput) {
311
+ return opts.truncateOutput(options.output);
312
+ }
313
+ const modelOutput = await originalToModelOutput(options);
314
+ if (modelOutput.type === "text" || modelOutput.type === "json") {
315
+ return opts.truncateOutput(modelOutput.value);
316
+ }
317
+ return modelOutput;
318
+ }
319
+ };
320
+ }
321
+ return result;
322
+ }
323
+ static deriveKey(slug, authType) {
324
+ if (authType) return `${slug}-${authType}`;
325
+ const LEGACY_NULL_AUTH_TYPE_MAP = {
326
+ // user-password
327
+ "postgresql": "user-password",
328
+ "mysql": "user-password",
329
+ "clickhouse": "user-password",
330
+ "kintone": "user-password",
331
+ "squadbase-db": "user-password",
332
+ // service-account
333
+ "snowflake": "service-account",
334
+ "bigquery": "service-account",
335
+ "google-analytics": "service-account",
336
+ "google-calendar": "service-account",
337
+ "aws-athena": "service-account",
338
+ "redshift": "service-account",
339
+ // api-key
340
+ "databricks": "api-key",
341
+ "dbt": "api-key",
342
+ "airtable": "api-key",
343
+ "openai": "api-key",
344
+ "gemini": "api-key",
345
+ "anthropic": "api-key",
346
+ "wix-store": "api-key"
347
+ };
348
+ const fallbackAuthType = LEGACY_NULL_AUTH_TYPE_MAP[slug];
349
+ if (fallbackAuthType) return `${slug}-${fallbackAuthType}`;
350
+ return slug;
351
+ }
352
+ };
353
+
354
+ // ../connectors/src/auth-types.ts
355
+ var AUTH_TYPES = {
356
+ OAUTH: "oauth",
357
+ API_KEY: "api-key",
358
+ JWT: "jwt",
359
+ SERVICE_ACCOUNT: "service-account",
360
+ PAT: "pat",
361
+ USER_PASSWORD: "user-password"
362
+ };
363
+
364
+ // ../connectors/src/connectors/tableau/setup.ts
365
+ var tableauOnboarding = new ConnectorOnboarding({
366
+ connectionSetupInstructions: {
367
+ en: `Follow these steps to verify the Tableau PAT connection.
368
+
369
+ 1. Call \`tableau_request\` with \`method: "GET"\` and \`path: "/sites/{siteId}/projects?pageSize=5"\` to list a few projects on the signed-in site
370
+ 2. If the call fails with HTTP 401, ask the user to confirm the PAT name/secret and that the Site Content URL matches the site where the PAT was issued (Tableau Cloud sites are case-sensitive)
371
+
372
+ #### Constraints
373
+ - **Do NOT mutate Tableau resources during setup** (no publish/update/delete). Only the project listing above is allowed
374
+ - The literal placeholder \`{siteId}\` in the path is automatically replaced with the session's site ID \u2014 do NOT hardcode the ID`,
375
+ ja: `Tableau PAT \u30B3\u30CD\u30AF\u30B7\u30E7\u30F3\u306E\u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u306F\u4EE5\u4E0B\u306E\u624B\u9806\u3067\u884C\u3063\u3066\u304F\u3060\u3055\u3044\u3002
376
+
377
+ 1. \`tableau_request\` \u3092 \`method: "GET"\`\u3001\`path: "/sites/{siteId}/projects?pageSize=5"\` \u3067\u547C\u3073\u51FA\u3057\u3001\u30B5\u30A4\u30F3\u30A4\u30F3\u5148\u30B5\u30A4\u30C8\u306E\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u3092\u3044\u304F\u3064\u304B\u53D6\u5F97\u3059\u308B
378
+ 2. HTTP 401 \u3067\u5931\u6557\u3057\u305F\u5834\u5408\u306F\u3001PAT \u540D/\u30B7\u30FC\u30AF\u30EC\u30C3\u30C8\u304A\u3088\u3073 Site Content URL \u304C PAT \u767A\u884C\u30B5\u30A4\u30C8\u3068\u4E00\u81F4\u3057\u3066\u3044\u308B\u304B\u3092\u30E6\u30FC\u30B6\u30FC\u306B\u78BA\u8A8D\u3059\u308B\u3088\u3046\u4F1D\u3048\u308B\uFF08Tableau Cloud \u306E\u30B5\u30A4\u30C8\u540D\u306F\u5927\u6587\u5B57\u5C0F\u6587\u5B57\u3092\u533A\u5225\uFF09
379
+
380
+ #### \u5236\u7D04
381
+ - **\u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u4E2D\u306B Tableau \u30EA\u30BD\u30FC\u30B9\u3092\u5909\u66F4\u3057\u306A\u3044\u3053\u3068**\uFF08publish/update/delete \u4E0D\u53EF\uFF09\u3002\u4E0A\u8A18\u306E\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u4E00\u89A7\u53D6\u5F97\u306E\u307F\u8A31\u53EF
382
+ - \u30D1\u30B9\u5185\u306E\u30D7\u30EC\u30FC\u30B9\u30DB\u30EB\u30C0\u30FC \`{siteId}\` \u306F\u30BB\u30C3\u30B7\u30E7\u30F3\u306E\u30B5\u30A4\u30C8 ID \u3067\u81EA\u52D5\u7F6E\u63DB\u3055\u308C\u307E\u3059 \u2014 ID \u3092\u30CF\u30FC\u30C9\u30B3\u30FC\u30C9\u3057\u306A\u3044\u3053\u3068`
383
+ },
384
+ dataOverviewInstructions: {
385
+ en: `1. Call tableau_request with GET /sites/{siteId}/projects to list projects
386
+ 2. Call tableau_request with GET /sites/{siteId}/workbooks?pageSize=20 to list workbooks
387
+ 3. For a target workbook, call tableau_request with GET /sites/{siteId}/workbooks/{workbookId}/views to list its views
388
+ 4. Call tableau_request with GET /sites/{siteId}/datasources?pageSize=20 to list published data sources`,
389
+ ja: `1. tableau_request \u3067 GET /sites/{siteId}/projects \u3092\u547C\u3073\u51FA\u3057\u3001\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u4E00\u89A7\u3092\u53D6\u5F97
390
+ 2. tableau_request \u3067 GET /sites/{siteId}/workbooks?pageSize=20 \u3092\u547C\u3073\u51FA\u3057\u3001\u30EF\u30FC\u30AF\u30D6\u30C3\u30AF\u4E00\u89A7\u3092\u53D6\u5F97
391
+ 3. \u5BFE\u8C61\u30EF\u30FC\u30AF\u30D6\u30C3\u30AF\u306B\u3064\u3044\u3066 tableau_request \u3067 GET /sites/{siteId}/workbooks/{workbookId}/views \u3092\u547C\u3073\u51FA\u3057\u3001\u30D3\u30E5\u30FC\u4E00\u89A7\u3092\u53D6\u5F97
392
+ 4. tableau_request \u3067 GET /sites/{siteId}/datasources?pageSize=20 \u3092\u547C\u3073\u51FA\u3057\u3001\u516C\u958B\u30C7\u30FC\u30BF\u30BD\u30FC\u30B9\u4E00\u89A7\u3092\u53D6\u5F97`
393
+ }
394
+ });
395
+
396
+ // ../connectors/src/connectors/tableau/tools/request.ts
397
+ import { z } from "zod";
398
+ var DEFAULT_API_VERSION2 = "3.28";
399
+ var REQUEST_TIMEOUT_MS = 6e4;
400
+ var sessionCache = /* @__PURE__ */ new Map();
401
+ function buildBaseUrl(serverUrl, apiVersion) {
402
+ return `${serverUrl.replace(/\/$/, "")}/api/${apiVersion}`;
403
+ }
404
+ async function signIn(serverUrl, apiVersion, siteContentUrl, patName, patSecret) {
405
+ const url = `${buildBaseUrl(serverUrl, apiVersion)}/auth/signin`;
406
+ const body = {
407
+ credentials: {
408
+ personalAccessTokenName: patName,
409
+ personalAccessTokenSecret: patSecret,
410
+ site: { contentUrl: siteContentUrl }
411
+ }
412
+ };
413
+ const res = await fetch(url, {
414
+ method: "POST",
415
+ headers: {
416
+ "Content-Type": "application/json",
417
+ Accept: "application/json"
418
+ },
419
+ body: JSON.stringify(body)
420
+ });
421
+ if (!res.ok) {
422
+ const errorText = await res.text().catch(() => res.statusText);
423
+ throw new Error(
424
+ `Tableau sign-in failed: HTTP ${res.status} ${errorText}`
425
+ );
426
+ }
427
+ const data = await res.json();
428
+ return {
429
+ authToken: data.credentials.token,
430
+ siteId: data.credentials.site.id,
431
+ userId: data.credentials.user.id,
432
+ expiresAt: Date.now() + 30 * 60 * 1e3
433
+ };
434
+ }
435
+ async function getSession(serverUrl, apiVersion, siteContentUrl, patName, patSecret) {
436
+ const cacheKey = `${serverUrl}|${siteContentUrl}|${patName}`;
437
+ const cached = sessionCache.get(cacheKey);
438
+ if (cached && cached.expiresAt > Date.now() + 6e4) {
439
+ return cached;
440
+ }
441
+ const session = await signIn(
442
+ serverUrl,
443
+ apiVersion,
444
+ siteContentUrl,
445
+ patName,
446
+ patSecret
447
+ );
448
+ sessionCache.set(cacheKey, session);
449
+ return session;
450
+ }
451
+ var inputSchema = z.object({
452
+ toolUseIntent: z.string().optional().describe(
453
+ "Brief description of what you intend to accomplish with this tool call"
454
+ ),
455
+ connectionId: z.string().describe("ID of the Tableau connection to use"),
456
+ method: z.enum(["GET", "POST", "PUT", "DELETE"]).describe(
457
+ "HTTP method. GET for listing/reading, POST for creating, PUT for updates, DELETE for removal."
458
+ ),
459
+ path: z.string().describe(
460
+ "API path appended to {serverUrl}/api/{apiVersion} (e.g., '/sites/{siteId}/projects', '/sites/{siteId}/workbooks/{workbookId}', '/sites/{siteId}/views/{viewId}/data'). The {siteId} placeholder is automatically replaced with the signed-in site ID."
461
+ ),
462
+ queryParams: z.record(z.string(), z.string()).optional().describe(
463
+ "Query parameters to append (e.g., { pageSize: '100', filter: 'name:eq:Sales' }). Tableau supports field filtering via 'fields' and sorting via 'sort'."
464
+ ),
465
+ body: z.record(z.string(), z.unknown()).optional().describe(
466
+ "JSON request body for POST/PUT (Tableau also accepts XML, but JSON is recommended with Accept: application/json)."
467
+ )
468
+ });
469
+ var outputSchema = z.discriminatedUnion("success", [
470
+ z.object({
471
+ success: z.literal(true),
472
+ status: z.number(),
473
+ data: z.unknown()
474
+ }),
475
+ z.object({
476
+ success: z.literal(false),
477
+ error: z.string()
478
+ })
479
+ ]);
480
+ var requestTool = new ConnectorTool({
481
+ name: "request",
482
+ description: `Send authenticated requests to the Tableau REST API.
483
+ The tool signs in once with the configured Personal Access Token (PAT) to obtain an X-Tableau-Auth token (cached per connection), then forwards the request with the token attached.
484
+ All paths are relative to {serverUrl}/api/{apiVersion}. Use the literal placeholder \`{siteId}\` in the path \u2014 it is automatically substituted with the site ID returned from sign-in.
485
+ Accept and Content-Type headers default to application/json so list responses come back as JSON instead of Tableau's default XML.`,
486
+ inputSchema,
487
+ outputSchema,
488
+ async execute({ connectionId, method, path: path2, queryParams, body }, connections) {
489
+ const connection2 = connections.find((c) => c.id === connectionId);
490
+ if (!connection2) {
491
+ return {
492
+ success: false,
493
+ error: `Connection ${connectionId} not found`
494
+ };
495
+ }
496
+ console.log(
497
+ `[connector-request] tableau/${connection2.name}: ${method} ${path2}`
498
+ );
499
+ try {
500
+ const serverUrl = parameters.serverUrl.getValue(connection2);
501
+ const siteContentUrl = parameters.siteContentUrl.getValue(connection2);
502
+ const patName = parameters.patName.getValue(connection2);
503
+ const patSecret = parameters.patSecret.getValue(connection2);
504
+ const apiVersion = parameters.apiVersion.tryGetValue(connection2) || DEFAULT_API_VERSION2;
505
+ const session = await getSession(
506
+ serverUrl,
507
+ apiVersion,
508
+ siteContentUrl,
509
+ patName,
510
+ patSecret
511
+ );
512
+ const resolvedPath = path2.trim().replace(/\{siteId\}/g, session.siteId).replace(/^([^/])/, "/$1");
513
+ let url = `${buildBaseUrl(serverUrl, apiVersion)}${resolvedPath}`;
514
+ if (queryParams) {
515
+ const searchParams = new URLSearchParams(queryParams);
516
+ url += `?${searchParams.toString()}`;
517
+ }
518
+ const controller = new AbortController();
519
+ const timeout = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
520
+ try {
521
+ const init = {
522
+ method,
523
+ headers: {
524
+ "X-Tableau-Auth": session.authToken,
525
+ Accept: "application/json",
526
+ "Content-Type": "application/json"
527
+ },
528
+ signal: controller.signal
529
+ };
530
+ if (body !== void 0) {
531
+ init.body = JSON.stringify(body);
532
+ }
533
+ const response = await fetch(url, init);
534
+ const text = await response.text();
535
+ const data = text ? (() => {
536
+ try {
537
+ return JSON.parse(text);
538
+ } catch {
539
+ return text;
540
+ }
541
+ })() : null;
542
+ if (!response.ok) {
543
+ const errorMessage = data && typeof data === "object" && "error" in data ? JSON.stringify(data.error) : typeof data === "string" && data ? data : `HTTP ${response.status} ${response.statusText}`;
544
+ return { success: false, error: errorMessage };
545
+ }
546
+ return { success: true, status: response.status, data };
547
+ } finally {
548
+ clearTimeout(timeout);
549
+ }
550
+ } catch (err) {
551
+ const msg = err instanceof Error ? err.message : String(err);
552
+ return { success: false, error: msg };
553
+ }
554
+ }
555
+ });
556
+
557
+ // ../connectors/src/connectors/tableau/index.ts
558
+ var tools = { request: requestTool };
559
+ var tableauConnector = new ConnectorPlugin({
560
+ slug: "tableau",
561
+ authType: AUTH_TYPES.PAT,
562
+ name: "Tableau",
563
+ description: "Connect to Tableau Cloud or Tableau Server via a Personal Access Token (PAT). Use it to enumerate projects, workbooks, views, and data sources, and to pull view data.",
564
+ iconUrl: "https://upload.wikimedia.org/wikipedia/commons/4/4b/Tableau_Logo.png",
565
+ parameters,
566
+ releaseFlag: { dev1: true, dev2: false, prod: false },
567
+ categories: ["other"],
568
+ onboarding: tableauOnboarding,
569
+ systemPrompt: {
570
+ en: `### Tools
571
+
572
+ - \`tableau_request\`: The only way to call the Tableau REST API. Use it for projects, workbooks, views, data sources, users, and permissions. The tool signs in once with the configured PAT to obtain an \`X-Tableau-Auth\` token (cached), then forwards each request with the token attached. Use the literal \`{siteId}\` placeholder in the path \u2014 it is replaced with the session's site ID automatically.
573
+
574
+ ### Business Logic
575
+
576
+ The business logic type for this connector is "typescript". Use the connector SDK in your handler. Do NOT read credentials from environment variables.
577
+
578
+ SDK methods (client created via \`connection(connectionId)\`):
579
+ - \`client.request(path, init?)\` \u2014 low-level authenticated fetch (path is appended to \`{serverUrl}/api/{apiVersion}\`; \`{siteId}\` is substituted)
580
+ - \`client.getSession()\` \u2014 sign in (if needed) and return \`{ authToken, siteId, userId }\`
581
+ - \`client.listProjects(options?)\` / \`client.listWorkbooks(options?)\` / \`client.listDatasources(options?)\`
582
+ - \`client.listViewsForWorkbook(workbookId)\`
583
+ - \`client.getViewData(viewId)\` \u2014 returns the view's underlying data as CSV text
584
+
585
+ \`\`\`ts
586
+ import type { Context } from "hono";
587
+ import { connection } from "@squadbase/vite-server/connectors/tableau";
588
+
589
+ const tableau = connection("<connectionId>");
590
+
591
+ export default async function handler(c: Context) {
592
+ const { pageSize = 20 } = await c.req.json<{ pageSize?: number }>();
593
+ const { workbooks, pagination } = await tableau.listWorkbooks({ pageSize });
594
+ return c.json({
595
+ workbooks: workbooks.workbook,
596
+ totalAvailable: Number(pagination.totalAvailable),
597
+ });
598
+ }
599
+ \`\`\`
600
+
601
+ ### Tableau REST API Reference
602
+
603
+ - Base URL: \`{serverUrl}/api/{apiVersion}\` (default version 3.28; see https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_concepts_versions.htm)
604
+ - Authentication: Sign-in with a PAT returns \`X-Tableau-Auth\` token, site ID, and user ID. Sessions expire after ~240 minutes idle on Tableau Cloud
605
+ - Response format: JSON when \`Accept: application/json\` is sent (default); otherwise Tableau returns XML
606
+ - Pagination: \`?pageSize=&pageNumber=\` query params with \`pagination\` object in response
607
+
608
+ #### Common Endpoints
609
+ - POST \`/auth/signin\` \u2014 sign in (handled automatically)
610
+ - POST \`/auth/signout\` \u2014 sign out
611
+ - GET \`/sites/{siteId}/projects\` \u2014 list projects
612
+ - GET \`/sites/{siteId}/workbooks\` \u2014 list workbooks (supports \`filter\`, \`sort\`)
613
+ - GET \`/sites/{siteId}/workbooks/{workbookId}\` \u2014 get a workbook
614
+ - GET \`/sites/{siteId}/workbooks/{workbookId}/views\` \u2014 list views in a workbook
615
+ - GET \`/sites/{siteId}/views/{viewId}/data\` \u2014 get view data as CSV
616
+ - GET \`/sites/{siteId}/views/{viewId}/image\` \u2014 get view as PNG
617
+ - GET \`/sites/{siteId}/views/{viewId}/pdf\` \u2014 get view as PDF
618
+ - GET \`/sites/{siteId}/datasources\` \u2014 list published data sources
619
+ - GET \`/sites/{siteId}/users\` \u2014 list users
620
+ - GET \`/sites/{siteId}/groups\` \u2014 list groups
621
+
622
+ #### Filter Syntax
623
+ - \`filter=name:eq:Sales\` \u2014 exact match
624
+ - \`filter=name:in:[Sales,Marketing]\` \u2014 set membership
625
+ - \`filter=updatedAt:gte:2024-01-01T00:00:00Z\` \u2014 comparison operators (gt/gte/lt/lte)
626
+ - Combine: \`filter=ownerName:eq:alice,tags:in:[finance]\``,
627
+ ja: `### \u30C4\u30FC\u30EB
628
+
629
+ - \`tableau_request\`: Tableau REST API \u3092\u547C\u3073\u51FA\u3059\u552F\u4E00\u306E\u624B\u6BB5\u3067\u3059\u3002\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u3001\u30EF\u30FC\u30AF\u30D6\u30C3\u30AF\u3001\u30D3\u30E5\u30FC\u3001\u30C7\u30FC\u30BF\u30BD\u30FC\u30B9\u3001\u30E6\u30FC\u30B6\u30FC\u3001\u6A29\u9650\u306A\u3069\u306B\u4F7F\u7528\u3057\u307E\u3059\u3002\u8A2D\u5B9A\u3055\u308C\u305F PAT \u3067\u4E00\u5EA6\u30B5\u30A4\u30F3\u30A4\u30F3\u3057\u3066 \`X-Tableau-Auth\` \u30C8\u30FC\u30AF\u30F3\u3092\u53D6\u5F97 (\u30AD\u30E3\u30C3\u30B7\u30E5) \u3057\u3001\u5404\u30EA\u30AF\u30A8\u30B9\u30C8\u306B\u305D\u306E\u30C8\u30FC\u30AF\u30F3\u3092\u4ED8\u3051\u3066\u9001\u4FE1\u3057\u307E\u3059\u3002\u30D1\u30B9\u5185\u306B\u306F \`{siteId}\` \u30D7\u30EC\u30FC\u30B9\u30DB\u30EB\u30C0\u30FC\u3092\u4F7F\u3063\u3066\u304F\u3060\u3055\u3044 \u2014 \u30BB\u30C3\u30B7\u30E7\u30F3\u306E\u30B5\u30A4\u30C8 ID \u3067\u81EA\u52D5\u7F6E\u63DB\u3055\u308C\u307E\u3059\u3002
630
+
631
+ ### Business Logic
632
+
633
+ \u3053\u306E\u30B3\u30CD\u30AF\u30BF\u306E\u30D3\u30B8\u30CD\u30B9\u30ED\u30B8\u30C3\u30AF\u30BF\u30A4\u30D7\u306F "typescript" \u3067\u3059\u3002\u30CF\u30F3\u30C9\u30E9\u5185\u3067\u306F\u30B3\u30CD\u30AF\u30BF SDK \u3092\u4F7F\u7528\u3057\u3066\u304F\u3060\u3055\u3044\u3002\u74B0\u5883\u5909\u6570\u304B\u3089\u8A8D\u8A3C\u60C5\u5831\u3092\u8AAD\u307F\u53D6\u3089\u306A\u3044\u3067\u304F\u3060\u3055\u3044\u3002
634
+
635
+ SDK \u30E1\u30BD\u30C3\u30C9 (\`connection(connectionId)\` \u3067\u4F5C\u6210\u3057\u305F\u30AF\u30E9\u30A4\u30A2\u30F3\u30C8):
636
+ - \`client.request(path, init?)\` \u2014 \u4F4E\u30EC\u30D9\u30EB\u8A8D\u8A3C\u4ED8\u304D fetch (path \u306F \`{serverUrl}/api/{apiVersion}\` \u306B\u8FFD\u52A0\u3055\u308C\u3001\`{siteId}\` \u306F\u7F6E\u63DB\u3055\u308C\u307E\u3059)
637
+ - \`client.getSession()\` \u2014 \u30B5\u30A4\u30F3\u30A4\u30F3 (\u5FC5\u8981\u306A\u3089) \u3057\u3066 \`{ authToken, siteId, userId }\` \u3092\u8FD4\u3059
638
+ - \`client.listProjects(options?)\` / \`client.listWorkbooks(options?)\` / \`client.listDatasources(options?)\`
639
+ - \`client.listViewsForWorkbook(workbookId)\`
640
+ - \`client.getViewData(viewId)\` \u2014 \u30D3\u30E5\u30FC\u306E\u30C7\u30FC\u30BF\u3092 CSV \u30C6\u30AD\u30B9\u30C8\u3067\u8FD4\u3059
641
+
642
+ \`\`\`ts
643
+ import type { Context } from "hono";
644
+ import { connection } from "@squadbase/vite-server/connectors/tableau";
645
+
646
+ const tableau = connection("<connectionId>");
647
+
648
+ export default async function handler(c: Context) {
649
+ const { pageSize = 20 } = await c.req.json<{ pageSize?: number }>();
650
+ const { workbooks, pagination } = await tableau.listWorkbooks({ pageSize });
651
+ return c.json({
652
+ workbooks: workbooks.workbook,
653
+ totalAvailable: Number(pagination.totalAvailable),
654
+ });
655
+ }
656
+ \`\`\`
657
+
658
+ ### Tableau REST API \u30EA\u30D5\u30A1\u30EC\u30F3\u30B9
659
+
660
+ - \u30D9\u30FC\u30B9 URL: \`{serverUrl}/api/{apiVersion}\` (\u30C7\u30D5\u30A9\u30EB\u30C8\u30D0\u30FC\u30B8\u30E7\u30F3 3.28; https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_concepts_versions.htm)
661
+ - \u8A8D\u8A3C: PAT \u3067\u30B5\u30A4\u30F3\u30A4\u30F3\u3059\u308B\u3068 \`X-Tableau-Auth\` \u30C8\u30FC\u30AF\u30F3\u3001\u30B5\u30A4\u30C8 ID\u3001\u30E6\u30FC\u30B6\u30FC ID \u304C\u8FD4\u3055\u308C\u308B\u3002Tableau Cloud \u3067\u306F\u7D04 240 \u5206\u306E\u30A2\u30A4\u30C9\u30EB\u3067\u30BB\u30C3\u30B7\u30E7\u30F3\u5931\u52B9
662
+ - \u30EC\u30B9\u30DD\u30F3\u30B9\u5F62\u5F0F: \`Accept: application/json\` \u3092\u9001\u308B\u3068 JSON (\u30C7\u30D5\u30A9\u30EB\u30C8)\u3002\u9001\u3089\u306A\u3044\u5834\u5408\u306F XML
663
+ - \u30DA\u30FC\u30B8\u30CD\u30FC\u30B7\u30E7\u30F3: \`?pageSize=&pageNumber=\` \u30AF\u30A8\u30EA\u3002\u30EC\u30B9\u30DD\u30F3\u30B9\u306B \`pagination\` \u30AA\u30D6\u30B8\u30A7\u30AF\u30C8
664
+
665
+ #### \u4E3B\u8981\u30A8\u30F3\u30C9\u30DD\u30A4\u30F3\u30C8
666
+ - POST \`/auth/signin\` \u2014 \u30B5\u30A4\u30F3\u30A4\u30F3 (\u81EA\u52D5\u51E6\u7406)
667
+ - POST \`/auth/signout\` \u2014 \u30B5\u30A4\u30F3\u30A2\u30A6\u30C8
668
+ - GET \`/sites/{siteId}/projects\` \u2014 \u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u4E00\u89A7
669
+ - GET \`/sites/{siteId}/workbooks\` \u2014 \u30EF\u30FC\u30AF\u30D6\u30C3\u30AF\u4E00\u89A7 (\`filter\`, \`sort\` \u5BFE\u5FDC)
670
+ - GET \`/sites/{siteId}/workbooks/{workbookId}\` \u2014 \u30EF\u30FC\u30AF\u30D6\u30C3\u30AF\u53D6\u5F97
671
+ - GET \`/sites/{siteId}/workbooks/{workbookId}/views\` \u2014 \u30EF\u30FC\u30AF\u30D6\u30C3\u30AF\u5185\u306E\u30D3\u30E5\u30FC\u4E00\u89A7
672
+ - GET \`/sites/{siteId}/views/{viewId}/data\` \u2014 \u30D3\u30E5\u30FC\u30C7\u30FC\u30BF\u3092 CSV \u3067\u53D6\u5F97
673
+ - GET \`/sites/{siteId}/views/{viewId}/image\` \u2014 \u30D3\u30E5\u30FC\u3092 PNG \u3067\u53D6\u5F97
674
+ - GET \`/sites/{siteId}/views/{viewId}/pdf\` \u2014 \u30D3\u30E5\u30FC\u3092 PDF \u3067\u53D6\u5F97
675
+ - GET \`/sites/{siteId}/datasources\` \u2014 \u516C\u958B\u30C7\u30FC\u30BF\u30BD\u30FC\u30B9\u4E00\u89A7
676
+ - GET \`/sites/{siteId}/users\` \u2014 \u30E6\u30FC\u30B6\u30FC\u4E00\u89A7
677
+ - GET \`/sites/{siteId}/groups\` \u2014 \u30B0\u30EB\u30FC\u30D7\u4E00\u89A7
678
+
679
+ #### \u30D5\u30A3\u30EB\u30BF\u69CB\u6587
680
+ - \`filter=name:eq:Sales\` \u2014 \u5B8C\u5168\u4E00\u81F4
681
+ - \`filter=name:in:[Sales,Marketing]\` \u2014 \u96C6\u5408\u306B\u542B\u307E\u308C\u308B
682
+ - \`filter=updatedAt:gte:2024-01-01T00:00:00Z\` \u2014 \u6BD4\u8F03\u6F14\u7B97\u5B50 (gt/gte/lt/lte)
683
+ - \u7D44\u307F\u5408\u308F\u305B: \`filter=ownerName:eq:alice,tags:in:[finance]\``
684
+ },
685
+ tools,
686
+ async checkConnection(params) {
687
+ const serverUrl = params[parameters.serverUrl.slug];
688
+ const siteContentUrl = params[parameters.siteContentUrl.slug];
689
+ const patName = params[parameters.patName.slug];
690
+ const patSecret = params[parameters.patSecret.slug];
691
+ const apiVersion = params[parameters.apiVersion.slug] || "3.28";
692
+ if (!serverUrl || siteContentUrl == null || !patName || !patSecret) {
693
+ return {
694
+ success: false,
695
+ error: "Missing required parameters: server-url, site-content-url, pat-name, pat-secret"
696
+ };
697
+ }
698
+ try {
699
+ const res = await fetch(
700
+ `${serverUrl.replace(/\/$/, "")}/api/${apiVersion}/auth/signin`,
701
+ {
702
+ method: "POST",
703
+ headers: {
704
+ "Content-Type": "application/json",
705
+ Accept: "application/json"
706
+ },
707
+ body: JSON.stringify({
708
+ credentials: {
709
+ personalAccessTokenName: patName,
710
+ personalAccessTokenSecret: patSecret,
711
+ site: { contentUrl: siteContentUrl }
712
+ }
713
+ })
714
+ }
715
+ );
716
+ if (!res.ok) {
717
+ const errorText = await res.text().catch(() => res.statusText);
718
+ return {
719
+ success: false,
720
+ error: `Tableau sign-in failed: HTTP ${res.status} ${errorText}`
721
+ };
722
+ }
723
+ return { success: true };
724
+ } catch (error) {
725
+ return {
726
+ success: false,
727
+ error: error instanceof Error ? error.message : String(error)
728
+ };
729
+ }
730
+ }
731
+ });
732
+
733
+ // src/connectors/create-connector-sdk.ts
734
+ import { readFileSync } from "fs";
735
+ import path from "path";
736
+
737
+ // src/connector-client/env.ts
738
+ function resolveEnvVar(entry, key, connectionId) {
739
+ const envVarName = entry.envVars[key];
740
+ if (!envVarName) {
741
+ throw new Error(`Connection "${connectionId}" is missing envVars mapping for key "${key}"`);
742
+ }
743
+ const value = process.env[envVarName];
744
+ if (!value) {
745
+ throw new Error(`Environment variable "${envVarName}" (for connection "${connectionId}", key "${key}") is not set`);
746
+ }
747
+ return value;
748
+ }
749
+ function resolveEnvVarOptional(entry, key) {
750
+ const envVarName = entry.envVars[key];
751
+ if (!envVarName) return void 0;
752
+ return process.env[envVarName] || void 0;
753
+ }
754
+
755
+ // src/connector-client/proxy-fetch.ts
756
+ import { getContext } from "hono/context-storage";
757
+ import { getCookie } from "hono/cookie";
758
+ var APP_SESSION_COOKIE_NAME = "__Host-squadbase-session";
759
+ function normalizeHeaders(input) {
760
+ const out = {};
761
+ if (!input) return out;
762
+ new Headers(input).forEach((value, key) => {
763
+ out[key] = value;
764
+ });
765
+ return out;
766
+ }
767
+ function createSandboxProxyFetch(connectionId) {
768
+ return async (input, init) => {
769
+ const token = process.env.INTERNAL_SQUADBASE_OAUTH_MACHINE_CREDENTIAL;
770
+ const sandboxId = process.env.INTERNAL_SQUADBASE_SANDBOX_ID;
771
+ if (!token || !sandboxId) {
772
+ throw new Error(
773
+ "Connection proxy is not configured. Please check your deployment settings."
774
+ );
775
+ }
776
+ const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
777
+ const originalMethod = init?.method ?? "GET";
778
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
779
+ const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
780
+ const proxyUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
781
+ return fetch(proxyUrl, {
782
+ method: "POST",
783
+ headers: {
784
+ "Content-Type": "application/json",
785
+ Authorization: `Bearer ${token}`
786
+ },
787
+ body: JSON.stringify({
788
+ url: originalUrl,
789
+ method: originalMethod,
790
+ headers: normalizeHeaders(init?.headers),
791
+ body: originalBody
792
+ })
793
+ });
794
+ };
795
+ }
796
+ function createDeployedAppProxyFetch(connectionId) {
797
+ const projectId = process.env["SQUADBASE_PROJECT_ID"];
798
+ if (!projectId) {
799
+ throw new Error(
800
+ "Connection proxy is not configured. Please check your deployment settings."
801
+ );
802
+ }
803
+ const baseDomain = process.env["SQUADBASE_APP_BASE_DOMAIN"] ?? "squadbase.app";
804
+ const proxyUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
805
+ return async (input, init) => {
806
+ const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
807
+ const originalMethod = init?.method ?? "GET";
808
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
809
+ const c = getContext();
810
+ const appSession = getCookie(c, APP_SESSION_COOKIE_NAME);
811
+ if (!appSession) {
812
+ throw new Error(
813
+ "No authentication method available for connection proxy."
814
+ );
815
+ }
816
+ return fetch(proxyUrl, {
817
+ method: "POST",
818
+ headers: {
819
+ "Content-Type": "application/json",
820
+ Authorization: `Bearer ${appSession}`
821
+ },
822
+ body: JSON.stringify({
823
+ url: originalUrl,
824
+ method: originalMethod,
825
+ headers: normalizeHeaders(init?.headers),
826
+ body: originalBody
827
+ })
828
+ });
829
+ };
830
+ }
831
+ function createProxyFetch(connectionId) {
832
+ if (process.env.INTERNAL_SQUADBASE_SANDBOX_ID) {
833
+ return createSandboxProxyFetch(connectionId);
834
+ }
835
+ return createDeployedAppProxyFetch(connectionId);
836
+ }
837
+
838
+ // src/connectors/create-connector-sdk.ts
839
+ function loadConnectionsSync() {
840
+ const filePath = process.env.CONNECTIONS_PATH ?? path.join(process.cwd(), ".squadbase/connections.json");
841
+ try {
842
+ const raw = readFileSync(filePath, "utf-8");
843
+ return JSON.parse(raw);
844
+ } catch {
845
+ return {};
846
+ }
847
+ }
848
+ function createConnectorSdk(plugin, createClient2) {
849
+ return (connectionId) => {
850
+ const connections = loadConnectionsSync();
851
+ const entry = connections[connectionId];
852
+ if (!entry) {
853
+ throw new Error(
854
+ `Connection "${connectionId}" not found in .squadbase/connections.json`
855
+ );
856
+ }
857
+ if (entry.connector.slug !== plugin.slug) {
858
+ throw new Error(
859
+ `Connection "${connectionId}" is not a ${plugin.slug} connection (got "${entry.connector.slug}")`
860
+ );
861
+ }
862
+ const params = {};
863
+ for (const param of Object.values(plugin.parameters)) {
864
+ if (param.required) {
865
+ params[param.slug] = resolveEnvVar(entry, param.slug, connectionId);
866
+ } else {
867
+ const val = resolveEnvVarOptional(entry, param.slug);
868
+ if (val !== void 0) params[param.slug] = val;
869
+ }
870
+ }
871
+ return createClient2(params, createProxyFetch(connectionId));
872
+ };
873
+ }
874
+
875
+ // src/connectors/entries/tableau.ts
876
+ var connection = createConnectorSdk(tableauConnector, createClient);
877
+ export {
878
+ connection
879
+ };