@elementumai/edk 0.10.3 → 0.11.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 (155) hide show
  1. package/README.md +11 -7
  2. package/dist-sdk/src/catalog/token.js +2 -1
  3. package/dist-sdk/src/core/wire/ref-serializer.js +26 -1
  4. package/dist-sdk/src/engine/build/context.d.ts +4 -0
  5. package/dist-sdk/src/engine/coverage-gaps.d.ts +2 -0
  6. package/dist-sdk/src/engine/coverage-gaps.js +3 -0
  7. package/dist-sdk/src/engine/ei/json-stream-reader.d.ts +43 -0
  8. package/dist-sdk/src/engine/ei/json-stream-reader.js +234 -0
  9. package/dist-sdk/src/engine/ei/run.d.ts +22 -0
  10. package/dist-sdk/src/engine/ei/run.js +99 -18
  11. package/dist-sdk/src/engine/ei/saved-plan.d.ts +16 -0
  12. package/dist-sdk/src/engine/ei/saved-plan.js +19 -0
  13. package/dist-sdk/src/engine/ei/state.d.ts +1 -1
  14. package/dist-sdk/src/engine/ei/state.js +17 -4
  15. package/dist-sdk/src/engine/progress.d.ts +3 -1
  16. package/dist-sdk/src/engine/progress.js +7 -3
  17. package/dist-sdk/src/engine/pull/authored-address.d.ts +15 -1
  18. package/dist-sdk/src/engine/pull/authored-address.js +180 -29
  19. package/dist-sdk/src/engine/pull/context.d.ts +52 -7
  20. package/dist-sdk/src/engine/pull/context.js +7 -4
  21. package/dist-sdk/src/engine/tf/index.d.ts +3 -2
  22. package/dist-sdk/src/engine/tf/index.js +3 -2
  23. package/dist-sdk/src/engine/tf/labels.d.ts +22 -0
  24. package/dist-sdk/src/engine/tf/labels.js +50 -0
  25. package/dist-sdk/src/engine/tf/model.d.ts +2 -0
  26. package/dist-sdk/src/engine/tf/model.js +26 -0
  27. package/dist-sdk/src/engine/tf/scan.d.ts +22 -0
  28. package/dist-sdk/src/engine/tf/scan.js +123 -0
  29. package/dist-sdk/src/engine/validation.d.ts +2 -0
  30. package/dist-sdk/src/engine/workspace/loader.d.ts +8 -0
  31. package/dist-sdk/src/engine/workspace/loader.js +20 -0
  32. package/dist-sdk/src/entities/access-policy/from-tf.d.ts +17 -0
  33. package/dist-sdk/src/entities/access-policy/from-tf.js +52 -24
  34. package/dist-sdk/src/entities/access-policy/member-list.d.ts +32 -0
  35. package/dist-sdk/src/entities/access-policy/member-list.js +57 -0
  36. package/dist-sdk/src/entities/access-policy/module.js +5 -0
  37. package/dist-sdk/src/entities/access-policy/to-tf.d.ts +4 -3
  38. package/dist-sdk/src/entities/access-policy/to-tf.js +21 -12
  39. package/dist-sdk/src/entities/agent/build.js +7 -5
  40. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +2 -0
  41. package/dist-sdk/src/entities/agent/from-tf.js +13 -3
  42. package/dist-sdk/src/entities/agent/to-tf.d.ts +13 -11
  43. package/dist-sdk/src/entities/agent/to-tf.js +28 -17
  44. package/dist-sdk/src/entities/agent/tools.d.ts +8 -0
  45. package/dist-sdk/src/entities/agent/tools.js +6 -2
  46. package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +2 -0
  47. package/dist-sdk/src/entities/agent-tool/from-tf.js +2 -2
  48. package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +29 -0
  49. package/dist-sdk/src/entities/agent-tool/to-tf.js +65 -3
  50. package/dist-sdk/src/entities/agent-tool/types.d.ts +12 -8
  51. package/dist-sdk/src/entities/agent-tool/types.js +13 -9
  52. package/dist-sdk/src/entities/app/build.d.ts +11 -0
  53. package/dist-sdk/src/entities/app/build.js +1 -0
  54. package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +11 -7
  55. package/dist-sdk/src/entities/app/from-tf.js +19 -9
  56. package/dist-sdk/src/entities/app/to-tf.js +6 -4
  57. package/dist-sdk/src/entities/automation/build.d.ts +2 -7
  58. package/dist-sdk/src/entities/automation/build.js +55 -16
  59. package/dist-sdk/src/entities/automation/deserializer/ast.d.ts +7 -4
  60. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +7 -11
  61. package/dist-sdk/src/entities/automation/from-tf.d.ts +23 -1
  62. package/dist-sdk/src/entities/automation/from-tf.js +456 -34
  63. package/dist-sdk/src/entities/automation/index.d.ts +1 -1
  64. package/dist-sdk/src/entities/automation/module.d.ts +22 -2
  65. package/dist-sdk/src/entities/automation/module.js +273 -58
  66. package/dist-sdk/src/entities/automation/output-field-types.d.ts +8 -0
  67. package/dist-sdk/src/entities/automation/output-field-types.js +20 -0
  68. package/dist-sdk/src/entities/automation/output-key-wire-name.d.ts +24 -2
  69. package/dist-sdk/src/entities/automation/output-key-wire-name.js +72 -3
  70. package/dist-sdk/src/entities/automation/run-target.d.ts +59 -0
  71. package/dist-sdk/src/entities/automation/run-target.js +99 -0
  72. package/dist-sdk/src/entities/automation/script-code.d.ts +9 -0
  73. package/dist-sdk/src/entities/automation/script-code.js +24 -3
  74. package/dist-sdk/src/entities/automation/task-output-labels.d.ts +16 -0
  75. package/dist-sdk/src/entities/automation/task-output-labels.js +49 -0
  76. package/dist-sdk/src/entities/automation/tasks.d.ts +20 -8
  77. package/dist-sdk/src/entities/automation/to-tf.d.ts +8 -3
  78. package/dist-sdk/src/entities/automation/to-tf.js +171 -58
  79. package/dist-sdk/src/entities/automation/triggers.d.ts +22 -3
  80. package/dist-sdk/src/entities/automation/triggers.js +40 -0
  81. package/dist-sdk/src/entities/automation/types.d.ts +21 -0
  82. package/dist-sdk/src/entities/automation/types.js +26 -0
  83. package/dist-sdk/src/entities/dashboard/from-tf.d.ts +11 -1
  84. package/dist-sdk/src/entities/dashboard/from-tf.js +57 -7
  85. package/dist-sdk/src/entities/dashboard/to-tf.js +13 -0
  86. package/dist-sdk/src/entities/dynamic-layout/build.d.ts +7 -2
  87. package/dist-sdk/src/entities/dynamic-layout/from-tf.d.ts +3 -0
  88. package/dist-sdk/src/entities/dynamic-layout/from-tf.js +65 -19
  89. package/dist-sdk/src/entities/dynamic-layout/to-tf.d.ts +4 -2
  90. package/dist-sdk/src/entities/dynamic-layout/to-tf.js +341 -32
  91. package/dist-sdk/src/entities/element/build.d.ts +10 -0
  92. package/dist-sdk/src/entities/element/build.js +1 -0
  93. package/dist-sdk/src/entities/element/from-tf.js +16 -9
  94. package/dist-sdk/src/entities/element/to-tf.js +6 -4
  95. package/dist-sdk/src/entities/field/from-tf.d.ts +24 -0
  96. package/dist-sdk/src/entities/field/from-tf.js +79 -1
  97. package/dist-sdk/src/entities/field/module.js +7 -0
  98. package/dist-sdk/src/entities/field/to-tf.d.ts +30 -1
  99. package/dist-sdk/src/entities/field/to-tf.js +51 -0
  100. package/dist-sdk/src/entities/file-reader/module.js +3 -3
  101. package/dist-sdk/src/entities/file-reader/to-tf.js +3 -3
  102. package/dist-sdk/src/entities/file-reader/types.d.ts +4 -16
  103. package/dist-sdk/src/entities/file-reader/types.js +7 -0
  104. package/dist-sdk/src/entities/org/group.d.ts +1 -0
  105. package/dist-sdk/src/entities/org/group.js +2 -1
  106. package/dist-sdk/src/entities/record-create-form/from-tf.d.ts +8 -0
  107. package/dist-sdk/src/entities/record-create-form/from-tf.js +10 -2
  108. package/dist-sdk/src/entities/record-create-form/to-tf.d.ts +2 -1
  109. package/dist-sdk/src/entities/record-create-form/to-tf.js +14 -2
  110. package/dist-sdk/src/entities/relationship/from-tf.d.ts +8 -0
  111. package/dist-sdk/src/entities/relationship/from-tf.js +88 -10
  112. package/dist-sdk/src/entities/relationship/to-tf.d.ts +3 -2
  113. package/dist-sdk/src/entities/relationship/to-tf.js +79 -8
  114. package/dist-sdk/src/entities/role/from-tf.js +24 -7
  115. package/dist-sdk/src/entities/role/to-tf.js +25 -7
  116. package/dist-sdk/src/entities/service-account/from-tf.js +2 -1
  117. package/dist-sdk/src/entities/service-account/module.js +15 -0
  118. package/dist-sdk/src/entities/service-account/to-tf.js +12 -4
  119. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +1 -1
  120. package/dist-sdk/src/entities/shared/filters/tf-codec.js +12 -7
  121. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +5 -2
  122. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +8 -1
  123. package/dist-sdk/src/entities/skill/from-tf.js +10 -3
  124. package/dist-sdk/src/entities/skill/module.js +44 -2
  125. package/dist-sdk/src/entities/skill/to-tf.d.ts +8 -1
  126. package/dist-sdk/src/entities/skill/to-tf.js +23 -14
  127. package/dist-sdk/src/entities/skill/tools.d.ts +8 -0
  128. package/dist-sdk/src/entities/skill/tools.js +6 -2
  129. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +2 -0
  130. package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +8 -0
  131. package/dist-sdk/src/entities/skill-tool/to-tf.js +6 -2
  132. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.d.ts +10 -2
  133. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.js +18 -4
  134. package/dist-sdk/src/entities/view/custom-view-validate.js +6 -5
  135. package/dist-sdk/src/entities/view/from-tf.d.ts +68 -0
  136. package/dist-sdk/src/entities/view/from-tf.js +503 -25
  137. package/dist-sdk/src/entities/view/module.js +15 -0
  138. package/dist-sdk/src/entities/view/portable.d.ts +11 -0
  139. package/dist-sdk/src/entities/view/portable.js +47 -0
  140. package/dist-sdk/src/entities/view/to-tf.d.ts +4 -1
  141. package/dist-sdk/src/entities/view/to-tf.js +25 -7
  142. package/dist-sdk/src/entities/view/types.js +1 -1
  143. package/dist-sdk/src/entities/widget/build.d.ts +4 -3
  144. package/dist-sdk/src/entities/widget/from-tf.d.ts +3 -0
  145. package/dist-sdk/src/entities/widget/from-tf.js +100 -3
  146. package/dist-sdk/src/entities/widget/to-tf.d.ts +16 -1
  147. package/dist-sdk/src/entities/widget/to-tf.js +77 -14
  148. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +27 -8
  149. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
  150. package/dist-sdk/src/graph/field-resource-types.d.ts +2 -0
  151. package/dist-sdk/src/graph/field-resource-types.js +11 -0
  152. package/dist-sdk/src/graph/index.d.ts +28 -3
  153. package/dist-sdk/src/graph/index.js +12 -2
  154. package/dist-sdk/src/graph/types.d.ts +164 -5
  155. package/package.json +1 -1
