fix: preserve completed Pascal agent streams

This commit is contained in:
134 2026-07-12 01:08:45 +08:00
parent 9efb9e8237
commit 28c817429a
2 changed files with 23 additions and 2 deletions

View File

@ -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()

View File

@ -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}` : '.'}`)
}
}