@elementumai/edk 0.13.4 → 0.14.0

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 (123) hide show
  1. package/dist-sdk/src/catalog/factories.d.ts +4 -2
  2. package/dist-sdk/src/catalog/factories.js +3 -1
  3. package/dist-sdk/src/catalog/from-authoring.d.ts +8 -3
  4. package/dist-sdk/src/catalog/from-authoring.js +21 -8
  5. package/dist-sdk/src/engine/build/context.d.ts +17 -0
  6. package/dist-sdk/src/engine/coverage-gaps.d.ts +10 -0
  7. package/dist-sdk/src/engine/coverage-gaps.js +16 -0
  8. package/dist-sdk/src/engine/pull/context.d.ts +56 -0
  9. package/dist-sdk/src/engine/pull/context.js +8 -0
  10. package/dist-sdk/src/engine/pull/pulled-roots.d.ts +14 -1
  11. package/dist-sdk/src/engine/pull/pulled-roots.js +23 -3
  12. package/dist-sdk/src/engine/pull/ref-only.d.ts +6 -1
  13. package/dist-sdk/src/engine/pull/ref-only.js +4 -1
  14. package/dist-sdk/src/engine/pull/stream-root.d.ts +13 -1
  15. package/dist-sdk/src/engine/pull/stream-root.js +54 -4
  16. package/dist-sdk/src/engine/validation.d.ts +36 -1
  17. package/dist-sdk/src/engine/validation.js +56 -2
  18. package/dist-sdk/src/engine/workspace/loader.d.ts +6 -0
  19. package/dist-sdk/src/engine/workspace/loader.js +87 -2
  20. package/dist-sdk/src/entities/access-policy/from-tf.d.ts +7 -0
  21. package/dist-sdk/src/entities/access-policy/from-tf.js +58 -17
  22. package/dist-sdk/src/entities/access-policy/to-tf.d.ts +3 -1
  23. package/dist-sdk/src/entities/access-policy/to-tf.js +1 -1
  24. package/dist-sdk/src/entities/agent/build.d.ts +15 -0
  25. package/dist-sdk/src/entities/agent/build.js +139 -16
  26. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.d.ts +3 -3
  27. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +39 -25
  28. package/dist-sdk/src/entities/agent/module.js +95 -3
  29. package/dist-sdk/src/entities/agent/to-tf.js +6 -4
  30. package/dist-sdk/src/entities/agent-evaluation/from-tf.d.ts +7 -0
  31. package/dist-sdk/src/entities/agent-evaluation/from-tf.js +14 -5
  32. package/dist-sdk/src/entities/agent-evaluation/module.js +4 -2
  33. package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +11 -2
  34. package/dist-sdk/src/entities/agent-tool/from-tf.js +38 -40
  35. package/dist-sdk/src/entities/agent-tool/to-tf.js +12 -5
  36. package/dist-sdk/src/entities/app/build.d.ts +1 -1
  37. package/dist-sdk/src/entities/automation/build.d.ts +75 -42
  38. package/dist-sdk/src/entities/automation/build.js +17 -7
  39. package/dist-sdk/src/entities/automation/deserializer/ast.d.ts +14 -2
  40. package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +9 -0
  41. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +57 -12
  42. package/dist-sdk/src/entities/automation/from-tf.d.ts +51 -0
  43. package/dist-sdk/src/entities/automation/from-tf.js +476 -93
  44. package/dist-sdk/src/entities/automation/index.d.ts +1 -1
  45. package/dist-sdk/src/entities/automation/index.js +1 -1
  46. package/dist-sdk/src/entities/automation/module.js +90 -9
  47. package/dist-sdk/src/entities/automation/operators.d.ts +6 -2
  48. package/dist-sdk/src/entities/automation/operators.js +0 -2
  49. package/dist-sdk/src/entities/automation/task-output-labels.d.ts +8 -0
  50. package/dist-sdk/src/entities/automation/task-output-labels.js +11 -0
  51. package/dist-sdk/src/entities/automation/tasks.d.ts +37 -2
  52. package/dist-sdk/src/entities/automation/tasks.js +38 -1
  53. package/dist-sdk/src/entities/automation/to-tf.d.ts +8 -0
  54. package/dist-sdk/src/entities/automation/to-tf.js +413 -47
  55. package/dist-sdk/src/entities/chart/to-tf.js +18 -5
  56. package/dist-sdk/src/entities/dashboard/from-tf.js +45 -11
  57. package/dist-sdk/src/entities/dashboard-widget-order/order.d.ts +5 -3
  58. package/dist-sdk/src/entities/dashboard-widget-order/order.js +6 -4
  59. package/dist-sdk/src/entities/datamine/from-tf.js +10 -3
  60. package/dist-sdk/src/entities/dynamic-layout/build.d.ts +9 -2
  61. package/dist-sdk/src/entities/dynamic-layout/from-tf.js +35 -7
  62. package/dist-sdk/src/entities/dynamic-layout/to-tf.js +63 -7
  63. package/dist-sdk/src/entities/element/build.d.ts +4 -1
  64. package/dist-sdk/src/entities/element/build.js +3 -4
  65. package/dist-sdk/src/entities/field/from-tf.js +8 -1
  66. package/dist-sdk/src/entities/field/to-tf.d.ts +29 -2
  67. package/dist-sdk/src/entities/field/to-tf.js +106 -7
  68. package/dist-sdk/src/entities/phone-service/from-tf.d.ts +7 -0
  69. package/dist-sdk/src/entities/phone-service/from-tf.js +15 -7
  70. package/dist-sdk/src/entities/phone-service/module.js +4 -2
  71. package/dist-sdk/src/entities/portal/to-tf.d.ts +1 -1
  72. package/dist-sdk/src/entities/portal/to-tf.js +61 -2
  73. package/dist-sdk/src/entities/record-create-form/from-tf.js +3 -1
  74. package/dist-sdk/src/entities/relationship/from-tf.js +34 -4
  75. package/dist-sdk/src/entities/relationship/to-tf.js +24 -6
  76. package/dist-sdk/src/entities/role/from-tf.js +3 -1
  77. package/dist-sdk/src/entities/search-table/from-tf.d.ts +3 -1
  78. package/dist-sdk/src/entities/search-table/from-tf.js +6 -3
  79. package/dist-sdk/src/entities/search-table/module.js +18 -2
  80. package/dist-sdk/src/entities/search-table/to-tf.js +10 -16
  81. package/dist-sdk/src/entities/shared/aspect-target-from-tf.js +6 -1
  82. package/dist-sdk/src/entities/shared/filters/index.d.ts +6 -1
  83. package/dist-sdk/src/entities/shared/filters/index.js +8 -2
  84. package/dist-sdk/src/entities/shared/filters/print.js +18 -7
  85. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +11 -0
  86. package/dist-sdk/src/entities/shared/filters/tf-codec.js +24 -2
  87. package/dist-sdk/src/entities/shared/run-automation-requirement.d.ts +15 -0
  88. package/dist-sdk/src/entities/shared/run-automation-requirement.js +28 -0
  89. package/dist-sdk/src/entities/shared/search-table-address.d.ts +17 -0
  90. package/dist-sdk/src/entities/shared/search-table-address.js +24 -0
  91. package/dist-sdk/src/entities/shared/skip-release.d.ts +49 -0
  92. package/dist-sdk/src/entities/shared/skip-release.js +74 -0
  93. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +3 -3
  94. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +11 -5
  95. package/dist-sdk/src/entities/skill/module.js +3 -25
  96. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +4 -2
  97. package/dist-sdk/src/entities/skill-tool/from-tf.js +28 -27
  98. package/dist-sdk/src/entities/skill-tool/to-tf.js +12 -5
  99. package/dist-sdk/src/entities/skill-tool/types.d.ts +1 -0
  100. package/dist-sdk/src/entities/skill-tool/types.js +2 -1
  101. package/dist-sdk/src/entities/table/catalog.d.ts +16 -0
  102. package/dist-sdk/src/entities/table/catalog.js +44 -2
  103. package/dist-sdk/src/entities/table/from-tf.js +30 -4
  104. package/dist-sdk/src/entities/table/keys.d.ts +27 -0
  105. package/dist-sdk/src/entities/table/keys.js +46 -0
  106. package/dist-sdk/src/entities/table/to-tf.js +2 -2
  107. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.d.ts +12 -1
  108. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.js +9 -4
  109. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.js +215 -10
  110. package/dist-sdk/src/entities/view/agent-view-layout.d.ts +10 -4
  111. package/dist-sdk/src/entities/view/custom-view-runtime-rules.d.ts +43 -0
  112. package/dist-sdk/src/entities/view/custom-view-runtime-rules.js +285 -0
  113. package/dist-sdk/src/entities/view/custom-view-validate.d.ts +3 -1
  114. package/dist-sdk/src/entities/view/custom-view-validate.js +24 -5
  115. package/dist-sdk/src/entities/view/from-tf.js +14 -1
  116. package/dist-sdk/src/entities/widget/from-tf.js +14 -7
  117. package/dist-sdk/src/entities/widget/to-tf.js +7 -5
  118. package/dist-sdk/src/graph/index.d.ts +14 -1
  119. package/dist-sdk/src/graph/index.js +2 -0
  120. package/dist-sdk/src/graph/resource-types.d.ts +2 -0
  121. package/dist-sdk/src/graph/resource-types.js +3 -0
  122. package/dist-sdk/src/graph/types.d.ts +82 -0
  123. package/package.json +1 -1
