@elementumai/edk 0.10.3 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/README.md +11 -7
  2. package/dist-sdk/src/catalog/token.js +2 -1
  3. package/dist-sdk/src/core/wire/ref-serializer.js +26 -1
  4. package/dist-sdk/src/engine/build/context.d.ts +4 -0
  5. package/dist-sdk/src/engine/coverage-gaps.d.ts +2 -0
  6. package/dist-sdk/src/engine/coverage-gaps.js +3 -0
  7. package/dist-sdk/src/engine/ei/json-stream-reader.d.ts +43 -0
  8. package/dist-sdk/src/engine/ei/json-stream-reader.js +234 -0
  9. package/dist-sdk/src/engine/ei/run.d.ts +22 -0
  10. package/dist-sdk/src/engine/ei/run.js +99 -18
  11. package/dist-sdk/src/engine/ei/saved-plan.d.ts +16 -0
  12. package/dist-sdk/src/engine/ei/saved-plan.js +19 -0
  13. package/dist-sdk/src/engine/ei/state.d.ts +1 -1
  14. package/dist-sdk/src/engine/ei/state.js +17 -4
  15. package/dist-sdk/src/engine/progress.d.ts +3 -1
  16. package/dist-sdk/src/engine/progress.js +7 -3
  17. package/dist-sdk/src/engine/pull/authored-address.d.ts +15 -1
  18. package/dist-sdk/src/engine/pull/authored-address.js +180 -29
  19. package/dist-sdk/src/engine/pull/context.d.ts +52 -7
  20. package/dist-sdk/src/engine/pull/context.js +7 -4
  21. package/dist-sdk/src/engine/tf/index.d.ts +3 -2
  22. package/dist-sdk/src/engine/tf/index.js +3 -2
  23. package/dist-sdk/src/engine/tf/labels.d.ts +22 -0
  24. package/dist-sdk/src/engine/tf/labels.js +50 -0
  25. package/dist-sdk/src/engine/tf/model.d.ts +2 -0
  26. package/dist-sdk/src/engine/tf/model.js +26 -0
  27. package/dist-sdk/src/engine/tf/scan.d.ts +22 -0
  28. package/dist-sdk/src/engine/tf/scan.js +123 -0
  29. package/dist-sdk/src/engine/validation.d.ts +2 -0
  30. package/dist-sdk/src/engine/workspace/loader.d.ts +8 -0
  31. package/dist-sdk/src/engine/workspace/loader.js +20 -0
  32. package/dist-sdk/src/entities/access-policy/from-tf.d.ts +17 -0
  33. package/dist-sdk/src/entities/access-policy/from-tf.js +52 -24
  34. package/dist-sdk/src/entities/access-policy/member-list.d.ts +32 -0
  35. package/dist-sdk/src/entities/access-policy/member-list.js +57 -0
  36. package/dist-sdk/src/entities/access-policy/module.js +5 -0
  37. package/dist-sdk/src/entities/access-policy/to-tf.d.ts +4 -3
  38. package/dist-sdk/src/entities/access-policy/to-tf.js +21 -12
  39. package/dist-sdk/src/entities/agent/build.js +7 -5
  40. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +2 -0
  41. package/dist-sdk/src/entities/agent/from-tf.js +13 -3
  42. package/dist-sdk/src/entities/agent/to-tf.d.ts +13 -11
  43. package/dist-sdk/src/entities/agent/to-tf.js +28 -17
  44. package/dist-sdk/src/entities/agent/tools.d.ts +8 -0
  45. package/dist-sdk/src/entities/agent/tools.js +6 -2
  46. package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +2 -0
  47. package/dist-sdk/src/entities/agent-tool/from-tf.js +2 -2
  48. package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +29 -0
  49. package/dist-sdk/src/entities/agent-tool/to-tf.js +65 -3
  50. package/dist-sdk/src/entities/agent-tool/types.d.ts +12 -8
  51. package/dist-sdk/src/entities/agent-tool/types.js +13 -9
  52. package/dist-sdk/src/entities/app/build.d.ts +11 -0
  53. package/dist-sdk/src/entities/app/build.js +1 -0
  54. package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +11 -7
  55. package/dist-sdk/src/entities/app/from-tf.js +19 -9
  56. package/dist-sdk/src/entities/app/to-tf.js +6 -4
  57. package/dist-sdk/src/entities/automation/build.d.ts +2 -7
  58. package/dist-sdk/src/entities/automation/build.js +55 -16
  59. package/dist-sdk/src/entities/automation/deserializer/ast.d.ts +7 -4
  60. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +7 -11
  61. package/dist-sdk/src/entities/automation/from-tf.d.ts +23 -1
  62. package/dist-sdk/src/entities/automation/from-tf.js +456 -34
  63. package/dist-sdk/src/entities/automation/index.d.ts +1 -1
  64. package/dist-sdk/src/entities/automation/module.d.ts +22 -2
  65. package/dist-sdk/src/entities/automation/module.js +273 -58
  66. package/dist-sdk/src/entities/automation/output-field-types.d.ts +8 -0
  67. package/dist-sdk/src/entities/automation/output-field-types.js +20 -0
  68. package/dist-sdk/src/entities/automation/output-key-wire-name.d.ts +24 -2
  69. package/dist-sdk/src/entities/automation/output-key-wire-name.js +72 -3
  70. package/dist-sdk/src/entities/automation/run-target.d.ts +59 -0
  71. package/dist-sdk/src/entities/automation/run-target.js +99 -0
  72. package/dist-sdk/src/entities/automation/script-code.d.ts +9 -0
  73. package/dist-sdk/src/entities/automation/script-code.js +24 -3
  74. package/dist-sdk/src/entities/automation/task-output-labels.d.ts +16 -0
  75. package/dist-sdk/src/entities/automation/task-output-labels.js +49 -0
  76. package/dist-sdk/src/entities/automation/tasks.d.ts +20 -8
  77. package/dist-sdk/src/entities/automation/to-tf.d.ts +8 -3
  78. package/dist-sdk/src/entities/automation/to-tf.js +171 -58
  79. package/dist-sdk/src/entities/automation/triggers.d.ts +22 -3
  80. package/dist-sdk/src/entities/automation/triggers.js +40 -0
  81. package/dist-sdk/src/entities/automation/types.d.ts +21 -0
  82. package/dist-sdk/src/entities/automation/types.js +26 -0
  83. package/dist-sdk/src/entities/dashboard/from-tf.d.ts +11 -1
  84. package/dist-sdk/src/entities/dashboard/from-tf.js +57 -7
  85. package/dist-sdk/src/entities/dashboard/to-tf.js +13 -0
  86. package/dist-sdk/src/entities/dynamic-layout/build.d.ts +7 -2
  87. package/dist-sdk/src/entities/dynamic-layout/from-tf.d.ts +3 -0
  88. package/dist-sdk/src/entities/dynamic-layout/from-tf.js +65 -19
  89. package/dist-sdk/src/entities/dynamic-layout/to-tf.d.ts +4 -2
  90. package/dist-sdk/src/entities/dynamic-layout/to-tf.js +341 -32
  91. package/dist-sdk/src/entities/element/build.d.ts +10 -0
  92. package/dist-sdk/src/entities/element/build.js +1 -0
  93. package/dist-sdk/src/entities/element/from-tf.js +16 -9
  94. package/dist-sdk/src/entities/element/to-tf.js +6 -4
  95. package/dist-sdk/src/entities/field/from-tf.d.ts +24 -0
  96. package/dist-sdk/src/entities/field/from-tf.js +79 -1
  97. package/dist-sdk/src/entities/field/module.js +7 -0
  98. package/dist-sdk/src/entities/field/to-tf.d.ts +30 -1
  99. package/dist-sdk/src/entities/field/to-tf.js +51 -0
  100. package/dist-sdk/src/entities/file-reader/module.js +3 -3
  101. package/dist-sdk/src/entities/file-reader/to-tf.js +3 -3
  102. package/dist-sdk/src/entities/file-reader/types.d.ts +4 -16
  103. package/dist-sdk/src/entities/file-reader/types.js +7 -0
  104. package/dist-sdk/src/entities/org/group.d.ts +1 -0
  105. package/dist-sdk/src/entities/org/group.js +2 -1
  106. package/dist-sdk/src/entities/record-create-form/from-tf.d.ts +8 -0
  107. package/dist-sdk/src/entities/record-create-form/from-tf.js +10 -2
  108. package/dist-sdk/src/entities/record-create-form/to-tf.d.ts +2 -1
  109. package/dist-sdk/src/entities/record-create-form/to-tf.js +14 -2
  110. package/dist-sdk/src/entities/relationship/from-tf.d.ts +8 -0
  111. package/dist-sdk/src/entities/relationship/from-tf.js +88 -10
  112. package/dist-sdk/src/entities/relationship/to-tf.d.ts +3 -2
  113. package/dist-sdk/src/entities/relationship/to-tf.js +79 -8
  114. package/dist-sdk/src/entities/role/from-tf.js +24 -7
  115. package/dist-sdk/src/entities/role/to-tf.js +25 -7
  116. package/dist-sdk/src/entities/service-account/from-tf.js +2 -1
  117. package/dist-sdk/src/entities/service-account/module.js +15 -0
  118. package/dist-sdk/src/entities/service-account/to-tf.js +12 -4
  119. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +1 -1
  120. package/dist-sdk/src/entities/shared/filters/tf-codec.js +12 -7
  121. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +5 -2
  122. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +8 -1
  123. package/dist-sdk/src/entities/skill/from-tf.js +10 -3
  124. package/dist-sdk/src/entities/skill/module.js +44 -2
  125. package/dist-sdk/src/entities/skill/to-tf.d.ts +8 -1
  126. package/dist-sdk/src/entities/skill/to-tf.js +23 -14
  127. package/dist-sdk/src/entities/skill/tools.d.ts +8 -0
  128. package/dist-sdk/src/entities/skill/tools.js +6 -2
  129. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +2 -0
  130. package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +8 -0
  131. package/dist-sdk/src/entities/skill-tool/to-tf.js +6 -2
  132. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.d.ts +10 -2
  133. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.js +18 -4
  134. package/dist-sdk/src/entities/view/custom-view-validate.js +6 -5
  135. package/dist-sdk/src/entities/view/from-tf.d.ts +68 -0
  136. package/dist-sdk/src/entities/view/from-tf.js +503 -25
  137. package/dist-sdk/src/entities/view/module.js +15 -0
  138. package/dist-sdk/src/entities/view/portable.d.ts +11 -0
  139. package/dist-sdk/src/entities/view/portable.js +47 -0
  140. package/dist-sdk/src/entities/view/to-tf.d.ts +4 -1
  141. package/dist-sdk/src/entities/view/to-tf.js +25 -7
  142. package/dist-sdk/src/entities/view/types.js +1 -1
  143. package/dist-sdk/src/entities/widget/build.d.ts +4 -3
  144. package/dist-sdk/src/entities/widget/from-tf.d.ts +3 -0
  145. package/dist-sdk/src/entities/widget/from-tf.js +100 -3
  146. package/dist-sdk/src/entities/widget/to-tf.d.ts +16 -1
  147. package/dist-sdk/src/entities/widget/to-tf.js +77 -14
  148. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +27 -8
  149. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
  150. package/dist-sdk/src/graph/field-resource-types.d.ts +2 -0
  151. package/dist-sdk/src/graph/field-resource-types.js +11 -0
  152. package/dist-sdk/src/graph/index.d.ts +28 -3
  153. package/dist-sdk/src/graph/index.js +12 -2
  154. package/dist-sdk/src/graph/types.d.ts +164 -5
  155. package/package.json +1 -1
