@absolutejs/absolute 0.19.0-beta.605 → 0.19.0-beta.607
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 +112 -1
- package/dist/ai/client/index.js.map +4 -4
- package/dist/ai/client/ui.js +113 -1
- package/dist/ai/client/ui.js.map +4 -4
- package/dist/ai/index.js +153 -4
- package/dist/ai/index.js.map +6 -6
- package/dist/ai/rag/quality.js +60 -1
- package/dist/ai/rag/quality.js.map +3 -3
- package/dist/ai/rag/ui.js +113 -1
- package/dist/ai/rag/ui.js.map +4 -4
- package/dist/ai-client/angular/ai/index.js +111 -0
- package/dist/ai-client/react/ai/index.js +141 -7
- package/dist/ai-client/vue/ai/index.js +135 -1
- package/dist/angular/ai/index.js +112 -1
- package/dist/angular/ai/index.js.map +4 -4
- package/dist/react/ai/index.js +142 -8
- package/dist/react/ai/index.js.map +6 -6
- package/dist/src/ai/client/ui.d.ts +1 -1
- package/dist/src/ai/rag/grounding.d.ts +2 -1
- package/dist/src/ai/rag/index.d.ts +1 -1
- package/dist/src/ai/rag/presentation.d.ts +2 -2
- package/dist/src/ai/rag/ui.d.ts +1 -1
- package/dist/src/react/ai/useRAG.d.ts +4 -0
- package/dist/src/react/ai/useRAGChunkPreview.d.ts +3 -0
- package/dist/src/react/ai/useRAGSources.d.ts +1 -0
- package/dist/src/svelte/ai/createRAG.d.ts +4 -0
- package/dist/src/svelte/ai/createRAGChunkPreview.d.ts +3 -0
- package/dist/src/svelte/ai/createRAGSources.d.ts +1 -0
- package/dist/src/vue/ai/useRAG.d.ts +4 -0
- package/dist/src/vue/ai/useRAGChunkPreview.d.ts +3 -0
- package/dist/src/vue/ai/useRAGSources.d.ts +1 -0
- package/dist/svelte/ai/index.js +149 -3
- package/dist/svelte/ai/index.js.map +6 -6
- package/dist/types/ai.d.ts +20 -1
- package/dist/vue/ai/index.js +136 -2
- package/dist/vue/ai/index.js.map +6 -6
- package/package.json +1 -1
|
@@ -876,6 +876,13 @@ var buildGroundingReferenceEvidenceSummary = (reference) => [
|
|
|
876
876
|
reference.contextLabel,
|
|
877
877
|
reference.provenanceLabel
|
|
878
878
|
].filter((value) => Boolean(value && value.length > 0)).filter((value, index, values) => values.findIndex((entry) => entry === value) === index).join(" · ");
|
|
879
|
+
var buildGroundingSectionKey = (reference) => reference.contextLabel ?? reference.locatorLabel ?? reference.label ?? reference.source ?? reference.chunkId;
|
|
880
|
+
var buildGroundingSectionSummaryLine = (reference) => [
|
|
881
|
+
reference.source ?? reference.title ?? reference.chunkId,
|
|
882
|
+
reference.locatorLabel,
|
|
883
|
+
reference.contextLabel,
|
|
884
|
+
reference.provenanceLabel
|
|
885
|
+
].filter((value) => Boolean(value && value.length > 0)).filter((value, index, values) => values.findIndex((entry) => entry === value) === index).join(" · ");
|
|
879
886
|
var buildGroundedAnswerCitationDetail = (reference) => ({
|
|
880
887
|
contextLabel: reference.contextLabel,
|
|
881
888
|
evidenceLabel: buildGroundingReferenceEvidenceLabel(reference),
|
|
@@ -966,9 +973,61 @@ var buildRAGGroundedAnswer = (content, sources) => {
|
|
|
966
973
|
hasCitations,
|
|
967
974
|
parts,
|
|
968
975
|
references,
|
|
976
|
+
sectionSummaries: buildRAGGroundedAnswerSectionSummaries(references),
|
|
969
977
|
ungroundedReferenceNumbers: [...ungroundedReferenceNumbers].sort((left, right) => left - right)
|
|
970
978
|
};
|
|
971
979
|
};
|
|
980
|
+
var buildRAGGroundedAnswerSectionSummaries = (references) => {
|
|
981
|
+
const groups = new Map;
|
|
982
|
+
for (const reference of references) {
|
|
983
|
+
const key = buildGroundingSectionKey(reference);
|
|
984
|
+
const existing = groups.get(key);
|
|
985
|
+
if (!existing) {
|
|
986
|
+
groups.set(key, {
|
|
987
|
+
chunkIds: [reference.chunkId],
|
|
988
|
+
contextLabel: reference.contextLabel,
|
|
989
|
+
count: 1,
|
|
990
|
+
key,
|
|
991
|
+
label: key,
|
|
992
|
+
locatorLabel: reference.locatorLabel,
|
|
993
|
+
provenanceLabel: reference.provenanceLabel,
|
|
994
|
+
referenceNumbers: [reference.number],
|
|
995
|
+
references: [reference],
|
|
996
|
+
summary: buildGroundingSectionSummaryLine(reference) || reference.label || reference.chunkId
|
|
997
|
+
});
|
|
998
|
+
continue;
|
|
999
|
+
}
|
|
1000
|
+
existing.count += 1;
|
|
1001
|
+
if (!existing.chunkIds.includes(reference.chunkId)) {
|
|
1002
|
+
existing.chunkIds.push(reference.chunkId);
|
|
1003
|
+
}
|
|
1004
|
+
if (!existing.referenceNumbers.includes(reference.number)) {
|
|
1005
|
+
existing.referenceNumbers.push(reference.number);
|
|
1006
|
+
}
|
|
1007
|
+
existing.references.push(reference);
|
|
1008
|
+
if (!existing.contextLabel && reference.contextLabel) {
|
|
1009
|
+
existing.contextLabel = reference.contextLabel;
|
|
1010
|
+
}
|
|
1011
|
+
if (!existing.locatorLabel && reference.locatorLabel) {
|
|
1012
|
+
existing.locatorLabel = reference.locatorLabel;
|
|
1013
|
+
}
|
|
1014
|
+
if (!existing.provenanceLabel && reference.provenanceLabel) {
|
|
1015
|
+
existing.provenanceLabel = reference.provenanceLabel;
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
return [...groups.values()].map((group) => ({
|
|
1019
|
+
...group,
|
|
1020
|
+
referenceNumbers: [...group.referenceNumbers].sort((left, right) => left - right),
|
|
1021
|
+
references: group.references.slice().sort((left, right) => left.number - right.number)
|
|
1022
|
+
})).sort((left, right) => {
|
|
1023
|
+
const leftFirst = left.referenceNumbers[0] ?? Number.POSITIVE_INFINITY;
|
|
1024
|
+
const rightFirst = right.referenceNumbers[0] ?? Number.POSITIVE_INFINITY;
|
|
1025
|
+
if (leftFirst !== rightFirst) {
|
|
1026
|
+
return leftFirst - rightFirst;
|
|
1027
|
+
}
|
|
1028
|
+
return left.label.localeCompare(right.label);
|
|
1029
|
+
});
|
|
1030
|
+
};
|
|
972
1031
|
var buildRAGGroundingReferences = (sources) => {
|
|
973
1032
|
const citations = buildRAGCitations(sources);
|
|
974
1033
|
const citationReferenceMap = buildRAGCitationReferenceMap(citations);
|
|
@@ -1250,11 +1309,13 @@ var buildRAGChunkGraph = (chunks) => {
|
|
|
1250
1309
|
const existing = sections.get(sectionId);
|
|
1251
1310
|
if (!existing) {
|
|
1252
1311
|
sections.set(sectionId, {
|
|
1312
|
+
childSectionIds: [],
|
|
1253
1313
|
chunkCount: structure.sequence?.sectionChunkCount ?? 1,
|
|
1254
1314
|
chunkIds: [chunk.chunkId],
|
|
1255
1315
|
depth: structure.section?.depth,
|
|
1256
1316
|
id: sectionId,
|
|
1257
1317
|
kind: structure.section?.kind,
|
|
1318
|
+
leadChunkId: chunk.chunkId,
|
|
1258
1319
|
path: structure.section?.path,
|
|
1259
1320
|
title: structure.section?.title
|
|
1260
1321
|
});
|
|
@@ -1277,6 +1338,48 @@ var buildRAGChunkGraph = (chunks) => {
|
|
|
1277
1338
|
}
|
|
1278
1339
|
return left.localeCompare(right);
|
|
1279
1340
|
});
|
|
1341
|
+
section.leadChunkId = section.chunkIds[0];
|
|
1342
|
+
}
|
|
1343
|
+
const sectionPathIndex = new Map;
|
|
1344
|
+
for (const section of sections.values()) {
|
|
1345
|
+
const path = section.path && section.path.length > 0 ? section.path : section.title ? [section.title] : undefined;
|
|
1346
|
+
if (path && path.length > 0) {
|
|
1347
|
+
sectionPathIndex.set(path.join("\x00"), section);
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1350
|
+
for (const section of sections.values()) {
|
|
1351
|
+
const path = section.path && section.path.length > 0 ? section.path : section.title ? [section.title] : undefined;
|
|
1352
|
+
if (!path || path.length < 2) {
|
|
1353
|
+
continue;
|
|
1354
|
+
}
|
|
1355
|
+
const parent = sectionPathIndex.get(path.slice(0, -1).join("\x00"));
|
|
1356
|
+
if (!parent || parent.id === section.id) {
|
|
1357
|
+
continue;
|
|
1358
|
+
}
|
|
1359
|
+
section.parentSectionId = parent.id;
|
|
1360
|
+
if (!parent.childSectionIds.includes(section.id)) {
|
|
1361
|
+
parent.childSectionIds.push(section.id);
|
|
1362
|
+
}
|
|
1363
|
+
if (parent.leadChunkId && section.leadChunkId) {
|
|
1364
|
+
const parentKey = `section_parent:${section.leadChunkId}:${parent.leadChunkId}`;
|
|
1365
|
+
if (!edgeKeys.has(parentKey)) {
|
|
1366
|
+
edgeKeys.add(parentKey);
|
|
1367
|
+
edges.push({
|
|
1368
|
+
fromChunkId: section.leadChunkId,
|
|
1369
|
+
relation: "section_parent",
|
|
1370
|
+
toChunkId: parent.leadChunkId
|
|
1371
|
+
});
|
|
1372
|
+
}
|
|
1373
|
+
const childKey = `section_child:${parent.leadChunkId}:${section.leadChunkId}`;
|
|
1374
|
+
if (!edgeKeys.has(childKey)) {
|
|
1375
|
+
edgeKeys.add(childKey);
|
|
1376
|
+
edges.push({
|
|
1377
|
+
fromChunkId: parent.leadChunkId,
|
|
1378
|
+
relation: "section_child",
|
|
1379
|
+
toChunkId: section.leadChunkId
|
|
1380
|
+
});
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1280
1383
|
}
|
|
1281
1384
|
nodes.sort((left, right) => {
|
|
1282
1385
|
const leftSection = left.structure?.sequence?.sectionChunkIndex ?? Number.MAX_SAFE_INTEGER;
|
|
@@ -1310,6 +1413,8 @@ var buildRAGChunkGraphNavigation = (graph, activeChunkId) => {
|
|
|
1310
1413
|
if (graph.nodes.length === 0) {
|
|
1311
1414
|
return {
|
|
1312
1415
|
activeChunkId,
|
|
1416
|
+
childSections: [],
|
|
1417
|
+
siblingSections: [],
|
|
1313
1418
|
sectionNodes: []
|
|
1314
1419
|
};
|
|
1315
1420
|
}
|
|
@@ -1318,13 +1423,19 @@ var buildRAGChunkGraphNavigation = (graph, activeChunkId) => {
|
|
|
1318
1423
|
const previousNode = activeNode?.structure?.sequence?.previousChunkId ? graph.nodes.find((node) => node.chunkId === activeNode.structure?.sequence?.previousChunkId) : undefined;
|
|
1319
1424
|
const nextNode = activeNode?.structure?.sequence?.nextChunkId ? graph.nodes.find((node) => node.chunkId === activeNode.structure?.sequence?.nextChunkId) : undefined;
|
|
1320
1425
|
const section = activeNode?.structure?.sequence?.sectionChunkId ? graph.sections.find((entry) => entry.id === activeNode.structure?.sequence?.sectionChunkId) : undefined;
|
|
1426
|
+
const parentSection = section?.parentSectionId ? graph.sections.find((entry) => entry.id === section.parentSectionId) : undefined;
|
|
1427
|
+
const childSections = section ? section.childSectionIds.map((sectionId) => graph.sections.find((entry) => entry.id === sectionId)).filter((entry) => Boolean(entry)) : [];
|
|
1428
|
+
const siblingSections = section?.parentSectionId ? graph.sections.filter((entry) => entry.parentSectionId === section.parentSectionId && entry.id !== section.id) : [];
|
|
1321
1429
|
const sectionNodes = section ? section.chunkIds.map((chunkId) => graph.nodes.find((node) => node.chunkId === chunkId)).filter((node) => Boolean(node)) : activeNode ? [activeNode] : [];
|
|
1322
1430
|
return {
|
|
1323
1431
|
activeChunkId: resolvedActiveChunkId,
|
|
1324
1432
|
activeNode,
|
|
1433
|
+
childSections,
|
|
1325
1434
|
nextNode,
|
|
1435
|
+
parentSection,
|
|
1326
1436
|
previousNode,
|
|
1327
1437
|
section,
|
|
1438
|
+
siblingSections,
|
|
1328
1439
|
sectionNodes
|
|
1329
1440
|
};
|
|
1330
1441
|
};
|
|
@@ -836,6 +836,13 @@ var buildGroundingReferenceEvidenceSummary = (reference) => [
|
|
|
836
836
|
reference.contextLabel,
|
|
837
837
|
reference.provenanceLabel
|
|
838
838
|
].filter((value) => Boolean(value && value.length > 0)).filter((value, index, values) => values.findIndex((entry) => entry === value) === index).join(" · ");
|
|
839
|
+
var buildGroundingSectionKey = (reference) => reference.contextLabel ?? reference.locatorLabel ?? reference.label ?? reference.source ?? reference.chunkId;
|
|
840
|
+
var buildGroundingSectionSummaryLine = (reference) => [
|
|
841
|
+
reference.source ?? reference.title ?? reference.chunkId,
|
|
842
|
+
reference.locatorLabel,
|
|
843
|
+
reference.contextLabel,
|
|
844
|
+
reference.provenanceLabel
|
|
845
|
+
].filter((value) => Boolean(value && value.length > 0)).filter((value, index, values) => values.findIndex((entry) => entry === value) === index).join(" · ");
|
|
839
846
|
var buildGroundedAnswerCitationDetail = (reference) => ({
|
|
840
847
|
contextLabel: reference.contextLabel,
|
|
841
848
|
evidenceLabel: buildGroundingReferenceEvidenceLabel(reference),
|
|
@@ -926,9 +933,61 @@ var buildRAGGroundedAnswer = (content, sources) => {
|
|
|
926
933
|
hasCitations,
|
|
927
934
|
parts,
|
|
928
935
|
references,
|
|
936
|
+
sectionSummaries: buildRAGGroundedAnswerSectionSummaries(references),
|
|
929
937
|
ungroundedReferenceNumbers: [...ungroundedReferenceNumbers].sort((left, right) => left - right)
|
|
930
938
|
};
|
|
931
939
|
};
|
|
940
|
+
var buildRAGGroundedAnswerSectionSummaries = (references) => {
|
|
941
|
+
const groups = new Map;
|
|
942
|
+
for (const reference of references) {
|
|
943
|
+
const key = buildGroundingSectionKey(reference);
|
|
944
|
+
const existing = groups.get(key);
|
|
945
|
+
if (!existing) {
|
|
946
|
+
groups.set(key, {
|
|
947
|
+
chunkIds: [reference.chunkId],
|
|
948
|
+
contextLabel: reference.contextLabel,
|
|
949
|
+
count: 1,
|
|
950
|
+
key,
|
|
951
|
+
label: key,
|
|
952
|
+
locatorLabel: reference.locatorLabel,
|
|
953
|
+
provenanceLabel: reference.provenanceLabel,
|
|
954
|
+
referenceNumbers: [reference.number],
|
|
955
|
+
references: [reference],
|
|
956
|
+
summary: buildGroundingSectionSummaryLine(reference) || reference.label || reference.chunkId
|
|
957
|
+
});
|
|
958
|
+
continue;
|
|
959
|
+
}
|
|
960
|
+
existing.count += 1;
|
|
961
|
+
if (!existing.chunkIds.includes(reference.chunkId)) {
|
|
962
|
+
existing.chunkIds.push(reference.chunkId);
|
|
963
|
+
}
|
|
964
|
+
if (!existing.referenceNumbers.includes(reference.number)) {
|
|
965
|
+
existing.referenceNumbers.push(reference.number);
|
|
966
|
+
}
|
|
967
|
+
existing.references.push(reference);
|
|
968
|
+
if (!existing.contextLabel && reference.contextLabel) {
|
|
969
|
+
existing.contextLabel = reference.contextLabel;
|
|
970
|
+
}
|
|
971
|
+
if (!existing.locatorLabel && reference.locatorLabel) {
|
|
972
|
+
existing.locatorLabel = reference.locatorLabel;
|
|
973
|
+
}
|
|
974
|
+
if (!existing.provenanceLabel && reference.provenanceLabel) {
|
|
975
|
+
existing.provenanceLabel = reference.provenanceLabel;
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
return [...groups.values()].map((group) => ({
|
|
979
|
+
...group,
|
|
980
|
+
referenceNumbers: [...group.referenceNumbers].sort((left, right) => left - right),
|
|
981
|
+
references: group.references.slice().sort((left, right) => left.number - right.number)
|
|
982
|
+
})).sort((left, right) => {
|
|
983
|
+
const leftFirst = left.referenceNumbers[0] ?? Number.POSITIVE_INFINITY;
|
|
984
|
+
const rightFirst = right.referenceNumbers[0] ?? Number.POSITIVE_INFINITY;
|
|
985
|
+
if (leftFirst !== rightFirst) {
|
|
986
|
+
return leftFirst - rightFirst;
|
|
987
|
+
}
|
|
988
|
+
return left.label.localeCompare(right.label);
|
|
989
|
+
});
|
|
990
|
+
};
|
|
932
991
|
var buildRAGGroundingReferences = (sources) => {
|
|
933
992
|
const citations = buildRAGCitations(sources);
|
|
934
993
|
const citationReferenceMap = buildRAGCitationReferenceMap(citations);
|
|
@@ -1210,11 +1269,13 @@ var buildRAGChunkGraph = (chunks) => {
|
|
|
1210
1269
|
const existing = sections.get(sectionId);
|
|
1211
1270
|
if (!existing) {
|
|
1212
1271
|
sections.set(sectionId, {
|
|
1272
|
+
childSectionIds: [],
|
|
1213
1273
|
chunkCount: structure.sequence?.sectionChunkCount ?? 1,
|
|
1214
1274
|
chunkIds: [chunk.chunkId],
|
|
1215
1275
|
depth: structure.section?.depth,
|
|
1216
1276
|
id: sectionId,
|
|
1217
1277
|
kind: structure.section?.kind,
|
|
1278
|
+
leadChunkId: chunk.chunkId,
|
|
1218
1279
|
path: structure.section?.path,
|
|
1219
1280
|
title: structure.section?.title
|
|
1220
1281
|
});
|
|
@@ -1237,6 +1298,48 @@ var buildRAGChunkGraph = (chunks) => {
|
|
|
1237
1298
|
}
|
|
1238
1299
|
return left.localeCompare(right);
|
|
1239
1300
|
});
|
|
1301
|
+
section.leadChunkId = section.chunkIds[0];
|
|
1302
|
+
}
|
|
1303
|
+
const sectionPathIndex = new Map;
|
|
1304
|
+
for (const section of sections.values()) {
|
|
1305
|
+
const path = section.path && section.path.length > 0 ? section.path : section.title ? [section.title] : undefined;
|
|
1306
|
+
if (path && path.length > 0) {
|
|
1307
|
+
sectionPathIndex.set(path.join("\x00"), section);
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
for (const section of sections.values()) {
|
|
1311
|
+
const path = section.path && section.path.length > 0 ? section.path : section.title ? [section.title] : undefined;
|
|
1312
|
+
if (!path || path.length < 2) {
|
|
1313
|
+
continue;
|
|
1314
|
+
}
|
|
1315
|
+
const parent = sectionPathIndex.get(path.slice(0, -1).join("\x00"));
|
|
1316
|
+
if (!parent || parent.id === section.id) {
|
|
1317
|
+
continue;
|
|
1318
|
+
}
|
|
1319
|
+
section.parentSectionId = parent.id;
|
|
1320
|
+
if (!parent.childSectionIds.includes(section.id)) {
|
|
1321
|
+
parent.childSectionIds.push(section.id);
|
|
1322
|
+
}
|
|
1323
|
+
if (parent.leadChunkId && section.leadChunkId) {
|
|
1324
|
+
const parentKey = `section_parent:${section.leadChunkId}:${parent.leadChunkId}`;
|
|
1325
|
+
if (!edgeKeys.has(parentKey)) {
|
|
1326
|
+
edgeKeys.add(parentKey);
|
|
1327
|
+
edges.push({
|
|
1328
|
+
fromChunkId: section.leadChunkId,
|
|
1329
|
+
relation: "section_parent",
|
|
1330
|
+
toChunkId: parent.leadChunkId
|
|
1331
|
+
});
|
|
1332
|
+
}
|
|
1333
|
+
const childKey = `section_child:${parent.leadChunkId}:${section.leadChunkId}`;
|
|
1334
|
+
if (!edgeKeys.has(childKey)) {
|
|
1335
|
+
edgeKeys.add(childKey);
|
|
1336
|
+
edges.push({
|
|
1337
|
+
fromChunkId: parent.leadChunkId,
|
|
1338
|
+
relation: "section_child",
|
|
1339
|
+
toChunkId: section.leadChunkId
|
|
1340
|
+
});
|
|
1341
|
+
}
|
|
1342
|
+
}
|
|
1240
1343
|
}
|
|
1241
1344
|
nodes.sort((left, right) => {
|
|
1242
1345
|
const leftSection = left.structure?.sequence?.sectionChunkIndex ?? Number.MAX_SAFE_INTEGER;
|
|
@@ -1270,6 +1373,8 @@ var buildRAGChunkGraphNavigation = (graph, activeChunkId) => {
|
|
|
1270
1373
|
if (graph.nodes.length === 0) {
|
|
1271
1374
|
return {
|
|
1272
1375
|
activeChunkId,
|
|
1376
|
+
childSections: [],
|
|
1377
|
+
siblingSections: [],
|
|
1273
1378
|
sectionNodes: []
|
|
1274
1379
|
};
|
|
1275
1380
|
}
|
|
@@ -1278,13 +1383,19 @@ var buildRAGChunkGraphNavigation = (graph, activeChunkId) => {
|
|
|
1278
1383
|
const previousNode = activeNode?.structure?.sequence?.previousChunkId ? graph.nodes.find((node) => node.chunkId === activeNode.structure?.sequence?.previousChunkId) : undefined;
|
|
1279
1384
|
const nextNode = activeNode?.structure?.sequence?.nextChunkId ? graph.nodes.find((node) => node.chunkId === activeNode.structure?.sequence?.nextChunkId) : undefined;
|
|
1280
1385
|
const section = activeNode?.structure?.sequence?.sectionChunkId ? graph.sections.find((entry) => entry.id === activeNode.structure?.sequence?.sectionChunkId) : undefined;
|
|
1386
|
+
const parentSection = section?.parentSectionId ? graph.sections.find((entry) => entry.id === section.parentSectionId) : undefined;
|
|
1387
|
+
const childSections = section ? section.childSectionIds.map((sectionId) => graph.sections.find((entry) => entry.id === sectionId)).filter((entry) => Boolean(entry)) : [];
|
|
1388
|
+
const siblingSections = section?.parentSectionId ? graph.sections.filter((entry) => entry.parentSectionId === section.parentSectionId && entry.id !== section.id) : [];
|
|
1281
1389
|
const sectionNodes = section ? section.chunkIds.map((chunkId) => graph.nodes.find((node) => node.chunkId === chunkId)).filter((node) => Boolean(node)) : activeNode ? [activeNode] : [];
|
|
1282
1390
|
return {
|
|
1283
1391
|
activeChunkId: resolvedActiveChunkId,
|
|
1284
1392
|
activeNode,
|
|
1393
|
+
childSections,
|
|
1285
1394
|
nextNode,
|
|
1395
|
+
parentSection,
|
|
1286
1396
|
previousNode,
|
|
1287
1397
|
section,
|
|
1398
|
+
siblingSections,
|
|
1288
1399
|
sectionNodes
|
|
1289
1400
|
};
|
|
1290
1401
|
};
|
|
@@ -3019,6 +3130,24 @@ var useRAGChunkPreview = (path) => {
|
|
|
3019
3130
|
const selectChunk = useCallback2((id) => {
|
|
3020
3131
|
setActiveChunkId(id);
|
|
3021
3132
|
}, []);
|
|
3133
|
+
const selectParentSection = useCallback2(() => {
|
|
3134
|
+
const leadChunkId = navigation?.parentSection?.leadChunkId;
|
|
3135
|
+
if (leadChunkId) {
|
|
3136
|
+
setActiveChunkId(leadChunkId);
|
|
3137
|
+
}
|
|
3138
|
+
}, [navigation]);
|
|
3139
|
+
const selectChildSection = useCallback2((sectionId) => {
|
|
3140
|
+
const leadChunkId = navigation?.childSections.find((section) => section.id === sectionId)?.leadChunkId;
|
|
3141
|
+
if (leadChunkId) {
|
|
3142
|
+
setActiveChunkId(leadChunkId);
|
|
3143
|
+
}
|
|
3144
|
+
}, [navigation]);
|
|
3145
|
+
const selectSiblingSection = useCallback2((sectionId) => {
|
|
3146
|
+
const leadChunkId = navigation?.siblingSections.find((section) => section.id === sectionId)?.leadChunkId;
|
|
3147
|
+
if (leadChunkId) {
|
|
3148
|
+
setActiveChunkId(leadChunkId);
|
|
3149
|
+
}
|
|
3150
|
+
}, [navigation]);
|
|
3022
3151
|
return {
|
|
3023
3152
|
activeChunkId,
|
|
3024
3153
|
chunkGraph,
|
|
@@ -3028,7 +3157,10 @@ var useRAGChunkPreview = (path) => {
|
|
|
3028
3157
|
isLoading,
|
|
3029
3158
|
navigation,
|
|
3030
3159
|
preview,
|
|
3031
|
-
|
|
3160
|
+
selectChildSection,
|
|
3161
|
+
selectChunk,
|
|
3162
|
+
selectParentSection,
|
|
3163
|
+
selectSiblingSection
|
|
3032
3164
|
};
|
|
3033
3165
|
};
|
|
3034
3166
|
// src/react/ai/useRAG.ts
|
|
@@ -3603,7 +3735,7 @@ var useRAGSearch = (path) => {
|
|
|
3603
3735
|
};
|
|
3604
3736
|
|
|
3605
3737
|
// src/react/ai/useRAGSources.ts
|
|
3606
|
-
import { useMemo as useMemo10 } from "react";
|
|
3738
|
+
import { useCallback as useCallback9, useMemo as useMemo10 } from "react";
|
|
3607
3739
|
var useRAGSources = (messages) => {
|
|
3608
3740
|
const latestAssistantMessage = useMemo10(() => getLatestAssistantMessage(messages), [messages]);
|
|
3609
3741
|
const sources = useMemo10(() => getLatestRAGSources(messages), [messages]);
|
|
@@ -3611,11 +3743,13 @@ var useRAGSources = (messages) => {
|
|
|
3611
3743
|
const sourceSummaries = useMemo10(() => buildRAGSourceSummaries(sources), [sources]);
|
|
3612
3744
|
const chunkGraph = useMemo10(() => buildRAGChunkGraph(sources), [sources]);
|
|
3613
3745
|
const citationReferenceMap = useMemo10(() => buildRAGCitationReferenceMap(sourceSummaries.flatMap((summary) => summary.citations)), [sourceSummaries]);
|
|
3746
|
+
const navigationForChunk = useCallback9((chunkId) => buildRAGChunkGraphNavigation(chunkGraph, chunkId ?? undefined), [chunkGraph]);
|
|
3614
3747
|
return {
|
|
3615
3748
|
citationReferenceMap,
|
|
3616
3749
|
chunkGraph,
|
|
3617
3750
|
hasSources: sources.length > 0,
|
|
3618
3751
|
latestAssistantMessage,
|
|
3752
|
+
navigationForChunk,
|
|
3619
3753
|
sourceGroups,
|
|
3620
3754
|
sources,
|
|
3621
3755
|
sourceSummaries
|
|
@@ -3623,14 +3757,14 @@ var useRAGSources = (messages) => {
|
|
|
3623
3757
|
};
|
|
3624
3758
|
|
|
3625
3759
|
// src/react/ai/useRAGStatus.ts
|
|
3626
|
-
import { useCallback as
|
|
3760
|
+
import { useCallback as useCallback10, useEffect as useEffect4, useMemo as useMemo11, useState as useState8 } from "react";
|
|
3627
3761
|
var useRAGStatus = (path, autoLoad = true) => {
|
|
3628
3762
|
const client = useMemo11(() => createRAGClient({ path }), [path]);
|
|
3629
3763
|
const [status, setStatus] = useState8();
|
|
3630
3764
|
const [capabilities, setCapabilities] = useState8();
|
|
3631
3765
|
const [error, setError] = useState8(null);
|
|
3632
3766
|
const [isLoading, setIsLoading] = useState8(autoLoad);
|
|
3633
|
-
const refresh =
|
|
3767
|
+
const refresh = useCallback10(async () => {
|
|
3634
3768
|
setIsLoading(true);
|
|
3635
3769
|
setError(null);
|
|
3636
3770
|
try {
|
|
@@ -3646,7 +3780,7 @@ var useRAGStatus = (path, autoLoad = true) => {
|
|
|
3646
3780
|
setIsLoading(false);
|
|
3647
3781
|
}
|
|
3648
3782
|
}, [client]);
|
|
3649
|
-
const reset =
|
|
3783
|
+
const reset = useCallback10(() => {
|
|
3650
3784
|
setCapabilities(undefined);
|
|
3651
3785
|
setError(null);
|
|
3652
3786
|
setIsLoading(false);
|
|
@@ -3673,7 +3807,7 @@ var useRAGStatus = (path, autoLoad = true) => {
|
|
|
3673
3807
|
import { useMemo as useMemo13 } from "react";
|
|
3674
3808
|
|
|
3675
3809
|
// src/react/ai/useRAGStream.ts
|
|
3676
|
-
import { useCallback as
|
|
3810
|
+
import { useCallback as useCallback11, useMemo as useMemo12 } from "react";
|
|
3677
3811
|
var useRAGStream = (path, conversationId) => {
|
|
3678
3812
|
const stream = useAIStream(path, conversationId);
|
|
3679
3813
|
const workflow = useMemo12(() => buildRAGAnswerWorkflowState({
|
|
@@ -3703,7 +3837,7 @@ var useRAGStream = (path, conversationId) => {
|
|
|
3703
3837
|
sourceCount: workflow.sources.length,
|
|
3704
3838
|
stage: workflow.stage
|
|
3705
3839
|
}), [workflow]);
|
|
3706
|
-
const query =
|
|
3840
|
+
const query = useCallback11((content, attachments) => {
|
|
3707
3841
|
stream.send(content, attachments);
|
|
3708
3842
|
}, [stream]);
|
|
3709
3843
|
return {
|
|
@@ -1879,6 +1879,13 @@ var buildGroundingReferenceEvidenceSummary = (reference) => [
|
|
|
1879
1879
|
reference.contextLabel,
|
|
1880
1880
|
reference.provenanceLabel
|
|
1881
1881
|
].filter((value) => Boolean(value && value.length > 0)).filter((value, index, values) => values.findIndex((entry) => entry === value) === index).join(" · ");
|
|
1882
|
+
var buildGroundingSectionKey = (reference) => reference.contextLabel ?? reference.locatorLabel ?? reference.label ?? reference.source ?? reference.chunkId;
|
|
1883
|
+
var buildGroundingSectionSummaryLine = (reference) => [
|
|
1884
|
+
reference.source ?? reference.title ?? reference.chunkId,
|
|
1885
|
+
reference.locatorLabel,
|
|
1886
|
+
reference.contextLabel,
|
|
1887
|
+
reference.provenanceLabel
|
|
1888
|
+
].filter((value) => Boolean(value && value.length > 0)).filter((value, index, values) => values.findIndex((entry) => entry === value) === index).join(" · ");
|
|
1882
1889
|
var buildGroundedAnswerCitationDetail = (reference) => ({
|
|
1883
1890
|
contextLabel: reference.contextLabel,
|
|
1884
1891
|
evidenceLabel: buildGroundingReferenceEvidenceLabel(reference),
|
|
@@ -1969,9 +1976,61 @@ var buildRAGGroundedAnswer = (content, sources) => {
|
|
|
1969
1976
|
hasCitations,
|
|
1970
1977
|
parts,
|
|
1971
1978
|
references,
|
|
1979
|
+
sectionSummaries: buildRAGGroundedAnswerSectionSummaries(references),
|
|
1972
1980
|
ungroundedReferenceNumbers: [...ungroundedReferenceNumbers].sort((left, right) => left - right)
|
|
1973
1981
|
};
|
|
1974
1982
|
};
|
|
1983
|
+
var buildRAGGroundedAnswerSectionSummaries = (references) => {
|
|
1984
|
+
const groups = new Map;
|
|
1985
|
+
for (const reference of references) {
|
|
1986
|
+
const key = buildGroundingSectionKey(reference);
|
|
1987
|
+
const existing = groups.get(key);
|
|
1988
|
+
if (!existing) {
|
|
1989
|
+
groups.set(key, {
|
|
1990
|
+
chunkIds: [reference.chunkId],
|
|
1991
|
+
contextLabel: reference.contextLabel,
|
|
1992
|
+
count: 1,
|
|
1993
|
+
key,
|
|
1994
|
+
label: key,
|
|
1995
|
+
locatorLabel: reference.locatorLabel,
|
|
1996
|
+
provenanceLabel: reference.provenanceLabel,
|
|
1997
|
+
referenceNumbers: [reference.number],
|
|
1998
|
+
references: [reference],
|
|
1999
|
+
summary: buildGroundingSectionSummaryLine(reference) || reference.label || reference.chunkId
|
|
2000
|
+
});
|
|
2001
|
+
continue;
|
|
2002
|
+
}
|
|
2003
|
+
existing.count += 1;
|
|
2004
|
+
if (!existing.chunkIds.includes(reference.chunkId)) {
|
|
2005
|
+
existing.chunkIds.push(reference.chunkId);
|
|
2006
|
+
}
|
|
2007
|
+
if (!existing.referenceNumbers.includes(reference.number)) {
|
|
2008
|
+
existing.referenceNumbers.push(reference.number);
|
|
2009
|
+
}
|
|
2010
|
+
existing.references.push(reference);
|
|
2011
|
+
if (!existing.contextLabel && reference.contextLabel) {
|
|
2012
|
+
existing.contextLabel = reference.contextLabel;
|
|
2013
|
+
}
|
|
2014
|
+
if (!existing.locatorLabel && reference.locatorLabel) {
|
|
2015
|
+
existing.locatorLabel = reference.locatorLabel;
|
|
2016
|
+
}
|
|
2017
|
+
if (!existing.provenanceLabel && reference.provenanceLabel) {
|
|
2018
|
+
existing.provenanceLabel = reference.provenanceLabel;
|
|
2019
|
+
}
|
|
2020
|
+
}
|
|
2021
|
+
return [...groups.values()].map((group) => ({
|
|
2022
|
+
...group,
|
|
2023
|
+
referenceNumbers: [...group.referenceNumbers].sort((left, right) => left - right),
|
|
2024
|
+
references: group.references.slice().sort((left, right) => left.number - right.number)
|
|
2025
|
+
})).sort((left, right) => {
|
|
2026
|
+
const leftFirst = left.referenceNumbers[0] ?? Number.POSITIVE_INFINITY;
|
|
2027
|
+
const rightFirst = right.referenceNumbers[0] ?? Number.POSITIVE_INFINITY;
|
|
2028
|
+
if (leftFirst !== rightFirst) {
|
|
2029
|
+
return leftFirst - rightFirst;
|
|
2030
|
+
}
|
|
2031
|
+
return left.label.localeCompare(right.label);
|
|
2032
|
+
});
|
|
2033
|
+
};
|
|
1975
2034
|
var buildRAGGroundingReferences = (sources) => {
|
|
1976
2035
|
const citations = buildRAGCitations(sources);
|
|
1977
2036
|
const citationReferenceMap = buildRAGCitationReferenceMap(citations);
|
|
@@ -2253,11 +2312,13 @@ var buildRAGChunkGraph = (chunks) => {
|
|
|
2253
2312
|
const existing = sections.get(sectionId);
|
|
2254
2313
|
if (!existing) {
|
|
2255
2314
|
sections.set(sectionId, {
|
|
2315
|
+
childSectionIds: [],
|
|
2256
2316
|
chunkCount: structure.sequence?.sectionChunkCount ?? 1,
|
|
2257
2317
|
chunkIds: [chunk.chunkId],
|
|
2258
2318
|
depth: structure.section?.depth,
|
|
2259
2319
|
id: sectionId,
|
|
2260
2320
|
kind: structure.section?.kind,
|
|
2321
|
+
leadChunkId: chunk.chunkId,
|
|
2261
2322
|
path: structure.section?.path,
|
|
2262
2323
|
title: structure.section?.title
|
|
2263
2324
|
});
|
|
@@ -2280,6 +2341,48 @@ var buildRAGChunkGraph = (chunks) => {
|
|
|
2280
2341
|
}
|
|
2281
2342
|
return left.localeCompare(right);
|
|
2282
2343
|
});
|
|
2344
|
+
section.leadChunkId = section.chunkIds[0];
|
|
2345
|
+
}
|
|
2346
|
+
const sectionPathIndex = new Map;
|
|
2347
|
+
for (const section of sections.values()) {
|
|
2348
|
+
const path = section.path && section.path.length > 0 ? section.path : section.title ? [section.title] : undefined;
|
|
2349
|
+
if (path && path.length > 0) {
|
|
2350
|
+
sectionPathIndex.set(path.join("\x00"), section);
|
|
2351
|
+
}
|
|
2352
|
+
}
|
|
2353
|
+
for (const section of sections.values()) {
|
|
2354
|
+
const path = section.path && section.path.length > 0 ? section.path : section.title ? [section.title] : undefined;
|
|
2355
|
+
if (!path || path.length < 2) {
|
|
2356
|
+
continue;
|
|
2357
|
+
}
|
|
2358
|
+
const parent = sectionPathIndex.get(path.slice(0, -1).join("\x00"));
|
|
2359
|
+
if (!parent || parent.id === section.id) {
|
|
2360
|
+
continue;
|
|
2361
|
+
}
|
|
2362
|
+
section.parentSectionId = parent.id;
|
|
2363
|
+
if (!parent.childSectionIds.includes(section.id)) {
|
|
2364
|
+
parent.childSectionIds.push(section.id);
|
|
2365
|
+
}
|
|
2366
|
+
if (parent.leadChunkId && section.leadChunkId) {
|
|
2367
|
+
const parentKey = `section_parent:${section.leadChunkId}:${parent.leadChunkId}`;
|
|
2368
|
+
if (!edgeKeys.has(parentKey)) {
|
|
2369
|
+
edgeKeys.add(parentKey);
|
|
2370
|
+
edges.push({
|
|
2371
|
+
fromChunkId: section.leadChunkId,
|
|
2372
|
+
relation: "section_parent",
|
|
2373
|
+
toChunkId: parent.leadChunkId
|
|
2374
|
+
});
|
|
2375
|
+
}
|
|
2376
|
+
const childKey = `section_child:${parent.leadChunkId}:${section.leadChunkId}`;
|
|
2377
|
+
if (!edgeKeys.has(childKey)) {
|
|
2378
|
+
edgeKeys.add(childKey);
|
|
2379
|
+
edges.push({
|
|
2380
|
+
fromChunkId: parent.leadChunkId,
|
|
2381
|
+
relation: "section_child",
|
|
2382
|
+
toChunkId: section.leadChunkId
|
|
2383
|
+
});
|
|
2384
|
+
}
|
|
2385
|
+
}
|
|
2283
2386
|
}
|
|
2284
2387
|
nodes.sort((left, right) => {
|
|
2285
2388
|
const leftSection = left.structure?.sequence?.sectionChunkIndex ?? Number.MAX_SAFE_INTEGER;
|
|
@@ -2313,6 +2416,8 @@ var buildRAGChunkGraphNavigation = (graph, activeChunkId) => {
|
|
|
2313
2416
|
if (graph.nodes.length === 0) {
|
|
2314
2417
|
return {
|
|
2315
2418
|
activeChunkId,
|
|
2419
|
+
childSections: [],
|
|
2420
|
+
siblingSections: [],
|
|
2316
2421
|
sectionNodes: []
|
|
2317
2422
|
};
|
|
2318
2423
|
}
|
|
@@ -2321,13 +2426,19 @@ var buildRAGChunkGraphNavigation = (graph, activeChunkId) => {
|
|
|
2321
2426
|
const previousNode = activeNode?.structure?.sequence?.previousChunkId ? graph.nodes.find((node) => node.chunkId === activeNode.structure?.sequence?.previousChunkId) : undefined;
|
|
2322
2427
|
const nextNode = activeNode?.structure?.sequence?.nextChunkId ? graph.nodes.find((node) => node.chunkId === activeNode.structure?.sequence?.nextChunkId) : undefined;
|
|
2323
2428
|
const section = activeNode?.structure?.sequence?.sectionChunkId ? graph.sections.find((entry) => entry.id === activeNode.structure?.sequence?.sectionChunkId) : undefined;
|
|
2429
|
+
const parentSection = section?.parentSectionId ? graph.sections.find((entry) => entry.id === section.parentSectionId) : undefined;
|
|
2430
|
+
const childSections = section ? section.childSectionIds.map((sectionId) => graph.sections.find((entry) => entry.id === sectionId)).filter((entry) => Boolean(entry)) : [];
|
|
2431
|
+
const siblingSections = section?.parentSectionId ? graph.sections.filter((entry) => entry.parentSectionId === section.parentSectionId && entry.id !== section.id) : [];
|
|
2324
2432
|
const sectionNodes = section ? section.chunkIds.map((chunkId) => graph.nodes.find((node) => node.chunkId === chunkId)).filter((node) => Boolean(node)) : activeNode ? [activeNode] : [];
|
|
2325
2433
|
return {
|
|
2326
2434
|
activeChunkId: resolvedActiveChunkId,
|
|
2327
2435
|
activeNode,
|
|
2436
|
+
childSections,
|
|
2328
2437
|
nextNode,
|
|
2438
|
+
parentSection,
|
|
2329
2439
|
previousNode,
|
|
2330
2440
|
section,
|
|
2441
|
+
siblingSections,
|
|
2331
2442
|
sectionNodes
|
|
2332
2443
|
};
|
|
2333
2444
|
};
|
|
@@ -2610,6 +2721,24 @@ var useRAGChunkPreview = (path) => {
|
|
|
2610
2721
|
const selectChunk = (id) => {
|
|
2611
2722
|
activeChunkId.value = id;
|
|
2612
2723
|
};
|
|
2724
|
+
const selectParentSection = () => {
|
|
2725
|
+
const leadChunkId = navigation.value?.parentSection?.leadChunkId;
|
|
2726
|
+
if (leadChunkId) {
|
|
2727
|
+
activeChunkId.value = leadChunkId;
|
|
2728
|
+
}
|
|
2729
|
+
};
|
|
2730
|
+
const selectChildSection = (sectionId) => {
|
|
2731
|
+
const leadChunkId = navigation.value?.childSections.find((section) => section.id === sectionId)?.leadChunkId;
|
|
2732
|
+
if (leadChunkId) {
|
|
2733
|
+
activeChunkId.value = leadChunkId;
|
|
2734
|
+
}
|
|
2735
|
+
};
|
|
2736
|
+
const selectSiblingSection = (sectionId) => {
|
|
2737
|
+
const leadChunkId = navigation.value?.siblingSections.find((section) => section.id === sectionId)?.leadChunkId;
|
|
2738
|
+
if (leadChunkId) {
|
|
2739
|
+
activeChunkId.value = leadChunkId;
|
|
2740
|
+
}
|
|
2741
|
+
};
|
|
2613
2742
|
return {
|
|
2614
2743
|
activeChunkId,
|
|
2615
2744
|
clear,
|
|
@@ -2619,7 +2748,10 @@ var useRAGChunkPreview = (path) => {
|
|
|
2619
2748
|
isLoading,
|
|
2620
2749
|
navigation,
|
|
2621
2750
|
preview,
|
|
2622
|
-
|
|
2751
|
+
selectChildSection,
|
|
2752
|
+
selectChunk,
|
|
2753
|
+
selectParentSection,
|
|
2754
|
+
selectSiblingSection
|
|
2623
2755
|
};
|
|
2624
2756
|
};
|
|
2625
2757
|
// src/vue/ai/useRAG.ts
|
|
@@ -3565,11 +3697,13 @@ var useRAGSources = (messages) => {
|
|
|
3565
3697
|
const chunkGraph = computed5(() => buildRAGChunkGraph(sources.value));
|
|
3566
3698
|
const citationReferenceMap = computed5(() => buildRAGCitationReferenceMap(sourceSummaries.value.flatMap((summary) => summary.citations)));
|
|
3567
3699
|
const hasSources = computed5(() => sources.value.length > 0);
|
|
3700
|
+
const navigationForChunk = (chunkId) => buildRAGChunkGraphNavigation(chunkGraph.value, chunkId ?? undefined);
|
|
3568
3701
|
return {
|
|
3569
3702
|
citationReferenceMap,
|
|
3570
3703
|
chunkGraph,
|
|
3571
3704
|
hasSources,
|
|
3572
3705
|
latestAssistantMessage,
|
|
3706
|
+
navigationForChunk,
|
|
3573
3707
|
sourceGroups,
|
|
3574
3708
|
sources,
|
|
3575
3709
|
sourceSummaries
|