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

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 (45) hide show
  1. package/dist/ai/client/index.js +238 -6
  2. package/dist/ai/client/index.js.map +4 -4
  3. package/dist/ai/client/ui.js +242 -6
  4. package/dist/ai/client/ui.js.map +4 -4
  5. package/dist/ai/index.js +381 -38
  6. package/dist/ai/index.js.map +7 -7
  7. package/dist/ai/rag/quality.js +17 -6
  8. package/dist/ai/rag/quality.js.map +3 -3
  9. package/dist/ai/rag/ui.js +242 -6
  10. package/dist/ai/rag/ui.js.map +4 -4
  11. package/dist/ai-client/angular/ai/index.js +237 -5
  12. package/dist/ai-client/react/ai/index.js +281 -12
  13. package/dist/ai-client/vue/ai/index.js +364 -97
  14. package/dist/angular/ai/index.js +238 -6
  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 +282 -13
  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 +7 -1
  29. package/dist/src/ai/rag/ui.d.ts +1 -1
  30. package/dist/src/react/ai/useRAG.d.ts +9 -0
  31. package/dist/src/react/ai/useRAGChunkPreview.d.ts +7 -0
  32. package/dist/src/react/ai/useRAGSources.d.ts +2 -0
  33. package/dist/src/svelte/ai/createRAG.d.ts +9 -0
  34. package/dist/src/svelte/ai/createRAGChunkPreview.d.ts +7 -0
  35. package/dist/src/svelte/ai/createRAGSources.d.ts +2 -0
  36. package/dist/src/vue/ai/useRAG.d.ts +69 -0
  37. package/dist/src/vue/ai/useRAGChunkPreview.d.ts +37 -0
  38. package/dist/src/vue/ai/useRAGSearch.d.ts +30 -0
  39. package/dist/src/vue/ai/useRAGSources.d.ts +2 -0
  40. package/dist/svelte/ai/index.js +334 -53
  41. package/dist/svelte/ai/index.js.map +6 -6
  42. package/dist/types/ai.d.ts +66 -0
  43. package/dist/vue/ai/index.js +328 -59
  44. package/dist/vue/ai/index.js.map +6 -6
  45. package/package.json +1 -1
@@ -243,6 +243,11 @@ var buildContextLabel = (metadata) => {
243
243
  if (speaker) {
244
244
  return `Speaker ${speaker}`;
245
245
  }
246
+ const sectionPath = Array.isArray(metadata.sectionPath) ? metadata.sectionPath.map((value) => getContextString(value)).filter((value) => typeof value === "string") : [];
247
+ const sectionTitle = getContextString(metadata.sectionTitle) ?? sectionPath.at(-1);
248
+ if (sectionTitle) {
249
+ return `Section ${sectionTitle}`;
250
+ }
246
251
  return;
247
252
  };