@@ -53,7 +53,33 @@ export const TRIGGER_SUB_TYPES = [
53
53
  { typeKey: "slackMessage", resourceType: "elementum_slack_message_trigger", implemented: true },
54
54
  { typeKey: "survey", resourceType: "elementum_survey_trigger", implemented: true },
55
55
  { typeKey: "schedule", resourceType: "elementum_schedule_trigger", implemented: true },
56
+ { typeKey: "temporal", resourceType: "elementum_temporal_trigger", implemented: true },
56
57
  ];
58
+ /**
59
+ * A webhook trigger's request refs are named "Body (<key>)" and
60
+ * "Headers (<key>)": one wire key naming both the `body`/`headers` property
61
+ * of `WebhookTriggerOutput` and the request key under it.
62
+ */
63
+ export const WEBHOOK_REQUEST_REF_PATTERN = /^(Body|Headers) \((.+)\)$/;
64
+ /** The raw request body, `ctx.trigger.body["Plain Text"]`. */
65
+ export const WEBHOOK_RAW_BODY_REF = "Body (Plain Text)";
66
+ /**
67
+ * A webhook request ref that exists only after the platform has seen a sample
68
+ * request, as the authored path (`body["Title"]` is `{ property: "body",
69
+ * key: "Title" }`), or undefined for any other ref. Named body and header keys
70
+ * appear in the trigger's refs only once a sample request has been captured,
71
+ * which only the Elementum UI can do. A newly created webhook trigger
72
+ * publishes just "Body (Plain Text)" and "contentType" (edk#2047), so indexing
73
+ * any other request ref on it fails apply with "Invalid index".
74
+ */
75
+ export function webhookSampleOnlyRef(refKey) {
76
+ if (refKey === WEBHOOK_RAW_BODY_REF)
77
+ return undefined;
78
+ const match = WEBHOOK_REQUEST_REF_PATTERN.exec(refKey);
79
+ if (match === null)
80
+ return undefined;
81
+ return { property: match[1] === "Body" ? "body" : "headers", key: match[2] };
82
+ }
57
83
  /**
58
84
  * Task kinds. All rows are implemented as of `aiFileAnalysis` (the last
59
85
  * holdout — it needs its `elementum_ai_file_reader` target to also round-trip,
@@ -4,9 +4,19 @@ import type { NormalizedDashboard } from "../app/deserializer/normalize.js";
4
4
  export interface DashboardOwner {
5
5
  readonly type: "elementum_app" | "elementum_element";
6
6
  readonly label: string;
7
+ /**
8
+ * The owner's TF label (`preston_high`), which its child resource labels
9
+ * carry (`apps_preston_high_preston_high_board`). Never the camelCase ref:
10
+ * the two differ once the label has an underscore (#2046).
11
+ */
7
12
  readonly ownerTfLabel: string;
