fix: remove open execution record caps and preserve recovery history
This commit is contained in:
+4
-2
@@ -25,6 +25,7 @@ import { validateModelWaitSettings } from '../core/models/request-deadline.mjs';
|
||||
import { nativeParameterSettings } from '../shared/contracts/native-parameters.mjs';
|
||||
import { localDirectories } from './local-directories.mjs';
|
||||
import { readInstallationProgress } from '../core/desktop/installation-progress.mjs';
|
||||
import { recordPageQuery } from '../shared/contracts/record-page.mjs';
|
||||
|
||||
export function createSessionPublisher(clients) {
|
||||
return session => {
|
||||
@@ -103,6 +104,7 @@ return async (request, response) => {
|
||||
if (route.startsWith('/api/companion')) {
|
||||
const gateway = companionGateway({ appDirectory, server, store, provider, runtime });
|
||||
if (method === 'GET' && route === '/api/companion') return json(response, gateway.status());
|
||||
if (method === 'GET' && route === '/api/companion/audit') return json(response, gateway.registry.auditPage(recordPageQuery(url) ?? {}));
|
||||
if (method === 'POST' && route === '/api/companion/start') return json(response, await gateway.start(await body(request)));
|
||||
if (method === 'POST' && route === '/api/companion/close') { const value = await body(request); if (Object.keys(value).length) throw Object.assign(new Error('关闭手机连接不接受额外字段。'), { status: 400 }); return json(response, await gateway.close()); }
|
||||
if (method === 'POST' && route === '/api/companion/pair') return json(response, await gateway.pairing(await body(request)));
|
||||
@@ -488,7 +490,7 @@ return async (request, response) => {
|
||||
'X-Content-Type-Options': 'nosniff', ...(engineRun[2] === 'download' ? { 'Content-Disposition': 'attachment; filename="agent-workbench-engine-run-' + job.id + '.json"' } : {}) });
|
||||
response.end(text); return;
|
||||
}
|
||||
if (method === 'GET' && action === 'mcp/jobs') return json(response, runtime.mcpRegistry().jobs(session));
|
||||
if (method === 'GET' && action === 'mcp/jobs') return json(response, runtime.mcpRegistry().jobs(session, recordPageQuery(url)));
|
||||
if (method === 'POST' && action === 'mcp/probe') {
|
||||
const started = runtime.mcpRegistry().start(session, await body(request));
|
||||
return json(response, { job: started.job, session: store.publicSession(session) }, 202);
|
||||
@@ -535,7 +537,7 @@ 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 === 'task-checkpoints') return json(response, runtime.checkpointManager().list(session));
|
||||
if (method === 'GET' && action === 'task-checkpoints') return json(response, runtime.checkpointManager().list(session, recordPageQuery(url)));
|
||||
if (method === 'POST' && action === 'task-checkpoints') {
|
||||
const input = await body(request);
|
||||
if (Object.keys(input).some(key => !['taskId', 'runId'].includes(key)) || input.taskId !== session.taskId || input.runId !== session.runId) throw Object.assign(new Error('检查点的原任务或运行已变化,请刷新当前任务。'), { status: 409 });
|
||||
|
||||
@@ -12,6 +12,7 @@ import { isId } from '../shared/contracts/execution.mjs';
|
||||
import { mobileSession, sessionBrief, reportKinds } from '../core/companion/projection.mjs';
|
||||
import { InputAttachments } from '../core/context/input-attachments.mjs';
|
||||
import { hostAuthority } from '../core/desktop/host-authority.mjs';
|
||||
import { recordPageQuery } from '../shared/contracts/record-page.mjs';
|
||||
|
||||
export function companionGateway(context) {
|
||||
if (!context.server.workbenchCompanion) {
|
||||
@@ -190,7 +191,7 @@ export class CompanionGateway {
|
||||
const mobileUrl = new URL(request.url, this.origin), route = mobileUrl.pathname, method = request.method;
|
||||
if (mobileUrl.origin !== this.origin || request.headers.origin && request.headers.origin !== this.origin) throw companionError('请求来源不属于当前手机网关。', 403);
|
||||
if (method === 'POST' && request.headers.origin !== this.origin) throw companionError('手机操作需要来自当前HTTPS页面。', 403);
|
||||
if (mobileUrl.search && route !== '/mobile-api/events' && !/^\/mobile-api\/sessions\/[a-f0-9-]+\/changes\/[a-f0-9-]+$/.test(route)) throw companionError('手机接口不接受额外查询字段。');
|
||||
if (mobileUrl.search && !['/mobile-api/events', '/mobile-api/operations'].includes(route) && !/^\/mobile-api\/sessions\/[a-f0-9-]+\/changes\/[a-f0-9-]+$/.test(route)) throw companionError('手机接口不接受额外查询字段。');
|
||||
if (method === 'POST' && route === '/mobile-api/pair') {
|
||||
this.limit('pair:' + request.socket.remoteAddress, 8);
|
||||
const value = await input(request, this.store.config); fields(value, ['token', 'name']);
|
||||
@@ -204,10 +205,15 @@ export class CompanionGateway {
|
||||
if (!this.sockets.has(request.socket)) request.socket.once('close', () => this.sockets.delete(request.socket));
|
||||
this.sockets.set(request.socket, device.id);
|
||||
if (method === 'GET' && route === '/mobile-api/me') {
|
||||
const state = this.registry.read();
|
||||
const state = this.registry.read(), page = this.registry.operationsPage(device, {}, state);
|
||||
return reply(response, { device: { id: device.id, name: device.name, projectIds: device.projectIds, permissions: device.permissions, expiresAt: device.expiresAt, revision: device.revision },
|
||||
gatewayId: state.gatewayId, operations: Object.values(state.operations).filter(value => value.deviceId === device.id && device.projectIds.includes(value.projectId)).slice(-20)
|
||||
.map(value => ({ requestId: value.requestId, action: value.action, status: value.status === 'pending' ? 'unknown' : value.status, taskId: value.taskId, runId: value.runId, createdAt: value.createdAt })) });
|
||||
gatewayId: state.gatewayId, operations: page.items, operationsPage: page,
|
||||
unresolvedOperations: Object.values(state.operations).filter(value => value.deviceId === device.id && device.projectIds.includes(value.projectId) && ['pending', 'unknown'].includes(value.status))
|
||||
.map(value => ({ requestId: value.requestId, action: value.action, status: 'unknown', taskId: value.taskId, runId: value.runId, createdAt: value.createdAt })) });
|
||||
}
|
||||
if (method === 'GET' && route === '/mobile-api/operations') {
|
||||
try { return reply(response, this.registry.operationsPage(device, recordPageQuery(mobileUrl) ?? {})); }
|
||||
catch (error) { throw companionError(error.message, error.status ?? 400); }
|
||||
}
|
||||
if (method === 'POST' && route === '/mobile-api/rotate') {
|
||||
fields(await input(request, this.store.config), []); const token = this.registry.rotate(device); setCookie(response, token, device.expiresAt); return reply(response, { rotated: true });
|
||||
|
||||
@@ -684,6 +684,8 @@ export class Store extends EventEmitter {
|
||||
executionSnapshot(session) {
|
||||
const task = this.core.task.get(session.taskId), run = this.core.run.get(session.runId);
|
||||
const tools = [...this.core.tool.values()].filter(value => value.sessionId === session.id && value.taskId === task?.id);
|
||||
const mcpAll = [...this.core.mcp_job.values()].filter(value => value.sessionId === session.id);
|
||||
const mcpPreview = mcpAll.filter(value => value.taskId === task?.id || value.requiresVerification).slice(-30);
|
||||
const artifacts = [...this.core.artifact.values()].filter(value => value.sessionId === session.id && value.taskId === task?.id).slice(-30);
|
||||
const jobs = [...this.core.check_job.values()].filter(value => value.sessionId === session.id && value.taskId === task?.id).slice(-10);
|
||||
const projectWorkspaces = [...this.core.workspace.values()].filter(value => value.projectId === session.projectId);
|
||||
@@ -715,7 +717,7 @@ export class Store extends EventEmitter {
|
||||
environmentPlans: [...this.core.environment_plan.values()].filter(value=>value.sessionId===session.id && value.taskId===task?.id).slice(-5),
|
||||
environmentJobs: [...this.core.environment_job.values()].filter(value=>value.sessionId===session.id && (value.taskId===task?.id || value.requiresVerification)).filter((value,index,all)=>index>=all.length-12 || value.requiresVerification || ['queued','running','stopping'].includes(value.status)),
|
||||
} : {}),
|
||||
mcpJobs: [...this.core.mcp_job.values()].filter(value => value.sessionId === session.id && (value.taskId === task?.id || value.requiresVerification)).slice(-30),
|
||||
mcpJobs: mcpPreview, mcpJobCount: mcpAll.length, mcpJobsTruncated: mcpAll.length > mcpPreview.length,
|
||||
taskPlans: [...this.core.task_plan.values()].filter(value => value.sessionId === session.id && value.taskId === task?.id).slice(-6),
|
||||
taskProofs: [...this.core.task_proof.values()].filter(value => value.sessionId === session.id && value.taskId === task?.id).slice(-24),
|
||||
researchTargets: [...this.core.research_target.values()].filter(value => value.sessionId === session.id && value.taskId === task?.id).slice(-32),
|
||||
|
||||
Reference in New Issue
Block a user