@openfairygui/backend 0.7.1 → 0.8.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.
@@ -1,12 +1,12 @@
1
1
  require("./rolldown-runtime-BJqNVkSG.cjs");
2
- const require_diagnostics = require("./diagnostics-CIe7S-RW.cjs");
2
+ const require_diagnostics = require("./diagnostics-DZPzUEY9.cjs");
3
3
  let _openfairygui_core_uam = require("@openfairygui/core/uam");
4
4
  let _openfairygui_functions_uam = require("@openfairygui/functions/uam");
5
5
  let _openfairygui_core_project_io = require("@openfairygui/core/project-io");
6
6
  let _openfairygui_functions = require("@openfairygui/functions");
7
7
  //#region src/contracts.ts
8
8
  const BACKEND_CONTRACT_VERSION = "3.0.0";
9
- const BACKEND_CAPABILITY_SCHEMA_VERSION = 15;
9
+ const BACKEND_CAPABILITY_SCHEMA_VERSION = 16;
10
10
  const BACKEND_COMPATIBILITY_POLICY = {
11
11
  incompatibleChange: "requires contractVersion bump",
12
12
  capabilitySchemaChange: "requires capabilitySchemaVersion bump",
@@ -154,7 +154,7 @@ function createMeta(stage, startedAt, options) {
154
154
  diagnostics: (options?.diagnostics ?? []).map((entry) => require_diagnostics.enrichBackendDiagnostic(entry, options?.sessionId)),
155
155
  stage,
156
156
  contractVersion: BACKEND_CONTRACT_VERSION,
157
- capabilitySchemaVersion: 15
157
+ capabilitySchemaVersion: 16
158
158
  };
159
159
  }
