@elementumai/edk 0.9.7 → 0.9.10

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 (152) hide show
  1. package/README.md +3 -2
  2. package/dist-sdk/src/catalog/factories.d.ts +14 -3
  3. package/dist-sdk/src/catalog/factories.js +32 -0
  4. package/dist-sdk/src/catalog/from-authoring.js +27 -33
  5. package/dist-sdk/src/catalog/index.d.ts +2 -2
  6. package/dist-sdk/src/catalog/index.js +2 -2
  7. package/dist-sdk/src/catalog/org.js +67 -29
  8. package/dist-sdk/src/catalog/token.js +10 -0
  9. package/dist-sdk/src/catalog/types.d.ts +20 -2
  10. package/dist-sdk/src/catalog/types.js +5 -0
  11. package/dist-sdk/src/core/index.d.ts +1 -1
  12. package/dist-sdk/src/core/index.js +1 -1
  13. package/dist-sdk/src/core/platform-id.d.ts +2 -0
  14. package/dist-sdk/src/core/platform-id.js +4 -0
  15. package/dist-sdk/src/core/system-fields.d.ts +14 -0
  16. package/dist-sdk/src/core/system-fields.js +6 -0
  17. package/dist-sdk/src/core/triggers/on-demand.d.ts +27 -24
  18. package/dist-sdk/src/core/triggers/on-demand.js +33 -12
  19. package/dist-sdk/src/core/types/aspect-category.d.ts +1 -0
  20. package/dist-sdk/src/core/types/aspect-category.js +1 -0
  21. package/dist-sdk/src/engine/build/context.d.ts +22 -8
  22. package/dist-sdk/src/engine/build/source-context.d.ts +14 -17
  23. package/dist-sdk/src/engine/build/source-context.js +1 -1
  24. package/dist-sdk/src/engine/pull/context.d.ts +9 -0
  25. package/dist-sdk/src/engine/pull/org.d.ts +4 -0
  26. package/dist-sdk/src/engine/pull/org.js +17 -2
  27. package/dist-sdk/src/engine/pull/procedure-refs.d.ts +16 -0
  28. package/dist-sdk/src/engine/pull/procedure-refs.js +69 -0
  29. package/dist-sdk/src/engine/tf/expr.js +1 -1
  30. package/dist-sdk/src/engine/workspace/authoring-layout.d.ts +15 -0
  31. package/dist-sdk/src/engine/workspace/authoring-layout.js +33 -1
  32. package/dist-sdk/src/engine/workspace/loader.d.ts +40 -0
  33. package/dist-sdk/src/engine/workspace/loader.js +328 -0
  34. package/dist-sdk/src/entities/access-policy/from-tf.d.ts +4 -0
  35. package/dist-sdk/src/entities/access-policy/from-tf.js +10 -2
  36. package/dist-sdk/src/entities/access-policy/to-tf.d.ts +1 -0
  37. package/dist-sdk/src/entities/access-policy/to-tf.js +7 -2
  38. package/dist-sdk/src/entities/agent/build.d.ts +54 -8
  39. package/dist-sdk/src/entities/agent/build.js +36 -1
  40. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +126 -2
  41. package/dist-sdk/src/entities/agent/from-tf.d.ts +7 -6
  42. package/dist-sdk/src/entities/agent/from-tf.js +176 -5
  43. package/dist-sdk/src/entities/agent/index.d.ts +2 -2
  44. package/dist-sdk/src/entities/agent/index.js +1 -1
  45. package/dist-sdk/src/entities/agent/to-tf.d.ts +4 -4
  46. package/dist-sdk/src/entities/agent/to-tf.js +185 -11
  47. package/dist-sdk/src/entities/agent/tools.d.ts +16 -5
  48. package/dist-sdk/src/entities/agent/tools.js +13 -1
  49. package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +7 -0
  50. package/dist-sdk/src/entities/agent-tool/from-tf.js +29 -4
  51. package/dist-sdk/src/entities/agent-tool/to-tf.js +10 -9
  52. package/dist-sdk/src/entities/agent-tool/types.js +1 -0
  53. package/dist-sdk/src/entities/app/build.d.ts +2 -2
  54. package/dist-sdk/src/entities/app/build.js +6 -3
  55. package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +5 -0
  56. package/dist-sdk/src/entities/app/display-blocks-to-layout.d.ts +45 -0
  57. package/dist-sdk/src/entities/app/display-blocks-to-layout.js +98 -0
  58. package/dist-sdk/src/entities/app/display-blocks-to-record-create-form.d.ts +55 -0
  59. package/dist-sdk/src/entities/app/display-blocks-to-record-create-form.js +99 -0
  60. package/dist-sdk/src/entities/app/from-tf.js +9 -7
  61. package/dist-sdk/src/entities/app/to-tf.d.ts +1 -1
  62. package/dist-sdk/src/entities/app/to-tf.js +17 -7
  63. package/dist-sdk/src/entities/automation/build.d.ts +8 -1
  64. package/dist-sdk/src/entities/automation/build.js +36 -5
  65. package/dist-sdk/src/entities/automation/deserializer/ast.d.ts +3 -7
  66. package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +2 -0
  67. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +140 -12
  68. package/dist-sdk/src/entities/automation/from-tf.d.ts +10 -1
  69. package/dist-sdk/src/entities/automation/from-tf.js +803 -62
  70. package/dist-sdk/src/entities/automation/index.d.ts +1 -1
  71. package/dist-sdk/src/entities/automation/module.js +13 -3
  72. package/dist-sdk/src/entities/automation/output-key-wire-name.d.ts +12 -4
  73. package/dist-sdk/src/entities/automation/output-key-wire-name.js +17 -6
  74. package/dist-sdk/src/entities/automation/script-code.d.ts +8 -1
  75. package/dist-sdk/src/entities/automation/script-code.js +32 -14
  76. package/dist-sdk/src/entities/automation/task-label.d.ts +2 -0
  77. package/dist-sdk/src/entities/automation/task-label.js +18 -0
  78. package/dist-sdk/src/entities/automation/tasks.d.ts +60 -9
  79. package/dist-sdk/src/entities/automation/tasks.js +16 -4
  80. package/dist-sdk/src/entities/automation/to-tf.d.ts +4 -0
  81. package/dist-sdk/src/entities/automation/to-tf.js +394 -52
  82. package/dist-sdk/src/entities/automation/triggers.d.ts +14 -5
  83. package/dist-sdk/src/entities/automation/triggers.js +1 -1
  84. package/dist-sdk/src/entities/dashboard/from-tf.js +1 -1
  85. package/dist-sdk/src/entities/dashboard/to-tf.d.ts +2 -0
  86. package/dist-sdk/src/entities/dashboard/to-tf.js +4 -0
  87. package/dist-sdk/src/entities/datamine/from-tf.js +23 -3
  88. package/dist-sdk/src/entities/dynamic-layout/to-tf.d.ts +1 -0
  89. package/dist-sdk/src/entities/dynamic-layout/to-tf.js +1 -1
  90. package/dist-sdk/src/entities/element/build.d.ts +30 -7
  91. package/dist-sdk/src/entities/element/build.js +6 -3
  92. package/dist-sdk/src/entities/element/from-tf.js +7 -3
  93. package/dist-sdk/src/entities/element/index.d.ts +1 -1
  94. package/dist-sdk/src/entities/element/index.js +1 -1
  95. package/dist-sdk/src/entities/element/to-tf.js +49 -8
  96. package/dist-sdk/src/entities/field/from-tf.d.ts +6 -0
  97. package/dist-sdk/src/entities/field/from-tf.js +12 -0
  98. package/dist-sdk/src/entities/field/module.js +1 -0
  99. package/dist-sdk/src/entities/field/to-tf.d.ts +1 -1
  100. package/dist-sdk/src/entities/field/to-tf.js +19 -5
  101. package/dist-sdk/src/entities/org/category-ref.d.ts +5 -0
  102. package/dist-sdk/src/entities/org/category-ref.js +12 -0
  103. package/dist-sdk/src/entities/record-create-form/from-tf.js +3 -3
  104. package/dist-sdk/src/entities/record-create-form/to-tf.d.ts +1 -0
  105. package/dist-sdk/src/entities/record-create-form/to-tf.js +13 -5
  106. package/dist-sdk/src/entities/relationship/from-tf.js +15 -4
  107. package/dist-sdk/src/entities/role/from-tf.js +10 -4
  108. package/dist-sdk/src/entities/search-table/build.d.ts +1 -1
  109. package/dist-sdk/src/entities/search-table/from-tf.d.ts +1 -0
  110. package/dist-sdk/src/entities/search-table/from-tf.js +6 -0
  111. package/dist-sdk/src/entities/search-table/printer.js +3 -1
  112. package/dist-sdk/src/entities/search-table/to-tf.js +3 -3
  113. package/dist-sdk/src/entities/search-table/types.js +1 -0
  114. package/dist-sdk/src/entities/service-account/from-tf.js +10 -4
  115. package/dist-sdk/src/entities/service-account/to-tf.d.ts +2 -1
  116. package/dist-sdk/src/entities/service-account/to-tf.js +7 -0
  117. package/dist-sdk/src/entities/shared/filters/ast.d.ts +7 -1
  118. package/dist-sdk/src/entities/shared/filters/ast.js +3 -0
  119. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +7 -1
  120. package/dist-sdk/src/entities/shared/filters/tf-codec.js +8 -4
  121. package/dist-sdk/src/entities/shared/handle-description.d.ts +12 -0
  122. package/dist-sdk/src/entities/shared/handle-description.js +20 -0
  123. package/dist-sdk/src/entities/shared/types/field-types.d.ts +6 -1
  124. package/dist-sdk/src/entities/shared/types/field-types.js +5 -8
  125. package/dist-sdk/src/entities/skill/build.d.ts +51 -2
  126. package/dist-sdk/src/entities/skill/build.js +65 -8
  127. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +35 -3
  128. package/dist-sdk/src/entities/skill/from-tf.d.ts +11 -0
  129. package/dist-sdk/src/entities/skill/from-tf.js +39 -7
  130. package/dist-sdk/src/entities/skill/index.d.ts +1 -1
  131. package/dist-sdk/src/entities/skill/index.js +1 -1
  132. package/dist-sdk/src/entities/skill/input-coverage.d.ts +21 -0
  133. package/dist-sdk/src/entities/skill/input-coverage.js +148 -5
  134. package/dist-sdk/src/entities/skill/to-tf.d.ts +6 -25
  135. package/dist-sdk/src/entities/skill/to-tf.js +22 -38
  136. package/dist-sdk/src/entities/skill/tools.d.ts +2 -1
  137. package/dist-sdk/src/entities/skill/tools.js +3 -1
  138. package/dist-sdk/src/entities/skill-tool/from-tf.js +10 -3
  139. package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +5 -5
  140. package/dist-sdk/src/entities/skill-tool/to-tf.js +5 -7
  141. package/dist-sdk/src/entities/table/to-tf.js +3 -4
  142. package/dist-sdk/src/entities/task/to-tf.js +3 -2
  143. package/dist-sdk/src/entities/view/from-tf.js +36 -10
  144. package/dist-sdk/src/entities/view/to-tf.d.ts +2 -0
  145. package/dist-sdk/src/entities/view/to-tf.js +44 -30
  146. package/dist-sdk/src/entities/widget/from-tf.js +2 -2
  147. package/dist-sdk/src/entities/widget/to-tf.d.ts +1 -0
  148. package/dist-sdk/src/entities/widget/to-tf.js +52 -23
  149. package/dist-sdk/src/graph/index.d.ts +19 -1
  150. package/dist-sdk/src/graph/index.js +20 -0
  151. package/dist-sdk/src/graph/types.d.ts +19 -0
  152. package/package.json +10 -5
