集成 OpenHub 与 WeKnora Page AI
This commit is contained in:
@@ -199,6 +199,12 @@ export function createSidebarPageAiRuntime(context) {
|
||||
pageAiOpencodeEventSource: null,
|
||||
pageAiOpencodeEventSessionId: '',
|
||||
pageAiOpencodeEventTimer: 0,
|
||||
pageAiOpenHubStatus: null,
|
||||
pageAiOpenHubStatusError: '',
|
||||
pageAiOpenHubBootstrap: null,
|
||||
pageAiOpenHubIframeUrl: '',
|
||||
pageAiOpenHubScopeSummary: '',
|
||||
pageAiOpenHubFallbackReason: '',
|
||||
pageAiSessionSearchQuery: '',
|
||||
pageAiSessionSearchResults: [],
|
||||
pageAiSessionSearchTimer: 0,
|
||||
@@ -886,6 +892,10 @@ export function createSidebarPageAiRuntime(context) {
|
||||
}
|
||||
}
|
||||
|
||||
function pageAiOpenHubHostEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
function pageAiOpencodeStatusLabel(status) {
|
||||
var node = status && typeof status === 'object' ? status : {};
|
||||
var state = String(node.status || node.state || node.runtimeStatus || '').trim();
|
||||
@@ -949,6 +959,44 @@ export function createSidebarPageAiRuntime(context) {
|
||||
});
|
||||
}
|
||||
|
||||
function pageAiNormalizeRootRelativePath(path) {
|
||||
return String(path || '').trim().replace(/\\/g, '/').replace(/^\/+/, '');
|
||||
}
|
||||
|
||||
function pageAiRootPathFromFileUri(rootUri) {
|
||||
var root = String(rootUri || '').trim();
|
||||
if (!root.startsWith('file://')) return '';
|
||||
try {
|
||||
return decodeURIComponent(new URL(root).pathname || '').replace(/\/+$/, '');
|
||||
} catch (_error) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
function pageAiRootRelativePathFromChangedPath(path, rootUri) {
|
||||
var value = String(path || '').trim();
|
||||
if (!value) return '';
|
||||
try {
|
||||
var parsed = new URL(value, window.location.origin);
|
||||
if (parsed.pathname === '/api/local-folder/files/open') {
|
||||
return pageAiNormalizeRootRelativePath(parsed.searchParams.get('path') || '');
|
||||
}
|
||||
if (parsed.protocol === 'file:') value = decodeURIComponent(parsed.pathname || '');
|
||||
} catch (_error) {}
|
||||
value = value.replace(/^file:\/\//, '');
|
||||
var rootPath = pageAiRootPathFromFileUri(rootUri || currentRootUri());
|
||||
if (rootPath && value.startsWith(rootPath + '/')) {
|
||||
value = value.slice(rootPath.length + 1);
|
||||
}
|
||||
return pageAiNormalizeRootRelativePath(value);
|
||||
}
|
||||
|
||||
function pageAiDocumentIdFromRootRelativePath(relativePath) {
|
||||
var normalized = pageAiNormalizeRootRelativePath(relativePath);
|
||||
if (!normalized || !/\.(md|markdown)$/i.test(normalized)) return '';
|
||||
return localMarkdownDocumentIdFromPageAiRelativePath(normalized);
|
||||
}
|
||||
|
||||
function pageAiOpencodeCurrentPageLabel() {
|
||||
var aggregate = currentPageAggregate();
|
||||
var meta = aggregate && aggregate.meta && typeof aggregate.meta === 'object' ? aggregate.meta : {};
|
||||
@@ -983,6 +1031,95 @@ export function createSidebarPageAiRuntime(context) {
|
||||
}
|
||||
}
|
||||
|
||||
function pageAiMNoteDocumentPathSegment(documentId) {
|
||||
return encodeURIComponent(String(documentId || '').trim()).replace(/%3A/g, ':').replace(/%7E/g, '~');
|
||||
}
|
||||
|
||||
function pageAiParentRelativePath(relativePath) {
|
||||
var normalized = pageAiNormalizeRootRelativePath(relativePath);
|
||||
if (!normalized || normalized.indexOf('/') === -1) return '';
|
||||
return normalized.split('/').slice(0, -1).join('/');
|
||||
}
|
||||
|
||||
function pageAiFileUriForRootRelativePath(rootUri, relativePath) {
|
||||
var root = String(rootUri || '').trim().replace(/\/+$/, '');
|
||||
var relative = pageAiNormalizeRootRelativePath(relativePath);
|
||||
if (!root) return '';
|
||||
if (!relative) return root;
|
||||
return root + '/' + relative.split('/').map(function(segment) {
|
||||
return encodeURIComponent(segment);
|
||||
}).join('/');
|
||||
}
|
||||
|
||||
function pageAiCurrentActiveTabEditorTarget() {
|
||||
var snapshot = currentPageAiOpenEditorsSnapshot();
|
||||
if (snapshot && snapshot.activeEditor) {
|
||||
var activeTarget = pageAiTargetFromOpenEditor(snapshot.activeEditor, 'open_editors_active_tab');
|
||||
if (activeTarget) return activeTarget;
|
||||
}
|
||||
if (snapshot) {
|
||||
var entries = pageAiNormalizeArray(snapshot.editors).concat(pageAiNormalizeArray(snapshot.resourceEditors));
|
||||
var activeEntry = entries.find(function(entry) { return entry && entry.active === true; });
|
||||
if (activeEntry) {
|
||||
var target = pageAiTargetFromOpenEditor(activeEntry, 'open_editors_active_tab');
|
||||
if (target) return target;
|
||||
}
|
||||
}
|
||||
return pageAiFallbackEditorTarget();
|
||||
}
|
||||
|
||||
function pageAiCurrentActiveTabAddressPayload() {
|
||||
var target = pageAiCurrentActiveTabEditorTarget() || {};
|
||||
var workspacePath = target && target.workspacePath && typeof target.workspacePath === 'object' ? target.workspacePath : {};
|
||||
var rootUri = String(workspacePath.rootUri || target.rootUri || currentRootUri() || '').trim();
|
||||
var sourceKind = String(workspacePath.sourceKind || target.sourceKind || currentSourceKind() || '').trim();
|
||||
var workspaceId = String(workspacePath.workspaceId || target.workspaceId || resolveWorkspaceId(document.body) || '').trim();
|
||||
var documentId = String(workspacePath.documentId || target.documentId || currentDocumentId() || '').trim();
|
||||
var relativePath = pageAiNormalizeRootRelativePath(workspacePath.relativePath || workspacePath.path || target.relativePath || target.path || '');
|
||||
if (!relativePath) relativePath = pageAiNormalizeRootRelativePath(localMarkdownRelativePathFromPageAiDocumentId(documentId));
|
||||
if (!documentId && relativePath && /\.(md|markdown)$/i.test(relativePath)) {
|
||||
documentId = localMarkdownDocumentIdFromPageAiRelativePath(relativePath);
|
||||
}
|
||||
if (!documentId) documentId = String(currentDocumentId() || '').trim();
|
||||
var resourceKind = String(target.resourceKind || workspacePath.resourceKind || target.editorKind || '').trim().toLowerCase();
|
||||
var editorKind = String(target.editorKind || '').trim().toLowerCase();
|
||||
var objectIdentity = String(target.objectIdentity || target.targetId || workspacePath.objectIdentity || '').trim();
|
||||
var tabUrl = new URL('/documents/' + pageAiMNoteDocumentPathSegment(documentId), window.location.origin);
|
||||
if (sourceKind) tabUrl.searchParams.set('sourceKind', sourceKind);
|
||||
if (rootUri) tabUrl.searchParams.set('rootUri', rootUri);
|
||||
if (workspaceId) tabUrl.searchParams.set('workspaceId', workspaceId);
|
||||
var isResourceTab = Boolean(relativePath)
|
||||
&& resourceKind !== 'markdown_page'
|
||||
&& resourceKind !== 'page'
|
||||
&& editorKind !== 'page';
|
||||
if (isResourceTab) {
|
||||
tabUrl.searchParams.set('resourcePath', relativePath);
|
||||
if (objectIdentity) tabUrl.searchParams.set('resourceTab', objectIdentity);
|
||||
}
|
||||
var folderRelativePath = pageAiParentRelativePath(relativePath);
|
||||
var folderUrl = pageAiFileUriForRootRelativePath(rootUri, folderRelativePath);
|
||||
if (!folderUrl) {
|
||||
var folderMNoteUrl = new URL('/documents/' + pageAiMNoteDocumentPathSegment(documentId), window.location.origin);
|
||||
if (sourceKind) folderMNoteUrl.searchParams.set('sourceKind', sourceKind);
|
||||
if (rootUri) folderMNoteUrl.searchParams.set('rootUri', rootUri);
|
||||
if (workspaceId) folderMNoteUrl.searchParams.set('workspaceId', workspaceId);
|
||||
if (folderRelativePath) folderMNoteUrl.searchParams.set('fileTreeScope', folderRelativePath);
|
||||
folderUrl = folderMNoteUrl.toString();
|
||||
}
|
||||
return {
|
||||
schema: 'mnote.page_ai.active_tab_address.v1',
|
||||
tabUrl: tabUrl.toString(),
|
||||
folderUrl: folderUrl,
|
||||
documentId: documentId,
|
||||
rootUri: rootUri,
|
||||
workspaceId: workspaceId,
|
||||
relativePath: relativePath,
|
||||
folderRelativePath: folderRelativePath,
|
||||
targetId: String(target.targetId || objectIdentity || '').trim(),
|
||||
resourceKind: resourceKind || 'markdown_page'
|
||||
};
|
||||
}
|
||||
|
||||
function pageAiBuildOpencodeContextPayload() {
|
||||
var selectedText = currentPageAiSelectedText();
|
||||
var target = currentPageAiEditorTarget() || {};
|
||||
@@ -1014,6 +1151,116 @@ export function createSidebarPageAiRuntime(context) {
|
||||
return lines.join('\n');
|
||||
}
|
||||
|
||||
function pageAiOpenHubScopeSummary(scope) {
|
||||
var node = scope && typeof scope === 'object' ? scope : {};
|
||||
var workspace = node.workspaceScope && typeof node.workspaceScope === 'object' ? node.workspaceScope : {};
|
||||
var items = [];
|
||||
if (node.openhubUserKey || node.openhub_user_key) items.push('openhub_user_key=' + String(node.openhubUserKey || node.openhub_user_key));
|
||||
if (node.openhubWorkspaceKey || node.workspace_key) items.push('workspace_key=' + String(node.openhubWorkspaceKey || node.workspace_key));
|
||||
if (workspace.workspaceId) items.push('workspace=' + String(workspace.workspaceId));
|
||||
if (workspace.rootUri) items.push('rootUri=' + String(workspace.rootUri));
|
||||
if (node.openhubSessionScope || node.session_scope) items.push('session_scope=' + String(node.openhubSessionScope || node.session_scope));
|
||||
if (node.skillScope || node.skill_scope) items.push('skill_scope=' + String(node.skillScope || node.skill_scope));
|
||||
if (node.mcpScope) items.push('mcp_scope=' + String(node.mcpScope));
|
||||
if (node.toolPermissionScope || node.tool_permission_scope) items.push('tool_permission_scope=' + String(node.toolPermissionScope || node.tool_permission_scope));
|
||||
if (node.weknoraToolScope || node.weknora_tool_scope) items.push('weknora_tool_scope=' + String(node.weknoraToolScope || node.weknora_tool_scope));
|
||||
return items.join('\n');
|
||||
}
|
||||
|
||||
function pageAiOpenHubStatusText(status) {
|
||||
var node = status && typeof status === 'object' ? status : {};
|
||||
if (node.ok === true || String(node.status || '').trim() === 'ready') return '已连接 OpenHub';
|
||||
if (String(node.status || '').trim() === 'degraded') return 'OpenHub 连接受限';
|
||||
return '正在连接 OpenHub';
|
||||
}
|
||||
|
||||
function pageAiRenderOpenHubHostChrome() {
|
||||
var drawer = document.querySelector('[data-testid="wolai-page-ai-drawer"]');
|
||||
if (!(drawer instanceof HTMLElement) || drawer.getAttribute('data-page-ai-openhub-host') !== 'true') return;
|
||||
var bootstrap = pageUiState.pageAiOpenHubBootstrap && typeof pageUiState.pageAiOpenHubBootstrap === 'object' ? pageUiState.pageAiOpenHubBootstrap : {};
|
||||
var scope = bootstrap.scope && typeof bootstrap.scope === 'object' ? bootstrap.scope : {};
|
||||
var status = pageUiState.pageAiOpenHubStatus && typeof pageUiState.pageAiOpenHubStatus === 'object' ? pageUiState.pageAiOpenHubStatus : {};
|
||||
var statusNode = drawer.querySelector('[data-page-ai-openhub-runtime-status]');
|
||||
if (statusNode instanceof HTMLElement) {
|
||||
statusNode.textContent = pageUiState.pageAiOpenHubStatusError || pageAiOpenHubStatusText(status);
|
||||
statusNode.setAttribute('data-state', pageUiState.pageAiOpenHubStatusError ? 'error' : (status.ok ? 'ok' : 'degraded'));
|
||||
}
|
||||
var userNode = drawer.querySelector('[data-page-ai-openhub-user-key]');
|
||||
if (userNode instanceof HTMLElement) userNode.textContent = String(scope.openhubUserKey || scope.openhub_user_key || '等待 bootstrap');
|
||||
var authNode = drawer.querySelector('[data-page-ai-openhub-auth-truth]');
|
||||
if (authNode instanceof HTMLElement) authNode.textContent = '登录真相:MNote mnote_session;拒绝 OpenHub JWT/localStorage';
|
||||
var workspaceNode = drawer.querySelector('[data-page-ai-openhub-workspace-scope]');
|
||||
if (workspaceNode instanceof HTMLElement) workspaceNode.textContent = pageAiOpenHubScopeSummary(scope) || '等待 workspace/rootUri/session/tool scope';
|
||||
var guardNode = drawer.querySelector('[data-page-ai-openhub-route-guard]');
|
||||
if (guardNode instanceof HTMLElement) guardNode.textContent = '非 AI 路由 guard:login/admin/file/knowledge 由 MNote 接管';
|
||||
var fallbackNode = drawer.querySelector('[data-page-ai-openhub-fallback]');
|
||||
if (fallbackNode instanceof HTMLElement) {
|
||||
fallbackNode.textContent = pageUiState.pageAiOpenHubFallbackReason || 'OpenHub 不可用时提示用户刷新或检查服务,不再提供 opencode 页面回退';
|
||||
}
|
||||
var iframe = drawer.querySelector('[data-page-ai-openhub-iframe]');
|
||||
if (iframe instanceof HTMLIFrameElement) {
|
||||
var nextUrl = String(pageUiState.pageAiOpenHubIframeUrl || bootstrap.openhubIframeUrl || '/page-ai/openhub/ai').trim();
|
||||
if (nextUrl && iframe.getAttribute('src') !== nextUrl) iframe.setAttribute('src', nextUrl);
|
||||
iframe.hidden = !nextUrl;
|
||||
}
|
||||
}
|
||||
|
||||
function pageAiEnsureOpenHubHostDrawer() {
|
||||
var drawer = ensurePageAiDrawer();
|
||||
pageAiInstallMNoteOpenFileBridge();
|
||||
if (drawer.getAttribute('data-page-ai-openhub-host') !== 'true') {
|
||||
drawer.setAttribute('data-page-ai-openhub-host', 'true');
|
||||
drawer.removeAttribute('data-page-ai-opencode-host');
|
||||
drawer.setAttribute('data-mnote-acp-runtime', 'openhub-opencode');
|
||||
drawer.innerHTML = '' +
|
||||
'<div class="wolai-page-ai-resize-handle" data-page-ai-resize-handle title="拖动调整页面 AI 宽度" aria-hidden="true"></div>' +
|
||||
'<div class="wolai-page-ai-panel wolai-page-ai-opencode-panel" role="dialog" aria-modal="false" aria-label="OpenHub AI">' +
|
||||
'<details class="wolai-page-ai-openhub-diagnostics" data-page-ai-openhub-bootstrap-copy hidden aria-hidden="true">' +
|
||||
'<summary>诊断</summary>' +
|
||||
'<div class="wolai-page-ai-opencode-row"><span>用户隔离</span><code data-page-ai-openhub-user-key>等待 bootstrap</code></div>' +
|
||||
'<div class="wolai-page-ai-opencode-row"><span>认证边界</span><strong data-page-ai-openhub-auth-truth>登录真相:MNote mnote_session</strong></div>' +
|
||||
'<pre class="wolai-page-ai-opencode-empty" data-page-ai-openhub-workspace-scope>等待 workspace/rootUri/session/tool scope</pre>' +
|
||||
'<div class="wolai-page-ai-opencode-badges"><span data-page-ai-openhub-route-guard>非 AI 路由 guard:login/admin/file/knowledge</span><span data-page-ai-openhub-fallback>OpenHub 不可用时提示刷新或检查服务</span></div>' +
|
||||
'</details>' +
|
||||
'<div class="wolai-page-ai-opencode-frame-wrap" data-page-ai-openhub-frame-wrap>' +
|
||||
'<iframe class="wolai-page-ai-opencode-iframe" data-page-ai-openhub-iframe title="OpenHub AI 面板" allow="clipboard-read; clipboard-write" referrerpolicy="same-origin" src="about:blank"></iframe>' +
|
||||
'</div>' +
|
||||
'</div>';
|
||||
}
|
||||
pageAiRenderOpenHubHostChrome();
|
||||
void pageAiBootstrapOpenHubHost();
|
||||
return drawer;
|
||||
}
|
||||
|
||||
async function pageAiBootstrapOpenHubHost() {
|
||||
var context = pageAiBuildOpencodeContextPayload();
|
||||
try {
|
||||
var statusResponse = await fetch('/api/page-ai/openhub/status', { headers: { accept: 'application/json' }, cache: 'no-store' });
|
||||
pageUiState.pageAiOpenHubStatus = await statusResponse.json().catch(function() { return null; }) || {};
|
||||
var response = await fetch('/api/page-ai/openhub/bootstrap', {
|
||||
method: 'POST',
|
||||
headers: { 'content-type': 'application/json', accept: 'application/json' },
|
||||
cache: 'no-store',
|
||||
body: JSON.stringify(context)
|
||||
});
|
||||
var payload = await response.json().catch(function() { return null; });
|
||||
if (!response.ok) throw new Error(payload && (payload.error || payload.message) ? String(payload.error || payload.message) : 'HTTP ' + response.status);
|
||||
pageUiState.pageAiOpenHubBootstrap = payload || {};
|
||||
pageUiState.pageAiOpenHubStatusError = '';
|
||||
pageUiState.pageAiOpenHubIframeUrl = String(payload && payload.openhubIframeUrl || '/page-ai/openhub/ai').trim();
|
||||
var statusFallback = pageUiState.pageAiOpenHubStatus && pageUiState.pageAiOpenHubStatus.fallback ? pageUiState.pageAiOpenHubStatus.fallback : null;
|
||||
pageUiState.pageAiOpenHubFallbackReason = payload && payload.fallback
|
||||
? String(payload.fallback.reason || '')
|
||||
: (statusFallback ? String(statusFallback.reason || '') : '');
|
||||
pageUiState.pageAiOpenHubScopeSummary = pageAiOpenHubScopeSummary(payload && payload.scope);
|
||||
pageAiRenderOpenHubHostChrome();
|
||||
} catch (error) {
|
||||
pageUiState.pageAiOpenHubStatusError = error instanceof Error ? error.message : String(error);
|
||||
pageUiState.pageAiOpenHubFallbackReason = 'OpenHub bootstrap 不可用,请刷新或检查 OpenHub 服务';
|
||||
pageAiRenderOpenHubHostChrome();
|
||||
}
|
||||
}
|
||||
|
||||
function pageAiPostOpencodeBridgeMessage(type, payload) {
|
||||
var iframe = document.querySelector('[data-page-ai-opencode-iframe]');
|
||||
if (!(iframe instanceof HTMLIFrameElement) || !iframe.contentWindow) return false;
|
||||
@@ -1021,6 +1268,41 @@ export function createSidebarPageAiRuntime(context) {
|
||||
return true;
|
||||
}
|
||||
|
||||
function pageAiInstallMNoteOpenFileBridge() {
|
||||
if (pageUiState.pageAiMNoteOpenFileBridgeInstalled) return;
|
||||
pageUiState.pageAiMNoteOpenFileBridgeInstalled = true;
|
||||
window.addEventListener('message', function(event) {
|
||||
if (event.origin !== window.location.origin) return;
|
||||
var message = event.data && typeof event.data === 'object' ? event.data : null;
|
||||
if (message && message.source === 'openhub-ai' && message.type === 'mnote:get-active-tab-address') {
|
||||
var addressPayload = pageAiCurrentActiveTabAddressPayload();
|
||||
var requestPayload = message.payload && typeof message.payload === 'object' ? message.payload : {};
|
||||
var kind = String(requestPayload.kind || message.kind || 'tab').trim();
|
||||
var value = kind === 'folder' ? addressPayload.folderUrl : addressPayload.tabUrl;
|
||||
if (event.source && typeof event.source.postMessage === 'function') {
|
||||
event.source.postMessage({
|
||||
source: 'mnote-page-ai',
|
||||
type: 'mnote:active-tab-address',
|
||||
requestId: message.requestId || '',
|
||||
payload: Object.assign({}, addressPayload, {
|
||||
kind: kind === 'folder' ? 'folder' : 'tab',
|
||||
value: value
|
||||
})
|
||||
}, event.origin);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!message || (message.type !== 'mnote:open-file' && message.type !== 'mnote:open-reference')) return;
|
||||
if (message.source !== 'openhub-diff' && message.source !== 'openhub-changed-files' && message.source !== 'openhub-citation') return;
|
||||
var payload = message.payload && typeof message.payload === 'object' ? message.payload : {};
|
||||
pageAiOpenOpencodeChangedFile(message.path || payload.path || payload.href || '', {
|
||||
rootUri: String(message.rootUri || payload.rootUri || payload.root_uri || currentRootUri() || '').trim(),
|
||||
workspaceId: String(message.workspaceId || payload.workspaceId || payload.workspace_id || resolveWorkspaceId(document.body) || '').trim(),
|
||||
documentId: String(message.documentId || payload.documentId || payload.document_id || '').trim()
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function pageAiInstallOpencodeBridge() {
|
||||
if (pageUiState.pageAiOpencodeBridgeInstalled) return;
|
||||
pageUiState.pageAiOpencodeBridgeInstalled = true;
|
||||
@@ -1254,8 +1536,10 @@ export function createSidebarPageAiRuntime(context) {
|
||||
|
||||
function pageAiEnsureOpencodeHostDrawer() {
|
||||
var drawer = ensurePageAiDrawer();
|
||||
pageAiInstallMNoteOpenFileBridge();
|
||||
if (drawer.getAttribute('data-page-ai-opencode-host') !== 'true') {
|
||||
drawer.setAttribute('data-page-ai-opencode-host', 'true');
|
||||
drawer.removeAttribute('data-page-ai-openhub-host');
|
||||
drawer.setAttribute('data-mnote-acp-runtime', 'opencode');
|
||||
drawer.innerHTML = '' +
|
||||
'<div class="wolai-page-ai-resize-handle" data-page-ai-resize-handle title="拖动调整页面 AI 宽度" aria-hidden="true"></div>' +
|
||||
@@ -1530,16 +1814,59 @@ export function createSidebarPageAiRuntime(context) {
|
||||
pageAiRenderOpencodeHostChrome();
|
||||
}
|
||||
|
||||
function pageAiOpenOpencodeChangedFile(path) {
|
||||
var targetPath = String(path || '').trim();
|
||||
if (!targetPath || !window.__mnoteDocumentPaneRuntime || typeof window.__mnoteDocumentPaneRuntime.openResourceInActiveTab !== 'function') return false;
|
||||
void window.__mnoteDocumentPaneRuntime.openResourceInActiveTab({ path: targetPath });
|
||||
function pageAiOpenOpencodeChangedFile(path, options) {
|
||||
var rootUri = String(options && options.rootUri || currentRootUri() || '').trim();
|
||||
var targetPath = pageAiRootRelativePathFromChangedPath(path, rootUri);
|
||||
if (!targetPath || !window.__mnoteDocumentPaneRuntime) return false;
|
||||
var documentId = String(options && options.documentId || pageAiDocumentIdFromRootRelativePath(targetPath) || '').trim();
|
||||
var workspaceId = String(options && options.workspaceId || resolveWorkspaceId(document.body) || '').trim();
|
||||
var isMarkdown = Boolean(documentId);
|
||||
if (isMarkdown) {
|
||||
if (window.__mnoteLocalFolderEventBus && typeof window.__mnoteLocalFolderEventBus.emitSyntheticWatchBatch === 'function') {
|
||||
window.__mnoteLocalFolderEventBus.emitSyntheticWatchBatch({
|
||||
source: 'openhub_changed_file_bridge',
|
||||
reason: 'openhub_changed_file',
|
||||
rootUri: rootUri,
|
||||
workspaceId: workspaceId,
|
||||
payload: {
|
||||
schema: 'mnote.local_folder.watch_batch.v1',
|
||||
source: 'openhub_changed_file_bridge',
|
||||
rootUri: rootUri,
|
||||
changedPaths: [{ relativePath: targetPath, documentId: documentId, changeType: 'modified' }],
|
||||
affectedParents: [{ relativePath: pageAiParentRelativePath(targetPath), reason: 'openhub_changed_file' }]
|
||||
}
|
||||
});
|
||||
}
|
||||
if (typeof window.__mnoteDocumentPaneRuntime.refreshPrimaryDocument === 'function') {
|
||||
void window.__mnoteDocumentPaneRuntime.refreshPrimaryDocument({
|
||||
documentId: documentId,
|
||||
workspaceId: workspaceId,
|
||||
source: 'openhub-changed-file-bridge'
|
||||
});
|
||||
}
|
||||
if (typeof window.__mnoteDocumentPaneRuntime.openPrimaryDocument === 'function') {
|
||||
void window.__mnoteDocumentPaneRuntime.openPrimaryDocument({
|
||||
documentId: documentId,
|
||||
workspaceId: workspaceId,
|
||||
sourceKind: currentSourceKind() || 'local_folder',
|
||||
rootUri: rootUri
|
||||
});
|
||||
document.documentElement.setAttribute('data-mnote-page-ai-openhub-document-pane-refresh', targetPath);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (typeof window.__mnoteDocumentPaneRuntime.openResourceInActiveTab !== 'function') return false;
|
||||
void window.__mnoteDocumentPaneRuntime.openResourceInActiveTab({ path: targetPath, rootUri: rootUri });
|
||||
return true;
|
||||
}
|
||||
|
||||
function pageAiRefreshOpencodeCurrentPage(reason) {
|
||||
if (window.__mnoteDocumentPaneRuntime && typeof window.__mnoteDocumentPaneRuntime.refreshPrimaryDocument === 'function') {
|
||||
void window.__mnoteDocumentPaneRuntime.refreshPrimaryDocument({ reason: reason || 'page-ai-opencode-host' });
|
||||
if (reason) {
|
||||
void window.__mnoteDocumentPaneRuntime.refreshPrimaryDocument({ reason: reason });
|
||||
} else {
|
||||
void window.__mnoteDocumentPaneRuntime.refreshPrimaryDocument({ reason: 'page-ai-opencode-host' });
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -1739,7 +2066,7 @@ export function createSidebarPageAiRuntime(context) {
|
||||
'mnote.selection.read',
|
||||
'mnote.open_resources.snapshot',
|
||||
'mnote.allowed_roots.describe',
|
||||
'mnote.lightrag.query',
|
||||
'mnote.weknora.search',
|
||||
'mnote.reference.open',
|
||||
'mnote.page_aggregate.snapshot',
|
||||
'mnote.local_file.receipt'
|
||||
@@ -3540,6 +3867,20 @@ export function createSidebarPageAiRuntime(context) {
|
||||
|
||||
|
||||
function openPageAiDrawer() {
|
||||
if (pageAiOpenHubHostEnabled()) {
|
||||
pageAiEnsureContextRefState();
|
||||
void pageAiLoadAllowedRoots().then(function() {
|
||||
pageAiRenderOpenHubHostChrome();
|
||||
}).catch(function() {
|
||||
pageAiRenderOpenHubHostChrome();
|
||||
});
|
||||
var openhubDrawer = pageAiEnsureOpenHubHostDrawer();
|
||||
pageAiApplyDrawerWidth(openhubDrawer);
|
||||
openhubDrawer.hidden = false;
|
||||
pageUiState.pageAiOpen = true;
|
||||
updatePageAiTriggerState();
|
||||
return;
|
||||
}
|
||||
if (pageAiOpencodeHostEnabled()) {
|
||||
pageAiEnsureContextRefState();
|
||||
void pageAiLoadAllowedRoots().then(function() {
|
||||
@@ -3748,7 +4089,7 @@ export function createSidebarPageAiRuntime(context) {
|
||||
return text.indexOf(word) >= 0;
|
||||
});
|
||||
if (!asksCitation) return false;
|
||||
return ['lightrag', '资料库', '知识库', 'rag', '文献', '论文', '保护基'].some(function(word) {
|
||||
return ['weknora', '资料库', '知识库', 'rag', '文献', '论文', '保护基'].some(function(word) {
|
||||
return text.indexOf(word) >= 0;
|
||||
});
|
||||
}
|
||||
@@ -3759,7 +4100,7 @@ export function createSidebarPageAiRuntime(context) {
|
||||
var afterColon = text.split(/[::]/).slice(1).join(':').trim();
|
||||
var candidate = afterColon || text;
|
||||
candidate = candidate
|
||||
.replace(/^(请|请用|帮我|帮忙|用)?(资料库|知识库|lightrag|rag)?(搜索|检索|查找|查询|回答|说明|解释|总结)?/i, '')
|
||||
.replace(/^(请|请用|帮我|帮忙|用)?(资料库|知识库|weknora|rag)?(搜索|检索|查找|查询|回答|说明|解释|总结)?/i, '')
|
||||
.replace(/(请)?(给出|给我|附上|提供)?(链接|引用|来源|出处|证据|定位).*$/i, '')
|
||||
.trim();
|
||||
var stopIndex = candidate.search(/(在|的|是|有哪些|有什么|如何|怎么|用于|用途|作用|资料|文献|论文)/);
|
||||
@@ -3885,7 +4226,7 @@ export function createSidebarPageAiRuntime(context) {
|
||||
pageAiPersistSessions();
|
||||
renderPageAiConversation();
|
||||
} catch (error) {
|
||||
console.warn('MNote Page AI 自动追加 LightRAG 引用失败', error);
|
||||
console.warn('MNote Page AI 自动追加知识库引用失败', error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4749,6 +5090,9 @@ export function createSidebarPageAiRuntime(context) {
|
||||
});
|
||||
}
|
||||
}
|
||||
if (action === 'openhub-refresh-bootstrap') {
|
||||
void pageAiBootstrapOpenHubHost();
|
||||
}
|
||||
if (action === 'cancel-queued-run') {
|
||||
void pageAiCancelQueuedRun(pageAiAction.getAttribute('data-page-ai-queue-id'));
|
||||
}
|
||||
@@ -5159,7 +5503,7 @@ export function createSidebarPageAiRuntime(context) {
|
||||
}
|
||||
|
||||
|
||||
return {
|
||||
var api = {
|
||||
ensurePageAiStateFacade: (...args) => ensurePageAiStateFacade(...args),
|
||||
installPageAiDelegates: (...args) => installPageAiDelegates(...args),
|
||||
handlePageAiClick: (...args) => handlePageAiClick(...args),
|
||||
@@ -5217,4 +5561,6 @@ export function createSidebarPageAiRuntime(context) {
|
||||
pageAiRefreshOpencodeCurrentPage: (...args) => pageAiRefreshOpencodeCurrentPage(...args),
|
||||
updatePageAiTriggerState: (...args) => updatePageAiTriggerState(...args)
|
||||
};
|
||||
window.__mnoteSidebarPageAiRuntime = api;
|
||||
return api;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -210,6 +210,7 @@ import { createSidebarPageSettingsRuntime } from './sidebar-page-settings-runtim
|
||||
const openPageHistoryDrawer = (...args) => sidebarPageSettings.openPageHistoryDrawer(...args);
|
||||
const openPageIndexSettingsPopover = (...args) => sidebarPageSettings.openPageIndexSettingsPopover(...args);
|
||||
const openKnowledgeRagSettingsPopover = (...args) => sidebarPageSettings.openKnowledgeRagSettingsPopover(...args);
|
||||
const openKnowledgeRagSourceReference = (...args) => sidebarPageSettings.openKnowledgeRagSourceReference(...args);
|
||||
const openPageShareDialog = (...args) => sidebarPageSettings.openPageShareDialog(...args);
|
||||
const pageOptionIsSupported = (...args) => sidebarPageSettings.pageOptionIsSupported(...args);
|
||||
const addLocalIndexRange = (...args) => sidebarPageSettings.addLocalIndexRange(...args);
|
||||
@@ -219,6 +220,7 @@ import { createSidebarPageSettingsRuntime } from './sidebar-page-settings-runtim
|
||||
const ingestSingleKnowledgeRagSource = (...args) => sidebarPageSettings.ingestSingleKnowledgeRagSource(...args);
|
||||
const loadKnowledgeRagStatus = (...args) => sidebarPageSettings.loadKnowledgeRagStatus(...args);
|
||||
const openKnowledgeRagDashboard = (...args) => sidebarPageSettings.openKnowledgeRagDashboard(...args);
|
||||
const createKnowledgeRagKnowledgeBase = (...args) => sidebarPageSettings.createKnowledgeRagKnowledgeBase(...args);
|
||||
const setActiveKnowledgeRagDetailTab = (...args) => sidebarPageSettings.setActiveKnowledgeRagDetailTab(...args);
|
||||
const performKnowledgeRagSearch = (...args) => sidebarPageSettings.performKnowledgeRagSearch(...args);
|
||||
const saveKnowledgeRagSearchParams = (...args) => sidebarPageSettings.saveKnowledgeRagSearchParams(...args);
|
||||
@@ -227,6 +229,7 @@ import { createSidebarPageSettingsRuntime } from './sidebar-page-settings-runtim
|
||||
const refreshDashboardPanel = (...args) => sidebarPageSettings.refreshDashboardPanel(...args);
|
||||
|
||||
const pruneKnowledgeRagRegistry = (...args) => sidebarPageSettings.pruneKnowledgeRagRegistry(...args);
|
||||
const setKnowledgeRagSelectedProviderKnowledgeBaseId = (...args) => sidebarPageSettings.setKnowledgeRagSelectedProviderKnowledgeBaseId(...args);
|
||||
const setKnowledgeRagSourceFilter = (...args) => sidebarPageSettings.setKnowledgeRagSourceFilter(...args);
|
||||
const useKnowledgeRagFileTreeSelection = (...args) => sidebarPageSettings.useKnowledgeRagFileTreeSelection(...args);
|
||||
const persistLocalIndexSettings = (...args) => sidebarPageSettings.persistLocalIndexSettings(...args);
|
||||
@@ -3055,6 +3058,19 @@ import { createSidebarPageSettingsRuntime } from './sidebar-page-settings-runtim
|
||||
void loadKnowledgeRagStatus(true);
|
||||
return;
|
||||
}
|
||||
if (knowledgeRagActionName === 'create-kb') {
|
||||
void createKnowledgeRagKnowledgeBase();
|
||||
return;
|
||||
}
|
||||
if (knowledgeRagActionName === 'focus-create-kb') {
|
||||
var createKbInput = document.querySelector('[data-knowledge-rag-create-kb-name]');
|
||||
if (createKbInput instanceof HTMLInputElement) createKbInput.focus();
|
||||
return;
|
||||
}
|
||||
if (knowledgeRagActionName === 'select-kb') {
|
||||
setKnowledgeRagSelectedProviderKnowledgeBaseId(knowledgeRagAction.getAttribute('data-knowledge-rag-kb-id') || '');
|
||||
return;
|
||||
}
|
||||
if (knowledgeRagActionName === 'add-source') {
|
||||
addKnowledgeRagSourceInput();
|
||||
return;
|
||||
@@ -3079,6 +3095,10 @@ import { createSidebarPageSettingsRuntime } from './sidebar-page-settings-runtim
|
||||
void deleteKnowledgeRagSource(knowledgeRagAction.getAttribute('data-knowledge-rag-source-path') || '');
|
||||
return;
|
||||
}
|
||||
if (knowledgeRagActionName === 'open-source-reference') {
|
||||
openKnowledgeRagSourceReference(knowledgeRagAction.getAttribute('data-knowledge-rag-source-path') || '');
|
||||
return;
|
||||
}
|
||||
if (knowledgeRagActionName === 'prune') {
|
||||
void pruneKnowledgeRagRegistry();
|
||||
return;
|
||||
@@ -3590,6 +3610,11 @@ import { createSidebarPageSettingsRuntime } from './sidebar-page-settings-runtim
|
||||
if (pageWidthSelect instanceof HTMLSelectElement) {
|
||||
var pageWidthType = pageWidthSelect.getAttribute('data-page-width-select') || '';
|
||||
void persistPageWidthPreference(pageWidthType, pageWidthSelect.value);
|
||||
return;
|
||||
}
|
||||
var knowledgeRagKbSelect = closestAction(event.target, '[data-knowledge-rag-kb-select]');
|
||||
if (knowledgeRagKbSelect instanceof HTMLSelectElement) {
|
||||
setKnowledgeRagSelectedProviderKnowledgeBaseId(knowledgeRagKbSelect.value);
|
||||
}
|
||||
});
|
||||
sidebarPageAi.installPageAiDelegates();
|
||||
|
||||
Reference in New Issue
Block a user