feat: support codex pool account priority

This commit is contained in:
Codex
2026-06-09 06:28:40 +00:00
parent 54e72713a1
commit 51cb038fd3
2 changed files with 20 additions and 1 deletions
@@ -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
+19 -1
View File
@@ -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<string, unknown> {
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,
})