@elementumai/edk 0.8.0-preview.11 → 0.8.1

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 (165) hide show
  1. package/README.md +378 -324
  2. package/dist-sdk/src/catalog/ai-provider-models.d.ts +30 -0
  3. package/dist-sdk/src/catalog/ai-provider-models.js +63 -0
  4. package/dist-sdk/src/catalog/factories.d.ts +56 -3
  5. package/dist-sdk/src/catalog/factories.js +65 -2
  6. package/dist-sdk/src/catalog/from-authoring.js +6 -1
  7. package/dist-sdk/src/catalog/index.d.ts +3 -2
  8. package/dist-sdk/src/catalog/index.js +3 -2
  9. package/dist-sdk/src/catalog/org.d.ts +1 -1
  10. package/dist-sdk/src/catalog/org.js +83 -6
  11. package/dist-sdk/src/catalog/render.d.ts +13 -1
  12. package/dist-sdk/src/catalog/render.js +21 -4
  13. package/dist-sdk/src/catalog/token.js +14 -0
  14. package/dist-sdk/src/catalog/types.d.ts +60 -3
  15. package/dist-sdk/src/catalog/types.js +3 -0
  16. package/dist-sdk/src/core/system-fields.d.ts +2 -0
  17. package/dist-sdk/src/core/system-fields.js +2 -0
  18. package/dist-sdk/src/core/types/ai-provider.d.ts +10 -23
  19. package/dist-sdk/src/core/types/ai-provider.js +1 -25
  20. package/dist-sdk/src/core/types/app.d.ts +20 -1
  21. package/dist-sdk/src/engine/build/context.d.ts +18 -0
  22. package/dist-sdk/src/engine/build/source-context.d.ts +45 -0
  23. package/dist-sdk/src/engine/build/source-context.js +23 -0
  24. package/dist-sdk/src/engine/pull/context.d.ts +15 -0
  25. package/dist-sdk/src/engine/pull/org.d.ts +10 -0
  26. package/dist-sdk/src/engine/pull/org.js +34 -4
  27. package/dist-sdk/src/engine/tf/index.d.ts +1 -1
  28. package/dist-sdk/src/engine/tf/index.js +1 -1
  29. package/dist-sdk/src/engine/tf/labels.d.ts +45 -0
  30. package/dist-sdk/src/engine/tf/labels.js +71 -0
  31. package/dist-sdk/src/entities/access-policy/build.d.ts +26 -0
  32. package/dist-sdk/src/entities/access-policy/build.js +7 -0
  33. package/dist-sdk/src/entities/access-policy/filter.d.ts +61 -0
  34. package/dist-sdk/src/entities/access-policy/filter.js +83 -0
  35. package/dist-sdk/src/entities/access-policy/from-tf.d.ts +48 -0
  36. package/dist-sdk/src/entities/access-policy/from-tf.js +189 -0
  37. package/dist-sdk/src/entities/access-policy/module.d.ts +3 -0
  38. package/dist-sdk/src/entities/access-policy/module.js +17 -0
  39. package/dist-sdk/src/entities/access-policy/to-tf.d.ts +36 -0
  40. package/dist-sdk/src/entities/access-policy/to-tf.js +149 -0
  41. package/dist-sdk/src/entities/access-policy/types.d.ts +4 -0
  42. package/dist-sdk/src/entities/access-policy/types.js +10 -0
  43. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.d.ts +38 -3
  44. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +199 -32
  45. package/dist-sdk/src/entities/agent/from-tf.d.ts +18 -3
  46. package/dist-sdk/src/entities/agent/from-tf.js +135 -15
  47. package/dist-sdk/src/entities/agent/index.d.ts +1 -1
  48. package/dist-sdk/src/entities/agent/module.js +8 -2
  49. package/dist-sdk/src/entities/agent/to-tf.js +62 -10
  50. package/dist-sdk/src/entities/agent/tools.d.ts +88 -9
  51. package/dist-sdk/src/entities/agent/tools.js +46 -7
  52. package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +51 -4
  53. package/dist-sdk/src/entities/agent-tool/from-tf.js +131 -35
  54. package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +4 -2
  55. package/dist-sdk/src/entities/agent-tool/to-tf.js +103 -17
  56. package/dist-sdk/src/entities/agent-tool/types.d.ts +5 -4
  57. package/dist-sdk/src/entities/agent-tool/types.js +38 -6
  58. package/dist-sdk/src/entities/app/build.d.ts +63 -13
  59. package/dist-sdk/src/entities/app/build.js +48 -1
  60. package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +3 -0
  61. package/dist-sdk/src/entities/app/from-tf.d.ts +1 -1
  62. package/dist-sdk/src/entities/app/from-tf.js +32 -15
  63. package/dist-sdk/src/entities/app/index.d.ts +4 -1
  64. package/dist-sdk/src/entities/app/index.js +2 -1
  65. package/dist-sdk/src/entities/app/module.js +9 -2
  66. package/dist-sdk/src/entities/app/to-tf.d.ts +5 -0
  67. package/dist-sdk/src/entities/app/to-tf.js +33 -4
  68. package/dist-sdk/src/entities/automation/build.d.ts +57 -13
  69. package/dist-sdk/src/entities/automation/build.js +48 -36
  70. package/dist-sdk/src/entities/automation/deserializer/ast.d.ts +25 -8
  71. package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +16 -1
  72. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +179 -43
  73. package/dist-sdk/src/entities/automation/filter.d.ts +15 -3
  74. package/dist-sdk/src/entities/automation/filter.js +12 -2
  75. package/dist-sdk/src/entities/automation/from-tf.d.ts +26 -27
  76. package/dist-sdk/src/entities/automation/from-tf.js +1229 -223
  77. package/dist-sdk/src/entities/automation/index.d.ts +4 -0
  78. package/dist-sdk/src/entities/automation/index.js +4 -0
  79. package/dist-sdk/src/entities/automation/module.js +29 -32
  80. package/dist-sdk/src/entities/automation/operators.d.ts +29 -2
  81. package/dist-sdk/src/entities/automation/operators.js +27 -1
  82. package/dist-sdk/src/entities/automation/output-key-wire-name.d.ts +19 -0
  83. package/dist-sdk/src/entities/automation/output-key-wire-name.js +24 -0
  84. package/dist-sdk/src/entities/automation/script-code.d.ts +10 -21
  85. package/dist-sdk/src/entities/automation/script-code.js +272 -5
  86. package/dist-sdk/src/entities/automation/tasks.d.ts +125 -19
  87. package/dist-sdk/src/entities/automation/tasks.js +83 -15
  88. package/dist-sdk/src/entities/automation/to-tf.d.ts +10 -29
  89. package/dist-sdk/src/entities/automation/to-tf.js +1134 -231
  90. package/dist-sdk/src/entities/automation/triggers.d.ts +9 -1
  91. package/dist-sdk/src/entities/automation/types.d.ts +29 -4
  92. package/dist-sdk/src/entities/automation/types.js +76 -46
  93. package/dist-sdk/src/entities/element/build.d.ts +23 -10
  94. package/dist-sdk/src/entities/element/build.js +1 -0
  95. package/dist-sdk/src/entities/element/from-tf.d.ts +1 -1
  96. package/dist-sdk/src/entities/element/from-tf.js +18 -3
  97. package/dist-sdk/src/entities/element/index.d.ts +4 -1
  98. package/dist-sdk/src/entities/element/index.js +2 -1
  99. package/dist-sdk/src/entities/element/module.js +3 -1
  100. package/dist-sdk/src/entities/element/to-tf.js +21 -3
  101. package/dist-sdk/src/entities/field/build.d.ts +56 -13
  102. package/dist-sdk/src/entities/field/build.js +10 -0
  103. package/dist-sdk/src/entities/field/calc/runtime.js +4 -0
  104. package/dist-sdk/src/entities/field/from-tf.d.ts +5 -3
  105. package/dist-sdk/src/entities/field/from-tf.js +118 -7
  106. package/dist-sdk/src/entities/field/module.js +3 -2
  107. package/dist-sdk/src/entities/field/to-tf.d.ts +27 -9
  108. package/dist-sdk/src/entities/field/to-tf.js +62 -17
  109. package/dist-sdk/src/entities/field/types.d.ts +26 -0
  110. package/dist-sdk/src/entities/field/types.js +34 -12
  111. package/dist-sdk/src/entities/file-reader/build.d.ts +108 -50
  112. package/dist-sdk/src/entities/file-reader/build.js +23 -23
  113. package/dist-sdk/src/entities/file-reader/deserializer/print-file-reader.d.ts +6 -0
  114. package/dist-sdk/src/entities/file-reader/deserializer/print-file-reader.js +109 -0
  115. package/dist-sdk/src/entities/file-reader/from-tf.d.ts +13 -0
  116. package/dist-sdk/src/entities/file-reader/from-tf.js +172 -0
  117. package/dist-sdk/src/entities/file-reader/index.d.ts +8 -3
  118. package/dist-sdk/src/entities/file-reader/index.js +7 -2
  119. package/dist-sdk/src/entities/file-reader/module.d.ts +3 -0
  120. package/dist-sdk/src/entities/file-reader/module.js +115 -0
  121. package/dist-sdk/src/entities/file-reader/to-tf.d.ts +14 -0
  122. package/dist-sdk/src/entities/file-reader/to-tf.js +84 -0
  123. package/dist-sdk/src/entities/file-reader/types.d.ts +32 -0
  124. package/dist-sdk/src/entities/file-reader/types.js +30 -0
  125. package/dist-sdk/src/entities/org/ai-provider.d.ts +13 -0
  126. package/dist-sdk/src/entities/org/ai-provider.js +46 -0
  127. package/dist-sdk/src/entities/org/connector.d.ts +8 -1
  128. package/dist-sdk/src/entities/org/connector.js +12 -14
  129. package/dist-sdk/src/entities/org/group.js +10 -1
  130. package/dist-sdk/src/entities/org/index.d.ts +1 -0
  131. package/dist-sdk/src/entities/org/index.js +1 -0
  132. package/dist-sdk/src/entities/org/user.js +10 -1
  133. package/dist-sdk/src/entities/shared/filters/ast.d.ts +44 -9
  134. package/dist-sdk/src/entities/shared/filters/types.d.ts +1 -1
  135. package/dist-sdk/src/entities/shared/tool-field-ref.d.ts +17 -0
  136. package/dist-sdk/src/entities/shared/tool-field-ref.js +31 -0
  137. package/dist-sdk/src/entities/shared/types/field-types.d.ts +10 -1
  138. package/dist-sdk/src/entities/shared/types/field-types.js +9 -0
  139. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +19 -0
  140. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +36 -8
  141. package/dist-sdk/src/entities/skill/from-tf.js +4 -3
  142. package/dist-sdk/src/entities/skill/index.d.ts +1 -1
  143. package/dist-sdk/src/entities/skill/module.js +6 -1
  144. package/dist-sdk/src/entities/skill/to-tf.js +3 -2
  145. package/dist-sdk/src/entities/skill/tools.d.ts +25 -3
  146. package/dist-sdk/src/entities/skill/tools.js +17 -0
  147. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +15 -2
  148. package/dist-sdk/src/entities/skill-tool/from-tf.js +32 -11
  149. package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +2 -0
  150. package/dist-sdk/src/entities/skill-tool/to-tf.js +32 -9
  151. package/dist-sdk/src/entities/view/from-tf.d.ts +6 -2
  152. package/dist-sdk/src/entities/view/from-tf.js +11 -9
  153. package/dist-sdk/src/entities/view/to-tf.d.ts +9 -7
  154. package/dist-sdk/src/entities/view/to-tf.js +33 -18
  155. package/dist-sdk/src/entities/view/types.d.ts +1 -1
  156. package/dist-sdk/src/entities/view/types.js +1 -1
  157. package/dist-sdk/src/graph/deferred-catalog-render.d.ts +0 -5
  158. package/dist-sdk/src/graph/deferred-catalog-render.js +1 -20
  159. package/dist-sdk/src/graph/index.d.ts +8 -0
  160. package/dist-sdk/src/graph/index.js +13 -9
  161. package/dist-sdk/src/graph/modules.js +6 -1
  162. package/dist-sdk/src/graph/types.d.ts +77 -3
  163. package/package.json +42 -14
  164. package/dist-sdk/src/entities/automation/value-ref-tf.d.ts +0 -76
  165. package/dist-sdk/src/entities/automation/value-ref-tf.js +0 -190
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * v2 automation printer — walks the SAME `AutomationAst` the v1 deserializer
3
3
  * produces (`src/automations/deserializer/ast.ts`) and emits **v2** EDK
