@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
@@ -1016,21 +1016,48 @@ var buildExcerpt = (text, maxLength = 160) => {
1016
1016
  };
1017
1017
  var selectPreferredExcerpt = (excerpts, sectionChunkCount) => {
1018
1018
  if (!excerpts) {
1019
- return "";
1019
+ return {
1020
+ excerpt: "",
1021
+ mode: "chunk",
1022
+ reason: "single_chunk"
1023
+ };
1020
1024
  }
1021
1025
  const chunkExcerpt = excerpts.chunkExcerpt?.trim() ?? "";
1022
1026
  const windowExcerpt = excerpts.windowExcerpt?.trim() ?? "";
1023
1027
  const sectionExcerpt = excerpts.sectionExcerpt?.trim() ?? "";
1024
1028
  if (sectionChunkCount && sectionChunkCount > 1 && chunkExcerpt.length > 0 && chunkExcerpt.length < 72) {
1025
1029
  if (sectionChunkCount <= 3 && sectionExcerpt) {
1026
- return sectionExcerpt;
1030
+ return {
1031
+ excerpt: sectionExcerpt,
1032
+ mode: "section",
1033
+ reason: "section_small_enough"
1034
+ };
1027
1035
  }
1028
1036
  if (windowExcerpt) {
1029
- return windowExcerpt;
1037
+ return {
1038
+ excerpt: windowExcerpt,
1039
+ mode: "window",
1040
+ reason: "section_too_large_use_window"
1041
+ };
1030
1042
  }
1043
+ return {
1044
+ excerpt: chunkExcerpt,
1045
+ mode: "chunk",
1046
+ reason: "chunk_too_narrow"
1047
+ };
1031
1048
  }
1032
- return chunkExcerpt || windowExcerpt || sectionExcerpt;
1049
+ return {
1050
+ excerpt: chunkExcerpt || windowExcerpt || sectionExcerpt,
1051
+ mode: "chunk",
1052
+ reason: (sectionChunkCount ?? 0) > 1 ? "chunk_too_narrow" : "single_chunk"
1053
+ };
1033
1054
  };
