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

@@ -930,7 +930,7 @@ public class AgentRunService {
buildAssistantRuntimeMessage(chatContext, finalAnswer, assistantAccumulator, citations));
chatRuntimeManager.recordCompleted(chatContext);
}
sendDone(chatSseEmitter);
sendDone(chatSseEmitter, finalAnswer);
}
private void handleRuntimeError(Throwable error,
@@ -1184,10 +1184,30 @@ public class AgentRunService {
return chatSseEmitter.send(envelope);
}
/**
* 发送不携带最终正文的完成事件。
*
* @param chatSseEmitter SSE 发送器
* @return 发送成功时为 {@code true}
*/
private boolean sendDone(ChatSseEmitter chatSseEmitter) {
return sendDone(chatSseEmitter, null);
}
/**
* 发送完成事件,并提供最终正文供前端校正流式增量。
*
* @param chatSseEmitter SSE 发送器
* @param finalText 最终完整正文;取消场景可为空
* @return 发送成功时为 {@code true}
*/
private boolean sendDone(ChatSseEmitter chatSseEmitter, String finalText) {
ChatEnvelope<Map<String, Object>> envelope = new ChatEnvelope<>();
envelope.setDomain(ChatDomain.SYSTEM);
envelope.setType(ChatType.DONE);
if (finalText != null) {
envelope.setPayload(Map.of("finalText", finalText));
}
return chatSseEmitter.sendDone(envelope);
}