@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
package/dist/ai/rag/ui.js CHANGED
@@ -132,6 +132,11 @@ var buildContextLabel = (metadata) => {
132
132
  if (speaker) {
133
133
  return `Speaker ${speaker}`;
134
134
  }
135
+ const sectionPath = Array.isArray(metadata.sectionPath) ? metadata.sectionPath.map((value) => getContextString(value)).filter((value) => typeof value === "string") : [];
136
+ const sectionTitle = getContextString(metadata.sectionTitle) ?? sectionPath.at(-1);
137
+ if (sectionTitle) {
138
+ return `Section ${sectionTitle}`;
139
+ }
135
140
  return;
136
141
  };
137
142
  var formatMediaTimestamp = (value) => {
@@ -181,6 +186,10 @@ var buildLocatorLabel = (metadata, source, title) => {
181
186
  if (mediaStart) {
182
187
  return `Timestamp ${mediaStart}`;
183
188
  }
189
+ const sectionPath = Array.isArray(metadata.sectionPath) ? metadata.sectionPath.map((value) => getContextString(value)).filter((value) => typeof value === "string") : [];
190
+ if (sectionPath.length > 0) {
191
+ return `Section ${sectionPath.join(" > ")}`;
192
+ }
184
193
  return;
185
194
  };
186
195
  var formatTimestampLabel = (value) => {
@@ -230,8 +239,10 @@ var buildExcerpt = (text, maxLength = 160) => {
230
239
  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 ");
231
240
  var buildGroundingReferenceEvidenceSummary = (reference) => [
232
241
  reference.source ?? reference.title ?? reference.chunkId,
242
+ reference.locatorLabel,
243
+ reference.contextLabel,
233
244
  reference.provenanceLabel
234
- ].filter((value) => Boolean(value && value.length > 0)).join(" \xB7 ");
245
+ ].filter((value) => Boolean(value && value.length > 0)).filter((value, index, values) => values.findIndex((entry) => entry === value) === index).join(" \xB7 ");
235
246
  var buildGroundedAnswerCitationDetail = (reference) => ({
236
247
  contextLabel: reference.contextLabel,
237
248
  evidenceLabel: buildGroundingReferenceEvidenceLabel(reference),
@@ -255,12 +266,12 @@ var buildRAGCitations = (sources) => {
255
266
  continue;
256
267
  unique.set(key, {
257
268
  chunkId: source.chunkId,
258
- contextLabel: buildContextLabel(source.metadata),
269
+ contextLabel: source.labels?.contextLabel ?? buildContextLabel(source.metadata),
259
270
  key,
260
271
  label: buildSourceLabel(source),
261
- locatorLabel: buildLocatorLabel(source.metadata, source.source, source.title),
272
+ locatorLabel: source.labels?.locatorLabel ?? buildLocatorLabel(source.metadata, source.source, source.title),
262
273
  metadata: source.metadata,
263
- provenanceLabel: buildProvenanceLabel(source.metadata),
274
+ provenanceLabel: source.labels?.provenanceLabel ?? buildProvenanceLabel(source.metadata),
264
275
  score: source.score,
265
276
  source: source.source,
266
277
  text: source.text,
@@ -330,7 +341,7 @@ var buildRAGGroundingReferences = (sources) => {
330
341
  const citationReferenceMap = buildRAGCitationReferenceMap(citations);
331
342
  return citations.map((citation) => ({
332
343
  chunkId: citation.chunkId,
333
- contextLabel: buildContextLabel(citation.metadata),
344
+ contextLabel: citation.contextLabel ?? buildContextLabel(citation.metadata),
334
345
  excerpt: buildExcerpt(citation.text),
335
346
  label: citation.label,
336
347
  locatorLabel: citation.locatorLabel ?? buildLocatorLabel(citation.metadata, citation.source, citation.title),
@@ -832,6 +843,11 @@ var buildContextLabel2 = (metadata) => {
832
843
  if (speaker) {
833
844
  return `Speaker ${speaker}`;
834
845
  }
846
+ const sectionPath = Array.isArray(metadata.sectionPath) ? metadata.sectionPath.map((value) => getContextString2(value)).filter((value) => typeof value === "string") : [];
847
+ const sectionTitle = getContextString2(metadata.sectionTitle) ?? sectionPath.at(-1);
848
+ if (sectionTitle) {
849
+ return `Section ${sectionTitle}`;
850
+ }
835
851
  return;
836
852
  };
837
853
  var buildLocatorLabel2 = (metadata, source, title) => {
@@ -871,6 +887,10 @@ var buildLocatorLabel2 = (metadata, source, title) => {
871
887
  if (mediaStart) {
872
888
  return `Timestamp ${mediaStart}`;
873
889
  }
890
+ const sectionPath = Array.isArray(metadata.sectionPath) ? metadata.sectionPath.map((value) => getContextString2(value)).filter((value) => typeof value === "string") : [];
891
+ if (sectionPath.length > 0) {
892
+ return `Section ${sectionPath.join(" > ")}`;
893
+ }
874
894
  return;
875
895
  };
876
896
  var buildProvenanceLabel2 = (metadata) => {
@@ -916,6 +936,33 @@ var buildRAGSourceLabels = ({
916
936
  provenanceLabel
917
937
  };
918
938
  };
939
+ var buildRAGChunkStructure = (metadata) => {
940
+ if (!metadata) {
941
+ return;
942
+ }
943
+ const sectionPath = Array.isArray(metadata.sectionPath) ? metadata.sectionPath.filter((value) => typeof value === "string" && value.trim().length > 0) : undefined;
944
+ const sectionKind = metadata.sectionKind === "markdown_heading" || metadata.sectionKind === "html_heading" ? metadata.sectionKind : undefined;
945
+ const section = {
946
+ depth: getContextNumber2(metadata.sectionDepth),
947
+ kind: sectionKind,
948
+ path: sectionPath && sectionPath.length > 0 ? sectionPath : undefined,
949
+ title: getContextString2(metadata.sectionTitle)
950
+ };
951
+ const sequence = {
952
+ nextChunkId: getContextString2(metadata.nextChunkId),
953
+ previousChunkId: getContextString2(metadata.previousChunkId),
954
+ sectionChunkCount: getContextNumber2(metadata.sectionChunkCount),
955
+ sectionChunkId: getContextString2(metadata.sectionChunkId),
956
+ sectionChunkIndex: getContextNumber2(metadata.sectionChunkIndex)
957
+ };
958
+ 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") {
959
+ return;
960
+ }
961
+ return {
962
+ section: section.title || section.path && section.path.length > 0 || typeof section.depth === "number" || section.kind ? section : undefined,
963
+ sequence: sequence.nextChunkId || sequence.previousChunkId || typeof sequence.sectionChunkCount === "number" || sequence.sectionChunkId || typeof sequence.sectionChunkIndex === "number" ? sequence : undefined
964
+ };
965
+ };
919
966
  var buildExcerpt2 = (text, maxLength = 160) => {
920
967
  const normalized = text.replaceAll(/\s+/g, " ").trim();
921
968
  if (normalized.length <= maxLength) {
@@ -923,6 +970,188 @@ var buildExcerpt2 = (text, maxLength = 160) => {
923
970
  }
924
971
  return `${normalized.slice(0, Math.max(0, maxLength - 1)).trimEnd()}\u2026`;
925
972
  };
973
+ var buildRAGChunkGraph = (chunks) => {
974
+ const nodes = [];
975
+ const edges = [];
976
+ const edgeKeys = new Set;
977
+ const sections = new Map;
978
+ for (const chunk of chunks) {
979
+ const labels = chunk.labels ?? buildRAGSourceLabels({
980
+ metadata: chunk.metadata,
981
+ source: chunk.source,
982
+ title: chunk.title
983
+ });
984
+ const structure = chunk.structure ?? buildRAGChunkStructure(chunk.metadata);
985
+ nodes.push({
986
+ chunkId: chunk.chunkId,
987
+ contextLabel: labels?.contextLabel,
988
+ label: chunk.source ?? chunk.title ?? chunk.chunkId,
989
+ locatorLabel: labels?.locatorLabel,
990
+ provenanceLabel: labels?.provenanceLabel,
991
+ score: chunk.score,
992
+ source: chunk.source,
993
+ structure,
994
+ title: chunk.title
995
+ });
996
+ const previousChunkId = structure?.sequence?.previousChunkId;
997
+ if (previousChunkId) {
998
+ const key = `previous:${previousChunkId}:${chunk.chunkId}`;
999
+ if (!edgeKeys.has(key)) {
1000
+ edgeKeys.add(key);
1001
+ edges.push({
1002
+ fromChunkId: previousChunkId,
1003
+ relation: "previous",
1004
+ toChunkId: chunk.chunkId
1005
+ });
1006
+ }
1007
+ }
1008
+ const nextChunkId = structure?.sequence?.nextChunkId;
1009
+ if (nextChunkId) {
1010
+ const key = `next:${chunk.chunkId}:${nextChunkId}`;
1011
+ if (!edgeKeys.has(key)) {
1012
+ edgeKeys.add(key);
1013
+ edges.push({
1014
+ fromChunkId: chunk.chunkId,
1015
+ relation: "next",
1016
+ toChunkId: nextChunkId
1017
+ });
1018
+ }
1019
+ }
1020
+ const sectionId = structure?.sequence?.sectionChunkId;
1021
+ if (sectionId) {
1022
+ const existing = sections.get(sectionId);
1023
+ if (!existing) {
1024
+ sections.set(sectionId, {
1025
+ childSectionIds: [],
1026
+ chunkCount: structure.sequence?.sectionChunkCount ?? 1,
1027
+ chunkIds: [chunk.chunkId],
1028
+ depth: structure.section?.depth,
1029
+ id: sectionId,
1030
+ kind: structure.section?.kind,
1031
+ leadChunkId: chunk.chunkId,
1032
+ path: structure.section?.path,
1033
+ title: structure.section?.title
1034
+ });
1035
+ continue;
1036
+ }
1037
+ if (!existing.chunkIds.includes(chunk.chunkId)) {
1038
+ existing.chunkIds.push(chunk.chunkId);
1039
+ }
1040
+ existing.chunkCount = Math.max(existing.chunkCount, structure.sequence?.sectionChunkCount ?? existing.chunkCount);
1041
+ }
1042
+ }
1043
+ for (const section of sections.values()) {
1044
+ section.chunkIds.sort((left, right) => {
1045
+ const leftNode = nodes.find((node) => node.chunkId === left);
1046
+ const rightNode = nodes.find((node) => node.chunkId === right);
1047
+ const leftIndex = leftNode?.structure?.sequence?.sectionChunkIndex ?? Number.MAX_SAFE_INTEGER;
1048
+ const rightIndex = rightNode?.structure?.sequence?.sectionChunkIndex ?? Number.MAX_SAFE_INTEGER;
1049
+ if (leftIndex !== rightIndex) {
1050
+ return leftIndex - rightIndex;
1051
+ }
1052
+ return left.localeCompare(right);
1053
+ });
1054
+ section.leadChunkId = section.chunkIds[0];
1055
+ }
1056
+ const sectionPathIndex = new Map;
1057
+ for (const section of sections.values()) {
1058
+ const path = section.path && section.path.length > 0 ? section.path : section.title ? [section.title] : undefined;
1059
+ if (path && path.length > 0) {
1060
+ sectionPathIndex.set(path.join("\x00"), section);
1061
+ }
1062
+ }
1063
+ for (const section of sections.values()) {
1064
+ const path = section.path && section.path.length > 0 ? section.path : section.title ? [section.title] : undefined;
1065
+ if (!path || path.length < 2) {
1066
+ continue;
1067
+ }
1068
+ const parent = sectionPathIndex.get(path.slice(0, -1).join("\x00"));
1069
+ if (!parent || parent.id === section.id) {
1070
+ continue;
1071
+ }
1072
+ section.parentSectionId = parent.id;
1073
+ if (!parent.childSectionIds.includes(section.id)) {
1074
+ parent.childSectionIds.push(section.id);
1075
+ }
1076
+ if (parent.leadChunkId && section.leadChunkId) {
1077
+ const parentKey = `section_parent:${section.leadChunkId}:${parent.leadChunkId}`;
1078
+ if (!edgeKeys.has(parentKey)) {
1079
+ edgeKeys.add(parentKey);
1080
+ edges.push({
1081
+ fromChunkId: section.leadChunkId,
1082
+ relation: "section_parent",
1083
+ toChunkId: parent.leadChunkId
1084
+ });
1085
+ }
1086
+ const childKey = `section_child:${parent.leadChunkId}:${section.leadChunkId}`;
1087
+ if (!edgeKeys.has(childKey)) {
1088
+ edgeKeys.add(childKey);
1089
+ edges.push({
1090
+ fromChunkId: parent.leadChunkId,
1091
+ relation: "section_child",
1092
+ toChunkId: section.leadChunkId
1093
+ });
1094
+ }
1095
+ }
1096
+ }
1097
+ nodes.sort((left, right) => {
1098
+ const leftSection = left.structure?.sequence?.sectionChunkIndex ?? Number.MAX_SAFE_INTEGER;
1099
+ const rightSection = right.structure?.sequence?.sectionChunkIndex ?? Number.MAX_SAFE_INTEGER;
1100
+ if (leftSection !== rightSection) {
1101
+ return leftSection - rightSection;
1102
+ }
1103
+ const leftScore = left.score ?? Number.NEGATIVE_INFINITY;
1104
+ const rightScore = right.score ?? Number.NEGATIVE_INFINITY;
1105
+ if (leftScore !== rightScore) {
1106
+ return rightScore - leftScore;
1107
+ }
1108
+ return left.label.localeCompare(right.label);
1109
+ });
1110
+ return {
1111
+ edges,
1112
+ nodes,
1113
+ sections: [...sections.values()].sort((left, right) => (left.title ?? left.id).localeCompare(right.title ?? right.id))
1114
+ };
1115
+ };
1116
+ var buildRAGChunkPreviewGraph = (preview) => buildRAGChunkGraph(preview.chunks.map((chunk) => ({
1117
+ chunkId: chunk.chunkId,
1118
+ labels: chunk.labels,
1119
+ metadata: chunk.metadata,
1120
+ source: chunk.source ?? preview.document.source,
1121
+ structure: chunk.structure,
1122
+ title: chunk.title ?? preview.document.title
1123
+ })));
1124
+ var buildRAGChunkPreviewNavigation = (preview, activeChunkId) => buildRAGChunkGraphNavigation(buildRAGChunkPreviewGraph(preview), activeChunkId);
1125
+ var buildRAGChunkGraphNavigation = (graph, activeChunkId) => {
1126
+ if (graph.nodes.length === 0) {
1127
+ return {
1128
+ activeChunkId,
1129
+ childSections: [],
1130
+ siblingSections: [],
1131
+ sectionNodes: []
1132
+ };
1133
+ }
1134
+ const activeNode = (activeChunkId ? graph.nodes.find((node) => node.chunkId === activeChunkId) : undefined) ?? graph.nodes[0];
1135
+ const resolvedActiveChunkId = activeNode?.chunkId;
1136
+ const previousNode = activeNode?.structure?.sequence?.previousChunkId ? graph.nodes.find((node) => node.chunkId === activeNode.structure?.sequence?.previousChunkId) : undefined;
1137
+ const nextNode = activeNode?.structure?.sequence?.nextChunkId ? graph.nodes.find((node) => node.chunkId === activeNode.structure?.sequence?.nextChunkId) : undefined;
1138
+ const section = activeNode?.structure?.sequence?.sectionChunkId ? graph.sections.find((entry) => entry.id === activeNode.structure?.sequence?.sectionChunkId) : undefined;
1139
+ const parentSection = section?.parentSectionId ? graph.sections.find((entry) => entry.id === section.parentSectionId) : undefined;
1140
+ const childSections = section ? section.childSectionIds.map((sectionId) => graph.sections.find((entry) => entry.id === sectionId)).filter((entry) => Boolean(entry)) : [];
1141
+ const siblingSections = section?.parentSectionId ? graph.sections.filter((entry) => entry.parentSectionId === section.parentSectionId && entry.id !== section.id) : [];
1142
+ const sectionNodes = section ? section.chunkIds.map((chunkId) => graph.nodes.find((node) => node.chunkId === chunkId)).filter((node) => Boolean(node)) : activeNode ? [activeNode] : [];
1143
+ return {
1144
+ activeChunkId: resolvedActiveChunkId,
1145
+ activeNode,
1146
+ childSections,
1147
+ nextNode,
1148
+ parentSection,
1149
+ previousNode,
1150
+ section,
1151
+ siblingSections,
1152
+ sectionNodes
1153
+ };
1154
+ };
926
1155
  var buildRAGRetrievedState = (messages) => {
927
1156
  const message = getLatestRetrievedMessage(messages);
928
1157
  if (!message) {
@@ -964,6 +1193,7 @@ var buildRAGSourceSummaries = (sources) => {
964
1193
  label: group.label,
965
1194
  locatorLabel: leadChunk?.labels?.locatorLabel ?? buildLocatorLabel2(leadChunk?.metadata, leadChunk?.source, leadChunk?.title),
966
1195
  provenanceLabel: leadChunk?.labels?.provenanceLabel ?? buildProvenanceLabel2(leadChunk?.metadata),
1196
+ structure: leadChunk?.structure ?? buildRAGChunkStructure(leadChunk?.metadata),
967
1197
  source: group.source,
968
1198
  title: group.title
969
1199
  };
@@ -1092,6 +1322,7 @@ var buildSourceGroup = (source, key) => ({
1092
1322
  source: source.source,
1093
1323
  title: source.title
1094
1324
  }),
1325
+ structure: source.structure ?? buildRAGChunkStructure(source.metadata),
1095
1326
  source: source.source,
1096
1327
  title: source.title
1097
1328
  });
@@ -1110,6 +1341,7 @@ var updateSourceGroup = (groups, source) => {
1110
1341
  source: source.source,
1111
1342
  title: source.title
1112
1343
  });
1344
+ existing.structure = source.structure ?? buildRAGChunkStructure(source.metadata);
1113
1345
  existing.source = source.source;
1114
1346
  existing.title = source.title;
1115
1347
  } else {
@@ -1769,6 +2001,10 @@ export {
1769
2001
  buildRAGComparisonTraceDiffRows,
1770
2002
  buildRAGCitations,
1771
2003
  buildRAGCitationReferenceMap,
2004
+ buildRAGChunkPreviewNavigation,
2005
+ buildRAGChunkPreviewGraph,
2006
+ buildRAGChunkGraphNavigation,
2007
+ buildRAGChunkGraph,
1772
2008
  buildRAGAnswerWorkflowState,
1773
2009
  buildRAGAnswerGroundingHistoryRows,
1774
2010
  buildRAGAnswerGroundingHistoryPresentation,
@@ -1779,5 +2015,5 @@ export {
1779
2015
  buildRAGAdminActionPresentation
1780
2016
  };
1781
2017
 
1782
- //# debugId=879C26B2DEBFB06864756E2164756E21
2018
+ //# debugId=90BBD34D0B0A271364756E2164756E21
1783
2019
  //# sourceMappingURL=ui.js.map