@absolutejs/absolute 0.19.0-beta.604 → 0.19.0-beta.605
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.
- package/dist/ai/client/index.js +186 -6
- package/dist/ai/client/index.js.map +4 -4
- package/dist/ai/client/ui.js +190 -6
- package/dist/ai/client/ui.js.map +4 -4
- package/dist/ai/index.js +289 -36
- package/dist/ai/index.js.map +7 -7
- package/dist/ai/rag/quality.js +17 -6
- package/dist/ai/rag/quality.js.map +3 -3
- package/dist/ai/rag/ui.js +190 -6
- package/dist/ai/rag/ui.js.map +4 -4
- package/dist/ai-client/angular/ai/index.js +185 -5
- package/dist/ai-client/react/ai/index.js +200 -6
- package/dist/ai-client/vue/ai/index.js +289 -97
- package/dist/angular/ai/index.js +186 -6
- package/dist/angular/ai/index.js.map +4 -4
- package/dist/angular/index.js +2 -2
- package/dist/angular/index.js.map +1 -1
- package/dist/angular/server.js +2 -2
- package/dist/angular/server.js.map +1 -1
- package/dist/build.js +2 -2
- package/dist/build.js.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/react/ai/index.js +201 -7
- package/dist/react/ai/index.js.map +6 -6
- package/dist/src/ai/client/ui.d.ts +1 -1
- package/dist/src/ai/rag/index.d.ts +1 -1
- package/dist/src/ai/rag/presentation.d.ts +7 -1
- package/dist/src/ai/rag/ui.d.ts +1 -1
- package/dist/src/react/ai/useRAG.d.ts +5 -0
- package/dist/src/react/ai/useRAGChunkPreview.d.ts +4 -0
- package/dist/src/react/ai/useRAGSources.d.ts +1 -0
- package/dist/src/svelte/ai/createRAG.d.ts +5 -0
- package/dist/src/svelte/ai/createRAGChunkPreview.d.ts +4 -0
- package/dist/src/svelte/ai/createRAGSources.d.ts +1 -0
- package/dist/src/vue/ai/useRAG.d.ts +65 -0
- package/dist/src/vue/ai/useRAGChunkPreview.d.ts +34 -0
- package/dist/src/vue/ai/useRAGSearch.d.ts +30 -0
- package/dist/src/vue/ai/useRAGSources.d.ts +1 -0
- package/dist/svelte/ai/index.js +247 -53
- package/dist/svelte/ai/index.js.map +6 -6
- package/dist/types/ai.d.ts +60 -0
- package/dist/vue/ai/index.js +253 -59
- package/dist/vue/ai/index.js.map +6 -6
- package/package.json +1 -1
package/dist/ai/client/index.js
CHANGED
|
@@ -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,136 @@ 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
|
+
chunkCount: structure.sequence?.sectionChunkCount ?? 1,
|
|
4805
|
+
chunkIds: [chunk.chunkId],
|
|
4806
|
+
depth: structure.section?.depth,
|
|
4807
|
+
id: sectionId,
|
|
4808
|
+
kind: structure.section?.kind,
|
|
4809
|
+
path: structure.section?.path,
|
|
4810
|
+
title: structure.section?.title
|
|
4811
|
+
});
|
|
4812
|
+
continue;
|
|
4813
|
+
}
|
|
4814
|
+
if (!existing.chunkIds.includes(chunk.chunkId)) {
|
|
4815
|
+
existing.chunkIds.push(chunk.chunkId);
|
|
4816
|
+
}
|
|
4817
|
+
existing.chunkCount = Math.max(existing.chunkCount, structure.sequence?.sectionChunkCount ?? existing.chunkCount);
|
|
4818
|
+
}
|
|
4819
|
+
}
|
|
4820
|
+
for (const section of sections.values()) {
|
|
4821
|
+
section.chunkIds.sort((left, right) => {
|
|
4822
|
+
const leftNode = nodes.find((node) => node.chunkId === left);
|
|
4823
|
+
const rightNode = nodes.find((node) => node.chunkId === right);
|
|
4824
|
+
const leftIndex = leftNode?.structure?.sequence?.sectionChunkIndex ?? Number.MAX_SAFE_INTEGER;
|
|
4825
|
+
const rightIndex = rightNode?.structure?.sequence?.sectionChunkIndex ?? Number.MAX_SAFE_INTEGER;
|
|
4826
|
+
if (leftIndex !== rightIndex) {
|
|
4827
|
+
return leftIndex - rightIndex;
|
|
4828
|
+
}
|
|
4829
|
+
return left.localeCompare(right);
|
|
4830
|
+
});
|
|
4831
|
+
}
|
|
4832
|
+
nodes.sort((left, right) => {
|
|
4833
|
+
const leftSection = left.structure?.sequence?.sectionChunkIndex ?? Number.MAX_SAFE_INTEGER;
|
|
4834
|
+
const rightSection = right.structure?.sequence?.sectionChunkIndex ?? Number.MAX_SAFE_INTEGER;
|
|
4835
|
+
if (leftSection !== rightSection) {
|
|
4836
|
+
return leftSection - rightSection;
|
|
4837
|
+
}
|
|
4838
|
+
const leftScore = left.score ?? Number.NEGATIVE_INFINITY;
|
|
4839
|
+
const rightScore = right.score ?? Number.NEGATIVE_INFINITY;
|
|
4840
|
+
if (leftScore !== rightScore) {
|
|
4841
|
+
return rightScore - leftScore;
|
|
4842
|
+
}
|
|
4843
|
+
return left.label.localeCompare(right.label);
|
|
4844
|
+
});
|
|
4845
|
+
return {
|
|
4846
|
+
edges,
|
|
4847
|
+
nodes,
|
|
4848
|
+
sections: [...sections.values()].sort((left, right) => (left.title ?? left.id).localeCompare(right.title ?? right.id))
|
|
4849
|
+
};
|
|
4850
|
+
};
|
|
4851
|
+
var buildRAGChunkPreviewGraph = (preview) => buildRAGChunkGraph(preview.chunks.map((chunk) => ({
|
|
4852
|
+
chunkId: chunk.chunkId,
|
|
4853
|
+
labels: chunk.labels,
|
|
4854
|
+
metadata: chunk.metadata,
|
|
4855
|
+
source: chunk.source ?? preview.document.source,
|
|
4856
|
+
structure: chunk.structure,
|
|
4857
|
+
title: chunk.title ?? preview.document.title
|
|
4858
|
+
})));
|
|
4859
|
+
var buildRAGChunkPreviewNavigation = (preview, activeChunkId) => buildRAGChunkGraphNavigation(buildRAGChunkPreviewGraph(preview), activeChunkId);
|
|
4860
|
+
var buildRAGChunkGraphNavigation = (graph, activeChunkId) => {
|
|
4861
|
+
if (graph.nodes.length === 0) {
|
|
4862
|
+
return {
|
|
4863
|
+
activeChunkId,
|
|
4864
|
+
sectionNodes: []
|
|
4865
|
+
};
|
|
4866
|
+
}
|
|
4867
|
+
const activeNode = (activeChunkId ? graph.nodes.find((node) => node.chunkId === activeChunkId) : undefined) ?? graph.nodes[0];
|
|
4868
|
+
const resolvedActiveChunkId = activeNode?.chunkId;
|
|
4869
|
+
const previousNode = activeNode?.structure?.sequence?.previousChunkId ? graph.nodes.find((node) => node.chunkId === activeNode.structure?.sequence?.previousChunkId) : undefined;
|
|
4870
|
+
const nextNode = activeNode?.structure?.sequence?.nextChunkId ? graph.nodes.find((node) => node.chunkId === activeNode.structure?.sequence?.nextChunkId) : undefined;
|
|
4871
|
+
const section = activeNode?.structure?.sequence?.sectionChunkId ? graph.sections.find((entry) => entry.id === activeNode.structure?.sequence?.sectionChunkId) : undefined;
|
|
4872
|
+
const sectionNodes = section ? section.chunkIds.map((chunkId) => graph.nodes.find((node) => node.chunkId === chunkId)).filter((node) => Boolean(node)) : activeNode ? [activeNode] : [];
|
|
4873
|
+
return {
|
|
4874
|
+
activeChunkId: resolvedActiveChunkId,
|
|
4875
|
+
activeNode,
|
|
4876
|
+
nextNode,
|
|
4877
|
+
previousNode,
|
|
4878
|
+
section,
|
|
4879
|
+
sectionNodes
|
|
4880
|
+
};
|
|
4881
|
+
};
|
|
4705
4882
|
var buildRAGRetrievedState = (messages) => {
|
|
4706
4883
|
const message = getLatestRetrievedMessage(messages);
|
|
4707
4884
|
if (!message) {
|
|
@@ -4743,6 +4920,7 @@ var buildRAGSourceSummaries = (sources) => {
|
|
|
4743
4920
|
label: group.label,
|
|
4744
4921
|
locatorLabel: leadChunk?.labels?.locatorLabel ?? buildLocatorLabel2(leadChunk?.metadata, leadChunk?.source, leadChunk?.title),
|
|
4745
4922
|
provenanceLabel: leadChunk?.labels?.provenanceLabel ?? buildProvenanceLabel2(leadChunk?.metadata),
|
|
4923
|
+
structure: leadChunk?.structure ?? buildRAGChunkStructure(leadChunk?.metadata),
|
|
4746
4924
|
source: group.source,
|
|
4747
4925
|
title: group.title
|
|
4748
4926
|
};
|
|
@@ -4871,6 +5049,7 @@ var buildSourceGroup = (source, key) => ({
|
|
|
4871
5049
|
source: source.source,
|
|
4872
5050
|
title: source.title
|
|
4873
5051
|
}),
|
|
5052
|
+
structure: source.structure ?? buildRAGChunkStructure(source.metadata),
|
|
4874
5053
|
source: source.source,
|
|
4875
5054
|
title: source.title
|
|
4876
5055
|
});
|
|
@@ -4889,6 +5068,7 @@ var updateSourceGroup = (groups, source) => {
|
|
|
4889
5068
|
source: source.source,
|
|
4890
5069
|
title: source.title
|
|
4891
5070
|
});
|
|
5071
|
+
existing.structure = source.structure ?? buildRAGChunkStructure(source.metadata);
|
|
4892
5072
|
existing.source = source.source;
|
|
4893
5073
|
existing.title = source.title;
|
|
4894
5074
|
} else {
|
|
@@ -6668,5 +6848,5 @@ export {
|
|
|
6668
6848
|
buildRAGEvaluationLeaderboard
|
|
6669
6849
|
};
|
|
6670
6850
|
|
|
6671
|
-
//# debugId=
|
|
6851
|
+
//# debugId=C86DB4BD7A51410264756E2164756E21
|
|
6672
6852
|
//# sourceMappingURL=index.js.map
|