refactor: 替换 asyncio.get_event_loop 为 get_running_loop 并优化会话卡片

- 将多处 asyncio.get_event_loop() 替换为更安全的 asyncio.get_running_loop()
- 重构 Feishu 卡片功能,新增 build_sessions_card 方法显示所有会话
- 优化文件路径处理逻辑,支持绝对路径和相对路径
- 在健康检查接口中添加 pending_requests 计数
- 更新会话状态命令以支持卡片显示
This commit is contained in:
Yuyao Huang (Sam)
2026-03-28 14:59:33 +08:00
parent 09b63341cd
commit a3622ce26d
7 changed files with 71 additions and 89 deletions
+6 -3
View File
@@ -301,7 +301,8 @@ class FileReadTool(BaseTool):
async def _arun(self, path: str, start_line: Optional[int] = None, end_line: Optional[int] = None) -> str:
try:
file_path = _resolve_dir(path)
p = Path(path.strip())
file_path = _resolve_dir(str(p.parent)) / p.name if not p.is_absolute() else p.resolve()
if not file_path.is_file():
return json.dumps({"error": f"Not a file: {path}"}, ensure_ascii=False)
@@ -342,7 +343,8 @@ class FileWriteTool(BaseTool):
async def _arun(self, path: str, content: str, mode: Optional[str] = "overwrite") -> str:
try:
file_path = _resolve_dir(path)
p = Path(path.strip())
file_path = (_resolve_dir(str(p.parent)) / p.name) if not p.is_absolute() else p.resolve()
file_path.parent.mkdir(parents=True, exist_ok=True)
write_mode = "a" if mode == "append" else "w"
@@ -484,7 +486,8 @@ class FileSendTool(BaseTool):
async def _arun(self, path: str) -> str:
try:
file_path = _resolve_dir(path)
p = Path(path.strip())
file_path = _resolve_dir(str(p.parent)) / p.name if not p.is_absolute() else p.resolve()
if not file_path.is_file():
return json.dumps({"error": f"Not a file: {path}"}, ensure_ascii=False)