Improve LightRAG knowledge search locator alignment

This commit is contained in:
lix-2026
2026-06-08 20:35:49 +08:00
parent 9551d4c1dc
commit 0e8b03daf8
28 changed files with 5769 additions and 140 deletions
@@ -984,9 +984,11 @@ export const createResourceTabRuntime = (dependencies = {}) => {
const bbox = normalizeEvidenceBBox(input.bbox ?? locator?.bbox ?? params.bbox);
const sourceMapPath = String(input.sourceMapPath || locator?.sourceMapPath || params.sourceMapPath || '').trim();
const blockId = String(input.blockId || locator?.blockId || params.blockId || '').trim();
const evidenceText = String(input.evidenceText || input.query || locator?.evidenceText || locator?.query || params.evidenceText || params.query || '').trim();
const searchQuery = String(input.searchQuery || locator?.searchQuery || params.searchQuery || '').trim();
const lineRange = input.lineRange || locator?.lineRange || params.lineRange || null;
const charRange = input.charRange || locator?.charRange || params.charRange || null;
if (!locator && !Number.isFinite(page) && !bbox && !sourceMapPath && !blockId && !lineRange && !charRange) return null;
if (!locator && !Number.isFinite(page) && !bbox && !sourceMapPath && !blockId && !evidenceText && !lineRange && !charRange) return null;
return {
schema: 'mnote.evidence_locator.v1',
...(locator || {}),
@@ -994,6 +996,8 @@ export const createResourceTabRuntime = (dependencies = {}) => {
bbox,
sourceMapPath,
blockId,
evidenceText,
searchQuery,
lineRange,
charRange,
};
@@ -1013,13 +1017,29 @@ export const createResourceTabRuntime = (dependencies = {}) => {
if (bbox) url.searchParams.set('bbox', bbox);
if (locator.sourceMapPath) url.searchParams.set('sourceMapPath', String(locator.sourceMapPath));
if (locator.blockId) url.searchParams.set('blockId', String(locator.blockId));
if (locator.evidenceText) url.searchParams.set('evidenceText', String(locator.evidenceText));
if (locator.searchQuery) url.searchParams.set('searchQuery', String(locator.searchQuery));
if (url.pathname === '/office-preview' && frame.contentWindow) {
const currentSrc = new URL(frame.getAttribute('src') || frame.src || '', window.location.origin);
if (officePreviewBaseHref(currentSrc.toString()) !== officePreviewBaseHref(url.toString())) {
frame.src = url.toString();
return;
}
const frameDoc = frame.contentDocument || null;
const previewReady = frameDoc?.documentElement?.getAttribute('data-mnote-office-preview-status') === '完成'
|| (frameDoc?.readyState === 'complete' && Boolean(frameDoc?.body?.dataset?.fileUrl));
if (!previewReady) {
frame.src = url.toString();
return;
}
frame.contentWindow.postMessage({
type: 'mnote:office-evidence-locator',
page: locator.page,
bbox,
sourceMapPath: locator.sourceMapPath || '',
blockId: locator.blockId || '',
evidenceText: locator.evidenceText || '',
searchQuery: locator.searchQuery || '',
}, window.location.origin);
return;
}
@@ -1095,6 +1115,7 @@ export const createResourceTabRuntime = (dependencies = {}) => {
entry.panel.setAttribute('data-mnote-evidence-open', 'true');
if (Number.isFinite(Number(locator.page))) entry.panel.setAttribute('data-mnote-evidence-page', String(Number(locator.page)));
if (locator.blockId) entry.panel.setAttribute('data-mnote-evidence-block-id', String(locator.blockId));
if (locator.evidenceText) entry.panel.setAttribute('data-mnote-evidence-text', String(locator.evidenceText).slice(0, 240));
if (locator.sourceMapPath) entry.panel.setAttribute('data-mnote-evidence-source-map-path', String(locator.sourceMapPath));
const bbox = evidenceBBoxParam(locator.bbox);
if (bbox) entry.panel.setAttribute('data-mnote-evidence-bbox', bbox);
@@ -2286,7 +2307,7 @@ export const createResourceTabRuntime = (dependencies = {}) => {
if (!raw) return '';
try {
const url = new URL(raw, window.location.origin);
['page', 'bbox', 'sourceMapPath', 'blockId', 'lineRange', 'charRange', 'mnoteResourceReload'].forEach((key) => {
['page', 'bbox', 'sourceMapPath', 'blockId', 'lineRange', 'charRange', 'evidenceText', 'query', 'searchQuery', 'mnoteResourceReload'].forEach((key) => {
url.searchParams.delete(key);
});
return url.pathname + '?' + url.searchParams.toString();