fix: improve provider routing and assignments

This commit is contained in:
MUH. IQRAM BAHRING committed 2026-08-15 03:47:18 +08:00
1 parent d00205511a
commit df8c4ccb81
17 files changed
+471 -51

No files matched your search

+21 -1
View File
@@ -309,8 +309,29 @@ export async function handleChatCore({ body, modelInfo, credentials, log, onCred
proxyPoolId: psd?.proxyPoolId || psd?.connectionProxyPoolId || null,
});
const proxyScope = `${provider}::${model}`;
let proxyOptions = buildProxyOptions(credentials?.providerSpecificData || {});
if (provider === "freebuff" && credentials?.providerSpecificData?.noFitPool === true) {
const error = new Error(`Freebuff has no healthy proxy pool for ${model}; all assigned pools are cooling down after limited-IP errors.`);
error.status = 503;
error.poolScoped = { poolId: null, scope: proxyScope, reason: "no_fit_pool" };
trackPendingRequest(model, provider, connectionId, false, true);
return createErrorResult(503, error.message);
}
if (
provider === "freebuff" &&
!proxyOptions.proxyPoolId &&
!proxyOptions.vercelRelayUrl &&
!(proxyOptions.connectionProxyEnabled && proxyOptions.connectionProxyUrl)
) {
const error = new Error(`Freebuff requires a configured proxy pool for ${model}; direct egress is disabled to prevent limited-IP rate limits.`);
error.status = 503;
trackPendingRequest(model, provider, connectionId, false, true);
return createErrorResult(503, error.message);
}
if (proxyOptions.vercelRelayUrl) {
const connectionName = credentials?.connectionName || credentials?.connectionId || "unknown";
const poolId = proxyOptions.proxyPoolId || "none";
@@ -342,7 +363,6 @@ export async function handleChatCore({ body, modelInfo, credentials, log, onCred
// another pool instead of failing the account. Covers both thrown errors
// (executor.execute) and non-ok responses declared poolScoped via
// parseError — poolId/scope are completed here from proxyOptions.
const proxyScope = `${provider}::${model}`;
let parsedNonOk = null;
const tryNextPool = async (poolScoped, reasonMsg) => {