Przeglądaj źródła

修复/tools的bug

kevin.yang 4 dni temu
rodzic
commit
28c30c9b1d

+ 104 - 10
data/registry.json

@@ -3,7 +3,6 @@
     {
       "tool_id": "image_stitcher",
       "name": "图片拼接工具",
-      "tool_slug_ids": [],
       "category": "cv",
       "description": "将多张图片按指定方向(水平/垂直/网格)拼接成一张大图。支持间距设置、背景色填充和统一缩放模式。输入输出均为 Base64 编码的 PNG 图片。",
       "input_schema": {
@@ -84,12 +83,14 @@
         "type": "object"
       },
       "stream_support": false,
-      "status": "active"
+      "status": "active",
+      "backend_runtime": "local",
+      "group_ids": [],
+      "tool_slug_ids": []
     },
     {
       "tool_id": "liblibai_controlnet",
       "name": "LibLib ControlNet 图生图",
-      "tool_slug_ids": [],
       "category": "cv",
       "description": "基于 LibLib AI 开放 API 的 ControlNet Canny 图生图工具,支持通过边缘检测控制图像生成",
       "input_schema": {
@@ -180,12 +181,14 @@
         }
       },
       "stream_support": false,
-      "status": "active"
+      "status": "active",
+      "backend_runtime": "local",
+      "group_ids": [],
+      "tool_slug_ids": []
     },
     {
       "tool_id": "launch_comfy_env",
       "name": "Launch ComfyUI Environment",
-      "tool_slug_ids": ["comfyui"],
       "category": "ai",
       "description": "启动 RunComfy 云端机器并等待就绪。返回 server_id 用于后续 ComfyUI workflow 执行。需要环境变量 RUNCOMFY_USER_ID 和 API_TOKEN。",
       "input_schema": {
@@ -243,12 +246,18 @@
         ]
       },
       "stream_support": false,
-      "status": "active"
+      "status": "active",
+      "backend_runtime": "local",
+      "group_ids": [
+        "runcomfy_lifecycle"
+      ],
+      "tool_slug_ids": [
+        "comfyui"
+      ]
     },
     {
       "tool_id": "runcomfy_workflow_executor",
       "name": "RunComfy Workflow Executor",
-      "tool_slug_ids": ["comfyui"],
       "category": "image_generation",
       "description": "在已就绪的 RunComfy 机器上提交 ComfyUI 工作流,上传输入文件,监听执行状态,下载结果图片(不启动/关闭机器)",
       "input_schema": {
@@ -319,12 +328,18 @@
         }
       },
       "stream_support": false,
-      "status": "active"
+      "status": "active",
+      "backend_runtime": "local",
+      "group_ids": [
+        "runcomfy_lifecycle"
+      ],
+      "tool_slug_ids": [
+        "comfyui"
+      ]
     },
     {
       "tool_id": "runcomfy_stop_env",
       "name": "RunComfy Stop Service",
-      "tool_slug_ids": ["comfyui"],
       "category": "cloud",
       "description": "Stop and delete RunComfy server instances to release resources. Works with launch_comfy_env for complete lifecycle management.",
       "input_schema": {
@@ -357,7 +372,86 @@
         }
       },
       "stream_support": false,
-      "status": "active"
+      "status": "active",
+      "backend_runtime": "local",
+      "group_ids": [
+        "runcomfy_lifecycle"
+      ],
+      "tool_slug_ids": [
+        "comfyui"
+      ]
+    },
+    {
+      "tool_id": "ji_meng_add_task",
+      "name": "即梦-创建任务",
+      "category": "cv",
+      "description": "提交异步任务到上游(POST 转发 JI_MENG_API_BASE + add_task 路径)。",
+      "input_schema": {
+        "type": "object",
+        "properties": {
+          "prompt": {
+            "type": "string",
+            "description": "任务描述 / 提示词"
+          },
+          "extra": {
+            "type": "object",
+            "description": "可选,合并进上游 JSON body"
+          }
+        },
+        "required": [
+          "prompt"
+        ]
+      },
+      "output_schema": {
+        "type": "object",
+        "properties": {
+          "task_id": {
+            "type": "string"
+          },
+          "status": {
+            "type": "string"
+          }
+        }
+      },
+      "stream_support": false,
+      "status": "active",
+      "backend_runtime": "local",
+      "group_ids": [],
+      "tool_slug_ids": []
+    },
+    {
+      "tool_id": "ji_meng_query_task",
+      "name": "即梦-查询任务",
+      "category": "cv",
+      "description": "按 task_id 查询上游任务状态与结果(POST 转发 query_task 路径)。",
+      "input_schema": {
+        "type": "object",
+        "properties": {
+          "task_id": {
+            "type": "string",
+            "description": "创建任务返回的任务 ID"
+          }
+        },
+        "required": [
+          "task_id"
+        ]
+      },
+      "output_schema": {
+        "type": "object",
+        "properties": {
+          "task_id": {
+            "type": "string"
+          },
+          "status": {
+            "type": "string"
+          }
+        }
+      },
+      "stream_support": false,
+      "status": "active",
+      "backend_runtime": "local",
+      "group_ids": [],
+      "tool_slug_ids": []
     }
   ],
   "version": "2.0"

