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

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,822 @@
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/gamma/parameters.ts
46
+ var parameters = {
47
+ apiKey: new ParameterDefinition({
48
+ slug: "api-key",
49
+ name: "Gamma API Key",
50
+ description: "The Gamma API key for authentication. Generate from Account Settings > API Keys. Requires Pro, Ultra, Teams, or Business plan.",
51
+ envVarBaseKey: "GAMMA_API_KEY",
52
+ type: "text",
53
+ secret: true,
54
+ required: true
55
+ })
56
+ };
57
+
58
+ // ../connectors/src/connectors/gamma/sdk/index.ts
59
+ var BASE_URL = "https://public-api.gamma.app/v1.0";
60
+ function createClient(params) {
61
+ const apiKey = params[parameters.apiKey.slug];
62
+ if (!apiKey) {
63
+ throw new Error(
64
+ `gamma: missing required parameter: ${parameters.apiKey.slug}`
65
+ );
66
+ }
67
+ function authHeaders(extra) {
68
+ const headers = new Headers(extra);
69
+ headers.set("X-API-KEY", apiKey);
70
+ headers.set("Content-Type", "application/json");
71
+ return headers;
72
+ }
73
+ async function assertOk(res, label) {
74
+ if (!res.ok) {
75
+ const body = await res.text().catch(() => "(unreadable body)");
76
+ throw new Error(
77
+ `gamma ${label}: ${res.status} ${res.statusText} \u2014 ${body}`
78
+ );
79
+ }
80
+ }
81
+ return {
82
+ request(path2, init) {
83
+ const url = `${BASE_URL}${path2}`;
84
+ const headers = new Headers(init?.headers);
85
+ headers.set("X-API-KEY", apiKey);
86
+ headers.set("Content-Type", "application/json");
87
+ return fetch(url, { ...init, headers });
88
+ },
89
+ async listThemes(options) {
90
+ const params2 = new URLSearchParams();
91
+ if (options?.query) params2.set("query", options.query);
92
+ if (options?.limit) params2.set("limit", String(options.limit));
93
+ if (options?.after) params2.set("after", options.after);
94
+ const qs = params2.toString();
95
+ const res = await fetch(
96
+ `${BASE_URL}/themes${qs ? `?${qs}` : ""}`,
97
+ { method: "GET", headers: authHeaders() }
98
+ );
99
+ await assertOk(res, "listThemes");
100
+ return await res.json();
101
+ },
102
+ async listFolders(options) {
103
+ const params2 = new URLSearchParams();
104
+ if (options?.query) params2.set("query", options.query);
105
+ if (options?.limit) params2.set("limit", String(options.limit));
106
+ if (options?.after) params2.set("after", options.after);
107
+ const qs = params2.toString();
108
+ const res = await fetch(
109
+ `${BASE_URL}/folders${qs ? `?${qs}` : ""}`,
110
+ { method: "GET", headers: authHeaders() }
111
+ );
112
+ await assertOk(res, "listFolders");
113
+ return await res.json();
114
+ },
115
+ async createGeneration(options) {
116
+ const res = await fetch(`${BASE_URL}/generations`, {
117
+ method: "POST",
118
+ headers: authHeaders(),
119
+ body: JSON.stringify(options)
120
+ });
121
+ await assertOk(res, "createGeneration");
122
+ return await res.json();
123
+ },
124
+ async getGeneration(generationId) {
125
+ const res = await fetch(
126
+ `${BASE_URL}/generations/${encodeURIComponent(generationId)}`,
127
+ { method: "GET", headers: authHeaders() }
128
+ );
129
+ await assertOk(res, "getGeneration");
130
+ return await res.json();
131
+ },
132
+ async generateAndWait(options) {
133
+ const { generationId } = await this.createGeneration(options);
134
+ const deadline = Date.now() + 3e5;
135
+ while (Date.now() < deadline) {
136
+ await new Promise((resolve) => setTimeout(resolve, 5e3));
137
+ const result = await this.getGeneration(generationId);
138
+ if (result.status === "completed" || result.status === "failed") {
139
+ return result;
140
+ }
141
+ }
142
+ return {
143
+ generationId,
144
+ status: "failed",
145
+ error: {
146
+ message: `Generation timed out after 300s`,
147
+ statusCode: 408
148
+ }
149
+ };
150
+ }
151
+ };
152
+ }
153
+
154
+ // ../connectors/src/connector-onboarding.ts
155
+ var ConnectorOnboarding = class {
156
+ /** Phase 1: Connection setup instructions (optional — some connectors don't need this) */
157
+ connectionSetupInstructions;
158
+ /** Phase 2: Data overview instructions */
159
+ dataOverviewInstructions;
160
+ constructor(config) {
161
+ this.connectionSetupInstructions = config.connectionSetupInstructions;
162
+ this.dataOverviewInstructions = config.dataOverviewInstructions;
163
+ }
164
+ getConnectionSetupPrompt(language) {
165
+ return this.connectionSetupInstructions?.[language] ?? null;
166
+ }
167
+ getDataOverviewInstructions(language) {
168
+ return this.dataOverviewInstructions[language];
169
+ }
170
+ };
171
+
172
+ // ../connectors/src/connector-tool.ts
173
+ var ConnectorTool = class {
174
+ name;
175
+ description;
176
+ inputSchema;
177
+ outputSchema;
178
+ _execute;
179
+ constructor(config) {
180
+ this.name = config.name;
181
+ this.description = config.description;
182
+ this.inputSchema = config.inputSchema;
183
+ this.outputSchema = config.outputSchema;
184
+ this._execute = config.execute;
185
+ }
186
+ createTool(connections, config) {
187
+ return {
188
+ description: this.description,
189
+ inputSchema: this.inputSchema,
190
+ outputSchema: this.outputSchema,
191
+ execute: (input) => this._execute(input, connections, config)
192
+ };
193
+ }
194
+ };
195
+
196
+ // ../connectors/src/connector-plugin.ts
197
+ var ConnectorPlugin = class _ConnectorPlugin {
198
+ slug;
199
+ authType;
200
+ name;
201
+ description;
202
+ iconUrl;
203
+ parameters;
204
+ releaseFlag;
205
+ proxyPolicy;
206
+ experimentalAttributes;
207
+ onboarding;
208
+ systemPrompt;
209
+ tools;
210
+ query;
211
+ checkConnection;
212
+ constructor(config) {
213
+ this.slug = config.slug;
214
+ this.authType = config.authType;
215
+ this.name = config.name;
216
+ this.description = config.description;
217
+ this.iconUrl = config.iconUrl;
218
+ this.parameters = config.parameters;
219
+ this.releaseFlag = config.releaseFlag;
220
+ this.proxyPolicy = config.proxyPolicy;
221
+ this.experimentalAttributes = config.experimentalAttributes;
222
+ this.onboarding = config.onboarding;
223
+ this.systemPrompt = config.systemPrompt;
224
+ this.tools = config.tools;
225
+ this.query = config.query;
226
+ this.checkConnection = config.checkConnection;
227
+ }
228
+ get connectorKey() {
229
+ return _ConnectorPlugin.deriveKey(this.slug, this.authType);
230
+ }
231
+ /**
232
+ * Create tools for connections that belong to this connector.
233
+ * Filters connections by connectorKey internally.
234
+ * Returns tools keyed as `${connectorKey}_${toolName}`.
235
+ */
236
+ createTools(connections, config) {
237
+ const myConnections = connections.filter(
238
+ (c) => _ConnectorPlugin.deriveKey(c.connector.slug, c.connector.authType) === this.connectorKey
239
+ );
240
+ const result = {};
241
+ for (const t of Object.values(this.tools)) {
242
+ result[`${this.connectorKey}_${t.name}`] = t.createTool(
243
+ myConnections,
244
+ config
245
+ );
246
+ }
247
+ return result;
248
+ }
249
+ static deriveKey(slug, authType) {
250
+ return authType ? `${slug}-${authType}` : slug;
251
+ }
252
+ };
253
+
254
+ // ../connectors/src/auth-types.ts
255
+ var AUTH_TYPES = {
256
+ OAUTH: "oauth",
257
+ API_KEY: "api-key",
258
+ JWT: "jwt",
259
+ SERVICE_ACCOUNT: "service-account",
260
+ PAT: "pat",
261
+ USER_PASSWORD: "user-password"
262
+ };
263
+
264
+ // ../connectors/src/connectors/gamma/setup.ts
265
+ var gammaOnboarding = new ConnectorOnboarding({
266
+ dataOverviewInstructions: {
267
+ en: `1. Call gamma_request with GET /themes to list available themes in the workspace
268
+ 2. Call gamma_request with GET /folders to list workspace folders
269
+ 3. Try generating a simple presentation with gamma_generate: inputText "Sample presentation about AI", textMode "generate", numCards 3`,
270
+ ja: `1. gamma_request \u3067 GET /themes \u3092\u547C\u3073\u51FA\u3057\u3001\u30EF\u30FC\u30AF\u30B9\u30DA\u30FC\u30B9\u3067\u5229\u7528\u53EF\u80FD\u306A\u30C6\u30FC\u30DE\u4E00\u89A7\u3092\u53D6\u5F97
271
+ 2. gamma_request \u3067 GET /folders \u3092\u547C\u3073\u51FA\u3057\u3001\u30EF\u30FC\u30AF\u30B9\u30DA\u30FC\u30B9\u306E\u30D5\u30A9\u30EB\u30C0\u4E00\u89A7\u3092\u53D6\u5F97
272
+ 3. gamma_generate \u3067\u30B7\u30F3\u30D7\u30EB\u306A\u30D7\u30EC\u30BC\u30F3\u30C6\u30FC\u30B7\u30E7\u30F3\u3092\u8A66\u4F5C: inputText "AI\u306B\u3064\u3044\u3066\u306E\u30B5\u30F3\u30D7\u30EB\u30D7\u30EC\u30BC\u30F3\u30C6\u30FC\u30B7\u30E7\u30F3", textMode "generate", numCards 3`
273
+ }
274
+ });
275
+
276
+ // ../connectors/src/connectors/gamma/tools/request.ts
277
+ import { z } from "zod";
278
+ var BASE_URL2 = "https://public-api.gamma.app/v1.0";
279
+ var REQUEST_TIMEOUT_MS = 6e4;
280
+ var inputSchema = z.object({
281
+ toolUseIntent: z.string().optional().describe(
282
+ "Brief description of what you intend to accomplish with this tool call"
283
+ ),
284
+ connectionId: z.string().describe("ID of the Gamma connection to use"),
285
+ method: z.enum(["GET", "POST"]).describe("HTTP method. GET for listing resources, POST for creating."),
286
+ path: z.string().describe(
287
+ "API path (e.g., '/themes', '/folders', '/generations', '/generations/{generationId}')"
288
+ ),
289
+ body: z.record(z.string(), z.unknown()).optional().describe("Request body (JSON) for POST requests")
290
+ });
291
+ var outputSchema = z.discriminatedUnion("success", [
292
+ z.object({
293
+ success: z.literal(true),
294
+ status: z.number(),
295
+ data: z.unknown()
296
+ }),
297
+ z.object({
298
+ success: z.literal(false),
299
+ error: z.string()
300
+ })
301
+ ]);
302
+ var requestTool = new ConnectorTool({
303
+ name: "request",
304
+ description: `Send authenticated requests to the Gamma REST API.
305
+ Authentication is handled automatically using the API Key (X-API-KEY header).
306
+ Use this tool for listing themes, listing folders, checking generation status, and other read operations.
307
+ For creating presentations/documents, prefer the gamma_generate tool instead.`,
308
+ inputSchema,
309
+ outputSchema,
310
+ async execute({ connectionId, method, path: path2, body }, connections) {
311
+ const connection2 = connections.find((c) => c.id === connectionId);
312
+ if (!connection2) {
313
+ return {
314
+ success: false,
315
+ error: `Connection ${connectionId} not found`
316
+ };
317
+ }
318
+ console.log(
319
+ `[connector-request] gamma/${connection2.name}: ${method} ${path2}`
320
+ );
321
+ try {
322
+ const apiKey = parameters.apiKey.getValue(connection2);
323
+ const url = `${BASE_URL2}${path2}`;
324
+ const controller = new AbortController();
325
+ const timeout = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
326
+ try {
327
+ const response = await fetch(url, {
328
+ method,
329
+ headers: {
330
+ "X-API-KEY": apiKey,
331
+ "Content-Type": "application/json"
332
+ },
333
+ body: body ? JSON.stringify(body) : void 0,
334
+ signal: controller.signal
335
+ });
336
+ const data = await response.json();
337
+ if (!response.ok) {
338
+ const err = data;
339
+ const errorMessage = typeof err?.message === "string" ? err.message : typeof err?.error === "string" ? err.error : `HTTP ${response.status} ${response.statusText}`;
340
+ return { success: false, error: errorMessage };
341
+ }
342
+ return { success: true, status: response.status, data };
343
+ } finally {
344
+ clearTimeout(timeout);
345
+ }
346
+ } catch (err) {
347
+ const msg = err instanceof Error ? err.message : String(err);
348
+ return { success: false, error: msg };
349
+ }
350
+ }
351
+ });
352
+
353
+ // ../connectors/src/connectors/gamma/tools/generate.ts
354
+ import { z as z2 } from "zod";
355
+ var BASE_URL3 = "https://public-api.gamma.app/v1.0";
356
+ var POLL_INTERVAL_MS = 5e3;
357
+ var MAX_POLL_DURATION_MS = 3e5;
358
+ var inputSchema2 = z2.object({
359
+ toolUseIntent: z2.string().optional().describe(
360
+ "Brief description of what you intend to accomplish with this tool call"
361
+ ),
362
+ connectionId: z2.string().describe("ID of the Gamma connection to use"),
363
+ inputText: z2.string().describe(
364
+ "Content for the generation. Can include text and image URLs. Max ~400,000 characters."
365
+ ),
366
+ textMode: z2.enum(["generate", "condense", "preserve"]).describe(
367
+ "How inputText is modified: 'generate' creates new content from the topic, 'condense' shortens existing text, 'preserve' keeps text as-is."
368
+ ),
369
+ format: z2.enum(["presentation", "document", "webpage", "social"]).optional().describe("Type of artifact to create. Defaults to 'presentation'."),
370
+ numCards: z2.number().int().min(1).max(75).optional().describe("Number of cards/slides. Defaults to 10."),
371
+ themeId: z2.string().optional().describe(
372
+ "Theme ID for look and feel. Use gamma_request GET /themes to list available themes."
373
+ ),
374
+ tone: z2.string().optional().describe(
375
+ "Tone/voice of the output (e.g., 'professional', 'casual', 'academic'). Max 500 chars."
376
+ ),
377
+ audience: z2.string().optional().describe(
378
+ "Target audience description (e.g., 'marketing executives'). Max 500 chars."
379
+ ),
380
+ language: z2.string().optional().describe("Output language code (e.g., 'en', 'ja'). Defaults to 'en'."),
381
+ textAmount: z2.enum(["brief", "medium", "detailed", "extensive"]).optional().describe("Text volume per card. Defaults to 'medium'."),
382
+ imageSource: z2.enum([
383
+ "aiGenerated",
384
+ "pictographic",
385
+ "pexels",
386
+ "giphy",
387
+ "webAllImages",
388
+ "webFreeToUse",
389
+ "webFreeToUseCommercially",
390
+ "themeAccent",
391
+ "placeholder",
392
+ "noImages"
393
+ ]).optional().describe("Image source. Defaults to 'aiGenerated'."),
394
+ additionalInstructions: z2.string().optional().describe(
395
+ "Additional specifications for content, layout, and aesthetics. Max 5000 chars."
396
+ ),
397
+ exportAs: z2.enum(["pdf", "pptx", "png"]).optional().describe("Export file format. If omitted, no export file is generated.")
398
+ });
399
+ var outputSchema2 = z2.discriminatedUnion("success", [
400
+ z2.object({
401
+ success: z2.literal(true),
402
+ generationId: z2.string(),
403
+ gammaId: z2.string(),
404
+ gammaUrl: z2.string(),
405
+ exportUrl: z2.string().optional(),
406
+ credits: z2.object({
407
+ deducted: z2.number(),
408
+ remaining: z2.number()
409
+ }).optional()
410
+ }),
411
+ z2.object({
412
+ success: z2.literal(false),
413
+ error: z2.string()
414
+ })
415
+ ]);
416
+ var generateTool = new ConnectorTool({
417
+ name: "generate",
418
+ description: `Generate a presentation, document, webpage, or social post using Gamma AI.
419
+ This tool creates the generation, then automatically polls until completion and returns the result URL.
420
+ Use gamma_request GET /themes first if you want to pick a specific theme.`,
421
+ inputSchema: inputSchema2,
422
+ outputSchema: outputSchema2,
423
+ async execute({
424
+ connectionId,
425
+ inputText,
426
+ textMode,
427
+ format,
428
+ numCards,
429
+ themeId,
430
+ tone,
431
+ audience,
432
+ language,
433
+ textAmount,
434
+ imageSource,
435
+ additionalInstructions,
436
+ exportAs
437
+ }, connections) {
438
+ const connection2 = connections.find((c) => c.id === connectionId);
439
+ if (!connection2) {
440
+ return {
441
+ success: false,
442
+ error: `Connection ${connectionId} not found`
443
+ };
444
+ }
445
+ console.log(
446
+ `[connector-generate] gamma/${connection2.name}: creating ${format ?? "presentation"}`
447
+ );
448
+ try {
449
+ const apiKey = parameters.apiKey.getValue(connection2);
450
+ const headers = {
451
+ "X-API-KEY": apiKey,
452
+ "Content-Type": "application/json"
453
+ };
454
+ const body = {
455
+ inputText,
456
+ textMode
457
+ };
458
+ if (format) body.format = format;
459
+ if (numCards) body.numCards = numCards;
460
+ if (themeId) body.themeId = themeId;
461
+ if (additionalInstructions)
462
+ body.additionalInstructions = additionalInstructions;
463
+ if (exportAs) body.exportAs = exportAs;
464
+ const textOptions = {};
465
+ if (tone) textOptions.tone = tone;
466
+ if (audience) textOptions.audience = audience;
467
+ if (language) textOptions.language = language;
468
+ if (textAmount) textOptions.amount = textAmount;
469
+ if (Object.keys(textOptions).length > 0) body.textOptions = textOptions;
470
+ if (imageSource) body.imageOptions = { source: imageSource };
471
+ const createRes = await fetch(`${BASE_URL3}/generations`, {
472
+ method: "POST",
473
+ headers,
474
+ body: JSON.stringify(body)
475
+ });
476
+ const createData = await createRes.json();
477
+ if (!createRes.ok) {
478
+ const errorMessage = typeof createData?.message === "string" ? createData.message : typeof createData?.error === "string" ? createData.error : `HTTP ${createRes.status} ${createRes.statusText}`;
479
+ return { success: false, error: errorMessage };
480
+ }
481
+ const generationId = createData.generationId;
482
+ if (!generationId) {
483
+ return {
484
+ success: false,
485
+ error: "No generationId returned from API"
486
+ };
487
+ }
488
+ const deadline = Date.now() + MAX_POLL_DURATION_MS;
489
+ while (Date.now() < deadline) {
490
+ await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL_MS));
491
+ const pollRes = await fetch(`${BASE_URL3}/generations/${generationId}`, {
492
+ method: "GET",
493
+ headers
494
+ });
495
+ const pollData = await pollRes.json();
496
+ if (!pollRes.ok) {
497
+ const errorMessage = typeof pollData?.message === "string" ? pollData.message : `Polling failed: HTTP ${pollRes.status}`;
498
+ return { success: false, error: errorMessage };
499
+ }
500
+ const status = pollData.status;
501
+ if (status === "completed") {
502
+ return {
503
+ success: true,
504
+ generationId,
505
+ gammaId: pollData.gammaId,
506
+ gammaUrl: pollData.gammaUrl,
507
+ exportUrl: pollData.exportUrl || void 0,
508
+ credits: pollData.credits
509
+ };
510
+ }
511
+ if (status === "failed") {
512
+ const error = pollData.error;
513
+ const errorMessage = typeof error?.message === "string" ? error.message : "Generation failed";
514
+ return { success: false, error: errorMessage };
515
+ }
516
+ }
517
+ return {
518
+ success: false,
519
+ error: `Generation timed out after ${MAX_POLL_DURATION_MS / 1e3}s. generationId: ${generationId} \u2014 you can check status with GET /generations/${generationId}`
520
+ };
521
+ } catch (err) {
522
+ const msg = err instanceof Error ? err.message : String(err);
523
+ return { success: false, error: msg };
524
+ }
525
+ }
526
+ });
527
+
528
+ // ../connectors/src/connectors/gamma/index.ts
529
+ var tools = { request: requestTool, generate: generateTool };
530
+ var gammaConnector = new ConnectorPlugin({
531
+ slug: "gamma",
532
+ authType: AUTH_TYPES.API_KEY,
533
+ name: "Gamma",
534
+ description: "Connect to Gamma for AI-powered presentation, document, webpage, and social post generation.",
535
+ iconUrl: "https://images.ctfassets.net/9ncizv60xc5y/KoMGPpPcgtB9oDYe1OBjS/1ba7eb061c4497106bf6d249866dc471/gamma.svg",
536
+ parameters,
537
+ releaseFlag: { dev1: true, dev2: false, prod: false },
538
+ onboarding: gammaOnboarding,
539
+ systemPrompt: {
540
+ en: `### Tools
541
+
542
+ - \`gamma_request\`: Send authenticated requests to the Gamma REST API. Use for listing themes, folders, and checking generation status. Authentication (X-API-KEY) is configured automatically.
543
+ - \`gamma_generate\`: Generate a presentation, document, webpage, or social post using Gamma AI. This tool handles the full workflow: creates the generation, polls for completion, and returns the result URL. Prefer this over manually calling POST /generations + polling.
544
+
545
+ ### Business Logic
546
+
547
+ The business logic type for this connector is "typescript". Use the connector SDK in your handler. Do NOT read credentials from environment variables.
548
+
549
+ SDK methods (client created via \`connection(connectionId)\`):
550
+ - \`client.request(path, init?)\` \u2014 low-level authenticated fetch
551
+ - \`client.listThemes(options?)\` \u2014 list available themes (query, limit, after)
552
+ - \`client.listFolders(options?)\` \u2014 list workspace folders (query, limit, after)
553
+ - \`client.createGeneration(options)\` \u2014 create a generation, returns generationId
554
+ - \`client.getGeneration(generationId)\` \u2014 get generation status and result
555
+ - \`client.generateAndWait(options)\` \u2014 create generation and poll until completion
556
+
557
+ \`\`\`ts
558
+ import type { Context } from "hono";
559
+ import { connection } from "@squadbase/vite-server/connectors/gamma";
560
+
561
+ const gamma = connection("<connectionId>");
562
+
563
+ export default async function handler(c: Context) {
564
+ const { topic, numCards = 5 } = await c.req.json<{
565
+ topic: string;
566
+ numCards?: number;
567
+ }>();
568
+
569
+ const result = await gamma.generateAndWait({
570
+ inputText: topic,
571
+ textMode: "generate",
572
+ format: "presentation",
573
+ numCards,
574
+ });
575
+
576
+ return c.json(result);
577
+ }
578
+ \`\`\`
579
+
580
+ ### Gamma REST API Reference
581
+
582
+ - Base URL: \`https://public-api.gamma.app/v1.0\`
583
+ - Authentication: X-API-KEY header (handled automatically)
584
+
585
+ #### Endpoints
586
+
587
+ - POST \`/generations\` \u2014 Create a generation (presentation, document, webpage, social)
588
+ - Required: \`inputText\` (string), \`textMode\` ("generate" | "condense" | "preserve")
589
+ - Optional: \`format\`, \`numCards\`, \`themeId\`, \`textOptions\` (tone, audience, language, amount), \`imageOptions\` (source, model, style), \`additionalInstructions\`, \`exportAs\` (pdf, pptx, png), \`folderIds\`, \`sharingOptions\`
590
+ - Returns: \`{ generationId }\`
591
+ - GET \`/generations/{generationId}\` \u2014 Poll generation status
592
+ - Returns: \`{ generationId, status, gammaId?, gammaUrl?, exportUrl?, credits?, error? }\`
593
+ - Status values: "pending", "completed", "failed"
594
+ - Poll every 5 seconds until status changes from "pending"
595
+ - GET \`/themes\` \u2014 List available themes (query, limit, after for pagination)
596
+ - GET \`/folders\` \u2014 List workspace folders (query, limit, after for pagination)
597
+
598
+ #### Generation Formats
599
+ - \`presentation\` \u2014 Slide deck (dimensions: fluid, 16x9, 4x3)
600
+ - \`document\` \u2014 Document (dimensions: fluid, pageless, letter, a4)
601
+ - \`webpage\` \u2014 Web page
602
+ - \`social\` \u2014 Social media post (dimensions: 1x1, 4x5, 9x16)
603
+
604
+ #### Text Modes
605
+ - \`generate\` \u2014 AI generates new content from the input topic
606
+ - \`condense\` \u2014 AI shortens the provided text
607
+ - \`preserve\` \u2014 Input text is used as-is
608
+
609
+ #### Image Sources
610
+ - \`aiGenerated\`, \`pictographic\`, \`pexels\`, \`giphy\`, \`webFreeToUseCommercially\`, \`noImages\`, etc.`,
611
+ ja: `### \u30C4\u30FC\u30EB
612
+
613
+ - \`gamma_request\`: Gamma REST API\u306B\u8A8D\u8A3C\u6E08\u307F\u30EA\u30AF\u30A8\u30B9\u30C8\u3092\u9001\u4FE1\u3057\u307E\u3059\u3002\u30C6\u30FC\u30DE\u4E00\u89A7\u3001\u30D5\u30A9\u30EB\u30C0\u4E00\u89A7\u3001\u751F\u6210\u30B9\u30C6\u30FC\u30BF\u30B9\u306E\u78BA\u8A8D\u306B\u4F7F\u7528\u3057\u307E\u3059\u3002\u8A8D\u8A3C\uFF08X-API-KEY\uFF09\u306F\u81EA\u52D5\u7684\u306B\u8A2D\u5B9A\u3055\u308C\u307E\u3059\u3002
614
+ - \`gamma_generate\`: Gamma AI\u3092\u4F7F\u3063\u3066\u30D7\u30EC\u30BC\u30F3\u30C6\u30FC\u30B7\u30E7\u30F3\u3001\u30C9\u30AD\u30E5\u30E1\u30F3\u30C8\u3001\u30A6\u30A7\u30D6\u30DA\u30FC\u30B8\u3001\u30BD\u30FC\u30B7\u30E3\u30EB\u6295\u7A3F\u3092\u751F\u6210\u3057\u307E\u3059\u3002\u751F\u6210\u306E\u4F5C\u6210\u304B\u3089\u30DD\u30FC\u30EA\u30F3\u30B0\u3001\u7D50\u679CURL\u306E\u8FD4\u5374\u307E\u3067\u4E00\u62EC\u3067\u51E6\u7406\u3057\u307E\u3059\u3002\u624B\u52D5\u3067POST /generations + \u30DD\u30FC\u30EA\u30F3\u30B0\u3059\u308B\u3088\u308A\u3082\u3053\u3061\u3089\u3092\u63A8\u5968\u3057\u307E\u3059\u3002
615
+
616
+ ### Business Logic
617
+
618
+ \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\u30BFSDK\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
619
+
620
+ SDK\u30E1\u30BD\u30C3\u30C9 (\`connection(connectionId)\` \u3067\u4F5C\u6210\u3057\u305F\u30AF\u30E9\u30A4\u30A2\u30F3\u30C8):
621
+ - \`client.request(path, init?)\` \u2014 \u4F4E\u30EC\u30D9\u30EB\u306E\u8A8D\u8A3C\u4ED8\u304Dfetch
622
+ - \`client.listThemes(options?)\` \u2014 \u30C6\u30FC\u30DE\u4E00\u89A7\u306E\u53D6\u5F97\uFF08query, limit, after\uFF09
623
+ - \`client.listFolders(options?)\` \u2014 \u30EF\u30FC\u30AF\u30B9\u30DA\u30FC\u30B9\u30D5\u30A9\u30EB\u30C0\u4E00\u89A7\u306E\u53D6\u5F97\uFF08query, limit, after\uFF09
624
+ - \`client.createGeneration(options)\` \u2014 \u751F\u6210\u306E\u4F5C\u6210\u3001generationId\u3092\u8FD4\u3059
625
+ - \`client.getGeneration(generationId)\` \u2014 \u751F\u6210\u30B9\u30C6\u30FC\u30BF\u30B9\u3068\u7D50\u679C\u306E\u53D6\u5F97
626
+ - \`client.generateAndWait(options)\` \u2014 \u751F\u6210\u3092\u4F5C\u6210\u3057\u5B8C\u4E86\u307E\u3067\u30DD\u30FC\u30EA\u30F3\u30B0
627
+
628
+ \`\`\`ts
629
+ import type { Context } from "hono";
630
+ import { connection } from "@squadbase/vite-server/connectors/gamma";
631
+
632
+ const gamma = connection("<connectionId>");
633
+
634
+ export default async function handler(c: Context) {
635
+ const { topic, numCards = 5 } = await c.req.json<{
636
+ topic: string;
637
+ numCards?: number;
638
+ }>();
639
+
640
+ const result = await gamma.generateAndWait({
641
+ inputText: topic,
642
+ textMode: "generate",
643
+ format: "presentation",
644
+ numCards,
645
+ });
646
+
647
+ return c.json(result);
648
+ }
649
+ \`\`\`
650
+
651
+ ### Gamma REST API \u30EA\u30D5\u30A1\u30EC\u30F3\u30B9
652
+
653
+ - \u30D9\u30FC\u30B9URL: \`https://public-api.gamma.app/v1.0\`
654
+ - \u8A8D\u8A3C: X-API-KEY\u30D8\u30C3\u30C0\u30FC\uFF08\u81EA\u52D5\u8A2D\u5B9A\uFF09
655
+
656
+ #### \u30A8\u30F3\u30C9\u30DD\u30A4\u30F3\u30C8
657
+
658
+ - POST \`/generations\` \u2014 \u751F\u6210\u306E\u4F5C\u6210\uFF08\u30D7\u30EC\u30BC\u30F3\u30C6\u30FC\u30B7\u30E7\u30F3\u3001\u30C9\u30AD\u30E5\u30E1\u30F3\u30C8\u3001\u30A6\u30A7\u30D6\u30DA\u30FC\u30B8\u3001\u30BD\u30FC\u30B7\u30E3\u30EB\uFF09
659
+ - \u5FC5\u9808: \`inputText\`\uFF08\u6587\u5B57\u5217\uFF09\u3001\`textMode\`\uFF08"generate" | "condense" | "preserve"\uFF09
660
+ - \u30AA\u30D7\u30B7\u30E7\u30F3: \`format\`, \`numCards\`, \`themeId\`, \`textOptions\`\uFF08tone, audience, language, amount\uFF09, \`imageOptions\`\uFF08source, model, style\uFF09, \`additionalInstructions\`, \`exportAs\`\uFF08pdf, pptx, png\uFF09, \`folderIds\`, \`sharingOptions\`
661
+ - \u8FD4\u5374: \`{ generationId }\`
662
+ - GET \`/generations/{generationId}\` \u2014 \u751F\u6210\u30B9\u30C6\u30FC\u30BF\u30B9\u306E\u30DD\u30FC\u30EA\u30F3\u30B0
663
+ - \u8FD4\u5374: \`{ generationId, status, gammaId?, gammaUrl?, exportUrl?, credits?, error? }\`
664
+ - \u30B9\u30C6\u30FC\u30BF\u30B9\u5024: "pending", "completed", "failed"
665
+ - status\u304C"pending"\u3067\u306A\u304F\u306A\u308B\u307E\u30675\u79D2\u3054\u3068\u306B\u30DD\u30FC\u30EA\u30F3\u30B0
666
+ - GET \`/themes\` \u2014 \u30C6\u30FC\u30DE\u4E00\u89A7\uFF08query, limit, after\u3067\u30DA\u30FC\u30B8\u30CD\u30FC\u30B7\u30E7\u30F3\uFF09
667
+ - GET \`/folders\` \u2014 \u30D5\u30A9\u30EB\u30C0\u4E00\u89A7\uFF08query, limit, after\u3067\u30DA\u30FC\u30B8\u30CD\u30FC\u30B7\u30E7\u30F3\uFF09
668
+
669
+ #### \u751F\u6210\u30D5\u30A9\u30FC\u30DE\u30C3\u30C8
670
+ - \`presentation\` \u2014 \u30B9\u30E9\u30A4\u30C9\u30C7\u30C3\u30AD\uFF08\u5BF8\u6CD5: fluid, 16x9, 4x3\uFF09
671
+ - \`document\` \u2014 \u30C9\u30AD\u30E5\u30E1\u30F3\u30C8\uFF08\u5BF8\u6CD5: fluid, pageless, letter, a4\uFF09
672
+ - \`webpage\` \u2014 \u30A6\u30A7\u30D6\u30DA\u30FC\u30B8
673
+ - \`social\` \u2014 \u30BD\u30FC\u30B7\u30E3\u30EB\u30E1\u30C7\u30A3\u30A2\u6295\u7A3F\uFF08\u5BF8\u6CD5: 1x1, 4x5, 9x16\uFF09
674
+
675
+ #### \u30C6\u30AD\u30B9\u30C8\u30E2\u30FC\u30C9
676
+ - \`generate\` \u2014 AI\u304C\u5165\u529B\u30C8\u30D4\u30C3\u30AF\u304B\u3089\u65B0\u3057\u3044\u30B3\u30F3\u30C6\u30F3\u30C4\u3092\u751F\u6210
677
+ - \`condense\` \u2014 AI\u304C\u63D0\u4F9B\u3055\u308C\u305F\u30C6\u30AD\u30B9\u30C8\u3092\u77ED\u7E2E
678
+ - \`preserve\` \u2014 \u5165\u529B\u30C6\u30AD\u30B9\u30C8\u3092\u305D\u306E\u307E\u307E\u4F7F\u7528
679
+
680
+ #### \u753B\u50CF\u30BD\u30FC\u30B9
681
+ - \`aiGenerated\`, \`pictographic\`, \`pexels\`, \`giphy\`, \`webFreeToUseCommercially\`, \`noImages\` \u306A\u3069`
682
+ },
683
+ tools
684
+ });
685
+
686
+ // src/connectors/create-connector-sdk.ts
687
+ import { readFileSync } from "fs";
688
+ import path from "path";
689
+
690
+ // src/connector-client/env.ts
691
+ function resolveEnvVar(entry, key, connectionId) {
692
+ const envVarName = entry.envVars[key];
693
+ if (!envVarName) {
694
+ throw new Error(`Connection "${connectionId}" is missing envVars mapping for key "${key}"`);
695
+ }
696
+ const value = process.env[envVarName];
697
+ if (!value) {
698
+ throw new Error(`Environment variable "${envVarName}" (for connection "${connectionId}", key "${key}") is not set`);
699
+ }
700
+ return value;
701
+ }
702
+ function resolveEnvVarOptional(entry, key) {
703
+ const envVarName = entry.envVars[key];
704
+ if (!envVarName) return void 0;
705
+ return process.env[envVarName] || void 0;
706
+ }
707
+
708
+ // src/connector-client/proxy-fetch.ts
709
+ import { getContext } from "hono/context-storage";
710
+ import { getCookie } from "hono/cookie";
711
+ var APP_SESSION_COOKIE_NAME = "__Host-squadbase-session";
712
+ function createSandboxProxyFetch(connectionId) {
713
+ return async (input, init) => {
714
+ const token = process.env.INTERNAL_SQUADBASE_OAUTH_MACHINE_CREDENTIAL;
715
+ const sandboxId = process.env.INTERNAL_SQUADBASE_SANDBOX_ID;
716
+ if (!token || !sandboxId) {
717
+ throw new Error(
718
+ "Connection proxy is not configured. Please check your deployment settings."
719
+ );
720
+ }
721
+ const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
722
+ const originalMethod = init?.method ?? "GET";
723
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
724
+ const baseDomain = process.env["SQUADBASE_PREVIEW_BASE_DOMAIN"] ?? "preview.app.squadbase.dev";
725
+ const proxyUrl = `https://${sandboxId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
726
+ return fetch(proxyUrl, {
727
+ method: "POST",
728
+ headers: {
729
+ "Content-Type": "application/json",
730
+ Authorization: `Bearer ${token}`
731
+ },
732
+ body: JSON.stringify({
733
+ url: originalUrl,
734
+ method: originalMethod,
735
+ body: originalBody
736
+ })
737
+ });
738
+ };
739
+ }
740
+ function createDeployedAppProxyFetch(connectionId) {
741
+ const projectId = process.env["SQUADBASE_PROJECT_ID"];
742
+ if (!projectId) {
743
+ throw new Error(
744
+ "Connection proxy is not configured. Please check your deployment settings."
745
+ );
746
+ }
747
+ const baseDomain = process.env["SQUADBASE_APP_BASE_DOMAIN"] ?? "squadbase.app";
748
+ const proxyUrl = `https://${projectId}.${baseDomain}/_sqcore/connections/${connectionId}/request`;
749
+ return async (input, init) => {
750
+ const originalUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
751
+ const originalMethod = init?.method ?? "GET";
752
+ const originalBody = init?.body ? JSON.parse(init.body) : void 0;
753
+ const c = getContext();
754
+ const appSession = getCookie(c, APP_SESSION_COOKIE_NAME);
755
+ if (!appSession) {
756
+ throw new Error(
757
+ "No authentication method available for connection proxy."
758
+ );
759
+ }
760
+ return fetch(proxyUrl, {
761
+ method: "POST",
762
+ headers: {
763
+ "Content-Type": "application/json",
764
+ Authorization: `Bearer ${appSession}`
765
+ },
766
+ body: JSON.stringify({
767
+ url: originalUrl,
768
+ method: originalMethod,
769
+ body: originalBody
770
+ })
771
+ });
772
+ };
773
+ }
774
+ function createProxyFetch(connectionId) {
775
+ if (process.env.INTERNAL_SQUADBASE_SANDBOX_ID) {
776
+ return createSandboxProxyFetch(connectionId);
777
+ }
778
+ return createDeployedAppProxyFetch(connectionId);
779
+ }
780
+
781
+ // src/connectors/create-connector-sdk.ts
782
+ function loadConnectionsSync() {
783
+ const filePath = process.env.CONNECTIONS_PATH ?? path.join(process.cwd(), ".squadbase/connections.json");
784
+ try {
785
+ const raw = readFileSync(filePath, "utf-8");
786
+ return JSON.parse(raw);
787
+ } catch {
788
+ return {};
789
+ }
790
+ }
791
+ function createConnectorSdk(plugin, createClient2) {
792
+ return (connectionId) => {
793
+ const connections = loadConnectionsSync();
794
+ const entry = connections[connectionId];
795
+ if (!entry) {
796
+ throw new Error(
797
+ `Connection "${connectionId}" not found in .squadbase/connections.json`
798
+ );
799
+ }
800
+ if (entry.connector.slug !== plugin.slug) {
801
+ throw new Error(
802
+ `Connection "${connectionId}" is not a ${plugin.slug} connection (got "${entry.connector.slug}")`
803
+ );
804
+ }
805
+ const params = {};
806
+ for (const param of Object.values(plugin.parameters)) {
807
+ if (param.required) {
808
+ params[param.slug] = resolveEnvVar(entry, param.slug, connectionId);
809
+ } else {
810
+ const val = resolveEnvVarOptional(entry, param.slug);
811
+ if (val !== void 0) params[param.slug] = val;
812
+ }
813
+ }
814
+ return createClient2(params, createProxyFetch(connectionId));
815
+ };
816
+ }
817
+
818
+ // src/connectors/entries/gamma.ts
819
+ var connection = createConnectorSdk(gammaConnector, createClient);
820
+ export {
821
+ connection
822
+ };