Files
codex-proxy-rs/frontend/src/api/modules/settings/index.ts
T
ZyyandCodex b02f13c9cc refactor(admin)!: remove legacy management API fields
Use provider profile maps, saved proxy IDs, and structured dashboard metrics across the admin API and UI. Require the quota reset mode on full settings updates.

Migrate existing Redis freezes atomically with cooldown writes and reuse validated OpenAI credentials during runtime decoding.

Co-authored-by: Codex <noreply@openai.com>
2026-11-20 21:38:58 +08:00

177 lines
4.9 KiB
TypeScript

import type { RequestOptions } from '../../request'
import type { RequestLocation, RequestLocationDetection } from '../../types/location'
import type { CodexPrivacyPolicy } from './privacy'
import type { ProviderRequestProfiles, ProviderRequestProfileUpdates } 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 ResetWindowWeights {
fiveHour: number
weekly: number
monthly: number
}
export interface SmartSchedulingConfig {
loadWeight: number
quotaWeight: number
healthWeight: number
latencyWeight: number
resetWeight: number
queueWeight: number
resetWindowWeights: ResetWindowWeights
}
export type OpenAiRequestCountry
= | { mode: 'default' | 'passthrough' | 'follow_location' }
| { mode: 'custom', country: string }
export interface RuntimeSettings {
configRevision: number
smartScheduling: SmartSchedulingConfig
smartSchedulingDefaults: SmartSchedulingConfig
quotaResetWindowWeights: ResetWindowWeights
quotaResetWindowWeightsDefaults: ResetWindowWeights
providerRequestProfiles: ProviderRequestProfiles
codexPrivacyPolicy: CodexPrivacyPolicy
openaiRequestCountry: OpenAiRequestCountry
requestLocationEnabled: boolean
requestLocation: RequestLocation
openaiOauthGuardianReviewModel: boolean
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
resetCreditOnLowWeeklyQuota: boolean
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' | 'quotaResetWindowWeightsDefaults' | '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,
})
}