@cargo-ai/cdk 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/README.md +64 -35
  2. package/build/src/cli/auth.d.ts +9 -0
  3. package/build/src/cli/auth.d.ts.map +1 -0
  4. package/build/src/cli/auth.js +100 -0
  5. package/build/src/cli/bin.d.ts +3 -0
  6. package/build/src/cli/bin.d.ts.map +1 -0
  7. package/build/src/cli/bin.js +9 -0
  8. package/build/src/cli/commands/deploy.d.ts +4 -0
  9. package/build/src/cli/commands/deploy.d.ts.map +1 -0
  10. package/build/src/cli/commands/deploy.js +531 -0
  11. package/build/src/cli/commands/index.d.ts +4 -0
  12. package/build/src/cli/commands/index.d.ts.map +1 -0
  13. package/build/src/cli/commands/index.js +11 -0
  14. package/build/src/cli/commands/init.d.ts +3 -0
  15. package/build/src/cli/commands/init.d.ts.map +1 -0
  16. package/build/src/cli/commands/init.js +76 -0
  17. package/build/src/cli/commands/inputTypes.d.ts +24 -0
  18. package/build/src/cli/commands/inputTypes.d.ts.map +1 -0
  19. package/build/src/cli/commands/inputTypes.js +273 -0
  20. package/build/src/cli/commands/templates.d.ts +6 -0
  21. package/build/src/cli/commands/templates.d.ts.map +1 -0
  22. package/build/src/cli/commands/templates.js +33 -0
  23. package/build/src/cli/commands/types.d.ts +4 -0
  24. package/build/src/cli/commands/types.d.ts.map +1 -0
  25. package/build/src/cli/commands/types.js +385 -0
  26. package/build/src/cli/deployCommands.d.ts +4 -0
  27. package/build/src/cli/deployCommands.d.ts.map +1 -0
  28. package/build/src/cli/deployCommands.js +531 -0
  29. package/build/src/cli/index.d.ts +4 -0
  30. package/build/src/cli/index.d.ts.map +1 -0
  31. package/build/src/cli/index.js +20 -0
  32. package/build/src/cli/initCommand.d.ts +3 -0
  33. package/build/src/cli/initCommand.d.ts.map +1 -0
  34. package/build/src/cli/initCommand.js +76 -0
  35. package/build/src/cli/inputTypes.d.ts +24 -0
  36. package/build/src/cli/inputTypes.d.ts.map +1 -0
  37. package/build/src/cli/inputTypes.js +273 -0
  38. package/build/src/cli/io.d.ts +38 -0
  39. package/build/src/cli/io.d.ts.map +1 -0
  40. package/build/src/cli/io.js +226 -0
  41. package/build/src/cli/templates.d.ts +6 -0
  42. package/build/src/cli/templates.d.ts.map +1 -0
  43. package/build/src/cli/templates.js +34 -0
  44. package/build/src/cli/typesCommand.d.ts +4 -0
  45. package/build/src/cli/typesCommand.d.ts.map +1 -0
  46. package/build/src/cli/typesCommand.js +385 -0
  47. package/build/src/cli/version.d.ts +2 -0
  48. package/build/src/cli/version.d.ts.map +1 -0
  49. package/build/src/cli/version.js +25 -0
  50. package/build/src/deploy/executors.live.d.ts.map +1 -1
  51. package/build/src/deploy/executors.live.js +15 -3
  52. package/build/src/resources/bundle.d.ts +4 -2
  53. package/build/src/resources/bundle.d.ts.map +1 -1
  54. package/build/src/resources/bundle.js +11 -2
  55. package/build/src/resources/connector.d.ts.map +1 -1
  56. package/build/src/resources/connector.js +3 -2
  57. package/build/src/resources/worker.d.ts.map +1 -1
  58. package/build/src/resources/worker.js +14 -7
  59. package/build/tsconfig.tsbuildinfo +1 -1
  60. package/package.json +14 -4
  61. package/templates/blank/package.json +3 -3
  62. package/templates/full/README.md +21 -20
  63. package/templates/full/apps/dashboard/index.html +1 -1
  64. package/templates/full/apps/dashboard/package.json +18 -3
  65. package/templates/full/apps/dashboard/src/App.tsx +57 -0
  66. package/templates/full/apps/dashboard/src/index.css +4 -0
  67. package/templates/full/apps/dashboard/src/main.tsx +13 -7
  68. package/templates/full/apps/dashboard/tailwind.config.ts +13 -0
  69. package/templates/full/apps/dashboard/tsconfig.json +10 -3
  70. package/templates/full/apps/dashboard/vite.config.ts +22 -0
  71. package/templates/full/package.json +3 -3
  72. package/templates/full/workers/webhook/package.json +12 -1
  73. package/templates/full/workers/webhook/src/index.ts +53 -0
  74. package/templates/full/workers/webhook/tsconfig.json +14 -0
  75. package/templates/full/workers/webhook.ts +9 -7
  76. package/templates/full/apps/dashboard/package-lock.json +0 -1080
  77. package/templates/full/workers/webhook/index.js +0 -12
  78. package/templates/full/workers/webhook/package-lock.json +0 -12
