fix(agent-chat): 确认框显示工具名+参数摘要——旧实现只读command字段致apply类工具显示空命令被迫盲确认

This commit is contained in:
yumoqing 2026-09-05 21:25:49 +08:00
parent bb2b7b4094
commit e03e1fa213
2 changed files with 29 additions and 4 deletions

View File

@ -129,8 +129,22 @@ if action == 'send_message':
elif t == 'confirm':
_tool = data.get('tool', '')
_params = data.get('params', {}) or {}
_cmd = _params.get('command', '') if isinstance(_params, dict) else ''
yield json.dumps({"content": "⚠️ 需要你确认执行命令:`" + str(_cmd)[:120] + "`\n请回复「确认」执行、「全部确认」本会话不再询问或「取消」放弃。"}, ensure_ascii=False) + '\n'
# 确认框摘要2026-09-05 修复):旧实现只取 command 字段run_command 专用),
# 其他工具apply_llm_config 等参数叫 spec显示为空命令用户被迫盲确认。
# 改为显示工具名 + 关键参数摘要use_last_extract/overrides/url/model_name 等),
# 大字段spec/doc_text只显长度不显内容。
_brief = []
if isinstance(_params, dict):
for _k in ('command', 'url', 'model_name', 'use_last_extract', 'overrides', 'task_ref'):
if _k in _params and str(_params.get(_k) or '') != '':
_v = _params.get(_k)
_vs = _v if isinstance(_v, str) else json.dumps(_v, ensure_ascii=False)
_brief.append("%s=%s" % (_k, _vs[:80]))
for _k in ('spec', 'doc_text'):
if _params.get(_k):
_brief.append("%s=<%d字符>" % (_k, len(str(_params.get(_k)))))
_summary = ''.join(_brief) if _brief else '(无参数)'
yield json.dumps({"content": "⚠️ 需要你确认执行工具:**" + str(_tool) + "**\n参数" + _summary[:300] + "\n请回复「确认」执行、「全部确认」本会话不再询问或「取消」放弃。"}, ensure_ascii=False) + '\n'
elif t == 'error':
yield json.dumps({"error": data.get('message', '')}, ensure_ascii=False) + '\n'
else:

View File

@ -80,8 +80,19 @@ if action == 'send_message':
elif t == 'confirm':
_tool = data.get('tool', '')
_params = data.get('params', {}) or {}
_cmd = _params.get('command', '') if isinstance(_params, dict) else ''
yield json.dumps({"content": "⚠️ 需要你确认执行命令:`" + str(_cmd)[:120] + "`\n请回复「确认」执行、「全部确认」本会话不再询问或「取消」放弃。"}, ensure_ascii=False) + '\n'
# 确认框摘要2026-09-05 修复,同 agent_chat.dspy不再只显示 command 字段
_brief = []
if isinstance(_params, dict):
for _k in ('command', 'url', 'model_name', 'use_last_extract', 'overrides', 'task_ref'):
if _k in _params and str(_params.get(_k) or '') != '':
_v = _params.get(_k)
_vs = _v if isinstance(_v, str) else json.dumps(_v, ensure_ascii=False)
_brief.append("%s=%s" % (_k, _vs[:80]))
for _k in ('spec', 'doc_text'):
if _params.get(_k):
_brief.append("%s=<%d字符>" % (_k, len(str(_params.get(_k)))))
_summary = ''.join(_brief) if _brief else '(无参数)'
yield json.dumps({"content": "⚠️ 需要你确认执行工具:**" + str(_tool) + "**\n参数" + _summary[:300] + "\n请回复「确认」执行、「全部确认」本会话不再询问或「取消」放弃。"}, ensure_ascii=False) + '\n'
elif t == 'error':
yield json.dumps({"error": data.get('message', '')}, ensure_ascii=False) + '\n'
else: