@elementumai/edk 0.12.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 (193) hide show
  1. package/README.md +2 -0
  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/types/app.d.ts +6 -0
  13. package/dist-sdk/src/engine/build/context.d.ts +3 -0
  14. package/dist-sdk/src/engine/pull/authored-address.js +42 -6
  15. package/dist-sdk/src/engine/pull/authored-root.d.ts +88 -0
  16. package/dist-sdk/src/engine/pull/authored-root.js +306 -0
  17. package/dist-sdk/src/engine/pull/context.d.ts +10 -0
  18. package/dist-sdk/src/engine/pull/field-refs-registry.d.ts +114 -0
  19. package/dist-sdk/src/engine/pull/field-refs-registry.js +501 -0
  20. package/dist-sdk/src/engine/pull/org.d.ts +1 -0
  21. package/dist-sdk/src/engine/pull/org.js +2 -0
  22. package/dist-sdk/src/engine/pull/partition.d.ts +8 -0
  23. package/dist-sdk/src/engine/pull/partition.js +43 -0
  24. package/dist-sdk/src/engine/pull/pulled-roots.d.ts +89 -0
  25. package/dist-sdk/src/engine/pull/pulled-roots.js +203 -0
  26. package/dist-sdk/src/engine/pull/ref-only.d.ts +4 -0
  27. package/dist-sdk/src/engine/pull/ref-only.js +7 -1
  28. package/dist-sdk/src/engine/pull/source-resources.d.ts +39 -0
  29. package/dist-sdk/src/engine/pull/source-resources.js +110 -0
  30. package/dist-sdk/src/engine/pull/stream-root.d.ts +148 -0
  31. package/dist-sdk/src/engine/pull/stream-root.js +563 -0
  32. package/dist-sdk/src/engine/workspace/reserved-catalog-keys.d.ts +47 -0
  33. package/dist-sdk/src/engine/workspace/reserved-catalog-keys.js +115 -0
  34. package/dist-sdk/src/entities/access-policy/build.d.ts +2 -1
  35. package/dist-sdk/src/entities/access-policy/from-tf.d.ts +7 -0
  36. package/dist-sdk/src/entities/access-policy/from-tf.js +18 -3
  37. package/dist-sdk/src/entities/access-policy/to-tf.d.ts +19 -0
  38. package/dist-sdk/src/entities/access-policy/to-tf.js +65 -8
  39. package/dist-sdk/src/entities/agent/build.d.ts +52 -1
  40. package/dist-sdk/src/entities/agent/build.js +34 -0
  41. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +68 -0
  42. package/dist-sdk/src/entities/agent/from-tf.d.ts +34 -1
  43. package/dist-sdk/src/entities/agent/from-tf.js +262 -2
  44. package/dist-sdk/src/entities/agent/index.d.ts +1 -1
  45. package/dist-sdk/src/entities/agent/to-tf.d.ts +8 -10
  46. package/dist-sdk/src/entities/agent/to-tf.js +158 -14
  47. package/dist-sdk/src/entities/agent-tool/from-tf.js +6 -0
  48. package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +2 -2
  49. package/dist-sdk/src/entities/agent-tool/to-tf.js +2 -2
  50. package/dist-sdk/src/entities/app/build.d.ts +33 -13
  51. package/dist-sdk/src/entities/app/build.js +14 -12
  52. package/dist-sdk/src/entities/app/from-tf.js +24 -9
  53. package/dist-sdk/src/entities/app/index.d.ts +1 -0
  54. package/dist-sdk/src/entities/app/index.js +1 -0
  55. package/dist-sdk/src/entities/app/module.js +1 -0
  56. package/dist-sdk/src/entities/app/stage-keys.d.ts +2 -2
  57. package/dist-sdk/src/entities/app/stage-keys.js +3 -3
  58. package/dist-sdk/src/entities/app/to-tf.js +1 -0
  59. package/dist-sdk/src/entities/approval-chain/build.d.ts +46 -11
  60. package/dist-sdk/src/entities/approval-chain/build.js +120 -8
  61. package/dist-sdk/src/entities/approval-chain/from-tf.d.ts +24 -2
  62. package/dist-sdk/src/entities/approval-chain/from-tf.js +148 -6
  63. package/dist-sdk/src/entities/approval-chain/index.d.ts +4 -1
  64. package/dist-sdk/src/entities/approval-chain/index.js +4 -1
  65. package/dist-sdk/src/entities/approval-chain/module.js +23 -5
  66. package/dist-sdk/src/entities/approval-chain/printer.d.ts +1 -1
  67. package/dist-sdk/src/entities/approval-chain/printer.js +91 -5
  68. package/dist-sdk/src/entities/approval-chain/steps-tf.d.ts +77 -0
  69. package/dist-sdk/src/entities/approval-chain/steps-tf.js +255 -0
  70. package/dist-sdk/src/entities/approval-chain/steps.d.ts +71 -0
  71. package/dist-sdk/src/entities/approval-chain/steps.js +83 -0
  72. package/dist-sdk/src/entities/approval-chain/to-tf.d.ts +16 -6
  73. package/dist-sdk/src/entities/approval-chain/to-tf.js +37 -4
  74. package/dist-sdk/src/entities/automation/build.js +70 -27
  75. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +20 -5
  76. package/dist-sdk/src/entities/automation/from-tf.d.ts +26 -5
  77. package/dist-sdk/src/entities/automation/from-tf.js +593 -101
  78. package/dist-sdk/src/entities/automation/index.d.ts +1 -0
  79. package/dist-sdk/src/entities/automation/index.js +1 -0
  80. package/dist-sdk/src/entities/automation/module.d.ts +4 -3
  81. package/dist-sdk/src/entities/automation/module.js +33 -12
  82. package/dist-sdk/src/entities/automation/refs-read.d.ts +19 -0
  83. package/dist-sdk/src/entities/automation/refs-read.js +48 -0
  84. package/dist-sdk/src/entities/automation/slack-message-refs.d.ts +9 -0
  85. package/dist-sdk/src/entities/automation/slack-message-refs.js +75 -0
  86. package/dist-sdk/src/entities/automation/task-output-labels.d.ts +11 -0
  87. package/dist-sdk/src/entities/automation/task-output-labels.js +23 -0
  88. package/dist-sdk/src/entities/automation/tasks.d.ts +29 -4
  89. package/dist-sdk/src/entities/automation/tasks.js +34 -11
  90. package/dist-sdk/src/entities/automation/to-tf.d.ts +3 -0
  91. package/dist-sdk/src/entities/automation/to-tf.js +337 -77
  92. package/dist-sdk/src/entities/automation/triggers.d.ts +0 -8
  93. package/dist-sdk/src/entities/automation/triggers.js +26 -11
  94. package/dist-sdk/src/entities/automation/unsafe-script-output.d.ts +50 -0
  95. package/dist-sdk/src/entities/automation/unsafe-script-output.js +92 -0
  96. package/dist-sdk/src/entities/chart/build.d.ts +9 -1
  97. package/dist-sdk/src/entities/chart/from-tf.js +3 -0
  98. package/dist-sdk/src/entities/chart/to-tf.js +19 -2
  99. package/dist-sdk/src/entities/dynamic-layout/build.d.ts +2 -0
  100. package/dist-sdk/src/entities/dynamic-layout/from-tf.js +44 -5
  101. package/dist-sdk/src/entities/dynamic-layout/to-tf.js +46 -12
  102. package/dist-sdk/src/entities/element/audit-field-guard.d.ts +9 -0
  103. package/dist-sdk/src/entities/element/audit-field-guard.js +88 -0
  104. package/dist-sdk/src/entities/element/build.js +2 -1
  105. package/dist-sdk/src/entities/element/from-tf.js +15 -2
  106. package/dist-sdk/src/entities/element/module.js +3 -0
  107. package/dist-sdk/src/entities/element/system-fields.d.ts +13 -0
  108. package/dist-sdk/src/entities/element/system-fields.js +23 -0
  109. package/dist-sdk/src/entities/element/to-tf.js +1 -0
  110. package/dist-sdk/src/entities/field/build.d.ts +9 -0
  111. package/dist-sdk/src/entities/field/from-tf.d.ts +29 -1
  112. package/dist-sdk/src/entities/field/from-tf.js +99 -6
  113. package/dist-sdk/src/entities/field/module.js +4 -0
  114. package/dist-sdk/src/entities/field/to-tf.d.ts +5 -1
  115. package/dist-sdk/src/entities/field/to-tf.js +33 -12
  116. package/dist-sdk/src/entities/org/category.js +1 -0
  117. package/dist-sdk/src/entities/org/index.d.ts +1 -0
  118. package/dist-sdk/src/entities/org/index.js +1 -0
  119. package/dist-sdk/src/entities/org/voice-auth.d.ts +5 -0
  120. package/dist-sdk/src/entities/org/voice-auth.js +33 -0
  121. package/dist-sdk/src/entities/organization/build.d.ts +3 -0
  122. package/dist-sdk/src/entities/organization/build.js +2 -0
  123. package/dist-sdk/src/entities/organization/index.d.ts +1 -0
  124. package/dist-sdk/src/entities/organization/index.js +1 -0
  125. package/dist-sdk/src/entities/organization/to-tf.d.ts +2 -0
  126. package/dist-sdk/src/entities/organization/to-tf.js +59 -1
  127. package/dist-sdk/src/entities/organization/voice-auth.d.ts +60 -0
  128. package/dist-sdk/src/entities/organization/voice-auth.js +60 -0
  129. package/dist-sdk/src/entities/phone-service/build.d.ts +9 -1
  130. package/dist-sdk/src/entities/phone-service/build.js +1 -0
  131. package/dist-sdk/src/entities/phone-service/deserializer/print-phone-service.js +3 -0
  132. package/dist-sdk/src/entities/phone-service/from-tf.d.ts +1 -0
  133. package/dist-sdk/src/entities/phone-service/from-tf.js +8 -1
  134. package/dist-sdk/src/entities/phone-service/to-tf.js +16 -0
  135. package/dist-sdk/src/entities/record-create-form/from-tf.js +2 -2
  136. package/dist-sdk/src/entities/relationship/from-tf.js +7 -2
  137. package/dist-sdk/src/entities/relationship/module.js +2 -2
  138. package/dist-sdk/src/entities/relationship/pair-check.d.ts +6 -2
  139. package/dist-sdk/src/entities/relationship/pair-check.js +105 -18
  140. package/dist-sdk/src/entities/relationship/to-tf.js +5 -2
  141. package/dist-sdk/src/entities/role/permission-levels.d.ts +7 -0
  142. package/dist-sdk/src/entities/role/permission-levels.js +78 -0
  143. package/dist-sdk/src/entities/role/to-tf.js +32 -2
  144. package/dist-sdk/src/entities/service-account/module.d.ts +2 -1
  145. package/dist-sdk/src/entities/service-account/module.js +4 -1
  146. package/dist-sdk/src/entities/service-account/resource-type.d.ts +2 -0
  147. package/dist-sdk/src/entities/service-account/resource-type.js +2 -0
  148. package/dist-sdk/src/entities/service-account/role-membership-check.d.ts +20 -0
  149. package/dist-sdk/src/entities/service-account/role-membership-check.js +80 -0
  150. package/dist-sdk/src/entities/shared/aspect-target-from-tf.d.ts +15 -0
  151. package/dist-sdk/src/entities/shared/aspect-target-from-tf.js +36 -0
  152. package/dist-sdk/src/entities/shared/filters/ast.d.ts +2 -0
  153. package/dist-sdk/src/entities/shared/filters/index.d.ts +85 -14
  154. package/dist-sdk/src/entities/shared/filters/index.js +18 -6
  155. package/dist-sdk/src/entities/shared/filters/option-lookups.d.ts +57 -0
  156. package/dist-sdk/src/entities/shared/filters/option-lookups.js +108 -0
  157. package/dist-sdk/src/entities/shared/filters/print.js +9 -5
  158. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +12 -7
  159. package/dist-sdk/src/entities/shared/filters/tf-codec.js +9 -5
  160. package/dist-sdk/src/entities/shared/raw-option-id.d.ts +30 -0
  161. package/dist-sdk/src/entities/shared/raw-option-id.js +41 -0
  162. package/dist-sdk/src/entities/shared/tool-field-ref.js +6 -2
  163. package/dist-sdk/src/entities/skill/input-coverage.js +5 -2
  164. package/dist-sdk/src/entities/sla/build.d.ts +96 -0
  165. package/dist-sdk/src/entities/sla/build.js +124 -0
  166. package/dist-sdk/src/entities/sla/from-tf.d.ts +40 -0
  167. package/dist-sdk/src/entities/sla/from-tf.js +164 -0
  168. package/dist-sdk/src/entities/sla/index.d.ts +1 -0
  169. package/dist-sdk/src/entities/sla/index.js +1 -0
  170. package/dist-sdk/src/entities/sla/module.d.ts +4 -0
  171. package/dist-sdk/src/entities/sla/module.js +73 -0
  172. package/dist-sdk/src/entities/sla/printer.d.ts +2 -0
  173. package/dist-sdk/src/entities/sla/printer.js +84 -0
  174. package/dist-sdk/src/entities/sla/to-tf.d.ts +12 -0
  175. package/dist-sdk/src/entities/sla/to-tf.js +81 -0
  176. package/dist-sdk/src/entities/table/build.d.ts +7 -2
  177. package/dist-sdk/src/entities/table/build.js +22 -1
  178. package/dist-sdk/src/entities/table/deserializer/normalize.d.ts +4 -1
  179. package/dist-sdk/src/entities/table/from-tf.js +89 -14
  180. package/dist-sdk/src/entities/table/index.d.ts +1 -1
  181. package/dist-sdk/src/entities/table/to-tf.js +41 -2
  182. package/dist-sdk/src/entities/task/from-tf.js +2 -1
  183. package/dist-sdk/src/entities/view/from-tf.js +7 -4
  184. package/dist-sdk/src/entities/widget/from-tf.js +13 -2
  185. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +49 -4
  186. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
  187. package/dist-sdk/src/graph/index.d.ts +5 -0
  188. package/dist-sdk/src/graph/index.js +7 -0
  189. package/dist-sdk/src/graph/modules.js +11 -1
  190. package/dist-sdk/src/graph/resource-types.d.ts +47 -0
  191. package/dist-sdk/src/graph/resource-types.js +62 -0
  192. package/dist-sdk/src/graph/types.d.ts +78 -6
  193. package/package.json +6 -3