248
253
  var formatMediaTimestamp = (value) => {
@@ -292,6 +297,10 @@ var buildLocatorLabel = (metadata, source, title) => {
292
297
  if (mediaStart) {
293
298
  return `Timestamp ${mediaStart}`;
294
299
  }
300
+ const sectionPath = Array.isArray(metadata.sectionPath) ? metadata.sectionPath.map((value) => getContextString(value)).filter((value) => typeof value === "string") : [];
301
+ if (sectionPath.length > 0) {
302
+ return `Section ${sectionPath.join(" > ")}`;
303
+ }
295
304
  return;
296
305
  };
297
306
  var formatTimestampLabel = (value) => {
@@ -341,8 +350,10 @@ var buildExcerpt = (text, maxLength = 160) => {
341
350
  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 ");
342
351
  var buildGroundingReferenceEvidenceSummary = (reference) => [
343
352
  reference.source ?? reference.title ?? reference.chunkId,
353
+ reference.locatorLabel,
354
+ reference.contextLabel,
344
355
  reference.provenanceLabel
345
- ].filter((value) => Boolean(value && value.length > 0)).join(" \xB7 ");
356
+ ].filter((value) => Boolean(value && value.length > 0)).filter((value, index, values) => values.findIndex((entry) => entry === value) === index).join(" \xB7 ");
346
357
  var buildGroundedAnswerCitationDetail = (reference) => ({
347
358
  contextLabel: reference.contextLabel,
348
359
  evidenceLabel: buildGroundingReferenceEvidenceLabel(reference),
@@ -366,12 +377,12 @@ var buildRAGCitations = (sources) => {
366
377
  continue;
367
378
  unique.set(key, {
368
379
  chunkId: source.chunkId,
369
- contextLabel: buildContextLabel(source.metadata),
380
+ contextLabel: source.labels?.contextLabel ?? buildContextLabel(source.metadata),
370
381
  key,
371
382
  label: buildSourceLabel(source),
372
- locatorLabel: buildLocatorLabel(source.metadata, source.source, source.title),
383
+ locatorLabel: source.labels?.locatorLabel ?? buildLocatorLabel(source.metadata, source.source, source.title),
373
384
  metadata: source.metadata,
374
- provenanceLabel: buildProvenanceLabel(source.metadata),
385
+ provenanceLabel: source.labels?.provenanceLabel ?? buildProvenanceLabel(source.metadata),
375
386
  score: source.score,
376
387
  source: source.source,
377
388
  text: source.text,
@@ -441,7 +452,7 @@ var buildRAGGroundingReferences = (sources) => {
441
452
  const citationReferenceMap = buildRAGCitationReferenceMap(citations);
442
453
  return citations.map((citation) => ({
443
454
  chunkId: citation.chunkId,
444
- contextLabel: buildContextLabel(citation.metadata),
455
+ contextLabel: citation.contextLabel ?? buildContextLabel(citation.metadata),
445
456
  excerpt: buildExcerpt(citation.text),
446
457
  label: citation.label,
447
458
  locatorLabel: citation.locatorLabel ?? buildLocatorLabel(citation.metadata, citation.source, citation.title),
@@ -4611,6 +4622,11 @@ var buildContextLabel2 = (metadata) => {
4611
4622
  if (speaker) {
4612
4623
  return `Speaker ${speaker}`;
4613
4624
  }
4625
+ const sectionPath = Array.isArray(metadata.sectionPath) ? metadata.sectionPath.map((value) => getContextString2(value)).filter((value) => typeof value === "string") : [];
4626
+ const sectionTitle = getContextString2(metadata.sectionTitle) ?? sectionPath.at(-1);
4627
+ if (sectionTitle) {
4628
+ return `Section ${sectionTitle}`;
4629
+ }
4614
4630
  return;
4615
4631
  };
4616
4632
  var buildLocatorLabel2 = (metadata, source, title) => {
@@ -4650,6 +4666,10 @@ var buildLocatorLabel2 = (metadata, source, title) => {
4650
4666
  if (mediaStart) {
4651
4667
  return `Timestamp ${mediaStart}`;
4652
4668
  }
4669
+ const sectionPath = Array.isArray(metadata.sectionPath) ? metadata.sectionPath.map((value) => getContextString2(value)).filter((value) => typeof value === "string") : [];
4670
+ if (sectionPath.length > 0) {
4671
+ return `Section ${sectionPath.join(" > ")}`;
4672
+ }
4653
4673
  return;
4654
4674
  };
4655
4675
  var buildProvenanceLabel2 = (metadata) => {
@@ -4695,6 +4715,33 @@ var buildRAGSourceLabels = ({
4695
4715
  provenanceLabel
4696
4716
  };
4697
4717
  };
4718
+ var buildRAGChunkStructure = (metadata) => {
4719
+ if (!metadata) {
4720
+ return;
4721
+ }
4722
+ const sectionPath = Array.isArray(metadata.sectionPath) ? metadata.sectionPath.filter((value) => typeof value === "string" && value.trim().length > 0) : undefined;
4723
+ const sectionKind = metadata.sectionKind === "markdown_heading" || metadata.sectionKind === "html_heading" ? metadata.sectionKind : undefined;
4724
+ const section = {
4725
+ depth: getContextNumber2(metadata.sectionDepth),
4726
+ kind: sectionKind,
4727
+ path: sectionPath && sectionPath.length > 0 ? sectionPath : undefined,
4728
+ title: getContextString2(metadata.sectionTitle)
4729
+ };
4730
+ const sequence = {
4731
+ nextChunkId: getContextString2(metadata.nextChunkId),
4732
+ previousChunkId: getContextString2(metadata.previousChunkId),
4733
+ sectionChunkCount: getContextNumber2(metadata.sectionChunkCount),
4734
+ sectionChunkId: getContextString2(metadata.sectionChunkId),
4735
+ sectionChunkIndex: getContextNumber2(metadata.sectionChunkIndex)
4736
+ };
4737
+ if (!section.title && (!section.path || section.path.length === 0) && typeof section.depth !== "number" && !section.kind && !sequence.nextChunkId && !sequence.previousChunkId && typeof sequence.sectionChunkCount !== "number" && !sequence.sectionChunkId && typeof sequence.sectionChunkIndex !== "number") {
4738
+ return;
4739
+ }
4740
+ return {
4741
+ section: section.title || section.path && section.path.length > 0 || typeof section.depth === "number" || section.kind ? section : undefined,
4742
+ sequence: sequence.nextChunkId || sequence.previousChunkId || typeof sequence.sectionChunkCount === "number" || sequence.sectionChunkId || typeof sequence.sectionChunkIndex === "number" ? sequence : undefined
4743
+ };
4744
+ };
4698
4745
  var buildExcerpt2 = (text, maxLength = 160) => {
4699
4746
  const normalized = text.replaceAll(/\s+/g, " ").trim();
4700
4747
  if (normalized.length <= maxLength) {
@@ -4702,6 +4749,188 @@ var buildExcerpt2 = (text, maxLength = 160) => {
4702
4749
  }
4703
4750
  return `${normalized.slice(0, Math.max(0, maxLength - 1)).trimEnd()}\u2026`;
4704
4751
  };
4752
+ var buildRAGChunkGraph = (chunks) => {
4753
+ const nodes = [];
4754
+ const edges = [];
4755
+ const edgeKeys = new Set;
4756
+ const sections = new Map;
4757
+ for (const chunk of chunks) {
4758
+ const labels = chunk.labels ?? buildRAGSourceLabels({
4759
+ metadata: chunk.metadata,
4760
+ source: chunk.source,
4761
+ title: chunk.title
4762
+ });
4763
+ const structure = chunk.structure ?? buildRAGChunkStructure(chunk.metadata);
4764
+ nodes.push({
4765
+ chunkId: chunk.chunkId,
4766
+ contextLabel: labels?.contextLabel,
4767
+ label: chunk.source ?? chunk.title ?? chunk.chunkId,
4768
+ locatorLabel: labels?.locatorLabel,
4769
+ provenanceLabel: labels?.provenanceLabel,
4770
+ score: chunk.score,
4771
+ source: chunk.source,
4772
+ structure,
4773
+ title: chunk.title
4774
+ });
4775
+ const previousChunkId = structure?.sequence?.previousChunkId;
4776
+ if (previousChunkId) {
4777
+ const key = `previous:${previousChunkId}:${chunk.chunkId}`;
4778
+ if (!edgeKeys.has(key)) {
4779
+ edgeKeys.add(key);
4780
+ edges.push({
4781
+ fromChunkId: previousChunkId,
4782
+ relation: "previous",
4783
+ toChunkId: chunk.chunkId
4784
+ });
4785
+ }
4786
+ }
4787
+ const nextChunkId = structure?.sequence?.nextChunkId;
4788
+ if (nextChunkId) {
4789
+ const key = `next:${chunk.chunkId}:${nextChunkId}`;
4790
+ if (!edgeKeys.has(key)) {
4791
+ edgeKeys.add(key);
4792
+ edges.push({
4793
+ fromChunkId: chunk.chunkId,
4794
+ relation: "next",
4795
+ toChunkId: nextChunkId
4796
+ });
4797
+ }
4798
+ }
4799
+ const sectionId = structure?.sequence?.sectionChunkId;
4800
+ if (sectionId) {
4801
+ const existing = sections.get(sectionId);
4802
+ if (!existing) {
4803
+ sections.set(sectionId, {
4804
+ childSectionIds: [],
4805
+ chunkCount: structure.sequence?.sectionChunkCount ?? 1,
4806
+ chunkIds: [chunk.chunkId],
4807
+ depth: structure.section?.depth,
4808
+ id: sectionId,
4809
+ kind: structure.section?.kind,
4810
+ leadChunkId: chunk.chunkId,
4811
+ path: structure.section?.path,
4812
+ title: structure.section?.title
4813
+ });
4814
+ continue;
4815
+ }
4816
+ if (!existing.chunkIds.includes(chunk.chunkId)) {
4817
+ existing.chunkIds.push(chunk.chunkId);
4818
+ }
4819
+ existing.chunkCount = Math.max(existing.chunkCount, structure.sequence?.sectionChunkCount ?? existing.chunkCount);
4820
+ }
4821
+ }
4822
+ for (const section of sections.values()) {
4823
+ section.chunkIds.sort((left, right) => {
4824
+ const leftNode = nodes.find((node) => node.chunkId === left);
4825
+ const rightNode = nodes.find((node) => node.chunkId === right);
4826
+ const leftIndex = leftNode?.structure?.sequence?.sectionChunkIndex ?? Number.MAX_SAFE_INTEGER;
4827
+ const rightIndex = rightNode?.structure?.sequence?.sectionChunkIndex ?? Number.MAX_SAFE_INTEGER;
4828
+ if (leftIndex !== rightIndex) {
4829
+ return leftIndex - rightIndex;
4830
+ }
4831
+ return left.localeCompare(right);
4832
+ });
4833
+ section.leadChunkId = section.chunkIds[0];
4834
+ }
4835
+ const sectionPathIndex = new Map;
4836
+ for (const section of sections.values()) {
4837
+ const path = section.path && section.path.length > 0 ? section.path : section.title ? [section.title] : undefined;
4838
+ if (path && path.length > 0) {
4839
+ sectionPathIndex.set(path.join("\x00"), section);
4840
+ }
4841
+ }
4842
+ for (const section of sections.values()) {
4843
+ const path = section.path && section.path.length > 0 ? section.path : section.title ? [section.title] : undefined;
4844
+ if (!path || path.length < 2) {
4845
+ continue;
4846
+ }
4847
+ const parent = sectionPathIndex.get(path.slice(0, -1).join("\x00"));
4848
+ if (!parent || parent.id === section.id) {
4849
+ continue;
4850
+ }
4851
+ section.parentSectionId = parent.id;
4852
+ if (!parent.childSectionIds.includes(section.id)) {
4853
+ parent.childSectionIds.push(section.id);
4854
+ }
4855
+ if (parent.leadChunkId && section.leadChunkId) {
4856
+ const parentKey = `section_parent:${section.leadChunkId}:${parent.leadChunkId}`;
4857
+ if (!edgeKeys.has(parentKey)) {
4858
+ edgeKeys.add(parentKey);
4859
+ edges.push({
4860
+ fromChunkId: section.leadChunkId,
4861
+ relation: "section_parent",
4862
+ toChunkId: parent.leadChunkId
4863
+ });
4864
+ }
4865
+ const childKey = `section_child:${parent.leadChunkId}:${section.leadChunkId}`;
4866
+ if (!edgeKeys.has(childKey)) {
4867
+ edgeKeys.add(childKey);
4868
+ edges.push({
4869
+ fromChunkId: parent.leadChunkId,
4870
+ relation: "section_child",
4871
+ toChunkId: section.leadChunkId
4872
+ });
4873
+ }
4874
+ }
4875
+ }
4876
+ nodes.sort((left, right) => {
4877
+ const leftSection = left.structure?.sequence?.sectionChunkIndex ?? Number.MAX_SAFE_INTEGER;
4878
+ const rightSection = right.structure?.sequence?.sectionChunkIndex ?? Number.MAX_SAFE_INTEGER;
4879
+ if (leftSection !== rightSection) {
4880
+ return leftSection - rightSection;
4881
+ }
4882
+ const leftScore = left.score ?? Number.NEGATIVE_INFINITY;
4883
+ const rightScore = right.score ?? Number.NEGATIVE_INFINITY;
4884
+ if (leftScore !== rightScore) {
4885
+ return rightScore - leftScore;
4886
+ }
4887
+ return left.label.localeCompare(right.label);
4888
+ });
4889
+ return {
4890
+ edges,
4891
+ nodes,
4892
+ sections: [...sections.values()].sort((left, right) => (left.title ?? left.id).localeCompare(right.title ?? right.id))
4893
+ };
4894
+ };
4895
+ var buildRAGChunkPreviewGraph = (preview) => buildRAGChunkGraph(preview.chunks.map((chunk) => ({
4896
+ chunkId: chunk.chunkId,
4897
+ labels: chunk.labels,
4898
+ metadata: chunk.metadata,
4899
+ source: chunk.source ?? preview.document.source,
4900
+ structure: chunk.structure,
4901
+ title: chunk.title ?? preview.document.title
4902
+ })));
4903
+ var buildRAGChunkPreviewNavigation = (preview, activeChunkId) => buildRAGChunkGraphNavigation(buildRAGChunkPreviewGraph(preview), activeChunkId);
4904
+ var buildRAGChunkGraphNavigation = (graph, activeChunkId) => {
4905
+ if (graph.nodes.length === 0) {
4906
+ return {
4907
+ activeChunkId,
4908
+ childSections: [],
4909
+ siblingSections: [],
4910
+ sectionNodes: []
4911
+ };
4912
+ }
4913
+ const activeNode = (activeChunkId ? graph.nodes.find((node) => node.chunkId === activeChunkId) : undefined) ?? graph.nodes[0];
4914
+ const resolvedActiveChunkId = activeNode?.chunkId;
4915
+ const previousNode = activeNode?.structure?.sequence?.previousChunkId ? graph.nodes.find((node) => node.chunkId === activeNode.structure?.sequence?.previousChunkId) : undefined;
4916
+ const nextNode = activeNode?.structure?.sequence?.nextChunkId ? graph.nodes.find((node) => node.chunkId === activeNode.structure?.sequence?.nextChunkId) : undefined;
4917
+ const section = activeNode?.structure?.sequence?.sectionChunkId ? graph.sections.find((entry) => entry.id === activeNode.structure?.sequence?.sectionChunkId) : undefined;
4918
+ const parentSection = section?.parentSectionId ? graph.sections.find((entry) => entry.id === section.parentSectionId) : undefined;
4919
+ const childSections = section ? section.childSectionIds.map((sectionId) => graph.sections.find((entry) => entry.id === sectionId)).filter((entry) => Boolean(entry)) : [];
4920
+ const siblingSections = section?.parentSectionId ? graph.sections.filter((entry) => entry.parentSectionId === section.parentSectionId && entry.id !== section.id) : [];
4921
+ const sectionNodes = section ? section.chunkIds.map((chunkId) => graph.nodes.find((node) => node.chunkId === chunkId)).filter((node) => Boolean(node)) : activeNode ? [activeNode] : [];
4922
+ return {
4923
+ activeChunkId: resolvedActiveChunkId,
4924
+ activeNode,
4925
+ childSections,
4926
+ nextNode,
4927
+ parentSection,
4928
+ previousNode,
4929
+ section,
4930
+ siblingSections,
4931
+ sectionNodes
4932
+ };
4933
+ };
4705
4934
  var buildRAGRetrievedState = (messages) => {
4706
4935
  const message = getLatestRetrievedMessage(messages);
4707
4936
  if (!message) {
@@ -4743,6 +4972,7 @@ var buildRAGSourceSummaries = (sources) => {
4743
4972
  label: group.label,
4744
4973
  locatorLabel: leadChunk?.labels?.locatorLabel ?? buildLocatorLabel2(leadChunk?.metadata, leadChunk?.source, leadChunk?.title),
4745
4974
  provenanceLabel: leadChunk?.labels?.provenanceLabel ?? buildProvenanceLabel2(leadChunk?.metadata),
4975
+ structure: leadChunk?.structure ?? buildRAGChunkStructure(leadChunk?.metadata),
4746
4976
  source: group.source,
4747
4977
  title: group.title
4748
4978
  };
@@ -4871,6 +5101,7 @@ var buildSourceGroup = (source, key) => ({
4871
5101
  source: source.source,
4872
5102
  title: source.title
4873
5103
  }),
5104
+ structure: source.structure ?? buildRAGChunkStructure(source.metadata),
4874
5105
  source: source.source,
4875
5106
  title: source.title
4876
5107
  });
@@ -4889,6 +5120,7 @@ var updateSourceGroup = (groups, source) => {
4889
5120
  source: source.source,
4890
5121
  title: source.title
4891
5122
  });
5123
+ existing.structure = source.structure ?? buildRAGChunkStructure(source.metadata);
4892
5124
  existing.source = source.source;
4893
5125
  existing.title = source.title;
4894
5126
  } else {
@@ -6668,5 +6900,5 @@ export {
6668
6900
  buildRAGEvaluationLeaderboard
6669
6901
  };
6670
6902
 
6671
- //# debugId=81AEE958590F833D64756E2164756E21
6903
+ //# debugId=3CD5187B947B133564756E2164756E21
6672
6904
  //# sourceMappingURL=index.js.map