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

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