@elementumai/edk 0.8.0-preview.11 → 0.8.2-alpha.5

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 (180) hide show
  1. package/README.md +510 -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 +83 -4
  6. package/dist-sdk/src/catalog/from-authoring.js +19 -2
  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 +134 -50
  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 +18 -0
  14. package/dist-sdk/src/catalog/types.d.ts +75 -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 +26 -1
  21. package/dist-sdk/src/engine/build/context.d.ts +58 -0
  22. package/dist-sdk/src/engine/build/context.js +11 -1
  23. package/dist-sdk/src/engine/build/source-context.d.ts +45 -0
  24. package/dist-sdk/src/engine/build/source-context.js +23 -0
  25. package/dist-sdk/src/engine/pull/context.d.ts +15 -0
  26. package/dist-sdk/src/engine/pull/org.d.ts +10 -0
  27. package/dist-sdk/src/engine/pull/org.js +34 -4
  28. package/dist-sdk/src/engine/tf/index.d.ts +2 -2
  29. package/dist-sdk/src/engine/tf/index.js +2 -2
  30. package/dist-sdk/src/engine/tf/labels.d.ts +54 -0
  31. package/dist-sdk/src/engine/tf/labels.js +75 -0
  32. package/dist-sdk/src/engine/tf/parse.d.ts +15 -0
  33. package/dist-sdk/src/engine/tf/parse.js +162 -0
  34. package/dist-sdk/src/entities/access-policy/build.d.ts +26 -0
  35. package/dist-sdk/src/entities/access-policy/build.js +7 -0
  36. package/dist-sdk/src/entities/access-policy/filter.d.ts +61 -0
  37. package/dist-sdk/src/entities/access-policy/filter.js +83 -0
  38. package/dist-sdk/src/entities/access-policy/from-tf.d.ts +66 -0
  39. package/dist-sdk/src/entities/access-policy/from-tf.js +187 -0
  40. package/dist-sdk/src/entities/access-policy/module.d.ts +3 -0
  41. package/dist-sdk/src/entities/access-policy/module.js +17 -0
  42. package/dist-sdk/src/entities/access-policy/to-tf.d.ts +43 -0
  43. package/dist-sdk/src/entities/access-policy/to-tf.js +164 -0
  44. package/dist-sdk/src/entities/access-policy/types.d.ts +4 -0
  45. package/dist-sdk/src/entities/access-policy/types.js +10 -0
  46. package/dist-sdk/src/entities/agent/build.d.ts +2 -0
  47. package/dist-sdk/src/entities/agent/build.js +1 -0
  48. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.d.ts +38 -3
  49. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +257 -32
  50. package/dist-sdk/src/entities/agent/from-tf.d.ts +29 -9
  51. package/dist-sdk/src/entities/agent/from-tf.js +146 -19
  52. package/dist-sdk/src/entities/agent/index.d.ts +1 -1
  53. package/dist-sdk/src/entities/agent/module.js +14 -4
  54. package/dist-sdk/src/entities/agent/to-tf.d.ts +46 -1
  55. package/dist-sdk/src/entities/agent/to-tf.js +160 -14
  56. package/dist-sdk/src/entities/agent/tools.d.ts +88 -9
  57. package/dist-sdk/src/entities/agent/tools.js +46 -7
  58. package/dist-sdk/src/entities/agent-a2a-skill/from-tf.d.ts +17 -0
  59. package/dist-sdk/src/entities/agent-a2a-skill/from-tf.js +64 -0
  60. package/dist-sdk/src/entities/agent-a2a-skill/module.d.ts +4 -0
  61. package/dist-sdk/src/entities/agent-a2a-skill/module.js +14 -0
  62. package/dist-sdk/src/entities/agent-a2a-skill/to-tf.d.ts +40 -0
  63. package/dist-sdk/src/entities/agent-a2a-skill/to-tf.js +47 -0
  64. package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +51 -4
  65. package/dist-sdk/src/entities/agent-tool/from-tf.js +131 -35
  66. package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +11 -4
  67. package/dist-sdk/src/entities/agent-tool/to-tf.js +176 -30
  68. package/dist-sdk/src/entities/agent-tool/types.d.ts +5 -4
  69. package/dist-sdk/src/entities/agent-tool/types.js +38 -6
  70. package/dist-sdk/src/entities/app/build.d.ts +91 -13
  71. package/dist-sdk/src/entities/app/build.js +63 -5
  72. package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +3 -0
  73. package/dist-sdk/src/entities/app/from-tf.d.ts +1 -1
  74. package/dist-sdk/src/entities/app/from-tf.js +32 -22
  75. package/dist-sdk/src/entities/app/index.d.ts +4 -1
  76. package/dist-sdk/src/entities/app/index.js +2 -1
  77. package/dist-sdk/src/entities/app/module.js +10 -2
  78. package/dist-sdk/src/entities/app/to-tf.d.ts +5 -0
  79. package/dist-sdk/src/entities/app/to-tf.js +45 -4
  80. package/dist-sdk/src/entities/automation/build.d.ts +57 -13
  81. package/dist-sdk/src/entities/automation/build.js +62 -42
  82. package/dist-sdk/src/entities/automation/deserializer/ast.d.ts +25 -8
  83. package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +16 -1
  84. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +206 -47
  85. package/dist-sdk/src/entities/automation/filter.d.ts +37 -3
  86. package/dist-sdk/src/entities/automation/filter.js +54 -3
  87. package/dist-sdk/src/entities/automation/from-tf.d.ts +26 -27
  88. package/dist-sdk/src/entities/automation/from-tf.js +1344 -222
  89. package/dist-sdk/src/entities/automation/index.d.ts +4 -0
  90. package/dist-sdk/src/entities/automation/index.js +4 -0
  91. package/dist-sdk/src/entities/automation/module.js +29 -32
  92. package/dist-sdk/src/entities/automation/operators.d.ts +29 -2
  93. package/dist-sdk/src/entities/automation/operators.js +27 -1
  94. package/dist-sdk/src/entities/automation/output-key-wire-name.d.ts +19 -0
  95. package/dist-sdk/src/entities/automation/output-key-wire-name.js +24 -0
  96. package/dist-sdk/src/entities/automation/script-code.d.ts +10 -21
  97. package/dist-sdk/src/entities/automation/script-code.js +272 -5
  98. package/dist-sdk/src/entities/automation/tasks.d.ts +125 -19
  99. package/dist-sdk/src/entities/automation/tasks.js +83 -15
  100. package/dist-sdk/src/entities/automation/to-tf.d.ts +10 -29
  101. package/dist-sdk/src/entities/automation/to-tf.js +1291 -230
  102. package/dist-sdk/src/entities/automation/triggers.d.ts +9 -1
  103. package/dist-sdk/src/entities/automation/types.d.ts +29 -4
  104. package/dist-sdk/src/entities/automation/types.js +76 -46
  105. package/dist-sdk/src/entities/element/build.d.ts +44 -13
  106. package/dist-sdk/src/entities/element/build.js +45 -3
  107. package/dist-sdk/src/entities/element/from-tf.d.ts +1 -1
  108. package/dist-sdk/src/entities/element/from-tf.js +28 -14
  109. package/dist-sdk/src/entities/element/index.d.ts +4 -1
  110. package/dist-sdk/src/entities/element/index.js +2 -1
  111. package/dist-sdk/src/entities/element/module.js +4 -1
  112. package/dist-sdk/src/entities/element/to-tf.js +26 -3
  113. package/dist-sdk/src/entities/field/build.d.ts +61 -14
  114. package/dist-sdk/src/entities/field/build.js +10 -0
  115. package/dist-sdk/src/entities/field/calc/runtime.js +4 -0
  116. package/dist-sdk/src/entities/field/from-tf.d.ts +5 -3
  117. package/dist-sdk/src/entities/field/from-tf.js +118 -7
  118. package/dist-sdk/src/entities/field/module.js +3 -2
  119. package/dist-sdk/src/entities/field/to-tf.d.ts +46 -11
  120. package/dist-sdk/src/entities/field/to-tf.js +166 -17
  121. package/dist-sdk/src/entities/field/types.d.ts +26 -0
  122. package/dist-sdk/src/entities/field/types.js +34 -12
  123. package/dist-sdk/src/entities/file-reader/build.d.ts +108 -50
  124. package/dist-sdk/src/entities/file-reader/build.js +23 -23
  125. package/dist-sdk/src/entities/file-reader/deserializer/print-file-reader.d.ts +6 -0
  126. package/dist-sdk/src/entities/file-reader/deserializer/print-file-reader.js +109 -0
  127. package/dist-sdk/src/entities/file-reader/from-tf.d.ts +13 -0
  128. package/dist-sdk/src/entities/file-reader/from-tf.js +172 -0
  129. package/dist-sdk/src/entities/file-reader/index.d.ts +8 -3
  130. package/dist-sdk/src/entities/file-reader/index.js +7 -2
  131. package/dist-sdk/src/entities/file-reader/module.d.ts +3 -0
  132. package/dist-sdk/src/entities/file-reader/module.js +115 -0
  133. package/dist-sdk/src/entities/file-reader/to-tf.d.ts +14 -0
  134. package/dist-sdk/src/entities/file-reader/to-tf.js +84 -0
  135. package/dist-sdk/src/entities/file-reader/types.d.ts +32 -0
  136. package/dist-sdk/src/entities/file-reader/types.js +30 -0
  137. package/dist-sdk/src/entities/org/ai-provider.d.ts +13 -0
  138. package/dist-sdk/src/entities/org/ai-provider.js +46 -0
  139. package/dist-sdk/src/entities/org/connector.d.ts +8 -1
  140. package/dist-sdk/src/entities/org/connector.js +12 -14
  141. package/dist-sdk/src/entities/org/group.js +10 -1
  142. package/dist-sdk/src/entities/org/index.d.ts +1 -0
  143. package/dist-sdk/src/entities/org/index.js +1 -0
  144. package/dist-sdk/src/entities/org/user.js +10 -1
  145. package/dist-sdk/src/entities/shared/filters/ast.d.ts +59 -9
  146. package/dist-sdk/src/entities/shared/filters/types.d.ts +1 -1
  147. package/dist-sdk/src/entities/shared/tool-field-ref.d.ts +17 -0
  148. package/dist-sdk/src/entities/shared/tool-field-ref.js +46 -0
  149. package/dist-sdk/src/entities/shared/types/field-types.d.ts +10 -1
  150. package/dist-sdk/src/entities/shared/types/field-types.js +9 -0
  151. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +19 -0
  152. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +128 -11
  153. package/dist-sdk/src/entities/skill/from-tf.js +4 -3
  154. package/dist-sdk/src/entities/skill/index.d.ts +1 -1
  155. package/dist-sdk/src/entities/skill/module.js +7 -1
  156. package/dist-sdk/src/entities/skill/to-tf.d.ts +26 -0
  157. package/dist-sdk/src/entities/skill/to-tf.js +65 -4
  158. package/dist-sdk/src/entities/skill/tools.d.ts +37 -8
  159. package/dist-sdk/src/entities/skill/tools.js +43 -1
  160. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +34 -4
  161. package/dist-sdk/src/entities/skill-tool/from-tf.js +128 -18
  162. package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +13 -1
  163. package/dist-sdk/src/entities/skill-tool/to-tf.js +164 -25
  164. package/dist-sdk/src/entities/skill-tool/types.d.ts +5 -7
  165. package/dist-sdk/src/entities/skill-tool/types.js +47 -11
  166. package/dist-sdk/src/entities/view/from-tf.d.ts +6 -2
  167. package/dist-sdk/src/entities/view/from-tf.js +11 -9
  168. package/dist-sdk/src/entities/view/to-tf.d.ts +9 -7
  169. package/dist-sdk/src/entities/view/to-tf.js +39 -18
  170. package/dist-sdk/src/entities/view/types.d.ts +1 -1
  171. package/dist-sdk/src/entities/view/types.js +1 -1
  172. package/dist-sdk/src/graph/deferred-catalog-render.d.ts +0 -5
  173. package/dist-sdk/src/graph/deferred-catalog-render.js +1 -20
  174. package/dist-sdk/src/graph/index.d.ts +8 -0
  175. package/dist-sdk/src/graph/index.js +13 -9
  176. package/dist-sdk/src/graph/modules.js +8 -1
  177. package/dist-sdk/src/graph/types.d.ts +98 -4
  178. package/package.json +49 -16
  179. package/dist-sdk/src/entities/automation/value-ref-tf.d.ts +0 -76
  180. package/dist-sdk/src/entities/automation/value-ref-tf.js +0 -190
