@elementumai/edk 0.9.18 → 0.9.20

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 (219) hide show
  1. package/README.md +154 -9
  2. package/dist-sdk/src/catalog/factories.d.ts +35 -1
  3. package/dist-sdk/src/catalog/factories.js +36 -0
  4. package/dist-sdk/src/catalog/from-authoring.d.ts +13 -8
  5. package/dist-sdk/src/catalog/from-authoring.js +34 -9
  6. package/dist-sdk/src/catalog/index.d.ts +2 -2
  7. package/dist-sdk/src/catalog/index.js +2 -2
  8. package/dist-sdk/src/catalog/org.d.ts +39 -1
  9. package/dist-sdk/src/catalog/org.js +460 -50
  10. package/dist-sdk/src/catalog/render.js +6 -6
  11. package/dist-sdk/src/catalog/token.js +7 -0
  12. package/dist-sdk/src/catalog/types.d.ts +44 -1
  13. package/dist-sdk/src/catalog/types.js +13 -0
  14. package/dist-sdk/src/core/triggers/on-demand.d.ts +39 -3
  15. package/dist-sdk/src/core/triggers/on-demand.js +10 -2
  16. package/dist-sdk/src/engine/build/context.d.ts +1 -1
  17. package/dist-sdk/src/engine/ei/run.d.ts +149 -0
  18. package/dist-sdk/src/engine/ei/run.js +1132 -0
  19. package/dist-sdk/src/engine/logging.d.ts +17 -0
  20. package/dist-sdk/src/engine/logging.js +18 -0
  21. package/dist-sdk/src/engine/pull/ref-only.d.ts +5 -0
  22. package/dist-sdk/src/engine/pull/ref-only.js +64 -27
  23. package/dist-sdk/src/engine/pull/result-output.d.ts +8 -0
  24. package/dist-sdk/src/engine/pull/result-output.js +88 -4
  25. package/dist-sdk/src/engine/tf/expr.js +39 -14
  26. package/dist-sdk/src/engine/tf/index.d.ts +3 -3
  27. package/dist-sdk/src/engine/tf/index.js +2 -2
  28. package/dist-sdk/src/engine/tf/labels.d.ts +8 -0
  29. package/dist-sdk/src/engine/tf/labels.js +13 -0
  30. package/dist-sdk/src/engine/tf/model.d.ts +22 -1
  31. package/dist-sdk/src/engine/tf/parse.d.ts +19 -0
  32. package/dist-sdk/src/engine/tf/parse.js +197 -10
  33. package/dist-sdk/src/engine/tf/render.d.ts +4 -2
  34. package/dist-sdk/src/engine/tf/render.js +41 -7
  35. package/dist-sdk/src/engine/validation.d.ts +39 -0
  36. package/dist-sdk/src/engine/validation.js +85 -0
  37. package/dist-sdk/src/engine/workspace/loader.js +49 -12
  38. package/dist-sdk/src/entities/access-policy/from-tf.d.ts +11 -1
  39. package/dist-sdk/src/entities/access-policy/from-tf.js +6 -1
  40. package/dist-sdk/src/entities/access-policy/to-tf.d.ts +11 -0
  41. package/dist-sdk/src/entities/access-policy/to-tf.js +16 -6
  42. package/dist-sdk/src/entities/agent/build.d.ts +4 -16
  43. package/dist-sdk/src/entities/agent/build.js +40 -5
  44. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +4 -2
  45. package/dist-sdk/src/entities/agent/to-tf.js +6 -3
  46. package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +2 -0
  47. package/dist-sdk/src/entities/agent-tool/from-tf.js +7 -1
  48. package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +2 -2
  49. package/dist-sdk/src/entities/agent-tool/to-tf.js +29 -6
  50. package/dist-sdk/src/entities/app/build.d.ts +98 -19
  51. package/dist-sdk/src/entities/app/build.js +51 -19
  52. package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +22 -1
  53. package/dist-sdk/src/entities/app/from-tf.d.ts +1 -0
  54. package/dist-sdk/src/entities/app/from-tf.js +11 -5
  55. package/dist-sdk/src/entities/app/index.d.ts +6 -5
  56. package/dist-sdk/src/entities/app/index.js +2 -0
  57. package/dist-sdk/src/entities/app/module.js +18 -2
  58. package/dist-sdk/src/entities/app/to-tf.js +21 -11
  59. package/dist-sdk/src/entities/automation/build.d.ts +49 -6
  60. package/dist-sdk/src/entities/automation/build.js +163 -19
  61. package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +24 -1
  62. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +320 -39
  63. package/dist-sdk/src/entities/automation/from-tf.d.ts +28 -6
  64. package/dist-sdk/src/entities/automation/from-tf.js +563 -74
  65. package/dist-sdk/src/entities/automation/generated/task-output-contracts.d.ts +33 -0
  66. package/dist-sdk/src/entities/automation/generated/task-output-contracts.js +183 -0
  67. package/dist-sdk/src/entities/automation/index.d.ts +2 -2
  68. package/dist-sdk/src/entities/automation/index.js +1 -1
  69. package/dist-sdk/src/entities/automation/module.d.ts +2 -0
  70. package/dist-sdk/src/entities/automation/module.js +93 -8
  71. package/dist-sdk/src/entities/automation/output-field-types.d.ts +7 -0
  72. package/dist-sdk/src/entities/automation/output-field-types.js +36 -0
  73. package/dist-sdk/src/entities/automation/output-key-wire-name.d.ts +9 -0
  74. package/dist-sdk/src/entities/automation/output-key-wire-name.js +13 -0
  75. package/dist-sdk/src/entities/automation/script-code.d.ts +17 -0
  76. package/dist-sdk/src/entities/automation/script-code.js +91 -5
  77. package/dist-sdk/src/entities/automation/system-ref-name.d.ts +16 -0
  78. package/dist-sdk/src/entities/automation/system-ref-name.js +48 -0
  79. package/dist-sdk/src/entities/automation/task-output-labels.d.ts +17 -0
  80. package/dist-sdk/src/entities/automation/task-output-labels.js +47 -0
  81. package/dist-sdk/src/entities/automation/tasks.d.ts +53 -4
  82. package/dist-sdk/src/entities/automation/tasks.js +38 -9
  83. package/dist-sdk/src/entities/automation/to-tf.d.ts +4 -0
  84. package/dist-sdk/src/entities/automation/to-tf.js +647 -167
  85. package/dist-sdk/src/entities/automation/triggers.d.ts +4 -2
  86. package/dist-sdk/src/entities/automation/triggers.js +4 -0
  87. package/dist-sdk/src/entities/automation/types.js +1 -0
  88. package/dist-sdk/src/entities/chart/from-tf.js +33 -17
  89. package/dist-sdk/src/entities/chart/module.js +3 -1
  90. package/dist-sdk/src/entities/chart/printer.d.ts +1 -0
  91. package/dist-sdk/src/entities/chart/printer.js +26 -16
  92. package/dist-sdk/src/entities/chart/rebind-owner.d.ts +3 -0
  93. package/dist-sdk/src/entities/chart/rebind-owner.js +42 -0
  94. package/dist-sdk/src/entities/chart/to-tf.js +21 -12
  95. package/dist-sdk/src/entities/dashboard/build.d.ts +4 -0
  96. package/dist-sdk/src/entities/dashboard/from-tf.js +15 -4
  97. package/dist-sdk/src/entities/dashboard/to-tf.d.ts +2 -0
  98. package/dist-sdk/src/entities/dashboard/to-tf.js +13 -0
  99. package/dist-sdk/src/entities/dashboard-widget/module.js +4 -0
  100. package/dist-sdk/src/entities/dynamic-layout/build.d.ts +72 -30
  101. package/dist-sdk/src/entities/dynamic-layout/dialect.d.ts +3 -0
  102. package/dist-sdk/src/entities/dynamic-layout/dialect.js +5 -0
  103. package/dist-sdk/src/entities/dynamic-layout/from-tf.d.ts +9 -6
  104. package/dist-sdk/src/entities/dynamic-layout/from-tf.js +188 -26
  105. package/dist-sdk/src/entities/dynamic-layout/module.js +4 -1
  106. package/dist-sdk/src/entities/dynamic-layout/to-tf.d.ts +5 -1
  107. package/dist-sdk/src/entities/dynamic-layout/to-tf.js +254 -23
  108. package/dist-sdk/src/entities/element/build.d.ts +33 -13
  109. package/dist-sdk/src/entities/element/build.js +5 -1
  110. package/dist-sdk/src/entities/element/from-tf.d.ts +12 -0
  111. package/dist-sdk/src/entities/element/from-tf.js +64 -3
  112. package/dist-sdk/src/entities/element/index.d.ts +5 -2
  113. package/dist-sdk/src/entities/element/index.js +2 -0
  114. package/dist-sdk/src/entities/element/module.js +11 -3
  115. package/dist-sdk/src/entities/element/to-tf.js +20 -2
  116. package/dist-sdk/src/entities/field/build.d.ts +14 -1
  117. package/dist-sdk/src/entities/field/build.js +3 -0
  118. package/dist-sdk/src/entities/field/from-tf.d.ts +3 -0
  119. package/dist-sdk/src/entities/field/from-tf.js +50 -1
  120. package/dist-sdk/src/entities/field/media-types.d.ts +6 -0
  121. package/dist-sdk/src/entities/field/media-types.js +30 -0
  122. package/dist-sdk/src/entities/field/module.js +1 -0
  123. package/dist-sdk/src/entities/field/to-tf.d.ts +23 -2
  124. package/dist-sdk/src/entities/field/to-tf.js +142 -22
  125. package/dist-sdk/src/entities/file-reader/from-tf.js +14 -5
  126. package/dist-sdk/src/entities/file-reader/module.js +1 -0
  127. package/dist-sdk/src/entities/file-reader/types.d.ts +2 -0
  128. package/dist-sdk/src/entities/file-reader/types.js +1 -1
  129. package/dist-sdk/src/entities/portal/build.d.ts +26 -0
  130. package/dist-sdk/src/entities/portal/build.js +37 -0
  131. package/dist-sdk/src/entities/portal/from-tf.d.ts +27 -0
  132. package/dist-sdk/src/entities/portal/from-tf.js +75 -0
  133. package/dist-sdk/src/entities/portal/index.d.ts +1 -0
  134. package/dist-sdk/src/entities/portal/index.js +1 -0
  135. package/dist-sdk/src/entities/portal/module.d.ts +3 -0
  136. package/dist-sdk/src/entities/portal/module.js +28 -0
  137. package/dist-sdk/src/entities/portal/to-tf.d.ts +12 -0
  138. package/dist-sdk/src/entities/portal/to-tf.js +73 -0
  139. package/dist-sdk/src/entities/portal/types.d.ts +1 -0
  140. package/dist-sdk/src/entities/portal/types.js +1 -0
  141. package/dist-sdk/src/entities/relationship/from-tf.d.ts +8 -1
  142. package/dist-sdk/src/entities/relationship/from-tf.js +53 -10
  143. package/dist-sdk/src/entities/relationship/module.js +2 -0
  144. package/dist-sdk/src/entities/relationship/pair-check.d.ts +7 -0
  145. package/dist-sdk/src/entities/relationship/pair-check.js +68 -0
  146. package/dist-sdk/src/entities/relationship/to-tf.d.ts +10 -0
  147. package/dist-sdk/src/entities/relationship/to-tf.js +31 -13
  148. package/dist-sdk/src/entities/search-table/module.js +1 -0
  149. package/dist-sdk/src/entities/search-table/to-tf.d.ts +1 -0
  150. package/dist-sdk/src/entities/search-table/to-tf.js +1 -1
  151. package/dist-sdk/src/entities/service-account/build.d.ts +15 -2
  152. package/dist-sdk/src/entities/service-account/from-tf.d.ts +2 -4
  153. package/dist-sdk/src/entities/service-account/from-tf.js +17 -5
  154. package/dist-sdk/src/entities/service-account/role-fidelity.d.ts +56 -0
  155. package/dist-sdk/src/entities/service-account/role-fidelity.js +243 -0
  156. package/dist-sdk/src/entities/service-account/to-tf.d.ts +14 -0
  157. package/dist-sdk/src/entities/service-account/to-tf.js +17 -0
  158. package/dist-sdk/src/entities/shared/aspect-target-from-tf.d.ts +1 -1
  159. package/dist-sdk/src/entities/shared/aspect-target-from-tf.js +5 -2
  160. package/dist-sdk/src/entities/shared/filters/ast.d.ts +15 -2
  161. package/dist-sdk/src/entities/shared/filters/index.d.ts +25 -2
  162. package/dist-sdk/src/entities/shared/filters/index.js +38 -5
  163. package/dist-sdk/src/entities/shared/filters/print.js +31 -3
  164. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +25 -3
  165. package/dist-sdk/src/entities/shared/filters/tf-codec.js +51 -15
  166. package/dist-sdk/src/entities/shared/filters/types.d.ts +22 -5
  167. package/dist-sdk/src/entities/shared/foreign-ref.d.ts +16 -0
  168. package/dist-sdk/src/entities/shared/foreign-ref.js +17 -1
  169. package/dist-sdk/src/entities/shared/tool-field-ref.js +6 -9
  170. package/dist-sdk/src/entities/shared/types/field-types.d.ts +10 -5
  171. package/dist-sdk/src/entities/shared/types/field-types.js +4 -0
  172. package/dist-sdk/src/entities/skill/access-policy.d.ts +17 -0
  173. package/dist-sdk/src/entities/skill/access-policy.js +101 -0
  174. package/dist-sdk/src/entities/skill/build.d.ts +3 -0
  175. package/dist-sdk/src/entities/skill/build.js +3 -0
  176. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +4 -1
  177. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +23 -1
  178. package/dist-sdk/src/entities/skill/from-tf.d.ts +2 -0
  179. package/dist-sdk/src/entities/skill/from-tf.js +70 -22
  180. package/dist-sdk/src/entities/skill/index.d.ts +2 -0
  181. package/dist-sdk/src/entities/skill/index.js +1 -0
  182. package/dist-sdk/src/entities/skill/input-coverage.d.ts +7 -0
  183. package/dist-sdk/src/entities/skill/input-coverage.js +11 -0
  184. package/dist-sdk/src/entities/skill/module.js +1 -0
  185. package/dist-sdk/src/entities/skill/to-tf.d.ts +2 -2
  186. package/dist-sdk/src/entities/skill/to-tf.js +19 -6
  187. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +2 -0
  188. package/dist-sdk/src/entities/skill-tool/from-tf.js +8 -2
  189. package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +2 -2
  190. package/dist-sdk/src/entities/skill-tool/to-tf.js +29 -6
  191. package/dist-sdk/src/entities/table/catalog.d.ts +14 -0
  192. package/dist-sdk/src/entities/table/catalog.js +66 -0
  193. package/dist-sdk/src/entities/table/module.js +2 -1
  194. package/dist-sdk/src/entities/table/to-tf.js +5 -5
  195. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.d.ts +89 -0
  196. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.js +277 -0
  197. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.d.ts +51 -0
  198. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.js +360 -0
  199. package/dist-sdk/src/entities/view/agent-view-layout.d.ts +151 -0
  200. package/dist-sdk/src/entities/view/agent-view-layout.js +21 -0
  201. package/dist-sdk/src/entities/view/from-tf.d.ts +6 -3
  202. package/dist-sdk/src/entities/view/from-tf.js +161 -14
  203. package/dist-sdk/src/entities/view/module.js +30 -3
  204. package/dist-sdk/src/entities/view/to-tf.d.ts +24 -2
  205. package/dist-sdk/src/entities/view/to-tf.js +95 -9
  206. package/dist-sdk/src/entities/view/types.d.ts +4 -15
  207. package/dist-sdk/src/entities/view/types.js +17 -15
  208. package/dist-sdk/src/entities/widget/build.d.ts +16 -1
  209. package/dist-sdk/src/entities/widget/build.js +11 -1
  210. package/dist-sdk/src/entities/widget/to-tf.js +36 -10
  211. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +38 -10
  212. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
  213. package/dist-sdk/src/graph/index.d.ts +54 -0
  214. package/dist-sdk/src/graph/index.js +30 -0
  215. package/dist-sdk/src/graph/modules.js +2 -0
  216. package/dist-sdk/src/graph/types.d.ts +133 -2
  217. package/dist-sdk/src/internal/sdk-package.d.ts +1 -1
  218. package/dist-sdk/src/internal/sdk-package.js +1 -0
  219. package/package.json +11 -1
