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

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 (44) hide show
  1. package/dist/ai/client/index.js +244 -21
  2. package/dist/ai/client/index.js.map +4 -4
  3. package/dist/ai/client/ui.js +245 -21
  4. package/dist/ai/client/ui.js.map +4 -4
  5. package/dist/ai/index.js +294 -28
  6. package/dist/ai/index.js.map +7 -7
  7. package/dist/ai/rag/quality.js +53 -11
  8. package/dist/ai/rag/quality.js.map +3 -3
  9. package/dist/ai/rag/ui.js +245 -21
  10. package/dist/ai/rag/ui.js.map +4 -4
  11. package/dist/ai-client/angular/ai/index.js +243 -20
  12. package/dist/ai-client/react/ai/index.js +262 -20
  13. package/dist/ai-client/vue/ai/index.js +262 -20
  14. package/dist/angular/ai/index.js +244 -21
  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 +263 -21
  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 +8 -1
  29. package/dist/src/ai/rag/ui.d.ts +1 -1
  30. package/dist/src/react/ai/useRAG.d.ts +3 -0
  31. package/dist/src/react/ai/useRAGChunkPreview.d.ts +2 -0
  32. package/dist/src/react/ai/useRAGSources.d.ts +1 -0
  33. package/dist/src/svelte/ai/createRAG.d.ts +3 -0
  34. package/dist/src/svelte/ai/createRAGChunkPreview.d.ts +2 -0
  35. package/dist/src/svelte/ai/createRAGSources.d.ts +1 -0
  36. package/dist/src/vue/ai/useRAG.d.ts +11 -0
  37. package/dist/src/vue/ai/useRAGChunkPreview.d.ts +10 -0
  38. package/dist/src/vue/ai/useRAGSources.d.ts +1 -0
  39. package/dist/svelte/ai/index.js +263 -21
  40. package/dist/svelte/ai/index.js.map +6 -6
  41. package/dist/types/ai.d.ts +56 -0
  42. package/dist/vue/ai/index.js +263 -21
  43. package/dist/vue/ai/index.js.map +6 -6
  44. package/package.json +1 -1
@@ -1874,21 +1874,48 @@ var buildExcerpt = (text, maxLength = 160) => {
1874
1874
  };
1875
1875
  var selectPreferredExcerpt = (excerpts, sectionChunkCount) => {
1876
1876
  if (!excerpts) {
1877
- return "";
1877
+ return {
1878
+ excerpt: "",
1879
+ mode: "chunk",
1880
+ reason: "single_chunk"
1881
+ };
1878
1882
  }
1879
1883
  const chunkExcerpt = excerpts.chunkExcerpt?.trim() ?? "";
1880
1884
  const windowExcerpt = excerpts.windowExcerpt?.trim() ?? "";
1881
1885
  const sectionExcerpt = excerpts.sectionExcerpt?.trim() ?? "";
1882
1886
  if (sectionChunkCount && sectionChunkCount > 1 && chunkExcerpt.length > 0 && chunkExcerpt.length < 72) {
1883
1887
  if (sectionChunkCount <= 3 && sectionExcerpt) {
1884
- return sectionExcerpt;
1888
+ return {
1889
+ excerpt: sectionExcerpt,
1890
+ mode: "section",
1891
+ reason: "section_small_enough"
1892
+ };
1885
1893
  }
1886
1894
  if (windowExcerpt) {
1887
- return windowExcerpt;
1895
+ return {
1896
+ excerpt: windowExcerpt,
1897
+ mode: "window",
1898
+ reason: "section_too_large_use_window"
1899
+ };
1888
1900
  }
1901
+ return {
1902
+ excerpt: chunkExcerpt,
1903
+ mode: "chunk",
1904
+ reason: "chunk_too_narrow"
1905
+ };
1889
1906
  }
1890
- return chunkExcerpt || windowExcerpt || sectionExcerpt;
1907
+ return {
1908
+ excerpt: chunkExcerpt || windowExcerpt || sectionExcerpt,
1909
+ mode: "chunk",
1910
+ reason: (sectionChunkCount ?? 0) > 1 ? "chunk_too_narrow" : "single_chunk"
1911
+ };
1891
1912
  };