@@ -13,12 +13,12 @@ import { workspaceServiceAccountAppResolver } from "../service-account/workspace
13
13
  import { foreignFieldDataLabel, resolveForeignRef } from "../shared/foreign-ref.js";
14
14
  import { filterToTf as serializeFilterToTf } from "../shared/filters/tf-codec.js";
15
15
  import { referenceValueTypeForField } from "../shared/filters/index.js";
16
- import { API_TASK_REF_AUTHORING_NAMES, API_TASK_REF_WIRE_NAMES, executeScriptRefsIndex, OUTPUT_KEY_CANONICAL, OUTPUT_KEY_WIRE_NAME } from "./output-key-wire-name.js";
16
+ import { aiCompletionRefsIndex, API_TASK_REF_AUTHORING_NAMES, API_TASK_REF_WIRE_NAMES, executeScriptRefsIndex, OUTPUT_KEY_CANONICAL, OUTPUT_KEY_WIRE_NAME } from "./output-key-wire-name.js";
17
17
  import { outputFieldTypesFromScriptSchema, scriptOutputReferenceIsDeclared } from "./output-field-types.js";
18
18
  import { RESOURCE_TYPE_TO_EXECUTOR, TASK_OUTPUT_CONTRACTS } from "./generated/task-output-contracts.js";
19
19
  import { CONNECTOR_ORG_BAG } from "../org/connector.js";
20
20
  import { GROUP_ORG_BAG } from "../org/group.js";
21
- import { FILE_READER_SUB_TYPE_BY_RESOURCE, FILE_READER_SUB_TYPE_BY_TYPE_KEY } from "../file-reader/types.js";
21
+ import { FILE_READER_SUB_TYPE_BY_RESOURCE, FILE_READER_SUB_TYPE_BY_TYPE_KEY, fileReaderResourceLabel } from "../file-reader/types.js";
22
22
  import { UNRESOLVED_FIELD_MARKER } from "../shared/ref.js";
23
23
  import { ELEMENT_SYSTEM_FIELD_KEYS } from "../element/system-fields.js";
