@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
package/dist/ai/rag/ui.js CHANGED
@@ -236,6 +236,60 @@ 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 = [
281
+ previousChunkId,
282
+ activeSource.chunkId,
283
+ nextChunkId
284
+ ].filter((chunkId, index, values) => Boolean(chunkId) && values.indexOf(chunkId) === index);
285
+ return {
286
+ chunkExcerpt: buildExcerpt(activeSource.text, 160),
287
+ sectionExcerpt: buildExcerpt(sectionSources.map((source) => source.text).join(`
288
+
289
+ `), 320),
290
+ windowExcerpt: buildExcerpt(collectText(orderedWindowIds), 240)
291
+ };
292
+ };
239
293
  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
294
  var buildGroundingReferenceEvidenceSummary = (reference) => [
241
295
  reference.source ?? reference.title ?? reference.chunkId,
@@ -254,7 +308,8 @@ var buildGroundedAnswerCitationDetail = (reference) => ({
254
308
  contextLabel: reference.contextLabel,
255
309
  evidenceLabel: buildGroundingReferenceEvidenceLabel(reference),
256
310
  evidenceSummary: buildGroundingReferenceEvidenceSummary(reference),
257
- excerpt: reference.excerpt,
311
+ excerpt: selectPreferredExcerpt(reference.excerpts, getContextNumber(reference.metadata?.sectionChunkCount)) || reference.excerpt,
312
+ excerpts: reference.excerpts,
258
313
  label: reference.label,
259
314
  locatorLabel: reference.locatorLabel,
260
315
  number: reference.number,
@@ -274,6 +329,8 @@ var buildRAGCitations = (sources) => {
274
329
  unique.set(key, {
275
330
  chunkId: source.chunkId,
276
331
  contextLabel: source.labels?.contextLabel ?? buildContextLabel(source.metadata),
332
+ excerpt: selectPreferredExcerpt(buildGroundingChunkExcerpts(sources, source.chunkId), getContextNumber(source.metadata?.sectionChunkCount)) || buildExcerpt(source.text),
333
+ excerpts: buildGroundingChunkExcerpts(sources, source.chunkId),
277
334
  key,
278
335
  label: buildSourceLabel(source),
279
336
  locatorLabel: source.labels?.locatorLabel ?? buildLocatorLabel(source.metadata, source.source, source.title),
@@ -350,10 +407,17 @@ var buildRAGGroundedAnswerSectionSummaries = (references) => {
350
407
  const key = buildGroundingSectionKey(reference);
351
408
  const existing = groups.get(key);
352
409
  if (!existing) {
410
+ const excerpts = reference.excerpts ? {
411
+ chunkExcerpt: reference.excerpts.chunkExcerpt,
412
+ sectionExcerpt: reference.excerpts.sectionExcerpt,
413
+ windowExcerpt: reference.excerpts.windowExcerpt
414
+ } : undefined;
353
415
  groups.set(key, {
354
416
  chunkIds: [reference.chunkId],
355
417
  contextLabel: reference.contextLabel,
356
418
  count: 1,
419
+ excerpt: selectPreferredExcerpt(excerpts, getContextNumber(reference.metadata?.sectionChunkCount)) || excerpts?.sectionExcerpt || reference.excerpt,
420
+ excerpts,
357
421
  key,
358
422
  label: key,
359
423
  locatorLabel: reference.locatorLabel,
@@ -381,6 +445,14 @@ var buildRAGGroundedAnswerSectionSummaries = (references) => {
381
445
  if (!existing.provenanceLabel && reference.provenanceLabel) {
382
446
  existing.provenanceLabel = reference.provenanceLabel;
383
447
  }
448
+ if (!existing.excerpts && reference.excerpts) {
449
+ existing.excerpts = {
450
+ chunkExcerpt: reference.excerpts.chunkExcerpt,
451
+ sectionExcerpt: reference.excerpts.sectionExcerpt,
452
+ windowExcerpt: reference.excerpts.windowExcerpt
453
+ };
454
+ existing.excerpt = reference.excerpts.sectionExcerpt;
455
+ }
384
456
  }
385
457
  return [...groups.values()].map((group) => ({
386
458
  ...group,
@@ -398,20 +470,24 @@ var buildRAGGroundedAnswerSectionSummaries = (references) => {
398
470
  var buildRAGGroundingReferences = (sources) => {
399
471
  const citations = buildRAGCitations(sources);
400
472
  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
- }));
473
+ return citations.map((citation) => {
474
+ const excerpts = buildGroundingChunkExcerpts(sources, citation.chunkId);
475
+ return {
476
+ chunkId: citation.chunkId,
477
+ contextLabel: citation.contextLabel ?? buildContextLabel(citation.metadata),
478
+ excerpt: selectPreferredExcerpt(excerpts, getContextNumber(citation.metadata?.sectionChunkCount)) || excerpts?.chunkExcerpt || buildExcerpt(citation.text),
479
+ excerpts,
480
+ label: citation.label,
481
+ locatorLabel: citation.locatorLabel ?? buildLocatorLabel(citation.metadata, citation.source, citation.title),
482
+ metadata: citation.metadata,
483
+ number: citationReferenceMap[citation.chunkId] ?? 0,
484
+ provenanceLabel: citation.provenanceLabel ?? buildProvenanceLabel(citation.metadata),
485
+ score: citation.score,
486
+ source: citation.source,
487
+ text: citation.text,
488
+ title: citation.title
489
+ };
490
+ });
415
491
  };
416
492
 
417
493
  // src/ai/rag/presentation.ts
@@ -1000,7 +1076,7 @@ var buildRAGChunkStructure = (metadata) => {
1000
1076
  return;
1001
1077
  }
1002
1078
  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;
1079
+ 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
1080
  const section = {
1005
1081
  depth: getContextNumber2(metadata.sectionDepth),
1006
1082
  kind: sectionKind,
@@ -1029,6 +1105,52 @@ var buildExcerpt2 = (text, maxLength = 160) => {
1029
1105
  }
1030
1106
  return `${normalized.slice(0, Math.max(0, maxLength - 1)).trimEnd()}\u2026`;
1031
1107
  };
1108
+ var buildRAGChunkExcerpts = (chunks, activeChunkId) => {
1109
+ if (chunks.length === 0) {
1110
+ return;
1111
+ }
1112
+ const graph = buildRAGChunkGraph(chunks.map((chunk) => ({
1113
+ chunkId: chunk.chunkId,
1114
+ metadata: chunk.metadata,
1115
+ structure: chunk.structure
1116
+ })));
1117
+ const navigation = buildRAGChunkGraphNavigation(graph, activeChunkId);
1118
+ const activeChunk = chunks.find((chunk) => chunk.chunkId === navigation.activeChunkId) ?? chunks[0];
1119
+ if (!activeChunk) {
1120
+ return;
1121
+ }
1122
+ const chunkMap = new Map(chunks.map((chunk) => [chunk.chunkId, chunk]));
1123
+ const orderedWindowIds = [
1124
+ navigation.previousNode?.chunkId,
1125
+ activeChunk.chunkId,
1126
+ navigation.nextNode?.chunkId
1127
+ ].filter((chunkId, index, ids) => Boolean(chunkId) && ids.indexOf(chunkId) === index);
1128
+ const orderedSectionIds = navigation.sectionNodes.length > 0 ? navigation.sectionNodes.map((node) => node.chunkId) : [activeChunk.chunkId];
1129
+ const collectText = (chunkIds) => chunkIds.map((chunkId) => chunkMap.get(chunkId)?.text).filter((text) => typeof text === "string").join(`
1130
+
1131
+ `);
1132
+ return {
1133
+ chunkExcerpt: buildExcerpt2(activeChunk.text, 160),
1134
+ sectionExcerpt: buildExcerpt2(collectText(orderedSectionIds), 320),
1135
+ windowExcerpt: buildExcerpt2(collectText(orderedWindowIds), 240)
1136
+ };
1137
+ };
1138
+ var buildRAGPreferredExcerpt = (excerpts, structure) => {
1139
+ if (!excerpts) {
1140
+ return "";
1141
+ }
1142
+ const chunkLength = excerpts.chunkExcerpt.trim().length;
1143
+ const sectionChunkCount = structure?.sequence?.sectionChunkCount ?? 1;
1144
+ if (sectionChunkCount > 1 && chunkLength > 0 && chunkLength < 72) {
1145
+ if (sectionChunkCount <= 3 && excerpts.sectionExcerpt.trim().length > 0) {
1146
+ return excerpts.sectionExcerpt;
1147
+ }
1148
+ if (excerpts.windowExcerpt.trim().length > 0) {
1149
+ return excerpts.windowExcerpt;
1150
+ }
1151
+ }
1152
+ return excerpts.chunkExcerpt;
1153
+ };
1032
1154
  var buildRAGChunkGraph = (chunks) => {
1033
1155
  const nodes = [];
1034
1156
  const edges = [];
@@ -1240,6 +1362,7 @@ var buildRAGSourceSummaries = (sources) => {
1240
1362
  return sourceGroups.map((group) => {
1241
1363
  const groupCitations = citations.filter((citation) => group.chunks.some((chunk) => chunk.chunkId === citation.chunkId));
1242
1364
  const leadChunk = group.chunks.slice().sort((left, right) => right.score - left.score)[0];
1365
+ const excerpts = leadChunk ? buildRAGChunkExcerpts(group.chunks, leadChunk.chunkId) : undefined;
1243
1366
  return {
1244
1367
  bestScore: group.bestScore,
1245
1368
  citationNumbers: groupCitations.map((citation) => citationReferenceMap[citation.chunkId] ?? 0),
@@ -1247,7 +1370,8 @@ var buildRAGSourceSummaries = (sources) => {
1247
1370
  chunkIds: group.chunks.map((chunk) => chunk.chunkId),
1248
1371
  contextLabel: leadChunk?.labels?.contextLabel ?? buildContextLabel2(leadChunk?.metadata),
1249
1372
  count: group.count,
1250
- excerpt: buildExcerpt2(leadChunk?.text ?? ""),
1373
+ excerpt: buildRAGPreferredExcerpt(excerpts, leadChunk?.structure ?? buildRAGChunkStructure(leadChunk?.metadata)) || buildExcerpt2(leadChunk?.text ?? ""),
1374
+ excerpts,
1251
1375
  key: group.key,
1252
1376
  label: group.label,
1253
1377
  locatorLabel: leadChunk?.labels?.locatorLabel ?? buildLocatorLabel2(leadChunk?.metadata, leadChunk?.source, leadChunk?.title),
@@ -2065,6 +2189,7 @@ export {
2065
2189
  buildRAGChunkPreviewGraph,
2066
2190
  buildRAGChunkGraphNavigation,
2067
2191
  buildRAGChunkGraph,
2192
+ buildRAGChunkExcerpts,
2068
2193
  buildRAGAnswerWorkflowState,
2069
2194
  buildRAGAnswerGroundingHistoryRows,
2070
2195
  buildRAGAnswerGroundingHistoryPresentation,
@@ -2075,5 +2200,5 @@ export {
2075
2200
  buildRAGAdminActionPresentation
2076
2201
  };
2077
2202
 
2078
- //# debugId=C09751511BFD6FA564756E2164756E21
2203
+ //# debugId=62489218E5536C5664756E2164756E21
2079
2204
  //# sourceMappingURL=ui.js.map