diff --git a/src/openclaw_extra/web/app.py b/src/openclaw_extra/web/app.py index dd3ae41..50c6fd2 100644 --- a/src/openclaw_extra/web/app.py +++ b/src/openclaw_extra/web/app.py @@ -46,6 +46,74 @@ def get_client() -> OpenClawClient: # ============== API 路由 ============== +@app.get("/api/config") +async def api_config(): + """获取 OpenClaw 配置信息""" + try: + client = get_client() + config = client.get_config() + + # 提取关键信息 + agents_config = config.get("agents", {}) + defaults = agents_config.get("defaults", {}) + + # 查找所有智能体目录 + agents_list = agents_config.get("list", []) + agent_dirs = [] + for agent in agents_list: + if agent.get("agentDir"): + agent_dirs.append(agent.get("agentDir")) + + return { + "config_path": config.get("_path", "/home/openclaw/.openclaw/openclaw.json"), + "workspace_root": defaults.get("workspace", "/home/openclaw/.openclaw/workspace"), + "agents_dir": "/home/openclaw/.openclaw", # OpenClaw 根目录 + "agents_count": len(agents_list), + "agent_dirs": agent_dirs, + } + except Exception as e: + raise HTTPException(status_code=500, detail=str(e)) + + +@app.post("/api/rescan") +async def api_rescan(): + """重新扫描智能体目录""" + try: + import subprocess + import os + + # 调用 openclaw gateway 命令重新加载配置 + result = subprocess.run( + ["openclaw", "gateway", "call", "agents.list", "--json"], + capture_output=True, + text=True, + timeout=10, + ) + + if result.returncode != 0: + raise Exception(f"扫描失败: {result.stderr}") + + # 解析结果 + import json + output_lines = result.stdout.strip().split("\n") + json_line = [l for l in output_lines if l.startswith("{") or l.startswith("[")] + + if json_line: + data = json.loads(json_line[-1]) + agents = data.get("agents", []) + + return { + "success": True, + "agents_count": len(agents), + "message": f"扫描完成,找到 {len(agents)} 个智能体", + } + + + return {"success": True, "agents_count": 0, "message": "扫描完成"} + except Exception as e: + raise HTTPException(status_code=500, detail=str(e)) + + @app.get("/api/health") async def api_health(): """健康检查""" diff --git a/src/openclaw_extra/web/static/index.html b/src/openclaw_extra/web/static/index.html index 930ff15..7bdb01c 100644 --- a/src/openclaw_extra/web/static/index.html +++ b/src/openclaw_extra/web/static/index.html @@ -18,8 +18,15 @@
智能体管理面板
+