@absolutejs/absolute 0.19.0-beta.605 → 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.
Files changed (37) hide show
  1. package/dist/ai/client/index.js +112 -1
  2. package/dist/ai/client/index.js.map +4 -4
  3. package/dist/ai/client/ui.js +113 -1
  4. package/dist/ai/client/ui.js.map +4 -4
  5. package/dist/ai/index.js +153 -4
  6. package/dist/ai/index.js.map +6 -6
  7. package/dist/ai/rag/quality.js +60 -1
  8. package/dist/ai/rag/quality.js.map +3 -3
  9. package/dist/ai/rag/ui.js +113 -1
  10. package/dist/ai/rag/ui.js.map +4 -4
  11. package/dist/ai-client/angular/ai/index.js +111 -0
  12. package/dist/ai-client/react/ai/index.js +141 -7
  13. package/dist/ai-client/vue/ai/index.js +135 -1
  14. package/dist/angular/ai/index.js +112 -1
  15. package/dist/angular/ai/index.js.map +4 -4
  16. package/dist/react/ai/index.js +142 -8
  17. package/dist/react/ai/index.js.map +6 -6
  18. package/dist/src/ai/client/ui.d.ts +1 -1
  19. package/dist/src/ai/rag/grounding.d.ts +2 -1
  20. package/dist/src/ai/rag/index.d.ts +1 -1
  21. package/dist/src/ai/rag/presentation.d.ts +2 -2
  22. package/dist/src/ai/rag/ui.d.ts +1 -1
  23. package/dist/src/react/ai/useRAG.d.ts +4 -0
  24. package/dist/src/react/ai/useRAGChunkPreview.d.ts +3 -0
  25. package/dist/src/react/ai/useRAGSources.d.ts +1 -0
  26. package/dist/src/svelte/ai/createRAG.d.ts +4 -0
  27. package/dist/src/svelte/ai/createRAGChunkPreview.d.ts +3 -0
  28. package/dist/src/svelte/ai/createRAGSources.d.ts +1 -0
  29. package/dist/src/vue/ai/useRAG.d.ts +4 -0
  30. package/dist/src/vue/ai/useRAGChunkPreview.d.ts +3 -0
  31. package/dist/src/vue/ai/useRAGSources.d.ts +1 -0
  32. package/dist/svelte/ai/index.js +149 -3
  33. package/dist/svelte/ai/index.js.map +6 -6
  34. package/dist/types/ai.d.ts +20 -1
  35. package/dist/vue/ai/index.js +136 -2
  36. package/dist/vue/ai/index.js.map +6 -6
  37. package/package.json +1 -1
package/dist/ai/index.js CHANGED
@@ -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);
@@ -4204,11 +4263,13 @@ var buildRAGChunkGraph = (chunks) => {
4204
4263
  const existing = sections.get(sectionId);
4205
4264
  if (!existing) {
4206
4265
  sections.set(sectionId, {
4266
+ childSectionIds: [],
4207
4267
  chunkCount: structure.sequence?.sectionChunkCount ?? 1,
4208
4268
  chunkIds: [chunk.chunkId],
4209
4269
  depth: structure.section?.depth,
4210
4270
  id: sectionId,
4211
4271
  kind: structure.section?.kind,
4272
+ leadChunkId: chunk.chunkId,
4212
4273
  path: structure.section?.path,
4213
4274
  title: structure.section?.title
4214
4275
  });
@@ -4231,6 +4292,48 @@ var buildRAGChunkGraph = (chunks) => {
4231
4292
  }
4232
4293
  return left.localeCompare(right);
4233
4294
  });
4295
+ section.leadChunkId = section.chunkIds[0];
4296
+ }
4297
+ const sectionPathIndex = new Map;
4298
+ for (const section of sections.values()) {
4299
+ const path = section.path && section.path.length > 0 ? section.path : section.title ? [section.title] : undefined;
4300
+ if (path && path.length > 0) {
4301
+ sectionPathIndex.set(path.join("\x00"), section);
4302
+ }
4303
+ }
4304
+ for (const section of sections.values()) {
4305
+ const path = section.path && section.path.length > 0 ? section.path : section.title ? [section.title] : undefined;
4306
+ if (!path || path.length < 2) {
4307
+ continue;
4308
+ }
4309
+ const parent = sectionPathIndex.get(path.slice(0, -1).join("\x00"));
4310
+ if (!parent || parent.id === section.id) {
4311
+ continue;
4312
+ }
4313
+ section.parentSectionId = parent.id;
4314
+ if (!parent.childSectionIds.includes(section.id)) {
4315
+ parent.childSectionIds.push(section.id);
4316
+ }
4317
+ if (parent.leadChunkId && section.leadChunkId) {
4318
+ const parentKey = `section_parent:${section.leadChunkId}:${parent.leadChunkId}`;
4319
+ if (!edgeKeys.has(parentKey)) {
4320
+ edgeKeys.add(parentKey);
4321
+ edges.push({
4322
+ fromChunkId: section.leadChunkId,
4323
+ relation: "section_parent",
4324
+ toChunkId: parent.leadChunkId
4325
+ });
4326
+ }
4327
+ const childKey = `section_child:${parent.leadChunkId}:${section.leadChunkId}`;
4328
+ if (!edgeKeys.has(childKey)) {
4329
+ edgeKeys.add(childKey);
4330
+ edges.push({
4331
+ fromChunkId: parent.leadChunkId,
4332
+ relation: "section_child",
4333
+ toChunkId: section.leadChunkId
4334
+ });
4335
+ }
4336
+ }
4234
4337
  }
