Restore existing project works independently of model sessions

This commit is contained in:
鲨鱼辣椒 committed 2026-10-14 11:15:17 +08:00
1 parent 4eb3efa3d1
commit 0f26b6d072
19 files changed
+1977 -68

No files matched your search

+9 -2
View File
@@ -9,6 +9,7 @@ import { parseJsonBody, sendJson } from '../route-utils';
type AgentBrowserBody = {
conversation_id?: unknown;
allow_assistant?: unknown;
request_id?: unknown;
project_id?: unknown;
project_path?: unknown;
@@ -42,6 +43,7 @@ function workPreviewService(ctx: HostApiContext): CodingWorkPreviewService | und
conversations: ctx.codingProducts.conversations,
runtime: ctx.codingProducts.runtime,
ensureActive: (target) => ensureProjectStillActive(ctx, target),
storedSnapshot: (id) => ctx.codingProducts!.conversations.getStoredSnapshot(id),
});
workPreviewServices.set(ctx, preview);
}
@@ -264,11 +266,16 @@ export async function handleAgentBrowserRoutes(
if (!requestId || !/^[a-zA-Z0-9-]{1,80}$/.test(requestId)) {
throw new AgentBrowserRouteError('INVALID_REQUEST', '作品请求无效。');
}
if (body.allow_assistant !== undefined && typeof body.allow_assistant !== 'boolean') {
throw new AgentBrowserRouteError('INVALID_REQUEST', '作品请求无效。');
}
if (!ctx.codingProducts) throw new AgentBrowserRouteError('CLOSED', '本地编程服务暂时不可用。', 503);
const preview = workPreviewService(ctx)!;
const release = ctx.lifecycle?.acquireLease({ id: `work-preview:${project.id}:${requestId}`, kind: 'work-preview' });
try {
const result = await preview.ensure(project, requestId, nonEmptyString(body.conversation_id));
const result = body.allow_assistant === true
? await preview.ensure(project, requestId, nonEmptyString(body.conversation_id), true)
: await preview.ensure(project, requestId, nonEmptyString(body.conversation_id));
await ensureProjectStillActive(ctx, project);
sendJson(res, 200, { success: true, ...result });
} finally {
@@ -313,7 +320,7 @@ export async function handleAgentBrowserRoutes(
...(body.inject_project_data === true ? { injectProjectData: true } : {}),
});
await ensureProjectStillActive(ctx, project);
workPreviewService(ctx)?.remember(project, browser);
await workPreviewService(ctx)?.remember(project, browser).catch(() => undefined);
emitState(ctx, 'agent-browser:show', browser);
sendJson(res, 200, { success: true, browser });
return true;