fix: stabilize sub2api codex pool operations

This commit is contained in:
Codex
2026-07-01 15:52:22 +00:00
parent 8f54b591d7
commit 113b6809d1
16 changed files with 509 additions and 59 deletions
@@ -263,9 +263,10 @@ export function readManualAccountsConfig(value: unknown): CodexPoolManualAccount
if (seen.has(normalized)) throw new Error(`${codexPoolConfigPath}.${key}.accountName is duplicated in manualAccounts.protected`);
seen.add(normalized);
const reason = isRecord(entry) ? readManualAccountReason(entry.reason, `${key}.reason`) : null;
const targetIds = isRecord(entry) ? readManualAccountTargetIds(entry.targetIds, `${key}.targetIds`) : null;
const proxyBinding = isRecord(entry) ? readManualAccountProxyBinding(entry.proxyBinding, `${key}.proxyBinding`, bindingSources) : null;
const groupBinding = isRecord(entry) ? readManualAccountGroupBinding(entry.groupBinding, `${key}.groupBinding`, bindingSources) : null;
return { accountName, reason, proxyBinding, groupBinding };
return { accountName, reason, targetIds, proxyBinding, groupBinding };
});
return { bindingSources, protected: protectedAccounts };
}
@@ -380,6 +381,22 @@ export function readManualAccountReason(value: unknown, key: string): string | n
return text;
}
export function readManualAccountTargetIds(value: unknown, key: string): string[] | null {
if (value === undefined || value === null) return null;
if (!Array.isArray(value)) throw new Error(`${codexPoolConfigPath}.${key} must be a YAML array of target ids`);
if (value.length === 0) throw new Error(`${codexPoolConfigPath}.${key} must not be empty`);
const seen = new Set<string>();
return value.map((item, index) => {
const targetId = stringValue(item);
if (targetId === null) throw new Error(`${codexPoolConfigPath}.${key}[${index}] must be a non-empty string`);
if (!/^[A-Za-z0-9._-]+$/u.test(targetId)) throw new Error(`${codexPoolConfigPath}.${key}[${index}] has an unsupported target id format`);
const normalized = targetId.toLowerCase();
if (seen.has(normalized)) throw new Error(`${codexPoolConfigPath}.${key}[${index}] duplicates target ${targetId}`);
seen.add(normalized);
return targetId;
});
}
export function assertProtectedManualAccountsNotManaged(profiles: CodexPoolProfileConfig[], manualAccounts: CodexPoolManualAccountsConfig): void {
const protectedNames = new Set(manualAccounts.protected.map((account) => account.accountName.toLowerCase()));
for (const [index, profile] of profiles.entries()) {