@elementumai/edk 0.11.0 → 0.13.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 (222) hide show
  1. package/README.md +40 -6
  2. package/dist-sdk/src/catalog/factories.d.ts +7 -1
  3. package/dist-sdk/src/catalog/factories.js +2 -0
  4. package/dist-sdk/src/catalog/index.d.ts +2 -2
  5. package/dist-sdk/src/catalog/index.js +1 -1
  6. package/dist-sdk/src/catalog/org.js +79 -34
  7. package/dist-sdk/src/catalog/token.js +5 -0
  8. package/dist-sdk/src/catalog/types.d.ts +7 -1
  9. package/dist-sdk/src/catalog/types.js +3 -0
  10. package/dist-sdk/src/core/system-fields.d.ts +1 -1
  11. package/dist-sdk/src/core/system-fields.js +1 -1
  12. package/dist-sdk/src/core/triggers/on-demand.d.ts +2 -0
  13. package/dist-sdk/src/core/triggers/on-demand.js +3 -0
  14. package/dist-sdk/src/core/types/app.d.ts +6 -0
  15. package/dist-sdk/src/engine/build/context.d.ts +3 -0
  16. package/dist-sdk/src/engine/coverage-gaps.d.ts +5 -0
  17. package/dist-sdk/src/engine/coverage-gaps.js +9 -0
  18. package/dist-sdk/src/engine/ei/run.d.ts +20 -1
  19. package/dist-sdk/src/engine/ei/run.js +102 -14
  20. package/dist-sdk/src/engine/pull/authored-address.js +42 -6
  21. package/dist-sdk/src/engine/pull/authored-root.d.ts +88 -0
  22. package/dist-sdk/src/engine/pull/authored-root.js +306 -0
  23. package/dist-sdk/src/engine/pull/context.d.ts +10 -0
  24. package/dist-sdk/src/engine/pull/field-refs-registry.d.ts +114 -0
  25. package/dist-sdk/src/engine/pull/field-refs-registry.js +501 -0
  26. package/dist-sdk/src/engine/pull/org.d.ts +1 -0
  27. package/dist-sdk/src/engine/pull/org.js +2 -0
  28. package/dist-sdk/src/engine/pull/partition.d.ts +8 -0
  29. package/dist-sdk/src/engine/pull/partition.js +43 -0
  30. package/dist-sdk/src/engine/pull/pulled-roots.d.ts +89 -0
  31. package/dist-sdk/src/engine/pull/pulled-roots.js +203 -0
  32. package/dist-sdk/src/engine/pull/ref-only.d.ts +22 -0
  33. package/dist-sdk/src/engine/pull/ref-only.js +59 -1
  34. package/dist-sdk/src/engine/pull/source-resources.d.ts +39 -0
  35. package/dist-sdk/src/engine/pull/source-resources.js +110 -0
  36. package/dist-sdk/src/engine/pull/stream-root.d.ts +148 -0
  37. package/dist-sdk/src/engine/pull/stream-root.js +563 -0
  38. package/dist-sdk/src/engine/workspace/reserved-catalog-keys.d.ts +47 -0
  39. package/dist-sdk/src/engine/workspace/reserved-catalog-keys.js +115 -0
  40. package/dist-sdk/src/entities/access-policy/build.d.ts +2 -1
  41. package/dist-sdk/src/entities/access-policy/from-tf.d.ts +9 -1
  42. package/dist-sdk/src/entities/access-policy/from-tf.js +25 -4
  43. package/dist-sdk/src/entities/access-policy/module.js +5 -0
  44. package/dist-sdk/src/entities/access-policy/to-tf.d.ts +19 -0
  45. package/dist-sdk/src/entities/access-policy/to-tf.js +65 -8
  46. package/dist-sdk/src/entities/agent/build.d.ts +52 -1
  47. package/dist-sdk/src/entities/agent/build.js +34 -0
  48. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +68 -0
  49. package/dist-sdk/src/entities/agent/from-tf.d.ts +34 -1
  50. package/dist-sdk/src/entities/agent/from-tf.js +262 -2
  51. package/dist-sdk/src/entities/agent/index.d.ts +1 -1
  52. package/dist-sdk/src/entities/agent/to-tf.d.ts +8 -10
  53. package/dist-sdk/src/entities/agent/to-tf.js +158 -14
  54. package/dist-sdk/src/entities/agent-tool/from-tf.js +6 -0
  55. package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +2 -2
  56. package/dist-sdk/src/entities/agent-tool/to-tf.js +2 -2
  57. package/dist-sdk/src/entities/app/build.d.ts +34 -14
  58. package/dist-sdk/src/entities/app/build.js +93 -16
  59. package/dist-sdk/src/entities/app/from-tf.js +25 -11
  60. package/dist-sdk/src/entities/app/index.d.ts +1 -0
  61. package/dist-sdk/src/entities/app/index.js +1 -0
  62. package/dist-sdk/src/entities/app/module.js +1 -0
  63. package/dist-sdk/src/entities/app/stage-keys.d.ts +20 -5
  64. package/dist-sdk/src/entities/app/stage-keys.js +43 -9
  65. package/dist-sdk/src/entities/app/to-tf.js +2 -0
  66. package/dist-sdk/src/entities/approval-chain/build.d.ts +46 -11
  67. package/dist-sdk/src/entities/approval-chain/build.js +120 -8
  68. package/dist-sdk/src/entities/approval-chain/from-tf.d.ts +24 -2
  69. package/dist-sdk/src/entities/approval-chain/from-tf.js +148 -6
  70. package/dist-sdk/src/entities/approval-chain/index.d.ts +4 -1
  71. package/dist-sdk/src/entities/approval-chain/index.js +4 -1
  72. package/dist-sdk/src/entities/approval-chain/module.js +23 -5
  73. package/dist-sdk/src/entities/approval-chain/printer.d.ts +1 -1
  74. package/dist-sdk/src/entities/approval-chain/printer.js +91 -5
  75. package/dist-sdk/src/entities/approval-chain/steps-tf.d.ts +77 -0
  76. package/dist-sdk/src/entities/approval-chain/steps-tf.js +255 -0
  77. package/dist-sdk/src/entities/approval-chain/steps.d.ts +71 -0
  78. package/dist-sdk/src/entities/approval-chain/steps.js +83 -0
  79. package/dist-sdk/src/entities/approval-chain/to-tf.d.ts +16 -6
  80. package/dist-sdk/src/entities/approval-chain/to-tf.js +37 -4
  81. package/dist-sdk/src/entities/automation/build.d.ts +50 -24
  82. package/dist-sdk/src/entities/automation/build.js +86 -33
  83. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +52 -8
  84. package/dist-sdk/src/entities/automation/from-tf.d.ts +38 -6
  85. package/dist-sdk/src/entities/automation/from-tf.js +855 -157
  86. package/dist-sdk/src/entities/automation/index.d.ts +2 -1
  87. package/dist-sdk/src/entities/automation/index.js +1 -0
  88. package/dist-sdk/src/entities/automation/module.d.ts +4 -3
  89. package/dist-sdk/src/entities/automation/module.js +33 -12
  90. package/dist-sdk/src/entities/automation/refs-read.d.ts +19 -0
  91. package/dist-sdk/src/entities/automation/refs-read.js +48 -0
  92. package/dist-sdk/src/entities/automation/run-target.d.ts +2 -0
  93. package/dist-sdk/src/entities/automation/run-target.js +5 -0
  94. package/dist-sdk/src/entities/automation/script-code.d.ts +2 -1
  95. package/dist-sdk/src/entities/automation/script-code.js +82 -1
  96. package/dist-sdk/src/entities/automation/script-lint.d.ts +13 -0
  97. package/dist-sdk/src/entities/automation/script-lint.js +418 -0
  98. package/dist-sdk/src/entities/automation/slack-message-refs.d.ts +9 -0
  99. package/dist-sdk/src/entities/automation/slack-message-refs.js +75 -0
  100. package/dist-sdk/src/entities/automation/task-output-labels.d.ts +12 -1
  101. package/dist-sdk/src/entities/automation/task-output-labels.js +32 -1
  102. package/dist-sdk/src/entities/automation/tasks.d.ts +76 -18
  103. package/dist-sdk/src/entities/automation/tasks.js +52 -15
  104. package/dist-sdk/src/entities/automation/to-tf.d.ts +3 -0
  105. package/dist-sdk/src/entities/automation/to-tf.js +585 -97
  106. package/dist-sdk/src/entities/automation/triggers.d.ts +48 -23
  107. package/dist-sdk/src/entities/automation/triggers.js +27 -12
  108. package/dist-sdk/src/entities/automation/unsafe-script-output.d.ts +50 -0
  109. package/dist-sdk/src/entities/automation/unsafe-script-output.js +92 -0
  110. package/dist-sdk/src/entities/chart/build.d.ts +18 -2
  111. package/dist-sdk/src/entities/chart/from-tf.d.ts +2 -2
  112. package/dist-sdk/src/entities/chart/from-tf.js +28 -1
  113. package/dist-sdk/src/entities/chart/index.d.ts +1 -1
  114. package/dist-sdk/src/entities/chart/printer.js +5 -2
  115. package/dist-sdk/src/entities/chart/to-tf.js +38 -3
  116. package/dist-sdk/src/entities/dynamic-layout/build.d.ts +3 -0
  117. package/dist-sdk/src/entities/dynamic-layout/condition-keys.d.ts +48 -0
  118. package/dist-sdk/src/entities/dynamic-layout/condition-keys.js +261 -0
  119. package/dist-sdk/src/entities/dynamic-layout/from-tf.js +45 -6
  120. package/dist-sdk/src/entities/dynamic-layout/module.js +2 -1
  121. package/dist-sdk/src/entities/dynamic-layout/to-tf.js +46 -12
  122. package/dist-sdk/src/entities/element/audit-field-guard.d.ts +9 -0
  123. package/dist-sdk/src/entities/element/audit-field-guard.js +88 -0
  124. package/dist-sdk/src/entities/element/build.js +2 -1
  125. package/dist-sdk/src/entities/element/from-tf.js +15 -2
  126. package/dist-sdk/src/entities/element/module.js +3 -0
  127. package/dist-sdk/src/entities/element/system-fields.d.ts +13 -0
  128. package/dist-sdk/src/entities/element/system-fields.js +23 -0
  129. package/dist-sdk/src/entities/element/to-tf.js +2 -0
  130. package/dist-sdk/src/entities/field/build.d.ts +9 -0
  131. package/dist-sdk/src/entities/field/from-tf.d.ts +29 -1
  132. package/dist-sdk/src/entities/field/from-tf.js +99 -6
  133. package/dist-sdk/src/entities/field/module.js +12 -2
  134. package/dist-sdk/src/entities/field/to-tf.d.ts +13 -3
  135. package/dist-sdk/src/entities/field/to-tf.js +90 -46
  136. package/dist-sdk/src/entities/org/category.js +1 -0
  137. package/dist-sdk/src/entities/org/index.d.ts +1 -0
  138. package/dist-sdk/src/entities/org/index.js +1 -0
  139. package/dist-sdk/src/entities/org/role.js +5 -0
  140. package/dist-sdk/src/entities/org/voice-auth.d.ts +5 -0
  141. package/dist-sdk/src/entities/org/voice-auth.js +33 -0
  142. package/dist-sdk/src/entities/organization/build.d.ts +3 -0
  143. package/dist-sdk/src/entities/organization/build.js +2 -0
  144. package/dist-sdk/src/entities/organization/index.d.ts +1 -0
  145. package/dist-sdk/src/entities/organization/index.js +1 -0
  146. package/dist-sdk/src/entities/organization/to-tf.d.ts +2 -0
  147. package/dist-sdk/src/entities/organization/to-tf.js +59 -1
  148. package/dist-sdk/src/entities/organization/voice-auth.d.ts +60 -0
  149. package/dist-sdk/src/entities/organization/voice-auth.js +60 -0
  150. package/dist-sdk/src/entities/phone-service/build.d.ts +9 -1
  151. package/dist-sdk/src/entities/phone-service/build.js +1 -0
  152. package/dist-sdk/src/entities/phone-service/deserializer/print-phone-service.js +3 -0
  153. package/dist-sdk/src/entities/phone-service/from-tf.d.ts +1 -0
  154. package/dist-sdk/src/entities/phone-service/from-tf.js +8 -1
  155. package/dist-sdk/src/entities/phone-service/to-tf.js +16 -0
  156. package/dist-sdk/src/entities/record-create-form/from-tf.js +2 -2
  157. package/dist-sdk/src/entities/relationship/from-tf.js +7 -2
  158. package/dist-sdk/src/entities/relationship/module.js +2 -2
  159. package/dist-sdk/src/entities/relationship/pair-check.d.ts +6 -2
  160. package/dist-sdk/src/entities/relationship/pair-check.js +105 -18
  161. package/dist-sdk/src/entities/relationship/to-tf.js +5 -2
  162. package/dist-sdk/src/entities/role/permission-levels.d.ts +7 -0
  163. package/dist-sdk/src/entities/role/permission-levels.js +78 -0
  164. package/dist-sdk/src/entities/role/to-tf.js +32 -2
  165. package/dist-sdk/src/entities/service-account/module.d.ts +2 -1
  166. package/dist-sdk/src/entities/service-account/module.js +9 -1
  167. package/dist-sdk/src/entities/service-account/resource-type.d.ts +2 -0
  168. package/dist-sdk/src/entities/service-account/resource-type.js +2 -0
  169. package/dist-sdk/src/entities/service-account/role-fidelity.d.ts +5 -5
  170. package/dist-sdk/src/entities/service-account/role-fidelity.js +21 -13
  171. package/dist-sdk/src/entities/service-account/role-membership-check.d.ts +20 -0
  172. package/dist-sdk/src/entities/service-account/role-membership-check.js +80 -0
  173. package/dist-sdk/src/entities/shared/aspect-target-from-tf.d.ts +15 -0
  174. package/dist-sdk/src/entities/shared/aspect-target-from-tf.js +36 -0
  175. package/dist-sdk/src/entities/shared/filters/ast.d.ts +4 -0
  176. package/dist-sdk/src/entities/shared/filters/index.d.ts +85 -14
  177. package/dist-sdk/src/entities/shared/filters/index.js +18 -6
  178. package/dist-sdk/src/entities/shared/filters/option-lookups.d.ts +57 -0
  179. package/dist-sdk/src/entities/shared/filters/option-lookups.js +108 -0
  180. package/dist-sdk/src/entities/shared/filters/print.js +9 -5
  181. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +12 -7
  182. package/dist-sdk/src/entities/shared/filters/tf-codec.js +9 -5
  183. package/dist-sdk/src/entities/shared/raw-option-id.d.ts +30 -0
  184. package/dist-sdk/src/entities/shared/raw-option-id.js +41 -0
  185. package/dist-sdk/src/entities/shared/tool-field-ref.js +6 -2
  186. package/dist-sdk/src/entities/shared/types/field-types.d.ts +6 -3
  187. package/dist-sdk/src/entities/shared/types/field-types.js +3 -1
  188. package/dist-sdk/src/entities/skill/input-coverage.js +5 -2
  189. package/dist-sdk/src/entities/skill/module.js +2 -0
  190. package/dist-sdk/src/entities/sla/build.d.ts +96 -0
  191. package/dist-sdk/src/entities/sla/build.js +124 -0
  192. package/dist-sdk/src/entities/sla/from-tf.d.ts +40 -0
  193. package/dist-sdk/src/entities/sla/from-tf.js +164 -0
  194. package/dist-sdk/src/entities/sla/index.d.ts +1 -0
  195. package/dist-sdk/src/entities/sla/index.js +1 -0
  196. package/dist-sdk/src/entities/sla/module.d.ts +4 -0
  197. package/dist-sdk/src/entities/sla/module.js +73 -0
  198. package/dist-sdk/src/entities/sla/printer.d.ts +2 -0
  199. package/dist-sdk/src/entities/sla/printer.js +84 -0
  200. package/dist-sdk/src/entities/sla/to-tf.d.ts +12 -0
  201. package/dist-sdk/src/entities/sla/to-tf.js +81 -0
  202. package/dist-sdk/src/entities/table/build.d.ts +7 -2
  203. package/dist-sdk/src/entities/table/build.js +22 -1
  204. package/dist-sdk/src/entities/table/deserializer/normalize.d.ts +4 -1
  205. package/dist-sdk/src/entities/table/from-tf.js +89 -14
  206. package/dist-sdk/src/entities/table/index.d.ts +1 -1
  207. package/dist-sdk/src/entities/table/to-tf.js +41 -2
  208. package/dist-sdk/src/entities/task/from-tf.js +2 -1
  209. package/dist-sdk/src/entities/task/to-tf.js +1 -0
  210. package/dist-sdk/src/entities/view/from-tf.d.ts +8 -4
  211. package/dist-sdk/src/entities/view/from-tf.js +10 -9
  212. package/dist-sdk/src/entities/view/module.js +5 -0
  213. package/dist-sdk/src/entities/widget/from-tf.js +15 -4
  214. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +51 -4
  215. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
  216. package/dist-sdk/src/graph/index.d.ts +20 -2
  217. package/dist-sdk/src/graph/index.js +19 -0
  218. package/dist-sdk/src/graph/modules.js +11 -1
  219. package/dist-sdk/src/graph/resource-types.d.ts +47 -0
  220. package/dist-sdk/src/graph/resource-types.js +62 -0
  221. package/dist-sdk/src/graph/types.d.ts +116 -6
  222. package/package.json +6 -3
