Skip to content

Commit 7b6dcaf

Browse files
committed
fix: 修正服务器架构 - AI代理和版本检查路由改到 testpilot.xinzaoai.com
1 parent 1d5c121 commit 7b6dcaf

3 files changed

Lines changed: 48 additions & 3 deletions

File tree

extension/src/engineManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ export class EngineManager {
265265

266266
/** 版本检查:低于最低版本强制提示,低于最新版本弱提示 */
267267
private async _checkVersion(): Promise<void> {
268-
const VERSION_URL = "https://xinzaoai.com/api/version/check";
268+
const VERSION_URL = "https://testpilot.xinzaoai.com/api/v1/version/check";
269269
const currentVersion = vscode.extensions.getExtension("wenzhouxinzao.testpilot-ai")
270270
?.packageJSON?.version as string | undefined;
271271
if (!currentVersion) { return; }

src/api/routes.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

src/core/ai_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ def _call_chat(
298298

299299

300300
# 代理服务器地址和鉴权 secret(后端随时可切换模型,引擎无需更新)
301-
_PROXY_URL = "https://xinzaoai.com/api/ai/proxy"
301+
_PROXY_URL = "https://testpilot.xinzaoai.com/api/v1/ai/proxy"
302302
_ENGINE_SECRET = "testpilot-engine-secret-2026"
303303

304304

@@ -383,12 +383,12 @@ def _call(
383383
"messages": messages,
384384
"reasoning_effort": reasoning_effort or self._reasoning_effort,
385385
"max_tokens": max_tokens or self._max_tokens,
386+
"_secret": _ENGINE_SECRET,
386387
}
387388
try:
388389
resp = self._http.post(
389390
_PROXY_URL,
390391
json=payload,
391-
headers={"X-Engine-Secret": _ENGINE_SECRET},
392392
timeout=timeout or 120.0,
393393
)
394394
resp.raise_for_status()

0 commit comments

Comments
 (0)