fix: AI 控制台实时画面跟随 AI 所选设备——后端 step 事件 args 原为 str() 的 Python repr(单引号),前端 JSON.parse 失败导致 followSerialFromArgs 从未生效;改为保留对象序列化,前端兼容对象/字符串并修 step 卡片 args 展示(避免 [object Object])
This commit is contained in:
+10
-6
@@ -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 = '<span class="dot"></span>'
|
||||
+ '<code style="color:var(--teal)">' + esc(d.tool||'') + '</code>'
|
||||
+ '<span class="text-muted">' + esc(d.args||'') + '</span>';
|
||||
+ '<span class="text-muted">' + esc(argsTxt) + '</span>';
|
||||
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; }
|
||||
|
||||
+3
-1
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user