@@ -0,0 +1,385 @@
1
+ import { mkdirSync, writeFileSync } from "node:fs";
2
+ import { resolve } from "node:path";
3
+ import { printJsonSchemaInput, printJsonSchemaType } from "./inputTypes.js";
4
+ import { handleApiCall, info, success } from "./io.js";
5
+ // Composite natives surfaced via dedicated SDK syntax / scope helpers —
6
+ // excluded so we don't double-register them. Mirrors the codegen exclusion
7
+ // list in `packages/workflow-sdk/scripts/generateNativeIntegration.ts`
8
+ // (everything in the `logic` category gets dedicated syntax instead of
9
+ // going through `native.<slug>`).
10
+ const COMPOSITE_NATIVE = new Set([
11
+ "start",
12
+ "end",
13
+ "agent",
14
+ "balance",
15
+ "branch",
16
+ "delay",
17
+ "filter",
18
+ "group",
19
+ "humanReview",
20
+ "memory",
21
+ "split",
22
+ "switch",
23
+ "tool",
24
+ "variables",
25
+ ]);
26
+ // Native actions the SDK already ships typed declarations + registrations
27
+ // for (platform-level, identical in every workspace) — skipped so the
28
+ // synced `.d.ts` doesn't redeclare `Native` properties with conflicting
29
+ // (looser) types. Source of truth lives in
30
+ // `packages/workflow-sdk/src/native/manifest.generated.ts`.
31
+ const BUNDLED_NATIVE = new Set([
32
+ "note",
33
+ "python",
34
+ "scoring",
35
+ "script",
36
+ ]);
37
+ export function registerTypesCommand(parent, getApi) {
38
+ parent
39
+ .command("types")
40
+ .description("Generate per-workspace TypeScript types for the Cargo CDK — typed defineConnector/defineModel config + integration actions in workflow bodies")
41
+ .option("--dir <path>", "Repo root the generated files are written into (default: cwd)")
42
+ .option("--out <dir>", "Output subdirectory for generated files (default: .cargo-ai)", ".cargo-ai")
43
+ .action(async (opts) => {
44
+ const api = getApi();
45
+ // Match the other `cdk` commands: `--dir` selects the repo root, and the
46
+ // generated `.cargo-ai` lands there (not wherever the CLI happens to run).
47
+ if (opts.dir !== undefined)
48
+ process.chdir(opts.dir);
49
+ const baseDir = process.cwd();
50
+ const outDir = resolve(baseDir, opts.out);
51
+ info(`Fetching workspace surface…`);
52
+ const payload = await fetchWorkspaceSurface(api);
53
+ mkdirSync(outDir, { recursive: true });
54
+ const typesPath = resolve(outDir, "cargo-types.d.ts");
55
+ writeFileSync(typesPath, renderTypes(payload));
56
+ success(`Wrote ${relativeToBase(baseDir, typesPath)}`);
57
+ const eagerPath = resolve(outDir, "cargo-register.ts");
58
+ writeFileSync(eagerPath, renderEagerRegistration(payload));
59
+ success(`Wrote ${relativeToBase(baseDir, eagerPath)}`);
60
+ info(``);
61
+ info([
62
+ `Next steps:`,
63
+ ` 1. Add "${relativeToBase(baseDir, outDir)}/**/*.d.ts" to your tsconfig`,
64
+ ` include so the types are picked up (a bare dot-dir path is ignored by`,
65
+ ` TypeScript). Enables typed defineConnector/defineModel config.`,
66
+ ` 2. To also type integration actions inside workflow bodies, add`,
67
+ ` \`import "./${relativeToBase(baseDir, eagerPath).replace(/\.ts$/, ".js")}";\``,
68
+ ` to your entry file so the workspace's integrations register at runtime.`,
69
+ ].join("\n"));
70
+ info(``);
71
+ const extractorCount = payload.extractorConfigs.reduce((n, e) => n + e.extractors.length, 0);
72
+ info(`Typed ${String(payload.connectorConfigs.length)} connector config(s), ${String(extractorCount)} extractor config(s), ${String(payload.integrations.length)} integration(s), ${String(payload.native.length)} native action(s).`);
73
+ });
74
+ }
75
+ async function fetchWorkspaceSurface(api) {
76
+ const integrationsResult = await handleApiCall(() => api.connection.integration.list({}));
77
+ const nativeIntegrationResult = await handleApiCall(() => api.connection.nativeIntegration.get());
78
+ const rawIntegrations = integrationsResult.integrations;
79
+ const integrations = collectIntegrations(rawIntegrations);
80
+ const native = collectNative(nativeIntegrationResult.nativeIntegration.actions);
81
+ const connectorConfigs = collectConnectorConfigs(rawIntegrations);
82
+ const extractorConfigs = collectExtractorConfigs(rawIntegrations);
83
+ return { integrations, native, connectorConfigs, extractorConfigs };
84
+ }
85
+ // integrationSlug → connector config type. Skips integrations whose schema
86
+ // prints as a bare record (no typing gained — the builder already falls back to
87
+ // that), keeping the generated file to connectors that actually add types.
88
+ function collectConnectorConfigs(integrations) {
89
+ const out = [];
90
+ for (const integration of integrations) {
91
+ const schema = integration.connector?.config?.schema;
92
+ if (schema === undefined)
93
+ continue;
94
+ const typeSrc = printJsonSchemaType(schema);
95
+ if (typeSrc === "Record<string, unknown>")
96
+ continue;
97
+ out.push({
98
+ slug: integration.slug,
99
+ name: trimOrUndefined(integration.name),
100
+ typeSrc,
101
+ });
102
+ }
103
+ out.sort((a, b) => a.slug.localeCompare(b.slug));
104
+ return out;
105
+ }
106
+ // integrationSlug → its extractors' config types. Skips extractors whose schema
107
+ // prints as a bare record, and integrations left with none.
108
+ function collectExtractorConfigs(integrations) {
109
+ const out = [];
110
+ for (const integration of integrations) {
111
+ const extractors = [];
112
+ for (const [slug, extractor] of Object.entries(integration.extractors ?? {}).sort(([a], [b]) => a.localeCompare(b))) {
113
+ const schema = extractor.config?.schema;
114
+ if (schema === undefined)
115
+ continue;
116
+ const typeSrc = printJsonSchemaType(schema);
117
+ if (typeSrc === "Record<string, unknown>")
118
+ continue;
119
+ extractors.push({ slug, typeSrc });
120
+ }
121
+ if (extractors.length === 0)
122
+ continue;
123
+ out.push({ integrationSlug: integration.slug, extractors });
124
+ }
125
+ out.sort((a, b) => a.integrationSlug.localeCompare(b.integrationSlug));
126
+ return out;
127
+ }
128
+ function collectIntegrations(integrations) {
129
+ const out = [];
130
+ for (const integration of integrations) {
131
+ const actionEntries = Object.entries(integration.actions ?? {}).sort(([a], [b]) => a.localeCompare(b));
132
+ if (actionEntries.length === 0)
133
+ continue;
134
+ const actions = actionEntries.map(([slug, raw]) => {
135
+ const meta = raw;
136
+ return {
137
+ slug,
138
+ name: trimOrUndefined(meta.name),
139
+ description: trimOrUndefined(meta.description),
140
+ inputTypeSrc: printJsonSchemaInput(meta.config?.schema),
141
+ };
142
+ });
143
+ out.push({
144
+ slug: integration.slug,
145
+ name: trimOrUndefined(integration.name),
146
+ description: trimOrUndefined(integration.description),
147
+ actions,
148
+ });
149
+ }
150
+ out.sort((a, b) => a.slug.localeCompare(b.slug));
151
+ return out;
152
+ }
153
+ function collectNative(actions) {
154
+ const out = [];
155
+ for (const [slug, meta] of Object.entries(actions)) {
156
+ if (COMPOSITE_NATIVE.has(slug))
157
+ continue;
158
+ if (BUNDLED_NATIVE.has(slug))
159
+ continue;
160
+ const name = meta.name.length > 0 ? meta.name : slug;
161
+ out.push({
162
+ slug,
163
+ name,
164
+ description: trimOrUndefined(meta.description),
165
+ });
166
+ }
167
+ out.sort((a, b) => a.slug.localeCompare(b.slug));
168
+ return out;
169
+ }
170
+ function trimOrUndefined(value) {
171
+ if (typeof value !== "string")
172
+ return undefined;
173
+ const trimmed = value.trim();
174
+ return trimmed.length > 0 ? trimmed : undefined;
175
+ }
176
+ const GENERATED_AT = new Date().toISOString();
177
+ const HEADER = `// THIS FILE IS GENERATED by \`cargo-ai cdk types\`. Do not edit by hand.
178
+ // Re-run the command to refresh after adding/removing workspace integrations
179
+ // or connectors.
180
+ // Last regenerated: ${GENERATED_AT}
181
+
182
+ `;
183
+ function renderTypes(payload) {
184
+ const blocks = [];
185
+ // ── @cargo-ai/cdk — typed define* config (connector + extractor schemas) ──
186
+ const cdkLines = [];
187
+ if (payload.connectorConfigs.length > 0) {
188
+ cdkLines.push(` interface ConnectorConfigs {`);
189
+ for (const c of payload.connectorConfigs) {
190
+ const doc = formatJsDoc({ name: c.name ?? c.slug, updatedAt: GENERATED_AT }, " ");
191
+ if (doc !== "")
192
+ cdkLines.push(doc.trimEnd());
193
+ cdkLines.push(` ${jsonKey(c.slug)}: ${c.typeSrc};`);
194
+ }
195
+ cdkLines.push(` }`);
196
+ }
197
+ if (payload.extractorConfigs.length > 0) {
198
+ cdkLines.push(` interface ExtractorConfigs {`);
199
+ for (const e of payload.extractorConfigs) {
200
+ cdkLines.push(` ${jsonKey(e.integrationSlug)}: {`);
201
+ for (const x of e.extractors) {
202
+ cdkLines.push(` ${jsonKey(x.slug)}: ${x.typeSrc};`);
203
+ }
204
+ cdkLines.push(` };`);
205
+ }
206
+ cdkLines.push(` }`);
207
+ }
208
+ if (cdkLines.length > 0) {
209
+ blocks.push([`declare module "@cargo-ai/cdk" {`, ...cdkLines, `}`].join("\n"));
210
+ }
211
+ // ── @cargo-ai/workflow-sdk — integration actions + natives (workflow bodies) ──
212
+ const wfLines = [];
213
+ if (payload.integrations.length > 0) {
214
+ wfLines.push(` interface Integrations {`);
215
+ for (const c of payload.integrations) {
216
+ const intDoc = formatJsDoc({
217
+ name: c.name ?? c.slug,
218
+ description: c.description,
219
+ updatedAt: GENERATED_AT,
220
+ }, " ");
221
+ if (intDoc !== "")
222
+ wfLines.push(intDoc.trimEnd());
223
+ wfLines.push(` ${jsonKey(c.slug)}: {`);
224
+ for (const action of c.actions) {
225
+ const actionDoc = formatJsDoc({
226
+ name: action.name,
227
+ description: action.description,
228
+ category: c.slug,
229
+ updatedAt: GENERATED_AT,
230
+ }, " ");
231
+ if (actionDoc !== "")
232
+ wfLines.push(actionDoc.trimEnd());
233
+ wfLines.push(` ${jsonKey(action.slug)}: IntegrationAction<${action.inputTypeSrc}, Record<string, unknown>>;`);
234
+ }
235
+ wfLines.push(` };`);
236
+ }
237
+ wfLines.push(` }`);
238
+ }
239
+ if (payload.native.length > 0) {
240
+ wfLines.push(` interface Native {`);
241
+ for (const n of payload.native) {
242
+ const doc = formatJsDoc({ name: n.name, description: n.description, updatedAt: GENERATED_AT }, " ");
243
+ if (doc !== "")
244
+ wfLines.push(doc.trimEnd());
245
+ wfLines.push(` ${jsonKey(n.slug)}: NativeAction<Record<string, unknown>, Record<string, unknown>>;`);
246
+ }
247
+ wfLines.push(` }`);
248
+ }
249
+ // The workflow-sdk augmentation needs its builder types imported; `Ref` only
250
+ // when a typed action input references it.
251
+ const preamble = [];
252
+ // The cdk augmentation references `EncryptionRef` at encryption-typed fields.
253
+ if (cdkLines.some((l) => l.includes("EncryptionRef"))) {
254
+ preamble.push(`import type { EncryptionRef } from "@cargo-ai/cdk";`);
255
+ }
256
+ if (wfLines.length > 0) {
257
+ const wfBody = wfLines.join("\n");
258
+ const imports = [
259
+ "IntegrationAction",
260
+ "NativeAction",
261
+ ...(wfBody.includes("Ref<") ? ["Ref"] : []),
262
+ ];
263
+ preamble.push([
264
+ `import type {`,
265
+ ...imports.map((name) => ` ${name},`),
266
+ `} from "@cargo-ai/workflow-sdk";`,
267
+ ].join("\n"));
268
+ blocks.push([`declare module "@cargo-ai/workflow-sdk" {`, wfBody, `}`].join("\n"));
269
+ }
270
+ // `declare module` only *augments* an existing module when this file is itself
271
+ // a module. The workflow-sdk import makes it one; when only the cdk block is
272
+ // emitted there's no import, so force module mode with an empty export.
273
+ if (preamble.length === 0)
274
+ preamble.push(`export {};`);
275
+ return `${HEADER.trim()}\n\n${[...preamble, ...blocks].join("\n\n")}\n`;
276
+ }
277
+ function renderEagerRegistration(payload) {
278
+ const lines = [];
279
+ lines.push(HEADER.trim());
280
+ const imports = [];
281
+ if (payload.integrations.length > 0)
282
+ imports.push("registerIntegration");
283
+ if (payload.native.length > 0)
284
+ imports.push("registerNative");
285
+ if (imports.length === 0) {
286
+ lines.push(``);
287
+ lines.push(`// Workspace surface is empty (no custom integrations / natives).`);
288
+ lines.push(``);
289
+ return lines.join("\n");
290
+ }
291
+ lines.push(`import { ${imports.join(", ")} } from "@cargo-ai/workflow-sdk";`);
292
+ lines.push(``);
293
+ for (const c of payload.integrations) {
294
+ lines.push(`registerIntegration(${JSON.stringify(c.slug)}, {`);
295
+ for (const action of c.actions) {
296
+ const displayName = action.name !== undefined && action.name.length > 0
297
+ ? action.name
298
+ : `${capitalize(c.slug)} ${humanize(action.slug)}`;
299
+ lines.push(` ${jsonKey(action.slug)}: { name: ${JSON.stringify(displayName)} },`);
300
+ }
301
+ lines.push(`});`);
302
+ }
303
+ for (const n of payload.native) {
304
+ lines.push(`registerNative(${JSON.stringify(n.slug)}, ${JSON.stringify(n.name)});`);
305
+ }
306
+ lines.push(``);
307
+ return lines.join("\n");
308
+ }
309
+ function jsonKey(key) {
310
+ return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(key) ? key : JSON.stringify(key);
311
+ }
312
+ // Render a JSDoc block above a generated declaration so editors surface the
313
+ // entry's metadata on hover. Returns "" when there's nothing to document.
314
+ function formatJsDoc(doc, indent) {
315
+ const body = [];
316
+ if (doc.name !== undefined && doc.name.trim().length > 0) {
317
+ body.push(doc.name.trim());
318
+ }
319
+ if (doc.description !== undefined && doc.description.trim().length > 0) {
320
+ if (body.length > 0)
321
+ body.push("");
322
+ for (const line of doc.description.split("\n")) {
323
+ body.push(line.trimEnd());
324
+ }
325
+ }
326
+ const tags = [];
327
+ if (doc.category !== undefined) {
328
+ const cats = Array.isArray(doc.category)
329
+ ? doc.category.join(", ")
330
+ : String(doc.category);
331
+ if (cats.trim().length > 0) {
332
+ tags.push(`@category ${cats}`);
333
+ }
334
+ }
335
+ if (doc.author !== undefined && doc.author.trim().length > 0) {
336
+ tags.push(`@author ${doc.author.trim()}`);
337
+ }
338
+ if (doc.version !== undefined && String(doc.version).length > 0) {
339
+ tags.push(`@version ${String(doc.version)}`);
340
+ }
341
+ if (doc.updatedAt !== undefined && doc.updatedAt !== null) {
342
+ const date = doc.updatedAt instanceof Date ? doc.updatedAt : new Date(doc.updatedAt);
343
+ if (!Number.isNaN(date.getTime())) {
344
+ tags.push(`@updated ${date.toISOString().slice(0, 10)}`);
345
+ }
346
+ }
347
+ if (doc.see !== undefined && doc.see.trim().length > 0) {
348
+ tags.push(`@see ${doc.see.trim()}`);
349
+ }
350
+ if (body.length > 0 && tags.length > 0) {
351
+ body.push("");
352
+ }
353
+ body.push(...tags);
354
+ if (body.length === 0)
355
+ return "";
356
+ const out = [`${indent}/**`];
357
+ for (const line of body) {
358
+ const safe = line.replace(/\*\//g, "*\\/");
359
+ out.push(safe.length > 0 ? `${indent} * ${safe}` : `${indent} *`);
360
+ }
361
+ out.push(`${indent} */`);
362
+ return `${out.join("\n")}\n`;
363
+ }
364
+ function capitalize(s) {
365
+ if (s.length === 0)
366
+ return s;
367
+ const first = s[0];
368
+ if (first === undefined)
369
+ return s;
370
+ return first.toUpperCase() + s.slice(1);
371
+ }
372
+ function humanize(slug) {
373
+ return slug
374
+ .replace(/([A-Z])/g, " $1")
375
+ .replace(/[_-]+/g, " ")
376
+ .trim()
377
+ .toLowerCase();
378
+ }
379
+ function relativeToBase(base, path) {
380
+ if (path.startsWith(base)) {
381
+ const rel = path.slice(base.length);
382
+ return rel.startsWith("/") ? rel.slice(1) : rel;
383
+ }
384
+ return path;
385
+ }
@@ -0,0 +1,2 @@
1
+ export declare function packageVersion(): string;
2
+ //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../../src/cli/version.ts"],"names":[],"mappings":"AAOA,wBAAgB,cAAc,IAAI,MAAM,CAkBvC"}
@@ -0,0 +1,25 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { dirname, join } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ // Read this package's version by walking up to the nearest `@cargo-ai/cdk`
5
+ // package.json — a walk (not a fixed relative path) so it's independent of build
6
+ // layout depth.
7
+ export function packageVersion() {
8
+ let cursor = dirname(fileURLToPath(import.meta.url));
9
+ for (let i = 0; i < 8; i += 1) {
10
+ try {
11
+ const pkg = JSON.parse(readFileSync(join(cursor, "package.json"), "utf-8"));
12
+ if (pkg.name === "@cargo-ai/cdk" && typeof pkg.version === "string") {
13
+ return pkg.version;
14
+ }
15
+ }
16
+ catch {
17
+ // no package.json here (or unreadable) — keep walking up
18
+ }
19
+ const parent = dirname(cursor);
20
+ if (parent === cursor)
21
+ break;
22
+ cursor = parent;
23
+ }
24
+ return "0.0.0";
25
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"executors.live.d.ts","sourceRoot":"","sources":["../../../src/deploy/executors.live.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAIzC,OAAO,KAAK,EAAE,SAAS,EAAW,MAAM,YAAY,CAAC;AA4BrD,wBAAgB,aAAa,CAAC,GAAG,EAAE,GAAG,GAAG,SAAS,CAkqBjD"}
1
+ {"version":3,"file":"executors.live.d.ts","sourceRoot":"","sources":["../../../src/deploy/executors.live.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAIzC,OAAO,KAAK,EAAE,SAAS,EAAW,MAAM,YAAY,CAAC;AA4BrD,wBAAgB,aAAa,CAAC,GAAG,EAAE,GAAG,GAAG,SAAS,CA4qBjD"}
@@ -2,6 +2,8 @@
2
2
  // Each executor receives the token-resolved spec (real uuids in place of tokens)
3
3
  // and the prior state entry, and decides: prior uuid → update; else (connector/
4
4
  // model, which have addressable slugs) exists-by-slug → adopt; else create.
5
+ // Explicit connector adopt (`adopt: true`) links the integration's default
6
+ // connector first, falling back to a slug match.
5
7
  //
6
8
  // This is the only file that imports @cargo-ai/api. Workspace is implicit — the
7
9
  // authenticated client already sends the selected-workspace-uuid header.
@@ -61,15 +63,25 @@ export function liveExecutors(api) {
61
63
  }
62
64
  return out;
63
65
  }
64
- const adopt = spec["adopt"] === true ||
66
+ const explicitAdopt = spec["adopt"] === true;
67
+ const adopt = explicitAdopt ||
65
68
  (await api.connection.connector.existsBySlug({ slug })).exists;
66
69
  if (adopt) {
67
70
  const { connectors } = await api.connection.connector.list({
68
71
  integrationSlug,
69
72
  });
70
- const found = connectors.find((c) => c.slug === slug);
73
+ // Explicit adopt (the OAuth escape hatch) links whatever connector the
74
+ // workspace already treats as default for this integration, falling back
75
+ // to a slug match. Implicit adopt (a same-slug connector already exists)
76
+ // recovers that exact slot, so it stays a strict slug match.
77
+ const found = explicitAdopt
78
+ ? (connectors.find((c) => c.isDefault === true) ??
79
+ connectors.find((c) => c.slug === slug))
80
+ : connectors.find((c) => c.slug === slug);
71
81
  if (found === undefined) {
72
- throw new Error(`connector "${slug}" reported to exist but was not found`);
82
+ throw new Error(explicitAdopt
83
+ ? `no connector found to adopt for integration "${integrationSlug}"`
84
+ : `connector "${slug}" reported to exist but was not found`);
73
85
  }
74
86
  // Mark as adopted — the CDK linked an existing connector it didn't
75
87
  // create, so destroy must release it rather than delete it.
@@ -7,9 +7,11 @@ export declare function readBundle(root: string): SourceFile[];
7
7
  /**
8
8
  * Fail at define time (not after a multi-minute server build) when a worker/app
9
9
  * bundle is missing a file the hosting build requires. `label` names the kind in
10
- * the error message.
10
+ * the error message. When `anyOf` is provided, at least one of those files must
11
+ * also exist — used for entrypoints that may live at more than one path (e.g. a
12
+ * worker's `src/index.ts` TS source or a pre-built `index.js`).
11
13
  */
12
- export declare function assertBundleFiles(root: string, label: string, required: string[]): void;
14
+ export declare function assertBundleFiles(root: string, label: string, required: string[], anyOf?: string[]): void;
13
15
  /** A content hash over the whole bundle — changes when any file changes. */
14
16
  export declare function bundleHash(root: string): string;
15
17
  //# sourceMappingURL=bundle.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["../../../src/resources/bundle.ts"],"names":[],"mappings":"AASA,MAAM,MAAM,UAAU,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAmB3D,0EAA0E;AAC1E,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,EAAE,CAOrD;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAAE,GACjB,IAAI,CAYN;AAED,4EAA4E;AAC5E,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAS/C"}
1
+ {"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["../../../src/resources/bundle.ts"],"names":[],"mappings":"AASA,MAAM,MAAM,UAAU,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAmB3D,0EAA0E;AAC1E,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,EAAE,CAOrD;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAAE,EAClB,KAAK,CAAC,EAAE,MAAM,EAAE,GACf,IAAI,CAqBN;AAED,4EAA4E;AAC5E,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAS/C"}
@@ -35,9 +35,11 @@ export function readBundle(root) {
35
35
  /**
36
36
  * Fail at define time (not after a multi-minute server build) when a worker/app
37
37
  * bundle is missing a file the hosting build requires. `label` names the kind in
38
- * the error message.
38
+ * the error message. When `anyOf` is provided, at least one of those files must
39
+ * also exist — used for entrypoints that may live at more than one path (e.g. a
40
+ * worker's `src/index.ts` TS source or a pre-built `index.js`).
39
41
  */
40
- export function assertBundleFiles(root, label, required) {
42
+ export function assertBundleFiles(root, label, required, anyOf) {
41
43
  const base = isAbsolute(root) ? root : resolve(process.cwd(), root);
42
44
  if (!existsSync(base)) {
43
45
  throw new Error(`${label} code path not found: ${base}`);
@@ -47,6 +49,13 @@ export function assertBundleFiles(root, label, required) {
47
49
  throw new Error(`${label} bundle at "${root}" is missing required file(s): ${missing.join(", ")}. ` +
48
50
  `A ${label} bundle must contain ${required.join(", ")} at its root.`);
49
51
  }
52
+ if (anyOf !== undefined && anyOf.length > 0) {
53
+ const hasEntrypoint = anyOf.some((file) => existsSync(join(base, file)));
54
+ if (!hasEntrypoint) {
55
+ throw new Error(`${label} bundle at "${root}" is missing an entrypoint. ` +
56
+ `Expected one of: ${anyOf.join(", ")}.`);
57
+ }
58
+ }
50
59
  }
51
60
  /** A content hash over the whole bundle — changes when any file changes. */
52
61
  export function bundleHash(root) {
@@ -1 +1 @@
1
- {"version":3,"file":"connector.d.ts","sourceRoot":"","sources":["../../../src/resources/connector.ts"],"names":[],"mappings":"AAWA,OAAO,EAAwB,KAAK,KAAK,EAAS,MAAM,YAAY,CAAC;AAErE,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,EAAE,KAAK,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ,CAAC;IAC3C,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC;CAC9B,CAAC;AAQF,MAAM,WAAW,gBAAgB;CAAG;AAEpC,KAAK,kBAAkB,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,SAAS,MAAM,gBAAgB,GACxE,gBAAgB,CAAC,CAAC,CAAC,GACnB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE5B,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,IAAI;IACrD,WAAW,EAAE,CAAC,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,kBAAkB,CAAC,CAAC,CAAC,CAAC;IAC/B,SAAS,CAAC,EAAE,aAAa,CAAC;IAC1B,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,IAAI;IACvD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,eAAe,EAAE,CAAC,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;IACrB,QAAQ,CAAC,WAAW,EAAE,KAAK,CAAC;IAC5B;;mEAE+D;IAC/D,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC;CAChC,CAAC;AAEF,wBAAgB,eAAe,CAAC,CAAC,SAAS,MAAM,EAC9C,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC,GACrB,eAAe,CAAC,CAAC,CAAC,CAuBpB"}
1
+ {"version":3,"file":"connector.d.ts","sourceRoot":"","sources":["../../../src/resources/connector.ts"],"names":[],"mappings":"AAYA,OAAO,EAAwB,KAAK,KAAK,EAAS,MAAM,YAAY,CAAC;AAErE,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,EAAE,KAAK,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ,CAAC;IAC3C,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC;CAC9B,CAAC;AAQF,MAAM,WAAW,gBAAgB;CAAG;AAEpC,KAAK,kBAAkB,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,SAAS,MAAM,gBAAgB,GACxE,gBAAgB,CAAC,CAAC,CAAC,GACnB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE5B,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,IAAI;IACrD,WAAW,EAAE,CAAC,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,kBAAkB,CAAC,CAAC,CAAC,CAAC;IAC/B,SAAS,CAAC,EAAE,aAAa,CAAC;IAC1B,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,IAAI;IACvD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,eAAe,EAAE,CAAC,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;IACrB,QAAQ,CAAC,WAAW,EAAE,KAAK,CAAC;IAC5B;;mEAE+D;IAC/D,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC;CAChC,CAAC;AAEF,wBAAgB,eAAe,CAAC,CAAC,SAAS,MAAM,EAC9C,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC,GACrB,eAAe,CAAC,CAAC,CAAC,CAuBpB"}
@@ -6,8 +6,9 @@
6
6
  // slug is known at define time, so it's a plain value on the handle.
7
7
  //
8
8
  // Two modes: create (config-based integrations, secrets via env) or adopt
9
- // (`adopt: true`) to link an already-authenticated connector by slug the
10
- // escape hatch for OAuth integrations whose tokens can't live in a repo.
9
+ // (`adopt: true`) to link an already-authenticated connector the escape hatch
10
+ // for OAuth integrations whose tokens can't live in a repo. Adopt links the
11
+ // integration's default connector first, falling back to a slug match.
11
12
  import { register, resourceId, token } from "../core.js";
12
13
  export function defineConnector(slug, spec) {
13
14
  const id = resourceId("connector", slug);
@@ -1 +1 @@
1
- {"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../../../src/resources/worker.ts"],"names":[],"mappings":"AAKA,OAAO,EAAwB,KAAK,KAAK,EAAS,MAAM,YAAY,CAAC;AACrE,OAAO,EAAE,KAAK,SAAS,EAAW,MAAM,YAAY,CAAC;AAErD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAWhD,MAAM,MAAM,UAAU,GAAG;IACvB,wEAAwE;IACxE,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,YAAY,GAAG,SAAS,CAAC;CACnC,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;IACrB,2DAA2D;IAC3D,QAAQ,CAAC,GAAG,EAAE,KAAK,CAAC;CACrB,CAAC;AAEF,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,YAAY,CAkBzE"}
1
+ {"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../../../src/resources/worker.ts"],"names":[],"mappings":"AAKA,OAAO,EAAwB,KAAK,KAAK,EAAS,MAAM,YAAY,CAAC;AACrE,OAAO,EAAE,KAAK,SAAS,EAAW,MAAM,YAAY,CAAC;AAErD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAmBhD,MAAM,MAAM,UAAU,GAAG;IACvB,wEAAwE;IACxE,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,YAAY,GAAG,SAAS,CAAC;CACnC,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;IACrB,2DAA2D;IAC3D,QAAQ,CAAC,GAAG,EAAE,KAAK,CAAC;CACrB,CAAC;AAEF,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,YAAY,CAkBzE"}
@@ -5,17 +5,24 @@
5
5
  import { register, resourceId, token } from "../core.js";
6
6
  import { refUuid } from "../refs.js";
7
7
  import { assertBundleFiles, bundleHash } from "./bundle.js";
8
- // Files the hosting worker build requires at the bundle root: a built entry
9
- // (esbuild bundles it no TS transpile), a manifest, and an npm-ci'able project.
10
- const WORKER_REQUIRED = [
8
+ // Files the hosting worker build always requires at the bundle root: a manifest
9
+ // and an npm-ci'able project. Like an app, a worker is uploaded as *source* and
10
+ // built server-side — the hosting build runs `npm ci` then esbuilds the
11
+ // entrypoint (esbuild transpiles TypeScript natively).
12
+ const WORKER_REQUIRED = ["manifest.json", "package.json", "package-lock.json"];
13
+ // The entrypoint may be authored in TypeScript (`src/index.ts`) — the same way
14
+ // an app ships `src/main.tsx` and is built with Vite — or shipped pre-built as
15
+ // `index.js`. At least one of these must exist; the hosting build resolves them
16
+ // in this order.
17
+ const WORKER_ENTRYPOINTS = [
18
+ "src/index.ts",
19
+ "src/index.js",
20
+ "index.ts",
11
21
  "index.js",
12
- "manifest.json",
13
- "package.json",
14
- "package-lock.json",
15
22
  ];
16
23
  export function defineWorker(slug, spec) {
17
24
  const id = resourceId("worker", slug);
18
- assertBundleFiles(spec.path, "worker", WORKER_REQUIRED);
25
+ assertBundleFiles(spec.path, "worker", WORKER_REQUIRED, WORKER_ENTRYPOINTS);
19
26
  register({
20
27
  id,
21
28
  kind: "worker",