@elementumai/edk 0.9.9 → 0.9.11

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/dist-sdk/src/catalog/factories.d.ts +8 -1
  2. package/dist-sdk/src/catalog/factories.js +13 -1
  3. package/dist-sdk/src/catalog/index.d.ts +2 -2
  4. package/dist-sdk/src/catalog/index.js +1 -1
  5. package/dist-sdk/src/catalog/types.d.ts +19 -2
  6. package/dist-sdk/src/catalog/types.js +1 -0
  7. package/dist-sdk/src/engine/build/context.d.ts +5 -0
  8. package/dist-sdk/src/entities/access-policy/from-tf.d.ts +3 -3
  9. package/dist-sdk/src/entities/access-policy/from-tf.js +27 -8
  10. package/dist-sdk/src/entities/access-policy/to-tf.d.ts +13 -0
  11. package/dist-sdk/src/entities/access-policy/to-tf.js +34 -3
  12. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +13 -7
  13. package/dist-sdk/src/entities/agent-tool/to-tf.js +13 -0
  14. package/dist-sdk/src/entities/app/build.d.ts +15 -2
  15. package/dist-sdk/src/entities/app/build.js +6 -0
  16. package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +13 -3
  17. package/dist-sdk/src/entities/app/from-tf.js +6 -3
  18. package/dist-sdk/src/entities/app/to-tf.d.ts +1 -1
  19. package/dist-sdk/src/entities/app/to-tf.js +7 -1
  20. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +78 -19
  21. package/dist-sdk/src/entities/automation/from-tf.js +113 -1
  22. package/dist-sdk/src/entities/automation/module.js +1 -0
  23. package/dist-sdk/src/entities/automation/script-code.d.ts +7 -0
  24. package/dist-sdk/src/entities/automation/script-code.js +17 -3
  25. package/dist-sdk/src/entities/automation/tasks.js +17 -0
  26. package/dist-sdk/src/entities/automation/to-tf.d.ts +8 -0
  27. package/dist-sdk/src/entities/automation/to-tf.js +162 -46
  28. package/dist-sdk/src/entities/automation/types.js +1 -0
  29. package/dist-sdk/src/entities/dashboard/from-tf.js +11 -2
  30. package/dist-sdk/src/entities/dashboard/to-tf.d.ts +2 -0
  31. package/dist-sdk/src/entities/dashboard/to-tf.js +4 -0
  32. package/dist-sdk/src/entities/datamine/from-tf.js +23 -3
  33. package/dist-sdk/src/entities/dynamic-layout/build.d.ts +2 -1
  34. package/dist-sdk/src/entities/dynamic-layout/dialect.d.ts +8 -0
  35. package/dist-sdk/src/entities/dynamic-layout/dialect.js +12 -0
  36. package/dist-sdk/src/entities/dynamic-layout/from-tf.d.ts +7 -0
  37. package/dist-sdk/src/entities/dynamic-layout/from-tf.js +64 -10
  38. package/dist-sdk/src/entities/dynamic-layout/to-tf.js +54 -6
  39. package/dist-sdk/src/entities/element/build.d.ts +7 -0
  40. package/dist-sdk/src/entities/element/from-tf.js +1 -1
  41. package/dist-sdk/src/entities/element/to-tf.d.ts +1 -1
  42. package/dist-sdk/src/entities/element/to-tf.js +19 -1
  43. package/dist-sdk/src/entities/field/build.d.ts +10 -1
  44. package/dist-sdk/src/entities/field/build.js +2 -1
  45. package/dist-sdk/src/entities/field/calc/index.js +7 -7
  46. package/dist-sdk/src/entities/field/calc/runtime.d.ts +19 -0
  47. package/dist-sdk/src/entities/field/calc/runtime.js +32 -0
  48. package/dist-sdk/src/entities/field/calc/types.d.ts +6 -0
  49. package/dist-sdk/src/entities/file-reader/to-tf.js +10 -2
  50. package/dist-sdk/src/entities/relationship/build.d.ts +14 -7
  51. package/dist-sdk/src/entities/relationship/from-tf.js +14 -14
  52. package/dist-sdk/src/entities/relationship/to-tf.d.ts +1 -0
  53. package/dist-sdk/src/entities/relationship/to-tf.js +18 -0
  54. package/dist-sdk/src/entities/shared/aspect-target-from-tf.d.ts +15 -0
  55. package/dist-sdk/src/entities/shared/aspect-target-from-tf.js +21 -0
  56. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +16 -4
  57. package/dist-sdk/src/entities/skill/tools.d.ts +10 -0
  58. package/dist-sdk/src/entities/skill/tools.js +10 -0
  59. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +7 -0
  60. package/dist-sdk/src/entities/skill-tool/from-tf.js +22 -2
  61. package/dist-sdk/src/entities/skill-tool/to-tf.js +21 -0
  62. package/dist-sdk/src/entities/table/catalog-render.js +2 -1
  63. package/dist-sdk/src/entities/view/from-tf.js +9 -0
  64. package/dist-sdk/src/entities/view/to-tf.d.ts +7 -0
  65. package/dist-sdk/src/entities/view/to-tf.js +34 -5
  66. package/dist-sdk/src/entities/widget/build.d.ts +17 -7
  67. package/dist-sdk/src/entities/widget/from-tf.d.ts +1 -1
  68. package/dist-sdk/src/entities/widget/from-tf.js +132 -18
  69. package/dist-sdk/src/entities/widget/to-tf.d.ts +17 -0
  70. package/dist-sdk/src/entities/widget/to-tf.js +40 -0
  71. package/dist-sdk/src/graph/types.d.ts +8 -0
  72. package/package.json +1 -1