+ 34 - 0
data/sources.json

@@ -69,6 +69,40 @@
         "http_method": "POST",
         "internal_port": 8000
       }
+    ],
+    "ji_meng_add_task": [
+      {
+        "type": "local",
+        "host_dir": "tools/local/ji_meng",
+        "container_id": "",
+        "image": "",
+        "remote_url": "",
+        "remote_path": "",
+        "remote_api_key": "",
+        "hub_url": "",
+        "hub_tool_path": "",
+        "hub_api_key": "",
+        "endpoint_path": "/add_task",
+        "http_method": "POST",
+        "internal_port": 0
+      }
+    ],
+    "ji_meng_query_task": [
+      {
+        "type": "local",
+        "host_dir": "tools/local/ji_meng",
+        "container_id": "",
+        "image": "",
+        "remote_url": "",
+        "remote_path": "",
+        "remote_api_key": "",
+        "hub_url": "",
+        "hub_tool_path": "",
+        "hub_api_key": "",
+        "endpoint_path": "/query_task",
+        "http_method": "POST",
+        "internal_port": 0
+      }
     ]
   }
 }

+ 3 - 0
src/tool_agent/router/server.py

@@ -102,6 +102,9 @@ def create_app(router: Router, session_manager: SessionManager = None) -> FastAP
                 "output_schema": tool.output_schema,
                 "state": route.state.value if route else "stopped",
                 "port": route.port if route else None,
+                "host_dir": source.host_dir if source else None,
+                "endpoint_path": source.endpoint_path if source else None,
+                "http_method": source.http_method if source else None,
             })
 
         return {

+ 10 - 0
src/tool_agent/router/status.py

@@ -292,6 +292,16 @@ class ToolStatusManager:
                 del self._popen_refs[tool_id]
         return self._routes.get(tool_id)
 
+    def get_primary_source(self, tool_id: str) -> ToolSource | None:
+        """当前工具选用的来源(与 route.active_source 下标对应)。"""
+        route = self._routes.get(tool_id)
+        if not route or not route.sources:
+            return None
+        idx = route.active_source
+        if idx < 0 or idx >= len(route.sources):
+            return route.sources[0]
+        return route.sources[idx]
+
     def get_active_endpoint(self, tool_id: str) -> dict | None:
         """获取工具当前活跃的调用端点"""
         route = self._routes.get(tool_id)

+ 1 - 1
tools/local/ji_meng/.env.example

@@ -2,7 +2,7 @@
 # 复制为 .env 后填写:cp .env.example .env
 
 # 必填:上游服务根 URL(不要末尾 /)
-JI_MENG_API_BASE=
+JI_MENG_API_BASE=https://crawler.aiddit.com/crawler/ji_meng
 
 # 可选:Bearer Token;不需要则留空
 JI_MENG_API_KEY=

+ 4 - 6
tools/local/ji_meng/ji_meng_client.py

@@ -3,7 +3,7 @@
 from __future__ import annotations
 
 import os
-from typing import Any
+from typing import Any, Literal
 
 import requests
 from dotenv import load_dotenv
@@ -28,11 +28,9 @@ class JiMengClient:
             h["Authorization"] = f"Bearer {self.api_key}"
         return h
 
-    def submit_task(self, prompt: str, extra: dict[str, Any] | None = None) -> dict[str, Any]:
-        url: str = f"{self.base}{self.add_path if self.add_path.startswith('/') else '/' + self.add_path}"
-        body: dict[str, Any] = {"task_type": "image", "prompt": prompt}
-        if extra:
-            body.update(extra)
+    def submit_task(self, task_type: Literal['image', 'video'], prompt: str) -> dict[str, Any]:
+        url = f"{self.base}{self.add_path if self.add_path.startswith('/') else '/' + self.add_path}"
+        body: dict[str, Any] = {"task_type": task_type, "prompt": prompt}
         resp = requests.post(url, json=body, headers=self._headers(), timeout=120)
         resp.raise_for_status()
         return resp.json()

+ 3 - 2
tools/local/ji_meng/main.py

@@ -16,6 +16,7 @@
 from __future__ import annotations
 
 import argparse
+from typing import Literal
 
 import uvicorn
 from fastapi import FastAPI, HTTPException
@@ -27,8 +28,8 @@ app = FastAPI(title="Ji Meng Task API")
 
 
 class AddTaskRequest(BaseModel):
+    task_type: Literal['image', 'video'] = Field(default=..., description="任务类型")
     prompt: str = Field(..., description="任务描述 / 提示词")
-    extra: dict | None = Field(default=None, description="可选,合并进提交给上游的 JSON body")
 
 
 class QueryTaskRequest(BaseModel):
@@ -44,7 +45,7 @@ def health() -> dict:
 def add_task(req: AddTaskRequest) -> dict:
     try:
         client = JiMengClient()
-        return client.submit_task(prompt=req.prompt, extra=req.extra)
+        return client.submit_task(task_type=req.task_type, prompt=req.prompt)
     except ValueError as e:
         raise HTTPException(status_code=503, detail=str(e)) from e
     except Exception as e: