From 28c817429a1273d64279a8f710d808952377b689 Mon Sep 17 00:00:00 2001 From: 134 Date: Sun, 12 Jul 2026 01:08:45 +0800 Subject: [PATCH] fix: preserve completed Pascal agent streams --- .../apps/editor/app/api/agent/chat/route.ts | 8 +++++++- .../apps/editor/lib/pascal-agent-mcp.ts | 17 ++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/services/pascal-editor/apps/editor/app/api/agent/chat/route.ts b/services/pascal-editor/apps/editor/app/api/agent/chat/route.ts index ac74871c8..3e845be6f 100644 --- a/services/pascal-editor/apps/editor/app/api/agent/chat/route.ts +++ b/services/pascal-editor/apps/editor/app/api/agent/chat/route.ts @@ -119,7 +119,13 @@ export async function POST(request: Request) { finalized = true try { if (save && !abortSignal.aborted) { - await session.saveDraft(abortSignal) + try { + await session.saveDraft(abortSignal) + } catch (error) { + // Semantic tools live-sync each successful change. A redundant final + // save must not tear down an otherwise completed streaming response. + console.error('Pascal agent final draft save failed.', error) + } } } finally { await session.close() diff --git a/services/pascal-editor/apps/editor/lib/pascal-agent-mcp.ts b/services/pascal-editor/apps/editor/lib/pascal-agent-mcp.ts index e0a99e082..d6ccc41b6 100644 --- a/services/pascal-editor/apps/editor/lib/pascal-agent-mcp.ts +++ b/services/pascal-editor/apps/editor/lib/pascal-agent-mcp.ts @@ -97,7 +97,22 @@ function readSceneName(result: unknown, fallback: string): string { function assertToolSucceeded(result: unknown, operation: string): void { if ((result as { isError?: unknown })?.isError === true) { - throw new Error(`Pascal MCP ${operation} failed.`) + const content = (result as { content?: unknown })?.content + const detail = Array.isArray(content) + ? content + .filter((item): item is { text: string; type: 'text' } => + Boolean( + item && + typeof item === 'object' && + (item as { type?: unknown }).type === 'text' && + typeof (item as { text?: unknown }).text === 'string', + ), + ) + .map((item) => item.text) + .join(' ') + .slice(0, 1000) + : '' + throw new Error(`Pascal MCP ${operation} failed${detail ? `: ${detail}` : '.'}`) } }