@elementumai/edk 0.13.0 → 0.13.2

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 (101) hide show
  1. package/README.md +6 -2
  2. package/dist-sdk/src/catalog/factories.js +8 -2
  3. package/dist-sdk/src/catalog/types.d.ts +5 -0
  4. package/dist-sdk/src/engine/coverage-gaps.d.ts +12 -0
  5. package/dist-sdk/src/engine/coverage-gaps.js +23 -0
  6. package/dist-sdk/src/engine/ei/run.d.ts +8 -0
  7. package/dist-sdk/src/engine/ei/run.js +46 -7
  8. package/dist-sdk/src/engine/progress.d.ts +1 -0
  9. package/dist-sdk/src/engine/progress.js +6 -0
  10. package/dist-sdk/src/engine/pull/context.d.ts +24 -0
  11. package/dist-sdk/src/engine/pull/result-output.d.ts +2 -0
  12. package/dist-sdk/src/engine/pull/result-output.js +1 -1
  13. package/dist-sdk/src/engine/pull/stream-root.d.ts +11 -0
  14. package/dist-sdk/src/engine/pull/stream-root.js +22 -6
  15. package/dist-sdk/src/engine/tf/escape.d.ts +8 -3
  16. package/dist-sdk/src/engine/tf/escape.js +17 -4
  17. package/dist-sdk/src/engine/workspace/authoring-layout.js +16 -2
  18. package/dist-sdk/src/entities/access-policy/from-tf.js +4 -7
  19. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +2 -1
  20. package/dist-sdk/src/entities/agent/from-tf.d.ts +2 -0
  21. package/dist-sdk/src/entities/agent/from-tf.js +28 -1
  22. package/dist-sdk/src/entities/agent/module.js +1 -0
  23. package/dist-sdk/src/entities/agent/to-tf.d.ts +3 -1
  24. package/dist-sdk/src/entities/agent/to-tf.js +21 -3
  25. package/dist-sdk/src/entities/app/from-tf.d.ts +1 -0
  26. package/dist-sdk/src/entities/app/from-tf.js +6 -23
  27. package/dist-sdk/src/entities/app/index.d.ts +1 -1
  28. package/dist-sdk/src/entities/app/module.js +2 -0
  29. package/dist-sdk/src/entities/approval-chain/from-tf.js +2 -2
  30. package/dist-sdk/src/entities/automation/build.d.ts +10 -1
  31. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +1 -0
  32. package/dist-sdk/src/entities/automation/from-tf.js +72 -11
  33. package/dist-sdk/src/entities/automation/index.d.ts +1 -1
  34. package/dist-sdk/src/entities/automation/module.js +12 -0
  35. package/dist-sdk/src/entities/automation/system-ref-name.d.ts +23 -3
  36. package/dist-sdk/src/entities/automation/system-ref-name.js +86 -4
  37. package/dist-sdk/src/entities/automation/to-tf.d.ts +5 -1
  38. package/dist-sdk/src/entities/automation/to-tf.js +312 -51
  39. package/dist-sdk/src/entities/automation/triggers.d.ts +5 -1
  40. package/dist-sdk/src/entities/automation/workflow-output.d.ts +7 -0
  41. package/dist-sdk/src/entities/automation/workflow-output.js +8 -0
  42. package/dist-sdk/src/entities/dashboard/from-tf.d.ts +3 -1
  43. package/dist-sdk/src/entities/dashboard/from-tf.js +42 -2
  44. package/dist-sdk/src/entities/dashboard/to-tf.js +9 -1
  45. package/dist-sdk/src/entities/dashboard-widget-order/module.d.ts +10 -0
  46. package/dist-sdk/src/entities/dashboard-widget-order/module.js +25 -0
  47. package/dist-sdk/src/entities/dashboard-widget-order/order.d.ts +31 -0
  48. package/dist-sdk/src/entities/dashboard-widget-order/order.js +102 -0
  49. package/dist-sdk/src/entities/dynamic-layout/lint.d.ts +7 -0
  50. package/dist-sdk/src/entities/dynamic-layout/lint.js +48 -0
  51. package/dist-sdk/src/entities/dynamic-layout/to-tf.js +2 -0
  52. package/dist-sdk/src/entities/element/from-tf.d.ts +1 -0
  53. package/dist-sdk/src/entities/element/from-tf.js +5 -21
  54. package/dist-sdk/src/entities/element/index.d.ts +1 -1
  55. package/dist-sdk/src/entities/element/module.js +2 -0
  56. package/dist-sdk/src/entities/element/to-tf.js +1 -0
  57. package/dist-sdk/src/entities/field/from-tf.d.ts +25 -2
  58. package/dist-sdk/src/entities/field/from-tf.js +119 -14
  59. package/dist-sdk/src/entities/relationship/from-tf.js +2 -2
  60. package/dist-sdk/src/entities/role/build.d.ts +3 -4
  61. package/dist-sdk/src/entities/search-table/build.d.ts +9 -3
  62. package/dist-sdk/src/entities/search-table/build.js +4 -4
  63. package/dist-sdk/src/entities/search-table/printer.js +3 -1
  64. package/dist-sdk/src/entities/search-table/to-tf.js +20 -2
  65. package/dist-sdk/src/entities/shared/context.d.ts +14 -1
  66. package/dist-sdk/src/entities/shared/filters/index.d.ts +24 -13
  67. package/dist-sdk/src/entities/shared/filters/index.js +12 -1
  68. package/dist-sdk/src/entities/shared/filters/print.d.ts +2 -0
  69. package/dist-sdk/src/entities/shared/filters/print.js +15 -6
  70. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +4 -0
  71. package/dist-sdk/src/entities/shared/filters/tf-codec.js +16 -0
  72. package/dist-sdk/src/entities/shared/filters/types.d.ts +4 -0
  73. package/dist-sdk/src/entities/shared/tool-field-ref.d.ts +1 -1
  74. package/dist-sdk/src/entities/shared/tool-field-ref.js +2 -5
  75. package/dist-sdk/src/entities/task/from-tf.js +3 -3
  76. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.d.ts +3 -3
  77. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.js +6 -4
  78. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.d.ts +4 -2
  79. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.js +6 -1
  80. package/dist-sdk/src/entities/view/agent-view-layout.d.ts +14 -2
  81. package/dist-sdk/src/entities/view/custom-view-references.d.ts +33 -0
  82. package/dist-sdk/src/entities/view/custom-view-references.js +140 -0
  83. package/dist-sdk/src/entities/view/custom-view-validate.d.ts +16 -9
  84. package/dist-sdk/src/entities/view/custom-view-validate.js +38 -18
  85. package/dist-sdk/src/entities/view/from-tf.js +9 -0
  86. package/dist-sdk/src/entities/view/layout-lint.d.ts +26 -0
  87. package/dist-sdk/src/entities/view/layout-lint.js +50 -0
  88. package/dist-sdk/src/entities/view/to-tf.d.ts +2 -0
  89. package/dist-sdk/src/entities/view/to-tf.js +69 -47
  90. package/dist-sdk/src/entities/visual-flow/build.d.ts +8 -1
  91. package/dist-sdk/src/entities/visual-flow/from-tf.js +16 -0
  92. package/dist-sdk/src/entities/visual-flow/initiate.d.ts +12 -0
  93. package/dist-sdk/src/entities/visual-flow/initiate.js +12 -0
  94. package/dist-sdk/src/entities/visual-flow/module.js +52 -1
  95. package/dist-sdk/src/entities/visual-flow/to-tf.js +16 -2
  96. package/dist-sdk/src/entities/widget/from-tf.js +6 -6
  97. package/dist-sdk/src/graph/index.d.ts +4 -0
  98. package/dist-sdk/src/graph/index.js +1 -0
  99. package/dist-sdk/src/graph/modules.js +2 -0
  100. package/dist-sdk/src/graph/types.d.ts +36 -1
  101. package/package.json +2 -2
