@elementumai/edk 0.9.10 → 0.9.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/dist-sdk/src/catalog/factories.d.ts +8 -1
  2. package/dist-sdk/src/catalog/factories.js +13 -1
  3. package/dist-sdk/src/catalog/index.d.ts +2 -2
  4. package/dist-sdk/src/catalog/index.js +1 -1
  5. package/dist-sdk/src/catalog/types.d.ts +19 -2
  6. package/dist-sdk/src/catalog/types.js +1 -0
  7. package/dist-sdk/src/engine/build/context.d.ts +3 -0
  8. package/dist-sdk/src/entities/access-policy/from-tf.d.ts +3 -3
  9. package/dist-sdk/src/entities/access-policy/from-tf.js +27 -8
  10. package/dist-sdk/src/entities/access-policy/to-tf.d.ts +13 -0
  11. package/dist-sdk/src/entities/access-policy/to-tf.js +34 -3
  12. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +13 -7
  13. package/dist-sdk/src/entities/agent-tool/to-tf.js +13 -0
  14. package/dist-sdk/src/entities/app/build.d.ts +15 -2
  15. package/dist-sdk/src/entities/app/build.js +6 -0
  16. package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +13 -3
  17. package/dist-sdk/src/entities/app/from-tf.js +6 -3
  18. package/dist-sdk/src/entities/app/to-tf.js +5 -1
  19. package/dist-sdk/src/entities/automation/from-tf.js +113 -1
  20. package/dist-sdk/src/entities/automation/module.js +1 -0
  21. package/dist-sdk/src/entities/automation/tasks.js +17 -0
  22. package/dist-sdk/src/entities/automation/to-tf.d.ts +8 -0
  23. package/dist-sdk/src/entities/automation/to-tf.js +153 -46
  24. package/dist-sdk/src/entities/automation/types.js +1 -0
  25. package/dist-sdk/src/entities/dashboard/from-tf.js +11 -2
  26. package/dist-sdk/src/entities/dynamic-layout/build.d.ts +2 -1
  27. package/dist-sdk/src/entities/dynamic-layout/dialect.d.ts +8 -0
  28. package/dist-sdk/src/entities/dynamic-layout/dialect.js +12 -0
  29. package/dist-sdk/src/entities/dynamic-layout/from-tf.d.ts +7 -0
  30. package/dist-sdk/src/entities/dynamic-layout/from-tf.js +64 -10
  31. package/dist-sdk/src/entities/dynamic-layout/to-tf.js +54 -6
  32. package/dist-sdk/src/entities/element/build.d.ts +7 -0
  33. package/dist-sdk/src/entities/element/from-tf.js +1 -1
  34. package/dist-sdk/src/entities/element/to-tf.d.ts +1 -1
  35. package/dist-sdk/src/entities/element/to-tf.js +19 -1
  36. package/dist-sdk/src/entities/field/build.d.ts +10 -1
  37. package/dist-sdk/src/entities/field/build.js +2 -1
  38. package/dist-sdk/src/entities/field/calc/index.js +7 -7
  39. package/dist-sdk/src/entities/field/calc/runtime.d.ts +19 -0
  40. package/dist-sdk/src/entities/field/calc/runtime.js +32 -0
  41. package/dist-sdk/src/entities/field/calc/types.d.ts +6 -0
  42. package/dist-sdk/src/entities/file-reader/to-tf.js +10 -2
  43. package/dist-sdk/src/entities/relationship/build.d.ts +14 -7
  44. package/dist-sdk/src/entities/relationship/from-tf.js +14 -14
  45. package/dist-sdk/src/entities/relationship/to-tf.d.ts +1 -0
  46. package/dist-sdk/src/entities/relationship/to-tf.js +18 -0
  47. package/dist-sdk/src/entities/shared/aspect-target-from-tf.d.ts +15 -0
  48. package/dist-sdk/src/entities/shared/aspect-target-from-tf.js +21 -0
  49. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +16 -4
  50. package/dist-sdk/src/entities/skill/tools.d.ts +10 -0
  51. package/dist-sdk/src/entities/skill/tools.js +10 -0
  52. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +7 -0
  53. package/dist-sdk/src/entities/skill-tool/from-tf.js +22 -2
  54. package/dist-sdk/src/entities/skill-tool/to-tf.js +21 -0
  55. package/dist-sdk/src/entities/table/catalog-render.js +2 -1
  56. package/dist-sdk/src/entities/view/from-tf.js +9 -0
  57. package/dist-sdk/src/entities/view/to-tf.d.ts +7 -0
  58. package/dist-sdk/src/entities/view/to-tf.js +34 -5
  59. package/dist-sdk/src/entities/widget/build.d.ts +17 -7
  60. package/dist-sdk/src/entities/widget/from-tf.d.ts +1 -1
  61. package/dist-sdk/src/entities/widget/from-tf.js +132 -18
  62. package/dist-sdk/src/entities/widget/to-tf.d.ts +17 -0
  63. package/dist-sdk/src/entities/widget/to-tf.js +40 -0
  64. package/dist-sdk/src/graph/types.d.ts +8 -0
  65. package/package.json +1 -1
