mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-11-08 08:55:22 +00:00
背景:gpt-5.3-codex-spark 使用独立于 codex 全局(5h/7d)的配额窗口(数据源是 /wham/usage 响应体的 codex_bengalfox,而非 codex 全局用的 x-codex-* 响应头),且 只能挂在已完成 OAuth 授权的 OpenAI 账号下复用其登录态,不能作为独立账号单独接入。 为此新增“链接型影子账号”(spark shadow account):影子账号本身不持有任何凭据, 通过 parent_account_id 指向母账号,凭据/token/代理透传自母账号并共享母账号的刷新 周期,仅在配额维度(quota_dimension=spark)和用量窗口上与母账号完全独立调度、互不 连坐。 实现: - 数据模型:migration 154(+154a)给 accounts 表加 parent_account_id / quota_dimension 列 + 4 条约束(维度合法 / parent⟺非 global 维度一致 / 禁自指 / FK)+ 2 个 CONCURRENTLY 索引(母账号索引 + 每母账号至多一个影子的唯一索引)。 - 创建:POST /api/v1/admin/accounts/:id/shadow(CreateShadow)—— 一母一影(唯一 索引兜底并发竞态),继承母账号 proxy/分组/并发/优先级(显式传参可覆盖),默认 model_mapping 恒等映射到 spark(拒绝非 spark 模型),母账号必须是真实的 OpenAI OAuth 账号(非影子)。 - 凭据透传:resolveCredentialAccount 把影子解析回母账号,GetAccessToken / 请求头 / WS 三条路径统一走此函数;影子自身 Credentials 恒为空(仅允许写 model_mapping), 凭据写入的汇聚点 persistAccountCredentials 对影子早返 no-op,防止误写。 - 调度:parentHealthyForShadow 只看母账号是否仍是 OpenAI OAuth + 凭据/传输是否 可用(active、token 未过期、未处于 401/刷新失败/传输故障导致的临时不可调度冷却), 刻意不看母账号的 global 限流窗口——两条 429 道互不连坐。 - 用量:影子的 codex_5h/7d 走 OpenAIQuotaService.QueryUsage(/wham/usage 的 codex_bengalfox),与母账号走的 WSv2 探测(/responses 头)完全独立的数据源、 刷新节流与 staleness 判定。 - 备份:ExportData 显式排除影子账号(影子不持凭据,通用凭据型导入强制 credentials 非空、无法表达父子链接),按 skipped_shadows 计数提示前端。 - 前端:账号操作菜单新增“创建 Spark 影子”入口,影子行展示回填的母账号信息 (邮箱 / plan / 隐私模式 / 订阅到期 / chatgpt_account_id),批量操作自动跳过 影子账号。 说明:migrations 目录用完整文件名(而非纯数字前缀)标识迁移,故本次新增的 154_account_spark_shadow.sql / 154a_..._notx.sql 与已有的 154_add_ops_system_logs_api_key_id.sql 按序号共存,与目录里 145/151 已有的 先例一致。 测试:新增约 20 个测试文件,覆盖 handler(CreateShadow 校验 / 母账号信息回填)、 repository(影子 round-trip / 一母一影唯一索引 / 迁移 schema)、service(凭据 透传三路径 / 调度母健康门 / 用量窗口来源与刷新节流 / CRS 母账号不变量 / 各类 早返与 fail-closed 场景)及前端组件(账号列表 / 操作菜单 / 用量重置)。 验证(镜像 CI;golangci-lint 首次全量分析耗时过长被跳过,其余全部实测): - gofmt -l:干净 - go build ./... / go vet ./...:通过 - go test ./... -count=1:全绿(全部包 ok,含 internal/service、 internal/repository、migrations) - go test -tags integration ./internal/repository/... ./internal/service/... (真实 Postgres,testcontainers):全绿,含迁移幂等性 (TestMigrationsRunner_IsIdempotent_AndSchemaIsUpToDate)与影子相关全部用例 - pnpm lint:check / pnpm typecheck / pnpm build(真实 vite 构建)/ pnpm vitest run:全绿(124 文件 760 用例) Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
443 lines
16 KiB
Go
443 lines
16 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
|
|
infraerrors "github.com/Wei-Shaw/sub2api/internal/pkg/errors"
|
|
"github.com/Wei-Shaw/sub2api/internal/pkg/pagination"
|
|
)
|
|
|
|
var (
|
|
ErrAccountNotFound = infraerrors.NotFound("ACCOUNT_NOT_FOUND", "account not found")
|
|
ErrAccountNilInput = infraerrors.BadRequest("ACCOUNT_NIL_INPUT", "account input cannot be nil")
|
|
ErrAccountNotInFallback = infraerrors.BadRequest("ACCOUNT_NOT_IN_FALLBACK", "account is not in proxy fallback state")
|
|
)
|
|
|
|
const AccountListGroupUngrouped int64 = -1
|
|
const AccountPrivacyModeUnsetFilter = "__unset__"
|
|
|
|
type AccountRepository interface {
|
|
Create(ctx context.Context, account *Account) error
|
|
GetByID(ctx context.Context, id int64) (*Account, error)
|
|
// GetByIDs fetches accounts by IDs in a single query.
|
|
// It should return all accounts found (missing IDs are ignored).
|
|
GetByIDs(ctx context.Context, ids []int64) ([]*Account, error)
|
|
// ExistsByID 检查账号是否存在,仅返回布尔值,用于删除前的轻量级存在性检查
|
|
ExistsByID(ctx context.Context, id int64) (bool, error)
|
|
// GetByCRSAccountID finds an account previously synced from CRS.
|
|
// Returns (nil, nil) if not found.
|
|
GetByCRSAccountID(ctx context.Context, crsAccountID string) (*Account, error)
|
|
// FindByExtraField 根据 extra 字段中的键值对查找账号
|
|
FindByExtraField(ctx context.Context, key string, value any) ([]Account, error)
|
|
// ListCRSAccountIDs returns a map of crs_account_id -> local account ID
|
|
// for all accounts that have been synced from CRS.
|
|
ListCRSAccountIDs(ctx context.Context) (map[string]int64, error)
|
|
Update(ctx context.Context, account *Account) error
|
|
Delete(ctx context.Context, id int64) error
|
|
|
|
List(ctx context.Context, params pagination.PaginationParams) ([]Account, *pagination.PaginationResult, error)
|
|
ListWithFilters(ctx context.Context, params pagination.PaginationParams, platform, accountType, status, search string, groupID int64, privacyMode string) ([]Account, *pagination.PaginationResult, error)
|
|
ListByGroup(ctx context.Context, groupID int64) ([]Account, error)
|
|
ListActive(ctx context.Context) ([]Account, error)
|
|
ListOAuthRefreshCandidates(ctx context.Context) ([]Account, error)
|
|
ListByPlatform(ctx context.Context, platform string) ([]Account, error)
|
|
|
|
UpdateLastUsed(ctx context.Context, id int64) error
|
|
BatchUpdateLastUsed(ctx context.Context, updates map[int64]time.Time) error
|
|
SetError(ctx context.Context, id int64, errorMsg string) error
|
|
ClearError(ctx context.Context, id int64) error
|
|
SetSchedulable(ctx context.Context, id int64, schedulable bool) error
|
|
AutoPauseExpiredAccounts(ctx context.Context, now time.Time) (int64, error)
|
|
BindGroups(ctx context.Context, accountID int64, groupIDs []int64) error
|
|
|
|
ListSchedulable(ctx context.Context) ([]Account, error)
|
|
ListSchedulableByGroupID(ctx context.Context, groupID int64) ([]Account, error)
|
|
ListSchedulableByPlatform(ctx context.Context, platform string) ([]Account, error)
|
|
ListSchedulableByGroupIDAndPlatform(ctx context.Context, groupID int64, platform string) ([]Account, error)
|
|
ListSchedulableByPlatforms(ctx context.Context, platforms []string) ([]Account, error)
|
|
ListSchedulableByGroupIDAndPlatforms(ctx context.Context, groupID int64, platforms []string) ([]Account, error)
|
|
ListSchedulableUngroupedByPlatform(ctx context.Context, platform string) ([]Account, error)
|
|
ListSchedulableUngroupedByPlatforms(ctx context.Context, platforms []string) ([]Account, error)
|
|
|
|
SetRateLimited(ctx context.Context, id int64, resetAt time.Time) error
|
|
SetModelRateLimit(ctx context.Context, id int64, scope string, resetAt time.Time, reason ...string) error
|
|
SetOverloaded(ctx context.Context, id int64, until time.Time) error
|
|
SetTempUnschedulable(ctx context.Context, id int64, until time.Time, reason string) error
|
|
ClearTempUnschedulable(ctx context.Context, id int64) error
|
|
ClearRateLimit(ctx context.Context, id int64) error
|
|
ClearAntigravityQuotaScopes(ctx context.Context, id int64) error
|
|
ClearModelRateLimits(ctx context.Context, id int64) error
|
|
UpdateSessionWindow(ctx context.Context, id int64, start, end *time.Time, status string) error
|
|
// UpdateSessionWindowEnd 仅更新 5h 窗口的结束时间,不动 start / status。
|
|
// 用于 active poll 拿到新 ResetsAt 后回写,避免覆盖请求路径上记录的 status。
|
|
UpdateSessionWindowEnd(ctx context.Context, id int64, end time.Time) error
|
|
UpdateExtra(ctx context.Context, id int64, updates map[string]any) error
|
|
BulkUpdate(ctx context.Context, ids []int64, updates AccountBulkUpdate) (int64, error)
|
|
// IncrementQuotaUsed 原子递增 API Key 账号的配额用量(总/日/周)
|
|
IncrementQuotaUsed(ctx context.Context, id int64, amount float64) error
|
|
// ResetQuotaUsed 重置 API Key 账号所有维度的配额用量为 0
|
|
ResetQuotaUsed(ctx context.Context, id int64) error
|
|
// RevertProxyFallback 将账号的 proxy_id 切回 proxy_fallback_origin_id,并清空 origin 字段。
|
|
// 仅当 proxy_fallback_origin_id IS NOT NULL 时更新,否则视为账号不存在(返回 ErrAccountNotFound)。
|
|
RevertProxyFallback(ctx context.Context, accountID int64) error
|
|
// ListShadowsByParent 返回指定父账号的影子账号;当前实现仅查 quota_dimension='spark'(唯一预设)。
|
|
// ⚠️ 新增影子维度时:须更新此函数(或新增维度专用列举),并检查所有调用点(级联删除/一母一影校验/type 守卫),否则会静默漏掉新维度。
|
|
ListShadowsByParent(ctx context.Context, parentID int64) ([]*Account, error)
|
|
}
|
|
|
|
// AccountBulkUpdate describes the fields that can be updated in a bulk operation.
|
|
// Nil pointers mean "do not change".
|
|
type AccountBulkUpdate struct {
|
|
Name *string
|
|
ProxyID *int64
|
|
Concurrency *int
|
|
Priority *int
|
|
RateMultiplier *float64
|
|
LoadFactor *int
|
|
Status *string
|
|
Schedulable *bool
|
|
Credentials map[string]any
|
|
Extra map[string]any
|
|
}
|
|
|
|
// CreateAccountRequest 创建账号请求
|
|
type CreateAccountRequest struct {
|
|
Name string `json:"name"`
|
|
Notes *string `json:"notes"`
|
|
Platform string `json:"platform"`
|
|
Type string `json:"type"`
|
|
Credentials map[string]any `json:"credentials"`
|
|
Extra map[string]any `json:"extra"`
|
|
ProxyID *int64 `json:"proxy_id"`
|
|
Concurrency int `json:"concurrency"`
|
|
Priority int `json:"priority"`
|
|
GroupIDs []int64 `json:"group_ids"`
|
|
ExpiresAt *time.Time `json:"expires_at"`
|
|
AutoPauseOnExpired *bool `json:"auto_pause_on_expired"`
|
|
}
|
|
|
|
// UpdateAccountRequest 更新账号请求
|
|
type UpdateAccountRequest struct {
|
|
Name *string `json:"name"`
|
|
Notes *string `json:"notes"`
|
|
Credentials *map[string]any `json:"credentials"`
|
|
Extra *map[string]any `json:"extra"`
|
|
ProxyID *int64 `json:"proxy_id"`
|
|
Concurrency *int `json:"concurrency"`
|
|
Priority *int `json:"priority"`
|
|
Status *string `json:"status"`
|
|
GroupIDs *[]int64 `json:"group_ids"`
|
|
ExpiresAt *time.Time `json:"expires_at"`
|
|
AutoPauseOnExpired *bool `json:"auto_pause_on_expired"`
|
|
}
|
|
|
|
// AccountService 账号管理服务
|
|
type AccountService struct {
|
|
accountRepo AccountRepository
|
|
groupRepo GroupRepository
|
|
}
|
|
|
|
type groupExistenceBatchChecker interface {
|
|
ExistsByIDs(ctx context.Context, ids []int64) (map[int64]bool, error)
|
|
}
|
|
|
|
// NewAccountService 创建账号服务实例
|
|
func NewAccountService(accountRepo AccountRepository, groupRepo GroupRepository) *AccountService {
|
|
return &AccountService{
|
|
accountRepo: accountRepo,
|
|
groupRepo: groupRepo,
|
|
}
|
|
}
|
|
|
|
// Create 创建账号
|
|
func (s *AccountService) Create(ctx context.Context, req CreateAccountRequest) (*Account, error) {
|
|
// 验证分组是否存在(如果指定了分组)
|
|
if len(req.GroupIDs) > 0 {
|
|
if err := s.validateGroupIDsExist(ctx, req.GroupIDs); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
// 创建账号
|
|
account := &Account{
|
|
Name: req.Name,
|
|
Notes: normalizeAccountNotes(req.Notes),
|
|
Platform: req.Platform,
|
|
Type: req.Type,
|
|
Credentials: req.Credentials,
|
|
Extra: req.Extra,
|
|
ProxyID: req.ProxyID,
|
|
Concurrency: req.Concurrency,
|
|
Priority: req.Priority,
|
|
Status: StatusActive,
|
|
ExpiresAt: req.ExpiresAt,
|
|
}
|
|
if req.AutoPauseOnExpired != nil {
|
|
account.AutoPauseOnExpired = *req.AutoPauseOnExpired
|
|
} else {
|
|
account.AutoPauseOnExpired = true
|
|
}
|
|
|
|
if err := s.accountRepo.Create(ctx, account); err != nil {
|
|
return nil, fmt.Errorf("create account: %w", err)
|
|
}
|
|
|
|
// require_oauth_only 检查:apikey 类型账号不可加入限制分组
|
|
if account.Type == AccountTypeAPIKey && len(req.GroupIDs) > 0 {
|
|
for _, gid := range req.GroupIDs {
|
|
g, err := s.groupRepo.GetByID(ctx, gid)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if g.RequireOAuthOnly && (g.Platform == PlatformOpenAI || g.Platform == PlatformAntigravity || g.Platform == PlatformAnthropic || g.Platform == PlatformGemini || g.Platform == PlatformGrok) {
|
|
return nil, fmt.Errorf("分组 [%s] 仅允许 OAuth 账号,apikey 类型账号无法加入", g.Name)
|
|
}
|
|
}
|
|
}
|
|
|
|
// 绑定分组
|
|
if len(req.GroupIDs) > 0 {
|
|
if err := s.accountRepo.BindGroups(ctx, account.ID, req.GroupIDs); err != nil {
|
|
return nil, fmt.Errorf("bind groups: %w", err)
|
|
}
|
|
}
|
|
|
|
return account, nil
|
|
}
|
|
|
|
// GetByID 根据ID获取账号
|
|
func (s *AccountService) GetByID(ctx context.Context, id int64) (*Account, error) {
|
|
account, err := s.accountRepo.GetByID(ctx, id)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("get account: %w", err)
|
|
}
|
|
return account, nil
|
|
}
|
|
|
|
// List 获取账号列表
|
|
func (s *AccountService) List(ctx context.Context, params pagination.PaginationParams) ([]Account, *pagination.PaginationResult, error) {
|
|
accounts, pagination, err := s.accountRepo.List(ctx, params)
|
|
if err != nil {
|
|
return nil, nil, fmt.Errorf("list accounts: %w", err)
|
|
}
|
|
return accounts, pagination, nil
|
|
}
|
|
|
|
// ListByPlatform 根据平台获取账号列表
|
|
func (s *AccountService) ListByPlatform(ctx context.Context, platform string) ([]Account, error) {
|
|
accounts, err := s.accountRepo.ListByPlatform(ctx, platform)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("list accounts by platform: %w", err)
|
|
}
|
|
return accounts, nil
|
|
}
|
|
|
|
// ListByGroup 根据分组获取账号列表
|
|
func (s *AccountService) ListByGroup(ctx context.Context, groupID int64) ([]Account, error) {
|
|
accounts, err := s.accountRepo.ListByGroup(ctx, groupID)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("list accounts by group: %w", err)
|
|
}
|
|
return accounts, nil
|
|
}
|
|
|
|
// Update 更新账号
|
|
func (s *AccountService) Update(ctx context.Context, id int64, req UpdateAccountRequest) (*Account, error) {
|
|
account, err := s.accountRepo.GetByID(ctx, id)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("get account: %w", err)
|
|
}
|
|
|
|
// 更新字段
|
|
if req.Name != nil {
|
|
account.Name = *req.Name
|
|
}
|
|
if req.Notes != nil {
|
|
account.Notes = normalizeAccountNotes(req.Notes)
|
|
}
|
|
|
|
if req.Credentials != nil {
|
|
account.Credentials = *req.Credentials
|
|
}
|
|
|
|
if req.Extra != nil {
|
|
account.Extra = *req.Extra
|
|
}
|
|
|
|
if req.ProxyID != nil {
|
|
account.ProxyID = req.ProxyID
|
|
}
|
|
|
|
if req.Concurrency != nil {
|
|
account.Concurrency = *req.Concurrency
|
|
}
|
|
|
|
if req.Priority != nil {
|
|
account.Priority = *req.Priority
|
|
}
|
|
|
|
if req.Status != nil {
|
|
account.Status = *req.Status
|
|
}
|
|
if req.ExpiresAt != nil {
|
|
account.ExpiresAt = req.ExpiresAt
|
|
}
|
|
if req.AutoPauseOnExpired != nil {
|
|
account.AutoPauseOnExpired = *req.AutoPauseOnExpired
|
|
}
|
|
|
|
// 先验证分组是否存在(在任何写操作之前)
|
|
if req.GroupIDs != nil {
|
|
if err := s.validateGroupIDsExist(ctx, *req.GroupIDs); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
// 执行更新
|
|
if err := s.accountRepo.Update(ctx, account); err != nil {
|
|
return nil, fmt.Errorf("update account: %w", err)
|
|
}
|
|
|
|
// require_oauth_only 检查
|
|
if account.Type == AccountTypeAPIKey && req.GroupIDs != nil {
|
|
for _, gid := range *req.GroupIDs {
|
|
g, err := s.groupRepo.GetByID(ctx, gid)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if g.RequireOAuthOnly && (g.Platform == PlatformOpenAI || g.Platform == PlatformAntigravity || g.Platform == PlatformAnthropic || g.Platform == PlatformGemini || g.Platform == PlatformGrok) {
|
|
return nil, fmt.Errorf("分组 [%s] 仅允许 OAuth 账号,apikey 类型账号无法加入", g.Name)
|
|
}
|
|
}
|
|
}
|
|
|
|
// 绑定分组
|
|
if req.GroupIDs != nil {
|
|
if err := s.accountRepo.BindGroups(ctx, account.ID, *req.GroupIDs); err != nil {
|
|
return nil, fmt.Errorf("bind groups: %w", err)
|
|
}
|
|
}
|
|
|
|
return account, nil
|
|
}
|
|
|
|
// Delete 删除账号
|
|
// 优化:使用 ExistsByID 替代 GetByID 进行存在性检查,
|
|
// 避免加载完整账号对象及其关联数据,提升删除操作的性能
|
|
func (s *AccountService) Delete(ctx context.Context, id int64) error {
|
|
// 使用轻量级的存在性检查,而非加载完整账号对象
|
|
exists, err := s.accountRepo.ExistsByID(ctx, id)
|
|
if err != nil {
|
|
return fmt.Errorf("check account: %w", err)
|
|
}
|
|
// 明确返回账号不存在错误,便于调用方区分错误类型
|
|
if !exists {
|
|
return ErrAccountNotFound
|
|
}
|
|
|
|
// 注意:此处不级联删除 spark 影子账号。当前唯一的后台删除入口走 AdminService.DeleteAccount
|
|
// (已 ListShadowsByParent 先删影子再删母)。本方法目前无删除调用方;若未来有调用方经此
|
|
// 删除母账号,需在此补级联,否则会留下孤儿影子(外审第6轮 P3:当前不可达,记为残留)。
|
|
if err := s.accountRepo.Delete(ctx, id); err != nil {
|
|
return fmt.Errorf("delete account: %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (s *AccountService) validateGroupIDsExist(ctx context.Context, groupIDs []int64) error {
|
|
if len(groupIDs) == 0 {
|
|
return nil
|
|
}
|
|
if s.groupRepo == nil {
|
|
return fmt.Errorf("group repository not configured")
|
|
}
|
|
|
|
if batchChecker, ok := s.groupRepo.(groupExistenceBatchChecker); ok {
|
|
existsByID, err := batchChecker.ExistsByIDs(ctx, groupIDs)
|
|
if err != nil {
|
|
return fmt.Errorf("check groups exists: %w", err)
|
|
}
|
|
for _, groupID := range groupIDs {
|
|
if groupID <= 0 {
|
|
return fmt.Errorf("get group: %w", ErrGroupNotFound)
|
|
}
|
|
if !existsByID[groupID] {
|
|
return fmt.Errorf("get group: %w", ErrGroupNotFound)
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
for _, groupID := range groupIDs {
|
|
_, err := s.groupRepo.GetByID(ctx, groupID)
|
|
if err != nil {
|
|
return fmt.Errorf("get group: %w", err)
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// UpdateStatus 更新账号状态
|
|
func (s *AccountService) UpdateStatus(ctx context.Context, id int64, status string, errorMessage string) error {
|
|
account, err := s.accountRepo.GetByID(ctx, id)
|
|
if err != nil {
|
|
return fmt.Errorf("get account: %w", err)
|
|
}
|
|
|
|
account.Status = status
|
|
account.ErrorMessage = errorMessage
|
|
|
|
if err := s.accountRepo.Update(ctx, account); err != nil {
|
|
return fmt.Errorf("update account: %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// UpdateLastUsed 更新最后使用时间
|
|
func (s *AccountService) UpdateLastUsed(ctx context.Context, id int64) error {
|
|
if err := s.accountRepo.UpdateLastUsed(ctx, id); err != nil {
|
|
return fmt.Errorf("update last used: %w", err)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// GetCredential 获取账号凭证(安全访问)
|
|
func (s *AccountService) GetCredential(ctx context.Context, id int64, key string) (string, error) {
|
|
account, err := s.accountRepo.GetByID(ctx, id)
|
|
if err != nil {
|
|
return "", fmt.Errorf("get account: %w", err)
|
|
}
|
|
|
|
return account.GetCredential(key), nil
|
|
}
|
|
|
|
// TestCredentials 测试账号凭证是否有效(需要实现具体平台的测试逻辑)
|
|
func (s *AccountService) TestCredentials(ctx context.Context, id int64) error {
|
|
account, err := s.accountRepo.GetByID(ctx, id)
|
|
if err != nil {
|
|
return fmt.Errorf("get account: %w", err)
|
|
}
|
|
|
|
// 根据平台执行不同的测试逻辑
|
|
switch account.Platform {
|
|
case PlatformAnthropic:
|
|
// TODO: 测试Anthropic API凭证
|
|
return nil
|
|
case PlatformOpenAI:
|
|
// TODO: 测试OpenAI API凭证
|
|
return nil
|
|
case PlatformGemini:
|
|
// TODO: 测试Gemini API凭证
|
|
return nil
|
|
case PlatformGrok:
|
|
// Grok OAuth credentials are validated via token exchange/refresh and request-path probes.
|
|
return nil
|
|
default:
|
|
return fmt.Errorf("unsupported platform: %s", account.Platform)
|
|
}
|
|
}
|