@@ -14,6 +14,7 @@ import { SERVICE_ACCOUNT_RESOURCE_TYPE } from "../service-account/module.js";
14
14
  import { serviceAccountRefToTf } from "../service-account/to-tf.js";
15
15
  import { workspaceServiceAccountAppResolver } from "../service-account/workspace-owner.js";
16
16
  import { foreignFieldDataLabel, resolveForeignRef } from "../shared/foreign-ref.js";
17
+ import { localSearchTableLabel } from "../shared/search-table-address.js";
17
18
  import { filterToTf as serializeFilterToTf } from "../shared/filters/tf-codec.js";
18
19
  import { isTextOptionValue, referenceValueTypeForField } from "../shared/filters/index.js";
19
20
  import { plainOptionStringWarning, rawOptionIdWarning } from "../shared/raw-option-id.js";
@@ -640,7 +641,11 @@ function tableColumnNameOf(input) {
640
641
  return col.cloud?.name ?? col.calculation?.name ?? col.reference?.name ?? input.name;
641
642
  }
642
643
  function extractTableColumnDisplayNames(sibling, extraNames) {
643
- const displayNames = new Map();
644
+ // Each column's own key wins over another column's alias (its sanitized
645
+ // name, its display name): "DOMAIN" keys as `domain` and "Domain" as
646
+ // `domain2`, and "Domain"'s sanitized alias `domain` must not take
647
+ // `domain` from "DOMAIN" (#3167).
648
+ const columns = [];
644
649
  if (sibling?.streamRootEntity?.payload !== undefined && isObject(sibling.streamRootEntity.payload)) {
645
650
  const payload = sibling.streamRootEntity.payload;
646
651
  const tableCols = isObject(payload.columns)
@@ -650,22 +655,23 @@ function extractTableColumnDisplayNames(sibling, extraNames) {
650
655
  for (const [colKey, colInput] of Object.entries(tableCols)) {
651
656
  if (isObject(colInput)) {
652
657
  const name = tableColumnNameOf(colInput);
653
- if (typeof name === "string" && name !== "") {
654
- displayNames.set(colKey, name);
655
- displayNames.set(tfLabelToTsLabel(sanitizeName(name)), name);
656
- displayNames.set(name, name);
657
- }
658
+ if (typeof name === "string" && name !== "")
659
+ columns.push([colKey, name]);
658
660
  }
659
661
  }
660
662
  }
661
663
  }
662
664
  if (extraNames !== undefined && isObject(extraNames)) {
663
665
  for (const [colKey, colName] of Object.entries(extraNames)) {
664
- if (typeof colName === "string" && colName !== "") {
665
- displayNames.set(colKey, colName);
666
- displayNames.set(tfLabelToTsLabel(sanitizeName(colName)), colName);
667
- displayNames.set(colName, colName);
668
- }
666
+ if (typeof colName === "string" && colName !== "")
667
+ columns.push([colKey, colName]);
668
+ }
669
+ }
670
+ const displayNames = new Map(columns);
671
+ for (const [, name] of columns) {
672
+ for (const alias of [tfLabelToTsLabel(sanitizeName(name)), name]) {
673
+ if (!displayNames.has(alias))
674
+ displayNames.set(alias, name);
669
675
  }
670
676
  }
671
677
  return displayNames;
@@ -788,6 +794,53 @@ function crossAppFieldToTf(value, ctx, dataBlocks) {
788
794
  }
789
795
  return expr.dataAttr("elementum_field", registerForeignFieldLookup(value, ctx, dataBlocks), ["id"]);
790
796
  }