@@ -117,6 +117,24 @@ function resolveTarget(value, where, opts) {
117
117
  };
118
118
  }
119
119
  function resolveRelatedField(value, target, where, opts) {
120
+ if (value?.__kind === "recordIdentity") {
121
+ if (value.target === undefined) {
122
+ opts.diagnostics.push(`${where}: record identity has no target; dropped`);
123
+ return undefined;
124
+ }
125
+ if (typeof value.target === "string") {
126
+ opts.diagnostics.push(`${where}: record identity target must be a typed reference, not a string; dropped`);
127
+ return undefined;
128
+ }
129
+ const identityTarget = resolveTarget(value.target, `${where}.target`, opts);
130
+ if (identityTarget === undefined)
131
+ return undefined;
132
+ if (identityTarget.kind !== target.kind || identityTarget.refName !== target.refName) {
133
+ opts.diagnostics.push(`${where}: record identity target does not match relationship target; dropped`);
134
+ return undefined;
135
+ }
136
+ return target.value;
137
+ }
120
138
  const refName = value?.refName ?? "";
121
139
  if (refName === "") {
122
140
  opts.diagnostics.push(`${where}: field has no refName; dropped`);
@@ -7,3 +7,18 @@ import type { FromTfContext } from "../../engine/pull/context.js";
7
7
  export declare function dataAspectDisplayName(ctx: FromTfContext, kind: "app" | "element", label: string): string | undefined;
8
8
  /** Resolve the stable pulled catalog key for the same foreign lookup. */
9
9
  export declare function dataAspectRefName(ctx: FromTfContext, kind: "app" | "element", label: string, displayName?: string): string | undefined;
10
+ export interface ResolvedAspectTarget {
11
+ readonly key: string;
12
+ readonly name: string;
13
+ readonly namespace?: string;
14
+ /** `key`/`name` are the target's real pulled catalog identity, not a guess. */
15
+ readonly catalogRef?: true;
16
+ }
17
+ /**
18
+ * Resolve a foreign app/element data lookup to the full identity a caller
19
+ * needs to build its own ref shape: the real display name/refName when the
20
+ * target was pulled separately, degrading to a tfLabel-derived guess (with
21
+ * the real namespace still attached) when it wasn't - never a bare guessed
22
+ * name with no namespace, which matches nothing on the platform.
23
+ */
24
+ export declare function resolveDataAspectTarget(ctx: FromTfContext, kind: "app" | "element", dataLabel: string): ResolvedAspectTarget;
@@ -1,3 +1,4 @@
1
+ import { tfLabelToTsLabel } from "../../engine/tf/index.js";
1
2
  /**
2
3
  * Resolve a foreign app/element data lookup to its display name. Ref-only
3
4
  * lookups are intentionally namespace-only, so fall back through the
@@ -37,3 +38,23 @@ export function dataAspectRefName(ctx, kind, label, displayName) {
37
38
  const byName = kind === "app" ? ctx.foreignAppRefNames : ctx.foreignElementRefNames;
38
39
  return name === undefined ? undefined : byName?.get(name);
39
40
  }
41
+ /**
42
+ * Resolve a foreign app/element data lookup to the full identity a caller
43
+ * needs to build its own ref shape: the real display name/refName when the
44
+ * target was pulled separately, degrading to a tfLabel-derived guess (with
45
+ * the real namespace still attached) when it wasn't - never a bare guessed
46
+ * name with no namespace, which matches nothing on the platform.
47
+ */
48
+ export function resolveDataAspectTarget(ctx, kind, dataLabel) {
49
+ const type = kind === "app" ? "elementum_app" : "elementum_element";
50
+ const displayName = dataAspectDisplayName(ctx, kind, dataLabel);
51
+ const refName = dataAspectRefName(ctx, kind, dataLabel, displayName);
52
+ const attrs = ctx.dataAttrs?.(type, dataLabel);
53
+ const namespace = typeof attrs?.namespace === "string" ? attrs.namespace : undefined;
54
+ return {
55
+ key: refName ?? tfLabelToTsLabel(dataLabel),
56
+ name: displayName ?? refName ?? tfLabelToTsLabel(dataLabel),
57
+ ...(namespace !== undefined ? { namespace } : {}),
58
+ ...(refName !== undefined ? { catalogRef: true } : {}),
59
+ };
60
+ }
@@ -51,7 +51,9 @@ export function printSkillV2(skill, opts) {
51
51
  ]),
52
52
  ].sort();
