@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/react/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 {
|
|
@@ -6782,6 +7014,7 @@ import { useCallback as useCallback2, useMemo, useState } from "react";
|
|
|
6782
7014
|
var useRAGChunkPreview = (path) => {
|
|
6783
7015
|
const client = useMemo(() => createRAGClient({ path }), [path]);
|
|
6784
7016
|
const [preview, setPreview] = useState(null);
|
|
7017
|
+
const [activeChunkId, setActiveChunkId] = useState(null);
|
|
6785
7018
|
const [isLoading, setIsLoading] = useState(false);
|
|
6786
7019
|
const [error, setError] = useState(null);
|
|
6787
7020
|
const inspect = useCallback2(async (id) => {
|
|
@@ -6793,6 +7026,7 @@ var useRAGChunkPreview = (path) => {
|
|
|
6793
7026
|
throw new Error(response.error);
|
|
6794
7027
|
}
|
|
6795
7028
|
setPreview(response);
|
|
7029
|
+
setActiveChunkId(response.chunks[0]?.chunkId ?? null);
|
|
6796
7030
|
return response;
|
|
6797
7031
|
} catch (err) {
|
|
6798
7032
|
const message = err instanceof Error ? err.message : "Failed to load RAG chunk preview";
|
|
@@ -6804,15 +7038,46 @@ var useRAGChunkPreview = (path) => {
|
|
|
6804
7038
|
}, [client]);
|
|
6805
7039
|
const clear = useCallback2(() => {
|
|
6806
7040
|
setPreview(null);
|
|
7041
|
+
setActiveChunkId(null);
|
|
6807
7042
|
setError(null);
|
|
6808
7043
|
setIsLoading(false);
|
|
6809
7044
|
}, []);
|
|
7045
|
+
const chunkGraph = useMemo(() => preview ? buildRAGChunkPreviewGraph(preview) : null, [preview]);
|
|
7046
|
+
const navigation = useMemo(() => preview ? buildRAGChunkPreviewNavigation(preview, activeChunkId ?? undefined) : null, [activeChunkId, preview]);
|
|
7047
|
+
const selectChunk = useCallback2((id) => {
|
|
7048
|
+
setActiveChunkId(id);
|
|
7049
|
+
}, []);
|
|
7050
|
+
const selectParentSection = useCallback2(() => {
|
|
7051
|
+
const leadChunkId = navigation?.parentSection?.leadChunkId;
|
|
7052
|
+
if (leadChunkId) {
|
|
7053
|
+
setActiveChunkId(leadChunkId);
|
|
7054
|
+
}
|
|
7055
|
+
}, [navigation]);
|
|
7056
|
+
const selectChildSection = useCallback2((sectionId) => {
|
|
7057
|
+
const leadChunkId = navigation?.childSections.find((section) => section.id === sectionId)?.leadChunkId;
|
|
7058
|
+
if (leadChunkId) {
|
|
7059
|
+
setActiveChunkId(leadChunkId);
|
|
7060
|
+
}
|
|
7061
|
+
}, [navigation]);
|
|
7062
|
+
const selectSiblingSection = useCallback2((sectionId) => {
|
|
7063
|
+
const leadChunkId = navigation?.siblingSections.find((section) => section.id === sectionId)?.leadChunkId;
|
|
7064
|
+
if (leadChunkId) {
|
|
7065
|
+
setActiveChunkId(leadChunkId);
|
|
7066
|
+
}
|
|
7067
|
+
}, [navigation]);
|
|
6810
7068
|
return {
|
|
7069
|
+
activeChunkId,
|
|
7070
|
+
chunkGraph,
|
|
6811
7071
|
clear,
|
|
6812
7072
|
error,
|
|
6813
7073
|
inspect,
|
|
6814
7074
|
isLoading,
|
|
6815
|
-
|
|
7075
|
+
navigation,
|
|
7076
|
+
preview,
|
|
7077
|
+
selectChildSection,
|
|
7078
|
+
selectChunk,
|
|
7079
|
+
selectParentSection,
|
|
7080
|
+
selectSiblingSection
|
|
6816
7081
|
};
|
|
6817
7082
|
};
|
|
6818
7083
|
// src/react/ai/useRAG.ts
|
|
@@ -7387,17 +7652,21 @@ var useRAGSearch = (path) => {
|
|
|
7387
7652
|
};
|
|
7388
7653
|
|
|
7389
7654
|
// src/react/ai/useRAGSources.ts
|
|
7390
|
-
import { useMemo as useMemo10 } from "react";
|
|
7655
|
+
import { useCallback as useCallback9, useMemo as useMemo10 } from "react";
|
|
7391
7656
|
var useRAGSources = (messages) => {
|
|
7392
7657
|
const latestAssistantMessage = useMemo10(() => getLatestAssistantMessage(messages), [messages]);
|
|
7393
7658
|
const sources = useMemo10(() => getLatestRAGSources(messages), [messages]);
|
|
7394
7659
|
const sourceGroups = useMemo10(() => buildRAGSourceGroups(sources), [sources]);
|
|
7395
7660
|
const sourceSummaries = useMemo10(() => buildRAGSourceSummaries(sources), [sources]);
|
|
7661
|
+
const chunkGraph = useMemo10(() => buildRAGChunkGraph(sources), [sources]);
|
|
7396
7662
|
const citationReferenceMap = useMemo10(() => buildRAGCitationReferenceMap(sourceSummaries.flatMap((summary) => summary.citations)), [sourceSummaries]);
|
|
7663
|
+
const navigationForChunk = useCallback9((chunkId) => buildRAGChunkGraphNavigation(chunkGraph, chunkId ?? undefined), [chunkGraph]);
|
|
7397
7664
|
return {
|
|
7398
7665
|
citationReferenceMap,
|
|
7666
|
+
chunkGraph,
|
|
7399
7667
|
hasSources: sources.length > 0,
|
|
7400
7668
|
latestAssistantMessage,
|
|
7669
|
+
navigationForChunk,
|
|
7401
7670
|
sourceGroups,
|
|
7402
7671
|
sources,
|
|
7403
7672
|
sourceSummaries
|
|
@@ -7405,14 +7674,14 @@ var useRAGSources = (messages) => {
|
|
|
7405
7674
|
};
|
|
7406
7675
|
|
|
7407
7676
|
// src/react/ai/useRAGStatus.ts
|
|
7408
|
-
import { useCallback as
|
|
7677
|
+
import { useCallback as useCallback10, useEffect as useEffect4, useMemo as useMemo11, useState as useState8 } from "react";
|
|
7409
7678
|
var useRAGStatus = (path, autoLoad = true) => {
|
|
7410
7679
|
const client = useMemo11(() => createRAGClient({ path }), [path]);
|
|
7411
7680
|
const [status, setStatus] = useState8();
|
|
7412
7681
|
const [capabilities, setCapabilities] = useState8();
|
|
7413
7682
|
const [error, setError] = useState8(null);
|
|
7414
7683
|
const [isLoading, setIsLoading] = useState8(autoLoad);
|
|
7415
|
-
const refresh =
|
|
7684
|
+
const refresh = useCallback10(async () => {
|
|
7416
7685
|
setIsLoading(true);
|
|
7417
7686
|
setError(null);
|
|
7418
7687
|
try {
|
|
@@ -7428,7 +7697,7 @@ var useRAGStatus = (path, autoLoad = true) => {
|
|
|
7428
7697
|
setIsLoading(false);
|
|
7429
7698
|
}
|
|
7430
7699
|
}, [client]);
|
|
7431
|
-
const reset =
|
|
7700
|
+
const reset = useCallback10(() => {
|
|
7432
7701
|
setCapabilities(undefined);
|
|
7433
7702
|
setError(null);
|
|
7434
7703
|
setIsLoading(false);
|
|
@@ -7455,7 +7724,7 @@ var useRAGStatus = (path, autoLoad = true) => {
|
|
|
7455
7724
|
import { useMemo as useMemo13 } from "react";
|
|
7456
7725
|
|
|
7457
7726
|
// src/react/ai/useRAGStream.ts
|
|
7458
|
-
import { useCallback as
|
|
7727
|
+
import { useCallback as useCallback11, useMemo as useMemo12 } from "react";
|
|
7459
7728
|
var useRAGStream = (path, conversationId) => {
|
|
7460
7729
|
const stream = useAIStream(path, conversationId);
|
|
7461
7730
|
const workflow = useMemo12(() => buildRAGAnswerWorkflowState({
|
|
@@ -7485,7 +7754,7 @@ var useRAGStream = (path, conversationId) => {
|
|
|
7485
7754
|
sourceCount: workflow.sources.length,
|
|
7486
7755
|
stage: workflow.stage
|
|
7487
7756
|
}), [workflow]);
|
|
7488
|
-
const query =
|
|
7757
|
+
const query = useCallback11((content, attachments) => {
|
|
7489
7758
|
stream.send(content, attachments);
|
|
7490
7759
|
}, [stream]);
|
|
7491
7760
|
return {
|
|
@@ -7597,5 +7866,5 @@ export {
|
|
|
7597
7866
|
AIStreamProvider
|
|
7598
7867
|
};
|
|
7599
7868
|
|
|
7600
|
-
//# debugId=
|
|
7869
|
+
//# debugId=97115FA6E1742FB464756E2164756E21
|
|
7601
7870
|
//# sourceMappingURL=index.js.map
|