fix: Corpus Agent SSE token events not forwarded to frontend\n\nRoot cause: Portal chat-v2 sends token events as {"token":"铸"} without a "type"\nfield. The Corpus Agent was checking data.get("type", "") == SSE_TYPE_TOKEN, but\nsince there was no "type" field, all token events were silently dropped.\n\nFix: Also match events where event_type is empty but a "token" key exists in data.

This commit is contained in:
root 2026-05-22 16:27:53 +08:00
parent b465d173f0
commit 088548405a

View File

@ -592,8 +592,8 @@ async def chat_with_agent(req: ChatRequest, token: str = Query(...)):
if event_type == SSE_TYPE_PERSONA:
yield f"data: {json.dumps({'type': SSE_TYPE_PERSONA, 'persona': data.get('persona', ''), 'fromDB': data.get('fromDB', False)})}\n\n"
# 转发 token 事件
elif event_type == SSE_TYPE_TOKEN:
# 转发 token 事件兼容Portal原始格式{"token":"铸"} 无type字段
if event_type == SSE_TYPE_TOKEN or (not event_type and "token" in data):
token_text = data.get("token", "")
full_response += token_text
yield f"data: {json.dumps({'type': SSE_TYPE_TOKEN, 'token': token_text})}\n\n"