chore: update codex pool git rules

This commit is contained in:
Codex
2026-06-09 07:18:35 +00:00
parent e17f15bdce
commit b7a44ee302
7 changed files with 138 additions and 7 deletions
+71 -4
View File
@@ -103,6 +103,16 @@ interface CodexPoolLocalCodexConfig {
backupSuffix: string;
providerName: string;
wireApi: string;
supportsWebSockets: boolean;
responsesWebSocketsV2: boolean;
}
interface CodexLocalConsumerTomlOptions {
providerName: string;
baseUrl: string;
wireApi: string;
supportsWebSockets: boolean;
responsesWebSocketsV2: boolean;
}
export function codexPoolHelp(): unknown {
@@ -367,6 +377,8 @@ async function codexPoolConfigureLocal(config: UniDeskConfig, options: ConfirmOp
baseUrl: pool.publicExposure.masterBaseUrl,
providerName: pool.localCodex.providerName,
wireApi: pool.localCodex.wireApi,
supportsWebSockets: pool.localCodex.supportsWebSockets,
responsesWebSocketsV2: pool.localCodex.responsesWebSocketsV2,
valuesPrinted: false,
},
next: {
@@ -570,6 +582,8 @@ function defaultCodexPoolConfig(): CodexPoolConfig {
backupSuffix: "pre-sub2api",
providerName: "OpenAI",
wireApi: "responses",
supportsWebSockets: true,
responsesWebSocketsV2: true,
},
};
}
@@ -647,6 +661,13 @@ function readAccountCapacity(value: unknown, key: string): number {
return capacity;
}
function readBooleanConfig(value: unknown, key: string, fallback: boolean): boolean {
if (value === undefined || value === null) return fallback;
const parsed = booleanValue(value);
if (parsed === null) throw new Error(`${codexPoolConfigPath}.${key} must be a boolean`);
return parsed;
}
function readPublicExposureConfig(value: unknown, defaults: CodexPoolPublicExposureConfig): CodexPoolPublicExposureConfig {
if (!isRecord(value)) return defaults;
const masterFrpsValue = isRecord(value.masterFrps) ? value.masterFrps : {};
@@ -688,6 +709,8 @@ function readLocalCodexConfig(value: unknown, defaults: CodexPoolLocalCodexConfi
backupSuffix: stringValue(value.backupSuffix) ?? defaults.backupSuffix,
providerName: stringValue(value.providerName) ?? defaults.providerName,
wireApi: stringValue(value.wireApi) ?? defaults.wireApi,
supportsWebSockets: readBooleanConfig(value.supportsWebSockets, "localCodex.supportsWebSockets", defaults.supportsWebSockets),
responsesWebSocketsV2: readBooleanConfig(value.responsesWebSocketsV2, "localCodex.responsesWebSocketsV2", defaults.responsesWebSocketsV2),
};
if (!/^[A-Za-z0-9._-]+$/u.test(config.backupSuffix)) throw new Error(`${codexPoolConfigPath}.localCodex.backupSuffix has an unsupported format`);
validateProxyName(config.providerName, "localCodex.providerName");
@@ -1093,6 +1116,8 @@ function writeLocalCodexConfig(pool: CodexPoolConfig, apiKey: string): Record<st
name: pool.localCodex.providerName,
baseUrl: pool.publicExposure.masterBaseUrl,
wireApi: pool.localCodex.wireApi,
supportsWebSockets: pool.localCodex.supportsWebSockets,
responsesWebSocketsV2: pool.localCodex.responsesWebSocketsV2,
},
valuesPrinted: false,
};
@@ -1106,8 +1131,19 @@ function copyIfMissing(source: string, target: string): "created" | "kept-existi
}
function updateCodexConfigToml(current: string, pool: CodexPoolConfig): string {
let next = upsertTopLevelTomlString(current, "model_provider", pool.localCodex.providerName);
next = upsertProviderSection(next, pool.localCodex.providerName, pool.publicExposure.masterBaseUrl, pool.localCodex.wireApi);
return renderCodexLocalConsumerToml(current, {
providerName: pool.localCodex.providerName,
baseUrl: pool.publicExposure.masterBaseUrl,
wireApi: pool.localCodex.wireApi,
supportsWebSockets: pool.localCodex.supportsWebSockets,
responsesWebSocketsV2: pool.localCodex.responsesWebSocketsV2,
});
}
export function renderCodexLocalConsumerToml(current: string, options: CodexLocalConsumerTomlOptions): string {
let next = upsertTopLevelTomlString(current, "model_provider", options.providerName);
next = upsertProviderSection(next, options);
next = upsertTomlSectionBoolean(next, "features", "responses_websockets_v2", options.responsesWebSocketsV2);
return next.endsWith("\n") ? next : `${next}\n`;
}
@@ -1125,7 +1161,8 @@ function upsertTopLevelTomlString(text: string, key: string, value: string): str
return lines.join("\n");
}
function upsertProviderSection(text: string, providerName: string, baseUrl: string, wireApi: string): string {
function upsertProviderSection(text: string, options: CodexLocalConsumerTomlOptions): string {
const { providerName, baseUrl, wireApi, supportsWebSockets } = options;
const header = `[model_providers.${providerName}]`;
const lines = text.split(/\r?\n/u);
const start = lines.findIndex((line) => line.trim() === header);
@@ -1134,6 +1171,7 @@ function upsertProviderSection(text: string, providerName: string, baseUrl: stri
`base_url = ${tomlString(baseUrl)}`,
`wire_api = ${tomlString(wireApi)}`,
"requires_openai_auth = true",
`supports_websockets = ${tomlBoolean(supportsWebSockets)}`,
];
if (start === -1) {
const needsBlank = lines.length > 0 && lines[lines.length - 1].trim() !== "";
@@ -1147,12 +1185,37 @@ function upsertProviderSection(text: string, providerName: string, baseUrl: stri
}
}
const preserved = lines.slice(start + 1, end).filter((line) => {
return !/^\s*(name|base_url|wire_api|requires_openai_auth|env_key)\s*=/u.test(line);
return !/^\s*(name|base_url|wire_api|requires_openai_auth|supports_websockets|env_key)\s*=/u.test(line);
});
const replacement = [header, ...canonical, ...preserved.filter((line) => line.trim() !== "")];
return [...lines.slice(0, start), ...replacement, ...lines.slice(end)].join("\n");
}
function upsertTomlSectionBoolean(text: string, sectionName: string, key: string, value: boolean): string {
const header = `[${sectionName}]`;
const lines = text.split(/\r?\n/u);
const start = lines.findIndex((line) => line.trim() === header);
const assignment = `${key} = ${tomlBoolean(value)}`;
if (start === -1) {
const needsBlank = lines.length > 0 && lines[lines.length - 1].trim() !== "";
return [...lines, ...(needsBlank ? [""] : []), header, assignment].join("\n");
}
let end = lines.length;
for (let index = start + 1; index < lines.length; index += 1) {
if (/^\s*\[/.test(lines[index])) {
end = index;
break;
}
}
for (let index = start + 1; index < end; index += 1) {
if (new RegExp(`^\\s*${escapeRegExp(key)}\\s*=`).test(lines[index])) {
lines[index] = assignment;
return lines.join("\n");
}
}
return [...lines.slice(0, start + 1), assignment, ...lines.slice(start + 1)].join("\n");
}
async function validatePublicGatewayWithKey(pool: CodexPoolConfig, apiKey: string): Promise<Record<string, unknown>> {
const probe = await probePublicModels(pool, "with-api-key", apiKey);
return {
@@ -1216,6 +1279,10 @@ function tomlString(value: string): string {
return JSON.stringify(value);
}
function tomlBoolean(value: boolean): string {
return value ? "true" : "false";
}
function escapeRegExp(value: string): string {
return value.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
}