@squadbase/vite-server 0.1.3-dev.12 → 0.1.3-dev.14

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,748 @@
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/google-slides/sdk/index.ts
46
+ import * as crypto from "crypto";
47
+
48
+ // ../connectors/src/connectors/google-slides/parameters.ts
49
+ var parameters = {
50
+ serviceAccountKeyJsonBase64: new ParameterDefinition({
51
+ slug: "service-account-key-json-base64",
52
+ name: "Google Cloud Service Account JSON",
53
+ description: "The service account JSON key used to authenticate with Google Cloud Platform. Ensure that the service account has the necessary permissions to access Google Slides.",
54
+ envVarBaseKey: "GOOGLE_SLIDES_SERVICE_ACCOUNT_JSON_BASE64",
55
+ type: "base64EncodedJson",
56
+ secret: true,
57
+ required: true
58
+ }),
59
+ presentationUrl: new ParameterDefinition({
60
+ slug: "presentation-url",
61
+ name: "Google Slides Presentation URL",
62
+ description: "The URL of the Google Slides presentation (e.g., https://docs.google.com/presentation/d/xxxxx/edit). The presentation ID is automatically extracted from the URL.",
63
+ envVarBaseKey: "GOOGLE_SLIDES_PRESENTATION_URL",
64
+ type: "text",
65
+ secret: false,
66
+ required: false
67
+ }),
68
+ sharedDriveId: new ParameterDefinition({
69
+ slug: "shared-drive-id",
70
+ name: "Shared Drive ID",
71
+ description: "The ID of the Google Shared Drive where new presentations will be created. Required for service accounts that do not have their own Drive storage. You can find the ID in the Shared Drive URL: https://drive.google.com/drive/folders/{sharedDriveId}",
72
+ envVarBaseKey: "GOOGLE_SLIDES_SHARED_DRIVE_ID",
73
+ type: "text",
74
+ secret: false,
75
+ required: false
76
+ })
77
+ };
78
+
79
+ // ../connectors/src/connectors/google-slides-oauth/utils.ts
80
+ var PRESENTATION_URL_PATTERN = /docs\.google\.com\/presentation\/d\/([a-zA-Z0-9_-]+)/;
81
+ function extractPresentationId(urlOrId) {
82
+ const trimmed = urlOrId.trim();
83
+ const match = trimmed.match(PRESENTATION_URL_PATTERN);
84
+ if (match) {
85
+ return match[1];
86
+ }
87
+ return trimmed;
88
+ }
89
+
90
+ // ../connectors/src/connectors/google-slides/sdk/index.ts
91
+ var TOKEN_URL = "https://oauth2.googleapis.com/token";
92
+ var SLIDES_BASE_URL = "https://slides.googleapis.com/v1/presentations";
93
+ var DRIVE_FILES_URL = "https://www.googleapis.com/drive/v3/files";
94
+ var SCOPE = "https://www.googleapis.com/auth/presentations https://www.googleapis.com/auth/drive";
95
+ function base64url(input) {
96
+ const buf = typeof input === "string" ? Buffer.from(input) : input;
97
+ return buf.toString("base64url");
98
+ }
99
+ function buildJwt(clientEmail, privateKey, nowSec) {
100
+ const header = base64url(JSON.stringify({ alg: "RS256", typ: "JWT" }));
101
+ const payload = base64url(
102
+ JSON.stringify({
103
+ iss: clientEmail,
104
+ scope: SCOPE,
105
+ aud: TOKEN_URL,
106
+ iat: nowSec,
107
+ exp: nowSec + 3600
108
+ })
109
+ );
110
+ const signingInput = `${header}.${payload}`;
111
+ const sign = crypto.createSign("RSA-SHA256");
112
+ sign.update(signingInput);
113
+ sign.end();
114
+ const signature = base64url(sign.sign(privateKey));
115
+ return `${signingInput}.${signature}`;
116
+ }
117
+ function createClient(params) {
118
+ const serviceAccountKeyJsonBase64 = params[parameters.serviceAccountKeyJsonBase64.slug];
119
+ const presentationUrl = params[parameters.presentationUrl.slug];
120
+ const defaultPresentationId = presentationUrl ? extractPresentationId(presentationUrl) : void 0;
121
+ const sharedDriveId = params[parameters.sharedDriveId.slug] || void 0;
122
+ if (!serviceAccountKeyJsonBase64) {
123
+ throw new Error(
124
+ `google-slides: missing required parameter: ${parameters.serviceAccountKeyJsonBase64.slug}`
125
+ );
126
+ }
127
+ let serviceAccountKey;
128
+ try {
129
+ const decoded = Buffer.from(
130
+ serviceAccountKeyJsonBase64,
131
+ "base64"
132
+ ).toString("utf-8");
133
+ serviceAccountKey = JSON.parse(decoded);
134
+ } catch {
135
+ throw new Error(
136
+ "google-slides: failed to decode service account key JSON from base64"
137
+ );
138
+ }
139
+ if (!serviceAccountKey.client_email || !serviceAccountKey.private_key) {
140
+ throw new Error(
141
+ "google-slides: service account key JSON must contain client_email and private_key"
142
+ );
143
+ }
144
+ let cachedToken = null;
145
+ let tokenExpiresAt = 0;
146
+ async function getAccessToken() {
147
+ const nowSec = Math.floor(Date.now() / 1e3);
148
+ if (cachedToken && nowSec < tokenExpiresAt - 60) {
149
+ return cachedToken;
150
+ }
151
+ const jwt = buildJwt(
152
+ serviceAccountKey.client_email,
153
+ serviceAccountKey.private_key,
154
+ nowSec
155
+ );
156
+ const response = await fetch(TOKEN_URL, {
157
+ method: "POST",
158
+ headers: { "Content-Type": "application/x-www-form-urlencoded" },
159
+ body: new URLSearchParams({
160
+ grant_type: "urn:ietf:params:oauth:grant-type:jwt-bearer",
161
+ assertion: jwt
162
+ })
163
+ });
164
+ if (!response.ok) {
165
+ const text = await response.text();
166
+ throw new Error(
167
+ `google-slides: token exchange failed (${response.status}): ${text}`
168
+ );
169
+ }
170
+ const data = await response.json();
171
+ cachedToken = data.access_token;
172
+ tokenExpiresAt = nowSec + data.expires_in;
173
+ return cachedToken;
174
+ }
175
+ function resolvePresentationId(override) {
176
+ const id = override ?? defaultPresentationId;
177
+ if (!id) {
178
+ throw new Error(
179
+ "google-slides: presentationId is required. Either configure a default or pass it explicitly."
180
+ );
181
+ }
182
+ return id;
183
+ }
184
+ async function authenticatedFetch(url, init) {
185
+ const accessToken = await getAccessToken();
186
+ const headers = new Headers(init?.headers);
187
+ headers.set("Authorization", `Bearer ${accessToken}`);
188
+ if (!headers.has("Content-Type")) {
189
+ headers.set("Content-Type", "application/json");
190
+ }
191
+ return fetch(url, { ...init, headers });
192
+ }
193
+ return {
194
+ async request(path2, init) {
195
+ const resolvedPath = defaultPresentationId ? path2.replace(/\{presentationId\}/g, defaultPresentationId) : path2;
196
+ const url = `${SLIDES_BASE_URL}${resolvedPath.startsWith("/") ? "" : "/"}${resolvedPath}`;
197
+ return authenticatedFetch(url, init);
198
+ },
199
+ async getPresentation(presentationId) {
200
+ const id = resolvePresentationId(presentationId);
201
+ const response = await authenticatedFetch(`${SLIDES_BASE_URL}/${id}`);
202
+ if (!response.ok) {
203
+ const body = await response.text();
204
+ throw new Error(`google-slides: getPresentation failed (${response.status}): ${body}`);
205
+ }
206
+ return await response.json();
207
+ },
208
+ async getPage(pageObjectId, presentationId) {
209
+ const id = resolvePresentationId(presentationId);
210
+ const response = await authenticatedFetch(`${SLIDES_BASE_URL}/${id}/pages/${pageObjectId}`);
211
+ if (!response.ok) {
212
+ const body = await response.text();
213
+ throw new Error(`google-slides: getPage failed (${response.status}): ${body}`);
214
+ }
215
+ return await response.json();
216
+ },
217
+ async batchUpdate(requests, presentationId) {
218
+ const id = resolvePresentationId(presentationId);
219
+ const response = await authenticatedFetch(`${SLIDES_BASE_URL}/${id}:batchUpdate`, {
220
+ method: "POST",
221
+ body: JSON.stringify({ requests })
222
+ });
223
+ if (!response.ok) {
224
+ const body = await response.text();
225
+ throw new Error(`google-slides: batchUpdate failed (${response.status}): ${body}`);
226
+ }
227
+ return await response.json();
228
+ },
229
+ async createPresentation(title) {
230
+ if (sharedDriveId) {
231
+ const driveResponse = await authenticatedFetch(
232
+ `${DRIVE_FILES_URL}?supportsAllDrives=true`,
233
+ {
234
+ method: "POST",
235
+ body: JSON.stringify({
236
+ name: title,
237
+ mimeType: "application/vnd.google-apps.presentation",
238
+ parents: [sharedDriveId]
239
+ })
240
+ }
241
+ );
242
+ if (!driveResponse.ok) {
243
+ const body = await driveResponse.text();
244
+ throw new Error(
245
+ `google-slides: createPresentation (Drive API) failed (${driveResponse.status}): ${body}`
246
+ );
247
+ }
248
+ const driveFile = await driveResponse.json();
249
+ const slidesResponse = await authenticatedFetch(
250
+ `${SLIDES_BASE_URL}/${driveFile.id}`
251
+ );
252
+ if (!slidesResponse.ok) {
253
+ const body = await slidesResponse.text();
254
+ throw new Error(
255
+ `google-slides: getPresentation after create failed (${slidesResponse.status}): ${body}`
256
+ );
257
+ }
258
+ return await slidesResponse.json();
259
+ }
260
+ const response = await authenticatedFetch(SLIDES_BASE_URL, {
261
+ method: "POST",
262
+ body: JSON.stringify({ title })
263
+ });
264
+ if (!response.ok) {
265
+ const body = await response.text();
266
+ throw new Error(`google-slides: createPresentation failed (${response.status}): ${body}`);
267
+ }
268
+ return await response.json();
269
+ }
270
+ };
271
+ }
272
+
273
+ // ../connectors/src/connector-onboarding.ts
274
+ var ConnectorOnboarding = class {
275
+ /** Phase 1: Connection setup instructions (optional — some connectors don't need this) */
276
+ connectionSetupInstructions;
277
+ /** Phase 2: Data overview instructions */
278
+ dataOverviewInstructions;
279
+ constructor(config) {
280
+ this.connectionSetupInstructions = config.connectionSetupInstructions;
281
+ this.dataOverviewInstructions = config.dataOverviewInstructions;
282
+ }
283
+ getConnectionSetupPrompt(language) {
284
+ return this.connectionSetupInstructions?.[language] ?? null;
285
+ }
286
+ getDataOverviewInstructions(language) {
287
+ return this.dataOverviewInstructions[language];
288
+ }
289
+ };
290
+
291
+ // ../connectors/src/connector-tool.ts
292
+ var ConnectorTool = class {
293
+ name;
294
+ description;
295
+ inputSchema;
296
+ outputSchema;
297
+ _execute;
298
+ constructor(config) {
299
+ this.name = config.name;
300
+ this.description = config.description;
301
+ this.inputSchema = config.inputSchema;
302
+ this.outputSchema = config.outputSchema;
303
+ this._execute = config.execute;
304
+ }
305
+ createTool(connections, config) {
306
+ return {
307
+ description: this.description,
308
+ inputSchema: this.inputSchema,
309
+ outputSchema: this.outputSchema,
310
+ execute: (input) => this._execute(input, connections, config)
311
+ };
312
+ }
313
+ };
314
+
315
+ // ../connectors/src/connector-plugin.ts
316
+ var ConnectorPlugin = class _ConnectorPlugin {
317
+ slug;
318
+ authType;
319
+ name;
320
+ description;
321
+ iconUrl;
322
+ parameters;
323
+ releaseFlag;
324
+ proxyPolicy;
325
+ experimentalAttributes;
326
+ onboarding;
327
+ systemPrompt;
328
+ tools;
329
+ query;
330
+ checkConnection;
331
+ constructor(config) {
332
+ this.slug = config.slug;
333
+ this.authType = config.authType;
334
+ this.name = config.name;
335
+ this.description = config.description;
336
+ this.iconUrl = config.iconUrl;
337
+ this.parameters = config.parameters;
338
+ this.releaseFlag = config.releaseFlag;
339
+ this.proxyPolicy = config.proxyPolicy;
340
+ this.experimentalAttributes = config.experimentalAttributes;
341
+ this.onboarding = config.onboarding;
342
+ this.systemPrompt = config.systemPrompt;
343
+ this.tools = config.tools;
344
+ this.query = config.query;
345
+ this.checkConnection = config.checkConnection;
346
+ }
347
+ get connectorKey() {
348
+ return _ConnectorPlugin.deriveKey(this.slug, this.authType);
349
+ }
350
+ /**
351
+ * Create tools for connections that belong to this connector.
352
+ * Filters connections by connectorKey internally.
353
+ * Returns tools keyed as `${connectorKey}_${toolName}`.
354
+ */
355
+ createTools(connections, config) {
356
+ const myConnections = connections.filter(
357
+ (c) => _ConnectorPlugin.deriveKey(c.connector.slug, c.connector.authType) === this.connectorKey
358
+ );
359
+ const result = {};
360
+ for (const t of Object.values(this.tools)) {
361
+ result[`${this.connectorKey}_${t.name}`] = t.createTool(
362
+ myConnections,
363
+ config
364
+ );
365
+ }
366
+ return result;
367
+ }
368
+ static deriveKey(slug, authType) {
369
+ return authType ? `${slug}-${authType}` : slug;
370
+ }
371
+ };
372
+
373
+ // ../connectors/src/auth-types.ts
374
+ var AUTH_TYPES = {
375
+ OAUTH: "oauth",
376
+ API_KEY: "api-key",
377
+ JWT: "jwt",
378
+ SERVICE_ACCOUNT: "service-account",
379
+ PAT: "pat",
380
+ USER_PASSWORD: "user-password"
381
+ };
382
+
383
+ // ../connectors/src/connectors/google-slides/setup.ts
384
+ var googleSlidesOnboarding = new ConnectorOnboarding({
385
+ dataOverviewInstructions: {
386
+ en: `1. Call google-slides_request with GET /{presentationId} to get presentation metadata (title, slide count, layout info)
387
+ 2. Call google-slides_request with GET /{presentationId}/pages/{pageObjectId} to inspect individual slide content`,
388
+ ja: `1. google-slides_request \u3067 GET /{presentationId} \u3092\u547C\u3073\u51FA\u3057\u3001\u30D7\u30EC\u30BC\u30F3\u30C6\u30FC\u30B7\u30E7\u30F3\u306E\u30E1\u30BF\u30C7\u30FC\u30BF\uFF08\u30BF\u30A4\u30C8\u30EB\u3001\u30B9\u30E9\u30A4\u30C9\u6570\u3001\u30EC\u30A4\u30A2\u30A6\u30C8\u60C5\u5831\uFF09\u3092\u53D6\u5F97
389
+ 2. google-slides_request \u3067 GET /{presentationId}/pages/{pageObjectId} \u3092\u547C\u3073\u51FA\u3057\u3001\u500B\u5225\u30B9\u30E9\u30A4\u30C9\u306E\u5185\u5BB9\u3092\u78BA\u8A8D`
390
+ }
391
+ });
392
+
393
+ // ../connectors/src/connectors/google-slides/tools/request.ts
394
+ import { z } from "zod";
395
+ var BASE_URL = "https://slides.googleapis.com/v1/presentations";
396
+ var REQUEST_TIMEOUT_MS = 6e4;
397
+ var inputSchema = z.object({
398
+ toolUseIntent: z.string().optional().describe(
399
+ "Brief description of what you intend to accomplish with this tool call"
400
+ ),
401
+ connectionId: z.string().describe("ID of the Google Slides connection to use"),
402
+ method: z.enum(["GET", "POST"]).describe("HTTP method"),
403
+ path: z.string().describe(
404
+ "API path appended to https://slides.googleapis.com/v1/presentations (e.g., '/{presentationId}', '/{presentationId}/pages/{pageId}'). {presentationId} is automatically replaced if a default is configured."
405
+ ),
406
+ body: z.record(z.string(), z.unknown()).optional().describe("JSON request body for POST requests"),
407
+ queryParams: z.record(z.string(), z.string()).optional().describe("Query parameters to append to the URL")
408
+ });
409
+ var outputSchema = z.discriminatedUnion("success", [
410
+ z.object({
411
+ success: z.literal(true),
412
+ status: z.number(),
413
+ data: z.record(z.string(), z.unknown())
414
+ }),
415
+ z.object({
416
+ success: z.literal(false),
417
+ error: z.string()
418
+ })
419
+ ]);
420
+ var requestTool = new ConnectorTool({
421
+ name: "request",
422
+ description: `Send authenticated requests to the Google Slides API v1.
423
+ Supports GET (read) and POST (create/update) methods.
424
+ Authentication is handled automatically using a service account.
425
+ {presentationId} in the path is automatically replaced with the connection's default presentation ID if configured.`,
426
+ inputSchema,
427
+ outputSchema,
428
+ async execute({ connectionId, method, path: path2, body, queryParams }, connections) {
429
+ const connection2 = connections.find((c) => c.id === connectionId);
430
+ if (!connection2) {
431
+ return {
432
+ success: false,
433
+ error: `Connection ${connectionId} not found`
434
+ };
435
+ }
436
+ console.log(
437
+ `[connector-request] google-slides/${connection2.name}: ${method} ${path2}`
438
+ );
439
+ try {
440
+ const { GoogleAuth } = await import("google-auth-library");
441
+ const keyJsonBase64 = parameters.serviceAccountKeyJsonBase64.getValue(connection2);
442
+ const presentationUrl = parameters.presentationUrl.tryGetValue(connection2);
443
+ const presentationId = presentationUrl ? extractPresentationId(presentationUrl) : void 0;
444
+ const credentials = JSON.parse(
445
+ Buffer.from(keyJsonBase64, "base64").toString("utf-8")
446
+ );
447
+ const auth = new GoogleAuth({
448
+ credentials,
449
+ scopes: [
450
+ "https://www.googleapis.com/auth/presentations",
451
+ "https://www.googleapis.com/auth/drive"
452
+ ]
453
+ });
454
+ const token = await auth.getAccessToken();
455
+ if (!token) {
456
+ return {
457
+ success: false,
458
+ error: "Failed to obtain access token"
459
+ };
460
+ }
461
+ const resolvedPath = presentationId ? path2.replace(/\{presentationId\}/g, presentationId) : path2;
462
+ let url = `${BASE_URL}${resolvedPath.startsWith("/") ? "" : "/"}${resolvedPath}`;
463
+ if (queryParams) {
464
+ const searchParams = new URLSearchParams(queryParams);
465
+ url += `?${searchParams.toString()}`;
466
+ }
467
+ const controller = new AbortController();
468
+ const timeout = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
469
+ try {
470
+ const response = await fetch(url, {
471
+ method,
472
+ headers: {
473
+ Authorization: `Bearer ${token}`,
474
+ "Content-Type": "application/json"
475
+ },
476
+ ...body != null ? { body: JSON.stringify(body) } : {},
477
+ signal: controller.signal
478
+ });
479
+ const data = await response.json();
480
+ if (!response.ok) {
481
+ const errorObj = data?.error;
482
+ return {
483
+ success: false,
484
+ error: errorObj?.message ?? `HTTP ${response.status} ${response.statusText}`
485
+ };
486
+ }
487
+ return { success: true, status: response.status, data };
488
+ } finally {
489
+ clearTimeout(timeout);
490
+ }
491
+ } catch (err) {
492
+ const msg = err instanceof Error ? err.message : String(err);
493
+ return { success: false, error: msg };
494
+ }
495
+ }
496
+ });
497
+
498
+ // ../connectors/src/connectors/google-slides/index.ts
499
+ var tools = { request: requestTool };
500
+ var googleSlidesConnector = new ConnectorPlugin({
501
+ slug: "google-slides",
502
+ authType: AUTH_TYPES.SERVICE_ACCOUNT,
503
+ name: "Google Slides",
504
+ description: "Connect to Google Slides for presentation data access and creation using a service account.",
505
+ iconUrl: "https://images.ctfassets.net/9ncizv60xc5y/5g0LJMwN28s2OhJbYU9CxC/71f1abfb40c89e5a6b5e3a3ad83b5a73/google-slides.svg",
506
+ parameters,
507
+ releaseFlag: { dev1: true, dev2: false, prod: false },
508
+ onboarding: googleSlidesOnboarding,
509
+ systemPrompt: {
510
+ en: `### Tools
511
+
512
+ - \`google-slides_request\`: Send authenticated requests to the Google Slides API v1. Supports GET (read) and POST (create/update) methods. Authentication is configured automatically via service account. The {presentationId} placeholder in paths is automatically replaced with the configured default presentation ID.
513
+
514
+ ### Google Slides API Reference
515
+
516
+ #### Read Endpoints
517
+ - GET \`/{presentationId}\` \u2014 Get presentation metadata (title, slides, layouts, masters)
518
+ - GET \`/{presentationId}/pages/{pageObjectId}\` \u2014 Get a specific slide page with all its elements
519
+
520
+ #### Write Endpoints
521
+ - POST \`\` (empty path, with body) \u2014 Create a new presentation. Body: \`{ "title": "My Presentation" }\`
522
+ - POST \`/{presentationId}:batchUpdate\` \u2014 Apply multiple updates. Body: \`{ "requests": [...] }\`
523
+
524
+ #### Common batchUpdate Request Types
525
+ - \`createSlide\` \u2014 Add a new slide
526
+ - \`insertText\` \u2014 Insert text into a shape
527
+ - \`createShape\` \u2014 Add a shape to a slide
528
+ - \`createImage\` \u2014 Add an image
529
+ - \`deleteObject\` \u2014 Delete a page element or slide
530
+ - \`replaceAllText\` \u2014 Find & replace text
531
+ - \`updateTextStyle\` \u2014 Style text (bold, color, font)
532
+
533
+ #### Predefined Slide Layouts
534
+ \`BLANK\`, \`TITLE\`, \`TITLE_AND_BODY\`, \`TITLE_AND_TWO_COLUMNS\`, \`TITLE_ONLY\`, \`SECTION_HEADER\`, \`ONE_COLUMN_TEXT\`, \`MAIN_POINT\`, \`BIG_NUMBER\`
535
+
536
+ ### Tips
537
+ - Use \`{presentationId}\` placeholder in paths \u2014 automatically replaced
538
+ - Shape sizes use EMU: 1 inch = 914400 EMU, 1 pt = 12700 EMU
539
+
540
+ ### Business Logic
541
+
542
+ The business logic type for this connector is "typescript". Write handler code using the connector SDK shown below.
543
+
544
+ #### Example
545
+
546
+ \`\`\`ts
547
+ import { connection } from "@squadbase/vite-server/connectors/google-slides";
548
+
549
+ const slides = connection("<connectionId>");
550
+
551
+ const presentation = await slides.getPresentation();
552
+ console.log(presentation.title, presentation.slides.length);
553
+
554
+ const newPres = await slides.createPresentation("Report");
555
+ await slides.batchUpdate([
556
+ { createSlide: { insertionIndex: 1, slideLayoutReference: { predefinedLayout: "TITLE_AND_BODY" } } },
557
+ ]);
558
+ \`\`\``,
559
+ ja: `### \u30C4\u30FC\u30EB
560
+
561
+ - \`google-slides_request\`: Google Slides API v1\u3078\u306E\u8A8D\u8A3C\u6E08\u307F\u30EA\u30AF\u30A8\u30B9\u30C8\u3092\u9001\u4FE1\u3057\u307E\u3059\u3002GET\uFF08\u8AAD\u307F\u53D6\u308A\uFF09\u3068POST\uFF08\u4F5C\u6210/\u66F4\u65B0\uFF09\u30E1\u30BD\u30C3\u30C9\u3092\u30B5\u30DD\u30FC\u30C8\u3057\u307E\u3059\u3002\u30B5\u30FC\u30D3\u30B9\u30A2\u30AB\u30A6\u30F3\u30C8\u7D4C\u7531\u3067\u8A8D\u8A3C\u306F\u81EA\u52D5\u8A2D\u5B9A\u3055\u308C\u307E\u3059\u3002\u30D1\u30B9\u5185\u306E{presentationId}\u30D7\u30EC\u30FC\u30B9\u30DB\u30EB\u30C0\u30FC\u306F\u8A2D\u5B9A\u6E08\u307F\u306E\u30C7\u30D5\u30A9\u30EB\u30C8\u30D7\u30EC\u30BC\u30F3\u30C6\u30FC\u30B7\u30E7\u30F3ID\u3067\u81EA\u52D5\u7684\u306B\u7F6E\u63DB\u3055\u308C\u307E\u3059\u3002
562
+
563
+ ### Google Slides API \u30EA\u30D5\u30A1\u30EC\u30F3\u30B9
564
+
565
+ #### \u8AAD\u307F\u53D6\u308A\u30A8\u30F3\u30C9\u30DD\u30A4\u30F3\u30C8
566
+ - GET \`/{presentationId}\` \u2014 \u30D7\u30EC\u30BC\u30F3\u30C6\u30FC\u30B7\u30E7\u30F3\u306E\u30E1\u30BF\u30C7\u30FC\u30BF\u3092\u53D6\u5F97
567
+ - GET \`/{presentationId}/pages/{pageObjectId}\` \u2014 \u7279\u5B9A\u306E\u30B9\u30E9\u30A4\u30C9\u30DA\u30FC\u30B8\u3068\u305D\u306E\u5168\u8981\u7D20\u3092\u53D6\u5F97
568
+
569
+ #### \u66F8\u304D\u8FBC\u307F\u30A8\u30F3\u30C9\u30DD\u30A4\u30F3\u30C8
570
+ - POST \`\`\uFF08\u7A7A\u30D1\u30B9\u3001\u30DC\u30C7\u30A3\u4ED8\u304D\uFF09\u2014 \u65B0\u3057\u3044\u30D7\u30EC\u30BC\u30F3\u30C6\u30FC\u30B7\u30E7\u30F3\u3092\u4F5C\u6210\u3002Body: \`{ "title": "\u30DE\u30A4\u30D7\u30EC\u30BC\u30F3\u30C6\u30FC\u30B7\u30E7\u30F3" }\`
571
+ - POST \`/{presentationId}:batchUpdate\` \u2014 \u8907\u6570\u306E\u66F4\u65B0\u3092\u9069\u7528\u3002Body: \`{ "requests": [...] }\`
572
+
573
+ #### \u4E3B\u306A batchUpdate \u30EA\u30AF\u30A8\u30B9\u30C8\u30BF\u30A4\u30D7
574
+ - \`createSlide\` \u2014 \u30B9\u30E9\u30A4\u30C9\u3092\u8FFD\u52A0
575
+ - \`insertText\` \u2014 \u30C6\u30AD\u30B9\u30C8\u3092\u633F\u5165
576
+ - \`createShape\` \u2014 \u56F3\u5F62\u3092\u8FFD\u52A0
577
+ - \`createImage\` \u2014 \u753B\u50CF\u3092\u8FFD\u52A0
578
+ - \`deleteObject\` \u2014 \u8981\u7D20\u307E\u305F\u306F\u30B9\u30E9\u30A4\u30C9\u3092\u524A\u9664
579
+ - \`replaceAllText\` \u2014 \u30C6\u30AD\u30B9\u30C8\u306E\u691C\u7D22\u3068\u7F6E\u63DB
580
+ - \`updateTextStyle\` \u2014 \u30C6\u30AD\u30B9\u30C8\u306E\u30B9\u30BF\u30A4\u30EB\u8A2D\u5B9A
581
+
582
+ #### \u5B9A\u7FA9\u6E08\u307F\u30B9\u30E9\u30A4\u30C9\u30EC\u30A4\u30A2\u30A6\u30C8
583
+ \`BLANK\`, \`TITLE\`, \`TITLE_AND_BODY\`, \`TITLE_AND_TWO_COLUMNS\`, \`TITLE_ONLY\`, \`SECTION_HEADER\`, \`ONE_COLUMN_TEXT\`, \`MAIN_POINT\`, \`BIG_NUMBER\`
584
+
585
+ ### \u30D2\u30F3\u30C8
586
+ - \u30D1\u30B9\u306B \`{presentationId}\` \u30D7\u30EC\u30FC\u30B9\u30DB\u30EB\u30C0\u30FC\u3092\u4F7F\u7528 \u2014 \u81EA\u52D5\u7684\u306B\u7F6E\u63DB\u3055\u308C\u307E\u3059
587
+ - \u56F3\u5F62\u30B5\u30A4\u30BA\u306FEMU\u3092\u4F7F\u7528: 1\u30A4\u30F3\u30C1 = 914400 EMU\u30011pt = 12700 EMU
588
+
589
+ ### Business Logic
590
+
591
+ \u3053\u306E\u30B3\u30CD\u30AF\u30BF\u306E\u30D3\u30B8\u30CD\u30B9\u30ED\u30B8\u30C3\u30AF\u30BF\u30A4\u30D7\u306F "typescript" \u3067\u3059\u3002\u4EE5\u4E0B\u306ESDK\u3092\u4F7F\u7528\u3057\u3066\u304F\u3060\u3055\u3044\u3002
592
+
593
+ #### Example
594
+
595
+ \`\`\`ts
596
+ import { connection } from "@squadbase/vite-server/connectors/google-slides";
597
+
598
+ const slides = connection("<connectionId>");
599
+
600
+ const presentation = await slides.getPresentation();
601
+ console.log(presentation.title, presentation.slides.length);
602
+
603
+ const newPres = await slides.createPresentation("\u30EC\u30DD\u30FC\u30C8");
604
+ await slides.batchUpdate([
605
+ { createSlide: { insertionIndex: 1, slideLayoutReference: { predefinedLayout: "TITLE_AND_BODY" } } },
606
+ ]);
607
+ \`\`\``
608
+ },
609
+ tools
610
+ });
611
+
612
+ // src/connectors/create-connector-sdk.ts
613
+ import { readFileSync } from "fs";
614
+ import path from "path";
615
+
616
+ // src/connector-client/env.ts
617
+ function resolveEnvVar(entry, key, connectionId) {
618
+ const envVarName = entry.envVars[key];
619
+ if (!envVarName) {
620
+ throw new Error(`Connection "${connectionId}" is missing envVars mapping for key "${key}"`);
621
+ }
622
+ const value = process.env[envVarName];
623
+ if (!value) {
624
+ throw new Error(`Environment variable "${envVarName}" (for connection "${connectionId}", key "${key}") is not set`);
625
+ }
626
+ return value;
627
+ }
628
+ function resolveEnvVarOptional(entry, key) {
629
+ const envVarName = entry.envVars[key];
630
+ if (!envVarName) return void 0;
631
+ return process.env[envVarName] || void 0;
632
+ }
633
+
634
+ // src/connector-client/proxy-fetch.ts
635
+ import { getContext } from "hono/context-storage";
636
+ import { getCookie } from "hono/cookie";
637
+ var APP_SESSION_COOKIE_NAME = "__Host-squadbase-session";
638
+ function createSandboxProxyFetch(connectionId) {
639
+ return async (input, init) => {
640
+ const token = process.env.INTERNAL_SQUADBASE_OAUTH_MACHINE_CREDENTIAL;
641
+ const sandboxId = process.env.INTERNAL_SQUADBASE_SANDBOX_ID;
642
+ if (!token || !sandboxId) {
643
+ throw new Error(
644
+ "Connection proxy is not configured. Please check your deployment settings."
645
+ );
646
+ }
647
+ const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
648
+ const originalMethod = init?.method ?? "GET";
649
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
650
+ const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
651
+ const proxyUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
652
+ return fetch(proxyUrl, {
653
+ method: "POST",
654
+ headers: {
655
+ "Content-Type": "application/json",
656
+ Authorization: `Bearer ${token}`
657
+ },
658
+ body: JSON.stringify({
659
+ url: originalUrl,
660
+ method: originalMethod,
661
+ body: originalBody
662
+ })
663
+ });
664
+ };
665
+ }
666
+ function createDeployedAppProxyFetch(connectionId) {
667
+ const projectId = process.env["SQUADBASE_PROJECT_ID"];
668
+ if (!projectId) {
669
+ throw new Error(
670
+ "Connection proxy is not configured. Please check your deployment settings."
671
+ );
672
+ }
673
+ const baseDomain = process.env["SQUADBASE_APP_BASE_DOMAIN"] ?? "squadbase.app";
674
+ const proxyUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
675
+ return async (input, init) => {
676
+ const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
677
+ const originalMethod = init?.method ?? "GET";
678
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
679
+ const c = getContext();
680
+ const appSession = getCookie(c, APP_SESSION_COOKIE_NAME);
681
+ if (!appSession) {
682
+ throw new Error(
683
+ "No authentication method available for connection proxy."
684
+ );
685
+ }
686
+ return fetch(proxyUrl, {
687
+ method: "POST",
688
+ headers: {
689
+ "Content-Type": "application/json",
690
+ Authorization: `Bearer ${appSession}`
691
+ },
692
+ body: JSON.stringify({
693
+ url: originalUrl,
694
+ method: originalMethod,
695
+ body: originalBody
696
+ })
697
+ });
698
+ };
699
+ }
700
+ function createProxyFetch(connectionId) {
701
+ if (process.env.INTERNAL_SQUADBASE_SANDBOX_ID) {
702
+ return createSandboxProxyFetch(connectionId);
703
+ }
704
+ return createDeployedAppProxyFetch(connectionId);
705
+ }
706
+
707
+ // src/connectors/create-connector-sdk.ts
708
+ function loadConnectionsSync() {
709
+ const filePath = process.env.CONNECTIONS_PATH ?? path.join(process.cwd(), ".squadbase/connections.json");
710
+ try {
711
+ const raw = readFileSync(filePath, "utf-8");
712
+ return JSON.parse(raw);
713
+ } catch {
714
+ return {};
715
+ }
716
+ }
717
+ function createConnectorSdk(plugin, createClient2) {
718
+ return (connectionId) => {
719
+ const connections = loadConnectionsSync();
720
+ const entry = connections[connectionId];
721
+ if (!entry) {
722
+ throw new Error(
723
+ `Connection "${connectionId}" not found in .squadbase/connections.json`
724
+ );
725
+ }
726
+ if (entry.connector.slug !== plugin.slug) {
727
+ throw new Error(
728
+ `Connection "${connectionId}" is not a ${plugin.slug} connection (got "${entry.connector.slug}")`
729
+ );
730
+ }
731
+ const params = {};
732
+ for (const param of Object.values(plugin.parameters)) {
733
+ if (param.required) {
734
+ params[param.slug] = resolveEnvVar(entry, param.slug, connectionId);
735
+ } else {
736
+ const val = resolveEnvVarOptional(entry, param.slug);
737
+ if (val !== void 0) params[param.slug] = val;
738
+ }
739
+ }
740
+ return createClient2(params, createProxyFetch(connectionId));
741
+ };
742
+ }
743
+
744
+ // src/connectors/entries/google-slides.ts
745
+ var connection = createConnectorSdk(googleSlidesConnector, createClient);
746
+ export {
747
+ connection
748
+ };