retry capacity-style upstream errors

This commit is contained in:
2026-06-29 15:54:36 +08:00
parent 778068af42
commit 283c14b6b4
8 changed files with 384 additions and 24 deletions
+31 -16
View File
@@ -177,16 +177,27 @@ export function normalizeIntArray(values, fallback = [516]) {
return normalized.length > 0 ? [...new Set(normalized)] : [...fallback];
}
export function normalizeStringArray(values, fallback = []) {
const source = values === undefined || values === null ? fallback : values;
const queue = Array.isArray(source) ? source.flat(Infinity) : [source];
const normalized = queue
export function normalizeStringArray(values, fallback = []) {
const source = values === undefined || values === null ? fallback : values;
const queue = Array.isArray(source) ? source.flat(Infinity) : [source];
const normalized = queue
.flatMap((value) => `${value ?? ""}`.split(/[\s,]+/))
.map((value) => value.trim())
.filter(Boolean);
return normalized.length > 0 ? [...new Set(normalized)] : [...fallback];
}
return normalized.length > 0 ? [...new Set(normalized)] : [...fallback];
}
export function normalizePhraseArray(values, fallback = []) {
const source = values === undefined || values === null ? fallback : values;
const queue = Array.isArray(source) ? source.flat(Infinity) : [source];
const normalized = queue
.flatMap((value) => (typeof value === "string" ? value.split(/\r?\n/) : [value]))
.map((value) => `${value ?? ""}`.trim())
.filter(Boolean);
return normalized.length > 0 ? [...new Set(normalized)] : [...fallback];
}
export function isProcessAlive(processId) {
try {
@@ -404,19 +415,23 @@ export async function installForCurrentProvider({
}
}
const gatewayConfig = {
listen_host: listenHost,
listen_port: listenPort,
upstream_base_url: originalBaseUrl,
const gatewayConfig = {
listen_host: listenHost,
listen_port: listenPort,
upstream_base_url: originalBaseUrl,
request_body_limit_bytes:
existingGatewayConfig?.request_body_limit_bytes === undefined || existingGatewayConfig?.request_body_limit_bytes === null
? 10485760
: Number.parseInt(`${existingGatewayConfig.request_body_limit_bytes}`, 10),
endpoints: mergedEndpoints,
reasoning_equals: normalizeIntArray(existingGatewayConfig?.reasoning_equals, [516]),
non_stream_status_code:
existingGatewayConfig?.non_stream_status_code === undefined || existingGatewayConfig?.non_stream_status_code === null
? 502
endpoints: mergedEndpoints,
reasoning_equals: normalizeIntArray(existingGatewayConfig?.reasoning_equals, [516]),
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.",
]),
non_stream_status_code:
existingGatewayConfig?.non_stream_status_code === undefined || existingGatewayConfig?.non_stream_status_code === null
? 502
: Number.parseInt(`${existingGatewayConfig.non_stream_status_code}`, 10),
stream_action: existingGatewayConfig?.stream_action || "strict_502",
log_match: existingGatewayConfig?.log_match === undefined ? true : Boolean(existingGatewayConfig.log_match),