@@ -31,14 +31,15 @@ import { isOnDemandRecordType } from "../shared/types/field-types.js";
31
31
  import { buildContext, createForEachItemProxy } from "../shared/context.js";
32
32
  import { outputFieldTypesFromScriptSchema } from "./output-field-types.js";
33
33
  import { isRef } from "../shared/ref.js";
34
- import { API_TASK_REF_WIRE_NAMES, OUTPUT_KEY_WIRE_NAME } from "./output-key-wire-name.js";
35
- import { extractScriptBody, inferOutputSchema, isScriptFile, readScriptFile, tryExtractFromCurrentSource } from "./script-code.js";
34
+ import { API_TASK_REF_WIRE_NAMES, OUTPUT_KEY_CANONICAL, OUTPUT_KEY_WIRE_NAME } from "./output-key-wire-name.js";
35
+ import { extractScriptBody, inferOutputSchema, isScriptFile, readScriptFile, toPlatformScriptBody, tryExtractFromCurrentSource } from "./script-code.js";
36
36
  import { serializeNode } from "./serialize.js";
37
37
  // Runtime factory imports stay below the public action-native surface. Their
38
38
  // ActionDef return values are an internal serialization detail; authored
39
39
  // automations call the direct fluent methods declared on ActionBuilder.
40
40
  import * as operatorFactories from "./operators.js";
