@@ -2833,4 +2833,49 @@ async def device_health_check(req: dict = None) -> dict:
28332833 offline = _device_pool .check_health (req .get ("timeout" , 60 ))
28342834 return {"offline_count" : len (offline ), "offline_devices" : offline }
28352835
2836+ # ── 版本检查(插件启动时调用)──────────────────────────────────────
2837+
2838+ @router .get ("/version/check" , tags = ["系统" ])
2839+ async def version_check () -> dict :
2840+ """返回最新版本和最低支持版本,插件据此决定是否强制更新。"""
2841+ return {
2842+ "latest" : "1.5.4" ,
2843+ "minimum" : "1.5.0" ,
2844+ "model" : "doubao-seed-1-8-251228" ,
2845+ "changelog" : "AI 全代理模式,引擎无需配置 API Key" ,
2846+ }
2847+
2848+ # ── AI 代理(本地 exe 无 API Key 时通过此路由调豆包)──────────────────
2849+
2850+ @router .post ("/ai/proxy" , tags = ["系统" ])
2851+ async def ai_proxy (req : dict ) -> dict :
2852+ """代理调用豆包 AI(用于本地 exe 无 API Key 的场景)。
2853+
2854+ 引擎校验 X-Engine-Secret header,通过后转发请求到方舟平台,
2855+ 返回标准 OpenAI Chat Completions 格式响应。
2856+ """
2857+ import os
2858+ from fastapi import Request
2859+ secret = req .get ("_secret" , "" )
2860+ expected = os .environ .get ("TP_ENGINE_SECRET" , "testpilot-engine-secret-2026" )
2861+ if secret != expected :
2862+ raise HTTPException (status_code = 403 , detail = "无效的引擎凭证" )
2863+
2864+ if ai_client is None :
2865+ raise HTTPException (status_code = 503 , detail = "AI 服务未配置,请联系管理员" )
2866+
2867+ messages = req .get ("messages" , [])
2868+ reasoning = req .get ("reasoning_effort" , "medium" )
2869+ max_tokens = req .get ("max_tokens" , 65535 )
2870+ if not messages :
2871+ raise HTTPException (status_code = 400 , detail = "messages 不能为空" )
2872+
2873+ try :
2874+ result = ai_client ._call_chat (messages , reasoning , max_tokens = max_tokens )
2875+ return {
2876+ "choices" : [{"message" : {"content" : result }, "finish_reason" : "stop" }],
2877+ }
2878+ except Exception as e :
2879+ raise HTTPException (status_code = 502 , detail = f"AI 调用失败: { e } " )
2880+
28362881 return router
0 commit comments