@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
|
@@ -631,7 +631,7 @@ var useAIStream = (path, conversationId) => {
|
|
|
631
631
|
};
|
|
632
632
|
};
|
|
633
633
|
// src/vue/ai/useRAGChunkPreview.ts
|
|
634
|
-
import { ref as ref2 } from "vue";
|
|
634
|
+
import { computed, ref as ref2 } from "vue";
|
|
635
635
|
|
|
636
636
|
// src/constants.ts
|
|
637
637
|
var HOURS_IN_DAY = 24;
|
|
@@ -1714,48 +1714,6 @@ var createRAGClient = (options) => {
|
|
|
1714
1714
|
};
|
|
1715
1715
|
};
|
|
1716
1716
|
|
|
1717
|
-
// src/vue/ai/useRAGChunkPreview.ts
|
|
1718
|
-
var useRAGChunkPreview = (path) => {
|
|
1719
|
-
const client = createRAGClient({ path });
|
|
1720
|
-
const preview = ref2(null);
|
|
1721
|
-
const error = ref2(null);
|
|
1722
|
-
const isLoading = ref2(false);
|
|
1723
|
-
const inspect = async (id) => {
|
|
1724
|
-
isLoading.value = true;
|
|
1725
|
-
error.value = null;
|
|
1726
|
-
try {
|
|
1727
|
-
const response = await client.documentChunks(id);
|
|
1728
|
-
if (!response.ok) {
|
|
1729
|
-
throw new Error(response.error);
|
|
1730
|
-
}
|
|
1731
|
-
preview.value = response;
|
|
1732
|
-
return response;
|
|
1733
|
-
} catch (caught) {
|
|
1734
|
-
error.value = caught instanceof Error ? caught.message : String(caught);
|
|
1735
|
-
throw caught;
|
|
1736
|
-
} finally {
|
|
1737
|
-
isLoading.value = false;
|
|
1738
|
-
}
|
|
1739
|
-
};
|
|
1740
|
-
const clear = () => {
|
|
1741
|
-
error.value = null;
|
|
1742
|
-
isLoading.value = false;
|
|
1743
|
-
preview.value = null;
|
|
1744
|
-
};
|
|
1745
|
-
return {
|
|
1746
|
-
clear,
|
|
1747
|
-
error,
|
|
1748
|
-
inspect,
|
|
1749
|
-
isLoading,
|
|
1750
|
-
preview
|
|
1751
|
-
};
|
|
1752
|
-
};
|
|
1753
|
-
// src/vue/ai/useRAG.ts
|
|
1754
|
-
import { computed as computed8 } from "vue";
|
|
1755
|
-
|
|
1756
|
-
// src/vue/ai/useRAGCitations.ts
|
|
1757
|
-
import { computed } from "vue";
|
|
1758
|
-
|
|
1759
1717
|
// src/ai/rag/grounding.ts
|
|
1760
1718
|
var getContextString = (value) => typeof value === "string" && value.trim().length > 0 ? value.trim() : undefined;
|
|
1761
1719
|
var getContextNumber = (value) => typeof value === "number" && Number.isFinite(value) ? value : undefined;
|
|
@@ -1810,6 +1768,11 @@ var buildContextLabel = (metadata) => {
|
|
|
1810
1768
|
if (speaker) {
|
|
1811
1769
|
return `Speaker ${speaker}`;
|
|
1812
1770
|
}
|
|
1771
|
+
const sectionPath = Array.isArray(metadata.sectionPath) ? metadata.sectionPath.map((value) => getContextString(value)).filter((value) => typeof value === "string") : [];
|
|
1772
|
+
const sectionTitle = getContextString(metadata.sectionTitle) ?? sectionPath.at(-1);
|
|
1773
|
+
if (sectionTitle) {
|
|
1774
|
+
return `Section ${sectionTitle}`;
|
|
1775
|
+
}
|
|
1813
1776
|
return;
|
|
1814
1777
|
};
|
|
1815
1778
|
var formatMediaTimestamp = (value) => {
|
|
@@ -1859,6 +1822,10 @@ var buildLocatorLabel = (metadata, source, title) => {
|
|
|
1859
1822
|
if (mediaStart) {
|
|
1860
1823
|
return `Timestamp ${mediaStart}`;
|
|
1861
1824
|
}
|
|
1825
|
+
const sectionPath = Array.isArray(metadata.sectionPath) ? metadata.sectionPath.map((value) => getContextString(value)).filter((value) => typeof value === "string") : [];
|
|
1826
|
+
if (sectionPath.length > 0) {
|
|
1827
|
+
return `Section ${sectionPath.join(" > ")}`;
|
|
1828
|
+
}
|
|
1862
1829
|
return;
|
|
1863
1830
|
};
|
|
1864
1831
|
var formatTimestampLabel = (value) => {
|
|
@@ -1908,8 +1875,10 @@ var buildExcerpt = (text, maxLength = 160) => {
|
|
|
1908
1875
|
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(" · ");
|
|
1909
1876
|
var buildGroundingReferenceEvidenceSummary = (reference) => [
|
|
1910
1877
|
reference.source ?? reference.title ?? reference.chunkId,
|
|
1878
|
+
reference.locatorLabel,
|
|
1879
|
+
reference.contextLabel,
|
|
1911
1880
|
reference.provenanceLabel
|
|
1912
|
-
].filter((value) => Boolean(value && value.length > 0)).join(" · ");
|
|
1881
|
+
].filter((value) => Boolean(value && value.length > 0)).filter((value, index, values) => values.findIndex((entry) => entry === value) === index).join(" · ");
|
|
1913
1882
|
var buildGroundedAnswerCitationDetail = (reference) => ({
|
|
1914
1883
|
contextLabel: reference.contextLabel,
|
|
1915
1884
|
evidenceLabel: buildGroundingReferenceEvidenceLabel(reference),
|
|
@@ -1933,12 +1902,12 @@ var buildRAGCitations = (sources) => {
|
|
|
1933
1902
|
continue;
|
|
1934
1903
|
unique.set(key, {
|
|
1935
1904
|
chunkId: source.chunkId,
|
|
1936
|
-
contextLabel: buildContextLabel(source.metadata),
|
|
1905
|
+
contextLabel: source.labels?.contextLabel ?? buildContextLabel(source.metadata),
|
|
1937
1906
|
key,
|
|
1938
1907
|
label: buildSourceLabel(source),
|
|
1939
|
-
locatorLabel: buildLocatorLabel(source.metadata, source.source, source.title),
|
|
1908
|
+
locatorLabel: source.labels?.locatorLabel ?? buildLocatorLabel(source.metadata, source.source, source.title),
|
|
1940
1909
|
metadata: source.metadata,
|
|
1941
|
-
provenanceLabel: buildProvenanceLabel(source.metadata),
|
|
1910
|
+
provenanceLabel: source.labels?.provenanceLabel ?? buildProvenanceLabel(source.metadata),
|
|
1942
1911
|
score: source.score,
|
|
1943
1912
|
source: source.source,
|
|
1944
1913
|
text: source.text,
|
|
@@ -2008,7 +1977,7 @@ var buildRAGGroundingReferences = (sources) => {
|
|
|
2008
1977
|
const citationReferenceMap = buildRAGCitationReferenceMap(citations);
|
|
2009
1978
|
return citations.map((citation) => ({
|
|
2010
1979
|
chunkId: citation.chunkId,
|
|
2011
|
-
contextLabel: buildContextLabel(citation.metadata),
|
|
1980
|
+
contextLabel: citation.contextLabel ?? buildContextLabel(citation.metadata),
|
|
2012
1981
|
excerpt: buildExcerpt(citation.text),
|
|
2013
1982
|
label: citation.label,
|
|
2014
1983
|
locatorLabel: citation.locatorLabel ?? buildLocatorLabel(citation.metadata, citation.source, citation.title),
|
|
@@ -2105,6 +2074,11 @@ var buildContextLabel2 = (metadata) => {
|
|
|
2105
2074
|
if (speaker) {
|
|
2106
2075
|
return `Speaker ${speaker}`;
|
|
2107
2076
|
}
|
|
2077
|
+
const sectionPath = Array.isArray(metadata.sectionPath) ? metadata.sectionPath.map((value) => getContextString2(value)).filter((value) => typeof value === "string") : [];
|
|
2078
|
+
const sectionTitle = getContextString2(metadata.sectionTitle) ?? sectionPath.at(-1);
|
|
2079
|
+
if (sectionTitle) {
|
|
2080
|
+
return `Section ${sectionTitle}`;
|
|
2081
|
+
}
|
|
2108
2082
|
return;
|
|
2109
2083
|
};
|
|
2110
2084
|
var buildLocatorLabel2 = (metadata, source, title) => {
|
|
@@ -2144,6 +2118,10 @@ var buildLocatorLabel2 = (metadata, source, title) => {
|
|
|
2144
2118
|
if (mediaStart) {
|
|
2145
2119
|
return `Timestamp ${mediaStart}`;
|
|
2146
2120
|
}
|
|
2121
|
+
const sectionPath = Array.isArray(metadata.sectionPath) ? metadata.sectionPath.map((value) => getContextString2(value)).filter((value) => typeof value === "string") : [];
|
|
2122
|
+
if (sectionPath.length > 0) {
|
|
2123
|
+
return `Section ${sectionPath.join(" > ")}`;
|
|
2124
|
+
}
|
|
2147
2125
|
return;
|
|
2148
2126
|
};
|
|
2149
2127
|
var buildProvenanceLabel2 = (metadata) => {
|
|
@@ -2189,6 +2167,33 @@ var buildRAGSourceLabels = ({
|
|
|
2189
2167
|
provenanceLabel
|
|
2190
2168
|
};
|
|
2191
2169
|
};
|
|
2170
|
+
var buildRAGChunkStructure = (metadata) => {
|
|
2171
|
+
if (!metadata) {
|
|
2172
|
+
return;
|
|
2173
|
+
}
|
|
2174
|
+
const sectionPath = Array.isArray(metadata.sectionPath) ? metadata.sectionPath.filter((value) => typeof value === "string" && value.trim().length > 0) : undefined;
|
|
2175
|
+
const sectionKind = metadata.sectionKind === "markdown_heading" || metadata.sectionKind === "html_heading" ? metadata.sectionKind : undefined;
|
|
2176
|
+
const section = {
|
|
2177
|
+
depth: getContextNumber2(metadata.sectionDepth),
|
|
2178
|
+
kind: sectionKind,
|
|
2179
|
+
path: sectionPath && sectionPath.length > 0 ? sectionPath : undefined,
|
|
2180
|
+
title: getContextString2(metadata.sectionTitle)
|
|
2181
|
+
};
|
|
2182
|
+
const sequence = {
|
|
2183
|
+
nextChunkId: getContextString2(metadata.nextChunkId),
|
|
2184
|
+
previousChunkId: getContextString2(metadata.previousChunkId),
|
|
2185
|
+
sectionChunkCount: getContextNumber2(metadata.sectionChunkCount),
|
|
2186
|
+
sectionChunkId: getContextString2(metadata.sectionChunkId),
|
|
2187
|
+
sectionChunkIndex: getContextNumber2(metadata.sectionChunkIndex)
|
|
2188
|
+
};
|
|
2189
|
+
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") {
|
|
2190
|
+
return;
|
|
2191
|
+
}
|
|
2192
|
+
return {
|
|
2193
|
+
section: section.title || section.path && section.path.length > 0 || typeof section.depth === "number" || section.kind ? section : undefined,
|
|
2194
|
+
sequence: sequence.nextChunkId || sequence.previousChunkId || typeof sequence.sectionChunkCount === "number" || sequence.sectionChunkId || typeof sequence.sectionChunkIndex === "number" ? sequence : undefined
|
|
2195
|
+
};
|
|
2196
|
+
};
|
|
2192
2197
|
var buildExcerpt2 = (text, maxLength = 160) => {
|
|
2193
2198
|
const normalized = text.replaceAll(/\s+/g, " ").trim();
|
|
2194
2199
|
if (normalized.length <= maxLength) {
|
|
@@ -2196,6 +2201,136 @@ var buildExcerpt2 = (text, maxLength = 160) => {
|
|
|
2196
2201
|
}
|
|
2197
2202
|
return `${normalized.slice(0, Math.max(0, maxLength - 1)).trimEnd()}…`;
|
|
2198
2203
|
};
|
|
2204
|
+
var buildRAGChunkGraph = (chunks) => {
|
|
2205
|
+
const nodes = [];
|
|
2206
|
+
const edges = [];
|
|
2207
|
+
const edgeKeys = new Set;
|
|
2208
|
+
const sections = new Map;
|
|
2209
|
+
for (const chunk of chunks) {
|
|
2210
|
+
const labels = chunk.labels ?? buildRAGSourceLabels({
|
|
2211
|
+
metadata: chunk.metadata,
|
|
2212
|
+
source: chunk.source,
|
|
2213
|
+
title: chunk.title
|
|
2214
|
+
});
|
|
2215
|
+
const structure = chunk.structure ?? buildRAGChunkStructure(chunk.metadata);
|
|
2216
|
+
nodes.push({
|
|
2217
|
+
chunkId: chunk.chunkId,
|
|
2218
|
+
contextLabel: labels?.contextLabel,
|
|
2219
|
+
label: chunk.source ?? chunk.title ?? chunk.chunkId,
|
|
2220
|
+
locatorLabel: labels?.locatorLabel,
|
|
2221
|
+
provenanceLabel: labels?.provenanceLabel,
|
|
2222
|
+
score: chunk.score,
|
|
2223
|
+
source: chunk.source,
|
|
2224
|
+
structure,
|
|
2225
|
+
title: chunk.title
|
|
2226
|
+
});
|
|
2227
|
+
const previousChunkId = structure?.sequence?.previousChunkId;
|
|
2228
|
+
if (previousChunkId) {
|
|
2229
|
+
const key = `previous:${previousChunkId}:${chunk.chunkId}`;
|
|
2230
|
+
if (!edgeKeys.has(key)) {
|
|
2231
|
+
edgeKeys.add(key);
|
|
2232
|
+
edges.push({
|
|
2233
|
+
fromChunkId: previousChunkId,
|
|
2234
|
+
relation: "previous",
|
|
2235
|
+
toChunkId: chunk.chunkId
|
|
2236
|
+
});
|
|
2237
|
+
}
|
|
2238
|
+
}
|
|
2239
|
+
const nextChunkId = structure?.sequence?.nextChunkId;
|
|
2240
|
+
if (nextChunkId) {
|
|
2241
|
+
const key = `next:${chunk.chunkId}:${nextChunkId}`;
|
|
2242
|
+
if (!edgeKeys.has(key)) {
|
|
2243
|
+
edgeKeys.add(key);
|
|
2244
|
+
edges.push({
|
|
2245
|
+
fromChunkId: chunk.chunkId,
|
|
2246
|
+
relation: "next",
|
|
2247
|
+
toChunkId: nextChunkId
|
|
2248
|
+
});
|
|
2249
|
+
}
|
|
2250
|
+
}
|
|
2251
|
+
const sectionId = structure?.sequence?.sectionChunkId;
|
|
2252
|
+
if (sectionId) {
|
|
2253
|
+
const existing = sections.get(sectionId);
|
|
2254
|
+
if (!existing) {
|
|
2255
|
+
sections.set(sectionId, {
|
|
2256
|
+
chunkCount: structure.sequence?.sectionChunkCount ?? 1,
|
|
2257
|
+
chunkIds: [chunk.chunkId],
|
|
2258
|
+
depth: structure.section?.depth,
|
|
2259
|
+
id: sectionId,
|
|
2260
|
+
kind: structure.section?.kind,
|
|
2261
|
+
path: structure.section?.path,
|
|
2262
|
+
title: structure.section?.title
|
|
2263
|
+
});
|
|
2264
|
+
continue;
|
|
2265
|
+
}
|
|
2266
|
+
if (!existing.chunkIds.includes(chunk.chunkId)) {
|
|
2267
|
+
existing.chunkIds.push(chunk.chunkId);
|
|
2268
|
+
}
|
|
2269
|
+
existing.chunkCount = Math.max(existing.chunkCount, structure.sequence?.sectionChunkCount ?? existing.chunkCount);
|
|
2270
|
+
}
|
|
2271
|
+
}
|
|
2272
|
+
for (const section of sections.values()) {
|
|
2273
|
+
section.chunkIds.sort((left, right) => {
|
|
2274
|
+
const leftNode = nodes.find((node) => node.chunkId === left);
|
|
2275
|
+
const rightNode = nodes.find((node) => node.chunkId === right);
|
|
2276
|
+
const leftIndex = leftNode?.structure?.sequence?.sectionChunkIndex ?? Number.MAX_SAFE_INTEGER;
|
|
2277
|
+
const rightIndex = rightNode?.structure?.sequence?.sectionChunkIndex ?? Number.MAX_SAFE_INTEGER;
|
|
2278
|
+
if (leftIndex !== rightIndex) {
|
|
2279
|
+
return leftIndex - rightIndex;
|
|
2280
|
+
}
|
|
2281
|
+
return left.localeCompare(right);
|
|
2282
|
+
});
|
|
2283
|
+
}
|
|
2284
|
+
nodes.sort((left, right) => {
|
|
2285
|
+
const leftSection = left.structure?.sequence?.sectionChunkIndex ?? Number.MAX_SAFE_INTEGER;
|
|
2286
|
+
const rightSection = right.structure?.sequence?.sectionChunkIndex ?? Number.MAX_SAFE_INTEGER;
|
|
2287
|
+
if (leftSection !== rightSection) {
|
|
2288
|
+
return leftSection - rightSection;
|
|
2289
|
+
}
|
|
2290
|
+
const leftScore = left.score ?? Number.NEGATIVE_INFINITY;
|
|
2291
|
+
const rightScore = right.score ?? Number.NEGATIVE_INFINITY;
|
|
2292
|
+
if (leftScore !== rightScore) {
|
|
2293
|
+
return rightScore - leftScore;
|
|
2294
|
+
}
|
|
2295
|
+
return left.label.localeCompare(right.label);
|
|
2296
|
+
});
|
|
2297
|
+
return {
|
|
2298
|
+
edges,
|
|
2299
|
+
nodes,
|
|
2300
|
+
sections: [...sections.values()].sort((left, right) => (left.title ?? left.id).localeCompare(right.title ?? right.id))
|
|
2301
|
+
};
|
|
2302
|
+
};
|
|
2303
|
+
var buildRAGChunkPreviewGraph = (preview) => buildRAGChunkGraph(preview.chunks.map((chunk) => ({
|
|
2304
|
+
chunkId: chunk.chunkId,
|
|
2305
|
+
labels: chunk.labels,
|
|
2306
|
+
metadata: chunk.metadata,
|
|
2307
|
+
source: chunk.source ?? preview.document.source,
|
|
2308
|
+
structure: chunk.structure,
|
|
2309
|
+
title: chunk.title ?? preview.document.title
|
|
2310
|
+
})));
|
|
2311
|
+
var buildRAGChunkPreviewNavigation = (preview, activeChunkId) => buildRAGChunkGraphNavigation(buildRAGChunkPreviewGraph(preview), activeChunkId);
|
|
2312
|
+
var buildRAGChunkGraphNavigation = (graph, activeChunkId) => {
|
|
2313
|
+
if (graph.nodes.length === 0) {
|
|
2314
|
+
return {
|
|
2315
|
+
activeChunkId,
|
|
2316
|
+
sectionNodes: []
|
|
2317
|
+
};
|
|
2318
|
+
}
|
|
2319
|
+
const activeNode = (activeChunkId ? graph.nodes.find((node) => node.chunkId === activeChunkId) : undefined) ?? graph.nodes[0];
|
|
2320
|
+
const resolvedActiveChunkId = activeNode?.chunkId;
|
|
2321
|
+
const previousNode = activeNode?.structure?.sequence?.previousChunkId ? graph.nodes.find((node) => node.chunkId === activeNode.structure?.sequence?.previousChunkId) : undefined;
|
|
2322
|
+
const nextNode = activeNode?.structure?.sequence?.nextChunkId ? graph.nodes.find((node) => node.chunkId === activeNode.structure?.sequence?.nextChunkId) : undefined;
|
|
2323
|
+
const section = activeNode?.structure?.sequence?.sectionChunkId ? graph.sections.find((entry) => entry.id === activeNode.structure?.sequence?.sectionChunkId) : undefined;
|
|
2324
|
+
const sectionNodes = section ? section.chunkIds.map((chunkId) => graph.nodes.find((node) => node.chunkId === chunkId)).filter((node) => Boolean(node)) : activeNode ? [activeNode] : [];
|
|
2325
|
+
return {
|
|
2326
|
+
activeChunkId: resolvedActiveChunkId,
|
|
2327
|
+
activeNode,
|
|
2328
|
+
nextNode,
|
|
2329
|
+
previousNode,
|
|
2330
|
+
section,
|
|
2331
|
+
sectionNodes
|
|
2332
|
+
};
|
|
2333
|
+
};
|
|
2199
2334
|
var buildRAGRetrievedState = (messages) => {
|
|
2200
2335
|
const message = getLatestRetrievedMessage(messages);
|
|
2201
2336
|
if (!message) {
|
|
@@ -2237,6 +2372,7 @@ var buildRAGSourceSummaries = (sources) => {
|
|
|
2237
2372
|
label: group.label,
|
|
2238
2373
|
locatorLabel: leadChunk?.labels?.locatorLabel ?? buildLocatorLabel2(leadChunk?.metadata, leadChunk?.source, leadChunk?.title),
|
|
2239
2374
|
provenanceLabel: leadChunk?.labels?.provenanceLabel ?? buildProvenanceLabel2(leadChunk?.metadata),
|
|
2375
|
+
structure: leadChunk?.structure ?? buildRAGChunkStructure(leadChunk?.metadata),
|
|
2240
2376
|
source: group.source,
|
|
2241
2377
|
title: group.title
|
|
2242
2378
|
};
|
|
@@ -2365,6 +2501,7 @@ var buildSourceGroup = (source, key) => ({
|
|
|
2365
2501
|
source: source.source,
|
|
2366
2502
|
title: source.title
|
|
2367
2503
|
}),
|
|
2504
|
+
structure: source.structure ?? buildRAGChunkStructure(source.metadata),
|
|
2368
2505
|
source: source.source,
|
|
2369
2506
|
title: source.title
|
|
2370
2507
|
});
|
|
@@ -2383,6 +2520,7 @@ var updateSourceGroup = (groups, source) => {
|
|
|
2383
2520
|
source: source.source,
|
|
2384
2521
|
title: source.title
|
|
2385
2522
|
});
|
|
2523
|
+
existing.structure = source.structure ?? buildRAGChunkStructure(source.metadata);
|
|
2386
2524
|
existing.source = source.source;
|
|
2387
2525
|
existing.title = source.title;
|
|
2388
2526
|
} else {
|
|
@@ -2436,13 +2574,65 @@ var resolveRAGStreamStage = ({
|
|
|
2436
2574
|
}
|
|
2437
2575
|
return "streaming";
|
|
2438
2576
|
};
|
|
2577
|
+
// src/vue/ai/useRAGChunkPreview.ts
|
|
2578
|
+
var useRAGChunkPreview = (path) => {
|
|
2579
|
+
const client = createRAGClient({ path });
|
|
2580
|
+
const preview = ref2(null);
|
|
2581
|
+
const activeChunkId = ref2(null);
|
|
2582
|
+
const error = ref2(null);
|
|
2583
|
+
const isLoading = ref2(false);
|
|
2584
|
+
const chunkGraph = computed(() => preview.value ? buildRAGChunkPreviewGraph(preview.value) : null);
|
|
2585
|
+
const navigation = computed(() => preview.value ? buildRAGChunkPreviewNavigation(preview.value, activeChunkId.value ?? undefined) : null);
|
|
2586
|
+
const inspect = async (id) => {
|
|
2587
|
+
isLoading.value = true;
|
|
2588
|
+
error.value = null;
|
|
2589
|
+
try {
|
|
2590
|
+
const response = await client.documentChunks(id);
|
|
2591
|
+
if (!response.ok) {
|
|
2592
|
+
throw new Error(response.error);
|
|
2593
|
+
}
|
|
2594
|
+
preview.value = response;
|
|
2595
|
+
activeChunkId.value = response.chunks[0]?.chunkId ?? null;
|
|
2596
|
+
return response;
|
|
2597
|
+
} catch (caught) {
|
|
2598
|
+
error.value = caught instanceof Error ? caught.message : String(caught);
|
|
2599
|
+
throw caught;
|
|
2600
|
+
} finally {
|
|
2601
|
+
isLoading.value = false;
|
|
2602
|
+
}
|
|
2603
|
+
};
|
|
2604
|
+
const clear = () => {
|
|
2605
|
+
error.value = null;
|
|
2606
|
+
isLoading.value = false;
|
|
2607
|
+
activeChunkId.value = null;
|
|
2608
|
+
preview.value = null;
|
|
2609
|
+
};
|
|
2610
|
+
const selectChunk = (id) => {
|
|
2611
|
+
activeChunkId.value = id;
|
|
2612
|
+
};
|
|
2613
|
+
return {
|
|
2614
|
+
activeChunkId,
|
|
2615
|
+
clear,
|
|
2616
|
+
chunkGraph,
|
|
2617
|
+
error,
|
|
2618
|
+
inspect,
|
|
2619
|
+
isLoading,
|
|
2620
|
+
navigation,
|
|
2621
|
+
preview,
|
|
2622
|
+
selectChunk
|
|
2623
|
+
};
|
|
2624
|
+
};
|
|
2625
|
+
// src/vue/ai/useRAG.ts
|
|
2626
|
+
import { computed as computed9 } from "vue";
|
|
2627
|
+
|
|
2439
2628
|
// src/vue/ai/useRAGCitations.ts
|
|
2629
|
+
import { computed as computed2 } from "vue";
|
|
2440
2630
|
var useRAGCitations = (sources) => {
|
|
2441
|
-
const citations =
|
|
2442
|
-
const citationReferenceMap =
|
|
2443
|
-
const sourceGroups =
|
|
2444
|
-
const sourceSummaries =
|
|
2445
|
-
const hasCitations =
|
|
2631
|
+
const citations = computed2(() => buildRAGCitations(sources.value));
|
|
2632
|
+
const citationReferenceMap = computed2(() => buildRAGCitationReferenceMap(citations.value));
|
|
2633
|
+
const sourceGroups = computed2(() => buildRAGSourceGroups(sources.value));
|
|
2634
|
+
const sourceSummaries = computed2(() => buildRAGSourceSummaries(sources.value));
|
|
2635
|
+
const hasCitations = computed2(() => citations.value.length > 0);
|
|
2446
2636
|
return {
|
|
2447
2637
|
citationReferenceMap,
|
|
2448
2638
|
citations,
|
|
@@ -2492,7 +2682,7 @@ var useRAGDocuments = (path) => {
|
|
|
2492
2682
|
};
|
|
2493
2683
|
|
|
2494
2684
|
// src/vue/ai/useRAGEvaluate.ts
|
|
2495
|
-
import { computed as
|
|
2685
|
+
import { computed as computed3, ref as ref4 } from "vue";
|
|
2496
2686
|
|
|
2497
2687
|
// src/ai/rag/quality.ts
|
|
2498
2688
|
var {mkdir, readFile, writeFile} = (() => ({}));
|
|
@@ -2923,7 +3113,7 @@ var useRAGEvaluate = (path) => {
|
|
|
2923
3113
|
const clearRuns = () => {
|
|
2924
3114
|
suiteRuns.value = [];
|
|
2925
3115
|
};
|
|
2926
|
-
const leaderboard =
|
|
3116
|
+
const leaderboard = computed3(() => buildRAGEvaluationLeaderboard(suiteRuns.value));
|
|
2927
3117
|
const reset = () => {
|
|
2928
3118
|
error.value = null;
|
|
2929
3119
|
lastRequest.value = null;
|
|
@@ -2948,14 +3138,14 @@ var useRAGEvaluate = (path) => {
|
|
|
2948
3138
|
};
|
|
2949
3139
|
|
|
2950
3140
|
// src/vue/ai/useRAGGrounding.ts
|
|
2951
|
-
import { computed as
|
|
3141
|
+
import { computed as computed4 } from "vue";
|
|
2952
3142
|
var useRAGGrounding = (content, sources) => {
|
|
2953
|
-
const groundedAnswer =
|
|
2954
|
-
const references =
|
|
2955
|
-
const hasCitations =
|
|
2956
|
-
const hasGrounding =
|
|
2957
|
-
const coverage =
|
|
2958
|
-
const ungroundedReferenceNumbers =
|
|
3143
|
+
const groundedAnswer = computed4(() => buildRAGGroundedAnswer(content.value, sources.value));
|
|
3144
|
+
const references = computed4(() => buildRAGGroundingReferences(sources.value));
|
|
3145
|
+
const hasCitations = computed4(() => groundedAnswer.value.hasCitations);
|
|
3146
|
+
const hasGrounding = computed4(() => references.value.length > 0);
|
|
3147
|
+
const coverage = computed4(() => groundedAnswer.value.coverage);
|
|
3148
|
+
const ungroundedReferenceNumbers = computed4(() => groundedAnswer.value.ungroundedReferenceNumbers);
|
|
2959
3149
|
return {
|
|
2960
3150
|
coverage,
|
|
2961
3151
|
groundedAnswer,
|
|
@@ -3366,16 +3556,18 @@ var useRAGSearch = (path) => {
|
|
|
3366
3556
|
};
|
|
3367
3557
|
|
|
3368
3558
|
// src/vue/ai/useRAGSources.ts
|
|
3369
|
-
import { computed as
|
|
3559
|
+
import { computed as computed5 } from "vue";
|
|
3370
3560
|
var useRAGSources = (messages) => {
|
|
3371
|
-
const latestAssistantMessage =
|
|
3372
|
-
const sources =
|
|
3373
|
-
const sourceGroups =
|
|
3374
|
-
const sourceSummaries =
|
|
3375
|
-
const
|
|
3376
|
-
const
|
|
3561
|
+
const latestAssistantMessage = computed5(() => getLatestAssistantMessage(messages.value));
|
|
3562
|
+
const sources = computed5(() => getLatestRAGSources(messages.value));
|
|
3563
|
+
const sourceGroups = computed5(() => buildRAGSourceGroups(sources.value));
|
|
3564
|
+
const sourceSummaries = computed5(() => buildRAGSourceSummaries(sources.value));
|
|
3565
|
+
const chunkGraph = computed5(() => buildRAGChunkGraph(sources.value));
|
|
3566
|
+
const citationReferenceMap = computed5(() => buildRAGCitationReferenceMap(sourceSummaries.value.flatMap((summary) => summary.citations)));
|
|
3567
|
+
const hasSources = computed5(() => sources.value.length > 0);
|
|
3377
3568
|
return {
|
|
3378
3569
|
citationReferenceMap,
|
|
3570
|
+
chunkGraph,
|
|
3379
3571
|
hasSources,
|
|
3380
3572
|
latestAssistantMessage,
|
|
3381
3573
|
sourceGroups,
|
|
@@ -3431,14 +3623,14 @@ var useRAGStatus = (path, autoLoad = true) => {
|
|
|
3431
3623
|
};
|
|
3432
3624
|
|
|
3433
3625
|
// src/vue/ai/useRAGWorkflow.ts
|
|
3434
|
-
import { computed as
|
|
3626
|
+
import { computed as computed8 } from "vue";
|
|
3435
3627
|
|
|
3436
3628
|
// src/vue/ai/useRAGStream.ts
|
|
3437
|
-
import { computed as
|
|
3629
|
+
import { computed as computed7 } from "vue";
|
|
3438
3630
|
|
|
3439
3631
|
// src/vue/ai/useRAGStreamProgress.ts
|
|
3440
|
-
import { computed as
|
|
3441
|
-
var useRAGStreamProgress = (params) =>
|
|
3632
|
+
import { computed as computed6 } from "vue";
|
|
3633
|
+
var useRAGStreamProgress = (params) => computed6(() => buildRAGStreamProgress({
|
|
3442
3634
|
error: params.error.value,
|
|
3443
3635
|
isStreaming: params.isStreaming.value,
|
|
3444
3636
|
messages: params.messages.value
|
|
@@ -3447,7 +3639,7 @@ var useRAGStreamProgress = (params) => computed5(() => buildRAGStreamProgress({
|
|
|
3447
3639
|
// src/vue/ai/useRAGStream.ts
|
|
3448
3640
|
var useRAGStream = (path, conversationId) => {
|
|
3449
3641
|
const stream = useAIStream(path, conversationId);
|
|
3450
|
-
const workflow =
|
|
3642
|
+
const workflow = computed7(() => buildRAGAnswerWorkflowState({
|
|
3451
3643
|
error: stream.error.value,
|
|
3452
3644
|
isStreaming: stream.isStreaming.value,
|
|
3453
3645
|
messages: stream.messages.value
|
|
@@ -3460,37 +3652,37 @@ var useRAGStream = (path, conversationId) => {
|
|
|
3460
3652
|
const query = (content, attachments) => {
|
|
3461
3653
|
stream.send(content, attachments);
|
|
3462
3654
|
};
|
|
3463
|
-
const hasRetrieved =
|
|
3464
|
-
const isRetrieving =
|
|
3465
|
-
const isRetrieved =
|
|
3466
|
-
const isAnswerStreaming =
|
|
3467
|
-
const isComplete =
|
|
3468
|
-
const hasSources =
|
|
3655
|
+
const hasRetrieved = computed7(() => workflow.value.hasRetrieved);
|
|
3656
|
+
const isRetrieving = computed7(() => workflow.value.isRetrieving);
|
|
3657
|
+
const isRetrieved = computed7(() => workflow.value.isRetrieved);
|
|
3658
|
+
const isAnswerStreaming = computed7(() => workflow.value.isAnswerStreaming);
|
|
3659
|
+
const isComplete = computed7(() => workflow.value.isComplete);
|
|
3660
|
+
const hasSources = computed7(() => workflow.value.hasSources);
|
|
3469
3661
|
return {
|
|
3470
3662
|
...stream,
|
|
3471
|
-
citationReferenceMap:
|
|
3472
|
-
citations:
|
|
3473
|
-
coverage:
|
|
3474
|
-
groundedAnswer:
|
|
3475
|
-
groundingReferences:
|
|
3476
|
-
hasGrounding:
|
|
3663
|
+
citationReferenceMap: computed7(() => workflow.value.citationReferenceMap),
|
|
3664
|
+
citations: computed7(() => workflow.value.citations),
|
|
3665
|
+
coverage: computed7(() => workflow.value.coverage),
|
|
3666
|
+
groundedAnswer: computed7(() => workflow.value.groundedAnswer),
|
|
3667
|
+
groundingReferences: computed7(() => workflow.value.groundingReferences),
|
|
3668
|
+
hasGrounding: computed7(() => workflow.value.hasGrounding),
|
|
3477
3669
|
hasRetrieved,
|
|
3478
3670
|
hasSources,
|
|
3479
3671
|
isAnswerStreaming,
|
|
3480
3672
|
isComplete,
|
|
3481
|
-
isError:
|
|
3673
|
+
isError: computed7(() => workflow.value.isError),
|
|
3482
3674
|
isRetrieved,
|
|
3483
3675
|
isRetrieving,
|
|
3484
|
-
isRunning:
|
|
3485
|
-
latestAssistantMessage:
|
|
3676
|
+
isRunning: computed7(() => workflow.value.isRunning),
|
|
3677
|
+
latestAssistantMessage: computed7(() => workflow.value.latestAssistantMessage),
|
|
3486
3678
|
progress,
|
|
3487
3679
|
query,
|
|
3488
|
-
retrieval:
|
|
3489
|
-
sourceGroups:
|
|
3490
|
-
sourceSummaries:
|
|
3491
|
-
sources:
|
|
3492
|
-
stage:
|
|
3493
|
-
ungroundedReferenceNumbers:
|
|
3680
|
+
retrieval: computed7(() => workflow.value.retrieval),
|
|
3681
|
+
sourceGroups: computed7(() => workflow.value.sourceGroups),
|
|
3682
|
+
sourceSummaries: computed7(() => workflow.value.sourceSummaries),
|
|
3683
|
+
sources: computed7(() => workflow.value.sources),
|
|
3684
|
+
stage: computed7(() => workflow.value.stage),
|
|
3685
|
+
ungroundedReferenceNumbers: computed7(() => workflow.value.ungroundedReferenceNumbers),
|
|
3494
3686
|
workflow
|
|
3495
3687
|
};
|
|
3496
3688
|
};
|
|
@@ -3498,7 +3690,7 @@ var useRAGStream = (path, conversationId) => {
|
|
|
3498
3690
|
// src/vue/ai/useRAGWorkflow.ts
|
|
3499
3691
|
var useRAGWorkflow = (path, conversationId) => {
|
|
3500
3692
|
const stream = useRAGStream(path, conversationId);
|
|
3501
|
-
const state =
|
|
3693
|
+
const state = computed8(() => stream.workflow.value);
|
|
3502
3694
|
return {
|
|
3503
3695
|
...stream,
|
|
3504
3696
|
state
|
|
@@ -3518,7 +3710,7 @@ var useRAG = (path, options = {}) => {
|
|
|
3518
3710
|
const workflow = useRAGWorkflow(options.streamPath ?? path, options.conversationId);
|
|
3519
3711
|
const sources = useRAGSources(workflow.messages);
|
|
3520
3712
|
const citations = useRAGCitations(sources.sources);
|
|
3521
|
-
const grounding = useRAGGrounding(
|
|
3713
|
+
const grounding = useRAGGrounding(computed9(() => workflow.latestAssistantMessage.value?.content ?? ""), sources.sources);
|
|
3522
3714
|
return {
|
|
3523
3715
|
chunkPreview,
|
|
3524
3716
|
citations,
|