mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-31 12:22:14 +03:00
* chore(config): ignore additional agent workflow command files Add newly introduced agent workflow and Claude command files to .gitignore so proprietary automation assets are not committed. * feat(deepseek-web): fix auth to use userToken + WASM PoW solver Rewrite deepseek-web executor from broken cookie auth to userToken Bearer flow (like Chat2API). Replace pure JS Keccak PoW with WASM solver (5.8s → 86ms). Add 14 models, validation, and dashboard UX. * fix(deepseek-web): update target_path to use challenge property * refactor(deepseek-web): streamline token handling and implement cache eviction * fix(deepseek-web): fix SSE parser, prompt format, and error handling - Handle all 3 DeepSeek SSE stream formats: initial fragments, APPEND operations, and bare string tokens (fixes truncated responses) - Simplify prompt builder to send system + last user message only (DeepSeek web API is single-turn, full history caused marker leakage) - Check json.code before token extraction (fixes "did not return access token: Authorization" on code 40003 with HTTP 200) - Clear session cache alongside token cache on auth errors - Add dev origin for remote testing Co-authored-by: Cursor <cursoragent@cursor.com> * chore: ignore memory-bank and cursor agent rules from tracking Co-authored-by: Cursor <cursoragent@cursor.com> * feat: enhance documentation and configuration for Fumadocs integration - Added Fumadocs MDX support in the Next.js configuration. - Updated transpile packages to include fumadocs-ui and fumadocs-core. - Implemented a comprehensive set of redirects for documentation paths to improve navigation. - Removed the generate-docs-index script as it is no longer needed. - Updated various documentation titles for consistency and clarity. - Enhanced global styles to incorporate Fumadocs UI themes and styles. * refactor(docs): cleanup fumadocs PR — revert deepseek, add i18n fallback, restore LanguageSelector - Revert unrelated deepseek-web.ts changes (should be separate PR) - Add .source/ to .gitignore (Fumadocs generated files) - Remove contributor IP from allowedDevOrigins - Add i18n runtime fallback: reads NEXT_LOCALE cookie, loads translated .md from docs/i18n/<locale>/docs/ (preserves existing translation pipeline) - Restore LanguageSelector in Fumadocs layout nav - Restore SEO metadata (title template, description, robots) * fix(codex): use allowlist to strip non-Responses-API fields in non-passthrough path (#2608) (#2615) Integrated into release/v3.8.3 — fix(codex): allowlist-based sanitization for gpt-5.5 Responses API * fix(deepseek-web): fix SSE parser, prompt format, error handling, and cache keys (#2616) Integrated into release/v3.8.3 — fix(deepseek-web): SSE parser (APPEND + bare tokens), prompt builder, error handling, session cache cleanup * chore(config): ignore additional agent workflow command files Add newly introduced agent workflow and Claude command files to .gitignore so proprietary automation assets are not committed. * feat(docs): migrate /docs to Fumadocs MDX with nested routes (#2614) Integrated into release/v3.8.3 — Fumadocs MDX migration with nested routes, search API, and 50+ URL redirects * fix(catalog): skip static PROVIDER_MODELS when synced models exist (#2625) Integrated into release/v3.8.3 * fix(qoder): Cosy auth fallback for PAT tokens + vision support for qwen3-vl-plus (#2629) Integrated into release/v3.8.3 * fix(cli): register tsx loader and add opencode config subcommand (#2631) Integrated into release/v3.8.3 * feat(dashboard): add search and filters to /dashboard/api-manager (#2628) Integrated into release/v3.8.3 * fix(claude): improve Pi and OpenCode compatibility (#2621) Integrated into release/v3.8.3 * fix: restore semantic passthrough system-role-only extraction instead of full normalization (#2620) Integrated into release/v3.8.3 * fix(kiro): stabilize conversationId across prompt compression (#2630) Integrated into release/v3.8.3 * fix(deepseek-web): SSE thinking/search routing and session lifecycle (#2624) Integrated into release/v3.8.3 — DeepSeek Web SSE thinking/search routing overhaul * feat(dashboard): free-tier grouping with symbolic link in /providers (#2632) Integrated into release/v3.8.3 * fix: close implementation gaps — t3-chat-web, stream_options, combo_strategy, batch config (#2634) Integrated into release/v3.8.3 * feat(dashboard): risk notice modal for sensitive providers (#2633) Integrated into release/v3.8.3 * fix(reasoning): extend reasoning_content injection to Kimi K2 and other replay models (#2639) Integrated into release/v3.8.3 * fix(cli): Linux autostart via systemd user service (fixes #2627) (#2635) Integrated into release/v3.8.3 * Refactor/providers free tier (#2640) Integrated into release/v3.8.3 * fix(tests): remove duplicate assertion in schema coercion & fix(cli): ignore system vars in env check * fix(combo): preserve omniModel tag in streaming output for round-trip context pinning (#2646) Integrated into release/v3.8.3 * feat(dashboard): media providers pages + Web Fetch category (#2645) Integrated into release/v3.8.3 * Feature provider adapta org com tutorial de conexão em modal (#2643) Integrated into release/v3.8.3 * fix(rtk): skip content-based filter matching for non-shell tool results (#2642) Integrated into release/v3.8.3 * fix(translator): enable Claude extended thinking for Copilot Responses-API requests (#2647) Integrated into release/v3.8.3 * feat(dashboard): add search and filters to /dashboard/api-manager (#2641) Integrated into release/v3.8.3 * feat(dashboard): risk notice modal for sensitive providers (#2638) Integrated into release/v3.8.3 * feat(dashboard): mini-playground inline (Phase 4) (#2648) Integrated into release/v3.8.3 * fix(settings): fix Require Login modal Cancel button text and dismissal (#2649) Integrated into release/v3.8.3 * feat(combos): universal context handoff for cross-model conversation continuity (#2653) Integrated into release/v3.8.3 * chore(release): bump to v3.8.3 — changelog, docs, version sync * feat(i18n): complete zh-CN translations for 1220 missing keys (#2655) Integrated into release/v3.8.3 * chore(release): include electron package changes in v3.8.3 * docs(changelog): integrate PR #2655 into v3.8.3 * feat(i18n): translate 377 additional zh-CN entries (81 new keys + 296 same-as-en) (#2659) Integrated into release/v3.8.3 * feat(dashboard): add Cmd+K / Ctrl+K command palette for sidebar navigation (#2656) Integrated into release/v3.8.3 * docs: update changelog for PR integrations under v3.8.3 * feat(cli): integrate native updates, autostart and headless CLI mode (#2662) Integrated into release/v3.8.3 * fix(proxy): save dashboard custom proxies in registry (#2661) Integrated into release/v3.8.3 * feat(dashboard): chat-first test slide-over (Option A) (#2660) Integrated into release/v3.8.3 * docs: update changelog with Batch 2 PR merges for v3.8.3 * fix: add xhigh+max to effortLevel schema; add opencode-plugin publish job (#2666) Integrated into release/v3.8.3 * docs: update changelog with Batch 3 PR #2666 merge for v3.8.3 * feat(quota+providers): card-grid layout, provider group headers, Codex race fix (#2667) Integrated into release/v3.8.3 * feat(dashboard): real-time live WebSocket monitoring (#2668) Integrated into release/v3.8.3 * feat(copilot): AI assistant with CodeGraph + CLI + knowledge base (#2669) Integrated into release/v3.8.3 * feat(pipeline): pre-request middleware hooks (#2670) Integrated into release/v3.8.3 * feat(resilience): credential health check + adaptive circuit breaker (#2671) Integrated into release/v3.8.3 * feat(playground): combo routing visual simulator (#2672) Integrated into release/v3.8.3 * feat(auth): API key groups with model-level permissions (#2673) Integrated into release/v3.8.3 * feat(pwa): enhanced manifest + push notification support (#2674) Integrated into release/v3.8.3 * feat(proxy): serverless relay endpoints with rate limiting (#2675) Integrated into release/v3.8.3 * docs(changelog): update changelog for PRs 2667-2675 & fix: resolve typescript compile-time errors * fix(db): remove transactions from migrations Remove explicit transaction wrappers from recent migrations and correct the API key groups migration metadata. Also fix codegraph path resolution for ESM environments and refresh generated fumadocs source output. --------- Co-authored-by: Ömer Vehbe <ovehbe@gmail.com> Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: Mr. Meowgi <mr@meowgi.dev> Co-authored-by: Hernan Javier Ardila Sanchez <hjasgr@gmail.com> Co-authored-by: amogus22877769 <y.lev357@gmail.com> Co-authored-by: Halil Tezcan KARABULUT <info@hlltzcnkb.com> Co-authored-by: Tentoxa <53821604+Tentoxa@users.noreply.github.com> Co-authored-by: HALDRO <121296348+HALDRO@users.noreply.github.com> Co-authored-by: Paijo <14921983+oyi77@users.noreply.github.com> Co-authored-by: janeza2 <49841619+janeza2@users.noreply.github.com> Co-authored-by: df4p <38404+df4p@users.noreply.github.com> Co-authored-by: ivan-mezentsev <ivan@mezentsev.me> Co-authored-by: Chewji <126886556+Chewji9875@users.noreply.github.com> Co-authored-by: L-aros <107354918+L-aros@users.noreply.github.com> Co-authored-by: M.M <mr.maatoug@gmail.com> Co-authored-by: Benson K B <bensonkbmca@gmail.com> Co-authored-by: terence71-glitch <mcdowellterence71@gmail.com>
199 lines
7.5 KiB
JavaScript
Executable File
199 lines
7.5 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
|
|
/**
|
|
* OmniRoute CLI entry point.
|
|
*
|
|
* Special bypasses (handled before Commander):
|
|
* --mcp Start MCP server over stdio
|
|
* reset-encrypted-columns Recovery tool for broken encrypted credentials
|
|
*
|
|
* All other commands are routed through Commander (bin/cli/program.mjs).
|
|
*/
|
|
|
|
import { existsSync, readFileSync } from "node:fs";
|
|
import { join, dirname } from "node:path";
|
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
import { homedir, platform } from "node:os";
|
|
import updateNotifier from "update-notifier";
|
|
|
|
// Register tsx so dynamic imports of .ts source files (referenced as .js per
|
|
// TypeScript conventions) resolve correctly. The build never emits .js for
|
|
// src/lib/cli-helper/, so tsx handles the .ts → .js resolution at runtime.
|
|
await import("tsx/esm");
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = dirname(__filename);
|
|
const ROOT = join(__dirname, "..");
|
|
|
|
function loadEnvFile() {
|
|
const envPaths = [];
|
|
|
|
if (process.env.DATA_DIR) {
|
|
envPaths.push(join(process.env.DATA_DIR, ".env"));
|
|
}
|
|
|
|
const home = homedir();
|
|
if (home) {
|
|
if (platform() === "win32") {
|
|
const appData = process.env.APPDATA || join(home, "AppData", "Roaming");
|
|
envPaths.push(join(appData, "omniroute", ".env"));
|
|
} else {
|
|
envPaths.push(join(home, ".omniroute", ".env"));
|
|
}
|
|
}
|
|
|
|
envPaths.push(join(process.cwd(), ".env"));
|
|
envPaths.push(join(ROOT, ".env"));
|
|
|
|
for (const envPath of envPaths) {
|
|
try {
|
|
if (existsSync(envPath)) {
|
|
const content = readFileSync(envPath, "utf-8");
|
|
for (const line of content.split("\n")) {
|
|
const trimmed = line.trim();
|
|
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
const eqIdx = trimmed.indexOf("=");
|
|
if (eqIdx > 0) {
|
|
const key = trimmed.slice(0, eqIdx).trim();
|
|
const value = trimmed.slice(eqIdx + 1).trim();
|
|
if (process.env[key] === undefined) {
|
|
process.env[key] = value.replace(/^["']|["']$/g, "");
|
|
}
|
|
}
|
|
}
|
|
console.log(` \x1b[2m📋 Loaded env from ${envPath}\x1b[0m`);
|
|
return;
|
|
}
|
|
} catch {
|
|
// Ignore errors reading env files.
|
|
}
|
|
}
|
|
}
|
|
|
|
loadEnvFile();
|
|
|
|
// Generate STORAGE_ENCRYPTION_KEY if not set (persisted to ~/.omniroute/.env)
|
|
// This ensures the key survives across upgrades and is not regenerated on each install.
|
|
// See: https://github.com/diegosouzapw/OmniRoute/issues/1622
|
|
{
|
|
const { randomBytes } = await import("node:crypto");
|
|
const { existsSync, mkdirSync, readFileSync, writeFileSync } = await import("node:fs");
|
|
const { join } = await import("node:path");
|
|
const { homedir } = await import("node:os");
|
|
|
|
if (!process.env.STORAGE_ENCRYPTION_KEY) {
|
|
// Persist the key into DATA_DIR when set — that's the directory mounted as a volume in
|
|
// Docker (where storage.sqlite lives), so the key survives `docker down` / `docker pull`.
|
|
// Writing only to ~/.omniroute (the container home, not a volume) silently lost the key on
|
|
// container recreation, leaving the persisted encrypted DB undecryptable (regression of #1622).
|
|
const dataDir = process.env.DATA_DIR || join(homedir(), ".omniroute");
|
|
const envPath = join(dataDir, ".env");
|
|
const dbPath = join(dataDir, "storage.sqlite");
|
|
|
|
// Safety guard: never auto-generate a fresh key when a database already exists in
|
|
// DATA_DIR. A new key cannot decrypt previously-encrypted credentials and would lock the
|
|
// user out (then the encryption layer aborts on every read). Mirrors bootstrapEnv's
|
|
// hasEncryptedCredentials guard. Restoring the previous key in DATA_DIR/.env recovers it.
|
|
// (#1622 follow-up — reported by Daniel Nach; original persistence by @Chewji9875)
|
|
if (existsSync(dbPath)) {
|
|
console.warn(
|
|
` \x1b[33m⚠ STORAGE_ENCRYPTION_KEY is not set but a database already exists at\x1b[0m\n` +
|
|
` \x1b[33m ${dbPath}\x1b[0m\n` +
|
|
` \x1b[33m Not auto-generating a new key — it could not decrypt existing data. Restore your\x1b[0m\n` +
|
|
` \x1b[33m previous key in ${envPath}, or move/remove the database to start fresh.\x1b[0m`
|
|
);
|
|
} else {
|
|
// First run (no database yet) — generate and persist a fresh key.
|
|
if (!existsSync(dataDir)) {
|
|
mkdirSync(dataDir, { recursive: true });
|
|
}
|
|
|
|
const key = randomBytes(32).toString("hex");
|
|
|
|
// Read existing .env content or start fresh
|
|
let content = "";
|
|
if (existsSync(envPath)) {
|
|
content = readFileSync(envPath, "utf-8");
|
|
}
|
|
|
|
// Append key if not already present
|
|
if (!content.includes("STORAGE_ENCRYPTION_KEY=")) {
|
|
const separator = content.trim() ? "\n" : "";
|
|
const newContent = content.trimEnd() + separator + `STORAGE_ENCRYPTION_KEY=${key}`;
|
|
writeFileSync(envPath, newContent + "\n", "utf-8");
|
|
console.log(` \x1b[2m✨ Generated STORAGE_ENCRYPTION_KEY in ${envPath}\x1b[0m`);
|
|
}
|
|
|
|
// Set in process.env for immediate use
|
|
process.env.STORAGE_ENCRYPTION_KEY = key;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Apply --lang before Commander parses (program descriptions call t() during setup)
|
|
{
|
|
const langIdx = process.argv.findIndex((a) => a === "--lang");
|
|
const langArg = langIdx >= 0 ? process.argv[langIdx + 1] : null;
|
|
const langEnv = process.env.OMNIROUTE_LANG;
|
|
const chosen = langArg || langEnv;
|
|
if (chosen) {
|
|
const { setLocale } = await import(
|
|
pathToFileURL(join(ROOT, "bin", "cli", "i18n.mjs")).href
|
|
);
|
|
setLocale(chosen);
|
|
}
|
|
}
|
|
|
|
// Register update notifier — checks npm once per 24h, notifies on exit via stderr.
|
|
const _pkg = JSON.parse(readFileSync(join(ROOT, "package.json"), "utf8"));
|
|
const _notifier = updateNotifier({ pkg: _pkg, updateCheckInterval: 1000 * 60 * 60 * 24 });
|
|
process.on("exit", () => {
|
|
if (process.env.OMNIROUTE_NO_UPDATE_NOTIFIER) return;
|
|
if (process.env.CI) return;
|
|
if (process.argv.includes("--quiet") || process.argv.includes("-q")) return;
|
|
const outputIdx = process.argv.indexOf("--output");
|
|
const outputVal = outputIdx >= 0 ? process.argv[outputIdx + 1] : null;
|
|
if (outputVal === "json" || outputVal === "jsonl" || outputVal === "csv") return;
|
|
if (process.argv.some((a) => a.startsWith("--output=json") || a.startsWith("--output=jsonl") || a.startsWith("--output=csv"))) return;
|
|
if (_notifier.update) {
|
|
_notifier.notify({
|
|
defer: false,
|
|
isGlobal: true,
|
|
message:
|
|
`Update available: ${_notifier.update.current} → ${_notifier.update.latest}\n` +
|
|
"Run `npm install -g omniroute` or `omniroute update --apply`",
|
|
});
|
|
}
|
|
});
|
|
|
|
if (process.argv.includes("--mcp")) {
|
|
try {
|
|
const { startMcpCli } = await import(pathToFileURL(join(ROOT, "bin", "mcp-server.mjs")).href);
|
|
await startMcpCli(ROOT);
|
|
} catch (err) {
|
|
console.error("\x1b[31m✖ Failed to start MCP server:\x1b[0m", err.message || err);
|
|
process.exit(1);
|
|
}
|
|
process.exit(0);
|
|
}
|
|
|
|
if (process.argv.includes("reset-encrypted-columns")) {
|
|
const { runResetEncryptedColumns } = await import(
|
|
pathToFileURL(join(ROOT, "bin", "cli", "commands", "reset-encrypted-columns.mjs")).href
|
|
);
|
|
const exitCode = await runResetEncryptedColumns(process.argv.slice(2));
|
|
process.exit(exitCode ?? 0);
|
|
}
|
|
|
|
try {
|
|
const { createProgram } = await import(
|
|
pathToFileURL(join(ROOT, "bin", "cli", "program.mjs")).href
|
|
);
|
|
const program = createProgram();
|
|
await program.parseAsync(process.argv);
|
|
} catch (err) {
|
|
if (err.exitCode !== undefined) process.exit(err.exitCode);
|
|
console.error("\x1b[31m✖", err.message, "\x1b[0m");
|
|
process.exit(1);
|
|
}
|