@elementumai/edk 0.11.0 → 0.12.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 (72) hide show
  1. package/README.md +38 -6
  2. package/dist-sdk/src/core/triggers/on-demand.d.ts +2 -0
  3. package/dist-sdk/src/core/triggers/on-demand.js +3 -0
  4. package/dist-sdk/src/engine/coverage-gaps.d.ts +5 -0
  5. package/dist-sdk/src/engine/coverage-gaps.js +9 -0
  6. package/dist-sdk/src/engine/ei/run.d.ts +20 -1
  7. package/dist-sdk/src/engine/ei/run.js +102 -14
  8. package/dist-sdk/src/engine/pull/ref-only.d.ts +18 -0
  9. package/dist-sdk/src/engine/pull/ref-only.js +52 -0
  10. package/dist-sdk/src/entities/access-policy/from-tf.d.ts +2 -1
  11. package/dist-sdk/src/entities/access-policy/from-tf.js +7 -1
  12. package/dist-sdk/src/entities/access-policy/module.js +5 -0
  13. package/dist-sdk/src/entities/app/build.d.ts +1 -1
  14. package/dist-sdk/src/entities/app/build.js +79 -4
  15. package/dist-sdk/src/entities/app/from-tf.js +1 -2
  16. package/dist-sdk/src/entities/app/stage-keys.d.ts +18 -3
  17. package/dist-sdk/src/entities/app/stage-keys.js +40 -6
  18. package/dist-sdk/src/entities/app/to-tf.js +1 -0
  19. package/dist-sdk/src/entities/automation/build.d.ts +50 -24
  20. package/dist-sdk/src/entities/automation/build.js +16 -6
  21. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +32 -3
  22. package/dist-sdk/src/entities/automation/from-tf.d.ts +13 -2
  23. package/dist-sdk/src/entities/automation/from-tf.js +269 -63
  24. package/dist-sdk/src/entities/automation/index.d.ts +1 -1
  25. package/dist-sdk/src/entities/automation/module.js +1 -1
  26. package/dist-sdk/src/entities/automation/run-target.d.ts +2 -0
  27. package/dist-sdk/src/entities/automation/run-target.js +5 -0
  28. package/dist-sdk/src/entities/automation/script-code.d.ts +2 -1
  29. package/dist-sdk/src/entities/automation/script-code.js +82 -1
  30. package/dist-sdk/src/entities/automation/script-lint.d.ts +13 -0
  31. package/dist-sdk/src/entities/automation/script-lint.js +418 -0
  32. package/dist-sdk/src/entities/automation/task-output-labels.d.ts +1 -1
  33. package/dist-sdk/src/entities/automation/task-output-labels.js +9 -1
  34. package/dist-sdk/src/entities/automation/tasks.d.ts +47 -14
  35. package/dist-sdk/src/entities/automation/tasks.js +18 -4
  36. package/dist-sdk/src/entities/automation/to-tf.js +256 -28
  37. package/dist-sdk/src/entities/automation/triggers.d.ts +48 -15
  38. package/dist-sdk/src/entities/automation/triggers.js +9 -9
  39. package/dist-sdk/src/entities/chart/build.d.ts +9 -1
  40. package/dist-sdk/src/entities/chart/from-tf.d.ts +2 -2
  41. package/dist-sdk/src/entities/chart/from-tf.js +25 -1
  42. package/dist-sdk/src/entities/chart/index.d.ts +1 -1
  43. package/dist-sdk/src/entities/chart/printer.js +5 -2
  44. package/dist-sdk/src/entities/chart/to-tf.js +19 -1
  45. package/dist-sdk/src/entities/dynamic-layout/build.d.ts +1 -0
  46. package/dist-sdk/src/entities/dynamic-layout/condition-keys.d.ts +48 -0
  47. package/dist-sdk/src/entities/dynamic-layout/condition-keys.js +261 -0
  48. package/dist-sdk/src/entities/dynamic-layout/from-tf.js +1 -1
  49. package/dist-sdk/src/entities/dynamic-layout/module.js +2 -1
  50. package/dist-sdk/src/entities/element/to-tf.js +1 -0
  51. package/dist-sdk/src/entities/field/module.js +8 -2
  52. package/dist-sdk/src/entities/field/to-tf.d.ts +8 -2
  53. package/dist-sdk/src/entities/field/to-tf.js +57 -34
  54. package/dist-sdk/src/entities/org/role.js +5 -0
  55. package/dist-sdk/src/entities/service-account/module.js +5 -0
  56. package/dist-sdk/src/entities/service-account/role-fidelity.d.ts +5 -5
  57. package/dist-sdk/src/entities/service-account/role-fidelity.js +21 -13
  58. package/dist-sdk/src/entities/shared/filters/ast.d.ts +2 -0
  59. package/dist-sdk/src/entities/shared/types/field-types.d.ts +6 -3
  60. package/dist-sdk/src/entities/shared/types/field-types.js +3 -1
  61. package/dist-sdk/src/entities/skill/module.js +2 -0
  62. package/dist-sdk/src/entities/task/to-tf.js +1 -0
  63. package/dist-sdk/src/entities/view/from-tf.d.ts +8 -4
  64. package/dist-sdk/src/entities/view/from-tf.js +3 -5
  65. package/dist-sdk/src/entities/view/module.js +5 -0
  66. package/dist-sdk/src/entities/widget/from-tf.js +2 -2
  67. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +5 -3
  68. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
  69. package/dist-sdk/src/graph/index.d.ts +15 -2
  70. package/dist-sdk/src/graph/index.js +12 -0
  71. package/dist-sdk/src/graph/types.d.ts +38 -0
  72. package/package.json +1 -1
