feat(context): expose verified cache controls and optimize snapshot closure

This commit is contained in:
Agent Workbench Dev
2026-11-01 02:35:47 +08:00
parent be126525c5
commit 7a7e0bbe87
27 changed files with 2452 additions and 26 deletions
+20
View File
@@ -203,9 +203,18 @@ return async (request, response) => {
version: APP_VERSION, environment: executionEnvironment(),
connection: { mode: store.config.mode, endpoint: store.config.baseUrl, model: store.config.model, hasKey: provider.hasKey(), lastRequest: provider.lastRequest ?? null },
storage: store.storageInfo(),
projectCache: runtime.projectIndexer().status(session ? store.project(session.projectId) : undefined),
session: session ? { ...sessionSnapshot(session, store.project(session.projectId), store.config, value => provider.redact(value)), execution: store.executionSnapshot(session) } : null,
});
}
if (route === '/api/project-cache') {
if (method === 'GET') return json(response, runtime.projectIndexer().status());
if (method === 'POST') {
const input = await body(request);
if (!input || Object.keys(input).length !== 1 || typeof input.enabled !== 'boolean') throw new Error('仅接受enabled缓存开关。');
return json(response, runtime.projectIndexer().configure(input.enabled));
}
}
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/engines/deepseek/controlled-availability') return json(response, runtime.engineRunner().availability(url.searchParams.has('root') ? url.searchParams.get('root') : undefined));
@@ -244,6 +253,17 @@ return async (request, response) => {
if (typeof input.root !== 'string' || input.root.length > 2000) throw new Error('请输入项目文件夹的完整路径。');
return json(response, store.addProject(input.root), 201);
}
const cacheMatch = route.match(/^\/api\/projects\/([a-f0-9-]+)\/index-cache$/);
if (cacheMatch && ['GET', 'DELETE'].includes(method)) {
const project = store.project(cacheMatch[1]);
await verifyWorkspaceProject(store, project);
if (method === 'DELETE') {
const input = await body(request);
if (!input || Object.keys(input).length) throw new Error('清除派生缓存不接受路径或其他字段。');
return json(response, runtime.projectIndexer().clear(project));
}
return json(response, runtime.projectIndexer().status(project));
}
const projectMatch = route.match(/^\/api\/projects\/([a-f0-9-]+)\/(files|file|inspection|code-index|code-query)$/);
if (method === 'GET' && projectMatch) {
const project = store.project(projectMatch[1]);