mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-03 05:45:04 +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
64 lines
2.1 KiB
TypeScript
64 lines
2.1 KiB
TypeScript
import { machineIdSync } from "node-machine-id";
|
|
|
|
/**
|
|
* Get consistent machine ID using node-machine-id with salt
|
|
* This ensures the same physical machine gets the same ID across runs
|
|
*
|
|
* @param {string} salt - Optional salt to use (defaults to environment variable)
|
|
* @returns {Promise<string>} Machine ID (16-character base32)
|
|
*/
|
|
export async function getConsistentMachineId(salt = null) {
|
|
// For server-side, use node-machine-id with salt
|
|
const saltValue = salt || process.env.MACHINE_ID_SALT || "endpoint-proxy-salt";
|
|
try {
|
|
const rawMachineId = machineIdSync();
|
|
// Create consistent ID using salt
|
|
const crypto = await import("crypto");
|
|
const hashedMachineId = crypto
|
|
.createHash("sha256")
|
|
.update(rawMachineId + saltValue)
|
|
.digest("hex");
|
|
// Return only first 16 characters for brevity
|
|
return hashedMachineId.substring(0, 16);
|
|
} catch (error) {
|
|
console.log("Error getting machine ID:", error);
|
|
// Fallback to random ID if node-machine-id fails
|
|
return crypto.randomUUID
|
|
? crypto.randomUUID()
|
|
: "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
|
|
const r = (Math.random() * 16) | 0;
|
|
const v = c == "x" ? r : (r & 0x3) | 0x8;
|
|
return v.toString(16);
|
|
});
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get raw machine ID without hashing (for debugging purposes)
|
|
* @returns {Promise<string>} Raw machine ID
|
|
*/
|
|
export async function getRawMachineId() {
|
|
// For server-side, use raw node-machine-id
|
|
try {
|
|
return machineIdSync();
|
|
} catch (error) {
|
|
console.log("Error getting raw machine ID:", error);
|
|
// Fallback to random ID if node-machine-id fails
|
|
return crypto.randomUUID
|
|
? crypto.randomUUID()
|
|
: "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
|
|
const r = (Math.random() * 16) | 0;
|
|
const v = c == "x" ? r : (r & 0x3) | 0x8;
|
|
return v.toString(16);
|
|
});
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Check if we're running in browser or server environment
|
|
* @returns {boolean} True if in browser, false if in server
|
|
*/
|
|
export function isBrowser() {
|
|
return typeof window !== "undefined";
|
|
}
|