feat: verify owned DeepSeek engine connections and responsive task execution
This commit is contained in:
@@ -6,6 +6,7 @@ import { inspectProject } from '../core/project-inspector.mjs';
|
||||
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';
|
||||
|
||||
export function createSessionPublisher(clients) {
|
||||
return session => {
|
||||
@@ -87,6 +88,7 @@ return async (request, response) => {
|
||||
});
|
||||
}
|
||||
if (method === 'GET' && route === '/api/research/availability') return json(response, runtime.researchManager().availability());
|
||||
if (method === 'GET' && route === '/api/engines/deepseek/availability') return json(response, runtime.engineManager().availability(url.searchParams.has('root') ? url.searchParams.get('root') : undefined));
|
||||
if (method === 'GET' && route === '/api/events') {
|
||||
const cursor = Math.max(cursorNumber(url.searchParams.get('after')), cursorNumber(request.headers['last-event-id']));
|
||||
if (cursor > store.eventCursor) throw Object.assign(new Error('事件游标超出当前历史,请重新加载工作台。'), { status: 409 });
|
||||
@@ -147,6 +149,35 @@ return async (request, response) => {
|
||||
const session = store.session(id);
|
||||
if (method === 'GET' && !action) return json(response, store.publicSession(session));
|
||||
if (method === 'GET' && action === 'execution') return json(response, store.executionSnapshot(session));
|
||||
if (method === 'GET' && action === 'engines') {
|
||||
const manager = runtime.engineManager();
|
||||
return json(response, { availability: manager.availability(), jobs: manager.jobs(session).map(publicEngineJob) });
|
||||
}
|
||||
if (method === 'POST' && action === 'engines/jobs') {
|
||||
const started = runtime.engineManager().start(session, await body(request));
|
||||
return json(response, { job: publicEngineJob(started.job), session: store.publicSession(session) }, 202);
|
||||
}
|
||||
if (method === 'POST' && action === 'engines/stop') { await runtime.engineManager().stop(id); return json(response, store.publicSession(session)); }
|
||||
const engineJob = action.match(/^engines\/jobs\/([a-f0-9-]+)(?:\/(report|download))?$/);
|
||||
if (method === 'GET' && engineJob) {
|
||||
const manager = runtime.engineManager(), job = store.owned('engine_job', engineJob[1], id);
|
||||
if (engineJob[2]) {
|
||||
if (!job.reportArtifactId) throw Object.assign(new Error('这次引擎检查尚未封存原记录,请等待检查结束。'), { status: 409 });
|
||||
const text = manager.originalReport(session, job), artifact = store.owned('artifact', job.reportArtifactId, id);
|
||||
if (engineJob[2] === 'download') {
|
||||
response.writeHead(200, { 'Content-Type': 'application/json; charset=utf-8', 'Cache-Control': 'no-store',
|
||||
'X-Content-Type-Options': 'nosniff', 'Content-Disposition': 'attachment; filename="agent-workbench-engine-' + job.id + '.json"' });
|
||||
response.end(text); return;
|
||||
}
|
||||
const offset = cursorNumber(url.searchParams.get('offset'));
|
||||
const limit = Math.min(16000, url.searchParams.has('limit') ? cursorNumber(url.searchParams.get('limit')) : 4000);
|
||||
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 (job.reportArtifactId) manager.originalReport(session, job); else manager.inputFor(session, job);
|
||||
return json(response, publicEngineJob(job));
|
||||
}
|
||||
if (method === 'GET' && action === 'research') {
|
||||
const manager = runtime.researchManager(); return json(response, { availability: manager.availability(), targets: manager.targets(session), jobs: manager.jobs(session) });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user