mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-01 21:02:12 +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
106 lines
2.5 KiB
TypeScript
106 lines
2.5 KiB
TypeScript
import { createRequire } from "module";
|
|
|
|
const require = createRequire(import.meta.url);
|
|
|
|
let createSession: any;
|
|
try {
|
|
({ createSession } = require("wreq-js"));
|
|
} catch {
|
|
createSession = null;
|
|
}
|
|
|
|
/**
|
|
* Get proxy URL from environment variables.
|
|
* Priority: HTTPS_PROXY > HTTP_PROXY > ALL_PROXY
|
|
*/
|
|
function getProxyFromEnv(): string | undefined {
|
|
return (
|
|
process.env.HTTPS_PROXY ||
|
|
process.env.https_proxy ||
|
|
process.env.HTTP_PROXY ||
|
|
process.env.http_proxy ||
|
|
process.env.ALL_PROXY ||
|
|
process.env.all_proxy ||
|
|
undefined
|
|
);
|
|
}
|
|
|
|
interface FetchOptions {
|
|
method?: string;
|
|
headers?: Record<string, string>;
|
|
body?: any;
|
|
redirect?: string;
|
|
signal?: AbortSignal;
|
|
}
|
|
|
|
/**
|
|
* TLS Client — Chrome 124 TLS fingerprint spoofing via wreq-js
|
|
* Singleton instance used to disguise Node.js TLS handshake as Chrome browser.
|
|
*
|
|
* wreq-js natively supports proxy — TLS fingerprinting works through proxy.
|
|
* Proxy URL is read from environment variables (HTTPS_PROXY, HTTP_PROXY, ALL_PROXY).
|
|
*/
|
|
class TlsClient {
|
|
session: any = null;
|
|
available: boolean;
|
|
|
|
constructor() {
|
|
this.available = !!createSession;
|
|
}
|
|
|
|
async getSession() {
|
|
if (!this.available) return null;
|
|
if (this.session) return this.session;
|
|
|
|
const proxy = getProxyFromEnv();
|
|
const sessionOpts: Record<string, any> = {
|
|
browser: "chrome_124",
|
|
os: "macos",
|
|
};
|
|
if (proxy) {
|
|
sessionOpts.proxy = proxy;
|
|
console.log(`[TlsClient] Using proxy: ${proxy}`);
|
|
}
|
|
|
|
this.session = await createSession(sessionOpts);
|
|
console.log("[TlsClient] Session created (Chrome 124 TLS fingerprint)");
|
|
return this.session;
|
|
}
|
|
|
|
/**
|
|
* Fetch with Chrome 124 TLS fingerprint.
|
|
* wreq-js Response is already fetch-compatible (headers, text(), json(), clone(), body).
|
|
*/
|
|
async fetch(url: string, options: FetchOptions = {}) {
|
|
const session = await this.getSession();
|
|
if (!session) throw new Error("wreq-js not available");
|
|
|
|
const method = (options.method || "GET").toUpperCase();
|
|
|
|
const wreqOptions: Record<string, any> = {
|
|
method,
|
|
headers: options.headers,
|
|
body: options.body,
|
|
redirect: options.redirect === "manual" ? "manual" : "follow",
|
|
};
|
|
|
|
// Pass signal through if available
|
|
if (options.signal) {
|
|
wreqOptions.signal = options.signal;
|
|
}
|
|
|
|
const response = await session.fetch(url, wreqOptions);
|
|
return response;
|
|
}
|
|
|
|
async exit() {
|
|
if (this.session) {
|
|
await this.session.close();
|
|
this.session = null;
|
|
}
|
|
}
|
|
}
|
|
|
|
export default new TlsClient();
|
|
|