@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,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,19 +128,6 @@ 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
@@ -262,32 +256,45 @@ function serializeOutputValue(value) {
262
256
  return isRef(value) ? serializeNode(value) : { value };
263
257
  }
264
258
  function makeWorkflowBuilder(state) {
259
+ const appendTask = (name, def, displayName, hclParent) => makeWorkflowBuilder({ ...state, tasks: [...state.tasks, { name, def, displayName, hclParent }] });
265
260
  const builder = {
266
- task(name, fn, displayName) {
261
+ task(name, fn, displayName, hclParent) {
267
262
  const ctx = buildContext(state.tasks.map((t) => t.name));
268
263
  const def = fn(ctx);
269
- return makeWorkflowBuilder({ ...state, tasks: [...state.tasks, { name, def, displayName }] });
264
+ if (def.key === "executeScript") {
265
+ throw new Error(`Use .executeScript(${JSON.stringify(name)}, { inputs, code }) instead of ` +
266
+ `.task(${JSON.stringify(name)}, () => executeScript(...)). ` +
267
+ `Nested operator bodies still use childTask(..., executeScript({ code: (input) => ... })).`);
268
+ }
269
+ return appendTask(name, def, displayName, hclParent);
270
270
  },
271
271
  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,
272
+ // Resolve the body BYTE-EXACT from the automation file's own
273
+ // untranspiled source when running under `elementum build`
274
+ // (tryExtractFromCurrentSource); fall back to the toString()-based
275
+ // extractScriptBody otherwise (e.g. an automation built directly in a
276
+ // test, with no tracked source file). Either way the body is computed
277
+ // exactly ONCE here and threaded straight into the TaskDef — no
278
+ // separate re-extraction downstream.
279
+ // Explicit `outputs` always wins; an explicit `null` means "no schema"
280
+ // and suppresses inference (pulled sources with no platform
281
+ // output_schema print this, so adopted no-schema scripts do not
282
+ // drift); omitting `outputs` entirely infers from the body.
283
+ const body = tryExtractFromCurrentSource(name) ?? extractScriptBody(opts.code);
284
+ const outputs = opts.outputs === undefined ? inferOutputSchema(body) : (opts.outputs ?? undefined);
285
+ const ctx = buildContext(state.tasks.map((t) => t.name));
286
+ const def = executeScriptTaskDefWithBody(body, {
283
287
  ...(opts.inputs !== undefined ? { inputs: opts.inputs(ctx) } : {}),
284
288
  ...(outputs !== undefined ? { outputs } : {}),
285
- }));
289
+ });
290
+ return appendTask(name, def);
286
291
  },
287
292
  setVariable(name, opts) {
288
- return builder.task(name, (ctx) => setVariableTask({
293
+ const ctx = buildContext(state.tasks.map((t) => t.name));
294
+ const def = setVariableTask({
289
295
  create: [{ name, type: opts.type ?? "TEXT", value: opts.value(ctx) }],
290
- }));
296
+ });
297
+ return appendTask(name, def);
291
298
  },
292
299
  outputs(fn) {
293
300
  const ctx = buildContext(state.tasks.map((t) => t.name));
@@ -306,7 +313,7 @@ function makeWorkflowBuilder(state) {
306
313
  },
307
314
  __finalize() {
308
315
  const taskKindByRefKey = collectTaskKinds(state.tasks);
309
- const tasks = state.tasks.map((t) => serializeTaskEntry(t.name, t.def, t.displayName));
316
+ const tasks = state.tasks.map((t) => serializeTaskEntry(t.name, t.def, t.displayName, t.hclParent));
310
317
  const outputs = state.outputs?.map((o) => ({ ...o }));
311
318
  rewriteTaskOutputRefs(tasks, taskKindByRefKey);
312
319
  if (outputs)
@@ -364,6 +371,9 @@ export function defineWorkflow() {
364
371
  * `AutomationConfigured` with `ref(refName)` and `def(refName)`.
365
372
  */
366
373
  export function defineAutomation(opts) {
374
+ if (validSemver(opts.workflowRevision) === null) {
375
+ throw new EntityTfError(`automation "${opts.name}" has invalid workflowRevision ${JSON.stringify(opts.workflowRevision)}; expected a SemVer string such as "1.0.0"`);
376
+ }
367
377
  return {
368
378
  ref(refName) {
369
379
  const triggerParams = opts.workflow.__triggerParams();
@@ -409,8 +419,10 @@ export function defineAutomation(opts) {
409
419
  refName,
410
420
  payload: {
411
421
  name: opts.name,
422
+ workflowRevision: opts.workflowRevision,
423
+ ...(opts.description !== undefined ? { description: opts.description } : {}),
424
+ triggersOtherAutomations: opts.triggersOtherAutomations ?? false,
412
425
  status: opts.status ?? "DRAFT",
413
- workflowRevision: opts.workflowRevision ?? "1.0.0",
414
426
  trigger: wf.trigger,
415
427
  tasks: wf.tasks,
416
428
  ...(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