feat(upstream): 自定义上游支持 Vivid 协议(/v1/generate NDJSON)

- custom 上游新增 protocol 选项(openai|vivid);vivid 走
  POST /v1/generate NDJSON 流:跳过心跳空行,取末行终态,
  断流携 jobId 重连不重复扣费;参考图先 POST /v1/uploads
  拿预签名再 PUT 直传;错误码 4011/4002/4293/5001/4001 分类
- 添加上游弹窗加协议二选一;账号 meta 存 protocol 并可回显
- 附 vivid 链路单测(成功流/URL 透传/失败帧/错误码/两步上传)

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
2026-10-14 12:18:26 +08:00
co-authored by Devin
parent ae49b95e0f
commit babfc71f13
6 changed files with 513 additions and 26 deletions
@@ -6,6 +6,7 @@ import (
"strings"
"backend/internal/service"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
)
@@ -141,6 +142,7 @@ func (h *ProviderAdminHandler) ImportCustomAccount(c *gin.Context) {
APIKey string `json:"api_key"`
Models string `json:"models"`
Name string `json:"name"`
Protocol string `json:"protocol"` // openai (default) | vivid
Weight int `json:"weight"`
Concurrency int `json:"concurrency"`
ID string `json:"id"`
@@ -157,7 +159,7 @@ func (h *ProviderAdminHandler) ImportCustomAccount(c *gin.Context) {
if key == "" {
key = body.APIKey
}
item, err := h.tokens.ImportCustomAccount(c.Request.Context(), baseURL, key, body.Models, body.Name, body.Weight, body.Concurrency, body.ID)
item, err := h.tokens.ImportCustomAccount(c.Request.Context(), baseURL, key, body.Models, body.Name, body.Protocol, body.Weight, body.Concurrency, body.ID)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"detail": err.Error()})
return
@@ -395,13 +397,21 @@ func (h *ProviderAdminHandler) AccountsList(c *gin.Context) {
isFree := plan == "" || plan == "free"
switch planFilter {
case "vip":
if isFree { continue }
if isFree {
continue
}
case "free":
if !isFree { continue }
if !isFree {
continue
}
case "sub":
if !isSub { continue }
if !isSub {
continue
}
case "master":
if isFree || isSub { continue }
if isFree || isSub {
continue
}
}
}
if q != "" {