@@ -1,7 +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
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
+ import { appResourceLabelPrefix, appScopedResourceLabel, expr, isTfExpr, isUuid, sanitizeName, scopedResourceLabel, tsLabelToTfLabel, } from "../../engine/tf/index.js";
5
5
  import { workspaceAspectKey } from "../../engine/build/context.js";
6
6
  import { SEARCH_TABLE_RESOURCE_TYPES } from "../search-table/types.js";
7
7
  import { fieldRefToTfValue } from "../field/to-tf.js";
@@ -58,6 +58,7 @@ const TRIGGER_RESOURCES = {
58
58
  approvalChain: "elementum_approval_chain_trigger",
59
59
  datamine: "elementum_datamine_trigger",
60
60
  survey: "elementum_survey_trigger",
61
+ schedule: "elementum_schedule_trigger",
61
62
  };
62
63
  /**
63
64
  * setVariable tasks share one wire key ("variable") but two distinct
@@ -564,7 +565,12 @@ function tokenToTf(value, ctx, dataBlocks) {
564
565
  }
565
566
  else {
566
567
  const tableLabel = tsLabelToTfLabel(value.parent);
567
- const tableName = value.parent;
568
+ // value.parent is the table's refName, not its display name - the
569
+ // platform's data.elementum_table lookup keys by name, so a
570
+ // catalog-carried parentName (same escape FieldRef/TableColumnRef
571
+ // already use) must win when present, or the lookup 404s with the
572
+ // camelCase refName instead of the real table name.
573
+ const tableName = typeof value.parentName === "string" && value.parentName !== "" ? value.parentName : value.parent;
568
574
  if (ctx.orgRefs !== undefined) {
569
575
  ctx.orgRefs.rawLookup(TABLE_RESOURCE_TYPE, tableLabel, tableName);
570
576
  }
@@ -882,28 +888,86 @@ function calculationFormulaRefToParts(value, refs) {
882
888
  throw new EntityTfError("calculation formula is not a trigger/task/variable ref, literal, or template");
883
889
  }
884
890
  /**
885
- * Calc-engine mustache for a prior task output. Matches the live dialect
886
- * `{{task name="<wire output>" id="<task-id>"}}` (name is the refs-map key,
887
- * not the task display name). Task id interpolates from the task resource.
891
+ * Calc-engine mustache for a prior task output:
892
+ * `{{task name="<reference name>" id="<task-id>"}}`, with the task id
893
+ * interpolated from the task resource.
894
+ *
895
+ * `name` is the WorkflowTaskReference's own name, NOT the Terraform
896
+ * `refs[…]` map key. Mobius parses this mustache itself
897
+ * (`CalcParamVisitor#visitCalculatedParameter` → `ValueReference
898
+ * .ofTaskReference(id, name)`) and then resolves the reference against the
899
+ * workflow's available refs; an unknown name throws `paramNotFound` and the
900
+ * whole task create fails with "Unable to validate". The refs-map key is a
901
+ * localized DISPLAY label from mobius' `shared.json` bundle ("Records Size",
902
+ * "Triage SLA (business days)") and never resolves here.
888
903
  */
