@elementumai/edk 0.9.18 → 0.9.19

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 (125) hide show
  1. package/README.md +8 -3
  2. package/dist-sdk/src/catalog/factories.d.ts +11 -0
  3. package/dist-sdk/src/catalog/factories.js +6 -0
  4. package/dist-sdk/src/catalog/index.d.ts +2 -2
  5. package/dist-sdk/src/catalog/index.js +2 -2
  6. package/dist-sdk/src/catalog/org.d.ts +39 -1
  7. package/dist-sdk/src/catalog/org.js +460 -50
  8. package/dist-sdk/src/catalog/types.d.ts +10 -0
  9. package/dist-sdk/src/catalog/types.js +2 -0
  10. package/dist-sdk/src/engine/pull/ref-only.js +54 -20
  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/tf/expr.js +38 -13
  14. package/dist-sdk/src/engine/tf/index.d.ts +2 -2
  15. package/dist-sdk/src/engine/tf/index.js +2 -2
  16. package/dist-sdk/src/engine/tf/labels.d.ts +2 -0
  17. package/dist-sdk/src/engine/tf/labels.js +4 -0
  18. package/dist-sdk/src/engine/tf/parse.d.ts +19 -0
  19. package/dist-sdk/src/engine/tf/parse.js +105 -6
  20. package/dist-sdk/src/engine/workspace/loader.js +49 -12
  21. package/dist-sdk/src/entities/access-policy/from-tf.d.ts +11 -1
  22. package/dist-sdk/src/entities/access-policy/from-tf.js +6 -1
  23. package/dist-sdk/src/entities/access-policy/to-tf.d.ts +11 -0
  24. package/dist-sdk/src/entities/access-policy/to-tf.js +11 -4
  25. package/dist-sdk/src/entities/agent-tool/to-tf.js +2 -1
  26. package/dist-sdk/src/entities/app/build.d.ts +10 -0
  27. package/dist-sdk/src/entities/app/build.js +0 -13
  28. package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +6 -1
  29. package/dist-sdk/src/entities/app/from-tf.js +4 -3
  30. package/dist-sdk/src/entities/app/index.d.ts +1 -0
  31. package/dist-sdk/src/entities/app/index.js +1 -0
  32. package/dist-sdk/src/entities/app/module.js +13 -0
  33. package/dist-sdk/src/entities/app/to-tf.js +2 -0
  34. package/dist-sdk/src/entities/automation/build.d.ts +2 -1
  35. package/dist-sdk/src/entities/automation/build.js +27 -0
  36. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +6 -0
  37. package/dist-sdk/src/entities/automation/from-tf.js +135 -26
  38. package/dist-sdk/src/entities/automation/index.d.ts +1 -1
  39. package/dist-sdk/src/entities/automation/module.d.ts +2 -0
  40. package/dist-sdk/src/entities/automation/module.js +56 -0
  41. package/dist-sdk/src/entities/automation/system-ref-name.d.ts +16 -0
  42. package/dist-sdk/src/entities/automation/system-ref-name.js +44 -0
  43. package/dist-sdk/src/entities/automation/task-output-labels.d.ts +15 -0
  44. package/dist-sdk/src/entities/automation/task-output-labels.js +38 -0
  45. package/dist-sdk/src/entities/automation/tasks.d.ts +29 -2
  46. package/dist-sdk/src/entities/automation/to-tf.js +158 -84
  47. package/dist-sdk/src/entities/automation/types.js +1 -0
  48. package/dist-sdk/src/entities/chart/from-tf.js +33 -17
  49. package/dist-sdk/src/entities/chart/module.js +3 -1
  50. package/dist-sdk/src/entities/chart/printer.d.ts +1 -0
  51. package/dist-sdk/src/entities/chart/printer.js +26 -16
  52. package/dist-sdk/src/entities/chart/rebind-owner.d.ts +3 -0
  53. package/dist-sdk/src/entities/chart/rebind-owner.js +42 -0
  54. package/dist-sdk/src/entities/chart/to-tf.js +12 -10
  55. package/dist-sdk/src/entities/dashboard/build.d.ts +4 -0
  56. package/dist-sdk/src/entities/dashboard/from-tf.js +15 -4
  57. package/dist-sdk/src/entities/dashboard/to-tf.d.ts +2 -0
  58. package/dist-sdk/src/entities/dashboard/to-tf.js +13 -0
  59. package/dist-sdk/src/entities/dashboard-widget/module.js +4 -0
  60. package/dist-sdk/src/entities/dynamic-layout/build.d.ts +51 -2
  61. package/dist-sdk/src/entities/dynamic-layout/dialect.d.ts +3 -0
  62. package/dist-sdk/src/entities/dynamic-layout/dialect.js +5 -0
  63. package/dist-sdk/src/entities/dynamic-layout/from-tf.d.ts +9 -6
  64. package/dist-sdk/src/entities/dynamic-layout/from-tf.js +188 -26
  65. package/dist-sdk/src/entities/dynamic-layout/module.js +4 -1
  66. package/dist-sdk/src/entities/dynamic-layout/to-tf.d.ts +5 -1
  67. package/dist-sdk/src/entities/dynamic-layout/to-tf.js +254 -23
  68. package/dist-sdk/src/entities/element/build.d.ts +8 -0
  69. package/dist-sdk/src/entities/element/build.js +1 -0
  70. package/dist-sdk/src/entities/element/from-tf.d.ts +1 -0
  71. package/dist-sdk/src/entities/element/from-tf.js +6 -2
  72. package/dist-sdk/src/entities/element/index.d.ts +1 -0
  73. package/dist-sdk/src/entities/element/index.js +1 -0
  74. package/dist-sdk/src/entities/element/module.js +2 -0
  75. package/dist-sdk/src/entities/element/to-tf.js +12 -0
  76. package/dist-sdk/src/entities/field/from-tf.d.ts +2 -0
  77. package/dist-sdk/src/entities/field/from-tf.js +11 -0
  78. package/dist-sdk/src/entities/field/to-tf.js +13 -9
  79. package/dist-sdk/src/entities/relationship/from-tf.d.ts +8 -1
  80. package/dist-sdk/src/entities/relationship/from-tf.js +53 -10
  81. package/dist-sdk/src/entities/relationship/to-tf.d.ts +8 -0
  82. package/dist-sdk/src/entities/relationship/to-tf.js +19 -10
  83. package/dist-sdk/src/entities/shared/filters/ast.d.ts +7 -2
  84. package/dist-sdk/src/entities/shared/filters/index.d.ts +23 -2
  85. package/dist-sdk/src/entities/shared/filters/index.js +24 -1
  86. package/dist-sdk/src/entities/shared/filters/print.js +14 -2
  87. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +23 -3
  88. package/dist-sdk/src/entities/shared/filters/tf-codec.js +46 -14
  89. package/dist-sdk/src/entities/shared/filters/types.d.ts +13 -4
  90. package/dist-sdk/src/entities/shared/foreign-ref.d.ts +16 -0
  91. package/dist-sdk/src/entities/shared/foreign-ref.js +17 -1
  92. package/dist-sdk/src/entities/shared/tool-field-ref.js +6 -9
  93. package/dist-sdk/src/entities/skill/access-policy.d.ts +17 -0
  94. package/dist-sdk/src/entities/skill/access-policy.js +101 -0
  95. package/dist-sdk/src/entities/skill/build.d.ts +3 -0
  96. package/dist-sdk/src/entities/skill/build.js +3 -0
  97. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +4 -1
  98. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +21 -0
  99. package/dist-sdk/src/entities/skill/from-tf.d.ts +2 -0
  100. package/dist-sdk/src/entities/skill/from-tf.js +4 -9
  101. package/dist-sdk/src/entities/skill/index.d.ts +2 -0
  102. package/dist-sdk/src/entities/skill/index.js +1 -0
  103. package/dist-sdk/src/entities/skill/module.js +1 -0
  104. package/dist-sdk/src/entities/skill/to-tf.d.ts +2 -2
  105. package/dist-sdk/src/entities/skill/to-tf.js +5 -2
  106. package/dist-sdk/src/entities/skill-tool/to-tf.js +2 -1
  107. package/dist-sdk/src/entities/table/to-tf.js +3 -3
  108. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.d.ts +49 -0
  109. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.js +224 -0
  110. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.d.ts +36 -0
  111. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.js +288 -0
  112. package/dist-sdk/src/entities/view/agent-view-layout.d.ts +121 -0
  113. package/dist-sdk/src/entities/view/agent-view-layout.js +21 -0
  114. package/dist-sdk/src/entities/view/from-tf.d.ts +3 -1
  115. package/dist-sdk/src/entities/view/from-tf.js +42 -7
  116. package/dist-sdk/src/entities/view/to-tf.d.ts +10 -1
  117. package/dist-sdk/src/entities/view/to-tf.js +30 -1
  118. package/dist-sdk/src/entities/view/types.js +2 -0
  119. package/dist-sdk/src/entities/widget/to-tf.js +2 -2
  120. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +25 -8
  121. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
  122. package/dist-sdk/src/graph/index.d.ts +43 -0
  123. package/dist-sdk/src/graph/index.js +9 -0
  124. package/dist-sdk/src/graph/types.d.ts +78 -0
  125. package/package.json +2 -1
