@absolutejs/absolute 0.19.0-beta.603 → 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 +244 -10
- package/dist/ai/client/index.js.map +4 -4
- package/dist/ai/client/ui.js +248 -10
- package/dist/ai/client/ui.js.map +4 -4
- package/dist/ai/index.js +1003 -110
- package/dist/ai/index.js.map +8 -8
- package/dist/ai/rag/quality.js +27 -6
- package/dist/ai/rag/quality.js.map +3 -3
- package/dist/ai/rag/ui.js +248 -10
- package/dist/ai/rag/ui.js.map +4 -4
- package/dist/ai-client/angular/ai/index.js +243 -9
- package/dist/ai-client/react/ai/index.js +258 -10
- package/dist/ai-client/vue/ai/index.js +347 -101
- package/dist/angular/ai/index.js +244 -10
- package/dist/angular/ai/index.js.map +4 -4
- package/dist/react/ai/index.js +259 -11
- 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 +12 -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 +125 -0
- package/dist/src/vue/ai/useRAGChunkPreview.d.ts +54 -0
- package/dist/src/vue/ai/useRAGDocuments.d.ts +20 -0
- package/dist/src/vue/ai/useRAGIndexAdmin.d.ts +10 -0
- package/dist/src/vue/ai/useRAGSearch.d.ts +40 -0
- package/dist/src/vue/ai/useRAGSources.d.ts +1 -0
- package/dist/svelte/ai/index.js +305 -57
- package/dist/svelte/ai/index.js.map +6 -6
- package/dist/types/ai.d.ts +102 -1
- package/dist/vue/ai/index.js +311 -63
- package/dist/vue/ai/index.js.map +6 -6
- package/package.json +1 -1
package/dist/svelte/ai/index.js
CHANGED
|
@@ -216,6 +216,10 @@ var buildContextLabel = (metadata) => {
|
|
|
216
216
|
return from ? `Message from ${from}` : "Message evidence";
|
|
217
217
|
}
|
|
218
218
|
const page = getContextNumber(metadata.page) ?? getContextNumber(metadata.pageNumber) ?? (typeof metadata.pageIndex === "number" ? metadata.pageIndex + 1 : undefined);
|
|
219
|
+
const region = getContextNumber(metadata.regionNumber) ?? (typeof metadata.regionIndex === "number" ? metadata.regionIndex + 1 : undefined);
|
|
220
|
+
if (page && region) {
|
|
221
|
+
return `Page ${page} region ${region}`;
|
|
222
|
+
}
|
|
219
223
|
if (page) {
|
|
220
224
|
return `Page ${page}`;
|
|
221
225
|
}
|
|
@@ -239,6 +243,11 @@ var buildContextLabel = (metadata) => {
|
|
|
239
243
|
if (speaker) {
|
|
240
244
|
return `Speaker ${speaker}`;
|
|
241
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
|
+
}
|
|
242
251
|
return;
|
|
243
252
|
};
|
|
244
253
|
var formatMediaTimestamp = (value) => {
|
|
@@ -256,6 +265,10 @@ var buildLocatorLabel = (metadata, source, title) => {
|
|
|
256
265
|
return;
|
|
257
266
|
}
|
|
258
267
|
const page = getContextNumber(metadata.page) ?? getContextNumber(metadata.pageNumber) ?? (typeof metadata.pageIndex === "number" ? metadata.pageIndex + 1 : undefined);
|
|
268
|
+
const region = getContextNumber(metadata.regionNumber) ?? (typeof metadata.regionIndex === "number" ? metadata.regionIndex + 1 : undefined);
|
|
269
|
+
if (page && region) {
|
|
270
|
+
return `Page ${page} \xB7 Region ${region}`;
|
|
271
|
+
}
|
|
259
272
|
if (page) {
|
|
260
273
|
return `Page ${page}`;
|
|
261
274
|
}
|
|
@@ -284,6 +297,10 @@ var buildLocatorLabel = (metadata, source, title) => {
|
|
|
284
297
|
if (mediaStart) {
|
|
285
298
|
return `Timestamp ${mediaStart}`;
|
|
286
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
|
+
}
|
|
287
304
|
return;
|
|
288
305
|
};
|
|
289
306
|
var formatTimestampLabel = (value) => {
|
|
@@ -308,9 +325,11 @@ var buildProvenanceLabel = (metadata) => {
|
|
|
308
325
|
const transcriptSource = getContextString(metadata.transcriptSource);
|
|
309
326
|
const pdfTextMode = getContextString(metadata.pdfTextMode);
|
|
310
327
|
const ocrEngine = getContextString(metadata.ocrEngine);
|
|
328
|
+
const ocrConfidence = getContextNumber(metadata.ocrRegionConfidence) ?? getContextNumber(metadata.ocrConfidence);
|
|
311
329
|
const labels = [
|
|
312
330
|
pdfTextMode ? `PDF ${pdfTextMode}` : "",
|
|
313
331
|
ocrEngine ? `OCR ${ocrEngine}` : "",
|
|
332
|
+
typeof ocrConfidence === "number" ? `Confidence ${ocrConfidence.toFixed(2)}` : "",
|
|
314
333
|
mediaKind ? `Media ${mediaKind}` : "",
|
|
315
334
|
transcriptSource ? `Transcript ${transcriptSource}` : "",
|
|
316
335
|
threadTopic ? `Thread ${threadTopic}` : "",
|
|
@@ -331,8 +350,10 @@ var buildExcerpt = (text, maxLength = 160) => {
|
|
|
331
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 ");
|
|
332
351
|
var buildGroundingReferenceEvidenceSummary = (reference) => [
|
|
333
352
|
reference.source ?? reference.title ?? reference.chunkId,
|
|
353
|
+
reference.locatorLabel,
|
|
354
|
+
reference.contextLabel,
|
|
334
355
|
reference.provenanceLabel
|
|
335
|
-
].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 ");
|
|
336
357
|
var buildGroundedAnswerCitationDetail = (reference) => ({
|
|
337
358
|
contextLabel: reference.contextLabel,
|
|
338
359
|
evidenceLabel: buildGroundingReferenceEvidenceLabel(reference),
|
|
@@ -356,12 +377,12 @@ var buildRAGCitations = (sources) => {
|
|
|
356
377
|
continue;
|
|
357
378
|
unique.set(key, {
|
|
358
379
|
chunkId: source.chunkId,
|
|
359
|
-
contextLabel: buildContextLabel(source.metadata),
|
|
380
|
+
contextLabel: source.labels?.contextLabel ?? buildContextLabel(source.metadata),
|
|
360
381
|
key,
|
|
361
382
|
label: buildSourceLabel(source),
|
|
362
|
-
locatorLabel: buildLocatorLabel(source.metadata, source.source, source.title),
|
|
383
|
+
locatorLabel: source.labels?.locatorLabel ?? buildLocatorLabel(source.metadata, source.source, source.title),
|
|
363
384
|
metadata: source.metadata,
|
|
364
|
-
provenanceLabel: buildProvenanceLabel(source.metadata),
|
|
385
|
+
provenanceLabel: source.labels?.provenanceLabel ?? buildProvenanceLabel(source.metadata),
|
|
365
386
|
score: source.score,
|
|
366
387
|
source: source.source,
|
|
367
388
|
text: source.text,
|
|
@@ -431,7 +452,7 @@ var buildRAGGroundingReferences = (sources) => {
|
|
|
431
452
|
const citationReferenceMap = buildRAGCitationReferenceMap(citations);
|
|
432
453
|
return citations.map((citation) => ({
|
|
433
454
|
chunkId: citation.chunkId,
|
|
434
|
-
contextLabel: buildContextLabel(citation.metadata),
|
|
455
|
+
contextLabel: citation.contextLabel ?? buildContextLabel(citation.metadata),
|
|
435
456
|
excerpt: buildExcerpt(citation.text),
|
|
436
457
|
label: citation.label,
|
|
437
458
|
locatorLabel: citation.locatorLabel ?? buildLocatorLabel(citation.metadata, citation.source, citation.title),
|
|
@@ -3977,6 +3998,10 @@ var buildContextLabel2 = (metadata) => {
|
|
|
3977
3998
|
return from ? `Message from ${from}` : "Message evidence";
|
|
3978
3999
|
}
|
|
3979
4000
|
const page = getContextNumber2(metadata.page) ?? getContextNumber2(metadata.pageNumber) ?? (typeof metadata.pageIndex === "number" ? metadata.pageIndex + 1 : undefined);
|
|
4001
|
+
const region = getContextNumber2(metadata.regionNumber) ?? (typeof metadata.regionIndex === "number" ? metadata.regionIndex + 1 : undefined);
|
|
4002
|
+
if (page && region) {
|
|
4003
|
+
return `Page ${page} region ${region}`;
|
|
4004
|
+
}
|
|
3980
4005
|
if (page) {
|
|
3981
4006
|
return `Page ${page}`;
|
|
3982
4007
|
}
|
|
@@ -4000,6 +4025,11 @@ var buildContextLabel2 = (metadata) => {
|
|
|
4000
4025
|
if (speaker) {
|
|
4001
4026
|
return `Speaker ${speaker}`;
|
|
4002
4027
|
}
|
|
4028
|
+
const sectionPath = Array.isArray(metadata.sectionPath) ? metadata.sectionPath.map((value) => getContextString2(value)).filter((value) => typeof value === "string") : [];
|
|
4029
|
+
const sectionTitle = getContextString2(metadata.sectionTitle) ?? sectionPath.at(-1);
|
|
4030
|
+
if (sectionTitle) {
|
|
4031
|
+
return `Section ${sectionTitle}`;
|
|
4032
|
+
}
|
|
4003
4033
|
return;
|
|
4004
4034
|
};
|
|
4005
4035
|
var buildLocatorLabel2 = (metadata, source, title) => {
|
|
@@ -4007,6 +4037,10 @@ var buildLocatorLabel2 = (metadata, source, title) => {
|
|
|
4007
4037
|
return;
|
|
4008
4038
|
}
|
|
4009
4039
|
const page = getContextNumber2(metadata.page) ?? getContextNumber2(metadata.pageNumber) ?? (typeof metadata.pageIndex === "number" ? metadata.pageIndex + 1 : undefined);
|
|
4040
|
+
const region = getContextNumber2(metadata.regionNumber) ?? (typeof metadata.regionIndex === "number" ? metadata.regionIndex + 1 : undefined);
|
|
4041
|
+
if (page && region) {
|
|
4042
|
+
return `Page ${page} \xB7 Region ${region}`;
|
|
4043
|
+
}
|
|
4010
4044
|
if (page) {
|
|
4011
4045
|
return `Page ${page}`;
|
|
4012
4046
|
}
|
|
@@ -4035,6 +4069,10 @@ var buildLocatorLabel2 = (metadata, source, title) => {
|
|
|
4035
4069
|
if (mediaStart) {
|
|
4036
4070
|
return `Timestamp ${mediaStart}`;
|
|
4037
4071
|
}
|
|
4072
|
+
const sectionPath = Array.isArray(metadata.sectionPath) ? metadata.sectionPath.map((value) => getContextString2(value)).filter((value) => typeof value === "string") : [];
|
|
4073
|
+
if (sectionPath.length > 0) {
|
|
4074
|
+
return `Section ${sectionPath.join(" > ")}`;
|
|
4075
|
+
}
|
|
4038
4076
|
return;
|
|
4039
4077
|
};
|
|
4040
4078
|
var buildProvenanceLabel2 = (metadata) => {
|
|
@@ -4049,9 +4087,11 @@ var buildProvenanceLabel2 = (metadata) => {
|
|
|
4049
4087
|
const transcriptSource = getContextString2(metadata.transcriptSource);
|
|
4050
4088
|
const pdfTextMode = getContextString2(metadata.pdfTextMode);
|
|
4051
4089
|
const ocrEngine = getContextString2(metadata.ocrEngine);
|
|
4090
|
+
const ocrConfidence = getContextNumber2(metadata.ocrRegionConfidence) ?? getContextNumber2(metadata.ocrConfidence);
|
|
4052
4091
|
const labels = [
|
|
4053
4092
|
pdfTextMode ? `PDF ${pdfTextMode}` : "",
|
|
4054
4093
|
ocrEngine ? `OCR ${ocrEngine}` : "",
|
|
4094
|
+
typeof ocrConfidence === "number" ? `Confidence ${ocrConfidence.toFixed(2)}` : "",
|
|
4055
4095
|
mediaKind ? `Media ${mediaKind}` : "",
|
|
4056
4096
|
transcriptSource ? `Transcript ${transcriptSource}` : "",
|
|
4057
4097
|
threadTopic ? `Thread ${threadTopic}` : "",
|
|
@@ -4061,6 +4101,50 @@ var buildProvenanceLabel2 = (metadata) => {
|
|
|
4061
4101
|
].filter((value) => value.length > 0);
|
|
4062
4102
|
return labels.length > 0 ? labels.join(" \xB7 ") : undefined;
|
|
4063
4103
|
};
|
|
4104
|
+
var buildRAGSourceLabels = ({
|
|
4105
|
+
metadata,
|
|
4106
|
+
source,
|
|
4107
|
+
title
|
|
4108
|
+
}) => {
|
|
4109
|
+
const contextLabel = buildContextLabel2(metadata);
|
|
4110
|
+
const locatorLabel = buildLocatorLabel2(metadata, source, title);
|
|
4111
|
+
const provenanceLabel = buildProvenanceLabel2(metadata);
|
|
4112
|
+
if (!contextLabel && !locatorLabel && !provenanceLabel) {
|
|
4113
|
+
return;
|
|
4114
|
+
}
|
|
4115
|
+
return {
|
|
4116
|
+
contextLabel,
|
|
4117
|
+
locatorLabel,
|
|
4118
|
+
provenanceLabel
|
|
4119
|
+
};
|
|
4120
|
+
};
|
|
4121
|
+
var buildRAGChunkStructure = (metadata) => {
|
|
4122
|
+
if (!metadata) {
|
|
4123
|
+
return;
|
|
4124
|
+
}
|
|
4125
|
+
const sectionPath = Array.isArray(metadata.sectionPath) ? metadata.sectionPath.filter((value) => typeof value === "string" && value.trim().length > 0) : undefined;
|
|
4126
|
+
const sectionKind = metadata.sectionKind === "markdown_heading" || metadata.sectionKind === "html_heading" ? metadata.sectionKind : undefined;
|
|
4127
|
+
const section = {
|
|
4128
|
+
depth: getContextNumber2(metadata.sectionDepth),
|
|
4129
|
+
kind: sectionKind,
|
|
4130
|
+
path: sectionPath && sectionPath.length > 0 ? sectionPath : undefined,
|
|
4131
|
+
title: getContextString2(metadata.sectionTitle)
|
|
4132
|
+
};
|
|
4133
|
+
const sequence = {
|
|
4134
|
+
nextChunkId: getContextString2(metadata.nextChunkId),
|
|
4135
|
+
previousChunkId: getContextString2(metadata.previousChunkId),
|
|
4136
|
+
sectionChunkCount: getContextNumber2(metadata.sectionChunkCount),
|
|
4137
|
+
sectionChunkId: getContextString2(metadata.sectionChunkId),
|
|
4138
|
+
sectionChunkIndex: getContextNumber2(metadata.sectionChunkIndex)
|
|
4139
|
+
};
|
|
4140
|
+
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") {
|
|
4141
|
+
return;
|
|
4142
|
+
}
|
|
4143
|
+
return {
|
|
4144
|
+
section: section.title || section.path && section.path.length > 0 || typeof section.depth === "number" || section.kind ? section : undefined,
|
|
4145
|
+
sequence: sequence.nextChunkId || sequence.previousChunkId || typeof sequence.sectionChunkCount === "number" || sequence.sectionChunkId || typeof sequence.sectionChunkIndex === "number" ? sequence : undefined
|
|
4146
|
+
};
|
|
4147
|
+
};
|
|
4064
4148
|
var buildExcerpt2 = (text, maxLength = 160) => {
|
|
4065
4149
|
const normalized = text.replaceAll(/\s+/g, " ").trim();
|
|
4066
4150
|
if (normalized.length <= maxLength) {
|
|
@@ -4068,6 +4152,136 @@ var buildExcerpt2 = (text, maxLength = 160) => {
|
|
|
4068
4152
|
}
|
|
4069
4153
|
return `${normalized.slice(0, Math.max(0, maxLength - 1)).trimEnd()}\u2026`;
|
|
4070
4154
|
};
|
|
4155
|
+
var buildRAGChunkGraph = (chunks) => {
|
|
4156
|
+
const nodes = [];
|
|
4157
|
+
const edges = [];
|
|
4158
|
+
const edgeKeys = new Set;
|
|
4159
|
+
const sections = new Map;
|
|
4160
|
+
for (const chunk of chunks) {
|
|
4161
|
+
const labels = chunk.labels ?? buildRAGSourceLabels({
|
|
4162
|
+
metadata: chunk.metadata,
|
|
4163
|
+
source: chunk.source,
|
|
4164
|
+
title: chunk.title
|
|
4165
|
+
});
|
|
4166
|
+
const structure = chunk.structure ?? buildRAGChunkStructure(chunk.metadata);
|
|
4167
|
+
nodes.push({
|
|
4168
|
+
chunkId: chunk.chunkId,
|
|
4169
|
+
contextLabel: labels?.contextLabel,
|
|
4170
|
+
label: chunk.source ?? chunk.title ?? chunk.chunkId,
|
|
4171
|
+
locatorLabel: labels?.locatorLabel,
|
|
4172
|
+
provenanceLabel: labels?.provenanceLabel,
|
|
4173
|
+
score: chunk.score,
|
|
4174
|
+
source: chunk.source,
|
|
4175
|
+
structure,
|
|
4176
|
+
title: chunk.title
|
|
4177
|
+
});
|
|
4178
|
+
const previousChunkId = structure?.sequence?.previousChunkId;
|
|
4179
|
+
if (previousChunkId) {
|
|
4180
|
+
const key = `previous:${previousChunkId}:${chunk.chunkId}`;
|
|
4181
|
+
if (!edgeKeys.has(key)) {
|
|
4182
|
+
edgeKeys.add(key);
|
|
4183
|
+
edges.push({
|
|
4184
|
+
fromChunkId: previousChunkId,
|
|
4185
|
+
relation: "previous",
|
|
4186
|
+
toChunkId: chunk.chunkId
|
|
4187
|
+
});
|
|
4188
|
+
}
|
|
4189
|
+
}
|
|
4190
|
+
const nextChunkId = structure?.sequence?.nextChunkId;
|
|
4191
|
+
if (nextChunkId) {
|
|
4192
|
+
const key = `next:${chunk.chunkId}:${nextChunkId}`;
|
|
4193
|
+
if (!edgeKeys.has(key)) {
|
|
4194
|
+
edgeKeys.add(key);
|
|
4195
|
+
edges.push({
|
|
4196
|
+
fromChunkId: chunk.chunkId,
|
|
4197
|
+
relation: "next",
|
|
4198
|
+
toChunkId: nextChunkId
|
|
4199
|
+
});
|
|
4200
|
+
}
|
|
4201
|
+
}
|
|
4202
|
+
const sectionId = structure?.sequence?.sectionChunkId;
|
|
4203
|
+
if (sectionId) {
|
|
4204
|
+
const existing = sections.get(sectionId);
|
|
4205
|
+
if (!existing) {
|
|
4206
|
+
sections.set(sectionId, {
|
|
4207
|
+
chunkCount: structure.sequence?.sectionChunkCount ?? 1,
|
|
4208
|
+
chunkIds: [chunk.chunkId],
|
|
4209
|
+
depth: structure.section?.depth,
|
|
4210
|
+
id: sectionId,
|
|
4211
|
+
kind: structure.section?.kind,
|
|
4212
|
+
path: structure.section?.path,
|
|
4213
|
+
title: structure.section?.title
|
|
4214
|
+
});
|
|
4215
|
+
continue;
|
|
4216
|
+
}
|
|
4217
|
+
if (!existing.chunkIds.includes(chunk.chunkId)) {
|
|
4218
|
+
existing.chunkIds.push(chunk.chunkId);
|
|
4219
|
+
}
|
|
4220
|
+
existing.chunkCount = Math.max(existing.chunkCount, structure.sequence?.sectionChunkCount ?? existing.chunkCount);
|
|
4221
|
+
}
|
|
4222
|
+
}
|
|
4223
|
+
for (const section of sections.values()) {
|
|
4224
|
+
section.chunkIds.sort((left, right) => {
|
|
4225
|
+
const leftNode = nodes.find((node) => node.chunkId === left);
|
|
4226
|
+
const rightNode = nodes.find((node) => node.chunkId === right);
|
|
4227
|
+
const leftIndex = leftNode?.structure?.sequence?.sectionChunkIndex ?? Number.MAX_SAFE_INTEGER;
|
|
4228
|
+
const rightIndex = rightNode?.structure?.sequence?.sectionChunkIndex ?? Number.MAX_SAFE_INTEGER;
|
|
4229
|
+
if (leftIndex !== rightIndex) {
|
|
4230
|
+
return leftIndex - rightIndex;
|
|
4231
|
+
}
|
|
4232
|
+
return left.localeCompare(right);
|
|
4233
|
+
});
|
|
4234
|
+
}
|
|
4235
|
+
nodes.sort((left, right) => {
|
|
4236
|
+
const leftSection = left.structure?.sequence?.sectionChunkIndex ?? Number.MAX_SAFE_INTEGER;
|
|
4237
|
+
const rightSection = right.structure?.sequence?.sectionChunkIndex ?? Number.MAX_SAFE_INTEGER;
|
|
4238
|
+
if (leftSection !== rightSection) {
|
|
4239
|
+
return leftSection - rightSection;
|
|
4240
|
+
}
|
|
4241
|
+
const leftScore = left.score ?? Number.NEGATIVE_INFINITY;
|
|
4242
|
+
const rightScore = right.score ?? Number.NEGATIVE_INFINITY;
|
|
4243
|
+
if (leftScore !== rightScore) {
|
|
4244
|
+
return rightScore - leftScore;
|
|
4245
|
+
}
|
|
4246
|
+
return left.label.localeCompare(right.label);
|
|
4247
|
+
});
|
|
4248
|
+
return {
|
|
4249
|
+
edges,
|
|
4250
|
+
nodes,
|
|
4251
|
+
sections: [...sections.values()].sort((left, right) => (left.title ?? left.id).localeCompare(right.title ?? right.id))
|
|
4252
|
+
};
|
|
4253
|
+
};
|
|
4254
|
+
var buildRAGChunkPreviewGraph = (preview) => buildRAGChunkGraph(preview.chunks.map((chunk) => ({
|
|
4255
|
+
chunkId: chunk.chunkId,
|
|
4256
|
+
labels: chunk.labels,
|
|
4257
|
+
metadata: chunk.metadata,
|
|
4258
|
+
source: chunk.source ?? preview.document.source,
|
|
4259
|
+
structure: chunk.structure,
|
|
4260
|
+
title: chunk.title ?? preview.document.title
|
|
4261
|
+
})));
|
|
4262
|
+
var buildRAGChunkPreviewNavigation = (preview, activeChunkId) => buildRAGChunkGraphNavigation(buildRAGChunkPreviewGraph(preview), activeChunkId);
|
|
4263
|
+
var buildRAGChunkGraphNavigation = (graph, activeChunkId) => {
|
|
4264
|
+
if (graph.nodes.length === 0) {
|
|
4265
|
+
return {
|
|
4266
|
+
activeChunkId,
|
|
4267
|
+
sectionNodes: []
|
|
4268
|
+
};
|
|
4269
|
+
}
|
|
4270
|
+
const activeNode = (activeChunkId ? graph.nodes.find((node) => node.chunkId === activeChunkId) : undefined) ?? graph.nodes[0];
|
|
4271
|
+
const resolvedActiveChunkId = activeNode?.chunkId;
|
|
4272
|
+
const previousNode = activeNode?.structure?.sequence?.previousChunkId ? graph.nodes.find((node) => node.chunkId === activeNode.structure?.sequence?.previousChunkId) : undefined;
|
|
4273
|
+
const nextNode = activeNode?.structure?.sequence?.nextChunkId ? graph.nodes.find((node) => node.chunkId === activeNode.structure?.sequence?.nextChunkId) : undefined;
|
|
4274
|
+
const section = activeNode?.structure?.sequence?.sectionChunkId ? graph.sections.find((entry) => entry.id === activeNode.structure?.sequence?.sectionChunkId) : undefined;
|
|
4275
|
+
const sectionNodes = section ? section.chunkIds.map((chunkId) => graph.nodes.find((node) => node.chunkId === chunkId)).filter((node) => Boolean(node)) : activeNode ? [activeNode] : [];
|
|
4276
|
+
return {
|
|
4277
|
+
activeChunkId: resolvedActiveChunkId,
|
|
4278
|
+
activeNode,
|
|
4279
|
+
nextNode,
|
|
4280
|
+
previousNode,
|
|
4281
|
+
section,
|
|
4282
|
+
sectionNodes
|
|
4283
|
+
};
|
|
4284
|
+
};
|
|
4071
4285
|
var buildRAGRetrievedState = (messages) => {
|
|
4072
4286
|
const message = getLatestRetrievedMessage(messages);
|
|
4073
4287
|
if (!message) {
|
|
@@ -4102,13 +4316,14 @@ var buildRAGSourceSummaries = (sources) => {
|
|
|
4102
4316
|
citationNumbers: groupCitations.map((citation) => citationReferenceMap[citation.chunkId] ?? 0),
|
|
4103
4317
|
citations: groupCitations,
|
|
4104
4318
|
chunkIds: group.chunks.map((chunk) => chunk.chunkId),
|
|
4105
|
-
contextLabel: buildContextLabel2(leadChunk?.metadata),
|
|
4319
|
+
contextLabel: leadChunk?.labels?.contextLabel ?? buildContextLabel2(leadChunk?.metadata),
|
|
4106
4320
|
count: group.count,
|
|
4107
4321
|
excerpt: buildExcerpt2(leadChunk?.text ?? ""),
|
|
4108
4322
|
key: group.key,
|
|
4109
4323
|
label: group.label,
|
|
4110
|
-
locatorLabel: buildLocatorLabel2(leadChunk?.metadata, leadChunk?.source, leadChunk?.title),
|
|
4111
|
-
provenanceLabel: buildProvenanceLabel2(leadChunk?.metadata),
|
|
4324
|
+
locatorLabel: leadChunk?.labels?.locatorLabel ?? buildLocatorLabel2(leadChunk?.metadata, leadChunk?.source, leadChunk?.title),
|
|
4325
|
+
provenanceLabel: leadChunk?.labels?.provenanceLabel ?? buildProvenanceLabel2(leadChunk?.metadata),
|
|
4326
|
+
structure: leadChunk?.structure ?? buildRAGChunkStructure(leadChunk?.metadata),
|
|
4112
4327
|
source: group.source,
|
|
4113
4328
|
title: group.title
|
|
4114
4329
|
};
|
|
@@ -4232,6 +4447,12 @@ var buildSourceGroup = (source, key) => ({
|
|
|
4232
4447
|
count: 1,
|
|
4233
4448
|
key,
|
|
4234
4449
|
label: buildSourceLabel2(source),
|
|
4450
|
+
labels: source.labels ?? buildRAGSourceLabels({
|
|
4451
|
+
metadata: source.metadata,
|
|
4452
|
+
source: source.source,
|
|
4453
|
+
title: source.title
|
|
4454
|
+
}),
|
|
4455
|
+
structure: source.structure ?? buildRAGChunkStructure(source.metadata),
|
|
4235
4456
|
source: source.source,
|
|
4236
4457
|
title: source.title
|
|
4237
4458
|
});
|
|
@@ -4242,7 +4463,20 @@ var updateSourceGroup = (groups, source) => {
|
|
|
4242
4463
|
groups.set(key, buildSourceGroup(source, key));
|
|
4243
4464
|
return;
|
|
4244
4465
|
}
|
|
4245
|
-
|
|
4466
|
+
if (source.score > existing.bestScore) {
|
|
4467
|
+
existing.bestScore = source.score;
|
|
4468
|
+
existing.label = buildSourceLabel2(source);
|
|
4469
|
+
existing.labels = source.labels ?? buildRAGSourceLabels({
|
|
4470
|
+
metadata: source.metadata,
|
|
4471
|
+
source: source.source,
|
|
4472
|
+
title: source.title
|
|
4473
|
+
});
|
|
4474
|
+
existing.structure = source.structure ?? buildRAGChunkStructure(source.metadata);
|
|
4475
|
+
existing.source = source.source;
|
|
4476
|
+
existing.title = source.title;
|
|
4477
|
+
} else {
|
|
4478
|
+
existing.bestScore = Math.max(existing.bestScore, source.score);
|
|
4479
|
+
}
|
|
4246
4480
|
existing.count += 1;
|
|
4247
4481
|
existing.chunks.push(source);
|
|
4248
4482
|
};
|
|
@@ -5459,7 +5693,7 @@ var createAIStream = (path, conversationId) => {
|
|
|
5459
5693
|
};
|
|
5460
5694
|
};
|
|
5461
5695
|
// src/svelte/ai/createRAGChunkPreview.ts
|
|
5462
|
-
import { writable } from "svelte/store";
|
|
5696
|
+
import { derived, writable } from "svelte/store";
|
|
5463
5697
|
|
|
5464
5698
|
// src/ai/client/ragClient.ts
|
|
5465
5699
|
init_constants();
|
|
@@ -6537,8 +6771,11 @@ var createRAGClient = (options) => {
|
|
|
6537
6771
|
var createRAGChunkPreview = (path) => {
|
|
6538
6772
|
const client = createRAGClient({ path });
|
|
6539
6773
|
const preview = writable(null);
|
|
6774
|
+
const activeChunkId = writable(null);
|
|
6540
6775
|
const error = writable(null);
|
|
6541
6776
|
const isLoading = writable(false);
|
|
6777
|
+
const chunkGraph = derived(preview, ($preview) => $preview ? buildRAGChunkPreviewGraph($preview) : null);
|
|
6778
|
+
const navigationWithSelection = derived([preview, activeChunkId], ([$preview, $activeChunkId]) => $preview ? buildRAGChunkPreviewNavigation($preview, $activeChunkId ?? undefined) : null);
|
|
6542
6779
|
const inspect = async (id) => {
|
|
6543
6780
|
isLoading.set(true);
|
|
6544
6781
|
error.set(null);
|
|
@@ -6548,6 +6785,7 @@ var createRAGChunkPreview = (path) => {
|
|
|
6548
6785
|
throw new Error(response.error);
|
|
6549
6786
|
}
|
|
6550
6787
|
preview.set(response);
|
|
6788
|
+
activeChunkId.set(response.chunks[0]?.chunkId ?? null);
|
|
6551
6789
|
return response;
|
|
6552
6790
|
} catch (caught) {
|
|
6553
6791
|
error.set(caught instanceof Error ? caught.message : String(caught));
|
|
@@ -6559,25 +6797,33 @@ var createRAGChunkPreview = (path) => {
|
|
|
6559
6797
|
const clear = () => {
|
|
6560
6798
|
error.set(null);
|
|
6561
6799
|
isLoading.set(false);
|
|
6800
|
+
activeChunkId.set(null);
|
|
6562
6801
|
preview.set(null);
|
|
6563
6802
|
};
|
|
6803
|
+
const selectChunk = (id) => {
|
|
6804
|
+
activeChunkId.set(id);
|
|
6805
|
+
};
|
|
6564
6806
|
return {
|
|
6807
|
+
activeChunkId,
|
|
6565
6808
|
clear,
|
|
6809
|
+
chunkGraph,
|
|
6566
6810
|
error,
|
|
6567
6811
|
inspect,
|
|
6568
6812
|
isLoading,
|
|
6569
|
-
|
|
6813
|
+
navigation: navigationWithSelection,
|
|
6814
|
+
preview,
|
|
6815
|
+
selectChunk
|
|
6570
6816
|
};
|
|
6571
6817
|
};
|
|
6572
6818
|
|
|
6573
6819
|
// src/svelte/ai/createRAGCitations.ts
|
|
6574
|
-
import { derived } from "svelte/store";
|
|
6820
|
+
import { derived as derived2 } from "svelte/store";
|
|
6575
6821
|
var createRAGCitations = (sources) => {
|
|
6576
|
-
const citations =
|
|
6577
|
-
const sourceGroups =
|
|
6578
|
-
const sourceSummaries =
|
|
6579
|
-
const citationReferenceMap =
|
|
6580
|
-
const hasCitations =
|
|
6822
|
+
const citations = derived2(sources, ($sources) => buildRAGCitations($sources));
|
|
6823
|
+
const sourceGroups = derived2(sources, ($sources) => buildRAGSourceGroups($sources));
|
|
6824
|
+
const sourceSummaries = derived2(sources, ($sources) => buildRAGSourceSummaries($sources));
|
|
6825
|
+
const citationReferenceMap = derived2(citations, ($citations) => buildRAGCitationReferenceMap($citations));
|
|
6826
|
+
const hasCitations = derived2(citations, ($citations) => $citations.length > 0);
|
|
6581
6827
|
return {
|
|
6582
6828
|
citationReferenceMap,
|
|
6583
6829
|
citations,
|
|
@@ -6627,7 +6873,7 @@ var createRAGDocuments = (path) => {
|
|
|
6627
6873
|
};
|
|
6628
6874
|
|
|
6629
6875
|
// src/svelte/ai/createRAGEvaluate.ts
|
|
6630
|
-
import { derived as
|
|
6876
|
+
import { derived as derived3, writable as writable3 } from "svelte/store";
|
|
6631
6877
|
var createRAGEvaluate = (path) => {
|
|
6632
6878
|
const client = createRAGClient({ path });
|
|
6633
6879
|
const error = writable3(null);
|
|
@@ -6684,7 +6930,7 @@ var createRAGEvaluate = (path) => {
|
|
|
6684
6930
|
const clearRuns = () => {
|
|
6685
6931
|
suiteRuns.set([]);
|
|
6686
6932
|
};
|
|
6687
|
-
const leaderboard =
|
|
6933
|
+
const leaderboard = derived3(suiteRuns, ($suiteRuns) => buildRAGEvaluationLeaderboard($suiteRuns));
|
|
6688
6934
|
const reset = () => {
|
|
6689
6935
|
error.set(null);
|
|
6690
6936
|
lastRequest.set(null);
|
|
@@ -6709,14 +6955,14 @@ var createRAGEvaluate = (path) => {
|
|
|
6709
6955
|
};
|
|
6710
6956
|
|
|
6711
6957
|
// src/svelte/ai/createRAGGrounding.ts
|
|
6712
|
-
import { derived as
|
|
6958
|
+
import { derived as derived4 } from "svelte/store";
|
|
6713
6959
|
var createRAGGrounding = (content, sources) => {
|
|
6714
|
-
const groundedAnswer =
|
|
6715
|
-
const references =
|
|
6716
|
-
const hasCitations =
|
|
6717
|
-
const hasGrounding =
|
|
6718
|
-
const coverage =
|
|
6719
|
-
const ungroundedReferenceNumbers =
|
|
6960
|
+
const groundedAnswer = derived4([content, sources], ([$content, $sources]) => buildRAGGroundedAnswer($content, $sources));
|
|
6961
|
+
const references = derived4(sources, ($sources) => buildRAGGroundingReferences($sources));
|
|
6962
|
+
const hasCitations = derived4(groundedAnswer, ($groundedAnswer) => $groundedAnswer.hasCitations);
|
|
6963
|
+
const hasGrounding = derived4(references, ($references) => $references.length > 0);
|
|
6964
|
+
const coverage = derived4(groundedAnswer, ($groundedAnswer) => $groundedAnswer.coverage);
|
|
6965
|
+
const ungroundedReferenceNumbers = derived4(groundedAnswer, ($groundedAnswer) => $groundedAnswer.ungroundedReferenceNumbers);
|
|
6720
6966
|
return {
|
|
6721
6967
|
coverage,
|
|
6722
6968
|
groundedAnswer,
|
|
@@ -7125,16 +7371,18 @@ var createRAGSearch = (path) => {
|
|
|
7125
7371
|
};
|
|
7126
7372
|
|
|
7127
7373
|
// src/svelte/ai/createRAGSources.ts
|
|
7128
|
-
import { derived as
|
|
7374
|
+
import { derived as derived5 } from "svelte/store";
|
|
7129
7375
|
var createRAGSources = (messages) => {
|
|
7130
|
-
const latestAssistantMessage =
|
|
7131
|
-
const sources =
|
|
7132
|
-
const sourceGroups =
|
|
7133
|
-
const sourceSummaries =
|
|
7134
|
-
const
|
|
7135
|
-
const
|
|
7376
|
+
const latestAssistantMessage = derived5(messages, ($messages) => getLatestAssistantMessage($messages));
|
|
7377
|
+
const sources = derived5(messages, ($messages) => getLatestRAGSources($messages));
|
|
7378
|
+
const sourceGroups = derived5(sources, ($sources) => buildRAGSourceGroups($sources));
|
|
7379
|
+
const sourceSummaries = derived5(sources, ($sources) => buildRAGSourceSummaries($sources));
|
|
7380
|
+
const chunkGraph = derived5(sources, ($sources) => buildRAGChunkGraph($sources));
|
|
7381
|
+
const citationReferenceMap = derived5(sourceSummaries, ($sourceSummaries) => buildRAGCitationReferenceMap($sourceSummaries.flatMap((summary) => summary.citations)));
|
|
7382
|
+
const hasSources = derived5(sources, ($sources) => $sources.length > 0);
|
|
7136
7383
|
return {
|
|
7137
7384
|
citationReferenceMap,
|
|
7385
|
+
chunkGraph,
|
|
7138
7386
|
hasSources,
|
|
7139
7387
|
latestAssistantMessage,
|
|
7140
7388
|
sourceGroups,
|
|
@@ -7188,14 +7436,14 @@ var createRAGStatus = (path, autoLoad = true) => {
|
|
|
7188
7436
|
};
|
|
7189
7437
|
|
|
7190
7438
|
// src/svelte/ai/createRAGWorkflow.ts
|
|
7191
|
-
import { derived as
|
|
7439
|
+
import { derived as derived8 } from "svelte/store";
|
|
7192
7440
|
|
|
7193
7441
|
// src/svelte/ai/createRAGStream.ts
|
|
7194
|
-
import { derived as
|
|
7442
|
+
import { derived as derived7, readable } from "svelte/store";
|
|
7195
7443
|
|
|
7196
7444
|
// src/svelte/ai/createRAGStreamProgress.ts
|
|
7197
|
-
import { derived as
|
|
7198
|
-
var createRAGStreamProgress = (params) =>
|
|
7445
|
+
import { derived as derived6 } from "svelte/store";
|
|
7446
|
+
var createRAGStreamProgress = (params) => derived6([params.error, params.isStreaming, params.messages], ([$error, $isStreaming, $messages]) => buildRAGStreamProgress({
|
|
7199
7447
|
error: $error,
|
|
7200
7448
|
isStreaming: $isStreaming,
|
|
7201
7449
|
messages: $messages
|
|
@@ -7216,7 +7464,7 @@ var createRAGStream = (path, conversationId) => {
|
|
|
7216
7464
|
set(stream.isStreaming);
|
|
7217
7465
|
return stream.subscribe(() => set(stream.isStreaming));
|
|
7218
7466
|
});
|
|
7219
|
-
const workflow =
|
|
7467
|
+
const workflow = derived7([messages, error, isStreaming], ([$messages, $error, $isStreaming]) => buildRAGAnswerWorkflowState({
|
|
7220
7468
|
error: $error,
|
|
7221
7469
|
isStreaming: $isStreaming,
|
|
7222
7470
|
messages: $messages
|
|
@@ -7226,21 +7474,21 @@ var createRAGStream = (path, conversationId) => {
|
|
|
7226
7474
|
isStreaming,
|
|
7227
7475
|
messages
|
|
7228
7476
|
});
|
|
7229
|
-
const latestAssistantMessage =
|
|
7230
|
-
const sources =
|
|
7231
|
-
const sourceGroups =
|
|
7232
|
-
const citations =
|
|
7233
|
-
const sourceSummaries =
|
|
7234
|
-
const retrieval =
|
|
7235
|
-
const groundedAnswer =
|
|
7236
|
-
const groundingReferences =
|
|
7237
|
-
const stage =
|
|
7238
|
-
const hasRetrieved =
|
|
7239
|
-
const hasSources =
|
|
7240
|
-
const isRetrieving =
|
|
7241
|
-
const isRetrieved =
|
|
7242
|
-
const isAnswerStreaming =
|
|
7243
|
-
const isComplete =
|
|
7477
|
+
const latestAssistantMessage = derived7(workflow, ($workflow) => $workflow.latestAssistantMessage);
|
|
7478
|
+
const sources = derived7(workflow, ($workflow) => $workflow.sources);
|
|
7479
|
+
const sourceGroups = derived7(workflow, ($workflow) => $workflow.sourceGroups);
|
|
7480
|
+
const citations = derived7(workflow, ($workflow) => $workflow.citations);
|
|
7481
|
+
const sourceSummaries = derived7(workflow, ($workflow) => $workflow.sourceSummaries);
|
|
7482
|
+
const retrieval = derived7(workflow, ($workflow) => $workflow.retrieval);
|
|
7483
|
+
const groundedAnswer = derived7(workflow, ($workflow) => $workflow.groundedAnswer);
|
|
7484
|
+
const groundingReferences = derived7(workflow, ($workflow) => $workflow.groundingReferences);
|
|
7485
|
+
const stage = derived7(workflow, ($workflow) => $workflow.stage);
|
|
7486
|
+
const hasRetrieved = derived7(workflow, ($workflow) => $workflow.hasRetrieved);
|
|
7487
|
+
const hasSources = derived7(workflow, ($workflow) => $workflow.hasSources);
|
|
7488
|
+
const isRetrieving = derived7(workflow, ($workflow) => $workflow.isRetrieving);
|
|
7489
|
+
const isRetrieved = derived7(workflow, ($workflow) => $workflow.isRetrieved);
|
|
7490
|
+
const isAnswerStreaming = derived7(workflow, ($workflow) => $workflow.isAnswerStreaming);
|
|
7491
|
+
const isComplete = derived7(workflow, ($workflow) => $workflow.isComplete);
|
|
7244
7492
|
const query = (content, attachments) => {
|
|
7245
7493
|
stream.send(content, attachments);
|
|
7246
7494
|
};
|
|
@@ -7273,7 +7521,7 @@ var createRAGStream = (path, conversationId) => {
|
|
|
7273
7521
|
// src/svelte/ai/createRAGWorkflow.ts
|
|
7274
7522
|
var createRAGWorkflow = (path, conversationId) => {
|
|
7275
7523
|
const stream = createRAGStream(path, conversationId);
|
|
7276
|
-
const state =
|
|
7524
|
+
const state = derived8(stream.workflow, ($workflow) => $workflow);
|
|
7277
7525
|
return {
|
|
7278
7526
|
...stream,
|
|
7279
7527
|
state
|
|
@@ -7281,7 +7529,7 @@ var createRAGWorkflow = (path, conversationId) => {
|
|
|
7281
7529
|
};
|
|
7282
7530
|
|
|
7283
7531
|
// src/svelte/ai/createRAG.ts
|
|
7284
|
-
import { derived as
|
|
7532
|
+
import { derived as derived9 } from "svelte/store";
|
|
7285
7533
|
var createRAG = (path, options = {}) => {
|
|
7286
7534
|
const search = createRAGSearch(path);
|
|
7287
7535
|
const ingest = createRAGIngest(path);
|
|
@@ -7294,7 +7542,7 @@ var createRAG = (path, options = {}) => {
|
|
|
7294
7542
|
const workflow = createRAGWorkflow(options.streamPath ?? path, options.conversationId);
|
|
7295
7543
|
const sources = createRAGSources(workflow.messages);
|
|
7296
7544
|
const citations = createRAGCitations(sources.sources);
|
|
7297
|
-
const grounding = createRAGGrounding(
|
|
7545
|
+
const grounding = createRAGGrounding(derived9(workflow.latestAssistantMessage, ($latestAssistantMessage) => $latestAssistantMessage?.content ?? ""), sources.sources);
|
|
7298
7546
|
return {
|
|
7299
7547
|
chunkPreview,
|
|
7300
7548
|
citations,
|
|
@@ -7330,5 +7578,5 @@ export {
|
|
|
7330
7578
|
createAIStream
|
|
7331
7579
|
};
|
|
7332
7580
|
|
|
7333
|
-
//# debugId=
|
|
7581
|
+
//# debugId=4B08CD73149144C364756E2164756E21
|
|
7334
7582
|
//# sourceMappingURL=index.js.map
|