渠道: Base URL 智能识别前缀/完整端点 + API 格式垂直堆叠

- upstreamURL 按内容智能拼接: 完整端点直接用 / 含 /v1 只拼资源路径 / 纯域名拼全路径
- resolveBaseURL 不再去 /v1, 交网关识别
- 渠道表 API 格式改垂直堆叠, 显示短标识 chat/completions / responses / messages
- 前端 Base URL 提示支持前缀或完整端点

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Sakurasan
2026-08-16 00:08:52 +08:00
co-authored by Claude
parent 512e46664c
commit 8d9940ad5a
4 changed files with 25 additions and 12 deletions
+5 -4
View File
@@ -33,7 +33,8 @@ func (h *Handler) AdminChannels(c *gin.Context) {
masked = "****"
}
out = append(out, gin.H{
"id": ch.ID, "name": ch.Name, "provider": ch.Provider, "formats": ch.FormatsEffective(), "base_url": ch.BaseURL,
"id": ch.ID, "name": ch.Name, "provider": ch.Provider, "formats": ch.FormatsEffective(),
"base_url": ch.BaseURL,
"api_key_masked": masked, "weight": ch.Weight, "priority": ch.Priority,
"timeout_ms": ch.TimeoutMS, "max_concurrency": ch.MaxConcurrency,
"health_status": ch.HealthStatus, "enabled": ch.Enabled,
@@ -47,7 +48,7 @@ type channelBody struct {
Name string `json:"name" binding:"required,min=1,max=64"`
Provider string `json:"provider"` // 可选:为空时按 formats 推断(兼容旧数据)
Formats []string `json:"formats"` // 原生支持的协议 chat|responses|messages(主配置)
BaseURL string `json:"base_url"` // 可选:为空时按供应商默认(openai/anthropic)
BaseURL string `json:"base_url"` // 可选:留空按供应商默认;支持前缀或完整端点
APIKey string `json:"api_key"`
Weight *int `json:"weight"`
Priority *int `json:"priority"`
@@ -56,7 +57,7 @@ type channelBody struct {
Enabled *bool `json:"enabled"`
}
// resolveBaseURL 渠道 base_url:留空按供应商默认;兼容用户填完整地址(含 /v1)。
// resolveBaseURL 渠道 base_url:留空按供应商默认;网关按内容智能识别前缀/完整端点。
func resolveBaseURL(provider, raw string) (string, error) {
base := strings.TrimRight(raw, "/")
if base == "" {
@@ -70,7 +71,7 @@ func resolveBaseURL(provider, raw string) (string, error) {
if base == "" {
return "", errors.New("base_url required for compatible channels")
}
return strings.TrimSuffix(base, "/v1"), nil
return base, nil
}
func validateProvider(p string) bool {
+1
View File
@@ -15,6 +15,7 @@ import (
"time"
"github.com/gin-gonic/gin"
"github.com/openteam/server/internal/channel"
"github.com/openteam/server/internal/store"
)