@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.
package/dist/ai/rag/ui.js CHANGED
@@ -236,6 +236,56 @@ var buildExcerpt = (text, maxLength = 160) => {
236
236
  }
237
237
  return `${normalized.slice(0, Math.max(0, maxLength - 1)).trimEnd()}\u2026`;
238
238
  };
239
+ var selectPreferredExcerpt = (excerpts, sectionChunkCount) => {
240
+ if (!excerpts) {
241
+ return "";
242
+ }
243
+ const chunkExcerpt = excerpts.chunkExcerpt?.trim() ?? "";
244
+ const windowExcerpt = excerpts.windowExcerpt?.trim() ?? "";
245
+ const sectionExcerpt = excerpts.sectionExcerpt?.trim() ?? "";
246
+ if (sectionChunkCount && sectionChunkCount > 1 && chunkExcerpt.length > 0 && chunkExcerpt.length < 72) {
247
+ if (sectionChunkCount <= 3 && sectionExcerpt) {
248
+ return sectionExcerpt;
249
+ }
250
+ if (windowExcerpt) {
251
+ return windowExcerpt;
252
+ }
253
+ }
254
+ return chunkExcerpt || windowExcerpt || sectionExcerpt;
255
+ };
256
+ var buildGroundingChunkExcerpts = (sources, activeChunkId) => {
257
+ if (sources.length === 0) {
258
+ return;
259
+ }
260
+ const activeSource = (activeChunkId ? sources.find((source) => source.chunkId === activeChunkId) : undefined) ?? sources[0];
261
+ if (!activeSource) {
262
+ return;
263
+ }
264
+ const chunkMap = new Map(sources.map((source) => [source.chunkId, source]));
265
+ const activeMetadata = activeSource.metadata ?? {};
266
+ const previousChunkId = getContextString(activeMetadata.previousChunkId);
267
+ const nextChunkId = getContextString(activeMetadata.nextChunkId);
268
+ const sectionChunkId = getContextString(activeMetadata.sectionChunkId);
269
+ const sectionSources = sectionChunkId ? sources.filter((source) => getContextString(source.metadata?.sectionChunkId) === sectionChunkId).sort((left, right) => {
270
+ const leftIndex = getContextNumber(left.metadata?.sectionChunkIndex) ?? Number.MAX_SAFE_INTEGER;
271
+ const rightIndex = getContextNumber(right.metadata?.sectionChunkIndex) ?? Number.MAX_SAFE_INTEGER;
272
+ if (leftIndex !== rightIndex) {
273
+ return leftIndex - rightIndex;
274
+ }
275
+ return left.chunkId.localeCompare(right.chunkId);
276
+ }) : [activeSource];
277
+ const collectText = (chunkIds) => chunkIds.map((chunkId) => chunkMap.get(chunkId)?.text).filter((text) => typeof text === "string").join(`
278
+
279
+ `);
280
+ const orderedWindowIds = [previousChunkId, activeSource.chunkId, nextChunkId].filter((chunkId, index, values) => Boolean(chunkId) && values.indexOf(chunkId) === index);
281
+ return {
282
+ chunkExcerpt: buildExcerpt(activeSource.text, 160),
283
+ sectionExcerpt: buildExcerpt(sectionSources.map((source) => source.text).join(`
284
+
285
+ `), 320),
286
+ windowExcerpt: buildExcerpt(collectText(orderedWindowIds), 240)
287
+ };
288
+ };
239
289
  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 ");
