From 088548405a01bfb420f6bc8e68495d80f225a960 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 22 May 2026 16:27:53 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20Corpus=20Agent=20SSE=20token=20events=20?= =?UTF-8?q?not=20forwarded=20to=20frontend\n\nRoot=20cause:=20Portal=20cha?= =?UTF-8?q?t-v2=20sends=20token=20events=20as=20{"token":"=E9=93=B8"}=20wi?= =?UTF-8?q?thout=20a=20"type"\nfield.=20The=20Corpus=20Agent=20was=20check?= =?UTF-8?q?ing=20data.get("type",=20"")=20=3D=3D=20SSE=5FTYPE=5FTOKEN,=20b?= =?UTF-8?q?ut\nsince=20there=20was=20no=20"type"=20field,=20all=20token=20?= =?UTF-8?q?events=20were=20silently=20dropped.\n\nFix:=20Also=20match=20ev?= =?UTF-8?q?ents=20where=20event=5Ftype=20is=20empty=20but=20a=20"token"=20?= =?UTF-8?q?key=20exists=20in=20data.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/corpus-agent/server.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/corpus-agent/server.py b/server/corpus-agent/server.py index fe27dc9..912c8be 100644 --- a/server/corpus-agent/server.py +++ b/server/corpus-agent/server.py @@ -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"