1055
+ var buildExcerptModeCounts = (references) => references.reduce((counts, reference) => {
1056
+ if (reference?.excerptSelection) {
1057
+ counts[reference.excerptSelection.mode] += 1;
1058
+ }
1059
+ return counts;
1060
+ }, { chunk: 0, section: 0, window: 0 });
1034
1061
  var buildGroundingChunkExcerpts = (sources, activeChunkId) => {
1035
1062
  if (sources.length === 0) {
1036
1063
  return;
@@ -1086,8 +1113,9 @@ var buildGroundedAnswerCitationDetail = (reference) => ({
1086
1113
  contextLabel: reference.contextLabel,
1087
1114
  evidenceLabel: buildGroundingReferenceEvidenceLabel(reference),
1088
1115
  evidenceSummary: buildGroundingReferenceEvidenceSummary(reference),
1089
- excerpt: selectPreferredExcerpt(reference.excerpts, getContextNumber(reference.metadata?.sectionChunkCount)) || reference.excerpt,
1116
+ excerpt: selectPreferredExcerpt(reference.excerpts, getContextNumber(reference.metadata?.sectionChunkCount)).excerpt || reference.excerpt,
1090
1117
  excerpts: reference.excerpts,
1118
+ excerptSelection: reference.excerptSelection,
1091
1119
  label: reference.label,
1092
1120
  locatorLabel: reference.locatorLabel,
1093
1121
  number: reference.number,
@@ -1104,11 +1132,14 @@ var buildRAGCitations = (sources) => {
1104
1132
  const hasBetterExisting = existing !== undefined && existing.score >= source.score;
1105
1133
  if (hasBetterExisting)
1106
1134
  continue;
1135
+ const excerpts = buildGroundingChunkExcerpts(sources, source.chunkId);
1136
+ const excerptSelection = selectPreferredExcerpt(excerpts, getContextNumber(source.metadata?.sectionChunkCount));
1107
1137
  unique.set(key, {
1108
1138
  chunkId: source.chunkId,
1109
1139
  contextLabel: source.labels?.contextLabel ?? buildContextLabel(source.metadata),
1110
- excerpt: selectPreferredExcerpt(buildGroundingChunkExcerpts(sources, source.chunkId), getContextNumber(source.metadata?.sectionChunkCount)) || buildExcerpt(source.text),
1111
- excerpts: buildGroundingChunkExcerpts(sources, source.chunkId),
1140
+ excerpt: excerptSelection.excerpt || buildExcerpt(source.text),
1141
+ excerpts,
1142
+ excerptSelection,
1112
1143
  key,
1113
1144
  label: buildSourceLabel(source),
1114
1145
  locatorLabel: source.labels?.locatorLabel ?? buildLocatorLabel(source.metadata, source.source, source.title),
@@ -1129,6 +1160,7 @@ var buildRAGCitations = (sources) => {
1129
1160
  };
1130
1161
  var buildRAGGroundedAnswer = (content, sources) => {
1131
1162
  const references = buildRAGGroundingReferences(sources);
1163
+ const sectionSummaries = buildRAGGroundedAnswerSectionSummaries(references);
1132
1164
  const referenceMap = new Map(references.map((reference) => [reference.number, reference]));
1133
1165
  const parts = [];
1134
1166
  const ungroundedReferenceNumbers = new Set;
@@ -1172,10 +1204,14 @@ var buildRAGGroundedAnswer = (content, sources) => {
1172
1204
  return {
1173
1205
  content,
1174
1206
  coverage,
1207
+ excerptModeCounts: buildExcerptModeCounts([
1208
+ ...references,
1209
+ ...sectionSummaries
1210
+ ]),
1175
1211
  hasCitations,
1176
1212
  parts,
1177
1213
  references,
1178
- sectionSummaries: buildRAGGroundedAnswerSectionSummaries(references),
1214
+ sectionSummaries,
1179
1215
  ungroundedReferenceNumbers: [...ungroundedReferenceNumbers].sort((left, right) => left - right)
1180
1216
  };
1181
1217
  };
@@ -1194,8 +1230,9 @@ var buildRAGGroundedAnswerSectionSummaries = (references) => {
1194
1230
  chunkIds: [reference.chunkId],
1195
1231
  contextLabel: reference.contextLabel,
1196
1232
  count: 1,
1197
- excerpt: selectPreferredExcerpt(excerpts, getContextNumber(reference.metadata?.sectionChunkCount)) || excerpts?.sectionExcerpt || reference.excerpt,
1233
+ excerpt: selectPreferredExcerpt(excerpts, getContextNumber(reference.metadata?.sectionChunkCount)).excerpt || excerpts?.sectionExcerpt || reference.excerpt,
1198
1234
  excerpts,
1235
+ excerptSelection: reference.excerptSelection,
1199
1236
  key,
1200
1237
  label: key,
1201
1238
  locatorLabel: reference.locatorLabel,
@@ -1231,6 +1268,9 @@ var buildRAGGroundedAnswerSectionSummaries = (references) => {
1231
1268
  };
1232
1269
  existing.excerpt = reference.excerpts.sectionExcerpt;
1233
1270
  }
1271
+ if (!existing.excerptSelection && reference.excerptSelection) {
1272
+ existing.excerptSelection = reference.excerptSelection;
1273
+ }
1234
1274
  }
1235
1275
  return [...groups.values()].map((group) => ({
1236
1276
  ...group,
@@ -1250,11 +1290,13 @@ var buildRAGGroundingReferences = (sources) => {
1250
1290
  const citationReferenceMap = buildRAGCitationReferenceMap(citations);
1251
1291
  return citations.map((citation) => {
1252
1292
  const excerpts = buildGroundingChunkExcerpts(sources, citation.chunkId);
1293
+ const excerptSelection = selectPreferredExcerpt(excerpts, getContextNumber(citation.metadata?.sectionChunkCount));
1253
1294
  return {
1254
1295
  chunkId: citation.chunkId,
1255
1296
  contextLabel: citation.contextLabel ?? buildContextLabel(citation.metadata),
1256
- excerpt: selectPreferredExcerpt(excerpts, getContextNumber(citation.metadata?.sectionChunkCount)) || excerpts?.chunkExcerpt || buildExcerpt(citation.text),
1297
+ excerpt: excerptSelection.excerpt || excerpts?.chunkExcerpt || buildExcerpt(citation.text),
1257
1298
  excerpts,
1299
+ excerptSelection,
1258
1300
  label: citation.label,
1259
1301
  locatorLabel: citation.locatorLabel ?? buildLocatorLabel(citation.metadata, citation.source, citation.title),
1260
1302
  metadata: citation.metadata,
@@ -1913,22 +1955,49 @@ var buildRAGChunkExcerpts = (chunks, activeChunkId) => {
1913
1955
  windowExcerpt: buildExcerpt2(collectText(orderedWindowIds), 240)
1914
1956
  };
1915
1957
  };
1916
- var buildRAGPreferredExcerpt = (excerpts, structure) => {
1958
+ var buildRAGExcerptSelection = (excerpts, structure) => {
1917
1959
  if (!excerpts) {
1918
- return "";
1960
+ return {
1961
+ excerpt: "",
1962
+ mode: "chunk",
1963
+ reason: "single_chunk"
1964
+ };
1919
1965
  }
1920
1966
  const chunkLength = excerpts.chunkExcerpt.trim().length;
1921
1967
  const sectionChunkCount = structure?.sequence?.sectionChunkCount ?? 1;
1922
1968
  if (sectionChunkCount > 1 && chunkLength > 0 && chunkLength < 72) {
1923
1969
  if (sectionChunkCount <= 3 && excerpts.sectionExcerpt.trim().length > 0) {
1924
- return excerpts.sectionExcerpt;
1970
+ return {
1971
+ excerpt: excerpts.sectionExcerpt,
1972
+ mode: "section",
1973
+ reason: "section_small_enough"
1974
+ };
1925
1975
  }
1926
1976
  if (excerpts.windowExcerpt.trim().length > 0) {
1927
- return excerpts.windowExcerpt;
1977
+ return {
1978
+ excerpt: excerpts.windowExcerpt,
1979
+ mode: "window",
1980
+ reason: "section_too_large_use_window"
1981
+ };
1928
1982
  }
1983
+ return {
1984
+ excerpt: excerpts.chunkExcerpt,
1985
+ mode: "chunk",
1986
+ reason: "chunk_too_narrow"
1987
+ };
1929
1988
  }
1930
- return excerpts.chunkExcerpt;
1989
+ return {
1990
+ excerpt: excerpts.chunkExcerpt,
1991
+ mode: "chunk",
1992
+ reason: sectionChunkCount > 1 ? "chunk_too_narrow" : "single_chunk"
1993
+ };
1931
1994
  };
1995
+ var buildRAGExcerptModeCounts = (selections) => selections.reduce((counts, selection) => {
1996
+ if (selection) {
1997
+ counts[selection.mode] += 1;
1998
+ }
1999
+ return counts;
2000
+ }, { chunk: 0, section: 0, window: 0 });
1932
2001
  var buildRAGChunkGraph = (chunks) => {
1933
2002
  const nodes = [];
1934
2003
  const edges = [];
@@ -2117,19 +2186,27 @@ var buildRAGRetrievedState = (messages) => {
2117
2186
  return null;
2118
2187
  }
2119
2188
  const sources = message.sources ?? [];
2189
+ const citations = buildRAGCitations(sources);
2190
+ const sectionDiagnostics = buildRAGSectionRetrievalDiagnostics(sources, isRAGRetrievalTrace(message.retrievalTrace) ? message.retrievalTrace : undefined);
2191
+ const sourceSummaries = buildRAGSourceSummaries(sources);
2120
2192
  const groundedAnswer = buildRAGGroundedAnswer(message.content, sources);
2121
2193
  return {
2122
- citationReferenceMap: buildRAGCitationReferenceMap(buildRAGCitations(sources)),
2123
- citations: buildRAGCitations(sources),
2194
+ citationReferenceMap: buildRAGCitationReferenceMap(citations),
2195
+ citations,
2124
2196
  conversationId: message.conversationId,
2197
+ excerptModeCounts: buildRAGExcerptModeCounts([
2198
+ ...citations.map((citation) => citation.excerptSelection),
2199
+ ...sourceSummaries.map((summary) => summary.excerptSelection)
2200
+ ]),
2125
2201
  groundedAnswer,
2126
2202
  messageId: message.id,
2127
2203
  retrievalDurationMs: message.retrievalDurationMs,
2128
2204
  retrievalStartedAt: message.retrievalStartedAt,
2129
2205
  retrievedAt: message.retrievedAt,
2130
2206
  trace: isRAGRetrievalTrace(message.retrievalTrace) ? message.retrievalTrace : undefined,
2207
+ sectionDiagnostics,
2131
2208
  sourceGroups: buildRAGSourceGroups(sources),
2132
- sourceSummaries: buildRAGSourceSummaries(sources),
2209
+ sourceSummaries,
2133
2210
  sources
2134
2211
  };
2135
2212
  };
@@ -2141,6 +2218,8 @@ var buildRAGSourceSummaries = (sources) => {
2141
2218
  const groupCitations = citations.filter((citation) => group.chunks.some((chunk) => chunk.chunkId === citation.chunkId));
2142
2219
  const leadChunk = group.chunks.slice().sort((left, right) => right.score - left.score)[0];
2143
2220
  const excerpts = leadChunk ? buildRAGChunkExcerpts(group.chunks, leadChunk.chunkId) : undefined;
2221
+ const structure = leadChunk?.structure ?? buildRAGChunkStructure(leadChunk?.metadata);
2222
+ const excerptSelection = buildRAGExcerptSelection(excerpts, structure);
2144
2223
  return {
2145
2224
  bestScore: group.bestScore,
2146
2225
  citationNumbers: groupCitations.map((citation) => citationReferenceMap[citation.chunkId] ?? 0),
@@ -2148,18 +2227,154 @@ var buildRAGSourceSummaries = (sources) => {
2148
2227
  chunkIds: group.chunks.map((chunk) => chunk.chunkId),
2149
2228
  contextLabel: leadChunk?.labels?.contextLabel ?? buildContextLabel2(leadChunk?.metadata),
2150
2229
  count: group.count,
2151
- excerpt: buildRAGPreferredExcerpt(excerpts, leadChunk?.structure ?? buildRAGChunkStructure(leadChunk?.metadata)) || buildExcerpt2(leadChunk?.text ?? ""),
2230
+ excerpt: excerptSelection.excerpt || buildExcerpt2(leadChunk?.text ?? ""),
2152
2231
  excerpts,
2232
+ excerptSelection,
2153
2233
  key: group.key,
2154
2234
  label: group.label,
2155
2235
  locatorLabel: leadChunk?.labels?.locatorLabel ?? buildLocatorLabel2(leadChunk?.metadata, leadChunk?.source, leadChunk?.title),
2156
2236
  provenanceLabel: leadChunk?.labels?.provenanceLabel ?? buildProvenanceLabel2(leadChunk?.metadata),
2157
- structure: leadChunk?.structure ?? buildRAGChunkStructure(leadChunk?.metadata),
2237
+ structure,
2158
2238
  source: group.source,
2159
2239
  title: group.title
2160
2240
  };
2161
2241
  });
2162
2242
  };
2243
+ var getSectionPathFromSource = (source) => {
2244
+ const path = source.structure?.section?.path ?? (Array.isArray(source.metadata?.sectionPath) ? source.metadata.sectionPath.map((value) => getContextString2(value)).filter((value) => typeof value === "string") : []);
2245
+ return path.length > 0 ? path : undefined;
2246
+ };
2247
+ var buildRAGSectionRetrievalDiagnostics = (sources, trace) => {
2248
+ const totalScore = sources.reduce((sum, source) => sum + source.score, 0);
2249
+ if (sources.length === 0 || totalScore <= 0) {
2250
+ return [];
2251
+ }
2252
+ const sections = new Map;
2253
+ for (const source of sources) {
2254
+ const path = getSectionPathFromSource(source);
2255
+ if (!path) {
2256
+ continue;
2257
+ }
2258
+ const key = path.join(" > ");
2259
+ const label = path.at(-1) ?? key;
2260
+ const parentLabel = path.length > 1 ? path.slice(0, -1).join(" > ") : undefined;
2261
+ const existing = sections.get(key);
2262
+ const channels = Array.isArray(source.metadata?.retrievalChannels) ? source.metadata.retrievalChannels.filter((value) => value === "vector" || value === "lexical") : [];
2263
+ const isHybrid = channels.includes("vector") && channels.includes("lexical");
2264
+ const vectorHits = channels.includes("vector") ? 1 : 0;
2265
+ const lexicalHits = channels.includes("lexical") ? 1 : 0;
2266
+ const hybridHits = isHybrid ? 1 : 0;
2267
+ if (!existing) {
2268
+ sections.set(key, {
2269
+ bestScore: source.score,
2270
+ count: 1,
2271
+ hybridHits,
2272
+ key,
2273
+ label,
2274
+ lexicalHits,
2275
+ parentLabel,
2276
+ path,
2277
+ sourceSet: new Set(source.source ? [source.source] : []),
2278
+ topChunkId: source.chunkId,
2279
+ topSource: source.source,
2280
+ totalScore: source.score,
2281
+ vectorHits
2282
+ });
2283
+ continue;
2284
+ }
2285
+ existing.count += 1;
2286
+ existing.totalScore += source.score;
2287
+ if (source.source) {
2288
+ existing.sourceSet.add(source.source);
2289
+ }
2290
+ existing.vectorHits += vectorHits;
2291
+ existing.lexicalHits += lexicalHits;
2292
+ existing.hybridHits += hybridHits;
2293
+ if (source.score > existing.bestScore) {
2294
+ existing.bestScore = source.score;
2295
+ existing.topChunkId = source.chunkId;
2296
+ existing.topSource = source.source;
2297
+ }
2298
+ }
2299
+ const diagnostics = [...sections.values()];
2300
+ const strongestBestHit = diagnostics.reduce((highest, section) => Math.max(highest, section.bestScore), 0);
2301
+ return diagnostics.map((section) => {
2302
+ const siblingPool = diagnostics.filter((entry) => entry.parentLabel === section.parentLabel);
2303
+ const siblings = siblingPool.filter((entry) => entry.key !== section.key);
2304
+ const strongestSibling = siblings.slice().sort((left, right) => right.totalScore - left.totalScore)[0];
2305
+ const parentTotal = siblingPool.reduce((sum, entry) => sum + entry.totalScore, 0);
2306
+ const scoreShare = section.totalScore / totalScore;
2307
+ const parentShare = parentTotal > 0 ? section.totalScore / parentTotal : undefined;
2308
+ const parentDistribution = parentTotal > 0 ? siblingPool.map((entry) => ({
2309
+ count: entry.count,
2310
+ isActive: entry.key === section.key,
2311
+ key: entry.key,
2312
+ label: entry.label,
2313
+ parentShare: entry.totalScore / parentTotal,
2314
+ totalScore: entry.totalScore
2315
+ })).sort((left, right) => right.totalScore - left.totalScore) : [];
2316
+ const reasons = [];
2317
+ if (section.bestScore >= strongestBestHit) {
2318
+ reasons.push("best_hit");
2319
+ }
2320
+ if (section.count > 1) {
2321
+ reasons.push("multi_hit_section");
2322
+ }
2323
+ if (siblings.length === 0) {
2324
+ reasons.push("only_section_in_parent");
2325
+ } else if (!strongestSibling || section.totalScore >= strongestSibling.totalScore) {
2326
+ reasons.push("dominant_within_parent");
2327
+ }
2328
+ if (scoreShare >= 0.5 || (parentShare ?? 0) >= 0.6) {
2329
+ reasons.push("concentrated_evidence");
2330
+ }
2331
+ const summaryParts = [
2332
+ `${section.count} hit${section.count === 1 ? "" : "s"}`,
2333
+ `${(scoreShare * 100).toFixed(0)}% score share`,
2334
+ `vector ${section.vectorHits} \xB7 lexical ${section.lexicalHits} \xB7 hybrid ${section.hybridHits}`,
2335
+ typeof parentShare === "number" ? `${(parentShare * 100).toFixed(0)}% of parent section set` : "",
2336
+ strongestSibling ? `ahead of ${strongestSibling.label} by ${(section.totalScore - strongestSibling.totalScore).toFixed(2)}` : "no sibling competition"
2337
+ ].filter(Boolean);
2338
+ return {
2339
+ averageScore: section.totalScore / section.count,
2340
+ bestScore: section.bestScore,
2341
+ count: section.count,
2342
+ key: section.key,
2343
+ label: section.label,
2344
+ parentLabel: section.parentLabel,
2345
+ parentDistribution,
2346
+ parentShare,
2347
+ parentShareGap: typeof parentShare === "number" && strongestSibling && parentTotal > 0 ? parentShare - strongestSibling.totalScore / parentTotal : undefined,
2348
+ path: section.path,
2349
+ retrievalMode: trace?.mode,
2350
+ reasons,
2351
+ rerankApplied: trace?.steps.some((step) => step.stage === "rerank" && step.metadata?.applied === true),
2352
+ scoreShare,
2353
+ scoreThresholdApplied: trace?.steps.some((step) => step.stage === "score_filter"),
2354
+ siblingCount: siblings.length,
2355
+ siblingScoreGap: strongestSibling ? section.totalScore - strongestSibling.totalScore : undefined,
2356
+ sourceCount: section.sourceSet.size,
2357
+ sourceBalanceApplied: trace?.steps.some((step) => step.stage === "source_balance"),
2358
+ strongestSiblingLabel: strongestSibling?.label,
2359
+ strongestSiblingScore: strongestSibling?.totalScore,
2360
+ summary: summaryParts.join(" \xB7 "),
2361
+ topChunkId: section.topChunkId,
2362
+ topSource: section.topSource,
2363
+ totalScore: section.totalScore,
2364
+ hybridHits: section.hybridHits,
2365
+ lexicalHits: section.lexicalHits,
2366
+ vectorHits: section.vectorHits
2367
+ };
2368
+ }).sort((left, right) => {
2369
+ if (right.totalScore !== left.totalScore) {
2370
+ return right.totalScore - left.totalScore;
2371
+ }
2372
+ if (right.bestScore !== left.bestScore) {
2373
+ return right.bestScore - left.bestScore;
2374
+ }
2375
+ return left.label.localeCompare(right.label);
2376
+ });
2377
+ };
2163
2378
  var buildStreamProgressState = (messages) => {
2164
2379
  const latestMessage = getLatestAssistantMessage(messages);
2165
2380
  const retrieved = latestMessage ? buildRAGRetrievedState(messages) : undefined;
@@ -2223,12 +2438,19 @@ var buildRAGAnswerWorkflowState = ({
2223
2438
  const groundingReferences = buildRAGGroundingReferences(sources);
2224
2439
  const groundedAnswer = buildRAGGroundedAnswer(latestAssistantMessage?.content ?? "", sources);
2225
2440
  const retrieval = buildRAGRetrievedState(messages);
2441
+ const sectionDiagnostics = buildRAGSectionRetrievalDiagnostics(sources, retrieval?.trace);
2226
2442
  const progress = buildRAGStreamProgress({
2227
2443
  error,
2228
2444
  isStreaming,
2229
2445
  messages
2230
2446
  });
2231
2447
  return {
2448
+ excerptModeCounts: buildRAGExcerptModeCounts([
2449
+ ...citations.map((citation) => citation.excerptSelection),
2450
+ ...sourceSummaries.map((summary) => summary.excerptSelection),
2451
+ ...groundingReferences.map((reference) => reference.excerptSelection),
2452
+ ...groundedAnswer.sectionSummaries.map((summary) => summary.excerptSelection)
2453
+ ]),
2232
2454
  citationReferenceMap,
2233
2455
  citations,
2234
2456
  coverage: groundedAnswer.coverage,
@@ -2253,6 +2475,7 @@ var buildRAGAnswerWorkflowState = ({
2253
2475
  retrievalDurationMs: retrieval?.retrievalDurationMs,
2254
2476
  retrievalStartedAt: retrieval?.retrievalStartedAt,
2255
2477
  retrievedAt: retrieval?.retrievedAt,
2478
+ sectionDiagnostics,
2256
2479
  sourceGroups,
2257
2480
  sourceSummaries,
2258
2481
  sources,
@@ -4317,5 +4540,5 @@ export {
4317
4540
  AIStreamService
4318
4541
  };
4319
4542
 
4320
- //# debugId=66CB3D3B24BE2E6464756E2164756E21
4543
+ //# debugId=258C7444FC4D9BD664756E2164756E21
4321
4544
  //# sourceMappingURL=index.js.map