@absolutejs/absolute 0.19.0-beta.607 → 0.19.0-beta.608

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.
@@ -1014,6 +1014,56 @@ var buildExcerpt = (text, maxLength = 160) => {
1014
1014
  }
1015
1015
  return `${normalized.slice(0, Math.max(0, maxLength - 1)).trimEnd()}\u2026`;
1016
1016
  };
1017
+ var selectPreferredExcerpt = (excerpts, sectionChunkCount) => {
1018
+ if (!excerpts) {
1019
+ return "";
1020
+ }
1021
+ const chunkExcerpt = excerpts.chunkExcerpt?.trim() ?? "";
1022
+ const windowExcerpt = excerpts.windowExcerpt?.trim() ?? "";
1023
+ const sectionExcerpt = excerpts.sectionExcerpt?.trim() ?? "";
1024
+ if (sectionChunkCount && sectionChunkCount > 1 && chunkExcerpt.length > 0 && chunkExcerpt.length < 72) {
1025
+ if (sectionChunkCount <= 3 && sectionExcerpt) {
1026
+ return sectionExcerpt;
1027
+ }
1028
+ if (windowExcerpt) {
1029
+ return windowExcerpt;
1030
+ }
1031
+ }
1032
+ return chunkExcerpt || windowExcerpt || sectionExcerpt;
1033
+ };
1034
+ var buildGroundingChunkExcerpts = (sources, activeChunkId) => {
1035
+ if (sources.length === 0) {
1036
+ return;
1037
+ }
1038
+ const activeSource = (activeChunkId ? sources.find((source) => source.chunkId === activeChunkId) : undefined) ?? sources[0];
1039
+ if (!activeSource) {
1040
+ return;
1041
+ }
1042
+ const chunkMap = new Map(sources.map((source) => [source.chunkId, source]));
1043
+ const activeMetadata = activeSource.metadata ?? {};
1044
+ const previousChunkId = getContextString(activeMetadata.previousChunkId);
1045
+ const nextChunkId = getContextString(activeMetadata.nextChunkId);
1046
+ const sectionChunkId = getContextString(activeMetadata.sectionChunkId);
1047
+ const sectionSources = sectionChunkId ? sources.filter((source) => getContextString(source.metadata?.sectionChunkId) === sectionChunkId).sort((left, right) => {
1048
+ const leftIndex = getContextNumber(left.metadata?.sectionChunkIndex) ?? Number.MAX_SAFE_INTEGER;
1049
+ const rightIndex = getContextNumber(right.metadata?.sectionChunkIndex) ?? Number.MAX_SAFE_INTEGER;
1050
+ if (leftIndex !== rightIndex) {
1051
+ return leftIndex - rightIndex;
1052
+ }
1053
+ return left.chunkId.localeCompare(right.chunkId);
1054
+ }) : [activeSource];
1055
+ const collectText = (chunkIds) => chunkIds.map((chunkId) => chunkMap.get(chunkId)?.text).filter((text) => typeof text === "string").join(`
1056
+
1057
+ `);
1058
+ const orderedWindowIds = [previousChunkId, activeSource.chunkId, nextChunkId].filter((chunkId, index, values) => Boolean(chunkId) && values.indexOf(chunkId) === index);
1059
+ return {
1060
+ chunkExcerpt: buildExcerpt(activeSource.text, 160),
1061
+ sectionExcerpt: buildExcerpt(sectionSources.map((source) => source.text).join(`
1062
+
1063
+ `), 320),
1064
+ windowExcerpt: buildExcerpt(collectText(orderedWindowIds), 240)
1065
+ };
1066
+ };
1017
1067
  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 ");
