fix: 使用终态答案校正流式输出

- DONE 事件携带后端汇总的完整最终正文

- 前端完成时替换可能受损的流式文本

- 补充文件 URL 终态校正回归测试
This commit is contained in:
2026-07-23 19:49:45 +08:00
parent 417e846cbd
commit 41545fcef0
4 changed files with 65 additions and 3 deletions

View File

@@ -298,6 +298,38 @@ describe('agentTimelineAdapter', () => {
});
});
it('reconciles streamed text with the canonical final answer', () => {
const items: any[] = [];
for (const delta of [
'http://127.0.0.1:39',
'0',
'/easyflow/file.docx',
]) {
applyAgentSseEnvelope(items, {
domain: 'LLM',
type: 'MESSAGE',
payload: { delta },
});
}
applyAgentSseEnvelope(items, {
domain: 'SYSTEM',
type: 'DONE',
payload: {
finalText: 'http://127.0.0.1:39000/easyflow/file.docx',
},
});
const assistant = items.find(
(item): item is ChatTimelineMessageItem =>
item.type === 'message' && item.role === 'assistant',
);
expect(assistant?.parts[0]?.content).toBe(
'http://127.0.0.1:39000/easyflow/file.docx',
);
expect(assistant?.status).toBe('done');
});
it('applies streaming text, HITL approval and error envelopes', () => {
const items: any[] = [];

View File

@@ -534,6 +534,10 @@ export function applyAgentSseEnvelope(
return;
}
if (domain === 'SYSTEM' && type === 'DONE') {
const finalText = asText(payload.finalText ?? payload.text);
if (finalText) {
ChatTimelineBuilder.replaceMessageContent(items, finalText);
}
ChatTimelineBuilder.finalize(items);
return;
}