@elementumai/edk 0.13.3 → 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 (140) 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 +13 -0
  7. package/dist-sdk/src/engine/coverage-gaps.js +21 -0
  8. package/dist-sdk/src/engine/pull/context.d.ts +57 -1
  9. package/dist-sdk/src/engine/pull/context.js +9 -1
  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 +17 -1
  15. package/dist-sdk/src/engine/pull/stream-root.js +57 -4
  16. package/dist-sdk/src/engine/tf/index.d.ts +1 -0
  17. package/dist-sdk/src/engine/tf/index.js +1 -0
  18. package/dist-sdk/src/engine/tf/jsonencode.d.ts +19 -0
  19. package/dist-sdk/src/engine/tf/jsonencode.js +49 -0
  20. package/dist-sdk/src/engine/validation.d.ts +36 -1
  21. package/dist-sdk/src/engine/validation.js +56 -2
  22. package/dist-sdk/src/engine/workspace/loader.d.ts +6 -0
  23. package/dist-sdk/src/engine/workspace/loader.js +87 -2
  24. package/dist-sdk/src/entities/access-policy/from-tf.d.ts +7 -0
  25. package/dist-sdk/src/entities/access-policy/from-tf.js +58 -17
  26. package/dist-sdk/src/entities/access-policy/to-tf.d.ts +3 -1
  27. package/dist-sdk/src/entities/access-policy/to-tf.js +1 -1
  28. package/dist-sdk/src/entities/agent/build.d.ts +15 -0
  29. package/dist-sdk/src/entities/agent/build.js +139 -16
  30. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.d.ts +3 -3
  31. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +39 -25
  32. package/dist-sdk/src/entities/agent/module.js +95 -3
  33. package/dist-sdk/src/entities/agent/to-tf.js +6 -4
  34. package/dist-sdk/src/entities/agent-evaluation/from-tf.d.ts +7 -0
  35. package/dist-sdk/src/entities/agent-evaluation/from-tf.js +14 -5
  36. package/dist-sdk/src/entities/agent-evaluation/module.js +4 -2
  37. package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +11 -2
  38. package/dist-sdk/src/entities/agent-tool/from-tf.js +38 -40
  39. package/dist-sdk/src/entities/agent-tool/to-tf.js +12 -5
  40. package/dist-sdk/src/entities/app/build.d.ts +1 -1
  41. package/dist-sdk/src/entities/app/index.d.ts +1 -1
  42. package/dist-sdk/src/entities/automation/approval-trigger-refs.d.ts +20 -0
  43. package/dist-sdk/src/entities/automation/approval-trigger-refs.js +83 -0
  44. package/dist-sdk/src/entities/automation/build.d.ts +75 -42
  45. package/dist-sdk/src/entities/automation/build.js +18 -8
  46. package/dist-sdk/src/entities/automation/deserializer/ast.d.ts +14 -2
  47. package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +9 -0
  48. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +64 -12
  49. package/dist-sdk/src/entities/automation/from-tf.d.ts +53 -0
  50. package/dist-sdk/src/entities/automation/from-tf.js +579 -106
  51. package/dist-sdk/src/entities/automation/index.d.ts +2 -2
  52. package/dist-sdk/src/entities/automation/index.js +1 -1
  53. package/dist-sdk/src/entities/automation/lookup-owner.d.ts +23 -0
  54. package/dist-sdk/src/entities/automation/lookup-owner.js +27 -0
  55. package/dist-sdk/src/entities/automation/module.js +265 -26
  56. package/dist-sdk/src/entities/automation/operators.d.ts +6 -2
  57. package/dist-sdk/src/entities/automation/operators.js +0 -2
  58. package/dist-sdk/src/entities/automation/task-output-labels.d.ts +8 -0
  59. package/dist-sdk/src/entities/automation/task-output-labels.js +11 -0
  60. package/dist-sdk/src/entities/automation/tasks.d.ts +37 -2
  61. package/dist-sdk/src/entities/automation/tasks.js +38 -1
  62. package/dist-sdk/src/entities/automation/to-tf.d.ts +8 -0
  63. package/dist-sdk/src/entities/automation/to-tf.js +576 -52
  64. package/dist-sdk/src/entities/automation/triggers.d.ts +47 -1
  65. package/dist-sdk/src/entities/automation/unsafe-script-output.d.ts +10 -5
  66. package/dist-sdk/src/entities/automation/unsafe-script-output.js +10 -5
  67. package/dist-sdk/src/entities/chart/to-tf.js +18 -5
  68. package/dist-sdk/src/entities/dashboard/from-tf.js +45 -11
  69. package/dist-sdk/src/entities/dashboard-widget-order/order.d.ts +5 -3
  70. package/dist-sdk/src/entities/dashboard-widget-order/order.js +6 -4
  71. package/dist-sdk/src/entities/datamine/from-tf.js +10 -3
  72. package/dist-sdk/src/entities/dynamic-layout/build.d.ts +38 -11
  73. package/dist-sdk/src/entities/dynamic-layout/from-tf.js +35 -7
  74. package/dist-sdk/src/entities/dynamic-layout/to-tf.js +101 -9
  75. package/dist-sdk/src/entities/element/build.d.ts +4 -1
  76. package/dist-sdk/src/entities/element/build.js +3 -4
  77. package/dist-sdk/src/entities/element/index.d.ts +1 -1
  78. package/dist-sdk/src/entities/field/from-tf.js +8 -1
  79. package/dist-sdk/src/entities/field/to-tf.d.ts +29 -2
  80. package/dist-sdk/src/entities/field/to-tf.js +106 -7
  81. package/dist-sdk/src/entities/phone-service/from-tf.d.ts +7 -0
  82. package/dist-sdk/src/entities/phone-service/from-tf.js +15 -7
  83. package/dist-sdk/src/entities/phone-service/module.js +4 -2
  84. package/dist-sdk/src/entities/portal/to-tf.d.ts +1 -1
  85. package/dist-sdk/src/entities/portal/to-tf.js +61 -2
  86. package/dist-sdk/src/entities/record-create-form/from-tf.js +3 -1
  87. package/dist-sdk/src/entities/relationship/from-tf.js +34 -4
  88. package/dist-sdk/src/entities/relationship/to-tf.js +24 -6
  89. package/dist-sdk/src/entities/role/from-tf.js +3 -1
  90. package/dist-sdk/src/entities/search-table/from-tf.d.ts +3 -1
  91. package/dist-sdk/src/entities/search-table/from-tf.js +6 -3
  92. package/dist-sdk/src/entities/search-table/module.js +18 -2
  93. package/dist-sdk/src/entities/search-table/to-tf.js +10 -16
  94. package/dist-sdk/src/entities/shared/aspect-target-from-tf.js +6 -1
  95. package/dist-sdk/src/entities/shared/filters/ast.d.ts +6 -0
  96. package/dist-sdk/src/entities/shared/filters/index.d.ts +21 -4
  97. package/dist-sdk/src/entities/shared/filters/index.js +27 -3
  98. package/dist-sdk/src/entities/shared/filters/print.js +23 -7
  99. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +24 -0
  100. package/dist-sdk/src/entities/shared/filters/tf-codec.js +98 -3
  101. package/dist-sdk/src/entities/shared/filters/types.d.ts +8 -1
  102. package/dist-sdk/src/entities/shared/run-automation-requirement.d.ts +15 -0
  103. package/dist-sdk/src/entities/shared/run-automation-requirement.js +28 -0
  104. package/dist-sdk/src/entities/shared/search-table-address.d.ts +17 -0
  105. package/dist-sdk/src/entities/shared/search-table-address.js +24 -0
  106. package/dist-sdk/src/entities/shared/skip-release.d.ts +49 -0
  107. package/dist-sdk/src/entities/shared/skip-release.js +74 -0
  108. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +3 -3
  109. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +11 -5
  110. package/dist-sdk/src/entities/skill/module.js +3 -25
  111. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +4 -2
  112. package/dist-sdk/src/entities/skill-tool/from-tf.js +28 -27
  113. package/dist-sdk/src/entities/skill-tool/to-tf.js +12 -5
  114. package/dist-sdk/src/entities/skill-tool/types.d.ts +1 -0
  115. package/dist-sdk/src/entities/skill-tool/types.js +2 -1
  116. package/dist-sdk/src/entities/table/catalog.d.ts +16 -0
  117. package/dist-sdk/src/entities/table/catalog.js +44 -2
  118. package/dist-sdk/src/entities/table/from-tf.js +30 -4
  119. package/dist-sdk/src/entities/table/keys.d.ts +27 -0
  120. package/dist-sdk/src/entities/table/keys.js +46 -0
  121. package/dist-sdk/src/entities/table/to-tf.js +2 -2
  122. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.d.ts +12 -1
  123. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.js +9 -4
  124. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.js +215 -10
  125. package/dist-sdk/src/entities/view/agent-view-layout.d.ts +10 -4
  126. package/dist-sdk/src/entities/view/custom-view-runtime-rules.d.ts +43 -0
  127. package/dist-sdk/src/entities/view/custom-view-runtime-rules.js +285 -0
  128. package/dist-sdk/src/entities/view/custom-view-validate.d.ts +3 -1
  129. package/dist-sdk/src/entities/view/custom-view-validate.js +24 -5
  130. package/dist-sdk/src/entities/view/from-tf.js +14 -1
  131. package/dist-sdk/src/entities/widget/from-tf.js +14 -7
  132. package/dist-sdk/src/entities/widget/to-tf.js +9 -6
  133. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +4 -2
  134. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
  135. package/dist-sdk/src/graph/index.d.ts +14 -1
  136. package/dist-sdk/src/graph/index.js +2 -0
  137. package/dist-sdk/src/graph/resource-types.d.ts +2 -0
  138. package/dist-sdk/src/graph/resource-types.js +3 -0
  139. package/dist-sdk/src/graph/types.d.ts +105 -0
  140. 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";
