@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,3 +1,7 @@
1
+ export { automationFromTf, type AutomationFromTfResult } from "./from-tf.js";
2
+ export { automationModule } from "./module.js";
3
+ export { AUTOMATION_RESOURCE_TYPES, AUTOMATION_TRIGGER_TYPES, AUTOMATION_TASK_TYPES } from "./types.js";
4
+ export { automationToTf, type AutomationToTfContext, type AutomationToTfResult } from "./to-tf.js";
1
5
  /**
2
6
  * v2 automation authoring — the typed, chainable builder (validation slice).
3
7
  *
@@ -1,3 +1,7 @@
1
+ export { automationFromTf } from "./from-tf.js";
2
+ export { automationModule } from "./module.js";
3
+ export { AUTOMATION_RESOURCE_TYPES, AUTOMATION_TRIGGER_TYPES, AUTOMATION_TASK_TYPES } from "./types.js";
4
+ export { automationToTf } from "./to-tf.js";
1
5
  /**
2
6
  * v2 automation authoring — the typed, chainable builder (validation slice).
3
7
  *
@@ -1,9 +1,9 @@
1
1
  /** The automation entity's registry entry (see src/graph/). */
2
- import { isTfExpr, sanitizeName, tfLabelToTsLabel } from "../../engine/tf/index.js";
2
+ import { sanitizeName, tfLabelToTsLabel } from "../../engine/tf/index.js";
3
3
  import { NO_DATA, } from "../../graph/types.js";
4
4
  import { renderAutomationCatalogEntry } from "./catalog-render.js";
5
5
  import { printAutomationV2 } from "./deserializer/print-automation.js";
6
- import { automationFromTf } from "./from-tf.js";
6
+ import { automationFromTf, automationOwnedAddresses } from "./from-tf.js";
7
7
  import { automationToTf } from "./to-tf.js";
8
8
  import { ALL_AUTOMATION_SUB_TYPES, AUTOMATION_RESOURCE_TYPE, WORKFLOW_PUBLISH_RESOURCE_TYPE, } from "./types.js";
9
9
  function isConfigured(value) {
@@ -59,38 +59,24 @@ function automationRefFromAuthoring(args) {
59
59
  ...(outputs !== undefined ? { outputs } : {}),
60
60
  };
61
61
  }
