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))