mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-01 04:42:10 +03:00
OmniRoute is an intelligent API gateway that unifies 20+ AI providers behind a single OpenAI-compatible endpoint. Features include intelligent routing with 6 strategies, multi-format translation (OpenAI/Claude/Gemini/Responses API), circuit breakers, semantic caching, combo fallback chains, real-time health monitoring, and a full dashboard with provider management, analytics, and CLI tool integration. Key highlights: - 20+ providers (Claude Code, Codex, Gemini CLI, GitHub Copilot, iFlow, Qwen, Kiro, etc.) - 6 routing strategies (Fill First, Round Robin, P2C, Random, Least Used, Cost Optimized) - Export/Import database backup with full archive support - Translator Playground with 4 modes (Playground, Chat Tester, Test Bench, Live Monitor) - 100% TypeScript across src/ and open-sse/ - Docker support with multi-stage builds - Comprehensive documentation and 9 dashboard screenshots
76 lines
2.0 KiB
TypeScript
76 lines
2.0 KiB
TypeScript
/**
|
|
* Network Proxy Resolver
|
|
*
|
|
* Resolves the outbound proxy URL for a given provider.
|
|
* Precedence: provider-specific > global > environment variables
|
|
*
|
|
* Usage:
|
|
* import { resolveProxy } from "open-sse/utils/networkProxy.js";
|
|
* const proxyUrl = await resolveProxy("openai");
|
|
*/
|
|
|
|
let _cachedConfig = null;
|
|
let _cacheExpiry = 0;
|
|
|
|
/**
|
|
* Get proxy config from localDb (with caching)
|
|
*/
|
|
async function getConfig() {
|
|
const now = Date.now();
|
|
if (_cachedConfig && now < _cacheExpiry) return _cachedConfig;
|
|
|
|
try {
|
|
const { getProxyConfig } = await import("../../src/lib/localDb");
|
|
_cachedConfig = await getProxyConfig();
|
|
_cacheExpiry = now + 30_000; // Cache for 30s
|
|
return _cachedConfig;
|
|
} catch {
|
|
return { global: null, providers: {} };
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Resolve proxy URL for a given provider
|
|
* @param {string} providerId - Provider ID (e.g., "openai", "anthropic")
|
|
* @returns {string|null} Proxy URL or null if no proxy configured
|
|
*/
|
|
/** @returns {Promise<any>} */
|
|
export async function resolveProxy(providerId) {
|
|
const config = await getConfig();
|
|
|
|
// 1. Provider-specific proxy
|
|
if (providerId && config.providers?.[providerId]) {
|
|
return config.providers[providerId];
|
|
}
|
|
|
|
// 2. Global proxy
|
|
if (config.global) {
|
|
return config.global;
|
|
}
|
|
|
|
// 3. Environment variables
|
|
const envProxy = process.env.HTTPS_PROXY || process.env.HTTP_PROXY || process.env.ALL_PROXY;
|
|
if (envProxy) {
|
|
// Check NO_PROXY
|
|
const noProxy = process.env.NO_PROXY || process.env.no_proxy || "";
|
|
// Simple check: if providerId is in NO_PROXY list, skip
|
|
if (noProxy && providerId) {
|
|
const noProxyList = noProxy.split(",").map((s) => s.trim().toLowerCase());
|
|
if (noProxyList.includes(providerId.toLowerCase())) {
|
|
return null;
|
|
}
|
|
}
|
|
return envProxy;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Invalidate the proxy config cache (call after config changes)
|
|
*/
|
|
export function invalidateProxyCache() {
|
|
_cachedConfig = null;
|
|
_cacheExpiry = 0;
|
|
}
|