feat: 增加管理员 AI 模型配置 (#200)

This commit is contained in:
chengma
2026-08-14 09:49:11 +08:00
parent ad44f83ea6
commit 018da3f732
24 changed files with 1546 additions and 8 deletions
+59 -1
View File
@@ -4,7 +4,10 @@
// 字段含义的权威定义在 docs/admin/03-data-model.md。
package model
import "time"
import (
"fmt"
"time"
)
// ---------- 时间 ----------
@@ -100,6 +103,61 @@ func (u User) StatusLabel() string {
return "禁用"
}
// AIProviderConfig 是一个 OpenAI 兼容服务商的非敏感配置。
// API Key 不属于这个结构,也绝不能进入数据库。
type AIProviderConfig struct {
ProviderID string
Name string
BaseURL string
Model string
TimeoutSeconds int
MaxConcurrency int
ConfidenceThresholdBPS int
Enabled bool
LastTestStatus string
LastTestMessage string
LastTestedAt string
LastTestFingerprint string
CreatedByUserID string
UpdatedByUserID string
CreatedAt string
UpdatedAt string
SecretConfigured bool
SecretSuffix string
}
func (c AIProviderConfig) StatusLabel() string {
if c.Enabled {
return "已启用"
}
return "已停用"
}
func (c AIProviderConfig) TestStatusLabel() string {
switch c.LastTestStatus {
case "succeeded":
return "连接正常"
case "failed":
return "连接失败"
default:
return "尚未测试"
}
}
func (c AIProviderConfig) ConfidencePercent() string {
return fmt.Sprintf("%d.%02d", c.ConfidenceThresholdBPS/100, c.ConfidenceThresholdBPS%100)
}
// AIProviderAudit 只记录非敏感配置变更;DetailsJSON 不得含 API Key。
type AIProviderAudit struct {
ID int64
ProviderID string
Action string
DetailsJSON string
ActorUserID string
CreatedAt string
}
// WebSession 是服务端保存的网页登录状态。SessionHash 是浏览器随机 Token
// 的 SHA-256,不是 Token 原文。
type WebSession struct {