53
53
  const usesUnsafePlatformId = skill.tools.some((tool) => tool.automationRawId !== undefined ||
54
- tool.fields?.some((field) => field.rawFieldId !== undefined && !opts.foreignFieldRefsById?.has(field.rawFieldId)) === true);
54
+ tool.target?.kind === "unresolved" ||
55
+ tool.fields?.some((field) => field.rawFieldId !== undefined && !opts.foreignFieldRefsById?.has(field.rawFieldId)) === true ||
56
+ (tool.filterVariables?.length ?? 0) > 0);
55
57
  const lines = [];
56
58
  lines.push("/**");
57
59
  lines.push(` * ${skill.name}`);
@@ -227,10 +229,13 @@ function printTool(tool, appRefName, crossOrg, foreignAppRefNames, foreignElemen
227
229
  }
228
230
  else if (tool.target?.kind === "unresolved") {
229
231
  // Export couldn't resolve target_id to any portable app/element
230
- // reference (board issue #648) — keep the raw platform id visible and
231
- // cast past the type system instead of silently dropping the tool.
232
+ // reference (board issue #648) — keep the raw platform id visible via
233
+ // the same unsafePlatformId() escape automation/field refs already use,
234
+ // so build round-trips it directly instead of misreading it as a named
235
+ // reference; cast past the type system since the field itself is a
236
+ // strict CatalogRef.
232
237
  const entityKind = tool.typeKey === "searchTable" ? "element" : "app";
233
- lines.push(` ${entityKind}: ${quote(tool.target.uuid)} as any /* TODO: unresolved ${entityKind} - export couldn't resolve target_id to a portable reference; replace with a real ref before deploying */,`);
238
+ lines.push(` ${entityKind}: unsafePlatformId(${quote(tool.target.uuid)}) as any /* TODO: unresolved ${entityKind} - export couldn't resolve target_id to a portable reference; replace with a real ref before deploying */,`);
234
239
  }
235
240
  else if (tool.target !== undefined) {
236
241
  // Board issue #42: the target can be a foreign APP or a foreign
@@ -288,6 +293,13 @@ function printTool(tool, appRefName, crossOrg, foreignAppRefNames, foreignElemen
288
293
  if (tool.limit !== undefined)
289
294
  lines.push(` limit: ${tool.limit},`);
290
295
  }
296
+ if ((tool.typeKey === "searchAspect" || tool.typeKey === "searchTable") && tool.filterVariables !== undefined && tool.filterVariables.length > 0) {
297
+ lines.push(" filterVariables: [");
298
+ for (const variable of tool.filterVariables) {
299
+ lines.push(` { id: unsafePlatformId(${quote(variable.id)}), name: ${quote(variable.name)}, description: ${quote(variable.description)}, required: ${variable.required} },`);
300
+ }
301
+ lines.push(" ],");
302
+ }
291
303
  if (tool.typeKey === "updateRecord" && tool.handleDescription !== undefined) {
292
304
  lines.push(` handleDescription: ${quote(tool.handleDescription)},`);
293
305
  }
@@ -47,6 +47,14 @@ export interface SkillSearchRawIdField {
47
47
  readonly description: string;
48
48
  }
49
49
  export type SkillSearchFieldInput<Target extends ToolTarget = ToolTarget> = SkillSearchField<Target> | SkillSearchRawIdField;
50
+ /** A runtime value supplied by the agent for a search filter variable. */
51
+ export interface SkillFilterVariable {
52
+ /** Stable platform identifier referenced by the filter JSON. */
53
+ readonly id: UnsafePlatformId;
54
+ readonly name: string;
55
+ readonly description: string;
56
+ readonly required: boolean;
57
+ }
50
58
  export interface SkillRecordField<Target extends ToolTarget = ToolTarget> {
51
59
  readonly field: FieldRef<Target["refName"]>;
52
60
  readonly name: string;
@@ -93,6 +101,7 @@ export type SkillSearchRecordsToolOptions<Target extends ToolTarget = ToolTarget
93
101
  readonly fields?: readonly SkillSearchFieldInput<Target>[];
94
102
  /** Maximum number of records the search returns. */
95
103
  readonly limit?: number;
104
+ readonly filterVariables?: readonly SkillFilterVariable[];
96
105
  };
97
106
  export declare function skillSearchRecords<Target extends ToolTarget>(opts: SkillSearchRecordsToolOptions<Target>): SkillTool;
98
107
  /**
@@ -106,6 +115,7 @@ export type SkillSearchTableToolV2<Target extends ElementCatalogRef = ElementCat
106
115
  readonly fields: readonly SkillSearchFieldInput<Target>[];
107
116
  /** Maximum number of records the search returns. */
108
117
  readonly limit?: number;
118
+ readonly filterVariables?: readonly SkillFilterVariable[];
109
119
  };
