feat: add owned Vite previews and isolated task browser with approved actions
This commit is contained in:
+55
-2
@@ -110,7 +110,21 @@ return async (request, response) => {
|
||||
if (method === 'GET' && route === '/api/host/identity') return json(response, host().attest(url.searchParams.get('challenge')));
|
||||
if (method === 'GET' && route === '/api/host/status') return json(response, host().status());
|
||||
if (method === 'POST' && route === '/api/host/windows/register') return json(response, host().registerWindow(await body(request)));
|
||||
if (method === 'POST' && route === '/api/host/windows/unregister') return json(response, host().unregisterWindow(await body(request)));
|
||||
if (method === 'POST' && route === '/api/host/windows/unregister') {
|
||||
const input = await body(request); const result = host().unregisterWindow(input); runtime.browsing?.disconnect(input.windowId); return json(response, result);
|
||||
}
|
||||
if (method === 'POST' && /^\/api\/browsing-desktop\/(poll|complete|validate)$/.test(route)) {
|
||||
const input = await body(request, 12 * 1024 * 1024), owner = input.owner, registered = host().windows?.get(owner?.windowId);
|
||||
if (!registered || ['windowId','pid','createdAt','instanceId','runtimeIdentity'].some(key => registered[key] !== owner[key])) throw Object.assign(new Error('原桌面进程登记已变化。'), { status: 403 });
|
||||
runtime.workbenchOrigin = 'http://127.0.0.1:' + actualPort; const manager = runtime.browsingManager(); manager.workbenchOrigin = runtime.workbenchOrigin;
|
||||
if (route.endsWith('/poll')) return json(response, manager.poll(owner.windowId, input.states));
|
||||
if (route.endsWith('/validate')) {
|
||||
const pending = manager.active.get(input.id);
|
||||
if (!pending || pending.job.windowId !== owner.windowId || pending.nonce !== input.nonce || !pending.job.dispatchedAt) throw Object.assign(new Error('原动作已经停止或授权已撤销。'), { status: 409 });
|
||||
return json(response, { valid: true });
|
||||
}
|
||||
return json(response, manager.complete(owner.windowId, input));
|
||||
}
|
||||
if (method === 'POST' && route === '/api/host/stop') {
|
||||
const result = await host().stop(await body(request)); json(response, result); setTimeout(shutdown, 100); return;
|
||||
}
|
||||
@@ -314,7 +328,7 @@ return async (request, response) => {
|
||||
}
|
||||
}
|
||||
if (method === 'POST' && workerForProject(store, session.projectId)
|
||||
&& /^(?:mcp|engines|research|workspaces|delivery|browser|task-plans|task-proofs|task-checkpoints|collaborations|evaluations)(?:\/|-|$)/.test(action)) throw workerConflict('受限子任务只开放原目标的读取、范围内改动和已审批检查;此操作请返回父项目。');
|
||||
&& /^(?:mcp|engines|research|workspaces|delivery|browser|browsing|preview|task-plans|task-proofs|task-checkpoints|collaborations|evaluations)(?:\/|-|$)/.test(action)) throw workerConflict('受限子任务只开放原目标的读取、范围内改动和已审批检查;此操作请返回父项目。');
|
||||
if (method === 'GET' && action === 'evaluations') return json(response,runtime.evaluationManager().view(session));
|
||||
if (method === 'POST' && action === 'evaluations') {
|
||||
const batch=await runtime.evaluationManager().plan(session,await body(request));
|
||||
@@ -616,6 +630,45 @@ return async (request, response) => {
|
||||
await body(request); await runtime.gitDelivery().report(session);
|
||||
return json(response, store.publicSession(session), 201);
|
||||
}
|
||||
if (method === 'GET' && action === 'browsing') return json(response, runtime.browsingManager().snapshot(session));
|
||||
const browsingImage = action.match(/^browsing\/observations\/([a-f0-9-]+)\/image$/);
|
||||
if (method === 'GET' && browsingImage) {
|
||||
const observation = store.owned('browsing_observation', browsingImage[1], id), artifact = store.owned('artifact', observation.screenshotArtifactId, id);
|
||||
if (artifact.kind !== 'browsing-screenshot' || artifact.sha256 !== observation.screenshotSha256) throw new Error('原页面截图身份无法核对。');
|
||||
const bytes = store.artifactStore.readBytes(artifact); response.writeHead(200, { 'Content-Type': 'image/png', 'Content-Length': bytes.length, 'Cache-Control': 'no-store', 'X-Content-SHA256': artifact.sha256 }); return response.end(bytes);
|
||||
}
|
||||
if (method === 'POST' && action === 'browsing/tabs') {
|
||||
runtime.workbenchOrigin = 'http://127.0.0.1:' + actualPort; runtime.browsingManager().workbenchOrigin = runtime.workbenchOrigin;
|
||||
await runtime.browsingManager().open(session, await body(request)); return json(response, store.publicSession(session), 201);
|
||||
}
|
||||
const browsingTab = action.match(/^browsing\/tabs\/([a-f0-9-]+)\/(observe|act|close|clear)$/);
|
||||
if (method === 'POST' && browsingTab) {
|
||||
const input = await body(request), manager = runtime.browsingManager(), tabId = browsingTab[1];
|
||||
if (browsingTab[2] === 'observe') await manager.observe(session, tabId);
|
||||
else if (browsingTab[2] === 'act') { const { approved, ...operation } = input; await manager.act(session, tabId, operation, { approved }); }
|
||||
else { if (input.approved !== true) throw Object.assign(new Error('关闭/撤销需要明确确认。'), { status: 400 }); await manager.close(session, tabId, { clear: browsingTab[2] === 'clear' }); }
|
||||
return json(response, store.publicSession(session));
|
||||
}
|
||||
const browsingAck = action.match(/^browsing\/actions\/([a-f0-9-]+)\/acknowledge$/);
|
||||
if (method === 'POST' && browsingAck) {
|
||||
const input = await body(request); if (input.approved !== true) throw Object.assign(new Error('请先核对原页面和回执,再明确保留未知结果。'), { status: 400 });
|
||||
runtime.browsingManager().acknowledge(session, browsingAck[1]); return json(response, store.publicSession(session));
|
||||
}
|
||||
if (method === 'POST' && action === 'preview-plans') {
|
||||
await runtime.previewManager().plan(session, await body(request)); return json(response, store.publicSession(session), 201);
|
||||
}
|
||||
if (method === 'POST' && action === 'preview-jobs') {
|
||||
const input = await body(request);
|
||||
if (!input || Array.isArray(input) || Object.keys(input).some(key => !['planId','fingerprint','approved'].includes(key))) throw Object.assign(new Error('预览启动只接受原计划身份和明确审批。'), { status: 400 });
|
||||
await runtime.previewManager().start(session, input.planId, input.fingerprint, { approved: input.approved }); return json(response, store.publicSession(session), 202);
|
||||
}
|
||||
const previewJob = action.match(/^preview-jobs\/([a-f0-9-]+)\/(stop|reconcile)$/);
|
||||
if (method === 'POST' && previewJob) {
|
||||
const input = await body(request), manager = runtime.previewManager();
|
||||
store.owned('preview_job', previewJob[1], id);
|
||||
if (previewJob[2] === 'stop') await manager.stop(id, previewJob[1]); else await manager.reconcile(session, previewJob[1], input.fingerprint);
|
||||
return json(response, store.publicSession(session));
|
||||
}
|
||||
if (method === 'POST' && action === 'environment-diagnostics') {
|
||||
await body(request); await runtime.environmentManager().diagnose(session);
|
||||
return json(response,store.publicSession(session),201);
|
||||
|
||||
Reference in New Issue
Block a user