@cargo-ai/cdk 1.0.4 → 1.0.6

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 (70) hide show
  1. package/README.md +55 -8
  2. package/build/src/cli/bin.js +0 -0
  3. package/build/src/cli/commands/types.js +11 -35
  4. package/build/src/core.d.ts +1 -1
  5. package/build/src/core.d.ts.map +1 -1
  6. package/build/src/deploy/apply.d.ts +6 -0
  7. package/build/src/deploy/apply.d.ts.map +1 -1
  8. package/build/src/deploy/apply.js +4 -0
  9. package/build/src/deploy/destroy.d.ts.map +1 -1
  10. package/build/src/deploy/destroy.js +33 -0
  11. package/build/src/deploy/executors.live.d.ts.map +1 -1
  12. package/build/src/deploy/executors.live.js +157 -1
  13. package/build/src/deploy/readers.live.d.ts.map +1 -1
  14. package/build/src/deploy/readers.live.js +34 -1
  15. package/build/src/index.d.ts +9 -5
  16. package/build/src/index.d.ts.map +1 -1
  17. package/build/src/index.js +4 -2
  18. package/build/src/refs.d.ts +22 -0
  19. package/build/src/refs.d.ts.map +1 -1
  20. package/build/src/refs.js +11 -2
  21. package/build/src/resources/actions.d.ts +39 -19
  22. package/build/src/resources/actions.d.ts.map +1 -1
  23. package/build/src/resources/actions.js +60 -33
  24. package/build/src/resources/agent.d.ts +10 -23
  25. package/build/src/resources/agent.d.ts.map +1 -1
  26. package/build/src/resources/agent.js +8 -25
  27. package/build/src/resources/app.d.ts +3 -1
  28. package/build/src/resources/app.d.ts.map +1 -1
  29. package/build/src/resources/app.js +2 -1
  30. package/build/src/resources/connector.d.ts +10 -0
  31. package/build/src/resources/connector.d.ts.map +1 -1
  32. package/build/src/resources/connector.js +18 -1
  33. package/build/src/resources/customIntegration.d.ts +12 -0
  34. package/build/src/resources/customIntegration.d.ts.map +1 -0
  35. package/build/src/resources/customIntegration.js +18 -0
  36. package/build/src/resources/mcpServer.d.ts +8 -10
  37. package/build/src/resources/mcpServer.d.ts.map +1 -1
  38. package/build/src/resources/mcpServer.js +4 -7
  39. package/build/src/resources/model.d.ts +36 -1
  40. package/build/src/resources/model.d.ts.map +1 -1
  41. package/build/src/resources/model.js +38 -1
  42. package/build/src/resources/relationship.d.ts +21 -0
  43. package/build/src/resources/relationship.d.ts.map +1 -0
  44. package/build/src/resources/relationship.js +39 -0
  45. package/build/src/resources/worker.d.ts +13 -1
  46. package/build/src/resources/worker.d.ts.map +1 -1
  47. package/build/src/resources/worker.js +3 -1
  48. package/build/tsconfig.tsbuildinfo +1 -1
  49. package/package.json +5 -5
  50. package/templates/blank/cargo.ts +17 -22
  51. package/templates/full/README.md +7 -4
  52. package/templates/full/agents/sdr.ts +12 -8
  53. package/templates/full/connectors/hunter.ts +10 -0
  54. package/templates/full/mcp/crm.ts +9 -6
  55. package/templates/full/tools/enrich.ts +28 -9
  56. package/build/src/cli/deployCommands.d.ts +0 -4
  57. package/build/src/cli/deployCommands.d.ts.map +0 -1
  58. package/build/src/cli/deployCommands.js +0 -531
  59. package/build/src/cli/initCommand.d.ts +0 -3
  60. package/build/src/cli/initCommand.d.ts.map +0 -1
  61. package/build/src/cli/initCommand.js +0 -76
  62. package/build/src/cli/inputTypes.d.ts +0 -24
  63. package/build/src/cli/inputTypes.d.ts.map +0 -1
  64. package/build/src/cli/inputTypes.js +0 -273
  65. package/build/src/cli/templates.d.ts +0 -6
  66. package/build/src/cli/templates.d.ts.map +0 -1
  67. package/build/src/cli/templates.js +0 -34
  68. package/build/src/cli/typesCommand.d.ts +0 -4
  69. package/build/src/cli/typesCommand.d.ts.map +0 -1
  70. package/build/src/cli/typesCommand.js +0 -385
@@ -1,385 +0,0 @@
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
- }