@absolutejs/absolute 0.19.0-beta.604 → 0.19.0-beta.606

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 (45) hide show
  1. package/dist/ai/client/index.js +238 -6
  2. package/dist/ai/client/index.js.map +4 -4
  3. package/dist/ai/client/ui.js +242 -6
  4. package/dist/ai/client/ui.js.map +4 -4
  5. package/dist/ai/index.js +381 -38
  6. package/dist/ai/index.js.map +7 -7
  7. package/dist/ai/rag/quality.js +17 -6
  8. package/dist/ai/rag/quality.js.map +3 -3
  9. package/dist/ai/rag/ui.js +242 -6
  10. package/dist/ai/rag/ui.js.map +4 -4
  11. package/dist/ai-client/angular/ai/index.js +237 -5
  12. package/dist/ai-client/react/ai/index.js +281 -12
  13. package/dist/ai-client/vue/ai/index.js +364 -97
  14. package/dist/angular/ai/index.js +238 -6
  15. package/dist/angular/ai/index.js.map +4 -4
  16. package/dist/angular/index.js +2 -2
  17. package/dist/angular/index.js.map +1 -1
  18. package/dist/angular/server.js +2 -2
  19. package/dist/angular/server.js.map +1 -1
  20. package/dist/build.js +2 -2
  21. package/dist/build.js.map +1 -1
  22. package/dist/index.js +2 -2
  23. package/dist/index.js.map +1 -1
  24. package/dist/react/ai/index.js +282 -13
  25. package/dist/react/ai/index.js.map +6 -6
  26. package/dist/src/ai/client/ui.d.ts +1 -1
  27. package/dist/src/ai/rag/index.d.ts +1 -1
  28. package/dist/src/ai/rag/presentation.d.ts +7 -1
  29. package/dist/src/ai/rag/ui.d.ts +1 -1
  30. package/dist/src/react/ai/useRAG.d.ts +9 -0
  31. package/dist/src/react/ai/useRAGChunkPreview.d.ts +7 -0
  32. package/dist/src/react/ai/useRAGSources.d.ts +2 -0
  33. package/dist/src/svelte/ai/createRAG.d.ts +9 -0
  34. package/dist/src/svelte/ai/createRAGChunkPreview.d.ts +7 -0
  35. package/dist/src/svelte/ai/createRAGSources.d.ts +2 -0
  36. package/dist/src/vue/ai/useRAG.d.ts +69 -0
  37. package/dist/src/vue/ai/useRAGChunkPreview.d.ts +37 -0
  38. package/dist/src/vue/ai/useRAGSearch.d.ts +30 -0
  39. package/dist/src/vue/ai/useRAGSources.d.ts +2 -0
  40. package/dist/svelte/ai/index.js +334 -53
  41. package/dist/svelte/ai/index.js.map +6 -6
  42. package/dist/types/ai.d.ts +66 -0
  43. package/dist/vue/ai/index.js +328 -59
  44. package/dist/vue/ai/index.js.map +6 -6
  45. package/package.json +1 -1
@@ -910,6 +910,11 @@ var buildContextLabel = (metadata) => {
910
910
  if (speaker) {
911
911
  return `Speaker ${speaker}`;
912
912
  }
913
+ const sectionPath = Array.isArray(metadata.sectionPath) ? metadata.sectionPath.map((value) => getContextString(value)).filter((value) => typeof value === "string") : [];
914
+ const sectionTitle = getContextString(metadata.sectionTitle) ?? sectionPath.at(-1);
915
+ if (sectionTitle) {
916
+ return `Section ${sectionTitle}`;
917
+ }
913
918
  return;
914
919
  };