4235
4338
  nodes.sort((left, right) => {
4236
4339
  const leftSection = left.structure?.sequence?.sectionChunkIndex ?? Number.MAX_SAFE_INTEGER;
@@ -4264,6 +4367,8 @@ var buildRAGChunkGraphNavigation = (graph, activeChunkId) => {
4264
4367
  if (graph.nodes.length === 0) {
4265
4368
  return {
4266
4369
  activeChunkId,
4370
+ childSections: [],
4371
+ siblingSections: [],
4267
4372
  sectionNodes: []
4268
4373
  };
4269
4374
  }
@@ -4272,13 +4377,19 @@ var buildRAGChunkGraphNavigation = (graph, activeChunkId) => {
4272
4377
  const previousNode = activeNode?.structure?.sequence?.previousChunkId ? graph.nodes.find((node) => node.chunkId === activeNode.structure?.sequence?.previousChunkId) : undefined;
4273
4378
  const nextNode = activeNode?.structure?.sequence?.nextChunkId ? graph.nodes.find((node) => node.chunkId === activeNode.structure?.sequence?.nextChunkId) : undefined;
4274
4379
  const section = activeNode?.structure?.sequence?.sectionChunkId ? graph.sections.find((entry) => entry.id === activeNode.structure?.sequence?.sectionChunkId) : undefined;
4380
+ const parentSection = section?.parentSectionId ? graph.sections.find((entry) => entry.id === section.parentSectionId) : undefined;
4381
+ const childSections = section ? section.childSectionIds.map((sectionId) => graph.sections.find((entry) => entry.id === sectionId)).filter((entry) => Boolean(entry)) : [];
4382
+ const siblingSections = section?.parentSectionId ? graph.sections.filter((entry) => entry.parentSectionId === section.parentSectionId && entry.id !== section.id) : [];
4275
4383
  const sectionNodes = section ? section.chunkIds.map((chunkId) => graph.nodes.find((node) => node.chunkId === chunkId)).filter((node) => Boolean(node)) : activeNode ? [activeNode] : [];
4276
4384
  return {
4277
4385
  activeChunkId: resolvedActiveChunkId,
4278
4386
  activeNode,
4387
+ childSections,
4279
4388
  nextNode,
4389
+ parentSection,
4280
4390
  previousNode,
4281
4391
  section,
4392
+ siblingSections,
4282
4393
  sectionNodes
4283
4394
  };
4284
4395
  };
@@ -10200,6 +10311,10 @@ var renderChunkStructure = (structure) => {
10200
10311
  ].filter((row) => row.length > 0);
10201
10312
  return rows.length > 0 ? `<ul class="rag-chunk-structure">${rows.join("")}</ul>` : "";
10202
10313
  };
10314
+ var renderSectionJumpList = (label, items) => {
10315
+ const rows = items.map((item) => item.href ? `<li><strong>${escapeHtml2(label)}</strong> <a href="${escapeHtml2(item.href)}"${item.active ? ' aria-current="true"' : ""}>${escapeHtml2(item.label)}</a></li>` : `<li><strong>${escapeHtml2(label)}</strong> ${escapeHtml2(item.label)}</li>`).join("");
10316
+ return rows ? `<ul class="rag-chunk-structure">${rows}</ul>` : "";
10317
+ };
10203
10318
  var renderEmptyState = (kind) => {
10204
10319
  switch (kind) {
10205
10320
  case "documents":
@@ -10239,17 +10354,43 @@ var defaultStatus = ({
10239
10354
  }
10240
10355
  return `<dl class="rag-status">` + `<div><dt>Backend</dt><dd>${escapeHtml2(status.backend)}</dd></div>` + `<div><dt>Vector mode</dt><dd>${escapeHtml2(status.vectorMode)}</dd></div>` + `<div><dt>Embedding dimensions</dt><dd>${status.dimensions ?? "n/a"}</dd></div>` + `<div><dt>Vector acceleration</dt><dd>${status.native?.active ? "active" : "inactive"}</dd></div>` + `<div><dt>Documents</dt><dd>${documents?.total ?? "n/a"}</dd></div>` + `<div><dt>Total chunks</dt><dd>${documents?.chunkCount ?? "n/a"}</dd></div>` + `<div><dt>Seed docs</dt><dd>${documents?.byKind.seed ?? 0}</dd></div>` + `<div><dt>Custom docs</dt><dd>${documents?.byKind.custom ?? 0}</dd></div>` + `</dl>${renderCapabilityList(capabilities)}`;
10241
10356
  };
10242
- var defaultSearchResultItem = (source, index) => '<article class="rag-search-result">' + `<h3>${escapeHtml2(source.title ?? source.chunkId ?? `Result ${index + 1}`)}</h3>` + `<p class="rag-search-source">${escapeHtml2(source.source ?? "unknown source")}</p>` + renderSourceLabels(source.labels) + renderChunkStructure(source.structure) + `<p class="rag-search-score">score ${source.score.toFixed(RAG_SEARCH_SCORE_DECIMAL_PLACES)}</p>` + `<p class="rag-search-text">${escapeHtml2(source.text)}</p>` + "</article>";
10357
+ var defaultSearchResultItem = (source, index, sectionJumps = "") => `<article class="rag-search-result" id="rag-search-result-${escapeHtml2(source.chunkId)}">` + `<h3>${escapeHtml2(source.title ?? source.chunkId ?? `Result ${index + 1}`)}</h3>` + `<p class="rag-search-source">${escapeHtml2(source.source ?? "unknown source")}</p>` + renderSourceLabels(source.labels) + renderChunkStructure(source.structure) + sectionJumps + `<p class="rag-search-score">score ${source.score.toFixed(RAG_SEARCH_SCORE_DECIMAL_PLACES)}</p>` + `<p class="rag-search-text">${escapeHtml2(source.text)}</p>` + "</article>";
10243
10358
  var defaultSearchResults = ({
10244
10359
  query,
10245
10360
  results,
10246
10361
  trace
10247
- }) => results.length === 0 ? renderEmptyState("searchResults") : `<section class="rag-search-results">` + `<p class="rag-search-summary">${results.length} results for ${escapeHtml2(query)}</p>` + (trace ? `<p class="rag-search-summary">mode=${escapeHtml2(trace.mode)} \xB7 final=${trace.resultCounts.final} \xB7 vector=${trace.resultCounts.vector} \xB7 lexical=${trace.resultCounts.lexical}</p>` : "") + `${results.map((result, index) => defaultSearchResultItem(result, index)).join("")}</section>`;
10362
+ }) => results.length === 0 ? renderEmptyState("searchResults") : (() => {
10363
+ const graph = buildRAGChunkGraph(results);
10364
+ const availableChunkIds = new Set(results.map((result) => result.chunkId));
10365
+ return `<section class="rag-search-results">` + `<p class="rag-search-summary">${results.length} results for ${escapeHtml2(query)}</p>` + (trace ? `<p class="rag-search-summary">mode=${escapeHtml2(trace.mode)} \xB7 final=${trace.resultCounts.final} \xB7 vector=${trace.resultCounts.vector} \xB7 lexical=${trace.resultCounts.lexical}</p>` : "") + `${results.map((result, index) => {
10366
+ const navigation = buildRAGChunkGraphNavigation(graph, result.chunkId);
10367
+ const sectionJumps = [
10368
+ navigation.parentSection?.leadChunkId ? renderSectionJumpList("Parent section", [
10369
+ {
10370
+ href: availableChunkIds.has(navigation.parentSection.leadChunkId) ? `#rag-search-result-${navigation.parentSection.leadChunkId}` : undefined,
10371
+ label: navigation.parentSection.title ?? navigation.parentSection.path?.join(" > ") ?? navigation.parentSection.id
10372
+ }
10373
+ ]) : "",
10374
+ navigation.siblingSections.length > 0 ? renderSectionJumpList("Sibling section", navigation.siblingSections.map((section) => ({
10375
+ active: section.id === navigation.section?.id,
10376
+ href: section.leadChunkId && availableChunkIds.has(section.leadChunkId) ? `#rag-search-result-${section.leadChunkId}` : undefined,
10377
+ label: section.title ?? section.path?.join(" > ") ?? section.id
10378
+ }))) : "",
10379
+ navigation.childSections.length > 0 ? renderSectionJumpList("Child section", navigation.childSections.map((section) => ({
10380
+ href: section.leadChunkId && availableChunkIds.has(section.leadChunkId) ? `#rag-search-result-${section.leadChunkId}` : undefined,
10381
+ label: section.title ?? section.path?.join(" > ") ?? section.id
10382
+ }))) : ""
10383
+ ].join("");
10384
+ return defaultSearchResultItem(result, index, sectionJumps);
10385
+ }).join("")}</section>`;
10386
+ })();
10248
10387
  var defaultDocumentItem = (document, index) => '<article class="rag-document">' + `<h3>${escapeHtml2(document.title || `Document ${index + 1}`)}</h3>` + `<p class="rag-document-id">${escapeHtml2(document.id)}</p>` + `<p class="rag-document-source">${escapeHtml2(document.source)}</p>` + renderSourceLabels(document.labels) + `<p class="rag-document-meta">${escapeHtml2(document.format ?? "text")} \xB7 ${escapeHtml2(document.chunkStrategy ?? "paragraphs")} \xB7 ${document.chunkCount ?? 0} chunks</p>` + "</article>";
10249
10388
  var defaultDocuments = ({
10250
10389
  documents
10251
10390
  }) => documents.length === 0 ? renderEmptyState("documents") : `<section class="rag-documents">${documents.map((document, index) => defaultDocumentItem(document, index)).join("")}</section>`;
10252
10391
  var defaultChunkPreview = (input) => {
10392
+ const graph = buildRAGChunkPreviewGraph(input);
10393
+ const navigation = buildRAGChunkGraphNavigation(graph);
10253
10394
  const groups = input.chunks.reduce((acc, chunk) => {
10254
10395
  const metadata = chunk.metadata ?? {};
10255
10396
  const kind = typeof metadata.sourceNativeKind === "string" ? metadata.sourceNativeKind : "document_chunk";
@@ -10272,7 +10413,15 @@ var defaultChunkPreview = (input) => {
10272
10413
  const chunkHtml = group.chunks.map((chunk) => '<article class="rag-chunk">' + `<h5>${escapeHtml2(chunk.chunkId)}</h5>` + `<p class="rag-chunk-meta">chunk ${typeof chunk.metadata?.chunkIndex === "number" ? chunk.metadata.chunkIndex : 0} of ${typeof chunk.metadata?.chunkCount === "number" ? chunk.metadata.chunkCount : input.chunks.length}</p>` + renderSourceLabels(chunk.labels) + renderChunkStructure(chunk.structure) + `<pre>${escapeHtml2(chunk.text)}</pre>` + "</article>").join("");
10273
10414
  return `<section class="rag-chunk-group"><h4>${escapeHtml2(group.title)}</h4>${chunkHtml}</section>`;
10274
10415
  }).join("");
10275
- return `<section class="rag-chunk-preview">` + `<h3>${escapeHtml2(input.document.title)}</h3>` + `<p class="rag-chunk-preview-source">${escapeHtml2(input.document.source)}</p>` + renderSourceLabels(input.document.labels) + `<article class="rag-chunk-normalized">` + `<h4>Normalized text</h4>` + `<pre>${escapeHtml2(input.normalizedText)}</pre>` + `</article>${groupHtml}</section>`;
10416
+ return `<section class="rag-chunk-preview">` + `<h3>${escapeHtml2(input.document.title)}</h3>` + `<p class="rag-chunk-preview-source">${escapeHtml2(input.document.source)}</p>` + renderSourceLabels(input.document.labels) + (navigation.parentSection ? renderSectionJumpList("Parent section", [
10417
+ {
10418
+ label: navigation.parentSection.title ?? navigation.parentSection.path?.join(" > ") ?? navigation.parentSection.id
10419
+ }
10420
+ ]) : "") + (navigation.siblingSections.length > 0 ? renderSectionJumpList("Sibling section", navigation.siblingSections.map((section) => ({
10421
+ label: section.title ?? section.path?.join(" > ") ?? section.id
10422
+ }))) : "") + (navigation.childSections.length > 0 ? renderSectionJumpList("Child section", navigation.childSections.map((section) => ({
10423
+ label: section.title ?? section.path?.join(" > ") ?? section.id
10424
+ }))) : "") + `<article class="rag-chunk-normalized">` + `<h4>Normalized text</h4>` + `<pre>${escapeHtml2(input.normalizedText)}</pre>` + `</article>${groupHtml}</section>`;
10276
10425
  };
10277
10426
  var defaultMutationResult = (input) => {
10278
10427
  if (!input.ok) {
@@ -21450,5 +21599,5 @@ export {
21450
21599
  aiChat
21451
21600
  };
21452
21601
 
21453
- //# debugId=DE5EC1314BD5A9F664756E2164756E21
21602
+ //# debugId=D67670282225BF1964756E2164756E21
21454
21603
  //# sourceMappingURL=index.js.map