Documentation
¶
Index ¶
- Constants
- Variables
- type AccountDeleteResult
- type AutoCleanConfig
- type BatchProgressObserver
- type BuildConversionResult
- type BuildConversionStrategy
- type BuildDetectItemObserver
- type BuildDetectItemResult
- type BuildDetectOutcome
- type CleanupResult
- type CleanupStatus
- type CredentialStartupReport
- type DeviceStartResult
- type ExportPageResult
- type ExportResult
- type ImportResult
- type ImportedAccountObserver
- type IssueSummary
- type ListFilter
- type ProviderSummary
- type QuotaRefreshStats
- type QuotaStatus
- type QuotaType
- type QuotaView
- type RateLimitReconcileState
- type RecoverySummary
- type Service
- func (s *Service) AcceptWebTerms(ctx context.Context, id uint64) error
- func (s *Service) AccountsBelongToProvider(ctx context.Context, ids []uint64, providerValue accountdomain.Provider) (bool, error)
- func (s *Service) BatchDelete(ctx context.Context, ids []uint64) (int64, error)
- func (s *Service) BatchDeleteWithLinked(ctx context.Context, providerValue accountdomain.Provider, ids []uint64, ...) (AccountDeleteResult, error)
- func (s *Service) BatchRefreshBilling(ctx context.Context, ids []uint64) (int, int, error)
- func (s *Service) BatchRefreshQuota(ctx context.Context, ids []uint64) (int, int, error)
- func (s *Service) BatchRefreshTokens(ctx context.Context, ids []uint64) (int, int, int, error)
- func (s *Service) BatchResetQuotaState(ctx context.Context, ids []uint64) (int, error)
- func (s *Service) BatchUpdate(ctx context.Context, providerValue accountdomain.Provider, ids []uint64, ...) (int64, error)
- func (s *Service) CleanupAccounts(ctx context.Context, providerValue accountdomain.Provider, ...) (CleanupResult, error)
- func (s *Service) ClearCooldown(ctx context.Context, id uint64) (View, error)
- func (s *Service) ConvertAllWebAccountsToBuild(ctx context.Context) (BuildConversionResult, error)
- func (s *Service) ConvertAllWebAccountsToBuildWithObserver(ctx context.Context, observer ImportedAccountObserver) (BuildConversionResult, error)
- func (s *Service) ConvertAllWebAccountsToBuildWithProgress(ctx context.Context, observer ImportedAccountObserver, ...) (BuildConversionResult, error)
- func (s *Service) ConvertAllWebAccountsToBuildWithStrategy(ctx context.Context, strategy BuildConversionStrategy, ...) (BuildConversionResult, error)
- func (s *Service) ConvertWebAccountsToBuild(ctx context.Context, ids []uint64) (BuildConversionResult, error)
- func (s *Service) ConvertWebAccountsToBuildWithObserver(ctx context.Context, ids []uint64, observer ImportedAccountObserver) (BuildConversionResult, error)
- func (s *Service) ConvertWebAccountsToBuildWithProgress(ctx context.Context, ids []uint64, observer ImportedAccountObserver, ...) (BuildConversionResult, error)
- func (s *Service) ConvertWebAccountsToBuildWithStrategy(ctx context.Context, ids []uint64, strategy BuildConversionStrategy, ...) (BuildConversionResult, error)
- func (s *Service) DecrementQuota(ctx context.Context, id uint64, mode string, amount int) (bool, error)
- func (s *Service) DecrementWebQuota(ctx context.Context, id uint64, mode string, amount int) (bool, error)
- func (s *Service) Delete(ctx context.Context, id uint64) error
- func (s *Service) DeleteWithLinked(ctx context.Context, providerValue accountdomain.Provider, id uint64, ...) (AccountDeleteResult, error)
- func (s *Service) DetectBuildAccountsWithProgress(ctx context.Context, ids []uint64, all bool, progress BatchProgressObserver, ...) (int, int, error)
- func (s *Service) EnableWebNSFW(ctx context.Context, id uint64) error
- func (s *Service) EnsureCredential(ctx context.Context, value accountdomain.Credential, force bool) (accountdomain.Credential, error)
- func (s *Service) ExhaustQuota(ctx context.Context, id uint64, mode string, resetAt *time.Time) error
- func (s *Service) ExhaustWebQuota(ctx context.Context, id uint64, mode string, resetAt *time.Time) error
- func (s *Service) ExportCredentials(ctx context.Context) (ExportResult, error)
- func (s *Service) ExportProviderCredentials(ctx context.Context, providerValue accountdomain.Provider) (ExportResult, error)
- func (s *Service) ExportProviderCredentialsByIDs(ctx context.Context, providerValue accountdomain.Provider, ids []uint64) (ExportResult, error)
- func (s *Service) ExportProviderCredentialsCursor(ctx context.Context, providerValue accountdomain.Provider, ...) (ExportPageResult, error)
- func (s *Service) Get(ctx context.Context, id uint64) (View, error)
- func (s *Service) HasBillingSnapshot(ctx context.Context, id uint64) (bool, error)
- func (s *Service) HasQuotaWindows(ctx context.Context, id uint64) (bool, error)
- func (s *Service) ImportConsoleCredentialDocumentsWithProgress(ctx context.Context, documents [][]byte, observer ImportedAccountObserver, ...) (ImportResult, error)
- func (s *Service) ImportConsoleCredentials(ctx context.Context, data []byte) (ImportResult, error)
- func (s *Service) ImportConsoleCredentialsWithObserver(ctx context.Context, data []byte, observer ImportedAccountObserver) (ImportResult, error)
- func (s *Service) ImportConsoleCredentialsWithProgress(ctx context.Context, data []byte, observer ImportedAccountObserver, ...) (ImportResult, error)
- func (s *Service) ImportCredentialDocumentsWithProgress(ctx context.Context, documents [][]byte, observer ImportedAccountObserver, ...) (ImportResult, error)
- func (s *Service) ImportCredentials(ctx context.Context, data []byte) (ImportResult, error)
- func (s *Service) ImportCredentialsWithObserver(ctx context.Context, data []byte, observer ImportedAccountObserver) (ImportResult, error)
- func (s *Service) ImportCredentialsWithProgress(ctx context.Context, data []byte, observer ImportedAccountObserver, ...) (ImportResult, error)
- func (s *Service) ImportWebCredentialDocumentsWithProgress(ctx context.Context, documents [][]byte, observer ImportedAccountObserver, ...) (ImportResult, error)
- func (s *Service) ImportWebCredentials(ctx context.Context, data []byte) (ImportResult, error)
- func (s *Service) ImportWebCredentialsWithObserver(ctx context.Context, data []byte, observer ImportedAccountObserver) (ImportResult, error)
- func (s *Service) ImportWebCredentialsWithProgress(ctx context.Context, data []byte, observer ImportedAccountObserver, ...) (ImportResult, error)
- func (s *Service) List(ctx context.Context, page, pageSize int, search string, filter ListFilter) ([]View, int64, error)
- func (s *Service) ListBuildBotFlaggedAccountIDs(ctx context.Context) ([]uint64, error)
- func (s *Service) ListDueQuotaWindows(ctx context.Context, now time.Time, limit int) ([]accountdomain.QuotaWindow, error)
- func (s *Service) ListDueWebQuotaWindows(ctx context.Context, now time.Time, limit int) ([]accountdomain.QuotaWindow, error)
- func (s *Service) MarkBuildAPIFallback(ctx context.Context, id uint64, enabled bool) error
- func (s *Service) MarkReauthRequired(ctx context.Context, id uint64, reason string) error
- func (s *Service) ObserveResponseModel(ctx context.Context, id uint64, model string) error
- func (s *Service) PollDeviceLogin(ctx context.Context, sessionID string) (View, error)
- func (s *Service) PreviewCleanup(ctx context.Context, providerValue accountdomain.Provider, ...) (repository.CleanupPreview, error)
- func (s *Service) PreviewLinkedDelete(ctx context.Context, providerValue accountdomain.Provider, ids []uint64, ...) (repository.LinkedDeleteResolution, error)
- func (s *Service) ProbePaidQuota(ctx context.Context, value accountdomain.Credential) (bool, error)
- func (s *Service) ProbeQuotaMode(ctx context.Context, id uint64, mode string) (accountdomain.QuotaWindow, error)
- func (s *Service) ProviderDefinition(value accountdomain.Provider) (provider.Definition, bool)
- func (s *Service) QueueQuotaRefresh(id uint64, mode string)
- func (s *Service) QuotaRefreshStats() QuotaRefreshStats
- func (s *Service) RebuildBuildBotFlagIndex(ctx context.Context) error
- func (s *Service) ReconcileCredentialSchedules(ctx context.Context) (int, error)
- func (s *Service) ReconcileRateLimit(ctx context.Context, id uint64, mode string, retryAfter time.Duration) (RateLimitReconcileState, error)
- func (s *Service) ReconcileWebRateLimit(ctx context.Context, id uint64, mode string, retryAfter time.Duration) (bool, error)
- func (s *Service) RecoverCriticalCredentials(ctx context.Context, expiresWithin time.Duration, limit int) (CredentialStartupReport, error)
- func (s *Service) RefreshAllTokens(ctx context.Context) (int, int, int, error)
- func (s *Service) RefreshAllTokensWithProgress(ctx context.Context, progress BatchProgressObserver) (int, int, int, error)
- func (s *Service) RefreshBilling(ctx context.Context, id uint64) (accountdomain.Billing, error)
- func (s *Service) RefreshQuota(ctx context.Context, id uint64) ([]accountdomain.QuotaWindow, error)
- func (s *Service) RefreshQuotaMode(ctx context.Context, id uint64, mode string) (accountdomain.QuotaWindow, error)
- func (s *Service) RefreshToken(ctx context.Context, id uint64) (View, error)
- func (s *Service) RefreshWebQuota(ctx context.Context, id uint64) ([]accountdomain.QuotaWindow, error)
- func (s *Service) ResetAllBuildQuotaState(ctx context.Context) (int64, error)
- func (s *Service) RunAccountAutoClean(ctx context.Context)
- func (s *Service) RunAllWebAccountScriptsWithProgress(ctx context.Context, options WebAccountScriptOptions, ...) (int, int, error)
- func (s *Service) RunCredentialRefresh(ctx context.Context)
- func (s *Service) RunQuotaRefresh(ctx context.Context)
- func (s *Service) RunWebAccountScriptsWithProgress(ctx context.Context, ids []uint64, options WebAccountScriptOptions, ...) (int, int, error)
- func (s *Service) SetBulkPool(pool *batch.Pool)
- func (s *Service) SetConcurrencyLimiter(value repository.ConcurrencyLimiter)
- func (s *Service) SetDetectPool(pool *batch.Pool)
- func (s *Service) SetLogger(logger *slog.Logger)
- func (s *Service) SetObservedModelStore(value repository.ObservedModelStateRepository)
- func (s *Service) SetQuotaRecoveryQueue(queue repository.QuotaRecoveryQueue)
- func (s *Service) SetQuotaRefreshCoordinator(value repository.QuotaRefreshCoordinator)
- func (s *Service) SetTaskPools(conversion, syncPool, refresh *batch.Pool)
- func (s *Service) SetWebBirthDate(ctx context.Context, id uint64) error
- func (s *Service) StartDeviceLogin(ctx context.Context) (DeviceStartResult, error)
- func (s *Service) Summary(ctx context.Context) (Summary, error)
- func (s *Service) SyncAccountIdentity(ctx context.Context, id uint64) error
- func (s *Service) SyncAllBilling(ctx context.Context) (int, int, error)
- func (s *Service) SyncAllBillingWithProgress(ctx context.Context, progress BatchProgressObserver) (int, int, error)
- func (s *Service) SyncAllConsoleQuotas(ctx context.Context) (int, int, error)
- func (s *Service) SyncAllConsoleQuotasWithProgress(ctx context.Context, progress BatchProgressObserver) (int, int, error)
- func (s *Service) SyncAllWebAccountsToConsoleWithProgress(ctx context.Context, observer ImportedAccountObserver, ...) (ImportResult, error)
- func (s *Service) SyncAllWebAccountsToConsoleWithStrategy(ctx context.Context, strategy WebConsoleSyncStrategy, ...) (ImportResult, error)
- func (s *Service) SyncAllWebQuotas(ctx context.Context) (int, int, error)
- func (s *Service) SyncAllWebQuotasWithProgress(ctx context.Context, progress BatchProgressObserver) (int, int, error)
- func (s *Service) SyncIncompleteConsoleQuotas(ctx context.Context) (int, int, error)
- func (s *Service) SyncStaleConsoleQuotas(ctx context.Context, before time.Time, afterID uint64, limit int) (int, int, uint64, error)
- func (s *Service) SyncWebAccountsToConsoleWithProgress(ctx context.Context, ids []uint64, observer ImportedAccountObserver, ...) (ImportResult, error)
- func (s *Service) SyncWebAccountsToConsoleWithStrategy(ctx context.Context, ids []uint64, strategy WebConsoleSyncStrategy, ...) (ImportResult, error)
- func (s *Service) SyncWebQuotaAccounts(ctx context.Context, ids []uint64) (int, int, error)
- func (s *Service) Update(ctx context.Context, id uint64, input UpdateInput) (View, error)
- func (s *Service) UpdateAutoCleanConfig(value AutoCleanConfig)
- func (s *Service) UpdateExcludeBuildBotFlaggedFromScheduling(value bool)
- func (s *Service) WakeCredentialRefresh()
- type Summary
- type UpdateInput
- type View
- type WebAccountScriptOptions
- type WebConsoleSyncStrategy
Constants ¶
const ( QuotaTypeUnknown QuotaType = "unknown" QuotaTypeFree QuotaType = "free" QuotaTypePaid QuotaType = "paid" QuotaStatusActive QuotaStatus = "active" QuotaStatusWaitingReset QuotaStatus = "waitingReset" QuotaStatusProbing QuotaStatus = "probing" )
Variables ¶
var ( ErrDevicePending = errors.New("Device OAuth 等待用户授权") ErrDeviceSlowDown = errors.New("Device OAuth 轮询过快") ErrDeviceDenied = errors.New("Device OAuth 已拒绝或过期") ErrInvalidFilter = errors.New("账号筛选条件无效") ErrInvalidInput = errors.New("账号参数无效") ErrInvalidImport = errors.New("账号凭据格式无效") ErrImportLimit = errors.New("导入账号数量超过限制") ErrExportLimit = errors.New("导出账号数量超过限制") ErrNotFound = errors.New("账号不存在") ErrUnsupported = errors.New("账号来源不支持该操作") ErrConversionBusy = errors.New("账号正在转换为 Grok Build") ErrConflict = errors.New("账号操作存在冲突") ErrAccountPoolMismatch = errors.New("批量操作包含不属于当前号池的账号") )
var ErrCredentialRefreshPermanent = errors.New("OAuth refresh token 已永久失效")
var ErrWebAccountScriptBusy = errors.New("Grok Web 账号脚本正在执行")
Functions ¶
This section is empty.
Types ¶
type AccountDeleteResult ¶
type AccountDeleteResult struct {
Deleted int64
RootsDeleted int64
LinkedDeleted int64
Skipped int64
DeletedByProvider map[accountdomain.Provider]int64
}
AccountDeleteResult summarizes a single/batch delete with optional linked peers.
type AutoCleanConfig ¶
type AutoCleanConfig struct {
Enabled bool
Interval time.Duration
MinAge time.Duration
IncludeDisabled bool
}
AutoCleanConfig 是账号自动清理策略;由 app 层从运行设置映射,不依赖 infra/config。
type BatchProgressObserver ¶
BatchProgressObserver 在单个账号任务结束后报告批次完成数。
type BuildConversionResult ¶
type BuildConversionStrategy ¶
type BuildConversionStrategy string
const ( BuildConversionAll BuildConversionStrategy = "all" BuildConversionMissing BuildConversionStrategy = "missing" )
type BuildDetectItemObserver ¶
type BuildDetectItemObserver func(item BuildDetectItemResult) error
BuildDetectItemObserver 在单个账号探测完成后推送明细;返回错误会取消批次。
type BuildDetectItemResult ¶
type BuildDetectItemResult struct {
AccountID uint64
Name string
Email string
Outcome BuildDetectOutcome
Reason string
HTTPStatus int
}
BuildDetectItemResult 是单账号探测的结构化结果,供 SSE 增量推送。
type BuildDetectOutcome ¶
type BuildDetectOutcome string
BuildDetectOutcome 描述单次 Grok Build 可用性探测结果。
const ( // BuildDetectOutcomeOK 表示探测成功,账号可用。 BuildDetectOutcomeOK BuildDetectOutcome = "ok" // BuildDetectOutcomeInvalid 表示已确认失效并标 reauthRequired。 BuildDetectOutcomeInvalid BuildDetectOutcome = "invalid" // BuildDetectOutcomeFailed 表示探测失败但未判定为永久失效(网络/5xx/临时额度等)。 BuildDetectOutcomeFailed BuildDetectOutcome = "failed" )
type CleanupResult ¶
type CleanupResult struct {
Deleted int64
RootsDeleted int64
LinkedDeleted int64
Skipped int64
DeletedByProvider map[accountdomain.Provider]int64
}
CleanupResult summarizes rows deleted and root groups skipped by one cleanup operation.
type CleanupStatus ¶
type CleanupStatus string
const ( CleanupStatusCooldown CleanupStatus = "cooldown" CleanupStatusDisabled CleanupStatus = "disabled" CleanupStatusReauthRequired CleanupStatus = "reauthRequired" )
type CredentialStartupReport ¶
type CredentialStartupReport struct {
SchedulesBackfilled int
CriticalFound int
Refreshed int
Failed int
}
CredentialStartupReport 汇总启动阶段的凭据调度与恢复结果。
type DeviceStartResult ¶
type ExportPageResult ¶
type ExportPageResult struct {
ExportResult
NextID uint64
SnapshotMaxID uint64
HasMore bool
}
type ExportResult ¶
type ImportResult ¶
type ImportedAccountObserver ¶
type IssueSummary ¶
type ListFilter ¶
type ListFilter struct {
Provider string
QuotaType string
Status string
Egress string
Renewal string
Risk string
// Agreement applies only to grok_web accounts.
Agreement string
// Association values are provider-specific: Web supports build, console, and combined filters;
// Build and Console support only webLinked and webUnlinked.
Association string
Sort repository.SortQuery
}
type ProviderSummary ¶
type QuotaRefreshStats ¶
type QuotaStatus ¶
type QuotaStatus string
type QuotaView ¶
type QuotaView struct {
Type QuotaType
Source string
Confidence string
Unit string
Used float64
Limit float64
Remaining float64
UsagePercent float64
LimitKnown bool
WindowHours int
Observed bool
Confirmed bool
Status QuotaStatus
PeriodStart string
PeriodEnd string
ExhaustedAt *time.Time
NextProbeAt *time.Time
LastConfirmedAt *time.Time
}
type RateLimitReconcileState ¶
type RateLimitReconcileState string
const ( RateLimitReconcileInconclusive RateLimitReconcileState = "inconclusive" RateLimitReconcileRefreshing RateLimitReconcileState = "refreshing" RateLimitReconcileAvailable RateLimitReconcileState = "available" RateLimitReconcileExhausted RateLimitReconcileState = "exhausted" )
type RecoverySummary ¶
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service 负责 OAuth 账号接入、刷新、额度和持久化生命周期。
func NewService ¶
func NewService(accounts repository.AccountRepository, audits repository.AuditRepository, deviceSessions repository.DeviceSessionRepository, sticky repository.StickySessionRepository, providers *provider.Registry, cipher *security.Cipher, refreshLock repository.DistributedLock) *Service
func (*Service) AcceptWebTerms ¶
AcceptWebTerms 接受指定 Grok Web SSO 账号的上游服务协议。
func (*Service) AccountsBelongToProvider ¶
func (s *Service) AccountsBelongToProvider(ctx context.Context, ids []uint64, providerValue accountdomain.Provider) (bool, error)
AccountsBelongToProvider 校验批量账号是否全部属于指定号池。 该校验只读取账号主表,避免详情页的额度、审计或关联查询影响批量操作。
func (*Service) BatchDelete ¶
BatchDelete atomically removes roots and quota state without expanding linked accounts.
func (*Service) BatchDeleteWithLinked ¶
func (s *Service) BatchDeleteWithLinked(ctx context.Context, providerValue accountdomain.Provider, ids []uint64, targets []accountdomain.Provider) (AccountDeleteResult, error)
BatchDeleteWithLinked deletes root accounts and optional linked peers resolved from binding tables. Roots with active video jobs are skipped together with their linked group; other groups are deleted.
func (*Service) BatchRefreshBilling ¶
BatchRefreshBilling 使用有限并发刷新选中账号,避免大量账号同步时串行阻塞或无界创建 goroutine。
func (*Service) BatchRefreshQuota ¶
BatchRefreshQuota 使用有限并发同步选中 Web 或 Console 账号的额度窗口。
func (*Service) BatchRefreshTokens ¶
BatchRefreshTokens 续期指定账号的凭据;失效账号会强制向上游重试一次, 停用、Provider 不支持或缺少刷新凭据的账号会被跳过。
func (*Service) BatchResetQuotaState ¶
BatchResetQuotaState clears local Build quota recovery state without changing upstream billing snapshots or historical audit usage.
func (*Service) BatchUpdate ¶
func (s *Service) BatchUpdate(ctx context.Context, providerValue accountdomain.Provider, ids []uint64, input UpdateInput) (int64, error)
BatchUpdate 对同一号池的一组账号应用相同路由参数。
func (*Service) CleanupAccounts ¶
func (s *Service) CleanupAccounts(ctx context.Context, providerValue accountdomain.Provider, statuses []CleanupStatus, targets []accountdomain.Provider) (CleanupResult, error)
CleanupAccounts deletes accounts in selected admin states; healthy, waiting-reset, and probing accounts are excluded. Linked targets are resolved from binding tables regardless of peer state, and active-media groups are skipped whole. The ID cursor always advances, so skipped groups cannot stall a cleanup batch.
func (*Service) ClearCooldown ¶
ClearCooldown resets request-path health so a cooled account can be scheduled again. UpdateHealth publishes InvalidationAccountHealthChanged, which overwrites the selector memory overlay (runtimeStore=memory).
func (*Service) ConvertAllWebAccountsToBuild ¶
func (s *Service) ConvertAllWebAccountsToBuild(ctx context.Context) (BuildConversionResult, error)
ConvertAllWebAccountsToBuild 转换全部尚未建立 Build 关联的 Grok Web 账号。
func (*Service) ConvertAllWebAccountsToBuildWithObserver ¶
func (s *Service) ConvertAllWebAccountsToBuildWithObserver(ctx context.Context, observer ImportedAccountObserver) (BuildConversionResult, error)
func (*Service) ConvertAllWebAccountsToBuildWithProgress ¶
func (s *Service) ConvertAllWebAccountsToBuildWithProgress(ctx context.Context, observer ImportedAccountObserver, progress BatchProgressObserver) (BuildConversionResult, error)
ConvertAllWebAccountsToBuildWithProgress 转换完整未关联号池,并向调用方报告真实完成数。
func (*Service) ConvertAllWebAccountsToBuildWithStrategy ¶
func (s *Service) ConvertAllWebAccountsToBuildWithStrategy(ctx context.Context, strategy BuildConversionStrategy, observer ImportedAccountObserver, progress BatchProgressObserver) (BuildConversionResult, error)
func (*Service) ConvertWebAccountsToBuild ¶
func (s *Service) ConvertWebAccountsToBuild(ctx context.Context, ids []uint64) (BuildConversionResult, error)
ConvertWebAccountsToBuild 使用 Web SSO 自动完成 xAI Device Flow,并建立唯一的 Web/Build 账号关联。
func (*Service) ConvertWebAccountsToBuildWithObserver ¶
func (s *Service) ConvertWebAccountsToBuildWithObserver(ctx context.Context, ids []uint64, observer ImportedAccountObserver) (BuildConversionResult, error)
func (*Service) ConvertWebAccountsToBuildWithProgress ¶
func (s *Service) ConvertWebAccountsToBuildWithProgress(ctx context.Context, ids []uint64, observer ImportedAccountObserver, progress BatchProgressObserver) (BuildConversionResult, error)
ConvertWebAccountsToBuildWithProgress 转换指定账号,并向调用方报告真实完成数。
func (*Service) ConvertWebAccountsToBuildWithStrategy ¶
func (s *Service) ConvertWebAccountsToBuildWithStrategy(ctx context.Context, ids []uint64, strategy BuildConversionStrategy, observer ImportedAccountObserver, progress BatchProgressObserver) (BuildConversionResult, error)
func (*Service) DecrementQuota ¶
func (*Service) DecrementWebQuota ¶
func (*Service) DeleteWithLinked ¶
func (s *Service) DeleteWithLinked(ctx context.Context, providerValue accountdomain.Provider, id uint64, targets []accountdomain.Provider) (AccountDeleteResult, error)
DeleteWithLinked deletes one account and optional linked peers. A single delete is rejected if any account in the final group has an active video job.
func (*Service) DetectBuildAccountsWithProgress ¶
func (s *Service) DetectBuildAccountsWithProgress(ctx context.Context, ids []uint64, all bool, progress BatchProgressObserver, itemObserver BuildDetectItemObserver) (int, int, error)
DetectBuildAccountsWithProgress 对指定或全部 Grok Build 账号发起探测请求;all 与 ids 必须且只能提供一个。 该方法同时上报批量进度与单账号明细。 itemObserver 在每个账号完成后串行调用:选中检测会推送全部结果,全量检测仅推送已确认失效账号。
func (*Service) EnableWebNSFW ¶
EnableWebNSFW 为指定 Grok Web SSO 账号设置随机生日后开启成人内容显示偏好。
func (*Service) EnsureCredential ¶
func (s *Service) EnsureCredential(ctx context.Context, value accountdomain.Credential, force bool) (accountdomain.Credential, error)
EnsureCredential 在即将过期时刷新 token,同一账号并发请求只执行一次刷新。
func (*Service) ExhaustQuota ¶
func (*Service) ExhaustWebQuota ¶
func (*Service) ExportCredentials ¶
func (s *Service) ExportCredentials(ctx context.Context) (ExportResult, error)
ExportCredentials 保留 Grok Build 默认导出语义,供旧调用方兼容。
func (*Service) ExportProviderCredentials ¶
func (s *Service) ExportProviderCredentials(ctx context.Context, providerValue accountdomain.Provider) (ExportResult, error)
ExportProviderCredentials 导出可由对应 Provider 导入接口重新读取的凭据文档。
func (*Service) ExportProviderCredentialsByIDs ¶
func (s *Service) ExportProviderCredentialsByIDs(ctx context.Context, providerValue accountdomain.Provider, ids []uint64) (ExportResult, error)
ExportProviderCredentialsByIDs 只导出管理端明确选择且属于指定 Provider 的账号。
func (*Service) ExportProviderCredentialsCursor ¶
func (s *Service) ExportProviderCredentialsCursor(ctx context.Context, providerValue accountdomain.Provider, afterID, snapshotMaxID uint64, limit int) (ExportPageResult, error)
ExportProviderCredentialsCursor exports a stable provider batch bounded by the maximum account ID captured by the first request.
func (*Service) HasBillingSnapshot ¶
HasBillingSnapshot 判断账号是否已经完成过一次额度同步,不触发任何上游请求。
func (*Service) HasQuotaWindows ¶
func (*Service) ImportConsoleCredentialDocumentsWithProgress ¶
func (s *Service) ImportConsoleCredentialDocumentsWithProgress(ctx context.Context, documents [][]byte, observer ImportedAccountObserver, progress BatchProgressObserver) (ImportResult, error)
func (*Service) ImportConsoleCredentials ¶
func (*Service) ImportConsoleCredentialsWithObserver ¶
func (s *Service) ImportConsoleCredentialsWithObserver(ctx context.Context, data []byte, observer ImportedAccountObserver) (ImportResult, error)
func (*Service) ImportConsoleCredentialsWithProgress ¶
func (s *Service) ImportConsoleCredentialsWithProgress(ctx context.Context, data []byte, observer ImportedAccountObserver, progress BatchProgressObserver) (ImportResult, error)
func (*Service) ImportCredentialDocumentsWithProgress ¶
func (s *Service) ImportCredentialDocumentsWithProgress(ctx context.Context, documents [][]byte, observer ImportedAccountObserver, progress BatchProgressObserver) (ImportResult, error)
ImportCredentialDocumentsWithProgress 合并解析多个 Build 凭据文件,并作为一个批次写入和同步。
func (*Service) ImportCredentials ¶
ImportCredentials 导入用户上传的 OAuth 账号凭据。
func (*Service) ImportCredentialsWithObserver ¶
func (s *Service) ImportCredentialsWithObserver(ctx context.Context, data []byte, observer ImportedAccountObserver) (ImportResult, error)
func (*Service) ImportCredentialsWithProgress ¶
func (s *Service) ImportCredentialsWithProgress(ctx context.Context, data []byte, observer ImportedAccountObserver, progress BatchProgressObserver) (ImportResult, error)
ImportCredentialsWithProgress 导入 Build 凭据并报告已写入流水线的账号数。
func (*Service) ImportWebCredentialDocumentsWithProgress ¶
func (s *Service) ImportWebCredentialDocumentsWithProgress(ctx context.Context, documents [][]byte, observer ImportedAccountObserver, progress BatchProgressObserver) (ImportResult, error)
ImportWebCredentialDocumentsWithProgress 合并解析多个 Web JSON 或 SSO 文本文件,并作为一个批次写入和同步。
func (*Service) ImportWebCredentials ¶
ImportWebCredentials 导入版本化或旧号池格式的 Grok Web SSO 凭据。
func (*Service) ImportWebCredentialsWithObserver ¶
func (s *Service) ImportWebCredentialsWithObserver(ctx context.Context, data []byte, observer ImportedAccountObserver) (ImportResult, error)
func (*Service) ImportWebCredentialsWithProgress ¶
func (s *Service) ImportWebCredentialsWithProgress(ctx context.Context, data []byte, observer ImportedAccountObserver, progress BatchProgressObserver) (ImportResult, error)
ImportWebCredentialsWithProgress 导入 Web 凭据并报告已写入流水线的账号数。
func (*Service) ListBuildBotFlaggedAccountIDs ¶
ListBuildBotFlaggedAccountIDs returns Build account IDs whose access-token claims mark bot_flag_source/bfs as 1 or 2. Used by routing to optionally exclude them.
func (*Service) ListDueQuotaWindows ¶
func (s *Service) ListDueQuotaWindows(ctx context.Context, now time.Time, limit int) ([]accountdomain.QuotaWindow, error)
func (*Service) ListDueWebQuotaWindows ¶
func (s *Service) ListDueWebQuotaWindows(ctx context.Context, now time.Time, limit int) ([]accountdomain.QuotaWindow, error)
func (*Service) MarkBuildAPIFallback ¶
MarkBuildAPIFallback 幂等写入 Build 账号 XAI 推理回退标记;失败不吞掉,调用方可重试。
func (*Service) MarkReauthRequired ¶
func (*Service) ObserveResponseModel ¶
func (*Service) PollDeviceLogin ¶
PollDeviceLogin 执行一次上游轮询,成功后立即加密并写入账号仓储。
func (*Service) PreviewCleanup ¶
func (s *Service) PreviewCleanup(ctx context.Context, providerValue accountdomain.Provider, statuses []CleanupStatus, targets []accountdomain.Provider) (repository.CleanupPreview, error)
PreviewCleanup returns root and linked-peer counts for the cleanup confirmation dialog. The preview is informational; deletion revalidates state inside each transaction.
func (*Service) PreviewLinkedDelete ¶
func (s *Service) PreviewLinkedDelete(ctx context.Context, providerValue accountdomain.Provider, ids []uint64, targets []accountdomain.Provider) (repository.LinkedDeleteResolution, error)
PreviewLinkedDelete returns root/linked counts for the delete confirmation UI.
func (*Service) ProbePaidQuota ¶
func (s *Service) ProbePaidQuota(ctx context.Context, value accountdomain.Credential) (bool, error)
ProbePaidQuota 在真实账期到期后执行一次 Billing 探测,不消耗模型额度。
func (*Service) ProbeQuotaMode ¶
func (s *Service) ProbeQuotaMode(ctx context.Context, id uint64, mode string) (accountdomain.QuotaWindow, error)
ProbeQuotaMode refreshes a claimed recovery event without scheduling a second event for the same account and mode. The recovery worker owns the current claim and is responsible for acknowledging or rescheduling it.
func (*Service) ProviderDefinition ¶
func (s *Service) ProviderDefinition(value accountdomain.Provider) (provider.Definition, bool)
ProviderDefinition 向账号同步编排层暴露只读生命周期策略,不泄露具体 Adapter。
func (*Service) QueueQuotaRefresh ¶
QueueQuotaRefresh asynchronously refreshes the remote quota window after a successful request.
func (*Service) QuotaRefreshStats ¶
func (s *Service) QuotaRefreshStats() QuotaRefreshStats
func (*Service) RebuildBuildBotFlagIndex ¶
RebuildBuildBotFlagIndex backfills persisted non-sensitive routing metadata before the gateway begins serving traffic. Subsequent imports and refreshes update the source atomically with the encrypted access token.
func (*Service) ReconcileCredentialSchedules ¶
ReconcileCredentialSchedules 为升级前账号补齐持久化调度,不解密凭据,也不访问上游。
func (*Service) ReconcileRateLimit ¶
func (s *Service) ReconcileRateLimit(ctx context.Context, id uint64, mode string, retryAfter time.Duration) (RateLimitReconcileState, error)
ReconcileRateLimit 根据额度模式核实 429。Web 周池和 Console 均以上游快照为准;Console 的 resource-exhausted 还可能表示瞬时 RPS/RPM 限流,不能在未查询 /usage 时直接将账号冻结 24 小时。
func (*Service) ReconcileWebRateLimit ¶
func (*Service) RecoverCriticalCredentials ¶
func (s *Service) RecoverCriticalCredentials(ctx context.Context, expiresWithin time.Duration, limit int) (CredentialStartupReport, error)
RecoverCriticalCredentials 在启动预算内仅恢复缺失、已过期、两分钟内到期或失败重试到期的凭据。
func (*Service) RefreshAllTokens ¶
RefreshAllTokens 续期所有声明支持刷新的 Provider 凭据,不可续期账号会被跳过。
func (*Service) RefreshAllTokensWithProgress ¶
func (*Service) RefreshBilling ¶
func (*Service) RefreshQuota ¶
func (s *Service) RefreshQuota(ctx context.Context, id uint64) ([]accountdomain.QuotaWindow, error)
func (*Service) RefreshQuotaMode ¶
func (s *Service) RefreshQuotaMode(ctx context.Context, id uint64, mode string) (accountdomain.QuotaWindow, error)
func (*Service) RefreshToken ¶
func (*Service) RefreshWebQuota ¶
func (s *Service) RefreshWebQuota(ctx context.Context, id uint64) ([]accountdomain.QuotaWindow, error)
func (*Service) ResetAllBuildQuotaState ¶
ResetAllBuildQuotaState clears local quota state for every enabled Build account without materializing the complete account ID set in memory.
func (*Service) RunAccountAutoClean ¶
RunAccountAutoClean 在启用时周期性删除过期的 reauthRequired 账号;默认关闭。 timer 绑定配置 revision,旧 timer 即使与热更新同时就绪也只能重排,不能使用新配置执行删除。
func (*Service) RunAllWebAccountScriptsWithProgress ¶
func (s *Service) RunAllWebAccountScriptsWithProgress(ctx context.Context, options WebAccountScriptOptions, progress BatchProgressObserver) (int, int, error)
RunAllWebAccountScriptsWithProgress 分页处理完整 Web 号池,避免一次性加载全部账号。
func (*Service) RunCredentialRefresh ¶
RunCredentialRefresh 使用单个 Timer 和数据库到期索引驱动刷新,内存占用与账号总数无关。
func (*Service) RunQuotaRefresh ¶
RunQuotaRefresh uses a fixed worker set to avoid unbounded goroutine creation.
func (*Service) RunWebAccountScriptsWithProgress ¶
func (s *Service) RunWebAccountScriptsWithProgress(ctx context.Context, ids []uint64, options WebAccountScriptOptions, progress BatchProgressObserver) (int, int, error)
RunWebAccountScriptsWithProgress 为指定 Web 账号并发执行所选脚本,并按账号报告进度。
func (*Service) SetBulkPool ¶
func (*Service) SetConcurrencyLimiter ¶
func (s *Service) SetConcurrencyLimiter(value repository.ConcurrencyLimiter)
SetConcurrencyLimiter 让账号维护任务读取与推理路由相同的活动租约。
func (*Service) SetDetectPool ¶
SetDetectPool 绑定管理端「检测账号」专用并发池;nil 时保留现有池。
func (*Service) SetObservedModelStore ¶
func (s *Service) SetObservedModelStore(value repository.ObservedModelStateRepository)
SetObservedModelStore enables best-effort cross-instance duplicate suppression.
func (*Service) SetQuotaRecoveryQueue ¶
func (s *Service) SetQuotaRecoveryQueue(queue repository.QuotaRecoveryQueue)
func (*Service) SetQuotaRefreshCoordinator ¶
func (s *Service) SetQuotaRefreshCoordinator(value repository.QuotaRefreshCoordinator)
func (*Service) SetTaskPools ¶
SetTaskPools 为转换、同步和凭据刷新绑定独立分类并发池。
func (*Service) SetWebBirthDate ¶
SetWebBirthDate 为指定 Grok Web SSO 账号生成并设置 20–40 岁的随机生日。
func (*Service) StartDeviceLogin ¶
func (s *Service) StartDeviceLogin(ctx context.Context) (DeviceStartResult, error)
StartDeviceLogin 启动短期 Device OAuth,会话只保存在有界运行态存储中。
func (*Service) SyncAccountIdentity ¶
SyncAccountIdentity best-effort fills stable Web/Console identity metadata and reconciles trusted links. Definitive unauthorized signals mark the current Provider account as reauthRequired and remove it from scheduling; other synchronization failures do not affect account health.
func (*Service) SyncAllBilling ¶
SyncAllBilling 尽力刷新全部启用账号,单个账号失败不阻断其他账号。
func (*Service) SyncAllBillingWithProgress ¶
func (*Service) SyncAllConsoleQuotas ¶
func (*Service) SyncAllConsoleQuotasWithProgress ¶
func (*Service) SyncAllWebAccountsToConsoleWithProgress ¶
func (s *Service) SyncAllWebAccountsToConsoleWithProgress(ctx context.Context, observer ImportedAccountObserver, progress BatchProgressObserver) (ImportResult, error)
SyncAllWebAccountsToConsoleWithProgress 同步完整 Web 号池,避免前端分页遗漏账号。
func (*Service) SyncAllWebAccountsToConsoleWithStrategy ¶
func (s *Service) SyncAllWebAccountsToConsoleWithStrategy(ctx context.Context, strategy WebConsoleSyncStrategy, observer ImportedAccountObserver, progress BatchProgressObserver) (ImportResult, error)
func (*Service) SyncAllWebQuotas ¶
SyncAllWebQuotas 尽力同步全部启用 Grok Web 账号的分模式额度。
func (*Service) SyncAllWebQuotasWithProgress ¶
func (*Service) SyncIncompleteConsoleQuotas ¶
SyncIncompleteConsoleQuotas replaces pre-/usage synthetic windows and partial snapshots without refreshing accounts that already have all three authoritative Console quota kinds. It is safe to run periodically and uses the shared sync pool to preserve the deployment-wide upstream limit.
func (*Service) SyncStaleConsoleQuotas ¶
func (s *Service) SyncStaleConsoleQuotas(ctx context.Context, before time.Time, afterID uint64, limit int) (int, int, uint64, error)
SyncStaleConsoleQuotas refreshes a bounded batch of complete but old /usage snapshots. Active accounts are already refreshed after successful requests; this catch-up covers idle pools without turning a large deployment into a periodic upstream request burst.
func (*Service) SyncWebAccountsToConsoleWithProgress ¶
func (s *Service) SyncWebAccountsToConsoleWithProgress(ctx context.Context, ids []uint64, observer ImportedAccountObserver, progress BatchProgressObserver) (ImportResult, error)
SyncWebAccountsToConsoleWithProgress 使用 Web 账号的同一份 SSO 创建或更新 Console 账号。
func (*Service) SyncWebAccountsToConsoleWithStrategy ¶
func (s *Service) SyncWebAccountsToConsoleWithStrategy(ctx context.Context, ids []uint64, strategy WebConsoleSyncStrategy, observer ImportedAccountObserver, progress BatchProgressObserver) (ImportResult, error)
func (*Service) SyncWebQuotaAccounts ¶
SyncWebQuotaAccounts 同步指定 Web 账号集合,供启动追赶任务复用共享并发池。
func (*Service) UpdateAutoCleanConfig ¶
func (s *Service) UpdateAutoCleanConfig(value AutoCleanConfig)
UpdateAutoCleanConfig 热更新账号自动清理策略。 仅在策略实际变化时唤醒调度器;唤醒只重排 timer,不会直接硬删。
func (*Service) UpdateExcludeBuildBotFlaggedFromScheduling ¶
UpdateExcludeBuildBotFlaggedFromScheduling hot-updates whether bot-risk Build accounts are treated as non-schedulable in account summary available counts.
func (*Service) WakeCredentialRefresh ¶
func (s *Service) WakeCredentialRefresh()
WakeCredentialRefresh 合并调度唤醒;导入、手动刷新和失败退避更新不会阻塞调用方。
type Summary ¶
type Summary struct {
Total int64
Available int64
Recovering int64
Attention int64
Risk int64
Providers map[string]ProviderSummary
Recovery RecoverySummary
Issues IssueSummary
}
type UpdateInput ¶
type UpdateInput struct {
Name *string
Enabled *bool
Priority *int
MaxConcurrent *int
MinimumRemaining *float64
CloudflareCookies *string
ClearCloudflareCookies bool
// BuildSuperEntitled 仅 grok_build 可设置;非 Build 返回业务错误。
BuildSuperEntitled *bool
// BuildRouteMode 仅 grok_build 可设置;nil 表示不修改。
BuildRouteMode *accountdomain.BuildRouteMode
}
type View ¶
type View struct {
Credential accountdomain.Credential
Billing *accountdomain.Billing
Quota QuotaView
QuotaWindows []accountdomain.QuotaWindow
BuildBotFlagged bool
BuildBotFlagSource int
// EnabledChanged is request-scoped update metadata. It is not persisted or
// serialized directly; the HTTP layer uses it to avoid warning when a PATCH
// merely repeats the account's existing enabled value.
EnabledChanged bool
}
type WebAccountScriptOptions ¶
WebAccountScriptOptions 定义 Grok Web 账号脚本需要执行的步骤。 EnableNSFW 会隐式启用 SetBirthDate,保证上游年龄前置条件成立。
type WebConsoleSyncStrategy ¶
type WebConsoleSyncStrategy string
const ( WebConsoleSyncAll WebConsoleSyncStrategy = "all" WebConsoleSyncMissing WebConsoleSyncStrategy = "missing" )