@@ -33,7 +34,9 @@ import { normalizeOnDemandParamKey } from "../../../pull/util.js";
33
34
  import { PROVIDER_FIXED_SYSTEM_FIELD_KEYS, recordFieldWireRefName } from "./system-ref-name.js";
34
35
  import { taskTfLabel } from "./task-label.js";
35
36
  import { slackMessageTriggerReferenceName, slackMessageTriggerRefName } from "./slack-message-refs.js";
37
+ import { approvalTriggerReferenceName, approvalTriggerRefsKey } from "./approval-trigger-refs.js";
36
38
  import { automationRunTargetResourceAttr, automationTargetOwner, bareStaticRunTarget, onDemandRecordParamNames, recordInputMappingProblem } from "./run-target.js";
39
+ import { automationLookupOwnerId } from "./lookup-owner.js";
37
40
  import { FIELD_TYPE_MAP, isOnDemandRecordType } from "../shared/types/field-types.js";
38
41
  /** The context for reading records of `appRefName` (a `kind`), retargeted from the owner. */
39
42
  /**
@@ -638,7 +641,11 @@ function tableColumnNameOf(input) {
638
641
  return col.cloud?.name ?? col.calculation?.name ?? col.reference?.name ?? input.name;
639
642
  }
640
643
  function extractTableColumnDisplayNames(sibling, extraNames) {
641
- 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 = [];
642
649
  if (sibling?.streamRootEntity?.payload !== undefined && isObject(sibling.streamRootEntity.payload)) {
643
650
  const payload = sibling.streamRootEntity.payload;
644
651
  const tableCols = isObject(payload.columns)
@@ -648,22 +655,23 @@ function extractTableColumnDisplayNames(sibling, extraNames) {
648
655
  for (const [colKey, colInput] of Object.entries(tableCols)) {
649
656
  if (isObject(colInput)) {
650
657
  const name = tableColumnNameOf(colInput);
651
- if (typeof name === "string" && name !== "") {
652
- displayNames.set(colKey, name);
653
- displayNames.set(tfLabelToTsLabel(sanitizeName(name)), name);
654
- displayNames.set(name, name);
655
- }
658
+ if (typeof name === "string" && name !== "")
659
+ columns.push([colKey, name]);
656
660
  }
657
661
  }
658
662
  }
659
663
  }
660
664
  if (extraNames !== undefined && isObject(extraNames)) {
661
665
  for (const [colKey, colName] of Object.entries(extraNames)) {
662
- if (typeof colName === "string" && colName !== "") {
663
- displayNames.set(colKey, colName);
664
- displayNames.set(tfLabelToTsLabel(sanitizeName(colName)), colName);
665
- displayNames.set(colName, colName);
666
- }
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);
667
675
  }
668
676
  }
669
677
  return displayNames;
@@ -786,6 +794,53 @@ function crossAppFieldToTf(value, ctx, dataBlocks) {
786
794
  }
787
795
  return expr.dataAttr("elementum_field", registerForeignFieldLookup(value, ctx, dataBlocks), ["id"]);
788
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
+ }
789
844
  /**
790
845
  * Registers the `data.elementum_field` lookup (and its owner root lookup) for
791
846
  * a genuinely foreign field, plus the matching `<label>_options_by_label`
@@ -824,6 +879,61 @@ function registerForeignFieldLookup(value, ctx, dataBlocks) {
824
879
  registerForeignOptionsByLabelLocal(fieldLabel, ctx);
825
880
  return fieldLabel;
826
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
+ }
827
937
  /**
828
938
  * Resolve an automation token as a managed definition (same stream root or a
829
939
  * sibling root in this build) or as a ref-only `data.elementum_automation`
@@ -831,9 +941,20 @@ function registerForeignFieldLookup(value, ctx, dataBlocks) {
831
941
  * `automation { id }` + `inputMappings.parameter.id` contract; it must never
832
942
  * degrade to `target_automation_ref` / `dynamic_input_mappings`.
833
943
  */