110
120
  export declare function skillSearchTable<Target extends ElementCatalogRef>(opts: SkillSearchTableToolV2<Target>): SkillTool;
111
121
  export type SkillCreateRecordToolV2<Target extends ToolTarget = ToolTarget> = CommonToolOptions & TargetOption<Target> & {
@@ -3,6 +3,14 @@ import { assertHandleDescriptionNotEmpty } from "../shared/handle-description.js
3
3
  function targetOf(opts) {
4
4
  return ("app" in opts && opts.app !== undefined ? opts.app : opts.element);
5
5
  }
6
+ function filterVariableToken(variable) {
7
+ return {
8
+ id: variable.id.value,
9
+ name: variable.name,
10
+ description: variable.description,
11
+ required: variable.required,
12
+ };
13
+ }
6
14
  function serializeRunAs(runAs) {
7
15
  if ("currentUser" in runAs)
8
16
  return { currentUser: true };
@@ -95,6 +103,7 @@ export function skillSearchRecords(opts) {
95
103
  queryDescription: opts.queryDescription,
96
104
  ...(opts.fields !== undefined ? { fields: opts.fields.map(searchFieldToken) } : {}),
97
105
  ...(opts.limit !== undefined ? { limit: opts.limit } : {}),
106
+ ...(opts.filterVariables !== undefined ? { filterVariables: opts.filterVariables.map(filterVariableToken) } : {}),
98
107
  },
99
108
  });
100
109
  }
@@ -107,6 +116,7 @@ export function skillSearchTable(opts) {
107
116
  queryDescription: opts.queryDescription,
108
117
  fields: opts.fields.map(searchFieldToken),
109
118
  ...(opts.limit !== undefined ? { limit: opts.limit } : {}),
119
+ ...(opts.filterVariables !== undefined ? { filterVariables: opts.filterVariables.map(filterVariableToken) } : {}),
110
120
  },
111
121
  });
112
122
  }
@@ -22,6 +22,12 @@ export interface NormalizedSkillToolField {
22
22
  readonly required?: boolean;
23
23
  readonly defaultValue?: string;
24
24
  }
