Documentation
¶
Index ¶
- Constants
- Variables
- type AccountInfo
- type AccountPool
- func (p *AccountPool) AccountReason(accountID string, modelID string) string
- func (p *AccountPool) AcquireForModel(ctx context.Context, sessionKey string, modelID string, ...) (*gemini.Client, string, func(), error)
- func (p *AccountPool) Add(client *gemini.Client, accountID string)
- func (p *AccountPool) BindSession(sessionKey string, accountID string)
- func (p *AccountPool) CatalogAccounts() []CatalogAccount
- func (p *AccountPool) Changed() <-chan struct{}
- func (p *AccountPool) ClearCooldown(accountID string, model string) error
- func (p *AccountPool) ClearSession(sessionKey string)
- func (p *AccountPool) Client(accountID string) *gemini.Client
- func (p *AccountPool) Cooldowns() []Cooldown
- func (p *AccountPool) MarkFailed(accountID string, err error) bool
- func (p *AccountPool) MarkReady(accountID string)
- func (p *AccountPool) ModelAccounts() map[string]int
- func (p *AccountPool) ModelAvailability(modelID string) ModelAvailability
- func (p *AccountPool) NextForModelExcluding(sessionKey string, modelID string, excludedAccountIDs map[string]struct{}) (*gemini.Client, string)
- func (p *AccountPool) OnCooldownChange(save func([]Cooldown))
- func (p *AccountPool) OnTransportError(fn func())
- func (p *AccountPool) RecordError(accountID string, err error)
- func (p *AccountPool) Register(accountID string, info AccountInfo, disabled bool)
- func (p *AccountPool) Remove(accountID string)
- func (p *AccountPool) ReportFailure(accountID string, modelID string, err error)
- func (p *AccountPool) ReportSuccess(accountID string, modelID string)
- func (p *AccountPool) RestoreCooldowns(cooldowns []Cooldown)
- func (p *AccountPool) RetryAfter(modelID string) time.Time
- func (p *AccountPool) SessionIdle(sessionKey string, modelID string) bool
- func (p *AccountPool) SetClient(accountID string, client *gemini.Client)
- func (p *AccountPool) SetDisabled(accountID string, disabled bool)
- func (p *AccountPool) SetProxy(accountID string, proxy string)
- func (p *AccountPool) SetStrategy(strategy string)
- func (p *AccountPool) SetTimings(cooldown time.Duration, sessionTTL time.Duration)
- func (p *AccountPool) Size() int
- func (p *AccountPool) Status() PoolStatus
- func (p *AccountPool) Usage(ctx context.Context, refresh bool) PoolUsageStatus
- type AccountStatus
- type AccountUsageStatus
- type CatalogAccount
- type Cooldown
- type ModelAvailability
- type ModelCooldown
- type PoolStatus
- type PoolUsageStatus
Constants ¶
const ( StateInitializing = "initializing" StateReady = "ready" StateCooldown = "cooldown" StateAuthRequired = "auth_required" StateDisabled = "disabled" )
账号状态
const ( // RoundRobin 在账号间轮流分配 RoundRobin = "round-robin" // FillFirst 优先使用排在前面且有空闲请求槽的账号 FillFirst = "fill-first" )
调度策略
const SourceGuest = "guest"
SourceGuest 是访客会话的来源
Variables ¶
var ErrAccountNotFound = errors.New("账号不存在")
ErrAccountNotFound 表示账号池中没有该账号
Functions ¶
This section is empty.
Types ¶
type AccountInfo ¶ added in v0.1.3
type AccountInfo struct {
// Source 为 chrome(Chrome Profile 导入,可续签)、cookie(Cookie Header 导入)或 guest(未登录的访客会话)
Source string
// Profile 为 Chrome 导入时的 Profile 目录名
Profile string
// Proxy 为账号实际使用的代理 URL
Proxy string
// ProxySource 为代理来源:fixed(账号固定代理)、direct(直连)、pool(代理池)或 system(系统代理)
ProxySource string
// Path 为认证状态文件路径
Path string
}
AccountInfo 是账号的来源与出口
type AccountPool ¶
type AccountPool struct {
// contains filtered or unexported fields
}
AccountPool 在健康账号之间调度请求并维护账号状态、冷却与显式会话粘性
func NewAccountPool ¶
func NewAccountPool(cooldown time.Duration, sessionTTL time.Duration) *AccountPool
NewAccountPool 创建账号池,轮询从随机位置开始
func (*AccountPool) AccountReason ¶ added in v0.1.6
func (p *AccountPool) AccountReason(accountID string, modelID string) string
AccountReason 返回账号不能调度该模型的原因:冷却截止时间或账号状态
func (*AccountPool) AcquireForModel ¶ added in v0.1.6
func (p *AccountPool) AcquireForModel(ctx context.Context, sessionKey string, modelID string, excludedAccountIDs map[string]struct{}) (*gemini.Client, string, func(), error)
AcquireForModel 选择可调度该模型的账号并占用一个请求槽,返回客户端、账号与释放函数;同一排队键的请求按到达顺序排队,队首在任一账号空出、就绪或状态变化后重新选择,没有可调度账号时客户端为空
func (*AccountPool) Add ¶
func (p *AccountPool) Add(client *gemini.Client, accountID string)
Add 添加一个已经完成协议初始化的账号
func (*AccountPool) BindSession ¶
func (p *AccountPool) BindSession(sessionKey string, accountID string)
BindSession 将成功响应标识绑定到产生它的账号
func (*AccountPool) CatalogAccounts ¶ added in v0.1.6
func (p *AccountPool) CatalogAccounts() []CatalogAccount
CatalogAccounts 返回已就绪或已读取模型目录的账号,用于汇总模型目录
func (*AccountPool) Changed ¶ added in v0.1.6
func (p *AccountPool) Changed() <-chan struct{}
Changed 返回账号状态下一次变化或请求槽释放时关闭的通道
func (*AccountPool) ClearCooldown ¶ added in v0.1.6
func (p *AccountPool) ClearCooldown(accountID string, model string) error
ClearCooldown 清除账号的一项冷却并保存冷却记录,model 为空时清除账号级冷却,否则清除该模型的冷却
func (*AccountPool) ClearSession ¶
func (p *AccountPool) ClearSession(sessionKey string)
ClearSession 结束显式会话的账号粘性
func (*AccountPool) Client ¶ added in v0.1.3
func (p *AccountPool) Client(accountID string) *gemini.Client
Client 返回账号的协议客户端
func (*AccountPool) Cooldowns ¶ added in v0.1.6
func (p *AccountPool) Cooldowns() []Cooldown
Cooldowns 返回尚未结束的账号与模型冷却,含尚未就绪账号待恢复的冷却
func (*AccountPool) MarkFailed ¶ added in v0.1.3
func (p *AccountPool) MarkFailed(accountID string, err error) bool
MarkFailed 把账号标为不可用或待认证并记录原因,返回状态是否变化
func (*AccountPool) MarkReady ¶ added in v0.1.3
func (p *AccountPool) MarkReady(accountID string)
MarkReady 把账号标为就绪并清除错误与冷却
func (*AccountPool) ModelAccounts ¶ added in v0.1.3
func (p *AccountPool) ModelAccounts() map[string]int
ModelAccounts 返回每个模型当前可调度的账号数
func (*AccountPool) ModelAvailability ¶ added in v0.1.6
func (p *AccountPool) ModelAvailability(modelID string) ModelAvailability
ModelAvailability 按全部账号的模型目录返回目标模型的调度情况
func (*AccountPool) NextForModelExcluding ¶
func (p *AccountPool) NextForModelExcluding(sessionKey string, modelID string, excludedAccountIDs map[string]struct{}) (*gemini.Client, string)
NextForModelExcluding 为无会话重试选择未排除的同能力账号
func (*AccountPool) OnCooldownChange ¶ added in v0.1.6
func (p *AccountPool) OnCooldownChange(save func([]Cooldown))
OnCooldownChange 登记冷却变化后保存全部冷却的函数
func (*AccountPool) OnTransportError ¶ added in v0.1.5
func (p *AccountPool) OnTransportError(fn func())
OnTransportError 设置账号遇到连接、TLS 或代理错误时调用的函数
func (*AccountPool) RecordError ¶ added in v0.1.3
func (p *AccountPool) RecordError(accountID string, err error)
RecordError 记录账号最近一次后台操作错误,不改变调度状态
func (*AccountPool) Register ¶ added in v0.1.3
func (p *AccountPool) Register(accountID string, info AccountInfo, disabled bool)
Register 登记账号,disabled 为 true 时登记为停用,否则为初始化中
func (*AccountPool) Remove ¶ added in v0.1.3
func (p *AccountPool) Remove(accountID string)
Remove 删除账号并解除其会话绑定
func (*AccountPool) ReportFailure ¶
func (p *AccountPool) ReportFailure(accountID string, modelID string, err error)
ReportFailure 按错误类型把账号或该模型移入冷却,会话失效时把账号标为待认证,网络层失败只记录错误
func (*AccountPool) ReportSuccess ¶
func (p *AccountPool) ReportSuccess(accountID string, modelID string)
ReportSuccess 清除账号与该模型的失败状态
func (*AccountPool) RestoreCooldowns ¶ added in v0.1.6
func (p *AccountPool) RestoreCooldowns(cooldowns []Cooldown)
RestoreCooldowns 恢复上次运行保存的冷却,账号尚未就绪时在就绪时恢复
func (*AccountPool) RetryAfter ¶ added in v0.1.3
func (p *AccountPool) RetryAfter(modelID string) time.Time
RetryAfter 返回目标模型最早结束冷却的时间,没有冷却中的账号时为零值
func (*AccountPool) SessionIdle ¶ added in v0.1.6
func (p *AccountPool) SessionIdle(sessionKey string, modelID string) bool
SessionIdle 判断会话绑定的账号可调度该模型且有空闲请求槽
func (*AccountPool) SetClient ¶ added in v0.1.3
func (p *AccountPool) SetClient(accountID string, client *gemini.Client)
SetClient 设置账号的协议客户端
func (*AccountPool) SetDisabled ¶ added in v0.1.3
func (p *AccountPool) SetDisabled(accountID string, disabled bool)
SetDisabled 停用或启用账号,启用后账号回到初始化中
func (*AccountPool) SetProxy ¶ added in v0.1.3
func (p *AccountPool) SetProxy(accountID string, proxy string)
SetProxy 更新账号显示的代理
func (*AccountPool) SetStrategy ¶ added in v0.1.3
func (p *AccountPool) SetStrategy(strategy string)
SetStrategy 修改无会话请求的调度策略
func (*AccountPool) SetTimings ¶ added in v0.1.3
func (p *AccountPool) SetTimings(cooldown time.Duration, sessionTTL time.Duration)
SetTimings 修改失败冷却时长与显式会话存活时长
func (*AccountPool) Usage ¶
func (p *AccountPool) Usage(ctx context.Context, refresh bool) PoolUsageStatus
Usage 返回各账号最近读取的官网用量,refresh 为 true 时并发重新读取
type AccountStatus ¶
type AccountStatus struct {
AccountID string `json:"account_id"`
State string `json:"state"`
Enabled bool `json:"enabled"`
Source string `json:"source,omitempty"`
Profile string `json:"profile,omitempty"`
Proxy string `json:"proxy,omitempty"`
ProxySource string `json:"proxy_source,omitempty"`
Tier string `json:"tier,omitempty"`
ContextWindow int `json:"context_window,omitempty"`
Models []string `json:"models"`
Pending int `json:"pending"`
LastUsed *time.Time `json:"last_used,omitempty"`
ReadyAt *time.Time `json:"ready_at,omitempty"`
CooldownUntil *time.Time `json:"cooldown_until,omitempty"`
CooldownReason string `json:"cooldown_reason,omitempty"`
ModelCooldowns []ModelCooldown `json:"model_cooldowns,omitempty"`
ConsecutiveFails int `json:"consecutive_failures"`
LastError string `json:"last_error,omitempty"`
LastErrorAt *time.Time `json:"last_error_at,omitempty"`
Usage *gemini.UsageInfo `json:"usage,omitempty"`
}
AccountStatus 是账号的调度状态、层级、冷却与最近错误
type AccountUsageStatus ¶
type AccountUsageStatus struct {
AccountID string `json:"account_id"`
State string `json:"state"`
Usage *gemini.UsageInfo `json:"usage,omitempty"`
Error string `json:"error,omitempty"`
}
AccountUsageStatus 表示单个账号的官网用量
type CatalogAccount ¶ added in v0.1.6
CatalogAccount 是一个已就绪或已读取模型目录的账号,Ready 表示已就绪
type ModelAvailability ¶ added in v0.1.6
type ModelAvailability struct {
// Catalog 表示至少一个账号已就绪或已读取模型目录
Catalog bool
// Known 表示至少一个账号的模型目录含该模型
Known bool
// Ready 表示有可调度该模型的账号
Ready bool
// Reasons 为不可调度时支持该模型的各账号的原因
Reasons []string
// Pending 为尚未读取模型目录的未停用账号的状态
Pending []string
}
ModelAvailability 是目标模型在账号池中的调度情况
type ModelCooldown ¶ added in v0.1.3
type ModelCooldown struct {
Model string `json:"model"`
Until time.Time `json:"until"`
Reason string `json:"reason"`
}
ModelCooldown 是单个模型的冷却
type PoolStatus ¶
type PoolStatus struct {
Total int `json:"total"`
Available int `json:"available"`
CoolingDown int `json:"cooling_down"`
Initializing int `json:"initializing"`
AuthRequired int `json:"auth_required"`
Disabled int `json:"disabled"`
Accounts []AccountStatus `json:"accounts"`
// Guest 是访客会话的状态,不计入账号数
Guest *AccountStatus `json:"guest,omitempty"`
}
PoolStatus 汇总账号池状态
func (PoolStatus) Ready ¶ added in v0.1.3
func (s PoolStatus) Ready() bool
Ready 报告是否有就绪的账号或访客会话可以接收请求
type PoolUsageStatus ¶
type PoolUsageStatus struct {
Accounts []AccountUsageStatus `json:"accounts"`
}
PoolUsageStatus 汇总账号池官网用量