24
24
  import { TABLE_RESOURCE_TYPE } from "../table/module.js";
@@ -28,6 +28,7 @@ import { onDemandTriggerRefKey } from "./value-ref-tf.js";
28
28
  import { normalizeOnDemandParamKey } from "../../../pull/util.js";
29
29
  import { PROVIDER_FIXED_SYSTEM_FIELD_KEYS, recordFieldWireRefName } from "./system-ref-name.js";
30
30
  import { taskTfLabel } from "./task-label.js";
31
+ import { automationRunTargetResourceAttr, automationTargetOwner, bareStaticRunTarget, onDemandRecordParamNames, recordInputMappingProblem } from "./run-target.js";
31
32
  import { FIELD_TYPE_MAP, isOnDemandRecordType } from "../shared/types/field-types.js";
32
33
  /** The context for reading records of `appRefName` (a `kind`), retargeted from the owner. */
33
34
  /**
@@ -129,6 +130,7 @@ const TRIGGER_RESOURCES = {
129
130
  datamine: "elementum_datamine_trigger",
130
131
  survey: "elementum_survey_trigger",
131
132
  schedule: "elementum_schedule_trigger",
133
+ temporal: "elementum_temporal_trigger",
132
134
  };
133
135
  /**
134
136
  * The live platform id of a created variable: `variables[<index>].id` on its
@@ -503,19 +505,6 @@ function registerForeignFieldLookup(value, ctx, dataBlocks) {
503
505
  registerForeignOptionsByLabelLocal(fieldLabel, ctx);
504
506
  return fieldLabel;
505
507
  }
506
- /**
507
- * A bare platform-id target whose every input names a raw parameter id is a
508
- * static run: pull prints a static export with an undiscovered target
509
- * (`target_automation_id` + `input_mappings[].parameter_id`) as
510
- * `automation: "<uuid>"` + `inputs[].name: "<uuid>"`. Dynamic mappings name
511
- * the target's inputs, never a parameter id.
512
- */
513
- function bareStaticRunTarget(config) {
514
- return typeof config.targetAutomationId === "string" &&
515
- Array.isArray(config.inputMappings) &&
516
- config.inputMappings.length > 0 &&
517
- config.inputMappings.every((mapping) => isObject(mapping) && typeof mapping.name === "string" && isUuid(mapping.name));
518
- }
519
508
  /**
520
509
  * Resolve an automation token as a managed definition (same stream root or a
521
510
  * sibling root in this build) or as a ref-only `data.elementum_automation`
@@ -524,9 +513,7 @@ function bareStaticRunTarget(config) {
524
513
  * degrade to `target_automation_ref` / `dynamic_input_mappings`.
525
514
  */
526
515
  function automationTargetToTf(value, ctx, dataBlocks) {
527
- const ownerKind = value.parentKind ?? ctx.parentScope;
528
- const isOwn = value.parent === undefined ||
529
- (value.parent === ctx.appRefName && ownerKind === ctx.parentScope);
516
+ const { ownerKind, isOwn } = automationTargetOwner(value, ctx);
530
517
  const sibling = !isOwn && value.parent !== undefined
531
518
  ? ctx.workspaceAspects?.get(workspaceAspectKey(ownerKind, value.parent))
532
519
  : undefined;
@@ -542,6 +529,7 @@ function automationTargetToTf(value, ctx, dataBlocks) {
542
529
  : undefined;
543
530
  const managedLabel = automationResourceLabel(managedOwnerLabel, value.refName, ownerKind === "element" ? "element" : "app", managedHandle);
544
531
  const targetActiveRefs = targetOwner?.activeAutomationRefNames;
532
+ const recordInputNames = targetOwner?.onDemandRecordInputsByAutomationRefName?.get(value.refName);
545
533
  const isActive = targetActiveRefs !== undefined
546
534
  ? targetActiveRefs.has(value.refName)
547
535
  : isOwn && ctx.activeAutomationRefNames?.has(value.refName) === true;
@@ -574,12 +562,14 @@ function automationTargetToTf(value, ctx, dataBlocks) {
574
562
  id: expr.dataAttr(AUTOMATION_RESOURCE_TYPE, currentBindingLabel, ["id"]),
575
563
  parameterId: (name) => expr.dataAttr(AUTOMATION_RESOURCE_TYPE, currentBindingLabel, ["parameter_ids", { index: name }]),
576
564
  managedLabel,
565
+ recordInputNames,
577
566
  };
578
567
  }
579
568
  return {
580
569
  id: expr.resourceAttr(AUTOMATION_RESOURCE_TYPE, managedLabel, ["id"]),
581
570
  parameterId: (name) => expr.resourceAttr("elementum_on_demand_trigger", managedLabel, ["parameter_ids", { index: name }]),
582
571
  managedLabel,
572
+ recordInputNames,
583
573
  };
584
574
  }
