From 84104da111534bf64eab6d29b865c4158d5d996a Mon Sep 17 00:00:00 2001 From: xiaohei Date: Thu, 7 May 2026 09:56:16 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E6=97=B6=20/v1/models=20=E7=A9=BA=E5=88=97=E8=A1=A8=20panic=20?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=20500?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - heicode/controller/model.go: Anthropic ListModels case 对空模型列表 做边界保护,避免 index out of range panic -> HTTP 500 - cc-haha/src/server/services/providerService.ts: 模型探活不再发送 anthropic-version header,统一走 OpenAI 兼容路径返回 {data:[]} - heicode/controller/heicode_oauth.go: OAuth 未登录重定向指向 /sign-in - heicode/deploy/nginx/heicode-gateway.conf: 3000 端口 server block 补充 /models -> /v1/models 兼容路由 --- cc-haha/src/server/services/providerService.ts | 5 ++++- heicode/controller/heicode_oauth.go | 2 +- heicode/controller/model.go | 9 +++++++-- heicode/deploy/nginx/heicode-gateway.conf | 6 ++++++ 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/cc-haha/src/server/services/providerService.ts b/cc-haha/src/server/services/providerService.ts index 125b86fb..5f582f3e 100644 --- a/cc-haha/src/server/services/providerService.ts +++ b/cc-haha/src/server/services/providerService.ts @@ -431,7 +431,10 @@ export class ProviderService { if (input.apiKey) { headers['Authorization'] = `Bearer ${input.apiKey}` headers['x-api-key'] = input.apiKey - headers['anthropic-version'] = '2023-06-01' + // Note: anthropic-version is intentionally NOT set here. + // Model discovery always uses the OpenAI-compatible format (GET /v1/models → {data:[...]}). + // Sending anthropic-version causes relay servers (NewAPI / heicode Manager) to branch + // into the Anthropic-specific response handler, which panics on an empty model list. } const candidates = [`${base}/v1/models`, `${base}/models`] diff --git a/heicode/controller/heicode_oauth.go b/heicode/controller/heicode_oauth.go index c6e1bd18..b3a30d32 100644 --- a/heicode/controller/heicode_oauth.go +++ b/heicode/controller/heicode_oauth.go @@ -152,7 +152,7 @@ func renderHeicodeLoginRequired(c *gin.Context, state, redirectURI, providerID s url.QueryEscape(redirectURI), url.QueryEscape(providerID), ) - loginURL := "/login" + loginURL := "/sign-in?redirect=" + url.QueryEscape(authorizeURL) body := fmt.Sprintf(` diff --git a/heicode/controller/model.go b/heicode/controller/model.go index 0145efd1..1cd70e68 100644 --- a/heicode/controller/model.go +++ b/heicode/controller/model.go @@ -211,11 +211,16 @@ func ListModels(c *gin.Context, modelType int) { Type: "model", } } + var firstID, lastID interface{} + if len(useranthropicModels) > 0 { + firstID = useranthropicModels[0].ID + lastID = useranthropicModels[len(useranthropicModels)-1].ID + } c.JSON(200, gin.H{ "data": useranthropicModels, - "first_id": useranthropicModels[0].ID, + "first_id": firstID, "has_more": false, - "last_id": useranthropicModels[len(useranthropicModels)-1].ID, + "last_id": lastID, }) case constant.ChannelTypeGemini: userGeminiModels := make([]dto.GeminiModel, len(userOpenAiModels)) diff --git a/heicode/deploy/nginx/heicode-gateway.conf b/heicode/deploy/nginx/heicode-gateway.conf index 0b071498..780c0141 100644 --- a/heicode/deploy/nginx/heicode-gateway.conf +++ b/heicode/deploy/nginx/heicode-gateway.conf @@ -100,6 +100,12 @@ server { proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; + # Compatibility for older HeiCode desktop builds that probe /models + # instead of the OpenAI-compatible /v1/models endpoint. + location = /models { + proxy_pass http://newapi_relay/v1/models; + } + # Only relay-compatible API paths are sent to NewAPI. NewAPI admin/backend # pages are intentionally not proxied through the public Manager gateway. location = /v1/models {