@@ -7,12 +7,16 @@ import { appResourceLabelPrefix, appScopedResourceLabel, expr, isTfExpr, isUuid,
7
7
  import { workspaceAspectKey } from "../../engine/build/context.js";
8
8
  import { SEARCH_TABLE_RESOURCE_TYPES } from "../search-table/types.js";
9
9
  import { fieldRefToTfValue } from "../field/to-tf.js";
10
+ import { scriptLintFindings } from "./script-lint.js";
11
+ import { setRefsRead } from "./refs-read.js";
12
+ import { MANAGED_FIELD_ORDER_RESOURCE_TYPE } from "../field/types.js";
10
13
  import { SERVICE_ACCOUNT_RESOURCE_TYPE } from "../service-account/module.js";
11
14
  import { serviceAccountRefToTf } from "../service-account/to-tf.js";
12
15
  import { workspaceServiceAccountAppResolver } from "../service-account/workspace-owner.js";
13
16
  import { foreignFieldDataLabel, resolveForeignRef } from "../shared/foreign-ref.js";
14
17
  import { filterToTf as serializeFilterToTf } from "../shared/filters/tf-codec.js";
15
- import { referenceValueTypeForField } from "../shared/filters/index.js";
18
+ import { isTextOptionValue, referenceValueTypeForField } from "../shared/filters/index.js";
19
+ import { plainOptionStringWarning, rawOptionIdWarning } from "../shared/raw-option-id.js";
16
20
  import { aiCompletionRefsIndex, API_TASK_REF_AUTHORING_NAMES, API_TASK_REF_WIRE_NAMES, executeScriptRefsIndex, OUTPUT_KEY_CANONICAL, OUTPUT_KEY_WIRE_NAME } from "./output-key-wire-name.js";
17
21
  import { outputFieldTypesFromScriptSchema, scriptOutputReferenceIsDeclared } from "./output-field-types.js";
18
22
  import { RESOURCE_TYPE_TO_EXECUTOR, TASK_OUTPUT_CONTRACTS } from "./generated/task-output-contracts.js";
@@ -23,11 +27,12 @@ import { UNRESOLVED_FIELD_MARKER } from "../shared/ref.js";
23
27
  import { ELEMENT_SYSTEM_FIELD_KEYS } from "../element/system-fields.js";
24
28
  import { TABLE_RESOURCE_TYPE } from "../table/module.js";
25
29
  import { AUTOMATION_RESOURCE_TYPE, WORKFLOW_PUBLISH_RESOURCE_TYPE, automationResourceLabel } from "./types.js";
26
- import { AI_SEARCH_TABLE_OUTPUT_NAMES, TASK_OUTPUT_REFERENCE_NAMES, TRIGGER_WHOLE_RECORD_MARKER, USER_SEARCH_REF_WIRE_NAMES, triggerAttachmentPayloadRef, triggerWholeRecordRefJson, } from "./task-output-labels.js";
30
+ import { AI_SEARCH_TABLE_OUTPUT_NAMES, RECORD_ID_REFERENCE_FIELD, TASK_OUTPUT_REFERENCE_NAMES, TRIGGER_WHOLE_RECORD_MARKER, USER_SEARCH_REF_WIRE_NAMES, triggerAttachmentPayloadRef, triggerWholeRecordRefJson, } from "./task-output-labels.js";
27
31
  import { onDemandTriggerRefKey } from "./value-ref-tf.js";
28
32
  import { normalizeOnDemandParamKey } from "../../../pull/util.js";
29
33
  import { PROVIDER_FIXED_SYSTEM_FIELD_KEYS, recordFieldWireRefName } from "./system-ref-name.js";
30
34
  import { taskTfLabel } from "./task-label.js";
35
+ import { slackMessageTriggerReferenceName, slackMessageTriggerRefName } from "./slack-message-refs.js";
31
36
  import { automationRunTargetResourceAttr, automationTargetOwner, bareStaticRunTarget, onDemandRecordParamNames, recordInputMappingProblem } from "./run-target.js";
32
37
  import { FIELD_TYPE_MAP, isOnDemandRecordType } from "../shared/types/field-types.js";
33
38
  /** The context for reading records of `appRefName` (a `kind`), retargeted from the owner. */
@@ -47,10 +52,14 @@ const ON_DEMAND_TF_PARAM_TYPES = new Map([
47
52
  function recordOwnerContext(owner, appRefName, kind, fieldNames) {
48
53
  if (appRefName === owner.appRefName && (kind === undefined || kind === owner.parentScope))
49
54
  return owner;
55
+ // Retarget fieldAddresses with fieldNames so wireRefName's custom-shadow
56
+ // check (#1871) reads the record app's authored keys, not the automation
57
+ // owner's (taskWireRefName / recordParamFieldWireName / forEach item refs).
50
58
  return {
51
59
  ...owner,
52
60
  appRefName,
53
61
  fieldNames: fieldNames ?? new Map(),
62
+ fieldAddresses: fieldNamesForAppRefName(owner.fieldAddressesByAppRefName, appRefName) ?? new Map(),
54
63
  recordLacksAuditFields: kind === "element" && owner.elementsWithoutAuditFields?.has(appRefName) === true,
55
64
  };
56
65
  }
@@ -228,7 +237,7 @@ const CONFIG_ATTRS = {
228
237
  fromUsername: "from_username",
229
238
  fromPersonal: "from_personal",
230
239
  externalEmails: "external_emails",
231
- emailAttachments: "attachments",
240
+ emailAttachments: "email_attachments",
232
241
  contentsReference: "message",
233
242
  agentId: "agent_id",
234
243
  agentPrompt: "prompt",
@@ -280,6 +289,132 @@ function onlyEntry(value, subject) {
280
289
  }
281
290
  return entries[0];
282
291
  }
292
+ /**
293
+ * Tasks whose refs carry every field of the record they search (edk#2280)
294
+ * or create (edk#2406), including system fields via object_fields /
295
+ * object_system_field_ids (edk#2680). update_field refs carry them too and
296
+ * aren't covered yet.
297
+ */
298
+ const OBJECT_FIELD_REFS_TASK_TYPES = new Set([
299
+ "elementum_record_search_task",
300
+ "elementum_find_related_records_task",
301
+ "elementum_create_record_task",
302
+ ]);
303
+ /**
304
+ * Triggers whose refs were confirmed to carry every custom field of the
305
+ * owner's record (a Preston High state with 18 field types). Build sets
306
+ * `object_field_ids` on these triggers only.
307
+ */
308
+ const OBJECT_FIELD_REFS_TRIGGER_TYPES = new Set([
309
+ "elementum_record_created_trigger",
310
+ "elementum_record_updated_trigger",
311
+ "elementum_comment_added_trigger",
312
+ "elementum_attachment_added_trigger",
313
+ "elementum_agent_conversation_ended_trigger",
314
+ "elementum_on_demand_trigger",
315
+ ]);
316
+ /**
317
+ * A record-bearing task's or trigger's write-only `object_field_ids`
318
+ * (edk#2280). It is the field order of its app or element, so a field created
319
+ * in the same apply plans `refs` unknown instead of keeping refs read before
320
+ * the field existed. Only an owner whose own fields this build writes (and so
321
+ * whose `elementum_managed_field_order` it writes) gets one. ei's export sets it
322
+ * only for the exported app or element. A pull builds only that root, so the
323
+ * two agree there.
324
+ */
325
+ function objectFieldIdsAttr(objectId, fieldAddresses) {
326
+ if (fieldAddresses === undefined || fieldAddresses.size === 0)
327
+ return {};
328
+ if (objectId === undefined || !isTfExpr(objectId) || objectId.$expr !== "resource-attr" || objectId.path.length !== 1 || objectId.path[0] !== "id")
329
+ return {};
330
+ const scope = objectId.type === "elementum_app" ? "app" : objectId.type === "elementum_element" ? "element" : undefined;
331
+ if (scope === undefined)
332
+ return {};
333
+ // The addresses must be this owner's own fields, since an app and an element can share a refName.
334
+ const fieldLabelPrefix = scopedResourceLabel(objectId.label, "", scope);
335
+ const ownFields = [...fieldAddresses.values()].some((address) => address.slice(address.indexOf(".") + 1).startsWith(fieldLabelPrefix));
336
+ if (!ownFields)
337
+ return {};
338
+ return {
339
+ object_field_ids: expr.resourceAttr(MANAGED_FIELD_ORDER_RESOURCE_TYPE, scopedResourceLabel(objectId.label, "field_order", scope), ["field_ids"]),
340
+ };
341
+ }
342
+ /**
343
+ * A record trigger's write-only `object_fields` (edk#2438): each of its
344
+ * owner's own fields as `{ id, name }`. refs are keyed by field name, so a
345
+ * field renamed or removed in the same apply plans `refs` unknown. It is set
346
+ * only next to `object_field_ids`, so on the same owners.
347
+ */
348
+ function objectFieldsAttr(objectFieldIds, fieldAddresses) {
349
+ if (objectFieldIds["object_field_ids"] === undefined || fieldAddresses === undefined)
350
+ return {};
351
+ return {
352
+ object_fields: [...fieldAddresses.values()].map((address) => ({ id: addressExpr(address), name: addressExpr(address, ["name"]) })),
353
+ };
354
+ }
355
+ /**
356
+ * The owner attributes a record trigger's `object_system_field_ids` lists, in
357
+ * order (edk#2438). `ei apps export` writes the same lists.
358
+ */
359
+ const APP_SYSTEM_FIELD_ID_ATTRIBUTES = [
360
+ "title_field_id", "id_field_id", "status_field_id", "stage_field_id",
361
+ "created_at_field_id", "created_by_field_id", "updated_at_field_id", "updated_by_field_id",
362
+ "closed_at_field_id", "closed_by_field_id",
363
+ ];
364
+ const ELEMENT_SYSTEM_FIELD_ID_ATTRIBUTES = [
365
+ "title_field_id", "id_field_id",
366
+ "created_at_field_id", "created_by_field_id", "updated_at_field_id", "updated_by_field_id",
367
+ ];
368
+ /**
369
+ * A record trigger's `object_field_ids`, `object_fields` and
370
+ * `object_system_field_ids` (edk#2280, edk#2438). The system field ids let the
371
+ * provider tell a removed field from a system field, since refs key both by
372
+ * name.
373
+ */
374
+ function triggerObjectFieldAttrs(owner) {
375
+ const ownerType = owner.parentScope === "element" ? "elementum_element" : "elementum_app";
376
+ return objectFieldRefsAttrs(expr.resourceAttr(ownerType, owner.appTfLabel, ["id"]), owner.fieldAddresses);
377
+ }
378
+ /**
379
+ * A record search / find-related / create-record task's write-only
380
+ * `object_field_ids`, `object_fields` and `object_system_field_ids` (edk#2680).
381
+ * Same shape as a record trigger's, for the task's target app or element so
382
+ * the provider can plan `refs` unknown when a system field the task reads is
383
+ * removed while custom fields change.
384
+ */
385
+ function taskObjectFieldAttrs(objectId, fieldAddresses) {
386
+ return objectFieldRefsAttrs(objectId, fieldAddresses);
387
+ }
388
+ /** Shared object_field_ids / object_fields / object_system_field_ids for a target app or element. */
389
+ function objectFieldRefsAttrs(objectId, fieldAddresses) {
390
+ const ids = objectFieldIdsAttr(objectId, fieldAddresses);
391
+ const fields = objectFieldsAttr(ids, fieldAddresses);
392
+ if (fields["object_fields"] === undefined)
393
+ return ids;
394
+ if (objectId === undefined || !isTfExpr(objectId) || objectId.$expr !== "resource-attr")
395
+ return ids;
396
+ const ownerType = objectId.type;
397
+ if (ownerType !== "elementum_app" && ownerType !== "elementum_element")
398
+ return ids;
399
+ const systemAttributes = ownerType === "elementum_element" ? ELEMENT_SYSTEM_FIELD_ID_ATTRIBUTES : APP_SYSTEM_FIELD_ID_ATTRIBUTES;
400
+ return {
401
+ ...ids,
402
+ ...fields,
403
+ object_system_field_ids: systemAttributes.map((attribute) => expr.resourceAttr(ownerType, objectId.label, [attribute])),
404
+ };
405
+ }
406
+ /** The field addresses this build writes for a task's `aspectId` target. */
407
+ function taskTargetFieldAddresses(aspectId, owner) {
408
+ const target = token(aspectId);
409
+ if (target === undefined || typeof target.refName !== "string")
410
+ return undefined;
411
+ const kind = target.__kind === "element" ? "element" : target.__kind === "app" ? "app" : undefined;
412
+ if (kind === undefined)
413
+ return undefined;
414
+ if (target.refName === owner.appRefName && kind === owner.parentScope)
415
+ return owner.fieldAddresses;
416
+ return fieldNamesForAppRefName(owner.fieldAddressesByAppRefName, target.refName);
417
+ }
283
418
  function token(value) {
284
419
  if (!isObject(value) || typeof value.__kind !== "string")
285
420
  return undefined;
@@ -458,7 +593,7 @@ function crossAppFieldToTf(value, ctx, dataBlocks) {
458
593
  // table-owned search table has to be distinguishable from an element-owned
459
594
  // one.
460
595
  if (sibling !== undefined && sibling.kind !== "table" && sibling.kind !== "task") {
461
- const fieldValue = fieldRefToTfValue(value.fieldType ?? "", value.refName, sibling.tfLabel, sibling.kind, sibling.kind === "element" ? fieldNamesForAppRefName(ctx.fieldAddressesByAppRefName, value.parent) : undefined);
596
+ const fieldValue = fieldRefToTfValue(value.fieldType ?? "", value.refName, sibling.tfLabel, sibling.kind, fieldNamesForAppRefName(ctx.fieldAddressesByAppRefName, value.parent));
462
597
  if (fieldValue === undefined) {
463
598
  throw new EntityTfError(`field ref "${value.refName}" on sibling ${sibling.kind} "${value.parent}" has no terraform field resource mapping (fieldType ${JSON.stringify(value.fieldType ?? "")})`);
464
599
  }
@@ -912,16 +1047,19 @@ function tokenToTf(value, ctx, dataBlocks) {
912
1047
  // label (see ApprovalChainRef); preferring it rewrote live pulls to UUIDs.
913
1048
  const refName = typeof value.refName === "string" ? value.refName.trim() : "";
914
1049
  if (refName !== "") {
915
- const address = `elementum_approval_process.${scopedLabel(ctx.appTfLabel, tsLabelToTfLabel(refName))}`;
1050
+ // The approval process belongs to this automation's owner, an app or
1051
+ // an element (edk#373), so its label carries the owner's scope.
1052
+ const approvalLabel = scopedResourceLabel(ctx.appTfLabel, tsLabelToTfLabel(refName), ctx.parentScope);
1053
+ const address = `elementum_approval_process.${approvalLabel}`;
916
1054
  // Never emit a reference to an approval process this build doesn't
917
- // declare (edk#1416). The build records the app's discovered
1055
+ // declare (edk#1416). The build records the owner's discovered
918
1056
  // approval-chain files; direct callers without that information keep
919
1057
  // the managed reference.
920
1058
  const declared = ctx.workspaceAspects
921
- ?.get(workspaceAspectKey("app", ctx.appRefName))
1059
+ ?.get(workspaceAspectKey(ctx.parentScope, ctx.appRefName))
922
1060
  ?.managedChildRefNames?.get("approval-chain");
923
1061
  if (declared === undefined || declared.has(refName)) {
924
- return expr.resourceAttr("elementum_approval_process", scopedLabel(ctx.appTfLabel, tsLabelToTfLabel(refName)), ["id"]);
1062
+ return expr.resourceAttr("elementum_approval_process", approvalLabel, ["id"]);
925
1063
  }
926
1064
  if (value.unresolvedId !== undefined) {
927
1065
  ctx.diagnostics.push(`automation ${ctx.automationTfLabel}: approval chain "${refName}" is not declared in this build (${address} would be undeclared); ` +
@@ -929,7 +1067,7 @@ function tokenToTf(value, ctx, dataBlocks) {
929
1067
  return value.unresolvedId;
930
1068
  }
931
1069
  throw new EntityTfError(`automation ${ctx.automationTfLabel}: approval chain "${refName}" is not declared in this build (${address} is undeclared) ` +
932
- `and the reference has no unresolvedId — add approval-chains/${refName}.ts to app "${ctx.appRefName}" or reference an existing approval process`);
1070
+ `and the reference has no unresolvedId — add approval-chains/${refName}.ts to ${ctx.parentScope} "${ctx.appRefName}" or reference an existing approval process`);
933
1071
  }
934
1072
  if (value.unresolvedId !== undefined)
935
1073
  return value.unresolvedId;
@@ -1225,12 +1363,37 @@ function calculationTaskRefName(targetType, name, taskRefKey, refs) {
1225
1363
  suffix.length > 0 ? `.${suffix}` : "",
1226
1364
  ];
1227
1365
  }
1228
- const refName = taskOutputReferenceName(targetType, name, refs.tasks.get(taskRefKey)) ?? name;
1366
+ // A single-output AI task's `.output` reaches here as its refs label
1367
+ // (`Response`); the calc engine resolves only the canonical name (`response`, #2405).
1368
+ const refName = taskOutputReferenceName(targetType, name, refs.tasks.get(taskRefKey)) ??
1369
+ canonicalSingleOutputName(targetType, name) ?? name;
1229
1370
  if (refName.includes('"')) {
1230
1371
  throw new EntityTfError(`calculation task output name "${refName}" contains a double quote`);
1231
1372
  }
1232
1373
  return [refName];
1233
1374
  }
1375
+ /**
1376
+ * Output → refs-map key, the inverse of TASK_OUTPUT_REFERENCE_NAMES, for the
1377
+ * tasks whose refs are keyed by display label: bulkUpdateFields (edk#2281) and
1378
+ * tableRecordsSearch (edk#2407, whose count is authored as `totalCount`).
1379
+ * Envelopes and calculations keep the output's own name.
1380
+ */
1381
+ function inverseReferenceNames(resourceType) {
1382
+ return Object.fromEntries(Object.entries(TASK_OUTPUT_REFERENCE_NAMES[resourceType] ?? {}).map(([key, name]) => [name, key]));
1383
+ }
1384
+ const BULK_UPDATE_FIELDS_REFS_INDEX = inverseReferenceNames(TASK_RESOURCES.bulkUpdateFields);
1385
+ const TABLE_RECORDS_SEARCH_REFS_INDEX = (() => {
1386
+ const index = inverseReferenceNames(TASK_RESOURCES.tableRecordsSearch);
1387
+ return { ...index, totalCount: index["count"] };
1388
+ })();
1389
+ /** refs-map key for a task output keyed by a display label (AI completion tasks, bulkUpdateFields, tableRecordsSearch), or undefined. */
1390
+ function taskOutputRefsIndex(resourceType, name) {
1391
+ if (resourceType === TASK_RESOURCES.bulkUpdateFields)
1392
+ return BULK_UPDATE_FIELDS_REFS_INDEX[name];
1393
+ if (resourceType === TASK_RESOURCES.tableRecordsSearch)
1394
+ return TABLE_RECORDS_SEARCH_REFS_INDEX[name];
1395
+ return aiCompletionRefsIndex(resourceType, name);
1396
+ }
1234
1397
  /** A refs key's WorkflowTaskReference name. An apiRequest maps only when it's JSON; FILE and CUSTOM are unconfirmed live (edk#2058). */
1235
1398
  function taskOutputReferenceName(type, wireName, task) {
1236
1399
  if (type === TASK_RESOURCES.api && task?.jsonApiResponse !== true)
@@ -1359,9 +1522,9 @@ function foreignFoundRecordFieldId(fieldKey, taskRefKey, refs) {
1359
1522
  return expr.dataAttr("elementum_field", registerForeignFieldLookup(fieldToken, refs.owner, refs.dataBlocks), ["id"]);
1360
1523
  }
1361
1524
  function calculationTriggerMustache(name, refs) {
1362
- const onDemandName = onDemandTriggerRefName(name, refs);
1363
- if (onDemandName !== undefined)
1364
- return [`{{trigger name="${onDemandName}"}}`];
1525
+ const triggerName = onDemandTriggerRefName(name, refs) ?? slackTriggerReferenceName(name, refs);
1526
+ if (triggerName !== undefined)
1527
+ return [`{{trigger name="${triggerName}"}}`];
1365
1528
  const parts = name.split(".");
1366
1529
  if (parts[0] !== "record" || parts.length < 2) {
1367
1530
  return [`{{trigger name="${name}"}}`];
@@ -1432,14 +1595,9 @@ const TS_TRIGGER_REF_TO_WIRE = {
1432
1595
  // pseudo-fields only, keyed by the DIRECT ts accessor name, not a dotted
1433
1596
  // record path. Record-path refs are handled below from app fields and
1434
1597
  // suffix mappings.
1435
- slackThreadId: "Slack Thread ID",
1436
- slackChannelId: "Slack Channel ID",
1437
- messageAuthorEmail: "Message Author Email",
1438
- messageAuthorId: "Message Author ID",
1439
- messageAuthorName: "Message Author Name",
1440
- messageContent: "Message Content",
1441
- messageId: "Message ID",
1442
- messageMetadata: "Message Metadata",
1598
+ // Slack message trigger accessors resolve only on that trigger, through
1599
+ // SLACK_MESSAGE_TRIGGER_REF_TO_WIRE (#2581): names like `content` and
1600
+ // `meta` would otherwise rewrite same-named task outputs.
1443
1601
  sender_email: "Sender's Email Address",
1444
1602
  sender_name: "Sender's Name",
1445
1603
  body: "Body (Plain Text)",
@@ -1501,11 +1659,13 @@ function wireRefName(name, ctx) {
1501
1659
  // System fields are keyed in ctx.fieldNames under their canonical
1502
1660
  // SystemFieldKey (title/id/status/…) with the app's display name —
1503
1661
  // including systemFields renames ("App Name"). Provider-fixed audit
1504
- // keys (stage/createdBy/…) have no rename attribute and always use
1505
- // DEPLOY_DEFAULT. Renamable system fields prefer fieldNames; only
1506
- // when the map lacks the key do we fall back to DEPLOY_DEFAULT (the
1507
- // silent Title fallback that breaks cross-app findRelatedRecords when
1508
- // the related app renamed title and the map missed the canonical key).
1662
+ // keys (stage/createdBy/…) have no rename attribute, so the real
1663
+ // system field always uses DEPLOY_DEFAULT. Custom fields may not share
1664
+ // those keys (#1871 reject + pull re-key); a leftover fieldAddresses hit
1665
+ // is still treated as custom. Renamable system fields prefer fieldNames;
1666
+ // only when the map lacks the key do we fall back to DEPLOY_DEFAULT (the
1667
+ // silent Title fallback that breaks cross-app findRelatedRecords when the
1668
+ // related app renamed title and the map missed the canonical key).
1509
1669
  const systemFieldKey = SYSTEM_FIELD_KEY_SET.has(fieldKey)
1510
1670
  ? fieldKey
1511
1671
  : undefined;
@@ -1517,6 +1677,10 @@ function wireRefName(name, ctx) {
1517
1677
  "The platform adds them to apps but only to some elements, and EDK cannot create them. " +
1518
1678
  "Remove the reference, or set systemFields: { audit: true } on an element the platform did give them to.");
1519
1679
  }
1680
+ // Custom fields may not use reserved system keys (#1871); pull re-keys
1681
+ // them to `<key>Custom`, so a provider-fixed system key always names the
1682
+ // platform field. Leftover source that still keys a custom field as
1683
+ // `closedAt` is rejected at build.
1520
1684
  const fieldName = systemFieldKey !== undefined && PROVIDER_FIXED_SYSTEM_FIELD_KEYS.has(systemFieldKey)
1521
1685
  ? DEPLOY_DEFAULT_SYSTEM_FIELD_NAMES[systemFieldKey]
1522
1686
  : ctx.fieldNames.get(fieldKey) ??
@@ -1570,15 +1734,6 @@ const RECORD_COLLECTION_TASK_WIRE_TYPES = new Set([
1570
1734
  const TS_FOR_EACH_GENERIC_SEGMENT_TO_WIRE = {
1571
1735
  iteration: "Iteration",
1572
1736
  };
1573
- function forEachCompactFilterName(name, isRecordCollection) {
1574
- if (name === "recordId")
1575
- return "item";
1576
- // A plain-list loop's whole item is ForEachReference name "" on the
1577
- // platform; provider Read renders it as `for_each.<id>.`.
1578
- if (name === "item" && !isRecordCollection)
1579
- return "";
1580
- return name;
1581
- }
1582
1737
  function forEachWireRefName(name, ctx, isRecordCollection) {
1583
1738
  // A recordSearch collection's whole item and branded record identity both
1584
1739
  // point at the loop's ASPECT_RECORD_ID reference. Live provider state
@@ -1749,9 +1904,10 @@ function taskOutputWireRefKey(targetType, name, taskRefKey, refs) {
1749
1904
  if (scriptIndex !== undefined)
1750
1905
  return scriptIndex;
1751
1906
  }
1752
- const aiIndex = aiCompletionRefsIndex(targetType, name);
1753
- if (aiIndex !== undefined)
1754
- return aiIndex;
1907
+ // AI completion, bulkUpdateFields (edk#2281) and tableRecordsSearch (edk#2407) outputs are keyed by display label.
1908
+ const labelIndex = taskOutputRefsIndex(targetType, name);
1909
+ if (labelIndex !== undefined)
1910
+ return labelIndex;
1755
1911
  return taskWireRefName(name, taskRefKey, refs);
1756
1912
  }
1757
1913
  /** The platform's own on-demand "Triggered By" refs (live refs-map keys). */
@@ -1776,10 +1932,21 @@ function onDemandTriggerRefName(name, refs) {
1776
1932
  }
1777
1933
  return ON_DEMAND_TRIGGERED_BY_REFS[name];
1778
1934
  }
1935
+ /** A Slack message trigger's refs-map key; undefined on any other trigger. */
1936
+ function slackTriggerRefName(name, refs) {
1937
+ return refs.trigger.type === TRIGGER_RESOURCES.slackMessage ? slackMessageTriggerRefName(name) : undefined;
1938
+ }
1939
+ /** A Slack message trigger's `triggerReference.name`; undefined on any other trigger. */
1940
+ function slackTriggerReferenceName(name, refs) {
1941
+ return refs.trigger.type === TRIGGER_RESOURCES.slackMessage ? slackMessageTriggerReferenceName(name) : undefined;
1942
+ }
1779
1943
  function triggerWireRefName(name, refs) {
1780
1944
  const onDemandName = onDemandTriggerRefName(name, refs);
1781
1945
  if (onDemandName !== undefined)
1782
1946
  return onDemandName;
1947
+ const slackName = slackTriggerRefName(name, refs);
1948
+ if (slackName !== undefined)
1949
+ return slackName;
1783
1950
  const scalarParams = refs.triggerParamNames.filter((param) => !refs.recordParamNames.includes(param));
1784
1951
  const declared = onDemandTriggerRefKey(name, scalarParams);
1785
1952
  if (declared !== name || scalarParams.includes(name))
@@ -2048,7 +2215,9 @@ function workflowPublishOutputEnvelope(value, refs) {
2048
2215
  multiple: typed.multiple,
2049
2216
  taskReference: null,
2050
2217
  triggerReference: {
2051
- name: onDemandTriggerRefName(value.triggerReference.name, refs) ?? wireRefName(value.triggerReference.name, refs.owner),
2218
+ name: onDemandTriggerRefName(value.triggerReference.name, refs) ??
2219
+ slackTriggerReferenceName(value.triggerReference.name, refs) ??
2220
+ wireRefName(value.triggerReference.name, refs.owner),
2052
2221
  },
2053
2222
  variableReference: null,
2054
2223
  };
@@ -2504,6 +2673,10 @@ function valueToTf(value, refs) {
2504
2673
  function snake(name) {
2505
2674
  return name.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/-/g, "_").toLowerCase();
2506
2675
  }
2676
+ /** The provider's `default_value` is a string: a Number, Decimal or Checkbox default is quoted, as `ei` export writes it. */
2677
+ function onDemandDefaultToTf(value) {
2678
+ return typeof value === "number" || typeof value === "boolean" ? String(value) : value;
2679
+ }
2507
2680
  function unwrapDefault(value) {
2508
2681
  if (!isObject(value))
2509
2682
  return value;
@@ -2554,7 +2727,7 @@ function onDemandRecordFieldFilterReference(name, refs, operator) {
2554
2727
  `(ctx.trigger.${paramName}.${fieldKey}.id) or ".label" (ctx.trigger.${paramName}.${fieldKey}.label) explicitly.`);
2555
2728
  }
2556
2729
  const wireSuffix = suffix === "recordId"
2557
- ? "10000001-2000-4000-a000-800000000000"
2730
+ ? RECORD_ID_REFERENCE_FIELD
2558
2731
  : suffix.length === 0 && isOwner && isOptionBearingPicklist(refs.owner.fieldMetadata.get(fieldKey)) ? "id"
2559
2732
  : suffix.length === 0 && isOwner && operator === "is_null" && isIdentityField(refs.owner.fieldMetadata.get(fieldKey)) ? "id" : suffix;
2560
2733
  const tail = wireSuffix.length > 0 ? [`.${wireSuffix}`] : [];
@@ -2579,7 +2752,8 @@ function onDemandRecordFieldFilterReference(name, refs, operator) {
2579
2752
  /**
2580
2753
  * The canonical (`service_tasks`) name of a single-output AI task's output,
2581
2754
  * when `wireName` is that output's refs display label. The filter short form
2582
- * `task.<id>.<name>` uses it (`response`), not the label (`Response`).
2755
+ * `task.<id>.<name>` and a calculation's `{{task name="..."}}` use it
2756
+ * (`response`), not the label (`Response`, #2405).
2583
2757
  */
2584
2758
  function canonicalSingleOutputName(resourceType, wireName) {
2585
2759
  const taskKey = Object.keys(TASK_RESOURCES).find((key) => TASK_RESOURCES[key] === resourceType);
@@ -2587,6 +2761,27 @@ function canonicalSingleOutputName(resourceType, wireName) {
2587
2761
  return undefined;
2588
2762
  return OUTPUT_KEY_CANONICAL[taskKey];
2589
2763
  }
2764
+ /**
2765
+ * A Table Records Search's or AI Data Search's `.records` read as a filter
2766
+ * value, by authored name or refs key, keyed by resource type (edk#2402). The
2767
+ * filter value spells it by its output contract name, not the refs key
2768
+ * ("All matching table rows", "All Records") or Record Search's
2769
+ * `All found records`.
2770
+ */
2771
+ const SEARCH_RECORDS_FILTER_NAMES = {
2772
+ [TASK_RESOURCES.tableRecordsSearch]: { names: ["records", "All matching table rows"], contractName: "records" },
2773
+ [TASK_RESOURCES.aiSearchTable]: { names: ["records", AI_SEARCH_TABLE_OUTPUT_NAMES.records[0]], contractName: AI_SEARCH_TABLE_OUTPUT_NAMES.records[1] },
2774
+ };
2775
+ function searchRecordsContractName(resourceType, name, wireName) {
2776
+ const entry = SEARCH_RECORDS_FILTER_NAMES[resourceType];
2777
+ if (entry === undefined || !(entry.names.includes(name) || entry.names.includes(wireName)))
2778
+ return undefined;
2779
+ const executor = RESOURCE_TYPE_TO_EXECUTOR[resourceType];
2780
+ if (executor === undefined || TASK_OUTPUT_CONTRACTS[executor]?.[entry.contractName] === undefined) {
2781
+ throw new EntityTfError(`${resourceType} has no "${entry.contractName}" output contract`);
2782
+ }
2783
+ return entry.contractName;
2784
+ }
2590
2785
  const TRIGGER_REFERENCE_NAME_PATTERN = /^[a-z][A-Za-z0-9]*(?:\.[a-z][A-Za-z0-9]*)*$/;
2591
2786
  function filterReferenceToTf(value, refs, role = "value", realType, operator) {
2592
2787
  // Raw pass-through for a filter left side the pull-time deserializer
@@ -2617,7 +2812,7 @@ function filterReferenceToTf(value, refs, role = "value", realType, operator) {
2617
2812
  const fieldKey = parts[1];
2618
2813
  const address = refs.owner.fieldAddresses.get(fieldKey);
2619
2814
  const suffix = parts.slice(2).join(".");
2620
- let wireSuffix = suffix === "recordId" ? "10000001-2000-4000-a000-800000000000" : suffix;
2815
+ let wireSuffix = suffix === "recordId" ? RECORD_ID_REFERENCE_FIELD : suffix;
2621
2816
  // An option-bearing picklist has no bare wire form. The platform editor
2622
2817
  // sends `.id` or `.label`, and a null-check emits `.id`.
2623
2818
  if (suffix.length === 0 && isOptionBearingPicklist(refs.owner.fieldMetadata.get(fieldKey))) {
@@ -2704,11 +2899,21 @@ function filterReferenceToTf(value, refs, role = "value", realType, operator) {
2704
2899
  }
2705
2900
  const triggerRefKey = triggerWireRefName(value.name, refs);
2706
2901
  if (refs.trigger.type === TRIGGER_RESOURCES.onDemand) {
2707
- // filter_refs holds only declared inputs, so the clicking user has no key there.
2902
+ // filter_refs holds only declared inputs, so the user who ran the
2903
+ // automation has no key there. The platform reads it through the
2904
+ // short form instead: the editor saves `trigger.triggeredBy.id`, ei
2905
+ // exports it verbatim, and mobius resolves a TRIGGER reference by
2906
+ // walking the on-demand payload, which carries that user under
2907
+ // `triggeredBy` (OnDemandTriggerProcessor). edk#2788.
2708
2908
  if (ON_DEMAND_TRIGGERED_BY_REFS[value.name] !== undefined) {
2709
- throw new EntityTfError(`filter on ctx.trigger.${value.name}: an on-demand filter can only reference declared inputs, ` +
2710
- `and the platform publishes no filter reference for the user who ran the automation. ` +
2711
- `Read ctx.trigger.triggeredBy in a task input instead.`);
2909
+ // The bare user is the id everywhere else ("Triggered By's Id"),
2910
+ // but its short form would make the runtime walk to the whole user
2911
+ // object, so a filter must name the field it compares.
2912
+ if (value.name === "triggeredBy") {
2913
+ throw new EntityTfError("filter on ctx.trigger.triggeredBy: compare a field of the user who ran the automation, " +
2914
+ "ctx.trigger.triggeredBy.id, .email or .name");
2915
+ }
2916
+ return `trigger.${value.name}`;
2712
2917
  }
2713
2918
  return expr.resourceAttr(refs.trigger.type, refs.trigger.label, ["filter_refs", { index: triggerRefKey }]);
2714
2919
  }
@@ -2729,9 +2934,25 @@ function filterReferenceToTf(value, refs, role = "value", realType, operator) {
2729
2934
  throw new EntityTfError(`unresolved task filter ref "${value.taskRefKey}"`);
2730
2935
  const isFileReaderTask = task.type === "elementum_ai_file_read_task" || task.type === "elementum_file_reader_task";
2731
2936
  const isAiAgentTask = task.type === "elementum_ai_agent_task";
2937
+ // A found record's field on the value side is spelled by field id, so
2938
+ // its refs label is never needed. That label has no form for a field
2939
+ // of the related record (`record.<field>.<related field id>`).
2940
+ const recordFieldName = role === "left"
2941
+ ? undefined
2942
+ : foundRecordFieldReferenceName(task.type, value.name, value.taskRefKey, refs);
2943
+ if (recordFieldName !== undefined) {
2944
+ return expr.template(["task.", expr.resourceAttr(task.type, task.label, ["id"]), ".", ...recordFieldName]);
2945
+ }
2946
+ // A Table Records Search switch reads its refs by display label
2947
+ // (edk#2407). Look the authored name up before taskWireRefName, whose
2948
+ // generic rewrite turns `record` into `Record`, as taskOutputWireRefKey
2949
+ // does. `records` keeps its current spelling.
2950
+ const tableSearchLabel = role === "left" && task.type === TASK_RESOURCES.tableRecordsSearch && value.name !== "records"
2951
+ ? taskOutputRefsIndex(task.type, value.name)
2952
+ : undefined;
2732
2953
  const wireName = isFileReaderTask || isAiAgentTask
2733
2954
  ? value.name
2734
- : taskWireRefName(value.name, value.taskRefKey, refs);
2955
+ : tableSearchLabel ?? taskWireRefName(value.name, value.taskRefKey, refs);
2735
2956
  // left_value (switch cases): provider Read stores the JSON envelope that
2736
2957
  // `.refs["…"]` evaluates to (#490). Emitting the short `task.<id>.…`
2737
2958
  // string matches record_search RHS state but perpetual-diffs left_value.
@@ -2823,10 +3044,14 @@ function filterReferenceToTf(value, refs, role = "value", realType, operator) {
2823
3044
  // flattened. A NUMBER comparison of a DECIMAL script output is the
2824
3045
  // next branch (#1618).
2825
3046
  const envelopeName = taskOutputReferenceName(task.type, wireName, task) ?? wireName;
2826
- const executor = RESOURCE_TYPE_TO_EXECUTOR[task.type];
2827
- const declared = task.outputFieldTypes?.get(wireName) ??
2828
- (executor === undefined ? undefined : TASK_OUTPUT_CONTRACTS[executor]?.[envelopeName]);
2829
- const compared = realType?.toUpperCase();
3047
+ const declared = declaredTaskOutputType(task, wireName, envelopeName);
3048
+ // This includes a Table Records Search row (TABLE_RECORD): the
3049
+ // platform stores only the condition's real_type, so a check of
3050
+ // `.record`, bare (built with real_type text) or `filter.text(…)`, is
3051
+ // read back and exported as the TEXT envelope named `record`
3052
+ // (edk#2407).
3053
+ const isTableSearchRow = task.type === TASK_RESOURCES.tableRecordsSearch && declared?.fieldType === "TABLE_RECORD" && declared.multiple !== true;
3054
+ const compared = realType?.toUpperCase() ?? (isTableSearchRow ? "TEXT" : undefined);
2830
3055
  if (compared !== undefined &&
2831
3056
  declared !== undefined &&
2832
3057
  declared.fieldType !== compared &&
@@ -2901,29 +3126,37 @@ function filterReferenceToTf(value, refs, role = "value", realType, operator) {
2901
3126
  }
2902
3127
  const refsIndex = task.type === TASK_RESOURCES.executeScript
2903
3128
  ? executeScriptRefsIndex(wireName) ?? wireName
2904
- : aiCompletionRefsIndex(task.type, wireName) ?? wireName;
3129
+ : taskOutputRefsIndex(task.type, wireName) ?? wireName;
2905
3130
  return expr.resourceAttr(task.type, task.label, ["refs", { index: refsIndex }]);
2906
3131
  }
2907
- const recordFieldName = foundRecordFieldReferenceName(task.type, value.name, value.taskRefKey, refs);
2908
3132
  // The short form addresses user-search outputs by path, and an AI task's
2909
3133
  // single output by its canonical name (`response`, edk#1509); only
2910
3134
  // `.refs` is keyed by their display labels. recordSearch's ASPECT_RECORD_ID
2911
3135
  // is keyed `First found record id` in refs, but filter RHS / ei export use
2912
3136
  // the canonical short name `recordId` (service_tasks) — emitting the
2913
- // display label here plans drift after every pull (edk#1524).
3137
+ // display label here plans drift after every pull (edk#1524). Its
3138
+ // `All found records` short name is `records`, and a Find Related
3139
+ // Records filter value uses that same short name. A Table Records
3140
+ // Search's or AI Data Search's `.records` uses its contract name.
3141
+ const searchRecords = searchRecordsContractName(task.type, value.name, wireName);
2914
3142
  const shortName = task.type === TASK_RESOURCES.userSearch
2915
3143
  ? USER_SEARCH_PATH_BY_WIRE_NAME.get(wireName) ?? wireName
2916
3144
  : task.type === TASK_RESOURCES.recordSearch &&
2917
3145
  (wireName === "First found record id" || value.name === "record.recordId" || value.name === "recordId")
2918
3146
  ? "recordId"
2919
- : task.type === TASK_RESOURCES.api
2920
- ? taskOutputReferenceName(task.type, wireName, task) ?? wireName
2921
- : canonicalSingleOutputName(task.type, wireName) ?? wireName;
3147
+ : (task.type === TASK_RESOURCES.recordSearch || task.type === TASK_RESOURCES.findRelatedRecords) &&
3148
+ (wireName === "All found records" || value.name === "records")
3149
+ ? "records"
3150
+ : searchRecords !== undefined
3151
+ ? searchRecords
3152
+ : task.type === TASK_RESOURCES.api
3153
+ ? taskOutputReferenceName(task.type, wireName, task) ?? wireName
3154
+ : canonicalSingleOutputName(task.type, wireName) ?? wireName;
2922
3155
  return expr.template([
2923
3156
  "task.",
2924
3157
  expr.resourceAttr(task.type, task.label, ["id"]),
2925
3158
  ".",
2926
- ...(recordFieldName ?? [shortName]),
3159
+ shortName,
2927
3160
  ]);
2928
3161
  }
2929
3162
  case "FOR_EACH": {
@@ -2932,10 +3165,43 @@ function filterReferenceToTf(value, refs, role = "value", realType, operator) {
2932
3165
  const task = refs.tasks.get(value.forEachTaskRefKey);
2933
3166
  if (task === undefined)
2934
3167
  throw new EntityTfError(`unresolved forEach filter ref "${value.forEachTaskRefKey}"`);
3168
+ if (!refs.recordItemForEachRefKeys.has(value.forEachTaskRefKey)) {
3169
+ // Plain-list payload keys are not catalog fields. Preserve their
3170
+ // compact spelling, including the platform's empty whole-item name.
3171
+ const name = value.name === "recordId" ? "item" : value.name === "item" ? "" : value.name;
3172
+ return expr.template(["for_each.", expr.resourceAttr(task.type, task.label, ["id"]), `.${name}`]);
3173
+ }
3174
+ // Filter export uses a compact field-ID path, not inner.refs (the
3175
+ // script-input spelling) or the TypeScript property name. Resolve
3176
+ // the collection's actual owner and preserve that export dialect.
3177
+ const source = refs.recordItemForEachSourceByRefKey.get(value.forEachTaskRefKey);
3178
+ const [fieldKey, ...suffix] = value.name.split(".");
3179
+ if (fieldKey === undefined || fieldKey === "")
3180
+ throw new EntityTfError("record loop filter reference has no field");
3181
+ const isIdentity = value.name === "item" || value.name === "recordId";
3182
+ const foreignFieldId = isIdentity ? undefined : foreignFoundRecordFieldId(fieldKey, source, refs);
3183
+ const scope = isIdentity || foreignFieldId !== undefined ? undefined : calculationFieldScope(source, refs);
3184
+ const fieldId = isIdentity ? RECORD_ID_REFERENCE_FIELD : foreignFieldId ?? calculationRecordFieldId(fieldKey, scope);
3185
+ const joinedSuffix = suffix.join(".");
3186
+ let wireSuffix = joinedSuffix === "recordId" ? RECORD_ID_REFERENCE_FIELD : joinedSuffix;
3187
+ // Same rule as a trigger-record filter: an option-bearing picklist has
3188
+ // no bare wire form (`.id` / `.label`; a null-check emits `.id`), and a
3189
+ // user/group null-check emits `.id`. Field metadata is known only for
3190
+ // the automation's own app/element, as for onDemand record inputs.
3191
+ const metadata = scope === refs.owner ? refs.owner.fieldMetadata.get(fieldKey) : undefined;
3192
+ if (joinedSuffix.length === 0 && isOptionBearingPicklist(metadata)) {
3193
+ if (operator !== "is_null") {
3194
+ throw new EntityTfError(`filter reference to picklist field "${fieldKey}" is ambiguous — write ".id" ` +
3195
+ `(ctx.item.${fieldKey}.id, compare by the option's id) or ".label" ` +
3196
+ `(ctx.item.${fieldKey}.label, compare by display text) explicitly.`);
3197
+ }
3198
+ wireSuffix = "id";
3199
+ }
3200
+ if (joinedSuffix.length === 0 && operator === "is_null" && isIdentityField(metadata))
3201
+ wireSuffix = "id";
2935
3202
  return expr.template([
2936
- "for_each.",
2937
- expr.resourceAttr(task.type, task.label, ["id"]),
2938
- `.${forEachCompactFilterName(value.name, refs.recordItemForEachRefKeys.has(value.forEachTaskRefKey))}`,
3203
+ "for_each.", expr.resourceAttr(task.type, task.label, ["id"]), ".", fieldId,
3204
+ ...(wireSuffix === "" ? [] : [`.${wireSuffix}`]),
2939
3205
  ]);
2940
3206
  }
2941
3207
  case "VALUE":
@@ -2962,6 +3228,10 @@ function filterReferenceToTf(value, refs, role = "value", realType, operator) {
2962
3228
  throw new EntityTfError(`unsupported filter reference type "${value.type}"`);
2963
3229
  }
2964
3230
  }
3231
+ /**
3232
+ * A UUID-wrapped filter value on a picklist: a label resolves to its option
3233
+ * id, and a raw id or a pulled stale label passes through as written.
3234
+ */
2965
3235
  function picklistFilterValueToTf(value, field, refs) {
2966
3236
  if (typeof value !== "string" ||
2967
3237
  field?.__kind !== "field" ||
@@ -2994,6 +3264,101 @@ function picklistFilterValueToTf(value, field, refs) {
2994
3264
  refs.owner.diagnostics.push(`automation filter for picklist field ${JSON.stringify(field.name ?? field.refName)} preserves unknown option ${JSON.stringify(value)}`);
2995
3265
  return undefined;
2996
3266
  }
3267
+ return optionLookupToTf(value, field, refs);
3268
+ }
3269
+ /** A Dropdown or Multi-Select with static options. A record-sourced Dropdown has none and keeps its own rules. */
3270
+ function optionPicklist(field) {
3271
+ return field?.__kind === "field" &&
3272
+ (field.fieldType === "PICKLIST" || field.fieldType === "MULTI_PICKLIST") &&
3273
+ field.options !== undefined
3274
+ ? field
3275
+ : undefined;
3276
+ }
3277
+ /**
3278
+ * `filter.textOption(label)`: the option id for `label`, which must name
3279
+ * exactly one option of `field`. Unlike a pulled raw id or stale label, an
3280
+ * option selection never passes through unresolved (#1733).
3281
+ */
3282
+ function textOptionToTf(label, field, refs, slot) {
3283
+ const picklist = optionPicklist(field);
3284
+ const fieldName = field?.name ?? field?.refName ?? "unknown";
3285
+ if (picklist === undefined) {
3286
+ throw new EntityTfError(`${slot} uses filter.textOption(${JSON.stringify(label)}), but field "${fieldName}" is not a Dropdown or Multi-Select with static options`);
3287
+ }
3288
+ const matches = picklist.options.filter((option) => option === label).length;
3289
+ if (matches === 0 && refs.allowUnknownPicklistOptions === true) {
3290
+ // A pulled workspace keeps a label its live field no longer lists, as
3291
+ // main did for a plain label, so a fresh pull still builds (#1733).
3292
+ warnOption(refs, `${slot} uses filter.textOption(${JSON.stringify(label)}), but field "${fieldName}" has no option with that label; the pulled label is kept as written`);
3293
+ return label;
3294
+ }
3295
+ if (matches !== 1) {
3296
+ throw new EntityTfError(matches === 0
3297
+ ? `${slot} uses filter.textOption(${JSON.stringify(label)}), but field "${fieldName}" has no option with that label; expected one of: ${picklist.options.map((option) => JSON.stringify(option)).join(", ")}`
3298
+ : `${slot} uses filter.textOption(${JSON.stringify(label)}), but field "${fieldName}" has ${matches} options with that label, so it names no single option`);
3299
+ }
3300
+ return optionLookupToTf(label, picklist, refs);
3301
+ }
3302
+ /**
3303
+ * A static value assigned to a Dropdown or Multi-Select with static options.
3304
+ * `filter.textOption(label)` is the one spelling and builds to the option id
3305
+ * (#1733). A plain string is refused: it reads as label text, which is not
3306
+ * what the platform stores. Two values pass through as written: the "" clear
3307
+ * (handled by the caller) and a raw option id pull keeps for an option that no
3308
+ * longer exists. Undefined means the caller encodes the value itself.
3309
+ */
3310
+ function picklistAssignmentValueToTf(value, field, refs) {
3311
+ const fieldName = field?.name ?? field?.refName ?? "unknown";
3312
+ const slot = `automation field "${fieldName}"`;
3313
+ if (isTextOptionValue(value))
3314
+ return textOptionToTf(value.value, field, refs, slot);
3315
+ const picklist = optionPicklist(field);
3316
+ if (picklist === undefined || typeof value !== "string" || value === "")
3317
+ return undefined;
3318
+ if (isUuid(value)) {
3319
+ warnRawOptionId(value, picklist, refs, slot);
3320
+ return undefined;
3321
+ }
3322
+ // 1733 C (Dax, 2026-11-03: "One or the other not both"): a plain label is a
3323
+ // build error. This throw is the one place that decides it.
3324
+ throw new EntityTfError(`automation field "${fieldName}" is a ${field?.fieldType === "MULTI_PICKLIST" ? "Multi-Select" : "Dropdown"} with static options, so a plain string ${JSON.stringify(value)} is not an option. ` +
3325
+ `Select the option by label with filter.textOption(${JSON.stringify(value)})`);
3326
+ }
3327
+ /** A build warning on this automation (#1733). */
3328
+ function warnOption(refs, message) {
3329
+ recordValidations([{
3330
+ severity: "warning",
3331
+ address: `${AUTOMATION_RESOURCE_TYPE}.${refs.owner.automationTfLabel}`,
3332
+ name: refs.owner.automationTfLabel,
3333
+ ownerKind: "automation",
3334
+ message,
3335
+ }]);
3336
+ }
3337
+ /** A raw option id builds as written and warns with the preferred `filter.textOption(label)` (#1733). */
3338
+ function warnRawOptionId(id, field, refs, slot) {
3339
+ warnOption(refs, rawOptionIdWarning({
3340
+ slot,
3341
+ fieldName: field.name ?? field.refName,
3342
+ id,
3343
+ options: field.options,
3344
+ localName: ownedOptionsLocalName(field, refs),
3345
+ index: refs.owner.optionIds,
3346
+ }));
3347
+ }
3348
+ /** The options-by-label lookup that resolves `value` to `field`'s option id at apply. */
3349
+ function optionLookupToTf(value, field, refs) {
3350
+ const owned = ownedOptionsLocalName(field, refs);
3351
+ if (owned !== undefined)
3352
+ return expr.local(owned, [{ index: value }]);
3353
+ // A foreign field's options-by-label local is sourced from
3354
+ // `data.elementum_field.<label>.options` (issue #353) rather than an
3355
+ // owned resource's `options` attribute. Registering here also covers a
3356
+ // payload where nothing else resolves the field's id.
3357
+ const fieldLabel = registerForeignFieldLookup(field, refs.owner, refs.dataBlocks);
3358
+ return expr.local(fieldLabel + "_options_by_label", [{ index: value }]);
3359
+ }
3360
+ /** The options-by-label local of a field this workspace owns; undefined for a foreign field. */
3361
+ function ownedOptionsLocalName(field, refs) {
2997
3362
  if (field.parent !== undefined && field.parentKind !== undefined) {
2998
3363
  // A field owned by a SIBLING app/element built in this same workspace
2999
3364
  // has its options-by-label local sourced from ITS OWN resource's
@@ -3007,28 +3372,23 @@ function picklistFilterValueToTf(value, field, refs) {
3007
3372
  // Table siblings excluded for the same reason as in `crossAppFieldToTf`: a
3008
3373
  // picklist field's owner is an app or an element, never a table.
3009
3374
  if (sibling !== undefined && sibling.kind !== "table" && sibling.kind !== "task") {
3375
+ const childPart = tsLabelToTfLabel(field.resourceKey ?? field.refName);
3010
3376
  const localName = sibling.kind === "app" && field.tags?.includes("STATUS")
3011
3377
  ? `${sibling.tfLabel}_status_options_by_label`
3012
3378
  : sibling.kind === "app" && field.tags?.includes("STAGE")
3013
3379
  ? `${sibling.tfLabel}_stage_options_by_label`
3014
- : `${scopedResourceLabel(sibling.tfLabel, tsLabelToTfLabel(field.refName), sibling.kind)}_options_by_label`;
3015
- return expr.local(localName, [{ index: value }]);
3380
+ : `${scopedResourceLabel(sibling.tfLabel, childPart, sibling.kind)}_options_by_label`;
3381
+ return localName;
3016
3382
  }
3017
3383
  }
3018
- if (field.parent !== undefined && (field.parent !== refs.owner.appRefName || field.parentKind === "element")) {
3019
- // A foreign field's options-by-label local is sourced from
3020
- // `data.elementum_field.<label>.options` (issue #353) rather than an
3021
- // owned resource's `options` attribute. Registering here also covers a
3022
- // payload where nothing else resolves the field's id.
3023
- const fieldLabel = registerForeignFieldLookup(field, refs.owner, refs.dataBlocks);
3024
- return expr.local(fieldLabel + "_options_by_label", [{ index: value }]);
3025
- }
3026
- const localName = refs.owner.parentScope === "app" && field.tags?.includes("STATUS")
3384
+ if (field.parent !== undefined && (field.parent !== refs.owner.appRefName || field.parentKind === "element"))
3385
+ return undefined;
3386
+ const ownChildPart = tsLabelToTfLabel(field.resourceKey ?? field.refName);
3387
+ return refs.owner.parentScope === "app" && field.tags?.includes("STATUS")
3027
3388
  ? `${refs.owner.appTfLabel}_status_options_by_label`
3028
3389
  : refs.owner.parentScope === "app" && field.tags?.includes("STAGE")
3029
3390
  ? `${refs.owner.appTfLabel}_stage_options_by_label`
3030
- : `${scopedResourceLabel(refs.owner.appTfLabel, tsLabelToTfLabel(field.refName), refs.owner.parentScope)}_options_by_label`;
3031
- return expr.local(localName, [{ index: value }]);
3391
+ : `${scopedResourceLabel(refs.owner.appTfLabel, ownChildPart, refs.owner.parentScope)}_options_by_label`;
3032
3392
  }
3033
3393
  function triggerRecordFieldPath(reference, refs) {
3034
3394
  if (!isObject(reference) || typeof reference.name !== "string")
@@ -3098,12 +3458,54 @@ function recordRefKeyIsAmbiguous(name, wireName, taskRefKey, refs) {
3098
3458
  }
3099
3459
  return false;
3100
3460
  }
3461
+ /** A task output's declared type: from the task's own output schema, else the executor's output contract. */
3462
+ function declaredTaskOutputType(task, wireName, envelopeName) {
3463
+ const executor = RESOURCE_TYPE_TO_EXECUTOR[task.type];
3464
+ return task.outputFieldTypes?.get(wireName) ??
3465
+ (executor === undefined ? undefined : TASK_OUTPUT_CONTRACTS[executor]?.[envelopeName]);
3466
+ }
3467
+ /**
3468
+ * A switch case comparing a single BOOLEAN task output with no typed wrapper
3469
+ * (`filter.eq(ctx.actions.B.allMatchingRecordsUpdated, true)`) compares as
3470
+ * BOOLEAN, the same as `filter.boolean(...)`. Built with the operator's TEXT
3471
+ * fallback, the platform stores a text comparison, pull prints it back as
3472
+ * `filter.text(...)`, and the plan after that pull changes the envelope's
3473
+ * fieldType BOOLEAN -> TEXT (#2404). Only that fallback yields: a typed
3474
+ * wrapper (`filter.text(...)`) is explicit and never reaches this hook.
3475
+ */
3476
+ function booleanTaskOutputRealType(reference, refs, authored) {
3477
+ if (authored !== undefined && authored.toUpperCase() !== "TEXT")
3478
+ return undefined;
3479
+ if (!isObject(reference) || reference.type?.toString().toUpperCase() !== "TASK")
3480
+ return undefined;
3481
+ if (typeof reference.taskRefKey !== "string" || typeof reference.name !== "string")
3482
+ return undefined;
3483
+ const task = refs.tasks.get(reference.taskRefKey);
3484
+ // These spell their left values by their own rules in filterReferenceToTf.
3485
+ if (task === undefined ||
3486
+ task.type === "elementum_ai_file_read_task" ||
3487
+ task.type === "elementum_file_reader_task" ||
3488
+ task.type === "elementum_ai_agent_task" ||
3489
+ task.type === TASK_RESOURCES.tableRecordsSearch) {
3490
+ return undefined;
3491
+ }
3492
+ const wireName = taskWireRefName(reference.name, reference.taskRefKey, refs);
3493
+ const envelopeName = taskOutputReferenceName(task.type, wireName, task) ?? wireName;
3494
+ const declared = declaredTaskOutputType(task, wireName, envelopeName);
3495
+ return declared?.fieldType === "BOOLEAN" && declared.multiple !== true ? "BOOLEAN" : undefined;
3496
+ }
3101
3497
  function filterToTf(value, refs) {
3102
3498
  return serializeFilterToTf(value, {
3499
+ ...(refs.allowUnknownPicklistOptions === true && { keepUnresolvedOptions: true }),
3103
3500
  field: (field) => valueToTf(field, refs),
3104
3501
  fieldFromLeftValue: (left) => fieldFromFilterLeftValue(left, refs),
3105
3502
  reference: (reference, role, realType, operator) => filterReferenceToTf(reference, refs, role ?? "value", realType, operator),
3106
- referenceRealType: (reference, _role, authored) => {
3503
+ referenceRealType: (reference, role, authored) => {
3504
+ if (role === "left") {
3505
+ const booleanOutput = booleanTaskOutputRealType(reference, refs, authored);
3506
+ if (booleanOutput !== undefined)
3507
+ return booleanOutput;
3508
+ }
3107
3509
  if (!isObject(reference) || reference.type?.toString().toUpperCase() !== "TRIGGER")
3108
3510
  return authored;
3109
3511
  const parsed = triggerRecordFieldPath(reference, refs);
@@ -3128,7 +3530,24 @@ function filterToTf(value, refs) {
3128
3530
  return authored;
3129
3531
  return inferred;
3130
3532
  },
3131
- literal: (literal, field) => picklistFilterValueToTf(literal, token(field), refs) ?? valueToTf(literal, refs),
3533
+ // #1733: a plain string is literal text, sent as written. Only an option
3534
+ // selection, `filter.textOption(label)` or a UUID comparison value,
3535
+ // resolves a label to its option id.
3536
+ literal: (literal, field, valueType, isOptionLabel) => {
3537
+ const picklist = optionPicklist(token(field));
3538
+ if (picklist !== undefined && typeof literal === "string" && literal !== "") {
3539
+ // One warning per value (#1733): a raw option id, or a plain string.
3540
+ if (isUuid(literal) && !picklist.options.includes(literal))
3541
+ warnRawOptionId(literal, picklist, refs, "automation filter");
3542
+ else if (!isOptionLabel)
3543
+ warnOption(refs, plainOptionStringWarning("automation filter", picklist.name ?? picklist.refName, literal, picklist.options, false));
3544
+ }
3545
+ if (!isOptionLabel)
3546
+ return valueToTf(literal, refs);
3547
+ if (valueType === "text" && typeof literal === "string")
3548
+ return textOptionToTf(literal, token(field), refs, "automation filter");
3549
+ return picklistFilterValueToTf(literal, token(field), refs) ?? valueToTf(literal, refs);
3550
+ },
3132
3551
  });
3133
3552
  }
3134
3553
  /**
@@ -3147,6 +3566,22 @@ function isRunAutomationValueReference(raw) {
3147
3566
  isObject(raw.secretReference) ||
3148
3567
  isObject(raw.variableReference));
3149
3568
  }
3569
+ /**
3570
+ * #1870: the platform compiles a synchronous Dynamic Reference call to a WAIT
3571
+ * task and resumes the caller by matching that task's exact name. Inside a
3572
+ * forEach the loop suffixes the name per iteration, so the completion never
3573
+ * matches: the called automation runs, but the caller never resumes. The task
3574
+ * is still built and applied as authored (an advisory, coverage-gaps.ts).
3575
+ */
3576
+ function dynamicSyncRunInForEachWarning(refKey, config, enclosingForEach) {
3577
+ if (enclosingForEach === undefined || config.synchronous !== true || !isRunAutomationValueReference(config.targetAutomationRef)) {
3578
+ return undefined;
3579
+ }
3580
+ return `task "${refKey}" is a synchronous Dynamic Reference runAutomation inside forEach "${enclosingForEach}"; ` +
3581
+ "the platform never resumes the caller after the called automation finishes, so the steps after it never run " +
3582
+ "and the run stays parked. Move the call out of the forEach, or call a known automation by its catalog ref " +
3583
+ "(Select Automation)";
3584
+ }
3150
3585
  function configAttrs(kind, config, refs) {
3151
3586
  const attrs = {};
3152
3587
  for (const [key, raw] of Object.entries(config)) {
@@ -3206,6 +3641,13 @@ function configAttrs(kind, config, refs) {
3206
3641
  attrs.code = raw;
3207
3642
  continue;
3208
3643
  }
3644
+ if (key === "limit" && kind === "elementum_record_search_task") {
3645
+ if (typeof raw !== "number" || !Number.isInteger(raw) || raw < 1 || raw > 500) {
3646
+ throw new EntityTfError("recordSearch limit must be an integer between 1 and 500; use totalCount and explicit completeness checks when results may reach the limit");
3647
+ }
3648
+ attrs.limit = raw;
3649
+ continue;
3650
+ }
3209
3651
  // execute_script input values: provider Read stores Mobius-normalized
3210
3652
  // short names for on-demand scalars. Keep that envelope here only —
3211
3653
  // templates, notifications, and other attrs still use refs["…"].
@@ -3216,9 +3658,22 @@ function configAttrs(kind, config, refs) {
3216
3658
  if (!isObject(item) || typeof item.name !== "string") {
3217
3659
  throw new EntityTfError("invalid executeScript input");
3218
3660
  }
3661
+ const emptyInput = `executeScript input "${item.name}" has no value; omit unused inputs or pass a supported value reference. Creating a named, unbound input is rejected by the platform`;
3662
+ if (item.value === undefined || (isObject(item.value) && Object.keys(item.value).length === 1 &&
3663
+ "value" in item.value && item.value.value === undefined))
3664
+ throw new EntityTfError(emptyInput);
3665
+ const inputValue = executeScriptInputValueToTf(item.value, refs);
3666
+ if (inputValue === null) {
3667
+ // Update accepts an existing unbound input, unlike create. Keep
3668
+ // pulled configuration faithful; the provider can distinguish a
3669
+ // new task from an existing task during planning.
3670
+ if (!refs.owner.pulledLive && currentValidationMode() !== "pull")
3671
+ throw new EntityTfError(emptyInput);
3672
+ refs.owner.diagnostics.push(`automation ${refs.owner.automationTfLabel}: ${emptyInput}; existing pulled binding preserved`);
3673
+ }
3219
3674
  const mapped = {
3220
3675
  name: item.name,
3221
- value: executeScriptInputValueToTf(item.value, refs),
3676
+ value: inputValue,
3222
3677
  };
3223
3678
  if (item.field_mappings !== undefined) {
3224
3679
  mapped.field_mappings = valueToTf(item.field_mappings, refs);
@@ -3490,13 +3945,13 @@ function configAttrs(kind, config, refs) {
3490
3945
  if (typeof input.type !== "string" || !ON_DEMAND_TF_PARAM_TYPES.has(input.type)) {
3491
3946
  throw new EntityTfError(`onDemand parameter ${JSON.stringify(input.name)} has type ${JSON.stringify(input.type)}, which ` +
3492
3947
  `elementum_on_demand_trigger does not support (allowed: text, number, decimal, boolean, date, ` +
3493
- `datetime, userId, attachmentId, record). Use "text" for a JSON string.`);
3948
+ `datetime, userId, groupId, attachmentId, record). Use "text" for a JSON string.`);
3494
3949
  }
3495
3950
  const mapped = Object.fromEntries(Object.entries(input)
3496
3951
  .filter(([k]) => k !== "app")
3497
3952
  .map(([k, v]) => [
3498
3953
  CONFIG_ATTRS[k] ?? snake(k),
3499
- valueToTf(k === "defaultValue" ? unwrapDefault(v) :
3954
+ valueToTf(k === "defaultValue" ? onDemandDefaultToTf(unwrapDefault(v)) :
3500
3955
  k === "type" && typeof v === "string" ? ON_DEMAND_TF_PARAM_TYPES.get(v) : v, refs),
3501
3956
  ]));
3502
3957
  if (isOnDemandRecordType(typeof input.type === "string" ? input.type : undefined)) {
@@ -3547,7 +4002,7 @@ function configAttrs(kind, config, refs) {
3547
4002
  if (fieldToken?.fieldType !== "MULTI_PICKLIST" && !rawIdClear) {
3548
4003
  throw new EntityTfError(`automation field "${fieldToken?.name ?? fieldToken?.refName ?? "unknown"}" uses an array value but is not a Multi-Select field`);
3549
4004
  }
3550
- const values = staticValue.map((value) => picklistFilterValueToTf(value, fieldToken, refs) ?? valueToTf(value, refs));
4005
+ const values = staticValue.map((value) => picklistAssignmentValueToTf(value, fieldToken, refs) ?? valueToTf(value, refs));
3551
4006
  return {
3552
4007
  field_id: valueToTf(field.aspectFieldId, refs),
3553
4008
  value: expr.jsonencode(values),
@@ -3556,7 +4011,7 @@ function configAttrs(kind, config, refs) {
3556
4011
  }
3557
4012
  assertLiteralFitsFieldType(staticValue, fieldToken);
3558
4013
  const optionValue = staticValue !== undefined
3559
- ? picklistFilterValueToTf(staticValue, fieldToken, refs)
4014
+ ? picklistAssignmentValueToTf(staticValue, fieldToken, refs)
3560
4015
  : undefined;
3561
4016
  let reference = field.valueReference;
3562
4017
  if (typeof reference === "string") {
@@ -3781,6 +4236,7 @@ export function automationToTf(entity, ctx) {
3781
4236
  ownerHandle: ctx.ownerHandle,
3782
4237
  appTfLabel: ctx.appTfLabel,
3783
4238
  automationTfLabel,
4239
+ ...(ctx.optionIds !== undefined ? { optionIds: ctx.optionIds } : {}),
3784
4240
  pulledLive: ctx.workspaceAspects
3785
4241
  ?.get(workspaceAspectKey(ctx.parentScope ?? "app", ctx.appRefName ?? entity.parent))
3786
4242
  ?.pulledAutomationRefNames?.has(entity.refName) === true,
@@ -4030,19 +4486,25 @@ export function automationToTf(entity, ctx) {
4030
4486
  kind: "resource",
4031
4487
  type: triggerType,
4032
4488
  label,
4033
- attrs: { automation: expr.resourceAttr(AUTOMATION_RESOURCE_TYPE, label), ...triggerAttrs },
4489
+ attrs: {
4490
+ automation: expr.resourceAttr(AUTOMATION_RESOURCE_TYPE, label),
4491
+ ...triggerAttrs,
4492
+ ...(OBJECT_FIELD_REFS_TRIGGER_TYPES.has(triggerType) ? triggerObjectFieldAttrs(owner) : {}),
4493
+ },
4034
4494
  };
4035
4495
  const blocks = [automation, trigger];
4036
4496
  const dependencies = [expr.resourceAttr(triggerType, label)];
4037
4497
  const runAutomationPublishes = new Set();
4038
4498
  // `enclosingOperator` describes the switch/forkJoin/forEach scope THIS
4039
4499
  // `emitTasks` call is nested inside (undefined at automation top level) -
4040
- // needed only by `unimplementedTask` (edk#821) to populate
4500
+ // needed only by `unimplementedTask` (edk#821, edk#2571) to populate
4041
4501
  // `operator_task_id`/`operator_child_id` correctly regardless of how many
4042
4502
  // real sibling tasks precede the placeholder within the same case/branch
4043
4503
  // (the rolling `taskParent` chain below tracks the PRECEDING SIBLING, not
4044
4504
  // the enclosing operator, once more than one task shares a scope).
4045
- const emitTasks = (tasks, initialParent, enclosingOperator) => {
4505
+ // `enclosingForEach` is the refKey of the nearest forEach around this scope
4506
+ // at any depth (a switch or fork inside a loop body keeps it), for #1870.
4507
+ const emitTasks = (tasks, initialParent, enclosingOperator, enclosingForEach) => {
4046
4508
  let parent = initialParent;
4047
4509
  let first;
4048
4510
  for (const task of tasks) {
@@ -4089,22 +4551,27 @@ export function automationToTf(entity, ctx) {
4089
4551
  if (typeof inner.taskType !== "string" || inner.taskType === "") {
4090
4552
  throw new EntityTfError(`unimplementedTask "${refKey}" requires a taskType`);
4091
4553
  }
4092
- const operatorTaskAddress = enclosingOperator?.taskAddress;
4093
- const operatorChildAddress = enclosingOperator?.childAddress;
4094
- const isParentTrigger = enclosingOperator === undefined;
4554
+ // Both Required: "" at top level, as the export writes; else the operator
4555
+ // and its case/branch (a loop body's is the for_each, as its `inner` says).
4556
+ const operatorId = (address) => {
4557
+ if (address === undefined)
4558
+ return "";
4559
+ if (address.$expr !== "resource-attr")
4560
+ throw new EntityTfError(`unimplementedTask "${refKey}": its enclosing operator has no resource address`);
4561
+ return expr.resourceAttr(address.type, address.label, ["id"]);
4562
+ };
4563
+ // parent_is_trigger is always false on a task reference. The step this
4564
+ // placeholder comes after is a local, not this flag: the provider
4565
+ // copies the flag onto the following task (edk#2320).
4095
4566
  const extraAttrs = {
4096
4567
  id: idValue,
4097
4568
  task_type: inner.taskType,
4098
4569
  workflow_id: expr.resourceAttr(AUTOMATION_RESOURCE_TYPE, label, ["workflow_id"]),
4099
4570
  app_id: expr.resourceAttr(owner.parentScope === "element" ? "elementum_element" : "elementum_app", owner.appTfLabel, ["id"]),
4100
4571
  automation_id: expr.resourceAttr(AUTOMATION_RESOURCE_TYPE, label, ["id"]),
4101
- parent_is_trigger: isParentTrigger,
4102
- ...(operatorTaskAddress !== undefined && operatorTaskAddress.$expr === "resource-attr"
4103
- ? { operator_task_id: expr.resourceAttr(operatorTaskAddress.type, operatorTaskAddress.label, ["id"]) }
4104
- : {}),
4105
- ...(operatorChildAddress !== undefined && operatorChildAddress.$expr === "resource-attr"
4106
- ? { operator_child_id: expr.resourceAttr(operatorChildAddress.type, operatorChildAddress.label, ["id"]) }
4107
- : {}),
4572
+ parent_is_trigger: false,
4573
+ operator_task_id: operatorId(enclosingOperator?.taskAddress),
4574
+ operator_child_id: operatorId(enclosingOperator?.childAddress),
4108
4575
  };
4109
4576
  if (owner.orgRefs !== undefined) {
4110
4577
  owner.orgRefs.rawLookup("elementum_unmanaged_task_reference", tfLabel, displayName, extraAttrs);
@@ -4118,6 +4585,10 @@ export function automationToTf(entity, ctx) {
4118
4585
  });
4119
4586
  }
4120
4587
  const address = expr.dataAttr("elementum_unmanaged_task_reference", tfLabel);
4588
+ const predecessorLocal = `edk_unmanaged_predecessor_${tfLabel}`;
4589
+ if (ctx.localsAttrs !== undefined && !(predecessorLocal in ctx.localsAttrs)) {
4590
+ ctx.localsAttrs[predecessorLocal] = taskParent;
4591
+ }
4121
4592
  first ??= address;
4122
4593
  parent = address;
4123
4594
  continue;
@@ -4158,7 +4629,19 @@ export function automationToTf(entity, ctx) {
4158
4629
  const message = err instanceof Error ? err.message : String(err);
4159
4630
  throw new EntityTfError(`automation "${entity.refName}"'s task "${refKey}" (${wireType}): ${message}`);
4160
4631
  }
4161
- const attrs = { parent: taskParent, name: displayName, ...taskAttrs };
4632
+ const attrs = {
4633
+ parent: taskParent,
4634
+ name: displayName,
4635
+ ...taskAttrs,
4636
+ ...(OBJECT_FIELD_REFS_TASK_TYPES.has(resourceType)
4637
+ ? taskObjectFieldAttrs(taskAttrs["object_id"], taskTargetFieldAddresses(inner.aspectId ?? inner.relatedAspectId, owner))
4638
+ : {}),
4639
+ };
4640
+ if (wireType === "executeScript") {
4641
+ for (const finding of scriptLintFindings(displayName, inner.code, inner.inputs, inner.outputSchema)) {
4642
+ owner.diagnostics.push(`automation ${owner.automationTfLabel}: ${finding}`);
4643
+ }
4644
+ }
4162
4645
  const block = { kind: "resource", type: resourceType, label: tfLabel, attrs };
4163
4646
  if (wireType === "runAutomation") {
4164
4647
  const target = token(inner.targetAutomationId) ?? (isObject(inner.targetAutomationRef) ? token(inner.targetAutomationRef.value) : undefined);
@@ -4175,6 +4658,9 @@ export function automationToTf(entity, ctx) {
4175
4658
  }
4176
4659
  // Bare-UUID / unresolved targets skip depends_on — configAttrs already
4177
4660
  // emitted target_automation_id as a literal and pushed a diagnostic.
4661
+ const warning = dynamicSyncRunInForEachWarning(refKey, inner, enclosingForEach);
4662
+ if (warning !== undefined)
4663
+ owner.diagnostics.push(`automation ${owner.automationTfLabel}: ${warning}`);
4178
4664
  }
4179
4665
  blocks.push(block);
4180
4666
  const address = expr.resourceAttr(resourceType, tfLabel);
@@ -4191,7 +4677,8 @@ export function automationToTf(entity, ctx) {
4191
4677
  const children = task.children ?? [];
4192
4678
  if (children.length !== 1)
4193
4679
  throw new EntityTfError(`forEach task "${refKey}" must have exactly one child body`);
4194
- emitTasks(children[0].tasks ?? [], expr.resourceAttr(resourceType, tfLabel, ["inner"]), { taskAddress: expr.resourceAttr(resourceType, tfLabel) });
4680
+ const loopTask = expr.resourceAttr(resourceType, tfLabel);
4681
+ emitTasks(children[0].tasks ?? [], expr.resourceAttr(resourceType, tfLabel, ["inner"]), { taskAddress: loopTask, childAddress: loopTask }, refKey);
4195
4682
  // The loop body is a separate operator-owned chain. A fluent sibling
4196
4683
  // authored after `forEach` continues from the for_each task itself,
4197
4684
  // not from the body's terminal task; the latter silently moves that
@@ -4292,7 +4779,7 @@ export function automationToTf(entity, ctx) {
4292
4779
  blocks.push({ kind: "resource", type: branchType, label: branchLabel, attrs: branchAttrs });
4293
4780
  const branchAddress = expr.resourceAttr(branchType, branchLabel);
4294
4781
  dependencies.push(branchAddress);
4295
- emitTasks(child.tasks ?? [], branchAddress, { taskAddress: address, childAddress: branchAddress });
4782
+ emitTasks(child.tasks ?? [], branchAddress, { taskAddress: address, childAddress: branchAddress }, enclosingForEach);
4296
4783
  previous = branchAddress;
4297
4784
  }
4298
4785
  }
@@ -4334,6 +4821,7 @@ export function automationToTf(entity, ctx) {
4334
4821
  };
4335
4822
  blocks.push(publish);
4336
4823
  }
4824
+ setRefsRead(blocks);
4337
4825
  const secretBlocks = [...refs.requiredSecrets].sort().map(requiredSecretVariableBlock);
4338
4826
  return { blocks: [...secretBlocks, ...[...dataBlocks.values()].sort((a, b) => (a.type + "." + a.label).localeCompare(b.type + "." + b.label)), ...blocks], address: AUTOMATION_RESOURCE_TYPE + "." + label };
4339
4827
  }