62
- function bareRefLabel(v, refType) {
63
- return v !== undefined && isTfExpr(v) && v.$expr === "resource-attr" && v.type === refType ? v.label : undefined;
64
- }
65
62
  function extractAutomations(ownBlocks, stream, ctx) {
66
- const familyBlocks = stream.familyByKind.get("automation") ?? [];
67
- const taskFamilyBlocks = familyBlocks.filter((b) => b.type?.endsWith("_task"));
68
63
  const items = [];
69
64
  const skipped = [];
70
65
  const diagnostics = [];
71
66
  for (const autoBlock of ownBlocks) {
72
67
  const autoLabel = autoBlock.label ?? "";
73
- const trigger = familyBlocks.find((b) => b.type?.endsWith("_trigger") &&
74
- bareRefLabel(b.attrs["automation"], AUTOMATION_RESOURCE_TYPE) === autoLabel);
75
- const publish = familyBlocks.find((b) => b.type === WORKFLOW_PUBLISH_RESOURCE_TYPE &&
76
- bareRefLabel(b.attrs["automation"], AUTOMATION_RESOURCE_TYPE) === autoLabel);
77
- const group = [
78
- autoBlock,
79
- ...(trigger !== undefined ? [trigger] : []),
80
- ...taskFamilyBlocks,
81
- ...(publish !== undefined ? [publish] : []),
82
- ];
83
- const extractDiagnostics = [];
84
- const { automation, skippedReason } = automationFromTf(group, {
85
- ownerHandle: ctx.appRefName,
86
- diagnostics: extractDiagnostics,
87
- });
88
- diagnostics.push(...extractDiagnostics);
89
- if (automation !== undefined)
90
- items.push(automation);
91
- else if (skippedReason !== undefined) {
92
- skipped.push(`${AUTOMATION_RESOURCE_TYPE}.${autoLabel}`);
93
- diagnostics.push(skippedReason);
68
+ try {
69
+ const extracted = automationFromTf({ blocks: [...stream.allBlocks] }, autoLabel, ctx.appRefName);
70
+ items.push(extracted.ast);
71
+ }
72
+ catch (err) {
73
+ // Report the automation's FULL graph (trigger/tasks/branches/publish),
74
+ // not just its root - otherwise those children's otherwise-adoptable
75
+ // resource TYPES get imported into state anyway, and build (which
76
+ // never wrote this automation to source) can't reproduce them, so
77
+ // `plan` shows them as destroy-on-apply. See automationOwnedAddresses.
78
+ skipped.push(...automationOwnedAddresses({ blocks: [...stream.allBlocks] }, autoLabel));
79
+ diagnostics.push(err instanceof Error ? err.message : String(err));
94
80
  }
95
81
  }
96
82
  return { items, skipped, diagnostics };
@@ -110,7 +96,7 @@ export const automationModule = {
110
96
  { role: "skeleton", resourceType: AUTOMATION_RESOURCE_TYPE, implemented: true },
111
97
  { role: "publish", resourceType: WORKFLOW_PUBLISH_RESOURCE_TYPE, implemented: true },
112
98
  ...ALL_AUTOMATION_SUB_TYPES.map((t) => ({
113
- role: t.resourceType.endsWith("_trigger") ? "trigger" : "task",
99
+ role: t.resourceType.endsWith("_trigger") ? "trigger" : t.resourceType === "elementum_switch_case" || t.resourceType === "elementum_fork_join_branch" ? "branch" : "task",
114
100
  resourceType: t.resourceType,
115
101
  implemented: t.implemented === true,
116
102
  })),
@@ -130,14 +116,25 @@ export const automationModule = {
130
116
  lifecycle: {
131
117
  participates: true,
132
118
  extractOwnFile: extractAutomations,
133
- printOwnFile: (item) => {
119
+ printOwnFile: (item, opts) => {
134
120
  const automation = item;
135
121
  const refName = tfLabelToTsLabel(sanitizeName(automation.name));
136
- return { refName, source: printAutomationV2(automation, { refName }) };
122
+ return {
123
+ refName,
124
+ source: printAutomationV2(automation, {
125
+ refName,
126
+ appRefName: opts.appRefName,
127
+ ...(opts.foreignAppRefNames !== undefined && { foreignAppRefNames: opts.foreignAppRefNames }),
128
+ }),
129
+ };
137
130
  },
138
131
  toTf: (entity, ctx) => automationToTf(entity, {
132
+ appRefName: ctx.appRefName,
139
133
  appTfLabel: ctx.appTfLabel,
140
- diagnostics: ctx.diagnostics,
134
+ fieldAddresses: ctx.fieldAddresses ?? new Map(),
135
+ fieldNames: ctx.fieldNames ?? new Map(),
136
+ fieldMetadata: ctx.fieldMetadata ?? new Map(),
137
+ orgRefs: ctx.orgRefs,
141
138
  }),
142
139
  },
143
140
  catalog: {
@@ -19,6 +19,16 @@ type Empty = Record<string, never>;
19
19
  * `displayName` is only needed when adopting a platform-authored task whose
20
20
  * wire `name` differs from its `refKey` (e.g. a UI-built "For Each" task,
21
21
  * whose slugged refKey is "For_Each"); omit it otherwise.
22
+ *
23
+ * For a nested `executeScript` (`childTask(name, executeScript({...}))`),
24
+ * `def.config.code` was already resolved by the time this runs — the
25
+ * low-level `executeScript()` factory has no way to know its own task name
26
+ * (only the enclosing `childTask()` call does), so it can't consult
27
+ * `tryExtractFromCurrentSource` itself. Here — where `name` finally IS known
28
+ * — swap in the byte-exact body from the tracked automation source when one
29
+ * is found, overriding whatever `extractScriptBody`'s `toString()` fallback
30
+ * already computed. See `script-code.ts` for why that fallback can reformat
31
+ * a pulled script's exact text.
22
32
  */
23
33
  export declare function childTask(name: string, def: TaskDef<unknown>, displayName?: string): ChildTask;
24
34
  export interface ForEachConfig<TTrigger, TTasks extends Record<string, unknown>, TItem> {
@@ -50,8 +60,25 @@ export interface SwitchCase<TTrigger, TTasks extends Record<string, unknown>> {
50
60
  export interface SwitchConfig<TTrigger, TTasks extends Record<string, unknown>> {
51
61
  /** Ordered cases — first match wins. */
52
62
  readonly cases: readonly SwitchCase<TTrigger, TTasks>[];
53
- /** Tasks when no case matches (the default/else branch). */
54
- readonly defaultTasks?: (innerCtx: Context<TTrigger, TTasks>) => readonly ChildTask[];
63
+ /**
64
+ * Tasks when no case matches (the default/else branch). Plain function form
65
+ * matches the platform's usual "Default" display label; pass `{ label,
66
+ * tasks }` to preserve a manually renamed default branch (e.g. "Default
67
+ * Path") through a pull/build round trip.
68
+ */
69
+ readonly defaultTasks?: ((innerCtx: Context<TTrigger, TTasks>) => readonly ChildTask[]) | {
70
+ readonly label?: string;
71
+ readonly tasks: (innerCtx: Context<TTrigger, TTasks>) => readonly ChildTask[];
72
+ /**
73
+ * Internal round-trip detail, set only by `edk pull`: which wire
74
+ * shape the platform is currently using to mark this branch as the
75
+ * default (`is_default = true` vs. an explicit
76
+ * `filter = {type:"true"}` — both are live-confirmed on real orgs
77
+ * for the same case pattern, see #157). Leave unset when
78
+ * hand-authoring a new automation; it defaults to `is_default`.
79
+ */
80
+ readonly defaultFilterMode?: "isDefault" | "explicitTrueFilter";
81
+ };
55
82
  }
56
83
  export declare function switchTask<TTrigger, TTasks extends Record<string, unknown>>(_ctx: Context<TTrigger, TTasks>, config: SwitchConfig<TTrigger, TTasks>): TaskDef<Empty>;
57
84
  export interface ForkJoinBranch<TTrigger, TTasks extends Record<string, unknown>> {
@@ -1,13 +1,30 @@
1
1
  import { buildContext, createForEachItemProxy } from "../shared/context.js";
2
2
  import { FOR_EACH_PLACEHOLDER } from "./build.js";
3
+ import { tryExtractFromCurrentSource } from "./script-code.js";
3
4
  /**
4
5
  * Convenience: name a child task. Equivalent to `{ name, def }`.
5
6
  *
6
7
  * `displayName` is only needed when adopting a platform-authored task whose
7
8
  * wire `name` differs from its `refKey` (e.g. a UI-built "For Each" task,
8
9
  * whose slugged refKey is "For_Each"); omit it otherwise.
10
+ *
11
+ * For a nested `executeScript` (`childTask(name, executeScript({...}))`),
12
+ * `def.config.code` was already resolved by the time this runs — the
13
+ * low-level `executeScript()` factory has no way to know its own task name
14
+ * (only the enclosing `childTask()` call does), so it can't consult
15
+ * `tryExtractFromCurrentSource` itself. Here — where `name` finally IS known
16
+ * — swap in the byte-exact body from the tracked automation source when one
17
+ * is found, overriding whatever `extractScriptBody`'s `toString()` fallback
18
+ * already computed. See `script-code.ts` for why that fallback can reformat
19
+ * a pulled script's exact text.
9
20
  */
10
21
  export function childTask(name, def, displayName) {
22
+ if (def.key === "executeScript") {
23
+ const body = tryExtractFromCurrentSource(name);
24
+ if (body !== undefined && body !== def.config["code"]) {
25
+ return { name, def: { ...def, config: { ...def.config, code: body } }, displayName };
26
+ }
27
+ }
11
28
  return { name, def, displayName };
12
29
  }
13
30
  export function forEach(_ctx, config) {
@@ -29,7 +46,16 @@ export function switchTask(_ctx, config) {
29
46
  tasks: c.tasks(innerCtx),
30
47
  }));
31
48
  if (config.defaultTasks) {
32
- operatorChildren.push({ label: null, tasks: config.defaultTasks(innerCtx) });
49
+ const isPlainFn = typeof config.defaultTasks === "function";
50
+ const tasksFn = isPlainFn ? config.defaultTasks : config.defaultTasks.tasks;
51
+ const defaultLabel = isPlainFn ? undefined : config.defaultTasks.label;
52
+ const defaultFilterMode = isPlainFn ? undefined : config.defaultTasks.defaultFilterMode;
53
+ operatorChildren.push({
54
+ label: null,
55
+ ...(defaultLabel !== undefined ? { defaultLabel } : {}),
56
+ ...(defaultFilterMode !== undefined ? { defaultFilterMode } : {}),
57
+ tasks: tasksFn(innerCtx),
58
+ });
33
59
  }
34
60
  return { key: "switch", config: {}, operatorChildren };
35
61
  }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Single-scalar-output task kinds whose EDK factory exposes the result as
3
+ * `output` (`TaskDef<{ output: unknown }>`), but whose platform wire name
4
+ * differs. aiSummarize/aiTransform were "confirmed against real pulled wire
5
+ * data" per the original note, naming their output `response`; documentModel
6
+ * (rawText data source) names it `text`. aiClassify's `Response` is confirmed
7
+ * directly against a live-deployed task's own `refs` map (Preston High
8
+ * integration run, item 235) — that map is Title-Case (`Reason`, `Response`,
9
+ * `Success`), so the wire name here must match that casing exactly, not the
10
+ * lowercase property name. The aiSummarize/aiTransform `response` entries
11
+ * predate that discovery and have never been exercised by a fixture or live
12
+ * run that references their `.output` from a downstream task/output — their
13
+ * casing is UNVERIFIED and may have the same bug.
14
+ *
15
+ * Used by `build.ts` (forward: `output` → wire name) and `from-tf.ts`
16
+ * (inverse: wire name → `output`) — kept dependency-free so importing it from
17
+ * either side can never introduce a cycle.
18
+ */
19
+ export declare const OUTPUT_KEY_WIRE_NAME: Readonly<Record<string, string>>;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Single-scalar-output task kinds whose EDK factory exposes the result as
3
+ * `output` (`TaskDef<{ output: unknown }>`), but whose platform wire name
4
+ * differs. aiSummarize/aiTransform were "confirmed against real pulled wire
5
+ * data" per the original note, naming their output `response`; documentModel
6
+ * (rawText data source) names it `text`. aiClassify's `Response` is confirmed
7
+ * directly against a live-deployed task's own `refs` map (Preston High
8
+ * integration run, item 235) — that map is Title-Case (`Reason`, `Response`,
9
+ * `Success`), so the wire name here must match that casing exactly, not the
10
+ * lowercase property name. The aiSummarize/aiTransform `response` entries
11
+ * predate that discovery and have never been exercised by a fixture or live
12
+ * run that references their `.output` from a downstream task/output — their
13
+ * casing is UNVERIFIED and may have the same bug.
14
+ *
15
+ * Used by `build.ts` (forward: `output` → wire name) and `from-tf.ts`
16
+ * (inverse: wire name → `output`) — kept dependency-free so importing it from
17
+ * either side can never introduce a cycle.
18
+ */
19
+ export const OUTPUT_KEY_WIRE_NAME = {
20
+ aiSummarize: "response",
21
+ aiTransform: "response",
22
+ aiClassify: "Response",
23
+ documentModel: "text",
24
+ };
@@ -1,24 +1,3 @@
1
- /**
2
- * Function-form `code:` for executeScript (authoring v3).
3
- *
4
- * The platform's script contract (Hydra AddExecuteScriptActionInternalToolProvider):
5
- * the code is a top-level script body with `input` in scope — inputs are read
6
- * via `input.parameters.<name>`, and the script MUST `return` a plain object;
7
- * downstream refs read `result.<key>`. So an authored
8
- *
9
- * code: (input) => { const { X } = input.parameters; return { OUT: X }; }
10
- *
11
- * ships as the function's BODY, extracted from `Function.prototype.toString()`.
12
- *
13
- * Two authoring hazards, handled here:
14
- * - CLOSURES CANNOT SURVIVE: `const x = 5; code: () => ({v: x})` serializes the
15
- * reference, not the value — on the platform `x` is undefined. A best-effort
16
- * free-identifier scan throws at def() time on obvious captures (per the
17
- * tranche decision: best effort, not a guarantee).
18
- * - WHAT YOU AUTHOR IS TRANSPILED FIRST: jiti/tsc strip type annotations and
19
- * may normalize formatting before toString(), so the wire body is the
20
- * transpiled form. Pulled automations print the body as a plain string.
21
- */
22
1
  /** The shape the platform passes to a script: inputs under `parameters`. */
23
2
  export interface ScriptInput<I extends Record<string, unknown> = Record<string, unknown>> {
24
3
  readonly parameters: I;
@@ -60,3 +39,13 @@ export declare function inferOutputSchema(body: string): Record<string, string>
60
39
  * params, keywords, or known script globals.
61
40
  */
62
41
  export declare function freeIdentifiers(body: string, params: ReadonlySet<string>): string[];
42
+ /**
43
+ * Look up task `name`'s `code:` body verbatim from the automation file
44
+ * `elementum build` is currently importing (tracked engine-side by
45
+ * `withSourceText` around each own-file-child's `jiti.import()` —
46
+ * `src/engine/build/build.ts`/`source-context.ts`), or `undefined` if
47
+ * there's no tracked source (not running under `elementum build`, e.g. an
48
+ * automation constructed directly in a test) or the name/shape wasn't found
49
+ * by the scan (falls back to `extractScriptBody`).
50
+ */
51
+ export declare function tryExtractFromCurrentSource(name: string): string | undefined;
@@ -8,17 +8,37 @@
8
8
  *
9
9
  * code: (input) => { const { X } = input.parameters; return { OUT: X }; }
10
10
  *
11
- * ships as the function's BODY, extracted from `Function.prototype.toString()`.
11
+ * ships as the function's BODY. `code:` is ALWAYS a real function — #125
12
+ * deliberately banned a raw-string alternative so pulled automations stay
13
+ * editable TypeScript, not opaque blobs.
12
14
  *
13
15
  * Two authoring hazards, handled here:
14
16
  * - CLOSURES CANNOT SURVIVE: `const x = 5; code: () => ({v: x})` serializes the
15
17
  * reference, not the value — on the platform `x` is undefined. A best-effort
16
18
  * free-identifier scan throws at def() time on obvious captures (per the
17
19
  * tranche decision: best effort, not a guarantee).
18
- * - WHAT YOU AUTHOR IS TRANSPILED FIRST: jiti/tsc strip type annotations and
19
- * may normalize formatting before toString(), so the wire body is the
20
- * transpiled form. Pulled automations print the body as a plain string.
20
+ * - WHAT YOU AUTHOR IS TRANSPILED FIRST: jiti/Babel strip type annotations by
21
+ * fully re-printing the function from its AST, which normalizes formatting
22
+ * (`{done: true}` becomes `{ done: true }`) regardless of the original
23
+ * source's spacing. `Function.prototype.toString()` only ever sees that
24
+ * reprinted form. For a HAND-authored script this is harmless (there is no
25
+ * "original" spacing to preserve — the author's intent survives). For a
26
+ * PULLED script it's lossy: the platform's exact text stops matching after
27
+ * one `edk build`, producing a spurious plan diff forever.
28
+ *
29
+ * `elementum build` avoids that loss for pulled scripts WITHOUT relying on
30
+ * `toString()` at all: `src/engine/build/build.ts` wraps each automation
31
+ * file's jiti import with that file's own untranspiled text (engine-side,
32
+ * entity-agnostic — `source-context.ts`), and `tryExtractFromCurrentSource`
33
+ * here locates the matching `.executeScript("name", { code: (input) => {...}
34
+ * })` (or nested `childTask("name", executeScript({...}))`) call by a
35
+ * lightweight source scan — the same string/comment-aware tokenizing already
36
+ * used by {@link inferOutputSchema} — and slices the body's ORIGINAL text directly out
37
+ * of the file, never touching the transpiled function. `extractScriptBody`
38
+ * (the `toString()` path) remains the fallback for contexts with no tracked
39
+ * source (tests constructing automations directly, nested childTask bodies).
21
40
  */
41
+ import { currentSourceText } from "../../engine/build/source-context.js";
22
42
  /** Globals a script body may legitimately reference on the platform runtime. */
23
43
  const SCRIPT_GLOBALS = new Set([
24
44
  "input",
@@ -89,7 +109,7 @@ export function extractScriptBody(fn) {
89
109
  return finishBody(`return ${expr};`, m[1] ?? m[2] ?? "", src);
90
110
  }
91
111
  throw new ScriptCodeError("executeScript code: could not extract a script body from the function source — " +
92
- "author it as `(input) => { ... return {...}; }` (or pass the body as a string).");
112
+ "author it as `(input) => { ... return {...}; }`.");
93
113
  }
94
114
  function finishBody(rawBody, rawParams, fullSrc) {
95
115
  const body = dedent(rawBody.replace(/^\n+/, "").replace(/\s+$/, ""));
@@ -364,3 +384,250 @@ export function freeIdentifiers(body, params) {
364
384
  }
365
385
  return [...unknown].sort();
366
386
  }
387
+ // ---------------------------------------------------------------------------
388
+ // Byte-exact body extraction from untranspiled source (elementum build only)
389
+ // ---------------------------------------------------------------------------
390
+ /** Per-context (by object identity) cache of `scanExecuteScriptBodies`'s result — parse each file once. */
391
+ const scanCache = new WeakMap();
392
+ /**
393
+ * Look up task `name`'s `code:` body verbatim from the automation file
394
+ * `elementum build` is currently importing (tracked engine-side by
395
+ * `withSourceText` around each own-file-child's `jiti.import()` —
396
+ * `src/engine/build/build.ts`/`source-context.ts`), or `undefined` if
397
+ * there's no tracked source (not running under `elementum build`, e.g. an
398
+ * automation constructed directly in a test) or the name/shape wasn't found
399
+ * by the scan (falls back to `extractScriptBody`).
400
+ */
401
+ export function tryExtractFromCurrentSource(name) {
402
+ const ctx = currentSourceText();
403
+ if (ctx === undefined)
404
+ return undefined;
405
+ let bodies = scanCache.get(ctx);
406
+ if (bodies === undefined) {
407
+ bodies = scanExecuteScriptBodies(ctx.text);
408
+ scanCache.set(ctx, bodies);
409
+ }
410
+ return bodies.get(name);
411
+ }
412
+ /**
413
+ * Scan raw (untranspiled) `.ts` source text for every top-level
414
+ * `.executeScript("name", {...})` call and nested
415
+ * `childTask("name", executeScript({...}))` call, extracting each one's
416
+ * `code:` function body VERBATIM. Reuses this file's own comment/string-aware
417
+ * tokenizing ({@link skipNonCode}/{@link skipString}) rather than a full
418
+ * parser — the input is EDK's own printer output (a predictable shape) plus
419
+ * reasonable hand-edits, not arbitrary JavaScript. A call whose shape doesn't
420
+ * match is simply omitted, not an error — the caller falls back to
421
+ * `extractScriptBody`.
422
+ */
423
+ function scanExecuteScriptBodies(src) {
424
+ const result = new Map();
425
+ const n = src.length;
426
+ let i = 0;
427
+ while (i < n) {
428
+ i = skipNonCode(src, i);
429
+ const c = src[i];
430
+ if (c === undefined)
431
+ break;
432
+ if (c === '"' || c === "'" || c === "`") {
433
+ i = skipString(src, i);
434
+ continue;
435
+ }
436
+ if (isIdentifierBoundaryMatch(src, i, "executeScript")) {
437
+ const openParen = skipWs(src, i + "executeScript".length);
438
+ if (src[openParen] === "(") {
439
+ const call = scanCallArgs(src, openParen);
440
+ if (call !== undefined && call.args.length >= 2) {
441
+ const name = unquoteIfStringLiteral(call.args[0]);
442
+ if (name !== undefined) {
443
+ const body = extractCodeBody(call.args[1]);
444
+ if (body !== undefined)
445
+ result.set(name, dedent(body.replace(/^\n+/, "").replace(/\s+$/, "")));
446
+ }
447
+ }
448
+ }
449
+ }
450
+ if (isIdentifierBoundaryMatch(src, i, "childTask")) {
451
+ const openParen = skipWs(src, i + "childTask".length);
452
+ if (src[openParen] === "(") {
453
+ const call = scanCallArgs(src, openParen);
454
+ if (call !== undefined && call.args.length >= 2) {
455
+ const name = unquoteIfStringLiteral(call.args[0]);
456
+ const inner = call.args[1].trim();
457
+ const innerOpen = "executeScript".length;
458
+ if (name !== undefined && inner.startsWith("executeScript") && inner[innerOpen] === "(" && inner.endsWith(")")) {
459
+ const body = extractCodeBody(inner.slice(innerOpen + 1, -1));
460
+ if (body !== undefined)
461
+ result.set(name, dedent(body.replace(/^\n+/, "").replace(/\s+$/, "")));
462
+ }
463
+ }
464
+ }
465
+ }
466
+ i += 1;
467
+ }
468
+ return result;
469
+ }
470
+ /** True if `src` has identifier `name` starting at `i`, not as a substring of a longer identifier. */
471
+ function isIdentifierBoundaryMatch(src, i, name) {
472
+ return src.startsWith(name, i) && !/[A-Za-z0-9_$]/.test(src[i - 1] ?? "") && !/[A-Za-z0-9_$]/.test(src[i + name.length] ?? "");
473
+ }
474
+ /**
475
+ * Parse a balanced `(...)` argument list starting at `src[open] === "("`.
476
+ * Returns each top-level, comma-separated argument's raw text (untrimmed
477
+ * boundaries trimmed) — undefined if unbalanced before the string ends.
478
+ */
479
+ function scanCallArgs(src, open) {
480
+ const args = [];
481
+ let depth = 0;
482
+ let argStart = open + 1;
483
+ let i = open + 1;
484
+ while (i < src.length) {
485
+ i = skipNonCode(src, i);
486
+ const c = src[i];
487
+ if (c === undefined)
488
+ return undefined;
489
+ if (c === '"' || c === "'" || c === "`") {
490
+ i = skipString(src, i);
491
+ continue;
492
+ }
493
+ if (c === "(" || c === "[" || c === "{") {
494
+ depth += 1;
495
+ i += 1;
496
+ continue;
497
+ }
498
+ if (c === ")" && depth === 0) {
499
+ const arg = src.slice(argStart, i).trim();
500
+ if (arg.length > 0 || args.length > 0)
501
+ args.push(arg);
502
+ return { args };
503
+ }
504
+ if (c === ")" || c === "]" || c === "}") {
505
+ depth -= 1;
506
+ i += 1;
507
+ continue;
508
+ }
509
+ if (c === "," && depth === 0) {
510
+ args.push(src.slice(argStart, i).trim());
511
+ argStart = i + 1;
512
+ i += 1;
513
+ continue;
514
+ }
515
+ i += 1;
516
+ }
517
+ return undefined;
518
+ }
519
+ /** Unwrap a `"..."` / `'...'` / `` `...` `` string-literal argument's raw text; undefined if not a plain string literal. */
520
+ function unquoteIfStringLiteral(text) {
521
+ const t = text.trim();
522
+ if (t.length < 2)
523
+ return undefined;
524
+ const q = t[0];
525
+ if ((q === '"' || q === "'" || q === "`") && t[t.length - 1] === q) {
526
+ return t.slice(1, -1).replace(/\\(.)/g, "$1");
527
+ }
528
+ return undefined;
529
+ }
530
+ /**
531
+ * Given the raw text of an `executeScript(...)` options object literal
532
+ * (starting at its own `{`), find the top-level `code:` property and return
533
+ * its function value's body text verbatim — undefined if there's no `code:`
534
+ * key or its value isn't a recognizable function literal.
535
+ */
536
+ function extractCodeBody(optsText) {
537
+ const n = optsText.length;
538
+ let depth = 0;
539
+ let i = 0;
540
+ while (i < n) {
541
+ i = skipNonCode(optsText, i);
542
+ const c = optsText[i];
543
+ if (c === undefined)
544
+ break;
545
+ if (c === '"' || c === "'" || c === "`") {
546
+ i = skipString(optsText, i);
547
+ continue;
548
+ }
549
+ if (c === "{" || c === "(" || c === "[") {
550
+ depth += 1;
551
+ i += 1;
552
+ continue;
553
+ }
554
+ if (c === "}" || c === ")" || c === "]") {
555
+ depth -= 1;
556
+ i += 1;
557
+ continue;
558
+ }
559
+ if (depth === 1 && isIdentifierBoundaryMatch(optsText, i, "code")) {
560
+ let j = skipWs(optsText, i + "code".length);
561
+ if (optsText[j] === ":") {
562
+ j = skipWs(optsText, j + 1);
563
+ return extractFunctionBlockBodyAt(optsText, j);
564
+ }
565
+ }
566
+ i += 1;
567
+ }
568
+ return undefined;
569
+ }
570
+ /**
571
+ * Given text starting at a function-literal value (`(input) => { ... }` or
572
+ * `function(input) { ... }`, block-bodied only — matches what the printer
573
+ * always emits and what {@link extractScriptBody} otherwise requires), return
574
+ * the exact text between its outermost `{` and `}`.
575
+ */
576
+ function extractFunctionBlockBodyAt(text, start) {
577
+ const n = text.length;
578
+ let i = start;
579
+ let sawArrow = false;
580
+ let parenDepth = 0;
581
+ while (i < n) {
582
+ i = skipNonCode(text, i);
583
+ const c = text[i];
584
+ if (c === undefined)
585
+ return undefined;
586
+ if (c === '"' || c === "'" || c === "`") {
587
+ i = skipString(text, i);
588
+ continue;
589
+ }
590
+ if (text.startsWith("=>", i)) {
591
+ sawArrow = true;
592
+ i += 2;
593
+ continue;
594
+ }
595
+ if (c === "(" || c === "[") {
596
+ parenDepth += 1;
597
+ i += 1;
598
+ continue;
599
+ }
600
+ if (c === ")" || c === "]") {
601
+ parenDepth -= 1;
602
+ i += 1;
603
+ continue;
604
+ }
605
+ if (c === "{" && parenDepth === 0) {
606
+ if (!sawArrow && !/^function\b/.test(text.slice(start, i).trimStart()))
607
+ return undefined;
608
+ const bodyStart = i + 1;
609
+ let blockDepth = 1;
610
+ let k = bodyStart;
611
+ while (k < n && blockDepth > 0) {
612
+ k = skipNonCode(text, k);
613
+ const cc = text[k];
614
+ if (cc === undefined)
615
+ return undefined;
616
+ if (cc === '"' || cc === "'" || cc === "`") {
617
+ k = skipString(text, k);
618
+ continue;
619
+ }
620
+ if (cc === "{")
621
+ blockDepth += 1;
622
+ else if (cc === "}")
623
+ blockDepth -= 1;
624
+ k += 1;
625
+ }
626
+ return blockDepth === 0 ? text.slice(bodyStart, k - 1) : undefined;
627
+ }
628
+ if ((c === "," || c === "}") && parenDepth === 0 && !sawArrow)
629
+ return undefined; // not a function value
630
+ i += 1;
631
+ }
632
+ return undefined;
633
+ }