Documentation
¶
Index ¶
- type APICallRequest
- type APICallResponse
- type Config
- type CredentialType
- type Entry
- type FetchFunc
- type InternalAPICallFunc
- type QuotaStatus
- type Scheduler
- func (s *Scheduler) GetConfig() Config
- func (s *Scheduler) GetStatus() StatusResponse
- func (s *Scheduler) RefreshNow(fileNames []string)
- func (s *Scheduler) Register(fileName string, credType CredentialType, authIndex string)
- func (s *Scheduler) SetDisabled(fileName string, disabled bool)
- func (s *Scheduler) Start()
- func (s *Scheduler) Stop()
- func (s *Scheduler) Unregister(fileName string)
- func (s *Scheduler) UpdateAuthIndex(fileName, authIndex string)
- func (s *Scheduler) UpdateConfig(cfg Config)
- type StatusResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APICallRequest ¶
type APICallRequest struct {
URL string `json:"url"`
Method string `json:"method"`
Header map[string]string `json:"header,omitempty"`
AuthIndex string `json:"auth_index,omitempty"`
Data string `json:"data,omitempty"`
}
APICallRequest matches the management API's POST /api-call body format.
type APICallResponse ¶
type APICallResponse struct {
StatusCode int `json:"status_code"`
Body json.RawMessage `json:"body,omitempty"`
BodyText string `json:"bodyText,omitempty"`
}
APICallResponse matches the management API's response format.
type Config ¶
type Config struct {
Enabled bool `yaml:"enabled" json:"enabled"`
Interval int `yaml:"interval" json:"interval"` // seconds, default 600
MaxInterval int `yaml:"max-interval" json:"max-interval"` // seconds, default 1800
}
Config holds the quota refresh scheduler configuration.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns the default quota refresh configuration. Enabled defaults to false (R-095): auto-polling provider endpoints risks triggering anti-abuse detection. Frontend shows a confirmation dialog on opt-in (GlobalSettings.tsx:67).
type CredentialType ¶
type CredentialType string
CredentialType identifies which provider a credential belongs to.
const ( TypeClaude CredentialType = "claude" TypeCodex CredentialType = "codex" TypeGeminiCli CredentialType = "gemini-cli" TypeAntigravity CredentialType = "antigravity" TypeKimi CredentialType = "kimi" )
type Entry ¶
type Entry struct {
FileName string `json:"file_name"`
Type CredentialType `json:"type"`
AuthIndex string `json:"auth_index,omitempty"` // credential identifier for api-call proxy
Status QuotaStatus `json:"status"`
LastRefresh *time.Time `json:"last_refresh"`
NextRefresh *time.Time `json:"next_refresh"`
Error string `json:"error,omitempty"`
FailureCount int `json:"failure_count"`
Data json.RawMessage `json:"data,omitempty"`
Disabled bool `json:"disabled,omitempty"`
// contains filtered or unexported fields
}
Entry holds the cached quota state for a single credential.
type FetchFunc ¶
FetchFunc is called to refresh quota data for a credential. It receives the entry with all credential info, returns raw JSON data or an error.
type InternalAPICallFunc ¶
type InternalAPICallFunc func(req APICallRequest) (*APICallResponse, error)
InternalAPICallFunc wraps a call to the management /api-call endpoint on localhost.
func NewLocalAPICallFunc ¶
func NewLocalAPICallFunc(port int, managementKey string) InternalAPICallFunc
NewLocalAPICallFunc creates a function that calls the management API's /api-call endpoint on the local server. This is used by the quota scheduler to fetch quota data from provider APIs via the same proxy mechanism as the frontend.
type QuotaStatus ¶
type QuotaStatus string
QuotaStatus represents the current state of a credential's quota.
const ( StatusIdle QuotaStatus = "idle" StatusLoading QuotaStatus = "loading" StatusSuccess QuotaStatus = "success" StatusError QuotaStatus = "error" StatusBanned QuotaStatus = "banned" StatusQuotaExceeded QuotaStatus = "quota_exceeded" )
Entry status values.
type Scheduler ¶
type Scheduler struct {
// contains filtered or unexported fields
}
Scheduler manages periodic quota refresh for all registered credentials. It uses a min-heap priority queue sorted by next refresh time, with a single dispatcher goroutine that serializes all fetch operations.
func NewScheduler ¶
NewScheduler creates a new quota scheduler.
func (*Scheduler) GetStatus ¶
func (s *Scheduler) GetStatus() StatusResponse
GetStatus returns the current status of all credentials.
func (*Scheduler) RefreshNow ¶
RefreshNow triggers an immediate refresh for specific credentials (or all if empty). Works even when the scheduler is disabled (manual refresh). Manual calls are serialized so later requests wait for the current refresh instead of being silently dropped.
When fileNames is non-empty the call is treated as a user-initiated manual refresh and executes every named entry regardless of disabled/banned/quota-exceeded state so the operator can verify whether an account has recovered. When fileNames is empty the call is a bulk auto-refresh and skips entries that shouldSkipAutoRefresh reports as ineligible.
func (*Scheduler) Register ¶
func (s *Scheduler) Register(fileName string, credType CredentialType, authIndex string)
Register adds or updates a credential in the scheduler.
func (*Scheduler) SetDisabled ¶
SetDisabled updates the disabled state of a registered entry and pokes the dispatcher to re-evaluate the heap. Disabled entries are skipped by the auto refresh loop; manual RefreshNow(fileNames) still executes them so users can verify whether a banned/disabled account has recovered.
func (*Scheduler) Start ¶
func (s *Scheduler) Start()
Start begins the scheduler's dispatch loop. No-op if not enabled.
func (*Scheduler) Unregister ¶
Unregister removes a credential from the scheduler.
func (*Scheduler) UpdateAuthIndex ¶
UpdateAuthIndex sets the auth_index for a registered entry.
func (*Scheduler) UpdateConfig ¶
UpdateConfig updates the scheduler configuration.