240
290
  var buildGroundingReferenceEvidenceSummary = (reference) => [
241
291
  reference.source ?? reference.title ?? reference.chunkId,
@@ -254,7 +304,8 @@ var buildGroundedAnswerCitationDetail = (reference) => ({
254
304
  contextLabel: reference.contextLabel,
255
305
  evidenceLabel: buildGroundingReferenceEvidenceLabel(reference),
256
306
  evidenceSummary: buildGroundingReferenceEvidenceSummary(reference),
257
- excerpt: reference.excerpt,
307
+ excerpt: selectPreferredExcerpt(reference.excerpts, getContextNumber(reference.metadata?.sectionChunkCount)) || reference.excerpt,
308
+ excerpts: reference.excerpts,
258
309
  label: reference.label,
259
310
  locatorLabel: reference.locatorLabel,
260
311
  number: reference.number,
@@ -350,10 +401,17 @@ var buildRAGGroundedAnswerSectionSummaries = (references) => {
350
401
  const key = buildGroundingSectionKey(reference);
351
402
  const existing = groups.get(key);
352
403
  if (!existing) {
404
+ const excerpts = reference.excerpts ? {
405
+ chunkExcerpt: reference.excerpts.chunkExcerpt,
406
+ sectionExcerpt: reference.excerpts.sectionExcerpt,
407
+ windowExcerpt: reference.excerpts.windowExcerpt
408
+ } : undefined;
353
409
  groups.set(key, {
354
410
  chunkIds: [reference.chunkId],
355
411
  contextLabel: reference.contextLabel,
356
412
  count: 1,
413
+ excerpt: selectPreferredExcerpt(excerpts, getContextNumber(reference.metadata?.sectionChunkCount)) || excerpts?.sectionExcerpt || reference.excerpt,
414
+ excerpts,
357
415
  key,
358
416
  label: key,
359
417
  locatorLabel: reference.locatorLabel,
@@ -381,6 +439,14 @@ var buildRAGGroundedAnswerSectionSummaries = (references) => {
381
439
  if (!existing.provenanceLabel && reference.provenanceLabel) {
382
440
  existing.provenanceLabel = reference.provenanceLabel;
383
441
  }
442
+ if (!existing.excerpts && reference.excerpts) {
443
+ existing.excerpts = {
444
+ chunkExcerpt: reference.excerpts.chunkExcerpt,
445
+ sectionExcerpt: reference.excerpts.sectionExcerpt,
446
+ windowExcerpt: reference.excerpts.windowExcerpt
447
+ };
448
+ existing.excerpt = reference.excerpts.sectionExcerpt;
449
+ }
384
450
  }
385
451
  return [...groups.values()].map((group) => ({
386
452
  ...group,
@@ -398,20 +464,24 @@ var buildRAGGroundedAnswerSectionSummaries = (references) => {
398
464
  var buildRAGGroundingReferences = (sources) => {
399
465
  const citations = buildRAGCitations(sources);
400
466
  const citationReferenceMap = buildRAGCitationReferenceMap(citations);
401
- return citations.map((citation) => ({
402
- chunkId: citation.chunkId,
403
- contextLabel: citation.contextLabel ?? buildContextLabel(citation.metadata),
404
- excerpt: buildExcerpt(citation.text),
405
- label: citation.label,
406
- locatorLabel: citation.locatorLabel ?? buildLocatorLabel(citation.metadata, citation.source, citation.title),
407
- metadata: citation.metadata,
408
- number: citationReferenceMap[citation.chunkId] ?? 0,
409
- provenanceLabel: citation.provenanceLabel ?? buildProvenanceLabel(citation.metadata),
410
- score: citation.score,
411
- source: citation.source,
412
- text: citation.text,
413
- title: citation.title
414
- }));
467
+ return citations.map((citation) => {
468
+ const excerpts = buildGroundingChunkExcerpts(sources, citation.chunkId);
469
+ return {
470
+ chunkId: citation.chunkId,
471
+ contextLabel: citation.contextLabel ?? buildContextLabel(citation.metadata),
472
+ excerpt: selectPreferredExcerpt(excerpts, getContextNumber(citation.metadata?.sectionChunkCount)) || excerpts?.chunkExcerpt || buildExcerpt(citation.text),
473
+ excerpts,
474
+ label: citation.label,
475
+ locatorLabel: citation.locatorLabel ?? buildLocatorLabel(citation.metadata, citation.source, citation.title),
476
+ metadata: citation.metadata,
477
+ number: citationReferenceMap[citation.chunkId] ?? 0,
478
+ provenanceLabel: citation.provenanceLabel ?? buildProvenanceLabel(citation.metadata),
479
+ score: citation.score,
480
+ source: citation.source,
481
+ text: citation.text,
482
+ title: citation.title
483
+ };
484
+ });
415
485
  };
416
486
 
417
487
  // src/ai/rag/presentation.ts
@@ -1000,7 +1070,7 @@ var buildRAGChunkStructure = (metadata) => {
1000
1070
  return;
1001
1071
  }
1002
1072
  const sectionPath = Array.isArray(metadata.sectionPath) ? metadata.sectionPath.filter((value) => typeof value === "string" && value.trim().length > 0) : undefined;
1003
- const sectionKind = metadata.sectionKind === "markdown_heading" || metadata.sectionKind === "html_heading" ? metadata.sectionKind : undefined;
1073
+ 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;
1004
1074
  const section = {
1005
1075
  depth: getContextNumber2(metadata.sectionDepth),
1006
1076
  kind: sectionKind,
@@ -1029,6 +1099,52 @@ var buildExcerpt2 = (text, maxLength = 160) => {
1029
1099
  }
1030
1100
  return `${normalized.slice(0, Math.max(0, maxLength - 1)).trimEnd()}\u2026`;
1031
1101
  };
1102
+ var buildRAGChunkExcerpts = (chunks, activeChunkId) => {
1103
+ if (chunks.length === 0) {
1104
+ return;
1105
+ }
1106
+ const graph = buildRAGChunkGraph(chunks.map((chunk) => ({
1107
+ chunkId: chunk.chunkId,
1108
+ metadata: chunk.metadata,
1109
+ structure: chunk.structure
1110
+ })));
1111
+ const navigation = buildRAGChunkGraphNavigation(graph, activeChunkId);
1112
+ const activeChunk = chunks.find((chunk) => chunk.chunkId === navigation.activeChunkId) ?? chunks[0];
1113
+ if (!activeChunk) {
1114
+ return;
1115
+ }
1116
+ const chunkMap = new Map(chunks.map((chunk) => [chunk.chunkId, chunk]));
1117
+ const orderedWindowIds = [
1118
+ navigation.previousNode?.chunkId,
1119
+ activeChunk.chunkId,
1120
+ navigation.nextNode?.chunkId
1121
+ ].filter((chunkId, index, ids) => Boolean(chunkId) && ids.indexOf(chunkId) === index);
1122
+ const orderedSectionIds = navigation.sectionNodes.length > 0 ? navigation.sectionNodes.map((node) => node.chunkId) : [activeChunk.chunkId];
1123
+ const collectText = (chunkIds) => chunkIds.map((chunkId) => chunkMap.get(chunkId)?.text).filter((text) => typeof text === "string").join(`
1124
+
1125
+ `);
1126
+ return {
1127
+ chunkExcerpt: buildExcerpt2(activeChunk.text, 160),
1128
+ sectionExcerpt: buildExcerpt2(collectText(orderedSectionIds), 320),
1129
+ windowExcerpt: buildExcerpt2(collectText(orderedWindowIds), 240)
1130
+ };
1131
+ };
1132
+ var buildRAGPreferredExcerpt = (excerpts, structure) => {
1133
+ if (!excerpts) {
1134
+ return "";
1135
+ }
1136
+ const chunkLength = excerpts.chunkExcerpt.trim().length;
1137
+ const sectionChunkCount = structure?.sequence?.sectionChunkCount ?? 1;
1138
+ if (sectionChunkCount > 1 && chunkLength > 0 && chunkLength < 72) {
1139
+ if (sectionChunkCount <= 3 && excerpts.sectionExcerpt.trim().length > 0) {
1140
+ return excerpts.sectionExcerpt;
1141
+ }
1142
+ if (excerpts.windowExcerpt.trim().length > 0) {
1143
+ return excerpts.windowExcerpt;
1144
+ }
1145
+ }
1146
+ return excerpts.chunkExcerpt;
1147
+ };
1032
1148
  var buildRAGChunkGraph = (chunks) => {
1033
1149
  const nodes = [];
1034
1150
  const edges = [];
@@ -1240,6 +1356,7 @@ var buildRAGSourceSummaries = (sources) => {
1240
1356
  return sourceGroups.map((group) => {
1241
1357
  const groupCitations = citations.filter((citation) => group.chunks.some((chunk) => chunk.chunkId === citation.chunkId));
1242
1358
  const leadChunk = group.chunks.slice().sort((left, right) => right.score - left.score)[0];
1359
+ const excerpts = leadChunk ? buildRAGChunkExcerpts(group.chunks, leadChunk.chunkId) : undefined;
1243
1360
  return {
1244
1361
  bestScore: group.bestScore,
1245
1362
  citationNumbers: groupCitations.map((citation) => citationReferenceMap[citation.chunkId] ?? 0),
@@ -1247,7 +1364,8 @@ var buildRAGSourceSummaries = (sources) => {
1247
1364
  chunkIds: group.chunks.map((chunk) => chunk.chunkId),
1248
1365
  contextLabel: leadChunk?.labels?.contextLabel ?? buildContextLabel2(leadChunk?.metadata),
1249
1366
  count: group.count,
1250
- excerpt: buildExcerpt2(leadChunk?.text ?? ""),
1367
+ excerpt: buildRAGPreferredExcerpt(excerpts, leadChunk?.structure ?? buildRAGChunkStructure(leadChunk?.metadata)) || buildExcerpt2(leadChunk?.text ?? ""),
1368
+ excerpts,
1251
1369
  key: group.key,
1252
1370
  label: group.label,
1253
1371
  locatorLabel: leadChunk?.labels?.locatorLabel ?? buildLocatorLabel2(leadChunk?.metadata, leadChunk?.source, leadChunk?.title),
@@ -2065,6 +2183,7 @@ export {
2065
2183
  buildRAGChunkPreviewGraph,
2066
2184
  buildRAGChunkGraphNavigation,
2067
2185
  buildRAGChunkGraph,
2186
+ buildRAGChunkExcerpts,
2068
2187
  buildRAGAnswerWorkflowState,
2069
2188
  buildRAGAnswerGroundingHistoryRows,
2070
2189
  buildRAGAnswerGroundingHistoryPresentation,
@@ -2075,5 +2194,5 @@ export {
2075
2194
  buildRAGAdminActionPresentation
2076
2195
  };
2077
2196
 
2078
- //# debugId=C09751511BFD6FA564756E2164756E21
2197
+ //# debugId=726F5089BA9C01AA64756E2164756E21
2079
2198
  //# sourceMappingURL=ui.js.map