@cargo-ai/cdk 1.0.8 → 1.0.9

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.
@@ -15,6 +15,14 @@ export declare function printJsonSchemaInput(schema: unknown): string;
15
15
  * workflow builder Refs). Used by `cargo-ai cdk types`.
16
16
  */
17
17
  export declare function printJsonSchemaType(schema: unknown): string;
18
+ /**
19
+ * Print an integration action's static output JSON Schema as a plain TS type —
20
+ * no `Ref<T> | T` widening and no `EncryptionRef`. Returns `undefined` when
21
+ * the schema is missing or too loose to be useful; the caller falls back to
22
+ * `any`, which stays usable everywhere a nested `Ref<Record<string, unknown>>`
23
+ * would not.
24
+ */
25
+ export declare function printJsonSchemaOutput(schema: unknown): string | undefined;
18
26
  /**
19
27
  * Print a tool release's `formFields` as a TS input type. Returns
20
28
  * `undefined` when the fields can't be interpreted (caller falls back to
@@ -1 +1 @@
1
- {"version":3,"file":"inputTypes.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/inputTypes.ts"],"names":[],"mappings":"AAmCA;;;GAGG;AACH,eAAO,MAAM,oBAAoB,QAE+D,CAAC;AAEjG;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,CAM5D;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,CAQ3D;AAmTD;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAU5E"}
1
+ {"version":3,"file":"inputTypes.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/inputTypes.ts"],"names":[],"mappings":"AAqCA;;;GAGG;AACH,eAAO,MAAM,oBAAoB,QAE+D,CAAC;AAEjG;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,CAM5D;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,CAQ3D;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAQzE;AAmUD;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAU5E"}
@@ -1,17 +1,19 @@
1
- // TypeScript input-type printers for `cargo-ai workflow sync` codegen.
1
+ // TypeScript type printers for `cargo-ai workflow sync` codegen.
2
2
  //
3
- // Three sources of truth, three printers:
3
+ // Sources of truth:
4
4
  // - Integration actions expose their config as JSON Schema on
5
- // `connection.integration.list` (`action.config.schema`).
5
+ // `connection.integration.list` (`action.config.schema`), and — for
6
+ // actions with a static output — their output as `action.output.schema`.
6
7
  // - Workspace tools expose their input as `formFields` on the tool
7
8
  // workflow's deployed release (`orchestration.release.getDeployed`).
8
9
  // - Agent nodes accept a single global shape (`{ prompt, output? }`) —
9
10
  // the engine validates every agent node against `AiUtils.agentConfig`.
10
11
  //
11
- // All printers run in "input mode": each top-level property is widened to
12
- // `Ref<T> | T` so callers can pass either a builder Ref or a literal.
13
- // Anything unrecognized falls back to `unknown` codegen must never abort
14
- // on a schema edge case.
12
+ // Input printers run in "input mode": each top-level property is widened to
13
+ // `Ref<T> | T` so callers can pass either a builder Ref or a literal. The
14
+ // output printer emits plain types (outputs come back as a `Ref` the caller
15
+ // dot-accesses). Anything unrecognized falls back to `unknown` — codegen must
16
+ // never abort on a schema edge case.
15
17
  //
16
18
  // Mirrors `packages/workflow-sdk/scripts/lib/jsonSchemaToTs.ts` (which is a
17
19
  // build-time-only script the CLI can't import).
@@ -47,6 +49,22 @@ export function printJsonSchemaType(schema) {
47
49
  const printed = printSchema(schema, false, true);
48
50
  return printed === "unknown" ? "Record<string, unknown>" : printed;
49
51
  }
52
+ /**
53
+ * Print an integration action's static output JSON Schema as a plain TS type —
54
+ * no `Ref<T> | T` widening and no `EncryptionRef`. Returns `undefined` when
55
+ * the schema is missing or too loose to be useful; the caller falls back to
56
+ * `any`, which stays usable everywhere a nested `Ref<Record<string, unknown>>`
57
+ * would not.
58
+ */
59
+ export function printJsonSchemaOutput(schema) {
60
+ if (schema === null || typeof schema !== "object") {
61
+ return undefined;
62
+ }
63
+ const printed = printSchema(schema, false, false);
64
+ return printed === "unknown" || printed === "Record<string, unknown>"
65
+ ? undefined
66
+ : printed;
67
+ }
50
68
  // The platform's shared `encryption` schema definition: an object with a `type`