@@ -10,11 +10,12 @@
10
10
  * with the same `EntityTfError` path used by access-policy row filters.
11
11
  */
12
12
  import { agentViewLayoutToTf, viewBlocksToTf } from "./agent-view-layout-to-tf.js";
13
- import { expr, isCanonicalTsLabel, scopedResourceLabel, tsLabelToTfLabel, } from "../../engine/tf/index.js";
13
+ import { expr, isCanonicalTsLabel, isTfLabel, scopedResourceLabel, tfLabelToTsLabel, tsLabelToTfLabel, } from "../../engine/tf/index.js";
14
14
  import { fieldRefToTfValue as customFieldRefToTfValue } from "../field/to-tf.js";
15
15
  import { ELEMENT_SYSTEM_FIELD_KEYS } from "../element/system-fields.js";
16
16
  import { filterToTf, principalListToTf } from "../access-policy/to-tf.js";
17
17
  import { EntityTfError } from "../../engine/entity.js";
18
+ import { lintClassicLayout } from "./layout-lint.js";
18
19
  import { SUB_TYPE_BY_AUTHORING_TYPE } from "../field/types.js";
19
20
  import { DASHBOARD_RESOURCE_TYPE } from "../dashboard/module.js";
20
21
  import { WIDGET_RESOURCE_TYPE } from "../widget/module.js";