8
- readonly ownerRefName?: string;
13
+ /** The owner's catalog ref name (`prestonHigh`), for refs printed to source. */
14
+ readonly ownerRefName: string;
9
15
  readonly scope: ChildResourceScope;
10
16
  readonly ownerType: "APP_ASPECT" | "ELEMENT_ASPECT";
17
+ /** The owner's extracted fields, as views get them, so a widget sort's field resolves and fails closed like a view sort's (#1736, #1991). */
18
+ readonly fieldKeys?: ReadonlySet<string>;
19
+ readonly fieldKeysByName?: ReadonlyMap<string, string | null>;
20
+ readonly unextractedFieldIds?: Set<string>;
11
21
  }
12
22
  export declare function dashboardsFromTf(blocks: readonly TfBlock[], widgetBlocks: readonly TfBlock[], owner: DashboardOwner, ctx: FromTfContext): NormalizedDashboard[];
@@ -2,6 +2,7 @@ import { dataRefLabel, optionalString, plainObject, resourceRefLabel } from "../
2
2
  import { reportUnknownAttrs, stringList } from "../../engine/pull/attrs.js";
3
3
  import { isTfExpr, scopedLabelToBagKey, tfLabelToTsLabel } from "../../engine/tf/index.js";
4
4
  import { filterFromTf } from "../access-policy/from-tf.js";