@@ -1,6 +1,7 @@
1
1
  import { EntityTfError, recordFieldContextOf } from "../../engine/entity.js";
2
2
  import { DEPLOY_DEFAULT_SYSTEM_FIELD_NAMES, SYSTEM_FIELD_KEY_SET } from "../../core/system-fields.js";
3
- import { appResourceLabelPrefix, appScopedResourceLabel, expr, isCanonicalTsLabel, isTfExpr, isUuid, sanitizeName, scopedResourceLabel, snakeSlug, tsLabelToTfLabel, } from "../../engine/tf/index.js";
3
+ import { isUnsafePlatformId } from "../../core/platform-id.js";
4
+ import { appResourceLabelPrefix, appScopedResourceLabel, expr, isTfExpr, isUuid, sanitizeName, scopedResourceLabel, snakeSlug, tsLabelToTfLabel, } from "../../engine/tf/index.js";
4
5
  import { workspaceAspectKey } from "../../engine/build/context.js";
5
6
  import { SEARCH_TABLE_RESOURCE_TYPES } from "../search-table/types.js";
6
7
  import { fieldRefToTfValue } from "../field/to-tf.js";
@@ -15,6 +16,8 @@ import { UNRESOLVED_FIELD_MARKER } from "../shared/ref.js";
15
16
  import { TABLE_RESOURCE_TYPE } from "../table/module.js";
16
17
  import { AUTOMATION_RESOURCE_TYPE, WORKFLOW_PUBLISH_RESOURCE_TYPE } from "./types.js";
17
18
  import { onDemandTriggerRefKey } from "./value-ref-tf.js";
19
+ import { taskTfLabel } from "./task-label.js";
20
+ import { isOnDemandRecordType } from "../shared/types/field-types.js";
18
21
  function scopedLabel(appTfLabel, label) {
19
22
  return appScopedResourceLabel(appTfLabel, label);
20
23
  }
@@ -105,6 +108,10 @@ const TASK_RESOURCES = {
105
108
  runAutomation: "elementum_run_automation_task",
106
109
  aspectRecordFieldLocking: "elementum_aspect_record_field_locking_task",
107
110
  aiFileAnalysis: "elementum_ai_file_read_task",
111
+ // Not a real resource - a read-only data-source reference to a platform
112
+ // task type EDK doesn't implement (edk#785/edk#821). See the `isData` flag
113
+ // on `taskRefs` entries and the dedicated emission branch in `emitTasks`.
114
+ unimplementedTask: "elementum_unmanaged_task_reference",
108
115
  };