@@ -8,13 +8,15 @@ 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
10
  import { scriptLintFindings } from "./script-lint.js";
11
+ import { setRefsRead } from "./refs-read.js";
11
12
  import { MANAGED_FIELD_ORDER_RESOURCE_TYPE } from "../field/types.js";
12
13
  import { SERVICE_ACCOUNT_RESOURCE_TYPE } from "../service-account/module.js";
13
14
  import { serviceAccountRefToTf } from "../service-account/to-tf.js";
14
15
  import { workspaceServiceAccountAppResolver } from "../service-account/workspace-owner.js";
15
16
  import { foreignFieldDataLabel, resolveForeignRef } from "../shared/foreign-ref.js";
16
17
  import { filterToTf as serializeFilterToTf } from "../shared/filters/tf-codec.js";
17
- 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";
18
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";
19
21
  import { outputFieldTypesFromScriptSchema, scriptOutputReferenceIsDeclared } from "./output-field-types.js";
20
22
  import { RESOURCE_TYPE_TO_EXECUTOR, TASK_OUTPUT_CONTRACTS } from "./generated/task-output-contracts.js";
@@ -25,11 +27,12 @@ import { UNRESOLVED_FIELD_MARKER } from "../shared/ref.js";
25
27
  import { ELEMENT_SYSTEM_FIELD_KEYS } from "../element/system-fields.js";