585
575
  if (value.parent === undefined || value.parent === "") {
@@ -955,7 +945,7 @@ function tokenToTf(value, ctx, dataBlocks) {
955
945
  if (subType === undefined || subType.implemented !== true) {
956
946
  throw new EntityTfError(`file reader token "${value.refName}" has no recognized readerType ("${value.readerType}") — was it built with a file-reader factory?`);
957
947
  }
958
- return expr.resourceAttr(subType.resourceType, scopedLabel(ctx.appTfLabel, tsLabelToTfLabel(value.refName)), ["id"]);
948
+ return expr.resourceAttr(subType.resourceType, fileReaderResourceLabel(fileReaderOwnerTfLabel(value, ctx), value.refName), ["id"]);
959
949
  }
960
950
  case "group": {
961
951
  // Static notification/add-watcher recipients (edk#1389). An org.ts
@@ -988,6 +978,28 @@ function tokenToTf(value, ctx, dataBlocks) {
988
978
  throw new EntityTfError(`catalog ref kind "${value.__kind}" has no automation HCL representation`);
989
979
  }
990
980
  }
981
+ /**
982
+ * The Terraform label of the app that owns a file-reader token. Another
983
+ * app's reader is scoped under that app, built here or authored but left out
984
+ * of this build. An element-owned reader is reachable only from its own
985
+ * element: the provider and export do not carry one across owners yet.
986
+ */
987
+ function fileReaderOwnerTfLabel(value, ctx) {
988
+ const owner = value.parent;
989
+ if (owner === undefined || owner === ctx.appRefName)
990
+ return ctx.appTfLabel;
991
+ const app = ctx.workspaceAspects?.get(workspaceAspectKey("app", owner));
992
+ if (app !== undefined)
993
+ return app.tfLabel;
994
+ const outOfScope = ctx.outOfScopeApps?.get(owner)?.namespace;
995
+ if (outOfScope !== undefined)
996
+ return outOfScope;
997
+ if (ctx.workspaceAspects?.get(workspaceAspectKey("element", owner)) !== undefined) {
998
+ throw new EntityTfError(`automation ${ctx.automationTfLabel}: file reader "${owner}.${value.refName}" is owned by element "${owner}" — ` +
999
+ "a file reader is referenced across owners only from an app");
1000
+ }
1001
+ throw new EntityTfError(`automation ${ctx.automationTfLabel}: file reader "${owner}.${value.refName}" is owned by "${owner}", which is not an app in this workspace`);
1002
+ }
991
1003
  function procedureToTf(value, ctx, dataBlocks) {
992
1004
  if (value.__kind !== "procedure")
993
1005
  throw new EntityTfError("procedure requires a procedure catalog reference");
@@ -1209,36 +1221,75 @@ function calculationTaskRefName(targetType, name, taskRefKey, refs) {
1209
1221
  const fieldKey = segments[1];
1210
1222
  return [
1211
1223
  "record.",
1212
- calculationRawFieldId(fieldKey) ?? calculationRecordFieldId(fieldKey, calculationFieldScope(taskRefKey, refs)),
1224
+ calculationRawFieldId(fieldKey) ?? calculationFoundRecordFieldId(fieldKey, taskRefKey, refs),
1213
1225
  suffix.length > 0 ? `.${suffix}` : "",
1214
1226
  ];
1215
1227
  }
1216
- const refName = TASK_OUTPUT_REFERENCE_NAMES[targetType]?.[name] ?? name;
1228
+ const refName = taskOutputReferenceName(targetType, name, refs.tasks.get(taskRefKey)) ?? name;
1217
1229
  if (refName.includes('"')) {
1218
1230
  throw new EntityTfError(`calculation task output name "${refName}" contains a double quote`);
1219
1231
  }
1220
1232
  return [refName];
1221
1233
  }
1234
+ /** A refs key's WorkflowTaskReference name. An apiRequest maps only when it's JSON; FILE and CUSTOM are unconfirmed live (edk#2058). */
1235
+ function taskOutputReferenceName(type, wireName, task) {
1236
+ if (type === TASK_RESOURCES.api && task?.jsonApiResponse !== true)
1237
+ return undefined;
1238
+ return TASK_OUTPUT_REFERENCE_NAMES[type]?.[wireName];
1239
+ }
1240
+ /**
1241
+ * The calc-engine field id of a found record's field. A field of an aspect in
1242
+ * this build is its resource id. A sibling the workspace authors but this
1243
+ * build leaves out (pull builds only the pulled root, #1763) is read through
1244
+ * the same `data.elementum_field` lookup ei's export declares for it; the
1245
+ * whole-workspace build, which has the sibling, addresses its resource.
1246
+ */
1247
+ function calculationFoundRecordFieldId(fieldKey, taskRefKey, refs) {
1248
+ const taskApp = refs.recordFieldContext?.taskAppRefNameByRefKey?.[taskRefKey];
1249
+ const recordTargetKind = refs.tasks.get(taskRefKey)?.recordTarget?.__kind;
1250
+ const kind = refs.recordFieldContext?.taskAppKindByRefKey?.[taskRefKey] ??
1251
+ (recordTargetKind === "app" || recordTargetKind === "element" ? recordTargetKind : undefined);
1252
+ // An app and an element may share a refName, so "outside this build" and
1253
+ // "authored" are both checked by kind. (The owner check and the display-name
1254
+ // map below are still keyed by refName only.)
1255
+ const outsideBuild = taskApp !== undefined && taskApp !== refs.owner.appRefName && kind !== undefined &&
1256
+ refs.owner.workspaceAspects !== undefined && !refs.owner.workspaceAspects.has(workspaceAspectKey(kind, taskApp));
1257
+ if (!outsideBuild)
1258
+ return calculationRecordFieldId(fieldKey, calculationFieldScope(taskRefKey, refs));
1259
+ if (refs.owner.authoredAspectKeys?.has(workspaceAspectKey(kind, taskApp)) !== true)
1260
+ throw calculationNotAuthoredError(taskApp);
1261
+ const lookup = foreignFoundRecordFieldId(fieldKey, taskRefKey, refs);
1262
+ if (lookup !== undefined)
1263
+ return lookup;
1264
+ if (refs.fieldNamesByAppRefName?.get(taskApp) !== undefined) {
1265
+ throw new EntityTfError(`automation calculation targets field "${fieldKey}" which does not exist in app "${taskApp}"`);
1266
+ }
1267
+ throw new EntityTfError(`automation calculation reads field "${fieldKey}" of "${taskApp}", which is authored but outside this build, ` +
1268
+ `and its field names are not in the workspace catalog — run \`elementum generate\` and retry`);
1269
+ }
1222
1270
  /**
1223
1271
  * The aspect whose fields a task's `record.<field>` output belongs to. A
1224
1272
  * cross-aspect `recordSearch` reads the SEARCHED aspect's fields, and the
1225
- * calc engine wants their ids, so that aspect must be part of this build —
1226
- * a `data.elementum_app` stub carries display names but no field resources.
1273
+ * calc engine wants their ids, so that aspect must be authored in this
1274
+ * workspace — a `data.elementum_app` stub carries display names but no field
1275
+ * resources.
1227
1276
  */
1228
1277
  function calculationFieldScope(taskRefKey, refs) {
1229
1278
  const taskApp = refs.recordFieldContext?.taskAppRefNameByRefKey?.[taskRefKey];
1230
1279
  if (taskApp === undefined || taskApp === refs.owner.appRefName)
1231
1280
  return refs.owner;
1232
1281
  const fieldAddresses = refs.fieldAddressesByAppRefName?.get(taskApp);
1233
- if (fieldAddresses === undefined) {
1234
- throw new EntityTfError(`automation calculation reads a field of "${taskApp}", but that app/element is not authored in ` +
1235
- `this workspace — the calc engine addresses a found record's field by field id, which only a ` +
1236
- `built aspect can supply`);
1237
- }
1282
+ if (fieldAddresses === undefined)
1283
+ throw calculationNotAuthoredError(taskApp);
1238
1284
  const aspect = refs.owner.workspaceAspects?.get(workspaceAspectKey("app", taskApp))
1239
1285
  ?? refs.owner.workspaceAspects?.get(workspaceAspectKey("element", taskApp));
1240
1286
  return { appRefName: taskApp, appTfLabel: aspect?.tfLabel ?? refs.owner.appTfLabel, fieldAddresses };
1241
1287
  }
1288
+ function calculationNotAuthoredError(taskApp) {
1289
+ return new EntityTfError(`automation calculation reads a field of "${taskApp}", but that app/element is not authored in ` +
1290
+ `this workspace — the calc engine addresses a found record's field by field id, which only a ` +
1291
+ `built aspect can supply`);
1292
+ }
1242
1293
  const FOUND_RECORD_TASK_TYPES = new Set([
1243
1294
  "elementum_record_search_task",
1244
1295
  "elementum_create_record_task",
@@ -1268,13 +1319,31 @@ function foundRecordFieldReferenceName(targetType, name, taskRefKey, refs) {
1268
1319
  }
1269
1320
  }
1270
1321
  function foreignFoundRecordFieldReferenceName(segments, taskRefKey, refs) {
1322
+ // Reached only when the field id could not be resolved above. An
1323
+ // updateField record of an aspect the workspace does not author keeps the
1324
+ // display-label form it had before updateField carried a `recordTarget`; one
1325
+ // of an authored sibling outside this build already resolved to its
1326
+ // `data.elementum_field` lookup (the field-id form ei exports, #1763).
1327
+ if (refs.tasks.get(taskRefKey)?.type === TASK_RESOURCES.updateField)
1328
+ return undefined;
1329
+ const fieldId = foreignFoundRecordFieldId(segments[1], taskRefKey, refs);
1330
+ if (fieldId === undefined)
1331
+ return undefined;
1332
+ const suffix = segments.slice(2).join(".");
1333
+ return ["record.", fieldId, ...(suffix.length > 0 ? [`.${suffix}`] : [])];
1334
+ }
1335
+ /**
1336
+ * The `data.elementum_field` id of a found record's field when the record's
1337
+ * app/element is outside this build. Undefined when the task's target is in
1338
+ * this build or the field's display name is unknown.
1339
+ */
1340
+ function foreignFoundRecordFieldId(fieldKey, taskRefKey, refs) {
1271
1341
  const target = refs.tasks.get(taskRefKey)?.recordTarget;
1272
1342
  if (target === undefined || (target.__kind !== "app" && target.__kind !== "element") || target.name === undefined) {
1273
1343
  return undefined;
1274
1344
  }
1275
1345
  if (refs.owner.workspaceAspects?.has(workspaceAspectKey(target.__kind, target.refName)))
1276
1346
  return undefined;
1277
- const fieldKey = segments[1];
1278
1347
  const fieldName = refs.fieldNamesByAppRefName?.get(target.refName)?.get(fieldKey);
1279
1348
  if (fieldName === undefined)
1280
1349
  return undefined;
@@ -1287,12 +1356,7 @@ function foreignFoundRecordFieldReferenceName(segments, taskRefKey, refs) {
1287
1356
  parentName: target.name,
1288
1357
  ...(target.namespace !== undefined ? { parentNamespace: target.namespace } : {}),
1289
1358
  };
1290
- const suffix = segments.slice(2).join(".");
1291
- return [
1292
- "record.",
1293
- expr.dataAttr("elementum_field", registerForeignFieldLookup(fieldToken, refs.owner, refs.dataBlocks), ["id"]),
1294
- ...(suffix.length > 0 ? [`.${suffix}`] : []),
1295
- ];
1359
+ return expr.dataAttr("elementum_field", registerForeignFieldLookup(fieldToken, refs.owner, refs.dataBlocks), ["id"]);
1296
1360
  }
1297
1361
  function calculationTriggerMustache(name, refs) {
1298
1362
  const onDemandName = onDemandTriggerRefName(name, refs);
@@ -1685,6 +1749,9 @@ function taskOutputWireRefKey(targetType, name, taskRefKey, refs) {
1685
1749
  if (scriptIndex !== undefined)
1686
1750
  return scriptIndex;
1687
1751
  }
1752
+ const aiIndex = aiCompletionRefsIndex(targetType, name);
1753
+ if (aiIndex !== undefined)
1754
+ return aiIndex;
1688
1755
  return taskWireRefName(name, taskRefKey, refs);
1689
1756
  }
1690
1757
  /** The platform's own on-demand "Triggered By" refs (live refs-map keys). */
@@ -1743,14 +1810,6 @@ function recordParamFieldWireName(paramName, suffix, refs) {
1743
1810
  : fieldNamesForAppRefName(refs.fieldNamesByAppRefName, targetRefName);
1744
1811
  return wireRefName(`record.${suffix}`, recordOwnerContext(refs.owner, targetRefName, target.__kind === "element" || target.__kind === "app" ? target.__kind : undefined, targetFieldNames));
1745
1812
  }
1746
- /** Run-automation targets reference publish for ACTIVE automations, automation for draft/inactive. */
1747
- export function automationRunTargetResourceAttr(appTfLabel, automationRefName, activeAutomationRefNames, scope = "app", handle) {
1748
- const label = automationResourceLabel(appTfLabel, automationRefName, scope, handle);
1749
- if (activeAutomationRefNames?.has(automationRefName) === true) {
1750
- return expr.resourceAttr(WORKFLOW_PUBLISH_RESOURCE_TYPE, label, ["id"]);
1751
- }
1752
- return expr.resourceAttr(AUTOMATION_RESOURCE_TYPE, label, ["id"]);
1753
- }
1754
1813
  const UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
1755
1814
  const ISO_DATE_PATTERN = /^\d{4}-\d{2}-\d{2}$/;
1756
1815
  /** The provider's `ValidateFieldValue` datetime shape: seconds and a timezone are required. */
@@ -2049,6 +2108,21 @@ function aiAgentPlatformRefName(refsKey) {
2049
2108
  }
2050
2109
  return `ai_agent_task_structured_output.${refsKey.toLowerCase()}`;
2051
2110
  }
2111
+ /**
2112
+ * Switch left-value name for one AI agent structured field, or undefined
2113
+ * when `wireName` is the whole text response (`refs["Action Response"]`).
2114
+ * Filter refs arrive already rewritten (`candidateCount`); a leftover
2115
+ * `result.<field>` is accepted too.
2116
+ */
2117
+ function aiAgentStructuredLeftValueName(wireName) {
2118
+ if (wireName === "Action Response" || wireName === "result" || wireName === "ai_agent_task_response") {
2119
+ return undefined;
2120
+ }
2121
+ const field = wireName.startsWith("result.") ? wireName.slice("result.".length) : wireName;
2122
+ if (field === "" || field === "Action Response")
2123
+ return undefined;
2124
+ return aiAgentPlatformRefName(field);
2125
+ }
2052
2126
  function publishOutputType(value, target, wireName) {
2053
2127
  if (typeof value.fieldType === "string") {
2054
2128
  return { fieldType: value.fieldType, multiple: value.multiple === true };
@@ -2099,16 +2173,6 @@ function collectUnresolvedForEachItems(value, found) {
2099
2173
  for (const nested of Object.values(value))
2100
2174
  collectUnresolvedForEachItems(nested, found);
2101
2175
  }
2102
- /** The onDemand trigger's record parameters: they expose only a record ID. */
2103
- function onDemandRecordParamNames(trigger) {
2104
- const inputs = trigger?.onDemand?.inputs;
2105
- if (!Array.isArray(inputs))
2106
- return new Set();
2107
- return new Set(inputs.flatMap((input) => {
2108
- const param = input;
2109
- return typeof param?.name === "string" && isOnDemandRecordType(typeof param.type === "string" ? param.type : undefined) ? [param.name] : [];
2110
- }));
2111
- }
2112
2176
  /** refKey → task kind (`findRelatedRecords`, …) for every task, nested ones included. */
2113
2177
  function collectPayloadTaskKinds(value, kinds) {
2114
2178
  if (Array.isArray(value)) {
@@ -2721,6 +2785,23 @@ function filterReferenceToTf(value, refs, role = "value", realType, operator) {
2721
2785
  },
2722
2786
  });
2723
2787
  }
2788
+ // An AI agent's structured field is `refs["<field>"]` on a task input
2789
+ // (#759). A switch left-value is the other spelling: a NUMBER (or
2790
+ // other) envelope whose taskReference.name is
2791
+ // `ai_agent_task_structured_output.<field>` (#2096). Emitting the
2792
+ // refs index here plans that envelope away after every pull.
2793
+ const aiAgentStructuredName = isAiAgentTask ? aiAgentStructuredLeftValueName(wireName) : undefined;
2794
+ if (aiAgentStructuredName !== undefined) {
2795
+ const declared = task.outputFieldTypes?.get(wireName);
2796
+ return expr.jsonencode({
2797
+ fieldType: (realType ?? declared?.fieldType ?? "TEXT").toUpperCase(),
2798
+ multiple: declared?.multiple === true,
2799
+ taskReference: {
2800
+ name: aiAgentStructuredName,
2801
+ taskId: expr.resourceAttr(task.type, task.label, ["id"]),
2802
+ },
2803
+ });
2804
+ }
2724
2805
  // An explicit filter.text() on a runAutomation output is a TEXT
2725
2806
  // envelope. A missing realType stays on .refs; the provider's refs
2726
2807
  // map is already TEXT for outputs ei stores that way.
@@ -2741,7 +2822,7 @@ function filterReferenceToTf(value, refs, role = "value", realType, operator) {
2741
2822
  // `multiple` follows the declaration so an array output is not
2742
2823
  // flattened. A NUMBER comparison of a DECIMAL script output is the
2743
2824
  // next branch (#1618).
2744
- const envelopeName = TASK_OUTPUT_REFERENCE_NAMES[task.type]?.[wireName] ?? wireName;
2825
+ const envelopeName = taskOutputReferenceName(task.type, wireName, task) ?? wireName;
2745
2826
  const executor = RESOURCE_TYPE_TO_EXECUTOR[task.type];
2746
2827
  const declared = task.outputFieldTypes?.get(wireName) ??
2747
2828
  (executor === undefined ? undefined : TASK_OUTPUT_CONTRACTS[executor]?.[envelopeName]);
@@ -2820,7 +2901,7 @@ function filterReferenceToTf(value, refs, role = "value", realType, operator) {
2820
2901
  }
2821
2902
  const refsIndex = task.type === TASK_RESOURCES.executeScript
2822
2903
  ? executeScriptRefsIndex(wireName) ?? wireName
2823
- : wireName;
2904
+ : aiCompletionRefsIndex(task.type, wireName) ?? wireName;
2824
2905
  return expr.resourceAttr(task.type, task.label, ["refs", { index: refsIndex }]);
2825
2906
  }
2826
2907
  const recordFieldName = foundRecordFieldReferenceName(task.type, value.name, value.taskRefKey, refs);
@@ -2835,7 +2916,9 @@ function filterReferenceToTf(value, refs, role = "value", realType, operator) {
2835
2916
  : task.type === TASK_RESOURCES.recordSearch &&
2836
2917
  (wireName === "First found record id" || value.name === "record.recordId" || value.name === "recordId")
2837
2918
  ? "recordId"
2838
- : canonicalSingleOutputName(task.type, wireName) ?? wireName;
2919
+ : task.type === TASK_RESOURCES.api
2920
+ ? taskOutputReferenceName(task.type, wireName, task) ?? wireName
2921
+ : canonicalSingleOutputName(task.type, wireName) ?? wireName;
2839
2922
  return expr.template([
2840
2923
  "task.",
2841
2924
  expr.resourceAttr(task.type, task.label, ["id"]),
@@ -3078,6 +3161,10 @@ function configAttrs(kind, config, refs) {
3078
3161
  // default so build matches export's omit-when-1 convention.
3079
3162
  if (kind === "elementum_schedule_trigger" && key === "interval" && raw === 1)
3080
3163
  continue;
3164
+ if (kind === "elementum_temporal_trigger" && key === "aspectFieldId") {
3165
+ attrs.aspect_field_id = valueToTf(raw, refs);
3166
+ continue;
3167
+ }
3081
3168
  // A config value of exactly `undefined` almost always means the
3082
3169
  // authoring builder was called with a required option omitted (e.g. a
3083
3170
  // TS-only-enforced field that no runtime actually type-checks at
@@ -3163,6 +3250,20 @@ function configAttrs(kind, config, refs) {
3163
3250
  continue;
3164
3251
  }
3165
3252
  const resolvedTarget = automationTargetToTf(target, refs.owner, refs.dataBlocks);
3253
+ const recordInputProblem = recordInputMappingProblem(target, raw, resolvedTarget.recordInputNames);
3254
+ if (recordInputProblem !== undefined) {
3255
+ // The recorded unit is the whole automation (#2250): a key in
3256
+ // applied-automation-revisions.json means the platform already runs
3257
+ // this file, so a later edit of the mapping is reported too. Pull
3258
+ // reports and keeps emitting, the same as a record-id field mapping
3259
+ // (#1499), so the first pull can write that key. Build, plan, and
3260
+ // apply still refuse an automation the record does not have. The
3261
+ // report is an advisory (coverage-gaps.ts): the mapping is emitted
3262
+ // as authored, and the failure is at workflow runtime.
3263
+ if (!refs.owner.pulledLive && currentValidationMode() !== "pull")
3264
+ throw new EntityTfError(recordInputProblem);
3265
+ refs.owner.diagnostics.push(`automation ${refs.owner.automationTfLabel}: ${recordInputProblem}`);
3266
+ }
3166
3267
  attrs.input_mappings = raw.map((mapping) => {
3167
3268
  if (!isObject(mapping) || typeof mapping.name !== "string" || mapping.value === undefined) {
3168
3269
  throw new EntityTfError("runAutomation input mapping requires name and value");
@@ -3198,6 +3299,11 @@ function configAttrs(kind, config, refs) {
3198
3299
  }
3199
3300
  const target = token(raw.value);
3200
3301
  if (target?.__kind === "automation") {
3302
+ // The label below is the caller's own; another owner would bind a same-named automation (edk#2118).
3303
+ if (!automationTargetOwner(target, refs.owner).isOwn) {
3304
+ throw new EntityTfError(`runAutomation STATIC targetAutomationRef "${target.parent ?? ""}.${target.refName}" is owned by another ` +
3305
+ "app or element; pass the automation as `automation` (targetAutomationId) so it resolves by its owner");
3306
+ }
3201
3307
  attrs["target_automation_ref"] = automationRunTargetResourceAttr(refs.owner.appTfLabel, target.refName, refs.owner.activeAutomationRefNames, refs.owner.parentScope, refs.owner.ownerHandle);
3202
3308
  continue;
3203
3309
  }
@@ -3675,6 +3781,9 @@ export function automationToTf(entity, ctx) {
3675
3781
  ownerHandle: ctx.ownerHandle,
3676
3782
  appTfLabel: ctx.appTfLabel,
3677
3783
  automationTfLabel,
3784
+ pulledLive: ctx.workspaceAspects
3785
+ ?.get(workspaceAspectKey(ctx.parentScope ?? "app", ctx.appRefName ?? entity.parent))
3786
+ ?.pulledAutomationRefNames?.has(entity.refName) === true,
3678
3787
  fieldAddresses: ctx.fieldAddresses ?? new Map(),
3679
3788
  fieldNames: ctx.fieldNames ?? new Map(),
3680
3789
  fieldMetadata: ctx.fieldMetadata ?? new Map(),
@@ -3686,6 +3795,7 @@ export function automationToTf(entity, ctx) {
3686
3795
  activeAutomationRefNames: ctx.activeAutomationRefNames,
3687
3796
  ...(ctx.elementsWithoutAuditFields !== undefined ? { elementsWithoutAuditFields: ctx.elementsWithoutAuditFields } : {}),
3688
3797
  ...(ctx.fieldAddressesByAppRefName !== undefined ? { fieldAddressesByAppRefName: ctx.fieldAddressesByAppRefName } : {}),
3798
+ ...(ctx.authoredAspectKeys !== undefined ? { authoredAspectKeys: ctx.authoredAspectKeys } : {}),
3689
3799
  recordLacksAuditFields: ctx.parentScope === "element" && ctx.ownerAuditFields !== true,
3690
3800
  };
3691
3801
  if (entity.kind !== "automation")
@@ -3801,7 +3911,8 @@ export function automationToTf(entity, ctx) {
3801
3911
  ? [[field.name, { fieldType: field.type, multiple: false }]]
3802
3912
  : []))
3803
3913
  : undefined;
3804
- const recordTarget = FOUND_RECORD_TASK_TYPES.has(resourceType)
3914
+ // updateField's `record` output is the record it updated, of its `aspectId` app/element.
3915
+ const recordTarget = FOUND_RECORD_TASK_TYPES.has(resourceType) || resourceType === TASK_RESOURCES.updateField
3805
3916
  ? token(taskBody.aspectId ?? taskBody.relatedAspectId)
3806
3917
  : undefined;
3807
3918
  taskRefs.set(refKey, {
@@ -3810,6 +3921,7 @@ export function automationToTf(entity, ctx) {
3810
3921
  ...(wireType === "unimplementedTask" ? { isData: true } : {}),
3811
3922
  ...(outputFieldTypes !== undefined && outputFieldTypes.size > 0 ? { outputFieldTypes } : {}),
3812
3923
  ...(recordTarget !== undefined ? { recordTarget } : {}),
3924
+ ...(wireType === "api" && (taskBody.responseType ?? "JSON") === "JSON" ? { jsonApiResponse: true } : {}),
3813
3925
  });
3814
3926
  if (wireType === "variable" && Array.isArray(taskBody.create)) {
3815
3927
  taskBody.create.forEach((candidate, index) => {
@@ -4050,7 +4162,8 @@ export function automationToTf(entity, ctx) {
4050
4162
  const block = { kind: "resource", type: resourceType, label: tfLabel, attrs };
4051
4163
  if (wireType === "runAutomation") {
4052
4164
  const target = token(inner.targetAutomationId) ?? (isObject(inner.targetAutomationRef) ? token(inner.targetAutomationRef.value) : undefined);
4053
- if (target?.__kind === "automation") {
4165
+ // Own targets only: another owner's publish edge rides its `_for_<caller>` lookup (edk#2118).
4166
+ if (target?.__kind === "automation" && automationTargetOwner(target, owner).isOwn) {
4054
4167
  const targetLabel = scopedLabel(owner.appTfLabel, tsLabelToTfLabel(target.refName));
4055
4168
  // Only a running (ACTIVE) target is a run dependency. A paused
4056
4169
  // target keeps its publish resource, but ei export does not wait
@@ -80,13 +80,13 @@ export interface WebhookTriggerOptions {
80
80
  readonly customResponse?: {
81
81
  readonly success: {
82
82
  readonly enabled: boolean;
83
- readonly format: "JSON" | "XML" | "Text";
83
+ readonly format: "JSON" | "XML" | "TEXT";
84
84
  readonly statusCode: number;
85
85
  readonly body: string;
86
86
  };
87
87
  readonly failure: {
88
88
  readonly enabled: boolean;
89
- readonly format: "JSON" | "XML" | "Text";
89
+ readonly format: "JSON" | "XML" | "TEXT";
90
90
  readonly statusCode: number;
91
91
  readonly body: string;
92
92
  };
@@ -94,7 +94,14 @@ export interface WebhookTriggerOptions {
94
94
  }
95
95
  /** The inbound request payload exposed to tasks. */
96
96
  export interface WebhookTriggerOutput {
97
+ /**
98
+ * `body["Plain Text"]` is the raw request body. A named key such as
99
+ * `body["Title"]` exists only after the trigger has seen a sample request,
100
+ * which only the Elementum UI can capture, so plan refuses it on a trigger
101
+ * the run creates (edk#2047).
102
+ */
97
103
  readonly body: Record<string, unknown>;
104
+ /** Named header keys, like named body keys, exist only after a sample request. */
98
105
  readonly headers: Record<string, unknown>;
99
106
  }
100
107
  /** Fires on an inbound HTTP webhook. */
@@ -107,10 +114,14 @@ export interface TemporalTriggerOptions<A extends AppOrElementRef = AppOrElement
107
114
  readonly field: FieldRef;
108
115
  readonly temporalUnit: TemporalUnit;
109
116
  readonly value: number;
117
+ /** Pre-built wire `Filter` (may embed `FieldRef` tokens — resolved at deploy). */
118
+ readonly filter?: Filter;
110
119
  }
111
120
  /** Fires relative to a date/datetime field on records in the given aspect. */
112
121
  export declare function temporal<A extends AppOrElementRef>(opts: TemporalTriggerOptions<A>): TriggerChain<RecordTriggerOutput<A>>;
113
- export type approvalProcessStatusUpdatedStatus = "ACTIVE" | "STEP_APPROVED" | "CANCELLED" | "DENIED" | "APPROVED";
122
+ export type approvalProcessStatusUpdatedStatus = "ACTIVE" | "STEP_APPROVED" | "CANCELLED" | "DENIED" | "APPROVED"
123
+ /** The approval process's exception button (shown in the web app under the button's own name). */
124
+ | "EXCEPTION";
114
125
  export interface approvalProcessStatusUpdatedTriggerOptions<A extends AppOrElementRef = AppOrElementRef> {
115
126
  readonly app: A;
116
127
  /**
@@ -155,6 +166,12 @@ export interface DataMineTriggerOptions {
155
166
  readonly datamine: DatamineRef | UnsafePlatformId;
156
167
  readonly fireOnAlert?: boolean;
157
168
  readonly fireOnRecovery?: boolean;
169
+ /**
170
+ * Trigger Condition: the datamine's records must also match it (edk#2287).
171
+ * Column references must be columns of the datamine's own table. Leaving it
172
+ * out means no condition, the same as the platform's `filter: null`.
173
+ */
174
+ readonly filter?: Filter;
158
175
  }
159
176
  export interface DataMineTriggerOutput {
160
177
  readonly record: Record<string, unknown>;
@@ -232,6 +249,8 @@ export interface SurveyResponseCreateTriggerOptions {
232
249
  * explicit wrapper marks this platform-owned value as non-portable.
233
250
  */
234
251
  readonly survey: UnsafePlatformId;
252
+ /** Trigger Condition: the record the survey was completed for must match it (edk#2206). */
253
+ readonly filter?: Filter;
235
254
  }
236
255
  export type SurveyResponseCreateTriggerOutput = Record<string, unknown>;
237
256
  /** Fires when a response is created for the selected survey template. */
@@ -105,6 +105,7 @@ export function temporal(opts) {
105
105
  aspectFieldId: opts.field,
106
106
  temporalUnit: opts.temporalUnit,
107
107
  value: opts.value,
108
+ ...(opts.filter !== undefined ? { filter: opts.filter } : {}),
108
109
  type: "TEMPORAL",
109
110
  },
110
111
  },
@@ -140,8 +141,44 @@ export function attachment(opts) {
140
141
  __recordApp: opts.app.refName,
141
142
  });
142
143
  }
144
+ /**
145
+ * The owner check for a datamine trigger's condition (edk#2287): the record it
146
+ * tests is a row of the datamine's table, so every condition field must be a
147
+ * column of that table. Another table's column, or an app or element field,
148
+ * can't match the row. A raw `unsafePlatformId` datamine carries no table, so
149
+ * there is nothing to check against.
150
+ */
151
+ function assertDataMineFilterOnDatamineTable(datamine, condition) {
152
+ const table = datamine.__kind === "datamine" ? datamine.parent : undefined;
153
+ if (table === undefined)
154
+ return;
155
+ const datamineName = datamine.name || datamine.refName;
156
+ const visit = (node) => {
157
+ if (typeof node !== "object" || node === null)
158
+ return;
159
+ const { field, children } = node;
160
+ if (typeof field === "object" && field !== null && typeof field.__kind === "string") {
161
+ const ref = field;
162
+ const label = String(ref.name || ref.refName);
163
+ if (ref.__kind !== "tableColumn") {
164
+ throw new EdkValidationError(`dataMine filter: "${label}" is ${ref.__kind === "field" ? "an app or element field" : `a ${ref.__kind} reference`}, but a datamine trigger's ` +
165
+ `condition tests the rows of datamine "${datamineName}" (table "${table}"). Use a column of that table, ` +
166
+ `for example org.tables.${table}.columns.<column>.`);
167
+ }
168
+ if (ref.parent !== table) {
169
+ throw new EdkValidationError(`dataMine filter: column "${label}" belongs to table "${String(ref.parent)}", but datamine "${datamineName}" ` +
170
+ `reads table "${table}". A datamine trigger's condition can only test columns of the datamine's own table.`);
171
+ }
172
+ }
173
+ if (Array.isArray(children))
174
+ children.forEach(visit);
175
+ };
176
+ visit(condition);
177
+ }
143
178
  /** Fires when a data mine meets/no longer meets requirements. */
144
179
  export function dataMine(opts) {
180
+ if (opts.filter !== undefined)
181
+ assertDataMineFilterOnDatamineTable(opts.datamine, opts.filter);
145
182
  return chainableTrigger({
146
183
  wire: {
147
184
  datamine: {
@@ -149,6 +186,7 @@ export function dataMine(opts) {
149
186
  type: "DATAMINE",
150
187
  ...(opts.fireOnAlert !== undefined ? { fireOnAlert: opts.fireOnAlert } : {}),
151
188
  ...(opts.fireOnRecovery !== undefined ? { fireOnRecovery: opts.fireOnRecovery } : {}),
189
+ ...(opts.filter !== undefined ? { filter: opts.filter } : {}),
152
190
  },
153
191
  },
154
192
  });
@@ -208,8 +246,10 @@ export function surveyResponseCreate(opts) {
208
246
  survey: {
209
247
  aspectId: opts.app,
210
248
  surveyTemplateId: opts.survey,
249
+ ...(opts.filter !== undefined ? { filter: opts.filter } : {}),
211
250
  type: "SURVEY_RESPONSE_CREATE",
212
251
  },
213
252
  },
253
+ __recordApp: opts.app.refName,
214
254
  });
215
255
  }
@@ -40,6 +40,27 @@ export declare function automationResourceLabel(ownerTfLabel: string, refName: s
40
40
  export declare const TABLE_RECORDS_SEARCH_TASK_RESOURCE_TYPE = "elementum_table_records_search_task";
41
41
  /** Trigger kinds. One trigger per automation. Phase 1: onDemand only. */
42
42
  export declare const TRIGGER_SUB_TYPES: readonly AutomationSubType[];
43
+ /**
44
+ * A webhook trigger's request refs are named "Body (<key>)" and
45
+ * "Headers (<key>)": one wire key naming both the `body`/`headers` property
46
+ * of `WebhookTriggerOutput` and the request key under it.
47
+ */
48
+ export declare const WEBHOOK_REQUEST_REF_PATTERN: RegExp;
49
+ /** The raw request body, `ctx.trigger.body["Plain Text"]`. */
50
+ export declare const WEBHOOK_RAW_BODY_REF = "Body (Plain Text)";
51
+ /**
52
+ * A webhook request ref that exists only after the platform has seen a sample
53
+ * request, as the authored path (`body["Title"]` is `{ property: "body",
54
+ * key: "Title" }`), or undefined for any other ref. Named body and header keys
55
+ * appear in the trigger's refs only once a sample request has been captured,
56
+ * which only the Elementum UI can do. A newly created webhook trigger
57
+ * publishes just "Body (Plain Text)" and "contentType" (edk#2047), so indexing
58
+ * any other request ref on it fails apply with "Invalid index".
59
+ */
60
+ export declare function webhookSampleOnlyRef(refKey: string): {
61
+ readonly property: "body" | "headers";
62
+ readonly key: string;
63
+ } | undefined;
43
64
  /**
44
65
  * Task kinds. All rows are implemented as of `aiFileAnalysis` (the last
45
66
  * holdout — it needs its `elementum_ai_file_reader` target to also round-trip,