1.0 mvp
This commit is contained in:
@@ -267,16 +267,17 @@ const SIDEBAR_TREE_JS: &str = r##"
|
||||
return {
|
||||
pageContext: {
|
||||
contextScope: scope,
|
||||
documentBlocks: scope === 'page' ? (body.content || null) : null,
|
||||
documentBlocks: null,
|
||||
node: {
|
||||
documentId: currentDocumentId(),
|
||||
title: title
|
||||
},
|
||||
subtree: scope === 'page' ? subtree : null,
|
||||
outline: scope === 'page' ? outline : null,
|
||||
subtree: null,
|
||||
outline: null,
|
||||
pageSubtreeSource: scope === 'page' ? (contextSnapshot.pageSubtreeSource || 'none') : 'scope:' + scope,
|
||||
evidence: selectedText ? [{ kind: 'selection', text: selectedText }] : null,
|
||||
pageOptions: scope === 'options' || scope === 'page' ? currentPageOptions() : null
|
||||
pageOptions: scope === 'options' || scope === 'page' ? currentPageOptions() : null,
|
||||
contentAccess: 'mnote.page.get'
|
||||
},
|
||||
selectedText: selectedText,
|
||||
selectedBlockId: null
|
||||
@@ -503,6 +504,29 @@ const SIDEBAR_TREE_JS: &str = r##"
|
||||
var value = (root.getAttribute('data-workspace-id') || '').trim();
|
||||
if (value) return value;
|
||||
}
|
||||
var documentId = currentDocumentId();
|
||||
if (documentId) {
|
||||
var shell = document.querySelector('.document-shell[data-document-id="' + cssEscape(documentId) + '"][data-workspace-id]');
|
||||
if (shell instanceof HTMLElement) {
|
||||
var shellWorkspaceId = (shell.getAttribute('data-workspace-id') || '').trim();
|
||||
if (shellWorkspaceId) return shellWorkspaceId;
|
||||
}
|
||||
}
|
||||
var activePane = document.querySelector('[data-pane-visible="true"][data-pane-workspace-id]');
|
||||
if (activePane instanceof HTMLElement) {
|
||||
var paneWorkspaceId = (activePane.getAttribute('data-pane-workspace-id') || '').trim();
|
||||
if (paneWorkspaceId) return paneWorkspaceId;
|
||||
}
|
||||
var anyDocumentShell = document.querySelector('.document-shell[data-workspace-id]');
|
||||
if (anyDocumentShell instanceof HTMLElement) {
|
||||
var documentWorkspaceId = (anyDocumentShell.getAttribute('data-workspace-id') || '').trim();
|
||||
if (documentWorkspaceId) return documentWorkspaceId;
|
||||
}
|
||||
var fromDom = document.querySelector('[data-workspace-id]');
|
||||
if (fromDom instanceof HTMLElement) {
|
||||
var domWorkspaceId = (fromDom.getAttribute('data-workspace-id') || '').trim();
|
||||
if (domWorkspaceId) return domWorkspaceId;
|
||||
}
|
||||
return (new URLSearchParams(window.location.search).get('workspaceId') || 'default').trim() || 'default';
|
||||
}
|
||||
|
||||
@@ -4124,6 +4148,69 @@ const SIDEBAR_TREE_JS: &str = r##"
|
||||
}
|
||||
}
|
||||
|
||||
function pageAiNormalizeToolName(name) {
|
||||
return String(name || '').trim().replace(/_/g, '.');
|
||||
}
|
||||
|
||||
function pageAiToolEventDeepFindString(value, keys, depth) {
|
||||
if (!value || typeof value !== 'object' || depth > 5) return '';
|
||||
for (var index = 0; index < keys.length; index += 1) {
|
||||
var key = keys[index];
|
||||
if (Object.prototype.hasOwnProperty.call(value, key) && typeof value[key] === 'string' && value[key].trim()) {
|
||||
return value[key].trim();
|
||||
}
|
||||
}
|
||||
if (Array.isArray(value)) {
|
||||
for (var arrayIndex = 0; arrayIndex < value.length; arrayIndex += 1) {
|
||||
var fromArray = pageAiToolEventDeepFindString(value[arrayIndex], keys, depth + 1);
|
||||
if (fromArray) return fromArray;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
var preferred = ['audit', 'args', 'arguments', 'input', 'result', 'summary', 'output', 'upstream'];
|
||||
for (var prefIndex = 0; prefIndex < preferred.length; prefIndex += 1) {
|
||||
var child = value[preferred[prefIndex]];
|
||||
var fromPreferred = pageAiToolEventDeepFindString(child, keys, depth + 1);
|
||||
if (fromPreferred) return fromPreferred;
|
||||
}
|
||||
var objectKeys = Object.keys(value);
|
||||
for (var objectIndex = 0; objectIndex < objectKeys.length; objectIndex += 1) {
|
||||
var fromObject = pageAiToolEventDeepFindString(value[objectKeys[objectIndex]], keys, depth + 1);
|
||||
if (fromObject) return fromObject;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
function pageAiNotifyToolWriteCompleted(toolName, toolEvent, runId, runTraceId) {
|
||||
var normalizedTool = pageAiNormalizeToolName(toolName);
|
||||
var writesCurrentPage = [
|
||||
'mnote.page.save',
|
||||
'mnote.page.update.title',
|
||||
'mnote.page.update.options'
|
||||
].indexOf(normalizedTool) >= 0 || [
|
||||
'mnote.page.update_title',
|
||||
'mnote.page.update_options'
|
||||
].indexOf(String(toolName || '').trim()) >= 0;
|
||||
if (!writesCurrentPage) return;
|
||||
var documentId = pageAiToolEventDeepFindString(toolEvent, ['documentId', 'document_id'], 0) || currentDocumentId();
|
||||
var workspaceId = pageAiToolEventDeepFindString(toolEvent, ['workspaceId', 'workspace_id'], 0) || resolveWorkspaceId(document.body);
|
||||
try {
|
||||
window.dispatchEvent(new CustomEvent('mnote:page-ai-tool-write-completed', {
|
||||
detail: {
|
||||
toolName: toolName,
|
||||
normalizedToolName: normalizedTool,
|
||||
documentId: documentId,
|
||||
workspaceId: workspaceId,
|
||||
runId: String(toolEvent && (toolEvent.run_id || toolEvent.runId) || runId || ''),
|
||||
traceId: String(toolEvent && (toolEvent.trace_id || toolEvent.traceId) || runTraceId || ''),
|
||||
toolCallId: String(toolEvent && (toolEvent.tool_call_id || toolEvent.toolCallId || toolEvent.id) || '')
|
||||
}
|
||||
}));
|
||||
} catch (error) {
|
||||
console.warn('mnote 页面 AI 写入刷新事件派发失败', error);
|
||||
}
|
||||
}
|
||||
|
||||
function pageAiApplyToolEvent(eventName, payloadText, runId, runTraceId) {
|
||||
var toolEvent = null;
|
||||
try {
|
||||
@@ -4173,6 +4260,9 @@ const SIDEBAR_TREE_JS: &str = r##"
|
||||
existing.auditId = auditId || existing.auditId || '';
|
||||
if (argsSummary) existing.argsSummary = argsSummary;
|
||||
if (resultSummary) existing.resultSummary = resultSummary;
|
||||
if (status === 'completed') {
|
||||
pageAiNotifyToolWriteCompleted(toolName, toolEvent, runId, runTraceId);
|
||||
}
|
||||
}
|
||||
|
||||
async function pageAiCancelQueuedRun(queueId) {
|
||||
|
||||
Reference in New Issue
Block a user