4
- * TypeScript source: an options-shaped `defineAutomation({ name, parent, status,
4
+ * TypeScript source: an options-shaped `defineAutomation({ name, parent,
5
+ * workflowRevision, status,
5
6
  * workflow: defineWorkflow().trigger(...).task(...).outputs(...) })`, exported
6
7
  * as default. `defineAutomation` itself is not chained — the trigger/task/
7
8
  * outputs chain lives on the `workflow` field.
@@ -153,7 +154,11 @@ function printAutomation(ast, opts) {
153
154
  // can alias any factory whose v2 name collides with it before emitting a
154
155
  // single call site.
155
156
  const refName = opts.refName ?? (camelCase(ast.name) || ast.name);
156
- const state = { imports: emptyImports(), localIdentifier: refName };
157
+ const state = {
158
+ imports: emptyImports(),
159
+ localIdentifier: refName,
160
+ ...(opts.foreignAppRefNames !== undefined && { foreignAppRefNames: opts.foreignAppRefNames }),
161
+ };
157
162
  const triggerCode = printTrigger(ast.trigger, state);
158
163
  // The trigger/task/outputs chain lives on the `workflow` field, nested one
159
164
  // level inside the `defineAutomation({...})` object — so tasks print at a
@@ -168,11 +173,14 @@ function printAutomation(ast, opts) {
168
173
  const body = [];
169
174
  body.push(`const ${refName} = defineAutomation({`);
170
175
  body.push(` name: ${quote(ast.name)},`);
171
- body.push(` parent: ${quote(ast.ownerHandle)},`);
172
- body.push(` status: ${quote(ast.status)},`);
173
- if (ast.workflowRevision !== undefined) {
174
- body.push(` workflowRevision: ${quote(ast.workflowRevision)},`);
176
+ body.push(` workflowRevision: ${quote(ast.workflowRevision)},`);
177
+ if (ast.description !== undefined)
178
+ body.push(` description: ${quote(ast.description)},`);
179
+ if (ast.triggersOtherAutomations !== undefined) {
180
+ body.push(` triggersOtherAutomations: ${ast.triggersOtherAutomations},`);
175
181
  }
182
+ body.push(` parent: ${quote(opts.appRefName ?? ast.ownerHandle)},`);
183
+ body.push(` status: ${quote(ast.status)},`);
176
184
  body.push(` workflow: defineWorkflow()`);
177
185
  body.push(`${chain.join("\n")},`);
178
186
  body.push(`});`);
@@ -327,7 +335,9 @@ function printTrigger(trigger, state) {
327
335
  const approvalProcessStatusUpdated = trackFactory("approvalProcessStatusUpdated", state);
328
336
  const parts = [
329
337
  `app: ${printRef(trigger.app, state, DEFAULT_CTX)}`,
330
- `approvalChain: ${quote(trigger.approvalChain)}`,
338
+ `approvalChain: ${typeof trigger.approvalChain === "string"
339
+ ? quote(trigger.approvalChain)
340
+ : printRef(trigger.approvalChain, state, DEFAULT_CTX)}`,
331
341
  `status: ${quote(trigger.status)}`,
332
342
  ];
333
343
  return `${approvalProcessStatusUpdated}({\n ${parts.join(",\n ")}\n })`;
@@ -415,8 +425,15 @@ function printFieldRef(appHandle, fieldKey) {
415
425
  function displayNameArg(task) {
416
426
  return task.displayName ? `, ${quote(task.displayName)}` : "";
417
427
  }
428
+ function topLevelTaskTrailingArgs(task) {
429
+ if (task.hclParent === undefined)
430
+ return displayNameArg(task);
431
+ return `, ${task.displayName ? quote(task.displayName) : "undefined"}, ${quote(task.hclParent)}`;
432
+ }
418
433
  function printTask(task, state, indent) {
419
434
  const pad = " ".repeat(indent);
435
+ if (task.factory === "executeScript")
436
+ return formatExecuteScript(task, state, indent);
420
437
  if (task.factory === "forEach")
421
438
  return formatForEach(task, state, indent);
422
439
  if (task.factory === "switchTask")
@@ -425,7 +442,55 @@ function printTask(task, state, indent) {
425
442
  return formatForkJoin(task, state, indent);
426
443
  const factory = resolveTaskFactory(task.factory, state);
427
444
  const args = printTaskArgs(task, state, indent + 1, DEFAULT_CTX);
428
- return `${pad}.task(${quote(task.refKey)}, (ctx) => ${factory}(${args})${displayNameArg(task)})`;
445
+ return `${pad}.task(${quote(task.refKey)}, (ctx) => ${factory}(${args})${topLevelTaskTrailingArgs(task)})`;
446
+ }
447
+ /**
448
+ * Top-level executeScript — fluent `.executeScript(name, { inputs, code, outputs? })`
449
+ * with function-form `code`. Nested operator bodies still print
450
+ * `childTask(..., executeScript({…}))` via {@link printChildTask}.
451
+ */
452
+ function formatExecuteScript(task, state, indent) {
453
+ const pad = " ".repeat(indent);
454
+ const configPad = " ".repeat(indent + 1);
455
+ const lines = [];
456
+ if (task.args.inputs !== undefined && task.args.inputs !== null && typeof task.args.inputs === "object") {
457
+ const obj = printObjectLiteral(task.args.inputs, state, indent + 1, DEFAULT_CTX);
458
+ lines.push(`${configPad}inputs: (${lambdaParams(obj, "ctx")}) => (${obj}),`);
459
+ }
460
+ const code = task.args.code ?? task.args.script;
461
+ if (typeof code === "string") {
462
+ lines.push(`${configPad}code: ${printScriptCodeFn(code, indent + 1)},`);
463
+ }
464
+ if (task.args.outputs !== undefined && task.args.outputs !== null && typeof task.args.outputs === "object") {
465
+ lines.push(`${configPad}outputs: ${printObjectLiteral(task.args.outputs, state, indent + 1, DEFAULT_CTX)},`);
466
+ }
467
+ else {
468
+ // No `output_schema` on the platform resource — print an explicit `null`
469
+ // rather than omitting the key, so a rebuild doesn't re-infer a schema
470
+ // from the script body and drift from state.
471
+ lines.push(`${configPad}outputs: null,`);
472
+ }
473
+ if (lines.length === 0) {
474
+ return `${pad}.executeScript(${quote(task.refKey)}, {})`;
475
+ }
476
+ return `${pad}.executeScript(${quote(task.refKey)}, {\n${lines.join("\n")}\n${pad}})`;
477
+ }
478
+ /**
479
+ * Wrap a platform script body as `(input) => { … }` for authoring / pull —
480
+ * `code:` is always a real function (#125 banned a raw-string alternative).
481
+ * This writes the body's text into the `.ts` source verbatim; byte-fidelity
482
+ * through the SUBSEQUENT `elementum build` (which would otherwise reformat
483
+ * it via jiti/Babel's transpile-then-`toString()`) is handled separately at
484
+ * build time by `tryExtractFromCurrentSource` (`script-code.ts`), which reads
485
+ * this exact source text back out directly rather than trusting the
486
+ * transpiled runtime function.
487
+ */
488
+ function printScriptCodeFn(body, indent) {
489
+ const pad = " ".repeat(indent);
490
+ const innerPad = " ".repeat(indent + 1);
491
+ const lines = body.replace(/\r\n/g, "\n").split("\n");
492
+ const indented = lines.map((line) => (line.length === 0 ? "" : `${innerPad}${line}`)).join("\n");
493
+ return `(input) => {\n${indented}\n${pad}}`;
429
494
  }
430
495
  /**
431
496
  * Resolve a v1 AST factory string to its v2 factory function name and track
@@ -452,7 +517,35 @@ function formatForEach(task, state, indent) {
452
517
  const childLines = children.map((c) => printChildTask(c, state, indent + 2, childCtx));
453
518
  const tbody = childLines.length > 0 ? `[\n${childLines.join(",\n")}\n${configIndent}]` : `[]`;
454
519
  const tasksBlock = `(${lambdaParams(tbody, "item", "innerCtx")}) => ${tbody}`;
455
- return `${pad}.task(${quote(task.refKey)}, (ctx) => ${forEach}(ctx, {\n${configIndent}collection: ${collectionCode},\n${configIndent}tasks: ${tasksBlock},\n${pad}})${displayNameArg(task)})`;
520
+ return `${pad}.task(${quote(task.refKey)}, (ctx) => ${forEach}(ctx, {\n${configIndent}collection: ${collectionCode},\n${configIndent}tasks: ${tasksBlock},\n${pad}})${topLevelTaskTrailingArgs(task)})`;
521
+ }
522
+ /**
523
+ * Renders a switch's `defaultTasks:` config value. Platform-default label
524
+ * text ("Default") uses the plain `(innerCtx) => [...]` function form;
525
+ * anything else (e.g. a manual rename to "Default Path") is preserved via the
526
+ * `{ label, tasks }` object form so the build round trip reproduces it
527
+ * instead of hardcoding "Default".
528
+ */
529
+ function formatDefaultTasksBlock(defaults, state, indent, configIndent, ctxTypeName) {
530
+ const defaultTasks = defaults.flatMap((ch) => ch.tasks);
531
+ const defaultLabel = defaults.map((ch) => ch.defaultLabel).find((label) => label !== undefined);
532
+ const defaultFilterMode = defaults.map((ch) => ch.defaultFilterMode).find((mode) => mode !== undefined);
533
+ const innerCtx = { ctxName: "innerCtx" };
534
+ const defaultLines = defaultTasks.map((t) => printChildTask(t, state, indent + 2, innerCtx));
535
+ const dbody = defaultLines.length > 0 ? `[\n${defaultLines.join(",\n")}\n${configIndent}]` : `[]`;
536
+ const defaultFn = `(innerCtx: typeof ${ctxTypeName}) => ${dbody}`;
537
+ const needsLabel = defaultLabel !== undefined && defaultLabel !== "Default";
538
+ const needsFilterMode = defaultFilterMode === "explicitTrueFilter";
539
+ if (!needsLabel && !needsFilterMode)
540
+ return defaultFn;
541
+ const innerPad = `${configIndent} `;
542
+ const parts = [];
543
+ if (needsLabel)
544
+ parts.push(`${innerPad}label: ${quote(defaultLabel)}`);
545
+ parts.push(`${innerPad}tasks: ${defaultFn}`);
546
+ if (needsFilterMode)
547
+ parts.push(`${innerPad}defaultFilterMode: "explicitTrueFilter"`);
548
+ return `{\n${parts.join(",\n")},\n${configIndent}}`;
456
549
  }
457
550
  function formatSwitch(task, state, indent) {
458
551
  const pad = " ".repeat(indent);
@@ -466,14 +559,10 @@ function formatSwitch(task, state, indent) {
466
559
  const configParts = [];
467
560
  configParts.push(`${configIndent}cases: [\n${caseLines.join(",\n")}\n${configIndent}]`);
468
561
  if (defaults.length > 0) {
469
- const defaultTasks = defaults.flatMap((ch) => ch.tasks);
470
- const innerCtx = { ctxName: "innerCtx" };
471
- const defaultLines = defaultTasks.map((t) => printChildTask(t, state, indent + 2, innerCtx));
472
- const dbody = defaultLines.length > 0 ? `[\n${defaultLines.join(",\n")}\n${configIndent}]` : `[]`;
473
- const defaultBlock = `(innerCtx: typeof ctx) => ${dbody}`;
562
+ const defaultBlock = formatDefaultTasksBlock(defaults, state, indent, configIndent, "ctx");
474
563
  configParts.push(`${configIndent}defaultTasks: ${defaultBlock}`);
475
564
  }
476
- return `${pad}.task(${quote(task.refKey)}, (ctx) => ${switchTask}(ctx, {\n${configParts.join(",\n")},\n${pad}})${displayNameArg(task)})`;
565
+ return `${pad}.task(${quote(task.refKey)}, (ctx) => ${switchTask}(ctx, {\n${configParts.join(",\n")},\n${pad}})${topLevelTaskTrailingArgs(task)})`;
477
566
  }
478
567
  function formatSwitchCase(ch, state, indent, outerCtxName) {
479
568
  const pad = " ".repeat(indent);
@@ -499,7 +588,7 @@ function formatForkJoin(task, state, indent) {
499
588
  const branches = task.children ?? [];
500
589
  const branchLines = branches.map((ch) => formatForkJoinBranch(ch, state, indent + 2));
501
590
  const branchesBlock = branchLines.length > 0 ? `[\n${branchLines.join(",\n")}\n${configIndent}]` : `[]`;
502
- return `${pad}.task(${quote(task.refKey)}, (ctx) => ${forkJoin}(ctx, {\n${configIndent}branches: ${branchesBlock},\n${pad}})${displayNameArg(task)})`;
591
+ return `${pad}.task(${quote(task.refKey)}, (ctx) => ${forkJoin}(ctx, {\n${configIndent}branches: ${branchesBlock},\n${pad}})${topLevelTaskTrailingArgs(task)})`;
503
592
  }
504
593
  function formatForkJoinBranch(ch, state, indent) {
505
594
  const pad = " ".repeat(indent);
@@ -558,11 +647,7 @@ function formatChildSwitch(task, state, indent, refCtx) {
558
647
  const configParts = [];
559
648
  configParts.push(`${configIndent}cases: [\n${caseLines.join(",\n")}\n${configIndent}]`);
560
649
  if (defaults.length > 0) {
561
- const defaultTasks = defaults.flatMap((ch) => ch.tasks);
562
- const innerCtx = { ctxName: "innerCtx" };
563
- const defaultLines = defaultTasks.map((t) => printChildTask(t, state, indent + 2, innerCtx));
564
- const dbody = defaultLines.length > 0 ? `[\n${defaultLines.join(",\n")}\n${configIndent}]` : `[]`;
565
- const defaultBlock = `(innerCtx: typeof ${refCtx.ctxName}) => ${dbody}`;
650
+ const defaultBlock = formatDefaultTasksBlock(defaults, state, indent, configIndent, refCtx.ctxName);
566
651
  configParts.push(`${configIndent}defaultTasks: ${defaultBlock}`);
567
652
  }
568
653
  return `${pad}childTask(${quote(task.refKey)}, ${switchTask}(${refCtx.ctxName}, {\n${configParts.join(",\n")},\n${pad}})${displayNameArg(task)})`;
@@ -599,6 +684,12 @@ function printTaskArgs(task, state, indent, refCtx) {
599
684
  lines.push(`${pad}fields: ${printFieldAssignments(v, appHandle, state, indent + 1, refCtx)},`);
600
685
  continue;
601
686
  }
687
+ // relateRecords.sources is always a DSL array — even when HCL used a scalar.
688
+ if (k === "sources" && task.factory === "relateRecords") {
689
+ const items = Array.isArray(v) ? v : [v];
690
+ lines.push(`${pad}sources: ${printArrayLiteral(items, state, indent + 1, refCtx)},`);
691
+ continue;
692
+ }
602
693
  const outKey = renames[k] ?? k;
603
694
  lines.push(`${pad}${safeKey(outKey)}: ${printArgValue(k, v, state, indent + 1, refCtx)},`);
604
695
  }
@@ -655,10 +746,9 @@ function printArgValue(name, value, state, indent, refCtx) {
655
746
  return printRef(value, state, refCtx);
656
747
  if (isFilterAst(value))
657
748
  return printFilter(value, state);
658
- // executeScript `script` field — v2's `executeScript` takes the raw code
659
- // as a `code:` string (not an arrow body), so emit a string literal.
660
- if (name === "script" && typeof value === "string") {
661
- return quote(value);
749
+ // executeScript body (AST key `code`, legacy `script`) — always function form.
750
+ if ((name === "code" || name === "script") && typeof value === "string") {
751
+ return printScriptCodeFn(value, indent);
662
752
  }
663
753
  if (Array.isArray(value) && value.length > 0 && isSort(value[0])) {
664
754
  return printSortArray(value, state, refCtx);
@@ -717,6 +807,13 @@ function printRef(ref, state, refCtx) {
717
807
  // output) — always legitimate, so never as-any escape it: non-identifier
718
808
  // names print as typed bracket access (ctx.trigger["STUDENT NAME 2"]).
719
809
  const [head, ...rest] = ref.path;
810
+ // WebhookTriggerOutput's body/headers are Record<string, unknown> — any
811
+ // string key already type-checks there, so a sub-key prints as plain
812
+ // access. printPathAccess's "as any" escape is for genuinely untyped
813
+ // record field paths; using it here would just be a pointless cast.
814
+ if ((head === "body" || head === "headers") && rest.length > 0) {
815
+ return `${ctxName}.trigger${safeMember(head)}${rest.map(safeMember).join("")}`;
816
+ }
720
817
  return printPathAccess(`${ctxName}.trigger${safeMember(head)}`, rest);
721
818
  }
722
819
  case "forEachRef":
@@ -745,8 +842,20 @@ function printRef(ref, state, refCtx) {
745
842
  }
746
843
  case "field":
747
844
  return `catalog.${ref.appHandle}.fields${safeMember(ref.fieldKey)}`;
748
- case "app":
749
- return `catalog.${ref.appHandle}`;
845
+ case "userField":
846
+ return `catalog.users.fields${safeMember(ref.fieldKey)}`;
847
+ case "app": {
848
+ if (ref.entityType === undefined || ref.name === undefined) {
849
+ return `catalog.${ref.appHandle}`;
850
+ }
851
+ // A foreign APP (never an element — this map is app-name-keyed only,
852
+ // board issue #40) already pulled into this workspace resolves to a
853
+ // typed token instead of the always-safe literal stub.
854
+ const foreignRefName = ref.entityType === "app" ? state.foreignAppRefNames?.get(ref.name) : undefined;
855
+ if (foreignRefName !== undefined)
856
+ return `catalog.${foreignRefName}`;
857
+ return `{ __kind: ${quote(ref.entityType)}, refName: ${quote(ref.appHandle)}, name: ${quote(ref.name)} }`;
858
+ }
750
859
  case "agent":
751
860
  return `catalog.${ref.appHandle}.agents${safeMember(ref.agentKey)}`;
752
861
  case "automation":
@@ -756,18 +865,34 @@ function printRef(ref, state, refCtx) {
756
865
  case "documentModelField":
757
866
  return `catalog.${ref.appHandle}.fileReaders${safeMember(ref.documentModelKey)}.fields${safeMember(ref.fieldKey)}`;
758
867
  case "approvalChain":
759
- return `catalog.${ref.appHandle}.approvalChains${safeMember(ref.approvalChainKey)}`;
868
+ // Approval chains are reference-only in the HCL architecture: EDK does
869
+ // not have approval-chain authoring files from which catalog regeneration
870
+ // could rebuild this bag. Keep the provider label as a fully typed token
871
+ // instead of emitting a catalog lookup that disappears on `edk build`.
872
+ return `{ __kind: "approvalChain", refName: ${quote(ref.approvalChainKey)}, name: ${quote(ref.approvalChainKey)}, parent: ${quote(ref.appHandle)}${ref.unresolvedId !== undefined ? `, unresolvedId: ${quote(ref.unresolvedId)}` : ""} }`;
760
873
  case "connector": {
761
- // Connectors are org-level (no appHandle) — emit the minted catalog handle
762
- // the connector catalog resolved (matching what `elementum import connectors`
763
- // wrote), mirroring src/agents/deserializer/print-agent.ts's
764
- // `printConnector`. A catalog miss (no handle resolved) falls back to an
765
- // id-only inline literal that still structurally satisfies `ConnectorRef`.
874
+ // Connectors are org-level (no appHandle), nested under their owning
875
+ // provider — mirrors printConnectorToken in
876
+ // src/entities/agent/deserializer/print-agent-v2.ts. A resolved model
877
+ // with no resolved provider, or no resolution at all, falls back to a
878
+ // TODO that still structurally satisfies `ConnectorRef`.
766
879
  const handle = ref.handle ?? "";
767
- if (handle.length > 0)
768
- return `catalog.connectors${safeMember(handle)}`;
880
+ if (handle.length > 0 && ref.providerKey !== undefined)
881
+ return `catalog.aiProviders.${ref.providerKey}.models.${handle}`;
882
+ if (handle.length > 0) {
883
+ // NOT `catalog.aiProviders.TODO_PROVIDER.models.${handle}` — that
884
+ // reads like a TODO but is a live property-access chain, and
885
+ // TODO_PROVIDER is never a real catalog key, so evaluating it throws
886
+ // the moment anything loads this file instead of failing with the
887
+ // intended diagnostic (same class of bug print-agent-v2.ts's
888
+ // TODO_CONNECTOR_TOKEN had). A plain object literal loads safely and
889
+ // still structurally satisfies `ConnectorRef`.
890
+ return `{ __kind: "connector", refName: ${quote(handle)}, name: ${quote(handle)}, parent: "TODO_PROVIDER" } /* TODO: connector "${handle}" resolved but its AI provider could not be determined */`;
891
+ }
769
892
  return `{ __kind: "connector", refName: ${quote(ref.id)}, name: ${quote(ref.id)} } /* TODO: unresolved connector ${quote(ref.id)} */`;
770
893
  }
894
+ case "cloudLink":
895
+ return `catalog.cloudLinks${safeMember(ref.handle)}`;
771
896
  case "unresolved":
772
897
  // v2 value slots accept a literal directly — no `val()` wrapper. But this
773
898
  // RefExpr kind is also the fallback for ref-typed positions (automation,
@@ -776,6 +901,8 @@ function printRef(ref, state, refCtx) {
776
901
  // the same-purpose fallback in `printFieldAssignments` and keeps the
777
902
  // placeholder compiling regardless of which kind of slot it lands in.
778
903
  return `${quote(ref.uuid)} as any /* TODO: unresolved ${ref.hint} */`;
904
+ case "localRef":
905
+ return `{ kind: "localRef", localName: ${quote(ref.localName)}, path: ${JSON.stringify(ref.path)} }`;
779
906
  }
780
907
  }
781
908
  // ---------------------------------------------------------------------------
@@ -793,9 +920,12 @@ function printLikeOptions(f) {
793
920
  const entries = [];
794
921
  if (f.not)
795
922
  entries.push("not: true");
796
- if (f.caseInsensitive)
797
- entries.push("caseInsensitive: true");
798
- if (f.mode)
923
+ if (f.caseInsensitive !== undefined)
924
+ entries.push(`caseInsensitive: ${f.caseInsensitive}`);
925
+ // "legacy" is the platform's implicit default for a like filter that never
926
+ // had a mode authored — it's always returned on export regardless, so
927
+ // printing it back would fabricate an option the author never set.
928
+ if (f.mode && f.mode !== "legacy")
799
929
  entries.push(`mode: ${quote(f.mode)}`);
800
930
  return entries.length > 0 ? `, { ${entries.join(", ")} }` : "";
801
931
  }
@@ -872,6 +1002,9 @@ function printFilterField(left, state) {
872
1002
  if (left.kind === "field") {
873
1003
  return `catalog.${left.appHandle}.fields${safeMember(left.fieldKey)}`;
874
1004
  }
1005
+ if (left.kind === "userField") {
1006
+ return `catalog.users.fields${safeMember(left.fieldKey)}`;
1007
+ }
875
1008
  if (left.kind === "unresolved") {
876
1009
  return `${quote(left.uuid)} as any /* TODO: unresolved field */`;
877
1010
  }
@@ -904,7 +1037,8 @@ function printFilterPrimitive(v, state) {
904
1037
  case "null":
905
1038
  return "null";
906
1039
  case "currentUser":
907
- return `"" /* TODO: currentUser() unsupported in v2 filter */`;
1040
+ state.imports.filterOps.add("currentUser");
1041
+ return `filter.currentUser(${quote(v.currentUserType)})`;
908
1042
  case "reference":
909
1043
  return printRef(v.ref, state, DEFAULT_CTX);
910
1044
  }
@@ -1016,21 +1150,23 @@ function literalJson(value) {
1016
1150
  */
1017
1151
  function printCustomResponse(customResponse) {
1018
1152
  const parts = [];
1019
- // Print success configuration
1020
1153
  if (customResponse.success) {
1021
1154
  const successParts = [];
1022
1155
  successParts.push(`enabled: ${customResponse.success.enabled}`);
1023
1156
  successParts.push(`format: "${customResponse.success.format}"`);
1024
- successParts.push(`statusCode: ${customResponse.success.statusCode}`);
1157
+ if (customResponse.success.statusCode !== undefined) {
1158
+ successParts.push(`statusCode: ${customResponse.success.statusCode}`);
1159
+ }
1025
1160
  successParts.push(`body: ${quote(customResponse.success.body)}`);
1026
1161
  parts.push(`success: { ${successParts.join(", ")} }`);
1027
1162
  }
1028
- // Print failure configuration
1029
1163
  if (customResponse.failure) {
1030
1164
  const failureParts = [];
1031
1165
  failureParts.push(`enabled: ${customResponse.failure.enabled}`);
1032
1166
  failureParts.push(`format: "${customResponse.failure.format}"`);
1033
- failureParts.push(`statusCode: ${customResponse.failure.statusCode}`);
1167
+ if (customResponse.failure.statusCode !== undefined) {
1168
+ failureParts.push(`statusCode: ${customResponse.failure.statusCode}`);
1169
+ }
1034
1170
  failureParts.push(`body: ${quote(customResponse.failure.body)}`);
1035
1171
  parts.push(`failure: { ${failureParts.join(", ")} }`);
1036
1172
  }
@@ -22,7 +22,7 @@
22
22
  * reference-value conversion is shared with `core/filters` so the two DSLs can't
23
23
  * drift.
24
24
  */
25
- import type { FieldRef } from "../../catalog/index.js";
25
+ import type { FieldRef, UserFieldRef } from "../../catalog/index.js";
26
26
  import { type LikeMode, type ValueType } from "../shared/filters/index.js";
27
27
  import { type Ref } from "../shared/ref.js";
28
28
  /** A wire filter (may embed `FieldRef` tokens at `field` positions). */
@@ -34,9 +34,21 @@ type Primitive = string | number | boolean | null;
34
34
  * from the compared field's `fieldType` (or the operator's `leftType` when the
35
35
  * left side is itself a `Ref`).
36
36
  */
37
- export type FilterValue = Primitive | Ref<unknown> | FieldRef;
37
+ /**
38
+ * Marker produced by {@link currentUser} — compares against the acting
39
+ * user's id/email/domain rather than a literal or ref value. A plain object
40
+ * literal (not a `Ref`/`FieldRef`), recognized by {@link value} before
41
+ * falling through to the primitive cases.
42
+ */
43
+ export interface CurrentUserFilterValue {
44
+ readonly __kind: "currentUser";
45
+ readonly currentUserType: "id" | "email" | "domain";
46
+ }
47
+ export type FilterValue = Primitive | Ref<unknown> | FieldRef | UserFieldRef | CurrentUserFilterValue;
48
+ /** Compare against the current (acting) user — id by default. */
49
+ export declare function currentUser(type?: "id" | "email" | "domain"): CurrentUserFilterValue;
38
50
  /** Either side of a filter: a catalog field token, or a task/trigger/… output ref. */
39
- export type LeftRef = FieldRef | Ref<unknown>;
51
+ export type LeftRef = FieldRef | UserFieldRef | Ref<unknown>;
40
52
  /** Match every record (the minimal valid filter). */
41
53
  export declare function whereTrue(): Filter;
42
54
  /** Match no record. */
@@ -1,5 +1,12 @@
1
1
  import { fieldTypeToValueType, refDataToFilterReference } from "../shared/filters/index.js";
2
2
  import { isRef } from "../shared/ref.js";
3
+ /** Compare against the current (acting) user — id by default. */
4
+ export function currentUser(type = "id") {
5
+ return { __kind: "currentUser", currentUserType: type };
6
+ }
7
+ function isCurrentUserValue(value) {
8
+ return typeof value === "object" && value !== null && !isRef(value) && value.__kind === "currentUser";
9
+ }
3
10
  /**
4
11
  * True when `left` is a genuine `Ref` (task/trigger/… output) rather than a
5
12
  * field. Note this is *not* "is a `FieldRef`" — an unresolved-field
@@ -11,7 +18,8 @@ function isRefLeft(left) {
11
18
  return isRef(left);
12
19
  }
13
20
  function isFieldValue(value) {
14
- return typeof value === "object" && value !== null && !isRef(value) && value.__kind === "field";
21
+ const kind = typeof value === "object" && value !== null ? value.__kind : undefined;
22
+ return !isRef(value) && (kind === "field" || kind === "userField");
15
23
  }
16
24
  /** The wire LHS descriptor: `{ field }` for a FieldRef (or field placeholder), `{ leftValue }` for a Ref. */
17
25
  function leftDescriptor(left, defaultType, leftType) {
@@ -32,6 +40,8 @@ function leftValueType(left, defaultType, leftType) {
32
40
  }
33
41
  /** Map a filter value to the platform's `Value` wire shape, typed `vt`. */
34
42
  function value(vt, v) {
43
+ if (isCurrentUserValue(v))
44
+ return { type: "CURRENT_USER", currentUserType: v.currentUserType };
35
45
  if (isRef(v)) {
36
46
  // A `static` ref (`val(…)`) is a literal in disguise — unwrap it so it
37
47
  // emits as a plain typed value rather than a REFERENCE the platform
@@ -89,7 +99,7 @@ export function like(left, v, options, leftType) {
89
99
  ...leftDescriptor(left, "TEXT", leftType),
90
100
  value: value(vt, v),
91
101
  ...(options?.not ? { not: true } : {}),
92
- ...(options?.caseInsensitive ? { caseInsensitive: true } : {}),
102
+ ...(options?.caseInsensitive !== undefined ? { caseInsensitive: options.caseInsensitive } : {}),
93
103
  ...(options?.mode ? { mode: options.mode } : {}),
94
104
  };
95
105
  }
@@ -1,36 +1,35 @@
1
+ import { type TfBlock, type TfDocument } from "../../engine/tf/index.js";
2
+ import type { AutomationAst } from "./deserializer/ast.js";
3
+ export interface AutomationFromTfResult {
4
+ readonly refName: string;
5
+ readonly tfLabel: string;
6
+ readonly ast: AutomationAst;
7
+ readonly blocks: readonly TfBlock[];
8
+ }
1
9
  /**
2
- * Automation extraction (Phase 1). `automationFromTf` consumes the composite
3
- * HCL blocks for ONE automation (its `elementum_automation` + trigger + task
4
- * blocks + `elementum_workflow_publish`) and produces the `AutomationAst` the
5
- * existing `printAutomationV2` renders to editable `.ts`.
6
- *
7
- * Task ORDER is reconstructed by walking the `parent` chain from the trigger:
8
- * the first task's `parent` is the trigger, each subsequent task's `parent` is
9
- * its predecessor. Unimplemented trigger/task kinds are REPORTED (plan §6),
10
- * never silently dropped — but note a kind we can't reconstruct also can't be
11
- * adopted (see module.ts), so in a full pull they never reach here.
12
- *
13
- * Per the tranche's typing decision: rather than a name-allowlist drift-guard
14
- * (the agent-tool `KNOWN_TOOL_ATTRS` pattern), each IMPLEMENTED kind has its own
15
- * small typed extractor naming the wire fields it reads. The declared-only kinds
16
- * carry no extractor — they are metadata for reporting, never parsed.
10
+ * Best-effort resource footprint of one automation, used ONLY when whole-
11
+ * automation extraction throws (module.ts's `extractAutomations` catch
12
+ * branch) so adoption can exclude the FULL graph - not just the automation
13
+ * root - from its import scope. Without this, a trigger/task/branch/publish
14
+ * address is individually still an "adoptable" resource TYPE (the kind
15
+ * works fine for OTHER automations), so it gets imported into state anyway;
16
+ * build then can't reproduce what it never wrote to source, and `plan`
17
+ * shows those addresses as destroy-on-apply (confirmed live: several
18
+ * automations that failed extraction were imported into state anyway,
19
+ * driving spurious destroys). Deliberately lenient - tolerant of the exact
20
+ * conditions that make real extraction fail (zero/multiple triggers, an
21
+ * unrecognized task kind) - so it over-collects rather than under-collects:
22
+ * a false positive here just leaves one more resource unmanaged, a false
23
+ * negative would silently destroy a live automation on apply.
17
24
  */
18
- import { type TfBlock } from "../../engine/tf/index.js";
19
- import type { AutomationAst } from "./deserializer/ast.js";
25
+ export declare function automationOwnedAddresses(doc: TfDocument, automationLabel: string): readonly string[];
20
26
  export interface AutomationFromTfContext {
21
- /** The owning app's refName — becomes `AutomationAst.ownerHandle` (catalog.<owner>). */
22
27
  readonly ownerHandle: string;
23
28
  readonly diagnostics: string[];
24
29
  }
25
- export interface AutomationFromTfResult {
30
+ export interface AutomationGraphFromTfResult {
26
31
  readonly automation?: AutomationAst;
27
32
  readonly skippedReason?: string;
28
33
  }
29
- /**
30
- * Reconstruct one automation. `blocks` are the family blocks that belong to it
31
- * (already grouped by the caller: same `automation` ref / workflow_publish
32
- * depends_on set). Returns `{ automation }` or `{ skippedReason }`.
33
- */
34
- export declare function automationFromTf(blocks: readonly TfBlock[], ctx: AutomationFromTfContext): AutomationFromTfResult;
35
- /** Recognizes the blocks that make up automation families (for the pull partition). */
36
- export declare function isAutomationFamilyType(type: string | undefined): boolean;
34
+ export declare function automationFromTf(blocks: readonly TfBlock[], ctx: AutomationFromTfContext): AutomationGraphFromTfResult;
35
+ export declare function automationFromTf(doc: TfDocument, automationLabel: string, appRefName: string): AutomationFromTfResult;