@@ -18,7 +18,7 @@ import { apiTaskRefAuthoringPath, executeScriptAuthoringPath, matchesOutputWireK
18
18
  import { RESOURCE_TYPE_TO_EXECUTOR, TASK_OUTPUT_CONTRACTS } from "./generated/task-output-contracts.js";
19
19
  import { systemRefNameRoundTrips } from "./system-ref-name.js";
20
20
  import { taskTfLabel } from "./task-label.js";
21
- import { parseTriggerAttachmentPayloadRefJson, parseTriggerWholeRecordRefJson, TRIGGER_WHOLE_RECORD_REF_NAME } from "./task-output-labels.js";
21
+ import { parseTriggerAttachmentPayloadRefJson, parseTriggerWholeRecordRefJson, TASK_OUTPUT_REFERENCE_NAMES, TRIGGER_WHOLE_RECORD_REF_NAME } from "./task-output-labels.js";
22
22
  import { workflowOutputTypeFromFieldType } from "./workflow-output.js";
23
23
  import { ALL_AUTOMATION_TASK_TYPE_SET, AUTOMATION_BRANCH_TYPE_SET, AUTOMATION_RESOURCE_TYPE, AUTOMATION_TRIGGER_TYPE_SET, WEBHOOK_REQUEST_REF_PATTERN, WORKFLOW_PUBLISH_RESOURCE_TYPE, } from "./types.js";
24
24
  const TRIGGER_KINDS = {
@@ -334,15 +334,18 @@ const TRIGGER_ATTRIBUTES = new Set([
334
334
  "frequency", "interval", "timezone", "start_at", "weekdays", "day_of_month",
335
335
  "end_at", "ends_after_count", "interval_unit",
336
336
  "aspect_field_id", "temporal_unit", "value",
337
+ // Build-derived from the owner's field order and never printed (edk#2280).
338
+ "object_field_ids",
337
339
  ]);
338
340
  const TASK_ATTRIBUTES = new Set([
339
- "parent", "name", "depends_on", "filter", "fields", "inputs", "output_schema",
341
+ "parent", "name", "depends_on", "object_field_ids", "filter", "fields", "inputs", "output_schema",
340
342
  "list", "code", "variables", "updates", "variable", "value",
341
343
  "object_id", "table_id", "record_reference", "record_id", "source_record_ids",
342
344
  "approval_process_id", "requester_reference", "approver_references", "reason", "summary",
343
345
  "approval_reference", "status",
344
346
  "target_record_id", "message", "message_body", "body", "from_username",
345
- "from_personal", "external_emails", "users", "groups", "attachments", "contents",
347
+ "from_personal", "external_emails", "users", "groups", "attachments", "email_attachments",
348
+ "email_send_domain_id", "contents",
346
349
  "agent_id", "prompt", "output_type", "json_fields", "ai_provider_connector_id",
347
350
  "url", "response_type", "continue_on_error", "search_table_id",
348
351
  "text_to_summarize", "text_to_classify", "field_type", "category_source", "dynamic_category_source",
@@ -513,7 +516,9 @@ function declaredOnDemandInputFieldType(trigger, wireName) {
513
516
  return undefined;
514
517
  return {
515
518
  // Inverse of to-tf's on-demand parameter type spelling.
516
- fieldType: parameter.type === "attachment" ? "ATTACHMENT_ID" : parameter.type.toUpperCase(),
519
+ fieldType: parameter.type === "attachment" ? "ATTACHMENT_ID"
520
+ : parameter.type === "group" ? "GROUP_ID"
521
+ : parameter.type.toUpperCase(),
517
522
  multiple: parameter.multiple === true,
518
523
  };
519
524
  }
@@ -593,9 +598,12 @@ export const AI_SEARCH_TABLE_TASK_REF_SEGMENT_TO_TS = {
593
598
  // proxy at build time and omits the script/filter input entirely.
594
599
  export const TABLE_RECORDS_SEARCH_TASK_REF_SEGMENT_TO_TS = {
595
600
  // Canonical count output `count` → the `totalCount` accessor (edk#835 — same
596
- // as recordSearch). "All matching table rows" is the legacy display form.
601
+ // as recordSearch).
597
602
  count: "totalCount",
603
+ // The refs keys a deployed task has (edk#2407, task-output-labels.ts).
598
604
  "All matching table rows": "records",
605
+ "First matching table row": "record",
606
+ "Row count": "totalCount",
599
607
  };
600
608
  // Platform-fixed output labels → authoring path, inverse of
601
609
  // task-output-labels.ts and executeScript's "Text Result". Scoped per task
@@ -604,6 +612,8 @@ const TASK_OUTPUT_LABEL_TO_TS = {
604
612
  elementum_record_search_task: { "First found record": ["record"] },
605
613
  elementum_create_record_task: { "Created record": ["record"] },
606
614
  elementum_update_field_task: { "Updated record": ["record"] },
615
+ // Build indexes bulkUpdateFields outputs by these display-label refs keys (edk#2281).
616
+ elementum_bulk_update_fields_task: Object.fromEntries(Object.entries(TASK_OUTPUT_REFERENCE_NAMES["elementum_bulk_update_fields_task"] ?? {}).map(([key, name]) => [key, [name]])),
607
617
  elementum_execute_script_task: {
608
618
  // Display keys. Canonical `result` / `stringArrayResult` are not refs keys;
609
619
  // `Result` is the whole JSON envelope, not a property named Result (#1656).
@@ -2211,7 +2221,17 @@ function decodeValue(value, ctx) {
2211
2221
  if (typeof name !== "string" || name === "") {
2212
2222
  throw new EntityTfError(`data.elementum_group.${value.label}: name lookup is missing`);
2213
2223
  }
2214
- const groupKey = ctx.groupKeysByName?.get(name) ?? tfLabelToTsLabel(sanitizeName(name));
2224
+ const orgKey = ctx.groupKeysByName?.get(name);
2225
+ if (orgKey === undefined && ctx.groupKeysByName !== undefined) {
2226
+ // The org catalog this pull loaded doesn't carry this group: org.ts
2227
+ // predates it, or org.ts is missing or failed to import (the pull
2228
+ // then passes an empty map). A guessed org.groups key would be
2229
+ // undefined at load and fail the build (edk#2241): print a by-name
2230
+ // groupRef, which builds to the same data.elementum_group lookup.
2231
+ ctx.groupsMissingFromOrg?.add(name);
2232
+ return { kind: "orgGroup", groupKey: tfLabelToTsLabel(sanitizeName(name)), name, inOrgCatalog: false };
2233
+ }
2234
+ const groupKey = orgKey ?? tfLabelToTsLabel(sanitizeName(name));
2215
2235
  return { kind: "orgGroup", groupKey, name };
2216
2236
  }
2217
2237
  if (value.$expr === "variable") {
@@ -2757,16 +2777,11 @@ function decodeCalculationTaskMustache(taskId, wireName, ctx) {
2757
2777
  const keyPath = wireName.split(".");
2758
2778
  const taskKind = taskBlock?.type !== undefined ? TASK_FACTORIES[taskBlock.type] : undefined;
2759
2779
  const wireOutputKey = taskKind !== undefined ? OUTPUT_KEY_WIRE_NAME[taskKind] : undefined;
2760
- // Case-SENSITIVE here, unlike the refs-map/envelope call sites: a
2761
- // calculation mustache carries the calc-engine's own lowercase name
2762
- // (WorkflowTaskReference, e.g. "response"), never the refs-map display
2763
- // key ("Response") - calculationTaskMustache already documents that the
2764
- // display label does not resolve in this dialect. Case-folding this site
2765
- // too made "response" fold to "output" (correct) but ALSO folded any
2766
- // other lowercase wire name that happens to match a wireOutputKey
2767
- // case-insensitively, rewriting the mustache as {{task name="Response"}}
2768
- // on the next build - a key the calc engine's real API never has either.
2769
- const outputKeyPath = wireOutputKey !== undefined && keyPath[0] === wireOutputKey
2780
+ // A calculation mustache names a single-output AI task's output by the calc
2781
+ // engine's canonical name (`response`), not the refs label (`Response`).
2782
+ // Both read back as `output`, which build writes as `response` (#2405).
2783
+ // Only the exact or lowercased wire key matches, as in the refs decoder.
2784
+ const outputKeyPath = wireOutputKey !== undefined && keyPath[0] !== undefined && matchesOutputWireKey(keyPath[0], wireOutputKey)
2770
2785
  ? ["output", ...keyPath.slice(1)]
2771
2786
  : keyPath.map((segment) => WIRE_REF_SEGMENT_TO_TS[segment] ?? segment);
2772
2787
  return { kind: "taskRef", task: refKey, path: outputKeyPath };
@@ -3075,6 +3090,17 @@ function decodeFilter(value, ctx, fieldScope = "app") {
3075
3090
  literal: (literal, _valueType, field) => picklistOptionLabel(literal) ?? stageFilterName(literal, ctx) ?? filterOptionLabel(literal, field, ctx) ?? literal,
3076
3091
  }, fieldScope);
3077
3092
  }
3093
+ /**
3094
+ * A Checkbox (`boolean`) input's default. The provider's `default_value` is a
3095
+ * string, so HCL holds "true"/"false"; source authors a boolean (#2204).
3096
+ */
3097
+ function booleanDefault(value) {
3098
+ if (value === "true")
3099
+ return true;
3100
+ if (value === "false")
3101
+ return false;
3102
+ return value;
3103
+ }
3078
3104
  /**
3079
3105
  * A datamine trigger's condition (edk#2287). Pull used to drop it, so the next
3080
3106
  * apply cleared the live condition. It now comes back as source. A condition
@@ -3140,10 +3166,12 @@ function triggerFromBlock(block, ctx) {
3140
3166
  // (onDemand's TriggerFieldTypeAlias) does. Map back so printed
3141
3167
  // source uses a type-checkable alias instead of a raw wire string
3142
3168
  // "attachment" that TriggerFieldTypeAlias doesn't accept. The
3143
- // provider's "user" is USER_ID, authored as "userId".
3169
+ // provider's "user" is USER_ID, authored as "userId", and its
3170
+ // "group" is GROUP_ID, authored as "groupId" (#2204).
3144
3171
  const type = parameter.type === "attachment" ? "attachmentId"
3145
3172
  : parameter.type === "user" ? "userId"
3146
- : parameter.type;
3173
+ : parameter.type === "group" ? "groupId"
3174
+ : parameter.type;
3147
3175
  const record = type === "record";
3148
3176
  const recordApp = record
3149
3177
  ? aspectRefFromObjectId(parameter.default_value, ctx)
@@ -3158,7 +3186,7 @@ function triggerFromBlock(block, ctx) {
3158
3186
  ...(parameter.required === true ? { required: true } : {}),
3159
3187
  ...(parameter.multiple === true ? { multiple: true } : {}),
3160
3188
  ...(!record && parameter.default_value !== undefined
3161
- ? { defaultValue: type === "userId" ? userIdDefault(parameter.default_value, ctx) : parameter.default_value }
3189
+ ? { defaultValue: type === "userId" ? userIdDefault(parameter.default_value, ctx) : type === "boolean" ? booleanDefault(parameter.default_value) : parameter.default_value }
3162
3190
  : {}),
3163
3191
  ...(typeof parameter.description === "string" ? { description: parameter.description } : {}),
3164
3192
  };
@@ -3284,7 +3312,8 @@ function triggerFromBlock(block, ctx) {
3284
3312
  function taskArgs(block, factory, ctx, taskDiagnostics) {
3285
3313
  const args = {};
3286
3314
  for (const [attr, value] of Object.entries(block.attrs)) {
3287
- if (attr === "parent" || attr === "name" || attr === "depends_on")
3315
+ // object_field_ids is build-derived from the target's field order (edk#2280).
3316
+ if (attr === "parent" || attr === "name" || attr === "depends_on" || attr === "object_field_ids")
3288
3317
  continue;
3289
3318
  if (attr === "filter") {
3290
3319
  const where = `task ${JSON.stringify(typeof block.attrs.name === "string" ? block.attrs.name : block.label)} (${factory})`;
@@ -3692,15 +3721,17 @@ function taskArgs(block, factory, ctx, taskDiagnostics) {
3692
3721
  args.outputType = typeof value === "string" ? value.toLowerCase() : decodeValue(value, ctx);
3693
3722
  continue;
3694
3723
  }
3695
- if (attr === "attachments" && factory === "aiAgent") {
3724
+ // aiAgent's attachments and sendEmail's email_attachments share one shape.
3725
+ if ((attr === "attachments" && factory === "aiAgent") || (attr === "email_attachments" && factory === "sendEmail")) {
3726
+ const kind = factory === "aiAgent" ? "AI agent attachment" : "email attachment";
3696
3727
  if (!Array.isArray(value))
3697
- throw new EntityTfError(`${block.type}.${block.label}: attachments must be an array`);
3728
+ throw new EntityTfError(`${block.type}.${block.label}: ${attr} must be an array`);
3698
3729
  args.attachments = value.map((item) => {
3699
3730
  if (!isObject(item))
3700
- throw new EntityTfError(`${block.type}.${block.label}: invalid AI agent attachment`);
3701
- const present = ["file", "attachment", "record"].filter((key) => item[key] !== undefined);
3731
+ throw new EntityTfError(`${block.type}.${block.label}: invalid ${kind}`);
3732
+ const present = ["file", "attachment", "record"].filter((key) => item[key] !== undefined && item[key] !== null);
3702
3733
  if (present.length !== 1) {
3703
- throw new EntityTfError(`${block.type}.${block.label}: AI agent attachment must set exactly one of file, attachment, or record`);
3734
+ throw new EntityTfError(`${block.type}.${block.label}: ${kind} must set exactly one of file, attachment, or record`);
3704
3735
  }
3705
3736
  const key = present[0];
3706
3737
  return { [key]: decodeValue(item[key], ctx) };
@@ -3937,36 +3968,137 @@ function taskArgs(block, factory, ctx, taskDiagnostics) {
3937
3968
  }
3938
3969
  return args;
3939
3970
  }
3971
+ const UNMANAGED_PREDECESSOR_LOCAL_PREFIX = "edk_unmanaged_predecessor_";
3972
+ function documentLocals(doc) {
3973
+ return Object.assign({}, ...doc.blocks.filter((block) => block.kind === "locals").map((block) => block.attrs));
3974
+ }
3975
+ /** `type.label` plus a path such as `.inner`. A bare resource reference has no path. */
3976
+ function refAddress(value) {
3977
+ const ref = resourceRef(value);
3978
+ if (ref === undefined)
3979
+ return undefined;
3980
+ const suffix = ref.path.length > 0 ? `.${pathNames(ref.path).join(".")}` : "";
3981
+ return `${ref.type}.${ref.label}${suffix}`;
3982
+ }
3983
+ function unmanagedDataBlock(doc, label) {
3984
+ return doc.blocks.find((block) => block.kind === "data" && block.type === "elementum_unmanaged_task_reference" && block.label === label);
3985
+ }
3940
3986
  /**
3941
- * Resolve an `elementum_unmanaged_task_reference` data block's OWN real
3942
- * position in the task tree from its `operator_child_id`/`operator_task_id`/
3943
- * `parent_is_trigger` attributes (edk#821) - the platform already records
3944
- * exactly which switch case / fork-join branch / forEach body (or the
3945
- * trigger) the unsupported task sits in; this was previously discarded
3946
- * entirely in favor of always anchoring to the trigger. Returns `undefined`
3947
- * when none of those attributes resolve to an address this automation
3948
- * actually owns, so the caller can fall back to the trigger-anchor + diagnostic
3949
- * safety net rather than pointing at an address nothing will ever visit.
3987
+ * Where the task after an unsupported step sits. The local names the step it
3988
+ * comes after. The data source's operator fields are only the enclosing
3989
+ * branch, never that predecessor: the provider copies them onto the following
3990
+ * task (edk#2320). `parent_is_trigger` is not a position. It is always false
3991
+ * on a task reference, and treating it as "after the trigger" makes the next
3992
+ * plan move the live task.
3950
3993
  */
3951
- function resolveUnmanagedTaskPosition(dataBlock, triggerAddress, ownedAddresses) {
3952
- if (dataBlock.attrs.parent_is_trigger === true)
3953
- return triggerAddress;
3954
- const operatorRef = resourceRef(dataBlock.attrs.operator_task_id);
3955
- if (operatorRef?.type === "elementum_for_each_task") {
3956
- const inner = `${operatorRef.type}.${operatorRef.label}.inner`;
3957
- return ownedAddresses.has(`${operatorRef.type}.${operatorRef.label}`) ? inner : undefined;
3958
- }
3959
- const childRef = resourceRef(dataBlock.attrs.operator_child_id);
3960
- if (childRef !== undefined) {
3961
- const address = `${childRef.type}.${childRef.label}`;
3962
- return ownedAddresses.has(address) ? address : undefined;
3963
- }
3964
- if (operatorRef !== undefined) {
3965
- const address = `${operatorRef.type}.${operatorRef.label}`;
3966
- return ownedAddresses.has(address) ? address : undefined;
3994
+ function unmanagedSuccessorPosition(doc, label, ownedAddresses, addressByPlatformId, seen = new Set()) {
3995
+ if (seen.has(label))
3996
+ return undefined;
3997
+ const nextSeen = new Set(seen);
3998
+ nextSeen.add(label);
3999
+ const local = documentLocals(doc)[`${UNMANAGED_PREDECESSOR_LOCAL_PREFIX}${label}`];
4000
+ // A run of unsupported steps points each local at the previous data source.
4001
+ // The managed task at the end stays placed only when that chain reaches an
4002
+ // owned step (edk#2320).
4003
+ const predecessor = unmanagedTaskRef(local);
4004
+ if (predecessor !== undefined) {
4005
+ const predecessorPosition = unmanagedSuccessorPosition(doc, predecessor.label, ownedAddresses, addressByPlatformId, nextSeen);
4006
+ return predecessorPosition === undefined
4007
+ ? undefined
4008
+ : `elementum_unmanaged_task_reference.${predecessor.label}`;
4009
+ }
4010
+ const fromLocal = refAddress(local);
4011
+ const predecessorOwned = fromLocal !== undefined && (ownedAddresses.has(fromLocal) ||
4012
+ (fromLocal.endsWith(".inner") && ownedAddresses.has(fromLocal.slice(0, -".inner".length))));
4013
+ if (predecessorOwned)
4014
+ return fromLocal;
4015
+ const dataBlock = unmanagedDataBlock(doc, label);
4016
+ if (dataBlock === undefined)
4017
+ return undefined;
4018
+ return resolveUnmanagedTaskPosition(dataBlock, ownedAddresses, addressByPlatformId);
4019
+ }
4020
+ /** Puts every earlier unsupported step of a run into the same tree as the one a managed task parents onto. */
4021
+ function rememberUnmanagedPredecessors(doc, label, ownedAddresses, addressByPlatformId, dataBlocks, unmanagedTaskPositions, taskByAddress, placeholderTasks, seen) {
4022
+ const predecessor = unmanagedTaskRef(documentLocals(doc)[`${UNMANAGED_PREDECESSOR_LOCAL_PREFIX}${label}`]);
4023
+ if (predecessor === undefined || seen.has(predecessor.label))
4024
+ return;
4025
+ seen.add(predecessor.label);
4026
+ const address = `elementum_unmanaged_task_reference.${predecessor.label}`;
4027
+ if (!unmanagedTaskPositions.has(address)) {
4028
+ const dataBlock = dataBlocks.get(address);
4029
+ const position = unmanagedSuccessorPosition(doc, predecessor.label, ownedAddresses, addressByPlatformId);
4030
+ if (dataBlock === undefined || position === undefined)
4031
+ return;
4032
+ unmanagedTaskPositions.set(address, position);
4033
+ const refKey = typeof dataBlock.attrs.name === "string" && dataBlock.attrs.name !== ""
4034
+ ? dataBlock.attrs.name
4035
+ : tfLabelToTsLabel(dataBlock.label ?? "task");
4036
+ taskByAddress.set(address, { block: dataBlock, refKey });
4037
+ placeholderTasks.push({
4038
+ name: refKey,
4039
+ taskType: typeof dataBlock.attrs.task_type === "string" ? dataBlock.attrs.task_type : "unknown",
4040
+ });
4041
+ }
4042
+ rememberUnmanagedPredecessors(doc, predecessor.label, ownedAddresses, addressByPlatformId, dataBlocks, unmanagedTaskPositions, taskByAddress, placeholderTasks, seen);
4043
+ }
4044
+ function importPlatformId(doc, type, label) {
4045
+ for (const block of doc.blocks) {
4046
+ if (block.kind !== "import" || typeof block.attrs.id !== "string")
4047
+ continue;
4048
+ const target = resourceRef(block.attrs.to);
4049
+ if (target?.type !== type || target.label !== label)
4050
+ continue;
4051
+ const id = block.attrs.id.split(/[:/]/).at(-1);
4052
+ return id !== "" ? id : undefined;
3967
4053
  }
3968
4054
  return undefined;
3969
4055
  }
4056
+ function unmanagedBelongsToAutomation(doc, label, automationLabel, automationPlatformId) {
4057
+ const id = unmanagedDataBlock(doc, label)?.attrs.automation_id;
4058
+ if (typeof id === "string")
4059
+ return automationPlatformId !== undefined && id === automationPlatformId;
4060
+ const ref = resourceRef(id);
4061
+ return ref?.type === AUTOMATION_RESOURCE_TYPE && ref.label === automationLabel;
4062
+ }
4063
+ function resolveUnmanagedTaskPosition(dataBlock, ownedAddresses, addressByPlatformId) {
4064
+ // The export writes these as the platform id. A rebuild writes a resource
4065
+ // reference. Both name the same task (edk#2320).
4066
+ const operatorAddress = taskAddressOf(dataBlock.attrs.operator_task_id, addressByPlatformId);
4067
+ if (operatorAddress?.startsWith("elementum_for_each_task.")) {
4068
+ const taskAddress = operatorAddress;
4069
+ return ownedAddresses.has(taskAddress) ? `${taskAddress}.inner` : undefined;
4070
+ }
4071
+ const childAddress = taskAddressOf(dataBlock.attrs.operator_child_id, addressByPlatformId);
4072
+ if (childAddress !== undefined && ownedAddresses.has(childAddress))
4073
+ return childAddress;
4074
+ if (operatorAddress !== undefined && ownedAddresses.has(operatorAddress))
4075
+ return operatorAddress;
4076
+ return undefined;
4077
+ }
4078
+ /** The resource address a parent-position attribute names: a resource reference, or a platform id carried by an import. */
4079
+ function taskAddressOf(value, addressByPlatformId) {
4080
+ const ref = resourceRef(value);
4081
+ if (ref !== undefined)
4082
+ return `${ref.type}.${ref.label}`;
4083
+ if (typeof value !== "string" || value === "")
4084
+ return undefined;
4085
+ return addressByPlatformId.get(value);
4086
+ }
4087
+ /** Import id leaf (the platform task or case id) to its resource address. */
4088
+ function taskAddressesByPlatformId(doc) {
4089
+ const addresses = new Map();
4090
+ for (const block of doc.blocks) {
4091
+ if (block.kind !== "import" || typeof block.attrs.id !== "string")
4092
+ continue;
4093
+ const target = resourceRef(block.attrs.to);
4094
+ if (target === undefined)
4095
+ continue;
4096
+ const id = block.attrs.id;
4097
+ const leaf = id.includes(":") ? id.slice(id.lastIndexOf(":") + 1) : id;
4098
+ addresses.set(leaf, `${target.type}.${target.label}`);
4099
+ }
4100
+ return addresses;
4101
+ }
3970
4102
  /**
3971
4103
  * `triggerAddress`/`onUnmanagedParent` are the fallback of last resort: a
3972
4104
  * task whose real predecessor is an unsupported task type, when that
@@ -4056,6 +4188,16 @@ export function automationOwnedAddresses(doc, automationLabel) {
4056
4188
  owned.add(`${block.type}.${block.label}`);
4057
4189
  }
4058
4190
  }
4191
+ // A published automation names every task it owns in workflow_publish.depends_on.
4192
+ // A task whose parent is an unsupported step is only reachable that way:
4193
+ // the parent is a data source, not a resource (edk#2320).
4194
+ const publish = doc.blocks.find((block) => block.kind === "resource" && block.type === WORKFLOW_PUBLISH_RESOURCE_TYPE && references(block.attrs.automation, AUTOMATION_RESOURCE_TYPE, automationLabel));
4195
+ const publishDependencies = new Set(Array.isArray(publish?.attrs.depends_on)
4196
+ ? publish.attrs.depends_on.flatMap((value) => {
4197
+ const ref = resourceRef(value);
4198
+ return ref === undefined ? [] : [`${ref.type}.${ref.label}`];
4199
+ })
4200
+ : []);
4059
4201
  let changed = true;
4060
4202
  while (changed) {
4061
4203
  changed = false;
@@ -4069,6 +4211,14 @@ export function automationOwnedAddresses(doc, automationLabel) {
4069
4211
  if (parent !== undefined && owned.has(`${parent.type}.${parent.label}`)) {
4070
4212
  owned.add(address);
4071
4213
  changed = true;
4214
+ continue;
4215
+ }
4216
+ const unmanagedLabel = unmanagedTaskRef(block.attrs.parent)?.label;
4217
+ const placed = unmanagedLabel !== undefined && unmanagedSuccessorPosition(doc, unmanagedLabel, owned, taskAddressesByPlatformId(doc)) !== undefined;
4218
+ const draftOfThis = publish === undefined && unmanagedLabel !== undefined && unmanagedBelongsToAutomation(doc, unmanagedLabel, automationLabel, importPlatformId(doc, AUTOMATION_RESOURCE_TYPE, automationLabel));
4219
+ if (placed && (publishDependencies.has(address) || draftOfThis)) {
4220
+ owned.add(address);
4221
+ changed = true;
4072
4222
  }
4073
4223
  }
4074
4224
  }
@@ -4270,18 +4420,54 @@ export class UnresolvedTaskFilterRefError extends EntityTfError {
4270
4420
  }
4271
4421
  }
4272
4422
  }
4423
+ /**
4424
+ * The EDK ref of the app that owns a `data "elementum_service_account"`
4425
+ * lookup. Export looks up another app's account through its owning app
4426
+ * (edk#2197): `app_id = data.elementum_app.<label>.id`, that block naming the
4427
+ * app by namespace (or name). Undefined when `app_id` is not such a lookup,
4428
+ * so the account stays on the automation's own app. `{ missingApp }` when the
4429
+ * lookup names an app the workspace does not know, or names none: it
4430
+ * describes the lookup (`namespace "ns"`), and the caller throws
4431
+ * `UnresolvedServiceAccountOwnerAppError` with it (edk#2416).
4432
+ */
4433
+ function dataServiceAccountOwnerRefName(appId, dataBlocks, foreignAppRefNames, foreignAppRefNamespaces) {
4434
+ const appDataLabel = dataRefLabel(appId, "elementum_app");
4435
+ if (appDataLabel === undefined)
4436
+ return undefined;
4437
+ const appBlock = dataBlocks.get(`elementum_app.${appDataLabel}`);
4438
+ const namespace = appBlock?.attrs.namespace;
4439
+ if (typeof namespace === "string")
4440
+ return foreignAppRefNamespaces?.get(namespace) ?? { missingApp: `namespace "${namespace}"` };
4441
+ const name = appBlock?.attrs.name;
4442
+ if (typeof name === "string")
4443
+ return foreignAppRefNames?.get(name) ?? { missingApp: `name "${name}"` };
4444
+ return { missingApp: `data.elementum_app.${appDataLabel}, which names no namespace or name` };
4445
+ }
4273
4446
  /**
4274
4447
  * A bare service_account_id belongs to an app this export does not contain.
4275
4448
  * Pull cannot print a serviceAccountRef until that app is in the workspace,
4276
4449
  * and printing nothing would clear the live account.
4277
4450
  */
4278
4451
  export class UnresolvedForeignServiceAccountError extends EntityTfError {
4279
- constructor(automationLabel) {
4280
- super(`${AUTOMATION_RESOURCE_TYPE}.${automationLabel}: service_account_id names a service account outside this export ` +
4281
- "that no pulled app in state owns; pull the app that owns it first");
4452
+ constructor(automationLabel, message = `${AUTOMATION_RESOURCE_TYPE}.${automationLabel}: service_account_id names a service account outside this export ` +
4453
+ "that no pulled app in state owns; pull the app that owns it first") {
4454
+ super(message);
4282
4455
  this.name = "UnresolvedForeignServiceAccountError";
4283
4456
  }
4284
4457
  }
4458
+ /**
4459
+ * The service account is another app's, looked up through that app
4460
+ * (`data.elementum_app.<label>`), and no app in the workspace declares it.
4461
+ * Pull names the app so the next step can say which one to pull.
4462
+ */
4463
+ export class UnresolvedServiceAccountOwnerAppError extends UnresolvedForeignServiceAccountError {
4464
+ constructor(automationLabel, serviceAccountName, missingApp) {
4465
+ const account = serviceAccountName === undefined ? "a service account" : `service account "${serviceAccountName}"`;
4466
+ super(automationLabel, `${AUTOMATION_RESOURCE_TYPE}.${automationLabel}: service_account_id runs as ${account} of the app with ${missingApp}, ` +
4467
+ "and no app in this workspace declares it; pull that app first");
4468
+ this.name = "UnresolvedServiceAccountOwnerAppError";
4469
+ }
4470
+ }
4285
4471
  /**
4286
4472
  * #1320: a task reads the current item of a loop that doesn't enclose it.
4287
4473
  * Pull skips the automation like any other exclusion, and additionally
@@ -4390,7 +4576,7 @@ function describeUnresolvedTask(taskId, doc, automationLabel, taskByAddress, res
4390
4576
  `(the platform checks references only when an automation is published), or it is a task type EDK cannot export. ${FIX_FILTER_IN_BUILDER}`;
4391
4577
  }
4392
4578
  /** Extract one app- or element-owned automation graph from an ei export. */
4393
- function automationFromTfDocument(doc, automationLabel, appRefName, foreignFieldRefsById, foreignFieldRefsByDataAddress, foreignTableRefsById, picklistOptionLabelById, fieldNamesByOwnerRefName, foreignAppRefNames, foreignElementRefNames, procedureKeysByDiscriminator, foreignTaskRefNames, groupKeysByName, serviceAccountsById, foreignFileReaderRefsById) {
4579
+ function automationFromTfDocument(doc, automationLabel, appRefName, foreignFieldRefsById, foreignFieldRefsByDataAddress, foreignTableRefsById, picklistOptionLabelById, fieldNamesByOwnerRefName, foreignAppRefNames, foreignElementRefNames, procedureKeysByDiscriminator, foreignTaskRefNames, groupKeysByName, serviceAccountsById, foreignFileReaderRefsById, foreignAppRefNamespaces) {
4394
4580
  const automation = doc.blocks.find((block) => block.kind === "resource" && block.type === AUTOMATION_RESOURCE_TYPE && block.label === automationLabel);
4395
4581
  if (automation === undefined)
4396
4582
  throw new EntityTfError(`automation resource "${automationLabel}" not found`);
@@ -4455,9 +4641,14 @@ function automationFromTfDocument(doc, automationLabel, appRefName, foreignField
4455
4641
  }
4456
4642
  // edk#785: a data-source parent is always "resolved" (see unmanagedTaskRef) -
4457
4643
  // doesn't need its target to already be owned the way a resource-attr parent does.
4458
- else if (!parent && unmanagedTaskRef(task.attrs.parent) && publishDependencyAddresses.has(`${task.type}.${task.label}`) && !owned.has(`${task.type}.${task.label}`)) {
4459
- owned.add(`${task.type}.${task.label}`);
4460
- changed = true;
4644
+ else if (!parent && unmanagedTaskRef(task.attrs.parent) && !owned.has(`${task.type}.${task.label}`)) {
4645
+ const unmanagedLabel = unmanagedTaskRef(task.attrs.parent)?.label;
4646
+ const placed = unmanagedLabel !== undefined && unmanagedSuccessorPosition(doc, unmanagedLabel, owned, taskAddressesByPlatformId(doc)) !== undefined;
4647
+ const draftOfThis = publish === undefined && unmanagedLabel !== undefined && unmanagedBelongsToAutomation(doc, unmanagedLabel, automationLabel, importPlatformId(doc, AUTOMATION_RESOURCE_TYPE, automationLabel));
4648
+ if (placed && (publishDependencyAddresses.has(`${task.type}.${task.label}`) || draftOfThis)) {
4649
+ owned.add(`${task.type}.${task.label}`);
4650
+ changed = true;
4651
+ }
4461
4652
  }
4462
4653
  }
4463
4654
  }
@@ -4613,6 +4804,7 @@ function automationFromTfDocument(doc, automationLabel, appRefName, foreignField
4613
4804
  }
4614
4805
  }
4615
4806
  const stringifiedValueReferences = { unresolved: false };
4807
+ const groupsMissingFromOrg = new Set();
4616
4808
  const ctx = {
4617
4809
  appRefName,
4618
4810
  appTfLabel: app.label,
@@ -4638,12 +4830,14 @@ function automationFromTfDocument(doc, automationLabel, appRefName, foreignField
4638
4830
  ...(procedureKeysByDiscriminator !== undefined && { procedureKeysByDiscriminator }),
4639
4831
  ...(groupKeysByName !== undefined && { groupKeysByName }),
4640
4832
  stringifiedValueReferences,
4833
+ groupsMissingFromOrg,
4641
4834
  ...(resourceImportIds.has(`${AUTOMATION_RESOURCE_TYPE}.${automationLabel}`) && {
4642
4835
  automationId: resourceImportIds.get(`${AUTOMATION_RESOURCE_TYPE}.${automationLabel}`),
4643
4836
  }),
4644
4837
  describeUnresolvedTask: (taskId) => describeUnresolvedTask(taskId, doc, automationLabel, taskByAddress, resourceBlocks, dataBlocks, resourceImportIds),
4645
4838
  };
4646
4839
  let serviceAccountName;
4840
+ let foreignServiceAccountAppRefName;
4647
4841
  const serviceAccountValue = automation.attrs.service_account_id;
4648
4842
  if (serviceAccountValue !== undefined &&
4649
4843
  isTfExpr(serviceAccountValue) &&
@@ -4661,8 +4855,15 @@ function automationFromTfDocument(doc, automationLabel, appRefName, foreignField
4661
4855
  serviceAccountName = `${block.attrs.first_name} ${block.attrs.last_name}`;
4662
4856
  }
4663
4857
  }
4858
+ if (reference.$expr === "data-attr" && block !== undefined) {
4859
+ const owner = dataServiceAccountOwnerRefName(block.attrs.app_id, dataBlocks, foreignAppRefNames, foreignAppRefNamespaces);
4860
+ if (typeof owner === "object")
4861
+ throw new UnresolvedServiceAccountOwnerAppError(automationLabel, serviceAccountName, owner.missingApp);
4862
+ if (owner !== undefined)
4863
+ foreignServiceAccountAppRefName = owner;
4864
+ }
4664
4865
  }
4665
- let serviceAccountAppRefName;
4866
+ let serviceAccountAppRefName = foreignServiceAccountAppRefName;
4666
4867
  if (typeof serviceAccountValue === "string" && isUuid(serviceAccountValue) && serviceAccountsById !== undefined) {
4667
4868
  const owned = serviceAccountsById.get(serviceAccountValue);
4668
4869
  if (owned !== undefined) {
@@ -4694,6 +4895,7 @@ function automationFromTfDocument(doc, automationLabel, appRefName, foreignField
4694
4895
  ]);
4695
4896
  const unmanagedTaskPositions = new Map();
4696
4897
  const placeholderTasks = [];
4898
+ const addressByPlatformId = taskAddressesByPlatformId(doc);
4697
4899
  for (const task of tasks) {
4698
4900
  const unmanagedRef = unmanagedTaskRef(task.attrs.parent);
4699
4901
  if (unmanagedRef === undefined)
@@ -4702,7 +4904,9 @@ function automationFromTfDocument(doc, automationLabel, appRefName, foreignField
4702
4904
  if (unmanagedTaskPositions.has(address))
4703
4905
  continue;
4704
4906
  const dataBlock = dataBlocks.get(address);
4705
- const position = dataBlock !== undefined ? resolveUnmanagedTaskPosition(dataBlock, triggerAddress, ownedAddresses) : undefined;
4907
+ const position = unmanagedRef.label !== undefined
4908
+ ? unmanagedSuccessorPosition(doc, unmanagedRef.label, ownedAddresses, addressByPlatformId)
4909
+ : undefined;
4706
4910
  if (dataBlock === undefined || position === undefined)
4707
4911
  continue; // falls back to parentAddress's trigger-anchor + diagnostic
4708
4912
  unmanagedTaskPositions.set(address, position);
@@ -4712,6 +4916,7 @@ function automationFromTfDocument(doc, automationLabel, appRefName, foreignField
4712
4916
  name: refKey,
4713
4917
  taskType: typeof dataBlock.attrs.task_type === "string" ? dataBlock.attrs.task_type : "unknown",
4714
4918
  });
4919
+ rememberUnmanagedPredecessors(doc, unmanagedRef.label, ownedAddresses, addressByPlatformId, dataBlocks, unmanagedTaskPositions, taskByAddress, placeholderTasks, new Set([unmanagedRef.label]));
4715
4920
  }
4716
4921
  const childrenByParent = new Map();
4717
4922
  for (const task of tasks) {
@@ -4862,18 +5067,19 @@ function automationFromTfDocument(doc, automationLabel, appRefName, foreignField
4862
5067
  ast,
4863
5068
  blocks: [automation, trigger, ...tasks, ...ownedBranches, ...(publish ? [publish] : [])],
4864
5069
  adoptionAddressAliases,
4865
- ...((unrebuildableTasks.length > 0 || placeholderTasks.length > 0 || outputDiagnostics.length > 0 || taskDiagnostics.length > 0) && {
5070
+ ...((unrebuildableTasks.length > 0 || placeholderTasks.length > 0 || outputDiagnostics.length > 0 || taskDiagnostics.length > 0 || groupsMissingFromOrg.size > 0) && {
4866
5071
  diagnostics: [
4867
5072
  ...unrebuildableTasks.map((address) => `automation "${automationLabel}": ${address}'s real parent is a task type EDK doesn't support yet, so its authored position couldn't be reconstructed (anchored to the trigger instead) - not rebuildable from this source until that task type is supported`),
4868
5073
  ...placeholderTasks.map(({ name, taskType }) => `automation "${automationLabel}" uses platform task type "${taskType}" ("${name}"), which EDK doesn't implement - kept as an unimplementedTask(...) placeholder; its configuration isn't authorable, but its position and downstream chain are round-trip-safe`),
4869
5074
  ...outputDiagnostics,
4870
5075
  ...taskDiagnostics.map((message) => `automation "${automationLabel}": ${message}`),
5076
+ ...[...groupsMissingFromOrg].map((name) => `automation "${automationLabel}": group "${name}" is not in the org catalog this pull loaded (org.ts doesn't carry it, or org.ts is missing or couldn't be imported), so it was pulled as groupRef({ name: ${JSON.stringify(name)} }); run \`elementum pull org --data-only\`, then pull this app again to refer to it as org.groups.<key>`),
4871
5077
  ],
4872
5078
  }),
4873
5079
  ...(stringifiedValueReferences.unresolved ? { stringifiedValueReferences: true } : {}),
4874
5080
  };
4875
5081
  }
4876
- export function automationFromTf(first, second, third, fourth, fifth, sixth, seventh, eighth, ninth, tenth, eleventh, twelfth, thirteenth, fourteenth, fifteenth) {
5082
+ export function automationFromTf(first, second, third, fourth, fifth, sixth, seventh, eighth, ninth, tenth, eleventh, twelfth, thirteenth, fourteenth, fifteenth, sixteenth) {
4877
5083
  if (Array.isArray(first)) {
4878
5084
  const ctx = second;
4879
5085
  const automationBlock = first.find((block) => block.kind === "resource" && block.type === AUTOMATION_RESOURCE_TYPE);
@@ -4882,7 +5088,7 @@ export function automationFromTf(first, second, third, fourth, fifth, sixth, sev
4882
5088
  throw new EntityTfError(`automation graph has no ${AUTOMATION_RESOURCE_TYPE} resource, so its resources (${addresses.join(", ") || "none"}) cannot be pulled`);
4883
5089
  }
4884
5090
  try {
4885
- const result = automationFromTfDocument({ blocks: [...first] }, automationBlock.label, ctx.ownerHandle, ctx.foreignFieldRefsById, ctx.foreignFieldRefsByDataAddress, ctx.foreignTableRefsById, ctx.picklistOptionLabelById, ctx.fieldNamesByOwnerRefName, ctx.foreignAppRefNames, ctx.foreignElementRefNames, ctx.procedureKeysByDiscriminator, ctx.foreignTaskRefNames, ctx.groupKeysByName, ctx.serviceAccountsById, ctx.foreignFileReaderRefsById);
5091
+ const result = automationFromTfDocument({ blocks: [...first] }, automationBlock.label, ctx.ownerHandle, ctx.foreignFieldRefsById, ctx.foreignFieldRefsByDataAddress, ctx.foreignTableRefsById, ctx.picklistOptionLabelById, ctx.fieldNamesByOwnerRefName, ctx.foreignAppRefNames, ctx.foreignElementRefNames, ctx.procedureKeysByDiscriminator, ctx.foreignTaskRefNames, ctx.groupKeysByName, ctx.serviceAccountsById, ctx.foreignFileReaderRefsById, ctx.foreignAppRefNamespaces);
4886
5092
  if (result.diagnostics)
4887
5093
  ctx.diagnostics.push(...result.diagnostics);
4888
5094
  return { automation: result.ast };
@@ -4895,5 +5101,5 @@ export function automationFromTf(first, second, third, fourth, fifth, sixth, sev
4895
5101
  return { skippedReason: message };
4896
5102
  }
4897
5103
  }
4898
- return automationFromTfDocument(first, second, third ?? "", fourth, fifth, sixth, seventh, eighth, ninth, tenth, eleventh, twelfth, thirteenth, fourteenth, fifteenth);
5104
+ return automationFromTfDocument(first, second, third ?? "", fourth, fifth, sixth, seventh, eighth, ninth, tenth, eleventh, twelfth, thirteenth, fourteenth, fifteenth, sixteenth);
4899
5105
  }
@@ -18,5 +18,5 @@ export * as filter from "../shared/filters/index.js";
18
18
  export { automationStatus, chainableTrigger, actions, automation, type ActionBuilder, type ActionChain, type ActionDef, type ActionOptions, type ActionSequenceDef, type ActionsStarted, type AutomationConfigured, type AutomationOptions, type AutomationStatus, type ForkJoinBranch, type ForkJoinBranchBuilder, type ForkJoinConfig, type ForEachBuilder, type ForEachConfig, type ForEachScope, type LoopScope, type NestedActionBuilder, type NestedActionChain, type NestedActionContext, type OperatorChild, type SwitchCase, type SwitchCaseBuilder, type SwitchConfig, type TriggerChain, type TriggerDef, type TriggerParamMeta } from "./build.js";
19
19
  export { ScriptCodeError, scriptFile, type ScriptCodeFn, type ScriptFile, type ScriptInput } from "./script-code.js";
20
20
  export { workflowOutput, workflowOutputType, type WorkflowOutputDeclaration, type WorkflowOutputType, } from "./workflow-output.js";
21
- export { addWatcher, aiAgent, aiClassify, aiEmailAnalysis, aiFileAnalysis, aiSearchTable, aiSummarize, aiTransform, apiRequest, approvalChain, approvalChainTemplate, approvalStatusUpdate, requiredSecret, assignGroup, assignUser, assignmentEngine, bulkExcel, bulkUpdateFields, calculation, createRecord, executeScript, findRelatedRecords, generateReport, initiateCall, initiateEmailConversation, notification, postComment, postTeamsMessage, procedure, readFile, recordFieldLocking, recordSearch, relateRecords, runAutomation, saveAttachment, sendEmail, sendSurvey, setVariable, tableRecordsSearch, unzip, updateField, userGroupSearch, userSearch, withFieldMappings, type AddWatcherOptions, type AiAgentAttachment, type AiAgentOptions, type AiAgentOutput, type AiAgentOutputField, type AiAgentOutputFieldType, type AiClassifyCategorySource, type AiClassifyOptions, type AiClassifyStaticCategory, type AiEmailAnalysisOptions, type AiFileAnalysisOptions, type AiSearchTableOptions, type AiSearchTableOutput, type AiSummarizeOptions, type AiTransformOptions, type ApiRequestHeader, type ApiRequestOptions, type ApiRequestOutputs, type ApiResponseType, type ApprovalChainOptions, type RequiredSecret, type ApprovalChainTemplateOptions, type ApprovalStatusUpdateOptions, type ApprovalStatusUpdateStatus, type AssignGroupOptions, type AssignUserOptions, type AssignmentEngineOptions, type BulkExcelFieldMapping, type BulkExcelFieldSource, type BulkExcelOptions, type BulkUpdateFieldsOptions, type BulkUpdateFieldsOutput, type CalculationEntry, type CalculationExpression, type CalculationInclude, type CalculationOptions, type CalculationOutputs, type CalculationValueInput, type CalculationValueOptions, type CalculationValueOutputs, type CalculationValues, type CreateRecordOptions, type CreateRecordOutput, type EmailAttachment, type ExecuteScriptFieldMapping, type ExecuteScriptOptions, type FieldAssignment, type FindRelatedRecordsOptions, type FindRelatedRecordsOutput, type GenerateReportOptions, type InitiateCallOptions, type InitiateEmailConversationOptions, type InitiateEmailFirstEmail, type LegacyCalculationOptions, type MultiSelectUpdateMode, type NotificationOptions, type StaticGroupRecipient, type StaticUserRecipient, type PostCommentOptions, type PostTeamsMessageOptions, type LegacyProcedureOptions, type ProcedureOptions, type TypedProcedureOptions, type ReadFileDataSource, type ReadFileOptions, type RecordFieldLockingOptions, type RecordId, type RecordReference, type RecordSearchOptions, type RecordSearchOutput, type RelateRecordsOptions, type RunAutomationInput, type RunAutomationDynamicReferenceOptions, type RunAutomationOptions, type RunAutomationStaticOptions, type SaveAttachmentOptions, type ScriptOutputProperties, type ScriptOutputScalarType, type ScriptOutputType, type ScriptOutputs, type SendEmailOptions, type SendSurveyOptions, type SetVariableOptions, type TableRecordsSearchOptions, type TableRecordsSearchOutput, type UnzipOptions, type UpdateFieldAssignment, type UpdateFieldOptions, type UserGroupSearchOptions, type UserGroupSearchOutput, type UserGroupShape, type UserSearchOptions, type VariableAssign, type VariableDecl } from "./tasks.js";
21
+ export { addWatcher, aiAgent, aiClassify, aiEmailAnalysis, aiFileAnalysis, aiSearchTable, aiSummarize, aiTransform, apiRequest, approvalChain, approvalChainTemplate, approvalStatusUpdate, requiredSecret, assignGroup, assignUser, assignmentEngine, bulkExcel, bulkUpdateFields, calculation, createRecord, executeScript, findRelatedRecords, generateReport, initiateCall, initiateEmailConversation, notification, postComment, postTeamsMessage, procedure, readFile, recordFieldLocking, recordSearch, relateRecords, runAutomation, saveAttachment, sendEmail, sendSurvey, setVariable, tableRecordsSearch, unzip, updateField, userGroupSearch, userSearch, withFieldMappings, type AddWatcherOptions, type AiAgentAttachment, type AiAgentOptions, type AiAgentOutput, type AiAgentOutputField, type AiAgentOutputFieldType, type AiClassifyCategorySource, type AiClassifyOptions, type AiClassifyStaticCategory, type AiEmailAnalysisOptions, type AiFileAnalysisOptions, type AiSearchTableOptions, type AiSearchTableOutput, type AiSummarizeOptions, type AiTransformOptions, type ApiRequestHeader, type ApiRequestOptions, type ApiRequestOutputs, type ApiResponseType, type ApprovalChainOptions, type RequiredSecret, type ApprovalChainTemplateOptions, type ApprovalStatusUpdateOptions, type ApprovalStatusUpdateStatus, type AssignGroupOptions, type AssignUserOptions, type AssignmentEngineOptions, type BulkExcelFieldMapping, type BulkExcelFieldSource, type BulkExcelOptions, type BulkUpdateFieldsOptions, type BulkUpdateFieldsOutput, type CalculationEntry, type CalculationExpression, type CalculationInclude, type CalculationOptions, type CalculationOutputs, type CalculationValueInput, type CalculationValueOptions, type CalculationValueOutputs, type CalculationValues, type CreateRecordOptions, type CreateRecordOutput, type EmailAttachment, type ExecuteScriptFieldMapping, type ExecuteScriptOptions, type ExecuteScriptOutput, type FieldAssignment, type FindRelatedRecordsOptions, type FindRelatedRecordsOutput, type GenerateReportOptions, type InitiateCallOptions, type InitiateEmailConversationOptions, type InitiateEmailFirstEmail, type LegacyCalculationOptions, type MultiSelectUpdateMode, type NotificationOptions, type StaticGroupRecipient, type StaticUserRecipient, type PostCommentOptions, type PostTeamsMessageOptions, type LegacyProcedureOptions, type ProcedureOptions, type TypedProcedureOptions, type ReadFileDataSource, type ReadFileOptions, type RecordFieldLockingOptions, type RecordId, type RecordReference, type RecordSearchOptions, type RecordSearchOutput, type RelateRecordsOptions, type RunAutomationInput, type RunAutomationDynamicReferenceOptions, type RunAutomationOptions, type RunAutomationStaticOptions, type SaveAttachmentOptions, type ScriptOutputProperties, type ScriptOutputScalarType, type ScriptOutputType, type ScriptOutputs, type SendEmailOptions, type SendSurveyOptions, type SetVariableOptions, type TableRecordsSearchOptions, type TableRecordsSearchOutput, type UnzipOptions, type UpdateFieldAssignment, type UpdateFieldOptions, type UserGroupSearchOptions, type UserGroupSearchOutput, type UserGroupShape, type UserSearchOptions, type VariableAssign, type VariableDecl } from "./tasks.js";
22
22
  export { approvalProcessStatusUpdated, attachment, commentAdded, conversationEnd, dataMine, emailReceived, onDemand, recordCreated, recordUpdated, schedule, slackMessage, surveyResponseCreate, temporal, webHook, webhook, type AttachmentTriggerOptions, type AttachmentTriggerOutput, type CommentAddedTriggerOptions, type CommentAddedTriggerOutput, type ConversationEndConversationType, type ConversationEndTriggerOptions, type ConversationEndTriggerOutput, type DataMineTriggerOptions, type DataMineTriggerOutput, type EmailReceivedTriggerOptions, type EmailReceivedTriggerOutput, type RecordTriggerOptions, type RecordTriggerOutput, type ScheduleFrequency, type ScheduleTriggerOptions, type ScheduleTriggerOutput, type SlackMessageTriggerOutput, type SurveyResponseCreateTriggerOptions, type SurveyResponseCreateTriggerOutput, type TemporalTriggerOptions, type TemporalUnit, type WebhookTriggerOptions, type WebhookTriggerOutput, type Weekday, type approvalProcessStatusUpdatedStatus, type approvalProcessStatusUpdatedTriggerOptions } from "./triggers.js";
@@ -274,7 +274,7 @@ function extractAutomations(ownBlocks, stream, ctx) {
274
274
  }
275
275
  }
276
276
  try {
277
- const extracted = automationFromTf(doc, autoLabel, ctx.appRefName, ctx.foreignFieldRefsById, ctx.foreignFieldRefsByDataAddress, ctx.foreignTableRefsById, ctx.picklistOptionLabelById, ctx.fieldNamesByOwnerRefName, ctx.foreignAppRefNames, ctx.foreignElementRefNames, ctx.procedureKeysByDiscriminator, ctx.foreignTaskRefNames, ctx.groupKeysByName, ctx.serviceAccountsById, ctx.foreignFileReaderRefsById);
277
+ const extracted = automationFromTf(doc, autoLabel, ctx.appRefName, ctx.foreignFieldRefsById, ctx.foreignFieldRefsByDataAddress, ctx.foreignTableRefsById, ctx.picklistOptionLabelById, ctx.fieldNamesByOwnerRefName, ctx.foreignAppRefNames, ctx.foreignElementRefNames, ctx.procedureKeysByDiscriminator, ctx.foreignTaskRefNames, ctx.groupKeysByName, ctx.serviceAccountsById, ctx.foreignFileReaderRefsById, ctx.foreignAppRefNamespaces);
278
278
  // edk#1646 / #1858: adopt when a rebuilt ctx ref matches provider Read.
279
279
  // Otherwise the automation stays platform-managed. Releasing its state
280
280
  // also archives the authored file, so the next plan does not create a
@@ -44,6 +44,8 @@ export declare function recordInputMappingProblem(target: {
44
44
  export declare function automationRunTargetResourceAttr(appTfLabel: string, automationRefName: string, activeAutomationRefNames: ReadonlySet<string> | undefined, scope?: ChildResourceScope, handle?: string): TfExpr;
45
45
  /** The publish resource addresses a compiled automation file declares (its own). */
46
46
  export declare function automationPublishDeclarations(text: string): string[];
47
+ /** The `elementum_automation` label a compiled automation file declares. */
48
+ export declare function automationDeclaration(text: string): string | undefined;
47
49
  /**
48
50
  * The publish addresses of a compiled automation file's static
49
51
  * `runAutomation` targets. A static call to an ACTIVE target names the
@@ -70,12 +70,17 @@ export function automationRunTargetResourceAttr(appTfLabel, automationRefName, a
70
70
  }
71
71
  return expr.resourceAttr(AUTOMATION_RESOURCE_TYPE, label, ["id"]);
72
72
  }
73
+ const AUTOMATION_DECL = new RegExp(`^resource\\s+"${AUTOMATION_RESOURCE_TYPE}"\\s+"([^"]+)"`, "m");
73
74
  const PUBLISH_DECL = new RegExp(`^resource\\s+"${WORKFLOW_PUBLISH_RESOURCE_TYPE}"\\s+"([^"]+)"`, "gm");
74
75
  const PUBLISH_REF = new RegExp(`(?<![\\w.])${WORKFLOW_PUBLISH_RESOURCE_TYPE}\\.([a-z0-9_]+)`, "g");
75
76
  /** The publish resource addresses a compiled automation file declares (its own). */
76
77
  export function automationPublishDeclarations(text) {
77
78
  return [...text.matchAll(PUBLISH_DECL)].map((match) => `${WORKFLOW_PUBLISH_RESOURCE_TYPE}.${match[1]}`);
78
79
  }
80
+ /** The `elementum_automation` label a compiled automation file declares. */
81
+ export function automationDeclaration(text) {
82
+ return AUTOMATION_DECL.exec(text)?.[1];
83
+ }
79
84
  /**
80
85
  * The publish addresses of a compiled automation file's static
81
86
  * `runAutomation` targets. A static call to an ACTIVE target names the