@elementumai/edk 0.9.19 → 0.9.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (176) hide show
  1. package/README.md +146 -6
  2. package/dist-sdk/src/catalog/factories.d.ts +24 -1
  3. package/dist-sdk/src/catalog/factories.js +30 -0
  4. package/dist-sdk/src/catalog/from-authoring.d.ts +13 -8
  5. package/dist-sdk/src/catalog/from-authoring.js +34 -9
  6. package/dist-sdk/src/catalog/index.d.ts +2 -2
  7. package/dist-sdk/src/catalog/index.js +2 -2
  8. package/dist-sdk/src/catalog/render.js +6 -6
  9. package/dist-sdk/src/catalog/token.js +7 -0
  10. package/dist-sdk/src/catalog/types.d.ts +34 -1
  11. package/dist-sdk/src/catalog/types.js +11 -0
  12. package/dist-sdk/src/core/triggers/on-demand.d.ts +39 -3
  13. package/dist-sdk/src/core/triggers/on-demand.js +10 -2
  14. package/dist-sdk/src/engine/build/context.d.ts +1 -1
  15. package/dist-sdk/src/engine/ei/run.d.ts +149 -0
  16. package/dist-sdk/src/engine/ei/run.js +1132 -0
  17. package/dist-sdk/src/engine/logging.d.ts +17 -0
  18. package/dist-sdk/src/engine/logging.js +18 -0
  19. package/dist-sdk/src/engine/pull/ref-only.d.ts +5 -0
  20. package/dist-sdk/src/engine/pull/ref-only.js +10 -7
  21. package/dist-sdk/src/engine/pull/result-output.d.ts +6 -0
  22. package/dist-sdk/src/engine/pull/result-output.js +87 -3
  23. package/dist-sdk/src/engine/tf/expr.js +1 -1
  24. package/dist-sdk/src/engine/tf/index.d.ts +2 -2
  25. package/dist-sdk/src/engine/tf/index.js +1 -1
  26. package/dist-sdk/src/engine/tf/labels.d.ts +6 -0
  27. package/dist-sdk/src/engine/tf/labels.js +9 -0
  28. package/dist-sdk/src/engine/tf/model.d.ts +22 -1
  29. package/dist-sdk/src/engine/tf/parse.js +92 -4
  30. package/dist-sdk/src/engine/tf/render.d.ts +4 -2
  31. package/dist-sdk/src/engine/tf/render.js +41 -7
  32. package/dist-sdk/src/engine/validation.d.ts +39 -0
  33. package/dist-sdk/src/engine/validation.js +85 -0
  34. package/dist-sdk/src/entities/access-policy/to-tf.js +5 -2
  35. package/dist-sdk/src/entities/agent/build.d.ts +4 -16
  36. package/dist-sdk/src/entities/agent/build.js +40 -5
  37. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +4 -2
  38. package/dist-sdk/src/entities/agent/to-tf.js +6 -3
  39. package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +2 -0
  40. package/dist-sdk/src/entities/agent-tool/from-tf.js +7 -1
  41. package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +2 -2
  42. package/dist-sdk/src/entities/agent-tool/to-tf.js +27 -5
  43. package/dist-sdk/src/entities/app/build.d.ts +89 -20
  44. package/dist-sdk/src/entities/app/build.js +51 -6
  45. package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +16 -0
  46. package/dist-sdk/src/entities/app/from-tf.d.ts +1 -0
  47. package/dist-sdk/src/entities/app/from-tf.js +7 -2
  48. package/dist-sdk/src/entities/app/index.d.ts +6 -6
  49. package/dist-sdk/src/entities/app/index.js +1 -0
  50. package/dist-sdk/src/entities/app/module.js +5 -2
  51. package/dist-sdk/src/entities/app/to-tf.js +19 -11
  52. package/dist-sdk/src/entities/automation/build.d.ts +47 -5
  53. package/dist-sdk/src/entities/automation/build.js +137 -20
  54. package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +24 -1
  55. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +314 -39
  56. package/dist-sdk/src/entities/automation/from-tf.d.ts +28 -6
  57. package/dist-sdk/src/entities/automation/from-tf.js +428 -48
  58. package/dist-sdk/src/entities/automation/generated/task-output-contracts.d.ts +33 -0
  59. package/dist-sdk/src/entities/automation/generated/task-output-contracts.js +183 -0
  60. package/dist-sdk/src/entities/automation/index.d.ts +2 -2
  61. package/dist-sdk/src/entities/automation/index.js +1 -1
  62. package/dist-sdk/src/entities/automation/module.js +37 -8
  63. package/dist-sdk/src/entities/automation/output-field-types.d.ts +7 -0
  64. package/dist-sdk/src/entities/automation/output-field-types.js +36 -0
  65. package/dist-sdk/src/entities/automation/output-key-wire-name.d.ts +9 -0
  66. package/dist-sdk/src/entities/automation/output-key-wire-name.js +13 -0
  67. package/dist-sdk/src/entities/automation/script-code.d.ts +17 -0
  68. package/dist-sdk/src/entities/automation/script-code.js +91 -5
  69. package/dist-sdk/src/entities/automation/system-ref-name.js +4 -0
  70. package/dist-sdk/src/entities/automation/task-output-labels.d.ts +2 -0
  71. package/dist-sdk/src/entities/automation/task-output-labels.js +9 -0
  72. package/dist-sdk/src/entities/automation/tasks.d.ts +24 -2
  73. package/dist-sdk/src/entities/automation/tasks.js +38 -9
  74. package/dist-sdk/src/entities/automation/to-tf.d.ts +4 -0
  75. package/dist-sdk/src/entities/automation/to-tf.js +489 -83
  76. package/dist-sdk/src/entities/automation/triggers.d.ts +4 -2
  77. package/dist-sdk/src/entities/automation/triggers.js +4 -0
  78. package/dist-sdk/src/entities/chart/to-tf.js +10 -3
  79. package/dist-sdk/src/entities/dynamic-layout/build.d.ts +24 -31
  80. package/dist-sdk/src/entities/element/build.d.ts +25 -13
  81. package/dist-sdk/src/entities/element/build.js +4 -1
  82. package/dist-sdk/src/entities/element/from-tf.d.ts +11 -0
  83. package/dist-sdk/src/entities/element/from-tf.js +58 -1
  84. package/dist-sdk/src/entities/element/index.d.ts +5 -3
  85. package/dist-sdk/src/entities/element/index.js +1 -0
  86. package/dist-sdk/src/entities/element/module.js +9 -3
  87. package/dist-sdk/src/entities/element/to-tf.js +8 -2
  88. package/dist-sdk/src/entities/field/build.d.ts +14 -1
  89. package/dist-sdk/src/entities/field/build.js +3 -0
  90. package/dist-sdk/src/entities/field/from-tf.d.ts +1 -0
  91. package/dist-sdk/src/entities/field/from-tf.js +39 -1
  92. package/dist-sdk/src/entities/field/media-types.d.ts +6 -0
  93. package/dist-sdk/src/entities/field/media-types.js +30 -0
  94. package/dist-sdk/src/entities/field/module.js +1 -0
  95. package/dist-sdk/src/entities/field/to-tf.d.ts +23 -2
  96. package/dist-sdk/src/entities/field/to-tf.js +130 -14
  97. package/dist-sdk/src/entities/file-reader/from-tf.js +14 -5
  98. package/dist-sdk/src/entities/file-reader/module.js +1 -0
  99. package/dist-sdk/src/entities/file-reader/types.d.ts +2 -0
  100. package/dist-sdk/src/entities/file-reader/types.js +1 -1
  101. package/dist-sdk/src/entities/portal/build.d.ts +26 -0
  102. package/dist-sdk/src/entities/portal/build.js +37 -0
  103. package/dist-sdk/src/entities/portal/from-tf.d.ts +27 -0
  104. package/dist-sdk/src/entities/portal/from-tf.js +75 -0
  105. package/dist-sdk/src/entities/portal/index.d.ts +1 -0
  106. package/dist-sdk/src/entities/portal/index.js +1 -0
  107. package/dist-sdk/src/entities/portal/module.d.ts +3 -0
  108. package/dist-sdk/src/entities/portal/module.js +28 -0
  109. package/dist-sdk/src/entities/portal/to-tf.d.ts +12 -0
  110. package/dist-sdk/src/entities/portal/to-tf.js +73 -0
  111. package/dist-sdk/src/entities/portal/types.d.ts +1 -0
  112. package/dist-sdk/src/entities/portal/types.js +1 -0
  113. package/dist-sdk/src/entities/relationship/module.js +2 -0
  114. package/dist-sdk/src/entities/relationship/pair-check.d.ts +7 -0
  115. package/dist-sdk/src/entities/relationship/pair-check.js +68 -0
  116. package/dist-sdk/src/entities/relationship/to-tf.d.ts +2 -0
  117. package/dist-sdk/src/entities/relationship/to-tf.js +12 -3
  118. package/dist-sdk/src/entities/search-table/module.js +1 -0
  119. package/dist-sdk/src/entities/search-table/to-tf.d.ts +1 -0
  120. package/dist-sdk/src/entities/search-table/to-tf.js +1 -1
  121. package/dist-sdk/src/entities/service-account/build.d.ts +15 -2
  122. package/dist-sdk/src/entities/service-account/from-tf.d.ts +2 -4
  123. package/dist-sdk/src/entities/service-account/from-tf.js +17 -5
  124. package/dist-sdk/src/entities/service-account/role-fidelity.d.ts +56 -0
  125. package/dist-sdk/src/entities/service-account/role-fidelity.js +243 -0
  126. package/dist-sdk/src/entities/service-account/to-tf.d.ts +14 -0
  127. package/dist-sdk/src/entities/service-account/to-tf.js +17 -0
  128. package/dist-sdk/src/entities/shared/aspect-target-from-tf.d.ts +1 -1
  129. package/dist-sdk/src/entities/shared/aspect-target-from-tf.js +5 -2
  130. package/dist-sdk/src/entities/shared/filters/ast.d.ts +8 -0
  131. package/dist-sdk/src/entities/shared/filters/index.d.ts +2 -0
  132. package/dist-sdk/src/entities/shared/filters/index.js +14 -4
  133. package/dist-sdk/src/entities/shared/filters/print.js +17 -1
  134. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +2 -0
  135. package/dist-sdk/src/entities/shared/filters/tf-codec.js +5 -1
  136. package/dist-sdk/src/entities/shared/filters/types.d.ts +9 -1
  137. package/dist-sdk/src/entities/shared/types/field-types.d.ts +10 -5
  138. package/dist-sdk/src/entities/shared/types/field-types.js +4 -0
  139. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +2 -1
  140. package/dist-sdk/src/entities/skill/from-tf.js +66 -13
  141. package/dist-sdk/src/entities/skill/input-coverage.d.ts +7 -0
  142. package/dist-sdk/src/entities/skill/input-coverage.js +11 -0
  143. package/dist-sdk/src/entities/skill/to-tf.js +14 -4
  144. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +2 -0
  145. package/dist-sdk/src/entities/skill-tool/from-tf.js +8 -2
  146. package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +2 -2
  147. package/dist-sdk/src/entities/skill-tool/to-tf.js +27 -5
  148. package/dist-sdk/src/entities/table/catalog.d.ts +14 -0
  149. package/dist-sdk/src/entities/table/catalog.js +66 -0
  150. package/dist-sdk/src/entities/table/module.js +2 -1
  151. package/dist-sdk/src/entities/table/to-tf.js +2 -2
  152. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.d.ts +49 -9
  153. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.js +71 -18
  154. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.d.ts +19 -4
  155. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.js +82 -10
  156. package/dist-sdk/src/entities/view/agent-view-layout.d.ts +53 -23
  157. package/dist-sdk/src/entities/view/agent-view-layout.js +1 -1
  158. package/dist-sdk/src/entities/view/from-tf.d.ts +3 -2
  159. package/dist-sdk/src/entities/view/from-tf.js +124 -12
  160. package/dist-sdk/src/entities/view/module.js +30 -3
  161. package/dist-sdk/src/entities/view/to-tf.d.ts +14 -1
  162. package/dist-sdk/src/entities/view/to-tf.js +67 -10
  163. package/dist-sdk/src/entities/view/types.d.ts +4 -15
  164. package/dist-sdk/src/entities/view/types.js +15 -15
  165. package/dist-sdk/src/entities/widget/build.d.ts +16 -1
  166. package/dist-sdk/src/entities/widget/build.js +11 -1
  167. package/dist-sdk/src/entities/widget/to-tf.js +34 -8
  168. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +16 -5
  169. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
  170. package/dist-sdk/src/graph/index.d.ts +11 -0
  171. package/dist-sdk/src/graph/index.js +21 -0
  172. package/dist-sdk/src/graph/modules.js +2 -0
  173. package/dist-sdk/src/graph/types.d.ts +55 -2
  174. package/dist-sdk/src/internal/sdk-package.d.ts +1 -1
  175. package/dist-sdk/src/internal/sdk-package.js +1 -0
  176. package/package.json +10 -1