109
116
  const CONFIG_ATTRS = {
110
117
  aspectId: "object_id",
@@ -121,6 +128,7 @@ const CONFIG_ATTRS = {
121
128
  emailAliasId: "email_alias_id",
122
129
  approvalChainTemplateId: "approval_chain_template_id",
123
130
  approvalProcessId: "approval_process_id",
131
+ approvalReference: "approval_reference",
124
132
  surveyTemplateId: "survey_template_id",
125
133
  workflowFields: "fields",
126
134
  recordReference: "record_reference",
@@ -359,6 +367,44 @@ function automationTargetToTf(value, ctx, dataBlocks) {
359
367
  : undefined;
360
368
  if (managedOwnerLabel !== undefined) {
361
369
  const managedLabel = scopedLabel(managedOwnerLabel, tsLabelToTfLabel(value.refName));
370
+ const targetOwner = ctx.workspaceAspects?.get(workspaceAspectKey(ownerKind, isOwn ? ctx.appRefName : value.parent ?? ""));
371
+ const targetActiveNames = targetOwner?.activeAutomationNamesByRefName;
372
+ const isActive = targetActiveNames !== undefined
373
+ ? targetActiveNames.has(value.refName)
374
+ : isOwn && ctx.activeAutomationRefNames?.has(value.refName) === true;
375
+ // The on-demand trigger resource exposes the parameter ids from the
376
+ // mutable draft workflow. Once an ACTIVE target is published, however,
377
+ // run-automation validation is performed against its current workflow.
378
+ // Re-read the target after publish so both the target id and parameter
379
+ // ids describe that same current revision. Draft/inactive targets retain
380
+ // the direct resource references below because they have no publish edge.
381
+ if (isActive) {
382
+ const lookupName = targetActiveNames?.get(value.refName) ??
383
+ (isOwn ? ctx.automationNamesByRefName?.get(value.refName) : undefined) ??
384
+ value.name;
385
+ if (lookupName === undefined || lookupName === "") {
386
+ throw new EntityTfError(`managed ACTIVE automation ref "${value.refName}" has no lookup name`);
387
+ }
388
+ // Data block addresses are module-global even though EDK emits one
389
+ // file per automation. Scope the lookup to this caller so two callers
390
+ // of the same target cannot declare a duplicate data address.
391
+ const currentBindingLabel = `${managedLabel}_for_${ctx.automationTfLabel}`;
392
+ dataBlocks.set(`${AUTOMATION_RESOURCE_TYPE}.${currentBindingLabel}`, {
393
+ kind: "data",
394
+ type: AUTOMATION_RESOURCE_TYPE,
395
+ label: currentBindingLabel,
396
+ attrs: {
397
+ app_id: expr.resourceAttr(ownerKind === "element" ? "elementum_element" : "elementum_app", managedOwnerLabel, ["id"]),
398
+ name: lookupName,
399
+ depends_on: [expr.resourceAttr(WORKFLOW_PUBLISH_RESOURCE_TYPE, managedLabel)],
400
+ },
401
+ });
402
+ return {
403
+ id: expr.dataAttr(AUTOMATION_RESOURCE_TYPE, currentBindingLabel, ["id"]),
404
+ parameterId: (name) => expr.dataAttr(AUTOMATION_RESOURCE_TYPE, currentBindingLabel, ["parameter_ids", { index: name }]),
405
+ managedLabel,
406
+ };
407
+ }
362
408
  return {
363
409
  id: expr.resourceAttr(AUTOMATION_RESOURCE_TYPE, managedLabel, ["id"]),
364
410
  parameterId: (name) => expr.resourceAttr("elementum_on_demand_trigger", managedLabel, ["parameter_ids", { index: name }]),
@@ -437,7 +483,7 @@ function tokenToTf(value, ctx, dataBlocks) {
437
483
  return value.refName;
438
484
  case "app":
439
485
  case "element":
440
- if (value.refName !== ctx.appRefName) {
486
+ if (value.refName !== ctx.appRefName || value.__kind !== ctx.parentScope) {
441
487
  const sibling = ctx.workspaceAspects?.get(workspaceAspectKey(value.__kind, value.refName));
442
488
  if (sibling !== undefined) {
443
489
  const siblingType = sibling.kind === "element" ? "elementum_element" : "elementum_app";
@@ -458,7 +504,7 @@ function tokenToTf(value, ctx, dataBlocks) {
458
504
  });
459
505
  return expr.dataAttr(resolved.resourceType, resolved.tfLabel, ["id"]);
460
506
  }
461
- return expr.resourceAttr("elementum_app", ctx.appTfLabel, ["id"]);
507
+ return expr.resourceAttr(ctx.parentScope === "element" ? "elementum_element" : "elementum_app", ctx.appTfLabel, ["id"]);
462
508
  case "field": {
463
509
  // `!== ctx.appRefName` alone isn't enough: an app and a FOREIGN
464
510
  // ELEMENT can share a refName (workspace keys disambiguate by
@@ -506,7 +552,40 @@ function tokenToTf(value, ctx, dataBlocks) {
506
552
  if (value.parent === undefined || value.parent === "") {
507
553
  throw new EntityTfError(`datamine ref "${value.refName}" is missing its owning table`);
508
554
  }
509
- return expr.resourceAttr("elementum_datamine", `${tsLabelToTfLabel(value.parent)}_${tsLabelToTfLabel(value.refName)}`, ["id"]);
555
+ {
556
+ const label = `${tsLabelToTfLabel(value.parent)}_${tsLabelToTfLabel(value.refName)}`;
557
+ const tableSibling = ctx.workspaceAspects?.get(workspaceAspectKey("table", value.parent));
558
+ let tableId;
559
+ if (tableSibling !== undefined) {
560
+ tableId = expr.resourceAttr(TABLE_RESOURCE_TYPE, tableSibling.tfLabel, ["id"]);
561
+ if (tableSibling.managedDatamineLabels?.has(label) === true) {
562
+ return expr.resourceAttr("elementum_datamine", label, ["id"]);
563
+ }
564
+ }
565
+ else {
566
+ const tableLabel = tsLabelToTfLabel(value.parent);
567
+ const tableName = value.parent;
568
+ if (ctx.orgRefs !== undefined) {
569
+ ctx.orgRefs.rawLookup(TABLE_RESOURCE_TYPE, tableLabel, tableName);
570
+ }
571
+ else {
572
+ dataBlocks.set(`${TABLE_RESOURCE_TYPE}.${tableLabel}`, {
573
+ kind: "data",
574
+ type: TABLE_RESOURCE_TYPE,
575
+ label: tableLabel,
576
+ attrs: { name: tableName },
577
+ });
578
+ }
579
+ tableId = expr.dataAttr(TABLE_RESOURCE_TYPE, tableLabel, ["id"]);
580
+ }
581
+ dataBlocks.set(`elementum_datamine.${label}`, {
582
+ kind: "data",
583
+ type: "elementum_datamine",
584
+ label,
585
+ attrs: { table_id: tableId, name: value.name ?? value.refName },
586
+ });
587
+ return expr.dataAttr("elementum_datamine", label, ["id"]);
588
+ }
510
589
  case "table": {
511
590
  const sibling = ctx.workspaceAspects?.get(workspaceAspectKey("table", value.refName));
512
591
  if (sibling !== undefined) {
@@ -630,6 +709,61 @@ function tokenToTf(value, ctx, dataBlocks) {
630
709
  throw new EntityTfError(`catalog ref kind "${value.__kind}" has no automation HCL representation`);
631
710
  }
632
711
  }
712
+ function procedureToTf(value, ctx, dataBlocks) {
713
+ if (value.__kind !== "procedure")
714
+ throw new EntityTfError("procedure requires a procedure catalog reference");
715
+ if (!value.name)
716
+ throw new EntityTfError(`procedure token "${value.refName}" has no lookup name`);
717
+ if (!value.parent)
718
+ throw new EntityTfError(`procedure token "${value.refName}" is missing its owning CloudLink`);
719
+ if (!value.parentName) {
720
+ throw new EntityTfError(`procedure token "${value.parent}.${value.refName}" has no CloudLink lookup name`);
721
+ }
722
+ if (!Array.isArray(value.parameterTypes) || !value.parameterTypes.every((type) => typeof type === "string")) {
723
+ throw new EntityTfError(`procedure token "${value.parent}.${value.refName}" is missing its exact parameter signature`);
724
+ }
725
+ if (!value.databaseName || !value.schemaName) {
726
+ throw new EntityTfError(`procedure token "${value.parent}.${value.refName}" is missing its Snowflake database/schema`);
727
+ }
728
+ const cloudLinkLabel = tsLabelToTfLabel(value.parent);
729
+ const procedureLabel = `${cloudLinkLabel}_${tsLabelToTfLabel(value.refName)}`;
730
+ const cloudLinkId = expr.dataAttr("elementum_cloudlink", cloudLinkLabel, ["id"]);
731
+ if (ctx.orgRefs !== undefined) {
732
+ ctx.orgRefs.rawLookup("elementum_cloudlink", cloudLinkLabel, value.parentName);
733
+ ctx.orgRefs.rawLookup("elementum_stored_function", procedureLabel, value.name, {
734
+ cloudlink_id: cloudLinkId,
735
+ database_name: value.databaseName,
736
+ schema_name: value.schemaName,
737
+ type: "PROCEDURE",
738
+ parameter_types: value.parameterTypes,
739
+ });
740
+ }
741
+ else {
742
+ dataBlocks.set(`elementum_cloudlink.${cloudLinkLabel}`, {
743
+ kind: "data",
744
+ type: "elementum_cloudlink",
745
+ label: cloudLinkLabel,
746
+ attrs: { name: value.parentName },
747
+ });
748
+ dataBlocks.set(`elementum_stored_function.${procedureLabel}`, {
749
+ kind: "data",
750
+ type: "elementum_stored_function",
751
+ label: procedureLabel,
752
+ attrs: {
753
+ cloudlink_id: cloudLinkId,
754
+ name: value.name,
755
+ database_name: value.databaseName,
756
+ schema_name: value.schemaName,
757
+ type: "PROCEDURE",
758
+ parameter_types: value.parameterTypes,
759
+ },
760
+ });
761
+ }
762
+ return {
763
+ cloudLinkId,
764
+ procedureId: expr.dataAttr("elementum_stored_function", procedureLabel, ["id"]),
765
+ };
766
+ }
633
767
  function templateToTf(value, refs) {
634
768
  const template = value.template;
635
769
  const parameters = value.parameters;
@@ -647,11 +781,17 @@ function templateToTf(value, refs) {
647
781
  let cursor = 0;
648
782
  const pattern = /\{\{\{([^}]+)\}\}\}/g;
649
783
  for (let match = pattern.exec(template); match !== null; match = pattern.exec(template)) {
784
+ // The parameter list, not triple-brace text alone, identifies EDK
785
+ // reference placeholders. Third-party URLs and payloads can legitimately
786
+ // contain their own `{{{name}}}` syntax; leave unmatched occurrences in
787
+ // the surrounding literal so pull -> build reproduces them verbatim.
788
+ if (!byName.has(match[1]))
789
+ continue;
650
790
  if (match.index > cursor)
651
791
  parts.push(template.slice(cursor, match.index));
652
792
  const part = byName.get(match[1]);
653
793
  if (part === undefined || !isTfExpr(part)) {
654
- throw new EntityTfError(`template parameter "${match[1]}" is missing or is not a reference`);
794
+ throw new EntityTfError(`template parameter "${match[1]}" is not a reference`);
655
795
  }
656
796
  parts.push(part);
657
797
  cursor = match.index + match[0].length;
@@ -747,9 +887,14 @@ function calculationFormulaRefToParts(value, refs) {
747
887
  * not the task display name). Task id interpolates from the task resource.
748
888
  */
749
889
  function calculationTaskMustache(taskRefKey, wireName, refs) {
890
+ if (wireName.includes('"')) {
891
+ throw new EntityTfError(`calculation task output name "${wireName}" contains a double quote`);
892
+ }
750
893
  const target = refs.tasks.get(taskRefKey);
751
- if (target === undefined)
752
- throw new EntityTfError(`unresolved task ref "${taskRefKey}" in calculation formula`);
894
+ if (target === undefined) {
895
+ refs.owner.diagnostics.push(`automation unresolved task ref ${JSON.stringify(taskRefKey)} preserved as a literal calculation reference`);
896
+ return [`{{task name="${wireName}" id="${taskRefKey}"}}`];
897
+ }
753
898
  if (wireName.includes('"')) {
754
899
  throw new EntityTfError(`calculation task output name "${wireName}" contains a double quote`);
755
900
  }
@@ -877,6 +1022,12 @@ function wireRefName(name, ctx) {
877
1022
  // producer, and it marks the access as an unresolved-field TODO.
878
1023
  if (isUuid(fieldKey))
879
1024
  return name;
1025
+ // Pull-time unresolvedField() uses a typed marker around the raw platform
1026
+ // id so the generated source remains explicit. Strip that marker on the
1027
+ // wire path, just as calculation refs do above.
1028
+ if (fieldKey.startsWith(UNRESOLVED_FIELD_MARKER)) {
1029
+ return `record.${fieldKey.slice(UNRESOLVED_FIELD_MARKER.length)}${parts.length > 2 ? `.${parts.slice(2).join(".")}` : ""}`;
1030
+ }
880
1031
  // System fields (title/status/stage/createdBy/...) have no entry in
881
1032
  // ctx.fieldNames - that map only carries the app's custom fields bag.
882
1033
  // Fall back to the provider's default display name for them; a renamed
@@ -962,11 +1113,40 @@ function taskWireRefName(name, taskRefKey, refs) {
962
1113
  });
963
1114
  }
964
1115
  function triggerWireRefName(name, refs) {
965
- const declared = onDemandTriggerRefKey(name, refs.triggerParamNames);
966
- if (declared !== name || refs.triggerParamNames.includes(name))
1116
+ const scalarParams = refs.triggerParamNames.filter((param) => !refs.recordParamNames.includes(param));
1117
+ const declared = onDemandTriggerRefKey(name, scalarParams);
1118
+ if (declared !== name || scalarParams.includes(name))
967
1119
  return declared;
1120
+ const recordParamName = refs.recordParamNames
1121
+ .filter((paramName) => name === paramName || name.startsWith(`${paramName}.`))
1122
+ .sort((a, b) => b.length - a.length)[0];
1123
+ if (recordParamName !== undefined) {
1124
+ const paramName = recordParamName;
1125
+ const suffix = name === paramName ? "" : name.slice(paramName.length + 1);
1126
+ const displayName = suffix === ""
1127
+ ? "Record"
1128
+ : recordParamFieldWireName(paramName, suffix, refs);
1129
+ return refs.recordParamNames.length > 1
1130
+ ? `${paramName} - ${displayName}`
1131
+ : displayName;
1132
+ }
968
1133
  return wireRefName(name, refs.owner);
969
1134
  }
1135
+ function recordParamFieldWireName(paramName, suffix, refs) {
1136
+ const target = refs.recordParamTargets.get(paramName);
1137
+ if (target === undefined) {
1138
+ throw new EntityTfError(`onDemand record parameter "${paramName}" is missing its target app/element`);
1139
+ }
1140
+ const targetRefName = target.refName;
1141
+ const targetFieldNames = targetRefName === refs.owner.appRefName && target.__kind === refs.owner.parentScope
1142
+ ? refs.owner.fieldNames
1143
+ : refs.fieldNamesByAppRefName?.get(targetRefName);
1144
+ return wireRefName(`record.${suffix}`, {
1145
+ ...refs.owner,
1146
+ appRefName: targetRefName,
1147
+ fieldNames: targetFieldNames ?? new Map(),
1148
+ });
1149
+ }
970
1150
  /** Run-automation targets reference publish for ACTIVE automations, automation for draft/inactive. */
971
1151
  export function automationRunTargetResourceAttr(appTfLabel, automationRefName, activeAutomationRefNames) {
972
1152
  const label = appScopedResourceLabel(appTfLabel, tsLabelToTfLabel(automationRefName));
@@ -1001,15 +1181,19 @@ function workflowPublishOutputEnvelope(value, refs) {
1001
1181
  if (!isObject(value))
1002
1182
  return undefined;
1003
1183
  if (isObject(value.taskReference) && typeof value.taskReference.taskRefKey === "string" && typeof value.taskReference.name === "string") {
1184
+ if (value.taskReference.name.includes('"')) {
1185
+ throw new EntityTfError(`task output name "${value.taskReference.name}" contains a double quote`);
1186
+ }
1004
1187
  const target = refs.tasks.get(value.taskReference.taskRefKey);
1005
1188
  if (target === undefined)
1006
1189
  return undefined;
1007
1190
  const isFileReaderTask = target.type === "elementum_ai_file_read_task" || target.type === "elementum_file_reader_task";
1191
+ const isAiAgentTask = target.type === "elementum_ai_agent_task";
1008
1192
  const isAiSearchTableRecords = target.type === "elementum_ai_search_table_task" &&
1009
1193
  (value.taskReference.name === "records" || value.taskReference.name === "All Records");
1010
1194
  const isTableRecordsSearchRecords = target.type === "elementum_table_records_search_task" &&
1011
1195
  (value.taskReference.name === "records" || value.taskReference.name === "All matching table rows");
1012
- const wireName = isFileReaderTask
1196
+ const refsKey = isFileReaderTask || isAiAgentTask
1013
1197
  ? value.taskReference.name
1014
1198
  : isAiSearchTableRecords
1015
1199
  ? "All Records"
@@ -1018,12 +1202,15 @@ function workflowPublishOutputEnvelope(value, refs) {
1018
1202
  ? "All matching table rows"
1019
1203
  : "records"
1020
1204
  : taskWireRefName(value.taskReference.name, value.taskReference.taskRefKey, refs);
1021
- const typed = publishOutputType(value, target, wireName);
1205
+ const platformRefName = isAiAgentTask
1206
+ ? aiAgentPlatformRefName(refsKey)
1207
+ : refsKey;
1208
+ const typed = publishOutputType(value, target, refsKey);
1022
1209
  return {
1023
1210
  fieldType: typed.fieldType,
1024
1211
  multiple: typed.multiple,
1025
1212
  taskReference: {
1026
- name: wireName,
1213
+ name: platformRefName,
1027
1214
  taskId: expr.resourceAttr(target.type, target.label, ["id"]),
1028
1215
  },
1029
1216
  // ei export always pads the unused reference arms with null.
@@ -1057,6 +1244,19 @@ function workflowPublishOutputEnvelope(value, refs) {
1057
1244
  }
1058
1245
  return undefined;
1059
1246
  }
1247
+ /**
1248
+ * The provider's ai-agent refs map and the serialized platform reference use
1249
+ * different names. Keep the map key for Terraform indexing, but emit the
1250
+ * nested taskReference.name expected by workflow publish envelopes.
1251
+ */
1252
+ function aiAgentPlatformRefName(refsKey) {
1253
+ if (refsKey === "Action Response")
1254
+ return "ai_agent_task_response";
1255
+ if (refsKey === "ai_agent_task_response" || refsKey.startsWith("ai_agent_task_structured_output.")) {
1256
+ return refsKey;
1257
+ }
1258
+ return `ai_agent_task_structured_output.${refsKey.toLowerCase()}`;
1259
+ }
1060
1260
  function publishOutputType(value, target, wireName) {
1061
1261
  if (typeof value.fieldType === "string") {
1062
1262
  return { fieldType: value.fieldType, multiple: value.multiple === true };
@@ -1108,9 +1308,14 @@ function valueToTf(value, refs) {
1108
1308
  return expr.resourceAttr(refs.trigger.type, refs.trigger.label, ["refs", { index: triggerWireRefName(value.triggerReference.name, refs) }]);
1109
1309
  }
1110
1310
  if (isObject(value.taskReference) && typeof value.taskReference.taskRefKey === "string" && typeof value.taskReference.name === "string") {
1311
+ if (value.taskReference.name.includes('"')) {
1312
+ throw new EntityTfError(`task output name "${value.taskReference.name}" contains a double quote`);
1313
+ }
1111
1314
  const target = refs.tasks.get(value.taskReference.taskRefKey);
1112
- if (target === undefined)
1113
- throw new EntityTfError(`unresolved task ref "${value.taskReference.taskRefKey}"`);
1315
+ if (target === undefined) {
1316
+ refs.owner.diagnostics.push(`automation unresolved task ref ${JSON.stringify(value.taskReference.taskRefKey)} preserved as a literal reference`);
1317
+ return `{{task name="${value.taskReference.name}" id="${value.taskReference.taskRefKey}"}}`;
1318
+ }
1114
1319
  // aiFileAnalysis/readFile's refs are keyed by whatever arbitrary field
1115
1320
  // names the file reader schema itself defines (e.g. "title",
1116
1321
  // "document_type") - wireRefName's generic segment table
@@ -1121,6 +1326,7 @@ function valueToTf(value, refs) {
1121
1326
  // resources' actual refs map - confirmed live via a real apply's
1122
1327
  // "Invalid index" error. Their field names pass through verbatim.
1123
1328
  const isFileReaderTask = target.type === "elementum_ai_file_read_task" || target.type === "elementum_file_reader_task";
1329
+ const isAiAgentTask = target.type === "elementum_ai_agent_task";
1124
1330
  // aiSearchTable's collection is `refs["All Records"]`, not recordSearch's
1125
1331
  // globally-mapped `refs["All found records"]` (TS_REF_SEGMENT_TO_WIRE).
1126
1332
  // Accept both the authoring segment and the already-rewritten wire name
@@ -1130,7 +1336,7 @@ function valueToTf(value, refs) {
1130
1336
  // tableRecordsSearch uses yet another wire key: "All matching table rows".
1131
1337
  const isTableRecordsSearchRecords = target.type === "elementum_table_records_search_task" &&
1132
1338
  (value.taskReference.name === "records" || value.taskReference.name === "All matching table rows");
1133
- const refKey = isFileReaderTask
1339
+ const refKey = isFileReaderTask || isAiAgentTask
1134
1340
  ? value.taskReference.name
1135
1341
  : isAiSearchTableRecords
1136
1342
  ? "All Records"
@@ -1246,6 +1452,15 @@ function filterReferenceToTf(value, refs, role = "value", realType) {
1246
1452
  if (isUuid(fieldKey)) {
1247
1453
  return `trigger.${value.name}`;
1248
1454
  }
1455
+ // unresolvedField()'s value-position escape tags the same
1456
+ // unresolvable field with UNRESOLVED_FIELD_MARKER instead of a bare
1457
+ // uuid (see wireRefName's matching check). Without this, the marker
1458
+ // fails the isUuid check above and falls through to the generic
1459
+ // `.refs[...]` lookup below, which is the wrong wire convention for
1460
+ // a filter reference and points at a refs-map key that doesn't exist.
1461
+ if (fieldKey.startsWith(UNRESOLVED_FIELD_MARKER)) {
1462
+ return `trigger.${value.name.replace(UNRESOLVED_FIELD_MARKER, "")}`;
1463
+ }
1249
1464
  }
1250
1465
  const triggerRefKey = triggerWireRefName(value.name, refs);
1251
1466
  if (refs.trigger.type === TRIGGER_RESOURCES.onDemand) {
@@ -1259,7 +1474,11 @@ function filterReferenceToTf(value, refs, role = "value", realType) {
1259
1474
  const task = refs.tasks.get(value.taskRefKey);
1260
1475
  if (task === undefined)
1261
1476
  throw new EntityTfError(`unresolved task filter ref "${value.taskRefKey}"`);
1262
- const wireName = taskWireRefName(value.name, value.taskRefKey, refs);
1477
+ const isFileReaderTask = task.type === "elementum_ai_file_read_task" || task.type === "elementum_file_reader_task";
1478
+ const isAiAgentTask = task.type === "elementum_ai_agent_task";
1479
+ const wireName = isFileReaderTask || isAiAgentTask
1480
+ ? value.name
1481
+ : taskWireRefName(value.name, value.taskRefKey, refs);
1263
1482
  // left_value (switch cases): provider Read stores the JSON envelope that
1264
1483
  // `.refs["…"]` evaluates to (#490). Emitting the short `task.<id>.…`
1265
1484
  // string matches record_search RHS state but perpetual-diffs left_value.
@@ -1327,7 +1546,15 @@ function picklistFilterValueToTf(value, field, refs) {
1327
1546
  // rather than blocking on platform data it can't fix.
1328
1547
  if (isUuid(value))
1329
1548
  return undefined;
1330
- throw new EntityTfError(`automation filter for picklist field "${field.name ?? field.refName}" uses unknown option ${JSON.stringify(value)}; expected one of: ${field.options.map((option) => JSON.stringify(option)).join(", ")}`);
1549
+ // A pulled automation can legitimately retain a label for an option that
1550
+ // was deleted/recreated after the automation was authored. Keep the
1551
+ // literal so build remains a lossless offline round-trip; the provider
1552
+ // can report the platform-side mismatch during plan/apply.
1553
+ if (refs.allowUnknownPicklistOptions !== true) {
1554
+ throw new EntityTfError(`automation filter for picklist field "${field.name ?? field.refName}" uses unknown option ${JSON.stringify(value)}; expected one of: ${field.options.map((option) => JSON.stringify(option)).join(", ")}`);
1555
+ }
1556
+ refs.owner.diagnostics.push(`automation filter for picklist field ${JSON.stringify(field.name ?? field.refName)} preserves unknown option ${JSON.stringify(value)}`);
1557
+ return undefined;
1331
1558
  }
1332
1559
  if (field.parent !== undefined && field.parentKind !== undefined) {
1333
1560
  // A field owned by a SIBLING app/element built in this same workspace
@@ -1410,13 +1637,23 @@ function configAttrs(kind, config, refs) {
1410
1637
  continue;
1411
1638
  // A config value of exactly `undefined` almost always means the
1412
1639
  // authoring builder was called with a required option omitted (e.g. a
1413
- // TS-only-enforced field that jiti/bun never actually type-checks at
1640
+ // TS-only-enforced field that no runtime actually type-checks at
1414
1641
  // build time) - name the wire key here, since the generic valueToTf
1415
1642
  // fallback below has no attribute name to report by the time it gets to
1416
1643
  // its own "unsupported value" throw.
1417
1644
  if (raw === undefined) {
1418
1645
  throw new EntityTfError(`${kind}: config value for "${key}" is undefined — likely a missing required option on the authoring builder call that built this task/trigger`);
1419
1646
  }
1647
+ if (key === "procedure" && kind === "elementum_procedure_task") {
1648
+ const procedure = token(raw);
1649
+ if (procedure?.__kind !== "procedure") {
1650
+ throw new EntityTfError("procedure requires a procedure catalog reference");
1651
+ }
1652
+ const resolved = procedureToTf(procedure, refs.owner, refs.dataBlocks);
1653
+ attrs.cloudlink_id = resolved.cloudLinkId;
1654
+ attrs.stored_function_id = resolved.procedureId;
1655
+ continue;
1656
+ }
1420
1657
  // elementum_create_record_task has no "relate to record" boolean
1421
1658
  // attribute - relate_to_record_reference's presence alone conveys the
1422
1659
  // intent (see from-tf.ts's matching comment), so the flag itself is
@@ -1458,6 +1695,14 @@ function configAttrs(kind, config, refs) {
1458
1695
  });
1459
1696
  continue;
1460
1697
  }
1698
+ if (key === "outputMappings" && kind === "elementum_run_automation_task" && config.targetAutomationId !== undefined) {
1699
+ // Static run-automation tasks expose the published target's outputs in
1700
+ // `refs` automatically. The live API rejects even valid, matching
1701
+ // outputMappings with "Unable to validate" (#703), so keep authored
1702
+ // output names as a TypeScript typing aid and do not send the redundant
1703
+ // backend input. Dynamic targets still need their explicit mappings.
1704
+ continue;
1705
+ }
1461
1706
  if (key === "targetAutomationRef" && kind === "elementum_run_automation_task") {
1462
1707
  if (!isObject(raw) || raw.type !== "STATIC") {
1463
1708
  throw new EntityTfError("runAutomation targetAutomationRef must be { type: \"STATIC\", value: ... }");
@@ -1559,6 +1804,10 @@ function configAttrs(kind, config, refs) {
1559
1804
  attrs.record_id = valueToTf(raw, refs);
1560
1805
  continue;
1561
1806
  }
1807
+ if (key === "recordId" && kind === "elementum_initiate_call_task") {
1808
+ attrs.record_id = valueToTf(raw, refs);
1809
+ continue;
1810
+ }
1562
1811
  if (key === "calculations" && kind === "elementum_calculation_task") {
1563
1812
  if (!Array.isArray(raw))
1564
1813
  throw new EntityTfError("calculations must be an array");
@@ -1611,18 +1860,23 @@ function configAttrs(kind, config, refs) {
1611
1860
  const parameters = raw.map((input) => {
1612
1861
  if (!isObject(input))
1613
1862
  throw new EntityTfError("onDemand input must be an object");
1614
- return Object.fromEntries(Object.entries(input).map(([k, v]) => [
1863
+ const mapped = Object.fromEntries(Object.entries(input)
1864
+ .filter(([k]) => k !== "app")
1865
+ .map(([k, v]) => [
1615
1866
  CONFIG_ATTRS[k] ?? snake(k),
1616
1867
  valueToTf(k === "defaultValue" ? unwrapDefault(v) :
1617
- // elementum_on_demand_trigger.parameters[].type's real validator
1618
- // (on_demand_trigger_resource.go) only accepts a bare "attachment"
1619
- // - there is no "attachment_id" variant at this layer, unlike the
1620
- // WorkflowFieldType enum name (ATTACHMENT_ID) the "attachmentId"
1621
- // authoring alias otherwise maps to. A generic lowercase would
1622
- // wrongly emit "attachment_id" and fail plan/apply.
1623
1868
  k === "type" && v === "ATTACHMENT_ID" ? "attachment" :
1624
- k === "type" && typeof v === "string" ? v.toLowerCase() : v, refs),
1869
+ k === "type" && v === "ASPECT_RECORD" ? "record" :
1870
+ k === "type" && typeof v === "string" ? v.toLowerCase() : v, refs),
1625
1871
  ]));
1872
+ if (isOnDemandRecordType(typeof input.type === "string" ? input.type : undefined)) {
1873
+ const target = token(input.app);
1874
+ if (target === undefined || (target.__kind !== "app" && target.__kind !== "element")) {
1875
+ throw new EntityTfError(`onDemand record parameter ${JSON.stringify(input.name)} requires an explicit app/element target`);
1876
+ }
1877
+ mapped.default_value = tokenToTf(target, refs.owner, refs.dataBlocks);
1878
+ }
1879
+ return mapped;
1626
1880
  });
1627
1881
  // The provider normalizes an absent parameter collection to null. An
1628
1882
  // explicit [] therefore creates perpetual [] vs null drift after pull.
@@ -1817,28 +2071,14 @@ function fileReaderDependsOn(blocks) {
1817
2071
  });
1818
2072
  return deps;
1819
2073
  }
1820
- function taskLabel(automationLabel, refKey) {
1821
- // ei's task label is `<auto>_<sanitizeName(task name)>` for display-name
1822
- // stems. Pulled refKeys that are already canonical camelCase (e.g.
1823
- // `commodityBHit_1`) must use the lossless `tsLabelToTfLabel` bijection —
1824
- // `sanitizeName` lowercases before splitCamelCase and collapses
1825
- // single-letter camel segments (`commodityBHit` → `commodityb_hit`), which
1826
- // plans destroy+create against export's `commodity_b_hit_1`.
1827
- //
1828
- // ALLCAPS / SCREAMING_SNAKE refKeys (`GREETING`) also round-trip the
1829
- // bijection (via ugly `_g_r_e_e_t_i_n_g`), but ei's SanitizeName yields
1830
- // `greeting` — require a lowercase letter before preferring the bijection.
1831
- const normalized = isCanonicalTsLabel(refKey) && /[a-z]/.test(refKey)
1832
- ? tsLabelToTfLabel(refKey)
1833
- : sanitizeName(refKey);
1834
- return normalized.startsWith(`${automationLabel}_`) ? normalized : `${automationLabel}_${normalized}`;
1835
- }
1836
2074
  /** App- or element-owned `automation` entity → provider HCL blocks. */
1837
2075
  export function automationToTf(entity, ctx) {
2076
+ const automationTfLabel = scopedLabel(ctx.appTfLabel, tsLabelToTfLabel(entity.refName));
1838
2077
  const owner = {
1839
2078
  appRefName: ctx.appRefName ?? entity.parent,
1840
2079
  parentScope: ctx.parentScope ?? "app",
1841
2080
  appTfLabel: ctx.appTfLabel,
2081
+ automationTfLabel,
1842
2082
  fieldAddresses: ctx.fieldAddresses ?? new Map(),
1843
2083
  fieldNames: ctx.fieldNames ?? new Map(),
1844
2084
  fieldMetadata: ctx.fieldMetadata ?? new Map(),
@@ -1847,6 +2087,7 @@ export function automationToTf(entity, ctx) {
1847
2087
  workspaceAspects: ctx.workspaceAspects,
1848
2088
  diagnostics: ctx.diagnostics ?? [],
1849
2089
  activeAutomationRefNames: ctx.activeAutomationRefNames,
2090
+ automationNamesByRefName: ctx.automationNamesByRefName,
1850
2091
  };
1851
2092
  if (entity.kind !== "automation")
1852
2093
  throw new EntityTfError(`automationToTf expects kind "automation"; got "${entity.kind}"`);
@@ -1858,7 +2099,7 @@ export function automationToTf(entity, ctx) {
1858
2099
  throw new EntityTfError(`automation "${entity.refName}" has a non-object payload`);
1859
2100
  if (typeof payload.workflowRevision !== "string")
1860
2101
  throw new EntityTfError(`automation "${entity.refName}" has no workflowRevision`);
1861
- const label = scopedLabel(owner.appTfLabel, tsLabelToTfLabel(entity.refName));
2102
+ const label = automationTfLabel;
1862
2103
  const automation = {
1863
2104
  kind: "resource",
1864
2105
  type: AUTOMATION_RESOURCE_TYPE,
@@ -1908,7 +2149,10 @@ export function automationToTf(entity, ctx) {
1908
2149
  const resourceType = wireType === "variable" ? variableTaskResourceType(taskBody, refKey) : TASK_RESOURCES[wireType];
1909
2150
  if (resourceType === undefined)
1910
2151
  throw new EntityTfError(`task type "${wireType}" is not supported by the provider HCL contract`);
1911
- const registeredLabel = taskLabel(label, refKey);
2152
+ // elementum_unmanaged_task_reference is a data source exported under its
2153
+ // own bare sanitized-name label - never scoped under the automation the
2154
+ // way every real task resource is (confirmed live, edk#821).
2155
+ const registeredLabel = wireType === "unimplementedTask" ? sanitizeName(refKey) : taskTfLabel(label, refKey);
1912
2156
  const collidingRefKey = usedLabels.get(registeredLabel);
1913
2157
  if (collidingRefKey !== undefined) {
1914
2158
  throw new EntityTfError(`task "${refKey}" sanitizes to the same tf label as task "${collidingRefKey}" (${registeredLabel}) — rename one of them`);
@@ -1916,10 +2160,15 @@ export function automationToTf(entity, ctx) {
1916
2160
  usedLabels.set(registeredLabel, refKey);
1917
2161
  const outputFieldTypes = wireType === "executeScript"
1918
2162
  ? outputFieldTypesFromScriptSchema(taskBody.outputSchema)
1919
- : undefined;
2163
+ : wireType === "aiAgent" && Array.isArray(taskBody.jsonFields)
2164
+ ? new Map(taskBody.jsonFields.flatMap((field) => isObject(field) && typeof field.name === "string" && typeof field.type === "string"
2165
+ ? [[field.name, { fieldType: field.type, multiple: false }]]
2166
+ : []))
2167
+ : undefined;
1920
2168
  taskRefs.set(refKey, {
1921
2169
  type: resourceType,
1922
2170
  label: registeredLabel,
2171
+ ...(wireType === "unimplementedTask" ? { isData: true } : {}),
1923
2172
  ...(outputFieldTypes !== undefined && outputFieldTypes.size > 0 ? { outputFieldTypes } : {}),
1924
2173
  });
1925
2174
  if (wireType === "variable" && Array.isArray(taskBody.create)) {
@@ -1939,15 +2188,35 @@ export function automationToTf(entity, ctx) {
1939
2188
  const triggerParamNames = triggerKey === "onDemand" && isObject(triggerConfig) && Array.isArray(triggerConfig.inputs)
1940
2189
  ? triggerConfig.inputs.flatMap((input) => isObject(input) && typeof input.name === "string" ? [input.name] : [])
1941
2190
  : [];
2191
+ const recordParamNames = triggerKey === "onDemand" && isObject(triggerConfig) && Array.isArray(triggerConfig.inputs)
2192
+ ? triggerConfig.inputs.flatMap((input) => isObject(input) && typeof input.name === "string" && isOnDemandRecordType(typeof input.type === "string" ? input.type : undefined)
2193
+ ? [input.name]
2194
+ : [])
2195
+ : [];
2196
+ const recordParamTargets = new Map(triggerKey === "onDemand" && isObject(triggerConfig) && Array.isArray(triggerConfig.inputs)
2197
+ ? triggerConfig.inputs.flatMap((input) => {
2198
+ if (!isObject(input) ||
2199
+ typeof input.name !== "string" ||
2200
+ !isOnDemandRecordType(typeof input.type === "string" ? input.type : undefined))
2201
+ return [];
2202
+ const target = token(input.app);
2203
+ return target !== undefined && (target.__kind === "app" || target.__kind === "element")
2204
+ ? [[input.name, target]]
2205
+ : [];
2206
+ })
2207
+ : []);
1942
2208
  const refs = {
1943
2209
  trigger: { type: triggerType, label },
1944
2210
  triggerParamNames,
2211
+ recordParamNames,
2212
+ recordParamTargets,
1945
2213
  tasks: taskRefs,
1946
2214
  owner,
1947
2215
  dataBlocks,
1948
2216
  variableById,
1949
2217
  ...(recordFieldContext !== undefined ? { recordFieldContext } : {}),
1950
2218
  ...(ctx.fieldNamesByAppRefName !== undefined ? { fieldNamesByAppRefName: ctx.fieldNamesByAppRefName } : {}),
2219
+ ...(ctx.allowUnknownPicklistOptions === true ? { allowUnknownPicklistOptions: true } : {}),
1951
2220
  };
1952
2221
  let triggerAttrs;
1953
2222
  try {
@@ -1966,7 +2235,14 @@ export function automationToTf(entity, ctx) {
1966
2235
  const blocks = [automation, trigger];
1967
2236
  const dependencies = [expr.resourceAttr(triggerType, label)];
1968
2237
  const runAutomationPublishes = new Set();
1969
- const emitTasks = (tasks, initialParent) => {
2238
+ // `enclosingOperator` describes the switch/forkJoin/forEach scope THIS
2239
+ // `emitTasks` call is nested inside (undefined at automation top level) -
2240
+ // needed only by `unimplementedTask` (edk#821) to populate
2241
+ // `operator_task_id`/`operator_child_id` correctly regardless of how many
2242
+ // real sibling tasks precede the placeholder within the same case/branch
2243
+ // (the rolling `taskParent` chain below tracks the PRECEDING SIBLING, not
2244
+ // the enclosing operator, once more than one task shares a scope).
2245
+ const emitTasks = (tasks, initialParent, enclosingOperator) => {
1970
2246
  let parent = initialParent;
1971
2247
  let first;
1972
2248
  for (const task of tasks) {
@@ -1996,7 +2272,55 @@ export function automationToTf(entity, ctx) {
1996
2272
  initialParent.path[0] === "inner";
1997
2273
  taskParent = inBodyOfExplicitParent
1998
2274
  ? initialParent
1999
- : expr.resourceAttr(explicitParent.type, explicitParent.label);
2275
+ : explicitParent.isData === true
2276
+ ? expr.dataAttr(explicitParent.type, explicitParent.label)
2277
+ : expr.resourceAttr(explicitParent.type, explicitParent.label);
2278
+ }
2279
+ if (wireType === "unimplementedTask") {
2280
+ // elementum_unmanaged_task_reference (edk#785/edk#821) is a read-only
2281
+ // data source, not a resource: it has no CRUD, never joins
2282
+ // `depends_on`, and its structural fields (app_id/automation_id/
2283
+ // workflow_id/parent_is_trigger/operator_task_id/operator_child_id)
2284
+ // are re-derived from context rather than authored - only `id` and
2285
+ // `taskType` are authored (see tasks.ts's unimplementedTask).
2286
+ const idValue = isUnsafePlatformId(inner.id) ? inner.id.value : typeof inner.id === "string" ? inner.id : undefined;
2287
+ if (idValue === undefined)
2288
+ throw new EntityTfError(`unimplementedTask "${refKey}" requires an id`);
2289
+ if (typeof inner.taskType !== "string" || inner.taskType === "") {
2290
+ throw new EntityTfError(`unimplementedTask "${refKey}" requires a taskType`);
2291
+ }
2292
+ const operatorTaskAddress = enclosingOperator?.taskAddress;
2293
+ const operatorChildAddress = enclosingOperator?.childAddress;
2294
+ const isParentTrigger = enclosingOperator === undefined;
2295
+ const extraAttrs = {
2296
+ id: idValue,
2297
+ task_type: inner.taskType,
2298
+ workflow_id: expr.resourceAttr(AUTOMATION_RESOURCE_TYPE, label, ["workflow_id"]),
2299
+ app_id: expr.resourceAttr(owner.parentScope === "element" ? "elementum_element" : "elementum_app", owner.appTfLabel, ["id"]),
2300
+ automation_id: expr.resourceAttr(AUTOMATION_RESOURCE_TYPE, label, ["id"]),
2301
+ parent_is_trigger: isParentTrigger,
2302
+ ...(operatorTaskAddress !== undefined && operatorTaskAddress.$expr === "resource-attr"
2303
+ ? { operator_task_id: expr.resourceAttr(operatorTaskAddress.type, operatorTaskAddress.label, ["id"]) }
2304
+ : {}),
2305
+ ...(operatorChildAddress !== undefined && operatorChildAddress.$expr === "resource-attr"
2306
+ ? { operator_child_id: expr.resourceAttr(operatorChildAddress.type, operatorChildAddress.label, ["id"]) }
2307
+ : {}),
2308
+ };
2309
+ if (owner.orgRefs !== undefined) {
2310
+ owner.orgRefs.rawLookup("elementum_unmanaged_task_reference", tfLabel, displayName, extraAttrs);
2311
+ }
2312
+ else {
2313
+ dataBlocks.set(`elementum_unmanaged_task_reference.${tfLabel}`, {
2314
+ kind: "data",
2315
+ type: "elementum_unmanaged_task_reference",
2316
+ label: tfLabel,
2317
+ attrs: { name: displayName, ...extraAttrs },
2318
+ });
2319
+ }
2320
+ const address = expr.dataAttr("elementum_unmanaged_task_reference", tfLabel);
2321
+ first ??= address;
2322
+ parent = address;
2323
+ continue;
2000
2324
  }
2001
2325
  if (wireType === "variable") {
2002
2326
  const variableType = variableTaskResourceType(inner, refKey);
@@ -2056,14 +2380,18 @@ export function automationToTf(entity, ctx) {
2056
2380
  const address = expr.resourceAttr(resourceType, tfLabel);
2057
2381
  dependencies.push(address);
2058
2382
  first ??= address;
2059
- // Only chain linear siblings; explicit hclParent keeps parallel roots under trigger.
2060
- if (task.hclParent === undefined)
2061
- parent = address;
2383
+ // Always advance the rolling continuation point to this task, even when
2384
+ // it was explicitly anchored (a fork root off the trigger or another
2385
+ // task). Whatever comes next in this same printed sequence is either
2386
+ // this task's own descendant (which must continue from it) or a task
2387
+ // with its own explicit anchor (which ignores this value entirely) -
2388
+ // never a sibling that should skip back to an earlier task.
2389
+ parent = address;
2062
2390
  if (wireType === "forEach") {
2063
2391
  const children = task.children ?? [];
2064
2392
  if (children.length !== 1)
2065
2393
  throw new EntityTfError(`forEach task "${refKey}" must have exactly one child body`);
2066
- emitTasks(children[0].tasks ?? [], expr.resourceAttr(resourceType, tfLabel, ["inner"]));
2394
+ emitTasks(children[0].tasks ?? [], expr.resourceAttr(resourceType, tfLabel, ["inner"]), { taskAddress: expr.resourceAttr(resourceType, tfLabel) });
2067
2395
  // The loop body is a separate operator-owned chain. A fluent sibling
2068
2396
  // authored after `forEach` continues from the for_each task itself,
2069
2397
  // not from the body's terminal task; the latter silently moves that
@@ -2074,6 +2402,20 @@ export function automationToTf(entity, ctx) {
2074
2402
  const children = task.children ?? [];
2075
2403
  if (children.length === 0)
2076
2404
  throw new EntityTfError(`${wireType} task "${refKey}" must have branches`);
2405
+ const usedLabels = new Map();
2406
+ for (const [index, child] of children.entries()) {
2407
+ const isDefault = wireType === "switch" && (child.isDefault === true || child.label === null);
2408
+ const displayLabel = isDefault
2409
+ ? (child.defaultLabel ?? "Default")
2410
+ : (child.label ?? "");
2411
+ const prior = usedLabels.get(displayLabel);
2412
+ if (prior !== undefined) {
2413
+ throw new EntityTfError(displayLabel === ""
2414
+ ? `${wireType} task "${refKey}" has more than one unlabeled case (cases ${prior} and ${index + 1}); give each case a unique label`
2415
+ : `${wireType} task "${refKey}" reuses label ${JSON.stringify(displayLabel)} on cases ${prior} and ${index + 1}`);
2416
+ }
2417
+ usedLabels.set(displayLabel, index + 1);
2418
+ }
2077
2419
  let previous;
2078
2420
  for (const [index, child] of children.entries()) {
2079
2421
  const branchType = wireType === "switch" ? "elementum_switch_case" : "elementum_fork_join_branch";
@@ -2124,7 +2466,7 @@ export function automationToTf(entity, ctx) {
2124
2466
  blocks.push({ kind: "resource", type: branchType, label: branchLabel, attrs: branchAttrs });
2125
2467
  const branchAddress = expr.resourceAttr(branchType, branchLabel);
2126
2468
  dependencies.push(branchAddress);
2127
- emitTasks(child.tasks ?? [], branchAddress);
2469
+ emitTasks(child.tasks ?? [], branchAddress, { taskAddress: address, childAddress: branchAddress });
2128
2470
  previous = branchAddress;
2129
2471
  }
2130
2472
  }