@absolutejs/absolute 0.19.0-beta.606 → 0.19.0-beta.608
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 +195 -18
- package/dist/ai/client/index.js.map +4 -4
- package/dist/ai/client/ui.js +197 -18
- package/dist/ai/client/ui.js.map +4 -4
- package/dist/ai/index.js +424 -28
- package/dist/ai/index.js.map +7 -7
- package/dist/ai/rag/quality.js +145 -16
- package/dist/ai/rag/quality.js.map +3 -3
- package/dist/ai/rag/ui.js +197 -18
- package/dist/ai/rag/ui.js.map +4 -4
- package/dist/ai-client/angular/ai/index.js +194 -17
- package/dist/ai-client/react/ai/index.js +194 -17
- package/dist/ai-client/vue/ai/index.js +194 -17
- package/dist/angular/ai/index.js +195 -18
- package/dist/angular/ai/index.js.map +4 -4
- package/dist/react/ai/index.js +195 -18
- 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 +6 -3
- package/dist/src/ai/rag/ui.d.ts +1 -1
- package/dist/src/vue/ai/useRAG.d.ts +14 -4
- package/dist/src/vue/ai/useRAGChunkPreview.d.ts +12 -2
- package/dist/src/vue/ai/useRAGSearch.d.ts +2 -2
- package/dist/svelte/ai/index.js +195 -18
- package/dist/svelte/ai/index.js.map +6 -6
- package/dist/types/ai.d.ts +26 -2
- package/dist/vue/ai/index.js +195 -18
- package/dist/vue/ai/index.js.map +5 -5
- package/package.json +1 -1
package/dist/ai/rag/ui.js
CHANGED
|
@@ -236,6 +236,56 @@ var buildExcerpt = (text, maxLength = 160) => {
|
|
|
236
236
|
}
|
|
237
237
|
return `${normalized.slice(0, Math.max(0, maxLength - 1)).trimEnd()}\u2026`;
|
|
238
238
|
};
|
|
239
|
+
var selectPreferredExcerpt = (excerpts, sectionChunkCount) => {
|
|
240
|
+
if (!excerpts) {
|
|
241
|
+
return "";
|
|
242
|
+
}
|
|
243
|
+
const chunkExcerpt = excerpts.chunkExcerpt?.trim() ?? "";
|
|
244
|
+
const windowExcerpt = excerpts.windowExcerpt?.trim() ?? "";
|
|
245
|
+
const sectionExcerpt = excerpts.sectionExcerpt?.trim() ?? "";
|
|
246
|
+
if (sectionChunkCount && sectionChunkCount > 1 && chunkExcerpt.length > 0 && chunkExcerpt.length < 72) {
|
|
247
|
+
if (sectionChunkCount <= 3 && sectionExcerpt) {
|
|
248
|
+
return sectionExcerpt;
|
|
249
|
+
}
|
|
250
|
+
if (windowExcerpt) {
|
|
251
|
+
return windowExcerpt;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return chunkExcerpt || windowExcerpt || sectionExcerpt;
|
|
255
|
+
};
|
|
256
|
+
var buildGroundingChunkExcerpts = (sources, activeChunkId) => {
|
|
257
|
+
if (sources.length === 0) {
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
const activeSource = (activeChunkId ? sources.find((source) => source.chunkId === activeChunkId) : undefined) ?? sources[0];
|
|
261
|
+
if (!activeSource) {
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
const chunkMap = new Map(sources.map((source) => [source.chunkId, source]));
|
|
265
|
+
const activeMetadata = activeSource.metadata ?? {};
|
|
266
|
+
const previousChunkId = getContextString(activeMetadata.previousChunkId);
|
|
267
|
+
const nextChunkId = getContextString(activeMetadata.nextChunkId);
|
|
268
|
+
const sectionChunkId = getContextString(activeMetadata.sectionChunkId);
|
|
269
|
+
const sectionSources = sectionChunkId ? sources.filter((source) => getContextString(source.metadata?.sectionChunkId) === sectionChunkId).sort((left, right) => {
|
|
270
|
+
const leftIndex = getContextNumber(left.metadata?.sectionChunkIndex) ?? Number.MAX_SAFE_INTEGER;
|
|
271
|
+
const rightIndex = getContextNumber(right.metadata?.sectionChunkIndex) ?? Number.MAX_SAFE_INTEGER;
|
|
272
|
+
if (leftIndex !== rightIndex) {
|
|
273
|
+
return leftIndex - rightIndex;
|
|
274
|
+
}
|
|
275
|
+
return left.chunkId.localeCompare(right.chunkId);
|
|
276
|
+
}) : [activeSource];
|
|
277
|
+
const collectText = (chunkIds) => chunkIds.map((chunkId) => chunkMap.get(chunkId)?.text).filter((text) => typeof text === "string").join(`
|
|
278
|
+
|
|
279
|
+
`);
|
|
280
|
+
const orderedWindowIds = [previousChunkId, activeSource.chunkId, nextChunkId].filter((chunkId, index, values) => Boolean(chunkId) && values.indexOf(chunkId) === index);
|
|
281
|
+
return {
|
|
282
|
+
chunkExcerpt: buildExcerpt(activeSource.text, 160),
|
|
283
|
+
sectionExcerpt: buildExcerpt(sectionSources.map((source) => source.text).join(`
|
|
284
|
+
|
|
285
|
+
`), 320),
|
|
286
|
+
windowExcerpt: buildExcerpt(collectText(orderedWindowIds), 240)
|
|
287
|
+
};
|
|
288
|
+
};
|
|
239
289
|
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 ");
|
|
240
290
|
var buildGroundingReferenceEvidenceSummary = (reference) => [
|
|
241
291
|
reference.source ?? reference.title ?? reference.chunkId,
|
|
@@ -243,11 +293,19 @@ var buildGroundingReferenceEvidenceSummary = (reference) => [
|
|
|
243
293
|
reference.contextLabel,
|
|
244
294
|
reference.provenanceLabel
|
|
245
295
|
].filter((value) => Boolean(value && value.length > 0)).filter((value, index, values) => values.findIndex((entry) => entry === value) === index).join(" \xB7 ");
|
|
296
|
+
var buildGroundingSectionKey = (reference) => reference.contextLabel ?? reference.locatorLabel ?? reference.label ?? reference.source ?? reference.chunkId;
|
|
297
|
+
var buildGroundingSectionSummaryLine = (reference) => [
|
|
298
|
+
reference.source ?? reference.title ?? reference.chunkId,
|
|
299
|
+
reference.locatorLabel,
|
|
300
|
+
reference.contextLabel,
|
|
301
|
+
reference.provenanceLabel
|
|
302
|
+
].filter((value) => Boolean(value && value.length > 0)).filter((value, index, values) => values.findIndex((entry) => entry === value) === index).join(" \xB7 ");
|
|
246
303
|
var buildGroundedAnswerCitationDetail = (reference) => ({
|
|
247
304
|
contextLabel: reference.contextLabel,
|
|
248
305
|
evidenceLabel: buildGroundingReferenceEvidenceLabel(reference),
|
|
249
306
|
evidenceSummary: buildGroundingReferenceEvidenceSummary(reference),
|
|
250
|
-
excerpt: reference.excerpt,
|
|
307
|
+
excerpt: selectPreferredExcerpt(reference.excerpts, getContextNumber(reference.metadata?.sectionChunkCount)) || reference.excerpt,
|
|
308
|
+
excerpts: reference.excerpts,
|
|
251
309
|
label: reference.label,
|
|
252
310
|
locatorLabel: reference.locatorLabel,
|
|
253
311
|
number: reference.number,
|
|
@@ -333,26 +391,97 @@ var buildRAGGroundedAnswer = (content, sources) => {
|
|
|
333
391
|
hasCitations,
|
|
334
392
|
parts,
|
|
335
393
|
references,
|
|
394
|
+
sectionSummaries: buildRAGGroundedAnswerSectionSummaries(references),
|
|
336
395
|
ungroundedReferenceNumbers: [...ungroundedReferenceNumbers].sort((left, right) => left - right)
|
|
337
396
|
};
|
|
338
397
|
};
|
|
398
|
+
var buildRAGGroundedAnswerSectionSummaries = (references) => {
|
|
399
|
+
const groups = new Map;
|
|
400
|
+
for (const reference of references) {
|
|
401
|
+
const key = buildGroundingSectionKey(reference);
|
|
402
|
+
const existing = groups.get(key);
|
|
403
|
+
if (!existing) {
|
|
404
|
+
const excerpts = reference.excerpts ? {
|
|
405
|
+
chunkExcerpt: reference.excerpts.chunkExcerpt,
|
|
406
|
+
sectionExcerpt: reference.excerpts.sectionExcerpt,
|
|
407
|
+
windowExcerpt: reference.excerpts.windowExcerpt
|
|
408
|
+
} : undefined;
|
|
409
|
+
groups.set(key, {
|
|
410
|
+
chunkIds: [reference.chunkId],
|
|
411
|
+
contextLabel: reference.contextLabel,
|
|
412
|
+
count: 1,
|
|
413
|
+
excerpt: selectPreferredExcerpt(excerpts, getContextNumber(reference.metadata?.sectionChunkCount)) || excerpts?.sectionExcerpt || reference.excerpt,
|
|
414
|
+
excerpts,
|
|
415
|
+
key,
|
|
416
|
+
label: key,
|
|
417
|
+
locatorLabel: reference.locatorLabel,
|
|
418
|
+
provenanceLabel: reference.provenanceLabel,
|
|
419
|
+
referenceNumbers: [reference.number],
|
|
420
|
+
references: [reference],
|
|
421
|
+
summary: buildGroundingSectionSummaryLine(reference) || reference.label || reference.chunkId
|
|
422
|
+
});
|
|
423
|
+
continue;
|
|
424
|
+
}
|
|
425
|
+
existing.count += 1;
|
|
426
|
+
if (!existing.chunkIds.includes(reference.chunkId)) {
|
|
427
|
+
existing.chunkIds.push(reference.chunkId);
|
|
428
|
+
}
|
|
429
|
+
if (!existing.referenceNumbers.includes(reference.number)) {
|
|
430
|
+
existing.referenceNumbers.push(reference.number);
|
|
431
|
+
}
|
|
432
|
+
existing.references.push(reference);
|
|
433
|
+
if (!existing.contextLabel && reference.contextLabel) {
|
|
434
|
+
existing.contextLabel = reference.contextLabel;
|
|
435
|
+
}
|
|
436
|
+
if (!existing.locatorLabel && reference.locatorLabel) {
|
|
437
|
+
existing.locatorLabel = reference.locatorLabel;
|
|
438
|
+
}
|
|
439
|
+
if (!existing.provenanceLabel && reference.provenanceLabel) {
|
|
440
|
+
existing.provenanceLabel = reference.provenanceLabel;
|
|
441
|
+
}
|
|
442
|
+
if (!existing.excerpts && reference.excerpts) {
|
|
443
|
+
existing.excerpts = {
|
|
444
|
+
chunkExcerpt: reference.excerpts.chunkExcerpt,
|
|
445
|
+
sectionExcerpt: reference.excerpts.sectionExcerpt,
|
|
446
|
+
windowExcerpt: reference.excerpts.windowExcerpt
|
|
447
|
+
};
|
|
448
|
+
existing.excerpt = reference.excerpts.sectionExcerpt;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
return [...groups.values()].map((group) => ({
|
|
452
|
+
...group,
|
|
453
|
+
referenceNumbers: [...group.referenceNumbers].sort((left, right) => left - right),
|
|
454
|
+
references: group.references.slice().sort((left, right) => left.number - right.number)
|
|
455
|
+
})).sort((left, right) => {
|
|
456
|
+
const leftFirst = left.referenceNumbers[0] ?? Number.POSITIVE_INFINITY;
|
|
457
|
+
const rightFirst = right.referenceNumbers[0] ?? Number.POSITIVE_INFINITY;
|
|
458
|
+
if (leftFirst !== rightFirst) {
|
|
459
|
+
return leftFirst - rightFirst;
|
|
460
|
+
}
|
|
461
|
+
return left.label.localeCompare(right.label);
|
|
462
|
+
});
|
|
463
|
+
};
|
|
339
464
|
var buildRAGGroundingReferences = (sources) => {
|
|
340
465
|
const citations = buildRAGCitations(sources);
|
|
341
466
|
const citationReferenceMap = buildRAGCitationReferenceMap(citations);
|
|
342
|
-
return citations.map((citation) =>
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
467
|
+
return citations.map((citation) => {
|
|
468
|
+
const excerpts = buildGroundingChunkExcerpts(sources, citation.chunkId);
|
|
469
|
+
return {
|
|
470
|
+
chunkId: citation.chunkId,
|
|
471
|
+
contextLabel: citation.contextLabel ?? buildContextLabel(citation.metadata),
|
|
472
|
+
excerpt: selectPreferredExcerpt(excerpts, getContextNumber(citation.metadata?.sectionChunkCount)) || excerpts?.chunkExcerpt || buildExcerpt(citation.text),
|
|
473
|
+
excerpts,
|
|
474
|
+
label: citation.label,
|
|
475
|
+
locatorLabel: citation.locatorLabel ?? buildLocatorLabel(citation.metadata, citation.source, citation.title),
|
|
476
|
+
metadata: citation.metadata,
|
|
477
|
+
number: citationReferenceMap[citation.chunkId] ?? 0,
|
|
478
|
+
provenanceLabel: citation.provenanceLabel ?? buildProvenanceLabel(citation.metadata),
|
|
479
|
+
score: citation.score,
|
|
480
|
+
source: citation.source,
|
|
481
|
+
text: citation.text,
|
|
482
|
+
title: citation.title
|
|
483
|
+
};
|
|
484
|
+
});
|
|
356
485
|
};
|
|
357
486
|
|
|
358
487
|
// src/ai/rag/presentation.ts
|
|
@@ -941,7 +1070,7 @@ var buildRAGChunkStructure = (metadata) => {
|
|
|
941
1070
|
return;
|
|
942
1071
|
}
|
|
943
1072
|
const sectionPath = Array.isArray(metadata.sectionPath) ? metadata.sectionPath.filter((value) => typeof value === "string" && value.trim().length > 0) : undefined;
|
|
944
|
-
const sectionKind = metadata.sectionKind === "markdown_heading" || metadata.sectionKind === "html_heading" ? metadata.sectionKind : undefined;
|
|
1073
|
+
const sectionKind = metadata.sectionKind === "markdown_heading" || metadata.sectionKind === "html_heading" || metadata.sectionKind === "office_heading" || metadata.sectionKind === "spreadsheet_rows" || metadata.sectionKind === "presentation_slide" ? metadata.sectionKind : undefined;
|
|
945
1074
|
const section = {
|
|
946
1075
|
depth: getContextNumber2(metadata.sectionDepth),
|
|
947
1076
|
kind: sectionKind,
|
|
@@ -970,6 +1099,52 @@ var buildExcerpt2 = (text, maxLength = 160) => {
|
|
|
970
1099
|
}
|
|
971
1100
|
return `${normalized.slice(0, Math.max(0, maxLength - 1)).trimEnd()}\u2026`;
|
|
972
1101
|
};
|
|
1102
|
+
var buildRAGChunkExcerpts = (chunks, activeChunkId) => {
|
|
1103
|
+
if (chunks.length === 0) {
|
|
1104
|
+
return;
|
|
1105
|
+
}
|
|
1106
|
+
const graph = buildRAGChunkGraph(chunks.map((chunk) => ({
|
|
1107
|
+
chunkId: chunk.chunkId,
|
|
1108
|
+
metadata: chunk.metadata,
|
|
1109
|
+
structure: chunk.structure
|
|
1110
|
+
})));
|
|
1111
|
+
const navigation = buildRAGChunkGraphNavigation(graph, activeChunkId);
|
|
1112
|
+
const activeChunk = chunks.find((chunk) => chunk.chunkId === navigation.activeChunkId) ?? chunks[0];
|
|
1113
|
+
if (!activeChunk) {
|
|
1114
|
+
return;
|
|
1115
|
+
}
|
|
1116
|
+
const chunkMap = new Map(chunks.map((chunk) => [chunk.chunkId, chunk]));
|
|
1117
|
+
const orderedWindowIds = [
|
|
1118
|
+
navigation.previousNode?.chunkId,
|
|
1119
|
+
activeChunk.chunkId,
|
|
1120
|
+
navigation.nextNode?.chunkId
|
|
1121
|
+
].filter((chunkId, index, ids) => Boolean(chunkId) && ids.indexOf(chunkId) === index);
|
|
1122
|
+
const orderedSectionIds = navigation.sectionNodes.length > 0 ? navigation.sectionNodes.map((node) => node.chunkId) : [activeChunk.chunkId];
|
|
1123
|
+
const collectText = (chunkIds) => chunkIds.map((chunkId) => chunkMap.get(chunkId)?.text).filter((text) => typeof text === "string").join(`
|
|
1124
|
+
|
|
1125
|
+
`);
|
|
1126
|
+
return {
|
|
1127
|
+
chunkExcerpt: buildExcerpt2(activeChunk.text, 160),
|
|
1128
|
+
sectionExcerpt: buildExcerpt2(collectText(orderedSectionIds), 320),
|
|
1129
|
+
windowExcerpt: buildExcerpt2(collectText(orderedWindowIds), 240)
|
|
1130
|
+
};
|
|
1131
|
+
};
|
|
1132
|
+
var buildRAGPreferredExcerpt = (excerpts, structure) => {
|
|
1133
|
+
if (!excerpts) {
|
|
1134
|
+
return "";
|
|
1135
|
+
}
|
|
1136
|
+
const chunkLength = excerpts.chunkExcerpt.trim().length;
|
|
1137
|
+
const sectionChunkCount = structure?.sequence?.sectionChunkCount ?? 1;
|
|
1138
|
+
if (sectionChunkCount > 1 && chunkLength > 0 && chunkLength < 72) {
|
|
1139
|
+
if (sectionChunkCount <= 3 && excerpts.sectionExcerpt.trim().length > 0) {
|
|
1140
|
+
return excerpts.sectionExcerpt;
|
|
1141
|
+
}
|
|
1142
|
+
if (excerpts.windowExcerpt.trim().length > 0) {
|
|
1143
|
+
return excerpts.windowExcerpt;
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
return excerpts.chunkExcerpt;
|
|
1147
|
+
};
|
|
973
1148
|
var buildRAGChunkGraph = (chunks) => {
|
|
974
1149
|
const nodes = [];
|
|
975
1150
|
const edges = [];
|
|
@@ -1181,6 +1356,7 @@ var buildRAGSourceSummaries = (sources) => {
|
|
|
1181
1356
|
return sourceGroups.map((group) => {
|
|
1182
1357
|
const groupCitations = citations.filter((citation) => group.chunks.some((chunk) => chunk.chunkId === citation.chunkId));
|
|
1183
1358
|
const leadChunk = group.chunks.slice().sort((left, right) => right.score - left.score)[0];
|
|
1359
|
+
const excerpts = leadChunk ? buildRAGChunkExcerpts(group.chunks, leadChunk.chunkId) : undefined;
|
|
1184
1360
|
return {
|
|
1185
1361
|
bestScore: group.bestScore,
|
|
1186
1362
|
citationNumbers: groupCitations.map((citation) => citationReferenceMap[citation.chunkId] ?? 0),
|
|
@@ -1188,7 +1364,8 @@ var buildRAGSourceSummaries = (sources) => {
|
|
|
1188
1364
|
chunkIds: group.chunks.map((chunk) => chunk.chunkId),
|
|
1189
1365
|
contextLabel: leadChunk?.labels?.contextLabel ?? buildContextLabel2(leadChunk?.metadata),
|
|
1190
1366
|
count: group.count,
|
|
1191
|
-
excerpt: buildExcerpt2(leadChunk?.text ?? ""),
|
|
1367
|
+
excerpt: buildRAGPreferredExcerpt(excerpts, leadChunk?.structure ?? buildRAGChunkStructure(leadChunk?.metadata)) || buildExcerpt2(leadChunk?.text ?? ""),
|
|
1368
|
+
excerpts,
|
|
1192
1369
|
key: group.key,
|
|
1193
1370
|
label: group.label,
|
|
1194
1371
|
locatorLabel: leadChunk?.labels?.locatorLabel ?? buildLocatorLabel2(leadChunk?.metadata, leadChunk?.source, leadChunk?.title),
|
|
@@ -1992,6 +2169,7 @@ export {
|
|
|
1992
2169
|
buildRAGGroundingProviderOverviewPresentation,
|
|
1993
2170
|
buildRAGGroundingProviderCaseComparisonPresentations,
|
|
1994
2171
|
buildRAGGroundingOverviewPresentation,
|
|
2172
|
+
buildRAGGroundedAnswerSectionSummaries,
|
|
1995
2173
|
buildRAGGroundedAnswer,
|
|
1996
2174
|
buildRAGEvaluationHistoryRows,
|
|
1997
2175
|
buildRAGEvaluationHistoryPresentation,
|
|
@@ -2005,6 +2183,7 @@ export {
|
|
|
2005
2183
|
buildRAGChunkPreviewGraph,
|
|
2006
2184
|
buildRAGChunkGraphNavigation,
|
|
2007
2185
|
buildRAGChunkGraph,
|
|
2186
|
+
buildRAGChunkExcerpts,
|
|
2008
2187
|
buildRAGAnswerWorkflowState,
|
|
2009
2188
|
buildRAGAnswerGroundingHistoryRows,
|
|
2010
2189
|
buildRAGAnswerGroundingHistoryPresentation,
|
|
@@ -2015,5 +2194,5 @@ export {
|
|
|
2015
2194
|
buildRAGAdminActionPresentation
|
|
2016
2195
|
};
|
|
2017
2196
|
|
|
2018
|
-
//# debugId=
|
|
2197
|
+
//# debugId=726F5089BA9C01AA64756E2164756E21
|
|
2019
2198
|
//# sourceMappingURL=ui.js.map
|