25
+ export interface NormalizedFilterVariable {
26
+ readonly id: string;
27
+ readonly name: string;
28
+ readonly description: string;
29
+ readonly required: boolean;
30
+ }
25
31
  export type NormalizedSkillToolTarget = {
26
32
  readonly kind: "self";
27
33
  } | {
@@ -56,6 +62,7 @@ export interface NormalizedSkillTool {
56
62
  readonly startMessage?: string;
57
63
  readonly target?: NormalizedSkillToolTarget;
58
64
  readonly fields?: readonly NormalizedSkillToolField[];
65
+ readonly filterVariables?: readonly NormalizedFilterVariable[];
59
66
  readonly queryDescription?: string;
60
67
  readonly limit?: number;
61
68
  readonly handleDescription?: string;
@@ -349,8 +349,27 @@ export function skillToolFromTf(block, owner, ctx) {
349
349
  if ((subType.typeKey === "searchAspect" || subType.typeKey === "searchTable") && attrs["filter"] !== undefined) {
350
350
  ctx.diagnostics.push(`${where}: filter is not supported on the terraform path yet; a rebuilt stream will omit it`);
351
351
  }
352
- if ((subType.typeKey === "searchAspect" || subType.typeKey === "searchTable") && attrs["filter_variables"] !== undefined) {
353
- ctx.diagnostics.push(`${where}: filter_variables are not supported on the terraform path yet; a rebuilt stream will omit them`);
352
+ let filterVariables;
353
+ const rawFilterVariables = attrs["filter_variables"];
354
+ if ((subType.typeKey === "searchAspect" || subType.typeKey === "searchTable") && Array.isArray(rawFilterVariables)) {
355
+ filterVariables = [];
356
+ for (const item of rawFilterVariables) {
357
+ if (typeof item !== "object" || item === null || Array.isArray(item) || isTfExpr(item)) {
358
+ ctx.diagnostics.push(`${where}: filter_variables item has an unrecognized shape; dropped`);
359
+ continue;
360
+ }
361
+ const rec = item;
362
+ if (typeof rec["id"] !== "string" || rec["id"] === "" || typeof rec["name"] !== "string" || typeof rec["description"] !== "string" || typeof rec["required"] !== "boolean") {
363
+ ctx.diagnostics.push(`${where}: filter_variables item is missing a required attribute; dropped`);
364
+ continue;
365
+ }
366
+ filterVariables.push({ id: rec["id"], name: rec["name"], description: rec["description"], required: rec["required"] });
367
+ }
368
+ if (filterVariables.length === 0)
369
+ filterVariables = undefined;
370
+ }
371
+ else if ((subType.typeKey === "searchAspect" || subType.typeKey === "searchTable") && rawFilterVariables !== undefined) {
372
+ ctx.diagnostics.push(`${where}: filter_variables is not a list; dropped`);
354
373
  }
355
374
  let handleDescription;
356
375
  if (subType.typeKey === "updateRecord") {
@@ -366,6 +385,7 @@ export function skillToolFromTf(block, owner, ctx) {
366
385
  ...common,
367
386
  target,
368
387
  ...(fields !== undefined && { fields }),
388
+ ...(filterVariables !== undefined && { filterVariables }),
369
389
  ...((subType.typeKey === "searchAspect" || subType.typeKey === "searchTable") && {
370
390
  queryDescription: optionalString(attrs, "query_description", where, ctx) ?? "",
371
391
  }),
@@ -31,6 +31,19 @@ function serviceAccountIdValue(token, where, ctx) {
31
31
  }
32
32
  /** authoring AppOrElementRef token → target_id value (workspace resource or foreign data ref). */
33
33
  function targetIdValue(token, ctx) {
34
+ // Legacy escape hatch (pre-#889): pull used to print an unresolved target
35
+ // as a bare platform-id string cast (`"<uuid>" as any`) rather than
36
+ // unsafePlatformId(...) — already-pulled workspaces still have this shape
37
+ // on disk and must keep round-tripping directly as target_id.
38
+ if (typeof token === "string") {
39
+ return { value: token, refName: token, kind: "app" };
40
+ }
41
+ // Pull's escape hatch for a target export couldn't resolve to any
42
+ // portable reference (#648) - the platform id round-trips directly as
43
+ // target_id, no name/namespace data lookup needed or even possible.
44
+ if (token.__unsafe === "platformId" && typeof token.value === "string" && token.value !== "") {
45
+ return { value: token.value, refName: token.value, kind: "app" };
46
+ }
34
47
  const refName = token.refName ?? "";
35
48
  const kind = token.__kind === "element" ? "element" : "app";
36
49
  if (kind === "app" && refName === ctx.appRefName) {
@@ -264,6 +277,14 @@ export function skillToolToTf(entry, ctx) {
264
277
  if (inner.limit !== undefined)
265
278
  attrs["result_limit"] = inner.limit;
266
279
  }
280
+ if ((typeKey === "searchAspect" || typeKey === "searchTable") && inner.filterVariables !== undefined && inner.filterVariables.length > 0) {
281
+ attrs["filter_variables"] = inner.filterVariables.map((variable) => ({
282
+ id: typeof variable.id === "string" ? variable.id : variable.id?.value ?? "",
283
+ name: variable.name ?? "",
284
+ description: variable.description ?? "",
285
+ required: variable.required ?? false,
286
+ }));
287
+ }
267
288
  if (inner.fields !== undefined || typeKey === "createRecord" || typeKey === "updateRecord") {
268
289
  const fieldValues = [];
269
290
  for (const f of inner.fields ?? []) {
@@ -24,6 +24,7 @@ export function renderTableCatalogEntry(args) {
24
24
  const colParts = [
25
25
  `name: ${JSON.stringify(column.name)}`,
26
26
  `parent: ${JSON.stringify(parentHandle)}`,
27
+ `parentName: ${JSON.stringify(ref.name)}`,
27
28
  ];
28
29
  if (column.fieldType !== undefined) {
29
30
  colParts.push(`fieldType: ${JSON.stringify(column.fieldType)}`);
@@ -39,7 +40,7 @@ export function renderTableCatalogEntry(args) {
39
40
  if (datamines.length > 0) {
40
41
  extraFactories.push("datamineRef");
41
42
  const parentHandle = named.refName ?? args.keyName;
42
- parts.push(`datamines: { ${datamines.map(([key, datamine]) => `${safeCatalogKey(key)}: datamineRef({ name: ${JSON.stringify(datamine.name)}, parent: ${JSON.stringify(parentHandle)} })`).join(", ")} }`);
43
+ parts.push(`datamines: { ${datamines.map(([key, datamine]) => `${safeCatalogKey(key)}: datamineRef({ name: ${JSON.stringify(datamine.name)}, parent: ${JSON.stringify(parentHandle)}, parentName: ${JSON.stringify(ref.name)} })`).join(", ")} }`);
43
44
  }
44
45
  if (ref.categoryId !== undefined) {
45
46
  parts.push(`categoryId: ${JSON.stringify(ref.categoryId)}`);
@@ -10,6 +10,7 @@ import { reportUnknownAttrs } from "../../engine/pull/attrs.js";
10
10
  import { isTfExpr, scopedLabelToBagKey, tfLabelToTsLabel } from "../../engine/tf/index.js";
11
11
  import { fieldKeyFromTfValue } from "../field/from-tf.js";
12
12
  import { DASHBOARD_RESOURCE_TYPE } from "../dashboard/module.js";
13
+ import { WIDGET_RESOURCE_TYPE } from "../widget/module.js";
13
14
  import { filterFromTf, principalList } from "../access-policy/from-tf.js";
14
15
  import { listViewDensity, } from "./build.js";
15
16
  import { AGENT_VIEW_RESOURCE_TYPE, CALENDAR_VIEW_RESOURCE_TYPE, DASHBOARD_VIEW_RESOURCE_TYPE, GROUP_SECTION_WIRE_TYPE, KNOWN_AGENT_VIEW_ATTRS, KNOWN_CALENDAR_VIEW_ATTRS, KNOWN_DASHBOARD_VIEW_ATTRS, KNOWN_KANBAN_VIEW_ATTRS, KNOWN_LAYOUT_ATTRS, KNOWN_LAYOUT_SECTION_ATTRS, KNOWN_LIST_VIEW_ATTRS, KNOWN_MANAGED_VIEW_ORDER_ATTRS, LIST_VIEW_RESOURCE_TYPE, KANBAN_VIEW_RESOURCE_TYPE, SECTION_TYPE_FROM_WIRE, SYSTEM_FIELD_KEY_BY_ID_ATTR, UPDATE_SECTION_WIRE_TYPE, } from "./types.js";
@@ -307,12 +308,20 @@ function sectionFromTf(raw, ownerLabel, ownerTfLabel, scope, where, ctx) {
307
308
  const fieldIds = rec["field_ids"];
308
309
  if (Array.isArray(fieldIds)) {
309
310
  const fields = [];
311
+ const widgets = [];
310
312
  for (const f of fieldIds) {
313
+ const widgetLabel = resourceRefLabel(f, WIDGET_RESOURCE_TYPE);
314
+ if (widgetLabel !== undefined) {
315
+ widgets.push(scopedLabelToBagKey(ownerTfLabel, widgetLabel, scope));
316
+ continue;
317
+ }
311
318
  const key = fieldRefFromTf(f, ownerLabel, ownerTfLabel, scope, ctx);
312
319
  if (key !== undefined)
313
320
  fields.push(key);
314
321
  }
315
322
  section.fields = fields;
323
+ if (widgets.length > 0)
324
+ section.widgets = widgets;
316
325
  }
317
326
  }
318
327
  else if (wireType === UPDATE_SECTION_WIRE_TYPE && typeof rec["name"] === "string") {
@@ -31,6 +31,11 @@ export interface AppLayoutSectionWire {
31
31
  readonly color?: string;
32
32
  readonly maxColumns?: number;
33
33
  readonly fields?: readonly ViewFieldRefWire[];
34
+ readonly widgets?: readonly {
35
+ readonly __kind?: string;
36
+ readonly refName?: string;
37
+ readonly parent?: string;
38
+ }[];
34
39
  }
35
40
  export interface AppLayoutWire {
36
41
  readonly sections: readonly AppLayoutSectionWire[];
@@ -101,6 +106,8 @@ export interface ViewToTfOptions {
101
106
  readonly orgRefs?: OrgRefLookup;
102
107
  /** Known emitted field addresses keyed by field bag key, for robust reference resolution. */
103
108
  readonly fieldAddresses?: ReadonlyMap<string, string>;
109
+ /** Declared sibling widget keys, for typed classic-layout placement. */
110
+ readonly widgetKeys?: ReadonlySet<string>;
104
111
  /** Degradations land here — reported by the caller, never silent. */
105
112
  readonly diagnostics: string[];
106
113
  }
@@ -14,6 +14,7 @@ import { fieldRefToTfValue as customFieldRefToTfValue } from "../field/to-tf.js"
14
14
  import { filterToTf, principalListToTf } from "../access-policy/to-tf.js";
15
15
  import { SUB_TYPE_BY_AUTHORING_TYPE } from "../field/types.js";
16
16
  import { DASHBOARD_RESOURCE_TYPE } from "../dashboard/module.js";
17
+ import { WIDGET_RESOURCE_TYPE } from "../widget/module.js";
17
18
  import { AGENT_VIEW_RESOURCE_TYPE, CALENDAR_VIEW_RESOURCE_TYPE, DASHBOARD_VIEW_RESOURCE_TYPE, GROUP_SECTION_WIRE_TYPE, LAYOUT_RESOURCE_TYPE, LAYOUT_RESTRICTED_SYSTEM_FIELD_KEYS, LIST_VIEW_RESOURCE_TYPE, KANBAN_VIEW_RESOURCE_TYPE, MANAGED_VIEW_ORDER_RESOURCE_TYPE, SECTION_TYPE_TO_WIRE, SYSTEM_FIELD_ID_ATTR_BY_KEY, UPDATE_SECTION_WIRE_TYPE, } from "./types.js";
18
19
  /** Elements only have `id`/`title` as real system fields (no status/stage/audit fields) — see `element/locals.ts`. */
19
20
  const ELEMENT_SYSTEM_FIELD_KEYS = new Set(["id", "title"]);
@@ -40,7 +41,7 @@ export function viewToTf(layouts, listViews, calendarViews, kanbanViews, dashboa
40
41
  diagnostics.push(`layouts.${stageKey} has no matching authored stage option; dropped`);
41
42
  continue;
42
43
  }
43
- blocks.push(layoutToTf(stageKey, layout, ownerTfLabel, scope, objectId, diagnostics, fieldAddresses));
44
+ blocks.push(layoutToTf(stageKey, layout, ownerRefName, ownerTfLabel, scope, objectId, diagnostics, fieldAddresses, opts.widgetKeys));
44
45
  }
45
46
  const viewAddressByKey = new Map();
46
47
  for (const [viewKey, view] of Object.entries(listViews ?? {})) {
@@ -50,6 +51,7 @@ export function viewToTf(layouts, listViews, calendarViews, kanbanViews, dashboa
50
51
  }
51
52
  const tfLabel = scopedResourceLabel(ownerTfLabel, tsLabelToTfLabel(viewKey), scope);
52
53
  const where = `listViews.${viewKey}`;
54
+ const listColumns = resolveFieldRefs(view.columns ?? [], ownerTfLabel, scope, `${where}.columns`, diagnostics, fieldAddresses);
53
55
  const attrs = {
54
56
  aspect_id: objectId,
55
57
  name: view.name ?? "",
@@ -58,7 +60,11 @@ export function viewToTf(layouts, listViews, calendarViews, kanbanViews, dashboa
58
60
  // defaulting to `true` planned false→true against live views that
59
61
  // disallow create. Platform default when unset on create is still true.
60
62
  allow_record_creation: view.allowRecordCreation ?? true,
61
- columns: resolveFieldRefs(view.columns ?? [], ownerTfLabel, scope, `${where}.columns`, diagnostics, fieldAddresses),
63
+ // ei's own export omits `columns` entirely for a view with none
64
+ // configured rather than emitting an empty array — always including it
65
+ // planned a spurious in-place update on every build (live-confirmed on
66
+ // purchaseorder/eu-sanofi's Calendar/Kanban/List views).
67
+ ...(listColumns.length > 0 ? { columns: listColumns } : {}),
62
68
  density: view.density ?? "STANDARD",
63
69
  rows: view.rows ?? 25,
64
70
  };
@@ -93,11 +99,13 @@ export function viewToTf(layouts, listViews, calendarViews, kanbanViews, dashboa
93
99
  }
94
100
  const tfLabel = scopedResourceLabel(ownerTfLabel, tsLabelToTfLabel(viewKey), scope);
95
101
  const where = `${bagName}.${viewKey}`;
102
+ const bagColumns = resolveFieldRefs(view.columns ?? [], ownerTfLabel, scope, `${where}.columns`, diagnostics, fieldAddresses);
96
103
  const attrs = {
97
104
  aspect_id: objectId,
98
105
  name: view.name ?? "",
99
106
  allow_record_creation: view.allowRecordCreation ?? true,
100
- columns: resolveFieldRefs(view.columns ?? [], ownerTfLabel, scope, `${where}.columns`, diagnostics, fieldAddresses),
107
+ // See the list-view `columns` comment above — same omit-when-empty fix.
108
+ ...(bagColumns.length > 0 ? { columns: bagColumns } : {}),
101
109
  };
102
110
  if (view.displayByField !== undefined) {
103
111
  const displayBy = fieldRefToTfValue(view.displayByField, ownerTfLabel, scope, `${where}.displayByField`, diagnostics, fieldAddresses);
@@ -248,7 +256,7 @@ function managedViewSortToTf(sort, ownerTfLabel, scope, where, diagnostics, fiel
248
256
  }
249
257
  return expr.jsonencode({ orders });
250
258
  }
251
- function layoutToTf(stageKey, layout, ownerTfLabel, scope, objectId, diagnostics, fieldAddresses) {
259
+ function layoutToTf(stageKey, layout, ownerRefName, ownerTfLabel, scope, objectId, diagnostics, fieldAddresses, widgetKeys) {
252
260
  const sections = [];
253
261
  for (const section of layout.sections) {
254
262
  const authoringType = section.type ?? "group";
@@ -285,7 +293,28 @@ function layoutToTf(stageKey, layout, ownerTfLabel, scope, objectId, diagnostics
285
293
  }
286
294
  return true;
287
295
  });
288
- sec.field_ids = resolveFieldRefs(fields, ownerTfLabel, scope, where, diagnostics, fieldAddresses);
296
+ const widgetIds = [];
297
+ for (const [index, widget] of (section.widgets ?? []).entries()) {
298
+ const widgetWhere = `${where}.widgets[${index}]`;
299
+ const key = widget.refName ?? "";
300
+ if (widget.__kind !== "widget" || key === "") {
301
+ diagnostics.push(`${widgetWhere}: expected a typed widget reference; dropped`);
302
+ continue;
303
+ }
304
+ if (widget.parent !== undefined && widget.parent !== ownerRefName) {
305
+ diagnostics.push(`${widgetWhere}: widget belongs to ${JSON.stringify(widget.parent)}, not ${JSON.stringify(ownerRefName)}; dropped`);
306
+ continue;
307
+ }
308
+ if (!widgetKeys?.has(key)) {
309
+ diagnostics.push(`${widgetWhere}: widget ${JSON.stringify(key)} is not declared in this ${scope}; dropped`);
310
+ continue;
311
+ }
312
+ widgetIds.push(expr.resourceAttr(WIDGET_RESOURCE_TYPE, scopedResourceLabel(ownerTfLabel, tsLabelToTfLabel(key), scope), ["id"]));
313
+ }
314
+ sec.field_ids = [
315
+ ...resolveFieldRefs(fields, ownerTfLabel, scope, where, diagnostics, fieldAddresses),
316
+ ...widgetIds,
317
+ ];
289
318
  }
290
319
  else if (wireType === UPDATE_SECTION_WIRE_TYPE && section.name !== undefined) {
291
320
  sec.name = section.name;
@@ -1,4 +1,4 @@
1
- import type { AppOrElementRef, AutomationRef, FieldRef } from "../../catalog/index.js";
1
+ import type { AppOrElementRef, AutomationRef, FieldRef, RecordIdentityRef } from "../../catalog/index.js";
2
2
  import type { WorkflowFieldType } from "../shared/types/field-types.js";
3
3
  import type { Filter } from "../shared/filters/types.js";
4
4
  export type WidgetButtonType = "INLINE" | "PRIMARY" | "SECONDARY";
@@ -8,18 +8,28 @@ export interface WidgetButtonStyle {
8
8
  readonly icon?: string;
9
9
  readonly fullWidth?: boolean;
10
10
  }
11
- export interface RelatedRecordsWidget {
11
+ /**
12
+ * Lists matching records from `target` on this object's record page.
13
+ *
14
+ * The widget only names the target and display columns. The platform finds
15
+ * rows through an authored `relationships[]` join on **this** app/element
16
+ * whose columns join comparable stored values (TEXT→TEXT, or this object's
17
+ * `relationField` → related title/id). Do not join system `"id"` (HANDLE)
18
+ * to a child `relationField`. A child `relationField` / dynamic dropdown
19
+ * with `autoRelate` stores an instance link; it does not populate this widget.
20
+ */
21
+ export interface RelatedRecordsWidget<Target extends AppOrElementRef = AppOrElementRef> {
12
22
  readonly type: "relatedRecords";
13
23
  readonly name: string;
14
- readonly target: AppOrElementRef;
15
- readonly columns?: readonly FieldRef[];
24
+ readonly target: Target;
25
+ readonly columns?: readonly (FieldRef | RecordIdentityRef<Target>)[];
16
26
  readonly rows?: number;
17
27
  }
18
- export interface LinkRecordsWidget extends WidgetButtonStyle {
28
+ export interface LinkRecordsWidget<Target extends AppOrElementRef = AppOrElementRef> extends WidgetButtonStyle {
19
29
  readonly type: "linkRecords";
20
30
  readonly name: string;
21
- readonly target: AppOrElementRef;
22
- readonly columns?: readonly FieldRef[];
31
+ readonly target: Target;
32
+ readonly columns?: readonly (FieldRef | RecordIdentityRef<Target>)[];
23
33
  readonly rows?: number;
24
34
  /** Provider-native filter payload. */
25
35
  readonly filter?: Filter;
@@ -8,4 +8,4 @@ export interface WidgetOwner {
8
8
  readonly ownerTfLabel: string;
9
9
  readonly scope: ChildResourceScope;
10
10
  }
11
- export declare function widgetsFromTf(blocks: readonly TfBlock[], owner: WidgetOwner, ctx: FromTfContext): NormalizedWidget[];
11
+ export declare function widgetsFromTf(blocks: readonly TfBlock[], owner: WidgetOwner, ctx: FromTfContext, dynamicLayoutCompanionLabels?: ReadonlySet<string>): NormalizedWidget[];