From f7aa71cca4810bf49d023066923327a74af344f0 Mon Sep 17 00:00:00 2001 From: butubb <1422726308@qq.com> Date: Sun, 6 Sep 2026 09:21:03 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20AI=20=E6=8E=A7=E5=88=B6=E5=8F=B0?= =?UTF-8?q?=E5=AE=9E=E6=97=B6=E7=94=BB=E9=9D=A2=E8=B7=9F=E9=9A=8F=20AI=20?= =?UTF-8?q?=E6=89=80=E9=80=89=E8=AE=BE=E5=A4=87=E2=80=94=E2=80=94=E5=90=8E?= =?UTF-8?q?=E7=AB=AF=20step=20=E4=BA=8B=E4=BB=B6=20args=20=E5=8E=9F?= =?UTF-8?q?=E4=B8=BA=20str()=20=E7=9A=84=20Python=20repr=EF=BC=88=E5=8D=95?= =?UTF-8?q?=E5=BC=95=E5=8F=B7=EF=BC=89=EF=BC=8C=E5=89=8D=E7=AB=AF=20JSON.p?= =?UTF-8?q?arse=20=E5=A4=B1=E8=B4=A5=E5=AF=BC=E8=87=B4=20followSerialFromA?= =?UTF-8?q?rgs=20=E4=BB=8E=E6=9C=AA=E7=94=9F=E6=95=88=EF=BC=9B=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=E4=BF=9D=E7=95=99=E5=AF=B9=E8=B1=A1=E5=BA=8F=E5=88=97?= =?UTF-8?q?=E5=8C=96=EF=BC=8C=E5=89=8D=E7=AB=AF=E5=85=BC=E5=AE=B9=E5=AF=B9?= =?UTF-8?q?=E8=B1=A1/=E5=AD=97=E7=AC=A6=E4=B8=B2=E5=B9=B6=E4=BF=AE=20step?= =?UTF-8?q?=20=E5=8D=A1=E7=89=87=20args=20=E5=B1=95=E7=A4=BA=EF=BC=88?= =?UTF-8?q?=E9=81=BF=E5=85=8D=20[object=20Object]=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- static/admin/agent.js | 16 ++++++++++------ web/agent_api.py | 4 +++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/static/admin/agent.js b/static/admin/agent.js index 9ae532c..082de5e 100644 --- a/static/admin/agent.js +++ b/static/admin/agent.js @@ -184,9 +184,11 @@ function listenStream(runId){ const cards = msgEl.querySelector('.agent-toolcards'); const card = document.createElement('div'); card.className = 'agent-toolcard'; + const argsTxt = typeof d.args === 'string' ? d.args + : JSON.stringify(d.args || {}); card.innerHTML = '' + '' + esc(d.tool||'') + '' - + '' + esc(d.args||'') + ''; + + '' + esc(argsTxt) + ''; if(d.image){ const img = document.createElement('img'); img.src = 'data:image/jpeg;base64,' + d.image; @@ -242,11 +244,13 @@ function stopLive(){ document.getElementById('agent-live-empty').style.display = 'block'; document.getElementById('agent-live-serial').textContent = ''; } -function followSerialFromArgs(argsStr){ - try{ - const a = JSON.parse(argsStr || '{}'); - if(a.serial) showLive(a.serial); - }catch(e){} +function followSerialFromArgs(args){ + // 工具 args(后端 SSE 已序列化为对象;兼容历史字符串格式) + let a = args; + if(typeof args === 'string'){ + try{ a = JSON.parse(args); }catch(e){ return; } + } + if(a && a.serial) showLive(a.serial); } function watchDevice(serial){ if(!serial){ stopLive(); return; } diff --git a/web/agent_api.py b/web/agent_api.py index 4781f81..1750915 100644 --- a/web/agent_api.py +++ b/web/agent_api.py @@ -594,8 +594,10 @@ def _agent_thread(run_id, prompt, serial, cfg): tool_seq = [] # 本轮工具序列(经验提炼用) def on_tool(step): + # args 保留对象(json.dumps 序列化)——前端要解析 serial 做画面跟随; + # 之前 str() 成 Python repr(单引号)导致前端 JSON.parse 失败、跟随失效 rec = {"tool": step.get("tool"), - "args": str(step.get("args"))[:200]} + "args": step.get("args") or {}} if step.get("image"): rec["image"] = _shrink_image(step["image"]) q.put(("step", rec))