834
- function automationTargetToTf(value, ctx, dataBlocks) {
835
- const { ownerKind, isOwn } = automationTargetOwner(value, ctx);
836
- 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
837
958
  ? ctx.workspaceAspects?.get(workspaceAspectKey(ownerKind, value.parent))
838
959
  : undefined;
839
960
  const managedOwnerLabel = isOwn
@@ -841,6 +962,32 @@ function automationTargetToTf(value, ctx, dataBlocks) {
841
962
  : sibling !== undefined && sibling.kind !== "table"
842
963
  ? sibling.tfLabel
843
964
  : undefined;
965
+ const ownAutomations = isOwn ? ctx.workspaceAspects?.get(workspaceAspectKey(ownerKind, ctx.appRefName))?.automationRefNames : undefined;
966
+ if (ownAutomations !== undefined && !ownAutomations.has(value.refName) && typeof value.name === "string" && value.name !== "") {
967
+ // An automation of this owner that is not in source (pull leaves it
968
+ // platform-managed, #3047): a reference to its resources would be
969
+ // undeclared, so read its id and published parameter ids through a
970
+ // lookup by display name, the lookup a widget or dynamic-layout button
971
+ // uses (#1901, #2693). It names no publish, so nothing waits on one, and
972
+ // it reads the owner by namespace, so an app change doesn't defer it.
973
+ const label = `${ctx.appTfLabel}_${tsLabelToTfLabel(value.refName)}`;
974
+ const ownerId = automationLookupOwnerId(ctx.parentScope, ctx.appTfLabel, ctx.orgRefs, dataBlocks);
975
+ if (ctx.orgRefs !== undefined) {
976
+ ctx.orgRefs.rawLookup(AUTOMATION_RESOURCE_TYPE, label, value.name, { app_id: ownerId });
977
+ }
978
+ else {
979
+ dataBlocks.set(`${AUTOMATION_RESOURCE_TYPE}.${label}`, {
980
+ kind: "data",
981
+ type: AUTOMATION_RESOURCE_TYPE,
982
+ label,
983
+ attrs: { app_id: ownerId, name: value.name },
984
+ });
985
+ }
986
+ return {
987
+ id: expr.dataAttr(AUTOMATION_RESOURCE_TYPE, label, ["id"]),
988
+ parameterId: (name) => expr.dataAttr(AUTOMATION_RESOURCE_TYPE, label, ["parameter_ids", { index: name }]),
989
+ };
990
+ }
844
991
  if (managedOwnerLabel !== undefined) {
845
992
  const targetOwner = ctx.workspaceAspects?.get(workspaceAspectKey(ownerKind, isOwn ? ctx.appRefName : value.parent ?? ""));
846
993
  const managedHandle = ownerKind === "element"
@@ -895,7 +1042,8 @@ function automationTargetToTf(value, ctx, dataBlocks) {
895
1042
  throw new EntityTfError(`foreign automation ref "${value.refName}" has no parent`);
896
1043
  }
897
1044
  if (value.parentName === undefined || value.parentName === "") {
898
- 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).`);
899
1047
  }
900
1048
  if (value.name === undefined || value.name === "") {
901
1049
  throw new EntityTfError(`foreign automation ref "${value.parent}.${value.refName}" has no lookup name`);
@@ -1122,14 +1270,16 @@ function tokenToTf(value, ctx, dataBlocks) {
1122
1270
  if (owner === undefined || owner === "") {
1123
1271
  throw new EntityTfError(`table column ref "${value.refName}" is missing its owning table`);
1124
1272
  }
1125
- const sibling = ctx.workspaceAspects?.get(workspaceAspectKey("table", owner));
1126
- const displayNames = extractTableColumnDisplayNames(sibling);
1127
- 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;
1128
1278
  return resolveTableColumnFieldExpr({
1129
1279
  tableRefName: owner,
1130
1280
  tableName: value.parentName,
1131
- columnKey: rawColName,
1132
- columnDisplayNames: displayNames,
1281
+ columnKey: value.name ?? value.refName,
1282
+ ...(sibling !== undefined && { columnDisplayNames: extractTableColumnDisplayNames(sibling) }),
1133
1283
  workspaceAspects: ctx.workspaceAspects,
1134
1284
  orgRefs: ctx.orgRefs,
1135
1285
  dataBlocks,
@@ -1211,8 +1361,28 @@ function tokenToTf(value, ctx, dataBlocks) {
1211
1361
  }
1212
1362
  return expr.dataAttr("elementum_search_table", label, ["id"]);
1213
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
+ }
1214
1373
  if (element !== undefined) {
1215
- 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);
1216
1386
  }
1217
1387
  if (table !== undefined) {
1218
1388
  throw new EntityTfError(`search table "${owner}.${value.refName}" is a ${variant} search table owned by table "${owner}" — ` +
@@ -1468,6 +1638,7 @@ function calculationFormulaRefToParts(value, refs) {
1468
1638
  !("triggerReference" in value) &&
1469
1639
  !("taskReference" in value) &&
1470
1640
  !("variableReference" in value) &&
1641
+ !("forEachReference" in value) &&
1471
1642
  !("templateReference" in value) &&
1472
1643
  Object.keys(value).length === 1) {
1473
1644
  return calculationFormulaRefToParts(value.value, refs);
@@ -1494,6 +1665,11 @@ function calculationFormulaRefToParts(value, refs) {
1494
1665
  }
1495
1666
  return ["variable.", variableIdAttr(target)];
1496
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
+ }
1497
1673
  if (isObject(value.templateReference))
1498
1674
  return calculationTemplateToParts(value.templateReference, refs);
1499
1675
  if (typeof value.kind === "string") {
@@ -1503,7 +1679,50 @@ function calculationFormulaRefToParts(value, refs) {
1503
1679
  if (value.kind === "literal" && "value" in value)
1504
1680
  return calculationFormulaRefToParts(value.value, refs);
1505
1681
  }
1506
- 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}`]));
1507
1726
  }
