@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.
- package/dist/ai/client/index.js +238 -6
- package/dist/ai/client/index.js.map +4 -4
- package/dist/ai/client/ui.js +242 -6
- package/dist/ai/client/ui.js.map +4 -4
- package/dist/ai/index.js +381 -38
- 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 +242 -6
- package/dist/ai/rag/ui.js.map +4 -4
- package/dist/ai-client/angular/ai/index.js +237 -5
- package/dist/ai-client/react/ai/index.js +281 -12
- package/dist/ai-client/vue/ai/index.js +364 -97
- package/dist/angular/ai/index.js +238 -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 +282 -13
- 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 +9 -0
- package/dist/src/react/ai/useRAGChunkPreview.d.ts +7 -0
- package/dist/src/react/ai/useRAGSources.d.ts +2 -0
- package/dist/src/svelte/ai/createRAG.d.ts +9 -0
- package/dist/src/svelte/ai/createRAGChunkPreview.d.ts +7 -0
- package/dist/src/svelte/ai/createRAGSources.d.ts +2 -0
- package/dist/src/vue/ai/useRAG.d.ts +69 -0
- package/dist/src/vue/ai/useRAGChunkPreview.d.ts +37 -0
- package/dist/src/vue/ai/useRAGSearch.d.ts +30 -0
- package/dist/src/vue/ai/useRAGSources.d.ts +2 -0
- package/dist/svelte/ai/index.js +334 -53
- package/dist/svelte/ai/index.js.map +6 -6
- package/dist/types/ai.d.ts +66 -0
- package/dist/vue/ai/index.js +328 -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,188 @@ 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
|
+
childSectionIds: [],
|
|
2257
|
+
chunkCount: structure.sequence?.sectionChunkCount ?? 1,
|
|
2258
|
+
chunkIds: [chunk.chunkId],
|
|
2259
|
+
depth: structure.section?.depth,
|
|
2260
|
+
id: sectionId,
|
|
2261
|
+
kind: structure.section?.kind,
|
|
2262
|
+
leadChunkId: chunk.chunkId,
|
|
2263
|
+
path: structure.section?.path,
|
|
2264
|
+
title: structure.section?.title
|
|
2265
|
+
});
|
|
2266
|
+
continue;
|
|
2267
|
+
}
|
|
2268
|
+
if (!existing.chunkIds.includes(chunk.chunkId)) {
|
|
2269
|
+
existing.chunkIds.push(chunk.chunkId);
|
|
2270
|
+
}
|
|
2271
|
+
existing.chunkCount = Math.max(existing.chunkCount, structure.sequence?.sectionChunkCount ?? existing.chunkCount);
|
|
2272
|
+
}
|
|
2273
|
+
}
|
|
2274
|
+
for (const section of sections.values()) {
|
|
2275
|
+
section.chunkIds.sort((left, right) => {
|
|
2276
|
+
const leftNode = nodes.find((node) => node.chunkId === left);
|
|
2277
|
+
const rightNode = nodes.find((node) => node.chunkId === right);
|
|
2278
|
+
const leftIndex = leftNode?.structure?.sequence?.sectionChunkIndex ?? Number.MAX_SAFE_INTEGER;
|
|
2279
|
+
const rightIndex = rightNode?.structure?.sequence?.sectionChunkIndex ?? Number.MAX_SAFE_INTEGER;
|
|
2280
|
+
if (leftIndex !== rightIndex) {
|
|
2281
|
+
return leftIndex - rightIndex;
|
|
2282
|
+
}
|
|
2283
|
+
return left.localeCompare(right);
|
|
2284
|
+
});
|
|
2285
|
+
section.leadChunkId = section.chunkIds[0];
|
|
2286
|
+
}
|
|
2287
|
+
const sectionPathIndex = new Map;
|
|
2288
|
+
for (const section of sections.values()) {
|
|
2289
|
+
const path = section.path && section.path.length > 0 ? section.path : section.title ? [section.title] : undefined;
|
|
2290
|
+
if (path && path.length > 0) {
|
|
2291
|
+
sectionPathIndex.set(path.join("\x00"), section);
|
|
2292
|
+
}
|
|
2293
|
+
}
|
|
2294
|
+
for (const section of sections.values()) {
|
|
2295
|
+
const path = section.path && section.path.length > 0 ? section.path : section.title ? [section.title] : undefined;
|
|
2296
|
+
if (!path || path.length < 2) {
|
|
2297
|
+
continue;
|
|
2298
|
+
}
|
|
2299
|
+
const parent = sectionPathIndex.get(path.slice(0, -1).join("\x00"));
|
|
2300
|
+
if (!parent || parent.id === section.id) {
|
|
2301
|
+
continue;
|
|
2302
|
+
}
|
|
2303
|
+
section.parentSectionId = parent.id;
|
|
2304
|
+
if (!parent.childSectionIds.includes(section.id)) {
|
|
2305
|
+
parent.childSectionIds.push(section.id);
|
|
2306
|
+
}
|
|
2307
|
+
if (parent.leadChunkId && section.leadChunkId) {
|
|
2308
|
+
const parentKey = `section_parent:${section.leadChunkId}:${parent.leadChunkId}`;
|
|
2309
|
+
if (!edgeKeys.has(parentKey)) {
|
|
2310
|
+
edgeKeys.add(parentKey);
|
|
2311
|
+
edges.push({
|
|
2312
|
+
fromChunkId: section.leadChunkId,
|
|
2313
|
+
relation: "section_parent",
|
|
2314
|
+
toChunkId: parent.leadChunkId
|
|
2315
|
+
});
|
|
2316
|
+
}
|
|
2317
|
+
const childKey = `section_child:${parent.leadChunkId}:${section.leadChunkId}`;
|
|
2318
|
+
if (!edgeKeys.has(childKey)) {
|
|
2319
|
+
edgeKeys.add(childKey);
|
|
2320
|
+
edges.push({
|
|
2321
|
+
fromChunkId: parent.leadChunkId,
|
|
2322
|
+
relation: "section_child",
|
|
2323
|
+
toChunkId: section.leadChunkId
|
|
2324
|
+
});
|
|
2325
|
+
}
|
|
2326
|
+
}
|
|
2327
|
+
}
|
|
2328
|
+
nodes.sort((left, right) => {
|
|
2329
|
+
const leftSection = left.structure?.sequence?.sectionChunkIndex ?? Number.MAX_SAFE_INTEGER;
|
|
2330
|
+
const rightSection = right.structure?.sequence?.sectionChunkIndex ?? Number.MAX_SAFE_INTEGER;
|
|
2331
|
+
if (leftSection !== rightSection) {
|
|
2332
|
+
return leftSection - rightSection;
|
|
2333
|
+
}
|
|
2334
|
+
const leftScore = left.score ?? Number.NEGATIVE_INFINITY;
|
|
2335
|
+
const rightScore = right.score ?? Number.NEGATIVE_INFINITY;
|
|
2336
|
+
if (leftScore !== rightScore) {
|
|
2337
|
+
return rightScore - leftScore;
|
|
2338
|
+
}
|
|
2339
|
+
return left.label.localeCompare(right.label);
|
|
2340
|
+
});
|
|
2341
|
+
return {
|
|
2342
|
+
edges,
|
|
2343
|
+
nodes,
|
|
2344
|
+
sections: [...sections.values()].sort((left, right) => (left.title ?? left.id).localeCompare(right.title ?? right.id))
|
|
2345
|
+
};
|
|
2346
|
+
};
|
|
2347
|
+
var buildRAGChunkPreviewGraph = (preview) => buildRAGChunkGraph(preview.chunks.map((chunk) => ({
|
|
2348
|
+
chunkId: chunk.chunkId,
|
|
2349
|
+
labels: chunk.labels,
|
|
2350
|
+
metadata: chunk.metadata,
|
|
2351
|
+
source: chunk.source ?? preview.document.source,
|
|
2352
|
+
structure: chunk.structure,
|
|
2353
|
+
title: chunk.title ?? preview.document.title
|
|
2354
|
+
})));
|
|
2355
|
+
var buildRAGChunkPreviewNavigation = (preview, activeChunkId) => buildRAGChunkGraphNavigation(buildRAGChunkPreviewGraph(preview), activeChunkId);
|
|
2356
|
+
var buildRAGChunkGraphNavigation = (graph, activeChunkId) => {
|
|
2357
|
+
if (graph.nodes.length === 0) {
|
|
2358
|
+
return {
|
|
2359
|
+
activeChunkId,
|
|
2360
|
+
childSections: [],
|
|
2361
|
+
siblingSections: [],
|
|
2362
|
+
sectionNodes: []
|
|
2363
|
+
};
|
|
2364
|
+
}
|
|
2365
|
+
const activeNode = (activeChunkId ? graph.nodes.find((node) => node.chunkId === activeChunkId) : undefined) ?? graph.nodes[0];
|
|
2366
|
+
const resolvedActiveChunkId = activeNode?.chunkId;
|
|
2367
|
+
const previousNode = activeNode?.structure?.sequence?.previousChunkId ? graph.nodes.find((node) => node.chunkId === activeNode.structure?.sequence?.previousChunkId) : undefined;
|
|
2368
|
+
const nextNode = activeNode?.structure?.sequence?.nextChunkId ? graph.nodes.find((node) => node.chunkId === activeNode.structure?.sequence?.nextChunkId) : undefined;
|
|
2369
|
+
const section = activeNode?.structure?.sequence?.sectionChunkId ? graph.sections.find((entry) => entry.id === activeNode.structure?.sequence?.sectionChunkId) : undefined;
|
|
2370
|
+
const parentSection = section?.parentSectionId ? graph.sections.find((entry) => entry.id === section.parentSectionId) : undefined;
|
|
2371
|
+
const childSections = section ? section.childSectionIds.map((sectionId) => graph.sections.find((entry) => entry.id === sectionId)).filter((entry) => Boolean(entry)) : [];
|
|
2372
|
+
const siblingSections = section?.parentSectionId ? graph.sections.filter((entry) => entry.parentSectionId === section.parentSectionId && entry.id !== section.id) : [];
|
|
2373
|
+
const sectionNodes = section ? section.chunkIds.map((chunkId) => graph.nodes.find((node) => node.chunkId === chunkId)).filter((node) => Boolean(node)) : activeNode ? [activeNode] : [];
|
|
2374
|
+
return {
|
|
2375
|
+
activeChunkId: resolvedActiveChunkId,
|
|
2376
|
+
activeNode,
|
|
2377
|
+
childSections,
|
|
2378
|
+
nextNode,
|
|
2379
|
+
parentSection,
|
|
2380
|
+
previousNode,
|
|
2381
|
+
section,
|
|
2382
|
+
siblingSections,
|
|
2383
|
+
sectionNodes
|
|
2384
|
+
};
|
|
2385
|
+
};
|
|
2199
2386
|
var buildRAGRetrievedState = (messages) => {
|
|
2200
2387
|
const message = getLatestRetrievedMessage(messages);
|
|
2201
2388
|
if (!message) {
|
|
@@ -2237,6 +2424,7 @@ var buildRAGSourceSummaries = (sources) => {
|
|
|
2237
2424
|
label: group.label,
|
|
2238
2425
|
locatorLabel: leadChunk?.labels?.locatorLabel ?? buildLocatorLabel2(leadChunk?.metadata, leadChunk?.source, leadChunk?.title),
|
|
2239
2426
|
provenanceLabel: leadChunk?.labels?.provenanceLabel ?? buildProvenanceLabel2(leadChunk?.metadata),
|
|
2427
|
+
structure: leadChunk?.structure ?? buildRAGChunkStructure(leadChunk?.metadata),
|
|
2240
2428
|
source: group.source,
|
|
2241
2429
|
title: group.title
|
|
2242
2430
|
};
|
|
@@ -2365,6 +2553,7 @@ var buildSourceGroup = (source, key) => ({
|
|
|
2365
2553
|
source: source.source,
|
|
2366
2554
|
title: source.title
|
|
2367
2555
|
}),
|
|
2556
|
+
structure: source.structure ?? buildRAGChunkStructure(source.metadata),
|
|
2368
2557
|
source: source.source,
|
|
2369
2558
|
title: source.title
|
|
2370
2559
|
});
|
|
@@ -2383,6 +2572,7 @@ var updateSourceGroup = (groups, source) => {
|
|
|
2383
2572
|
source: source.source,
|
|
2384
2573
|
title: source.title
|
|
2385
2574
|
});
|
|
2575
|
+
existing.structure = source.structure ?? buildRAGChunkStructure(source.metadata);
|
|
2386
2576
|
existing.source = source.source;
|
|
2387
2577
|
existing.title = source.title;
|
|
2388
2578
|
} else {
|
|
@@ -2436,13 +2626,86 @@ var resolveRAGStreamStage = ({
|
|
|
2436
2626
|
}
|
|
2437
2627
|
return "streaming";
|
|
2438
2628
|
};
|
|
2629
|
+
// src/vue/ai/useRAGChunkPreview.ts
|
|
2630
|
+
var useRAGChunkPreview = (path) => {
|
|
2631
|
+
const client = createRAGClient({ path });
|
|
2632
|
+
const preview = ref2(null);
|
|
2633
|
+
const activeChunkId = ref2(null);
|
|
2634
|
+
const error = ref2(null);
|
|
2635
|
+
const isLoading = ref2(false);
|
|
2636
|
+
const chunkGraph = computed(() => preview.value ? buildRAGChunkPreviewGraph(preview.value) : null);
|
|
2637
|
+
const navigation = computed(() => preview.value ? buildRAGChunkPreviewNavigation(preview.value, activeChunkId.value ?? undefined) : null);
|
|
2638
|
+
const inspect = async (id) => {
|
|
2639
|
+
isLoading.value = true;
|
|
2640
|
+
error.value = null;
|
|
2641
|
+
try {
|
|
2642
|
+
const response = await client.documentChunks(id);
|
|
2643
|
+
if (!response.ok) {
|
|
2644
|
+
throw new Error(response.error);
|
|
2645
|
+
}
|
|
2646
|
+
preview.value = response;
|
|
2647
|
+
activeChunkId.value = response.chunks[0]?.chunkId ?? null;
|
|
2648
|
+
return response;
|
|
2649
|
+
} catch (caught) {
|
|
2650
|
+
error.value = caught instanceof Error ? caught.message : String(caught);
|
|
2651
|
+
throw caught;
|
|
2652
|
+
} finally {
|
|
2653
|
+
isLoading.value = false;
|
|
2654
|
+
}
|
|
2655
|
+
};
|
|
2656
|
+
const clear = () => {
|
|
2657
|
+
error.value = null;
|
|
2658
|
+
isLoading.value = false;
|
|
2659
|
+
activeChunkId.value = null;
|
|
2660
|
+
preview.value = null;
|
|
2661
|
+
};
|
|
2662
|
+
const selectChunk = (id) => {
|
|
2663
|
+
activeChunkId.value = id;
|
|
2664
|
+
};
|
|
2665
|
+
const selectParentSection = () => {
|
|
2666
|
+
const leadChunkId = navigation.value?.parentSection?.leadChunkId;
|
|
2667
|
+
if (leadChunkId) {
|
|
2668
|
+
activeChunkId.value = leadChunkId;
|
|
2669
|
+
}
|
|
2670
|
+
};
|
|
2671
|
+
const selectChildSection = (sectionId) => {
|
|
2672
|
+
const leadChunkId = navigation.value?.childSections.find((section) => section.id === sectionId)?.leadChunkId;
|
|
2673
|
+
if (leadChunkId) {
|
|
2674
|
+
activeChunkId.value = leadChunkId;
|
|
2675
|
+
}
|
|
2676
|
+
};
|
|
2677
|
+
const selectSiblingSection = (sectionId) => {
|
|
2678
|
+
const leadChunkId = navigation.value?.siblingSections.find((section) => section.id === sectionId)?.leadChunkId;
|
|
2679
|
+
if (leadChunkId) {
|
|
2680
|
+
activeChunkId.value = leadChunkId;
|
|
2681
|
+
}
|
|
2682
|
+
};
|
|
2683
|
+
return {
|
|
2684
|
+
activeChunkId,
|
|
2685
|
+
clear,
|
|
2686
|
+
chunkGraph,
|
|
2687
|
+
error,
|
|
2688
|
+
inspect,
|
|
2689
|
+
isLoading,
|
|
2690
|
+
navigation,
|
|
2691
|
+
preview,
|
|
2692
|
+
selectChildSection,
|
|
2693
|
+
selectChunk,
|
|
2694
|
+
selectParentSection,
|
|
2695
|
+
selectSiblingSection
|
|
2696
|
+
};
|
|
2697
|
+
};
|
|
2698
|
+
// src/vue/ai/useRAG.ts
|
|
2699
|
+
import { computed as computed9 } from "vue";
|
|
2700
|
+
|
|
2439
2701
|
// src/vue/ai/useRAGCitations.ts
|
|
2702
|
+
import { computed as computed2 } from "vue";
|
|
2440
2703
|
var useRAGCitations = (sources) => {
|
|
2441
|
-
const citations =
|
|
2442
|
-
const citationReferenceMap =
|
|
2443
|
-
const sourceGroups =
|
|
2444
|
-
const sourceSummaries =
|
|
2445
|
-
const hasCitations =
|
|
2704
|
+
const citations = computed2(() => buildRAGCitations(sources.value));
|
|
2705
|
+
const citationReferenceMap = computed2(() => buildRAGCitationReferenceMap(citations.value));
|
|
2706
|
+
const sourceGroups = computed2(() => buildRAGSourceGroups(sources.value));
|
|
2707
|
+
const sourceSummaries = computed2(() => buildRAGSourceSummaries(sources.value));
|
|
2708
|
+
const hasCitations = computed2(() => citations.value.length > 0);
|
|
2446
2709
|
return {
|
|
2447
2710
|
citationReferenceMap,
|
|
2448
2711
|
citations,
|
|
@@ -2492,7 +2755,7 @@ var useRAGDocuments = (path) => {
|
|
|
2492
2755
|
};
|
|
2493
2756
|
|
|
2494
2757
|
// src/vue/ai/useRAGEvaluate.ts
|
|
2495
|
-
import { computed as
|
|
2758
|
+
import { computed as computed3, ref as ref4 } from "vue";
|
|
2496
2759
|
|
|
2497
2760
|
// src/ai/rag/quality.ts
|
|
2498
2761
|
var {mkdir, readFile, writeFile} = (() => ({}));
|
|
@@ -2923,7 +3186,7 @@ var useRAGEvaluate = (path) => {
|
|
|
2923
3186
|
const clearRuns = () => {
|
|
2924
3187
|
suiteRuns.value = [];
|
|
2925
3188
|
};
|
|
2926
|
-
const leaderboard =
|
|
3189
|
+
const leaderboard = computed3(() => buildRAGEvaluationLeaderboard(suiteRuns.value));
|
|
2927
3190
|
const reset = () => {
|
|
2928
3191
|
error.value = null;
|
|
2929
3192
|
lastRequest.value = null;
|
|
@@ -2948,14 +3211,14 @@ var useRAGEvaluate = (path) => {
|
|
|
2948
3211
|
};
|
|
2949
3212
|
|
|
2950
3213
|
// src/vue/ai/useRAGGrounding.ts
|
|
2951
|
-
import { computed as
|
|
3214
|
+
import { computed as computed4 } from "vue";
|
|
2952
3215
|
var useRAGGrounding = (content, sources) => {
|
|
2953
|
-
const groundedAnswer =
|
|
2954
|
-
const references =
|
|
2955
|
-
const hasCitations =
|
|
2956
|
-
const hasGrounding =
|
|
2957
|
-
const coverage =
|
|
2958
|
-
const ungroundedReferenceNumbers =
|
|
3216
|
+
const groundedAnswer = computed4(() => buildRAGGroundedAnswer(content.value, sources.value));
|
|
3217
|
+
const references = computed4(() => buildRAGGroundingReferences(sources.value));
|
|
3218
|
+
const hasCitations = computed4(() => groundedAnswer.value.hasCitations);
|
|
3219
|
+
const hasGrounding = computed4(() => references.value.length > 0);
|
|
3220
|
+
const coverage = computed4(() => groundedAnswer.value.coverage);
|
|
3221
|
+
const ungroundedReferenceNumbers = computed4(() => groundedAnswer.value.ungroundedReferenceNumbers);
|
|
2959
3222
|
return {
|
|
2960
3223
|
coverage,
|
|
2961
3224
|
groundedAnswer,
|
|
@@ -3366,18 +3629,22 @@ var useRAGSearch = (path) => {
|
|
|
3366
3629
|
};
|
|
3367
3630
|
|
|
3368
3631
|
// src/vue/ai/useRAGSources.ts
|
|
3369
|
-
import { computed as
|
|
3632
|
+
import { computed as computed5 } from "vue";
|
|
3370
3633
|
var useRAGSources = (messages) => {
|
|
3371
|
-
const latestAssistantMessage =
|
|
3372
|
-
const sources =
|
|
3373
|
-
const sourceGroups =
|
|
3374
|
-
const sourceSummaries =
|
|
3375
|
-
const
|
|
3376
|
-
const
|
|
3634
|
+
const latestAssistantMessage = computed5(() => getLatestAssistantMessage(messages.value));
|
|
3635
|
+
const sources = computed5(() => getLatestRAGSources(messages.value));
|
|
3636
|
+
const sourceGroups = computed5(() => buildRAGSourceGroups(sources.value));
|
|
3637
|
+
const sourceSummaries = computed5(() => buildRAGSourceSummaries(sources.value));
|
|
3638
|
+
const chunkGraph = computed5(() => buildRAGChunkGraph(sources.value));
|
|
3639
|
+
const citationReferenceMap = computed5(() => buildRAGCitationReferenceMap(sourceSummaries.value.flatMap((summary) => summary.citations)));
|
|
3640
|
+
const hasSources = computed5(() => sources.value.length > 0);
|
|
3641
|
+
const navigationForChunk = (chunkId) => buildRAGChunkGraphNavigation(chunkGraph.value, chunkId ?? undefined);
|
|
3377
3642
|
return {
|
|
3378
3643
|
citationReferenceMap,
|
|
3644
|
+
chunkGraph,
|
|
3379
3645
|
hasSources,
|
|
3380
3646
|
latestAssistantMessage,
|
|
3647
|
+
navigationForChunk,
|
|
3381
3648
|
sourceGroups,
|
|
3382
3649
|
sources,
|
|
3383
3650
|
sourceSummaries
|
|
@@ -3431,14 +3698,14 @@ var useRAGStatus = (path, autoLoad = true) => {
|
|
|
3431
3698
|
};
|
|
3432
3699
|
|
|
3433
3700
|
// src/vue/ai/useRAGWorkflow.ts
|
|
3434
|
-
import { computed as
|
|
3701
|
+
import { computed as computed8 } from "vue";
|
|
3435
3702
|
|
|
3436
3703
|
// src/vue/ai/useRAGStream.ts
|
|
3437
|
-
import { computed as
|
|
3704
|
+
import { computed as computed7 } from "vue";
|
|
3438
3705
|
|
|
3439
3706
|
// src/vue/ai/useRAGStreamProgress.ts
|
|
3440
|
-
import { computed as
|
|
3441
|
-
var useRAGStreamProgress = (params) =>
|
|
3707
|
+
import { computed as computed6 } from "vue";
|
|
3708
|
+
var useRAGStreamProgress = (params) => computed6(() => buildRAGStreamProgress({
|
|
3442
3709
|
error: params.error.value,
|
|
3443
3710
|
isStreaming: params.isStreaming.value,
|
|
3444
3711
|
messages: params.messages.value
|
|
@@ -3447,7 +3714,7 @@ var useRAGStreamProgress = (params) => computed5(() => buildRAGStreamProgress({
|
|
|
3447
3714
|
// src/vue/ai/useRAGStream.ts
|
|
3448
3715
|
var useRAGStream = (path, conversationId) => {
|
|
3449
3716
|
const stream = useAIStream(path, conversationId);
|
|
3450
|
-
const workflow =
|
|
3717
|
+
const workflow = computed7(() => buildRAGAnswerWorkflowState({
|
|
3451
3718
|
error: stream.error.value,
|
|
3452
3719
|
isStreaming: stream.isStreaming.value,
|
|
3453
3720
|
messages: stream.messages.value
|
|
@@ -3460,37 +3727,37 @@ var useRAGStream = (path, conversationId) => {
|
|
|
3460
3727
|
const query = (content, attachments) => {
|
|
3461
3728
|
stream.send(content, attachments);
|
|
3462
3729
|
};
|
|
3463
|
-
const hasRetrieved =
|
|
3464
|
-
const isRetrieving =
|
|
3465
|
-
const isRetrieved =
|
|
3466
|
-
const isAnswerStreaming =
|
|
3467
|
-
const isComplete =
|
|
3468
|
-
const hasSources =
|
|
3730
|
+
const hasRetrieved = computed7(() => workflow.value.hasRetrieved);
|
|
3731
|
+
const isRetrieving = computed7(() => workflow.value.isRetrieving);
|
|
3732
|
+
const isRetrieved = computed7(() => workflow.value.isRetrieved);
|
|
3733
|
+
const isAnswerStreaming = computed7(() => workflow.value.isAnswerStreaming);
|
|
3734
|
+
const isComplete = computed7(() => workflow.value.isComplete);
|
|
3735
|
+
const hasSources = computed7(() => workflow.value.hasSources);
|
|
3469
3736
|
return {
|
|
3470
3737
|
...stream,
|
|
3471
|
-
citationReferenceMap:
|
|
3472
|
-
citations:
|
|
3473
|
-
coverage:
|
|
3474
|
-
groundedAnswer:
|
|
3475
|
-
groundingReferences:
|
|
3476
|
-
hasGrounding:
|
|
3738
|
+
citationReferenceMap: computed7(() => workflow.value.citationReferenceMap),
|
|
3739
|
+
citations: computed7(() => workflow.value.citations),
|
|
3740
|
+
coverage: computed7(() => workflow.value.coverage),
|
|
3741
|
+
groundedAnswer: computed7(() => workflow.value.groundedAnswer),
|
|
3742
|
+
groundingReferences: computed7(() => workflow.value.groundingReferences),
|
|
3743
|
+
hasGrounding: computed7(() => workflow.value.hasGrounding),
|
|
3477
3744
|
hasRetrieved,
|
|
3478
3745
|
hasSources,
|
|
3479
3746
|
isAnswerStreaming,
|
|
3480
3747
|
isComplete,
|
|
3481
|
-
isError:
|
|
3748
|
+
isError: computed7(() => workflow.value.isError),
|
|
3482
3749
|
isRetrieved,
|
|
3483
3750
|
isRetrieving,
|
|
3484
|
-
isRunning:
|
|
3485
|
-
latestAssistantMessage:
|
|
3751
|
+
isRunning: computed7(() => workflow.value.isRunning),
|
|
3752
|
+
latestAssistantMessage: computed7(() => workflow.value.latestAssistantMessage),
|
|
3486
3753
|
progress,
|
|
3487
3754
|
query,
|
|
3488
|
-
retrieval:
|
|
3489
|
-
sourceGroups:
|
|
3490
|
-
sourceSummaries:
|
|
3491
|
-
sources:
|
|
3492
|
-
stage:
|
|
3493
|
-
ungroundedReferenceNumbers:
|
|
3755
|
+
retrieval: computed7(() => workflow.value.retrieval),
|
|
3756
|
+
sourceGroups: computed7(() => workflow.value.sourceGroups),
|
|
3757
|
+
sourceSummaries: computed7(() => workflow.value.sourceSummaries),
|
|
3758
|
+
sources: computed7(() => workflow.value.sources),
|
|
3759
|
+
stage: computed7(() => workflow.value.stage),
|
|
3760
|
+
ungroundedReferenceNumbers: computed7(() => workflow.value.ungroundedReferenceNumbers),
|
|
3494
3761
|
workflow
|
|
3495
3762
|
};
|
|
3496
3763
|
};
|
|
@@ -3498,7 +3765,7 @@ var useRAGStream = (path, conversationId) => {
|
|
|
3498
3765
|
// src/vue/ai/useRAGWorkflow.ts
|
|
3499
3766
|
var useRAGWorkflow = (path, conversationId) => {
|
|
3500
3767
|
const stream = useRAGStream(path, conversationId);
|
|
3501
|
-
const state =
|
|
3768
|
+
const state = computed8(() => stream.workflow.value);
|
|
3502
3769
|
return {
|
|
3503
3770
|
...stream,
|
|
3504
3771
|
state
|
|
@@ -3518,7 +3785,7 @@ var useRAG = (path, options = {}) => {
|
|
|
3518
3785
|
const workflow = useRAGWorkflow(options.streamPath ?? path, options.conversationId);
|
|
3519
3786
|
const sources = useRAGSources(workflow.messages);
|
|
3520
3787
|
const citations = useRAGCitations(sources.sources);
|
|
3521
|
-
const grounding = useRAGGrounding(
|
|
3788
|
+
const grounding = useRAGGrounding(computed9(() => workflow.latestAssistantMessage.value?.content ?? ""), sources.sources);
|
|
3522
3789
|
return {
|
|
3523
3790
|
chunkPreview,
|
|
3524
3791
|
citations,
|