797
+ /**
798
+ * The element a search-table lookup names in `object_id`: the element's own
799
+ * resource when it is in this build, else its data lookup when the workspace
800
+ * knows its identity (a sibling a scoped build leaves out, or an element known
801
+ * only from its ref-only catalog). Undefined when neither holds.
802
+ */
803
+ function searchTableElementOwner(refName, element, ctx, dataBlocks) {
804
+ if (element !== undefined) {
805
+ return { tfLabel: element.tfLabel, value: expr.resourceAttr("elementum_element", element.tfLabel, ["id"]) };
806
+ }
807
+ const identity = ctx.outOfScopeElements?.get(refName) ?? ctx.catalogElementIdentities?.get(refName);
808
+ if (identity === undefined)
809
+ return undefined;
810
+ if (ctx.orgRefs !== undefined) {
811
+ return resolveForeignRef("element", identity, ctx.orgRefs, ctx.diagnostics, `automation search table owner "${refName}"`);
812
+ }
813
+ const resolved = foreignRootLookup("element", identity);
814
+ dataBlocks.set(`${resolved.resourceType}.${resolved.tfLabel}`, {
815
+ kind: "data",
816
+ type: resolved.resourceType,
817
+ label: resolved.tfLabel,
818
+ attrs: { [resolved.lookupAttr]: resolved.lookupValue },
819
+ });
820
+ return { tfLabel: resolved.tfLabel, value: expr.dataAttr(resolved.resourceType, resolved.tfLabel, ["id"]) };
821
+ }
822
+ /**
823
+ * `data.elementum_search_table` on an element, by name, or by id when the
824
+ * name is shared. The label is the one ei's export and an agent or skill
825
+ * tool on the same table use (`<element label>_<name>[_<id suffix>]`), so the
826
+ * lookups merge.
827
+ */
828
+ function searchTableElementLookup(owner, name, pinnedId, ctx, dataBlocks) {
829
+ const base = sanitizeName(`${owner.tfLabel}_${name}`);
830
+ const label = pinnedId === undefined ? base : `${base}_${stableIdSuffix(pinnedId)}`;
831
+ if (ctx.orgRefs !== undefined) {
832
+ ctx.orgRefs.foreignField("elementum_search_table", label, owner.value, name, pinnedId === undefined ? undefined : { id: pinnedId });
833
+ }
834
+ else {
835
+ dataBlocks.set(`elementum_search_table.${label}`, {
836
+ kind: "data",
837
+ type: "elementum_search_table",
838
+ label,
839
+ attrs: { object_id: owner.value, name, ...(pinnedId !== undefined ? { id: pinnedId } : {}) },
840
+ });
841
+ }
842
+ return expr.dataAttr("elementum_search_table", label, ["id"]);
843
+ }
791
844
  /**
792
845
  * Registers the `data.elementum_field` lookup (and its owner root lookup) for
793
846
  * a genuinely foreign field, plus the matching `<label>_options_by_label`
@@ -826,6 +879,61 @@ function registerForeignFieldLookup(value, ctx, dataBlocks) {
826
879
  registerForeignOptionsByLabelLocal(fieldLabel, ctx);
827
880
  return fieldLabel;
828
881
  }
882
+ /**
883
+ * Another app or element in this workspace that owns `value` but whose source
884
+ * leaves it out: its pull skipped the automation (#3064). Pull names such a
885
+ * target with `automationRef({ refName, name, parent })`, which carries no
886
+ * owner kind, so both kinds are tried, the caller's first. Returns the owner
887
+ * identity the display-name lookup needs, or undefined when the owner's
888
+ * source has the automation (or the owner is not in the workspace).
889
+ */
890
+ function workspaceOwnerLackingAutomation(value, ownerKind, ctx) {
891
+ if (value.parent === undefined || value.parent === "" || typeof value.name !== "string" || value.name === "")
892
+ return undefined;
893
+ const kinds = value.parentKind === "app" || value.parentKind === "element"
894
+ ? [value.parentKind]
895
+ : value.parentKind === undefined
896
+ ? (ownerKind === "element" ? ["element", "app"] : ["app", "element"])
897
+ : [];
898
+ for (const kind of kinds) {
899
+ const owner = ctx.workspaceAspects?.get(workspaceAspectKey(kind, value.parent));
900
+ if (owner === undefined || owner.kind === "table" || owner.automationRefNames === undefined)
901
+ continue;
902
+ if (owner.automationRefNames.has(value.refName))
903
+ return undefined;
904
+ const payload = owner.streamRootEntity?.payload;
905
+ const name = value.parentName ?? (typeof payload?.name === "string" ? payload.name : undefined);
906
+ if (name === undefined || name === "")
907
+ return undefined;
908
+ const namespace = value.parentNamespace ?? (typeof payload?.namespace === "string" && payload.namespace !== "" ? payload.namespace : owner.tfLabel);
909
+ return { kind, name, namespace };
910
+ }
911
+ return undefined;
912
+ }
913
+ /**
914
+ * The owner identity of `automationRef({ refName, name, parent })` (no
915
+ * `parentName`) when `parent` is an app or element of this workspace that a
916
+ * scoped build (pull's own build of one root) leaves out (#3064): it resolves
917
+ * through a data lookup, like any root outside the build, and the lookup
918
+ * needs the owner's display name and namespace.
919
+ */
920
+ function outOfScopeOwnerIdentity(value, ownerKind, ctx) {
921
+ if (value.parent === undefined || value.parent === "" || (value.parentName !== undefined && value.parentName !== ""))
922
+ return undefined;
923
+ const kinds = value.parentKind === "app" || value.parentKind === "element"
924
+ ? [value.parentKind]
925
+ : value.parentKind === undefined
926
+ ? (ownerKind === "element" ? ["element", "app"] : ["app", "element"])
927
+ : [];
928
+ for (const kind of kinds) {
929
+ if (ctx.workspaceAspects?.has(workspaceAspectKey(kind, value.parent)) === true)
930
+ return undefined;
931
+ const identity = (kind === "app" ? ctx.outOfScopeApps : ctx.outOfScopeElements)?.get(value.parent);
932
+ if (identity?.namespace !== undefined && identity.namespace !== "")
933
+ return { kind, name: identity.name, namespace: identity.namespace };
934
+ }
935
+ return undefined;
936
+ }
829
937
  /**
830
938
  * Resolve an automation token as a managed definition (same stream root or a
831
939
  * sibling root in this build) or as a ref-only `data.elementum_automation`
@@ -833,9 +941,20 @@ function registerForeignFieldLookup(value, ctx, dataBlocks) {
833
941
  * `automation { id }` + `inputMappings.parameter.id` contract; it must never
834
942
  * degrade to `target_automation_ref` / `dynamic_input_mappings`.
835
943
  */
