mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-02 21:32: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
40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
// Shared Utils - Export all
|
|
export { cn } from "./cn";
|
|
export * as api from "./api";
|
|
|
|
import { v4 as uuidv4 } from "uuid";
|
|
|
|
/**
|
|
* Generate unique ID (UUID v4)
|
|
* @returns {string} UUID v4 string
|
|
*/
|
|
export const generateId = uuidv4;
|
|
|
|
/**
|
|
* Extract error code from error message (401, 429, 503...)
|
|
* @param {string} lastError - Error message
|
|
* @returns {string|null} Error code or null
|
|
*/
|
|
export function getErrorCode(lastError) {
|
|
if (!lastError) return null;
|
|
const match = lastError.match(/\b([45]\d{2})\b/);
|
|
return match ? match[1] : "ERR";
|
|
}
|
|
|
|
/**
|
|
* Get relative time string (e.g. "5 min ago")
|
|
* @param {string} isoDate - ISO date string
|
|
* @returns {string} Relative time
|
|
*/
|
|
export function getRelativeTime(isoDate) {
|
|
if (!isoDate) return "";
|
|
const diff = Date.now() - new Date(isoDate).getTime();
|
|
const mins = Math.floor(diff / 60000);
|
|
if (mins < 1) return "just now";
|
|
if (mins < 60) return `${mins}m ago`;
|
|
const hours = Math.floor(mins / 60);
|
|
if (hours < 24) return `${hours}h ago`;
|
|
const days = Math.floor(hours / 24);
|
|
return `${days}d ago`;
|
|
}
|