@elementumai/edk 0.10.3 → 0.10.4

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 (30) hide show
  1. package/dist-sdk/src/engine/pull/context.d.ts +15 -5
  2. package/dist-sdk/src/engine/tf/index.d.ts +1 -0
  3. package/dist-sdk/src/engine/tf/index.js +1 -0
  4. package/dist-sdk/src/engine/tf/scan.d.ts +22 -0
  5. package/dist-sdk/src/engine/tf/scan.js +123 -0
  6. package/dist-sdk/src/engine/workspace/loader.d.ts +8 -0
  7. package/dist-sdk/src/engine/workspace/loader.js +20 -0
  8. package/dist-sdk/src/entities/agent/to-tf.d.ts +13 -11
  9. package/dist-sdk/src/entities/agent/to-tf.js +17 -12
  10. package/dist-sdk/src/entities/agent-tool/from-tf.js +2 -2
  11. package/dist-sdk/src/entities/agent-tool/to-tf.js +9 -0
  12. package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +6 -0
  13. package/dist-sdk/src/entities/app/from-tf.js +4 -0
  14. package/dist-sdk/src/entities/automation/build.js +12 -2
  15. package/dist-sdk/src/entities/automation/module.js +39 -11
  16. package/dist-sdk/src/entities/automation/output-field-types.d.ts +8 -0
  17. package/dist-sdk/src/entities/automation/output-field-types.js +20 -0
  18. package/dist-sdk/src/entities/automation/output-key-wire-name.d.ts +2 -0
  19. package/dist-sdk/src/entities/automation/output-key-wire-name.js +18 -0
  20. package/dist-sdk/src/entities/automation/to-tf.d.ts +7 -0
  21. package/dist-sdk/src/entities/automation/to-tf.js +69 -18
  22. package/dist-sdk/src/entities/element/from-tf.js +3 -1
  23. package/dist-sdk/src/entities/skill/module.js +28 -2
  24. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.d.ts +2 -0
  25. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.js +6 -2
  26. package/dist-sdk/src/entities/view/custom-view-validate.js +6 -5
  27. package/dist-sdk/src/entities/view/from-tf.d.ts +8 -0
  28. package/dist-sdk/src/entities/view/from-tf.js +125 -21
  29. package/dist-sdk/src/graph/types.d.ts +7 -0
  30. package/package.json +1 -1
@@ -13,7 +13,7 @@ import { workspaceServiceAccountAppResolver } from "../service-account/workspace
13
13
  import { foreignFieldDataLabel, resolveForeignRef } from "../shared/foreign-ref.js";
14
14
  import { filterToTf as serializeFilterToTf } from "../shared/filters/tf-codec.js";
15
15
  import { referenceValueTypeForField } from "../shared/filters/index.js";
16
- import { API_TASK_REF_AUTHORING_NAMES, API_TASK_REF_WIRE_NAMES, executeScriptRefsIndex, OUTPUT_KEY_CANONICAL, OUTPUT_KEY_WIRE_NAME } from "./output-key-wire-name.js";
16
+ import { aiCompletionRefsIndex, API_TASK_REF_AUTHORING_NAMES, API_TASK_REF_WIRE_NAMES, executeScriptRefsIndex, OUTPUT_KEY_CANONICAL, OUTPUT_KEY_WIRE_NAME } from "./output-key-wire-name.js";
17
17
  import { outputFieldTypesFromScriptSchema, scriptOutputReferenceIsDeclared } from "./output-field-types.js";
18
18
  import { RESOURCE_TYPE_TO_EXECUTOR, TASK_OUTPUT_CONTRACTS } from "./generated/task-output-contracts.js";
19
19
  import { CONNECTOR_ORG_BAG } from "../org/connector.js";
@@ -1209,7 +1209,7 @@ function calculationTaskRefName(targetType, name, taskRefKey, refs) {
1209
1209
  const fieldKey = segments[1];
1210
1210
  return [
1211
1211
  "record.",
1212
- calculationRawFieldId(fieldKey) ?? calculationRecordFieldId(fieldKey, calculationFieldScope(taskRefKey, refs)),
1212
+ calculationRawFieldId(fieldKey) ?? calculationFoundRecordFieldId(fieldKey, taskRefKey, refs),
1213
1213
  suffix.length > 0 ? `.${suffix}` : "",
1214
1214
  ];
1215
1215
  }
@@ -1219,26 +1219,59 @@ function calculationTaskRefName(targetType, name, taskRefKey, refs) {
1219
1219
  }
1220
1220
  return [refName];
1221
1221
  }