41
41
  import * as actionFactories from "./tasks.js";
42
+ import { AI_SEARCH_TABLE_OUTPUT_NAMES, USER_SEARCH_REF_WIRE_NAMES, WHOLE_RECORD_REF_WIRE_NAMES } from "./task-output-labels.js";
42
43
  import { isWorkflowOutputDeclaration, workflowOutputFieldType, } from "./workflow-output.js";
43
44
  /** Placeholder `forEachTaskRefKey` the forEach item proxy emits; replaced with the real refKey. */
44
45
  export const FOR_EACH_PLACEHOLDER = "__forEach__";
@@ -201,6 +202,14 @@ function collectRecordKinds(tasks) {
201
202
  */
202
203
  const RECORD_BEARING_TASK_KEYS = new Set(["recordSearch", "createRecord", "findRelatedRecords"]);
203
204
  const FIND_RELATED_RECORDS_COUNT_REF_NAMES = new Set(["totalCount", "Records Size", "count"]);
205
+ /** userGroupSearch authoring output → provider refs-map key (captured live with `ei refs --from-remote`). */
206
+ const USER_GROUP_SEARCH_REF_WIRE_NAMES = {
207
+ count: "Groups Size",
208
+ group: "First found group",
209
+ "group.id": "ID",
210
+ "group.name": "Name",
211
+ groups: "All found groups",
212
+ };
204
213
  function findRelatedRecordsTotalCountError(taskRefKey) {
205
214
  const task = taskRefKey === undefined ? "findRelatedRecords" : `findRelatedRecords task "${taskRefKey}"`;
206
215
  return new EntityTfError(`${task} does not expose totalCount. That output is recordSearch-only ` +
@@ -208,6 +217,18 @@ function findRelatedRecordsTotalCountError(taskRefKey) {
208
217
  `for a match count, or ctx.actions.${taskRefKey ?? "<findRelatedRecordsTask>"}.record / .records ` +
209
218
  `for related rows. Do not invent a count ref.`);
210
219
  }
220
+ /**
221
+ * User and user-group searches have a closed output set; any other name
222
+ * (e.g. `totalCount`, which user search does not expose) would compile to a
223
+ * `refs["…"]` key the platform never returns.
224
+ */
225
+ function assertKnownSearchOutput(taskKey, wireNames, name, taskRefKey) {
226
+ const known = new Set([...Object.keys(wireNames), ...Object.values(wireNames)]);
227
+ if (known.has(name))
228
+ return;
229
+ const outputs = Object.keys(wireNames).join(", ");
230
+ throw new EntityTfError(`${taskKey}${taskRefKey === undefined ? "" : ` task "${taskRefKey}"`} has no output "${name}"; its outputs are ${outputs}.`);
231
+ }
211
232
  /**
212
233
  * Forward output-name rewrites, the inverse of the deserializer's read-side
213
234
  * normalization (`applyOutputNameInverseRewrites` in
@@ -246,8 +267,19 @@ function rewriteForwardTaskRefName(taskKey, name, taskRefKey) {
246
267
  if (taskKey === "recordSearch" && name === "totalCount") {
247
268
  return "Records Size";
248
269
  }
249
- if (taskKey === "aiSearchTable" && name === "records") {
250
- return "All Records";
270
+ if (taskKey === "userGroupSearch") {
271
+ assertKnownSearchOutput("userGroupSearch", USER_GROUP_SEARCH_REF_WIRE_NAMES, name, taskRefKey);
272
+ return USER_GROUP_SEARCH_REF_WIRE_NAMES[name] ?? name;
273
+ }
274
+ if (taskKey === "userSearch") {
275
+ assertKnownSearchOutput("userSearch", USER_SEARCH_REF_WIRE_NAMES, name, taskRefKey);
276
+ return USER_SEARCH_REF_WIRE_NAMES[name] ?? name;
277
+ }
278
+ if (taskKey === "executeScript" && name === "textResult") {
279
+ return "Text Result";
280
+ }
281
+ if (taskKey === "aiSearchTable" && AI_SEARCH_TABLE_OUTPUT_NAMES[name] !== undefined) {
282
+ return AI_SEARCH_TABLE_OUTPUT_NAMES[name][0];
251
283
  }
252
284
  if (taskKey === "aiAgent") {
253
285
  const segs = name.split(".");
@@ -271,6 +303,88 @@ function rewriteForwardTaskRefName(taskKey, name, taskRefKey) {
271
303
  }
272
304
  return name;
273
305
  }
306
+ /**
307
+ * CANONICAL reference-name rewrite — used ONLY for workflow-publish OUTPUTS
308
+ * (see DESIGN-canonical-reference-model.md). A workflow output's
309
+ * `taskReference.name` must be the platform's CANONICAL output name
310
+ * (`service_tasks`), NOT the refs-map display label — the platform validates
311
+ * the published output against the canonical name (edk#835). Task INPUTS,
312
+ * FILTERS and CALC mustaches are UNCHANGED (they keep `rewriteForwardTaskRefName`
313
+ * / the display refs-map path — #1271 owns those positions). Maps EDK's friendly
314
+ * accessor → canonical; identity for most kinds. Validated against
315
+ * TASK_OUTPUT_CONTRACTS by canonical-reference-model.test.ts.
316
+ */
317
+ export function rewriteCanonicalOutputRefName(taskKey, name, taskRefKey) {
318
+ if (taskKey === "findRelatedRecords" && FIND_RELATED_RECORDS_COUNT_REF_NAMES.has(name.split(".")[0])) {
319
+ throw findRelatedRecordsTotalCountError(taskRefKey);
320
+ }
321
+ if (taskKey === "api" && name.startsWith("file.")) {
322
+ // apiRequest's file SUB-refs (.file.content / .contentType / .name) have no
323
+ // canonical service_tasks output name of their own — they resolve by the
324
+ // provider's refs-map DISPLAY label ("Content" / "Content Type" / "Name", via
325
+ // API_TASK_REF_WIRE_NAMES). Keep the base display rewrite. Top-level api
326
+ // outputs ARE contract names and ride the envelope as identity.
327
+ return rewriteForwardTaskRefName(taskKey, name, taskRefKey);
328
+ }
329
+ if ((taskKey === "recordSearch" || taskKey === "tableRecordsSearch") && name === "totalCount") {
330
+ // Both expose a `totalCount` accessor, but the executors' canonical count
331
+ // output is `count` (aspect_records_search.count / table_records_search.count).
332
+ return "count";
333
+ }
334
+ if (taskKey === "aiSearchTable" && AI_SEARCH_TABLE_OUTPUT_NAMES[name] !== undefined) {
335
+ return AI_SEARCH_TABLE_OUTPUT_NAMES[name][1];
336
+ }
337
+ if (taskKey === "userSearch" || taskKey === "userGroupSearch") {
338
+ if (taskKey === "userSearch" && (name === "user.managerName" || name === "user.managerEmail")) {
339
+ // Fail fast at build (like findRelatedRecords.totalCount) rather than let
340
+ // the platform reject it at publish: a user's manager fields are NOT
341
+ // referenceable workflow outputs — both the "Manager Name"/"Manager Email"
342
+ // display label and the "user.managerName"/"user.managerEmail" accessor are
343
+ // rejected at publish, and their real canonical name was never captured live.
344
+ const label = name === "user.managerName" ? "Manager Name" : "Manager Email";
345
+ throw new EntityTfError(`userSearch does not expose a referenceable "${name}" workflow output — the platform ` +
346
+ `rejects both the "${label}" label and "${name}" at publish. Reference ` +
347
+ `user.id / user.name / user.email instead, or drop this output.`);
348
+ }
349
+ // A userSearch/userGroupSearch workflow OUTPUT's canonical name IS the
350
+ // authoring accessor (count/group/group.id/group.name/groups and
351
+ // user/users/user.id/user.name/user.email). #1271's TASK_OUTPUT_REFERENCE_NAMES
352
+ // captured the userGroupSearch names live; the display refs-map labels the
353
+ // forward rewrite would otherwise emit ("Groups Size", "ID", …) are rejected
354
+ // at publish (edk#835). The display path stays for inputs/calc/filters,
355
+ // which #1271 owns. See docs/design/canonical-reference-model.md.
356
+ return name;
357
+ }
358
+ if (taskKey === "aiAgent") {
359
+ // aiAgent is NOT a #835 display-label victim: base already emits the correct
360
+ // platform reference via rewriteForwardTaskRefName + to-tf's
361
+ // aiAgentPlatformRefName. Keep that intact by delegating to the forward rewrite.
362
+ return rewriteForwardTaskRefName(taskKey, name, taskRefKey);
363
+ }
364
+ if (taskKey === "documentModel") {
365
+ // file_reader's published output wire name is "text" (confirmed live wire
366
+ // data), NOT a #835 display-label victim. Keep base behavior.
367
+ return rewriteForwardTaskRefName(taskKey, name, taskRefKey);
368
+ }
369
+ if (taskKey === "recordSearch" && name === "record.recordId") {
370
+ // recordSearch exposes a real canonical `recordId` output (service_tasks
371
+ // aspect_records_search.recordId, ASPECT_RECORD_ID) — validated live 0-diff.
372
+ return "recordId";
373
+ }
374
+ if (taskKey !== undefined && RECORD_BEARING_TASK_KEYS.has(taskKey) && name === "record.recordId") {
375
+ // createRecord/findRelatedRecords do NOT expose a `recordId` output
376
+ // (find_related_records has none in service_tasks). Their record-id reference
377
+ // is "Record" (ASPECT_RECORD_ID) — the base behavior. Keep via forward rewrite.
378
+ return rewriteForwardTaskRefName(taskKey, name, taskRefKey);
379
+ }
380
+ const canonicalOutputKey = taskKey ? OUTPUT_KEY_CANONICAL[taskKey] : undefined;
381
+ if (canonicalOutputKey) {
382
+ const segs = name.split(".");
383
+ if (segs[0] === "output")
384
+ return [canonicalOutputKey, ...segs.slice(1)].join(".");
385
+ }
386
+ return name;
387
+ }
274
388
  /**
275
389
  * Walk a serialized wire node and rewrite, in place, the `name` of every task
276
390
  * output reference whose target task needs an output-name rewrite. Two wire
@@ -281,24 +395,45 @@ function rewriteForwardTaskRefName(taskKey, name, taskRefKey) {
281
395
  * the `ref*` filter helpers) — both need the same rewrite. Runs at finalize,
282
396
  * when the full refKey→kind map is known.
283
397
  */
284
- function rewriteTaskOutputRefs(node, taskKindByRefKey) {
398
+ function rewriteTaskOutputRefs(node, taskKindByRefKey,
399
+ // Workflow OUTPUTS pass canonical=true: a `taskReference.name` becomes the
400
+ // platform's CANONICAL service_tasks output name (edk#835). Task inputs and
401
+ // filters (canonical=false, the default) keep the display rewrite — #1271 owns
402
+ // those positions.
403
+ canonical = false) {
285
404
  if (Array.isArray(node)) {
286
405
  for (const item of node)
287
- rewriteTaskOutputRefs(item, taskKindByRefKey);
406
+ rewriteTaskOutputRefs(item, taskKindByRefKey, canonical);
288
407
  return;
289
408
  }
290
409
  if (node === null || typeof node !== "object")
291
410
  return;
292
411
  const rec = node;
412
+ if (Array.isArray(rec.field_mappings)) {
413
+ const mapped = rec.value?.taskReference;
414
+ const wholeRecord = typeof mapped?.taskRefKey === "string" && mapped.name === "record"
415
+ ? WHOLE_RECORD_REF_WIRE_NAMES[taskKindByRefKey.get(mapped.taskRefKey) ?? ""]
416
+ : undefined;
417
+ if (wholeRecord !== undefined)
418
+ mapped.name = wholeRecord;
419
+ }
293
420
  const ref = rec.taskReference;
294
421
  if (ref && typeof ref.taskRefKey === "string" && typeof ref.name === "string") {
295
- ref.name = rewriteForwardTaskRefName(taskKindByRefKey.get(ref.taskRefKey), ref.name, ref.taskRefKey);
422
+ const rewrite = canonical ? rewriteCanonicalOutputRefName : rewriteForwardTaskRefName;
423
+ ref.name = rewrite(taskKindByRefKey.get(ref.taskRefKey), ref.name, ref.taskRefKey);
296
424
  }
297
425
  if (rec.type === "TASK" && typeof rec.taskRefKey === "string" && typeof rec.name === "string") {
426
+ // Filter `{type:"TASK"}` shapes never appear in a workflow OUTPUT subtree;
427
+ // keep the display rewrite (#1271's filter path) regardless of `canonical`.
298
428
  rec.name = rewriteForwardTaskRefName(taskKindByRefKey.get(rec.taskRefKey), rec.name, rec.taskRefKey);
299
429
  }
300
- for (const v of Object.values(rec))
301
- rewriteTaskOutputRefs(v, taskKindByRefKey);
430
+ for (const [key, v] of Object.entries(rec)) {
431
+ // A calc-engine mustache subtree (`calculationReference` → templateReference)
432
+ // keeps the display/forward rewrite even under an output, so its decode
433
+ // (decodeCalculationTaskMustache) stays idempotent.
434
+ const childCanonical = key === "calculationReference" ? false : canonical;
435
+ rewriteTaskOutputRefs(v, taskKindByRefKey, childCanonical);
436
+ }
302
437
  }
303
438
  /**
304
439
  * Walk serialized tasks and assign UUIDs to any `variable.create` entries that
@@ -393,14 +528,14 @@ function serializeOutputValue(value) {
393
528
  }
394
529
  return isRef(value) ? serializeNode(value) : { value };
395
530
  }
396
- function makeActionBuilder(state, mode = "root", item) {
397
- const appendAction = (name, def, displayName, hclParent) => makeActionBuilder({ ...state, tasks: [...state.tasks, { name, def, displayName, hclParent }] }, mode, item);
531
+ function makeActionBuilder(state, mode = "root", item, loops = {}) {
532
+ const appendAction = (name, def, displayName, hclParent) => makeActionBuilder({ ...state, tasks: [...state.tasks, { name, def, displayName, hclParent }] }, mode, item, loops);
398
533
  const context = () => {
399
534
  const base = buildContext(state.tasks.map((entry) => entry.name));
400
- return (item === undefined ? base : { ...base, item });
535
+ return (item === undefined ? base : { ...base, item, loops });
401
536
  };
402
537
  const resolveOptions = (value) => typeof value === "function" ? value(context()) : value;
403
- const materializeNested = (callback, childItem) => callback(makeActionBuilder({ trigger: state.trigger, tasks: [] }, "nested", childItem)).__children();
538
+ const materializeNested = (callback, childItem, childLoops = loops) => callback(makeActionBuilder({ trigger: state.trigger, tasks: [] }, "nested", childItem, childLoops)).__children();
404
539
  const leafFactories = {
405
540
  recordSearch: actionFactories.recordSearch,
406
541
  tableRecordsSearch: actionFactories.tableRecordsSearch,
@@ -427,6 +562,7 @@ function makeActionBuilder(state, mode = "root", item) {
427
562
  addWatcher: actionFactories.addWatcher,
428
563
  saveAttachment: actionFactories.saveAttachment,
429
564
  userSearch: actionFactories.userSearch,
565
+ userGroupSearch: actionFactories.userGroupSearch,
430
566
  initiateCall: actionFactories.initiateCall,
431
567
  recordFieldLocking: actionFactories.recordFieldLocking,
432
568
  unimplementedTask: actionFactories.unimplementedTask,
@@ -452,8 +588,8 @@ function makeActionBuilder(state, mode = "root", item) {
452
588
  // A `scriptFile(...)` reference IS the exact text (no source scan, no
453
589
  // toString(), no closure hazard: it is never a JS closure).
454
590
  const body = isScriptFile(opts.code)
455
- ? readScriptFile(opts.code)
456
- : tryExtractFromCurrentSource(name) ?? extractScriptBody(opts.code);
591
+ ? toPlatformScriptBody(readScriptFile(opts.code), `executeScript "${name}" scriptFile("${opts.code.path}")`, { stripTypes: false })
592
+ : toPlatformScriptBody(tryExtractFromCurrentSource(name) ?? extractScriptBody(opts.code), `executeScript "${name}"`);
457
593
  const outputs = opts.outputs === undefined ? inferOutputSchema(body) : (opts.outputs ?? undefined);
458
594
  const def = actionFactories.executeScriptActionDefWithBody(body, {
459
595
  ...(opts.inputs !== undefined ? { inputs: opts.inputs(context()) } : {}),
@@ -473,8 +609,14 @@ function makeActionBuilder(state, mode = "root", item) {
473
609
  },
474
610
  forEach(name, opts, displayName, hclParent) {
475
611
  const authored = opts;
476
- const childItem = createForEachItemProxy(FOR_EACH_PLACEHOLDER);
477
- const children = materializeNested(authored.actions, childItem);
612
+ // Bind the body's item to this loop's real name, never the shared
613
+ // placeholder: replaceForEachPlaceholder rewrites every placeholder in
614
+ // a forEach task's subtree to that loop, including an OUTER loop's item
615
+ // captured in this task's own collection (an enclosing ctx.item) or
616
+ // read by name from inside (ctx.loops.<outer>.item) (#1320).
617
+ const childItem = createForEachItemProxy(name);
618
+ const childLoops = { ...loops, [name]: { item: childItem } };
619
+ const children = materializeNested(authored.actions, childItem, childLoops);
478
620
  const def = operatorFactories.forEach(context(), {
479
621
  collection: typeof authored.collection === "function" ? authored.collection(context()) : authored.collection,
480
622
  actions: () => children,
@@ -518,7 +660,7 @@ function makeActionBuilder(state, mode = "root", item) {
518
660
  name,
519
661
  value: serializeOutputValue(value),
520
662
  }));
521
- return makeActionBuilder({ ...state, outputs }, mode, item);
663
+ return makeActionBuilder({ ...state, outputs }, mode, item, loops);
522
664
  },
523
665
  __children() {
524
666
  return state.tasks.map((entry) => ({
@@ -542,8 +684,10 @@ function makeActionBuilder(state, mode = "root", item) {
542
684
  const tasks = state.tasks.map((t) => serializeTaskEntry(t.name, t.def, t.displayName, t.hclParent));
543
685
  const outputs = state.outputs?.map((o) => ({ ...o }));
544
686
  rewriteTaskOutputRefs(tasks, taskKindByRefKey);
687
+ // Workflow OUTPUTS emit the platform's CANONICAL output name (edk#835);
688
+ // task inputs/filters above stay on the display path (#1271 owns them).
545
689
  if (outputs)
546
- rewriteTaskOutputRefs(outputs, taskKindByRefKey);
690
+ rewriteTaskOutputRefs(outputs, taskKindByRefKey, /* canonical */ true);
547
691
  // Trigger reference names are NOT canonicalized: the authored name is
548
692
  // the name, everywhere in EDK. (Mobius canonicalizes reference names in
549
693
  // ITS storage — `ValueReference.ofTriggerReference` — but on the tf
@@ -38,6 +38,11 @@ export declare function preserveAuthoredAutomationRevision(freshSource: string,
38
38
  * Extract a string-literal (or `+`-concatenated literals) description from
39
39
  * authored automation source. Pull reprints often omit description entirely
40
40
  * because Go export cannot read it back from the platform today.
41
+ *
42
+ * Only the automation's own `description` counts: the top-level key of the
43
+ * `automation({ ... })` options object, in any key order. A notification
44
+ * step's or on-demand input's `description` inside the actions chain is not
45
+ * the automation's.
41
46
  */
42
47
  export declare function extractAuthoredAutomationDescription(source: string): string | undefined;
43
48
  /**
@@ -48,7 +53,17 @@ export declare function extractAuthoredAutomationDescription(source: string): st
48
53
  * drops the attribute. Without this merge, pull → reprint → build clears
49
54
  * description from config while state still has it, forcing an adopt update.
50
55
  * Prefer a freshly pulled description when present; only reinstate the
51
- * authored value when the fresh source omitted it.
56
+ * authored value when the fresh source omitted it. Both checks and the
57
+ * insertion point are scoped to the automation's own options object, so a
58
+ * step's `description` neither hides nor supplies the automation's.
59
+ *
60
+ * Fail safe: when the fresh source cannot be scanned to its end (for example
61
+ * a pulled script body the scanner cannot tokenize), the authored description
62
+ * is still restored once the scan has reached the top-level `actions` key.
63
+ * The pull printer emits every other option, description included, before
64
+ * `actions`, so at that point the fresh source provably has no description of
65
+ * its own and the insertion point was read exactly. A scan that stops before
66
+ * `actions` leaves the fresh source unchanged.
52
67
  */
53
68
  export declare function preserveAuthoredAutomationDescription(freshSource: string, existingSource: string): string;
54
69
  /** Pull merge: preserve authored revision + description across live reprint. */
@@ -60,6 +75,14 @@ export interface PrintedScriptFile {
60
75
  }
61
76
  /** Folder (inside the automations folder) that holds printed script files. */
62
77
  export declare const SCRIPT_FILES_DIR = "scripts";
78
+ /**
79
+ * Key of the placeholder printed for a forEach item reference to a sibling
80
+ * loop (no authored form, #1320). Build fails on it; re-pull archives a file
81
+ * that still carries it.
82
+ */
83
+ export declare const UNRESOLVED_FOR_EACH_ITEM_KEY = "__edkUnresolvedForEachItem";
84
+ /** True when automation source still carries the unbuildable sibling-loop placeholder. */
85
+ export declare function hasUnresolvedForEachItem(source: string): boolean;
63
86
  export interface PrintAutomationV2Options {
64
87
  readonly refName?: string;
65
88
  /**