@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
package/dist/svelte/ai/index.js
CHANGED
|
@@ -243,6 +243,11 @@ var buildContextLabel = (metadata) => {
|
|
|
243
243
|
if (speaker) {
|
|
244
244
|
return `Speaker ${speaker}`;
|
|
245
245
|
}
|
|
246
|
+
const sectionPath = Array.isArray(metadata.sectionPath) ? metadata.sectionPath.map((value) => getContextString(value)).filter((value) => typeof value === "string") : [];
|
|
247
|
+
const sectionTitle = getContextString(metadata.sectionTitle) ?? sectionPath.at(-1);
|
|
248
|
+
if (sectionTitle) {
|
|
249
|
+
return `Section ${sectionTitle}`;
|
|
250
|
+
}
|
|
246
251
|
return;
|
|
247
252
|
};
|
|
248
253
|
var formatMediaTimestamp = (value) => {
|
|
@@ -292,6 +297,10 @@ var buildLocatorLabel = (metadata, source, title) => {
|
|
|
292
297
|
if (mediaStart) {
|
|
293
298
|
return `Timestamp ${mediaStart}`;
|
|
294
299
|
}
|
|
300
|
+
const sectionPath = Array.isArray(metadata.sectionPath) ? metadata.sectionPath.map((value) => getContextString(value)).filter((value) => typeof value === "string") : [];
|
|
301
|
+
if (sectionPath.length > 0) {
|
|
302
|
+
return `Section ${sectionPath.join(" > ")}`;
|
|
303
|
+
}
|
|
295
304
|
return;
|
|
296
305
|
};
|
|
297
306
|
var formatTimestampLabel = (value) => {
|
|
@@ -341,8 +350,10 @@ var buildExcerpt = (text, maxLength = 160) => {
|
|
|
341
350
|
var buildGroundingReferenceEvidenceLabel = (reference) => [reference.label, reference.locatorLabel, reference.contextLabel].filter((value) => Boolean(value && value.length > 0)).filter((value, index, values) => values.findIndex((entry) => entry === value) === index).join(" \xB7 ");
|
|
342
351
|
var buildGroundingReferenceEvidenceSummary = (reference) => [
|
|
343
352
|
reference.source ?? reference.title ?? reference.chunkId,
|
|
353
|
+
reference.locatorLabel,
|
|
354
|
+
reference.contextLabel,
|
|
344
355
|
reference.provenanceLabel
|
|
345
|
-
].filter((value) => Boolean(value && value.length > 0)).join(" \xB7 ");
|
|
356
|
+
].filter((value) => Boolean(value && value.length > 0)).filter((value, index, values) => values.findIndex((entry) => entry === value) === index).join(" \xB7 ");
|
|
346
357
|
var buildGroundedAnswerCitationDetail = (reference) => ({
|
|
347
358
|
contextLabel: reference.contextLabel,
|
|
348
359
|
evidenceLabel: buildGroundingReferenceEvidenceLabel(reference),
|
|
@@ -366,12 +377,12 @@ var buildRAGCitations = (sources) => {
|
|
|
366
377
|
continue;
|
|
367
378
|
unique.set(key, {
|
|
368
379
|
chunkId: source.chunkId,
|
|
369
|
-
contextLabel: buildContextLabel(source.metadata),
|
|
380
|
+
contextLabel: source.labels?.contextLabel ?? buildContextLabel(source.metadata),
|
|
370
381
|
key,
|
|
371
382
|
label: buildSourceLabel(source),
|
|
372
|
-
locatorLabel: buildLocatorLabel(source.metadata, source.source, source.title),
|
|
383
|
+
locatorLabel: source.labels?.locatorLabel ?? buildLocatorLabel(source.metadata, source.source, source.title),
|
|
373
384
|
metadata: source.metadata,
|
|
374
|
-
provenanceLabel: buildProvenanceLabel(source.metadata),
|
|
385
|
+
provenanceLabel: source.labels?.provenanceLabel ?? buildProvenanceLabel(source.metadata),
|
|
375
386
|
score: source.score,
|
|
376
387
|
source: source.source,
|
|
377
388
|
text: source.text,
|
|
@@ -441,7 +452,7 @@ var buildRAGGroundingReferences = (sources) => {
|
|
|
441
452
|
const citationReferenceMap = buildRAGCitationReferenceMap(citations);
|
|
442
453
|
return citations.map((citation) => ({
|
|
443
454
|
chunkId: citation.chunkId,
|
|
444
|
-
contextLabel: buildContextLabel(citation.metadata),
|
|
455
|
+
contextLabel: citation.contextLabel ?? buildContextLabel(citation.metadata),
|
|
445
456
|
excerpt: buildExcerpt(citation.text),
|
|
446
457
|
label: citation.label,
|
|
447
458
|
locatorLabel: citation.locatorLabel ?? buildLocatorLabel(citation.metadata, citation.source, citation.title),
|
|
@@ -4014,6 +4025,11 @@ var buildContextLabel2 = (metadata) => {
|
|
|
4014
4025
|
if (speaker) {
|
|
4015
4026
|
return `Speaker ${speaker}`;
|
|
4016
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
|
+
}
|
|
4017
4033
|
return;
|
|
4018
4034
|
};
|
|
4019
4035
|
var buildLocatorLabel2 = (metadata, source, title) => {
|
|
@@ -4053,6 +4069,10 @@ var buildLocatorLabel2 = (metadata, source, title) => {
|
|
|
4053
4069
|
if (mediaStart) {
|
|
4054
4070
|
return `Timestamp ${mediaStart}`;
|
|
4055
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
|
+
}
|
|
4056
4076
|
return;
|
|
4057
4077
|
};
|
|
4058
4078
|
var buildProvenanceLabel2 = (metadata) => {
|
|
@@ -4098,6 +4118,33 @@ var buildRAGSourceLabels = ({
|
|
|
4098
4118
|
provenanceLabel
|
|
4099
4119
|
};
|
|
4100
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
|
+
};
|
|
4101
4148
|
var buildExcerpt2 = (text, maxLength = 160) => {
|
|
4102
4149
|
const normalized = text.replaceAll(/\s+/g, " ").trim();
|
|
4103
4150
|
if (normalized.length <= maxLength) {
|
|
@@ -4105,6 +4152,188 @@ var buildExcerpt2 = (text, maxLength = 160) => {
|
|
|
4105
4152
|
}
|
|
4106
4153
|
return `${normalized.slice(0, Math.max(0, maxLength - 1)).trimEnd()}\u2026`;
|
|
4107
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
|
+
childSectionIds: [],
|
|
4208
|
+
chunkCount: structure.sequence?.sectionChunkCount ?? 1,
|
|
4209
|
+
chunkIds: [chunk.chunkId],
|
|
4210
|
+
depth: structure.section?.depth,
|
|
4211
|
+
id: sectionId,
|
|
4212
|
+
kind: structure.section?.kind,
|
|
4213
|
+
leadChunkId: chunk.chunkId,
|
|
4214
|
+
path: structure.section?.path,
|
|
4215
|
+
title: structure.section?.title
|
|
4216
|
+
});
|
|
4217
|
+
continue;
|
|
4218
|
+
}
|
|
4219
|
+
if (!existing.chunkIds.includes(chunk.chunkId)) {
|
|
4220
|
+
existing.chunkIds.push(chunk.chunkId);
|
|
4221
|
+
}
|
|
4222
|
+
existing.chunkCount = Math.max(existing.chunkCount, structure.sequence?.sectionChunkCount ?? existing.chunkCount);
|
|
4223
|
+
}
|
|
4224
|
+
}
|
|
4225
|
+
for (const section of sections.values()) {
|
|
4226
|
+
section.chunkIds.sort((left, right) => {
|
|
4227
|
+
const leftNode = nodes.find((node) => node.chunkId === left);
|
|
4228
|
+
const rightNode = nodes.find((node) => node.chunkId === right);
|
|
4229
|
+
const leftIndex = leftNode?.structure?.sequence?.sectionChunkIndex ?? Number.MAX_SAFE_INTEGER;
|
|
4230
|
+
const rightIndex = rightNode?.structure?.sequence?.sectionChunkIndex ?? Number.MAX_SAFE_INTEGER;
|
|
4231
|
+
if (leftIndex !== rightIndex) {
|
|
4232
|
+
return leftIndex - rightIndex;
|
|
4233
|
+
}
|
|
4234
|
+
return left.localeCompare(right);
|
|
4235
|
+
});
|
|
4236
|
+
section.leadChunkId = section.chunkIds[0];
|
|
4237
|
+
}
|
|
4238
|
+
const sectionPathIndex = new Map;
|
|
4239
|
+
for (const section of sections.values()) {
|
|
4240
|
+
const path = section.path && section.path.length > 0 ? section.path : section.title ? [section.title] : undefined;
|
|
4241
|
+
if (path && path.length > 0) {
|
|
4242
|
+
sectionPathIndex.set(path.join("\x00"), section);
|
|
4243
|
+
}
|
|
4244
|
+
}
|
|
4245
|
+
for (const section of sections.values()) {
|
|
4246
|
+
const path = section.path && section.path.length > 0 ? section.path : section.title ? [section.title] : undefined;
|
|
4247
|
+
if (!path || path.length < 2) {
|
|
4248
|
+
continue;
|
|
4249
|
+
}
|
|
4250
|
+
const parent = sectionPathIndex.get(path.slice(0, -1).join("\x00"));
|
|
4251
|
+
if (!parent || parent.id === section.id) {
|
|
4252
|
+
continue;
|
|
4253
|
+
}
|
|
4254
|
+
section.parentSectionId = parent.id;
|
|
4255
|
+
if (!parent.childSectionIds.includes(section.id)) {
|
|
4256
|
+
parent.childSectionIds.push(section.id);
|
|
4257
|
+
}
|
|
4258
|
+
if (parent.leadChunkId && section.leadChunkId) {
|
|
4259
|
+
const parentKey = `section_parent:${section.leadChunkId}:${parent.leadChunkId}`;
|
|
4260
|
+
if (!edgeKeys.has(parentKey)) {
|
|
4261
|
+
edgeKeys.add(parentKey);
|
|
4262
|
+
edges.push({
|
|
4263
|
+
fromChunkId: section.leadChunkId,
|
|
4264
|
+
relation: "section_parent",
|
|
4265
|
+
toChunkId: parent.leadChunkId
|
|
4266
|
+
});
|
|
4267
|
+
}
|
|
4268
|
+
const childKey = `section_child:${parent.leadChunkId}:${section.leadChunkId}`;
|
|
4269
|
+
if (!edgeKeys.has(childKey)) {
|
|
4270
|
+
edgeKeys.add(childKey);
|
|
4271
|
+
edges.push({
|
|
4272
|
+
fromChunkId: parent.leadChunkId,
|
|
4273
|
+
relation: "section_child",
|
|
4274
|
+
toChunkId: section.leadChunkId
|
|
4275
|
+
});
|
|
4276
|
+
}
|
|
4277
|
+
}
|
|
4278
|
+
}
|
|
4279
|
+
nodes.sort((left, right) => {
|
|
4280
|
+
const leftSection = left.structure?.sequence?.sectionChunkIndex ?? Number.MAX_SAFE_INTEGER;
|
|
4281
|
+
const rightSection = right.structure?.sequence?.sectionChunkIndex ?? Number.MAX_SAFE_INTEGER;
|
|
4282
|
+
if (leftSection !== rightSection) {
|
|
4283
|
+
return leftSection - rightSection;
|
|
4284
|
+
}
|
|
4285
|
+
const leftScore = left.score ?? Number.NEGATIVE_INFINITY;
|
|
4286
|
+
const rightScore = right.score ?? Number.NEGATIVE_INFINITY;
|
|
4287
|
+
if (leftScore !== rightScore) {
|
|
4288
|
+
return rightScore - leftScore;
|
|
4289
|
+
}
|
|
4290
|
+
return left.label.localeCompare(right.label);
|
|
4291
|
+
});
|
|
4292
|
+
return {
|
|
4293
|
+
edges,
|
|
4294
|
+
nodes,
|
|
4295
|
+
sections: [...sections.values()].sort((left, right) => (left.title ?? left.id).localeCompare(right.title ?? right.id))
|
|
4296
|
+
};
|
|
4297
|
+
};
|
|
4298
|
+
var buildRAGChunkPreviewGraph = (preview) => buildRAGChunkGraph(preview.chunks.map((chunk) => ({
|
|
4299
|
+
chunkId: chunk.chunkId,
|
|
4300
|
+
labels: chunk.labels,
|
|
4301
|
+
metadata: chunk.metadata,
|
|
4302
|
+
source: chunk.source ?? preview.document.source,
|
|
4303
|
+
structure: chunk.structure,
|
|
4304
|
+
title: chunk.title ?? preview.document.title
|
|
4305
|
+
})));
|
|
4306
|
+
var buildRAGChunkPreviewNavigation = (preview, activeChunkId) => buildRAGChunkGraphNavigation(buildRAGChunkPreviewGraph(preview), activeChunkId);
|
|
4307
|
+
var buildRAGChunkGraphNavigation = (graph, activeChunkId) => {
|
|
4308
|
+
if (graph.nodes.length === 0) {
|
|
4309
|
+
return {
|
|
4310
|
+
activeChunkId,
|
|
4311
|
+
childSections: [],
|
|
4312
|
+
siblingSections: [],
|
|
4313
|
+
sectionNodes: []
|
|
4314
|
+
};
|
|
4315
|
+
}
|
|
4316
|
+
const activeNode = (activeChunkId ? graph.nodes.find((node) => node.chunkId === activeChunkId) : undefined) ?? graph.nodes[0];
|
|
4317
|
+
const resolvedActiveChunkId = activeNode?.chunkId;
|
|
4318
|
+
const previousNode = activeNode?.structure?.sequence?.previousChunkId ? graph.nodes.find((node) => node.chunkId === activeNode.structure?.sequence?.previousChunkId) : undefined;
|
|
4319
|
+
const nextNode = activeNode?.structure?.sequence?.nextChunkId ? graph.nodes.find((node) => node.chunkId === activeNode.structure?.sequence?.nextChunkId) : undefined;
|
|
4320
|
+
const section = activeNode?.structure?.sequence?.sectionChunkId ? graph.sections.find((entry) => entry.id === activeNode.structure?.sequence?.sectionChunkId) : undefined;
|
|
4321
|
+
const parentSection = section?.parentSectionId ? graph.sections.find((entry) => entry.id === section.parentSectionId) : undefined;
|
|
4322
|
+
const childSections = section ? section.childSectionIds.map((sectionId) => graph.sections.find((entry) => entry.id === sectionId)).filter((entry) => Boolean(entry)) : [];
|
|
4323
|
+
const siblingSections = section?.parentSectionId ? graph.sections.filter((entry) => entry.parentSectionId === section.parentSectionId && entry.id !== section.id) : [];
|
|
4324
|
+
const sectionNodes = section ? section.chunkIds.map((chunkId) => graph.nodes.find((node) => node.chunkId === chunkId)).filter((node) => Boolean(node)) : activeNode ? [activeNode] : [];
|
|
4325
|
+
return {
|
|
4326
|
+
activeChunkId: resolvedActiveChunkId,
|
|
4327
|
+
activeNode,
|
|
4328
|
+
childSections,
|
|
4329
|
+
nextNode,
|
|
4330
|
+
parentSection,
|
|
4331
|
+
previousNode,
|
|
4332
|
+
section,
|
|
4333
|
+
siblingSections,
|
|
4334
|
+
sectionNodes
|
|
4335
|
+
};
|
|
4336
|
+
};
|
|
4108
4337
|
var buildRAGRetrievedState = (messages) => {
|
|
4109
4338
|
const message = getLatestRetrievedMessage(messages);
|
|
4110
4339
|
if (!message) {
|
|
@@ -4146,6 +4375,7 @@ var buildRAGSourceSummaries = (sources) => {
|
|
|
4146
4375
|
label: group.label,
|
|
4147
4376
|
locatorLabel: leadChunk?.labels?.locatorLabel ?? buildLocatorLabel2(leadChunk?.metadata, leadChunk?.source, leadChunk?.title),
|
|
4148
4377
|
provenanceLabel: leadChunk?.labels?.provenanceLabel ?? buildProvenanceLabel2(leadChunk?.metadata),
|
|
4378
|
+
structure: leadChunk?.structure ?? buildRAGChunkStructure(leadChunk?.metadata),
|
|
4149
4379
|
source: group.source,
|
|
4150
4380
|
title: group.title
|
|
4151
4381
|
};
|
|
@@ -4274,6 +4504,7 @@ var buildSourceGroup = (source, key) => ({
|
|
|
4274
4504
|
source: source.source,
|
|
4275
4505
|
title: source.title
|
|
4276
4506
|
}),
|
|
4507
|
+
structure: source.structure ?? buildRAGChunkStructure(source.metadata),
|
|
4277
4508
|
source: source.source,
|
|
4278
4509
|
title: source.title
|
|
4279
4510
|
});
|
|
@@ -4292,6 +4523,7 @@ var updateSourceGroup = (groups, source) => {
|
|
|
4292
4523
|
source: source.source,
|
|
4293
4524
|
title: source.title
|
|
4294
4525
|
});
|
|
4526
|
+
existing.structure = source.structure ?? buildRAGChunkStructure(source.metadata);
|
|
4295
4527
|
existing.source = source.source;
|
|
4296
4528
|
existing.title = source.title;
|
|
4297
4529
|
} else {
|
|
@@ -5513,7 +5745,7 @@ var createAIStream = (path, conversationId) => {
|
|
|
5513
5745
|
};
|
|
5514
5746
|
};
|
|
5515
5747
|
// src/svelte/ai/createRAGChunkPreview.ts
|
|
5516
|
-
import { writable } from "svelte/store";
|
|
5748
|
+
import { derived, writable } from "svelte/store";
|
|
5517
5749
|
|
|
5518
5750
|
// src/ai/client/ragClient.ts
|
|
5519
5751
|
init_constants();
|
|
@@ -6591,8 +6823,11 @@ var createRAGClient = (options) => {
|
|
|
6591
6823
|
var createRAGChunkPreview = (path) => {
|
|
6592
6824
|
const client = createRAGClient({ path });
|
|
6593
6825
|
const preview = writable(null);
|
|
6826
|
+
const activeChunkId = writable(null);
|
|
6594
6827
|
const error = writable(null);
|
|
6595
6828
|
const isLoading = writable(false);
|
|
6829
|
+
const chunkGraph = derived(preview, ($preview) => $preview ? buildRAGChunkPreviewGraph($preview) : null);
|
|
6830
|
+
const navigationWithSelection = derived([preview, activeChunkId], ([$preview, $activeChunkId]) => $preview ? buildRAGChunkPreviewNavigation($preview, $activeChunkId ?? undefined) : null);
|
|
6596
6831
|
const inspect = async (id) => {
|
|
6597
6832
|
isLoading.set(true);
|
|
6598
6833
|
error.set(null);
|
|
@@ -6602,6 +6837,7 @@ var createRAGChunkPreview = (path) => {
|
|
|
6602
6837
|
throw new Error(response.error);
|
|
6603
6838
|
}
|
|
6604
6839
|
preview.set(response);
|
|
6840
|
+
activeChunkId.set(response.chunks[0]?.chunkId ?? null);
|
|
6605
6841
|
return response;
|
|
6606
6842
|
} catch (caught) {
|
|
6607
6843
|
error.set(caught instanceof Error ? caught.message : String(caught));
|
|
@@ -6613,25 +6849,66 @@ var createRAGChunkPreview = (path) => {
|
|
|
6613
6849
|
const clear = () => {
|
|
6614
6850
|
error.set(null);
|
|
6615
6851
|
isLoading.set(false);
|
|
6852
|
+
activeChunkId.set(null);
|
|
6616
6853
|
preview.set(null);
|
|
6617
6854
|
};
|
|
6855
|
+
const selectChunk = (id) => {
|
|
6856
|
+
activeChunkId.set(id);
|
|
6857
|
+
};
|
|
6858
|
+
const selectParentSection = () => {
|
|
6859
|
+
let leadChunkId;
|
|
6860
|
+
const unsubscribe = navigationWithSelection.subscribe(($navigation) => {
|
|
6861
|
+
leadChunkId = $navigation?.parentSection?.leadChunkId;
|
|
6862
|
+
});
|
|
6863
|
+
unsubscribe();
|
|
6864
|
+
if (leadChunkId) {
|
|
6865
|
+
activeChunkId.set(leadChunkId);
|
|
6866
|
+
}
|
|
6867
|
+
};
|
|
6868
|
+
const selectChildSection = (sectionId) => {
|
|
6869
|
+
let leadChunkId;
|
|
6870
|
+
const unsubscribe = navigationWithSelection.subscribe(($navigation) => {
|
|
6871
|
+
leadChunkId = $navigation?.childSections.find((section) => section.id === sectionId)?.leadChunkId;
|
|
6872
|
+
});
|
|
6873
|
+
unsubscribe();
|
|
6874
|
+
if (leadChunkId) {
|
|
6875
|
+
activeChunkId.set(leadChunkId);
|
|
6876
|
+
}
|
|
6877
|
+
};
|
|
6878
|
+
const selectSiblingSection = (sectionId) => {
|
|
6879
|
+
let leadChunkId;
|
|
6880
|
+
const unsubscribe = navigationWithSelection.subscribe(($navigation) => {
|
|
6881
|
+
leadChunkId = $navigation?.siblingSections.find((section) => section.id === sectionId)?.leadChunkId;
|
|
6882
|
+
});
|
|
6883
|
+
unsubscribe();
|
|
6884
|
+
if (leadChunkId) {
|
|
6885
|
+
activeChunkId.set(leadChunkId);
|
|
6886
|
+
}
|
|
6887
|
+
};
|
|
6618
6888
|
return {
|
|
6889
|
+
activeChunkId,
|
|
6619
6890
|
clear,
|
|
6891
|
+
chunkGraph,
|
|
6620
6892
|
error,
|
|
6621
6893
|
inspect,
|
|
6622
6894
|
isLoading,
|
|
6623
|
-
|
|
6895
|
+
navigation: navigationWithSelection,
|
|
6896
|
+
preview,
|
|
6897
|
+
selectChildSection,
|
|
6898
|
+
selectChunk,
|
|
6899
|
+
selectParentSection,
|
|
6900
|
+
selectSiblingSection
|
|
6624
6901
|
};
|
|
6625
6902
|
};
|
|
6626
6903
|
|
|
6627
6904
|
// src/svelte/ai/createRAGCitations.ts
|
|
6628
|
-
import { derived } from "svelte/store";
|
|
6905
|
+
import { derived as derived2 } from "svelte/store";
|
|
6629
6906
|
var createRAGCitations = (sources) => {
|
|
6630
|
-
const citations =
|
|
6631
|
-
const sourceGroups =
|
|
6632
|
-
const sourceSummaries =
|
|
6633
|
-
const citationReferenceMap =
|
|
6634
|
-
const hasCitations =
|
|
6907
|
+
const citations = derived2(sources, ($sources) => buildRAGCitations($sources));
|
|
6908
|
+
const sourceGroups = derived2(sources, ($sources) => buildRAGSourceGroups($sources));
|
|
6909
|
+
const sourceSummaries = derived2(sources, ($sources) => buildRAGSourceSummaries($sources));
|
|
6910
|
+
const citationReferenceMap = derived2(citations, ($citations) => buildRAGCitationReferenceMap($citations));
|
|
6911
|
+
const hasCitations = derived2(citations, ($citations) => $citations.length > 0);
|
|
6635
6912
|
return {
|
|
6636
6913
|
citationReferenceMap,
|
|
6637
6914
|
citations,
|
|
@@ -6681,7 +6958,7 @@ var createRAGDocuments = (path) => {
|
|
|
6681
6958
|
};
|
|
6682
6959
|
|
|
6683
6960
|
// src/svelte/ai/createRAGEvaluate.ts
|
|
6684
|
-
import { derived as
|
|
6961
|
+
import { derived as derived3, writable as writable3 } from "svelte/store";
|
|
6685
6962
|
var createRAGEvaluate = (path) => {
|
|
6686
6963
|
const client = createRAGClient({ path });
|
|
6687
6964
|
const error = writable3(null);
|
|
@@ -6738,7 +7015,7 @@ var createRAGEvaluate = (path) => {
|
|
|
6738
7015
|
const clearRuns = () => {
|
|
6739
7016
|
suiteRuns.set([]);
|
|
6740
7017
|
};
|
|
6741
|
-
const leaderboard =
|
|
7018
|
+
const leaderboard = derived3(suiteRuns, ($suiteRuns) => buildRAGEvaluationLeaderboard($suiteRuns));
|
|
6742
7019
|
const reset = () => {
|
|
6743
7020
|
error.set(null);
|
|
6744
7021
|
lastRequest.set(null);
|
|
@@ -6763,14 +7040,14 @@ var createRAGEvaluate = (path) => {
|
|
|
6763
7040
|
};
|
|
6764
7041
|
|
|
6765
7042
|
// src/svelte/ai/createRAGGrounding.ts
|
|
6766
|
-
import { derived as
|
|
7043
|
+
import { derived as derived4 } from "svelte/store";
|
|
6767
7044
|
var createRAGGrounding = (content, sources) => {
|
|
6768
|
-
const groundedAnswer =
|
|
6769
|
-
const references =
|
|
6770
|
-
const hasCitations =
|
|
6771
|
-
const hasGrounding =
|
|
6772
|
-
const coverage =
|
|
6773
|
-
const ungroundedReferenceNumbers =
|
|
7045
|
+
const groundedAnswer = derived4([content, sources], ([$content, $sources]) => buildRAGGroundedAnswer($content, $sources));
|
|
7046
|
+
const references = derived4(sources, ($sources) => buildRAGGroundingReferences($sources));
|
|
7047
|
+
const hasCitations = derived4(groundedAnswer, ($groundedAnswer) => $groundedAnswer.hasCitations);
|
|
7048
|
+
const hasGrounding = derived4(references, ($references) => $references.length > 0);
|
|
7049
|
+
const coverage = derived4(groundedAnswer, ($groundedAnswer) => $groundedAnswer.coverage);
|
|
7050
|
+
const ungroundedReferenceNumbers = derived4(groundedAnswer, ($groundedAnswer) => $groundedAnswer.ungroundedReferenceNumbers);
|
|
6774
7051
|
return {
|
|
6775
7052
|
coverage,
|
|
6776
7053
|
groundedAnswer,
|
|
@@ -7179,18 +7456,22 @@ var createRAGSearch = (path) => {
|
|
|
7179
7456
|
};
|
|
7180
7457
|
|
|
7181
7458
|
// src/svelte/ai/createRAGSources.ts
|
|
7182
|
-
import { derived as
|
|
7459
|
+
import { derived as derived5, get } from "svelte/store";
|
|
7183
7460
|
var createRAGSources = (messages) => {
|
|
7184
|
-
const latestAssistantMessage =
|
|
7185
|
-
const sources =
|
|
7186
|
-
const sourceGroups =
|
|
7187
|
-
const sourceSummaries =
|
|
7188
|
-
const
|
|
7189
|
-
const
|
|
7461
|
+
const latestAssistantMessage = derived5(messages, ($messages) => getLatestAssistantMessage($messages));
|
|
7462
|
+
const sources = derived5(messages, ($messages) => getLatestRAGSources($messages));
|
|
7463
|
+
const sourceGroups = derived5(sources, ($sources) => buildRAGSourceGroups($sources));
|
|
7464
|
+
const sourceSummaries = derived5(sources, ($sources) => buildRAGSourceSummaries($sources));
|
|
7465
|
+
const chunkGraph = derived5(sources, ($sources) => buildRAGChunkGraph($sources));
|
|
7466
|
+
const citationReferenceMap = derived5(sourceSummaries, ($sourceSummaries) => buildRAGCitationReferenceMap($sourceSummaries.flatMap((summary) => summary.citations)));
|
|
7467
|
+
const hasSources = derived5(sources, ($sources) => $sources.length > 0);
|
|
7468
|
+
const navigationForChunk = (chunkId) => buildRAGChunkGraphNavigation(get(chunkGraph), chunkId ?? undefined);
|
|
7190
7469
|
return {
|
|
7191
7470
|
citationReferenceMap,
|
|
7471
|
+
chunkGraph,
|
|
7192
7472
|
hasSources,
|
|
7193
7473
|
latestAssistantMessage,
|
|
7474
|
+
navigationForChunk,
|
|
7194
7475
|
sourceGroups,
|
|
7195
7476
|
sources,
|
|
7196
7477
|
sourceSummaries
|
|
@@ -7242,14 +7523,14 @@ var createRAGStatus = (path, autoLoad = true) => {
|
|
|
7242
7523
|
};
|
|
7243
7524
|
|
|
7244
7525
|
// src/svelte/ai/createRAGWorkflow.ts
|
|
7245
|
-
import { derived as
|
|
7526
|
+
import { derived as derived8 } from "svelte/store";
|
|
7246
7527
|
|
|
7247
7528
|
// src/svelte/ai/createRAGStream.ts
|
|
7248
|
-
import { derived as
|
|
7529
|
+
import { derived as derived7, readable } from "svelte/store";
|
|
7249
7530
|
|
|
7250
7531
|
// src/svelte/ai/createRAGStreamProgress.ts
|
|
7251
|
-
import { derived as
|
|
7252
|
-
var createRAGStreamProgress = (params) =>
|
|
7532
|
+
import { derived as derived6 } from "svelte/store";
|
|
7533
|
+
var createRAGStreamProgress = (params) => derived6([params.error, params.isStreaming, params.messages], ([$error, $isStreaming, $messages]) => buildRAGStreamProgress({
|
|
7253
7534
|
error: $error,
|
|
7254
7535
|
isStreaming: $isStreaming,
|
|
7255
7536
|
messages: $messages
|
|
@@ -7270,7 +7551,7 @@ var createRAGStream = (path, conversationId) => {
|
|
|
7270
7551
|
set(stream.isStreaming);
|
|
7271
7552
|
return stream.subscribe(() => set(stream.isStreaming));
|
|
7272
7553
|
});
|
|
7273
|
-
const workflow =
|
|
7554
|
+
const workflow = derived7([messages, error, isStreaming], ([$messages, $error, $isStreaming]) => buildRAGAnswerWorkflowState({
|
|
7274
7555
|
error: $error,
|
|
7275
7556
|
isStreaming: $isStreaming,
|
|
7276
7557
|
messages: $messages
|
|
@@ -7280,21 +7561,21 @@ var createRAGStream = (path, conversationId) => {
|
|
|
7280
7561
|
isStreaming,
|
|
7281
7562
|
messages
|
|
7282
7563
|
});
|
|
7283
|
-
const latestAssistantMessage =
|
|
7284
|
-
const sources =
|
|
7285
|
-
const sourceGroups =
|
|
7286
|
-
const citations =
|
|
7287
|
-
const sourceSummaries =
|
|
7288
|
-
const retrieval =
|
|
7289
|
-
const groundedAnswer =
|
|
7290
|
-
const groundingReferences =
|
|
7291
|
-
const stage =
|
|
7292
|
-
const hasRetrieved =
|
|
7293
|
-
const hasSources =
|
|
7294
|
-
const isRetrieving =
|
|
7295
|
-
const isRetrieved =
|
|
7296
|
-
const isAnswerStreaming =
|
|
7297
|
-
const isComplete =
|
|
7564
|
+
const latestAssistantMessage = derived7(workflow, ($workflow) => $workflow.latestAssistantMessage);
|
|
7565
|
+
const sources = derived7(workflow, ($workflow) => $workflow.sources);
|
|
7566
|
+
const sourceGroups = derived7(workflow, ($workflow) => $workflow.sourceGroups);
|
|
7567
|
+
const citations = derived7(workflow, ($workflow) => $workflow.citations);
|
|
7568
|
+
const sourceSummaries = derived7(workflow, ($workflow) => $workflow.sourceSummaries);
|
|
7569
|
+
const retrieval = derived7(workflow, ($workflow) => $workflow.retrieval);
|
|
7570
|
+
const groundedAnswer = derived7(workflow, ($workflow) => $workflow.groundedAnswer);
|
|
7571
|
+
const groundingReferences = derived7(workflow, ($workflow) => $workflow.groundingReferences);
|
|
7572
|
+
const stage = derived7(workflow, ($workflow) => $workflow.stage);
|
|
7573
|
+
const hasRetrieved = derived7(workflow, ($workflow) => $workflow.hasRetrieved);
|
|
7574
|
+
const hasSources = derived7(workflow, ($workflow) => $workflow.hasSources);
|
|
7575
|
+
const isRetrieving = derived7(workflow, ($workflow) => $workflow.isRetrieving);
|
|
7576
|
+
const isRetrieved = derived7(workflow, ($workflow) => $workflow.isRetrieved);
|
|
7577
|
+
const isAnswerStreaming = derived7(workflow, ($workflow) => $workflow.isAnswerStreaming);
|
|
7578
|
+
const isComplete = derived7(workflow, ($workflow) => $workflow.isComplete);
|
|
7298
7579
|
const query = (content, attachments) => {
|
|
7299
7580
|
stream.send(content, attachments);
|
|
7300
7581
|
};
|
|
@@ -7327,7 +7608,7 @@ var createRAGStream = (path, conversationId) => {
|
|
|
7327
7608
|
// src/svelte/ai/createRAGWorkflow.ts
|
|
7328
7609
|
var createRAGWorkflow = (path, conversationId) => {
|
|
7329
7610
|
const stream = createRAGStream(path, conversationId);
|
|
7330
|
-
const state =
|
|
7611
|
+
const state = derived8(stream.workflow, ($workflow) => $workflow);
|
|
7331
7612
|
return {
|
|
7332
7613
|
...stream,
|
|
7333
7614
|
state
|
|
@@ -7335,7 +7616,7 @@ var createRAGWorkflow = (path, conversationId) => {
|
|
|
7335
7616
|
};
|
|
7336
7617
|
|
|
7337
7618
|
// src/svelte/ai/createRAG.ts
|
|
7338
|
-
import { derived as
|
|
7619
|
+
import { derived as derived9 } from "svelte/store";
|
|
7339
7620
|
var createRAG = (path, options = {}) => {
|
|
7340
7621
|
const search = createRAGSearch(path);
|
|
7341
7622
|
const ingest = createRAGIngest(path);
|
|
@@ -7348,7 +7629,7 @@ var createRAG = (path, options = {}) => {
|
|
|
7348
7629
|
const workflow = createRAGWorkflow(options.streamPath ?? path, options.conversationId);
|
|
7349
7630
|
const sources = createRAGSources(workflow.messages);
|
|
7350
7631
|
const citations = createRAGCitations(sources.sources);
|
|
7351
|
-
const grounding = createRAGGrounding(
|
|
7632
|
+
const grounding = createRAGGrounding(derived9(workflow.latestAssistantMessage, ($latestAssistantMessage) => $latestAssistantMessage?.content ?? ""), sources.sources);
|
|
7352
7633
|
return {
|
|
7353
7634
|
chunkPreview,
|
|
7354
7635
|
citations,
|
|
@@ -7384,5 +7665,5 @@ export {
|
|
|
7384
7665
|
createAIStream
|
|
7385
7666
|
};
|
|
7386
7667
|
|
|
7387
|
-
//# debugId=
|
|
7668
|
+
//# debugId=585BD3B22EFD464B64756E2164756E21
|
|
7388
7669
|
//# sourceMappingURL=index.js.map
|