@@ -1,7 +1,9 @@
1
1
  import { EntityTfError, recordFieldContextOf } from "../../engine/entity.js";
2
- import { DEPLOY_DEFAULT_SYSTEM_FIELD_NAMES, SYSTEM_FIELD_KEY_SET } from "../../core/system-fields.js";
2
+ import { ValidationFailureError } from "../../engine/validation.js";
3
+ import { DEPLOY_DEFAULT_SYSTEM_FIELD_NAMES, SYSTEM_FIELD_KEY_SET, SYSTEM_FIELD_KEYS } from "../../core/system-fields.js";
4
+ import { ELEMENT_AUDIT_SYSTEM_FIELD_KEYS } from "../element/system-fields.js";
3
5
  import { isUnsafePlatformId } from "../../core/platform-id.js";
4
- import { appResourceLabelPrefix, appScopedResourceLabel, expr, isTfExpr, isUuid, sanitizeName, scopedResourceLabel, tfLabelToTsLabel, tsLabelToTfLabel, } from "../../engine/tf/index.js";
6
+ import { appResourceLabelPrefix, appScopedResourceLabel, expr, isTfExpr, isUuid, sanitizeName, stableIdSuffix, scopedResourceLabel, tfLabelToTsLabel, tsLabelToTfLabel, } from "../../engine/tf/index.js";
5
7
  import { workspaceAspectKey } from "../../engine/build/context.js";
6
8
  import { SEARCH_TABLE_RESOURCE_TYPES } from "../search-table/types.js";
7
9
  import { fieldRefToTfValue } from "../field/to-tf.js";
@@ -11,16 +13,30 @@ import { filterToTf as serializeFilterToTf } from "../shared/filters/tf-codec.js
11
13
  import { referenceValueTypeForField } from "../shared/filters/index.js";
12
14
  import { API_TASK_REF_AUTHORING_NAMES, API_TASK_REF_WIRE_NAMES } from "./output-key-wire-name.js";
13
15
  import { outputFieldTypesFromScriptSchema, scriptOutputReferenceIsDeclared } from "./output-field-types.js";
16
+ import { RESOURCE_TYPE_TO_EXECUTOR, TASK_OUTPUT_CONTRACTS } from "./generated/task-output-contracts.js";
14
17
  import { CONNECTOR_ORG_BAG } from "../org/connector.js";
15
18
  import { FILE_READER_SUB_TYPE_BY_RESOURCE, FILE_READER_SUB_TYPE_BY_TYPE_KEY } from "../file-reader/types.js";
16
19
  import { UNRESOLVED_FIELD_MARKER } from "../shared/ref.js";
20
+ import { ELEMENT_SYSTEM_FIELD_KEYS } from "../element/system-fields.js";
17
21
  import { TABLE_RESOURCE_TYPE } from "../table/module.js";
18
22
  import { AUTOMATION_RESOURCE_TYPE, WORKFLOW_PUBLISH_RESOURCE_TYPE } from "./types.js";
19
- import { TASK_OUTPUT_REFERENCE_NAMES, USER_SEARCH_REF_WIRE_NAMES } from "./task-output-labels.js";
23
+ import { AI_SEARCH_TABLE_OUTPUT_NAMES, TASK_OUTPUT_REFERENCE_NAMES, USER_SEARCH_REF_WIRE_NAMES } from "./task-output-labels.js";
20
24
  import { onDemandTriggerRefKey } from "./value-ref-tf.js";
25
+ import { normalizeOnDemandParamKey } from "../../../pull/util.js";
21
26
  import { PROVIDER_FIXED_SYSTEM_FIELD_KEYS, recordFieldWireRefName } from "./system-ref-name.js";
22
27
  import { taskTfLabel } from "./task-label.js";
23
28
  import { isOnDemandRecordType } from "../shared/types/field-types.js";
29
+ /** The context for reading records of `appRefName` (a `kind`), retargeted from the owner. */
30
+ function recordOwnerContext(owner, appRefName, kind, fieldNames) {
31
+ if (appRefName === owner.appRefName && (kind === undefined || kind === owner.parentScope))
32
+ return owner;
33
+ return {
34
+ ...owner,
35
+ appRefName,
36
+ fieldNames: fieldNames ?? new Map(),
37
+ recordLacksAuditFields: kind === "element" && owner.elementsWithoutAuditFields?.has(appRefName) === true,
38
+ };
39
+ }
24
40
  function scopedLabel(appTfLabel, label) {
25
41
  return appScopedResourceLabel(appTfLabel, label);
26
42
  }