160
160
  function success(stage, startedAt, data, options) {
@@ -186,6 +186,7 @@ function toSessionSnapshot(session, capabilities) {
186
186
  lastSavedRevision: session.lastSavedRevision,
187
187
  dirty: session.dirty,
188
188
  uamFidelity: session.uamFidelity,
189
+ ...session.uamFidelity === "unsupported" && session.uamFidelityReport ? { uamFidelityReport: cloneReadData(session.uamFidelityReport) } : {},
189
190
  lockHeld: session.lockHeld,
190
191
  capabilities: cloneReadData(capabilities)
191
192
  };
@@ -214,6 +215,30 @@ const BACKEND_ENTITY_QUERY_LIMITS = {
214
215
  maxDepth: 32,
215
216
  maxNodes: 1e5
216
217
  };
218
+ const BACKEND_DISPLAY_NODE_QUERY_LIMITS = {
219
+ maxBytes: 262144,
220
+ maxDepth: 32,
221
+ maxNodes: 1e5,
222
+ defaultLimit: 50,
223
+ maxLimit: 200
224
+ };
225
+ const BACKEND_DISPLAY_NODE_FILTER_FIELDS = [
226
+ "kind",
227
+ "name",
228
+ "nameContains",
229
+ "text",
230
+ "textContains",
231
+ "title",
232
+ "titleContains",
233
+ "group",
234
+ "resourceId",
235
+ "url",
236
+ "visible",
237
+ "locked",
238
+ "touchable",
239
+ "hasGears",
240
+ "hasRelations"
241
+ ];
217
242
  const BACKEND_SESSION_READ_LIMITS = {
218
243
  model: {
219
244
  maxBytes: 4194304,
@@ -301,22 +326,6 @@ function createCaptureFileSystem(files, directories) {
301
326
  }
302
327
  };
303
328
  }
304
- function capturedFilesEqual(left, right) {
305
- if (left.size !== right.size) return false;
306
- for (const [filePath, leftValue] of left) {
307
- const rightValue = right.get(filePath);
308
- if (typeof leftValue === "string") {
309
- if (leftValue !== rightValue) return false;
310
- continue;
311
- }
312
- if (!(rightValue instanceof Uint8Array) || leftValue.length !== rightValue.length) return false;
313
- for (let index = 0; index < leftValue.length; index += 1) if (leftValue[index] !== rightValue[index]) return false;
314
- }
315
- return true;
316
- }
317
- function capturedDirectoriesEqual(left, right) {
318
- return left.size === right.size && [...left].every((directory) => right.has(directory));
319
- }
320
329
  /** Serialize only into memory. This is a model projection, not a disk inventory or write plan. */
321
330
  async function captureProject(document, fairyFileName) {
322
331
  const files = /* @__PURE__ */ new Map();
@@ -720,6 +729,180 @@ async function writeSessionProject(input) {
720
729
  throw error;
721
730
  }
722
731
  }
732
+ function boundText(value, maxChars) {
733
+ const normalized = value.replace(/\r/g, "").trim();
734
+ if (normalized.length <= maxChars) return normalized;
735
+ return `${normalized.slice(0, Math.max(0, maxChars - 3))}...`;
736
+ }
737
+ function bytesEqual(left, right) {
738
+ if (left.length !== right.length) return false;
739
+ for (let index = 0; index < left.length; index += 1) if (left[index] !== right[index]) return false;
740
+ return true;
741
+ }
742
+ function firstTextLineDiff(source, materialized) {
743
+ const sourceLines = source.split("\n");
744
+ const materializedLines = materialized.split("\n");
745
+ const limit = Math.max(sourceLines.length, materializedLines.length);
746
+ for (let index = 0; index < limit; index += 1) {
747
+ const left = sourceLines[index] ?? "";
748
+ const right = materializedLines[index] ?? "";
749
+ if (left !== right) return {
750
+ line: index + 1,
751
+ sourceExcerpt: boundText(left, 240),
752
+ materializedExcerpt: boundText(right, 240)
753
+ };
754
+ }
755
+ return {
756
+ line: 1,
757
+ sourceExcerpt: boundText(sourceLines[0] ?? "", 240),
758
+ materializedExcerpt: boundText(materializedLines[0] ?? "", 240)
759
+ };
760
+ }
761
+ function diffCapturedProjects(sourceFiles, sourceDirectories, materializedFiles, materializedDirectories, maxDiffs = 50) {
762
+ const allDiffs = [];
763
+ const filePaths = [...new Set([...sourceFiles.keys(), ...materializedFiles.keys()])].sort((left, right) => left.localeCompare(right));
764
+ for (const filePath of filePaths) {
765
+ const left = sourceFiles.get(filePath);
766
+ const right = materializedFiles.get(filePath);
767
+ if (left === void 0) {
768
+ allDiffs.push({
769
+ path: filePath,
770
+ kind: "file",
771
+ change: "extra"
772
+ });
773
+ continue;
774
+ }
775
+ if (right === void 0) {
776
+ allDiffs.push({
777
+ path: filePath,
778
+ kind: "file",
779
+ change: "missing"
780
+ });
781
+ continue;
782
+ }
783
+ if (typeof left === "string" && typeof right === "string") {
784
+ if (left !== right) {
785
+ const diff = firstTextLineDiff(left, right);
786
+ allDiffs.push({
787
+ path: filePath,
788
+ kind: "file",
789
+ change: "modified",
790
+ line: diff.line,
791
+ sourceExcerpt: diff.sourceExcerpt,
792
+ materializedExcerpt: diff.materializedExcerpt
793
+ });
794
+ }
795
+ continue;
796
+ }
797
+ if (left instanceof Uint8Array && right instanceof Uint8Array) {
798
+ if (!bytesEqual(left, right)) allDiffs.push({
799
+ path: filePath,
800
+ kind: "file",
801
+ change: "modified"
802
+ });
803
+ continue;
804
+ }
805
+ allDiffs.push({
806
+ path: filePath,
807
+ kind: "file",
808
+ change: "type_mismatch"
809
+ });
810
+ }
811
+ const directories = [...new Set([...sourceDirectories, ...materializedDirectories])].sort((left, right) => left.localeCompare(right));
812
+ for (const directory of directories) {
813
+ const inSource = sourceDirectories.has(directory);
814
+ const inMaterialized = materializedDirectories.has(directory);
815
+ if (inSource && !inMaterialized) allDiffs.push({
816
+ path: directory,
817
+ kind: "directory",
818
+ change: "missing"
819
+ });
820
+ else if (!inSource && inMaterialized) allDiffs.push({
821
+ path: directory,
822
+ kind: "directory",
823
+ change: "extra"
824
+ });
825
+ }
826
+ allDiffs.sort((left, right) => left.path === right.path ? left.kind.localeCompare(right.kind) : left.path.localeCompare(right.path));
827
+ const limit = Math.max(0, maxDiffs);
828
+ return {
829
+ totalDiffCount: allDiffs.length,
830
+ diffs: allDiffs.slice(0, limit),
831
+ truncated: allDiffs.length > limit
832
+ };
833
+ }
834
+ async function evaluateUamFidelity(document, project, options) {
835
+ if (options?.readComplete === false) {
836
+ const detail = options.readDiagnostics?.[0]?.message;
837
+ return {
838
+ uamFidelity: "unsupported",
839
+ report: {
840
+ reason: "incomplete_read",
841
+ ...detail ? { errorMessage: boundText(detail, 512) } : {},
842
+ totalDiffCount: 0,
843
+ diffs: [],
844
+ truncated: false
845
+ }
846
+ };
847
+ }
848
+ const fairyFileName = options?.fairyFileName || "Project.fairy";
849
+ const sourceFiles = /* @__PURE__ */ new Map();
850
+ const materializedFiles = /* @__PURE__ */ new Map();
851
+ const sourceDirectories = /* @__PURE__ */ new Set();
852
+ const materializedDirectories = /* @__PURE__ */ new Set();
853
+ try {
854
+ await Promise.all([new _openfairygui_core_project_io.ProjectWriter(createCaptureFileSystem(sourceFiles, sourceDirectories)).write(document, fairyFileName), new _openfairygui_core_project_io.ProjectWriter(createCaptureFileSystem(materializedFiles, materializedDirectories)).write((0, _openfairygui_core_uam.materializeUamProject)(project), fairyFileName)]);
855
+ } catch (error) {
856
+ const message = error instanceof Error ? error.message : String(error);
857
+ return {
858
+ uamFidelity: "unsupported",
859
+ report: {
860
+ reason: "materialize_failed",
861
+ ...message ? { errorMessage: boundText(message, 512) } : {},
862
+ totalDiffCount: 0,
863
+ diffs: [],
864
+ truncated: false
865
+ }
866
+ };
867
+ }
868
+ const comparison = diffCapturedProjects(sourceFiles, sourceDirectories, materializedFiles, materializedDirectories, options?.maxDiffs);
869
+ if (comparison.totalDiffCount === 0) return { uamFidelity: "full" };
870
+ return {
871
+ uamFidelity: "unsupported",
872
+ report: {
873
+ reason: "round_trip_mismatch",
874
+ totalDiffCount: comparison.totalDiffCount,
875
+ diffs: comparison.diffs,
876
+ truncated: comparison.truncated
877
+ }
878
+ };
879
+ }
880
+ function formatUamFidelityUnsupportedMessage(report) {
881
+ if (!report) return "The source project contains formal properties that the current UAM cannot preserve.";
882
+ if (report.reason === "incomplete_read") return report.errorMessage ? `The source project read was incomplete, so UAM fidelity cannot be verified: ${report.errorMessage}` : "The source project read was incomplete, so UAM fidelity cannot be verified.";
883
+ if (report.reason === "materialize_failed") return report.errorMessage ? `The source project could not be materialized through the current UAM: ${report.errorMessage}` : "The source project could not be materialized through the current UAM.";
884
+ const first = report.diffs[0];
885
+ const firstLocation = first ? `, first: ${first.path}${first.line !== void 0 ? `:${first.line}` : ""} [${first.change}]` : "";
886
+ return `The source project contains formal properties that the current UAM cannot preserve (${report.totalDiffCount} difference(s)${firstLocation}).`;
887
+ }
888
+ function formatDiffDiagnosticMessage(entry) {
889
+ if (entry.kind === "directory") return `UAM round-trip directory ${entry.change}: ${entry.path}`;
890
+ if (entry.change === "modified" && entry.line !== void 0) return `UAM round-trip modified ${entry.path} at line ${entry.line} (source: ${entry.sourceExcerpt ?? ""}; materialized: ${entry.materializedExcerpt ?? ""}).`;
891
+ return `UAM round-trip file ${entry.change}: ${entry.path}`;
892
+ }
893
+ function createUamFidelityDiagnostics(report, fallbackMessage) {
894
+ if (report?.reason === "round_trip_mismatch" && report.diffs.length > 0) return report.diffs.map((entry) => ({
895
+ code: "uam_fidelity_unsupported",
896
+ severity: "error",
897
+ path: entry.path,
898
+ message: formatDiffDiagnosticMessage(entry)
899
+ }));
900
+ return [{
901
+ code: "uam_fidelity_unsupported",
902
+ severity: "error",
903
+ message: fallbackMessage
904
+ }];
905
+ }
723
906
  //#endregion
724
907
  //#region src/services/persistence-service.ts
725
908
  function createCapabilityUnavailableError$1(message) {
@@ -731,11 +914,13 @@ function createCapabilityUnavailableError$1(message) {
731
914
  };
732
915
  }
733
916
  function createUamFidelityUnsupportedError(session) {
917
+ const report = session.uamFidelityReport;
734
918
  return {
735
919
  code: "uam_fidelity_unsupported",
736
- message: "The source project contains formal properties that the current UAM cannot preserve.",
920
+ message: formatUamFidelityUnsupportedMessage(report),
737
921
  sessionId: session.sessionId,
738
- canonicalPathKey: session.canonicalPathKey
922
+ canonicalPathKey: session.canonicalPathKey,
923
+ ...report ? { fidelityReport: structuredClone(report) } : {}
739
924
  };
740
925
  }
741
926
  function validationDiagnostics(sessionProject) {
@@ -827,10 +1012,14 @@ var PersistenceService = class {
827
1012
  sessionId: session.sessionId,
828
1013
  revision: session.revision
829
1014
  });
830
- if (session.uamFidelity === "unsupported") return failure("authoring", startedAt, createUamFidelityUnsupportedError(session), toSessionSnapshot(session, this.context.capabilities), {
831
- sessionId: session.sessionId,
832
- revision: session.revision
833
- });
1015
+ if (session.uamFidelity === "unsupported") {
1016
+ const error = createUamFidelityUnsupportedError(session);
1017
+ return failure("authoring", startedAt, error, toSessionSnapshot(session, this.context.capabilities), {
1018
+ sessionId: session.sessionId,
1019
+ revision: session.revision,
1020
+ diagnostics: createUamFidelityDiagnostics(session.uamFidelityReport, error.message)
1021
+ });
1022
+ }
834
1023
  const committedPaths = [];
835
1024
  const failedPaths = [];
836
1025
  this.eventService.emit({
@@ -923,10 +1112,14 @@ var PersistenceService = class {
923
1112
  sessionId: session.sessionId,
924
1113
  revision: session.revision
925
1114
  });
926
- if (session.uamFidelity === "unsupported") return failure("authoring", startedAt, createUamFidelityUnsupportedError(session), toSessionSnapshot(session, this.context.capabilities), {
927
- sessionId: session.sessionId,
928
- revision: session.revision
929
- });
1115
+ if (session.uamFidelity === "unsupported") {
1116
+ const error = createUamFidelityUnsupportedError(session);
1117
+ return failure("authoring", startedAt, error, toSessionSnapshot(session, this.context.capabilities), {
1118
+ sessionId: session.sessionId,
1119
+ revision: session.revision,
1120
+ diagnostics: createUamFidelityDiagnostics(session.uamFidelityReport, error.message)
1121
+ });
1122
+ }
930
1123
  const diagnostics = validationDiagnostics(session.project);
931
1124
  if (diagnostics.length > 0) return failure("authoring", startedAt, {
932
1125
  code: "materialize_validation_failed",
@@ -1309,6 +1502,167 @@ var EventService = class {
1309
1502
  };
1310
1503
  //#endregion
1311
1504
  //#region src/services/read-service.ts
1505
+ const DISPLAY_NODE_KINDS = new Set([
1506
+ "image",
1507
+ "text",
1508
+ "richText",
1509
+ "textInput",
1510
+ "component",
1511
+ "list",
1512
+ "tree",
1513
+ "graph",
1514
+ "group",
1515
+ "loader",
1516
+ "loader3D",
1517
+ "movieClip",
1518
+ "button",
1519
+ "label",
1520
+ "comboBox",
1521
+ "progressBar",
1522
+ "slider",
1523
+ "scrollBar"
1524
+ ]);
1525
+ const DISPLAY_NODE_FILTER_KEY_SET = new Set(BACKEND_DISPLAY_NODE_FILTER_FIELDS);
1526
+ const DISPLAY_NODE_FILTER_EXACT_STRINGS = [
1527
+ "name",
1528
+ "text",
1529
+ "title",
1530
+ "group",
1531
+ "url"
1532
+ ];
1533
+ const DISPLAY_NODE_FILTER_CONTAINS_STRINGS = [
1534
+ "nameContains",
1535
+ "textContains",
1536
+ "titleContains"
1537
+ ];
1538
+ const DISPLAY_NODE_FILTER_BOOLEANS = [
1539
+ "visible",
1540
+ "locked",
1541
+ "touchable",
1542
+ "hasGears",
1543
+ "hasRelations"
1544
+ ];
1545
+ const DISPLAY_NODE_QUERY_INPUT_KEYS = new Set([
1546
+ "sessionId",
1547
+ "selector",
1548
+ "filter",
1549
+ "limit"
1550
+ ]);
1551
+ function isPlainRecord(value) {
1552
+ return typeof value === "object" && value !== null && !Array.isArray(value) && (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null);
1553
+ }
1554
+ function isValidDisplayNodeFilter(value) {
1555
+ if (!isPlainRecord(value)) return false;
1556
+ for (const key of Object.keys(value)) if (!DISPLAY_NODE_FILTER_KEY_SET.has(key)) return false;
1557
+ if (value.kind !== void 0 && (typeof value.kind !== "string" || !DISPLAY_NODE_KINDS.has(value.kind))) return false;
1558
+ for (const key of DISPLAY_NODE_FILTER_EXACT_STRINGS) {
1559
+ const entry = value[key];
1560
+ if (entry !== void 0 && (typeof entry !== "string" || entry.length > 1024)) return false;
1561
+ }
1562
+ for (const key of DISPLAY_NODE_FILTER_CONTAINS_STRINGS) {
1563
+ const entry = value[key];
1564
+ if (entry !== void 0 && (typeof entry !== "string" || !entry.length || entry.length > 1024)) return false;
1565
+ }
1566
+ if (value.resourceId !== void 0 && (typeof value.resourceId !== "string" || !value.resourceId.length || value.resourceId.length > 256)) return false;
1567
+ for (const key of DISPLAY_NODE_FILTER_BOOLEANS) {
1568
+ const entry = value[key];
1569
+ if (entry !== void 0 && typeof entry !== "boolean") return false;
1570
+ }
1571
+ return true;
1572
+ }
1573
+ function displayNodeText(node) {
1574
+ if (node.kind === "text" || node.kind === "richText" || node.kind === "textInput") return node.text;
1575
+ }
1576
+ function displayNodeTitle(node) {
1577
+ if (node.kind === "button" || node.kind === "label" || node.kind === "comboBox") return node.title;
1578
+ if (node.kind === "component" && node.instanceProperties && "title" in node.instanceProperties && typeof node.instanceProperties.title === "string") return node.instanceProperties.title;
1579
+ }
1580
+ function displayNodeGroup(node) {
1581
+ return "group" in node ? node.group : void 0;
1582
+ }
1583
+ function displayNodeResource(node) {
1584
+ if (node.kind === "image" || node.kind === "component" || node.kind === "movieClip") return {
1585
+ ...node.resource.packageId !== void 0 ? { packageId: node.resource.packageId } : {},
1586
+ resourceId: node.resource.resourceId
1587
+ };
1588
+ if ("src" in node && typeof node.src === "string" && node.src.length > 0) {
1589
+ const packageId = "packageId" in node && typeof node.packageId === "string" && node.packageId.length > 0 ? node.packageId : void 0;
1590
+ return {
1591
+ ...packageId !== void 0 ? { packageId } : {},
1592
+ resourceId: node.src
1593
+ };
1594
+ }
1595
+ }
1596
+ function displayNodeUrl(node) {
1597
+ if (node.kind === "loader" || node.kind === "loader3D") return node.url;
1598
+ }
1599
+ function matchesDisplayNodeFilter(node, filter) {
1600
+ if (!filter) return true;
1601
+ if (filter.kind !== void 0 && node.kind !== filter.kind) return false;
1602
+ if (filter.name !== void 0 && node.name !== filter.name) return false;
1603
+ if (filter.nameContains !== void 0 && !node.name.includes(filter.nameContains)) return false;
1604
+ if (filter.text !== void 0 || filter.textContains !== void 0) {
1605
+ const text = displayNodeText(node);
1606
+ if (typeof text !== "string") return false;
1607
+ if (filter.text !== void 0 && text !== filter.text) return false;
1608
+ if (filter.textContains !== void 0 && !text.includes(filter.textContains)) return false;
1609
+ }
1610
+ if (filter.title !== void 0 || filter.titleContains !== void 0) {
1611
+ const title = displayNodeTitle(node);
1612
+ if (typeof title !== "string") return false;
1613
+ if (filter.title !== void 0 && title !== filter.title) return false;
1614
+ if (filter.titleContains !== void 0 && !title.includes(filter.titleContains)) return false;
1615
+ }
1616
+ if (filter.group !== void 0) {
1617
+ const group = displayNodeGroup(node);
1618
+ if (group === void 0 || group !== filter.group) return false;
1619
+ }
1620
+ if (filter.resourceId !== void 0) {
1621
+ const resource = displayNodeResource(node);
1622
+ if (!resource || resource.resourceId !== filter.resourceId) return false;
1623
+ }
1624
+ if (filter.url !== void 0) {
1625
+ const url = displayNodeUrl(node);
1626
+ if (typeof url !== "string" || url !== filter.url) return false;
1627
+ }
1628
+ if (filter.visible !== void 0 && node.visible !== filter.visible) return false;
1629
+ if (filter.locked !== void 0 && node.locked !== filter.locked) return false;
1630
+ if (filter.touchable !== void 0 && node.touchable !== filter.touchable) return false;
1631
+ if (filter.hasGears !== void 0 && node.gears.length > 0 !== filter.hasGears) return false;
1632
+ if (filter.hasRelations !== void 0 && node.relations.length > 0 !== filter.hasRelations) return false;
1633
+ return true;
1634
+ }
1635
+ function toDisplayNodeCandidate(node, index) {
1636
+ const group = displayNodeGroup(node);
1637
+ const text = displayNodeText(node);
1638
+ const title = displayNodeTitle(node);
1639
+ const resource = displayNodeResource(node);
1640
+ const url = displayNodeUrl(node);
1641
+ return {
1642
+ id: node.id,
1643
+ name: node.name,
1644
+ kind: node.kind,
1645
+ index,
1646
+ position: {
1647
+ x: node.position.x,
1648
+ y: node.position.y
1649
+ },
1650
+ size: {
1651
+ width: node.size.width,
1652
+ height: node.size.height
1653
+ },
1654
+ visible: node.visible,
1655
+ locked: node.locked,
1656
+ touchable: node.touchable,
1657
+ ...group !== void 0 && group.length > 0 ? { group } : {},
1658
+ ...text !== void 0 ? { text } : {},
1659
+ ...title !== void 0 ? { title } : {},
1660
+ ...resource !== void 0 ? { resource } : {},
1661
+ ...url !== void 0 ? { url } : {},
1662
+ gearCount: node.gears.length,
1663
+ relationCount: node.relations.length
1664
+ };
1665
+ }
1312
1666
  /** Bound traversal before serialization or cloning, including non-JSON values on a malformed native input. */
1313
1667
  function queryResponseProblem(value, limits = BACKEND_ENTITY_QUERY_LIMITS) {
1314
1668
  const pending = [{
@@ -1534,6 +1888,53 @@ var ReadService = class {
1534
1888
  }
1535
1889
  return respond(entity);
1536
1890
  }
1891
+ queryDisplayNodes(input) {
1892
+ const startedAt = Date.now();
1893
+ const sessionId = typeof input?.sessionId === "string" ? input.sessionId : "";
1894
+ const session = this.getSessionState(sessionId);
1895
+ if (!session || session.closed) return failure("read", startedAt, createSessionNotFoundError(sessionId));
1896
+ const meta = {
1897
+ sessionId: session.sessionId,
1898
+ revision: session.revision
1899
+ };
1900
+ const reject = (reason) => failure("read", startedAt, {
1901
+ code: "entity_query_failed",
1902
+ sessionId: session.sessionId,
1903
+ reason,
1904
+ message: `Display node query failed: ${reason}.`
1905
+ }, void 0, meta);
1906
+ if (!isPlainRecord(input) || Object.keys(input).some((key) => !DISPLAY_NODE_QUERY_INPUT_KEYS.has(key))) return reject("invalid_query");
1907
+ const selector = input.selector;
1908
+ if (!isPlainRecord(selector) || Object.keys(selector).length !== 2 || ["packageId", "componentResourceId"].some((key) => !Object.hasOwn(selector, key) || typeof selector[key] !== "string" || !selector[key].length || selector[key].length > 256)) return reject("invalid_query");
1909
+ const limit = input.limit ?? BACKEND_DISPLAY_NODE_QUERY_LIMITS.defaultLimit;
1910
+ if (typeof limit !== "number" || !Number.isInteger(limit) || limit < 1 || limit > BACKEND_DISPLAY_NODE_QUERY_LIMITS.maxLimit) return reject("invalid_query");
1911
+ if (input.filter !== void 0 && !isValidDisplayNodeFilter(input.filter)) return reject("invalid_query");
1912
+ const packages = session.project.packages.filter((pkg) => pkg.id === selector.packageId);
1913
+ if (packages.length !== 1) return reject(packages.length ? "ambiguous" : "not_found");
1914
+ const resources = packages[0].resources.filter((resource) => resource.id === selector.componentResourceId);
1915
+ if (resources.length !== 1) return reject(resources.length ? "ambiguous" : "not_found");
1916
+ const resource = resources[0];
1917
+ if (resource.kind !== "component") return reject("not_found");
1918
+ let totalMatched = 0;
1919
+ const nodes = [];
1920
+ for (const [index, node] of resource.component.displayList.entries()) {
1921
+ if (!matchesDisplayNodeFilter(node, input.filter)) continue;
1922
+ totalMatched += 1;
1923
+ if (nodes.length < limit) nodes.push(toDisplayNodeCandidate(node, index));
1924
+ }
1925
+ const data = {
1926
+ ...meta,
1927
+ selector: {
1928
+ packageId: selector.packageId,
1929
+ componentResourceId: selector.componentResourceId
1930
+ },
1931
+ totalMatched,
1932
+ truncated: totalMatched > nodes.length,
1933
+ nodes
1934
+ };
1935
+ const problem = queryResponseProblem(data, BACKEND_DISPLAY_NODE_QUERY_LIMITS);
1936
+ return problem ? reject(problem) : success("read", startedAt, structuredClone(data), meta);
1937
+ }
1537
1938
  resolveReadSession(input, startedAt) {
1538
1939
  if (!input || typeof input.sessionId !== "string" || !input.sessionId.length || input.sessionId.length > 256 || input.expectedRevision !== void 0 && (!Number.isSafeInteger(input.expectedRevision) || input.expectedRevision < 0)) return readFailure(startedAt, typeof input?.sessionId === "string" ? input.sessionId : "", "invalid_query");
1539
1940
  const session = this.getSessionState(input.sessionId);
@@ -1565,6 +1966,7 @@ var ReadService = class {
1565
1966
  dirty: session.dirty,
1566
1967
  lastSavedRevision: session.lastSavedRevision,
1567
1968
  uamFidelity: session.uamFidelity,
1969
+ ...session.uamFidelity === "unsupported" && session.uamFidelityReport ? { uamFidelityReport: session.uamFidelityReport } : {},
1568
1970
  readComplete: session.readComplete,
1569
1971
  readDiagnostics: session.readDiagnostics,
1570
1972
  project: {
@@ -1687,17 +2089,8 @@ function createProjectReaderFileSystem(fileSystem, projectRoot) {
1687
2089
  }
1688
2090
  };
1689
2091
  }
1690
- async function hasFullUamFidelity(document, project) {
1691
- const sourceFiles = /* @__PURE__ */ new Map();
1692
- const materializedFiles = /* @__PURE__ */ new Map();
1693
- const sourceDirectories = /* @__PURE__ */ new Set();
1694
- const materializedDirectories = /* @__PURE__ */ new Set();
1695
- try {
1696
- await Promise.all([new _openfairygui_core_project_io.ProjectWriter(createCaptureFileSystem(sourceFiles, sourceDirectories)).write(document, "Project.fairy"), new _openfairygui_core_project_io.ProjectWriter(createCaptureFileSystem(materializedFiles, materializedDirectories)).write((0, _openfairygui_core_uam.materializeUamProject)(project), "Project.fairy")]);
1697
- } catch {
1698
- return false;
1699
- }
1700
- return capturedFilesEqual(sourceFiles, materializedFiles) && capturedDirectoriesEqual(sourceDirectories, materializedDirectories);
2092
+ function extractFairyFileName(fairyPath) {
2093
+ return fairyPath.replace(/\\/g, "/").split("/").at(-1) || "Project.fairy";
1701
2094
  }
1702
2095
  var RuntimeService = class {
1703
2096
  constructor(context, cacheService, eventService, sessionOperations) {
@@ -1768,6 +2161,11 @@ var RuntimeService = class {
1768
2161
  if (!read.document) throw createProjectReadFailure(read.diagnostics[0]?.message);
1769
2162
  const document = read.document;
1770
2163
  const project = (0, _openfairygui_core_uam.liftDocumentToUamProject)(document);
2164
+ const fidelity = await evaluateUamFidelity(document, project, {
2165
+ readComplete: read.complete,
2166
+ readDiagnostics: read.diagnostics,
2167
+ fairyFileName: extractFairyFileName(fairyPath)
2168
+ });
1771
2169
  const session = {
1772
2170
  sessionId,
1773
2171
  fairyPath,
@@ -1779,7 +2177,8 @@ var RuntimeService = class {
1779
2177
  project,
1780
2178
  readDiagnostics: read.diagnostics,
1781
2179
  readComplete: read.complete,
1782
- uamFidelity: read.complete && await hasFullUamFidelity(document, project) ? "full" : "unsupported",
2180
+ uamFidelity: fidelity.uamFidelity,
2181
+ ...fidelity.uamFidelity === "unsupported" ? { uamFidelityReport: fidelity.report } : {},
1783
2182
  revision: 0,
1784
2183
  lastSavedRevision: 0,
1785
2184
  pendingStaleSourceFiles: /* @__PURE__ */ new Map(),
@@ -1944,6 +2343,7 @@ const BACKEND_METHODS = [
1944
2343
  "getSession",
1945
2344
  "getProjectOutline",
1946
2345
  "queryEntity",
2346
+ "queryDisplayNodes",
1947
2347
  "readSessionState",
1948
2348
  "readResourceBytes",
1949
2349
  "validateSession",
@@ -1966,7 +2366,7 @@ const ARTIFACT_BRIDGE_CAPABILITY = {
1966
2366
  function createCapabilities(atomicSave = false, caseSensitivePaths = false, maxSessions = 32, idleSessionTimeoutMs = 30 * 6e4) {
1967
2367
  return {
1968
2368
  contractVersion: BACKEND_CONTRACT_VERSION,
1969
- capabilitySchemaVersion: 15,
2369
+ capabilitySchemaVersion: 16,
1970
2370
  transactionKernelOwner: "@openfairygui/core",
1971
2371
  appSeamOwner: "@openfairygui/functions",
1972
2372
  runtimeOwner: "@openfairygui/backend",
@@ -1989,6 +2389,13 @@ function createCapabilities(atomicSave = false, caseSensitivePaths = false, maxS
1989
2389
  sourceBytes: false,
1990
2390
  limits: BACKEND_ENTITY_QUERY_LIMITS
1991
2391
  },
2392
+ displayNodeQuery: {
2393
+ scope: "component",
2394
+ filterFields: BACKEND_DISPLAY_NODE_FILTER_FIELDS,
2395
+ projection: "summary",
2396
+ sourceBytes: false,
2397
+ limits: BACKEND_DISPLAY_NODE_QUERY_LIMITS
2398
+ },
1992
2399
  sessionState: {
1993
2400
  sourceBytes: false,
1994
2401
  limits: BACKEND_SESSION_READ_LIMITS.model
@@ -2151,6 +2558,9 @@ var BackendRuntime = class {
2151
2558
  queryEntity(input) {
2152
2559
  return this.readService.queryEntity(input);
2153
2560
  }
2561
+ queryDisplayNodes(input) {
2562
+ return this.readService.queryDisplayNodes(input);
2563
+ }
2154
2564
  readSessionState(input) {
2155
2565
  return this.readService.readSessionState(input);
2156
2566
  }
@@ -2205,6 +2615,18 @@ Object.defineProperty(exports, "BACKEND_CONTRACT_VERSION", {
2205
2615
  return BACKEND_CONTRACT_VERSION;
2206
2616
  }
2207
2617
  });
2618
+ Object.defineProperty(exports, "BACKEND_DISPLAY_NODE_FILTER_FIELDS", {
2619
+ enumerable: true,
2620
+ get: function() {
2621
+ return BACKEND_DISPLAY_NODE_FILTER_FIELDS;
2622
+ }
2623
+ });
2624
+ Object.defineProperty(exports, "BACKEND_DISPLAY_NODE_QUERY_LIMITS", {
2625
+ enumerable: true,
2626
+ get: function() {
2627
+ return BACKEND_DISPLAY_NODE_QUERY_LIMITS;
2628
+ }
2629
+ });
2208
2630
  Object.defineProperty(exports, "BACKEND_ENTITY_QUERY_LIMITS", {
2209
2631
  enumerable: true,
2210
2632
  get: function() {