fix: normalize wildcard gateway URLs for Codex
This commit is contained in:
+26
-5
@@ -19,6 +19,7 @@ import {
|
||||
getCodexProviderContext,
|
||||
getGatewayBaseUrl,
|
||||
getGatewayStatePaths,
|
||||
isGatewayBaseUrlForListener,
|
||||
normalizeIntArray,
|
||||
normalizePhraseArray,
|
||||
normalizeReasoningMatchMode,
|
||||
@@ -345,12 +346,14 @@ function buildProfileConfig({
|
||||
imageProfileEnv,
|
||||
existingGatewayConfig,
|
||||
providerContext,
|
||||
listenHost,
|
||||
listenPort,
|
||||
localGatewayBaseUrl,
|
||||
}) {
|
||||
const upstreamBaseUrl =
|
||||
profileEnv.CODEX_RETRY_GATEWAY_UPSTREAM_BASE_URL ||
|
||||
existingGatewayConfig?.upstream_base_url ||
|
||||
(providerContext.currentBaseUrl === localGatewayBaseUrl
|
||||
(isGatewayBaseUrlForListener(providerContext.currentBaseUrl, listenHost, listenPort)
|
||||
? null
|
||||
: providerContext.currentBaseUrl);
|
||||
|
||||
@@ -425,15 +428,22 @@ function buildProfileConfig({
|
||||
};
|
||||
}
|
||||
|
||||
async function ensureCodexPointsToGateway({ paths, codexConfigPath, providerContext, localGatewayBaseUrl }) {
|
||||
async function ensureCodexPointsToGateway({
|
||||
paths,
|
||||
codexConfigPath,
|
||||
providerContext,
|
||||
listenHost,
|
||||
listenPort,
|
||||
localGatewayBaseUrl,
|
||||
}) {
|
||||
await ensureDirectory(paths.backupDir);
|
||||
const existingState = await readJsonFile(paths.statePath);
|
||||
|
||||
let originalBaseUrl = providerContext.currentBaseUrl;
|
||||
if (providerContext.currentBaseUrl === localGatewayBaseUrl) {
|
||||
if (isGatewayBaseUrlForListener(providerContext.currentBaseUrl, listenHost, listenPort)) {
|
||||
originalBaseUrl = existingState?.original_base_url || null;
|
||||
}
|
||||
if (!originalBaseUrl || originalBaseUrl === localGatewayBaseUrl) {
|
||||
if (!originalBaseUrl || isGatewayBaseUrlForListener(originalBaseUrl, listenHost, listenPort)) {
|
||||
throw new Error("A restorable original Codex base_url could not be determined.");
|
||||
}
|
||||
|
||||
@@ -536,19 +546,30 @@ async function main() {
|
||||
imageProfileEnv,
|
||||
existingGatewayConfig,
|
||||
providerContext,
|
||||
listenHost,
|
||||
listenPort,
|
||||
localGatewayBaseUrl,
|
||||
});
|
||||
|
||||
const installState = options.noCodexConfigUpdate
|
||||
? {
|
||||
existingState,
|
||||
originalBaseUrl: providerContext.currentBaseUrl,
|
||||
originalBaseUrl: isGatewayBaseUrlForListener(providerContext.currentBaseUrl, listenHost, listenPort)
|
||||
? (
|
||||
existingState?.original_base_url
|
||||
&& !isGatewayBaseUrlForListener(existingState.original_base_url, listenHost, listenPort)
|
||||
? `${existingState.original_base_url}`
|
||||
: null
|
||||
)
|
||||
: providerContext.currentBaseUrl,
|
||||
backupPath: null,
|
||||
}
|
||||
: await ensureCodexPointsToGateway({
|
||||
paths,
|
||||
codexConfigPath,
|
||||
providerContext,
|
||||
listenHost,
|
||||
listenPort,
|
||||
localGatewayBaseUrl,
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user