@@ -167,6 +183,7 @@ const CONFIG_ATTRS = {
167
183
  categorySource: "category_source",
168
184
  titleReference: "title",
169
185
  messageReference: "message",
186
+ descriptionReference: "description",
170
187
  notifyWatchers: "notify_watchers",
171
188
  fieldId: "field_id",
172
189
  userId: "user_id",
@@ -376,7 +393,7 @@ function crossAppFieldToTf(value, ctx, dataBlocks) {
376
393
  // table-owned search table has to be distinguishable from an element-owned
377
394
  // one.
378
395
  if (sibling !== undefined && sibling.kind !== "table" && sibling.kind !== "task") {
379
- const fieldValue = fieldRefToTfValue(value.fieldType ?? "", value.refName, sibling.tfLabel, sibling.kind);
396
+ const fieldValue = fieldRefToTfValue(value.fieldType ?? "", value.refName, sibling.tfLabel, sibling.kind, sibling.kind === "element" ? fieldNamesForAppRefName(ctx.fieldAddressesByAppRefName, value.parent) : undefined);
380
397
  if (fieldValue === undefined) {
381
398
  throw new EntityTfError(`field ref "${value.refName}" on sibling ${sibling.kind} "${value.parent}" has no terraform field resource mapping (fieldType ${JSON.stringify(value.fieldType ?? "")})`);
382
399
  }
@@ -759,14 +776,49 @@ function tokenToTf(value, ctx, dataBlocks) {
759
776
  const variant = value.__variant ?? "snowflake";
760
777
  const element = aspects.get(workspaceAspectKey("element", owner));
761
778
  const table = aspects.get(workspaceAspectKey("table", owner));
762
- if (variant === "table") {
763
- if (table === undefined) {
764
- throw new EntityTfError(`search table "${owner}.${value.refName}" is table-owned, but "${owner}" is not a table in this build` +
765
- `${element !== undefined ? ` (it is an element — use searchTable, not tableSearchTable)` : ""}`);
766
- }
779
+ const pinnedId = typeof value.id === "string" && value.id !== "" ? value.id : undefined;
780
+ if (variant === "table" && table !== undefined && pinnedId === undefined) {
767
781
  // Label shape mirrors search-table/to-tf.ts's own table branch.
768
782
  return expr.resourceAttr(SEARCH_TABLE_RESOURCE_TYPES.table, `tables_${table.tfLabel}_${tsLabelToTfLabel(value.refName)}`, ["id"]);
769
783
  }
784
+ // A table outside this build has no managed elementum_table_search_table.
785
+ // Pin by id when the name is ambiguous; otherwise keep the name lookup
786
+ // a unique name already used. An element that merely shares the refName
787
+ // is still the wrong owner.
788
+ if (variant === "table") {
789
+ if (pinnedId === undefined && element !== undefined) {
790
+ throw new EntityTfError(`search table "${owner}.${value.refName}" is table-owned, but "${owner}" is not a table in this build (it is an element — use searchTable, not tableSearchTable)`);
791
+ }
792
+ const tableName = typeof value.parentName === "string" && value.parentName !== "" ? value.parentName : owner;
793
+ const tableLabel = sanitizeName(tableName);
794
+ const searchName = value.name ?? value.refName;
795
+ const label = pinnedId === undefined
796
+ ? `${tableLabel}_${sanitizeName(searchName)}`
797
+ : `${tableLabel}_${sanitizeName(searchName)}_${stableIdSuffix(pinnedId)}`;
798
+ const tableId = expr.dataAttr(TABLE_RESOURCE_TYPE, tableLabel, ["id"]);
799
+ const searchAttrs = { table_id: tableId, name: searchName };
800
+ if (pinnedId !== undefined)
801
+ searchAttrs.id = pinnedId;
802
+ if (ctx.orgRefs !== undefined) {
803
+ ctx.orgRefs.rawLookup(TABLE_RESOURCE_TYPE, tableLabel, tableName);
804
+ ctx.orgRefs.rawLookup("elementum_search_table", label, searchName, searchAttrs);
805
+ }
806
+ else {
807
+ dataBlocks.set(`${TABLE_RESOURCE_TYPE}.${tableLabel}`, {
808
+ kind: "data",
809
+ type: TABLE_RESOURCE_TYPE,
810
+ label: tableLabel,
811
+ attrs: { name: tableName },
812
+ });
813
+ dataBlocks.set(`elementum_search_table.${label}`, {
814
+ kind: "data",
815
+ type: "elementum_search_table",
816
+ label,
817
+ attrs: searchAttrs,
818
+ });
819
+ }
820
+ return expr.dataAttr("elementum_search_table", label, ["id"]);
821
+ }
770
822
  if (element !== undefined) {
771
823
  return expr.resourceAttr(SEARCH_TABLE_RESOURCE_TYPES[variant], scopedResourceLabel(element.tfLabel, tsLabelToTfLabel(value.refName), "element"), ["id"]);
772
824
  }
@@ -1088,6 +1140,9 @@ function foundRecordFieldReferenceName(targetType, name, taskRefKey, refs) {
1088
1140
  }
1089
1141
  }
1090
1142
  function calculationTriggerMustache(name, refs) {
1143
+ const onDemandName = onDemandTriggerRefName(name, refs);
1144
+ if (onDemandName !== undefined)
1145
+ return [`{{trigger name="${onDemandName}"}}`];
1091
1146
  const parts = name.split(".");
1092
1147
  if (parts[0] !== "record" || parts.length < 2) {
1093
1148
  return [`{{trigger name="${name}"}}`];
@@ -1223,6 +1278,14 @@ function wireRefName(name, ctx) {
1223
1278
  const systemFieldKey = SYSTEM_FIELD_KEY_SET.has(fieldKey)
1224
1279
  ? fieldKey
1225
1280
  : undefined;
1281
+ if (systemFieldKey !== undefined &&
1282
+ ctx.recordLacksAuditFields === true &&
1283
+ ELEMENT_AUDIT_SYSTEM_FIELD_KEYS.includes(systemFieldKey) &&
1284
+ !ctx.fieldNames.has(fieldKey)) {
1285
+ throw new EntityTfError(`automation reference "${name}" reads audit field "${systemFieldKey}" on element "${ctx.appRefName}", which has no audit fields. ` +
1286
+ "The platform adds them to apps but only to some elements, and EDK cannot create them. " +
1287
+ "Remove the reference, or set systemFields: { audit: true } on an element the platform did give them to.");
1288
+ }
1226
1289
  const fieldName = systemFieldKey !== undefined && PROVIDER_FIXED_SYSTEM_FIELD_KEYS.has(systemFieldKey)
1227
1290
  ? DEPLOY_DEFAULT_SYSTEM_FIELD_NAMES[systemFieldKey]
1228
1291
  : ctx.fieldNames.get(fieldKey) ??
@@ -1407,15 +1470,11 @@ function taskWireRefName(name, taskRefKey, refs) {
1407
1470
  return handleKey;
1408
1471
  const normalized = normalizeIndexedRecordsFieldPath(name);
1409
1472
  const taskApp = refs.recordFieldContext?.taskAppRefNameByRefKey?.[taskRefKey];
1410
- if (taskApp === undefined || taskApp === refs.owner.appRefName) {
1473
+ if (taskApp === undefined)
1411
1474
  return wireRefName(normalized, refs.owner);
1412
- }
1413
- const foreignNames = fieldNamesForAppRefName(refs.fieldNamesByAppRefName, taskApp);
1414
- return wireRefName(normalized, {
1415
- ...refs.owner,
1416
- appRefName: taskApp,
1417
- fieldNames: foreignNames ?? new Map(),
1418
- });
1475
+ return wireRefName(normalized, recordOwnerContext(refs.owner, taskApp, taskTargetKind(taskRefKey, refs), taskApp === refs.owner.appRefName
1476
+ ? refs.owner.fieldNames
1477
+ : fieldNamesForAppRefName(refs.fieldNamesByAppRefName, taskApp)));
1419
1478
  }
1420
1479
  /**
1421
1480
  * The platform refs-map key for one task output, given the emitting task's
@@ -1444,6 +1503,9 @@ function taskOutputWireRefKey(targetType, name, taskRefKey, refs) {
1444
1503
  if (targetType === "elementum_ai_search_table_task" && (name === "records" || name === "All Records")) {
1445
1504
  return "All Records";
1446
1505
  }
1506
+ if (targetType === "elementum_ai_search_table_task" && AI_SEARCH_TABLE_OUTPUT_NAMES[name] !== undefined) {
1507
+ return AI_SEARCH_TABLE_OUTPUT_NAMES[name][0];
1508
+ }
1447
1509
  // tableRecordsSearch uses yet another wire key: "All matching table rows".
1448
1510
  if (targetType === "elementum_table_records_search_task" &&
1449
1511
  (name === "records" || name === "All matching table rows")) {
@@ -1451,7 +1513,32 @@ function taskOutputWireRefKey(targetType, name, taskRefKey, refs) {
1451
1513
  }
1452
1514
  return taskWireRefName(name, taskRefKey, refs);
1453
1515
  }
1516
+ /** The platform's own on-demand "Triggered By" refs (live refs-map keys). */
1517
+ const ON_DEMAND_TRIGGERED_BY_REFS = {
1518
+ "triggeredBy": "Triggered By's Id",
1519
+ "triggeredBy.id": "Triggered By's Id",
1520
+ "triggeredBy.email": "Triggered By's Email",
1521
+ "triggeredBy.name": "Triggered By's Name",
1522
+ };
1523
+ /**
1524
+ * The refs-map name of an on-demand `ctx.trigger.triggeredBy` read, which
1525
+ * every trigger reference (task input, calculation, publish output) shares.
1526
+ * A userId input has no reference at all, so reading one is refused.
1527
+ */
1528
+ function onDemandTriggerRefName(name, refs) {
1529
+ if (refs.trigger.type !== TRIGGER_RESOURCES.onDemand)
1530
+ return undefined;
1531
+ const userParam = refs.userParamNames.find((param) => name === param || name.startsWith(`${param}.`));
1532
+ if (userParam !== undefined) {
1533
+ throw new EntityTfError(`ctx.trigger.${name}: the platform publishes no reference for on-demand userId input "${userParam}", ` +
1534
+ `so a task cannot read it. Use ctx.trigger.triggeredBy (id/email/name) for the user who ran the automation.`);
1535
+ }
1536
+ return ON_DEMAND_TRIGGERED_BY_REFS[name];
1537
+ }
1454
1538
  function triggerWireRefName(name, refs) {
1539
+ const onDemandName = onDemandTriggerRefName(name, refs);
1540
+ if (onDemandName !== undefined)
1541
+ return onDemandName;
1455
1542
  const scalarParams = refs.triggerParamNames.filter((param) => !refs.recordParamNames.includes(param));
1456
1543
  const declared = onDemandTriggerRefKey(name, scalarParams);
1457
1544
  if (declared !== name || scalarParams.includes(name))
@@ -1480,11 +1567,7 @@ function recordParamFieldWireName(paramName, suffix, refs) {
1480
1567
  const targetFieldNames = targetRefName === refs.owner.appRefName && target.__kind === refs.owner.parentScope
1481
1568
  ? refs.owner.fieldNames
1482
1569
  : fieldNamesForAppRefName(refs.fieldNamesByAppRefName, targetRefName);
1483
- return wireRefName(`record.${suffix}`, {
1484
- ...refs.owner,
1485
- appRefName: targetRefName,
1486
- fieldNames: targetFieldNames ?? new Map(),
1487
- });
1570
+ return wireRefName(`record.${suffix}`, recordOwnerContext(refs.owner, targetRefName, target.__kind === "element" || target.__kind === "app" ? target.__kind : undefined, targetFieldNames));
1488
1571
  }
1489
1572
  /** Run-automation targets reference publish for ACTIVE automations, automation for draft/inactive. */
1490
1573
  export function automationRunTargetResourceAttr(appTfLabel, automationRefName, activeAutomationRefNames) {
@@ -1494,6 +1577,88 @@ export function automationRunTargetResourceAttr(appTfLabel, automationRefName, a
1494
1577
  }
1495
1578
  return expr.resourceAttr(AUTOMATION_RESOURCE_TYPE, label, ["id"]);
1496
1579
  }
1580
+ const UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
1581
+ const ISO_DATE_PATTERN = /^\d{4}-\d{2}-\d{2}$/;
1582
+ /** The provider's `ValidateFieldValue` datetime shape: seconds and a timezone are required. */
1583
+ const ISO_DATETIME_PATTERN = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/;
1584
+ /**
1585
+ * A literal the platform cannot coerce into the target field only fails at
1586
+ * apply. Checked for the field types where free text is never accepted:
1587
+ * user and group fields take ids, date fields ISO dates, datetime fields
1588
+ * ISO timestamps.
1589
+ */
1590
+ function assertLiteralFitsFieldType(value, field) {
1591
+ if (field === undefined || value === undefined)
1592
+ return;
1593
+ const fieldType = field.fieldType;
1594
+ const accepts = {
1595
+ USER: { test: (text) => UUID_PATTERN.test(text), expected: "a user id, or a user reference such as ctx.trigger.record.<userField>" },
1596
+ GROUP: { test: (text) => UUID_PATTERN.test(text), expected: "a group id, or a group reference" },
1597
+ DATE: { test: (text) => ISO_DATE_PATTERN.test(text) && !Number.isNaN(Date.parse(text)), expected: "an ISO date (YYYY-MM-DD) or a date reference" },
1598
+ DATETIME: {
1599
+ test: (text) => ISO_DATETIME_PATTERN.test(text) && !Number.isNaN(Date.parse(text)),
1600
+ expected: "an ISO timestamp with seconds and a timezone (YYYY-MM-DDTHH:MM:SS[.fff]Z or ±HH:MM) or a datetime reference",
1601
+ },
1602
+ };
1603
+ const rule = fieldType === undefined ? undefined : accepts[fieldType];
1604
+ if (rule === undefined)
1605
+ return;
1606
+ const label = field.name ?? field.refName ?? "unknown";
1607
+ if (typeof value !== "string") {
1608
+ throw new EntityTfError(`automation field "${label}" (${fieldType}) is given a ${typeof value} literal; it needs ${rule.expected}`);
1609
+ }
1610
+ // The provider refuses `${...}` templates on these four types too, so a
1611
+ // template string is not left to the platform here.
1612
+ if (rule.test(value))
1613
+ return;
1614
+ throw new EntityTfError(`automation field "${label}" (${fieldType}) is given the text ${JSON.stringify(value)}; it needs ${rule.expected}`);
1615
+ }
1616
+ /**
1617
+ * The platform refuses an element record create that leaves the title system
1618
+ * field empty, but only at apply and only as "Unable to validate". Fields
1619
+ * given by raw id cannot be identified, so those creates are left alone.
1620
+ */
1621
+ function assertElementCreateSetsTitle(target, fields) {
1622
+ if (!isObject(target) || target.__kind !== "element")
1623
+ return;
1624
+ const element = typeof target.name === "string" ? target.name : String(target.refName);
1625
+ let title;
1626
+ for (const field of fields) {
1627
+ if (!isObject(field) || !isObject(field.aspectFieldId) || typeof field.aspectFieldId.__kind !== "string")
1628
+ return;
1629
+ const token = field.aspectFieldId;
1630
+ if (token.tags?.includes("TITLE") === true || token.refName === "title")
1631
+ title = field;
1632
+ }
1633
+ if (title === undefined) {
1634
+ throw new EntityTfError(`createRecord on element "${element}" does not set its title field; the platform requires it and rejects the record at apply ("Unable to validate")`);
1635
+ }
1636
+ const reference = title.valueReference;
1637
+ const staticValue = isObject(reference) && "value" in reference ? reference.value : undefined;
1638
+ if (reference === undefined || reference === null || staticValue === "" || staticValue === null) {
1639
+ throw new EntityTfError(`createRecord on element "${element}" sets its title field to an empty value; the platform requires a title and rejects the record at apply ("Unable to validate")`);
1640
+ }
1641
+ }
1642
+ /**
1643
+ * The platform publishes outputs only from tasks at the top level of the
1644
+ * workflow, never from a task inside a switch case or for-each loop, and
1645
+ * rejects an output whose task is not in the workflow at all.
1646
+ */
1647
+ function assertPublishableOutputTask(outputName, value, topLevelTasks, refs) {
1648
+ while (isObject(value) && "value" in value && Object.keys(value).length === 1) {
1649
+ value = value.value;
1650
+ }
1651
+ if (!isObject(value) || !isObject(value.taskReference) || typeof value.taskReference.taskRefKey !== "string")
1652
+ return;
1653
+ const taskRefKey = value.taskReference.taskRefKey;
1654
+ if (!refs.tasks.has(taskRefKey)) {
1655
+ throw new EntityTfError(`automation output "${outputName}" references task "${taskRefKey}", which is not in this automation`);
1656
+ }
1657
+ if (!topLevelTasks.some((task) => task.refKey === taskRefKey)) {
1658
+ throw new EntityTfError(`automation output "${outputName}" references task "${taskRefKey}" inside a switch case or for-each loop; ` +
1659
+ "the platform publishes outputs only from top-level tasks. Copy the value into a variable at the top level and output that.");
1660
+ }
1661
+ }
1497
1662
  /**
1498
1663
  * workflow_publish outputs must match provider Read / ei export: a typed
1499
1664
  * `jsonencode({ fieldType, multiple, taskReference|... })` envelope — not
@@ -1554,55 +1719,92 @@ function createRecordOwnFieldRefTfValue(target, name, refs) {
1554
1719
  return undefined;
1555
1720
  return expr.template(["record.", fieldId, `.${suffix}`]);
1556
1721
  }
1722
+ /**
1723
+ * The canonical reference envelope for a workflow-OUTPUT task reference —
1724
+ * `{ fieldType, multiple, taskReference:{ name:<canonical>, taskId }, … }`.
1725
+ * By the time an output reaches here its `taskReference.name` is already the
1726
+ * platform's CANONICAL service_tasks output name (build.ts's
1727
+ * `rewriteCanonicalOutputRefName`): the platform validates the published output
1728
+ * against that name (edk#835), so EDK emits it directly instead of the refs-map
1729
+ * display label. The exceptions keep their existing resolution, since they
1730
+ * reference FIELDS / declared values by EDK-owned names, not the mobius
1731
+ * display-label drift class: a task's own record field (`record.<field>`),
1732
+ * aiAgent (platform-nested via {@link aiAgentPlatformRefName}), and file-reader
1733
+ * (arbitrary schema field names). `fieldType`/`multiple` come from the generated
1734
+ * service_tasks contract (via {@link publishOutputType}). Returns undefined when
1735
+ * the target task is unresolved so the caller keeps its own fallback.
1736
+ */
1737
+ function taskReferenceEnvelope(value, refs) {
1738
+ const taskRef = value.taskReference;
1739
+ if (taskRef.name.includes('"')) {
1740
+ throw new EntityTfError(`task output name "${taskRef.name}" contains a double quote`);
1741
+ }
1742
+ const target = refs.tasks.get(taskRef.taskRefKey);
1743
+ if (target === undefined)
1744
+ return undefined;
1745
+ const canonicalName = taskRef.name;
1746
+ const isFileReaderTask = target.type === "elementum_ai_file_read_task" || target.type === "elementum_file_reader_task";
1747
+ const isAiAgentTask = target.type === "elementum_ai_agent_task";
1748
+ // A task's OWN just-created/found record FIELD (`record.<field>`) is not a
1749
+ // task-output name — it resolves by the field's own id/display name. No
1750
+ // canonical output is ever spelled `record.<field>` (the contract has
1751
+ // record/records/recordId), so that dotted prefix uniquely marks it.
1752
+ const isOwnRecordFieldRef = canonicalName.startsWith("record.");
1753
+ const ownRecordFieldRef = createRecordOwnFieldRefTfValue(target, canonicalName, refs);
1754
+ const platformRefName = ownRecordFieldRef
1755
+ ?? (isFileReaderTask
1756
+ ? canonicalName
1757
+ : isOwnRecordFieldRef
1758
+ ? taskWireRefName(canonicalName, taskRef.taskRefKey, refs)
1759
+ : isAiAgentTask
1760
+ ? aiAgentPlatformRefName(canonicalName)
1761
+ : canonicalName);
1762
+ const typed = publishOutputType(value, target, canonicalName);
1763
+ return {
1764
+ fieldType: typed.fieldType,
1765
+ multiple: typed.multiple,
1766
+ taskReference: {
1767
+ name: platformRefName,
1768
+ taskId: expr.resourceAttr(target.type, target.label, ["id"]),
1769
+ },
1770
+ // ei export always pads the unused reference arms with null.
1771
+ triggerReference: null,
1772
+ variableReference: null,
1773
+ };
1774
+ }
1557
1775
  function workflowPublishOutputEnvelope(value, refs) {
1558
1776
  if (!isObject(value))
1559
1777
  return undefined;
1560
1778
  if (isObject(value.taskReference) && typeof value.taskReference.taskRefKey === "string" && typeof value.taskReference.name === "string") {
1561
- if (value.taskReference.name.includes('"')) {
1562
- throw new EntityTfError(`task output name "${value.taskReference.name}" contains a double quote`);
1563
- }
1564
- const target = refs.tasks.get(value.taskReference.taskRefKey);
1565
- if (target === undefined)
1566
- return undefined;
1567
- const isFileReaderTask = target.type === "elementum_ai_file_read_task" || target.type === "elementum_file_reader_task";
1568
- const isAiAgentTask = target.type === "elementum_ai_agent_task";
1569
- const isAiSearchTableRecords = target.type === "elementum_ai_search_table_task" &&
1570
- (value.taskReference.name === "records" || value.taskReference.name === "All Records");
1571
- const isTableRecordsSearchRecords = target.type === "elementum_table_records_search_task" &&
1572
- (value.taskReference.name === "records" || value.taskReference.name === "All matching table rows");
1573
- const refsKey = isFileReaderTask || isAiAgentTask
1574
- ? value.taskReference.name
1575
- : isAiSearchTableRecords
1576
- ? "All Records"
1577
- : isTableRecordsSearchRecords
1578
- ? value.taskReference.name === "All matching table rows"
1579
- ? "All matching table rows"
1580
- : "records"
1581
- : taskWireRefName(value.taskReference.name, value.taskReference.taskRefKey, refs);
1582
- const ownRecordFieldRef = createRecordOwnFieldRefTfValue(target, value.taskReference.name, refs);
1583
- const platformRefName = ownRecordFieldRef ?? (isAiAgentTask
1584
- ? aiAgentPlatformRefName(refsKey)
1585
- : refsKey);
1586
- const typed = publishOutputType(value, target, refsKey);
1587
- return {
1588
- fieldType: typed.fieldType,
1589
- multiple: typed.multiple,
1590
- taskReference: {
1591
- name: platformRefName,
1592
- taskId: expr.resourceAttr(target.type, target.label, ["id"]),
1593
- },
1594
- // ei export always pads the unused reference arms with null.
1595
- triggerReference: null,
1596
- variableReference: null,
1597
- };
1779
+ return taskReferenceEnvelope(value, refs);
1598
1780
  }
1599
1781
  if (isObject(value.triggerReference) && typeof value.triggerReference.name === "string") {
1782
+ const inputName = onDemandTriggerRefKey(value.triggerReference.name, [...refs.triggerParamFieldTypes.keys()]);
1783
+ const input = refs.triggerParamFieldTypes.get(inputName);
1784
+ if (input !== undefined) {
1785
+ // The platform stores a reference to an on-demand input under the
1786
+ // input's normalized name ("TICKET_ID" → "ticketId") and reads it back
1787
+ // that way, so emit that name rather than the declared one; the
1788
+ // envelope carries the input's declared type.
1789
+ const typed = typeof value.fieldType === "string"
1790
+ ? { fieldType: value.fieldType, multiple: value.multiple === true }
1791
+ : input;
1792
+ return {
1793
+ fieldType: typed.fieldType,
1794
+ multiple: typed.multiple,
1795
+ taskReference: null,
1796
+ triggerReference: { name: normalizeOnDemandParamKey(inputName) },
1797
+ variableReference: null,
1798
+ };
1799
+ }
1600
1800
  const typed = publishOutputType(value, undefined, value.triggerReference.name);
1601
1801
  return {
1602
1802
  fieldType: typed.fieldType,
1603
1803
  multiple: typed.multiple,
1604
1804
  taskReference: null,
1605
- triggerReference: { name: wireRefName(value.triggerReference.name, refs.owner) },
1805
+ triggerReference: {
1806
+ name: onDemandTriggerRefName(value.triggerReference.name, refs) ?? wireRefName(value.triggerReference.name, refs.owner),
1807
+ },
1606
1808
  variableReference: null,
1607
1809
  };
1608
1810
  }
@@ -1670,6 +1872,16 @@ function publishOutputType(value, target, wireName) {
1670
1872
  if (fromSchema !== undefined)
1671
1873
  return fromSchema;
1672
1874
  }
1875
+ // Canonical reference model: for a workflow OUTPUT, `wireName` is the platform's
1876
+ // canonical output name — take fieldType + multiple straight from the generated
1877
+ // service_tasks contract. The display-name heuristics below stay for the legacy
1878
+ // forms. See DESIGN-canonical-reference-model.md.
1879
+ if (target !== undefined) {
1880
+ const executor = RESOURCE_TYPE_TO_EXECUTOR[target.type];
1881
+ const contract = executor !== undefined ? TASK_OUTPUT_CONTRACTS[executor]?.[wireName] : undefined;
1882
+ if (contract !== undefined)
1883
+ return { fieldType: contract.fieldType, multiple: contract.multiple };
1884
+ }
1673
1885
  if (target !== undefined) {
1674
1886
  if ((target.type === "elementum_create_record_task" || target.type === "elementum_find_related_records_task") &&
1675
1887
  (wireName === "Record" || wireName === "Record ID")) {
@@ -1686,6 +1898,38 @@ function publishOutputType(value, target, wireName) {
1686
1898
  }
1687
1899
  return { fieldType: "TEXT", multiple: value.multiple === true };
1688
1900
  }
1901
+ function collectUnresolvedForEachItems(value, found) {
1902
+ if (Array.isArray(value)) {
1903
+ for (const item of value)
1904
+ collectUnresolvedForEachItems(item, found);
1905
+ return;
1906
+ }
1907
+ if (!isObject(value))
1908
+ return;
1909
+ if (typeof value.__edkUnresolvedForEachItem === "string") {
1910
+ const path = Array.isArray(value.path) ? value.path.filter((segment) => typeof segment === "string").join(".") : "";
1911
+ found.push({ ref: value.__edkUnresolvedForEachItem, path });
1912
+ }
1913
+ for (const nested of Object.values(value))
1914
+ collectUnresolvedForEachItems(nested, found);
1915
+ }
1916
+ function unresolvedForEachFailures(entity, payload, address) {
1917
+ const found = [];
1918
+ collectUnresolvedForEachItems(payload, found);
1919
+ if (found.length === 0)
1920
+ return [];
1921
+ const name = "name" in payload && typeof payload.name === "string" && payload.name !== "" ? payload.name : entity.refName;
1922
+ return found.map((item) => ({
1923
+ severity: "fatal",
1924
+ address,
1925
+ name,
1926
+ ownerKind: "automation",
1927
+ message: `unresolved forEach item reference to "${item.ref}"${item.path !== "" ? `.${item.path}` : ""}: ` +
1928
+ "EDK cannot express a reference to a sibling loop's current item (only an enclosing loop, as " +
1929
+ "ctx.loops.<name>.item) - re-express this by hand " +
1930
+ "(e.g. restructure the loops, or pass the value through a variable) before this automation can build",
1931
+ }));
1932
+ }
1689
1933
  function valueToTf(value, refs) {
1690
1934
  const catalog = token(value);
1691
1935
  if (catalog !== undefined)
@@ -1698,14 +1942,16 @@ function valueToTf(value, refs) {
1698
1942
  throw new EntityTfError(`unsupported automation value ${String(value)}`);
1699
1943
  if (typeof value.__edkUnresolvedForEachItem === "string") {
1700
1944
  // Printed by print-automation.ts for a forEachItemRef pointing at a
1701
- // sibling or non-nearest-ancestor loop - EDK has no authoring primitive
1702
- // for "another loop's current item". Fail the build loudly instead of
1703
- // silently reinterpreting this as a task-output reference: `ctx.actions`
1704
- // would have turned ANY property-access shape into a real, but WRONG,
1705
- // task ref (review feedback on PR #1097, cursor[bot]).
1945
+ // sibling loop - one that doesn't enclose the task. EDK has no
1946
+ // authoring form for it (an enclosing loop is ctx.loops.<name>.item,
1947
+ // #1320). Fail the build loudly instead of silently reinterpreting
1948
+ // this as a task-output reference: `ctx.actions` would have turned ANY
1949
+ // property-access shape into a real, but WRONG, task ref (review
1950
+ // feedback on PR #1097, cursor[bot]).
1706
1951
  const path = Array.isArray(value.path) ? value.path.join(".") : "";
1707
1952
  throw new EntityTfError(`unresolved forEach item reference to "${value.__edkUnresolvedForEachItem}"${path ? `.${path}` : ""}: ` +
1708
- `EDK cannot express a reference to another loop's current item - re-express this by hand ` +
1953
+ `EDK cannot express a reference to a sibling loop's current item (only an enclosing loop, as ` +
1954
+ `ctx.loops.<name>.item) - re-express this by hand ` +
1709
1955
  `(e.g. restructure the loops, or pass the value through a variable) before this automation can build`);
1710
1956
  }
1711
1957
  if (value.__unsafe === "platformId" && typeof value.value === "string") {
@@ -1714,6 +1960,10 @@ function valueToTf(value, refs) {
1714
1960
  }
1715
1961
  if ("value" in value && Object.keys(value).length === 1)
1716
1962
  return valueToTf(value.value, refs);
1963
+ if (value.kind === "requiredSecret" && typeof value.variable === "string") {
1964
+ refs.requiredSecrets.add(value.variable);
1965
+ return expr.variable(value.variable);
1966
+ }
1717
1967
  if (isObject(value.variableReference) && typeof value.variableReference.id === "string") {
1718
1968
  const target = refs.variableById.get(value.variableReference.id);
1719
1969
  if (target === undefined)
@@ -1739,7 +1989,13 @@ function valueToTf(value, refs) {
1739
1989
  const target = refs.tasks.get(value.forEachReference.forEachTaskRefKey);
1740
1990
  if (target === undefined)
1741
1991
  throw new EntityTfError(`unresolved forEach ref "${value.forEachReference.forEachTaskRefKey}"`);
1742
- const index = forEachWireRefName(value.forEachReference.name, refs.owner, refs.recordItemForEachRefKeys.has(value.forEachReference.forEachTaskRefKey));
1992
+ const source = refs.recordItemForEachSourceByRefKey.get(value.forEachReference.forEachTaskRefKey);
1993
+ const sourceApp = source === undefined ? undefined : refs.recordFieldContext?.taskAppRefNameByRefKey?.[source];
1994
+ const index = forEachWireRefName(value.forEachReference.name, source === undefined || sourceApp === undefined
1995
+ ? refs.owner
1996
+ : recordOwnerContext(refs.owner, sourceApp, taskTargetKind(source, refs), sourceApp === refs.owner.appRefName
1997
+ ? refs.owner.fieldNames
1998
+ : fieldNamesForAppRefName(refs.fieldNamesByAppRefName, sourceApp) ?? refs.owner.fieldNames), refs.recordItemForEachRefKeys.has(value.forEachReference.forEachTaskRefKey));
1743
1999
  return expr.resourceAttr(target.type, target.label, ["inner", "refs", { index }]);
1744
2000
  }
1745
2001
  if (isObject(value.templateReference))
@@ -1773,6 +2029,68 @@ function unwrapDefault(value) {
1773
2029
  function isOptionBearingPicklist(metadata) {
1774
2030
  return metadata?.fieldType === "PICKLIST" && (metadata.options?.length ?? 0) > 0;
1775
2031
  }
2032
+ /** A person or group field's bare reference is the whole value, which DEV fails to null-check as a uuid; its id is not. */
2033
+ function isIdentityField(metadata) {
2034
+ return metadata?.fieldType === "USER" || metadata?.fieldType === "GROUP";
2035
+ }
2036
+ /**
2037
+ * A filter on an on-demand record input's field. The platform names it
2038
+ * `<parameter>.<fieldId>` (the internal path `availableReferences` reports
2039
+ * for every record input, `record.<fieldId>` included), so the short form is
2040
+ * `trigger.<parameter>.<fieldId>[.<suffix>]`. `filter_refs` only carries
2041
+ * whole parameters and has no key for a field.
2042
+ */
2043
+ function onDemandRecordFieldPath(name, refs) {
2044
+ const paramName = refs.recordParamNames
2045
+ .filter((param) => name.startsWith(`${param}.`))
2046
+ .sort((a, b) => b.length - a.length)[0];
2047
+ if (paramName === undefined)
2048
+ return undefined;
2049
+ const [fieldKey, ...rest] = name.slice(paramName.length + 1).split(".");
2050
+ if (fieldKey === undefined || fieldKey === "")
2051
+ return undefined;
2052
+ const target = refs.recordParamTargets.get(paramName);
2053
+ if (target === undefined) {
2054
+ throw new EntityTfError(`onDemand record parameter "${paramName}" is missing its target app/element`);
2055
+ }
2056
+ const isOwner = target.refName === refs.owner.appRefName && (target.__kind ?? refs.owner.parentScope) === refs.owner.parentScope;
2057
+ return { paramName, fieldKey, suffix: rest.join("."), target, isOwner };
2058
+ }
2059
+ function onDemandRecordFieldFilterReference(name, refs, operator) {
2060
+ const path = onDemandRecordFieldPath(name, refs);
2061
+ if (path === undefined)
2062
+ return undefined;
2063
+ const { paramName, fieldKey, suffix, target, isOwner } = path;
2064
+ if (fieldKey.startsWith(UNRESOLVED_FIELD_MARKER))
2065
+ return `trigger.${name.replace(UNRESOLVED_FIELD_MARKER, "")}`;
2066
+ const fieldAddresses = isOwner ? refs.owner.fieldAddresses : fieldNamesForAppRefName(refs.fieldAddressesByAppRefName, target.refName);
2067
+ if (suffix.length === 0 && isOwner && isOptionBearingPicklist(refs.owner.fieldMetadata.get(fieldKey)) && operator !== "is_null") {
2068
+ throw new EntityTfError(`filter reference to picklist field "${fieldKey}" is ambiguous — write ".id" ` +
2069
+ `(ctx.trigger.${paramName}.${fieldKey}.id) or ".label" (ctx.trigger.${paramName}.${fieldKey}.label) explicitly.`);
2070
+ }
2071
+ const wireSuffix = suffix === "recordId"
2072
+ ? "10000001-2000-4000-a000-800000000000"
2073
+ : suffix.length === 0 && isOwner && isOptionBearingPicklist(refs.owner.fieldMetadata.get(fieldKey)) ? "id"
2074
+ : suffix.length === 0 && isOwner && operator === "is_null" && isIdentityField(refs.owner.fieldMetadata.get(fieldKey)) ? "id" : suffix;
2075
+ const tail = wireSuffix.length > 0 ? [`.${wireSuffix}`] : [];
2076
+ const address = fieldAddresses?.get(fieldKey);
2077
+ if (address !== undefined) {
2078
+ return expr.template([`trigger.${paramName}.`, addressExpr(address, ["id"]), ...tail]);
2079
+ }
2080
+ const targetTfLabel = isOwner
2081
+ ? refs.owner.appTfLabel
2082
+ : refs.owner.workspaceAspects?.get(workspaceAspectKey(target.__kind === "element" ? "element" : "app", target.refName))?.tfLabel;
2083
+ const isSystemField = (target.__kind ?? refs.owner.parentScope) === "element"
2084
+ ? ELEMENT_SYSTEM_FIELD_KEYS.includes(fieldKey)
2085
+ : SYSTEM_FIELD_KEY_SET.has(fieldKey);
2086
+ if (isSystemField && targetTfLabel !== undefined) {
2087
+ return expr.template([`trigger.${paramName}.`, expr.local(`${targetTfLabel}_${tsLabelToTfLabel(fieldKey)}_field_id`), ...tail]);
2088
+ }
2089
+ if (isUuid(fieldKey))
2090
+ return `trigger.${name}`;
2091
+ throw new EntityTfError(`filter reference to "${fieldKey}" on on-demand record input "${paramName}": ${target.refName} is not built in this ` +
2092
+ `workspace or has no field "${fieldKey}", so its field id cannot be resolved`);
2093
+ }
1776
2094
  function filterReferenceToTf(value, refs, role = "value", realType, operator) {
1777
2095
  // Raw pass-through for a filter left side the pull-time deserializer
1778
2096
  // couldn't decode to a typed ref (filter.ts's leftDescriptor, matching the
@@ -1792,6 +2110,11 @@ function filterReferenceToTf(value, refs, role = "value", realType, operator) {
1792
2110
  // convention from the `.refs[...]` map lookup used for task inputs.
1793
2111
  // Reproduce it via a template so the field id stays a real reference
1794
2112
  // (never hardcoded), matching the actual export byte-for-byte.
2113
+ if (refs.trigger.type === TRIGGER_RESOURCES.onDemand) {
2114
+ const recordField = onDemandRecordFieldFilterReference(value.name, refs, operator);
2115
+ if (recordField !== undefined)
2116
+ return recordField;
2117
+ }
1795
2118
  const parts = value.name.split(".");
1796
2119
  if (parts[0] === "record" && parts.length >= 2) {
1797
2120
  const fieldKey = parts[1];
@@ -1810,6 +2133,8 @@ function filterReferenceToTf(value, refs, role = "value", realType, operator) {
1810
2133
  `(ctx.trigger.record.${fieldKey}.label, compare by display text) explicitly.`);
1811
2134
  }
1812
2135
  }
2136
+ if (suffix.length === 0 && operator === "is_null" && isIdentityField(refs.owner.fieldMetadata.get(fieldKey)))
2137
+ wireSuffix = "id";
1813
2138
  if (refs.trigger.type === TRIGGER_RESOURCES.datamine && refs.triggerDatamineTable !== undefined) {
1814
2139
  const table = refs.triggerDatamineTable;
1815
2140
  const tableAttr = resolveTableColumnFieldExpr({
@@ -1872,6 +2197,12 @@ function filterReferenceToTf(value, refs, role = "value", realType, operator) {
1872
2197
  }
1873
2198
  const triggerRefKey = triggerWireRefName(value.name, refs);
1874
2199
  if (refs.trigger.type === TRIGGER_RESOURCES.onDemand) {
2200
+ // filter_refs holds only declared inputs, so the clicking user has no key there.
2201
+ if (ON_DEMAND_TRIGGERED_BY_REFS[value.name] !== undefined) {
2202
+ throw new EntityTfError(`filter on ctx.trigger.${value.name}: an on-demand filter can only reference declared inputs, ` +
2203
+ `and the platform publishes no filter reference for the user who ran the automation. ` +
2204
+ `Read ctx.trigger.triggeredBy in a task input instead.`);
2205
+ }
1875
2206
  return expr.resourceAttr(refs.trigger.type, refs.trigger.label, ["filter_refs", { index: triggerRefKey }]);
1876
2207
  }
1877
2208
  return expr.resourceAttr(refs.trigger.type, refs.trigger.label, ["refs", { index: triggerRefKey }]);
@@ -2050,9 +2381,9 @@ function picklistFilterValueToTf(value, field, refs) {
2050
2381
  // Table siblings excluded for the same reason as in `crossAppFieldToTf`: a
2051
2382
  // picklist field's owner is an app or an element, never a table.
2052
2383
  if (sibling !== undefined && sibling.kind !== "table" && sibling.kind !== "task") {
2053
- const localName = field.tags?.includes("STATUS")
2384
+ const localName = sibling.kind === "app" && field.tags?.includes("STATUS")
2054
2385
  ? `${sibling.tfLabel}_status_options_by_label`
2055
- : field.tags?.includes("STAGE")
2386
+ : sibling.kind === "app" && field.tags?.includes("STAGE")
2056
2387
  ? `${sibling.tfLabel}_stage_options_by_label`
2057
2388
  : `${scopedResourceLabel(sibling.tfLabel, tsLabelToTfLabel(field.refName), sibling.kind)}_options_by_label`;
2058
2389
  return expr.local(localName, [{ index: value }]);
@@ -2066,16 +2397,22 @@ function picklistFilterValueToTf(value, field, refs) {
2066
2397
  const fieldLabel = registerForeignFieldLookup(field, refs.owner, refs.dataBlocks);
2067
2398
  return expr.local(fieldLabel + "_options_by_label", [{ index: value }]);
2068
2399
  }
2069
- const localName = field.tags?.includes("STATUS")
2400
+ const localName = refs.owner.parentScope === "app" && field.tags?.includes("STATUS")
2070
2401
  ? `${refs.owner.appTfLabel}_status_options_by_label`
2071
- : field.tags?.includes("STAGE")
2402
+ : refs.owner.parentScope === "app" && field.tags?.includes("STAGE")
2072
2403
  ? `${refs.owner.appTfLabel}_stage_options_by_label`
2073
- : `${scopedLabel(refs.owner.appTfLabel, tsLabelToTfLabel(field.refName))}_options_by_label`;
2404
+ : `${scopedResourceLabel(refs.owner.appTfLabel, tsLabelToTfLabel(field.refName), refs.owner.parentScope)}_options_by_label`;
2074
2405
  return expr.local(localName, [{ index: value }]);
2075
2406
  }
2076
- function triggerRecordFieldPath(reference) {
2407
+ function triggerRecordFieldPath(reference, refs) {
2077
2408
  if (!isObject(reference) || typeof reference.name !== "string")
2078
2409
  return undefined;
2410
+ if (refs.trigger.type === TRIGGER_RESOURCES.onDemand && reference.type?.toString().toUpperCase() === "TRIGGER") {
2411
+ const onDemandPath = onDemandRecordFieldPath(reference.name, refs);
2412
+ // Field metadata is only known for the automation's own app or element.
2413
+ if (onDemandPath !== undefined)
2414
+ return onDemandPath.isOwner ? onDemandPath : undefined;
2415
+ }
2079
2416
  const path = reference.name.split(".");
2080
2417
  if (path[0] !== "record" || path.length < 2)
2081
2418
  return undefined;
@@ -2092,7 +2429,7 @@ function fieldFromFilterLeftValue(value, refs) {
2092
2429
  taskSearchesOwnerApp(value.value.taskRefKey, refs);
2093
2430
  if (referenceType !== "TRIGGER" && !ownAppTask)
2094
2431
  return undefined;
2095
- const parsed = triggerRecordFieldPath(value.value);
2432
+ const parsed = triggerRecordFieldPath(value.value, refs);
2096
2433
  if (parsed === undefined)
2097
2434
  return undefined;
2098
2435
  const { fieldKey: refName, suffix } = parsed;
@@ -2143,7 +2480,7 @@ function filterToTf(value, refs) {
2143
2480
  referenceRealType: (reference, _role, authored) => {
2144
2481
  if (!isObject(reference) || reference.type?.toString().toUpperCase() !== "TRIGGER")
2145
2482
  return authored;
2146
- const parsed = triggerRecordFieldPath(reference);
2483
+ const parsed = triggerRecordFieldPath(reference, refs);
2147
2484
  if (parsed === undefined)
2148
2485
  return authored;
2149
2486
  const metadata = refs.owner.fieldMetadata.get(parsed.fieldKey);
@@ -2154,9 +2491,12 @@ function filterToTf(value, refs) {
2154
2491
  const inferred = referenceValueTypeForField(metadata?.fieldType, parsed.suffix);
2155
2492
  if (inferred === undefined)
2156
2493
  return authored;
2157
- // Operator fallbacks and `filter.text()` are TEXT. Field metadata is
2158
- // the authority for a known trigger-record field (PICKLIST .id → UUID).
2159
- // Explicit non-TEXT wrappers (`filter.uuid()`, `filter.number()`, …) win.
2494
+ // This hook only sees unmarked references. `filter.text()` and the
2495
+ // other typed wrappers set `explicit`, and the filter codec keeps that
2496
+ // type before calling here. What remains is the operator fallback:
2497
+ // TEXT on an unwrapped trigger-record field yields to field metadata
2498
+ // (PICKLIST `.id` → UUID). A non-TEXT fallback (`gt` → NUMBER) already
2499
+ // names its type.
2160
2500
  const authoredNorm = authored?.toUpperCase();
2161
2501
  if (authoredNorm !== undefined && authoredNorm !== "TEXT")
2162
2502
  return authored;
@@ -2165,6 +2505,8 @@ function filterToTf(value, refs) {
2165
2505
  literal: (literal, field) => picklistFilterValueToTf(literal, token(field), refs) ?? valueToTf(literal, refs),
2166
2506
  });
2167
2507
  }
2508
+ /** System fields the platform stamps itself; a record-updated trigger can only watch Title, Status and Stage. */
2509
+ const UNWATCHABLE_SYSTEM_FIELD_KEYS = new Set(SYSTEM_FIELD_KEYS.filter((key) => key !== "title" && key !== "status" && key !== "stage"));
2168
2510
  function configAttrs(kind, config, refs) {
2169
2511
  const attrs = {};
2170
2512
  for (const [key, raw] of Object.entries(config)) {
@@ -2412,6 +2754,24 @@ function configAttrs(kind, config, refs) {
2412
2754
  });
2413
2755
  continue;
2414
2756
  }
2757
+ if (key === "changedFieldIds" && Array.isArray(raw)) {
2758
+ const watched = raw.filter((field) => {
2759
+ const fieldToken = token(field);
2760
+ if (fieldToken?.__kind !== "field" ||
2761
+ !UNWATCHABLE_SYSTEM_FIELD_KEYS.has(fieldToken.refName) ||
2762
+ refs.owner.fieldAddresses.has(fieldToken.refName))
2763
+ return true;
2764
+ refs.owner.diagnostics.push(`changedFields: system field "${fieldToken.name ?? fieldToken.refName}" is platform-managed and cannot be watched; dropped`);
2765
+ return false;
2766
+ });
2767
+ // An omitted or empty changed_fields fires the trigger on every field change.
2768
+ if (watched.length === 0 && raw.length > 0) {
2769
+ throw new EntityTfError("changedFields lists only platform-managed system fields, which cannot be watched; " +
2770
+ "list at least one other field, or leave changedFields out to fire on any change");
2771
+ }
2772
+ attrs.changed_fields = valueToTf(watched, refs);
2773
+ continue;
2774
+ }
2415
2775
  if (key === "inputs" && kind === "elementum_on_demand_trigger") {
2416
2776
  if (!Array.isArray(raw))
2417
2777
  throw new EntityTfError("onDemand inputs must be an array");
@@ -2424,8 +2784,9 @@ function configAttrs(kind, config, refs) {
2424
2784
  CONFIG_ATTRS[k] ?? snake(k),
2425
2785
  valueToTf(k === "defaultValue" ? unwrapDefault(v) :
2426
2786
  k === "type" && v === "ATTACHMENT_ID" ? "attachment" :
2427
- k === "type" && v === "ASPECT_RECORD" ? "record" :
2428
- k === "type" && typeof v === "string" ? v.toLowerCase() : v, refs),
2787
+ k === "type" && v === "USER_ID" ? "user" :
2788
+ k === "type" && v === "ASPECT_RECORD" ? "record" :
2789
+ k === "type" && typeof v === "string" ? v.toLowerCase() : v, refs),
2429
2790
  ]));
2430
2791
  if (isOnDemandRecordType(typeof input.type === "string" ? input.type : undefined)) {
2431
2792
  const target = token(input.app);
@@ -2445,6 +2806,8 @@ function configAttrs(kind, config, refs) {
2445
2806
  if (key === "workflowFields") {
2446
2807
  if (!Array.isArray(raw))
2447
2808
  throw new EntityTfError("workflowFields must be an array");
2809
+ if (kind === "elementum_create_record_task")
2810
+ assertElementCreateSetsTitle(config.aspectId, raw);
2448
2811
  attrs.fields = raw.map((field) => {
2449
2812
  if (!isObject(field))
2450
2813
  throw new EntityTfError("workflow field must be an object");
@@ -2476,6 +2839,7 @@ function configAttrs(kind, config, refs) {
2476
2839
  ...(field.operation === "ADD" ? { update_mode: "add" } : {}),
2477
2840
  };
2478
2841
  }
2842
+ assertLiteralFitsFieldType(staticValue, fieldToken);
2479
2843
  const optionValue = staticValue !== undefined
2480
2844
  ? picklistFilterValueToTf(staticValue, fieldToken, refs)
2481
2845
  : undefined;
@@ -2608,6 +2972,12 @@ function configAttrs(kind, config, refs) {
2608
2972
  };
2609
2973
  continue;
2610
2974
  }
2975
+ // The platform stores whatever string it is given and the trigger or task
2976
+ // then never matches an alias, so an alias name instead of its id only
2977
+ // shows up as mail that is silently not ingested.
2978
+ if (key === "emailAliasId" && typeof raw === "string" && !UUID_PATTERN.test(raw)) {
2979
+ throw new EntityTfError(`emailAliasId "${raw}" is not an email alias id; pass the alias's platform id (a UUID), not its name or address`);
2980
+ }
2611
2981
  const attr = CONFIG_ATTRS[key] ?? snake(key);
2612
2982
  attrs[attr] = valueToTf(raw, refs);
2613
2983
  }
@@ -2656,6 +3026,9 @@ export function automationToTf(entity, ctx) {
2656
3026
  workspaceAspects: ctx.workspaceAspects,
2657
3027
  diagnostics: ctx.diagnostics ?? [],
2658
3028
  activeAutomationRefNames: ctx.activeAutomationRefNames,
3029
+ ...(ctx.elementsWithoutAuditFields !== undefined ? { elementsWithoutAuditFields: ctx.elementsWithoutAuditFields } : {}),
3030
+ ...(ctx.fieldAddressesByAppRefName !== undefined ? { fieldAddressesByAppRefName: ctx.fieldAddressesByAppRefName } : {}),
3031
+ recordLacksAuditFields: ctx.parentScope === "element" && ctx.ownerAuditFields !== true,
2659
3032
  };
2660
3033
  if (entity.kind !== "automation")
2661
3034
  throw new EntityTfError(`automationToTf expects kind "automation"; got "${entity.kind}"`);
@@ -2665,6 +3038,9 @@ export function automationToTf(entity, ctx) {
2665
3038
  const payload = entity.payload;
2666
3039
  if (payload === null || typeof payload !== "object" || Array.isArray(payload))
2667
3040
  throw new EntityTfError(`automation "${entity.refName}" has a non-object payload`);
3041
+ const unresolved = unresolvedForEachFailures(entity, payload, `${AUTOMATION_RESOURCE_TYPE}.${automationTfLabel}`);
3042
+ if (unresolved.length > 0)
3043
+ throw new ValidationFailureError(unresolved);
2668
3044
  if (typeof payload.workflowRevision !== "string")
2669
3045
  throw new EntityTfError(`automation "${entity.refName}" has no workflowRevision`);
2670
3046
  const label = automationTfLabel;
@@ -2764,7 +3140,7 @@ export function automationToTf(entity, ctx) {
2764
3140
  // output. Everything else - a script array, a file-reader payload, an API
2765
3141
  // response, a variable, a nested item sub-array - keys its items by their
2766
3142
  // own keys, so their names pass through untouched.
2767
- const recordItemForEachRefKeys = new Set([...forEachCollectionByRefKey].flatMap(([refKey, collection]) => {
3143
+ const recordItemForEachSourceByRefKey = new Map([...forEachCollectionByRefKey].flatMap(([refKey, collection]) => {
2768
3144
  if (!isObject(collection) || !isObject(collection.taskReference))
2769
3145
  return [];
2770
3146
  const sourceRefKey = collection.taskReference.taskRefKey;
@@ -2772,9 +3148,10 @@ export function automationToTf(entity, ctx) {
2772
3148
  return [];
2773
3149
  const sourceWireType = wireTypeByRefKey.get(sourceRefKey);
2774
3150
  return sourceWireType !== undefined && RECORD_COLLECTION_TASK_WIRE_TYPES.has(sourceWireType)
2775
- ? [refKey]
3151
+ ? [[refKey, sourceRefKey]]
2776
3152
  : [];
2777
3153
  }));
3154
+ const recordItemForEachRefKeys = new Set(recordItemForEachSourceByRefKey.keys());
2778
3155
  const dataBlocks = new Map();
2779
3156
  const recordFieldContext = recordFieldContextOf(entity);
2780
3157
  const triggerParamNames = triggerKey === "onDemand" && isObject(triggerConfig) && Array.isArray(triggerConfig.inputs)
@@ -2785,6 +3162,15 @@ export function automationToTf(entity, ctx) {
2785
3162
  ? [input.name]
2786
3163
  : [])
2787
3164
  : [];
3165
+ const userParamNames = triggerKey === "onDemand" && isObject(triggerConfig) && Array.isArray(triggerConfig.inputs)
3166
+ ? triggerConfig.inputs.flatMap((input) => isObject(input) && typeof input.name === "string" && input.type === "USER_ID" ? [input.name] : [])
3167
+ : [];
3168
+ const triggerParamFieldTypes = new Map(triggerKey === "onDemand" && isObject(triggerConfig) && Array.isArray(triggerConfig.inputs)
3169
+ ? triggerConfig.inputs.flatMap((input) => isObject(input) && typeof input.name === "string" && typeof input.type === "string" &&
3170
+ !isOnDemandRecordType(input.type)
3171
+ ? [[input.name, { fieldType: input.type, multiple: input.multiple === true }]]
3172
+ : [])
3173
+ : []);
2788
3174
  const recordParamTargets = new Map(triggerKey === "onDemand" && isObject(triggerConfig) && Array.isArray(triggerConfig.inputs)
2789
3175
  ? triggerConfig.inputs.flatMap((input) => {
2790
3176
  if (!isObject(input) ||
@@ -2817,12 +3203,16 @@ export function automationToTf(entity, ctx) {
2817
3203
  trigger: { type: triggerType, label },
2818
3204
  triggerParamNames,
2819
3205
  recordParamNames,
3206
+ triggerParamFieldTypes,
2820
3207
  recordParamTargets,
3208
+ userParamNames,
2821
3209
  tasks: taskRefs,
2822
3210
  owner,
2823
3211
  dataBlocks,
2824
3212
  variableById,
3213
+ requiredSecrets: new Set(),
2825
3214
  recordItemForEachRefKeys,
3215
+ recordItemForEachSourceByRefKey,
2826
3216
  ...(recordFieldContext !== undefined ? { recordFieldContext } : {}),
2827
3217
  ...(ctx.fieldNamesByAppRefName !== undefined ? { fieldNamesByAppRefName: ctx.fieldNamesByAppRefName } : {}),
2828
3218
  ...(ctx.fieldAddressesByAppRefName !== undefined ? { fieldAddressesByAppRefName: ctx.fieldAddressesByAppRefName } : {}),
@@ -3137,6 +3527,7 @@ export function automationToTf(entity, ctx) {
3137
3527
  ? { outputs: outputValues.map((output) => {
3138
3528
  if (typeof output.name !== "string")
3139
3529
  throw new EntityTfError("automation output has no name");
3530
+ assertPublishableOutputTask(output.name, output.value, payload.tasks ?? [], refs);
3140
3531
  return { name: output.name, value: workflowPublishOutputValueToTf(output.value, refs) };
3141
3532
  }) }
3142
3533
  : {}),
@@ -3144,5 +3535,20 @@ export function automationToTf(entity, ctx) {
3144
3535
  };
3145
3536
  blocks.push(publish);
3146
3537
  }
3147
- return { blocks: [...[...dataBlocks.values()].sort((a, b) => (a.type + "." + a.label).localeCompare(b.type + "." + b.label)), ...blocks], address: AUTOMATION_RESOURCE_TYPE + "." + label };
3538
+ const secretBlocks = [...refs.requiredSecrets].sort().map(requiredSecretVariableBlock);
3539
+ return { blocks: [...secretBlocks, ...[...dataBlocks.values()].sort((a, b) => (a.type + "." + a.label).localeCompare(b.type + "." + b.label)), ...blocks], address: AUTOMATION_RESOURCE_TYPE + "." + label };
3540
+ }
3541
+ function requiredSecretVariableBlock(name) {
3542
+ return {
3543
+ kind: "variable",
3544
+ label: name,
3545
+ attrs: {
3546
+ sensitive: true,
3547
+ description: `Write-only secret. Supply a non-empty value as TF_VAR_${name} before plan or apply.`,
3548
+ },
3549
+ variableValidation: {
3550
+ condition: `var.${name} != ""`,
3551
+ errorMessage: `TF_VAR_${name} must be a non-empty value. An empty string would overwrite the live write-only secret.`,
3552
+ },
3553
+ };
3148
3554
  }