51
69
  // const/enum of "encryption" plus `isEncrypted` and `value`. In CDK config types
52
70
  // these positions become `EncryptionRef` (see printObject).
@@ -65,6 +83,10 @@ function isEncryptionSchema(schema) {
65
83
  }
66
84
  function printSchema(schema, topLevel, encRef) {
67
85
  if (Array.isArray(schema.type)) {
86
+ // zod's `z.any()` lowers to the full list of JSON types; print `unknown`
87
+ // instead of a noisy 7-member union.
88
+ if (isAnyTypeList(schema.type))
89
+ return "unknown";
68
90
  return uniqueUnion(schema.type.map((t) => printPrimitive(t, schema, false, encRef)));
69
91
  }
70
92
  if (schema.enum !== undefined && schema.enum.length > 0) {
@@ -103,6 +125,17 @@ function printSchema(schema, topLevel, encRef) {
103
125
  return "unknown";
104
126
  return printPrimitive(schema.type, schema, topLevel, encRef);
105
127
  }
128
+ const ANY_TYPE_LIST = [
129
+ "string",
130
+ "number",
131
+ "boolean",
132
+ "object",
133
+ "array",
134
+ "null",
135
+ ];
136
+ function isAnyTypeList(types) {
137
+ return ANY_TYPE_LIST.every((t) => types.includes(t));
138
+ }
106
139
  function printPrimitive(type, schema, topLevel, encRef) {
107
140
  switch (type) {
108
141
  case "string":
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/types.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAiHzC,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,GAAG,IAAI,CAgE7E"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/types.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAwHzC,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,GAAG,IAAI,CAgE7E"}
@@ -1,7 +1,7 @@
1
1
  import { mkdirSync, writeFileSync } from "node:fs";
2
2
  import { resolve } from "node:path";
3
3
  import { handleApiCall, info, success } from "../io.js";
4
- import { printJsonSchemaInput, printJsonSchemaType } from "./inputTypes.js";
4
+ import { printJsonSchemaInput, printJsonSchemaOutput, printJsonSchemaType, } from "./inputTypes.js";
5
5
  // Composite natives surfaced via dedicated SDK syntax / scope helpers —
6
6
  // excluded so we don't double-register them. Mirrors the codegen exclusion
7
7
  // list in `packages/workflow-sdk/scripts/generateNativeIntegration.ts`
@@ -186,12 +186,13 @@ function collectIntegrations(integrations) {
186
186
  continue;
187
187
  const actions = actionEntries.map(([slug, raw]) => {
188
188
  const meta = raw;
189
- const { config } = meta;
189
+ const { config, output } = meta;
190
190
  return {
191
191
  slug,
192
192
  name: trimOrUndefined(meta.name),
193
193
  description: trimOrUndefined(meta.description),
194
194
  inputTypeSrc: printJsonSchemaInput(config !== undefined ? config.schema : undefined),
195
+ outputTypeSrc: printJsonSchemaOutput(output !== undefined ? output.schema : undefined),
195
196
  };
196
197
  });
197
198
  out.push({
@@ -308,10 +309,12 @@ function renderTypes(payload) {
308
309
  }, " ");
309
310
  if (actionDoc !== "")
310
311
  wfLines.push(actionDoc.trimEnd());
311
- // Action outputs aren't schema-typed, so `any` (not `Record<string,
312
+ // Actions with a static output schema get a real output type; the rest
313
+ // (dynamic or absent outputs) fall back to `any` (not `Record<string,
312
314
  // unknown>`, which lowers to an unusable nested `Ref`) — the result is
313
315
  // then usable as a string, an object, or in any typed slot.
314
- wfLines.push(` ${jsonKey(action.slug)}: IntegrationAction<${action.inputTypeSrc}, any>;`);
316
+ const outputSrc = action.outputTypeSrc !== undefined ? action.outputTypeSrc : "any";
317
+ wfLines.push(` ${jsonKey(action.slug)}: IntegrationAction<${action.inputTypeSrc}, ${outputSrc}>;`);
315
318
  }
316
319
  wfLines.push(` };`);
317
320
  }