1018
1068
  var buildGroundingReferenceEvidenceSummary = (reference) => [
1019
1069
  reference.source ?? reference.title ?? reference.chunkId,
@@ -1032,7 +1082,8 @@ var buildGroundedAnswerCitationDetail = (reference) => ({
1032
1082
  contextLabel: reference.contextLabel,
1033
1083
  evidenceLabel: buildGroundingReferenceEvidenceLabel(reference),
1034
1084
  evidenceSummary: buildGroundingReferenceEvidenceSummary(reference),
1035
- excerpt: reference.excerpt,
1085
+ excerpt: selectPreferredExcerpt(reference.excerpts, getContextNumber(reference.metadata?.sectionChunkCount)) || reference.excerpt,
1086
+ excerpts: reference.excerpts,
1036
1087
  label: reference.label,
1037
1088
  locatorLabel: reference.locatorLabel,
1038
1089
  number: reference.number,
@@ -1128,10 +1179,17 @@ var buildRAGGroundedAnswerSectionSummaries = (references) => {
1128
1179
  const key = buildGroundingSectionKey(reference);
1129
1180
  const existing = groups.get(key);
1130
1181
  if (!existing) {
1182
+ const excerpts = reference.excerpts ? {
1183
+ chunkExcerpt: reference.excerpts.chunkExcerpt,
1184
+ sectionExcerpt: reference.excerpts.sectionExcerpt,
1185
+ windowExcerpt: reference.excerpts.windowExcerpt
1186
+ } : undefined;
1131
1187
  groups.set(key, {
1132
1188
  chunkIds: [reference.chunkId],
1133
1189
  contextLabel: reference.contextLabel,
1134
1190
  count: 1,
1191
+ excerpt: selectPreferredExcerpt(excerpts, getContextNumber(reference.metadata?.sectionChunkCount)) || excerpts?.sectionExcerpt || reference.excerpt,
1192
+ excerpts,
1135
1193
  key,
1136
1194
  label: key,
1137
1195
  locatorLabel: reference.locatorLabel,
@@ -1159,6 +1217,14 @@ var buildRAGGroundedAnswerSectionSummaries = (references) => {
1159
1217
  if (!existing.provenanceLabel && reference.provenanceLabel) {
1160
1218
  existing.provenanceLabel = reference.provenanceLabel;
1161
1219
  }
1220
+ if (!existing.excerpts && reference.excerpts) {
1221
+ existing.excerpts = {
1222
+ chunkExcerpt: reference.excerpts.chunkExcerpt,
1223
+ sectionExcerpt: reference.excerpts.sectionExcerpt,
1224
+ windowExcerpt: reference.excerpts.windowExcerpt
1225
+ };
1226
+ existing.excerpt = reference.excerpts.sectionExcerpt;
1227
+ }
1162
1228
  }
1163
1229
  return [...groups.values()].map((group) => ({
1164
1230
  ...group,
@@ -1176,20 +1242,24 @@ var buildRAGGroundedAnswerSectionSummaries = (references) => {
1176
1242
  var buildRAGGroundingReferences = (sources) => {
1177
1243
  const citations = buildRAGCitations(sources);
1178
1244
  const citationReferenceMap = buildRAGCitationReferenceMap(citations);
1179
- return citations.map((citation) => ({
1180
- chunkId: citation.chunkId,
1181
- contextLabel: citation.contextLabel ?? buildContextLabel(citation.metadata),
1182
- excerpt: buildExcerpt(citation.text),
1183
- label: citation.label,
1184
- locatorLabel: citation.locatorLabel ?? buildLocatorLabel(citation.metadata, citation.source, citation.title),
1185
- metadata: citation.metadata,
1186
- number: citationReferenceMap[citation.chunkId] ?? 0,
1187
- provenanceLabel: citation.provenanceLabel ?? buildProvenanceLabel(citation.metadata),
1188
- score: citation.score,
1189
- source: citation.source,
1190
- text: citation.text,
1191
- title: citation.title
1192
- }));
1245
+ return citations.map((citation) => {
1246
+ const excerpts = buildGroundingChunkExcerpts(sources, citation.chunkId);
1247
+ return {
1248
+ chunkId: citation.chunkId,
1249
+ contextLabel: citation.contextLabel ?? buildContextLabel(citation.metadata),
1250
+ excerpt: selectPreferredExcerpt(excerpts, getContextNumber(citation.metadata?.sectionChunkCount)) || excerpts?.chunkExcerpt || buildExcerpt(citation.text),
1251
+ excerpts,
1252
+ label: citation.label,
1253
+ locatorLabel: citation.locatorLabel ?? buildLocatorLabel(citation.metadata, citation.source, citation.title),
1254
+ metadata: citation.metadata,
1255
+ number: citationReferenceMap[citation.chunkId] ?? 0,
1256
+ provenanceLabel: citation.provenanceLabel ?? buildProvenanceLabel(citation.metadata),
1257
+ score: citation.score,
1258
+ source: citation.source,
1259
+ text: citation.text,
1260
+ title: citation.title
1261
+ };
1262
+ });
1193
1263
  };
1194
1264
 
1195
1265
  // src/ai/rag/presentation.ts
@@ -1778,7 +1848,7 @@ var buildRAGChunkStructure = (metadata) => {
1778
1848
  return;
1779
1849
  }
1780
1850
  const sectionPath = Array.isArray(metadata.sectionPath) ? metadata.sectionPath.filter((value) => typeof value === "string" && value.trim().length > 0) : undefined;
1781
- const sectionKind = metadata.sectionKind === "markdown_heading" || metadata.sectionKind === "html_heading" ? metadata.sectionKind : undefined;
1851
+ const sectionKind = metadata.sectionKind === "markdown_heading" || metadata.sectionKind === "html_heading" || metadata.sectionKind === "office_heading" || metadata.sectionKind === "spreadsheet_rows" || metadata.sectionKind === "presentation_slide" ? metadata.sectionKind : undefined;
1782
1852
  const section = {
1783
1853
  depth: getContextNumber2(metadata.sectionDepth),
1784
1854
  kind: sectionKind,
@@ -1807,6 +1877,52 @@ var buildExcerpt2 = (text, maxLength = 160) => {
1807
1877
  }
1808
1878
  return `${normalized.slice(0, Math.max(0, maxLength - 1)).trimEnd()}\u2026`;
1809
1879
  };
1880
+ var buildRAGChunkExcerpts = (chunks, activeChunkId) => {
1881
+ if (chunks.length === 0) {
1882
+ return;
1883
+ }
1884
+ const graph = buildRAGChunkGraph(chunks.map((chunk) => ({
1885
+ chunkId: chunk.chunkId,
1886
+ metadata: chunk.metadata,
1887
+ structure: chunk.structure
1888
+ })));
1889
+ const navigation = buildRAGChunkGraphNavigation(graph, activeChunkId);
1890
+ const activeChunk = chunks.find((chunk) => chunk.chunkId === navigation.activeChunkId) ?? chunks[0];
1891
+ if (!activeChunk) {
1892
+ return;
1893
+ }
1894
+ const chunkMap = new Map(chunks.map((chunk) => [chunk.chunkId, chunk]));
1895
+ const orderedWindowIds = [
1896
+ navigation.previousNode?.chunkId,
1897
+ activeChunk.chunkId,
1898
+ navigation.nextNode?.chunkId
1899
+ ].filter((chunkId, index, ids) => Boolean(chunkId) && ids.indexOf(chunkId) === index);
1900
+ const orderedSectionIds = navigation.sectionNodes.length > 0 ? navigation.sectionNodes.map((node) => node.chunkId) : [activeChunk.chunkId];
1901
+ const collectText = (chunkIds) => chunkIds.map((chunkId) => chunkMap.get(chunkId)?.text).filter((text) => typeof text === "string").join(`
1902
+
1903
+ `);
1904
+ return {
1905
+ chunkExcerpt: buildExcerpt2(activeChunk.text, 160),
1906
+ sectionExcerpt: buildExcerpt2(collectText(orderedSectionIds), 320),
1907
+ windowExcerpt: buildExcerpt2(collectText(orderedWindowIds), 240)
1908
+ };
1909
+ };
1910
+ var buildRAGPreferredExcerpt = (excerpts, structure) => {
1911
+ if (!excerpts) {
1912
+ return "";
1913
+ }
1914
+ const chunkLength = excerpts.chunkExcerpt.trim().length;
1915
+ const sectionChunkCount = structure?.sequence?.sectionChunkCount ?? 1;
1916
+ if (sectionChunkCount > 1 && chunkLength > 0 && chunkLength < 72) {
1917
+ if (sectionChunkCount <= 3 && excerpts.sectionExcerpt.trim().length > 0) {
1918
+ return excerpts.sectionExcerpt;
1919
+ }
1920
+ if (excerpts.windowExcerpt.trim().length > 0) {
1921
+ return excerpts.windowExcerpt;
1922
+ }
1923
+ }
1924
+ return excerpts.chunkExcerpt;
1925
+ };
1810
1926
  var buildRAGChunkGraph = (chunks) => {
1811
1927
  const nodes = [];
1812
1928
  const edges = [];
@@ -2018,6 +2134,7 @@ var buildRAGSourceSummaries = (sources) => {
2018
2134
  return sourceGroups.map((group) => {
2019
2135
  const groupCitations = citations.filter((citation) => group.chunks.some((chunk) => chunk.chunkId === citation.chunkId));
2020
2136
  const leadChunk = group.chunks.slice().sort((left, right) => right.score - left.score)[0];
2137
+ const excerpts = leadChunk ? buildRAGChunkExcerpts(group.chunks, leadChunk.chunkId) : undefined;
2021
2138
  return {
2022
2139
  bestScore: group.bestScore,
2023
2140
  citationNumbers: groupCitations.map((citation) => citationReferenceMap[citation.chunkId] ?? 0),
@@ -2025,7 +2142,8 @@ var buildRAGSourceSummaries = (sources) => {
2025
2142
  chunkIds: group.chunks.map((chunk) => chunk.chunkId),
2026
2143
  contextLabel: leadChunk?.labels?.contextLabel ?? buildContextLabel2(leadChunk?.metadata),
2027
2144
  count: group.count,
2028
- excerpt: buildExcerpt2(leadChunk?.text ?? ""),
2145
+ excerpt: buildRAGPreferredExcerpt(excerpts, leadChunk?.structure ?? buildRAGChunkStructure(leadChunk?.metadata)) || buildExcerpt2(leadChunk?.text ?? ""),
2146
+ excerpts,
2029
2147
  key: group.key,
2030
2148
  label: group.label,
2031
2149
  locatorLabel: leadChunk?.labels?.locatorLabel ?? buildLocatorLabel2(leadChunk?.metadata, leadChunk?.source, leadChunk?.title),
@@ -4193,5 +4311,5 @@ export {
4193
4311
  AIStreamService
4194
4312
  };
4195
4313
 
4196
- //# debugId=2C3A632BB772C68C64756E2164756E21
4314
+ //# debugId=CBE86239F7337F8064756E2164756E21
4197
4315
  //# sourceMappingURL=index.js.map