feat(desktop): attest and manage the owned Windows host lifecycle
This commit is contained in:
+12
-2
@@ -13,6 +13,7 @@ import { verifyBrowserJob } from '../core/browser/browser-manager.mjs';
|
||||
import { ConfigImporter } from '../core/models/config-import.mjs';
|
||||
import { ProjectMemoryManager } from '../core/memory/project-memory.mjs';
|
||||
import { workerForProject, workerConflict, assertWorkersResolved } from '../shared/contracts/workers.mjs';
|
||||
import { hostAuthority } from '../core/desktop/host-authority.mjs';
|
||||
|
||||
export function createSessionPublisher(clients) {
|
||||
return session => {
|
||||
@@ -31,6 +32,7 @@ function cursorNumber(value) {
|
||||
}
|
||||
|
||||
export function createRequestHandler({ appDirectory, server, store, provider, runtime, token, clients, started, getPort, exampleProject, shutdown }) {
|
||||
const host = () => hostAuthority({ appDirectory, server, store, provider, runtime });
|
||||
const research = [
|
||||
{ id: 'overview', title: '统一机制报告', file: 'RESEARCH.md', description: '研究结论、证据与本产品采用的独立设计。' },
|
||||
{ id: 'cursor', title: 'Cursor:执行与编辑', file: 'research/CURSOR-MECHANISMS.md', description: '工具能力、执行事件、取消、恢复与文本改动。' },
|
||||
@@ -81,7 +83,13 @@ return async (request, response) => {
|
||||
allowRequest(request, url);
|
||||
const method = request.method;
|
||||
const route = url.pathname;
|
||||
if (method === 'GET' && route === '/api/health') return json(response, { app: 'agent-workbench', version: APP_VERSION, pid: process.pid, ready: true, uptimeMs: Date.now() - started });
|
||||
if (method === 'GET' && route === '/api/health') return json(response, { app: 'agent-workbench', version: APP_VERSION, pid: process.pid, ready: server?.workbenchReady !== false, uptimeMs: Date.now() - started });
|
||||
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/stop') {
|
||||
const result = await host().stop(await body(request)); json(response, result); setTimeout(shutdown, 100); return;
|
||||
}
|
||||
if (!['GET', 'HEAD'].includes(method) && server?.workbenchHostAuthority?.stopping) throw Object.assign(new Error('执行宿主正在停止,请等待所属操作结束。'), { status: 409 });
|
||||
const skillsMatch = route.match(/^\/api\/projects\/([a-f0-9-]+)\/skills(?:\/(toggle|refresh|content))?$/i);
|
||||
if (skillsMatch) {
|
||||
const registry = runtime.skillRegistry(), projectId = skillsMatch[1], action = skillsMatch[2];
|
||||
@@ -655,7 +663,9 @@ return async (request, response) => {
|
||||
return json(response, { title: document.title, content: fs.existsSync(file) ? fs.readFileSync(file, 'utf8') : '这份报告正在整理,完成后会保存在产品的 docs 目录。' });
|
||||
}
|
||||
if (method === 'POST' && route === '/api/shutdown') {
|
||||
await body(request); json(response, { closing: true });
|
||||
await body(request);
|
||||
const authority = host(), identity = authority.identity();
|
||||
const result = await authority.stop({ ...identity, confirmation: 'stop-owned-host' }); json(response, result);
|
||||
setTimeout(shutdown, 100); return;
|
||||
}
|
||||
if (route.startsWith('/api/')) return json(response, { error: '接口不存在。' }, 404);
|
||||
|
||||
Reference in New Issue
Block a user