feat(page-ai): add resumable run journal descriptors

This commit is contained in:
lix-2026
2026-06-09 18:48:46 +08:00
parent 6ef233772e
commit 922965d30f
17 changed files with 3254 additions and 58 deletions
@@ -627,6 +627,37 @@ export function createSidebarPageAiSessionRuntime(context) {
renderPageAiControls();
}
async function pageAiCheckActiveRun(sessionId) {
sessionId = String(sessionId || pageUiState.pageAiActiveSessionId || '').trim();
if (!sessionId) return null;
var response = await fetch('/api/page-ai/sessions/' + encodeURIComponent(sessionId) + '/active-run?' + pageAiBackendSessionQuery({}), {
headers: { 'accept': 'application/json' }
});
var payload = await response.json().catch(function(){ return null; });
if (!response.ok || !payload || payload.ok !== true) {
throw new Error(pageAiErrorMessage(payload, 'active_run_failed_' + response.status));
}
if (!payload.active || !payload.run) return null;
var run = payload.run;
var hostRunId = String(run.hostRunId || run.runId || '').trim();
var status = String(run.status || '').trim();
var current = pageAiCurrentSession();
if (current && current.id === sessionId) {
current.runId = hostRunId;
current.status = status || current.status || 'running';
current.updatedAt = Date.now();
}
pageAiApplyRuntimeState(Object.assign({}, run.runtime || {}, {
status: status || 'running',
runId: hostRunId
}));
doc.documentElement.setAttribute('data-mnote-page-ai-active-run-checked', 'true');
if (hostRunId) doc.documentElement.setAttribute('data-mnote-page-ai-active-host-run-id', hostRunId);
pageAiPersistSessions();
renderPageAiControls();
return run;
}
return {
pageAiStorageKey,
pageAiBackendSessionQuery,
@@ -650,6 +681,7 @@ export function createSidebarPageAiSessionRuntime(context) {
pageAiStartNewSession,
pageAiRenameBackendSession,
pageAiDeleteBackendSession,
pageAiResumeBackendSession
pageAiResumeBackendSession,
pageAiCheckActiveRun
};
}