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

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.
@@ -354,6 +354,13 @@ var buildGroundingReferenceEvidenceSummary = (reference) => [
354
354
  reference.contextLabel,
355
355
  reference.provenanceLabel
356
356
  ].filter((value) => Boolean(value && value.length > 0)).filter((value, index, values) => values.findIndex((entry) => entry === value) === index).join(" \xB7 ");
357
+ var buildGroundingSectionKey = (reference) => reference.contextLabel ?? reference.locatorLabel ?? reference.label ?? reference.source ?? reference.chunkId;
358
+ var buildGroundingSectionSummaryLine = (reference) => [
359
+ reference.source ?? reference.title ?? reference.chunkId,
360
+ reference.locatorLabel,
361
+ reference.contextLabel,
362
+ reference.provenanceLabel
363
+ ].filter((value) => Boolean(value && value.length > 0)).filter((value, index, values) => values.findIndex((entry) => entry === value) === index).join(" \xB7 ");
357
364
  var buildGroundedAnswerCitationDetail = (reference) => ({
358
365
  contextLabel: reference.contextLabel,
359
366
  evidenceLabel: buildGroundingReferenceEvidenceLabel(reference),
@@ -444,9 +451,61 @@ var buildRAGGroundedAnswer = (content, sources) => {
444
451
  hasCitations,
445
452
  parts,
446
453
  references,
454
+ sectionSummaries: buildRAGGroundedAnswerSectionSummaries(references),
447
455
  ungroundedReferenceNumbers: [...ungroundedReferenceNumbers].sort((left, right) => left - right)
448
456
  };
449
457
  };
458
+ var buildRAGGroundedAnswerSectionSummaries = (references) => {
459
+ const groups = new Map;
460
+ for (const reference of references) {
461
+ const key = buildGroundingSectionKey(reference);
462
+ const existing = groups.get(key);
463
+ if (!existing) {
464
+ groups.set(key, {
465
+ chunkIds: [reference.chunkId],
466
+ contextLabel: reference.contextLabel,
467
+ count: 1,
468
+ key,
469
+ label: key,
470
+ locatorLabel: reference.locatorLabel,
471
+ provenanceLabel: reference.provenanceLabel,
472
+ referenceNumbers: [reference.number],
473
+ references: [reference],
474
+ summary: buildGroundingSectionSummaryLine(reference) || reference.label || reference.chunkId
475
+ });
476
+ continue;
477
+ }
478
+ existing.count += 1;
479
+ if (!existing.chunkIds.includes(reference.chunkId)) {
480
+ existing.chunkIds.push(reference.chunkId);
481
+ }
482
+ if (!existing.referenceNumbers.includes(reference.number)) {
483
+ existing.referenceNumbers.push(reference.number);
484
+ }
485
+ existing.references.push(reference);
486
+ if (!existing.contextLabel && reference.contextLabel) {
487
+ existing.contextLabel = reference.contextLabel;
488
+ }
489
+ if (!existing.locatorLabel && reference.locatorLabel) {
490
+ existing.locatorLabel = reference.locatorLabel;
491
+ }
492
+ if (!existing.provenanceLabel && reference.provenanceLabel) {
493
+ existing.provenanceLabel = reference.provenanceLabel;
494
+ }
495
+ }
496
+ return [...groups.values()].map((group) => ({
497
+ ...group,
498
+ referenceNumbers: [...group.referenceNumbers].sort((left, right) => left - right),
499
+ references: group.references.slice().sort((left, right) => left.number - right.number)
500
+ })).sort((left, right) => {
501
+ const leftFirst = left.referenceNumbers[0] ?? Number.POSITIVE_INFINITY;
502
+ const rightFirst = right.referenceNumbers[0] ?? Number.POSITIVE_INFINITY;
503
+ if (leftFirst !== rightFirst) {
504
+ return leftFirst - rightFirst;
505
+ }
506
+ return left.label.localeCompare(right.label);
507
+ });
508
+ };
450
509
  var buildRAGGroundingReferences = (sources) => {
451
510
  const citations = buildRAGCitations(sources);
452
511
  const citationReferenceMap = buildRAGCitationReferenceMap(citations);
@@ -7866,5 +7925,5 @@ export {
7866
7925
  AIStreamProvider
7867
7926
  };
7868
7927
 
7869
- //# debugId=97115FA6E1742FB464756E2164756E21
7928
+ //# debugId=D69799996BCD92A364756E2164756E21
7870
7929
  //# sourceMappingURL=index.js.map