feat(M2): Web AI 控制台——工具页新增子分栏:模型/Key/设备前端可配置(app_meta 存储,key 打码回显),指令执行 + 步骤流轮询(含截图缩略)+ 回答展示;Agent 加 on_step 回调、后台线程单实例运行
This commit is contained in:
+12
-1
@@ -39,6 +39,7 @@ class Agent:
|
||||
self.tools_schema = [] # OpenAI function schema
|
||||
self._tool_exec = {} # name -> callable
|
||||
self.messages = []
|
||||
self.on_step = None # 可选回调 fn(step_dict),web 展示进度用
|
||||
|
||||
# ---------- MCP 工具桥 ----------
|
||||
async def _load_tools(self):
|
||||
@@ -93,12 +94,22 @@ class Agent:
|
||||
except Exception as e:
|
||||
return {"ok": False, "error": f"工具执行失败: {e}"}, None
|
||||
# de_screenshot:图像分离(作为 image_url 追加给模型看)
|
||||
image_b64 = None
|
||||
if name == "de_screenshot" and isinstance(data, dict) and data.get("ok"):
|
||||
img = (data.get("data") or {}).get("image") or {}
|
||||
if img.get("data"):
|
||||
text_result = {k: v for k, v in (data.get("data") or {}).items()
|
||||
if k != "image"}
|
||||
return text_result, img["data"]
|
||||
image_b64 = img["data"]
|
||||
if self.on_step:
|
||||
try:
|
||||
self.on_step({"tool": name, "args": args,
|
||||
"result": text_result if image_b64 else data,
|
||||
"image_b64": image_b64})
|
||||
except Exception:
|
||||
pass
|
||||
if image_b64:
|
||||
return text_result, image_b64
|
||||
return data, None
|
||||
|
||||
# ---------- 主循环 ----------
|
||||
|
||||
Reference in New Issue
Block a user