1222
+ /**
1223
+ * The calc-engine field id of a found record's field. A field of an aspect in
1224
+ * this build is its resource id. A sibling the workspace authors but this
1225
+ * build leaves out (pull builds only the pulled root, #1763) is read through
1226
+ * the same `data.elementum_field` lookup ei's export declares for it; the
1227
+ * whole-workspace build, which has the sibling, addresses its resource.
1228
+ */
1229
+ function calculationFoundRecordFieldId(fieldKey, taskRefKey, refs) {
1230
+ const taskApp = refs.recordFieldContext?.taskAppRefNameByRefKey?.[taskRefKey];
1231
+ const recordTargetKind = refs.tasks.get(taskRefKey)?.recordTarget?.__kind;
1232
+ const kind = refs.recordFieldContext?.taskAppKindByRefKey?.[taskRefKey] ??
1233
+ (recordTargetKind === "app" || recordTargetKind === "element" ? recordTargetKind : undefined);
1234
+ // An app and an element may share a refName, so "outside this build" and
1235
+ // "authored" are both checked by kind. (The owner check and the display-name
1236
+ // map below are still keyed by refName only.)
1237
+ const outsideBuild = taskApp !== undefined && taskApp !== refs.owner.appRefName && kind !== undefined &&
1238
+ refs.owner.workspaceAspects !== undefined && !refs.owner.workspaceAspects.has(workspaceAspectKey(kind, taskApp));
1239
+ if (!outsideBuild)
1240
+ return calculationRecordFieldId(fieldKey, calculationFieldScope(taskRefKey, refs));
1241
+ if (refs.owner.authoredAspectKeys?.has(workspaceAspectKey(kind, taskApp)) !== true)
1242
+ throw calculationNotAuthoredError(taskApp);
1243
+ const lookup = foreignFoundRecordFieldId(fieldKey, taskRefKey, refs);
1244
+ if (lookup !== undefined)
1245
+ return lookup;
1246
+ if (refs.fieldNamesByAppRefName?.get(taskApp) !== undefined) {
1247
+ throw new EntityTfError(`automation calculation targets field "${fieldKey}" which does not exist in app "${taskApp}"`);
1248
+ }
1249
+ throw new EntityTfError(`automation calculation reads field "${fieldKey}" of "${taskApp}", which is authored but outside this build, ` +
1250
+ `and its field names are not in the workspace catalog — run \`elementum generate\` and retry`);
1251
+ }
1222
1252
  /**
1223
1253
  * The aspect whose fields a task's `record.<field>` output belongs to. A
1224
1254
  * cross-aspect `recordSearch` reads the SEARCHED aspect's fields, and the
1225
- * calc engine wants their ids, so that aspect must be part of this build —
1226
- * a `data.elementum_app` stub carries display names but no field resources.
1255
+ * calc engine wants their ids, so that aspect must be authored in this
1256
+ * workspace — a `data.elementum_app` stub carries display names but no field
1257
+ * resources.
1227
1258
  */
1228
1259
  function calculationFieldScope(taskRefKey, refs) {
1229
1260
  const taskApp = refs.recordFieldContext?.taskAppRefNameByRefKey?.[taskRefKey];
1230
1261
  if (taskApp === undefined || taskApp === refs.owner.appRefName)
1231
1262
  return refs.owner;
1232
1263
  const fieldAddresses = refs.fieldAddressesByAppRefName?.get(taskApp);
1233
- if (fieldAddresses === undefined) {
1234
- throw new EntityTfError(`automation calculation reads a field of "${taskApp}", but that app/element is not authored in ` +
1235
- `this workspace — the calc engine addresses a found record's field by field id, which only a ` +
1236
- `built aspect can supply`);
1237
- }
1264
+ if (fieldAddresses === undefined)
1265
+ throw calculationNotAuthoredError(taskApp);
1238
1266
  const aspect = refs.owner.workspaceAspects?.get(workspaceAspectKey("app", taskApp))
1239
1267
  ?? refs.owner.workspaceAspects?.get(workspaceAspectKey("element", taskApp));
1240
1268
  return { appRefName: taskApp, appTfLabel: aspect?.tfLabel ?? refs.owner.appTfLabel, fieldAddresses };
1241
1269
  }
1270
+ function calculationNotAuthoredError(taskApp) {
1271
+ return new EntityTfError(`automation calculation reads a field of "${taskApp}", but that app/element is not authored in ` +
1272
+ `this workspace — the calc engine addresses a found record's field by field id, which only a ` +
1273
+ `built aspect can supply`);
1274
+ }
1242
1275
  const FOUND_RECORD_TASK_TYPES = new Set([
1243
1276
  "elementum_record_search_task",
1244
1277
  "elementum_create_record_task",
@@ -1268,13 +1301,31 @@ function foundRecordFieldReferenceName(targetType, name, taskRefKey, refs) {
1268
1301
  }
1269
1302
  }
1270
1303
  function foreignFoundRecordFieldReferenceName(segments, taskRefKey, refs) {
1304
+ // Reached only when the field id could not be resolved above. An
1305
+ // updateField record of an aspect the workspace does not author keeps the
1306
+ // display-label form it had before updateField carried a `recordTarget`; one
1307
+ // of an authored sibling outside this build already resolved to its
1308
+ // `data.elementum_field` lookup (the field-id form ei exports, #1763).
1309
+ if (refs.tasks.get(taskRefKey)?.type === TASK_RESOURCES.updateField)
1310
+ return undefined;
1311
+ const fieldId = foreignFoundRecordFieldId(segments[1], taskRefKey, refs);
1312
+ if (fieldId === undefined)
1313
+ return undefined;
1314
+ const suffix = segments.slice(2).join(".");
1315
+ return ["record.", fieldId, ...(suffix.length > 0 ? [`.${suffix}`] : [])];
1316
+ }
1317
+ /**
1318
+ * The `data.elementum_field` id of a found record's field when the record's
1319
+ * app/element is outside this build. Undefined when the task's target is in
1320
+ * this build or the field's display name is unknown.
1321
+ */
1322
+ function foreignFoundRecordFieldId(fieldKey, taskRefKey, refs) {
1271
1323
  const target = refs.tasks.get(taskRefKey)?.recordTarget;
1272
1324
  if (target === undefined || (target.__kind !== "app" && target.__kind !== "element") || target.name === undefined) {
1273
1325
  return undefined;
1274
1326
  }
1275
1327
  if (refs.owner.workspaceAspects?.has(workspaceAspectKey(target.__kind, target.refName)))
1276
1328
  return undefined;
1277
- const fieldKey = segments[1];
1278
1329
  const fieldName = refs.fieldNamesByAppRefName?.get(target.refName)?.get(fieldKey);
1279
1330
  if (fieldName === undefined)
1280
1331
  return undefined;
@@ -1287,12 +1338,7 @@ function foreignFoundRecordFieldReferenceName(segments, taskRefKey, refs) {
1287
1338
  parentName: target.name,
1288
1339
  ...(target.namespace !== undefined ? { parentNamespace: target.namespace } : {}),
1289
1340
  };
1290
- const suffix = segments.slice(2).join(".");
1291
- return [
1292
- "record.",
1293
- expr.dataAttr("elementum_field", registerForeignFieldLookup(fieldToken, refs.owner, refs.dataBlocks), ["id"]),
1294
- ...(suffix.length > 0 ? [`.${suffix}`] : []),
1295
- ];
1341
+ return expr.dataAttr("elementum_field", registerForeignFieldLookup(fieldToken, refs.owner, refs.dataBlocks), ["id"]);
1296
1342
  }
1297
1343
  function calculationTriggerMustache(name, refs) {
1298
1344
  const onDemandName = onDemandTriggerRefName(name, refs);
@@ -1685,6 +1731,9 @@ function taskOutputWireRefKey(targetType, name, taskRefKey, refs) {
1685
1731
  if (scriptIndex !== undefined)
1686
1732
  return scriptIndex;
1687
1733
  }
1734
+ const aiIndex = aiCompletionRefsIndex(targetType, name);
1735
+ if (aiIndex !== undefined)
1736
+ return aiIndex;
1688
1737
  return taskWireRefName(name, taskRefKey, refs);
1689
1738
  }
1690
1739
  /** The platform's own on-demand "Triggered By" refs (live refs-map keys). */
@@ -2820,7 +2869,7 @@ function filterReferenceToTf(value, refs, role = "value", realType, operator) {
2820
2869
  }
2821
2870
  const refsIndex = task.type === TASK_RESOURCES.executeScript
2822
2871
  ? executeScriptRefsIndex(wireName) ?? wireName
2823
- : wireName;
2872
+ : aiCompletionRefsIndex(task.type, wireName) ?? wireName;
2824
2873
  return expr.resourceAttr(task.type, task.label, ["refs", { index: refsIndex }]);
2825
2874
  }
2826
2875
  const recordFieldName = foundRecordFieldReferenceName(task.type, value.name, value.taskRefKey, refs);
@@ -3686,6 +3735,7 @@ export function automationToTf(entity, ctx) {
3686
3735
  activeAutomationRefNames: ctx.activeAutomationRefNames,
3687
3736
  ...(ctx.elementsWithoutAuditFields !== undefined ? { elementsWithoutAuditFields: ctx.elementsWithoutAuditFields } : {}),
3688
3737
  ...(ctx.fieldAddressesByAppRefName !== undefined ? { fieldAddressesByAppRefName: ctx.fieldAddressesByAppRefName } : {}),
3738
+ ...(ctx.authoredAspectKeys !== undefined ? { authoredAspectKeys: ctx.authoredAspectKeys } : {}),
3689
3739
  recordLacksAuditFields: ctx.parentScope === "element" && ctx.ownerAuditFields !== true,
3690
3740
  };
3691
3741
  if (entity.kind !== "automation")
@@ -3801,7 +3851,8 @@ export function automationToTf(entity, ctx) {
3801
3851
  ? [[field.name, { fieldType: field.type, multiple: false }]]
3802
3852
  : []))
3803
3853
  : undefined;
3804
- const recordTarget = FOUND_RECORD_TASK_TYPES.has(resourceType)
3854
+ // updateField's `record` output is the record it updated, of its `aspectId` app/element.
3855
+ const recordTarget = FOUND_RECORD_TASK_TYPES.has(resourceType) || resourceType === TASK_RESOURCES.updateField
3805
3856
  ? token(taskBody.aspectId ?? taskBody.relatedAspectId)
3806
3857
  : undefined;