836
- function automationTargetToTf(value, ctx, dataBlocks) {
837
- const { ownerKind, isOwn } = automationTargetOwner(value, ctx);
838
- const sibling = !isOwn && value.parent !== undefined
944
+ function automationTargetToTf(token, ctx, dataBlocks) {
945
+ const resolvedOwner = automationTargetOwner(token, ctx);
946
+ // A skipped automation of another workspace app or element (#3064) is
947
+ // looked up by display name through its owner, exactly as when that owner
948
+ // is only a ref-only catalog: the foreign path below.
949
+ const lacking = resolvedOwner.isOwn
950
+ ? undefined
951
+ : workspaceOwnerLackingAutomation(token, resolvedOwner.ownerKind, ctx) ?? outOfScopeOwnerIdentity(token, resolvedOwner.ownerKind, ctx);
952
+ const value = lacking === undefined
953
+ ? token
954
+ : { ...token, parentKind: lacking.kind, parentName: lacking.name, parentNamespace: lacking.namespace };
955
+ const ownerKind = lacking?.kind ?? resolvedOwner.ownerKind;
956
+ const isOwn = resolvedOwner.isOwn;
957
+ const sibling = !isOwn && value.parent !== undefined && lacking === undefined
839
958
  ? ctx.workspaceAspects?.get(workspaceAspectKey(ownerKind, value.parent))
840
959
  : undefined;
841
960
  const managedOwnerLabel = isOwn
@@ -923,7 +1042,8 @@ function automationTargetToTf(value, ctx, dataBlocks) {
923
1042
  throw new EntityTfError(`foreign automation ref "${value.refName}" has no parent`);
924
1043
  }
925
1044
  if (value.parentName === undefined || value.parentName === "") {
926
- throw new EntityTfError(`foreign automation ref "${value.parent}.${value.refName}" has no parentName; the owner lookup cannot use a refName as a display name`);
1045
+ throw new EntityTfError(`foreign automation ref "${value.parent}.${value.refName}"${typeof value.name === "string" && value.name !== "" ? ` (${JSON.stringify(value.name)})` : ""} has no parentName; the owner lookup cannot use a refName as a display name. ` +
1046
+ `If "${value.parent}" is an app or element that is no longer pulled into this workspace, pull it again (or pull this automation's app again, so its reference reads the owner's catalog).`);
927
1047
  }
928
1048
  if (value.name === undefined || value.name === "") {
929
1049
  throw new EntityTfError(`foreign automation ref "${value.parent}.${value.refName}" has no lookup name`);
@@ -1150,14 +1270,16 @@ function tokenToTf(value, ctx, dataBlocks) {
1150
1270
  if (owner === undefined || owner === "") {
1151
1271
  throw new EntityTfError(`table column ref "${value.refName}" is missing its owning table`);
1152
1272
  }
1153
- const sibling = ctx.workspaceAspects?.get(workspaceAspectKey("table", owner));
1154
- const displayNames = extractTableColumnDisplayNames(sibling);
1155
- const rawColName = value.name ?? value.refName;
1273
+ // A token's `name` is already the display name: use it as is. Looked up
1274
+ // in the key → name map, a name that is another column's key ("email"
1275
+ // when "Email" keys as `email`) would build that other column (#3167).
1276
+ // Only a token without a name resolves its key through the table.
1277
+ const sibling = value.name === undefined ? ctx.workspaceAspects?.get(workspaceAspectKey("table", owner)) : undefined;
1156
1278
  return resolveTableColumnFieldExpr({
1157
1279
  tableRefName: owner,
1158
1280
  tableName: value.parentName,
1159
- columnKey: rawColName,
1160
- columnDisplayNames: displayNames,
1281
+ columnKey: value.name ?? value.refName,
1282
+ ...(sibling !== undefined && { columnDisplayNames: extractTableColumnDisplayNames(sibling) }),
1161
1283
  workspaceAspects: ctx.workspaceAspects,
1162
1284
  orgRefs: ctx.orgRefs,
1163
1285
  dataBlocks,
@@ -1239,8 +1361,28 @@ function tokenToTf(value, ctx, dataBlocks) {
1239
1361
  }
1240
1362
  return expr.dataAttr("elementum_search_table", label, ["id"]);
1241
1363
  }
1364
+ // A pinned id names one of several tables sharing a name: look it up by
1365
+ // id even when the element is in this build, as an agent or skill tool
1366
+ // on it does (edk#2881, edk#3228). Same label as theirs and ei's.
1367
+ if (pinnedId !== undefined && (element !== undefined || table === undefined)) {
1368
+ const lookupOwner = searchTableElementOwner(owner, element, ctx, dataBlocks);
1369
+ if (lookupOwner !== undefined) {
1370
+ return searchTableElementLookup(lookupOwner, value.name ?? value.refName, pinnedId, ctx, dataBlocks);
1371
+ }
1372
+ }
1242
1373
  if (element !== undefined) {
1243
- return expr.resourceAttr(SEARCH_TABLE_RESOURCE_TYPES[variant], scopedResourceLabel(element.tfLabel, tsLabelToTfLabel(value.refName), "element"), ["id"]);
1374
+ // A table literal pull wrote because it couldn't key the table
1375
+ // (edk#2880: added after the element was pulled, or the element was
1376
+ // pulled with --no-adopt) has no address here: refuse it with the
1377
+ // cause and the remedy, as for an agent or skill tool.
1378
+ return expr.resourceAttr(SEARCH_TABLE_RESOURCE_TYPES[variant], localSearchTableLabel(`automation ${ctx.automationTfLabel}`, { refName: value.refName, ...(value.name !== undefined ? { name: value.name } : {}) }, { refName: owner, tfLabel: element.tfLabel, scope: "element" }), ["id"]);
1379
+ }
1380
+ // An element outside this build (a dependency known from its ref-only
1381
+ // catalog, or a sibling a scoped build leaves out): look its table up
1382
+ // by name on the element (edk#3228).
1383
+ const foreignOwner = searchTableElementOwner(owner, undefined, ctx, dataBlocks);
1384
+ if (foreignOwner !== undefined && table === undefined) {
1385
+ return searchTableElementLookup(foreignOwner, value.name ?? value.refName, undefined, ctx, dataBlocks);
1244
1386
  }
1245
1387
  if (table !== undefined) {
1246
1388
  throw new EntityTfError(`search table "${owner}.${value.refName}" is a ${variant} search table owned by table "${owner}" — ` +
@@ -1496,6 +1638,7 @@ function calculationFormulaRefToParts(value, refs) {
1496
1638
  !("triggerReference" in value) &&
1497
1639
  !("taskReference" in value) &&
1498
1640
  !("variableReference" in value) &&
1641
+ !("forEachReference" in value) &&
1499
1642
  !("templateReference" in value) &&
1500
1643
  Object.keys(value).length === 1) {
1501
1644
  return calculationFormulaRefToParts(value.value, refs);
@@ -1522,6 +1665,11 @@ function calculationFormulaRefToParts(value, refs) {
1522
1665
  }
1523
1666
  return ["variable.", variableIdAttr(target)];
1524
1667
  }
1668
+ if (isObject(value.forEachReference) &&
1669
+ typeof value.forEachReference.forEachTaskRefKey === "string" &&
1670
+ typeof value.forEachReference.name === "string") {
1671
+ return calculationForEachMustache(value.forEachReference.forEachTaskRefKey, value.forEachReference.name, refs);
1672
+ }
1525
1673
  if (isObject(value.templateReference))
1526
1674
  return calculationTemplateToParts(value.templateReference, refs);
1527
1675
  if (typeof value.kind === "string") {
@@ -1531,7 +1679,50 @@ function calculationFormulaRefToParts(value, refs) {
1531
1679
  if (value.kind === "literal" && "value" in value)
1532
1680
  return calculationFormulaRefToParts(value.value, refs);
1533
1681
  }
1534
- throw new EntityTfError("calculation formula is not a trigger/task/variable ref, literal, or template");
1682
+ throw new EntityTfError("calculation formula is not a trigger/task/variable/loop item ref, literal, or template");
1683
+ }
1684
+ /**
1685
+ * Calc-engine mustache for a loop's current item (`ctx.item.<field>`,
1686
+ * `ctx.loops.<loop>.item.<field>`, `ctx.item.metadata.<name>`):
1687
+ * `{{forEach name="<name>" id="<loop task id>"}}`, the platform's own text
1688
+ * (elementum-core CalcParamVisitor FOR_EACH; ConductorUtil writes it name
1689
+ * first) and what ei's export and the provider's Read print (edk#3131).
1690
+ *
1691
+ * `name` is the forEachReference name a filter on the same item uses
1692
+ * (filterReferenceToTf's FOR_EACH case): a record loop's field is its field
1693
+ * id (the bare id; the platform refuses `record.<id>`), resolved the way a
1694
+ * calculation resolves a found record's field (the loop's collection is that
1695
+ * search's records); loop metadata keeps `metadata.<name>`; a plain list's
1696
+ * item keeps its own key. A plain list's whole item has an empty name, which
1697
+ * no calculation can address.
1698
+ */
1699
+ function calculationForEachMustache(loopRefKey, name, refs) {
1700
+ const loop = refs.tasks.get(loopRefKey);
1701
+ if (loop === undefined)
1702
+ throw new EntityTfError(`unresolved forEach calculation ref "${loopRefKey}"`);
1703
+ if (name.includes('"'))
1704
+ throw new EntityTfError(`calculation loop item key "${name}" contains a double quote`);
1705
+ const loopId = expr.resourceAttr(loop.type, loop.label, ["id"]);
1706
+ const mustache = (...nameParts) => ['{{forEach name="', ...nameParts, '" id="', loopId, '"}}'];
1707
+ if (isForEachLoopMetadata(name))
1708
+ return mustache(name);
1709
+ if (!refs.recordItemForEachRefKeys.has(loopRefKey)) {
1710
+ if (name === "item" || name === "recordId" || name === "") {
1711
+ throw new EntityTfError(`a calculation cannot read the whole current item of loop "${loopRefKey}", which is not a list of records; read one of the item's keys instead`);
1712
+ }
1713
+ return mustache(name);
1714
+ }
1715
+ if (name === "item" || name === "recordId")
1716
+ return mustache(RECORD_ID_REFERENCE_FIELD);
1717
+ const source = refs.recordItemForEachSourceByRefKey.get(loopRefKey);
1718
+ if (source === undefined)
1719
+ throw new EntityTfError(`loop "${loopRefKey}" has no record collection source`);
1720
+ const [fieldKey, ...suffix] = name.split(".");
1721
+ if (fieldKey === undefined || fieldKey === "")
1722
+ throw new EntityTfError("calculation loop item reference has no field");
1723
+ const joinedSuffix = suffix.join(".");
1724
+ const wireSuffix = joinedSuffix === "recordId" ? RECORD_ID_REFERENCE_FIELD : joinedSuffix;
1725
+ return mustache(calculationRawFieldId(fieldKey) ?? calculationFoundRecordFieldId(fieldKey, source, refs), ...(wireSuffix === "" ? [] : [`.${wireSuffix}`]));
1535
1726
  }
1536
1727
  /**
1537
1728
  * Calc-engine mustache for a prior task output:
@@ -1577,7 +1768,10 @@ function calculationTaskRefName(targetType, name, taskRefKey, refs) {
1577
1768
  }
1578
1769
  // A single-output AI task's `.output` reaches here as its refs label
1579
1770
  // (`Response`); the calc engine resolves only the canonical name (`response`, #2405).
1580
- const refName = taskOutputReferenceName(targetType, name, refs.tasks.get(taskRefKey)) ??
1771
+ // A Table Records Search's arrives as authored (`totalCount`), so look up
1772
+ // its refs label first: the calc engine knows only `count` (#3197).
1773
+ const refsKey = tableRecordsSearchRefsKey(targetType, name) ?? name;
1774
+ const refName = taskOutputReferenceName(targetType, refsKey, refs.tasks.get(taskRefKey)) ??
1581
1775
  canonicalSingleOutputName(targetType, name) ?? name;
1582
1776
  if (refName.includes('"')) {
1583
1777
  throw new EntityTfError(`calculation task output name "${refName}" contains a double quote`);
@@ -1606,6 +1800,16 @@ function taskOutputRefsIndex(resourceType, name) {
1606
1800
  return TABLE_RECORDS_SEARCH_REFS_INDEX[name];
1607
1801
  return aiCompletionRefsIndex(resourceType, name);
1608
1802
  }
1803
+ /**
1804
+ * A Table Records Search output's refs label ("Row count", "First matching
1805
+ * table row", …) for its authored name (`totalCount`, `record`, `records`),
1806
+ * so TASK_OUTPUT_REFERENCE_NAMES can name it. Other task types reach the
1807
+ * reference-name lookups as refs keys already (build's
1808
+ * rewriteForwardTaskRefName); undefined for them.
1809
+ */
1810
+ function tableRecordsSearchRefsKey(type, authoredName) {
1811
+ return type === TASK_RESOURCES.tableRecordsSearch ? taskOutputRefsIndex(type, authoredName) : undefined;
1812
+ }
1609
1813
  /** A refs key's WorkflowTaskReference name. An apiRequest maps only when it's JSON; FILE and CUSTOM are unconfirmed live (edk#2058). */
1610
1814
  function taskOutputReferenceName(type, wireName, task) {
1611
1815
  if (type === TASK_RESOURCES.api && task?.jsonApiResponse !== true)
@@ -2088,6 +2292,11 @@ function taskWireRefName(name, taskRefKey, refs) {
2088
2292
  // indexes a key the refs map does not contain (Invalid index at plan).
2089
2293
  if (refs.tasks.get(taskRefKey)?.type === TASK_RESOURCES.runAutomation)
2090
2294
  return name;
2295
+ // A Calculation task's refs are keyed by its variable names, exactly as
2296
+ // written (#3085): a variable named `status` or `record` is not a record
2297
+ // field either.
2298
+ if (refs.tasks.get(taskRefKey)?.type === TASK_RESOURCES.calculation)
2299
+ return name;
2091
2300
  assertFindRelatedRecordsHasNoCountRef(refs.tasks.get(taskRefKey)?.type, name, taskRefKey);
2092
2301
  const handleKey = findRelatedRecordsAppTitleWireKey(name, taskRefKey, refs);
2093
2302
  if (handleKey !== undefined)
@@ -2656,6 +2865,61 @@ function collectPayloadTaskKinds(value, kinds) {
2656
2865
  collectPayloadTaskKinds(nested, kinds);
2657
2866
  return kinds;
2658
2867
  }
2868
+ /** Task lists whose `record` entries hand over a record's files, and what a record ID does there. */
2869
+ const RECORD_ATTACHMENT_LISTS = [
2870
+ ["aiAgent", "attachments", "the AI agent gets none of its files"],
2871
+ ["sendEmail", "emailAttachments", "the email fails"],
2872
+ ];
2873
+ /** An on-demand record parameter, which carries only the record ID (#1499), as it was written. */
2874
+ function onDemandRecordParamSource(value, onDemandRecordParams) {
2875
+ const trigger = value.triggerReference;
2876
+ return isObject(trigger) && typeof trigger.name === "string" && onDemandRecordParams.has(trigger.name)
2877
+ ? `ctx.trigger.${trigger.name} (an on-demand record parameter)`
2878
+ : undefined;
2879
+ }
2880
+ /**
2881
+ * Built task-output names that are a record's ID: `.record.recordId`, and the
2882
+ * `Record` key a record-bearing task's ID builds to. Only on the task kinds
2883
+ * that build them: another task's own output can carry the same name (an AI
2884
+ * agent's structured field `recordId`).
2885
+ */
2886
+ const TASK_RECORD_ID_REF_NAMES = new Set(["Record", "First found record id", "recordId", "record.recordId"]);
2887
+ const RECORD_ID_TASK_KINDS = new Set(["recordSearch", "createRecord", "findRelatedRecords", "updateField"]);
2888
+ /**
2889
+ * How a record attachment that hands over only a record ID was written, or
2890
+ * undefined when it can carry the whole record. A task's `.record` builds the
2891
+ * whole record there (ATTACHMENT_WHOLE_RECORD_REF_WIRE_NAMES), so only an
2892
+ * on-demand record parameter or an explicit ID form is left.
2893
+ */
2894
+ function attachmentRecordIdSource(value, onDemandRecordParams, taskKinds) {
2895
+ const param = onDemandRecordParamSource(value, onDemandRecordParams);
2896
+ if (param !== undefined) {
2897
+ return {
2898
+ source: param,
2899
+ remedy: "Look the record up first with a recordSearch on that ID (e.g. .recordSearch(\"lookup\", …) filtered on the record id) and attach { record: ctx.actions.lookup.record }.",
2900
+ };
2901
+ }
2902
+ const task = value.taskReference;
2903
+ if (isObject(task) && typeof task.taskRefKey === "string" && typeof task.name === "string" &&
2904
+ TASK_RECORD_ID_REF_NAMES.has(task.name) && RECORD_ID_TASK_KINDS.has(taskKinds.get(task.taskRefKey) ?? "")) {
2905
+ return {
2906
+ source: `ctx.actions.${task.taskRefKey}.record.recordId`,
2907
+ remedy: `Attach the whole record instead: { record: ctx.actions.${task.taskRefKey}.record }.`,
2908
+ };
2909
+ }
2910
+ return undefined;
2911
+ }
2912
+ /** How a field-mapped value that is only a record ID was written (#1499). */
2913
+ function recordIdOnlySource(value, onDemandRecordParams, taskKinds) {
2914
+ const param = onDemandRecordParamSource(value, onDemandRecordParams);
2915
+ if (param !== undefined)
2916
+ return param;
2917
+ const task = value.taskReference;
2918
+ if (isObject(task) && typeof task.taskRefKey === "string" && task.name === "record" && taskKinds.get(task.taskRefKey) === "findRelatedRecords") {
2919
+ return `ctx.actions.${task.taskRefKey}.record (findRelatedRecords)`;
2920
+ }
2921
+ return undefined;
2922
+ }
2659
2923
  /**
2660
2924
  * edk#1499: script-input field mappings read fields off a whole record. A
2661
2925
  * value that exposes only a record ID (an onDemand record parameter, or
@@ -2663,6 +2927,10 @@ function collectPayloadTaskKinds(value, kinds) {
2663
2927
  * plus field mappings, and the script receives `{}` at runtime. Record
2664
2928
  * triggers' `ctx.trigger.record` and the `.record` of recordSearch,
2665
2929
  * createRecord and updateField carry the whole record (#1284, #1489).
2930
+ * AI agent and email record attachments read the record's files from the
2931
+ * whole record too: an on-demand record parameter or an explicit record ID
2932
+ * fails there (#3069). A task's `.record`, Find Related Records' included,
2933
+ * builds the whole record in an attachment.
2666
2934
  */
2667
2935
  export function recordIdFieldMappingFailures(entity, payload, address) {
2668
2936
  const onDemandRecordParams = onDemandRecordParamNames(payload.trigger);
@@ -2678,16 +2946,27 @@ export function recordIdFieldMappingFailures(entity, payload, address) {
2678
2946
  if (!isObject(value))
2679
2947
  return;
2680
2948
  const here = typeof value.refKey === "string" && isObject(value.task) ? value.refKey : action;
2681
- if (Array.isArray(value.field_mappings) && isObject(value.value)) {
2682
- let source;
2683
- const trigger = value.value.triggerReference;
2684
- if (isObject(trigger) && typeof trigger.name === "string" && onDemandRecordParams.has(trigger.name)) {
2685
- source = `ctx.trigger.${trigger.name} (an on-demand record parameter)`;
2686
- }
2687
- const task = value.value.taskReference;
2688
- if (isObject(task) && typeof task.taskRefKey === "string" && task.name === "record" && taskKinds.get(task.taskRefKey) === "findRelatedRecords") {
2689
- source = `ctx.actions.${task.taskRefKey}.record (findRelatedRecords)`;
2949
+ // A record attachment hands over the record's files, read from the whole
2950
+ // record; a record ID gives the AI agent no files and fails the email (#3069).
2951
+ for (const [taskKind, listKey, effect] of RECORD_ATTACHMENT_LISTS) {
2952
+ const list = isObject(value[taskKind]) ? value[taskKind][listKey] : undefined;
2953
+ if (!Array.isArray(list))
2954
+ continue;
2955
+ for (const item of list) {
2956
+ const found = isObject(item) && isObject(item.record) ? attachmentRecordIdSource(item.record, onDemandRecordParams, taskKinds) : undefined;
2957
+ if (found === undefined)
2958
+ continue;
2959
+ failures.push({
2960
+ severity: "fatal",
2961
+ address,
2962
+ name,
2963
+ ownerKind: "automation",
2964
+ message: `action "${here ?? "?"}": the record attachment ${found.source} is only a record ID, so ${effect} at runtime. ${found.remedy}`,
2965
+ });
2690
2966
  }
2967
+ }
2968
+ if (Array.isArray(value.field_mappings) && isObject(value.value)) {
2969
+ const source = recordIdOnlySource(value.value, onDemandRecordParams, taskKinds);
2691
2970
  if (source !== undefined) {
2692
2971
  failures.push({
2693
2972
  severity: "fatal",
@@ -3079,6 +3358,20 @@ function searchRecordsContractName(resourceType, name, wireName) {
3079
3358
  return entry.contractName;
3080
3359
  }
3081
3360
  const TRIGGER_REFERENCE_NAME_PATTERN = /^[a-z][A-Za-z0-9]*(?:\.[a-z][A-Za-z0-9]*)*$/;
3361
+ /**
3362
+ * Trigger outputs, by trigger resource, whose refs entry has a display label
3363
+ * although the platform's `triggerReference.name` is a short name: authored
3364
+ * name → that reference name (live refs: "Body (Plain Text)" → `body`,
3365
+ * "Attachment" → `attachment`, "Attachment Id" → `attachment.id`). A filter
3366
+ * spells them `trigger.<reference name>`, as export and provider Read do. A
3367
+ * webhook's raw body is also authored as `body["Plain Text"]`, the same refs
3368
+ * entry, which pull reprints as `ctx.trigger.body`.
3369
+ */
3370
+ const FILTER_SHORT_FORM_TRIGGER_REFS = {
3371
+ elementum_webhook_trigger: { body: "body", "body.Plain Text": "body" },
3372
+ elementum_email_ingestion_trigger: { body: "body" },
3373
+ elementum_attachment_added_trigger: { attachment: "attachment", "attachment.id": "attachment.id" },
3374
+ };
3082
3375
  function filterReferenceToTf(value, refs, role = "value", realType, operator) {
3083
3376
  // Raw pass-through for a filter left side the pull-time deserializer
3084
3377
  // couldn't decode to a typed ref (filter.ts's leftDescriptor, matching the
@@ -3234,6 +3527,14 @@ function filterReferenceToTf(value, refs, role = "value", realType, operator) {
3234
3527
  if (triggerRefKey === value.name && TRIGGER_REFERENCE_NAME_PATTERN.test(value.name)) {
3235
3528
  return `trigger.${value.name}`;
3236
3529
  }
3530
+ // Some outputs have a display label in `refs` although the platform's
3531
+ // reference name is short: `body` (and a webhook's `body["Plain Text"]`)
3532
+ // is refs["Body (Plain Text)"], reference `body`; `attachment.id` is
3533
+ // refs["Attachment Id"]. Export and Read spell those short (#3165).
3534
+ const shortForms = FILTER_SHORT_FORM_TRIGGER_REFS[refs.trigger.type];
3535
+ if (shortForms !== undefined && Object.hasOwn(shortForms, value.name)) {
3536
+ return `trigger.${shortForms[value.name]}`;
3537
+ }
3237
3538
  return expr.resourceAttr(refs.trigger.type, refs.trigger.label, ["refs", { index: triggerRefKey }]);
3238
3539
  }
3239
3540
  case "TASK": {
@@ -3439,7 +3740,7 @@ function filterReferenceToTf(value, refs, role = "value", realType, operator) {
3439
3740
  : taskOutputRefsIndex(task.type, wireName) ?? wireName;
3440
3741
  return expr.resourceAttr(task.type, task.label, ["refs", { index: refsIndex }]);
3441
3742
  }
3442
- // The short form addresses user-search outputs by path, and an AI task's
3743
+ // The short form addresses user-search and User/Group Search outputs by path, and an AI task's
3443
3744
  // single output by its canonical name (`response`, edk#1509); only
3444
3745
  // `.refs` is keyed by their display labels. recordSearch's ASPECT_RECORD_ID
3445
3746
  // is keyed `First found record id` in refs, but filter RHS / ei export use
@@ -3449,6 +3750,11 @@ function filterReferenceToTf(value, refs, role = "value", realType, operator) {
3449
3750
  // Records filter value uses that same short name. A Table Records
3450
3751
  // Search's or AI Data Search's `.records` uses its contract name.
3451
3752
  const searchRecords = searchRecordsContractName(task.type, value.name, wireName);
3753
+ // A Table Records Search's authored names (`totalCount`, `record`) are
3754
+ // not its refs labels ("Row count", "First matching table row"); look
3755
+ // the label up first, as the left side does, so the reference-name map
3756
+ // below applies (`count`, `record`; the generic rewrite made `Record`).
3757
+ const refsKey = tableRecordsSearchRefsKey(task.type, value.name) ?? wireName;
3452
3758
  const shortName = task.type === TASK_RESOURCES.userSearch
3453
3759
  ? USER_SEARCH_PATH_BY_WIRE_NAME.get(wireName) ?? wireName
3454
3760
  : task.type === TASK_RESOURCES.recordSearch &&
@@ -3459,9 +3765,13 @@ function filterReferenceToTf(value, refs, role = "value", realType, operator) {
3459
3765
  ? "records"
3460
3766
  : searchRecords !== undefined
3461
3767
  ? searchRecords
3462
- : task.type === TASK_RESOURCES.api
3463
- ? taskOutputReferenceName(task.type, wireName, task) ?? wireName
3464
- : canonicalSingleOutputName(task.type, wireName) ?? wireName;
3768
+ // Any other output whose refs label differs from the platform's
3769
+ // reference name is stored by that name: a Record Search's or Table
3770
+ // Records Search's count is `count`, not "Records Size" / `totalCount`
3771
+ // (edk#3190, live on ironman); a User/Group Search's `group.name`, not `Name`
3772
+ // (edk#3169); a JSON API task's `response` (edk#2058).
3773
+ : taskOutputReferenceName(task.type, refsKey, task) ??
3774
+ canonicalSingleOutputName(task.type, wireName) ?? wireName;
3465
3775
  return expr.template([
3466
3776
  "task.",
3467
3777
  expr.resourceAttr(task.type, task.label, ["id"]),
@@ -3494,9 +3804,15 @@ function filterReferenceToTf(value, refs, role = "value", realType, operator) {
3494
3804
  if (fieldKey === undefined || fieldKey === "")
3495
3805
  throw new EntityTfError("record loop filter reference has no field");
3496
3806
  const isIdentity = value.name === "item" || value.name === "recordId";
3497
- const foreignFieldId = isIdentity ? undefined : foreignFoundRecordFieldId(fieldKey, source, refs);
3498
- const scope = isIdentity || foreignFieldId !== undefined ? undefined : calculationFieldScope(source, refs);
3499
- const fieldId = isIdentity ? RECORD_ID_REFERENCE_FIELD : foreignFieldId ?? calculationRecordFieldId(fieldKey, scope);
3807
+ // A field pull couldn't name prints as its raw field id (a loop over
3808
+ // an element this workspace doesn't author: the export declares no
3809
+ // lookup for the item's field). Write it back exactly as the export
3810
+ // spells it, as a calculation reference already does, instead of
3811
+ // asking for the unauthored source's fields (#3130).
3812
+ const rawFieldId = isIdentity ? undefined : calculationRawFieldId(fieldKey);
3813
+ const foreignFieldId = isIdentity || rawFieldId !== undefined ? undefined : foreignFoundRecordFieldId(fieldKey, source, refs);
3814
+ const scope = isIdentity || rawFieldId !== undefined || foreignFieldId !== undefined ? undefined : calculationFieldScope(source, refs);
3815
+ const fieldId = isIdentity ? RECORD_ID_REFERENCE_FIELD : rawFieldId ?? foreignFieldId ?? calculationRecordFieldId(fieldKey, scope);
3500
3816
  const joinedSuffix = suffix.join(".");
3501
3817
  let wireSuffix = joinedSuffix === "recordId" ? RECORD_ID_REFERENCE_FIELD : joinedSuffix;
3502
3818
  // Same rule as a trigger-record filter: an option-bearing picklist has
@@ -4020,6 +4336,15 @@ function configAttrs(kind, config, refs) {
4020
4336
  // build time) - name the wire key here, since the generic valueToTf
4021
4337
  // fallback below has no attribute name to report by the time it gets to
4022
4338
  // its own "unsupported value" throw.
4339
+ if (raw === undefined && kind === "elementum_run_automation_task" && key === "targetAutomationId") {
4340
+ // Usually `catalog.<owner>.automations.<key>` names an entry the
4341
+ // owner's catalog doesn't have: the owner's pull skipped that
4342
+ // automation, so its source and catalog leave it out (#3064).
4343
+ throw new EntityTfError(`${kind}: \`automation\` is undefined. If it reads catalog.<app>.automations.<key>, that app's catalog has no such automation, ` +
4344
+ "usually because pulling that app skipped it (see that pull's skipped automations). Pull the app or element that owns this " +
4345
+ "automation again (`elementum pull app|element <namespace>`) so it names the skipped automation by display name, or write " +
4346
+ "`automationRef({ refName, name, parent })` with the automation's display name.");
4347
+ }
4023
4348
  if (raw === undefined) {
4024
4349
  throw new EntityTfError(`${kind}: config value for "${key}" is undefined — likely a missing required option on the authoring builder call that built this task/trigger`);
4025
4350
  }
@@ -4581,6 +4906,27 @@ function configAttrs(kind, config, refs) {
4581
4906
  };
4582
4907
  continue;
4583
4908
  }
4909
+ // Dynamic approvers with a group slot (edk#3163): one `{ user = { user_id } }`
4910
+ // or `{ group = { group_id, approvals_required, denials_required } }` per slot.
4911
+ if (key === "approvers" && kind === "elementum_approval_chain_task") {
4912
+ if (!Array.isArray(raw))
4913
+ throw new EntityTfError("approvalChain approvers must be an array");
4914
+ attrs.approvers = raw.map((entry) => {
4915
+ if (!isObject(entry))
4916
+ throw new EntityTfError("invalid approvalChain approver");
4917
+ if (entry.group !== undefined) {
4918
+ return {
4919
+ group: {
4920
+ group_id: valueToTf(entry.group, refs),
4921
+ approvals_required: valueToTf(entry.approvalsRequired, refs),
4922
+ denials_required: valueToTf(entry.denialsRequired, refs),
4923
+ },
4924
+ };
4925
+ }
4926
+ return { user: { user_id: valueToTf(entry.user, refs) } };
4927
+ });
4928
+ continue;
4929
+ }
4584
4930
  if (key === "multipartBody" && kind === "elementum_api_task") {
4585
4931
  if (!isObject(raw) || !Array.isArray(raw.parts))
4586
4932
  throw new EntityTfError("apiRequest multipartBody.parts must be an array");
@@ -4668,6 +5014,8 @@ export function automationToTf(entity, ctx) {
4668
5014
  localsAttrs: ctx.localsAttrs,
4669
5015
  workspaceAspects: ctx.workspaceAspects,
4670
5016
  ...(ctx.outOfScopeApps !== undefined ? { outOfScopeApps: ctx.outOfScopeApps } : {}),
5017
+ ...(ctx.outOfScopeElements !== undefined ? { outOfScopeElements: ctx.outOfScopeElements } : {}),
5018
+ ...(ctx.catalogElementIdentities !== undefined ? { catalogElementIdentities: ctx.catalogElementIdentities } : {}),
4671
5019
  diagnostics: ctx.diagnostics ?? [],
4672
5020
  activeAutomationRefNames: ctx.activeAutomationRefNames,
4673
5021
  ...(ctx.elementsWithoutAuditFields !== undefined ? { elementsWithoutAuditFields: ctx.elementsWithoutAuditFields } : {}),
@@ -4774,10 +5122,11 @@ export function automationToTf(entity, ctx) {
4774
5122
  const resourceType = wireType === "variable" ? variableTaskResourceType(taskBody, refKey) : TASK_RESOURCES[wireType];
4775
5123
  if (resourceType === undefined)
4776
5124
  throw new EntityTfError(`task type "${wireType}" is not supported by the provider HCL contract`);
4777
- // elementum_unmanaged_task_reference is a data source exported under its
4778
- // own bare sanitized-name label - never scoped under the automation the
4779
- // way every real task resource is (confirmed live, edk#821).
4780
- const registeredLabel = wireType === "unimplementedTask" ? sanitizeName(refKey) : taskTfLabel(label, refKey);
5125
+ // elementum_unmanaged_task_reference is a data source, but the export
5126
+ // labels it under its automation the way it labels a task (edk#3133;
5127
+ // edk#821 had a bare name label), so two roots' same-named steps never
5128
+ // share one data source in a workspace.
5129
+ const registeredLabel = taskTfLabel(label, refKey);
4781
5130
  const collidingRefKey = usedLabels.get(registeredLabel);
4782
5131
  if (collidingRefKey !== undefined) {
4783
5132
  throw new EntityTfError(`task "${refKey}" sanitizes to the same tf label as task "${collidingRefKey}" (${registeredLabel}) — rename one of them`);
@@ -4938,6 +5287,9 @@ export function automationToTf(entity, ctx) {
4938
5287
  const [wireType, inner] = onlyEntry(task.task, `task "${refKey}"`);
4939
5288
  const resourceType = TASK_RESOURCES[wireType];
4940
5289
  const tfLabel = taskRefs.get(refKey).label;
5290
+ // A step pulled with no name (`null` display name, edk#3191) builds without
5291
+ // `name`; diagnostics and the unsupported-step lookup still say its key.
5292
+ const nameAttr = typeof inner.name === "string" ? { name: inner.name } : {};
4941
5293
  const displayName = typeof inner.name === "string" ? inner.name : refKey;
4942
5294
  let taskParent = parent;
4943
5295
  if (task.hclParent === "trigger") {
@@ -5023,7 +5375,7 @@ export function automationToTf(entity, ctx) {
5023
5375
  const variableType = variableTaskResourceType(inner, refKey);
5024
5376
  const creates = Array.isArray(inner.create) ? inner.create : [];
5025
5377
  const updates = Array.isArray(inner.update) ? inner.update : [];
5026
- const variableAttrs = { parent: taskParent, name: displayName };
5378
+ const variableAttrs = { parent: taskParent, ...nameAttr };
5027
5379
  if (creates.length > 0) {
5028
5380
  variableAttrs.variables = creates.map((item) => {
5029
5381
  if (!isObject(item) || typeof item.name !== "string" || typeof item.type !== "string") {
@@ -5057,7 +5409,7 @@ export function automationToTf(entity, ctx) {
5057
5409
  }
5058
5410
  const attrs = {
5059
5411
  parent: taskParent,
5060
- name: displayName,
5412
+ ...nameAttr,
5061
5413
  ...taskAttrs,
5062
5414
  ...(OBJECT_FIELD_REFS_TASK_TYPES.has(resourceType)
5063
5415
  ? taskObjectFieldAttrs(taskAttrs["object_id"], taskTargetFieldAddresses(inner.aspectId ?? inner.relatedAspectId, owner))
@@ -5113,8 +5465,22 @@ export function automationToTf(entity, ctx) {
5113
5465
  }
5114
5466
  else if (wireType === "switch" || wireType === "forkJoin") {
5115
5467
  const children = task.children ?? [];
5116
- if (children.length === 0)
5117
- throw new EntityTfError(`${wireType} task "${refKey}" must have branches`);
5468
+ // No branches is a live shape: the platform keeps an If task with no
5469
+ // cases, or a fork/join with no branches, as a step in the draft, and
5470
+ // ei exports just the operator task. Build emits just that task (#3105).
5471
+ // A default-only If would emit a lone `is_default` case with no
5472
+ // previous_case_id, which the provider rejects at plan with an error
5473
+ // about that generated attribute. Fail here with one the author can
5474
+ // act on until #3113 supports it. The `filter = {type:"true"}` default
5475
+ // shape has no such check and builds as before.
5476
+ const onlyChild = children.length === 1 ? children[0] : undefined;
5477
+ if (wireType === "switch" &&
5478
+ onlyChild !== undefined &&
5479
+ (onlyChild.isDefault === true || onlyChild.label === null) &&
5480
+ onlyChild.defaultFilterMode !== "explicitTrueFilter") {
5481
+ throw new EntityTfError(`If task "${refKey}" has a default branch and no cases; ` +
5482
+ `add a case before the default (or remove defaultActions). A default-only If isn't supported yet (#3113)`);
5483
+ }
5118
5484
  const usedLabels = new Map();
5119
5485
  // Separate from usedLabels above: that map rejects two branches
5120
5486
  // sharing the same RAW display label/no-label, but a genuinely