5
+ import { filterOwnerForAspect } from "../relationship/from-tf.js";
5
6
  import { filterWireToTf } from "../shared/filters/tf-codec.js";
6
7
  import { DASHBOARD_WIDGET_RESOURCE_TYPE } from "../dashboard-widget/module.js";
7
8
  import { DASHBOARD_RESOURCE_TYPE } from "./module.js";
@@ -72,8 +73,8 @@ function dashboardWidgetsFromTf(blocks, dashboardLabel, dashboardKey, owner, ctx
72
73
  return [];
73
74
  }
74
75
  // The chart's own file is named from the app's TF label, so derive the
75
- // key the same way: owner.ownerTfLabel is the camelCase ref, which
76
- // differs for a namespace with underscores (#1731).
76
+ // key the same way, not from the camelCase ref, which differs for a
77
+ // namespace with underscores (#1731).
77
78
  const chartKey = chartRefNameFromTfLabel(owner.label, chartLabel);
78
79
  // The chart extracts later, as an own-file child. If pull skips it and
79
80
  // no authored file for it is kept, build cannot emit this widget, so
@@ -101,7 +102,13 @@ function dashboardWidgetsFromTf(blocks, dashboardLabel, dashboardKey, owner, ctx
101
102
  let sort;
102
103
  if (aspect["sort"] !== undefined) {
103
104
  const targetsOwner = resourceRefLabel(aspect["aspect_id"], owner.type) === owner.label;
104
- const decoded = managedViewSortFromTf(aspect["sort"], owner, `${where}.aspect_widget.sort`, ctx);
105
+ // Only a sort of the owner's own records names the owner's fields, so
106
+ // only that one checks them against the extracted fields; a foreign
107
+ // target's sort is dropped below either way.
108
+ const sortOwner = targetsOwner
109
+ ? owner
110
+ : { type: owner.type, label: owner.label, ownerTfLabel: owner.ownerTfLabel, ownerRefName: owner.ownerRefName, scope: owner.scope, ownerType: owner.ownerType };
111
+ const decoded = managedViewSortFromTf(aspect["sort"], sortOwner, `${where}.aspect_widget.sort`, ctx);
105
112
  if (decoded !== undefined && !targetsOwner && decoded.orders.length > 0) {
106
113
  ctx.diagnostics.push(`${where}.aspect_widget.sort: ordering a foreign target's records has no typed public contract; sort dropped, widget kept`);
107
114
  }
@@ -111,12 +118,55 @@ function dashboardWidgetsFromTf(blocks, dashboardLabel, dashboardKey, owner, ctx
111
118
  }
112
119
  return [{ ...style, type: "records", target,
113
120
  ...(sort !== undefined && { sort }),
114
- ...(aspect["filter"] !== undefined && {
115
- filter: filterFromTf(filterWireToTf(decodeJson(aspect["filter"])), { ...owner, ownerRefName: owner.ownerRefName ?? owner.ownerTfLabel, foreignFieldRefsById: ctx.foreignFieldRefsById }, `${where}.aspect_widget.filter`, ctx),
116
- }),
121
+ ...(aspect["filter"] !== undefined && { filter: widgetFilterFromTf(aspect["filter"], aspect["aspect_id"], owner, `${where}.aspect_widget.filter`, ctx) }),
117
122
  }];
118
123
  });
119
124
  }
125
+ /**
126
+ * The filter ranges over the target's records, so its fields may belong to
127
+ * the target rather than to the dashboard's owner. A raw field id decodes
128
+ * without throwing even when it is not the owner's field, so a decode that
129
+ * leaves one unresolved is only a fallback.
130
+ */
131
+ function widgetFilterFromTf(raw, aspectId, owner, where, ctx) {
132
+ const wire = filterWireToTf(decodeJson(raw));
133
+ const filterOwners = [{ ...owner, foreignFieldRefsById: ctx.foreignFieldRefsById }];
134
+ const targetOwner = aspectId === undefined || resourceRefLabel(aspectId, owner.type) === owner.label ? undefined : filterOwnerForAspect(aspectId, ctx);
135
+ if (targetOwner !== undefined)
136
+ filterOwners.push(targetOwner);
137
+ let failure;
138
+ let best;
139
+ let bestCount = Number.POSITIVE_INFINITY;
140
+ for (const filterOwner of filterOwners) {
141
+ try {
142
+ const decoded = filterFromTf(wire, filterOwner, where, ctx);
143
+ const unresolved = unresolvedRefCount(decoded);
144
+ if (unresolved === 0)
145
+ return decoded;
146
+ // A target field the owner cannot name is unresolved on every owner
147
+ // decode. One id the target also cannot name must not throw away the
148
+ // fields the target did resolve.
149
+ if (unresolved < bestCount) {
150
+ best = decoded;
151
+ bestCount = unresolved;
152
+ }
153
+ }
154
+ catch (error) {
155
+ failure ??= error;
156
+ }
157
+ }
158
+ if (best !== undefined)
159
+ return best;
160
+ throw failure;
161
+ }
162
+ function unresolvedRefCount(value) {
163
+ if (Array.isArray(value))
164
+ return value.reduce((count, item) => count + unresolvedRefCount(item), 0);
165
+ if (typeof value !== "object" || value === null)
166
+ return 0;
167
+ const self = value.kind === "unresolved" ? 1 : 0;
168
+ return self + Object.values(value).reduce((count, item) => count + unresolvedRefCount(item), 0);
169
+ }
120
170
  /** How an unresolved `chart_id` was exported, for the skipped gap. */