@@ -1,12 +1,15 @@
1
1
  import { dataRefLabel, optionalString, plainObject, resourceRefLabel } from "../../engine/pull/context.js";
2
- import { isTfExpr, scopedLabelToBagKey, tfLabelToTsLabel, } from "../../engine/tf/index.js";
3
- import { fieldKeyFromTfRef } from "../field/from-tf.js";
2
+ import { isTfExpr, isTfLabel, scopedLabelToBagKey, tfLabelToTsLabel, } from "../../engine/tf/index.js";
3
+ import { filterFromTf } from "../access-policy/from-tf.js";
4
+ import { fieldKeyFromTfValue } from "../field/from-tf.js";
5
+ import { filterOwnerForAspect } from "../relationship/from-tf.js";
6
+ import { filterWireToTf } from "../shared/filters/tf-codec.js";
4
7
  import { resolveDataAspectTarget } from "../shared/aspect-target-from-tf.js";
5
8
  import { WIDGET_RESOURCE_TYPE } from "../widget/module.js";
6
9
  import { DYNAMIC_LAYOUT_RESOURCE_TYPE } from "./module.js";
7
- import { DYNAMIC_LAYOUT_COMPARISON_KEYS, DYNAMIC_LAYOUT_FIELD_COMPONENT_WIRE_KEY_BY_PUBLIC_KEY, } from "./dialect.js";
10
+ import { DYNAMIC_LAYOUT_COMPARISON_KEYS, DYNAMIC_LAYOUT_FIELD_COMPONENT_WIRE_KEY_BY_PUBLIC_KEY, dynamicLayoutCompanionWidgetLabel, } from "./dialect.js";
8
11
  const KNOWN_ATTRS = new Set([
9
- "app_id", "stage_id", "name", "description", "active", "document_id", "document_version",
12
+ "app_id", "element_id", "stage_id", "name", "description", "active", "document_id", "document_version",
10
13
  "root_component", "components", "conditions", "save_groups", "field_validations", "dependencies",
11
14
  "metadata", "version", "created_at", "updated_at",
12
15
  ]);
