feat(proxy): add proxy pool and per-connection binding + strictProxy support

- Centralize proxy management with reusable proxy pools
- Per-connection proxy binding with legacy fallback
- Add strictProxy option: fail hard instead of silently falling back to direct
- Resolve alicode-intl conflict: keep alicode-intl support + proxy support

Made-with: Cursor
This commit is contained in:
decolua
2026-03-09 15:46:06 +07:00
parent 4c469291a1
commit 880f4eca91
22 changed files with 1811 additions and 146 deletions

View File

@@ -0,0 +1,58 @@
import { getProxyPoolById } from "@/models";
function normalizeString(value) {
if (value === undefined || value === null) return "";
return String(value).trim();
}
function normalizeLegacyProxy(providerSpecificData = {}) {
const connectionProxyEnabled = providerSpecificData?.connectionProxyEnabled === true;
const connectionProxyUrl = normalizeString(providerSpecificData?.connectionProxyUrl);
const connectionNoProxy = normalizeString(providerSpecificData?.connectionNoProxy);
return {
connectionProxyEnabled,
connectionProxyUrl,
connectionNoProxy,
};
}
export async function resolveConnectionProxyConfig(providerSpecificData = {}) {
const proxyPoolIdRaw = normalizeString(providerSpecificData?.proxyPoolId);
const proxyPoolId = proxyPoolIdRaw === "__none__" ? "" : proxyPoolIdRaw;
const legacy = normalizeLegacyProxy(providerSpecificData);
if (proxyPoolId) {
const proxyPool = await getProxyPoolById(proxyPoolId);
const proxyUrl = normalizeString(proxyPool?.proxyUrl);
const noProxy = normalizeString(proxyPool?.noProxy);
if (proxyPool && proxyPool.isActive === true && proxyUrl) {
return {
source: "pool",
proxyPoolId,
proxyPool,
connectionProxyEnabled: true,
connectionProxyUrl: proxyUrl,
connectionNoProxy: noProxy,
strictProxy: proxyPool.strictProxy === true,
};
}
}
if (legacy.connectionProxyEnabled && legacy.connectionProxyUrl) {
return {
source: "legacy",
proxyPoolId: proxyPoolId || null,
proxyPool: null,
...legacy,
};
}
return {
source: "none",
proxyPoolId: proxyPoolId || null,
proxyPool: null,
...legacy,
};
}