- 删除子智能体 search_workspace 工具定义、路由、formatter 与测试 - 传统/多智能体模式共用 SUB_AGENT_TOOLS,一处删除同时生效 - 老对话恢复后再调用 search_workspace 会返回 未知工具 错误 - 清理多智能体排查期间加入的 memory_debug 模块及所有调用点 (modules/memory_debug.py 删除,server/ core/ utils/ modules/sub_agent/ 中相关埋点全部移除) - 顺手删除 SubAgentActivityDialog 中 search_workspace 的历史显示文案
41 lines
1.6 KiB
Python
41 lines
1.6 KiB
Python
"""子智能体特有工具实现(read_mediafile)。
|
||
|
||
read_mediafile 直接读取项目内媒体文件并返回 base64。
|
||
(原 search_workspace 工具已移除:子智能体需要搜索时改用 run_command
|
||
执行 rg / grep / find,走主进程沙箱链路,避免进程内遍历大目录导致内存失控。)
|
||
"""
|
||
|
||
from __future__ import annotations
|
||
|
||
import base64
|
||
import mimetypes
|
||
from pathlib import Path
|
||
from typing import Any, Dict
|
||
|
||
|
||
async def handle_read_mediafile(project_path: Path, arguments: Dict[str, Any]) -> Dict[str, Any]:
|
||
"""read_mediafile 实现:直接读取项目内媒体文件并返回 base64。"""
|
||
path = arguments.get("path")
|
||
if not path:
|
||
return {"success": False, "error": "path 不能为空"}
|
||
try:
|
||
abs_path = (project_path / path).resolve()
|
||
abs_path.relative_to(project_path)
|
||
except Exception:
|
||
return {"success": False, "error": "非法路径,超出项目根目录"}
|
||
|
||
if not abs_path.exists() or not abs_path.is_file():
|
||
return {"success": False, "error": f"文件不存在: {path}"}
|
||
|
||
mime, _ = mimetypes.guess_type(str(abs_path))
|
||
if not mime or (not mime.startswith("image/") and not mime.startswith("video/")):
|
||
return {"success": False, "error": "禁止的文件类型"}
|
||
|
||
try:
|
||
data = abs_path.read_bytes()
|
||
b64 = base64.b64encode(data).decode("utf-8")
|
||
file_type = "image" if mime.startswith("image/") else "video"
|
||
return {"success": True, "path": path, "mime": mime, "type": file_type, "b64": b64}
|
||
except Exception as exc:
|
||
return {"success": False, "error": str(exc)}
|