feat: add retry wave visibility controls

This commit is contained in:
2026-07-07 20:28:24 +08:00
parent 446a0e99a8
commit a62f2cf1b9
11 changed files with 1760 additions and 267 deletions
+20 -9
View File
@@ -9,10 +9,12 @@ import path from "node:path";
export const DEFAULT_STATE_ROOT = path.join(os.homedir(), ".codex-retry-gateway");
const DEFAULT_REQUEST_BODY_LIMIT_BYTES = 1024 * 1024 * 1024;
const LEGACY_DEFAULT_REQUEST_BODY_LIMIT_BYTES = 10 * 1024 * 1024;
export const DEFAULT_CODEX_CONFIG_PATH = path.join(os.homedir(), ".codex", "config.toml");
export const DEFAULT_LISTEN_HOST = "127.0.0.1";
export const DEFAULT_LISTEN_PORT = 4610;
export const DEFAULT_HEALTH_PATH = "/__codex_retry_gateway/health";
export const DEFAULT_CODEX_CONFIG_PATH = path.join(os.homedir(), ".codex", "config.toml");
export const DEFAULT_LISTEN_HOST = "127.0.0.1";
export const DEFAULT_LISTEN_PORT = 4610;
export const DEFAULT_HEALTH_PATH = "/__codex_retry_gateway/health";
export const DEFAULT_REASONING_MATCH_MODE = "formula_518n_minus_2";
export const DEFAULT_REASONING_EQUALS = [516, 1034, 1552];
function escapeRegExp(value) {
return `${value}`.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
@@ -167,10 +169,10 @@ export async function setCodexProviderBaseUrl({ codexConfigPath, providerName, n
await writeUtf8File(codexConfigPath, updatedContent);
}
export function normalizeIntArray(values, fallback = [516]) {
const source = values === undefined || values === null ? fallback : values;
const queue = Array.isArray(source) ? source.flat(Infinity) : [source];
const normalized = queue
export function normalizeIntArray(values, fallback = DEFAULT_REASONING_EQUALS) {
const source = values === undefined || values === null ? fallback : values;
const queue = Array.isArray(source) ? source.flat(Infinity) : [source];
const normalized = queue
.map((value) => (typeof value === "string" ? value.split(/[\s,]+/).filter(Boolean) : [value]))
.flat()
.map((value) => Number.parseInt(`${value}`, 10))
@@ -190,6 +192,14 @@ export function normalizeStringArray(values, fallback = []) {
return normalized.length > 0 ? [...new Set(normalized)] : [...fallback];
}
export function normalizeReasoningMatchMode(value) {
const mode = `${value || DEFAULT_REASONING_MATCH_MODE}`.trim().toLowerCase();
if (["formula_518n_minus_2", "manual"].includes(mode)) {
return mode;
}
return DEFAULT_REASONING_MATCH_MODE;
}
export function normalizePhraseArray(values, fallback = []) {
const source = values === undefined || values === null ? fallback : values;
const queue = Array.isArray(source) ? source.flat(Infinity) : [source];
@@ -430,7 +440,8 @@ export async function installForCurrentProvider({
: Number.parseInt(`${existingGatewayConfig.request_body_limit_bytes}`, 10)
),
endpoints: mergedEndpoints,
reasoning_equals: normalizeIntArray(existingGatewayConfig?.reasoning_equals, [516]),
reasoning_match_mode: normalizeReasoningMatchMode(existingGatewayConfig?.reasoning_match_mode),
reasoning_equals: normalizeIntArray(existingGatewayConfig?.reasoning_equals, DEFAULT_REASONING_EQUALS),
retryable_status_codes: normalizeIntArray(existingGatewayConfig?.retryable_status_codes, [429, 503]),
retryable_error_messages: normalizePhraseArray(existingGatewayConfig?.retryable_error_messages, [
"Selected model is at capacity. Please try a different model.",