From 51cb038fd307966a96f0309f4d51ad7fb367eee0 Mon Sep 17 00:00:00 2001 From: Codex Date: Tue, 9 Jun 2026 06:28:40 +0000 Subject: [PATCH] feat: support codex pool account priority --- config/platform-infra/sub2api-codex-pool.yaml | 1 + scripts/src/platform-infra-sub2api-codex.ts | 20 ++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/config/platform-infra/sub2api-codex-pool.yaml b/config/platform-infra/sub2api-codex-pool.yaml index 1b137be4..948c3eed 100644 --- a/config/platform-infra/sub2api-codex-pool.yaml +++ b/config/platform-infra/sub2api-codex-pool.yaml @@ -20,6 +20,7 @@ profiles: accountName: unidesk-codex-gptclub configFile: config.toml.gptclub authFile: auth.json.gptclub + priority: 100 - profile: fixwikihub accountName: unidesk-codex-fixwikihub configFile: config.toml.fixwikihub diff --git a/scripts/src/platform-infra-sub2api-codex.ts b/scripts/src/platform-infra-sub2api-codex.ts index 52dbc649..4afef069 100644 --- a/scripts/src/platform-infra-sub2api-codex.ts +++ b/scripts/src/platform-infra-sub2api-codex.ts @@ -46,6 +46,7 @@ interface CodexProfile { apiKeySource: "auth-json" | "env" | null; openaiResponsesWebSocketsV2Mode: OpenAIResponsesWebSocketsV2Mode | null; upstreamUserAgent: string | null; + priority: number; authOpenAIKeyShape: string; ok: boolean; error: string | null; @@ -73,6 +74,7 @@ interface CodexPoolProfileConfig { fallbackAuthFile: string | null; openaiResponsesWebSocketsV2Mode: OpenAIResponsesWebSocketsV2Mode | null; upstreamUserAgent: string | null; + priority: number; } interface CodexPoolPublicExposureConfig { @@ -240,6 +242,7 @@ async function codexPoolSync(config: UniDeskConfig, options: SyncOptions): Promi apiKeyFingerprint: fingerprint(profile.apiKey ?? ""), openaiResponsesWebSocketsV2Mode: profile.openaiResponsesWebSocketsV2Mode, upstreamUserAgent: profile.upstreamUserAgent, + priority: profile.priority, })), }; const result = await capture(config, g14K3sRoute, ["script"], syncScript(payload, pool)); @@ -422,6 +425,7 @@ function collectCodexProfiles(): CodexProfile[] { apiKeySource: null, openaiResponsesWebSocketsV2Mode: entry.openaiResponsesWebSocketsV2Mode, upstreamUserAgent: entry.upstreamUserAgent, + priority: entry.priority, authOpenAIKeyShape: existsSync(authPath) ? "unknown" : "missing", ok: false, error: null, @@ -486,6 +490,7 @@ function discoverCodexProfileConfigs(codexDir: string): CodexPoolProfileConfig[] fallbackAuthFile: null, openaiResponsesWebSocketsV2Mode: null, upstreamUserAgent: null, + priority: 1, }; }); } @@ -582,6 +587,7 @@ function readProfileConfig(value: unknown, defaults: CodexPoolProfileConfig[]): if (fallbackAuthFile !== null) validateCodexFileName(fallbackAuthFile, `profiles.entries[${index}].fallbackAuthFile`); const openaiResponsesWebSocketsV2Mode = readOpenAIResponsesWebSocketsV2Mode(entry.openaiResponsesWebSocketsV2Mode, `profiles.entries[${index}].openaiResponsesWebSocketsV2Mode`); const upstreamUserAgent = readUpstreamUserAgent(entry.upstreamUserAgent, `profiles.entries[${index}].upstreamUserAgent`); + const priority = readAccountPriority(entry.priority, `profiles.entries[${index}].priority`); return { profile, accountName, @@ -591,6 +597,7 @@ function readProfileConfig(value: unknown, defaults: CodexPoolProfileConfig[]): fallbackAuthFile, openaiResponsesWebSocketsV2Mode, upstreamUserAgent, + priority, }; }); } @@ -612,6 +619,15 @@ function readUpstreamUserAgent(value: unknown, key: string): string | null { return text; } +function readAccountPriority(value: unknown, key: string): number { + if (value === undefined || value === null) return 1; + const priority = numberValue(value); + if (priority === null || !Number.isInteger(priority) || priority < 0 || priority > 1000) { + throw new Error(`${codexPoolConfigPath}.${key} must be an integer from 0 to 1000`); + } + return priority; +} + function readPublicExposureConfig(value: unknown, defaults: CodexPoolPublicExposureConfig): CodexPoolPublicExposureConfig { if (!isRecord(value)) return defaults; const masterFrpsValue = isRecord(value.masterFrps) ? value.masterFrps : {}; @@ -713,6 +729,7 @@ function redactProfile(profile: CodexProfile): Record { apiKeySource: profile.apiKeySource, openaiResponsesWebSocketsV2Mode: profile.openaiResponsesWebSocketsV2Mode, upstreamUserAgent: profile.upstreamUserAgent, + priority: profile.priority, apiKeyPresent: profile.apiKey !== null && profile.apiKey.length > 0, apiKeyBytes: profile.apiKey === null ? 0 : Buffer.byteLength(profile.apiKey, "utf8"), apiKeyFingerprint: profile.apiKey === null ? null : fingerprint(profile.apiKey), @@ -1482,7 +1499,7 @@ def account_payload(profile, group_id): "credentials": credentials, "extra": extra, "concurrency": 1, - "priority": 1, + "priority": int(profile.get("priority", 1) or 1), "rate_multiplier": 1, "load_factor": 1, "group_ids": [group_id], @@ -1516,6 +1533,7 @@ def ensure_accounts(token, profiles, group_id): "apiKeySource": profile["apiKeySource"], "apiKeyFingerprint": profile["apiKeyFingerprint"], "openaiResponsesWebSocketsV2Mode": profile.get("openaiResponsesWebSocketsV2Mode"), + "priority": int(profile.get("priority", 1) or 1), "upstreamUserAgentConfigured": bool(profile.get("upstreamUserAgent")), "valuesPrinted": False, })