1508
1727
  /**
1509
1728
  * Calc-engine mustache for a prior task output:
@@ -1549,7 +1768,10 @@ function calculationTaskRefName(targetType, name, taskRefKey, refs) {
1549
1768
  }
1550
1769
  // A single-output AI task's `.output` reaches here as its refs label
1551
1770
  // (`Response`); the calc engine resolves only the canonical name (`response`, #2405).
1552
- 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)) ??
1553
1775
  canonicalSingleOutputName(targetType, name) ?? name;
1554
1776
  if (refName.includes('"')) {
1555
1777
  throw new EntityTfError(`calculation task output name "${refName}" contains a double quote`);
@@ -1578,6 +1800,16 @@ function taskOutputRefsIndex(resourceType, name) {
1578
1800
  return TABLE_RECORDS_SEARCH_REFS_INDEX[name];
1579
1801
  return aiCompletionRefsIndex(resourceType, name);
1580
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
+ }
1581
1813
  /** A refs key's WorkflowTaskReference name. An apiRequest maps only when it's JSON; FILE and CUSTOM are unconfirmed live (edk#2058). */
1582
1814
  function taskOutputReferenceName(type, wireName, task) {
1583
1815
  if (type === TASK_RESOURCES.api && task?.jsonApiResponse !== true)
@@ -1706,7 +1938,9 @@ function foreignFoundRecordFieldId(fieldKey, taskRefKey, refs) {
1706
1938
  return expr.dataAttr("elementum_field", registerForeignFieldLookup(fieldToken, refs.owner, refs.dataBlocks), ["id"]);
1707
1939
  }
1708
1940
  function calculationTriggerMustache(name, refs) {
1709
- const triggerName = onDemandTriggerRefName(name, refs) ?? slackTriggerReferenceName(name, refs);
1941
+ const triggerName = onDemandTriggerRefName(name, refs) ??
1942
+ slackTriggerReferenceName(name, refs) ??
1943
+ approvalTriggerReferenceNameOn(name, refs);
1710
1944
  if (triggerName !== undefined)
1711
1945
  return [`{{trigger name="${triggerName}"}}`];
1712
1946
  const parts = name.split(".");
@@ -2058,6 +2292,11 @@ function taskWireRefName(name, taskRefKey, refs) {
2058
2292
  // indexes a key the refs map does not contain (Invalid index at plan).
2059
2293
  if (refs.tasks.get(taskRefKey)?.type === TASK_RESOURCES.runAutomation)
2060
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;
2061
2300
  assertFindRelatedRecordsHasNoCountRef(refs.tasks.get(taskRefKey)?.type, name, taskRefKey);
2062
2301
  const handleKey = findRelatedRecordsAppTitleWireKey(name, taskRefKey, refs);
2063
2302
  if (handleKey !== undefined)
@@ -2148,6 +2387,20 @@ function slackTriggerRefName(name, refs) {
2148
2387
  function slackTriggerReferenceName(name, refs) {
2149
2388
  return refs.trigger.type === TRIGGER_RESOURCES.slackMessage ? slackMessageTriggerReferenceName(name) : undefined;
2150
2389
  }
2390
+ /**
2391
+ * An approval process status trigger's refs-map key (#2990); undefined on any
2392
+ * other trigger or for a record reference. A field of the app that shares the
2393
+ * key's display name moves the output to its group-qualified key.
2394
+ */
2395
+ function approvalTriggerRefName(name, refs) {
2396
+ return refs.trigger.type === TRIGGER_RESOURCES.approvalChain
2397
+ ? approvalTriggerRefsKey(name, refs.owner.fieldNames.values())
2398
+ : undefined;
2399
+ }
2400
+ /** An approval process status trigger's `triggerReference.name`; undefined on any other trigger. */
2401
+ function approvalTriggerReferenceNameOn(name, refs) {
2402
+ return refs.trigger.type === TRIGGER_RESOURCES.approvalChain ? approvalTriggerReferenceName(name) : undefined;
2403
+ }
2151
2404
  function triggerWireRefName(name, refs) {
2152
2405
  const onDemandName = onDemandTriggerRefName(name, refs);
2153
2406
  if (onDemandName !== undefined)
@@ -2155,6 +2408,9 @@ function triggerWireRefName(name, refs) {
2155
2408
  const slackName = slackTriggerRefName(name, refs);
2156
2409
  if (slackName !== undefined)
2157
2410
  return slackName;
2411
+ const approvalName = approvalTriggerRefName(name, refs);
2412
+ if (approvalName !== undefined)
2413
+ return approvalName;
2158
2414
  const scalarParams = refs.triggerParamNames.filter((param) => !refs.recordParamNames.includes(param));
2159
2415
  const declared = onDemandTriggerRefKey(name, scalarParams);
2160
2416
  if (declared !== name || scalarParams.includes(name))
@@ -2465,6 +2721,7 @@ function workflowPublishOutputEnvelope(value, refs) {
2465
2721
  triggerReference: {
2466
2722
  name: onDemandTriggerRefName(value.triggerReference.name, refs) ??
2467
2723
  slackTriggerReferenceName(value.triggerReference.name, refs) ??
2724
+ approvalTriggerReferenceNameOn(value.triggerReference.name, refs) ??
2468
2725
  wireRefName(value.triggerReference.name, refs.owner),
2469
2726
  },
2470
2727
  variableReference: null,
@@ -2608,6 +2865,61 @@ function collectPayloadTaskKinds(value, kinds) {
2608
2865
  collectPayloadTaskKinds(nested, kinds);
2609
2866
  return kinds;
2610
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
+ }
2611
2923
  /**
2612
2924
  * edk#1499: script-input field mappings read fields off a whole record. A
2613
2925
  * value that exposes only a record ID (an onDemand record parameter, or
@@ -2615,6 +2927,10 @@ function collectPayloadTaskKinds(value, kinds) {
2615
2927
  * plus field mappings, and the script receives `{}` at runtime. Record
2616
2928
  * triggers' `ctx.trigger.record` and the `.record` of recordSearch,
2617
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.
2618
2934
  */
2619
2935
  export function recordIdFieldMappingFailures(entity, payload, address) {
2620
2936
  const onDemandRecordParams = onDemandRecordParamNames(payload.trigger);
@@ -2630,16 +2946,27 @@ export function recordIdFieldMappingFailures(entity, payload, address) {
2630
2946
  if (!isObject(value))
2631
2947
  return;
2632
2948
  const here = typeof value.refKey === "string" && isObject(value.task) ? value.refKey : action;
2633
- if (Array.isArray(value.field_mappings) && isObject(value.value)) {
2634
- let source;
2635
- const trigger = value.value.triggerReference;
2636
- if (isObject(trigger) && typeof trigger.name === "string" && onDemandRecordParams.has(trigger.name)) {
2637
- source = `ctx.trigger.${trigger.name} (an on-demand record parameter)`;
2638
- }
2639
- const task = value.value.taskReference;
2640
- if (isObject(task) && typeof task.taskRefKey === "string" && task.name === "record" && taskKinds.get(task.taskRefKey) === "findRelatedRecords") {
2641
- 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
+ });
2642
2966
  }
2967
+ }
2968
+ if (Array.isArray(value.field_mappings) && isObject(value.value)) {
2969
+ const source = recordIdOnlySource(value.value, onDemandRecordParams, taskKinds);
2643
2970
  if (source !== undefined) {
2644
2971
  failures.push({
2645
2972
  severity: "fatal",
@@ -3031,6 +3358,20 @@ function searchRecordsContractName(resourceType, name, wireName) {
3031
3358
  return entry.contractName;
3032
3359
  }
3033
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
+ };
3034
3375
  function filterReferenceToTf(value, refs, role = "value", realType, operator) {
3035
3376
  // Raw pass-through for a filter left side the pull-time deserializer
3036
3377
  // couldn't decode to a typed ref (filter.ts's leftDescriptor, matching the
@@ -3145,6 +3486,20 @@ function filterReferenceToTf(value, refs, role = "value", realType, operator) {
3145
3486
  (value.name === "recordId" || value.name === "record")) {
3146
3487
  return "trigger.recordId";
3147
3488
  }
3489
+ // An approval process status trigger's own outputs (#2990): a filter
3490
+ // reads them by the platform's short form, `trigger.approver.id`, as
3491
+ // the editor saves and export prints it (edk#1569). The bare approver
3492
+ // would walk to the whole user, so a filter names the field it compares.
3493
+ if (refs.trigger.type === TRIGGER_RESOURCES.approvalChain) {
3494
+ const referenceName = approvalTriggerReferenceName(value.name);
3495
+ if (referenceName !== undefined) {
3496
+ if (value.name === "approver") {
3497
+ throw new EntityTfError("filter on ctx.trigger.approver: compare a field of the approver, " +
3498
+ "ctx.trigger.approver.id, .email or .name");
3499
+ }
3500
+ return `trigger.${referenceName}`;
3501
+ }
3502
+ }
3148
3503
  const triggerRefKey = triggerWireRefName(value.name, refs);
3149
3504
  if (refs.trigger.type === TRIGGER_RESOURCES.onDemand) {
3150
3505
  // filter_refs holds only declared inputs, so the user who ran the
@@ -3159,7 +3514,7 @@ function filterReferenceToTf(value, refs, role = "value", realType, operator) {
3159
3514
  // object, so a filter must name the field it compares.
3160
3515
  if (value.name === "triggeredBy") {
3161
3516
  throw new EntityTfError("filter on ctx.trigger.triggeredBy: compare a field of the user who ran the automation, " +
3162
- "ctx.trigger.triggeredBy.id, .email or .name");
3517
+ "ctx.trigger.triggeredBy.id, .email or .name (filter.groupsOf takes ctx.trigger.triggeredBy.id)");
3163
3518
  }
3164
3519
  return `trigger.${value.name}`;
3165
3520
  }
@@ -3172,6 +3527,14 @@ function filterReferenceToTf(value, refs, role = "value", realType, operator) {
3172
3527
  if (triggerRefKey === value.name && TRIGGER_REFERENCE_NAME_PATTERN.test(value.name)) {
3173
3528
  return `trigger.${value.name}`;
3174
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
+ }
3175
3538
  return expr.resourceAttr(refs.trigger.type, refs.trigger.label, ["refs", { index: triggerRefKey }]);
3176
3539
  }
3177
3540
  case "TASK": {
@@ -3377,7 +3740,7 @@ function filterReferenceToTf(value, refs, role = "value", realType, operator) {
3377
3740
  : taskOutputRefsIndex(task.type, wireName) ?? wireName;
3378
3741
  return expr.resourceAttr(task.type, task.label, ["refs", { index: refsIndex }]);
3379
3742
  }
3380
- // 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
3381
3744
  // single output by its canonical name (`response`, edk#1509); only
3382
3745
  // `.refs` is keyed by their display labels. recordSearch's ASPECT_RECORD_ID
3383
3746
  // is keyed `First found record id` in refs, but filter RHS / ei export use
@@ -3387,6 +3750,11 @@ function filterReferenceToTf(value, refs, role = "value", realType, operator) {
3387
3750
  // Records filter value uses that same short name. A Table Records
3388
3751
  // Search's or AI Data Search's `.records` uses its contract name.
3389
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;
3390
3758
  const shortName = task.type === TASK_RESOURCES.userSearch
3391
3759
  ? USER_SEARCH_PATH_BY_WIRE_NAME.get(wireName) ?? wireName
3392
3760
  : task.type === TASK_RESOURCES.recordSearch &&
@@ -3397,9 +3765,13 @@ function filterReferenceToTf(value, refs, role = "value", realType, operator) {
3397
3765
  ? "records"
3398
3766
  : searchRecords !== undefined
3399
3767
  ? searchRecords
3400
- : task.type === TASK_RESOURCES.api
3401
- ? taskOutputReferenceName(task.type, wireName, task) ?? wireName
3402
- : 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;
3403
3775
  return expr.template([
3404
3776
  "task.",
3405
3777
  expr.resourceAttr(task.type, task.label, ["id"]),
@@ -3432,9 +3804,15 @@ function filterReferenceToTf(value, refs, role = "value", realType, operator) {
3432
3804
  if (fieldKey === undefined || fieldKey === "")
3433
3805
  throw new EntityTfError("record loop filter reference has no field");
3434
3806
  const isIdentity = value.name === "item" || value.name === "recordId";
3435
- const foreignFieldId = isIdentity ? undefined : foreignFoundRecordFieldId(fieldKey, source, refs);
3436
- const scope = isIdentity || foreignFieldId !== undefined ? undefined : calculationFieldScope(source, refs);
3437
- 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);
3438
3816
  const joinedSuffix = suffix.join(".");
3439
3817
  let wireSuffix = joinedSuffix === "recordId" ? RECORD_ID_REFERENCE_FIELD : joinedSuffix;
3440
3818
  // Same rule as a trigger-record filter: an option-bearing picklist has
@@ -3747,9 +4125,101 @@ function booleanTaskOutputRealType(reference, refs, authored) {
3747
4125
  const declared = declaredTaskOutputType(task, wireName, envelopeName);
3748
4126
  return declared?.fieldType === "BOOLEAN" && declared.multiple !== true ? "BOOLEAN" : undefined;
3749
4127
  }
3750
- function filterToTf(value, refs) {
4128
+ /**
4129
+ * What a record field holds when a filter reference reads it, for any record
4130
+ * `recordFieldSource` can place: the trigger record, an on-demand record
4131
+ * input, a found record or a record loop item, of this app or another
4132
+ * (edk#3039). A user field is the whole user unless the path ends in `.id`
4133
+ * (mobius normalizeUsers); every other known field is not a user's id.
4134
+ */
4135
+ function recordFieldDeclaredType(reference, refs) {
4136
+ const kind = reference.type?.toString().toUpperCase();
4137
+ const valueReference = kind === "TASK" ? { taskReference: { taskRefKey: reference.taskRefKey, name: reference.name } }
4138
+ : kind === "TRIGGER" ? { triggerReference: { name: reference.name } }
4139
+ : kind === "FOR_EACH" ? { forEachReference: { forEachTaskRefKey: reference.forEachTaskRefKey, name: reference.name } }
4140
+ : undefined;
4141
+ const source = valueReference === undefined ? undefined : recordFieldSource(valueReference, refs);
4142
+ if (source === undefined)
4143
+ return undefined;
4144
+ const address = source.addresses?.get(source.fieldKey);
4145
+ const resourceType = address === undefined ? undefined : address.slice(0, address.indexOf("."));
4146
+ const catalogTypes = source.addresses === undefined && source.ownerRefName !== undefined
4147
+ ? fieldNamesForAppRefName(refs.owner.catalogFieldTypesByAppRefName, source.ownerRefName)
4148
+ : undefined;
4149
+ const catalogType = catalogTypes?.get(source.fieldKey);
4150
+ const ownerKnown = source.addresses !== undefined || catalogTypes !== undefined;
4151
+ // Only a key the owner has is classified. Any other key (pull keeps a deleted
4152
+ // field's raw id, edk#3039 round 6) stays unchecked, as filter.uuid does.
4153
+ const systemField = ownerKnown && SYSTEM_FIELD_KEY_SET.has(source.fieldKey);
4154
+ const isUser = resourceType !== undefined ? resourceType === "elementum_user_field"
4155
+ : catalogType !== undefined ? catalogType === "USER" || catalogType === "USER_ID"
4156
+ : systemField ? OBJECT_VALUED_SYSTEM_FIELD_KINDS[source.fieldKey] === "user"
4157
+ : undefined;
4158
+ if (isUser === undefined)
4159
+ return undefined;
4160
+ const rest = source.rest.join(".");
4161
+ if (isUser)
4162
+ return { type: rest === "id" ? "USER_ID" : rest === "" ? "USER" : "TEXT" };
4163
+ // A deeper path through another field (a dynamic Dropdown's linked record,
4164
+ // `hallPassReason.createdBy.id`) reads that record, which isn't typed here.
4165
+ if (source.rest.length > 1)
4166
+ return undefined;
4167
+ const fieldType = resourceType?.replace(/^elementum_/, "").replace(/_field$/, "").toUpperCase()
4168
+ ?? catalogType
4169
+ ?? (source.fieldKey === "id" ? "RECORD_HANDLE" : "SYSTEM_FIELD");
4170
+ return { type: rest === "" ? fieldType : `${fieldType}_PART` };
4171
+ }
4172
+ /**
4173
+ * The declared type of what a filter reference holds, for `filter.groupsOf`'s
4174
+ * one-user-id check (edk#3039): the user who ran an on-demand automation, a
4175
+ * record field of any app (trigger record, on-demand record input, found
4176
+ * record or record loop item), a record loop's own item, a whole plain-list
4177
+ * loop item, a task output with a declared type, or a variable with a
4178
+ * declared type. Undefined when the type isn't known here.
4179
+ */
4180
+ function filterReferenceDeclaredType(reference, refs) {
4181
+ if (!isObject(reference) || typeof reference.name !== "string")
4182
+ return undefined;
4183
+ const kind = reference.type?.toString().toUpperCase();
4184
+ if (kind === "TRIGGER") {
4185
+ if (refs.trigger?.type === TRIGGER_RESOURCES.onDemand && ON_DEMAND_TRIGGERED_BY_REFS[reference.name] !== undefined) {
4186
+ return { type: reference.name === "triggeredBy" || reference.name === "triggeredBy.id" ? "USER_ID" : "TEXT" };
4187
+ }
4188
+ return recordFieldDeclaredType(reference, refs);
4189
+ }
4190
+ if (kind === "TASK" && typeof reference.taskRefKey === "string") {
4191
+ const task = refs.tasks.get(reference.taskRefKey);
4192
+ if (task === undefined)
4193
+ return undefined;
4194
+ if (/^records?\./.test(reference.name))
4195
+ return recordFieldDeclaredType(reference, refs);
4196
+ const wireName = taskWireRefName(reference.name, reference.taskRefKey, refs);
4197
+ const envelopeName = taskOutputReferenceName(task.type, wireName, task) ?? wireName;
4198
+ const declared = declaredTaskOutputType(task, wireName, envelopeName);
4199
+ return declared === undefined ? undefined : { type: declared.fieldType, multiple: declared.multiple };
4200
+ }
4201
+ if (kind === "FOR_EACH" && typeof reference.forEachTaskRefKey === "string") {
4202
+ if (!refs.recordItemForEachRefKeys.has(reference.forEachTaskRefKey)) {
4203
+ // A plain-list loop's whole item (a user, say) is an object, not an id.
4204
+ return reference.name === "" || reference.name === "item" ? { type: "OBJECT" } : undefined;
4205
+ }
4206
+ // The loop item itself is the record, of any app: its id, never a user's.
4207
+ const [fieldKey] = reference.name.split(".");
4208
+ if (fieldKey === undefined || fieldKey === "" || fieldKey === "item" || fieldKey === "recordId")
4209
+ return { type: "ASPECT_RECORD_ID" };
4210
+ return recordFieldDeclaredType(reference, refs);
4211
+ }
4212
+ if (kind === "VARIABLE" && typeof reference.variableId === "string") {
4213
+ const valueType = refs.variableById.get(reference.variableId)?.valueType;
4214
+ return valueType === undefined ? undefined : { type: valueType };
4215
+ }
4216
+ return undefined;
4217
+ }
4218
+ function filterToTf(value, refs, options = {}) {
3751
4219
  return serializeFilterToTf(value, {
3752
4220
  ...(refs.allowUnknownPicklistOptions === true && { keepUnresolvedOptions: true }),
4221
+ ...(options.allowGroupsOf === true && { allowGroupsOf: true }),
4222
+ referenceDeclaredType: (reference) => filterReferenceDeclaredType(reference, refs),
3753
4223
  field: (field) => valueToTf(field, refs),
3754
4224
  // `userRef(email)` compares as the user's id, through the same user lookup a task value uses (#2891).
3755
4225
  user: (email) => valueToTf({ __kind: "user", email }, refs),
@@ -3866,6 +4336,15 @@ function configAttrs(kind, config, refs) {
3866
4336
  // build time) - name the wire key here, since the generic valueToTf
3867
4337
  // fallback below has no attribute name to report by the time it gets to
3868
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
+ }
3869
4348
  if (raw === undefined) {
3870
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`);
3871
4350
  }
@@ -4049,7 +4528,8 @@ function configAttrs(kind, config, refs) {
4049
4528
  throw new EntityTfError("runAutomation targetAutomationId has an unresolved automation");
4050
4529
  }
4051
4530
  if (key === "filter") {
4052
- attrs.filter = filterToTf(raw, refs);
4531
+ // Only a record search expands filter.groupsOf (ultron), edk#3039.
4532
+ attrs.filter = filterToTf(raw, refs, { allowGroupsOf: kind === TASK_RESOURCES.recordSearch });
4053
4533
  continue;
4054
4534
  }
4055
4535
  if (key === "categorySource" && kind === "elementum_ai_classify_task") {
@@ -4426,6 +4906,27 @@ function configAttrs(kind, config, refs) {
4426
4906
  };
4427
4907
  continue;
4428
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
+ }
4429
4930
  if (key === "multipartBody" && kind === "elementum_api_task") {
4430
4931
  if (!isObject(raw) || !Array.isArray(raw.parts))
4431
4932
  throw new EntityTfError("apiRequest multipartBody.parts must be an array");
@@ -4513,6 +5014,8 @@ export function automationToTf(entity, ctx) {
4513
5014
  localsAttrs: ctx.localsAttrs,
4514
5015
  workspaceAspects: ctx.workspaceAspects,
4515
5016
  ...(ctx.outOfScopeApps !== undefined ? { outOfScopeApps: ctx.outOfScopeApps } : {}),
5017
+ ...(ctx.outOfScopeElements !== undefined ? { outOfScopeElements: ctx.outOfScopeElements } : {}),
5018
+ ...(ctx.catalogElementIdentities !== undefined ? { catalogElementIdentities: ctx.catalogElementIdentities } : {}),
4516
5019
  diagnostics: ctx.diagnostics ?? [],
4517
5020
  activeAutomationRefNames: ctx.activeAutomationRefNames,
4518
5021
  ...(ctx.elementsWithoutAuditFields !== undefined ? { elementsWithoutAuditFields: ctx.elementsWithoutAuditFields } : {}),
@@ -4619,10 +5122,11 @@ export function automationToTf(entity, ctx) {
4619
5122
  const resourceType = wireType === "variable" ? variableTaskResourceType(taskBody, refKey) : TASK_RESOURCES[wireType];
4620
5123
  if (resourceType === undefined)
4621
5124
  throw new EntityTfError(`task type "${wireType}" is not supported by the provider HCL contract`);
4622
- // elementum_unmanaged_task_reference is a data source exported under its
4623
- // own bare sanitized-name label - never scoped under the automation the
4624
- // way every real task resource is (confirmed live, edk#821).
4625
- 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);
4626
5130
  const collidingRefKey = usedLabels.get(registeredLabel);
4627
5131
  if (collidingRefKey !== undefined) {
4628
5132
  throw new EntityTfError(`task "${refKey}" sanitizes to the same tf label as task "${collidingRefKey}" (${registeredLabel}) — rename one of them`);
@@ -4650,7 +5154,10 @@ export function automationToTf(entity, ctx) {
4650
5154
  if (wireType === "variable" && Array.isArray(taskBody.create)) {
4651
5155
  taskBody.create.forEach((candidate, index) => {
4652
5156
  if (isObject(candidate) && typeof candidate.id === "string" && typeof candidate.name === "string") {
4653
- variableById.set(candidate.id, { type: "elementum_variable_task", label: registeredLabel, name: candidate.name, index });
5157
+ variableById.set(candidate.id, {
5158
+ type: "elementum_variable_task", label: registeredLabel, name: candidate.name, index,
5159
+ ...(typeof candidate.type === "string" ? { valueType: candidate.type } : {}),
5160
+ });
4654
5161
  }
4655
5162
  });
4656
5163
  }
@@ -4780,6 +5287,9 @@ export function automationToTf(entity, ctx) {
4780
5287
  const [wireType, inner] = onlyEntry(task.task, `task "${refKey}"`);
4781
5288
  const resourceType = TASK_RESOURCES[wireType];
4782
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 } : {};
4783
5293
  const displayName = typeof inner.name === "string" ? inner.name : refKey;
4784
5294
  let taskParent = parent;
4785
5295
  if (task.hclParent === "trigger") {
@@ -4865,7 +5375,7 @@ export function automationToTf(entity, ctx) {
4865
5375
  const variableType = variableTaskResourceType(inner, refKey);
4866
5376
  const creates = Array.isArray(inner.create) ? inner.create : [];
4867
5377
  const updates = Array.isArray(inner.update) ? inner.update : [];
4868
- const variableAttrs = { parent: taskParent, name: displayName };
5378
+ const variableAttrs = { parent: taskParent, ...nameAttr };
4869
5379
  if (creates.length > 0) {
4870
5380
  variableAttrs.variables = creates.map((item) => {
4871
5381
  if (!isObject(item) || typeof item.name !== "string" || typeof item.type !== "string") {
@@ -4899,7 +5409,7 @@ export function automationToTf(entity, ctx) {
4899
5409
  }
4900
5410
  const attrs = {
4901
5411
  parent: taskParent,
4902
- name: displayName,
5412
+ ...nameAttr,
4903
5413
  ...taskAttrs,
4904
5414
  ...(OBJECT_FIELD_REFS_TASK_TYPES.has(resourceType)
4905
5415
  ? taskObjectFieldAttrs(taskAttrs["object_id"], taskTargetFieldAddresses(inner.aspectId ?? inner.relatedAspectId, owner))
@@ -4955,8 +5465,22 @@ export function automationToTf(entity, ctx) {
4955
5465
  }
4956
5466
  else if (wireType === "switch" || wireType === "forkJoin") {
4957
5467
  const children = task.children ?? [];
4958
- if (children.length === 0)
4959
- 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
+ }
4960
5484
  const usedLabels = new Map();
4961
5485
  // Separate from usedLabels above: that map rejects two branches
4962
5486
  // sharing the same RAW display label/no-label, but a genuinely