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

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 (38) hide show
  1. package/dist/ai/client/index.js +142 -18
  2. package/dist/ai/client/index.js.map +4 -4
  3. package/dist/ai/client/ui.js +143 -18
  4. package/dist/ai/client/ui.js.map +4 -4
  5. package/dist/ai/index.js +371 -28
  6. package/dist/ai/index.js.map +7 -7
  7. package/dist/ai/rag/quality.js +92 -16
  8. package/dist/ai/rag/quality.js.map +3 -3
  9. package/dist/ai/rag/ui.js +143 -18
  10. package/dist/ai/rag/ui.js.map +4 -4
  11. package/dist/ai-client/angular/ai/index.js +141 -17
  12. package/dist/ai-client/react/ai/index.js +141 -17
  13. package/dist/ai-client/vue/ai/index.js +141 -17
  14. package/dist/angular/ai/index.js +142 -18
  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 +142 -18
  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 +4 -1
  29. package/dist/src/ai/rag/ui.d.ts +1 -1
  30. package/dist/src/vue/ai/useRAG.d.ts +14 -4
  31. package/dist/src/vue/ai/useRAGChunkPreview.d.ts +12 -2
  32. package/dist/src/vue/ai/useRAGSearch.d.ts +2 -2
  33. package/dist/svelte/ai/index.js +142 -18
  34. package/dist/svelte/ai/index.js.map +6 -6
  35. package/dist/types/ai.d.ts +15 -2
  36. package/dist/vue/ai/index.js +142 -18
  37. package/dist/vue/ai/index.js.map +5 -5
  38. package/package.json +1 -1
@@ -347,6 +347,60 @@ var buildExcerpt = (text, maxLength = 160) => {
347
347
  }
348
348
  return `${normalized.slice(0, Math.max(0, maxLength - 1)).trimEnd()}\u2026`;
349
349
  };
350
+ var selectPreferredExcerpt = (excerpts, sectionChunkCount) => {
351
+ if (!excerpts) {
352
+ return "";
353
+ }
354
+ const chunkExcerpt = excerpts.chunkExcerpt?.trim() ?? "";
355
+ const windowExcerpt = excerpts.windowExcerpt?.trim() ?? "";
356
+ const sectionExcerpt = excerpts.sectionExcerpt?.trim() ?? "";
357
+ if (sectionChunkCount && sectionChunkCount > 1 && chunkExcerpt.length > 0 && chunkExcerpt.length < 72) {
358
+ if (sectionChunkCount <= 3 && sectionExcerpt) {
359
+ return sectionExcerpt;
360
+ }
361
+ if (windowExcerpt) {
362
+ return windowExcerpt;
363
+ }
364
+ }
365
+ return chunkExcerpt || windowExcerpt || sectionExcerpt;
366
+ };
367
+ var buildGroundingChunkExcerpts = (sources, activeChunkId) => {
368
+ if (sources.length === 0) {
369
+ return;
370
+ }
371
+ const activeSource = (activeChunkId ? sources.find((source) => source.chunkId === activeChunkId) : undefined) ?? sources[0];
372
+ if (!activeSource) {
373
+ return;
374
+ }
375
+ const chunkMap = new Map(sources.map((source) => [source.chunkId, source]));
376
+ const activeMetadata = activeSource.metadata ?? {};
377
+ const previousChunkId = getContextString(activeMetadata.previousChunkId);
378
+ const nextChunkId = getContextString(activeMetadata.nextChunkId);
379
+ const sectionChunkId = getContextString(activeMetadata.sectionChunkId);
380
+ const sectionSources = sectionChunkId ? sources.filter((source) => getContextString(source.metadata?.sectionChunkId) === sectionChunkId).sort((left, right) => {
381
+ const leftIndex = getContextNumber(left.metadata?.sectionChunkIndex) ?? Number.MAX_SAFE_INTEGER;
382
+ const rightIndex = getContextNumber(right.metadata?.sectionChunkIndex) ?? Number.MAX_SAFE_INTEGER;
383
+ if (leftIndex !== rightIndex) {
384
+ return leftIndex - rightIndex;
385
+ }
386
+ return left.chunkId.localeCompare(right.chunkId);
387
+ }) : [activeSource];
388
+ const collectText = (chunkIds) => chunkIds.map((chunkId) => chunkMap.get(chunkId)?.text).filter((text) => typeof text === "string").join(`
389
+
390
+ `);
391
+ const orderedWindowIds = [
392
+ previousChunkId,
393
+ activeSource.chunkId,
394
+ nextChunkId
395
+ ].filter((chunkId, index, values) => Boolean(chunkId) && values.indexOf(chunkId) === index);
396
+ return {
397
+ chunkExcerpt: buildExcerpt(activeSource.text, 160),
398
+ sectionExcerpt: buildExcerpt(sectionSources.map((source) => source.text).join(`
399
+
400
+ `), 320),
401
+ windowExcerpt: buildExcerpt(collectText(orderedWindowIds), 240)
402
+ };
403
+ };
350
404
  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 ");
