fix: preserve completed Pascal agent streams
This commit is contained in:
parent
9efb9e8237
commit
28c817429a
@ -119,7 +119,13 @@ export async function POST(request: Request) {
|
|||||||
finalized = true
|
finalized = true
|
||||||
try {
|
try {
|
||||||
if (save && !abortSignal.aborted) {
|
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 {
|
} finally {
|
||||||
await session.close()
|
await session.close()
|
||||||
|
|||||||
@ -97,7 +97,22 @@ function readSceneName(result: unknown, fallback: string): string {
|
|||||||
|
|
||||||
function assertToolSucceeded(result: unknown, operation: string): void {
|
function assertToolSucceeded(result: unknown, operation: string): void {
|
||||||
if ((result as { isError?: unknown })?.isError === true) {
|
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}` : '.'}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user