26
28
  import { TABLE_RESOURCE_TYPE } from "../table/module.js";
27
29
  import { AUTOMATION_RESOURCE_TYPE, WORKFLOW_PUBLISH_RESOURCE_TYPE, automationResourceLabel } from "./types.js";
28
- 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";
29
31
  import { onDemandTriggerRefKey } from "./value-ref-tf.js";
30
32
  import { normalizeOnDemandParamKey } from "../../../pull/util.js";
31
33
  import { PROVIDER_FIXED_SYSTEM_FIELD_KEYS, recordFieldWireRefName } from "./system-ref-name.js";
32
34
  import { taskTfLabel } from "./task-label.js";
35
+ import { slackMessageTriggerReferenceName, slackMessageTriggerRefName } from "./slack-message-refs.js";
33
36
  import { automationRunTargetResourceAttr, automationTargetOwner, bareStaticRunTarget, onDemandRecordParamNames, recordInputMappingProblem } from "./run-target.js";
34
37
  import { FIELD_TYPE_MAP, isOnDemandRecordType } from "../shared/types/field-types.js";
35
38
  /** The context for reading records of `appRefName` (a `kind`), retargeted from the owner. */
@@ -49,10 +52,14 @@ const ON_DEMAND_TF_PARAM_TYPES = new Map([
49
52
  function recordOwnerContext(owner, appRefName, kind, fieldNames) {
50
53
  if (appRefName === owner.appRefName && (kind === undefined || kind === owner.parentScope))
51
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).
52
58
  return {
53
59
  ...owner,
54
60
  appRefName,
55
61
  fieldNames: fieldNames ?? new Map(),
62
+ fieldAddresses: fieldNamesForAppRefName(owner.fieldAddressesByAppRefName, appRefName) ?? new Map(),
56
63
  recordLacksAuditFields: kind === "element" && owner.elementsWithoutAuditFields?.has(appRefName) === true,
57
64
  };
58
65
  }
@@ -284,7 +291,9 @@ function onlyEntry(value, subject) {
284
291
  }
285
292
  /**
286
293
  * Tasks whose refs carry every field of the record they search (edk#2280)
287
- * or create (edk#2406). update_field refs carry them too and aren't covered yet.
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.
288
297
  */
289
298
  const OBJECT_FIELD_REFS_TASK_TYPES = new Set([
290
299
  "elementum_record_search_task",
@@ -330,6 +339,70 @@ function objectFieldIdsAttr(objectId, fieldAddresses) {
330
339
  object_field_ids: expr.resourceAttr(MANAGED_FIELD_ORDER_RESOURCE_TYPE, scopedResourceLabel(objectId.label, "field_order", scope), ["field_ids"]),
331
340
  };
332
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
+ }
333
406
  /** The field addresses this build writes for a task's `aspectId` target. */
334
407
  function taskTargetFieldAddresses(aspectId, owner) {
335
408
  const target = token(aspectId);
@@ -520,7 +593,7 @@ function crossAppFieldToTf(value, ctx, dataBlocks) {
520
593
  // table-owned search table has to be distinguishable from an element-owned
521
594
  // one.
522
595
  if (sibling !== undefined && sibling.kind !== "table" && sibling.kind !== "task") {
523
- 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));
524
597
  if (fieldValue === undefined) {
525
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 ?? "")})`);
526
599
  }
@@ -974,16 +1047,19 @@ function tokenToTf(value, ctx, dataBlocks) {
974
1047
  // label (see ApprovalChainRef); preferring it rewrote live pulls to UUIDs.
975
1048
  const refName = typeof value.refName === "string" ? value.refName.trim() : "";
976
1049
  if (refName !== "") {
977
- 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}`;
978
1054
  // Never emit a reference to an approval process this build doesn't
979
- // declare (edk#1416). The build records the app's discovered
1055
+ // declare (edk#1416). The build records the owner's discovered
980
1056
  // approval-chain files; direct callers without that information keep
981
1057
  // the managed reference.
982
1058
  const declared = ctx.workspaceAspects
983
- ?.get(workspaceAspectKey("app", ctx.appRefName))
1059
+ ?.get(workspaceAspectKey(ctx.parentScope, ctx.appRefName))
984
1060
  ?.managedChildRefNames?.get("approval-chain");
985
1061
  if (declared === undefined || declared.has(refName)) {
986
- return expr.resourceAttr("elementum_approval_process", scopedLabel(ctx.appTfLabel, tsLabelToTfLabel(refName)), ["id"]);
1062
+ return expr.resourceAttr("elementum_approval_process", approvalLabel, ["id"]);
987
1063
  }
988
1064
  if (value.unresolvedId !== undefined) {
989
1065
  ctx.diagnostics.push(`automation ${ctx.automationTfLabel}: approval chain "${refName}" is not declared in this build (${address} would be undeclared); ` +
@@ -991,7 +1067,7 @@ function tokenToTf(value, ctx, dataBlocks) {
991
1067
  return value.unresolvedId;
992
1068
  }
993
1069
  throw new EntityTfError(`automation ${ctx.automationTfLabel}: approval chain "${refName}" is not declared in this build (${address} is undeclared) ` +
994
- `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`);
995
1071
  }
996
1072
  if (value.unresolvedId !== undefined)
997
1073
  return value.unresolvedId;
@@ -1446,9 +1522,9 @@ function foreignFoundRecordFieldId(fieldKey, taskRefKey, refs) {
1446
1522
  return expr.dataAttr("elementum_field", registerForeignFieldLookup(fieldToken, refs.owner, refs.dataBlocks), ["id"]);
1447
1523
  }
1448
1524
  function calculationTriggerMustache(name, refs) {
1449
- const onDemandName = onDemandTriggerRefName(name, refs);
1450
- if (onDemandName !== undefined)
1451
- return [`{{trigger name="${onDemandName}"}}`];
1525
+ const triggerName = onDemandTriggerRefName(name, refs) ?? slackTriggerReferenceName(name, refs);
1526
+ if (triggerName !== undefined)
1527
+ return [`{{trigger name="${triggerName}"}}`];
1452
1528
  const parts = name.split(".");
1453
1529
  if (parts[0] !== "record" || parts.length < 2) {
1454
1530
  return [`{{trigger name="${name}"}}`];
@@ -1519,14 +1595,9 @@ const TS_TRIGGER_REF_TO_WIRE = {
1519
1595
  // pseudo-fields only, keyed by the DIRECT ts accessor name, not a dotted
1520
1596
  // record path. Record-path refs are handled below from app fields and
1521
1597
  // suffix mappings.
1522
- slackThreadId: "Slack Thread ID",
1523
- slackChannelId: "Slack Channel ID",
1524
- messageAuthorEmail: "Message Author Email",
1525
- messageAuthorId: "Message Author ID",
1526
- messageAuthorName: "Message Author Name",
1527
- messageContent: "Message Content",
1528
- messageId: "Message ID",
1529
- 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.
1530
1601
  sender_email: "Sender's Email Address",
1531
1602
  sender_name: "Sender's Name",
1532
1603
  body: "Body (Plain Text)",
@@ -1588,11 +1659,13 @@ function wireRefName(name, ctx) {
1588
1659
  // System fields are keyed in ctx.fieldNames under their canonical
1589
1660
  // SystemFieldKey (title/id/status/…) with the app's display name —
1590
1661
  // including systemFields renames ("App Name"). Provider-fixed audit
1591
- // keys (stage/createdBy/…) have no rename attribute and always use
1592
- // DEPLOY_DEFAULT. Renamable system fields prefer fieldNames; only
1593
- // when the map lacks the key do we fall back to DEPLOY_DEFAULT (the
1594
- // silent Title fallback that breaks cross-app findRelatedRecords when
1595
- // 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).
1596
1669
  const systemFieldKey = SYSTEM_FIELD_KEY_SET.has(fieldKey)
1597
1670
  ? fieldKey
1598
1671
  : undefined;
@@ -1604,6 +1677,10 @@ function wireRefName(name, ctx) {
1604
1677
  "The platform adds them to apps but only to some elements, and EDK cannot create them. " +
1605
1678
  "Remove the reference, or set systemFields: { audit: true } on an element the platform did give them to.");
1606
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.
1607
1684
  const fieldName = systemFieldKey !== undefined && PROVIDER_FIXED_SYSTEM_FIELD_KEYS.has(systemFieldKey)
1608
1685
  ? DEPLOY_DEFAULT_SYSTEM_FIELD_NAMES[systemFieldKey]
1609
1686
  : ctx.fieldNames.get(fieldKey) ??
@@ -1657,15 +1734,6 @@ const RECORD_COLLECTION_TASK_WIRE_TYPES = new Set([
1657
1734
  const TS_FOR_EACH_GENERIC_SEGMENT_TO_WIRE = {
1658
1735
  iteration: "Iteration",
1659
1736
  };
1660
- function forEachCompactFilterName(name, isRecordCollection) {
1661
- if (name === "recordId")
1662
- return "item";
1663
- // A plain-list loop's whole item is ForEachReference name "" on the
1664
- // platform; provider Read renders it as `for_each.<id>.`.
1665
- if (name === "item" && !isRecordCollection)
1666
- return "";
1667
- return name;
1668
- }
1669
1737
  function forEachWireRefName(name, ctx, isRecordCollection) {
1670
1738
  // A recordSearch collection's whole item and branded record identity both
1671
1739
  // point at the loop's ASPECT_RECORD_ID reference. Live provider state
@@ -1864,10 +1932,21 @@ function onDemandTriggerRefName(name, refs) {
1864
1932
  }
1865
1933
  return ON_DEMAND_TRIGGERED_BY_REFS[name];
1866
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
+ }
1867
1943
  function triggerWireRefName(name, refs) {
1868
1944
  const onDemandName = onDemandTriggerRefName(name, refs);
1869
1945
  if (onDemandName !== undefined)
1870
1946
  return onDemandName;
1947
+ const slackName = slackTriggerRefName(name, refs);
1948
+ if (slackName !== undefined)
1949
+ return slackName;
1871
1950
  const scalarParams = refs.triggerParamNames.filter((param) => !refs.recordParamNames.includes(param));
1872
1951
  const declared = onDemandTriggerRefKey(name, scalarParams);
1873
1952
  if (declared !== name || scalarParams.includes(name))
@@ -2136,7 +2215,9 @@ function workflowPublishOutputEnvelope(value, refs) {
2136
2215
  multiple: typed.multiple,
2137
2216
  taskReference: null,
2138
2217
  triggerReference: {
2139
- 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),
2140
2221
  },
2141
2222
  variableReference: null,
2142
2223
  };
@@ -2592,9 +2673,9 @@ function valueToTf(value, refs) {
2592
2673
  function snake(name) {
2593
2674
  return name.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/-/g, "_").toLowerCase();
2594
2675
  }
2595
- /** The provider's `default_value` is a string: a Checkbox default is `"true"` or `"false"`, as `ei` export writes it. */
2676
+ /** The provider's `default_value` is a string: a Number, Decimal or Checkbox default is quoted, as `ei` export writes it. */
2596
2677
  function onDemandDefaultToTf(value) {
2597
- return typeof value === "boolean" ? String(value) : value;
2678
+ return typeof value === "number" || typeof value === "boolean" ? String(value) : value;
2598
2679
  }
2599
2680
  function unwrapDefault(value) {
2600
2681
  if (!isObject(value))
@@ -2646,7 +2727,7 @@ function onDemandRecordFieldFilterReference(name, refs, operator) {
2646
2727
  `(ctx.trigger.${paramName}.${fieldKey}.id) or ".label" (ctx.trigger.${paramName}.${fieldKey}.label) explicitly.`);
2647
2728
  }
2648
2729
  const wireSuffix = suffix === "recordId"
2649
- ? "10000001-2000-4000-a000-800000000000"
2730
+ ? RECORD_ID_REFERENCE_FIELD
2650
2731
  : suffix.length === 0 && isOwner && isOptionBearingPicklist(refs.owner.fieldMetadata.get(fieldKey)) ? "id"
2651
2732
  : suffix.length === 0 && isOwner && operator === "is_null" && isIdentityField(refs.owner.fieldMetadata.get(fieldKey)) ? "id" : suffix;
2652
2733
  const tail = wireSuffix.length > 0 ? [`.${wireSuffix}`] : [];
@@ -2731,7 +2812,7 @@ function filterReferenceToTf(value, refs, role = "value", realType, operator) {
2731
2812
  const fieldKey = parts[1];
2732
2813
  const address = refs.owner.fieldAddresses.get(fieldKey);
2733
2814
  const suffix = parts.slice(2).join(".");
2734
- let wireSuffix = suffix === "recordId" ? "10000001-2000-4000-a000-800000000000" : suffix;
2815
+ let wireSuffix = suffix === "recordId" ? RECORD_ID_REFERENCE_FIELD : suffix;
2735
2816
  // An option-bearing picklist has no bare wire form. The platform editor
2736
2817
  // sends `.id` or `.label`, and a null-check emits `.id`.
2737
2818
  if (suffix.length === 0 && isOptionBearingPicklist(refs.owner.fieldMetadata.get(fieldKey))) {
@@ -2818,11 +2899,21 @@ function filterReferenceToTf(value, refs, role = "value", realType, operator) {
2818
2899
  }
2819
2900
  const triggerRefKey = triggerWireRefName(value.name, refs);
2820
2901
  if (refs.trigger.type === TRIGGER_RESOURCES.onDemand) {
2821
- // 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.
2822
2908
  if (ON_DEMAND_TRIGGERED_BY_REFS[value.name] !== undefined) {
2823
- throw new EntityTfError(`filter on ctx.trigger.${value.name}: an on-demand filter can only reference declared inputs, ` +
2824
- `and the platform publishes no filter reference for the user who ran the automation. ` +
2825
- `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}`;
2826
2917
  }
2827
2918
  return expr.resourceAttr(refs.trigger.type, refs.trigger.label, ["filter_refs", { index: triggerRefKey }]);
2828
2919
  }
@@ -3074,10 +3165,43 @@ function filterReferenceToTf(value, refs, role = "value", realType, operator) {
3074
3165
  const task = refs.tasks.get(value.forEachTaskRefKey);
3075
3166
  if (task === undefined)
3076
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";
3077
3202
  return expr.template([
3078
- "for_each.",
3079
- expr.resourceAttr(task.type, task.label, ["id"]),
3080
- `.${forEachCompactFilterName(value.name, refs.recordItemForEachRefKeys.has(value.forEachTaskRefKey))}`,
3203
+ "for_each.", expr.resourceAttr(task.type, task.label, ["id"]), ".", fieldId,
3204
+ ...(wireSuffix === "" ? [] : [`.${wireSuffix}`]),
3081
3205
  ]);
3082
3206
  }
3083
3207
  case "VALUE":
@@ -3104,6 +3228,10 @@ function filterReferenceToTf(value, refs, role = "value", realType, operator) {
3104
3228
  throw new EntityTfError(`unsupported filter reference type "${value.type}"`);
3105
3229
  }
3106
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
+ */
3107
3235
  function picklistFilterValueToTf(value, field, refs) {
3108
3236
  if (typeof value !== "string" ||
3109
3237
  field?.__kind !== "field" ||
@@ -3136,6 +3264,101 @@ function picklistFilterValueToTf(value, field, refs) {
3136
3264
  refs.owner.diagnostics.push(`automation filter for picklist field ${JSON.stringify(field.name ?? field.refName)} preserves unknown option ${JSON.stringify(value)}`);
3137
3265
  return undefined;
3138
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) {
3139
3362
  if (field.parent !== undefined && field.parentKind !== undefined) {
3140
3363
  // A field owned by a SIBLING app/element built in this same workspace
3141
3364
  // has its options-by-label local sourced from ITS OWN resource's
@@ -3149,28 +3372,23 @@ function picklistFilterValueToTf(value, field, refs) {
3149
3372
  // Table siblings excluded for the same reason as in `crossAppFieldToTf`: a
3150
3373
  // picklist field's owner is an app or an element, never a table.
3151
3374
  if (sibling !== undefined && sibling.kind !== "table" && sibling.kind !== "task") {
3375
+ const childPart = tsLabelToTfLabel(field.resourceKey ?? field.refName);
3152
3376
  const localName = sibling.kind === "app" && field.tags?.includes("STATUS")
3153
3377
  ? `${sibling.tfLabel}_status_options_by_label`
3154
3378
  : sibling.kind === "app" && field.tags?.includes("STAGE")
3155
3379
  ? `${sibling.tfLabel}_stage_options_by_label`
3156
- : `${scopedResourceLabel(sibling.tfLabel, tsLabelToTfLabel(field.refName), sibling.kind)}_options_by_label`;
3157
- return expr.local(localName, [{ index: value }]);
3380
+ : `${scopedResourceLabel(sibling.tfLabel, childPart, sibling.kind)}_options_by_label`;
3381
+ return localName;
3158
3382
  }
3159
3383
  }
3160
- if (field.parent !== undefined && (field.parent !== refs.owner.appRefName || field.parentKind === "element")) {
3161
- // A foreign field's options-by-label local is sourced from
3162
- // `data.elementum_field.<label>.options` (issue #353) rather than an
3163
- // owned resource's `options` attribute. Registering here also covers a
3164
- // payload where nothing else resolves the field's id.
3165
- const fieldLabel = registerForeignFieldLookup(field, refs.owner, refs.dataBlocks);
3166
- return expr.local(fieldLabel + "_options_by_label", [{ index: value }]);
3167
- }
3168
- 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")
3169
3388
  ? `${refs.owner.appTfLabel}_status_options_by_label`
3170
3389
  : refs.owner.parentScope === "app" && field.tags?.includes("STAGE")
3171
3390
  ? `${refs.owner.appTfLabel}_stage_options_by_label`
3172
- : `${scopedResourceLabel(refs.owner.appTfLabel, tsLabelToTfLabel(field.refName), refs.owner.parentScope)}_options_by_label`;
3173
- return expr.local(localName, [{ index: value }]);
3391
+ : `${scopedResourceLabel(refs.owner.appTfLabel, ownChildPart, refs.owner.parentScope)}_options_by_label`;
3174
3392
  }
3175
3393
  function triggerRecordFieldPath(reference, refs) {
3176
3394
  if (!isObject(reference) || typeof reference.name !== "string")
@@ -3278,6 +3496,7 @@ function booleanTaskOutputRealType(reference, refs, authored) {
3278
3496
  }
3279
3497
  function filterToTf(value, refs) {
3280
3498
  return serializeFilterToTf(value, {
3499
+ ...(refs.allowUnknownPicklistOptions === true && { keepUnresolvedOptions: true }),
3281
3500
  field: (field) => valueToTf(field, refs),
3282
3501
  fieldFromLeftValue: (left) => fieldFromFilterLeftValue(left, refs),
3283
3502
  reference: (reference, role, realType, operator) => filterReferenceToTf(reference, refs, role ?? "value", realType, operator),
@@ -3311,7 +3530,24 @@ function filterToTf(value, refs) {
3311
3530
  return authored;
3312
3531
  return inferred;
3313
3532
  },
3314
- 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
+ },
3315
3551
  });
3316
3552
  }
3317
3553
  /**
@@ -3405,6 +3641,13 @@ function configAttrs(kind, config, refs) {
3405
3641
  attrs.code = raw;
3406
3642
  continue;
3407
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
+ }
3408
3651
  // execute_script input values: provider Read stores Mobius-normalized
3409
3652
  // short names for on-demand scalars. Keep that envelope here only —
3410
3653
  // templates, notifications, and other attrs still use refs["…"].
@@ -3415,9 +3658,22 @@ function configAttrs(kind, config, refs) {
3415
3658
  if (!isObject(item) || typeof item.name !== "string") {
3416
3659
  throw new EntityTfError("invalid executeScript input");
3417
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
+ }
3418
3674
  const mapped = {
3419
3675
  name: item.name,
3420
- value: executeScriptInputValueToTf(item.value, refs),
3676
+ value: inputValue,
3421
3677
  };
3422
3678
  if (item.field_mappings !== undefined) {
3423
3679
  mapped.field_mappings = valueToTf(item.field_mappings, refs);
@@ -3746,7 +4002,7 @@ function configAttrs(kind, config, refs) {
3746
4002
  if (fieldToken?.fieldType !== "MULTI_PICKLIST" && !rawIdClear) {
3747
4003
  throw new EntityTfError(`automation field "${fieldToken?.name ?? fieldToken?.refName ?? "unknown"}" uses an array value but is not a Multi-Select field`);
3748
4004
  }
3749
- 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));
3750
4006
  return {
3751
4007
  field_id: valueToTf(field.aspectFieldId, refs),
3752
4008
  value: expr.jsonencode(values),
@@ -3755,7 +4011,7 @@ function configAttrs(kind, config, refs) {
3755
4011
  }
3756
4012
  assertLiteralFitsFieldType(staticValue, fieldToken);
3757
4013
  const optionValue = staticValue !== undefined
3758
- ? picklistFilterValueToTf(staticValue, fieldToken, refs)
4014
+ ? picklistAssignmentValueToTf(staticValue, fieldToken, refs)
3759
4015
  : undefined;
3760
4016
  let reference = field.valueReference;
3761
4017
  if (typeof reference === "string") {
@@ -3980,6 +4236,7 @@ export function automationToTf(entity, ctx) {
3980
4236
  ownerHandle: ctx.ownerHandle,
3981
4237
  appTfLabel: ctx.appTfLabel,
3982
4238
  automationTfLabel,
4239
+ ...(ctx.optionIds !== undefined ? { optionIds: ctx.optionIds } : {}),
3983
4240
  pulledLive: ctx.workspaceAspects
3984
4241
  ?.get(workspaceAspectKey(ctx.parentScope ?? "app", ctx.appRefName ?? entity.parent))
3985
4242
  ?.pulledAutomationRefNames?.has(entity.refName) === true,
@@ -4232,9 +4489,7 @@ export function automationToTf(entity, ctx) {
4232
4489
  attrs: {
4233
4490
  automation: expr.resourceAttr(AUTOMATION_RESOURCE_TYPE, label),
4234
4491
  ...triggerAttrs,
4235
- ...(OBJECT_FIELD_REFS_TRIGGER_TYPES.has(triggerType)
4236
- ? objectFieldIdsAttr(expr.resourceAttr(owner.parentScope === "element" ? "elementum_element" : "elementum_app", owner.appTfLabel, ["id"]), owner.fieldAddresses)
4237
- : {}),
4492
+ ...(OBJECT_FIELD_REFS_TRIGGER_TYPES.has(triggerType) ? triggerObjectFieldAttrs(owner) : {}),
4238
4493
  },
4239
4494
  };
4240
4495
  const blocks = [automation, trigger];
@@ -4242,7 +4497,7 @@ export function automationToTf(entity, ctx) {
4242
4497
  const runAutomationPublishes = new Set();
4243
4498
  // `enclosingOperator` describes the switch/forkJoin/forEach scope THIS
4244
4499
  // `emitTasks` call is nested inside (undefined at automation top level) -
4245
- // needed only by `unimplementedTask` (edk#821) to populate
4500
+ // needed only by `unimplementedTask` (edk#821, edk#2571) to populate
4246
4501
  // `operator_task_id`/`operator_child_id` correctly regardless of how many
4247
4502
  // real sibling tasks precede the placeholder within the same case/branch
4248
4503
  // (the rolling `taskParent` chain below tracks the PRECEDING SIBLING, not
@@ -4296,8 +4551,15 @@ export function automationToTf(entity, ctx) {
4296
4551
  if (typeof inner.taskType !== "string" || inner.taskType === "") {
4297
4552
  throw new EntityTfError(`unimplementedTask "${refKey}" requires a taskType`);
4298
4553
  }
4299
- const operatorTaskAddress = enclosingOperator?.taskAddress;
4300
- const operatorChildAddress = enclosingOperator?.childAddress;
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
+ };
4301
4563
  // parent_is_trigger is always false on a task reference. The step this
4302
4564
  // placeholder comes after is a local, not this flag: the provider
4303
4565
  // copies the flag onto the following task (edk#2320).
@@ -4308,12 +4570,8 @@ export function automationToTf(entity, ctx) {
4308
4570
  app_id: expr.resourceAttr(owner.parentScope === "element" ? "elementum_element" : "elementum_app", owner.appTfLabel, ["id"]),
4309
4571
  automation_id: expr.resourceAttr(AUTOMATION_RESOURCE_TYPE, label, ["id"]),
4310
4572
  parent_is_trigger: false,
4311
- ...(operatorTaskAddress !== undefined && operatorTaskAddress.$expr === "resource-attr"
4312
- ? { operator_task_id: expr.resourceAttr(operatorTaskAddress.type, operatorTaskAddress.label, ["id"]) }
4313
- : {}),
4314
- ...(operatorChildAddress !== undefined && operatorChildAddress.$expr === "resource-attr"
4315
- ? { operator_child_id: expr.resourceAttr(operatorChildAddress.type, operatorChildAddress.label, ["id"]) }
4316
- : {}),
4573
+ operator_task_id: operatorId(enclosingOperator?.taskAddress),
4574
+ operator_child_id: operatorId(enclosingOperator?.childAddress),
4317
4575
  };
4318
4576
  if (owner.orgRefs !== undefined) {
4319
4577
  owner.orgRefs.rawLookup("elementum_unmanaged_task_reference", tfLabel, displayName, extraAttrs);
@@ -4376,7 +4634,7 @@ export function automationToTf(entity, ctx) {
4376
4634
  name: displayName,
4377
4635
  ...taskAttrs,
4378
4636
  ...(OBJECT_FIELD_REFS_TASK_TYPES.has(resourceType)
4379
- ? objectFieldIdsAttr(taskAttrs["object_id"], taskTargetFieldAddresses(inner.aspectId ?? inner.relatedAspectId, owner))
4637
+ ? taskObjectFieldAttrs(taskAttrs["object_id"], taskTargetFieldAddresses(inner.aspectId ?? inner.relatedAspectId, owner))
4380
4638
  : {}),
4381
4639
  };
4382
4640
  if (wireType === "executeScript") {
@@ -4419,7 +4677,8 @@ export function automationToTf(entity, ctx) {
4419
4677
  const children = task.children ?? [];
4420
4678
  if (children.length !== 1)
4421
4679
  throw new EntityTfError(`forEach task "${refKey}" must have exactly one child body`);
4422
- emitTasks(children[0].tasks ?? [], expr.resourceAttr(resourceType, tfLabel, ["inner"]), { taskAddress: expr.resourceAttr(resourceType, tfLabel) }, refKey);
4680
+ const loopTask = expr.resourceAttr(resourceType, tfLabel);
4681
+ emitTasks(children[0].tasks ?? [], expr.resourceAttr(resourceType, tfLabel, ["inner"]), { taskAddress: loopTask, childAddress: loopTask }, refKey);
4423
4682
  // The loop body is a separate operator-owned chain. A fluent sibling
4424
4683
  // authored after `forEach` continues from the for_each task itself,
4425
4684
  // not from the body's terminal task; the latter silently moves that
@@ -4562,6 +4821,7 @@ export function automationToTf(entity, ctx) {
4562
4821
  };
4563
4822
  blocks.push(publish);
4564
4823
  }
4824
+ setRefsRead(blocks);
4565
4825
  const secretBlocks = [...refs.requiredSecrets].sort().map(requiredSecretVariableBlock);
4566
4826
  return { blocks: [...secretBlocks, ...[...dataBlocks.values()].sort((a, b) => (a.type + "." + a.label).localeCompare(b.type + "." + b.label)), ...blocks], address: AUTOMATION_RESOURCE_TYPE + "." + label };
4567
4827
  }