feat: add task-bound real browser checks and verified page delivery
This commit is contained in:
+42
-1
@@ -7,6 +7,7 @@ import { assertProposalUnsealed } from '../shared/contracts/change-sets.mjs';
|
||||
import { assertWorkspacesResolved } from '../shared/contracts/workspaces.mjs';
|
||||
import { verifyWorkspaceProject } from '../core/workspaces/git-workspaces.mjs';
|
||||
import { publicEngineJob } from '../shared/contracts/engines.mjs';
|
||||
import { verifyBrowserJob } from '../core/browser/browser-manager.mjs';
|
||||
|
||||
export function createSessionPublisher(clients) {
|
||||
return session => {
|
||||
@@ -75,7 +76,7 @@ return async (request, response) => {
|
||||
eventCursor: store.eventCursor, storage: store.storageInfo(), runtimeRoot: appDirectory,
|
||||
environment: executionEnvironment(),
|
||||
projects: store.projects, sessions: store.listSessions(), exampleProjectId: exampleProject?.id ?? null,
|
||||
capabilities: { workspaces: 'owned-git-worktree-and-explicit-recovery', gitReview: 'durable-confirmation-boundary', requestContext: 'bounded-whole-request-and-history-artifacts', latestToolFeedback: 'sealed-original-result-fields', changeSets: 'reviewed-recoverable-batches', fileChanges: 'review', exactPatches: 'sha256-unique-anchors', codeIndex: 'bounded-ast-and-candidates', commands: 'per-call-approval', recovery: 'durable-tool-results', model: 'chat-completions-compatible', execution: 'task-run-step', events: 'persistent-cursor', artifacts: 'sha256-verified', checks: 'npm-and-python-counted-jobs', pythonChecks: 'bound-interpreter-and-structured-results', projectInspection: 'bounded-source-and-git', gitDelivery: 'reviewed-local-snapshot', deliveryReports: 'evidence-json-markdown' },
|
||||
capabilities: { workspaces: 'owned-git-worktree-and-explicit-recovery', gitReview: 'durable-confirmation-boundary', requestContext: 'bounded-whole-request-and-history-artifacts', latestToolFeedback: 'sealed-original-result-fields', changeSets: 'reviewed-recoverable-batches', fileChanges: 'review', exactPatches: 'sha256-unique-anchors', codeIndex: 'bounded-ast-and-candidates', commands: 'per-call-approval', recovery: 'durable-tool-results', model: 'chat-completions-compatible', execution: 'task-run-step', events: 'persistent-cursor', artifacts: 'sha256-verified', checks: 'npm-and-python-counted-jobs', pythonChecks: 'bound-interpreter-and-structured-results', browserChecks: 'sealed-static-build-and-real-edge-assertions', projectInspection: 'bounded-source-and-git', gitDelivery: 'reviewed-local-snapshot', deliveryReports: 'evidence-json-markdown' },
|
||||
});
|
||||
if (method === 'GET' && route === '/api/diagnostics') {
|
||||
const selected = url.searchParams.get('session');
|
||||
@@ -181,6 +182,46 @@ return async (request, response) => {
|
||||
if (method === 'GET' && action === 'research') {
|
||||
const manager = runtime.researchManager(); return json(response, { availability: manager.availability(), targets: manager.targets(session), jobs: manager.jobs(session) });
|
||||
}
|
||||
if (method === 'GET' && action === 'browser') {
|
||||
const manager = runtime.browserManager(), available = manager.availability();
|
||||
return json(response, { availability: { status: available.status, engine: available.engine, playwrightVersion: available.playwrightVersion, message: available.message },
|
||||
builds: manager.builds(store.project(session.projectId)), plans: manager.plans(session), jobs: manager.jobs(session) });
|
||||
}
|
||||
if (method === 'POST' && action === 'browser-plans') {
|
||||
await runtime.browserManager().plan(session, await body(request)); return json(response, store.publicSession(session), 201);
|
||||
}
|
||||
if (method === 'POST' && action === 'browser-jobs') {
|
||||
const input = await body(request), started = runtime.browserManager().start(session, input.planId);
|
||||
if (started.reused) await started.promise;
|
||||
return json(response, store.publicSession(session), 202);
|
||||
}
|
||||
const browserJob = action.match(/^browser-jobs\/([a-f0-9-]+)(?:\/(stop|acknowledge|record))?$/);
|
||||
if (browserJob && method === 'POST' && ['stop', 'acknowledge'].includes(browserJob[2])) {
|
||||
const input = await body(request); store.owned('browser_job', browserJob[1], id);
|
||||
if (browserJob[2] === 'stop') await runtime.browserManager().stop(id, browserJob[1]);
|
||||
else runtime.browserManager().acknowledge(session, browserJob[1], input.fingerprint);
|
||||
return json(response, store.publicSession(session));
|
||||
}
|
||||
if (browserJob && method === 'GET') {
|
||||
const job = store.owned('browser_job', browserJob[1], id);
|
||||
if (browserJob[2] === 'record') {
|
||||
verifyBrowserJob(store, session, job); const artifact = store.owned('artifact', job.resultArtifactId, id), text = store.artifactStore.read(artifact);
|
||||
const offset = cursorNumber(url.searchParams.get('offset')), limit = Math.min(16000, url.searchParams.has('limit') ? cursorNumber(url.searchParams.get('limit')) : 8000);
|
||||
if (!limit || offset > text.length) throw Object.assign(new Error('浏览器原结果分页范围无效。'), { status: 400 });
|
||||
return json(response, { ...artifact, content: text.slice(offset, offset + limit), offset, totalCharacters: text.length, truncated: offset + limit < text.length });
|
||||
}
|
||||
if (!browserJob[2]) { if (job.resultArtifactId) verifyBrowserJob(store, session, job); else runtime.browserManager().planFor(session, job.planId); return json(response, job); }
|
||||
}
|
||||
const browserImage = action.match(/^browser-jobs\/([a-f0-9-]+)\/images\/([a-f0-9-]+)$/);
|
||||
if (method === 'GET' && browserImage) {
|
||||
const job = store.owned('browser_job', browserImage[1], id); verifyBrowserJob(store, session, job);
|
||||
const image = job.screenshots.find(value => value.artifactId === browserImage[2]);
|
||||
if (!image) throw Object.assign(new Error('图片不属于这次浏览器检查。'), { status: 404 });
|
||||
const artifact = store.owned('artifact', image.artifactId, id);
|
||||
response.writeHead(200, { 'Content-Type': 'image/png', 'Cache-Control': 'no-store', 'X-Content-Type-Options': 'nosniff',
|
||||
...(url.searchParams.get('download') === '1' ? { 'Content-Disposition': 'attachment; filename="workbench-browser-' + job.id + '-' + image.label + '.png"' } : {}) });
|
||||
response.end(store.artifactStore.readBytes(artifact)); return;
|
||||
}
|
||||
if (method === 'POST' && action === 'research/targets') {
|
||||
const target = await runtime.researchManager().register(session, await body(request));
|
||||
return json(response, { target, session: store.publicSession(session) }, 201);
|
||||
|
||||
Reference in New Issue
Block a user