@@ -41,16 +42,22 @@ export function viewToTf(layouts, listViews, calendarViews, kanbanViews, dashboa
41
42
  const { ownerRefName, ownerTfLabel, scope = "app", objectId, diagnostics, fieldAddresses } = opts;
42
43
  const principalCtx = { ...opts, scope, objectId };
43
44
  const blocks = [];
45
+ // A layout key that names no stage fails the build: dropping the layout
46
+ // would plan the deletion of a live one (#2894).
47
+ const validLayoutKeys = () => opts.stageTfLabels === undefined
48
+ ? ""
49
+ : ` Use one of: ${[...new Set([...opts.stageTfLabels].filter(isTfLabel).map(tfLabelToTsLabel))].sort().join(", ")}.`;
44
50
  for (const [stageKey, layout] of Object.entries(layouts ?? {})) {
45
51
  if (!isCanonicalTsLabel(stageKey)) {
46
- diagnostics.push(`layouts key "${stageKey}" is not a canonical tsLabel (see src/engine/tf/labels.ts) — rename the key`);
47
- continue;
52
+ throw new EntityTfError(opts.stageTfLabels === undefined
53
+ ? `${ownerRefName}: layouts key "${stageKey}" is not a valid key (keys are camelCase, with "_" before a digit; see src/engine/tf/labels.ts)`
54
+ : `${ownerRefName}: layouts key "${stageKey}" is not a stage key: a stage key is the stage's name in camelCase, with "_" before a digit (see src/engine/tf/labels.ts).${validLayoutKeys()}`);
48
55
  }
49
56
  const stageTfLabel = tsLabelToTfLabel(stageKey);
50
57
  if (opts.stageTfLabels !== undefined && !opts.stageTfLabels.has(stageTfLabel)) {
51
- diagnostics.push(`layouts.${stageKey} has no matching authored stage option; dropped`);
52
- continue;
58
+ throw new EntityTfError(`${ownerRefName}: layouts.${stageKey} matches none of its stages.${validLayoutKeys()}`);
53
59
  }
60
+ lintClassicLayout(`layouts.${stageKey}`, layout, diagnostics);
54
61
  blocks.push(layoutToTf(stageKey, layout, ownerRefName, ownerTfLabel, scope, objectId, diagnostics, fieldAddresses, opts.widgets, opts.stageKeyByTfLabel?.get(stageTfLabel)));
55
62
  }
56
63
  if (opts.deleteDefaultListView === true) {
@@ -236,6 +243,9 @@ export function viewToTf(layouts, listViews, calendarViews, kanbanViews, dashboa
236
243
  blocks.push({ kind: "resource", type: AGENT_VIEW_RESOURCE_TYPE, label: tfLabel, attrs });
237
244
  viewAddressByKey.set(viewKey, { type: AGENT_VIEW_RESOURCE_TYPE, label: tfLabel });
238
245
  }
246
+ // Every custom view's problems (layout, filter, sort, sharing) are reported
247
+ // together, not only the first failing view's (edk#2923).
248
+ const customViewProblems = [];
239
249
  for (const [viewKey, view] of Object.entries(customViews ?? {})) {
240
250
  const where = `customViews.${viewKey}`;
241
251
  if (!isCanonicalTsLabel(viewKey)) {
@@ -246,52 +256,64 @@ export function viewToTf(layouts, listViews, calendarViews, kanbanViews, dashboa
246
256
  diagnostics.push(`${where} collides with another view key; dropped`);
247
257
  continue;
248
258
  }
249
- const tfLabel = scopedResourceLabel(ownerTfLabel, tsLabelToTfLabel(viewKey), scope);
250
- const attrs = {
251
- aspect_id: objectId,
252
- name: view.name ?? "",
253
- allow_record_creation: view.allowRecordCreation ?? true,
254
- };
255
- if (view.agent !== undefined) {
256
- const agentRefName = view.agent.refName ?? "";
257
- if (agentRefName === "" || view.agent.parent !== ownerRefName) {
258
- // Dropping only the agent would detach it on apply; keep the whole view out instead.
259
- diagnostics.push(`${where}.agent must be an agent of this ${scope === "element" ? "element" : "app"}; dropped`);
260
- continue;
259
+ try {
260
+ const tfLabel = scopedResourceLabel(ownerTfLabel, tsLabelToTfLabel(viewKey), scope);
261
+ const attrs = {
262
+ aspect_id: objectId,
263
+ name: view.name ?? "",
264
+ allow_record_creation: view.allowRecordCreation ?? true,
265
+ };
266
+ if (view.agent !== undefined) {
267
+ const agentRefName = view.agent.refName ?? "";
268
+ if (agentRefName === "" || view.agent.parent !== ownerRefName) {
269
+ // Dropping only the agent would detach it on apply; keep the whole view out instead.
270
+ diagnostics.push(`${where}.agent must be an agent of this ${scope === "element" ? "element" : "app"}; dropped`);
271
+ continue;
272
+ }
273
+ attrs["agent_id"] = expr.resourceAttr("elementum_agent", scopedResourceLabel(ownerTfLabel, tsLabelToTfLabel(agentRefName), scope), ["id"]);
261
274
  }
262
- attrs["agent_id"] = expr.resourceAttr("elementum_agent", scopedResourceLabel(ownerTfLabel, tsLabelToTfLabel(agentRefName), scope), ["id"]);
263
- }
264
- if (view.filter !== undefined)
265
- attrs["filter"] = filterToTf(view.filter, `${where}.filter`, { ownerTfLabel, appRefName: ownerRefName, scope, objectId, diagnostics, resolvePicklistLiterals: false, fieldAddresses });
266
- if (view.sort !== undefined)
267
- attrs["sort"] = managedViewSortToTf(view.sort, ownerTfLabel, scope, `${where}.sort`, diagnostics, fieldAddresses);
268
- appendViewSharingAttrs(attrs, view, where, principalCtx);
269
- if (view.displayOrder !== undefined)
270
- attrs["display_order"] = view.displayOrder;
271
- if (view.layout !== undefined) {
272
- attrs["layout"] = expr.jsonencode(viewBlocksToTf(view.layout, `${where}.layout`, {
273
- ownerRefName,
274
- ownerKind: scope === "element" ? "element" : "app",
275
- ownerTfLabel,
276
- scope,
277
- objectId,
278
- diagnostics,
279
- fieldAddresses,
280
- fieldNames: opts.fieldNames,
281
- fieldMetadata: opts.fieldMetadata,
282
- orgRefs: opts.orgRefs,
283
- workspaceAspects: opts.workspaceAspects,
284
- resolveField: (ref, fieldWhere) => fieldRefToTfValue(ref, ownerTfLabel, scope, fieldWhere, diagnostics, fieldAddresses),
285
- }, { editorPolicy: false, strictStructure: true }));
275
+ if (view.filter !== undefined)
276
+ attrs["filter"] = filterToTf(view.filter, `${where}.filter`, { ownerTfLabel, appRefName: ownerRefName, scope, objectId, diagnostics, resolvePicklistLiterals: false, fieldAddresses });
277
+ if (view.sort !== undefined)
278
+ attrs["sort"] = managedViewSortToTf(view.sort, ownerTfLabel, scope, `${where}.sort`, diagnostics, fieldAddresses);
279
+ appendViewSharingAttrs(attrs, view, where, principalCtx);
280
+ if (view.displayOrder !== undefined)
281
+ attrs["display_order"] = view.displayOrder;
282
+ if (view.layout !== undefined) {
283
+ attrs["layout"] = expr.jsonencode(viewBlocksToTf(view.layout, `${where}.layout`, {
284
+ ownerRefName,
285
+ ownerKind: scope === "element" ? "element" : "app",
286
+ ...(opts.ownerAuditFields !== undefined ? { ownerAuditFields: opts.ownerAuditFields } : {}),
287
+ ownerTfLabel,
288
+ scope,
289
+ objectId,
290
+ diagnostics,
291
+ fieldAddresses,
292
+ fieldNames: opts.fieldNames,
293
+ fieldMetadata: opts.fieldMetadata,
294
+ orgRefs: opts.orgRefs,
295
+ workspaceAspects: opts.workspaceAspects,
296
+ resolveField: (ref, fieldWhere) => fieldRefToTfValue(ref, ownerTfLabel, scope, fieldWhere, diagnostics, fieldAddresses),
297
+ }, { editorPolicy: false, strictStructure: true }));
298
+ }
299
+ else {
300
+ // The page needs a layout document, and the platform rejects a blank
301
+ // one, so a view without a layout cannot be opened in the admin UI.
302
+ diagnostics.push(`${where} has no layout, so the admin UI cannot open this view ("This custom view could not be loaded"); add a layout`);
303
+ }
304
+ blocks.push({ kind: "resource", type: CUSTOM_VIEW_RESOURCE_TYPE, label: tfLabel, attrs });
305
+ viewAddressByKey.set(viewKey, { type: CUSTOM_VIEW_RESOURCE_TYPE, label: tfLabel });
286
306
  }
287
- else {
288
- // The page needs a layout document, and the platform rejects a blank
289
- // one, so a view without a layout cannot be opened in the admin UI.
290
- diagnostics.push(`${where} has no layout, so the admin UI cannot open this view ("This custom view could not be loaded"); add a layout`);
307
+ catch (err) {
308
+ if (!(err instanceof EntityTfError))
309
+ throw err;
310
+ // Codec errors (e.g. `unsupported filter type "X"`) carry no location; name the view.
311
+ const located = err.message.startsWith(`${where}.`) || err.message.startsWith(`${where}:`) || err.message.startsWith(`${where} `);
312
+ customViewProblems.push(located ? err.message : `${where}: ${err.message}`);
291
313
  }
292
- blocks.push({ kind: "resource", type: CUSTOM_VIEW_RESOURCE_TYPE, label: tfLabel, attrs });
293
- viewAddressByKey.set(viewKey, { type: CUSTOM_VIEW_RESOURCE_TYPE, label: tfLabel });
294
314
  }
315
+ if (customViewProblems.length > 0)
316
+ throw new EntityTfError(customViewProblems.join("\n"));
295
317
  if (opts.deleteDefaultListView === true && viewAddressByKey.size === 0) {
296
318
  throw new EntityTfError(`${ownerRefName}: deleteDefaultListView needs at least one declared view; without one there is no view order to apply and the "${PLATFORM_DEFAULT_LIST_VIEW_NAME}" view would stay.`);
297
319
  }
@@ -91,7 +91,14 @@ export interface VisualFlowStage {
91
91
  export type DefineVisualFlowOptions = EntityDeployOptions & {
92
92
  /** The app whose stages host this flow. Elements do not expose stages. */
93
93
  readonly app: AppCatalogRef;
94
- /** Stable stage keys map directly to the owner's authored stage keys. */
94
+ /**
95
+ * Stable stage keys map directly to the owner's authored stage keys. The key
96
+ * `initiate` is the app's Initiate stage (the first stage the platform
97
+ * creates with every app, which is not one of its authored stages), unless
98
+ * the app authors its own stage keyed `initiate` (or whose name slugs to it).
99
+ * Build always sends the Initiate stage first, as the platform lists it, so
100
+ * it may appear anywhere in this record.
101
+ */
95
102
  readonly stages: Readonly<Record<string, VisualFlowStage>>;
96
103
  };
97
104
  export interface VisualFlowConfigured {
@@ -7,6 +7,7 @@ import { DATAMINE_RESOURCE_TYPE } from "../datamine/module.js";
7
7
  import { RELATIONSHIP_RESOURCE_TYPE } from "../relationship/module.js";
8
8
  import { TABLE_RESOURCE_TYPE } from "../table/module.js";
9
9
  import { VISUAL_FLOW_RESOURCE_TYPE } from "./module.js";
10
+ import { INITIATE_STAGE_ID_ATTR, INITIATE_STAGE_KEY } from "./initiate.js";
10
11
  const KNOWN = new Set(["id", "object_id", "stages"]);
11
12
  const symbols = new Set(["SQUARE", "DIAMOND", "CIRCLE"]);
12
13
  const positions = new Set(["TOP", "RIGHT", "BOTTOM", "LEFT"]);
@@ -165,6 +166,21 @@ export function visualFlowFromTf(block, ownerType, ownerLabel, scope, ctx, stage
165
166
  if (!isTfExpr(stageId) || stageId.$expr !== "resource-attr" || stageId.type !== ownerType || stageId.label !== ownerLabel) {
166
167
  throw new EntityTfError(`${block.type}.${block.label}.stages[${index}]: stage_id must reference the owning ${scope} stage map`);
167
168
  }
169
+ const rawNodes0 = stage["nodes"];
170
+ // The platform's Initiate stage is named by its own attribute (#2987).
171
+ if (stageId.path.length === 1 && stageId.path[0] === INITIATE_STAGE_ID_ATTR) {
172
+ // Build sends the `initiate` handle to an authored stage that holds it
173
+ // (its key, or a name that slugs to it), so writing these blocks under
174
+ // `initiate` would move them to that stage, or print the key twice.
175
+ // Leave the flow unmanaged instead, like a lost stage handle (#1136).
176
+ const owner = stageHandles?.byHandle.get(INITIATE_STAGE_KEY);
177
+ if (owner !== undefined) {
178
+ throw new LostStageHandleError(`${block.type}.${block.label}.stages[${index}]: the app's Initiate stage has no handle of its own (its handle "${INITIATE_STAGE_KEY}" belongs to the app's stage "${owner}"); the flow is left unmanaged instead of binding it to "${owner}". Rename that stage so neither its key nor its name produces the handle "${INITIATE_STAGE_KEY}", then pull again (#2987)`);
179
+ }
180
+ if (!Array.isArray(rawNodes0))
181
+ throw new EntityTfError(`${block.type}.${block.label}.stages[${index}]: nodes must be a list`);
182
+ return { stage: INITIATE_STAGE_KEY, nodes: Object.fromEntries(rawNodes0.map((node, nodeIndex) => nodeFromTf(node, ownerLabel, scope, ctx, `${block.type}.${block.label}.stages[${index}].nodes[${nodeIndex}]`))) };
183
+ }
168
184
  const entry = stageId.path.find((part) => typeof part === "object" && "index" in part);
169
185
  if (entry === undefined || typeof entry !== "object")
170
186
  throw new EntityTfError(`${block.type}.${block.label}.stages[${index}]: stage_id has no stable key`);
@@ -0,0 +1,12 @@
1
+ /**
2
+ * The platform's Initiate stage (#2987). Every app gets one when it is
3
+ * created; it is not one of the app's authored `stages`, so it has no
4
+ * `stage_ids_by_key` entry. A process map names it with this stage key, and
5
+ * build points it at `elementum_app.<app>.initiate_stage_id`, unless the app
6
+ * authors its own stage keyed `initiate`, which then wins.
7
+ */
8
+ export declare const INITIATE_STAGE_KEY = "initiate";
9
+ /** The platform's display name for the Initiate stage. */
10
+ export declare const INITIATE_STAGE_NAME = "Initiate";
11
+ /** Computed `elementum_app` attribute holding the Initiate stage's id. */
12
+ export declare const INITIATE_STAGE_ID_ATTR = "initiate_stage_id";
@@ -0,0 +1,12 @@
1
+ /**
2
+ * The platform's Initiate stage (#2987). Every app gets one when it is
3
+ * created; it is not one of the app's authored `stages`, so it has no
4
+ * `stage_ids_by_key` entry. A process map names it with this stage key, and
5
+ * build points it at `elementum_app.<app>.initiate_stage_id`, unless the app
6
+ * authors its own stage keyed `initiate`, which then wins.
7
+ */
8
+ export const INITIATE_STAGE_KEY = "initiate";
9
+ /** The platform's display name for the Initiate stage. */
10
+ export const INITIATE_STAGE_NAME = "Initiate";
11
+ /** Computed `elementum_app` attribute holding the Initiate stage's id. */
12
+ export const INITIATE_STAGE_ID_ATTR = "initiate_stage_id";
@@ -1,3 +1,4 @@
1
+ import { isTfExpr, scopedLabelToBagKey } from "../../engine/tf/index.js";
1
2
  import { NO_CATALOG, NO_DATA } from "../../graph/types.js";
2
3
  import { APP_RESOURCE_TYPE } from "../app/module.js";
3
4
  import { ELEMENT_RESOURCE_TYPE } from "../element/module.js";
@@ -6,6 +7,54 @@ import { printVisualFlow } from "./printer.js";
6
7
  import { appStageKeyByHandle, LostStageHandleError, stageHandleIndexFromTfStages } from "../app/stage-keys.js";
7
8
  import { visualFlowToTf } from "./to-tf.js";
8
9
  export const VISUAL_FLOW_RESOURCE_TYPE = "elementum_flow";
10
+ /**
11
+ * Every automation or agent a flow's blocks run is a requirement of the flow:
12
+ * when pull leaves it out, the printed flow would point at something that
13
+ * isn't in source and fail to load. The flow is then left out and released
14
+ * from state like it, rather than destroyed (#2892).
15
+ */
16
+ function requireFlowAutomations(block, refName, ctx) {
17
+ if (block.type === undefined || block.label === undefined)
18
+ return;
19
+ const address = `${block.type}.${block.label}`;
20
+ const seen = new Set();
21
+ for (const stage of listOf(block.attrs["stages"])) {
22
+ for (const node of listOf(objectOf(stage)?.["nodes"])) {
23
+ const action = objectOf(objectOf(node)?.["action"]);
24
+ for (const [kind, attr, type] of RUN_ACTIONS) {
25
+ const target = objectOf(action?.[kind])?.[attr];
26
+ if (target === undefined || !isTfExpr(target) || target.$expr !== "resource-attr" || target.type !== type)
27
+ continue;
28
+ const requires = `${target.type}.${target.label}`;
29
+ if (seen.has(requires))
30
+ continue;
31
+ seen.add(requires);
32
+ ctx.requiresExtracted?.push({
33
+ address,
34
+ requires,
35
+ requiresOwnFile: { kind, refName: scopedLabelToBagKey(ctx.appTfLabel, target.label) },
36
+ prune: (root) => root,
37
+ pruneOwnFile: {
38
+ kind: "visual-flow",
39
+ prune: (items) => items.filter((item) => item.refName !== refName),
40
+ archiveRefName: refName,
41
+ },
42
+ });
43
+ }
44
+ }
45
+ }
46
+ }
47
+ /** Block actions that run an own-file resource of the app: the action variant, its id attribute, and the resource type. */
48
+ const RUN_ACTIONS = [
49
+ ["automation", "automation_id", "elementum_automation"],
50
+ ["agent", "agent_id", "elementum_agent"],
51
+ ];
52
+ function listOf(value) {
53
+ return Array.isArray(value) ? value : [];
54
+ }
55
+ function objectOf(value) {
56
+ return typeof value === "object" && value !== null && !Array.isArray(value) && !isTfExpr(value) ? value : undefined;
57
+ }
9
58
  function extract(blocks, _stream, ctx) {
10
59
  const items = [];
11
60
  const skipped = [];
@@ -18,7 +67,9 @@ function extract(blocks, _stream, ctx) {
18
67
  const releaseIfManaged = [];
19
68
  for (const block of blocks) {
20
69
  try {
21
- items.push(visualFlowFromTf(block, ownerType, ctx.appTfLabel, ctx.parentScope, ctx, stageHandles));
70
+ const flow = visualFlowFromTf(block, ownerType, ctx.appTfLabel, ctx.parentScope, ctx, stageHandles);
71
+ items.push(flow);
72
+ requireFlowAutomations(block, flow.refName, ctx);
22
73
  }
23
74
  catch (error) {
24
75
  const address = `${block.type}.${block.label ?? "?"}`;
@@ -8,6 +8,7 @@ import { DATAMINE_RESOURCE_TYPE } from "../datamine/module.js";
8
8
  import { RELATIONSHIP_RESOURCE_TYPE } from "../relationship/module.js";
9
9
  import { TABLE_RESOURCE_TYPE } from "../table/module.js";
10
10
  import { VISUAL_FLOW_RESOURCE_TYPE } from "./module.js";
11
+ import { INITIATE_STAGE_ID_ATTR, INITIATE_STAGE_KEY } from "./initiate.js";
11
12
  function ownedResourceRef(ref, expected, ctx) {
12
13
  if (ref.__kind !== expected || !ref.refName || ref.parent !== ctx.appRefName) {
13
14
  throw new EntityTfError(`visual flow ${expected} must be a typed reference owned by ${ctx.appRefName}`);
@@ -157,11 +158,24 @@ export function visualFlowToTf(entity, ctx) {
157
158
  const ownerType = APP_RESOURCE_TYPE;
158
159
  const label = appScopedResourceLabel(ctx.appTfLabel, tsLabelToTfLabel(entity.refName));
159
160
  const dataBlocks = new Map();
160
- const stages = (payload.stages ?? []).map((stage) => {
161
+ const resolved = (payload.stages ?? []).map((stage) => {
161
162
  if (!stage.stage)
162
163
  throw new EntityTfError(`visual flow ${entity.refName}: every stage requires a stable key`);
164
+ const stageHandle = tsLabelToTfLabel(stage.stage);
165
+ const appStageKey = ctx.stageKeyByTfLabel?.get(stageHandle);
166
+ // `initiate` names the platform's Initiate stage unless the app authors
167
+ // its own stage with that key (#2987).
168
+ return { stage, stageHandle, appStageKey, onInitiate: appStageKey === undefined && stageHandle === INITIATE_STAGE_KEY };
169
+ });
170
+ // The platform lists the Initiate stage first, and elementum_flow Read keeps
171
+ // platform order with stage_id RequiresReplace: emit it first wherever the
172
+ // source lists it, or every plan after the first apply replaces the flow.
173
+ const ordered = [...resolved.filter((entry) => entry.onInitiate), ...resolved.filter((entry) => !entry.onInitiate)];
174
+ const stages = ordered.map(({ stage, stageHandle, appStageKey, onInitiate }) => {
163
175
  return {
164
- stage_id: expr.resourceAttr(ownerType, ctx.appTfLabel, ["stage_ids_by_key", { index: ctx.stageKeyByTfLabel?.get(tsLabelToTfLabel(stage.stage)) ?? tsLabelToTfLabel(stage.stage) }]),
176
+ stage_id: onInitiate
177
+ ? expr.resourceAttr(ownerType, ctx.appTfLabel, [INITIATE_STAGE_ID_ATTR])
178
+ : expr.resourceAttr(ownerType, ctx.appTfLabel, ["stage_ids_by_key", { index: appStageKey ?? stageHandle }]),
165
179
  nodes: Object.entries(stage.nodes ?? {}).map(([key, node]) => ({
166
180
  key,
167
181
  ...(node.description !== undefined && { description: node.description }),
@@ -231,7 +231,7 @@ function widgetFieldRef(value, target, owner, ctx) {
231
231
  : target.namespace ?? tsLabelToTfLabel(target.key);
232
232
  const targetScope = typeof target === "string" || target.kind === "automation" || target.kind === "field" || target.kind === "recordIdentity" || target.kind === "task" ? owner.scope : target.kind;
233
233
  if (targetLabel !== undefined) {
234
- const key = fieldKeyFromTfRef(value, targetLabel, targetScope);
234
+ const key = fieldKeyFromTfRef(value, targetLabel, targetScope, ctx);
235
235
  if (key !== undefined) {
236
236
  // HANDLE system field (`local.<target>_id_field_id`) round-trips as
237
237
  // recordIdentity(target) — same catalog token widgets author with.
@@ -338,7 +338,7 @@ function ownerFieldRef(value, owner, ctx) {
338
338
  return undefined;
339
339
  if (typeof value === "string")
340
340
  return fieldRefFromRawId(value, owner.ownerRefName, owner, ctx) ?? value;
341
- const key = fieldKeyFromTfRef(value, owner.ownerTfLabel, owner.scope);
341
+ const key = fieldKeyFromTfRef(value, owner.ownerTfLabel, owner.scope, ctx);
342
342
  return key === undefined ? undefined : { kind: "field", key, name: key, parent: owner.ownerRefName, fieldType: "TEXT" };
343
343
  }
344
344
  /**
@@ -427,7 +427,7 @@ function fieldRefFromRawId(id, target, owner, ctx) {
427
427
  const subType = SUB_TYPE_BY_RESOURCE.get(imported.type);
428
428
  if (subType === undefined)
429
429
  return undefined;
430
- const ownerKey = fieldKeyIfScopedTo(imported.type, imported.label, owner.ownerTfLabel, owner.scope);
430
+ const ownerKey = fieldKeyIfScopedTo(imported.type, imported.label, owner.ownerTfLabel, owner.scope, ctx);
431
431
  if (ownerKey !== undefined) {
432
432
  return {
433
433
  kind: "field",
@@ -441,7 +441,7 @@ function fieldRefFromRawId(id, target, owner, ctx) {
441
441
  const targetTfLabel = target.key === owner.ownerRefName
442
442
  ? owner.ownerTfLabel
443
443
  : target.namespace ?? tsLabelToTfLabel(target.key);
444
- const targetKey = fieldKeyIfScopedTo(imported.type, imported.label, targetTfLabel, target.kind);
444
+ const targetKey = fieldKeyIfScopedTo(imported.type, imported.label, targetTfLabel, target.kind, ctx);
445
445
  if (targetKey !== undefined) {
446
446
  return {
447
447
  kind: "field",
@@ -455,8 +455,8 @@ function fieldRefFromRawId(id, target, owner, ctx) {
455
455
  return undefined;
456
456
  }
457
457
  /** `fieldKeyFromTfRef` camelCases any label; only treat it as owned when the scoped prefix was actually stripped. */
458
- function fieldKeyIfScopedTo(type, label, ownerTfLabel, scope) {
458
+ function fieldKeyIfScopedTo(type, label, ownerTfLabel, scope, ctx) {
459
459
  if (bareChildResourceLabel(ownerTfLabel, label, scope) === label)
460
460
  return undefined;
461
- return fieldKeyFromTfRef({ $expr: "resource-attr", type, label, path: ["id"] }, ownerTfLabel, scope);
461
+ return fieldKeyFromTfRef({ $expr: "resource-attr", type, label, path: ["id"] }, ownerTfLabel, scope, ctx);
462
462
  }
@@ -88,6 +88,10 @@ export declare const BUILD_VS_EXPORT_RECORD_FIELD_OUTPUT_KEYS: {
88
88
  readonly nameAttribute: string;
89
89
  readonly ownerAttribute: string;
90
90
  }[];
91
+ export declare const BUILD_VS_EXPORT_MAP_KEY_ALIASES: {
92
+ readonly attribute: string;
93
+ readonly canonicalKey: (key: string) => string | undefined;
94
+ }[];
91
95
  export declare const BUILD_VS_EXPORT_ATTRIBUTE_LOCALS: {
92
96
  readonly resourceType: string;
93
97
  readonly attribute: string;
@@ -63,6 +63,7 @@ export const BUILD_VS_EXPORT_COMPUTED_MAP_ATTRIBUTES = KIND_MODULES.flatMap((mod
63
63
  export const BUILD_VS_EXPORT_NESTED_OMITTED_DEFAULTS = KIND_MODULES.flatMap((module) => (module.roundtrip?.nestedOmittedDefaults ?? []).flatMap((declared) => implementedResourceTypes(module.resource).map((blockType) => ({ blockType, ...declared }))));
64
64
  export const BUILD_VS_EXPORT_COMPUTED_REFERENCE_MAPS = KIND_MODULES.flatMap((module) => module.roundtrip?.computedReferenceMaps ?? []);
65
65
  export const BUILD_VS_EXPORT_RECORD_FIELD_OUTPUT_KEYS = KIND_MODULES.flatMap((module) => module.roundtrip?.recordFieldOutputKeys ?? []);
66
+ export const BUILD_VS_EXPORT_MAP_KEY_ALIASES = KIND_MODULES.flatMap((module) => module.roundtrip?.mapKeyAliases ?? []);
66
67
  export const BUILD_VS_EXPORT_ATTRIBUTE_LOCALS = KIND_MODULES.flatMap((module) => module.roundtrip?.exportedAttributeLocals ?? []);
67
68
  export const BUILD_VS_EXPORT_PICKLIST_LABEL_ASSIGNMENTS = KIND_MODULES.flatMap((module) => module.roundtrip?.picklistLabelAssignments ?? []);
68
69
  export const BUILD_VS_EXPORT_STATE_EVALUATED_MAPS = KIND_MODULES.flatMap((module) => module.roundtrip?.stateEvaluatedMaps ?? []);
@@ -17,6 +17,7 @@ import { elementModule } from "../entities/element/module.js";
17
17
  import { dynamicLayoutModule } from "../entities/dynamic-layout/module.js";
18
18
  import { dashboardModule } from "../entities/dashboard/module.js";
19
19
  import { dashboardWidgetModule } from "../entities/dashboard-widget/module.js";
20
+ import { dashboardWidgetOrderModule } from "../entities/dashboard-widget-order/module.js";
20
21
  import { datamineModule } from "../entities/datamine/module.js";
21
22
  import { dataLookupModules } from "../entities/data-lookup/module.js";
22
23
  import { fieldModule, managedFieldOrderModule } from "../entities/field/module.js";
@@ -60,6 +61,7 @@ export const KIND_MODULES = [
60
61
  dynamicLayoutModule,
61
62
  dashboardModule,
62
63
  dashboardWidgetModule,
64
+ dashboardWidgetOrderModule,
63
65
  datamineModule,
64
66
  ...dataLookupModules,
65
67
  widgetModule,
@@ -12,7 +12,7 @@ import type { OptionIdIndex } from "../engine/pull/field-refs-registry.js";
12
12
  import type { PulledRootStatus } from "../engine/pull/pulled-roots.js";
13
13
  import type { ChildResourceScope, TfBlock, TfValue } from "../engine/tf/index.js";
14
14
  import type { ValidationFailure } from "../engine/validation.js";
15
- export type KindId = "org" | "app" | "element" | "field" | "access-policy" | "agent" | "agent-evaluation" | "sla" | "chart" | "agent-tool" | "agent-a2a-skill" | "automation" | "approval-chain" | "file-reader" | "visual-flow" | "skill" | "skill-tool" | "view" | "managed-view-order" | "managed-field-order" | "record-create-form" | "dynamic-layout" | "dashboard" | "dashboard-widget" | "datamine" | "automation-value-references" | "organization" | "permission-template" | "service-account" | "stored-function" | "vault-entry" | "task" | "portal" | "widget" | "relationship" | "search-table" | "table" | "cloud-link" | "email-alias" | "category" | "connector" | "ai-provider-anthropic" | "ai-provider-bedrock" | "ai-provider-custom" | "ai-provider-deepgram" | "ai-provider-elevenlab" | "ai-provider-gemini" | "ai-provider-openai" | "ai-provider-snowflake" | "ai-provider-xai" | "ai-provider-managed" | "group" | "phone-provider" | "phone-service" | "voice-auth" | "role" | "user";
15
+ export type KindId = "org" | "app" | "element" | "field" | "access-policy" | "agent" | "agent-evaluation" | "sla" | "chart" | "agent-tool" | "agent-a2a-skill" | "automation" | "approval-chain" | "file-reader" | "visual-flow" | "skill" | "skill-tool" | "view" | "managed-view-order" | "managed-field-order" | "record-create-form" | "dynamic-layout" | "dashboard" | "dashboard-widget" | "dashboard-widget-order" | "datamine" | "automation-value-references" | "organization" | "permission-template" | "service-account" | "stored-function" | "vault-entry" | "task" | "portal" | "widget" | "relationship" | "search-table" | "table" | "cloud-link" | "email-alias" | "category" | "connector" | "ai-provider-anthropic" | "ai-provider-bedrock" | "ai-provider-custom" | "ai-provider-deepgram" | "ai-provider-elevenlab" | "ai-provider-gemini" | "ai-provider-openai" | "ai-provider-snowflake" | "ai-provider-xai" | "ai-provider-managed" | "group" | "phone-provider" | "phone-service" | "voice-auth" | "role" | "user";
16
16
  /** @deprecated Use {@link KindId}. */
17
17
  export type EntityKindId = KindId;
18
18
  export type StreamFacet = {
@@ -519,6 +519,15 @@ export interface BuildFieldMetadata {
519
519
  readonly options?: readonly string[];
520
520
  readonly tags?: readonly string[];
521
521
  }
522
+ /** See {@link BuildChildContext.advisoriesWhileRecorded}. */
523
+ export interface AdvisoryWhileRecorded {
524
+ /** Stable identity the revision record keeps for this finding (#2283). */
525
+ readonly finding: string;
526
+ /** The diagnostic line while the record lists the finding. */
527
+ readonly advisory: string;
528
+ /** The fatal finding's message when it doesn't. */
529
+ readonly error: string;
530
+ }
522
531
  export interface BuildChildContext {
523
532
  readonly appRefName: string;
524
533
  readonly appTfLabel: string;
@@ -527,6 +536,13 @@ export interface BuildChildContext {
527
536
  readonly orgRefs: unknown;
528
537
  readonly diagnostics: string[];
529
538
  readonly reports?: string[];
539
+ /**
540
+ * Findings the platform may already run. Build writes each one's `finding`
541
+ * into the compiled file, where a pull or apply records it in the
542
+ * child's revision record. Build reports a finding the record lists as a
543
+ * diagnostic and fails any other (#2283).
544
+ */
545
+ readonly advisoriesWhileRecorded?: AdvisoryWhileRecorded[];
530
546
  readonly fieldAddresses?: ReadonlyMap<string, string>;
531
547
  readonly fieldNames?: ReadonlyMap<string, string>;
532
548
  readonly fieldMetadata?: ReadonlyMap<string, BuildFieldMetadata>;
@@ -546,6 +562,13 @@ export interface BuildChildContext {
546
562
  * used in a formula needs the searched aspect's field resources.
547
563
  */
548
564
  readonly fieldAddressesByAppRefName?: ReadonlyMap<string, ReadonlyMap<string, string>>;
565
+ /**
566
+ * Field types (`GROUP_ID`, `PICKLIST`, ...) from the org catalog for every
567
+ * app/element it lists, keyed by refName and then field key. Covers an
568
+ * app or element known only from its generated catalog, which has no
569
+ * field resources in {@link fieldAddressesByAppRefName}.
570
+ */
571
+ readonly catalogFieldTypesByAppRefName?: ReadonlyMap<string, ReadonlyMap<string, string>>;
549
572
  /**
550
573
  * Every app/element authored in the workspace, keyed like
551
574
  * `workspaceAspects` (`<kind>:<refName>`), including those a partial build
@@ -928,6 +951,18 @@ export interface EntityKindModule {
928
951
  readonly nameAttribute: string;
929
952
  readonly ownerAttribute: string;
930
953
  }[];
954
+ /**
955
+ * Computed map attributes (`refs`, also read as `inner.refs`) whose
956
+ * provider publishes one value under several keys: `canonicalKey` names
957
+ * the spelling a build emits for `key`, or undefined when it has no other
958
+ * spelling. Reads of two spellings of one key compare equal, so the
959
+ * declaring kind's pull must decode an alias only where the provider
960
+ * publishes it; this check can't tell.
961
+ */
962
+ readonly mapKeyAliases?: readonly {
963
+ readonly attribute: string;
964
+ readonly canonicalKey: (key: string) => string | undefined;
965
+ }[];
931
966
  /**
932
967
  * Map attributes the provider computes at plan time from the resource's
933
968
  * own list: `<attribute>[entry.<nameAttribute>]` is `value(name)`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elementumai/edk",
3
- "version": "0.13.0",
3
+ "version": "0.13.2",
4
4
  "description": "Elementum Development Kit — statically typed SDK for building Elementum apps, automations, and agents",
5
5
  "type": "module",
6
6
  "license": "SEE LICENSE IN LICENSE",
@@ -222,6 +222,7 @@
222
222
  "edk:canvas": "tsx --tsconfig tsconfig.examples-check.json src/scripts/edk-canvas.ts"
223
223
  },
224
224
  "dependencies": {
225
+ "@types/node": "^25.5.2",
225
226
  "acorn": "^8.16.0",
226
227
  "jiti": "^2.7.0",
227
228
  "semver": "^7.8.5"
@@ -229,7 +230,6 @@
229
230
  "devDependencies": {
230
231
  "@cdktf/hcl2json": "^0.21.0",
231
232
  "@eslint/js": "^9.39.4",
232
- "@types/node": "^25.5.2",
233
233
  "@types/semver": "^7.8.0",
234
234
  "@vercel/blob": "^2.6.1",
235
235
  "ajv": "^8.20.0",