@@ -1,7 +1,7 @@
1
1
  import type { AutomationCatalogRef } from "../../catalog/index.js";
2
2
  import { type Context } from "../shared/context.js";
3
3
  import { type Ref, type Simplify, type ValueOrRef } from "../shared/ref.js";
4
- import type { DeployableEntity, EntityDeployOptions, RecordFieldContext } from "../../engine/entity.js";
4
+ import { type DeployableEntity, type EntityDeployOptions, type RecordFieldContext } from "../../engine/entity.js";
5
5
  import { type ScriptInput } from "./script-code.js";
6
6
  /** Structural empty object — neutral element for the `&`-accumulated task map. */
7
7
  type EmptyObject = {
@@ -31,6 +31,7 @@ export interface ChildTask {
31
31
  readonly def: TaskDef<unknown>;
32
32
  /** Display name distinct from `refKey` (`name`), when adopting a platform-authored task. */
33
33
  readonly displayName?: string;
34
+ readonly hclParent?: string;
34
35
  }
35
36
  /**
36
37
  * One branch of an operator: a label (case name, or `null` for forEach body /
@@ -41,6 +42,23 @@ export interface OperatorChild {
41
42
  readonly label: string | null;
42
43
  readonly filter?: Record<string, unknown>;
43
44
  readonly tasks: readonly ChildTask[];
45
+ /**
46
+ * The switch default branch's actual display label, when it deviates from
47
+ * the platform's usual "Default" (e.g. a manually renamed "Default Path").
48
+ * Only meaningful when `label` is `null`; `label` itself stays `null` so
49
+ * `to-tf.ts`/the printer can keep using it as the case-vs-default
50
+ * discriminator.
51
+ */
52
+ readonly defaultLabel?: string;
53
+ /**
54
+ * Which wire shape to-tf.ts should emit for this switch default branch —
55
+ * `"explicitTrueFilter"` for the older `filter = {type:"true"}` form,
56
+ * unset/`"isDefault"` for the newer `is_default = true` form. Only
57
+ * meaningful when `label` is `null`. Round-trip metadata: `edk pull`
58
+ * records whichever shape a case's export actually has (see #157); a
59
+ * hand-authored default branch should leave this unset.
60
+ */
61
+ readonly defaultFilterMode?: "isDefault" | "explicitTrueFilter";
44
62
  }