@@ -20,25 +23,28 @@ export function dynamicLayoutsFromTf(blocks, owner, ctx) {
20
23
  return out;
21
24
  }
22
25
  /**
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.
26
+ * Labels of the companion widgets build derives for dynamic-layout automation
27
+ * buttons, among those the buttons reference. The label is the companion's
28
+ * stable Terraform identity; its display name is mutable and cannot safely
29
+ * distinguish generated from authored widgets during pull. A button bound to
30
+ * any other widget keeps that widget as authored source.
27
31
  */
28
- export function dynamicLayoutCompanionWidgetLabels(blocks) {
32
+ export function dynamicLayoutCompanionWidgetLabels(blocks, owner) {
29
33
  const labels = new Set();
30
34
  for (const block of blocks) {
31
35
  const components = plainObject(block.attrs["components"]);
32
36
  if (components === undefined)
33
37
  continue;
34
- for (const raw of Object.values(components)) {
38
+ const layoutKey = scopedLabelToBagKey(owner.ownerTfLabel, block.label ?? "", scopeOf(owner));
39
+ for (const [componentId, raw] of Object.entries(components)) {
35
40
  const component = plainObject(raw);
36
41
  const button = component === undefined ? undefined : plainObject(component["automation_button"]);
37
42
  const label = button === undefined
38
43
  ? undefined
39
44
  : resourceRefLabel(button["widget_id"], WIDGET_RESOURCE_TYPE);
40
- if (label !== undefined)
45
+ if (label !== undefined && label === dynamicLayoutCompanionWidgetLabel(owner.label, layoutKey, componentId, scopeOf(owner))) {
41
46
  labels.add(label);
47
+ }
42
48
  }
43
49
  }
44
50
  return labels;
@@ -49,8 +55,9 @@ function dynamicLayoutFromTf(block, owner, ctx) {
49
55
  if (!KNOWN_ATTRS.has(key))
50
56
  ctx.diagnostics.push(`${where}: unhandled attribute "${key}" — extend dynamic-layout extraction`);
51
57
  }
52
- if (resourceRefLabel(block.attrs["app_id"], owner.type) !== owner.label) {
53
- ctx.diagnostics.push(`${where}: app_id does not reference ${owner.type}.${owner.label}; skipped`);
58
+ const ownerAttr = scopeOf(owner) === "element" ? "element_id" : "app_id";
59
+ if (resourceRefLabel(block.attrs[ownerAttr], owner.type) !== owner.label) {
60
+ ctx.diagnostics.push(`${where}: ${ownerAttr} does not reference ${owner.type}.${owner.label}; skipped`);
54
61
  return undefined;
55
62
  }
56
63
  const componentsRaw = plainObject(block.attrs["components"]);
@@ -58,8 +65,8 @@ function dynamicLayoutFromTf(block, owner, ctx) {
58
65
  ctx.diagnostics.push(`${where}: components is not an object; skipped`);
59
66
  return undefined;
60
67
  }
61
- const resolvedStageKey = stageKey(block.attrs["stage_id"], owner);
62
- if (block.attrs["stage_id"] !== undefined && resolvedStageKey === undefined) {
68
+ const resolvedStageKey = stageKey(block.attrs["stage_id"], owner, ctx, `${where}.stage_id`);
69
+ if (block.attrs["stage_id"] !== undefined && stageIndex(block.attrs["stage_id"], owner) === undefined) {
63
70
  ctx.diagnostics.push(`${where}: stage_id has an unrecognized shape; layout kept unscoped instead of guessing`);
64
71
  }
65
72
  const layout = {
@@ -70,7 +77,7 @@ function dynamicLayoutFromTf(block, owner, ctx) {
70
77
  documentId: optionalString(block.attrs, "document_id", where, ctx) ?? "",
71
78
  ...(typeof block.attrs["document_version"] === "string" && { documentVersion: block.attrs["document_version"] }),
72
79
  rootComponent: optionalString(block.attrs, "root_component", where, ctx) ?? "",
73
- components: componentMap(componentsRaw, owner, ctx, where),
80
+ components: componentMap(componentsRaw, scopedLabelToBagKey(owner.ownerTfLabel, block.label ?? "", scopeOf(owner)), owner, ctx, where),
74
81
  };
75
82
  const conditions = plainObject(block.attrs["conditions"]);
76
83
  if (conditions !== undefined)
@@ -88,11 +95,14 @@ function dynamicLayoutFromTf(block, owner, ctx) {
88
95
  if (metadata !== undefined)
89
96
  layout["metadata"] = camelObject(metadata);
90
97
  return {
91
- key: scopedLabelToBagKey(owner.ownerTfLabel, block.label ?? "", "app"),
98
+ key: scopedLabelToBagKey(owner.ownerTfLabel, block.label ?? "", scopeOf(owner)),
92
99
  layout,
93
100
  };
94
101
  }
95
- function componentMap(values, owner, ctx, where) {
102
+ function scopeOf(owner) {
103
+ return owner.scope ?? "app";
104
+ }
105
+ function componentMap(values, layoutKey, owner, ctx, where) {
96
106
  const out = {};
97
107
  for (const [id, raw] of Object.entries(values)) {
98
108
  const component = camelObject(plainObject(raw) ?? {});
@@ -129,9 +139,14 @@ function componentMap(values, owner, ctx, where) {
129
139
  }
130
140
  const automation = plainUnknownObject(component["automationButton"]);
131
141
  if (automation !== undefined) {
132
- // Build derives the backing widget from the component itself, so the
142
+ // Build derives a companion widget from the component itself, so that
133
143
  // binding is never authored and must not be printed back into source.
144
+ const widgetLabel = resourceRefLabel(automation["widgetId"], WIDGET_RESOURCE_TYPE);
145
+ if (widgetLabel !== undefined && widgetLabel !== dynamicLayoutCompanionWidgetLabel(owner.label, layoutKey, id, scopeOf(owner))) {
146
+ automation["widget"] = pulledRef("widget", scopedLabelToBagKey(owner.label, widgetLabel, scopeOf(owner)), owner.ownerRefName);
147
+ }
134
148
  delete automation["widgetId"];
149
+ const automationId = automation["automationId"];
135
150
  if (automation["automationId"] !== undefined) {
136
151
  const label = resourceRefLabel(automation["automationId"], "elementum_automation");
137
152
  if (label !== undefined) {
@@ -141,7 +156,52 @@ function componentMap(values, owner, ctx, where) {
141
156
  ctx.diagnostics.push(`${where}.components.${id}.automationButton: automation_id is not a managed automation ref; dropped`);
142
157
  delete automation["automationId"];
143
158
  }
159
+ if (automation["automationAppId"] !== undefined) {
160
+ const ref = aspectRef(automation["automationAppId"], owner, ctx);
161
+ if (ref !== undefined)
162
+ automation["automationApp"] = ref;
163
+ else
164
+ ctx.diagnostics.push(`${where}.components.${id}.automationButton: automation_app_id is not resolvable; dropped`);
165
+ delete automation["automationAppId"];
166
+ }
167
+ if (Array.isArray(automation["inputs"])) {
168
+ const automationLabel = automationId === undefined ? undefined : resourceRefLabel(automationId, "elementum_automation");
169
+ automation["inputs"] = automation["inputs"].flatMap((raw, index) => {
170
+ const input = plainUnknownObject(raw);
171
+ if (input === undefined)
172
+ return [];
173
+ const parameter = input["parameterId"];
174
+ if (parameter !== undefined && isTfExpr(parameter)) {
175
+ const managed = managedParameter(parameter, ctx);
176
+ if (managed === undefined) {
177
+ ctx.diagnostics.push(`${where}.components.${id}.automationButton.inputs[${index}]: parameter_id is not a managed automation parameter; dropped`);
178
+ return [];
179
+ }
180
+ input["parameterName"] = managed.name;
181
+ if (managed.automationLabel !== automationLabel) {
182
+ input["automation"] = pulledRef("automation", scopedLabelToBagKey(owner.ownerTfLabel, managed.automationLabel, "app"), owner.ownerRefName);
183
+ }
184
+ delete input["parameterId"];
185
+ }
186
+ return [input];
187
+ });
188
+ for (const [index, raw] of automation["inputs"].entries()) {
189
+ const input = plainUnknownObject(raw);
190
+ if (input === undefined || !Array.isArray(input["fieldRefParams"]))
191
+ continue;
192
+ input["fieldRefParams"] = input["fieldRefParams"].flatMap((param) => {
193
+ const entry = plainUnknownObject(param);
194
+ const field = entry === undefined
195
+ ? undefined
196
+ : fieldKey(entry["fieldId"], owner, ctx, `${where}.components.${id}.automationButton.inputs[${index}]`);
197
+ return field === undefined ? [] : [{ name: entry["name"], field }];
198
+ });
199
+ }
200
+ }
144
201
  }
202
+ const related = plainUnknownObject(component["relatedItemsBlock"]);
203
+ if (related !== undefined)
204
+ relatedItemsBlock(related, owner, ctx, `${where}.components.${id}.relatedItemsBlock`);
145
205
  const create = plainUnknownObject(component["createButton"]);
146
206
  if (create !== undefined && create["targetAspectId"] !== undefined) {
147
207
  const ref = aspectRef(create["targetAspectId"], owner, ctx);
@@ -155,6 +215,101 @@ function componentMap(values, owner, ctx, where) {
155
215
  }
156
216
  return out;
157
217
  }
218
+ /**
219
+ * A managed automation's parameter, read from its draft on-demand trigger or
220
+ * from a `data.elementum_automation` lookup of the published workflow.
221
+ */
222
+ function managedParameter(parameter, ctx) {
223
+ if (!isTfExpr(parameter) || (parameter.$expr !== "resource-attr" && parameter.$expr !== "data-attr"))
224
+ return undefined;
225
+ const segment = parameter.path[1];
226
+ const name = typeof segment === "object" && segment !== null && "index" in segment ? segment.index : undefined;
227
+ if (parameter.path.length !== 2 || parameter.path[0] !== "parameter_ids" || typeof name !== "string")
228
+ return undefined;
229
+ if (parameter.$expr === "resource-attr") {
230
+ return parameter.type === "elementum_on_demand_trigger" ? { automationLabel: parameter.label, name } : undefined;
231
+ }
232
+ if (parameter.type !== "elementum_automation")
233
+ return undefined;
234
+ const automationId = ctx.dataAttrs?.("elementum_automation", parameter.label)?.["id"];
235
+ const automationLabel = automationId === undefined ? undefined : resourceRefLabel(automationId, "elementum_automation");
236
+ return automationLabel === undefined ? undefined : { automationLabel, name };
237
+ }
238
+ function relatedItemsBlock(block, owner, ctx, where) {
239
+ const aspectId = block["relatedAspectId"];
240
+ delete block["relatedAspectId"];
241
+ if (aspectId !== undefined) {
242
+ const ref = aspectRef(aspectId, owner, ctx);
243
+ if (ref !== undefined)
244
+ block["related"] = ref;
245
+ else
246
+ ctx.diagnostics.push(`${where}: related_aspect_id is not resolvable; dropped`);
247
+ }
248
+ const raw = block["filter"];
249
+ delete block["filter"];
250
+ if (raw === undefined)
251
+ return;
252
+ const wire = filterWireToTf(decodeJson(raw));
253
+ const filterOwners = [{
254
+ type: owner.type,
255
+ label: owner.label,
256
+ ownerRefName: owner.ownerRefName,
257
+ ownerTfLabel: owner.ownerTfLabel,
258
+ scope: scopeOf(owner),
259
+ foreignFieldRefsById: ctx.foreignFieldRefsById,
260
+ }];
261
+ // The filter ranges over the related aspect's records, so its fields may
262
+ // belong to that aspect rather than to the layout's owner.
263
+ const aspectOwner = aspectId === undefined || resourceRefLabel(aspectId, owner.type) === owner.label
264
+ ? undefined
265
+ : filterOwnerForAspect(aspectId, ctx);
266
+ if (aspectOwner !== undefined)
267
+ filterOwners.push(aspectOwner);
268
+ // A raw field id decodes without throwing even when it is not the owner's
269
+ // field, so a decode that leaves one unresolved is only a fallback.
270
+ let failure;
271
+ let partial;
272
+ for (const filterOwner of filterOwners) {
273
+ try {
274
+ const decoded = filterFromTf(wire, filterOwner, `${where}.filter`, ctx);
275
+ if (!hasUnresolvedRef(decoded)) {
276
+ block["filter"] = decoded;
277
+ return;
278
+ }
279
+ partial ??= decoded;
280
+ }
281
+ catch (error) {
282
+ failure ??= error;
283
+ }
284
+ }
285
+ if (partial !== undefined) {
286
+ block["filter"] = partial;
287
+ return;
288
+ }
289
+ ctx.diagnostics.push(failure instanceof Error ? `${failure.message}; filter dropped` : `${where}.filter: not decodable; dropped`);
290
+ }
291
+ function hasUnresolvedRef(value) {
292
+ if (Array.isArray(value))
293
+ return value.some(hasUnresolvedRef);
294
+ if (typeof value !== "object" || value === null)
295
+ return false;
296
+ if (value.kind === "unresolved")
297
+ return true;
298
+ return Object.values(value).some(hasUnresolvedRef);
299
+ }
300
+ function decodeJson(value) {
301
+ if (isTfExpr(value) && value.$expr === "jsonencode")
302
+ return value.value;
303
+ if (typeof value === "string") {
304
+ try {
305
+ return JSON.parse(value);
306
+ }
307
+ catch {
308
+ return value;
309
+ }
310
+ }
311
+ return value;
312
+ }
158
313
  function conditionMap(values, owner, ctx, where) {
159
314
  const out = {};
160
315
  for (const [id, raw] of Object.entries(values)) {
@@ -176,7 +331,7 @@ function conditionMap(values, owner, ctx, where) {
176
331
  }
177
332
  const stage = plainUnknownObject(condition["stage"]);
178
333
  if (stage !== undefined && stage["stageId"] !== undefined) {
179
- const key = stageKey(stage["stageId"], owner);
334
+ const key = stageKey(stage["stageId"], owner, ctx, `${where}.conditions.${id}.stage`);
180
335
  if (key !== undefined)
181
336
  stage["stage"] = key;
182
337
  delete stage["stageId"];
@@ -221,30 +376,37 @@ function dependency(value, owner, ctx, where) {
221
376
  return out;
222
377
  }
223
378
  function fieldKey(value, owner, ctx, where) {
224
- const key = fieldKeyFromTfRef(value, owner.ownerTfLabel, "app");
379
+ const key = fieldKeyFromTfValue(value, owner.ownerRefName, owner.ownerTfLabel, scopeOf(owner), ctx);
225
380
  if (key === undefined) {
226
381
  ctx.diagnostics.push(`${where}: field reference ${JSON.stringify(value)} is not resolvable; dropped`);
227
382
  }
228
383
  return key;
229
384
  }
230
- function stageKey(value, owner) {
385
+ function stageKey(value, owner, ctx, where) {
386
+ const index = stageIndex(value, owner);
387
+ if (index === undefined || isTfLabel(index))
388
+ return index === undefined ? undefined : tfLabelToTsLabel(index);
389
+ ctx.diagnostics.push(`${where}: stage key ${JSON.stringify(index)} is outside the terraform label alphabet; stage dropped`);
390
+ return undefined;
391
+ }
392
+ function stageIndex(value, owner) {
231
393
  if (value === undefined || !isTfExpr(value))
232
394
  return undefined;
233
395
  if (value.$expr === "resource-attr" && value.type === owner.type && value.label === owner.label && value.path[0] === "stage_ids_by_key") {
234
396
  const segment = value.path[1];
235
397
  if (value.path.length === 2 && typeof segment === "object" && segment !== null && "index" in segment)
236
- return tfLabelToTsLabel(segment.index);
398
+ return segment.index;
237
399
  }
238
- if (value.$expr === "local" && value.name === `${owner.ownerTfLabel}_stage_ids_by_key`) {
400
+ if (value.$expr === "local" && value.name === `${owner.label}_stage_ids_by_key`) {
239
401
  const segment = value.path[0];
240
402
  if (value.path.length === 1 && typeof segment === "object" && segment !== null && "index" in segment)
241
- return tfLabelToTsLabel(segment.index);
403
+ return segment.index;
242
404
  }
243
405
  return undefined;
244
406
  }
245
407
  function aspectRef(value, owner, ctx) {
246
408
  if (resourceRefLabel(value, owner.type) === owner.label)
247
- return pulledRef("app", owner.ownerRefName);
409
+ return pulledRef(scopeOf(owner), owner.ownerRefName);
248
410
  for (const [type, kind] of [["elementum_app", "app"], ["elementum_element", "element"]]) {
249
411
  const resourceLabel = resourceRefLabel(value, type);
250
412
  if (resourceLabel !== undefined)
@@ -4,7 +4,10 @@ export const dynamicLayoutModule = {
4
4
  kind: "dynamic-layout",
5
5
  stream: { role: "streamMember" },
6
6
  authoring: { unit: "inline", bag: "dynamicLayouts" },
7
- parents: [{ parent: "app", child: "dynamic-layout" }],
7
+ parents: [
8
+ { parent: "app", child: "dynamic-layout" },
9
+ { parent: "element", child: "dynamic-layout" },
10
+ ],
8
11
  resource: { shape: "single", resourceType: DYNAMIC_LAYOUT_RESOURCE_TYPE, adoptable: true },
9
12
  data: NO_DATA,
10
13
  lifecycle: NO_LIFECYCLE,
@@ -1,5 +1,5 @@
1
1
  import type { OrgRefLookup, WorkspaceAspect } from "../../engine/build/context.js";
2
- import { type TfBlock, type TfValue } from "../../engine/tf/index.js";
2
+ import { type ChildResourceScope, type TfBlock, type TfValue } from "../../engine/tf/index.js";
3
3
  export interface DynamicLayoutWire {
4
4
  readonly name?: string;
5
5
  readonly description?: string;
@@ -18,10 +18,14 @@ export interface DynamicLayoutWire {
18
18
  export interface DynamicLayoutToTfOptions {
19
19
  readonly ownerRefName: string;
20
20
  readonly ownerTfLabel: string;
21
+ /** Owning stream root kind; defaults to `"app"`. Elements have no stages. */
22
+ readonly scope?: ChildResourceScope;
21
23
  readonly objectId: TfValue;
22
24
  readonly diagnostics: string[];
23
25
  readonly orgRefs: OrgRefLookup;
24
26
  readonly workspaceAspects?: ReadonlyMap<string, WorkspaceAspect>;
25
27
  readonly fieldAddresses?: ReadonlyMap<string, string>;
28
+ /** Widget keys the owner declares, for buttons that run through an authored widget. */
29
+ readonly widgetKeys?: ReadonlySet<string>;
26
30
  }
27
31
  export declare function dynamicLayoutsToTf(layouts: Readonly<Record<string, DynamicLayoutWire>> | undefined, opts: DynamicLayoutToTfOptions): TfBlock[];