351
405
  var buildGroundingReferenceEvidenceSummary = (reference) => [
352
406
  reference.source ?? reference.title ?? reference.chunkId,
@@ -365,7 +419,8 @@ var buildGroundedAnswerCitationDetail = (reference) => ({
365
419
  contextLabel: reference.contextLabel,
366
420
  evidenceLabel: buildGroundingReferenceEvidenceLabel(reference),
367
421
  evidenceSummary: buildGroundingReferenceEvidenceSummary(reference),
368
- excerpt: reference.excerpt,
422
+ excerpt: selectPreferredExcerpt(reference.excerpts, getContextNumber(reference.metadata?.sectionChunkCount)) || reference.excerpt,
423
+ excerpts: reference.excerpts,
369
424
  label: reference.label,
370
425
  locatorLabel: reference.locatorLabel,
371
426
  number: reference.number,
@@ -385,6 +440,8 @@ var buildRAGCitations = (sources) => {
385
440
  unique.set(key, {
386
441
  chunkId: source.chunkId,
387
442
  contextLabel: source.labels?.contextLabel ?? buildContextLabel(source.metadata),
443
+ excerpt: selectPreferredExcerpt(buildGroundingChunkExcerpts(sources, source.chunkId), getContextNumber(source.metadata?.sectionChunkCount)) || buildExcerpt(source.text),
444
+ excerpts: buildGroundingChunkExcerpts(sources, source.chunkId),
388
445
  key,
389
446
  label: buildSourceLabel(source),
390
447
  locatorLabel: source.labels?.locatorLabel ?? buildLocatorLabel(source.metadata, source.source, source.title),
@@ -461,10 +518,17 @@ var buildRAGGroundedAnswerSectionSummaries = (references) => {
461
518
  const key = buildGroundingSectionKey(reference);
462
519
  const existing = groups.get(key);
463
520
  if (!existing) {
521
+ const excerpts = reference.excerpts ? {
522
+ chunkExcerpt: reference.excerpts.chunkExcerpt,
523
+ sectionExcerpt: reference.excerpts.sectionExcerpt,
524
+ windowExcerpt: reference.excerpts.windowExcerpt
525
+ } : undefined;
464
526
  groups.set(key, {
465
527
  chunkIds: [reference.chunkId],
466
528
  contextLabel: reference.contextLabel,
467
529
  count: 1,
530
+ excerpt: selectPreferredExcerpt(excerpts, getContextNumber(reference.metadata?.sectionChunkCount)) || excerpts?.sectionExcerpt || reference.excerpt,
531
+ excerpts,
468
532
  key,
469
533
  label: key,
470
534
  locatorLabel: reference.locatorLabel,
@@ -492,6 +556,14 @@ var buildRAGGroundedAnswerSectionSummaries = (references) => {
492
556
  if (!existing.provenanceLabel && reference.provenanceLabel) {
493
557
  existing.provenanceLabel = reference.provenanceLabel;
494
558
  }
559
+ if (!existing.excerpts && reference.excerpts) {
560
+ existing.excerpts = {
561
+ chunkExcerpt: reference.excerpts.chunkExcerpt,
562
+ sectionExcerpt: reference.excerpts.sectionExcerpt,
563
+ windowExcerpt: reference.excerpts.windowExcerpt
564
+ };
565
+ existing.excerpt = reference.excerpts.sectionExcerpt;
566
+ }
495
567
  }
496
568
  return [...groups.values()].map((group) => ({
497
569
  ...group,
@@ -509,20 +581,24 @@ var buildRAGGroundedAnswerSectionSummaries = (references) => {
509
581
  var buildRAGGroundingReferences = (sources) => {
510
582
  const citations = buildRAGCitations(sources);
511
583
  const citationReferenceMap = buildRAGCitationReferenceMap(citations);
512
- return citations.map((citation) => ({
513
- chunkId: citation.chunkId,
514
- contextLabel: citation.contextLabel ?? buildContextLabel(citation.metadata),
515
- excerpt: buildExcerpt(citation.text),
516
- label: citation.label,
517
- locatorLabel: citation.locatorLabel ?? buildLocatorLabel(citation.metadata, citation.source, citation.title),
518
- metadata: citation.metadata,
519
- number: citationReferenceMap[citation.chunkId] ?? 0,
520
- provenanceLabel: citation.provenanceLabel ?? buildProvenanceLabel(citation.metadata),
521
- score: citation.score,
522
- source: citation.source,
523
- text: citation.text,
524
- title: citation.title
525
- }));
584
+ return citations.map((citation) => {
585
+ const excerpts = buildGroundingChunkExcerpts(sources, citation.chunkId);
586
+ return {
587
+ chunkId: citation.chunkId,
588
+ contextLabel: citation.contextLabel ?? buildContextLabel(citation.metadata),
589
+ excerpt: selectPreferredExcerpt(excerpts, getContextNumber(citation.metadata?.sectionChunkCount)) || excerpts?.chunkExcerpt || buildExcerpt(citation.text),
590
+ excerpts,
591
+ label: citation.label,
592
+ locatorLabel: citation.locatorLabel ?? buildLocatorLabel(citation.metadata, citation.source, citation.title),
593
+ metadata: citation.metadata,
594
+ number: citationReferenceMap[citation.chunkId] ?? 0,
595
+ provenanceLabel: citation.provenanceLabel ?? buildProvenanceLabel(citation.metadata),
596
+ score: citation.score,
597
+ source: citation.source,
598
+ text: citation.text,
599
+ title: citation.title
600
+ };
601
+ });
526
602
  };
527
603
 
528
604
  // src/ai/rag/quality.ts
@@ -4779,7 +4855,7 @@ var buildRAGChunkStructure = (metadata) => {
4779
4855
  return;
4780
4856
  }
4781
4857
  const sectionPath = Array.isArray(metadata.sectionPath) ? metadata.sectionPath.filter((value) => typeof value === "string" && value.trim().length > 0) : undefined;
4782
- const sectionKind = metadata.sectionKind === "markdown_heading" || metadata.sectionKind === "html_heading" ? metadata.sectionKind : undefined;
4858
+ 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;
4783
4859
  const section = {
4784
4860
  depth: getContextNumber2(metadata.sectionDepth),
4785
4861
  kind: sectionKind,
@@ -4808,6 +4884,52 @@ var buildExcerpt2 = (text, maxLength = 160) => {
4808
4884
  }
4809
4885
  return `${normalized.slice(0, Math.max(0, maxLength - 1)).trimEnd()}\u2026`;
4810
4886
  };
4887
+ var buildRAGChunkExcerpts = (chunks, activeChunkId) => {
4888
+ if (chunks.length === 0) {
4889
+ return;
4890
+ }
4891
+ const graph = buildRAGChunkGraph(chunks.map((chunk) => ({
4892
+ chunkId: chunk.chunkId,
4893
+ metadata: chunk.metadata,
4894
+ structure: chunk.structure
4895
+ })));
4896
+ const navigation = buildRAGChunkGraphNavigation(graph, activeChunkId);
4897
+ const activeChunk = chunks.find((chunk) => chunk.chunkId === navigation.activeChunkId) ?? chunks[0];
4898
+ if (!activeChunk) {
4899
+ return;
4900
+ }
4901
+ const chunkMap = new Map(chunks.map((chunk) => [chunk.chunkId, chunk]));
4902
+ const orderedWindowIds = [
4903
+ navigation.previousNode?.chunkId,
4904
+ activeChunk.chunkId,
4905
+ navigation.nextNode?.chunkId
4906
+ ].filter((chunkId, index, ids) => Boolean(chunkId) && ids.indexOf(chunkId) === index);
4907
+ const orderedSectionIds = navigation.sectionNodes.length > 0 ? navigation.sectionNodes.map((node) => node.chunkId) : [activeChunk.chunkId];
4908
+ const collectText = (chunkIds) => chunkIds.map((chunkId) => chunkMap.get(chunkId)?.text).filter((text) => typeof text === "string").join(`
4909
+
4910
+ `);
4911
+ return {
4912
+ chunkExcerpt: buildExcerpt2(activeChunk.text, 160),
4913
+ sectionExcerpt: buildExcerpt2(collectText(orderedSectionIds), 320),
4914
+ windowExcerpt: buildExcerpt2(collectText(orderedWindowIds), 240)
4915
+ };
4916
+ };
4917
+ var buildRAGPreferredExcerpt = (excerpts, structure) => {
4918
+ if (!excerpts) {
4919
+ return "";
4920
+ }
4921
+ const chunkLength = excerpts.chunkExcerpt.trim().length;
4922
+ const sectionChunkCount = structure?.sequence?.sectionChunkCount ?? 1;
4923
+ if (sectionChunkCount > 1 && chunkLength > 0 && chunkLength < 72) {
4924
+ if (sectionChunkCount <= 3 && excerpts.sectionExcerpt.trim().length > 0) {
4925
+ return excerpts.sectionExcerpt;
4926
+ }
4927
+ if (excerpts.windowExcerpt.trim().length > 0) {
4928
+ return excerpts.windowExcerpt;
4929
+ }
4930
+ }
4931
+ return excerpts.chunkExcerpt;
4932
+ };
4811
4933
  var buildRAGChunkGraph = (chunks) => {
4812
4934
  const nodes = [];
4813
4935
  const edges = [];
@@ -5019,6 +5141,7 @@ var buildRAGSourceSummaries = (sources) => {
5019
5141
  return sourceGroups.map((group) => {
5020
5142
  const groupCitations = citations.filter((citation) => group.chunks.some((chunk) => chunk.chunkId === citation.chunkId));
5021
5143
  const leadChunk = group.chunks.slice().sort((left, right) => right.score - left.score)[0];
5144
+ const excerpts = leadChunk ? buildRAGChunkExcerpts(group.chunks, leadChunk.chunkId) : undefined;
5022
5145
  return {
5023
5146
  bestScore: group.bestScore,
5024
5147
  citationNumbers: groupCitations.map((citation) => citationReferenceMap[citation.chunkId] ?? 0),
@@ -5026,7 +5149,8 @@ var buildRAGSourceSummaries = (sources) => {
5026
5149
  chunkIds: group.chunks.map((chunk) => chunk.chunkId),
5027
5150
  contextLabel: leadChunk?.labels?.contextLabel ?? buildContextLabel2(leadChunk?.metadata),
5028
5151
  count: group.count,
5029
- excerpt: buildExcerpt2(leadChunk?.text ?? ""),
5152
+ excerpt: buildRAGPreferredExcerpt(excerpts, leadChunk?.structure ?? buildRAGChunkStructure(leadChunk?.metadata)) || buildExcerpt2(leadChunk?.text ?? ""),
5153
+ excerpts,
5030
5154
  key: group.key,
5031
5155
  label: group.label,
5032
5156
  locatorLabel: leadChunk?.labels?.locatorLabel ?? buildLocatorLabel2(leadChunk?.metadata, leadChunk?.source, leadChunk?.title),
@@ -6959,5 +7083,5 @@ export {
6959
7083
  buildRAGEvaluationLeaderboard
6960
7084
  };
6961
7085
 
6962
- //# debugId=260B815A92E7FE6E64756E2164756E21
7086
+ //# debugId=6D715A9108C4DFEA64756E2164756E21
6963
7087
  //# sourceMappingURL=index.js.map