915
920
  var formatMediaTimestamp = (value) => {
@@ -959,6 +964,10 @@ var buildLocatorLabel = (metadata, source, title) => {
959
964
  if (mediaStart) {
960
965
  return `Timestamp ${mediaStart}`;
961
966
  }
967
+ const sectionPath = Array.isArray(metadata.sectionPath) ? metadata.sectionPath.map((value) => getContextString(value)).filter((value) => typeof value === "string") : [];
968
+ if (sectionPath.length > 0) {
969
+ return `Section ${sectionPath.join(" > ")}`;
970
+ }
962
971
  return;
963
972
  };
964
973
  var formatTimestampLabel = (value) => {
@@ -1008,8 +1017,10 @@ var buildExcerpt = (text, maxLength = 160) => {
1008
1017
  var buildGroundingReferenceEvidenceLabel = (reference) => [reference.label, reference.locatorLabel, reference.contextLabel].filter((value) => Boolean(value && value.length > 0)).filter((value, index, values) => values.findIndex((entry) => entry === value) === index).join(" \xB7 ");
1009
1018
  var buildGroundingReferenceEvidenceSummary = (reference) => [
1010
1019
  reference.source ?? reference.title ?? reference.chunkId,
1020
+ reference.locatorLabel,
1021
+ reference.contextLabel,
1011
1022
  reference.provenanceLabel
1012
- ].filter((value) => Boolean(value && value.length > 0)).join(" \xB7 ");
1023
+ ].filter((value) => Boolean(value && value.length > 0)).filter((value, index, values) => values.findIndex((entry) => entry === value) === index).join(" \xB7 ");
1013
1024
  var buildGroundedAnswerCitationDetail = (reference) => ({
1014
1025
  contextLabel: reference.contextLabel,
1015
1026
  evidenceLabel: buildGroundingReferenceEvidenceLabel(reference),
@@ -1033,12 +1044,12 @@ var buildRAGCitations = (sources) => {
1033
1044
  continue;
1034
1045
  unique.set(key, {
1035
1046
  chunkId: source.chunkId,
1036
- contextLabel: buildContextLabel(source.metadata),
1047
+ contextLabel: source.labels?.contextLabel ?? buildContextLabel(source.metadata),
1037
1048
  key,
1038
1049
  label: buildSourceLabel(source),
1039
- locatorLabel: buildLocatorLabel(source.metadata, source.source, source.title),
1050
+ locatorLabel: source.labels?.locatorLabel ?? buildLocatorLabel(source.metadata, source.source, source.title),
1040
1051
  metadata: source.metadata,
1041
- provenanceLabel: buildProvenanceLabel(source.metadata),
1052
+ provenanceLabel: source.labels?.provenanceLabel ?? buildProvenanceLabel(source.metadata),
1042
1053
  score: source.score,
1043
1054
  source: source.source,
1044
1055
  text: source.text,
@@ -1108,7 +1119,7 @@ var buildRAGGroundingReferences = (sources) => {
1108
1119
  const citationReferenceMap = buildRAGCitationReferenceMap(citations);
1109
1120
  return citations.map((citation) => ({
1110
1121
  chunkId: citation.chunkId,
1111
- contextLabel: buildContextLabel(citation.metadata),
1122
+ contextLabel: citation.contextLabel ?? buildContextLabel(citation.metadata),
1112
1123
  excerpt: buildExcerpt(citation.text),
1113
1124
  label: citation.label,
1114
1125
  locatorLabel: citation.locatorLabel ?? buildLocatorLabel(citation.metadata, citation.source, citation.title),
@@ -1610,6 +1621,11 @@ var buildContextLabel2 = (metadata) => {
1610
1621
  if (speaker) {
1611
1622
  return `Speaker ${speaker}`;
1612
1623
  }
1624
+ const sectionPath = Array.isArray(metadata.sectionPath) ? metadata.sectionPath.map((value) => getContextString2(value)).filter((value) => typeof value === "string") : [];
1625
+ const sectionTitle = getContextString2(metadata.sectionTitle) ?? sectionPath.at(-1);
1626
+ if (sectionTitle) {
1627
+ return `Section ${sectionTitle}`;
1628
+ }
1613
1629
  return;
1614
1630
  };
1615
1631
  var buildLocatorLabel2 = (metadata, source, title) => {
@@ -1649,6 +1665,10 @@ var buildLocatorLabel2 = (metadata, source, title) => {
1649
1665
  if (mediaStart) {
1650
1666
  return `Timestamp ${mediaStart}`;
1651
1667
  }
1668
+ const sectionPath = Array.isArray(metadata.sectionPath) ? metadata.sectionPath.map((value) => getContextString2(value)).filter((value) => typeof value === "string") : [];
1669
+ if (sectionPath.length > 0) {
1670
+ return `Section ${sectionPath.join(" > ")}`;
1671
+ }
1652
1672
  return;
1653
1673
  };
1654
1674
  var buildProvenanceLabel2 = (metadata) => {
@@ -1694,6 +1714,33 @@ var buildRAGSourceLabels = ({
1694
1714
  provenanceLabel
1695
1715
  };
1696
1716
  };
1717
+ var buildRAGChunkStructure = (metadata) => {
1718
+ if (!metadata) {
1719
+ return;
1720
+ }
1721
+ const sectionPath = Array.isArray(metadata.sectionPath) ? metadata.sectionPath.filter((value) => typeof value === "string" && value.trim().length > 0) : undefined;
1722
+ const sectionKind = metadata.sectionKind === "markdown_heading" || metadata.sectionKind === "html_heading" ? metadata.sectionKind : undefined;
1723
+ const section = {
1724
+ depth: getContextNumber2(metadata.sectionDepth),
1725
+ kind: sectionKind,
1726
+ path: sectionPath && sectionPath.length > 0 ? sectionPath : undefined,
1727
+ title: getContextString2(metadata.sectionTitle)
1728
+ };
1729
+ const sequence = {
1730
+ nextChunkId: getContextString2(metadata.nextChunkId),
1731
+ previousChunkId: getContextString2(metadata.previousChunkId),
1732
+ sectionChunkCount: getContextNumber2(metadata.sectionChunkCount),
1733
+ sectionChunkId: getContextString2(metadata.sectionChunkId),
1734
+ sectionChunkIndex: getContextNumber2(metadata.sectionChunkIndex)
1735
+ };
1736
+ if (!section.title && (!section.path || section.path.length === 0) && typeof section.depth !== "number" && !section.kind && !sequence.nextChunkId && !sequence.previousChunkId && typeof sequence.sectionChunkCount !== "number" && !sequence.sectionChunkId && typeof sequence.sectionChunkIndex !== "number") {
1737
+ return;
1738
+ }
1739
+ return {
1740
+ section: section.title || section.path && section.path.length > 0 || typeof section.depth === "number" || section.kind ? section : undefined,
1741
+ sequence: sequence.nextChunkId || sequence.previousChunkId || typeof sequence.sectionChunkCount === "number" || sequence.sectionChunkId || typeof sequence.sectionChunkIndex === "number" ? sequence : undefined
1742
+ };
1743
+ };
1697
1744
  var buildExcerpt2 = (text, maxLength = 160) => {
1698
1745
  const normalized = text.replaceAll(/\s+/g, " ").trim();
1699
1746
  if (normalized.length <= maxLength) {
@@ -1701,6 +1748,188 @@ var buildExcerpt2 = (text, maxLength = 160) => {
1701
1748
  }
1702
1749
  return `${normalized.slice(0, Math.max(0, maxLength - 1)).trimEnd()}\u2026`;
1703
1750
  };
1751
+ var buildRAGChunkGraph = (chunks) => {
1752
+ const nodes = [];
1753
+ const edges = [];
1754
+ const edgeKeys = new Set;
1755
+ const sections = new Map;
1756
+ for (const chunk of chunks) {
1757
+ const labels = chunk.labels ?? buildRAGSourceLabels({
1758
+ metadata: chunk.metadata,
1759
+ source: chunk.source,
1760
+ title: chunk.title
1761
+ });
1762
+ const structure = chunk.structure ?? buildRAGChunkStructure(chunk.metadata);
1763
+ nodes.push({
1764
+ chunkId: chunk.chunkId,
1765
+ contextLabel: labels?.contextLabel,
1766
+ label: chunk.source ?? chunk.title ?? chunk.chunkId,
1767
+ locatorLabel: labels?.locatorLabel,
1768
+ provenanceLabel: labels?.provenanceLabel,
1769
+ score: chunk.score,
1770
+ source: chunk.source,
1771
+ structure,
1772
+ title: chunk.title
1773
+ });
1774
+ const previousChunkId = structure?.sequence?.previousChunkId;
1775
+ if (previousChunkId) {
1776
+ const key = `previous:${previousChunkId}:${chunk.chunkId}`;
1777
+ if (!edgeKeys.has(key)) {
1778
+ edgeKeys.add(key);
1779
+ edges.push({
1780
+ fromChunkId: previousChunkId,
1781
+ relation: "previous",
1782
+ toChunkId: chunk.chunkId
1783
+ });
1784
+ }
1785
+ }
1786
+ const nextChunkId = structure?.sequence?.nextChunkId;
1787
+ if (nextChunkId) {
1788
+ const key = `next:${chunk.chunkId}:${nextChunkId}`;
1789
+ if (!edgeKeys.has(key)) {
1790
+ edgeKeys.add(key);
1791
+ edges.push({
1792
+ fromChunkId: chunk.chunkId,
1793
+ relation: "next",
1794
+ toChunkId: nextChunkId
1795
+ });
1796
+ }
1797
+ }
1798
+ const sectionId = structure?.sequence?.sectionChunkId;
1799
+ if (sectionId) {
1800
+ const existing = sections.get(sectionId);
1801
+ if (!existing) {
1802
+ sections.set(sectionId, {
1803
+ childSectionIds: [],
1804
+ chunkCount: structure.sequence?.sectionChunkCount ?? 1,
1805
+ chunkIds: [chunk.chunkId],
1806
+ depth: structure.section?.depth,
1807
+ id: sectionId,
1808
+ kind: structure.section?.kind,
1809
+ leadChunkId: chunk.chunkId,
1810
+ path: structure.section?.path,
1811
+ title: structure.section?.title
1812
+ });
1813
+ continue;
1814
+ }
1815
+ if (!existing.chunkIds.includes(chunk.chunkId)) {
1816
+ existing.chunkIds.push(chunk.chunkId);
1817
+ }
1818
+ existing.chunkCount = Math.max(existing.chunkCount, structure.sequence?.sectionChunkCount ?? existing.chunkCount);
1819
+ }
1820
+ }
1821
+ for (const section of sections.values()) {
1822
+ section.chunkIds.sort((left, right) => {
1823
+ const leftNode = nodes.find((node) => node.chunkId === left);
1824
+ const rightNode = nodes.find((node) => node.chunkId === right);
1825
+ const leftIndex = leftNode?.structure?.sequence?.sectionChunkIndex ?? Number.MAX_SAFE_INTEGER;
1826
+ const rightIndex = rightNode?.structure?.sequence?.sectionChunkIndex ?? Number.MAX_SAFE_INTEGER;
1827
+ if (leftIndex !== rightIndex) {
1828
+ return leftIndex - rightIndex;
1829
+ }
1830
+ return left.localeCompare(right);
1831
+ });
1832
+ section.leadChunkId = section.chunkIds[0];
1833
+ }
1834
+ const sectionPathIndex = new Map;
1835
+ for (const section of sections.values()) {
1836
+ const path = section.path && section.path.length > 0 ? section.path : section.title ? [section.title] : undefined;
1837
+ if (path && path.length > 0) {
1838
+ sectionPathIndex.set(path.join("\x00"), section);
1839
+ }
1840
+ }
1841
+ for (const section of sections.values()) {
1842
+ const path = section.path && section.path.length > 0 ? section.path : section.title ? [section.title] : undefined;
1843
+ if (!path || path.length < 2) {
1844
+ continue;
1845
+ }
1846
+ const parent = sectionPathIndex.get(path.slice(0, -1).join("\x00"));
1847
+ if (!parent || parent.id === section.id) {
1848
+ continue;
1849
+ }
1850
+ section.parentSectionId = parent.id;
1851
+ if (!parent.childSectionIds.includes(section.id)) {
1852
+ parent.childSectionIds.push(section.id);
1853
+ }
1854
+ if (parent.leadChunkId && section.leadChunkId) {
1855
+ const parentKey = `section_parent:${section.leadChunkId}:${parent.leadChunkId}`;
1856
+ if (!edgeKeys.has(parentKey)) {
1857
+ edgeKeys.add(parentKey);
1858
+ edges.push({
1859
+ fromChunkId: section.leadChunkId,
1860
+ relation: "section_parent",
1861
+ toChunkId: parent.leadChunkId
1862
+ });
1863
+ }
1864
+ const childKey = `section_child:${parent.leadChunkId}:${section.leadChunkId}`;
1865
+ if (!edgeKeys.has(childKey)) {
1866
+ edgeKeys.add(childKey);
1867
+ edges.push({
1868
+ fromChunkId: parent.leadChunkId,
1869
+ relation: "section_child",
1870
+ toChunkId: section.leadChunkId
1871
+ });
1872
+ }
1873
+ }
1874
+ }
1875
+ nodes.sort((left, right) => {
1876
+ const leftSection = left.structure?.sequence?.sectionChunkIndex ?? Number.MAX_SAFE_INTEGER;
1877
+ const rightSection = right.structure?.sequence?.sectionChunkIndex ?? Number.MAX_SAFE_INTEGER;
1878
+ if (leftSection !== rightSection) {
1879
+ return leftSection - rightSection;
1880
+ }
1881
+ const leftScore = left.score ?? Number.NEGATIVE_INFINITY;
1882
+ const rightScore = right.score ?? Number.NEGATIVE_INFINITY;
1883
+ if (leftScore !== rightScore) {
1884
+ return rightScore - leftScore;
1885
+ }
1886
+ return left.label.localeCompare(right.label);
1887
+ });
1888
+ return {
1889
+ edges,
1890
+ nodes,
1891
+ sections: [...sections.values()].sort((left, right) => (left.title ?? left.id).localeCompare(right.title ?? right.id))
1892
+ };
1893
+ };
1894
+ var buildRAGChunkPreviewGraph = (preview) => buildRAGChunkGraph(preview.chunks.map((chunk) => ({
1895
+ chunkId: chunk.chunkId,
1896
+ labels: chunk.labels,
1897
+ metadata: chunk.metadata,
1898
+ source: chunk.source ?? preview.document.source,
1899
+ structure: chunk.structure,
1900
+ title: chunk.title ?? preview.document.title
1901
+ })));
1902
+ var buildRAGChunkPreviewNavigation = (preview, activeChunkId) => buildRAGChunkGraphNavigation(buildRAGChunkPreviewGraph(preview), activeChunkId);
1903
+ var buildRAGChunkGraphNavigation = (graph, activeChunkId) => {
1904
+ if (graph.nodes.length === 0) {
1905
+ return {
1906
+ activeChunkId,
1907
+ childSections: [],
1908
+ siblingSections: [],
1909
+ sectionNodes: []
1910
+ };
1911
+ }
1912
+ const activeNode = (activeChunkId ? graph.nodes.find((node) => node.chunkId === activeChunkId) : undefined) ?? graph.nodes[0];
1913
+ const resolvedActiveChunkId = activeNode?.chunkId;
1914
+ const previousNode = activeNode?.structure?.sequence?.previousChunkId ? graph.nodes.find((node) => node.chunkId === activeNode.structure?.sequence?.previousChunkId) : undefined;
1915
+ const nextNode = activeNode?.structure?.sequence?.nextChunkId ? graph.nodes.find((node) => node.chunkId === activeNode.structure?.sequence?.nextChunkId) : undefined;
1916
+ const section = activeNode?.structure?.sequence?.sectionChunkId ? graph.sections.find((entry) => entry.id === activeNode.structure?.sequence?.sectionChunkId) : undefined;
1917
+ const parentSection = section?.parentSectionId ? graph.sections.find((entry) => entry.id === section.parentSectionId) : undefined;
1918
+ const childSections = section ? section.childSectionIds.map((sectionId) => graph.sections.find((entry) => entry.id === sectionId)).filter((entry) => Boolean(entry)) : [];
1919
+ const siblingSections = section?.parentSectionId ? graph.sections.filter((entry) => entry.parentSectionId === section.parentSectionId && entry.id !== section.id) : [];
1920
+ const sectionNodes = section ? section.chunkIds.map((chunkId) => graph.nodes.find((node) => node.chunkId === chunkId)).filter((node) => Boolean(node)) : activeNode ? [activeNode] : [];
1921
+ return {
1922
+ activeChunkId: resolvedActiveChunkId,
1923
+ activeNode,
1924
+ childSections,
1925
+ nextNode,
1926
+ parentSection,
1927
+ previousNode,
1928
+ section,
1929
+ siblingSections,
1930
+ sectionNodes
1931
+ };
1932
+ };
1704
1933
  var buildRAGRetrievedState = (messages) => {
1705
1934
  const message = getLatestRetrievedMessage(messages);
1706
1935
  if (!message) {
@@ -1742,6 +1971,7 @@ var buildRAGSourceSummaries = (sources) => {
1742
1971
  label: group.label,
1743
1972
  locatorLabel: leadChunk?.labels?.locatorLabel ?? buildLocatorLabel2(leadChunk?.metadata, leadChunk?.source, leadChunk?.title),
1744
1973
  provenanceLabel: leadChunk?.labels?.provenanceLabel ?? buildProvenanceLabel2(leadChunk?.metadata),
1974
+ structure: leadChunk?.structure ?? buildRAGChunkStructure(leadChunk?.metadata),
1745
1975
  source: group.source,
1746
1976
  title: group.title
1747
1977
  };
@@ -1870,6 +2100,7 @@ var buildSourceGroup = (source, key) => ({
1870
2100
  source: source.source,
1871
2101
  title: source.title
1872
2102
  }),
2103
+ structure: source.structure ?? buildRAGChunkStructure(source.metadata),
1873
2104
  source: source.source,
1874
2105
  title: source.title
1875
2106
  });
@@ -1888,6 +2119,7 @@ var updateSourceGroup = (groups, source) => {
1888
2119
  source: source.source,
1889
2120
  title: source.title
1890
2121
  });
2122
+ existing.structure = source.structure ?? buildRAGChunkStructure(source.metadata);
1891
2123
  existing.source = source.source;
1892
2124
  existing.title = source.title;
1893
2125
  } else {
@@ -3902,5 +4134,5 @@ export {
3902
4134
  AIStreamService
3903
4135
  };
3904
4136
 
3905
- //# debugId=3F2480BFA9734C4564756E2164756E21
4137
+ //# debugId=6BA4A5140094B73664756E2164756E21
3906
4138
  //# sourceMappingURL=index.js.map