121
171
  function unresolvedChartRef(value) {
122
172
  const dataLabel = dataRefLabel(value, CHART_RESOURCE_TYPE);
@@ -146,7 +196,7 @@ function aspectRef(value, owner, ctx) {
146
196
  if (typeof value === "string")
147
197
  return undefined;
148
198
  if (resourceRefLabel(value, owner.type) === owner.label)
149
- return { kind: owner.scope, key: owner.ownerTfLabel, name: owner.ownerTfLabel };
199
+ return { kind: owner.scope, key: owner.ownerRefName, name: owner.ownerRefName };
150
200
  for (const [type, kind] of [["elementum_app", "app"], ["elementum_element", "element"]]) {
151
201
  const resourceLabel = resourceRefLabel(value, type);
152
202
  if (resourceLabel !== undefined)
@@ -3,6 +3,7 @@ import { workspaceAspectKey } from "../../engine/build/context.js";
3
3
  import { filterToTf } from "../access-policy/to-tf.js";
4
4
  import { filterTfToWire } from "../shared/filters/tf-codec.js";
5
5
  import { DASHBOARD_WIDGET_RESOURCE_TYPE } from "../dashboard-widget/module.js";
6
+ import { targetFilterFieldResolver } from "../relationship/to-tf.js";
6
7
  import { resolveForeignRef } from "../shared/foreign-ref.js";
7
8
  import { DASHBOARD_RESOURCE_TYPE } from "./module.js";
8
9
  import { CHART_RESOURCE_TYPE } from "../chart/types.js";
@@ -51,6 +52,17 @@ export function dashboardsToTf(dashboards, opts) {
51
52
  continue;
52
53
  const body = { aspect_id: aspectId };
53
54
  if (widget.filter !== undefined) {
55
+ const foreignField = typeof widget.target === "object" && opts.orgRefs !== undefined && !targetsOwner(widget.target, opts)
56
+ ? targetFilterFieldResolver(widget.target, `${where}.target`, {
57
+ ownerRefName: opts.ownerRefName ?? opts.ownerTfLabel,
58
+ ownerTfLabel: opts.ownerTfLabel,
59
+ scope: opts.scope,
60
+ objectId: opts.ownerId,
61
+ orgRefs: opts.orgRefs,
62
+ ...(opts.workspaceAspects !== undefined && { workspaceAspects: opts.workspaceAspects }),
63
+ diagnostics: opts.diagnostics,
64
+ })
65
+ : undefined;
54
66
  const hclFilter = filterToTf(widget.filter, `${where}.filter`, {
55
67
  ownerTfLabel: opts.ownerTfLabel,
56
68
  appRefName: opts.ownerRefName,
@@ -58,6 +70,7 @@ export function dashboardsToTf(dashboards, opts) {
58
70
  objectId: opts.ownerId,
59
71
  diagnostics: opts.diagnostics,
60
72
  orgRefs: opts.orgRefs,
73
+ ...(foreignField !== undefined && { foreignField }),
61
74
  });
62
75
  body["filter"] = expr.jsonencode(filterTfToWire(hclFilter));
63
76
  }
@@ -1,4 +1,5 @@
1
1
  import type { AgentRef, AppOrElementRef, AutomationRef, FieldRef, WidgetRef } from "../../catalog/index.js";
2
+ import type { UnsafePlatformId } from "../../core/platform-id.js";
2
3
  import type { AppViewFieldRef } from "../app/build.js";
3
4
  import type { Filter } from "../shared/filters/types.js";
4
5
  export type DynamicLayoutTypedValue = {
@@ -305,8 +306,12 @@ export interface AppDynamicLayout {
305
306
  readonly name: string;
306
307
  readonly description?: string;
307
308
  readonly active?: boolean;
308
- /** Optional stage key. Omit for the app-level default DASHBOARD layout. */
309
- readonly stage?: string;
309
+ /**
310
+ * Stage handle. Pull uses `unsafePlatformId(...)` when export could not
311
+ * resolve the stage, so the layout is not replaced. Omit for the app-level
312
+ * default DASHBOARD layout.
313
+ */
314
+ readonly stage?: string | UnsafePlatformId;
310
315
  readonly documentId: string;
311
316
  readonly documentVersion?: string;
312
317
  readonly rootComponent: string;
@@ -2,6 +2,7 @@ import { type FromTfContext } from "../../engine/pull/context.js";
2
2
  import { type ChildResourceScope, type TfBlock } from "../../engine/tf/index.js";
3
3
  import type { NormalizedDynamicLayout } from "../app/deserializer/normalize.js";
4
4
  import { type StageHandleIndex } from "../app/stage-keys.js";
5
+ import { type UnextractedFieldOwner } from "../view/from-tf.js";
5
6
  export interface DynamicLayoutOwner {
6
7
  readonly type: string;
7
8
  readonly label: string;
@@ -11,6 +12,8 @@ export interface DynamicLayoutOwner {
11
12
  readonly scope?: ChildResourceScope;
12
13
  /** The owning app's stage handles, so pull never writes another stage's handle (#1136). */
13
14
  readonly stageHandles?: StageHandleIndex;
15
+ /** The owner's extracted fields, so a field pull did not extract keeps its platform id (#1966). */
16
+ readonly unextracted?: UnextractedFieldOwner;
14
17
  }
15
18
  export declare function dynamicLayoutsFromTf(blocks: readonly TfBlock[], owner: DynamicLayoutOwner, ctx: FromTfContext): NormalizedDynamicLayout[];
16
19
  /**
@@ -1,5 +1,6 @@
1
- import { dataRefLabel, optionalString, plainObject, resourceRefLabel } from "../../engine/pull/context.js";
2
- import { isTfExpr, scopedLabelToBagKey, tfLabelToTsLabel, } from "../../engine/tf/index.js";
1
+ import { unsafePlatformId } from "../../core/platform-id.js";
2
+ import { dataRefLabel, optionalString, plainObject, reportAuthoringBlocker, resourceRefLabel } from "../../engine/pull/context.js";
3
+ import { isTfExpr, isUuid, scopedLabelToBagKey, tfLabelToTsLabel, } from "../../engine/tf/index.js";
3
4
  import { filterFromTf } from "../access-policy/from-tf.js";
4
5
  import { fieldKeyFromTfValue } from "../field/from-tf.js";
5
6
  import { filterOwnerForAspect } from "../relationship/from-tf.js";
@@ -7,6 +8,7 @@ import { filterWireToTf } from "../shared/filters/tf-codec.js";
7
8
  import { resolveDataAspectTarget } from "../shared/aspect-target-from-tf.js";
8
9
  import { WIDGET_RESOURCE_TYPE } from "../widget/module.js";
9
10
  import { lostStageMessage, pulledStageHandle } from "../app/stage-keys.js";
11
+ import { unextractedFieldRefId } from "../view/from-tf.js";
10
12
  import { DYNAMIC_LAYOUT_RESOURCE_TYPE } from "./module.js";
11
13
  import { DYNAMIC_LAYOUT_COMPARISON_KEYS, DYNAMIC_LAYOUT_FIELD_COMPONENT_WIRE_KEY_BY_PUBLIC_KEY, dynamicLayoutCompanionWidgetLabel, } from "./dialect.js";
12
14
  const KNOWN_ATTRS = new Set([
@@ -81,18 +83,26 @@ function dynamicLayoutFromTf(block, owner, ctx) {
81
83
  ctx.releaseIfManaged?.push(`${DYNAMIC_LAYOUT_RESOURCE_TYPE}.${block.label ?? ""}`);
82
84
  return undefined;
83
85
  }
84
- const resolvedStageKey = stageKey(block.attrs["stage_id"], owner, ctx, `${where}.stage_id`);
85
- if (block.attrs["stage_id"] !== undefined && stageIndex(block.attrs["stage_id"], owner) === undefined) {
86
+ const stageValue = block.attrs["stage_id"];
87
+ const rawStageId = typeof stageValue === "string" && isUuid(stageValue) ? stageValue : undefined;
88
+ const resolvedStageKey = stageKey(stageValue, owner, ctx, `${where}.stage_id`);
89
+ if (stageValue !== undefined && stageIndex(stageValue, owner) === undefined && rawStageId === undefined) {
86
90
  ctx.diagnostics.push(`${where}: stage_id has an unrecognized shape; layout kept unscoped instead of guessing`);
87
91
  }
92
+ if (rawStageId !== undefined && resolvedStageKey === undefined) {
93
+ ctx.diagnostics.push(`${where}: stage_id ${JSON.stringify(rawStageId)} could not be resolved to a stage handle; kept with unsafePlatformId so the layout is not replaced`);
94
+ }
95
+ const identity = layoutIdentity(block, owner, ctx, where, resolvedStageKey ?? rawStageId);
96
+ if (identity === undefined)
97
+ return undefined;
88
98
  const layout = {
89
- name: optionalString(block.attrs, "name", where, ctx) ?? "",
99
+ name: identity.name,
90
100
  ...(typeof block.attrs["description"] === "string" && { description: block.attrs["description"] }),
91
101
  ...(typeof block.attrs["active"] === "boolean" && { active: block.attrs["active"] }),
92
- ...(resolvedStageKey !== undefined && { stage: resolvedStageKey }),
93
- documentId: optionalString(block.attrs, "document_id", where, ctx) ?? "",
102
+ ...(resolvedStageKey !== undefined ? { stage: resolvedStageKey } : rawStageId !== undefined ? { stage: unsafePlatformId(rawStageId) } : {}),
103
+ documentId: identity.documentId,
94
104
  ...(typeof block.attrs["document_version"] === "string" && { documentVersion: block.attrs["document_version"] }),
95
- rootComponent: optionalString(block.attrs, "root_component", where, ctx) ?? "",
105
+ rootComponent: identity.rootComponent,
96
106
  components: componentMap(componentsRaw, scopedLabelToBagKey(owner.ownerTfLabel, block.label ?? "", scopeOf(owner)), owner, ctx, where),
97
107
  };
98
108
  const conditions = plainObject(block.attrs["conditions"]);
@@ -115,6 +125,37 @@ function dynamicLayoutFromTf(block, owner, ctx) {
115
125
  layout,
116
126
  };
117
127
  }
128
+ /** The attributes the provider requires non-empty, by public key. */
129
+ const LAYOUT_IDENTITY_ATTRS = [["name", "name"], ["documentId", "document_id"], ["rootComponent", "root_component"]];
130
+ /**
131
+ * The layout's name, document id and root component. The provider rejects an
132
+ * empty name and a blank (whitespace-only) document_id or root_component, so pull fails closed naming the layout instead of writing `""`
133
+ * that adoption and every plan then reject (#2052). Export fills a UI-built
134
+ * layout's blank header from its platform id (#1220), so this only fires
135
+ * when that fill was lost.
136
+ */
137
+ function layoutIdentity(block, owner, ctx, where, stage) {
138
+ const values = LAYOUT_IDENTITY_ATTRS.map(([, attr]) => optionalString(block.attrs, attr, where, ctx));
139
+ const [name, documentId, rootComponent] = values;
140
+ // name: exact "" only (LengthAtLeast(1) allows whitespace). document_id and
141
+ // root_component: the provider's Validate trims them and rejects blank at plan time.
142
+ const blank = [name === undefined || name === "", documentId === undefined || documentId.trim() === "", rootComponent === undefined || rootComponent.trim() === ""];
143
+ if (!blank.includes(true) && name !== undefined && documentId !== undefined && rootComponent !== undefined) {
144
+ return { name, documentId, rootComponent };
145
+ }
146
+ const missing = LAYOUT_IDENTITY_ATTRS.filter((_, index) => blank[index]).map(([, attr]) => attr);
147
+ const address = `${DYNAMIC_LAYOUT_RESOURCE_TYPE}.${block.label ?? ""}`;
148
+ const id = ctx.importId(address);
149
+ reportAuthoringBlocker(ctx, {
150
+ address,
151
+ description: `${where}: dynamic layout ${JSON.stringify(name ?? "")}${id === undefined ? "" : ` (import id ${id})`} on ${scopeOf(owner)} ` +
152
+ `${owner.ownerRefName}${stage === undefined ? "" : `, stage ${JSON.stringify(stage)}`} has no ${missing.join(", ")}. ` +
153
+ "The provider requires a non-empty name, document_id and root_component, so writing \"\" would make adoption and every plan fail.",
154
+ remedy: "Export fills a UI-built layout's blank document header from the layout's platform id. Pull again with the latest EDK; " +
155
+ "if it persists, report it to the EDK maintainers with this message.",
156
+ });
157
+ return undefined;
158
+ }
118
159
  function scopeOf(owner) {
119
160
  return owner.scope ?? "app";
120
161
  }
@@ -127,7 +168,7 @@ function componentMap(values, layoutKey, owner, ctx, where) {
127
168
  if (field === undefined)
128
169
  continue;
129
170
  if (field["fieldId"] !== undefined) {
130
- field["field"] = fieldKey(field["fieldId"], owner, ctx, `${where}.components.${id}.${publicKey}`);
171
+ field["field"] = fieldKey(field["fieldId"], owner, ctx, `${where}.components.${id}.${publicKey}`, `${where}.components.${id}`);
131
172
  delete field["fieldId"];
132
173
  }
133
174
  if (publicKey !== wireKey) {
@@ -137,8 +178,8 @@ function componentMap(values, layoutKey, owner, ctx, where) {
137
178
  }
138
179
  const update = plainUnknownObject(component["updateBlock"]);
139
180
  if (update !== undefined && Array.isArray(update["fieldIds"])) {
140
- update["fields"] = update["fieldIds"].flatMap((v) => {
141
- const key = fieldKey(v, owner, ctx, `${where}.components.${id}.updateBlock`);
181
+ update["fields"] = update["fieldIds"].flatMap((v, index) => {
182
+ const key = fieldKey(v, owner, ctx, `${where}.components.${id}.updateBlock`, `${where}.components.${id}.update_block.field_ids[${index}]`);
142
183
  return key === undefined ? [] : [key];
143
184
  });
144
185
  delete update["fieldIds"];
@@ -205,11 +246,11 @@ function componentMap(values, layoutKey, owner, ctx, where) {
205
246
  const input = plainUnknownObject(raw);
206
247
  if (input === undefined || !Array.isArray(input["fieldRefParams"]))
207
248
  continue;
208
- input["fieldRefParams"] = input["fieldRefParams"].flatMap((param) => {
249
+ input["fieldRefParams"] = input["fieldRefParams"].flatMap((param, paramIndex) => {
209
250
  const entry = plainUnknownObject(param);
210
251
  const field = entry === undefined
211
252
  ? undefined
212
- : fieldKey(entry["fieldId"], owner, ctx, `${where}.components.${id}.automationButton.inputs[${index}]`);
253
+ : fieldKey(entry["fieldId"], owner, ctx, `${where}.components.${id}.automationButton.inputs[${index}]`, `${where}.components.${id}.automation_button.inputs[${index}].field_ref_params[${paramIndex}]`);
213
254
  return field === undefined ? [] : [{ name: entry["name"], field }];
214
255
  });
215
256
  }
@@ -334,7 +375,7 @@ function conditionMap(values, owner, ctx, where) {
334
375
  const comparison = plainUnknownObject(condition[key]);
335
376
  if (comparison === undefined || comparison["fieldId"] === undefined)
336
377
  continue;
337
- comparison["field"] = fieldKey(comparison["fieldId"], owner, ctx, `${where}.conditions.${id}.${key}`);
378
+ comparison["field"] = fieldKey(comparison["fieldId"], owner, ctx, `${where}.conditions.${id}.${key}`, `${where}.conditions.${id}`);
338
379
  delete comparison["fieldId"];
339
380
  const value = plainUnknownObject(comparison["value"]);
340
381
  const stringValue = value?.["string"];
@@ -361,14 +402,14 @@ function saveGroupMap(values, owner, ctx, where) {
361
402
  for (const [id, raw] of Object.entries(values)) {
362
403
  const group = camelObject(plainObject(raw) ?? {});
363
404
  if (Array.isArray(group["fieldIds"])) {
364
- group["fields"] = group["fieldIds"].flatMap((v) => {
365
- const key = fieldKey(v, owner, ctx, `${where}.saveGroups.${id}`);
405
+ group["fields"] = group["fieldIds"].flatMap((v, index) => {
406
+ const key = fieldKey(v, owner, ctx, `${where}.saveGroups.${id}`, `${where}.save_groups.${id}.field_ids[${index}]`);
366
407
  return key === undefined ? [] : [key];
367
408
  });
368
409
  delete group["fieldIds"];
369
410
  }
370
411
  if (Array.isArray(group["validations"])) {
371
- group["validations"] = group["validations"].map((v, i) => fieldValidation(plainUnknownObject(v) ?? {}, owner, ctx, `${where}.saveGroups.${id}.validations[${i}]`));
412
+ group["validations"] = group["validations"].map((v, i) => fieldValidation(plainUnknownObject(v) ?? {}, owner, ctx, `${where}.save_groups.${id}.validations[${i}]`));
372
413
  }
373
414
  out[id] = group;
374
415
  }
@@ -391,8 +432,13 @@ function dependency(value, owner, ctx, where) {
391
432
  delete out["targetFieldId"];
392
433
  return out;
393
434
  }
394
- function fieldKey(value, owner, ctx, where) {
395
- const key = fieldKeyFromTfValue(value, owner.ownerRefName, owner.ownerTfLabel, scopeOf(owner), ctx);
435
+ /** `site` names the whole entry a field with no id fails the pull for (#1978); it defaults to `where`. */
436
+ function fieldKey(value, owner, ctx, where, site = where) {
437
+ const resolved = fieldKeyFromTfValue(value, owner.ownerRefName, owner.ownerTfLabel, scopeOf(owner), ctx);
438
+ // A field pull did not extract keeps its platform id: its key would print
439
+ // as nothing and build would drop the entry (#1966). With no id the pull
440
+ // fails, naming the entry (#1978).
441
+ const key = owner.unextracted === undefined ? resolved : unextractedFieldRefId(value, resolved, owner.unextracted, ctx, site);
396
442
  if (key === undefined) {
397
443
  ctx.diagnostics.push(`${where}: field reference ${JSON.stringify(value)} is not resolvable; dropped`);
398
444
  }
@@ -1,10 +1,12 @@
1
1
  import type { OrgRefLookup, WorkspaceAspect } from "../../engine/build/context.js";
2
2
  import { type ChildResourceScope, type TfBlock, type TfValue } from "../../engine/tf/index.js";
3
+ import { type UnsafePlatformId } from "../../core/platform-id.js";
4
+ import { type BuiltWidgets } from "../widget/to-tf.js";
3
5
  export interface DynamicLayoutWire {
4
6
  readonly name?: string;
5
7
  readonly description?: string;
6
8
  readonly active?: boolean;
7
- readonly stage?: string;
9
+ readonly stage?: string | UnsafePlatformId;
8
10
  readonly documentId?: string;
9
11
  readonly documentVersion?: string;
10
12
  readonly rootComponent?: string;
@@ -27,7 +29,7 @@ export interface DynamicLayoutToTfOptions {
27
29
  readonly workspaceAspects?: ReadonlyMap<string, WorkspaceAspect>;
28
30
  readonly fieldAddresses?: ReadonlyMap<string, string>;
29
31
  /** Widget keys the owner declares, for buttons that run through an authored widget. */
30
- readonly widgetKeys?: ReadonlySet<string>;
32
+ readonly widgets?: BuiltWidgets;
31
33
  /** Stage handle tfLabel → real `stage_ids_by_key` key, when they differ (#1136). */
32
34
  readonly stageKeyByTfLabel?: ReadonlyMap<string, string>;
33
35
  }