889
- function calculationTaskMustache(taskRefKey, wireName, refs) {
890
- if (wireName.includes('"')) {
891
- throw new EntityTfError(`calculation task output name "${wireName}" contains a double quote`);
904
+ function calculationTaskMustache(taskRefKey, name, refs) {
905
+ if (name.includes('"')) {
906
+ throw new EntityTfError(`calculation task output name "${name}" contains a double quote`);
892
907
  }
893
908
  const target = refs.tasks.get(taskRefKey);
894
909
  if (target === undefined) {
895
910
  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
- }
898
- if (wireName.includes('"')) {
899
- throw new EntityTfError(`calculation task output name "${wireName}" contains a double quote`);
911
+ return [`{{task name="${name}" id="${taskRefKey}"}}`];
900
912
  }
901
913
  return [
902
- `{{task name="${wireName}" id="`,
914
+ '{{task name="',
915
+ ...calculationTaskRefName(target.type, name, taskRefKey, refs),
916
+ '" id="',
903
917
  expr.resourceAttr(target.type, target.label, ["id"]),
904
918
  `"}}`,
905
919
  ];
906
920
  }
921
+ /**
922
+ * Task-own outputs whose calc-engine reference name differs from the
923
+ * refs-map key. Keys are the display labels the refs map uses (and that
924
+ * `build.ts`'s `rewriteForwardTaskRefName` already rewrote authoring names
925
+ * into); values are the underlying reference names — captured live with
926
+ * `ei refs --from-remote` against a real record-search task, and matching
927
+ * mobius' `shared.json` `aspect_records_search` label table.
928
+ */
929
+ const CALCULATION_TASK_OUTPUT_REF_NAME = {
930
+ elementum_record_search_task: {
931
+ "Records Size": "count",
932
+ "First found record id": "recordId",
933
+ },
934
+ };
935
+ function calculationTaskRefName(targetType, name, taskRefKey, refs) {
936
+ const segments = name.split(".");
937
+ if (segments[0] === "record" && segments.length >= 2) {
938
+ const suffix = segments.slice(2).join(".");
939
+ return [
940
+ "record.",
941
+ calculationRecordFieldId(segments[1], calculationFieldScope(taskRefKey, refs)),
942
+ suffix.length > 0 ? `.${suffix}` : "",
943
+ ];
944
+ }
945
+ const refName = CALCULATION_TASK_OUTPUT_REF_NAME[targetType]?.[name] ?? name;
946
+ if (refName.includes('"')) {
947
+ throw new EntityTfError(`calculation task output name "${refName}" contains a double quote`);
948
+ }
949
+ return [refName];
950
+ }
951
+ /**
952
+ * The aspect whose fields a task's `record.<field>` output belongs to. A
953
+ * cross-aspect `recordSearch` reads the SEARCHED aspect's fields, and the
954
+ * calc engine wants their ids, so that aspect must be part of this build —
955
+ * a `data.elementum_app` stub carries display names but no field resources.
956
+ */
957
+ function calculationFieldScope(taskRefKey, refs) {
958
+ const taskApp = refs.recordFieldContext?.taskAppRefNameByRefKey?.[taskRefKey];
959
+ if (taskApp === undefined || taskApp === refs.owner.appRefName)
960
+ return refs.owner;
961
+ const fieldAddresses = refs.fieldAddressesByAppRefName?.get(taskApp);
962
+ if (fieldAddresses === undefined) {
963
+ throw new EntityTfError(`automation calculation reads a field of "${taskApp}", but that app/element is not authored in ` +
964
+ `this workspace — the calc engine addresses a found record's field by field id, which only a ` +
965
+ `built aspect can supply`);
966
+ }
967
+ const aspect = refs.owner.workspaceAspects?.get(workspaceAspectKey("app", taskApp))
968
+ ?? refs.owner.workspaceAspects?.get(workspaceAspectKey("element", taskApp));
969
+ return { appRefName: taskApp, appTfLabel: aspect?.tfLabel ?? refs.owner.appTfLabel, fieldAddresses };
970
+ }
907
971
  function calculationTriggerMustache(name, refs) {
908
972
  const parts = name.split(".");
909
973
  if (parts[0] !== "record" || parts.length < 2) {
@@ -914,22 +978,22 @@ function calculationTriggerMustache(name, refs) {
914
978
  const suffixPart = suffix.length > 0 ? `.${suffix}` : "";
915
979
  return [
916
980
  '{{trigger name="record.',
917
- calculationRecordFieldId(fieldKey, refs),
981
+ calculationRecordFieldId(fieldKey, refs.owner),
918
982
  `${suffixPart}"}}`,
919
983
  ];
920
984
  }
921
- function calculationRecordFieldId(fieldKey, refs) {
985
+ function calculationRecordFieldId(fieldKey, scope) {
922
986
  if (fieldKey.startsWith(UNRESOLVED_FIELD_MARKER))
923
987
  return fieldKey.slice(UNRESOLVED_FIELD_MARKER.length);
924
988
  if (isUuid(fieldKey))
925
989
  return fieldKey;
926
- const address = refs.owner.fieldAddresses.get(fieldKey);
990
+ const address = scope.fieldAddresses.get(fieldKey);
927
991
  if (address !== undefined)
928
992
  return addressExpr(address, ["id"]);
929
993
  if (SYSTEM_FIELD_KEY_SET.has(fieldKey)) {
930
- return expr.local(`${refs.owner.appTfLabel}_${tsLabelToTfLabel(fieldKey)}_field_id`);
994
+ return expr.local(`${scope.appTfLabel}_${tsLabelToTfLabel(fieldKey)}_field_id`);
931
995
  }
932
- throw new EntityTfError(`automation calculation targets field "${fieldKey}" which does not exist in app "${refs.owner.appRefName}"`);
996
+ throw new EntityTfError(`automation calculation targets field "${fieldKey}" which does not exist in app "${scope.appRefName}"`);
933
997
  }
934
998
  function flattenAdjacentFormulaParts(parts) {
935
999
  const out = [];
@@ -1112,6 +1176,39 @@ function taskWireRefName(name, taskRefKey, refs) {
1112
1176
  fieldNames: foreignNames ?? new Map(),
1113
1177
  });
1114
1178
  }
1179
+ /**
1180
+ * The platform refs-map key for one task output, given the emitting task's
1181
+ * resource type. Shared by `refs[…]` inputs and calculation mustaches so both
1182
+ * dialects address the same output the same way.
1183
+ *
1184
+ * aiFileAnalysis/readFile's refs are keyed by whatever arbitrary field names
1185
+ * the file reader schema itself defines (e.g. "title", "document_type") -
1186
+ * wireRefName's generic segment table (TS_REF_SEGMENT_TO_WIRE) is for a
1187
+ * DIFFERENT thing (a task's own canonical record-identity fields, e.g.
1188
+ * createRecord's generic "id"/"title"), and wrongly rewrites a reader field
1189
+ * literally named "title" into the wire key "Title", which doesn't exist in
1190
+ * these two resources' actual refs map - confirmed live via a real apply's
1191
+ * "Invalid index" error. Their field names pass through verbatim.
1192
+ */
1193
+ function taskOutputWireRefKey(targetType, name, taskRefKey, refs) {
1194
+ if (targetType === "elementum_ai_file_read_task" || targetType === "elementum_file_reader_task")
1195
+ return name;
1196
+ if (targetType === "elementum_ai_agent_task")
1197
+ return name;
1198
+ // aiSearchTable's collection is `refs["All Records"]`, not recordSearch's
1199
+ // globally-mapped `refs["All found records"]` (TS_REF_SEGMENT_TO_WIRE).
1200
+ // Accept both the authoring segment and the already-rewritten wire name
1201
+ // from rewriteForwardTaskRefName so either path emits the same key.
1202
+ if (targetType === "elementum_ai_search_table_task" && (name === "records" || name === "All Records")) {
1203
+ return "All Records";
1204
+ }
1205
+ // tableRecordsSearch uses yet another wire key: "All matching table rows".
1206
+ if (targetType === "elementum_table_records_search_task" &&
1207
+ (name === "records" || name === "All matching table rows")) {
1208
+ return "All matching table rows";
1209
+ }
1210
+ return taskWireRefName(name, taskRefKey, refs);
1211
+ }
1115
1212
  function triggerWireRefName(name, refs) {
1116
1213
  const scalarParams = refs.triggerParamNames.filter((param) => !refs.recordParamNames.includes(param));
1117
1214
  const declared = onDemandTriggerRefKey(name, scalarParams);
@@ -1230,6 +1327,32 @@ function workflowPublishOutputEnvelope(value, refs) {
1230
1327
  }
1231
1328
  if (isObject(value.variableReference)) {
1232
1329
  const id = typeof value.variableReference.id === "string" ? value.variableReference.id : undefined;
1330
+ // A freshly-authored `ctx.variables[...]` reference carries the SAME
1331
+ // randomUUID `stampAndCollectVariableIds` just minted for this build's
1332
+ // own `elementum_variable_task` create entry — that id is never the
1333
+ // variable's real (deploy-time-assigned) platform id, so baking it in as
1334
+ // a literal string here always mismatches live state on the very next
1335
+ // plan. Interpolate the live resource instead.
1336
+ //
1337
+ // `elementum_variable_task` carries TWO platform ids: `id` is the TASK's
1338
+ // id, `variable_id` is the id of the variable that task creates. A
1339
+ // publish output addresses the VARIABLE, so it must interpolate
1340
+ // `variable_id`. This differs from taskReference's `taskId:
1341
+ // expr.resourceAttr(...)` treatment just above, which does want `.id`.
1342
+ //
1343
+ // Sending the task id instead fails at the PUBLISH step
1344
+ // ("Failed to publish workflow"). The emitted shape stays
1345
+ // `{ name = "variable|<id>" }` with no sibling `id`, byte-identical to
1346
+ // ei's export — the provider recovers the id from the name when it builds
1347
+ // VariableReferenceInput (workflow_publish_resource.go).
1348
+ const target = id !== undefined ? refs.variableById.get(id) : undefined;
1349
+ if (target !== undefined) {
1350
+ return {
1351
+ taskReference: null,
1352
+ triggerReference: null,
1353
+ variableReference: { name: expr.template(["variable|", expr.resourceAttr(target.type, target.label, ["variable_id"])]) },
1354
+ };
1355
+ }
1233
1356
  const name = typeof value.variableReference.name === "string" ? value.variableReference.name : undefined;
1234
1357
  // ei export / pull shape: `variableReference = { name = "variable|<uuid>" }`
1235
1358
  // with sibling null refs — not fieldType+id. Prefer that wire form.
@@ -1316,33 +1439,7 @@ function valueToTf(value, refs) {
1316
1439
  refs.owner.diagnostics.push(`automation unresolved task ref ${JSON.stringify(value.taskReference.taskRefKey)} preserved as a literal reference`);
1317
1440
  return `{{task name="${value.taskReference.name}" id="${value.taskReference.taskRefKey}"}}`;
1318
1441
  }
1319
- // aiFileAnalysis/readFile's refs are keyed by whatever arbitrary field
1320
- // names the file reader schema itself defines (e.g. "title",
1321
- // "document_type") - wireRefName's generic segment table
1322
- // (TS_REF_SEGMENT_TO_WIRE) is for a DIFFERENT thing (a task's own
1323
- // canonical record-identity fields, e.g. createRecord's generic "id"/
1324
- // "title"), and wrongly rewrites a reader field literally named "title"
1325
- // into the wire key "Title", which doesn't exist in these two
1326
- // resources' actual refs map - confirmed live via a real apply's
1327
- // "Invalid index" error. Their field names pass through verbatim.
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";
1330
- // aiSearchTable's collection is `refs["All Records"]`, not recordSearch's
1331
- // globally-mapped `refs["All found records"]` (TS_REF_SEGMENT_TO_WIRE).
1332
- // Accept both the authoring segment and the already-rewritten wire name
1333
- // from rewriteForwardTaskRefName so either path emits the same key.
1334
- const isAiSearchTableRecords = target.type === "elementum_ai_search_table_task" &&
1335
- (value.taskReference.name === "records" || value.taskReference.name === "All Records");
1336
- // tableRecordsSearch uses yet another wire key: "All matching table rows".
1337
- const isTableRecordsSearchRecords = target.type === "elementum_table_records_search_task" &&
1338
- (value.taskReference.name === "records" || value.taskReference.name === "All matching table rows");
1339
- const refKey = isFileReaderTask || isAiAgentTask
1340
- ? value.taskReference.name
1341
- : isAiSearchTableRecords
1342
- ? "All Records"
1343
- : isTableRecordsSearchRecords
1344
- ? "All matching table rows"
1345
- : taskWireRefName(value.taskReference.name, value.taskReference.taskRefKey, refs);
1442
+ const refKey = taskOutputWireRefKey(target.type, value.taskReference.name, value.taskReference.taskRefKey, refs);
1346
1443
  return expr.resourceAttr(target.type, target.label, ["refs", { index: refKey }]);
1347
1444
  }
1348
1445
  if (isObject(value.forEachReference) && typeof value.forEachReference.forEachTaskRefKey === "string" && typeof value.forEachReference.name === "string") {
@@ -1452,6 +1549,15 @@ function filterReferenceToTf(value, refs, role = "value", realType) {
1452
1549
  if (isUuid(fieldKey)) {
1453
1550
  return `trigger.${value.name}`;
1454
1551
  }
1552
+ // unresolvedField()'s value-position escape tags the same
1553
+ // unresolvable field with UNRESOLVED_FIELD_MARKER instead of a bare
1554
+ // uuid (see wireRefName's matching check). Without this, the marker
1555
+ // fails the isUuid check above and falls through to the generic
1556
+ // `.refs[...]` lookup below, which is the wrong wire convention for
1557
+ // a filter reference and points at a refs-map key that doesn't exist.
1558
+ if (fieldKey.startsWith(UNRESOLVED_FIELD_MARKER)) {
1559
+ return `trigger.${value.name.replace(UNRESOLVED_FIELD_MARKER, "")}`;
1560
+ }
1455
1561
  }
1456
1562
  const triggerRefKey = triggerWireRefName(value.name, refs);
1457
1563
  if (refs.trigger.type === TRIGGER_RESOURCES.onDemand) {
@@ -1626,6 +1732,15 @@ function configAttrs(kind, config, refs) {
1626
1732
  for (const [key, raw] of Object.entries(config)) {
1627
1733
  if (key === "name" || key === "type" || key === "aspectId" && kind.endsWith("_trigger"))
1628
1734
  continue;
1735
+ // Authoring-only schedule envelope (rrule / dtStart). The provider HCL
1736
+ // contract owns frequency/interval/timezone/start_at/weekdays/day_of_month
1737
+ // — the same fields WorkflowScheduleTriggerInput accepts.
1738
+ if (kind === "elementum_schedule_trigger" && (key === "rrule" || key === "dtStart"))
1739
+ continue;
1740
+ // interval defaults to 1 on the provider (Optional+Computed). Omit the
1741
+ // default so build matches export's omit-when-1 convention.
1742
+ if (kind === "elementum_schedule_trigger" && key === "interval" && raw === 1)
1743
+ continue;
1629
1744
  // A config value of exactly `undefined` almost always means the
1630
1745
  // authoring builder was called with a required option omitted (e.g. a
1631
1746
  // TS-only-enforced field that no runtime actually type-checks at
@@ -2207,6 +2322,7 @@ export function automationToTf(entity, ctx) {
2207
2322
  variableById,
2208
2323
  ...(recordFieldContext !== undefined ? { recordFieldContext } : {}),
2209
2324
  ...(ctx.fieldNamesByAppRefName !== undefined ? { fieldNamesByAppRefName: ctx.fieldNamesByAppRefName } : {}),
2325
+ ...(ctx.fieldAddressesByAppRefName !== undefined ? { fieldAddressesByAppRefName: ctx.fieldAddressesByAppRefName } : {}),
2210
2326
  ...(ctx.allowUnknownPicklistOptions === true ? { allowUnknownPicklistOptions: true } : {}),
2211
2327
  };
2212
2328
  let triggerAttrs;
@@ -2415,7 +2531,7 @@ export function automationToTf(entity, ctx) {
2415
2531
  // (a default branch renamed "Default Path" exports as
2416
2532
  // "..._default_path", not a hardcoded "..._default") - confirmed live.
2417
2533
  const fallbackLabel = isDefault ? "default" : `branch_${index + 1}`;
2418
- const branchLabel = `${tfLabel}_${snakeSlug(child.label ?? child.defaultLabel ?? fallbackLabel)}`;
2534
+ const branchLabel = `${tfLabel}_${sanitizeName(child.label ?? child.defaultLabel ?? fallbackLabel)}`;
2419
2535
  const branchAttrs = {
2420
2536
  [wireType === "switch" ? "switch_task" : "fork_join_task"]: address,
2421
2537
  ...(isDefault
@@ -35,6 +35,7 @@ export const TRIGGER_SUB_TYPES = [
35
35
  { typeKey: "conversationEnd", resourceType: "elementum_agent_conversation_ended_trigger", implemented: true },
36
36
  { typeKey: "slackMessage", resourceType: "elementum_slack_message_trigger", implemented: true },
37
37
  { typeKey: "survey", resourceType: "elementum_survey_trigger", implemented: true },
38
+ { typeKey: "schedule", resourceType: "elementum_schedule_trigger", implemented: true },
38
39
  ];
39
40
  /**
40
41
  * Task kinds. All rows are implemented as of `aiFileAnalysis` (the last
@@ -7,6 +7,7 @@ import { DASHBOARD_WIDGET_RESOURCE_TYPE } from "../dashboard-widget/module.js";
7
7
  import { DASHBOARD_RESOURCE_TYPE } from "./module.js";
8
8
  import { CHART_RESOURCE_TYPE } from "../chart/types.js";
9
9
  import { dashboardWidgetSize } from "./build.js";
10
+ import { resolveDataAspectTarget } from "../shared/aspect-target-from-tf.js";
10
11
  const KNOWN_DASHBOARD_ATTRS = new Set(["name", "owner_id", "owner_type", "favorite", "tags"]);
11
12
  export function dashboardsFromTf(blocks, widgetBlocks, owner, ctx) {
12
13
  const dashboards = [];
@@ -93,8 +94,16 @@ function aspectRef(value, owner, ctx) {
93
94
  if (resourceLabel !== undefined)
94
95
  return { kind, key: tfLabelToTsLabel(resourceLabel), name: tfLabelToTsLabel(resourceLabel) };
95
96
  const dataLabel = dataRefLabel(value, type);
96
- if (dataLabel !== undefined)
97
- return { kind, key: tfLabelToTsLabel(dataLabel), name: ctx.dataName(type, dataLabel) ?? tfLabelToTsLabel(dataLabel) };
97
+ if (dataLabel !== undefined) {
98
+ // Same namespace-only foreign-target shape widget/from-tf.ts resolves
99
+ // via the shared helper - a guessed tfLabel-derived name matches
100
+ // nothing on the platform and breaks elementum build/plan.
101
+ // printDashboardTargetRef always emits appRef()/elementRef() regardless
102
+ // of provenance, so catalogRef (widget's raw-literal-vs-factory-call
103
+ // switch) has no printer to gate here - only key/name/namespace matter.
104
+ const resolved = resolveDataAspectTarget(ctx, kind, dataLabel);
105
+ return { kind, key: resolved.key, name: resolved.name, ...(resolved.namespace !== undefined ? { namespace: resolved.namespace } : {}) };
106
+ }
98
107
  }
99
108
  return undefined;
100
109
  }
@@ -37,6 +37,8 @@ export interface DashboardToTfOptions {
37
37
  readonly ownerResourceType?: "elementum_app" | "elementum_element";
38
38
  readonly orgRefs?: OrgRefLookup;
39
39
  readonly workspaceAspects?: ReadonlyMap<string, WorkspaceAspect>;
40
+ /** Chart files actually present for this owner in the current workspace build. */
41
+ readonly availableChartRefNames?: ReadonlySet<string>;
40
42
  readonly diagnostics: string[];
41
43
  }
42
44
  export declare function dashboardsToTf(dashboards: Readonly<Record<string, AppDashboardWire>> | undefined, opts: DashboardToTfOptions): TfBlock[];
@@ -98,6 +98,10 @@ function resolveChart(value, where, opts) {
98
98
  opts.diagnostics.push(`${where}: chart belongs to ${JSON.stringify(value.parent)}, not dashboard owner ${JSON.stringify(opts.ownerRefName)}; dropped`);
99
99
  return undefined;
100
100
  }
101
+ if (opts.availableChartRefNames !== undefined && !opts.availableChartRefNames.has(refName)) {
102
+ opts.diagnostics.push(`${where}: chart ref ${JSON.stringify(refName)} has no available chart resource; dropped`);
103
+ return undefined;
104
+ }
101
105
  return expr.resourceAttr(CHART_RESOURCE_TYPE, scopedResourceLabel(opts.ownerTfLabel, tsLabelToTfLabel(refName), opts.scope), ["id"]);
102
106
  }
103
107
  function resolveAspect(value, where, opts) {
@@ -1,4 +1,4 @@
1
- import { optionalString, plainObject, resourceRefLabel } from "../../engine/pull/context.js";
1
+ import { dataRefLabel, optionalString, plainObject, resourceRefLabel } from "../../engine/pull/context.js";
2
2
  import { reportUnknownAttrs } from "../../engine/pull/attrs.js";
3
3
  import { EntityTfError } from "../../engine/entity.js";
4
4
  import { isTfExpr, tfLabelToTsLabel } from "../../engine/tf/index.js";
@@ -71,7 +71,7 @@ export function tableDataminesFromTf(blocks, tableTfLabel, columnKeyByName, ctx,
71
71
  field: (value) => ({
72
72
  kind: "tableColumn",
73
73
  tableRefName: tfLabelToTsLabel(tableTfLabel),
74
- columnRefName: tableColumnKey(value, tableTfLabel, columnKeyByName, columnKeyById, where),
74
+ columnRefName: tableColumnKey(value, tableTfLabel, columnKeyByName, columnKeyById, ctx, where),
75
75
  }),
76
76
  reference: () => { throw new EntityTfError(`${where}.filter: datamine filters do not support reference values`); },
77
77
  }),
@@ -81,7 +81,7 @@ export function tableDataminesFromTf(blocks, tableTfLabel, columnKeyByName, ctx,
81
81
  }];
82
82
  });
83
83
  }
84
- function tableColumnKey(value, tableTfLabel, columnKeyByName, columnKeyById, where) {
84
+ function tableColumnKey(value, tableTfLabel, columnKeyByName, columnKeyById, ctx, where) {
85
85
  if (typeof value === "string") {
86
86
  return columnKeyById.get(value) ?? columnKeyByName.get(value) ?? value;
87
87
  }
@@ -94,5 +94,25 @@ function tableColumnKey(value, tableTfLabel, columnKeyByName, columnKeyById, whe
94
94
  if (key !== undefined)
95
95
  return key;
96
96
  }
97
+ const fieldLabel = dataRefLabel(value, "elementum_field");
98
+ if (fieldLabel !== undefined) {
99
+ const attrs = ctx.dataAttrs?.("elementum_field", fieldLabel);
100
+ if (attrs === undefined) {
101
+ throw new EntityTfError(`${where}.filter: data.elementum_field.${fieldLabel} has no matching data block`);
102
+ }
103
+ const ownerLabel = resourceRefLabel(attrs["object_id"], "elementum_table")
104
+ ?? dataRefLabel(attrs["object_id"], "elementum_table");
105
+ if (ownerLabel !== tableTfLabel) {
106
+ throw new EntityTfError(`${where}.filter: data.elementum_field.${fieldLabel}.object_id does not reference elementum_table.${tableTfLabel}`);
107
+ }
108
+ const name = attrs["name"];
109
+ if (typeof name !== "string" || name === "") {
110
+ throw new EntityTfError(`${where}.filter: data.elementum_field.${fieldLabel}.name has no string name`);
111
+ }
112
+ const key = columnKeyByName.get(name);
113
+ if (key !== undefined)
114
+ return key;
115
+ throw new EntityTfError(`${where}.filter: data.elementum_field.${fieldLabel}.name does not resolve to a column on elementum_table.${tableTfLabel}`);
116
+ }
97
117
  throw new EntityTfError(`${where}.filter: field does not resolve to a column on this table`);
98
118
  }
@@ -1,4 +1,4 @@
1
- import type { AppOrElementRef, AutomationRef } from "../../catalog/index.js";
1
+ import type { AgentRef, AppOrElementRef, AutomationRef } from "../../catalog/index.js";
2
2
  import type { AppViewFieldRef } from "../app/build.js";
3
3
  export type DynamicLayoutTypedValue = {
4
4
  readonly string: string;
@@ -78,6 +78,7 @@ export interface DynamicLayoutComponentVariantMap {
78
78
  readonly icon?: string;
79
79
  readonly color?: string;
80
80
  readonly collapsible?: boolean;
81
+ readonly agent?: AgentRef;
81
82
  readonly defaultCollapsed?: boolean;
82
83
  readonly hidden?: boolean;
83
84
  readonly className?: string;
@@ -2,3 +2,11 @@ export declare const DYNAMIC_LAYOUT_FIELD_COMPONENT_WIRE_KEY_BY_PUBLIC_KEY: Read
2
2
  export declare const DYNAMIC_LAYOUT_FIELD_COMPONENT_KEYS: ReadonlySet<string>;
3
3
  export declare function dynamicLayoutFieldComponentWireKey(publicKey: string): string;
4
4
  export declare const DYNAMIC_LAYOUT_COMPARISON_KEYS: ReadonlySet<string>;
5
+ /**
6
+ * Dynamic-layout automation buttons are runnable only after a parameterless
7
+ * run-automation display widget exists for the selected automation. App Admin
8
+ * creates that widget as a save side effect; EDK emits an explicit companion
9
+ * resource instead so OpenTofu owns the complete contract.
10
+ */
11
+ export declare const DYNAMIC_LAYOUT_ACTION_WIDGET_NAME_PREFIX = "EDK dynamic layout action ";
12
+ export declare function dynamicLayoutActionWidgetName(layoutKey: string, componentId: string): string;
@@ -1,3 +1,4 @@
1
+ import { splitCamelCase } from "../../engine/tf/labels.js";
1
2
  /**
2
3
  * Public field-component keys are listed exhaustively against the authoring
3
4
  * variant map. Adding a field component there without adding it here is a
@@ -45,3 +46,14 @@ export const DYNAMIC_LAYOUT_COMPARISON_KEYS = new Set([
45
46
  "equals", "notEquals", "greaterThan", "greaterThanOrEqual", "lessThan", "lessThanOrEqual",
46
47
  "contains", "notContains", "in", "notIn", "empty", "notEmpty",
47
48
  ]);
49
+ /**
50
+ * Dynamic-layout automation buttons are runnable only after a parameterless
51
+ * run-automation display widget exists for the selected automation. App Admin
52
+ * creates that widget as a save side effect; EDK emits an explicit companion
53
+ * resource instead so OpenTofu owns the complete contract.
54
+ */
55
+ export const DYNAMIC_LAYOUT_ACTION_WIDGET_NAME_PREFIX = "EDK dynamic layout action ";
56
+ export function dynamicLayoutActionWidgetName(layoutKey, componentId) {
57
+ const words = (value) => splitCamelCase(value.replace(/[_-]+/g, " ")).toLowerCase();
58
+ return `${DYNAMIC_LAYOUT_ACTION_WIDGET_NAME_PREFIX}${words(layoutKey)} ${words(componentId)}`;
59
+ }
@@ -8,3 +8,10 @@ export interface DynamicLayoutOwner {
8
8
  readonly ownerTfLabel: string;
9
9
  }
10
10
  export declare function dynamicLayoutsFromTf(blocks: readonly TfBlock[], owner: DynamicLayoutOwner, ctx: FromTfContext): NormalizedDynamicLayout[];
11
+ /**
12
+ * Widget resource labels referenced by dynamic-layout automation buttons.
13
+ * The label is the companion widget's stable Terraform identity; its display
14
+ * name is mutable and cannot safely distinguish generated from authored
15
+ * widgets during pull.
16
+ */
17
+ export declare function dynamicLayoutCompanionWidgetLabels(blocks: readonly TfBlock[]): ReadonlySet<string>;
@@ -1,6 +1,8 @@
1
1
  import { dataRefLabel, optionalString, plainObject, resourceRefLabel } from "../../engine/pull/context.js";
2
2
  import { isTfExpr, scopedLabelToBagKey, tfLabelToTsLabel, } from "../../engine/tf/index.js";
3
3
  import { fieldKeyFromTfRef } from "../field/from-tf.js";
4
+ import { resolveDataAspectTarget } from "../shared/aspect-target-from-tf.js";
5
+ import { WIDGET_RESOURCE_TYPE } from "../widget/module.js";
4
6
  import { DYNAMIC_LAYOUT_RESOURCE_TYPE } from "./module.js";
5
7
  import { DYNAMIC_LAYOUT_COMPARISON_KEYS, DYNAMIC_LAYOUT_FIELD_COMPONENT_WIRE_KEY_BY_PUBLIC_KEY, } from "./dialect.js";
6
8
  const KNOWN_ATTRS = new Set([
@@ -17,6 +19,30 @@ export function dynamicLayoutsFromTf(blocks, owner, ctx) {
17
19
  }
18
20
  return out;
19
21
  }
22
+ /**
23
+ * Widget resource labels referenced by dynamic-layout automation buttons.
24
+ * The label is the companion widget's stable Terraform identity; its display
25
+ * name is mutable and cannot safely distinguish generated from authored
26
+ * widgets during pull.
27
+ */
28
+ export function dynamicLayoutCompanionWidgetLabels(blocks) {
29
+ const labels = new Set();
30
+ for (const block of blocks) {
31
+ const components = plainObject(block.attrs["components"]);
32
+ if (components === undefined)
33
+ continue;
34
+ for (const raw of Object.values(components)) {
35
+ const component = plainObject(raw);
36
+ const button = component === undefined ? undefined : plainObject(component["automation_button"]);
37
+ const label = button === undefined
38
+ ? undefined
39
+ : resourceRefLabel(button["widget_id"], WIDGET_RESOURCE_TYPE);
40
+ if (label !== undefined)
41
+ labels.add(label);
42
+ }
43
+ }
44
+ return labels;
45
+ }
20
46
  function dynamicLayoutFromTf(block, owner, ctx) {
21
47
  const where = `${DYNAMIC_LAYOUT_RESOURCE_TYPE}.${block.label ?? "?"}`;
22
48
  for (const key of Object.keys(block.attrs)) {
@@ -91,15 +117,30 @@ function componentMap(values, owner, ctx, where) {
91
117
  });
92
118
  delete update["fieldIds"];
93
119
  }
94
- const automation = plainUnknownObject(component["automationButton"]);
95
- if (automation !== undefined && automation["automationId"] !== undefined) {
96
- const label = resourceRefLabel(automation["automationId"], "elementum_automation");
120
+ const section = plainUnknownObject(component["section"]);
121
+ if (section !== undefined && section["agentId"] !== undefined) {
122
+ const label = resourceRefLabel(section["agentId"], "elementum_agent");
97
123
  if (label !== undefined) {
98
- automation["automation"] = pulledRef("automation", scopedLabelToBagKey(owner.ownerTfLabel, label, "app"), owner.ownerRefName);
124
+ section["agent"] = pulledRef("agent", scopedLabelToBagKey(owner.ownerTfLabel, label, "app"), owner.ownerRefName);
99
125
  }
100
126
  else
101
- ctx.diagnostics.push(`${where}.components.${id}.automationButton: automation_id is not a managed automation ref; dropped`);
102
- delete automation["automationId"];
127
+ ctx.diagnostics.push(`${where}.components.${id}.section: agent_id is not a managed agent ref; dropped`);
128
+ delete section["agentId"];
129
+ }
130
+ const automation = plainUnknownObject(component["automationButton"]);
131
+ if (automation !== undefined) {
132
+ // Build derives the backing widget from the component itself, so the
133
+ // binding is never authored and must not be printed back into source.
134
+ delete automation["widgetId"];
135
+ if (automation["automationId"] !== undefined) {
136
+ const label = resourceRefLabel(automation["automationId"], "elementum_automation");
137
+ if (label !== undefined) {
138
+ automation["automation"] = pulledRef("automation", scopedLabelToBagKey(owner.ownerTfLabel, label, "app"), owner.ownerRefName);
139
+ }
140
+ else
141
+ ctx.diagnostics.push(`${where}.components.${id}.automationButton: automation_id is not a managed automation ref; dropped`);
142
+ delete automation["automationId"];
143
+ }
103
144
  }
104
145
  const create = plainUnknownObject(component["createButton"]);
105
146
  if (create !== undefined && create["targetAspectId"] !== undefined) {
@@ -208,13 +249,26 @@ function aspectRef(value, owner, ctx) {
208
249
  if (resourceLabel !== undefined)
209
250
  return pulledRef(kind, tfLabelToTsLabel(resourceLabel));
210
251
  const dataLabel = dataRefLabel(value, type);
211
- if (dataLabel !== undefined)
212
- return pulledRef(kind, tfLabelToTsLabel(dataLabel), undefined, ctx.dataName(type, dataLabel));
252
+ if (dataLabel !== undefined) {
253
+ // Same namespace-only foreign-target shape widget/from-tf.ts and
254
+ // dashboard/from-tf.ts resolve via the shared helper - a guessed
255
+ // tfLabel-derived name matches nothing on the platform and breaks
256
+ // elementum build/plan. No printer-side catalogRef distinction here
257
+ // (unlike widget), so only key/name/namespace are carried through.
258
+ const resolved = resolveDataAspectTarget(ctx, kind, dataLabel);
259
+ return pulledRef(kind, resolved.key, undefined, resolved.name, resolved.namespace);
260
+ }
213
261
  }
214
262
  return undefined;
215
263
  }
216
- function pulledRef(kind, key, parent, name) {
217
- return { __pulledRef: kind, key, ...(parent !== undefined && { parent }), ...(name !== undefined && { name }) };
264
+ function pulledRef(kind, key, parent, name, namespace) {
265
+ return {
266
+ __pulledRef: kind,
267
+ key,
268
+ ...(parent !== undefined && { parent }),
269
+ ...(name !== undefined && { name }),
270
+ ...(namespace !== undefined && { namespace }),
271
+ };
218
272
  }
219
273
  function camelObject(value) {
220
274
  const out = {};