1913
+ var buildExcerptModeCounts = (references) => references.reduce((counts, reference) => {
1914
+ if (reference?.excerptSelection) {
1915
+ counts[reference.excerptSelection.mode] += 1;
1916
+ }
1917
+ return counts;
1918
+ }, { chunk: 0, section: 0, window: 0 });
1892
1919
  var buildGroundingChunkExcerpts = (sources, activeChunkId) => {
1893
1920
  if (sources.length === 0) {
1894
1921
  return;
@@ -1944,8 +1971,9 @@ var buildGroundedAnswerCitationDetail = (reference) => ({
1944
1971
  contextLabel: reference.contextLabel,
1945
1972
  evidenceLabel: buildGroundingReferenceEvidenceLabel(reference),
1946
1973
  evidenceSummary: buildGroundingReferenceEvidenceSummary(reference),
1947
- excerpt: selectPreferredExcerpt(reference.excerpts, getContextNumber(reference.metadata?.sectionChunkCount)) || reference.excerpt,
1974
+ excerpt: selectPreferredExcerpt(reference.excerpts, getContextNumber(reference.metadata?.sectionChunkCount)).excerpt || reference.excerpt,
1948
1975
  excerpts: reference.excerpts,
1976
+ excerptSelection: reference.excerptSelection,
1949
1977
  label: reference.label,
1950
1978
  locatorLabel: reference.locatorLabel,
1951
1979
  number: reference.number,
@@ -1962,11 +1990,14 @@ var buildRAGCitations = (sources) => {
1962
1990
  const hasBetterExisting = existing !== undefined && existing.score >= source.score;
1963
1991
  if (hasBetterExisting)
1964
1992
  continue;
1993
+ const excerpts = buildGroundingChunkExcerpts(sources, source.chunkId);
1994
+ const excerptSelection = selectPreferredExcerpt(excerpts, getContextNumber(source.metadata?.sectionChunkCount));
1965
1995
  unique.set(key, {
1966
1996
  chunkId: source.chunkId,
1967
1997
  contextLabel: source.labels?.contextLabel ?? buildContextLabel(source.metadata),
1968
- excerpt: selectPreferredExcerpt(buildGroundingChunkExcerpts(sources, source.chunkId), getContextNumber(source.metadata?.sectionChunkCount)) || buildExcerpt(source.text),
1969
- excerpts: buildGroundingChunkExcerpts(sources, source.chunkId),
1998
+ excerpt: excerptSelection.excerpt || buildExcerpt(source.text),
1999
+ excerpts,
2000
+ excerptSelection,
1970
2001
  key,
1971
2002
  label: buildSourceLabel(source),
1972
2003
  locatorLabel: source.labels?.locatorLabel ?? buildLocatorLabel(source.metadata, source.source, source.title),
@@ -1987,6 +2018,7 @@ var buildRAGCitations = (sources) => {
1987
2018
  };
1988
2019
  var buildRAGGroundedAnswer = (content, sources) => {
1989
2020
  const references = buildRAGGroundingReferences(sources);
2021
+ const sectionSummaries = buildRAGGroundedAnswerSectionSummaries(references);
1990
2022
  const referenceMap = new Map(references.map((reference) => [reference.number, reference]));
1991
2023
  const parts = [];
1992
2024
  const ungroundedReferenceNumbers = new Set;
@@ -2030,10 +2062,14 @@ var buildRAGGroundedAnswer = (content, sources) => {
2030
2062
  return {
2031
2063
  content,
2032
2064
  coverage,
2065
+ excerptModeCounts: buildExcerptModeCounts([
2066
+ ...references,
2067
+ ...sectionSummaries
2068
+ ]),
2033
2069
  hasCitations,
2034
2070
  parts,
2035
2071
  references,
2036
- sectionSummaries: buildRAGGroundedAnswerSectionSummaries(references),
2072
+ sectionSummaries,
2037
2073
  ungroundedReferenceNumbers: [...ungroundedReferenceNumbers].sort((left, right) => left - right)
2038
2074
  };
2039
2075
  };
@@ -2052,8 +2088,9 @@ var buildRAGGroundedAnswerSectionSummaries = (references) => {
2052
2088
  chunkIds: [reference.chunkId],
2053
2089
  contextLabel: reference.contextLabel,
2054
2090
  count: 1,
2055
- excerpt: selectPreferredExcerpt(excerpts, getContextNumber(reference.metadata?.sectionChunkCount)) || excerpts?.sectionExcerpt || reference.excerpt,
2091
+ excerpt: selectPreferredExcerpt(excerpts, getContextNumber(reference.metadata?.sectionChunkCount)).excerpt || excerpts?.sectionExcerpt || reference.excerpt,
2056
2092
  excerpts,
2093
+ excerptSelection: reference.excerptSelection,
2057
2094
  key,
2058
2095
  label: key,
2059
2096
  locatorLabel: reference.locatorLabel,
@@ -2089,6 +2126,9 @@ var buildRAGGroundedAnswerSectionSummaries = (references) => {
2089
2126
  };
2090
2127
  existing.excerpt = reference.excerpts.sectionExcerpt;
2091
2128
  }
2129
+ if (!existing.excerptSelection && reference.excerptSelection) {
2130
+ existing.excerptSelection = reference.excerptSelection;
2131
+ }
2092
2132
  }
2093
2133
  return [...groups.values()].map((group) => ({
2094
2134
  ...group,
@@ -2108,11 +2148,13 @@ var buildRAGGroundingReferences = (sources) => {
2108
2148
  const citationReferenceMap = buildRAGCitationReferenceMap(citations);
2109
2149
  return citations.map((citation) => {
2110
2150
  const excerpts = buildGroundingChunkExcerpts(sources, citation.chunkId);
2151
+ const excerptSelection = selectPreferredExcerpt(excerpts, getContextNumber(citation.metadata?.sectionChunkCount));
2111
2152
  return {
2112
2153
  chunkId: citation.chunkId,
2113
2154
  contextLabel: citation.contextLabel ?? buildContextLabel(citation.metadata),
2114
- excerpt: selectPreferredExcerpt(excerpts, getContextNumber(citation.metadata?.sectionChunkCount)) || excerpts?.chunkExcerpt || buildExcerpt(citation.text),
2155
+ excerpt: excerptSelection.excerpt || excerpts?.chunkExcerpt || buildExcerpt(citation.text),
2115
2156
  excerpts,
2157
+ excerptSelection,
2116
2158
  label: citation.label,
2117
2159
  locatorLabel: citation.locatorLabel ?? buildLocatorLabel(citation.metadata, citation.source, citation.title),
2118
2160
  metadata: citation.metadata,
@@ -2366,22 +2408,49 @@ var buildRAGChunkExcerpts = (chunks, activeChunkId) => {
2366
2408
  windowExcerpt: buildExcerpt2(collectText(orderedWindowIds), 240)
2367
2409
  };
2368
2410
  };
2369
- var buildRAGPreferredExcerpt = (excerpts, structure) => {
2411
+ var buildRAGExcerptSelection = (excerpts, structure) => {
2370
2412
  if (!excerpts) {
2371
- return "";
2413
+ return {
2414
+ excerpt: "",
2415
+ mode: "chunk",
2416
+ reason: "single_chunk"
2417
+ };
2372
2418
  }
2373
2419
  const chunkLength = excerpts.chunkExcerpt.trim().length;
2374
2420
  const sectionChunkCount = structure?.sequence?.sectionChunkCount ?? 1;
2375
2421
  if (sectionChunkCount > 1 && chunkLength > 0 && chunkLength < 72) {
2376
2422
  if (sectionChunkCount <= 3 && excerpts.sectionExcerpt.trim().length > 0) {
2377
- return excerpts.sectionExcerpt;
2423
+ return {
2424
+ excerpt: excerpts.sectionExcerpt,
2425
+ mode: "section",
2426
+ reason: "section_small_enough"
2427
+ };
2378
2428
  }
2379
2429
  if (excerpts.windowExcerpt.trim().length > 0) {
2380
- return excerpts.windowExcerpt;
2430
+ return {
2431
+ excerpt: excerpts.windowExcerpt,
2432
+ mode: "window",
2433
+ reason: "section_too_large_use_window"
2434
+ };
2381
2435
  }
2436
+ return {
2437
+ excerpt: excerpts.chunkExcerpt,
2438
+ mode: "chunk",
2439
+ reason: "chunk_too_narrow"
2440
+ };
2382
2441
  }
2383
- return excerpts.chunkExcerpt;
2442
+ return {
2443
+ excerpt: excerpts.chunkExcerpt,
2444
+ mode: "chunk",
2445
+ reason: sectionChunkCount > 1 ? "chunk_too_narrow" : "single_chunk"
2446
+ };
2384
2447
  };
2448
+ var buildRAGExcerptModeCounts = (selections) => selections.reduce((counts, selection) => {
2449
+ if (selection) {
2450
+ counts[selection.mode] += 1;
2451
+ }
2452
+ return counts;
2453
+ }, { chunk: 0, section: 0, window: 0 });
2385
2454
  var buildRAGChunkGraph = (chunks) => {
2386
2455
  const nodes = [];
2387
2456
  const edges = [];
@@ -2570,19 +2639,27 @@ var buildRAGRetrievedState = (messages) => {
2570
2639
  return null;
2571
2640
  }
2572
2641
  const sources = message.sources ?? [];
2642
+ const citations = buildRAGCitations(sources);
2643
+ const sectionDiagnostics = buildRAGSectionRetrievalDiagnostics(sources, isRAGRetrievalTrace(message.retrievalTrace) ? message.retrievalTrace : undefined);
2644
+ const sourceSummaries = buildRAGSourceSummaries(sources);
2573
2645
  const groundedAnswer = buildRAGGroundedAnswer(message.content, sources);
2574
2646
  return {
2575
- citationReferenceMap: buildRAGCitationReferenceMap(buildRAGCitations(sources)),
2576
- citations: buildRAGCitations(sources),
2647
+ citationReferenceMap: buildRAGCitationReferenceMap(citations),
2648
+ citations,
2577
2649
  conversationId: message.conversationId,
2650
+ excerptModeCounts: buildRAGExcerptModeCounts([
2651
+ ...citations.map((citation) => citation.excerptSelection),
2652
+ ...sourceSummaries.map((summary) => summary.excerptSelection)
2653
+ ]),
2578
2654
  groundedAnswer,
2579
2655
  messageId: message.id,
2580
2656
  retrievalDurationMs: message.retrievalDurationMs,
2581
2657
  retrievalStartedAt: message.retrievalStartedAt,
2582
2658
  retrievedAt: message.retrievedAt,
2583
2659
  trace: isRAGRetrievalTrace(message.retrievalTrace) ? message.retrievalTrace : undefined,
2660
+ sectionDiagnostics,
2584
2661
  sourceGroups: buildRAGSourceGroups(sources),
2585
- sourceSummaries: buildRAGSourceSummaries(sources),
2662
+ sourceSummaries,
2586
2663
  sources
2587
2664
  };
2588
2665
  };
@@ -2594,6 +2671,8 @@ var buildRAGSourceSummaries = (sources) => {
2594
2671
  const groupCitations = citations.filter((citation) => group.chunks.some((chunk) => chunk.chunkId === citation.chunkId));
2595
2672
  const leadChunk = group.chunks.slice().sort((left, right) => right.score - left.score)[0];
2596
2673
  const excerpts = leadChunk ? buildRAGChunkExcerpts(group.chunks, leadChunk.chunkId) : undefined;
2674
+ const structure = leadChunk?.structure ?? buildRAGChunkStructure(leadChunk?.metadata);
2675
+ const excerptSelection = buildRAGExcerptSelection(excerpts, structure);
2597
2676
  return {
2598
2677
  bestScore: group.bestScore,
2599
2678
  citationNumbers: groupCitations.map((citation) => citationReferenceMap[citation.chunkId] ?? 0),
@@ -2601,18 +2680,154 @@ var buildRAGSourceSummaries = (sources) => {
2601
2680
  chunkIds: group.chunks.map((chunk) => chunk.chunkId),
2602
2681
  contextLabel: leadChunk?.labels?.contextLabel ?? buildContextLabel2(leadChunk?.metadata),
2603
2682
  count: group.count,
2604
- excerpt: buildRAGPreferredExcerpt(excerpts, leadChunk?.structure ?? buildRAGChunkStructure(leadChunk?.metadata)) || buildExcerpt2(leadChunk?.text ?? ""),
2683
+ excerpt: excerptSelection.excerpt || buildExcerpt2(leadChunk?.text ?? ""),
2605
2684
  excerpts,
2685
+ excerptSelection,
2606
2686
  key: group.key,
2607
2687
  label: group.label,
2608
2688
  locatorLabel: leadChunk?.labels?.locatorLabel ?? buildLocatorLabel2(leadChunk?.metadata, leadChunk?.source, leadChunk?.title),
2609
2689
  provenanceLabel: leadChunk?.labels?.provenanceLabel ?? buildProvenanceLabel2(leadChunk?.metadata),
2610
- structure: leadChunk?.structure ?? buildRAGChunkStructure(leadChunk?.metadata),
2690
+ structure,
2611
2691
  source: group.source,
2612
2692
  title: group.title
2613
2693
  };
2614
2694
  });
2615
2695
  };
2696
+ var getSectionPathFromSource = (source) => {
2697
+ const path = source.structure?.section?.path ?? (Array.isArray(source.metadata?.sectionPath) ? source.metadata.sectionPath.map((value) => getContextString2(value)).filter((value) => typeof value === "string") : []);
2698
+ return path.length > 0 ? path : undefined;
2699
+ };
2700
+ var buildRAGSectionRetrievalDiagnostics = (sources, trace) => {
2701
+ const totalScore = sources.reduce((sum, source) => sum + source.score, 0);
2702
+ if (sources.length === 0 || totalScore <= 0) {
2703
+ return [];
2704
+ }
2705
+ const sections = new Map;
2706
+ for (const source of sources) {
2707
+ const path = getSectionPathFromSource(source);
2708
+ if (!path) {
2709
+ continue;
2710
+ }
2711
+ const key = path.join(" > ");
2712
+ const label = path.at(-1) ?? key;
2713
+ const parentLabel = path.length > 1 ? path.slice(0, -1).join(" > ") : undefined;
2714
+ const existing = sections.get(key);
2715
+ const channels = Array.isArray(source.metadata?.retrievalChannels) ? source.metadata.retrievalChannels.filter((value) => value === "vector" || value === "lexical") : [];
2716
+ const isHybrid = channels.includes("vector") && channels.includes("lexical");
2717
+ const vectorHits = channels.includes("vector") ? 1 : 0;
2718
+ const lexicalHits = channels.includes("lexical") ? 1 : 0;
2719
+ const hybridHits = isHybrid ? 1 : 0;
2720
+ if (!existing) {
2721
+ sections.set(key, {
2722
+ bestScore: source.score,
2723
+ count: 1,
2724
+ hybridHits,
2725
+ key,
2726
+ label,
2727
+ lexicalHits,
2728
+ parentLabel,
2729
+ path,
2730
+ sourceSet: new Set(source.source ? [source.source] : []),
2731
+ topChunkId: source.chunkId,
2732
+ topSource: source.source,
2733
+ totalScore: source.score,
2734
+ vectorHits
2735
+ });
2736
+ continue;
2737
+ }
2738
+ existing.count += 1;
2739
+ existing.totalScore += source.score;
2740
+ if (source.source) {
2741
+ existing.sourceSet.add(source.source);
2742
+ }
2743
+ existing.vectorHits += vectorHits;
2744
+ existing.lexicalHits += lexicalHits;
2745
+ existing.hybridHits += hybridHits;
2746
+ if (source.score > existing.bestScore) {
2747
+ existing.bestScore = source.score;
2748
+ existing.topChunkId = source.chunkId;
2749
+ existing.topSource = source.source;
2750
+ }
2751
+ }
2752
+ const diagnostics = [...sections.values()];
2753
+ const strongestBestHit = diagnostics.reduce((highest, section) => Math.max(highest, section.bestScore), 0);
2754
+ return diagnostics.map((section) => {
2755
+ const siblingPool = diagnostics.filter((entry) => entry.parentLabel === section.parentLabel);
2756
+ const siblings = siblingPool.filter((entry) => entry.key !== section.key);
2757
+ const strongestSibling = siblings.slice().sort((left, right) => right.totalScore - left.totalScore)[0];
2758
+ const parentTotal = siblingPool.reduce((sum, entry) => sum + entry.totalScore, 0);
2759
+ const scoreShare = section.totalScore / totalScore;
2760
+ const parentShare = parentTotal > 0 ? section.totalScore / parentTotal : undefined;
2761
+ const parentDistribution = parentTotal > 0 ? siblingPool.map((entry) => ({
2762
+ count: entry.count,
2763
+ isActive: entry.key === section.key,
2764
+ key: entry.key,
2765
+ label: entry.label,
2766
+ parentShare: entry.totalScore / parentTotal,
2767
+ totalScore: entry.totalScore
2768
+ })).sort((left, right) => right.totalScore - left.totalScore) : [];
2769
+ const reasons = [];
2770
+ if (section.bestScore >= strongestBestHit) {
2771
+ reasons.push("best_hit");
2772
+ }
2773
+ if (section.count > 1) {
2774
+ reasons.push("multi_hit_section");
2775
+ }
2776
+ if (siblings.length === 0) {
2777
+ reasons.push("only_section_in_parent");
2778
+ } else if (!strongestSibling || section.totalScore >= strongestSibling.totalScore) {
2779
+ reasons.push("dominant_within_parent");
2780
+ }
2781
+ if (scoreShare >= 0.5 || (parentShare ?? 0) >= 0.6) {
2782
+ reasons.push("concentrated_evidence");
2783
+ }
2784
+ const summaryParts = [
2785
+ `${section.count} hit${section.count === 1 ? "" : "s"}`,
2786
+ `${(scoreShare * 100).toFixed(0)}% score share`,
2787
+ `vector ${section.vectorHits} · lexical ${section.lexicalHits} · hybrid ${section.hybridHits}`,
2788
+ typeof parentShare === "number" ? `${(parentShare * 100).toFixed(0)}% of parent section set` : "",
2789
+ strongestSibling ? `ahead of ${strongestSibling.label} by ${(section.totalScore - strongestSibling.totalScore).toFixed(2)}` : "no sibling competition"
2790
+ ].filter(Boolean);
2791
+ return {
2792
+ averageScore: section.totalScore / section.count,
2793
+ bestScore: section.bestScore,
2794
+ count: section.count,
2795
+ key: section.key,
2796
+ label: section.label,
2797
+ parentLabel: section.parentLabel,
2798
+ parentDistribution,
2799
+ parentShare,
2800
+ parentShareGap: typeof parentShare === "number" && strongestSibling && parentTotal > 0 ? parentShare - strongestSibling.totalScore / parentTotal : undefined,
2801
+ path: section.path,
2802
+ retrievalMode: trace?.mode,
2803
+ reasons,
2804
+ rerankApplied: trace?.steps.some((step) => step.stage === "rerank" && step.metadata?.applied === true),
2805
+ scoreShare,
2806
+ scoreThresholdApplied: trace?.steps.some((step) => step.stage === "score_filter"),
2807
+ siblingCount: siblings.length,
2808
+ siblingScoreGap: strongestSibling ? section.totalScore - strongestSibling.totalScore : undefined,
2809
+ sourceCount: section.sourceSet.size,
2810
+ sourceBalanceApplied: trace?.steps.some((step) => step.stage === "source_balance"),
2811
+ strongestSiblingLabel: strongestSibling?.label,
2812
+ strongestSiblingScore: strongestSibling?.totalScore,
2813
+ summary: summaryParts.join(" · "),
2814
+ topChunkId: section.topChunkId,
2815
+ topSource: section.topSource,
2816
+ totalScore: section.totalScore,
2817
+ hybridHits: section.hybridHits,
2818
+ lexicalHits: section.lexicalHits,
2819
+ vectorHits: section.vectorHits
2820
+ };
2821
+ }).sort((left, right) => {
2822
+ if (right.totalScore !== left.totalScore) {
2823
+ return right.totalScore - left.totalScore;
2824
+ }
2825
+ if (right.bestScore !== left.bestScore) {
2826
+ return right.bestScore - left.bestScore;
2827
+ }
2828
+ return left.label.localeCompare(right.label);
2829
+ });
2830
+ };
2616
2831
  var buildStreamProgressState = (messages) => {
2617
2832
  const latestMessage = getLatestAssistantMessage(messages);
2618
2833
  const retrieved = latestMessage ? buildRAGRetrievedState(messages) : undefined;
@@ -2676,12 +2891,19 @@ var buildRAGAnswerWorkflowState = ({
2676
2891
  const groundingReferences = buildRAGGroundingReferences(sources);
2677
2892
  const groundedAnswer = buildRAGGroundedAnswer(latestAssistantMessage?.content ?? "", sources);
2678
2893
  const retrieval = buildRAGRetrievedState(messages);
2894
+ const sectionDiagnostics = buildRAGSectionRetrievalDiagnostics(sources, retrieval?.trace);
2679
2895
  const progress = buildRAGStreamProgress({
2680
2896
  error,
2681
2897
  isStreaming,
2682
2898
  messages
2683
2899
  });
2684
2900
  return {
2901
+ excerptModeCounts: buildRAGExcerptModeCounts([
2902
+ ...citations.map((citation) => citation.excerptSelection),
2903
+ ...sourceSummaries.map((summary) => summary.excerptSelection),
2904
+ ...groundingReferences.map((reference) => reference.excerptSelection),
2905
+ ...groundedAnswer.sectionSummaries.map((summary) => summary.excerptSelection)
2906
+ ]),
2685
2907
  citationReferenceMap,
2686
2908
  citations,
2687
2909
  coverage: groundedAnswer.coverage,
@@ -2706,6 +2928,7 @@ var buildRAGAnswerWorkflowState = ({
2706
2928
  retrievalDurationMs: retrieval?.retrievalDurationMs,
2707
2929
  retrievalStartedAt: retrieval?.retrievalStartedAt,
2708
2930
  retrievedAt: retrieval?.retrievedAt,
2931
+ sectionDiagnostics,
2709
2932
  sourceGroups,
2710
2933
  sourceSummaries,
2711
2934
  sources,
@@ -2818,6 +3041,21 @@ var useRAGChunkPreview = (path) => {
2818
3041
  const isLoading = ref2(false);
2819
3042
  const chunkGraph = computed(() => preview.value ? buildRAGChunkPreviewGraph(preview.value) : null);
2820
3043
  const navigation = computed(() => preview.value ? buildRAGChunkPreviewNavigation(preview.value, activeChunkId.value ?? undefined) : null);
3044
+ const previewSources = computed(() => preview.value ? preview.value.chunks.map((chunk, index) => ({
3045
+ chunkId: chunk.chunkId,
3046
+ labels: chunk.labels,
3047
+ metadata: chunk.metadata,
3048
+ score: Math.max(0, preview.value.chunks.length - index),
3049
+ source: chunk.source ?? preview.value.document.source,
3050
+ structure: chunk.structure,
3051
+ text: chunk.text,
3052
+ title: chunk.title ?? preview.value.document.title
3053
+ })) : []);
3054
+ const sectionDiagnostics = computed(() => buildRAGSectionRetrievalDiagnostics(previewSources.value));
3055
+ const activeSectionDiagnostic = computed(() => {
3056
+ const sectionKey = navigation.value?.section?.path?.join(" > ");
3057
+ return sectionKey ? sectionDiagnostics.value.find((diagnostic) => diagnostic.key === sectionKey) ?? null : null;
3058
+ });
2821
3059
  const inspect = async (id) => {
2822
3060
  isLoading.value = true;
2823
3061
  error.value = null;
@@ -2865,6 +3103,7 @@ var useRAGChunkPreview = (path) => {
2865
3103
  };
2866
3104
  return {
2867
3105
  activeChunkId,
3106
+ activeSectionDiagnostic,
2868
3107
  clear,
2869
3108
  chunkGraph,
2870
3109
  error,
@@ -2872,6 +3111,7 @@ var useRAGChunkPreview = (path) => {
2872
3111
  isLoading,
2873
3112
  navigation,
2874
3113
  preview,
3114
+ sectionDiagnostics,
2875
3115
  selectChildSection,
2876
3116
  selectChunk,
2877
3117
  selectParentSection,
@@ -3818,6 +4058,7 @@ var useRAGSources = (messages) => {
3818
4058
  const sources = computed5(() => getLatestRAGSources(messages.value));
3819
4059
  const sourceGroups = computed5(() => buildRAGSourceGroups(sources.value));
3820
4060
  const sourceSummaries = computed5(() => buildRAGSourceSummaries(sources.value));
4061
+ const sectionDiagnostics = computed5(() => buildRAGSectionRetrievalDiagnostics(sources.value, latestAssistantMessage.value?.retrievalTrace));
3821
4062
  const chunkGraph = computed5(() => buildRAGChunkGraph(sources.value));
3822
4063
  const citationReferenceMap = computed5(() => buildRAGCitationReferenceMap(sourceSummaries.value.flatMap((summary) => summary.citations)));
3823
4064
  const hasSources = computed5(() => sources.value.length > 0);
@@ -3828,6 +4069,7 @@ var useRAGSources = (messages) => {
3828
4069
  hasSources,
3829
4070
  latestAssistantMessage,
3830
4071
  navigationForChunk,
4072
+ sectionDiagnostics,
3831
4073
  sourceGroups,
3832
4074
  sources,
3833
4075
  sourceSummaries