45
63
  /**
46
64
  * A task definition produced by a factory. `key` is the one-of discriminator the
@@ -109,33 +127,55 @@ type ResolvedRefs<I> = {
109
127
  * dedicated methods whose options take ctx-lambdas. The generic `.task()` stays
110
128
  * as the escape hatch for every other kind.
111
129
  */
130
+ /** Reject `executeScript` TaskDefs through generic `.task()` — use fluent `.executeScript`. */
131
+ type NotExecuteScriptTask<D> = D extends {
132
+ readonly key: "executeScript";
133
+ } ? never : D;
112
134
  export interface WorkflowBuilder<TTrigger, TTasks extends Record<string, unknown>, TVars extends Record<string, unknown> = EmptyObject> extends WorkflowChain {
113
- task<TName extends string, TOutput>(name: TName, fn: (ctx: Context<TTrigger, TTasks, TVars>) => TaskDef<TOutput>,
135
+ /**
136
+ * Generic task escape hatch for every kind except `executeScript` — use
137
+ * {@link WorkflowBuilder.executeScript} for scripts (function-form `code`).
138
+ */
139
+ task<TName extends string, TOutput>(name: TName, fn: (ctx: Context<TTrigger, TTasks, TVars>) => NotExecuteScriptTask<TaskDef<TOutput>>,
114
140
  /**
115
141
  * Display name distinct from `refKey` — only needed when adopting a
116
142
  * platform-authored task whose wire `name` differs from its `refKey`
117
143
  * (e.g. a UI-built "For Each" task, whose slugged refKey is "For_Each").
118
144
  * Omit for normally-authored tasks; the wire name defaults to `refKey`.
119
145
  */
120
- displayName?: string): WorkflowBuilder<TTrigger, Simplify<TTasks & Record<TName, TOutput>>, TVars>;
146
+ displayName?: string, hclParent?: "trigger" | string): WorkflowBuilder<TTrigger, Simplify<TTasks & Record<TName, TOutput>>, TVars>;
121
147
  /**
122
148
  * Fluent executeScript (v3). `inputs` is a ctx-lambda mapping input names to
123
- * refs/values; `code` is a FUNCTION — the TS contract is the authoring
124
- * surface (typed `input.parameters` from `inputs`; the return type flows to
125
- * `ctx.tasks.<name>.result.*` downstream). Its transpiled body ships as the
126
- * platform script. String bodies exist only on the generic factory, for the
127
- * pulled-source path.
149
+ * refs/values; `code` is ALWAYS a FUNCTION — the TS contract is the
150
+ * authoring surface (typed `input.parameters` from `inputs`; the return
151
+ * type flows to `ctx.tasks.<name>.result.*` downstream; no raw-string
152
+ * alternative — #125). Under `elementum build`, the body ships byte-exact
153
+ * from the automation file's own untranspiled source (see
154
+ * `tryExtractFromCurrentSource` in `script-code.ts`) rather than from the
155
+ * transpiled function's `toString()`, which would otherwise reformat a
156
+ * pulled script's exact text on every rebuild. Outside `elementum build`
157
+ * (e.g. constructing an automation directly in a test), the body falls
158
+ * back to `extractScriptBody`'s `toString()` extraction.
128
159
  *
129
160
  * The output schema is INFERRED from the code's `return {...}` literals —
130
161
  * property names statically, property types from literal values (default
131
162
  * text). Pass `outputs` only to override: a non-text property whose value
132
- * isn't a literal, or a return the scan can't enumerate.
163
+ * isn't a literal, or a return the scan can't enumerate. Pass `outputs:
164
+ * null` (rather than omitting it) to explicitly suppress inference — the
165
+ * printer does this for pulled tasks whose platform resource genuinely
166
+ * carries no `output_schema`, so a rebuild doesn't invent one and drift
167
+ * from state.
133
168
  */
134
169
  executeScript<TName extends string, I extends Record<string, ValueOrRef<unknown>> = Record<string, never>, R extends Record<string, unknown> = Record<string, unknown>>(name: TName, opts: {
135
170
  readonly inputs?: (ctx: Context<TTrigger, TTasks, TVars>) => I;
136
171
  readonly code: (input: ScriptInput<ResolvedRefs<I>>) => R;
137
- /** Override the inferred output schema: property name → `"text" | "integer" | "number" | "decimal" | "boolean"`. */
138
- readonly outputs?: Record<string, string>;
172
+ /**
173
+ * Override the inferred output schema: property name → `"text" |
174
+ * "integer" | "number" | "decimal" | "boolean"`. `null` explicitly
175
+ * means "no schema" and suppresses inference; omitting the option
176
+ * infers from the code body.
177
+ */
178
+ readonly outputs?: Record<string, string> | null;
139
179
  }): WorkflowBuilder<TTrigger, Simplify<TTasks & Record<TName, {
140
180
  result: R;
141
181
  textResult: string;
@@ -187,11 +227,15 @@ export declare function defineWorkflow(): WorkflowStarted;
187
227
  export interface AutomationV2Options extends EntityDeployOptions {
188
228
  /** The automation's display name. Changing it updates the existing automation. */
189
229
  readonly name: string;
230
+ /** Explicit SemVer publish gate. Bump only when this workflow should become live. */
231
+ readonly workflowRevision: string;
232
+ /** Optional platform description, preserved by the Terraform authoring path. */
233
+ readonly description?: string;
234
+ /** Whether this workflow may trigger other automations. */
235
+ readonly triggersOtherAutomations?: boolean;
190
236
  /** The owning app's ref name (e.g. `"incidents"`). */
191
237
  readonly parent: string;
192
238
  readonly status?: "DRAFT" | "ACTIVE";
193
- /** Publish token preserved by pull; bump deliberately to republish a changed workflow. */
194
- readonly workflowRevision?: string;
195
239
  /** The workflow body — a `defineWorkflow()` chain with a trigger set. */
196
240
  readonly workflow: WorkflowChain;
197
241
  }
@@ -5,6 +5,7 @@
5
5
  * defineAutomation({
6
6
  * name: "Escalate",
7
7
  * parent: "incidents",
8
+ * workflowRevision: "1.0.0",
8
9
  * status: "DRAFT",
9
10
  * workflow: defineWorkflow()
10
11
  * .trigger(recordCreated({ app }))
@@ -25,13 +26,16 @@
25
26
  * Cross-entity references are `CatalogRef` tokens, resolved at deploy.
26
27
  */
27
28
  import { randomUUID } from "crypto";
29
+ import { valid as validSemver } from "semver";
28
30
  import { buildContext } from "../shared/context.js";
29
31
  import { isRef } from "../shared/ref.js";
32
+ import { EntityTfError } from "../../engine/entity.js";
30
33
  import { serializeNode } from "./serialize.js";
31
- import { extractScriptBody, inferOutputSchema } from "./script-code.js";
32
- // Runtime import of the two Phase-1 factories the fluent methods sugar over.
34
+ import { extractScriptBody, inferOutputSchema, tryExtractFromCurrentSource } from "./script-code.js";
35
+ import { OUTPUT_KEY_WIRE_NAME } from "./output-key-wire-name.js";
36
+ // Runtime import of the Phase-1 factories the fluent methods sugar over.
33
37
  // tasks.ts's own import of build.ts is type-only, so there is no runtime cycle.
34
- import { executeScript as executeScriptTask, setVariable as setVariableTask } from "./tasks.js";
38
+ import { executeScriptTaskDefWithBody, setVariable as setVariableTask } from "./tasks.js";
35
39
  /** Placeholder `forEachTaskRefKey` the forEach item proxy emits; replaced with the real refKey. */
36
40
  export const FOR_EACH_PLACEHOLDER = "__forEach__";
37
41
  /**
@@ -43,16 +47,19 @@ export const FOR_EACH_PLACEHOLDER = "__forEach__";
43
47
  * children become `children`; a forEach task's `__forEach__` placeholder is
44
48
  * swapped for its real refKey.
45
49
  */
46
- function serializeTaskEntry(name, def, displayName) {
50
+ function serializeTaskEntry(name, def, displayName, hclParent) {
47
51
  const result = {
48
52
  refKey: name,
49
53
  task: serializeNode({ [def.key]: { name: displayName ?? name, ...def.config } }),
54
+ ...(hclParent !== undefined ? { hclParent } : {}),
50
55
  };
51
56
  if (def.operatorChildren && def.operatorChildren.length > 0) {
52
57
  result.children = def.operatorChildren.map((child) => ({
53
58
  label: child.label,
54
59
  ...(child.filter !== undefined ? { filter: serializeNode(child.filter) } : {}),
55
- tasks: child.tasks.map((t) => serializeTaskEntry(t.name, t.def, t.displayName)),
60
+ ...(child.defaultLabel !== undefined ? { defaultLabel: child.defaultLabel } : {}),
61
+ ...(child.defaultFilterMode !== undefined ? { defaultFilterMode: child.defaultFilterMode } : {}),
62
+ tasks: child.tasks.map((t) => serializeTaskEntry(t.name, t.def, t.displayName, t.hclParent)),
56
63
  }));
57
64
  }
58
65
  if (def.key === "forEach")
@@ -121,35 +128,27 @@ function collectRecordApps(tasks) {
121
128
  * `RECORD_BEARING_TASK_TYPES` — kept local to avoid a builder → pull-path import.
122
129
  */
123
130
  const RECORD_BEARING_TASK_KEYS = new Set(["recordSearch", "createRecord", "findRelatedRecords"]);
124
- /**
125
- * Single-scalar-output task kinds whose EDK factory exposes the result as
126
- * `output` (`TaskDef<{ output: unknown }>`), but whose platform wire name
127
- * differs. Confirmed against real pulled wire data — aiSummarize/aiTransform
128
- * name their producing task's output `response`; documentModel (rawText data
129
- * source) names it `text`. Mirrors the deserializer's `OUTPUT_KEY_WIRE_NAME`
130
- * (`deserializer/ref-deserializer.ts`) — keep the two in sync.
131
- */
132
- const OUTPUT_KEY_WIRE_NAME = {
133
- aiSummarize: "response",
134
- aiTransform: "response",
135
- documentModel: "text",
136
- };
137
131
  /**
138
132
  * Forward output-name rewrites, the inverse of the deserializer's read-side
139
133
  * normalization (`applyOutputNameInverseRewrites` in
140
134
  * `materialize/ref-deserializer.ts` — keep the two in sync):
141
- * - recordSearch: `totalCount` → the platform's `count`.
135
+ * - recordSearch: `totalCount` → the platform's `Records Size`.
142
136
  * - aiAgent: `result` / `result.<field>` → the platform's
143
137
  * `ai_agent_task_response` (text) / `ai_agent_task_structured_output.<field>` (json).
144
138
  * - record-bearing tasks: the read path reinjects a `.record` hop on the id
145
- * accessor (wire `recordId` → source `record.recordId`); collapse it back to
146
- * the platform's flat `recordId` on write.
139
+ * accessor; collapse it back to the platform's flat wire key on write
140
+ * (recordSearch: `First found record id`; createRecord/findRelatedRecords:
141
+ * `Record` — confirmed live via `ei refs` against a real createRecord/
142
+ * findRelatedRecords task: neither exposes a `recordId` key at all;
143
+ * `Record` (type ASPECT_RECORD_ID) is the one that does, matching the
144
+ * provider's own schema docs for `relate_to_record_reference`
145
+ * ("From create task: `elementum_create_record_task.my_task.refs["Record"]`")).
147
146
  * - single-scalar-output tasks (see `OUTPUT_KEY_WIRE_NAME`): `output` →
148
147
  * the platform's actual output name for that task kind.
149
148
  */
150
149
  function rewriteForwardTaskRefName(taskKey, name) {
151
150
  if (taskKey === "recordSearch" && name === "totalCount") {
152
- return "count";
151
+ return "Records Size";
153
152
  }
154
153
  if (taskKey === "aiAgent") {
155
154
  const segs = name.split(".");
@@ -159,8 +158,11 @@ function rewriteForwardTaskRefName(taskKey, name) {
159
158
  return "ai_agent_task_response";
160
159
  return ["ai_agent_task_structured_output", ...segs.slice(1).map((s) => s.toLowerCase())].join(".");
161
160
  }
162
- if (taskKey && RECORD_BEARING_TASK_KEYS.has(taskKey) && name === "record.recordId") {
163
- return "recordId";
161
+ if (taskKey === "recordSearch" && name === "record.recordId") {
162
+ return "First found record id";
163
+ }
164
+ if (taskKey && RECORD_BEARING_TASK_KEYS.has(taskKey) && taskKey !== "recordSearch" && name === "record.recordId") {
165
+ return "Record";
164
166
  }
165
167
  const wireOutputKey = taskKey ? OUTPUT_KEY_WIRE_NAME[taskKey] : undefined;
166
168
  if (wireOutputKey) {
@@ -262,32 +264,45 @@ function serializeOutputValue(value) {
262
264
  return isRef(value) ? serializeNode(value) : { value };
263
265
  }
264
266
  function makeWorkflowBuilder(state) {
267
+ const appendTask = (name, def, displayName, hclParent) => makeWorkflowBuilder({ ...state, tasks: [...state.tasks, { name, def, displayName, hclParent }] });
265
268
  const builder = {
266
- task(name, fn, displayName) {
269
+ task(name, fn, displayName, hclParent) {
267
270
  const ctx = buildContext(state.tasks.map((t) => t.name));
268
271
  const def = fn(ctx);
269
- return makeWorkflowBuilder({ ...state, tasks: [...state.tasks, { name, def, displayName }] });
272
+ if (def.key === "executeScript") {
273
+ throw new Error(`Use .executeScript(${JSON.stringify(name)}, { inputs, code }) instead of ` +
274
+ `.task(${JSON.stringify(name)}, () => executeScript(...)). ` +
275
+ `Nested operator bodies still use childTask(..., executeScript({ code: (input) => ... })).`);
276
+ }
277
+ return appendTask(name, def, displayName, hclParent);
270
278
  },
271
279
  executeScript(name, opts) {
272
- // Sugar over the generic factory: resolve the ctx-lambda inputs, then
273
- // delegate. The declared return type carries the {result: R} phantom;
274
- // the factory's runtime TaskDef is shape-identical. The body is
275
- // extracted HERE (not left to the factory) so the output schema can be
276
- // inferred from its return literals; the generic factory itself never
277
- // infers — pulled sources must emit exactly the schema the platform
278
- // has, or adopted no-schema scripts would drift.
279
- const body = extractScriptBody(opts.code);
280
- const outputs = opts.outputs ?? inferOutputSchema(body);
281
- return builder.task(name, (ctx) => executeScriptTask({
282
- code: body,
280
+ // Resolve the body BYTE-EXACT from the automation file's own
281
+ // untranspiled source when running under `elementum build`
282
+ // (tryExtractFromCurrentSource); fall back to the toString()-based
283
+ // extractScriptBody otherwise (e.g. an automation built directly in a
284
+ // test, with no tracked source file). Either way the body is computed
285
+ // exactly ONCE here and threaded straight into the TaskDef — no
286
+ // separate re-extraction downstream.
287
+ // Explicit `outputs` always wins; an explicit `null` means "no schema"
288
+ // and suppresses inference (pulled sources with no platform
289
+ // output_schema print this, so adopted no-schema scripts do not
290
+ // drift); omitting `outputs` entirely infers from the body.
291
+ const body = tryExtractFromCurrentSource(name) ?? extractScriptBody(opts.code);
292
+ const outputs = opts.outputs === undefined ? inferOutputSchema(body) : (opts.outputs ?? undefined);
293
+ const ctx = buildContext(state.tasks.map((t) => t.name));
294
+ const def = executeScriptTaskDefWithBody(body, {
283
295
  ...(opts.inputs !== undefined ? { inputs: opts.inputs(ctx) } : {}),
284
296
  ...(outputs !== undefined ? { outputs } : {}),
285
- }));
297
+ });
298
+ return appendTask(name, def);
286
299
  },
287
300
  setVariable(name, opts) {
288
- return builder.task(name, (ctx) => setVariableTask({
301
+ const ctx = buildContext(state.tasks.map((t) => t.name));
302
+ const def = setVariableTask({
289
303
  create: [{ name, type: opts.type ?? "TEXT", value: opts.value(ctx) }],
290
- }));
304
+ });
305
+ return appendTask(name, def);
291
306
  },
292
307
  outputs(fn) {
293
308
  const ctx = buildContext(state.tasks.map((t) => t.name));
@@ -306,7 +321,7 @@ function makeWorkflowBuilder(state) {
306
321
  },
307
322
  __finalize() {
308
323
  const taskKindByRefKey = collectTaskKinds(state.tasks);
309
- const tasks = state.tasks.map((t) => serializeTaskEntry(t.name, t.def, t.displayName));
324
+ const tasks = state.tasks.map((t) => serializeTaskEntry(t.name, t.def, t.displayName, t.hclParent));
310
325
  const outputs = state.outputs?.map((o) => ({ ...o }));
311
326
  rewriteTaskOutputRefs(tasks, taskKindByRefKey);
312
327
  if (outputs)
@@ -364,6 +379,9 @@ export function defineWorkflow() {
364
379
  * `AutomationConfigured` with `ref(refName)` and `def(refName)`.
365
380
  */
366
381
  export function defineAutomation(opts) {
382
+ if (validSemver(opts.workflowRevision) === null) {
383
+ throw new EntityTfError(`automation "${opts.name}" has invalid workflowRevision ${JSON.stringify(opts.workflowRevision)}; expected a SemVer string such as "1.0.0"`);
384
+ }
367
385
  return {
368
386
  ref(refName) {
369
387
  const triggerParams = opts.workflow.__triggerParams();
@@ -409,8 +427,10 @@ export function defineAutomation(opts) {
409
427
  refName,
410
428
  payload: {
411
429
  name: opts.name,
430
+ workflowRevision: opts.workflowRevision,
431
+ ...(opts.description !== undefined ? { description: opts.description } : {}),
432
+ triggersOtherAutomations: opts.triggersOtherAutomations ?? false,
412
433
  status: opts.status ?? "DRAFT",
413
- workflowRevision: opts.workflowRevision ?? "1.0.0",
414
434
  trigger: wf.trigger,
415
435
  tasks: wf.tasks,
416
436
  ...(wf.outputProperties ? { outputProperties: wf.outputProperties } : {}),
@@ -10,8 +10,8 @@
10
10
  * re-exported here for backwards compatibility. Other tool surfaces
11
11
  * (agent search tools, etc.) import the same definitions from there.
12
12
  */
13
- import type { RefExpr, FilterValueAst, FilterAst, SortAst, AppRefAst, FieldRefAst, UnresolvedRefAst } from "../../shared/filters/ast.js";
14
- export type { RefExpr, FilterValueAst, FilterAst, SortAst, AppRefAst, FieldRefAst, UnresolvedRefAst, };
13
+ import type { RefExpr, FilterValueAst, FilterAst, SortAst, ApprovalChainRefAst, AppRefAst, FieldRefAst, UserFieldRefAst, UnresolvedRefAst } from "../../shared/filters/ast.js";
14
+ export type { RefExpr, FilterValueAst, FilterAst, SortAst, AppRefAst, ApprovalChainRefAst, FieldRefAst, UserFieldRefAst, UnresolvedRefAst, };
15
15
  /**
16
16
  * A TaskCall represents one call to a task factory like `executeScript({...})`.
17
17
  * `args` is a map of argument-name -> value; the printer emits each value
@@ -28,11 +28,26 @@ export interface TaskCall {
28
28
  readonly children?: readonly OperatorChildAst[];
29
29
  /** The task's real wire display name, when it differs from `refKey` (e.g. a platform-authored "For Each" vs. the slugged `refKey` "For_Each"). */
30
30
  readonly displayName?: string;
31
+ /** Explicit provider graph parent (`trigger` or another task refKey). */
32
+ readonly hclParent?: string;
31
33
  }
32
34
  export interface OperatorChildAst {
33
35
  readonly label: string | null;
34
36
  readonly filter?: FilterAst;
35
37
  readonly tasks: readonly TaskCall[];
38
+ /** The switch default branch's actual display label, when `label` is `null` and it deviates from "Default". */
39
+ readonly defaultLabel?: string;
40
+ /**
41
+ * Which of the two mutually-exclusive wire shapes this switch default
42
+ * branch was found in (`is_default = true` vs. an explicit
43
+ * `filter = {type:"true"}`) — both are live-confirmed on real orgs for the
44
+ * same case pattern (#157). Only set when the branch used the older
45
+ * filter-based shape; unset means the newer `is_default` shape, which is
46
+ * also to-tf.ts's default when this is absent (e.g. a freshly-authored
47
+ * branch). Present so a rebuild reproduces the shape a pulled case
48
+ * actually has instead of proposing a spurious "update".
49
+ */
50
+ readonly defaultFilterMode?: "isDefault" | "explicitTrueFilter";
36
51
  }
37
52
  export type TriggerAst = {
38
53
  kind: "onDemand";
@@ -74,16 +89,16 @@ export type TriggerAst = {
74
89
  authenticated?: boolean;
75
90
  /** Raw passthrough — printer emits as-is. */
76
91
  customResponse?: {
77
- success: {
92
+ success?: {
78
93
  enabled: boolean;
79
94
  format: "JSON" | "XML" | "Text";
80
- statusCode: number;
95
+ statusCode?: number;
81
96
  body: string;
82
97
  };
83
- failure: {
98
+ failure?: {
84
99
  enabled: boolean;
85
100
  format: "JSON" | "XML" | "Text";
86
- statusCode: number;
101
+ statusCode?: number;
87
102
  body: string;
88
103
  };
89
104
  };
@@ -96,7 +111,7 @@ export type TriggerAst = {
96
111
  } | {
97
112
  kind: "approvalProcessStatusUpdated";
98
113
  app: AppRefAst | UnresolvedRefAst;
99
- approvalChain: string;
114
+ approvalChain: string | ApprovalChainRefAst;
100
115
  status: "ACTIVE" | "STEP_APPROVED" | "CANCELLED" | "DENIED" | "APPROVED";
101
116
  } | {
102
117
  kind: "schedule";
@@ -124,8 +139,10 @@ export type TriggerAst = {
124
139
  export interface AutomationAst {
125
140
  readonly ownerHandle: string;
126
141
  readonly name: string;
142
+ readonly workflowRevision: string;
143
+ readonly description?: string;
144
+ readonly triggersOtherAutomations?: boolean;
127
145
  readonly status: "DRAFT" | "ACTIVE";
128
- readonly workflowRevision?: string;
129
146
  readonly trigger: TriggerAst;
130
147
  readonly tasks: readonly TaskCall[];
131
148
  readonly outputs?: readonly {
@@ -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.
@@ -32,6 +33,20 @@
32
33
  import type { AutomationAst } from "./ast.js";
33
34
  export interface PrintAutomationV2Options {
34
35
  readonly refName?: string;
36
+ /**
37
+ * The owning app's refName to print as `parent:`. Defaults to
38
+ * `ast.ownerHandle` (the app the automation was extracted FROM) — a caller
39
+ * retargeting the file to a different app (e.g. `edk clone app`) must pass
40
+ * this explicitly, or the printed `parent:` silently keeps pointing at the
41
+ * source app.
42
+ */
43
+ readonly appRefName?: string;
44
+ /**
45
+ * Name → refName for every app already on disk in this workspace (board
46
+ * issue #40). A cross-app `app`/aspect reference whose name is a key here
47
+ * prints `catalog.<refName>` instead of the literal stub.
48
+ */
49
+ readonly foreignAppRefNames?: ReadonlyMap<string, string>;
35
50
  }
36
51
  /**
37
52
  * Public entry point. Kept as a thin wrapper so call sites match the v1