Files
codex-proxy-rs/frontend/src/api/modules/settings/index.ts
T
ZyyandCodex 620db1b877 feat(openai): simplify account warmup scheduling
Use a single five-field Cron expression and allow lightweight warmup when
quota windows lack active evidence, without extra quota refreshes.
Reset saved schedules and disable warmup in migration 0040 while keeping
the configured model.

Co-authored-by: Codex <noreply@openai.com>
2026-11-09 16:15:35 +08:00

163 lines
4.5 KiB
TypeScript

import type { RequestOptions } from '../../request'
import type { RequestLocation, RequestLocationDetection } from '../../types/location'
import type { CodexPrivacyPolicy } from './privacy'
import type { ClientProfileSelection, ProviderRequestProfiles, ProviderRequestProfileUpdates, XaiClientProfileSelection } from './profiles'
import type { AccountErrorProtection } from './protection'
import request from '../../request'
export * from './backups'
export * from './pricing'
export * from './privacy'
export * from './protection'
export * from './system'
export function detectRequestLocation() {
return request<RequestLocationDetection>({
url: '/api/admin/settings/location/detect',
method: 'POST',
timeout: 25000,
})
}
export type AccountAffinity = 'relaxed' | 'preferred' | 'strict'
export type RotationStrategy = 'smart' | 'quota_reset_priority' | 'round_robin' | 'sticky'
export interface SmartSchedulingConfig {
loadWeight: number
quotaWeight: number
healthWeight: number
latencyWeight: number
resetWeight: number
queueWeight: number
}
export interface RuntimeSettings {
configRevision: number
smartScheduling: SmartSchedulingConfig
smartSchedulingDefaults: SmartSchedulingConfig
providerRequestProfiles: ProviderRequestProfiles
openaiClientProfile: ClientProfileSelection | null
xaiClientProfile: XaiClientProfileSelection | null
codexPrivacyPolicy: CodexPrivacyPolicy
requestLocationEnabled: boolean
requestLocation: RequestLocation
modelMappings: Record<string, string>
refreshMarginSeconds: number
refreshConcurrency: number
maxConcurrentPerAccount: number
openaiGuardianReservedConcurrency: number
openaiAccountAffinity: AccountAffinity
maxAccountRotations: number
openaiSessionAffinityTtlHours: number
maxWaitingPerKey: number
maxWaitingPerAccount: number
keyQueueTimeoutSeconds: number
accountQueueTimeoutSeconds: number
switchAccountOnQueueFailure: boolean
maxRetryAfterSeconds: number
responsesMaxDecompressedBodyBytes: number
rotationStrategy: RotationStrategy
minCodexDesktopVersion: string | null
minCodexCliVersion: string | null
usageRetentionDays: number
opsEventRetentionDays: number
auditRetentionDays: number
accountErrorProtection: AccountErrorProtection
accountWarmupEnabled: boolean
accountWarmupCron: string
accountWarmupModel: string | null
resetCreditLeadMinutes: number
resetCreditMaxWeeklyRemainingPercent: number | null
updatedAt: string
updatedAtDisplay: string
}
export type ClientArchitecture = 'x64' | 'arm64'
export type ClientDownloadSource = 'microsoft_store' | 'official_openai'
export interface ClientDownloadPackage {
architecture: ClientArchitecture
source: ClientDownloadSource
version: string | null
fileName: string
sizeBytes: number | null
downloadUrl: string
expiresAt: string | null
expiresAtDisplay: string | null
}
export interface CodexDesktopWindowsDownloads {
resolvedAt: string
resolvedAtDisplay: string
cached: boolean
warning: string | null
packages: ClientDownloadPackage[]
}
export interface AdminApiKeyStatus {
exists: boolean
}
export interface RegeneratedAdminApiKey {
key: string
}
export interface DeletedAdminApiKey {
message: string
}
export function getSettings(options: RequestOptions = {}) {
return request<RuntimeSettings>({
url: '/api/admin/settings',
method: 'GET',
...options,
})
}
type UpdateSettingsParam = Omit<RuntimeSettings, 'updatedAt' | 'updatedAtDisplay' | 'smartSchedulingDefaults' | 'openaiClientProfile' | 'xaiClientProfile' | 'providerRequestProfiles'> & {
providerRequestProfiles: ProviderRequestProfileUpdates
}
export function updateSettings(data: UpdateSettingsParam) {
return request<RuntimeSettings>({
url: '/api/admin/settings/update',
method: 'POST',
data,
})
}
export function getAdminApiKeyStatus() {
return request<AdminApiKeyStatus>({
url: '/api/admin/settings/admin-api-key',
method: 'GET',
})
}
export function regenerateAdminApiKey() {
return request<RegeneratedAdminApiKey>({
url: '/api/admin/settings/admin-api-key/regenerate',
method: 'POST',
})
}
export function deleteAdminApiKey() {
return request<DeletedAdminApiKey>({
url: '/api/admin/settings/admin-api-key/delete',
method: 'POST',
})
}
interface CodexDesktopWindowsDownloadsParams {
refresh?: boolean
}
export function getCodexDesktopWindowsDownloads(data: CodexDesktopWindowsDownloadsParams = {}) {
return request<CodexDesktopWindowsDownloads>({
url: '/api/admin/settings/client-downloads/codex-desktop/windows',
method: 'GET',
params: data,
})
}