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);
|
||||
|
||||
@@ -221,6 +221,14 @@ export class CompanionGateway {
|
||||
if (limit < 1 || limit > 200) throw companionError('手机事件每页需要1至200条。');
|
||||
return reply(response, this.events(device, after, limit));
|
||||
}
|
||||
const browserImage=route.match(/^\/mobile-api\/sessions\/([a-f0-9-]+)\/browser-observations\/([a-f0-9-]+)\/image$/);
|
||||
if(browserImage&&method==='GET'){
|
||||
const session=this.session(device,browserImage[1]),observation=this.store.owned('browsing_observation',browserImage[2],session.id);
|
||||
if(observation.taskId!==session.taskId)throw companionError('当前任务没有这份网页观察。',404);
|
||||
const artifact=this.store.owned('artifact',observation.screenshotArtifactId,session.id);
|
||||
if(artifact.kind!=='browsing-screenshot'||artifact.sha256!==observation.screenshotSha256)throw companionError('原网页截图身份无法核对。',409);
|
||||
const bytes=this.store.artifactStore.readBytes(artifact);response.writeHead(200,{'Content-Type':'image/png','Content-Length':bytes.length,'X-Content-SHA256':artifact.sha256,'Cache-Control':'no-store'});response.end(bytes);return;
|
||||
}
|
||||
const attachment=route.match(/^\/mobile-api\/sessions\/([a-f0-9-]+)\/input-attachments\/([a-f0-9-]+)\/(image|original)$/);
|
||||
if(attachment&&method==='GET'){
|
||||
const session=this.session(device,attachment[1]),manager=new InputAttachments(this.store),row=manager.get(session,attachment[2]);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { randomUUID, createHash } from 'node:crypto';
|
||||
|
||||
export const APP_VERSION = '1.21.0';
|
||||
export const APP_VERSION = '1.22.0';
|
||||
|
||||
export function executionEnvironment() {
|
||||
const windows = process.platform === 'win32';
|
||||
|
||||
@@ -19,7 +19,7 @@ export function installUpgrade(context, { appDirectory, updateServiceInfo = true
|
||||
if (server.workbenchHostAuthority?.stopping) throw new Error('Wait for the original host stop operation before upgrading.');
|
||||
if (server.workbenchCompanion?.server || server.workbenchCompanion?.busy) throw new Error('Close the mobile companion gateway before upgrading; original tasks remain on the host.');
|
||||
if (server.workbenchHostAuthority?.desktopWindows?.().count) throw new Error('Close the registered desktop windows before upgrading; the execution host remains running.');
|
||||
if (runtime.evaluations?.active.size || runtime.environments?.active.size || runtime.active.size || runtime.waiters.size || runtime.workers?.active.size || runtime.controlledEngines?.drivers.size || runtime.mcp?.active.size || runtime.checks?.active.size || runtime.deliveries?.active.size || runtime.changeSets?.projects.size || runtime.workspaces?.projects.size || runtime.workspaces?.pending.size || runtime.research?.active.size || runtime.engines?.active.size || runtime.browser?.active.size || runtime.taskPlans?.active.size) throw new Error('Wait for active evaluations, environments, tasks, workers, controlled engines, MCP operations, checks, Git deliveries, file batches, workspaces, research, engines, browsers, task plans and approvals to finish before upgrading.');
|
||||
if (runtime.browsing?.active.size || runtime.previews?.active.size || runtime.evaluations?.active.size || runtime.environments?.active.size || runtime.active.size || runtime.waiters.size || runtime.workers?.active.size || runtime.controlledEngines?.drivers.size || runtime.mcp?.active.size || runtime.checks?.active.size || runtime.deliveries?.active.size || runtime.changeSets?.projects.size || runtime.workspaces?.projects.size || runtime.workspaces?.pending.size || runtime.research?.active.size || runtime.engines?.active.size || runtime.browser?.active.size || runtime.taskPlans?.active.size) throw new Error('Wait for active evaluations, environments, tasks, workers, controlled engines, MCP operations, checks, Git deliveries, file batches, workspaces, research, engines, browsers, task plans and approvals to finish before upgrading.');
|
||||
if (provider.activeRequests || provider.hub?.waiting || [...(provider.hub?.leases.values() ?? [])].some(count => count > 0)) throw new Error('Wait for active model requests and probes before upgrading.');
|
||||
const root = fs.realpathSync.native(path.resolve(appDirectory));
|
||||
if (!fs.existsSync(path.join(root, 'dist-client', 'index.html'))) throw new Error('The new client bundle is missing.');
|
||||
@@ -32,7 +32,7 @@ export function installUpgrade(context, { appDirectory, updateServiceInfo = true
|
||||
importer: provider.hub?.importer ? Object.getPrototypeOf(provider.hub.importer) : null,
|
||||
vault: provider.hub?.credentialVault ? Object.getPrototypeOf(provider.hub.credentialVault) : null };
|
||||
const oldStoreProperties = { ...store };
|
||||
const oldRuntimeProperties = { evaluations:runtime.evaluations, environments: runtime.environments, appDirectory: runtime.appDirectory, workers: runtime.workers, controlledEngines: runtime.controlledEngines, checks: runtime.checks, deliveries: runtime.deliveries, codeIndex: runtime.codeIndex, changeSets: runtime.changeSets, contextPlans: runtime.contextPlans, workspaces: runtime.workspaces, research: runtime.research, engines: runtime.engines, browser: runtime.browser, taskPlans: runtime.taskPlans, projectMemories: runtime.projectMemories, taskCheckpoints: runtime.taskCheckpoints, skills: runtime.skills, mcp: runtime.mcp };
|
||||
const oldRuntimeProperties = { browsing: runtime.browsing, previews: runtime.previews, evaluations:runtime.evaluations, environments: runtime.environments, appDirectory: runtime.appDirectory, workers: runtime.workers, controlledEngines: runtime.controlledEngines, checks: runtime.checks, deliveries: runtime.deliveries, codeIndex: runtime.codeIndex, changeSets: runtime.changeSets, contextPlans: runtime.contextPlans, workspaces: runtime.workspaces, research: runtime.research, engines: runtime.engines, browser: runtime.browser, taskPlans: runtime.taskPlans, projectMemories: runtime.projectMemories, taskCheckpoints: runtime.taskCheckpoints, skills: runtime.skills, mcp: runtime.mcp };
|
||||
const oldUpdates = store.listeners('update');
|
||||
const oldInputs = runtime.inputs;
|
||||
const oldResumes = runtime.resumes;
|
||||
@@ -49,7 +49,7 @@ export function installUpgrade(context, { appDirectory, updateServiceInfo = true
|
||||
if (provider.hub.importer) Object.setPrototypeOf(provider.hub.importer, ConfigImporter.prototype);
|
||||
if (provider.hub.credentialVault) Object.setPrototypeOf(provider.hub.credentialVault, CredentialVault.prototype);
|
||||
}
|
||||
runtime.appDirectory = root; runtime.evaluations = null; runtime.environments = null; runtime.workers = null; runtime.controlledEngines = null; runtime.checks = null; runtime.deliveries = null; runtime.codeIndex = null; runtime.changeSets = null; runtime.contextPlans = null; runtime.workspaces = null; runtime.research = null; runtime.engines = null; runtime.browser = null; runtime.taskPlans = null; runtime.projectMemories = null; runtime.taskCheckpoints = null; runtime.skills = null; runtime.mcp = null;
|
||||
runtime.appDirectory = root; runtime.previews = null; runtime.browsing = null; runtime.evaluations = null; runtime.environments = null; runtime.workers = null; runtime.controlledEngines = null; runtime.checks = null; runtime.deliveries = null; runtime.codeIndex = null; runtime.changeSets = null; runtime.contextPlans = null; runtime.workspaces = null; runtime.research = null; runtime.engines = null; runtime.browser = null; runtime.taskPlans = null; runtime.projectMemories = null; runtime.taskCheckpoints = null; runtime.skills = null; runtime.mcp = null;
|
||||
delete server.workbenchCompanion;
|
||||
runtime.inputs = null;
|
||||
runtime.resumes = null;
|
||||
|
||||
+28
-9
@@ -1,3 +1,6 @@
|
||||
import { PreviewManager } from '../core/preview/preview-manager.mjs';
|
||||
import { BrowsingManager } from '../core/browser/browsing-manager.mjs';
|
||||
import { browsingToolDefinitions, browsingAction } from '../shared/contracts/browsing.mjs';
|
||||
import { publicEnvironmentDiagnostic } from '../core/environment/environment-manager.mjs';
|
||||
import { EnvironmentManager } from '../core/environment/environment-manager.mjs';
|
||||
import { spawn, execFile } from 'node:child_process';
|
||||
@@ -55,6 +58,9 @@ labels.inspect_engine_checks = '查看本任务外部引擎核验';
|
||||
labels.plan_browser = '准备页面检查计划';
|
||||
labels.run_browser = '运行实际浏览器检查';
|
||||
labels.read_browser_result = '读取原页面执行结果';
|
||||
labels.inspect_browser_tabs = '核对本任务浏览标签页';
|
||||
labels.observe_browser_tab = '观察所属浏览页面';
|
||||
labels.act_browser_tab = '执行原页面固定动作';
|
||||
labels.plan_task = '保存任务依赖计划';
|
||||
labels.verify_task_step = '核验任务步骤原证据';
|
||||
labels.inspect_task_plan = '核对任务计划与未完成项';
|
||||
@@ -69,6 +75,8 @@ export function validateToolArgs(tool, args) {
|
||||
if (tool === 'plan_task') { taskPlanInput(args); return; }
|
||||
if (tool === 'verify_task_step') { taskProofInput(args); return; }
|
||||
if (tool === 'inspect_task_plan') { if (Object.keys(args).length) throw new Error('任务计划查询只读取当前Task,不接受执行命令。'); return; }
|
||||
if (tool === 'inspect_browser_tabs') { if (Object.keys(args).length) throw new Error('标签页查询不接受附加参数。'); return; }
|
||||
if (['observe_browser_tab','act_browser_tab'].includes(tool)) { const {tab_id,...input}=args; if(typeof tab_id!=='string')throw new Error('需要当前Task的标签页ID。'); if(tool==='act_browser_tab')browsingAction(input); else if(Object.keys(input).length)throw new Error('观察不接受脚本或附加参数。'); return; }
|
||||
if (tool === 'plan_browser') { browserPlanInput(args); return; }
|
||||
if (['run_browser', 'read_browser_result'].includes(tool)) {
|
||||
const key = tool === 'run_browser' ? 'plan_id' : 'browser_job_id';
|
||||
@@ -113,8 +121,8 @@ export class Runtime {
|
||||
this.appDirectory = appDirectory;
|
||||
this.active = new Map(); this.waiters = new Map();
|
||||
}
|
||||
isActive(id) { return !!this.environments?.isActive(id) || !!this.evaluations?.isActive(id) || this.active.has(id) || !!this.workers?.isActive(id) || !!this.controlledEngines?.isActive(id) || !!this.checks?.isActive(id) || !!this.deliveries?.isActive(id) || !!this.changeSets?.isActive(id) || !!this.workspaces?.isActive(id) || !!this.research?.isActive(id) || !!this.engines?.isActive(id) || !!this.browser?.isActive(id) || !!this.taskPlans?.isActive(id); }
|
||||
hasActivity() { return (this.environments?.active.size ?? 0) > 0 || (this.evaluations?.active.size ?? 0) > 0 || (this.provider.activeRequests ?? 0) > 0 || (this.provider.hub?.waiting ?? 0) > 0 || this.active.size > 0 || (this.workers?.active.size ?? 0) > 0 || (this.controlledEngines?.drivers.size ?? 0) > 0 || (this.mcp?.active.size ?? 0) > 0 || (this.checks?.active.size ?? 0) > 0 || (this.deliveries?.active.size ?? 0) > 0 || (this.changeSets?.projects.size ?? 0) > 0 || (this.workspaces?.projects.size ?? 0) > 0 || (this.workspaces?.pending.size ?? 0) > 0 || (this.research?.active.size ?? 0) > 0 || (this.engines?.active.size ?? 0) > 0 || (this.browser?.active.size ?? 0) > 0 || (this.taskPlans?.active.size ?? 0) > 0; }
|
||||
isActive(id) { return !!this.browsing?.isActive(id) || !!this.previews?.isActive(id) || !!this.environments?.isActive(id) || !!this.evaluations?.isActive(id) || this.active.has(id) || !!this.workers?.isActive(id) || !!this.controlledEngines?.isActive(id) || !!this.checks?.isActive(id) || !!this.deliveries?.isActive(id) || !!this.changeSets?.isActive(id) || !!this.workspaces?.isActive(id) || !!this.research?.isActive(id) || !!this.engines?.isActive(id) || !!this.browser?.isActive(id) || !!this.taskPlans?.isActive(id); }
|
||||
hasActivity() { return (this.browsing?.active.size ?? 0) > 0 || (this.previews?.active.size ?? 0) > 0 || (this.environments?.active.size ?? 0) > 0 || (this.evaluations?.active.size ?? 0) > 0 || (this.provider.activeRequests ?? 0) > 0 || (this.provider.hub?.waiting ?? 0) > 0 || this.active.size > 0 || (this.workers?.active.size ?? 0) > 0 || (this.controlledEngines?.drivers.size ?? 0) > 0 || (this.mcp?.active.size ?? 0) > 0 || (this.checks?.active.size ?? 0) > 0 || (this.deliveries?.active.size ?? 0) > 0 || (this.changeSets?.projects.size ?? 0) > 0 || (this.workspaces?.projects.size ?? 0) > 0 || (this.workspaces?.pending.size ?? 0) > 0 || (this.research?.active.size ?? 0) > 0 || (this.engines?.active.size ?? 0) > 0 || (this.browser?.active.size ?? 0) > 0 || (this.taskPlans?.active.size ?? 0) > 0; }
|
||||
evaluationManager() { return this.evaluations ??= new EvaluationManager(this.store, this); }
|
||||
workerManager() { return this.workers ??= new WorkerManager(this.store, this); }
|
||||
projectIndexer() { return this.codeIndex ??= new ProjectIndex({ cacheDirectory: path.join(this.store.directory, 'cache', 'project-index') }); }
|
||||
@@ -122,6 +130,9 @@ export class Runtime {
|
||||
projectBusy: (projectId, exceptId) => this.projectHasActivity(projectId, exceptId) }); }
|
||||
browserManager() { return this.browser ??= new BrowserManager(this.store, { appDirectory: this.appDirectory,
|
||||
redact: value => this.provider.redact(value), projectBusy: (projectId, exceptId) => this.projectHasActivity(projectId, exceptId) }); }
|
||||
previewManager() { return this.previews ??= new PreviewManager(this.store, { runtimeDirectory: this.appDirectory ? path.join(this.appDirectory, 'runtime') : null,
|
||||
redact: value => this.provider.redact(value), projectBusy: projectId => this.projectHasActivity(projectId) }); }
|
||||
browsingManager() { return this.browsing ??= new BrowsingManager(this.store, { redact: value => this.provider.redact(value), workbenchOrigin: this.workbenchOrigin }); }
|
||||
engineManager() {
|
||||
return this.engines ??= new EngineManager(this.store, { appDirectory: this.appDirectory,
|
||||
redact: value => this.provider.redact(value), projectBusy: projectId => this.projectHasActivity(projectId) });
|
||||
@@ -143,12 +154,12 @@ export class Runtime {
|
||||
redact: value => this.provider.redact(value), projectBusy: (projectId, exceptId) => this.projectHasActivity(projectId, exceptId) });
|
||||
}
|
||||
projectHasActivity(projectId, exceptSessionId = null, { excludeGroupId = null, excludeEvaluationId = null } = {}) {
|
||||
return !!this.environments?.projectActive(projectId) || !!this.evaluations?.projectActive(projectId, excludeEvaluationId) || !!this.workers?.projectActive(projectId, excludeGroupId) || !!this.controlledEngines?.projectActive(projectId, exceptSessionId) || [...this.active.entries()].some(([id, run]) => id !== exceptSessionId && run.project.id === projectId) || !!this.environments?.projectActive(projectId) || !!this.checks?.projectActive(projectId) || !!this.deliveries?.projectActive(projectId) || !!this.changeSets?.projectActive(projectId) || !!this.workspaces?.projectActive(projectId) || !!this.research?.projectActive(projectId) || !!this.engines?.projectActive(projectId) || !!this.browser?.projectActive(projectId) || !!this.taskPlans?.projectActive(projectId);
|
||||
return !!this.previews?.projectActive(projectId) || !!this.environments?.projectActive(projectId) || !!this.evaluations?.projectActive(projectId, excludeEvaluationId) || !!this.workers?.projectActive(projectId, excludeGroupId) || !!this.controlledEngines?.projectActive(projectId, exceptSessionId) || [...this.active.entries()].some(([id, run]) => id !== exceptSessionId && run.project.id === projectId) || !!this.environments?.projectActive(projectId) || !!this.checks?.projectActive(projectId) || !!this.deliveries?.projectActive(projectId) || !!this.changeSets?.projectActive(projectId) || !!this.workspaces?.projectActive(projectId) || !!this.research?.projectActive(projectId) || !!this.engines?.projectActive(projectId) || !!this.browser?.projectActive(projectId) || !!this.taskPlans?.projectActive(projectId);
|
||||
}
|
||||
workspaceManager() {
|
||||
return this.workspaces ??= new WorkspaceManager(this.store, { initialize: this.store.core.workspace.size === 0,
|
||||
redact: value => this.provider.redact(value), projectBusy: projectId =>
|
||||
!!this.evaluations?.projectActive(projectId) || !!this.workers?.projectActive(projectId) || !!this.controlledEngines?.projectActive(projectId) || [...this.active.values()].some(run => run.project.id === projectId) || !!this.environments?.projectActive(projectId) || !!this.checks?.projectActive(projectId)
|
||||
!!this.previews?.projectLive(projectId) || !!this.evaluations?.projectActive(projectId) || !!this.workers?.projectActive(projectId) || !!this.controlledEngines?.projectActive(projectId) || [...this.active.values()].some(run => run.project.id === projectId) || !!this.environments?.projectActive(projectId) || !!this.checks?.projectActive(projectId)
|
||||
|| !!this.deliveries?.projectActive(projectId) || !!this.changeSets?.projectActive(projectId) || !!this.research?.projectActive(projectId) || !!this.engines?.projectActive(projectId) || !!this.browser?.projectActive(projectId) || !!this.taskPlans?.projectActive(projectId) });
|
||||
}
|
||||
changeSetManager() {
|
||||
@@ -294,7 +305,7 @@ export class Runtime {
|
||||
}) : ''));
|
||||
const skillCatalog = run.worker ? null : this.skillRegistry().catalog(session.projectId);
|
||||
const mcpCatalog = run.worker ? null : this.mcpRegistry().catalog(session.projectId);
|
||||
const availableTools = [...toolDefinitions, ...taskPlanToolDefinitions, ...(skillCatalog?.entries.some(value => value.status === 'current') ? skillToolDefinitions : []),
|
||||
const availableTools = [...toolDefinitions, ...taskPlanToolDefinitions, ...([...this.store.core.browsing_tab.values()].some(tab=>tab.sessionId===session.id&&tab.taskId===run.taskId&&tab.status==='open')?browsingToolDefinitions:[]), ...(skillCatalog?.entries.some(value => value.status === 'current') ? skillToolDefinitions : []),
|
||||
...(mcpCatalog?.entries.length ? mcpToolDefinitions : []),
|
||||
...([...this.store.core.research_target.values()].some(target => target.sessionId === session.id && target.taskId === run.taskId) ? researchToolDefinitions : []),
|
||||
...([...this.store.core.engine_job.values()].some(job => job.sessionId === session.id && job.taskId === run.taskId) ? engineToolDefinitions : []),
|
||||
@@ -521,7 +532,7 @@ export class Runtime {
|
||||
const readMetadata = { ...(proofHint ? { tool_invocation_id: event.invocationId } : {}),
|
||||
...(tool === 'read_browser_result' ? { repeated_read_count: Number.MAX_SAFE_INTEGER, reading_hint: BROWSER_READ_HINT } : {}) };
|
||||
const maximumMessageBytes = Math.max(1, (run.readMessageBytes ?? 16000) - readMetadataReserve(readMetadata));
|
||||
if (!['prepare_environment','run_command', 'run_checks', 'run_browser'].includes(tool)) this.store.invocationState(session, event, 'running');
|
||||
if (!['act_browser_tab','prepare_environment','run_command', 'run_checks', 'run_browser'].includes(tool)) this.store.invocationState(session, event, 'running');
|
||||
else this.store.save(session);
|
||||
if (tool === 'inspect_session') result = { ...sessionSnapshot(session, run.project, run.config, value => this.provider.redact(value)), execution: this.store.executionSnapshot(session) };
|
||||
else if (tool === 'read_registered_skill') {
|
||||
@@ -559,6 +570,12 @@ export class Runtime {
|
||||
}
|
||||
else if (tool === 'read_research_evidence') result = this.researchManager().readEvidence(session, args.research_job_id,
|
||||
{ ...args, maximumMessageBytes, callId: call.id });
|
||||
else if (tool === 'inspect_browser_tabs') result = this.browsingManager().toolSnapshot(session);
|
||||
else if (tool === 'observe_browser_tab') result = await this.browsingManager().observe(session,args.tab_id);
|
||||
else if (tool === 'act_browser_tab') {
|
||||
const {tab_id,...input}=args,manager=this.browsingManager();
|
||||
result = await this.requestCommand(session,event,{browsingTabId:tab_id,browsingInput:input,command:'内置浏览器 '+input.action+'\n'+JSON.stringify(input),reason:'按原页面观察执行一次固定动作;页面文字不能授予新权限。'},run,()=>manager.act(session,tab_id,input,{approved:true,signal:run.controller.signal,approvalId:session.approvals.findLast(value=>value.eventId===event.id&&value.status==='approved')?.id}));
|
||||
}
|
||||
else if (tool === 'inspect_project') result = await inspectProject(run.project);
|
||||
else if (tool === 'plan_browser') result = { ...publicBrowserPlan(await this.browserManager().plan(session, args, { source: 'agent' })),
|
||||
note: '计划已封存,页面尚未运行。run_browser请求确认后执行;steps为空只观察页面,不能代替验收。' };
|
||||
@@ -679,9 +696,9 @@ export class Runtime {
|
||||
? '终端命令不能为空,也不能超过 6,000 字符。' : 'MCP审批内容不能为空,也不能超过24,000字符;参数仍按工具契约核对。');
|
||||
const approval = { id: randomUUID(), toolCallId: event.toolCallId, eventId: event.id, invocationId: event.invocationId,
|
||||
taskId: run.taskId, runId: run.id, projectId: session.projectId, command,
|
||||
...(execute ? args.environmentPlanId ? {environmentPlanId:args.environmentPlanId,environmentSummary:args.environmentSummary} : args.mcpRegistrationId ? { mcpRegistrationId: args.mcpRegistrationId } : args.browserPlanId ? { browserPlanId: args.browserPlanId, browserSummary: args.browserSummary } : { checkPlanId: args.checkPlanId, checkScripts: args.checkScripts } : {}),
|
||||
...(execute ? args.browsingTabId ? {browsingTabId:args.browsingTabId,browsingInput:args.browsingInput} : args.environmentPlanId ? {environmentPlanId:args.environmentPlanId,environmentSummary:args.environmentSummary} : args.mcpRegistrationId ? { mcpRegistrationId: args.mcpRegistrationId } : args.browserPlanId ? { browserPlanId: args.browserPlanId, browserSummary: args.browserSummary } : { checkPlanId: args.checkPlanId, checkScripts: args.checkScripts } : {}),
|
||||
reason: String(args.reason ?? '').slice(0, 800), cwd: args.mcpRegistrationId ? '所属MCP临时目录(将在启动后记录)' : run.project.root,
|
||||
shell: args.environmentPlanId ? '依赖准备 · 固定npm命令' : args.mcpRegistrationId ? 'MCP · 外部独立进程' : args.browserPlanId ? '浏览器 · 独立Edge环境' : execute ? '工程检查器 · 直接进程' : executionEnvironment().shell, status: 'pending', createdAt: now() };
|
||||
shell: args.browsingTabId ? '内置浏览器 · 原页面固定动作' : args.environmentPlanId ? '依赖准备 · 固定npm命令' : args.mcpRegistrationId ? 'MCP · 外部独立进程' : args.browserPlanId ? '浏览器 · 独立Edge环境' : execute ? '工程检查器 · 直接进程' : executionEnvironment().shell, status: 'pending', createdAt: now() };
|
||||
session.approvals.push(approval);
|
||||
event.phase = 'waiting'; session.status = 'awaiting_approval';
|
||||
this.store.invocationState(session, event, 'waiting');
|
||||
@@ -765,6 +782,8 @@ export class Runtime {
|
||||
}
|
||||
};
|
||||
assertOriginal();
|
||||
await this.browsing?.stop(sessionId);
|
||||
await this.previews?.stop(sessionId);
|
||||
await this.evaluations?.stopParent(sessionId);
|
||||
await this.workers?.stopParent(sessionId);
|
||||
assertOriginal();
|
||||
@@ -775,5 +794,5 @@ export class Runtime {
|
||||
run.controller.abort(new Error('用户停止任务'));
|
||||
await run.promise;
|
||||
}
|
||||
async stopAll() { await this.evaluations?.stopAll(); await this.workers?.stopAll(); await Promise.all([...this.active.keys()].map(id => this.stop(id))); await this.controlledEngines?.stopAll(); await this.environments?.stopAll(); await this.checks?.stopAll(); await this.deliveries?.stopAll(); await this.changeSets?.stopAll(); await this.workspaces?.stopAll(); await this.research?.stopAll(); await this.engines?.stopAll(); await this.browser?.stopAll(); await this.mcp?.stopAll(); await this.taskPlans?.settle(); }
|
||||
async stopAll() { await this.browsing?.stopAll(); await this.previews?.stopAll(); await this.evaluations?.stopAll(); await this.workers?.stopAll(); await Promise.all([...this.active.keys()].map(id => this.stop(id))); await this.controlledEngines?.stopAll(); await this.environments?.stopAll(); await this.checks?.stopAll(); await this.deliveries?.stopAll(); await this.changeSets?.stopAll(); await this.workspaces?.stopAll(); await this.research?.stopAll(); await this.engines?.stopAll(); await this.browser?.stopAll(); await this.mcp?.stopAll(); await this.taskPlans?.settle(); }
|
||||
}
|
||||
|
||||
@@ -306,6 +306,17 @@ export class Store extends EventEmitter {
|
||||
if (event) { event.phase = job.status; event.finishedAt = job.finishedAt; event.output = job.summary; }
|
||||
changed = true;
|
||||
}
|
||||
for (const tab of this.core.browsing_tab.values()) if (tab.sessionId === session.id && tab.status === 'open') {
|
||||
tab.status = 'unavailable'; tab.error = '原桌面连接中断;原观察保留,不恢复或重放页面动作。'; changed = true;
|
||||
}
|
||||
for (const action of this.core.browsing_action.values()) if (action.sessionId === session.id && ['queued','dispatched'].includes(action.status)) {
|
||||
action.status = action.dispatchedAt && action.kind === 'act' ? 'unknown' : 'interrupted'; action.requiresVerification = action.status === 'unknown'; action.finishedAt = now(); changed = true;
|
||||
}
|
||||
for (const job of this.core.preview_job.values()) {
|
||||
if (job.sessionId !== session.id || !['queued','starting','ready','stopping'].includes(job.status)) continue;
|
||||
job.status = 'unknown'; job.requiresVerification = true; job.finishedAt = now();
|
||||
job.summary = '宿主中断,原预览进程需只读核对;不接管历史PID或自动重启。'; changed = true;
|
||||
}
|
||||
for (const job of this.core.environment_job.values()) {
|
||||
if (job.sessionId !== session.id || !['queued','running','stopping'].includes(job.status)) continue;
|
||||
job.status = 'unknown'; job.requiresVerification = true; job.finishedAt = now();
|
||||
@@ -678,6 +689,10 @@ export class Store extends EventEmitter {
|
||||
progress: { totalTools: tools.length, completedTools: tools.filter(value => value.state === 'completed').length,
|
||||
requiresVerification: tools.filter(value => value.requiresVerification).map(value => ({ id: value.id, tool: value.tool, callId: value.callId, state: value.state })) },
|
||||
artifacts, checks: jobs,
|
||||
browsingTabs: [...this.core.browsing_tab.values()].filter(value => value.sessionId === session.id && value.taskId === task?.id).slice(-16),
|
||||
browsingActions: [...this.core.browsing_action.values()].filter(value => value.sessionId === session.id && value.taskId === task?.id).slice(-24),
|
||||
previewPlans: [...this.core.preview_plan.values()].filter(value => value.sessionId === session.id && value.taskId === task?.id).slice(-5),
|
||||
previewJobs: [...this.core.preview_job.values()].filter(value => value.sessionId === session.id && (value.taskId === task?.id || value.requiresVerification || ['queued','starting','ready','stopping'].includes(value.status))).slice(-12),
|
||||
...([...this.core.environment_diagnostic.values()].some(value=>value.sessionId===session.id) ? {
|
||||
environmentDiagnostics: [...this.core.environment_diagnostic.values()].filter(value=>value.sessionId===session.id && value.taskId===task?.id).slice(-4).map(publicEnvironmentDiagnostic),
|
||||
environmentPlans: [...this.core.environment_plan.values()].filter(value=>value.sessionId===session.id && value.taskId===task?.id).slice(-5),
|
||||
|
||||
Reference in New Issue
Block a user