fix(short-novel): 同步 SSE 事件顶层 session_id 修复澄清卡片累积丢失
上游 SSE 事件中 session_id 与 type 同级(不在 payload 内),原 forwardSse 仅在 status 事件从 payload 取 session_id, 导致首次 stream 的 sessionId 为 null,后续 clarification_card 因 sessionId 为空不进入全局累积器, 详情页首次进入时少显示第一张澄清卡片。 改为在每个事件处理前从顶层 session_id 同步 currentSessionId,确保所有事件链路都能拿到正确的 sessionId。 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -307,6 +307,15 @@ public class ShortNovelServiceImpl implements ShortNovelService {
|
|||||||
long eventTimestamp = System.currentTimeMillis();
|
long eventTimestamp = System.currentTimeMillis();
|
||||||
log.info("[ShortNovel SSE] 处理事件: type={}, timestamp={}", type, eventTimestamp);
|
log.info("[ShortNovel SSE] 处理事件: type={}, timestamp={}", type, eventTimestamp);
|
||||||
|
|
||||||
|
// 从事件顶层取 session_id 同步 sessionId
|
||||||
|
// 上游事件结构与前端对齐:session_id 与 type 同级,不在 payload 内
|
||||||
|
// 修复:首次 stream 里 status 处理从 payload 取不到 session_id,导致 currentSessionId 保持 null,
|
||||||
|
// 第一个 clarification_card 因 sessionId 为 null 不累积,详情页少显示第一个选项卡
|
||||||
|
String topSessionId = event.getString("session_id");
|
||||||
|
if (topSessionId != null && !topSessionId.isEmpty()) {
|
||||||
|
currentSessionId[0] = topSessionId;
|
||||||
|
}
|
||||||
|
|
||||||
// 拦截 status 事件,缓存 sessionId → originalQuery 映射(供 followup 兜底)
|
// 拦截 status 事件,缓存 sessionId → originalQuery 映射(供 followup 兜底)
|
||||||
if ("status".equals(type)) {
|
if ("status".equals(type)) {
|
||||||
JSONObject payload = event.getJSONObject("payload");
|
JSONObject payload = event.getJSONObject("payload");
|
||||||
|
|||||||
Reference in New Issue
Block a user