3807
3858
  taskRefs.set(refKey, {
@@ -149,7 +149,8 @@ export function elementFromTf(elementBlock, fieldBlocks, ctx, viewBlocks = {
149
149
  ctx.diagnostics.push(`element "${label}": no import block in the stream — adoption has no identity to bind`);
150
150
  }
151
151
  const dashboards = dashboardsFromTf(viewBlocks.dashboardBlocks, viewBlocks.dashboardWidgetBlocks, { type: ELEMENT_RESOURCE_TYPE, label, ownerTfLabel: refName, ownerRefName: refName, scope: "element", ownerType: "ELEMENT_ASPECT" }, ctx);
152
- const { layouts, listViews, calendarViews, kanbanViews, dashboardViews, customViews, viewOrder } = viewsFromTf(viewBlocks.layoutBlocks, viewBlocks.listViewBlocks, viewBlocks.calendarViewBlocks, viewBlocks.kanbanViewBlocks, viewBlocks.dashboardViewBlocks, [], viewBlocks.managedViewOrderBlocks, { type: ELEMENT_RESOURCE_TYPE, label, ownerTfLabel: label, scope: "element" }, ctx, viewBlocks.customViewBlocks);
152
+ const unextractedFieldIds = new Set();
153
+ const { layouts, listViews, calendarViews, kanbanViews, dashboardViews, customViews, viewOrder } = viewsFromTf(viewBlocks.layoutBlocks, viewBlocks.listViewBlocks, viewBlocks.calendarViewBlocks, viewBlocks.kanbanViewBlocks, viewBlocks.dashboardViewBlocks, [], viewBlocks.managedViewOrderBlocks, { type: ELEMENT_RESOURCE_TYPE, label, ownerTfLabel: label, scope: "element", fieldKeys: new Set(fields.map((field) => field.key)), unextractedFieldIds }, ctx, viewBlocks.customViewBlocks);
153
154
  if (viewBlocks.recordCreateFormBlocks.length > 1) {
154
155
  ctx.diagnostics.push(`element "${label}": found ${viewBlocks.recordCreateFormBlocks.length} record create forms; only the first is used`);
155
156
  }
@@ -198,6 +199,7 @@ export function elementFromTf(elementBlock, fieldBlocks, ctx, viewBlocks = {
198
199
  ...(auditFields && { auditFields }),
199
200
  ...(layouts.length > 0 && { layouts }),
200
201
  ...(listViews.length > 0 && { listViews }),
202
+ ...(unextractedFieldIds.size > 0 && { unextractedFieldIds: [...unextractedFieldIds] }),
201
203
  ...(calendarViews.length > 0 && { calendarViews }),
202
204
  ...(kanbanViews.length > 0 && { kanbanViews }),
203
205
  ...(dashboardViews.length > 0 && { dashboardViews }),
@@ -1,6 +1,6 @@
1
1
  /** The skill entity's registry entry + resource-type constant (see src/graph/). */
2
2
  import { rootParentFactoryEntry } from "../../catalog/render-helpers.js";
3
- import { isTfExpr } from "../../engine/tf/index.js";
3
+ import { isTfExpr, scopedLabelToBagKey } from "../../engine/tf/index.js";
4
4
  import { printSkillV2 } from "./deserializer/print-skill-v2.js";
5
5
  import { skillFromTf } from "./from-tf.js";
6
6
  import { skillToTf } from "./to-tf.js";
@@ -41,6 +41,29 @@ function skillRefFromAuthoring(args) {
41
41
  : entityRefName;
42
42
  return { __kind: "skill", refName: entityRefName, name, parent: entityParent };
43
43
  }
44
+ /**
45
+ * A tool that runs a same-stream automation prints a catalog ref to it. If
46
+ * pull skips that automation and keeps no authored file for it, build cannot
47
+ * emit the tool, so stream-root drops it from the skill and releases it.
48
+ */
49
+ function requireRunAutomationTarget(tool, skillRefName, ctx) {
50
+ const automation = tool.attrs["automation_id"];
51
+ const toolName = tool.attrs["name"];
52
+ if (!isTfExpr(automation) || automation.$expr !== "resource-attr" || typeof toolName !== "string")
53
+ return;
54
+ if (automation.type !== "elementum_workflow_publish" && automation.type !== "elementum_automation")
55
+ return;
56
+ ctx.requiresExtracted?.push({
57
+ address: `${tool.type}.${tool.label}`,
58
+ requires: `${automation.type}.${automation.label}`,
59
+ requiresOwnFile: { kind: "automation", refName: scopedLabelToBagKey(ctx.appTfLabel, automation.label) },
60
+ prune: (root) => root,
61
+ pruneOwnFile: {
62
+ kind: "skill",
63
+ prune: (skills) => skills.map((skill) => skill.refName === skillRefName ? { ...skill, tools: skill.tools.filter((t) => t.name !== toolName) } : skill),
64
+ },
65
+ });
66
+ }
44
67
  function extractSkills(ownBlocks, stream, ctx) {
45
68
  const toolBlocks = stream.byKind.get("skill-tool") ?? [];
46
69
  const items = [];
@@ -53,8 +76,11 @@ function extractSkills(ownBlocks, stream, ctx) {
53
76
  return isTfExpr(ref) && ref.$expr === "resource-attr" && ref.type === SKILL_RESOURCE_TYPE && ref.label === skillLabel;
54
77
  });
55
78
  const { skill, skippedReason } = skillFromTf(skillBlock, ownTools, ctx.appTfLabel, ctx);
56
- if (skill !== undefined)
79
+ if (skill !== undefined) {
57
80
  items.push(skill);
81
+ for (const tool of ownTools)
82
+ requireRunAutomationTarget(tool, skill.refName, ctx);
83
+ }
58
84
  else if (skippedReason !== undefined) {
59
85
  skipped.push(`${SKILL_RESOURCE_TYPE}.${skillLabel}`);
60
86
  diagnostics.push(skippedReason);
@@ -61,6 +61,8 @@ export interface AgentViewLayoutFromTfOptions {
61
61
  readonly isOwnApp: (value: TfValue) => boolean;
62
62
  /** Resolves a field reference to its bag key, a system field key, or a raw id. */
63
63
  readonly fieldKey: (value: TfValue) => string | undefined;
64
+ /** Sees a raw platform id in a field position, which pulls as is (#1736 records the ones naming unextracted fields). */
65
+ readonly noteRawFieldId?: (id: string) => void;
64
66
  /** Resolves another app's or element's data lookup. */
65
67
  readonly foreignSource?: (value: TfValue) => ViewBlocksSourceMarker | undefined;
66
68
  /** Resolves the data lookup of another app's or element's field. */
@@ -152,8 +152,10 @@ function deepRefs(value, where, opts) {
152
152
  if (isTfExpr(value)) {
153
153
  return sourceRef(value, opts) ?? fieldMarker(value, where, opts);
154
154
  }
155
- if (isPlatformId(value))
155
+ if (isPlatformId(value)) {
156
+ opts.noteRawFieldId?.(value);
156
157
  return unsafe(value);
158
+ }
157
159
  if (Array.isArray(value))
158
160
  return value.map((item, i) => deepRefs(item, `${where}[${i}]`, opts));
159
161
  const rec = plain(value);
@@ -201,8 +203,10 @@ function sourceRef(value, opts) {
201
203
  return opts.foreignSource?.(value);
202
204
  }
203
205
  function fieldMarker(value, where, opts) {
204
- if (typeof value === "string")
206
+ if (typeof value === "string") {
207
+ opts.noteRawFieldId?.(value);
205
208
  return unsafe(value);
209
+ }
206
210
  // Checked first: the owner's resolver reports a foreign lookup as unknown.
207
211
  const foreign = opts.foreignField?.(value);
208
212
  if (foreign !== undefined)
@@ -65,11 +65,12 @@ export function validateCustomViewLayout(spec, where, opts = {}) {
65
65
  const rootType = isObj(rootEl) && typeof rootEl["type"] === "string" ? rootEl["type"] : "";
66
66
  // check.mjs warns on any non-PanesBlock root. We error only when a live list
67
67
  // needs the details pane — chart/StackBlock dashboards without lists stay valid.
68
+ // A null aspectId (or repeat, below) counts as absent, as in the Go provider (#1784).
68
69
  const hasLiveList = Object.values(elements).some((raw) => {
69
70
  if (!isObj(raw) || !isObj(raw["props"]))
70
71
  return false;
71
72
  const t = raw["type"];
72
- return typeof t === "string" && LIST_BLOCKS.has(t) && raw["props"]["aspectId"] !== undefined;
73
+ return typeof t === "string" && LIST_BLOCKS.has(t) && raw["props"]["aspectId"] != null;
73
74
  });
74
75
  if (hasLiveList && rootType !== "PanesBlock") {
75
76
  note(`${where}.root`, `"${root}" must be a PanesBlock (got ${rootType === "" ? "no type" : `"${rootType}"`}); a live list needs a panes root so rows can open the details panel`);
@@ -101,7 +102,7 @@ export function validateCustomViewLayout(spec, where, opts = {}) {
101
102
  if (children.length > 0 && !CONTAINERS.has(raw["type"])) {
102
103
  note(elWhere, `${raw["type"]} does not render children; only ${[...CONTAINERS].join(", ")} do`);
103
104
  }
104
- if (raw["repeat"] !== undefined && children.length === 0) {
105
+ if (raw["repeat"] != null && children.length === 0) {
105
106
  note(`${elWhere}.repeat`, "a repeated element needs a child element as its template; the page will fail to render this custom view");
106
107
  }
107
108
  for (const child of children) {
@@ -114,7 +115,7 @@ export function validateCustomViewLayout(spec, where, opts = {}) {
114
115
  }
115
116
  }
116
117
  }
117
- else if (raw["repeat"] !== undefined) {
118
+ else if (raw["repeat"] != null) {
118
119
  note(`${elWhere}.repeat`, "a repeated element needs a child element as its template; the page will fail to render this custom view");
119
120
  }
120
121
  }
@@ -239,7 +240,7 @@ export function validateCustomViewLayout(spec, where, opts = {}) {
239
240
  // Live lists on a custom view need all three selection bindings as $state /
240
241
  // $bindState so the details pane opens. $item / $index do not count.
241
242
  // Warn-only: pulled Blueprint layouts omit these and must still build.
242
- if (LIST_BLOCKS.has(type) && props["aspectId"] !== undefined) {
243
+ if (LIST_BLOCKS.has(type) && props["aspectId"] != null) {
243
244
  const missing = SELECTION_KEYS.filter((key) => !isStateBinding(props[key]));
244
245
  if (missing.length > 0) {
245
246
  warn(elWhere, `live list without selectedId/selectedAspectId/selectedHandle bindings; rows will not open the details pane (missing or not $state/$bindState: ${missing.join(", ")})`);
@@ -257,7 +258,7 @@ function throwIf(problems) {
257
258
  export function reportStructureProblems(_root, elements, where, diagnostics) {
258
259
  for (const [id, raw] of Object.entries(elements)) {
259
260
  const children = isObj(raw) ? raw["children"] : undefined;
260
- if (isObj(raw) && raw["repeat"] !== undefined && (!Array.isArray(children) || children.length === 0)) {
261
+ if (isObj(raw) && raw["repeat"] != null && (!Array.isArray(children) || children.length === 0)) {
261
262
  diagnostics.push(`${where}.elements.${id}.repeat: a repeated element needs a child element as its template; the page will fail to render this custom view`);
262
263
  }
263
264
  if (!Array.isArray(children))
@@ -23,6 +23,14 @@ export interface ViewOwner {
23
23
  readonly stageKeys?: ReadonlySet<string>;
24
24
  /** The owning app's stage handles → real stage keys (see `stageKeyByHandle`, #1136). */
25
25
  readonly stageKeyByHandle?: ReadonlyMap<string, string>;
26
+ /**
27
+ * Keys of the fields pull extracted for this owner. A field reference whose
28
+ * field is not among them keeps its platform id instead of a key that
29
+ * builds as nothing (#1736). Undefined when the caller does not know.
30
+ */
31
+ readonly fieldKeys?: ReadonlySet<string>;
32
+ /** Collects the platform ids kept for unextracted fields, so print can say they are intentional. */
33
+ readonly unextractedFieldIds?: Set<string>;
26
34
  }
27
35
  export interface ViewsFromTfResult {
28
36
  readonly layouts: readonly NormalizedLayout[];
@@ -8,7 +8,10 @@
8
8
  import { agentViewLayoutFromTf, viewBlocksFromTf, } from "./agent-view-layout-from-tf.js";
9
9
  import { dataRefLabel, optionalString, plainObject, resourceRefLabel } from "../../engine/pull/context.js";
10
10
  import { reportUnknownAttrs } from "../../engine/pull/attrs.js";
11
- import { isTfExpr, scopedLabelToBagKey, tfLabelToTsLabel, tsLabelToTfLabel } from "../../engine/tf/index.js";
11
+ import { canonicalImportId } from "../../engine/pull/authored-address.js";
12
+ import { SYSTEM_FIELD_KEY_SET } from "../../core/system-fields.js";
13
+ import { ELEMENT_SYSTEM_FIELD_KEYS } from "../element/system-fields.js";
14
+ import { expr, isTfExpr, scopedLabelToBagKey, tfLabelToTsLabel, tsLabelToTfLabel } from "../../engine/tf/index.js";
12
15
  import { lostStageMessage, pulledStageHandle } from "../app/stage-keys.js";
13
16
  import { decodeForeignDataField, fieldKeyFromTfValue } from "../field/from-tf.js";
14
17
  import { resolveDataAspectTarget } from "../shared/aspect-target-from-tf.js";
@@ -132,7 +135,7 @@ function customViewFromTf(block, owner, ctx) {
132
135
  if (layoutAttr !== undefined && layoutAttr !== null) {
133
136
  if (!isTfExpr(layoutAttr) || layoutAttr.$expr !== "jsonencode")
134
137
  return unmanaged("layout is not a jsonencode(...) expression");
135
- const decoded = viewBlocksFromTf(layoutAttr.value, layoutRefOptions(owner, ctx));
138
+ const decoded = viewBlocksFromTf(layoutAttr.value, layoutRefOptions(owner, ctx, where));
136
139
  if (!decoded.ok)
137
140
  return unmanaged(decoded.reason);
138
141
  layout = decoded.layout;
@@ -222,8 +225,8 @@ function typedFieldViewFromTf(block, owner, resourceType, knownAttrs, includeAll
222
225
  return undefined;
223
226
  }
224
227
  const fields = [];
225
- for (const value of raw) {
226
- const key = fieldRefFromTf(value, owner.label, owner.ownerTfLabel, scope, ctx);
228
+ for (const [index, value] of raw.entries()) {
229
+ const key = fieldRefFromTf(value, owner, ctx, `${where} ${attr}[${index}]`);
227
230
  if (key !== undefined)
228
231
  fields.push(key);
229
232
  }
@@ -231,7 +234,7 @@ function typedFieldViewFromTf(block, owner, resourceType, knownAttrs, includeAll
231
234
  };
232
235
  const columns = readFields("columns") ?? [];
233
236
  const displayByField = attrs["display_by_field"] !== undefined
234
- ? fieldRefFromTf(attrs["display_by_field"], owner.label, owner.ownerTfLabel, scope, ctx)
237
+ ? fieldRefFromTf(attrs["display_by_field"], owner, ctx, `${where} display_by_field`)
235
238
  : undefined;
236
239
  const allowedFilterFields = includeAllowedFilterFields ? readFields("allowed_filter_fields") : undefined;
237
240
  const sort = managedViewSortFromTf(attrs["sort"], owner, where, ctx);
@@ -257,7 +260,7 @@ function typedFieldViewFromTf(block, owner, resourceType, knownAttrs, includeAll
257
260
  * How a blocks layout's references pull: the owner and its fields, and other
258
261
  * apps and elements and their fields through the export's data lookups.
259
262
  */
260
- function layoutRefOptions(owner, ctx) {
263
+ function layoutRefOptions(owner, ctx, where) {
261
264
  const foreignSource = (value) => {
262
265
  for (const [type, kind] of [["elementum_app", "app"], ["elementum_element", "element"]]) {
263
266
  const dataLabel = dataRefLabel(value, type);
@@ -270,7 +273,8 @@ function layoutRefOptions(owner, ctx) {
270
273
  };
271
274
  return {
272
275
  isOwnApp: (value) => resourceRefLabel(value, owner.type) === owner.label,
273
- fieldKey: (value) => fieldRefFromTf(value, owner.label, owner.ownerTfLabel, owner.scope ?? "app", ctx),
276
+ fieldKey: (value) => fieldRefFromTf(value, owner, ctx, `${where} layout`),
277
+ noteRawFieldId: (id) => noteRawUnextractedFieldId(id, owner, ctx, `${where} layout`),
274
278
  foreignSource,
275
279
  foreignField: (value) => {
276
280
  const dataLabel = dataRefLabel(value, "elementum_field");
@@ -322,7 +326,7 @@ function agentViewFromTf(block, owner, ctx) {
322
326
  const filter = viewFilter(attrs["filter"], owner, where, ctx);
323
327
  let layout;
324
328
  if (attrs["layout"] !== undefined && attrs["layout"] !== null) {
325
- const decoded = agentViewLayoutFromTf(attrs["layout"], layoutRefOptions(owner, ctx));
329
+ const decoded = agentViewLayoutFromTf(attrs["layout"], layoutRefOptions(owner, ctx, where));
326
330
  if (!decoded.ok) {
327
331
  // The code owns the layout: printing the view without it would make the
328
332
  // next apply clear the live customization. Leave the view unmanaged.
@@ -370,8 +374,8 @@ function layoutFromTf(block, owner, ctx) {
370
374
  const sectionsAttr = attrs["sections"];
371
375
  const sections = [];
372
376
  if (Array.isArray(sectionsAttr)) {
373
- for (const item of sectionsAttr) {
374
- const section = sectionFromTf(item, owner.label, owner.ownerTfLabel, scope, where, ctx);
377
+ for (const [index, item] of sectionsAttr.entries()) {
378
+ const section = sectionFromTf(item, owner, `${where} sections[${index}]`, ctx);
375
379
  if (section !== undefined)
376
380
  sections.push(section);
377
381
  }
@@ -429,8 +433,8 @@ function layoutFromTf(block, owner, ctx) {
429
433
  const sectionsAttr = attrs["sections"];
430
434
  const sections = [];
431
435
  if (Array.isArray(sectionsAttr)) {
432
- for (const item of sectionsAttr) {
433
- const section = sectionFromTf(item, owner.label, owner.ownerTfLabel, scope, where, ctx);
436
+ for (const [index, item] of sectionsAttr.entries()) {
437
+ const section = sectionFromTf(item, owner, `${where} sections[${index}]`, ctx);
434
438
  if (section !== undefined)
435
439
  sections.push(section);
436
440
  }
@@ -448,7 +452,9 @@ function stageIndexFromTf(v, ownerLabel) {
448
452
  const seg = v.path[0];
449
453
  return v.path.length === 1 && typeof seg === "object" && "index" in seg ? seg.index : undefined;
450
454
  }
451
- function sectionFromTf(raw, ownerLabel, ownerTfLabel, scope, where, ctx) {
455
+ function sectionFromTf(raw, owner, where, ctx) {
456
+ const ownerTfLabel = owner.ownerTfLabel;
457
+ const scope = owner.scope ?? "app";
452
458
  const rec = plainObject(raw);
453
459
  if (rec === undefined) {
454
460
  ctx.diagnostics.push(`${where}: a sections entry has an unrecognized shape; dropped`);
@@ -494,7 +500,7 @@ function sectionFromTf(raw, ownerLabel, ownerTfLabel, scope, where, ctx) {
494
500
  const fields = [];
495
501
  const widgets = [];
496
502
  const widgetAts = {};
497
- for (const f of fieldIds) {
503
+ for (const [index, f] of fieldIds.entries()) {
498
504
  const widgetLabel = resourceRefLabel(f, WIDGET_RESOURCE_TYPE);
499
505
  if (widgetLabel !== undefined) {
500
506
  const key = scopedLabelToBagKey(ownerTfLabel, widgetLabel, scope);
@@ -504,7 +510,7 @@ function sectionFromTf(raw, ownerLabel, ownerTfLabel, scope, where, ctx) {
504
510
  widgetAts[key] = fields.length;
505
511
  continue;
506
512
  }
507
- const key = fieldRefFromTf(f, ownerLabel, ownerTfLabel, scope, ctx);
513
+ const key = fieldRefFromTf(f, owner, ctx, `${where} field_ids[${index}]`);
508
514
  if (key !== undefined)
509
515
  fields.push(key);
510
516
  }
@@ -522,10 +528,13 @@ function sectionFromTf(raw, ownerLabel, ownerTfLabel, scope, where, ctx) {
522
528
  return section;
523
529
  }
524
530
  /** A `field_ids`/`columns` entry → a system-field key or a custom field's bag key. */
525
- function fieldRefFromTf(v, ownerLabel, ownerTfLabel, scope, ctx) {
526
- const fieldKey = fieldKeyFromTfValue(v, tfLabelToTsLabel(ownerLabel), ownerTfLabel, scope, ctx);
531
+ function fieldRefFromTf(v, owner, ctx, site) {
532
+ const ownerLabel = owner.label;
533
+ const fieldKey = fieldKeyFromTfValue(v, tfLabelToTsLabel(ownerLabel), owner.ownerTfLabel, owner.scope ?? "app", ctx);
527
534
  if (fieldKey !== undefined)
528
- return fieldKey;
535
+ return unextractedFieldId(v, fieldKey, owner, ctx, site) ?? fieldKey;
536
+ if (typeof v === "string" && importedUnextractedFieldId(v, owner, ctx, site) !== undefined)
537
+ return v;
529
538
  if (typeof v === "string" && v !== "") {
530
539
  // The field itself couldn't be resolved to a portable reference at all
531
540
  // - ei's own export already fell back to a bare platform-id string here
@@ -554,6 +563,98 @@ function fieldRefFromTf(v, ownerLabel, ownerTfLabel, scope, ctx) {
554
563
  ctx.diagnostics.push(`field reference ${JSON.stringify(v)} does not resolve to a known field; dropped`);
555
564
  return undefined;
556
565
  }
566
+ /**
567
+ * The platform id of a field reference whose field pull did not extract for
568
+ * this owner (#1736). Its key prints as nothing, so build drops the column
569
+ * or section field and plan removes it. The id keeps it: a raw platform id
570
+ * as is (a re-pull of this fix's own output), or a resource reference's
571
+ * import id. Print marks it as intentional through `unextractedFieldIds`.
572
+ * Undefined when the field was extracted.
573
+ */
574
+ function unextractedFieldId(v, fieldKey, owner, ctx, site) {
575
+ if (owner.fieldKeys === undefined || owner.fieldKeys.has(fieldKey))
576
+ return undefined;
577
+ // A system key is never in the extracted fields bag (element audit keys
578
+ // never are; an app's only when system_field_config names it), yet print
579
+ // and build turn it into the owner's system-field local. It stays a key.
580
+ if (isOwnerSystemFieldKey(fieldKey, owner))
581
+ return undefined;
582
+ let field;
583
+ let id;
584
+ if (typeof v === "string") {
585
+ field = `"${fieldKey}"`;
586
+ id = PLATFORM_ID.test(v) ? v : undefined;
587
+ }
588
+ else if (isTfExpr(v) && v.$expr === "resource-attr") {
589
+ field = `${v.type}.${v.label}`;
590
+ const importId = ctx.importId(field);
591
+ const canonical = importId === undefined ? undefined : canonicalImportId(importId);
592
+ id = canonical !== undefined && PLATFORM_ID.test(canonical) ? canonical : undefined;
593
+ }
594
+ else {
595
+ return undefined;
596
+ }
597
+ reportUnextractedField(ctx, field, id, site);
598
+ if (id !== undefined)
599
+ owner.unextractedFieldIds?.add(id);
600
+ return id;
601
+ }
602
+ const ELEMENT_SYSTEM_FIELD_KEY_SET = new Set(ELEMENT_SYSTEM_FIELD_KEYS);
603
+ function isOwnerSystemFieldKey(fieldKey, owner) {
604
+ return (owner.scope === "element" ? ELEMENT_SYSTEM_FIELD_KEY_SET : SYSTEM_FIELD_KEY_SET).has(fieldKey);
605
+ }
606
+ /**
607
+ * A raw platform id this owner's export imports as one of its own fields
608
+ * that pull did not extract: a re-pull of an id #1736 kept. Undefined
609
+ * otherwise.
610
+ */
611
+ function importedUnextractedFieldId(v, owner, ctx, site) {
612
+ if (!PLATFORM_ID.test(v))
613
+ return undefined;
614
+ const imported = ctx.importedResource?.(v);
615
+ if (imported === undefined)
616
+ return undefined;
617
+ const importedRef = expr.resourceAttr(imported.type, imported.label, ["id"]);
618
+ const importedKey = fieldKeyFromTfValue(importedRef, tfLabelToTsLabel(owner.label), owner.ownerTfLabel, owner.scope ?? "app", ctx);
619
+ if (importedKey === undefined)
620
+ return undefined;
621
+ return unextractedFieldId(importedRef, importedKey, owner, ctx, site) === v ? v : undefined;
622
+ }
623
+ /**
624
+ * Records a raw platform id that a caller keeps as is (a sort order, a blocks
625
+ * layout id prop) when it names a field pull did not extract, so print marks
626
+ * it as intentional too (#1736). The caller's value does not change.
627
+ */
628
+ function noteRawUnextractedFieldId(v, owner, ctx, site) {
629
+ if (!PLATFORM_ID.test(v))
630
+ return;
631
+ const fieldKey = fieldKeyFromTfValue(v, tfLabelToTsLabel(owner.label), owner.ownerTfLabel, owner.scope ?? "app", ctx);
632
+ if (fieldKey !== undefined)
633
+ unextractedFieldId(v, fieldKey, owner, ctx, site);
634
+ else
635
+ importedUnextractedFieldId(v, owner, ctx, site);
636
+ }
637
+ /** One diagnostic per unextracted field per pull, naming every view site that references it (#1736). */
638
+ const unextractedFieldReports = new WeakMap();
639
+ function reportUnextractedField(ctx, field, id, site) {
640
+ let byField = unextractedFieldReports.get(ctx.diagnostics);
641
+ if (byField === undefined) {
642
+ byField = new Map();
643
+ unextractedFieldReports.set(ctx.diagnostics, byField);
644
+ }
645
+ let report = byField.get(field);
646
+ if (report === undefined) {
647
+ report = { index: ctx.diagnostics.length, sites: [] };
648
+ byField.set(field, report);
649
+ ctx.diagnostics.push("");
650
+ }
651
+ if (!report.sites.includes(site))
652
+ report.sites.push(site);
653
+ const sites = report.sites.join(", ");
654
+ ctx.diagnostics[report.index] = id !== undefined
655
+ ? `field ${field} was not extracted by pull; kept as its platform id ${id} at ${sites}, so plan keeps it in the view (dropping it would make plan remove it)`
656
+ : `field ${field} was not extracted by pull and has no platform id; ${sites} builds without it, so plan would remove it from the view`;
657
+ }
557
658
  function listViewFromTf(block, owner, ctx) {
558
659
  const label = block.label;
559
660
  if (label === undefined || label === "") {
@@ -573,8 +674,8 @@ function listViewFromTf(block, owner, ctx) {
573
674
  const columnsAttr = attrs["columns"];
574
675
  const columns = [];
575
676
  if (Array.isArray(columnsAttr)) {
576
- for (const c of columnsAttr) {
577
- const key = fieldRefFromTf(c, owner.label, owner.ownerTfLabel, scope, ctx);
677
+ for (const [index, c] of columnsAttr.entries()) {
678
+ const key = fieldRefFromTf(c, owner, ctx, `${where} columns[${index}]`);
578
679
  if (key !== undefined)
579
680
  columns.push(key);
580
681
  }
@@ -640,9 +741,12 @@ export function managedViewSortFromTf(value, owner, where, ctx) {
640
741
  return undefined;
641
742
  }
642
743
  const rawField = order["field"];
744
+ const site = `${where} sort.orders[${index}].field`;
745
+ if (typeof rawField === "string")
746
+ noteRawUnextractedFieldId(rawField, owner, ctx, site);
643
747
  const field = typeof rawField === "string"
644
748
  ? (PLATFORM_ID.test(rawField) ? rawField : undefined)
645
- : fieldRefFromTf(rawField, owner.label, owner.ownerTfLabel, owner.scope ?? "app", ctx);
749
+ : fieldRefFromTf(rawField, owner, ctx, site);
646
750
  if (field === undefined) {
647
751
  ctx.diagnostics.push(`${where}: sort.orders[${index}].field does not resolve to a field; dropped sort`);
648
752
  return undefined;
@@ -473,6 +473,13 @@ export interface BuildChildContext {
473
473
  * used in a formula needs the searched aspect's field resources.
474
474
  */
475
475
  readonly fieldAddressesByAppRefName?: ReadonlyMap<string, ReadonlyMap<string, string>>;
476
+ /**
477
+ * Every app/element authored in the workspace, keyed like
478
+ * `workspaceAspects` (`<kind>:<refName>`), including those a partial build
479
+ * (pull's root-only build) leaves out. Tells an authored sibling outside this
480
+ * build apart from an aspect the workspace never authors.
481
+ */
482
+ readonly authoredAspectKeys?: ReadonlySet<string>;
476
483
  /** Pulled roots may retain picklist labels removed from the live field. */
477
484
  readonly allowUnknownPicklistOptions?: boolean;
478
485
  /** Every app/element/table stream root in this build, by refName (see `ToTfContext.workspaceAspects`). */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elementumai/edk",
3
- "version": "0.10.3",
3
+ "version": "0.10.4",
4
4
  "description": "Elementum Development Kit — statically typed SDK for building Elementum apps, automations, and agents",
5
5
  "type": "module",
6
6
  "license": "SEE LICENSE IN LICENSE",