Compare commits
13
Commits
0b31cc209e
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d911881499 | ||
|
|
2e3bb22f81 | ||
|
|
923ac79039 | ||
|
|
6d951a0d61 | ||
|
|
1f5f60e905 | ||
|
|
c6a4fcfbbc | ||
|
|
5cb428bba9 | ||
|
|
658a9cb580 | ||
|
|
3a836bf0e9 | ||
|
|
faf38e2fd3 | ||
|
|
d8257df100 | ||
|
|
cd015d370c | ||
|
|
939a98d389 |
+1
-1
@@ -27,7 +27,7 @@ OT_MASTER_KEY=change-me-master-key
|
|||||||
OT_PROXY_UPSTREAM_KEY=
|
OT_PROXY_UPSTREAM_KEY=
|
||||||
OT_PROXY_UPSTREAM_BASE_URL=https://api.openai.com
|
OT_PROXY_UPSTREAM_BASE_URL=https://api.openai.com
|
||||||
OT_PROXY_DEFAULT_MODEL=gpt-4o-mini
|
OT_PROXY_DEFAULT_MODEL=gpt-4o-mini
|
||||||
OT_PROXY_TIMEOUT=120s
|
OT_PROXY_TIMEOUT=300s
|
||||||
|
|
||||||
# 渠道健康检查
|
# 渠道健康检查
|
||||||
OT_PROXY_HEALTH_INTERVAL=60s
|
OT_PROXY_HEALTH_INTERVAL=60s
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
.PHONY: run build test tidy mock-upstream web-dev web-build reset-admin-password
|
.PHONY: run build test tidy mock-upstream web-dev web-build reset-admin-password reset-password
|
||||||
|
|
||||||
run:
|
run:
|
||||||
cd server && go run ./cmd/server
|
cd server && go run ./cmd/server
|
||||||
@@ -6,6 +6,9 @@ run:
|
|||||||
reset-admin-password:
|
reset-admin-password:
|
||||||
cd server && go run ./cmd/server reset-admin-password
|
cd server && go run ./cmd/server reset-admin-password
|
||||||
|
|
||||||
|
reset-password:
|
||||||
|
cd server && go run ./cmd/server reset-password
|
||||||
|
|
||||||
build:
|
build:
|
||||||
cd server && go build -o bin/openteam ./cmd/server
|
cd server && go build -o bin/openteam ./cmd/server
|
||||||
|
|
||||||
|
|||||||
@@ -184,7 +184,7 @@ func (h *Handler) AdminCreateChannel(c *gin.Context) {
|
|||||||
Name: req.Name, Provider: req.Provider, Formats: formats, BaseURL: baseURL,
|
Name: req.Name, Provider: req.Provider, Formats: formats, BaseURL: baseURL,
|
||||||
BaseURLs: normalizeBaseURLs(req.BaseURLs),
|
BaseURLs: normalizeBaseURLs(req.BaseURLs),
|
||||||
APIKeyEnc: enc, Weight: intOr(req.Weight, 1), Priority: intOr(req.Priority, 0),
|
APIKeyEnc: enc, Weight: intOr(req.Weight, 1), Priority: intOr(req.Priority, 0),
|
||||||
TimeoutMS: intOr(req.TimeoutMS, 120000), MaxConcurrency: intOr(req.MaxConcurrency, 16),
|
TimeoutMS: intOr(req.TimeoutMS, 300000), MaxConcurrency: intOr(req.MaxConcurrency, 16),
|
||||||
HealthStatus: store.ChannelHealthHealthy, Enabled: boolOr(req.Enabled, true),
|
HealthStatus: store.ChannelHealthHealthy, Enabled: boolOr(req.Enabled, true),
|
||||||
}
|
}
|
||||||
if err := h.a.DB.Create(&ch).Error; err != nil {
|
if err := h.a.DB.Create(&ch).Error; err != nil {
|
||||||
|
|||||||
@@ -90,8 +90,13 @@ func (h *Handler) AdminUsage(c *gin.Context) {
|
|||||||
for _, l := range logs {
|
for _, l := range logs {
|
||||||
var uname string
|
var uname string
|
||||||
h.a.DB.Model(&store.User{}).Where("id = ?", l.UserID).Pluck("username", &uname)
|
h.a.DB.Model(&store.User{}).Where("id = ?", l.UserID).Pluck("username", &uname)
|
||||||
|
var chName string
|
||||||
|
if l.ChannelID > 0 {
|
||||||
|
h.a.DB.Model(&store.Channel{}).Where("id = ?", l.ChannelID).Pluck("name", &chName)
|
||||||
|
}
|
||||||
out = append(out, gin.H{
|
out = append(out, gin.H{
|
||||||
"id": l.ID, "user": uname, "user_id": l.UserID, "model": l.ModelName, "protocol": l.Protocol,
|
"id": l.ID, "user": uname, "user_id": l.UserID, "model": l.ModelName, "protocol": l.Protocol,
|
||||||
|
"channel_id": l.ChannelID, "channel": chName,
|
||||||
"input_tokens": l.InputTokens, "output_tokens": l.OutputTokens,
|
"input_tokens": l.InputTokens, "output_tokens": l.OutputTokens,
|
||||||
"cache_read_tokens": l.CacheReadTokens, "cost": l.Cost,
|
"cache_read_tokens": l.CacheReadTokens, "cost": l.Cost,
|
||||||
"latency_ms": l.LatencyMS, "status": l.Status, "error_code": l.ErrorCode,
|
"latency_ms": l.LatencyMS, "status": l.Status, "error_code": l.ErrorCode,
|
||||||
|
|||||||
@@ -0,0 +1,176 @@
|
|||||||
|
// Package cli 命令行入口。
|
||||||
|
package cli
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/openteam/server/internal/config"
|
||||||
|
"github.com/openteam/server/internal/pkg/crypto"
|
||||||
|
"github.com/openteam/server/internal/store"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"golang.org/x/term"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
resetPwUser string
|
||||||
|
resetPwPassword string
|
||||||
|
resetPwUserID string
|
||||||
|
)
|
||||||
|
|
||||||
|
var resetPasswordCmd = &cobra.Command{
|
||||||
|
Use: "reset-password",
|
||||||
|
Short: "重置用户密码",
|
||||||
|
Long: `重置任意用户密码(管理员可重置任何用户,需在可加载配置的目录下执行)。
|
||||||
|
|
||||||
|
交互式引导(默认):
|
||||||
|
go run ./cmd/server reset-password
|
||||||
|
|
||||||
|
非交互式(用于脚本):
|
||||||
|
go run ./cmd/server reset-password --user admin --password "新密码"
|
||||||
|
go run ./cmd/server reset-password --user-id 123 --password "新密码"`,
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
runResetPassword()
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rootCmd.AddCommand(resetPasswordCmd)
|
||||||
|
resetPasswordCmd.Flags().StringVar(&resetPwUser, "user", "", "目标用户名(留空则交互选择)")
|
||||||
|
resetPasswordCmd.Flags().StringVar(&resetPwUserID, "user-id", "", "目标用户 ID(优先于 --user)")
|
||||||
|
resetPasswordCmd.Flags().StringVar(&resetPwPassword, "password", "", "新密码,至少 8 位(留空则交互输入)")
|
||||||
|
}
|
||||||
|
|
||||||
|
func runResetPassword() {
|
||||||
|
// --- 阶段 1:加载配置与数据库 ---
|
||||||
|
cfg, err := config.Load()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("加载配置失败: %v", err)
|
||||||
|
}
|
||||||
|
db, err := store.Open(cfg.DB.Driver, cfg.DB.DSN)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("连接数据库失败: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- 阶段 2:选择目标用户 ---
|
||||||
|
target := targetUser(db)
|
||||||
|
|
||||||
|
// --- 阶段 3:获取新密码 ---
|
||||||
|
var pw string
|
||||||
|
if resetPwPassword != "" {
|
||||||
|
pw = resetPwPassword
|
||||||
|
} else {
|
||||||
|
pw = promptNewPassword()
|
||||||
|
}
|
||||||
|
if pw == "" {
|
||||||
|
log.Fatalf("密码不能为空")
|
||||||
|
}
|
||||||
|
if len(pw) < 8 || len(pw) > 72 {
|
||||||
|
log.Fatalf("密码长度必须在 8 到 72 位之间")
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- 阶段 4:加密并更新 ---
|
||||||
|
hasher := crypto.NewPasswordHasher(cfg.Auth.Argon2Time, cfg.Auth.Argon2Memory, cfg.Auth.Argon2Threads, cfg.Auth.Argon2KeyLen, cfg.Auth.SaltLen)
|
||||||
|
hash, err := hasher.HashPassword(pw)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("加密密码失败: %v", err)
|
||||||
|
}
|
||||||
|
if err := db.Model(&store.User{}).Where("id = ?", target.ID).Update("password_hash", hash).Error; err != nil {
|
||||||
|
log.Fatalf("更新密码失败: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("✅ 已重置用户 %q 的密码!\n", target.Username)
|
||||||
|
}
|
||||||
|
|
||||||
|
// targetUser 根据 --user-id 或 --user 解析目标用户,否则交互选择。
|
||||||
|
func targetUser(db *gorm.DB) *store.User {
|
||||||
|
// 优先使用 --user-id
|
||||||
|
if resetPwUserID != "" {
|
||||||
|
id, err := strconv.ParseUint(resetPwUserID, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("无效的用户 ID: %v", err)
|
||||||
|
}
|
||||||
|
var u store.User
|
||||||
|
if err := db.First(&u, id).Error; err != nil {
|
||||||
|
log.Fatalf("用户 ID %d 不存在", id)
|
||||||
|
}
|
||||||
|
return &u
|
||||||
|
}
|
||||||
|
|
||||||
|
// 使用 --user
|
||||||
|
if resetPwUser != "" {
|
||||||
|
var u store.User
|
||||||
|
if err := db.Where("username = ?", resetPwUser).First(&u).Error; err != nil {
|
||||||
|
log.Fatalf("用户 %q 不存在", resetPwUser)
|
||||||
|
}
|
||||||
|
return &u
|
||||||
|
}
|
||||||
|
|
||||||
|
// 交互选择
|
||||||
|
var users []struct {
|
||||||
|
ID uint64
|
||||||
|
Username string
|
||||||
|
Role string
|
||||||
|
}
|
||||||
|
db.Model(&store.User{}).Select("id, username, role").Order("id ASC").Find(&users)
|
||||||
|
if len(users) == 0 {
|
||||||
|
log.Fatalf("系统中没有用户")
|
||||||
|
}
|
||||||
|
if len(users) == 1 {
|
||||||
|
return &store.User{ID: users[0].ID, Username: users[0].Username}
|
||||||
|
}
|
||||||
|
return selectUser(users)
|
||||||
|
}
|
||||||
|
|
||||||
|
// selectUser 交互式选择用户。
|
||||||
|
func selectUser(users []struct {
|
||||||
|
ID uint64
|
||||||
|
Username string
|
||||||
|
Role string
|
||||||
|
}) *store.User {
|
||||||
|
fmt.Println("请选择要重置密码的用户:")
|
||||||
|
for i, u := range users {
|
||||||
|
fmt.Printf(" [%d] %s (%s)\n", i+1, u.Username, u.Role)
|
||||||
|
}
|
||||||
|
fmt.Printf("请输入编号 (1-%d): ", len(users))
|
||||||
|
var n int
|
||||||
|
if _, err := fmt.Scanf("%d", &n); err != nil || n < 1 || n > len(users) {
|
||||||
|
log.Fatalf("无效输入")
|
||||||
|
}
|
||||||
|
return &store.User{ID: users[n-1].ID, Username: users[n-1].Username}
|
||||||
|
}
|
||||||
|
|
||||||
|
// promptNewPassword 交互式输入密码。
|
||||||
|
func promptNewPassword() string {
|
||||||
|
fmt.Println("请选择密码设置方式:")
|
||||||
|
fmt.Println(" [1] 手动输入密码")
|
||||||
|
fmt.Println(" [2] 自动生成随机密码(16 位,不含易混淆字符)")
|
||||||
|
fmt.Printf("请输入编号 (1-2): ")
|
||||||
|
|
||||||
|
var n int
|
||||||
|
if _, err := fmt.Scanf("%d", &n); err != nil || n < 1 || n > 2 {
|
||||||
|
log.Fatalf("无效输入,请输入 1 或 2")
|
||||||
|
}
|
||||||
|
if n == 2 {
|
||||||
|
pw, err := randomPassword(16)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("生成随机密码失败: %v", err)
|
||||||
|
}
|
||||||
|
fmt.Printf("生成的随机密码:%s\n", pw)
|
||||||
|
fmt.Println("(请立即保存,不会再次显示)")
|
||||||
|
return pw
|
||||||
|
}
|
||||||
|
|
||||||
|
// 手动输入:静默输入(不回显)
|
||||||
|
fmt.Print("请输入新密码(至少 8 位):")
|
||||||
|
raw, err := term.ReadPassword(int(os.Stdin.Fd()))
|
||||||
|
fmt.Println()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("读取密码失败: %v", err)
|
||||||
|
}
|
||||||
|
return strings.TrimSpace(string(raw))
|
||||||
|
}
|
||||||
@@ -19,7 +19,8 @@ var rootCmd = &cobra.Command{
|
|||||||
go run ./cmd/server
|
go run ./cmd/server
|
||||||
|
|
||||||
子命令:
|
子命令:
|
||||||
reset-admin-password 重置管理员密码(交互式,无参数时自动提示)`,
|
reset-admin-password 重置管理员密码(交互式,无参数时自动提示)
|
||||||
|
reset-password 重置任意用户密码`,
|
||||||
RunE: func(c *cobra.Command, args []string) error {
|
RunE: func(c *cobra.Command, args []string) error {
|
||||||
return serve()
|
return serve()
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ func serve() error {
|
|||||||
}
|
}
|
||||||
defer a.Shutdown(context.Background())
|
defer a.Shutdown(context.Background())
|
||||||
|
|
||||||
gw := proxy.NewGateway(a.DB, a.Enc, a.Usage, a.Limit, cfg.RateLimit.UserRPS, cfg.Proxy.LogRaw)
|
gw := proxy.NewGateway(a.DB, a.Enc, a.Usage, a.Limit, cfg.RateLimit.UserRPS, cfg.Proxy.LogRaw, cfg.Proxy.Timeout)
|
||||||
router := api.NewRouter(a, gw)
|
router := api.NewRouter(a, gw)
|
||||||
|
|
||||||
srv := &http.Server{
|
srv := &http.Server{
|
||||||
|
|||||||
@@ -59,14 +59,14 @@ type AuthConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ProxyConfig struct {
|
type ProxyConfig struct {
|
||||||
DefaultChannelName string // 首次启动自动创建的渠道名(如 openai)
|
DefaultChannelName string // 首次启动自动创建的渠道名(如 openai)
|
||||||
UpstreamBaseURL string // 渠道 base_url 默认值
|
UpstreamBaseURL string // 渠道 base_url 默认值
|
||||||
UpstreamKey string // 渠道上游 key 默认值
|
UpstreamKey string // 渠道上游 key 默认值
|
||||||
DefaultModel string // 渠道模型导入时使用的模型名
|
DefaultModel string // 渠道模型导入时使用的模型名
|
||||||
Timeout time.Duration
|
Timeout time.Duration
|
||||||
HealthInterval time.Duration // 渠道健康检查周期
|
HealthInterval time.Duration // 渠道健康检查周期
|
||||||
HealthFailThreshold int // 连续失败 N 次进 cooldown
|
HealthFailThreshold int // 连续失败 N 次进 cooldown
|
||||||
LogRaw bool // 记录管理员原始请求体+响应到 usage_logs(调试用,默认关)
|
LogRaw bool // 记录管理员原始请求体+响应到 usage_logs(调试用,默认关)
|
||||||
}
|
}
|
||||||
|
|
||||||
// loadDotEnv 读取 .env 并把 KEY=VALUE 注入环境变量(AutomaticEnv 自动映射 OT_ 前缀)。
|
// loadDotEnv 读取 .env 并把 KEY=VALUE 注入环境变量(AutomaticEnv 自动映射 OT_ 前缀)。
|
||||||
@@ -127,7 +127,7 @@ func Load() (*Config, error) {
|
|||||||
v.SetDefault("proxy.upstream_base_url", "https://api.openai.com")
|
v.SetDefault("proxy.upstream_base_url", "https://api.openai.com")
|
||||||
v.SetDefault("proxy.upstream_key", "")
|
v.SetDefault("proxy.upstream_key", "")
|
||||||
v.SetDefault("proxy.default_model", "gpt-4o-mini")
|
v.SetDefault("proxy.default_model", "gpt-4o-mini")
|
||||||
v.SetDefault("proxy.timeout", "120s")
|
v.SetDefault("proxy.timeout", "300s")
|
||||||
v.SetDefault("proxy.health_interval", "60s")
|
v.SetDefault("proxy.health_interval", "60s")
|
||||||
v.SetDefault("proxy.health_fail_threshold", 2)
|
v.SetDefault("proxy.health_fail_threshold", 2)
|
||||||
v.SetDefault("proxy.log_raw", false)
|
v.SetDefault("proxy.log_raw", false)
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ func contains(list []string, s string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGateway(db *gorm.DB, enc *crypto.Encryptor, rec *usage.Recorder, lim *ratelimit.Limiter, userRPS int, logRaw bool) *Gateway {
|
func NewGateway(db *gorm.DB, enc *crypto.Encryptor, rec *usage.Recorder, lim *ratelimit.Limiter, userRPS int, logRaw bool, gw_timeout time.Duration) *Gateway {
|
||||||
return &Gateway{
|
return &Gateway{
|
||||||
db: db,
|
db: db,
|
||||||
ch: channel.NewService(db, enc),
|
ch: channel.NewService(db, enc),
|
||||||
@@ -118,7 +118,7 @@ func NewGateway(db *gorm.DB, enc *crypto.Encryptor, rec *usage.Recorder, lim *ra
|
|||||||
lim: lim,
|
lim: lim,
|
||||||
userRPS: userRPS,
|
userRPS: userRPS,
|
||||||
logRaw: logRaw,
|
logRaw: logRaw,
|
||||||
hc: &http.Client{Timeout: 120 * time.Second},
|
hc: &http.Client{Timeout: gw_timeout * time.Second},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -272,10 +272,10 @@ func upstreamPath(proto string) string {
|
|||||||
|
|
||||||
// upstreamPlan 描述一次代理请求的上游访问方式。
|
// upstreamPlan 描述一次代理请求的上游访问方式。
|
||||||
type upstreamPlan struct {
|
type upstreamPlan struct {
|
||||||
proto string // 上游协议(用于分协议 base_url)
|
proto string // 上游协议(用于分协议 base_url)
|
||||||
path string // 上游路径
|
path string // 上游路径
|
||||||
body []byte // 已转换的请求体
|
body []byte // 已转换的请求体
|
||||||
lineConv func([]byte) []byte // 流式逐行转换(nil=直通)
|
lineConv func([]byte) []byte // 流式逐行转换(nil=直通)
|
||||||
bodyConv func([]byte) ([]byte, error) // 非流式响应体转换(nil=直通)
|
bodyConv func([]byte) ([]byte, error) // 非流式响应体转换(nil=直通)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package proxy
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
@@ -164,11 +163,29 @@ func upstreamURL(ch *store.Channel, proto, path string) string {
|
|||||||
return ch.UpstreamURL(proto, path)
|
return ch.UpstreamURL(proto, path)
|
||||||
}
|
}
|
||||||
|
|
||||||
// doProxy 通用代理(M5):遍历候选渠道,按需转换;可安全重试的失败自动故障转移。
|
// doProxy 通用代理(M5):加权随机选一个候选渠道;失败自动故障转移。
|
||||||
func (g *Gateway) doProxy(c *gin.Context, cands []channel.Candidate, clientProto string, body []byte, stream bool, sink *usageSink) {
|
func (g *Gateway) doProxy(c *gin.Context, cands []channel.Candidate, clientProto string, body []byte, stream bool, sink *usageSink) {
|
||||||
|
if len(cands) == 0 {
|
||||||
|
apiError(c, http.StatusBadGateway, "upstream_error", "no available channel")
|
||||||
|
g.recordError(c, nil, nil, now(), "no_available_channel")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 加权随机选择起始渠道
|
||||||
|
picked := g.ch.Pick(cands)
|
||||||
|
startIdx := 0
|
||||||
|
for i, cand := range cands {
|
||||||
|
if cand.Channel.ID == picked.ID {
|
||||||
|
startIdx = i
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var lastStatus = http.StatusBadGateway
|
var lastStatus = http.StatusBadGateway
|
||||||
var lastBody = []byte("all upstream channels failed")
|
var lastBody = []byte("all upstream channels failed")
|
||||||
for _, cand := range cands {
|
// 从选中的渠道开始遍历,到末尾后再从头遍历到选中渠道之前
|
||||||
|
for offset := 0; offset < len(cands); offset++ {
|
||||||
|
idx := (startIdx + offset) % len(cands)
|
||||||
|
cand := cands[idx]
|
||||||
ch := cand.Channel
|
ch := cand.Channel
|
||||||
plan, err := prepareUpstream(ch, clientProto, body, cand.UpstreamModel)
|
plan, err := prepareUpstream(ch, clientProto, body, cand.UpstreamModel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -218,9 +235,7 @@ func (g *Gateway) proxyOne(c *gin.Context, ch *store.Channel, plan *upstreamPlan
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(c.Request.Context(), time.Duration(ch.TimeoutMS)*time.Millisecond)
|
req, err := http.NewRequest(http.MethodPost, upstreamURL(ch, plan.proto, plan.path), bytes.NewReader(upBody))
|
||||||
defer cancel()
|
|
||||||
req, err := http.NewRequestWithContext(ctx, http.MethodPost, upstreamURL(ch, plan.proto, plan.path), bytes.NewReader(upBody))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, false, http.StatusInternalServerError, []byte("failed to build upstream request")
|
return false, false, http.StatusInternalServerError, []byte("failed to build upstream request")
|
||||||
}
|
}
|
||||||
@@ -242,9 +257,6 @@ func (g *Gateway) proxyOne(c *gin.Context, ch *store.Channel, plan *upstreamPlan
|
|||||||
start := time.Now()
|
start := time.Now()
|
||||||
resp, err := g.hc.Do(req)
|
resp, err := g.hc.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if ctx.Err() == context.DeadlineExceeded {
|
|
||||||
return false, true, http.StatusGatewayTimeout, []byte("upstream request timed out")
|
|
||||||
}
|
|
||||||
return false, true, http.StatusBadGateway, []byte("upstream request failed: " + err.Error())
|
return false, true, http.StatusBadGateway, []byte("upstream request failed: " + err.Error())
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
@@ -497,6 +509,14 @@ func (u *usageSink) push(raw json.RawMessage) {
|
|||||||
if json.Unmarshal(raw, &t) != nil {
|
if json.Unmarshal(raw, &t) != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// messages 流式最终事件(message_delta 的 usage)带 cache_* 字段,是上游的最终计费口径,
|
||||||
|
// 其中 input_tokens 仅指"非缓存输入"(与 message_start 的"总输入"语义不同)。
|
||||||
|
// 整体替换而非字段合并,避免 delta 的非缓存 input 覆盖 start 的总 input 后语义错乱
|
||||||
|
// (实际消耗由 finishUsage 按 input + cache_read + cache_creation 汇总)。
|
||||||
|
if t.CacheReadInputTokens > 0 || t.CacheCreationInputTokens > 0 {
|
||||||
|
u.us = t
|
||||||
|
return
|
||||||
|
}
|
||||||
// 零值不覆盖:不同事件携带不同字段
|
// 零值不覆盖:不同事件携带不同字段
|
||||||
if t.PromptTokens > 0 {
|
if t.PromptTokens > 0 {
|
||||||
u.us.PromptTokens = t.PromptTokens
|
u.us.PromptTokens = t.PromptTokens
|
||||||
@@ -550,7 +570,7 @@ func (g *Gateway) finishUsage(c *gin.Context, ch *store.Channel, start time.Time
|
|||||||
// message_delta 不带 usage,只能按已收发内容估算,否则记账为 0 消耗
|
// message_delta 不带 usage,只能按已收发内容估算,否则记账为 0 消耗
|
||||||
// 非流式上游必返回 usage,此处 in/out 非 0 不受影响。
|
// 非流式上游必返回 usage,此处 in/out 非 0 不受影响。
|
||||||
if status == store.UsageStatusCanceled || status == store.UsageStatusSuccess {
|
if status == store.UsageStatusCanceled || status == store.UsageStatusSuccess {
|
||||||
if in == 0 {
|
if in == 0 && cacheRead == 0 && cacheCreate == 0 {
|
||||||
if est, ok := c.Get("est_input_text"); ok {
|
if est, ok := c.Get("est_input_text"); ok {
|
||||||
if v, ok2 := est.(string); ok2 && v != "" {
|
if v, ok2 := est.(string); ok2 && v != "" {
|
||||||
in = int64(tokenizer.Count(v, mn))
|
in = int64(tokenizer.Count(v, mn))
|
||||||
@@ -568,12 +588,18 @@ func (g *Gateway) finishUsage(c *gin.Context, ch *store.Channel, start time.Time
|
|||||||
_ = g.db.Where("name = ?", mn).First(&model).Error
|
_ = g.db.Where("name = ?", mn).First(&model).Error
|
||||||
if model.ID > 0 {
|
if model.ID > 0 {
|
||||||
modelID = model.ID
|
modelID = model.ID
|
||||||
|
// 计价口径:in=非缓存输入、cacheRead=缓存读、cacheCreate=缓存写(Anthropic 语义,
|
||||||
|
// messages 流式 message_delta 的 input_tokens 即非缓存部分)。
|
||||||
|
// 缓存写按 1.25× 输入价(Anthropic 5m 口径)。
|
||||||
cost = float64(in)/1e6*model.InputPrice +
|
cost = float64(in)/1e6*model.InputPrice +
|
||||||
float64(out)/1e6*model.OutputPrice +
|
float64(out)/1e6*model.OutputPrice +
|
||||||
float64(cacheRead)/1e6*model.CacheReadPrice
|
float64(cacheRead)/1e6*model.CacheReadPrice +
|
||||||
|
float64(cacheCreate)/1e6*model.InputPrice*1.25
|
||||||
} else {
|
} else {
|
||||||
cost = float64(in)/1e6*0.15 + float64(out)/1e6*0.60 // 无定价模型时按示例价
|
cost = float64(in+cacheRead+cacheCreate)/1e6*0.15 + float64(out)/1e6*0.60 // 无定价模型时按示例价
|
||||||
}
|
}
|
||||||
|
// 落库的 input_tokens 存输入总量(含缓存读/写),与上游 message_start 口径一致,便于对账展示。
|
||||||
|
in += cacheRead + cacheCreate
|
||||||
|
|
||||||
proto, _ := c.Get("protocol")
|
proto, _ := c.Get("protocol")
|
||||||
p, _ := proto.(string)
|
p, _ := proto.(string)
|
||||||
|
|||||||
@@ -46,3 +46,56 @@ func TestSSEDataPayloadSpacedAndMultiLine(t *testing.T) {
|
|||||||
t.Fatalf("multiline block: got %q, want yo", got)
|
t.Fatalf("multiline block: got %q, want yo", got)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 复现线上 qwen(dashscope)messages 流式缓存场景:
|
||||||
|
// message_start.usage.input_tokens 是总输入,message_delta.usage.input_tokens 是非缓存输入
|
||||||
|
// 且带 cache_read/cache_creation,是最终计费口径。合并后:
|
||||||
|
// in(落库)=input+cache_read+cache_creation,计价 in 只算非缓存部分。
|
||||||
|
// 此前 delta 的 input 覆盖 start 的 input 导致总输入丢失(31790 → 8)。
|
||||||
|
func TestUsageSinkMessageDeltaAuthoritative(t *testing.T) {
|
||||||
|
sink := &usageSink{}
|
||||||
|
// message_start:总输入 31790
|
||||||
|
start := json.RawMessage(`{"input_tokens":31790,"output_tokens":0}`)
|
||||||
|
sink.push(start)
|
||||||
|
if got := sink.us.InputTokens; got != 31790 {
|
||||||
|
t.Fatalf("after start: input=%d, want 31790", got)
|
||||||
|
}
|
||||||
|
// message_delta:非缓存输入 8 + 缓存写 33229(最终口径,整体替换)
|
||||||
|
delta := json.RawMessage(`{"output_tokens":8,"cache_creation_input_tokens":33229,"input_tokens":8,"cache_read_input_tokens":0}`)
|
||||||
|
sink.push(delta)
|
||||||
|
s := sink.Shape()
|
||||||
|
if s.InputTokens != 8 || s.CacheCreationInputTokens != 33229 || s.OutputTokens != 8 {
|
||||||
|
t.Fatalf("after delta: %+v, want input=8 cache_create=33229 output=8", s)
|
||||||
|
}
|
||||||
|
// finishUsage 口径:落库 input = 8 + 0 + 33229 = 33237(总量),计价 in=8、cacheCreate=33229
|
||||||
|
in := s.InputTokens + s.CacheReadInputTokens + s.CacheCreationInputTokens
|
||||||
|
if in != 33237 {
|
||||||
|
t.Fatalf("total input=%d, want 33237", in)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 缓存命中场景(id=55):delta input=76 非缓存 + cache_read=33229 + cache_creation=17。
|
||||||
|
func TestUsageSinkCacheHitMerge(t *testing.T) {
|
||||||
|
sink := &usageSink{}
|
||||||
|
sink.push(json.RawMessage(`{"input_tokens":31862,"output_tokens":0}`))
|
||||||
|
sink.push(json.RawMessage(`{"output_tokens":32,"cache_creation_input_tokens":17,"input_tokens":76,"cache_read_input_tokens":33229}`))
|
||||||
|
s := sink.Shape()
|
||||||
|
total := s.InputTokens + s.CacheReadInputTokens + s.CacheCreationInputTokens
|
||||||
|
if total != 33322 {
|
||||||
|
t.Fatalf("total input=%d, want 33322 (76+33229+17)", total)
|
||||||
|
}
|
||||||
|
if s.OutputTokens != 32 {
|
||||||
|
t.Fatalf("output=%d, want 32", s.OutputTokens)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// OpenAI chat 末块(无 cache 字段)仍走零值不覆盖合并,不受整体替换影响。
|
||||||
|
func TestUsageSinkChatLastChunkStillMerges(t *testing.T) {
|
||||||
|
sink := &usageSink{}
|
||||||
|
sink.push(json.RawMessage(`{"prompt_tokens":65,"completion_tokens":0}`))
|
||||||
|
sink.push(json.RawMessage(`{"prompt_tokens":65,"completion_tokens":82}`))
|
||||||
|
s := sink.Shape()
|
||||||
|
if s.PromptTokens != 65 || s.CompletionTokens != 82 {
|
||||||
|
t.Fatalf("chat merge broken: %+v", s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package store
|
package store
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@@ -11,6 +12,12 @@ import (
|
|||||||
gormlogger "gorm.io/gorm/logger"
|
gormlogger "gorm.io/gorm/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// schemaVersion 当前 schema 版本。struct 变更(加列/改列/删列)时递增,
|
||||||
|
// 触发一次 AutoMigrate 并把新版本写入库(SQLite 用 PRAGMA user_version)。
|
||||||
|
// AutoMigrate 对已有表的列判定不收敛(每次都重建表:CREATE __temp + INSERT SELECT + DROP),
|
||||||
|
// 大表上一次重建数十秒且每次重启重演,所以之后版本未变就直接跳过。
|
||||||
|
const schemaVersion = 2
|
||||||
|
|
||||||
// Open 打开数据库连接并自动迁移。
|
// Open 打开数据库连接并自动迁移。
|
||||||
// 开发默认 SQLite(dsn 支持 file:...?_journal_mode=WAL),生产可切 postgres。
|
// 开发默认 SQLite(dsn 支持 file:...?_journal_mode=WAL),生产可切 postgres。
|
||||||
func Open(driver, dsn string) (*gorm.DB, error) {
|
func Open(driver, dsn string) (*gorm.DB, error) {
|
||||||
@@ -33,13 +40,35 @@ func Open(driver, dsn string) (*gorm.DB, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if driver != "postgres" && currentSQLiteVersion(db) >= schemaVersion {
|
||||||
|
log.Printf("store: connected driver=%s (schema up-to-date v%d, skip migrate)", driver, schemaVersion)
|
||||||
|
return db, nil
|
||||||
|
}
|
||||||
|
|
||||||
if err := db.AutoMigrate(AllModels()...); err != nil {
|
if err := db.AutoMigrate(AllModels()...); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
log.Printf("store: connected driver=%s (migrated)", driver)
|
if driver != "postgres" {
|
||||||
|
setSQLiteVersion(db, schemaVersion)
|
||||||
|
}
|
||||||
|
log.Printf("store: connected driver=%s (migrated, schema v%d)", driver, schemaVersion)
|
||||||
|
// 将已有渠道的超时时间从 120000ms 更新为 300000ms(幂等操作)
|
||||||
|
db.Model(&Channel{}).Where("timeout_ms = ?", 120000).Update("timeout_ms", 300000)
|
||||||
return db, nil
|
return db, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// currentSQLiteVersion 读取 PRAGMA user_version。
|
||||||
|
func currentSQLiteVersion(db *gorm.DB) int {
|
||||||
|
var v int
|
||||||
|
db.Raw("PRAGMA user_version").Scan(&v)
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// setSQLiteVersion 写入 PRAGMA user_version。
|
||||||
|
func setSQLiteVersion(db *gorm.DB, v int) {
|
||||||
|
db.Exec(fmt.Sprintf("PRAGMA user_version = %d", v))
|
||||||
|
}
|
||||||
|
|
||||||
// sqliteDir 提取 SQLite DSN 中的目录部分(忽略 file: 前缀与查询参数)。
|
// sqliteDir 提取 SQLite DSN 中的目录部分(忽略 file: 前缀与查询参数)。
|
||||||
func sqliteDir(dsn string) string {
|
func sqliteDir(dsn string) string {
|
||||||
d := dsn
|
d := dsn
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ type Channel struct {
|
|||||||
APIKeyEnc string `gorm:"size:1024;not null" json:"-"` // AES-GCM 密文
|
APIKeyEnc string `gorm:"size:1024;not null" json:"-"` // AES-GCM 密文
|
||||||
Weight int `gorm:"not null;default:1" json:"weight"`
|
Weight int `gorm:"not null;default:1" json:"weight"`
|
||||||
Priority int `gorm:"not null;default:0" json:"priority"` // 数值小优先
|
Priority int `gorm:"not null;default:0" json:"priority"` // 数值小优先
|
||||||
TimeoutMS int `gorm:"not null;default:120000" json:"timeout_ms"`
|
TimeoutMS int `gorm:"not null;default:300000" json:"timeout_ms"`
|
||||||
MaxConcurrency int `gorm:"not null;default:16" json:"max_concurrency"`
|
MaxConcurrency int `gorm:"not null;default:16" json:"max_concurrency"`
|
||||||
HealthStatus string `gorm:"size:16;not null;default:healthy" json:"health_status"`
|
HealthStatus string `gorm:"size:16;not null;default:healthy" json:"health_status"`
|
||||||
Enabled bool `gorm:"not null;default:true" json:"enabled"`
|
Enabled bool `gorm:"not null;default:true" json:"enabled"`
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ async function logout() {
|
|||||||
</div>
|
</div>
|
||||||
</aside>
|
</aside>
|
||||||
|
|
||||||
<div class="flex min-h-[100dvh] flex-1 flex-col md:ml-56">
|
<div class="flex min-h-[100dvh] min-w-0 flex-1 flex-col md:ml-56">
|
||||||
<header class="flex h-14 items-center justify-between gap-2 border-b border-edge px-4 md:px-6">
|
<header class="flex h-14 items-center justify-between gap-2 border-b border-edge px-4 md:px-6">
|
||||||
<div class="flex min-w-0 items-center gap-2">
|
<div class="flex min-w-0 items-center gap-2">
|
||||||
<button
|
<button
|
||||||
@@ -142,7 +142,7 @@ async function logout() {
|
|||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<main class="flex-1 px-4 py-6 md:px-6">
|
<main class="min-w-0 flex-1 px-4 py-6 md:px-6">
|
||||||
<router-view />
|
<router-view />
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -82,6 +82,8 @@ export interface UsageLog {
|
|||||||
request_id: string
|
request_id: string
|
||||||
model: string
|
model: string
|
||||||
protocol: string
|
protocol: string
|
||||||
|
channel_id?: number
|
||||||
|
channel?: string
|
||||||
input_tokens: number
|
input_tokens: number
|
||||||
output_tokens: number
|
output_tokens: number
|
||||||
cache_read_tokens: number
|
cache_read_tokens: number
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ const form = reactive({
|
|||||||
api_key: '',
|
api_key: '',
|
||||||
weight: 1,
|
weight: 1,
|
||||||
priority: 0,
|
priority: 0,
|
||||||
timeout_ms: 120000,
|
timeout_ms: 300000,
|
||||||
max_concurrency: 16,
|
max_concurrency: 16,
|
||||||
enabled: true,
|
enabled: true,
|
||||||
})
|
})
|
||||||
@@ -51,7 +51,7 @@ function openCreate() {
|
|||||||
name: '', formats: ['chat'], base_url: '',
|
name: '', formats: ['chat'], base_url: '',
|
||||||
base_urls: { chat: '', responses: '', messages: '' },
|
base_urls: { chat: '', responses: '', messages: '' },
|
||||||
api_key: '',
|
api_key: '',
|
||||||
weight: 1, priority: 0, timeout_ms: 120000, max_concurrency: 16, enabled: true,
|
weight: 1, priority: 0, timeout_ms: 300000, max_concurrency: 16, enabled: true,
|
||||||
})
|
})
|
||||||
editOpen.value = true
|
editOpen.value = true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ onMounted(load)
|
|||||||
<div class="flex items-start justify-between gap-2">
|
<div class="flex items-start justify-between gap-2">
|
||||||
<div class="min-w-0">
|
<div class="min-w-0">
|
||||||
<p class="truncate font-mono text-sm text-ink">{{ l.model }}</p>
|
<p class="truncate font-mono text-sm text-ink">{{ l.model }}</p>
|
||||||
<p class="mt-0.5 truncate text-xs text-muted">{{ l.user }}</p>
|
<p class="mt-0.5 truncate text-xs text-muted">{{ l.channel }} · {{ l.user }}</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex shrink-0 flex-col items-end gap-1">
|
<div class="flex shrink-0 flex-col items-end gap-1">
|
||||||
<Badge :variant="l.status === 'success' ? 'ok' : l.status === 'canceled' ? 'neutral' : 'err'">{{ l.status }}</Badge>
|
<Badge :variant="l.status === 'success' ? 'ok' : l.status === 'canceled' ? 'neutral' : 'err'">{{ l.status }}</Badge>
|
||||||
@@ -165,6 +165,7 @@ onMounted(load)
|
|||||||
<tr class="border-b border-edge text-left text-xs text-muted">
|
<tr class="border-b border-edge text-left text-xs text-muted">
|
||||||
<th scope="col" class="px-4 py-2.5 font-medium">用户</th>
|
<th scope="col" class="px-4 py-2.5 font-medium">用户</th>
|
||||||
<th scope="col" class="px-4 py-2.5 font-medium">模型</th>
|
<th scope="col" class="px-4 py-2.5 font-medium">模型</th>
|
||||||
|
<th scope="col" class="px-4 py-2.5 font-medium">渠道</th>
|
||||||
<th scope="col" class="px-4 py-2.5 font-medium">API 格式</th>
|
<th scope="col" class="px-4 py-2.5 font-medium">API 格式</th>
|
||||||
<th scope="col" class="px-4 py-2.5 font-medium">Token 入/出</th>
|
<th scope="col" class="px-4 py-2.5 font-medium">Token 入/出</th>
|
||||||
<th scope="col" class="px-4 py-2.5 font-medium">成本</th>
|
<th scope="col" class="px-4 py-2.5 font-medium">成本</th>
|
||||||
@@ -178,6 +179,7 @@ onMounted(load)
|
|||||||
<tr v-for="l in logs" :key="l.id" class="table-row">
|
<tr v-for="l in logs" :key="l.id" class="table-row">
|
||||||
<td class="px-4 py-2.5 text-xs text-ink">{{ l.user }}</td>
|
<td class="px-4 py-2.5 text-xs text-ink">{{ l.user }}</td>
|
||||||
<td class="px-4 py-2.5 font-mono text-xs text-ink">{{ l.model }}</td>
|
<td class="px-4 py-2.5 font-mono text-xs text-ink">{{ l.model }}</td>
|
||||||
|
<td class="px-4 py-2.5 font-mono text-xs text-muted">{{ l.channel || '-' }}</td>
|
||||||
<td class="px-4 py-2.5 font-mono text-xs text-muted">{{ protocolShort(l.protocol) }}</td>
|
<td class="px-4 py-2.5 font-mono text-xs text-muted">{{ protocolShort(l.protocol) }}</td>
|
||||||
<td class="px-4 py-2.5 mono-num text-xs text-muted">{{ l.input_tokens }}/{{ l.output_tokens }}</td>
|
<td class="px-4 py-2.5 mono-num text-xs text-muted">{{ l.input_tokens }}/{{ l.output_tokens }}</td>
|
||||||
<td class="px-4 py-2.5 mono-num text-xs text-ink">{{ fmtCost(l.cost) }}</td>
|
<td class="px-4 py-2.5 mono-num text-xs text-ink">{{ fmtCost(l.cost) }}</td>
|
||||||
@@ -192,7 +194,7 @@ onMounted(load)
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr v-if="logs.length === 0">
|
<tr v-if="logs.length === 0">
|
||||||
<td colspan="9" class="px-4 py-10 text-center text-sm text-muted">暂无请求记录</td>
|
<td colspan="10" class="px-4 py-10 text-center text-sm text-muted">暂无请求记录</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
@@ -212,6 +214,8 @@ onMounted(load)
|
|||||||
<div class="text-xs text-muted">
|
<div class="text-xs text-muted">
|
||||||
<span class="font-mono text-ink">{{ viewing.model }}</span>
|
<span class="font-mono text-ink">{{ viewing.model }}</span>
|
||||||
<span class="mx-1.5">·</span>
|
<span class="mx-1.5">·</span>
|
||||||
|
<span class="font-mono">{{ viewing.channel || '-' }}</span>
|
||||||
|
<span class="mx-1.5">·</span>
|
||||||
<span class="font-mono">{{ viewing.user || '-' }}</span>
|
<span class="font-mono">{{ viewing.user || '-' }}</span>
|
||||||
<span class="mx-1.5">·</span>
|
<span class="mx-1.5">·</span>
|
||||||
<span class="mono-num">{{ fmtTime(viewing.created_at) }}</span>
|
<span class="mono-num">{{ fmtTime(viewing.created_at) }}</span>
|
||||||
|
|||||||
@@ -145,14 +145,14 @@ onMounted(load)
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 快速开始 -->
|
<!-- 快速开始 -->
|
||||||
<div class="card p-5">
|
<div class="card min-w-0 p-5">
|
||||||
<div class="mb-4">
|
<div class="mb-4">
|
||||||
<h2 class="text-sm font-semibold">快速开始</h2>
|
<h2 class="text-sm font-semibold">快速开始</h2>
|
||||||
<p class="text-xs text-muted">通过兼容端点接入,OpenAI / Anthropic 协议自动转换</p>
|
<p class="text-xs text-muted">通过兼容端点接入,OpenAI / Anthropic 协议自动转换</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="space-y-4">
|
<div class="space-y-4">
|
||||||
<div>
|
<div class="min-w-0">
|
||||||
<p class="mb-1.5 text-[11px] font-medium text-muted">Base URL</p>
|
<p class="mb-1.5 text-[11px] font-medium text-muted">Base URL</p>
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
<code class="min-w-0 flex-1 overflow-x-auto rounded-md border border-edge bg-surface px-3 py-2 font-mono text-xs whitespace-nowrap text-ink">{{ baseURL }}</code>
|
<code class="min-w-0 flex-1 overflow-x-auto rounded-md border border-edge bg-surface px-3 py-2 font-mono text-xs whitespace-nowrap text-ink">{{ baseURL }}</code>
|
||||||
@@ -162,7 +162,7 @@ onMounted(load)
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div class="min-w-0">
|
||||||
<p class="mb-1.5 text-[11px] font-medium text-muted">兼容</p>
|
<p class="mb-1.5 text-[11px] font-medium text-muted">兼容</p>
|
||||||
<div class="flex flex-wrap gap-1.5">
|
<div class="flex flex-wrap gap-1.5">
|
||||||
<Badge variant="neutral">messages</Badge>
|
<Badge variant="neutral">messages</Badge>
|
||||||
@@ -171,10 +171,10 @@ onMounted(load)
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div class="min-w-0">
|
||||||
<p class="mb-1.5 text-[11px] font-medium text-muted">curl 示例</p>
|
<p class="mb-1.5 text-[11px] font-medium text-muted">curl 示例</p>
|
||||||
<div class="relative">
|
<div class="relative min-w-0 overflow-hidden rounded-md border border-edge bg-surface">
|
||||||
<pre class="overflow-x-auto rounded-md border border-edge bg-surface px-3 py-2.5 pr-20 font-mono text-[11px] leading-relaxed text-ink">{{ curlCmd }}</pre>
|
<pre class="overflow-x-auto px-3 py-2.5 pr-20 font-mono text-[11px] leading-relaxed text-ink">{{ curlCmd }}</pre>
|
||||||
<Button size="sm" variant="ghost" class="absolute top-2 right-2" @click="copy(curlCmd, 'curl')">
|
<Button size="sm" variant="ghost" class="absolute top-2 right-2" @click="copy(curlCmd, 'curl')">
|
||||||
{{ copied === 'curl' ? '已复制' : '复制' }}
|
{{ copied === 'curl' ? '已复制' : '复制' }}
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
Reference in New Issue
Block a user