* chore(release): open v3.8.35 development cycle
* fix db vacuum scheduler settings (#4726)
Scheduled VACUUM now follows Storage page settings (scheduledVacuum/vacuumHour) as single source of truth; env-flag control path removed. 11/11 vacuum-scheduler tests pass against release/v3.8.35 tip; no orphaned env refs. Integrated into release/v3.8.35.
* fix(tier): noAuth providers count as free; free filter returns empty … (#4753)
noAuth providers now classified free (union of legacy list + NOAUTH_PROVIDERS chat-tier derivation), -free arena_elo alias, and auto/<cat>:free returns an empty pool when no free candidate matches (opt-in legacy fallback via OMNIROUTE_AUTO_FREE_FALLBACK_TO_FULL_POOL). New env var documented in .env.example + ENVIRONMENT.md; CHANGELOG bullet added (maintainer co-author). 46/46 node + 56/56 vitest tests pass on release tip; env-doc-sync, docs-sync, typecheck:core, lint, file-size all green. Integrated into release/v3.8.35.
* refactor(chatCore): extrai 11 helpers de nível superior para 6 leaves puros (#3501) (#4571)
chatCore god-file decomposition (#3501): extract 6 pure leaves (cacheUsageMeta, executorClientHeaders, nonStreamingResponseBody, skillsFormat, streamErrorResult, streamFinalize) from chatCore.ts. Rebased onto release/v3.8.35 tip (resolved single chatCore.ts conflict — removed now-extracted inline buildExecutorClientHeaders). 265/265 chatcore tests, 26/26 new leaf tests, typecheck:core, cycles, file-size all green. Integrated into release/v3.8.35.
* refactor(chatCore): extrai resolveExecutorWithProxy + getExecutionCredentials para leaves (#3501) (#4646)
chatCore #3501: extract resolveExecutorWithProxy + getExecutionCredentials to leaves (executorProxy.ts, executionCredentials.ts). Clean cherry-pick onto release tip post-#4571. 12/12 new leaf tests, typecheck:core, cycles, file-size green. Integrated into release/v3.8.35.
* refactor(chatCore): extrai transforms de mensagens Claude p/ leaf (#3501) (#4708)
chatCore #3501: extract Claude upstream-message transforms to leaf (claudeUpstreamMessages.ts + claudeMessageTypes.ts). Clean cherry-pick post-#4646. 8/8 new leaf tests, typecheck/cycles/file-size green. Integrated into release/v3.8.35.
* refactor(chatCore): extrai persistAttemptLogs para leaf (#3501) (#4717)
chatCore #3501: extract persistAttemptLogs to leaf (attemptLogging.ts). Rebased onto release tip post-#4708 (resolved imports conflict: kept tip's resolveCompressionHeader from compression Phase 3, dropped now-unused logTruncation import moved into the leaf). 288/288 chatcore tests, typecheck/cycles/file-size green. Integrated into release/v3.8.35.
* refactor(chatCore): extrai stageTrace + compressionUsageReceipt para leaves (#3501) (#4721)
chatCore #3501: extract stageTrace + compressionUsageReceipt to leaves. Clean cherry-pick post-#4717. 6/6 new leaf tests, typecheck/cycles/file-size green. Integrated into release/v3.8.35.
* refactor(chatCore): extrai prepareUpstreamBody (1ª sub-fatia do executeProviderRequest, #3501) (#4730)
chatCore #3501: extract prepareUpstreamBody (first sub-slice of executeProviderRequest) to leaf (upstreamBody.ts). Clean cherry-pick post-#4721. 7/7 new leaf tests, full 301/301 chatcore suite, typecheck/cycles/file-size green. Completes the 6-PR chatCore decomposition stack into release/v3.8.35.
* fix(db): make db-backup import size cap configurable (#4719) (#4757)
Co-authored-by: Diego Rodrigues de Sa e Souza <souzamiriamrodrigues790@gmail.com>
* chore(quality): expand check:release-green to the FULL release-PR gate set (#4758)
The release-green pre-flight (Solution C) previously covered only a subset of the
gates that run exclusively on the release PR (PR→main), so reds still accrued
silently on release/** and surfaced in ~40-min layers at release time (v3.8.34:
3 CI rounds — CodeQL sanitization, then the fail-fast Quality Ratchet revealing
openapi then cyclomatic-complexity one push at a time, plus zizmor/integration).
Now check:release-green reproduces the COMPLETE release-PR gate set and reports
EVERY red in one pass (collected, not fail-fast):
- New DRIFT ratchets (report-only, rebaselined at release, never block):
cyclomatic complexity, dead-code, type-coverage, compression-budget,
openapi-coverage, workflow-lint (zizmor), codeql-ratchet.
- New HARD gates (real defects): docs-all (fabricated-docs strict + i18n mirror
sync) and the integration test suite (gated behind !--quick).
The only release-PR gates it still cannot reproduce locally are GitHub-side CodeQL
semantic analysis and SonarQube/SonarCloud (external services).
The nightly-release-green workflow and /green-prs inherit the expanded coverage
automatically (they invoke this script), so cycle drift is now surfaced
continuously and the release PR is green on its first CI run.
Co-authored-by: Diego Rodrigues de Sa e Souza <souzamiriamrodrigues790@gmail.com>
* fix(dashboard): add missing onboarding.tiers step title (#4698) (#4755)
Co-authored-by: Diego Rodrigues de Sa e Souza <souzamiriamrodrigues790@gmail.com>
* feat(compression): Output Styles registry + D0 telemetry (Phase 4A) (#4694)
Phase 4A: Output Styles registry + D0 telemetry. Integrated into release/v3.8.35.
* feat(compression): SLM tier for ultra (Phase 4B) [stacked on #4694] (#4707)
Phase 4B: SLM tier for ultra. Integrated into release/v3.8.35.
* feat(compression): context-budget adaptive compression (Phase 4C) [stacked on #4707] (#4716)
Phase 4C: adaptive context-budget compression. Integrated into release/v3.8.35.
* feat(compression): offline evaluation harness (Phase 4 D1) [stacked on #4716] (#4720)
Phase 4 D1: offline evaluation harness. Integrated into release/v3.8.35.
* fix(sse): deepseek-web folds role:tool results into prompt transcript (#4712) (#4756)
Co-authored-by: Diego Rodrigues de Sa e Souza <souzamiriamrodrigues790@gmail.com>
* fix(dashboard): remove dead unconditional useLiveRequests call in HomePageClient (#4759, #4745, #4596) (#4761)
Co-authored-by: Diego Rodrigues de Sa e Souza <souzamiriamrodrigues790@gmail.com>
* fix(dashboard): dedupe provider nodes by id on compatible-provider add (#4746) (#4768)
Co-authored-by: Diego Rodrigues de Sa e Souza <souzamiriamrodrigues790@gmail.com>
* chore(db): re-export compressionRunTelemetry from localDb to satisfy db-rules (#4775)
Co-authored-by: Diego Rodrigues de Sa e Souza <souzamiriamrodrigues790@gmail.com>
* docs(security): add canonical STRIDE-based threat model (#4783)
Canonical STRIDE threat model. Integrated into release/v3.8.35.
* test(dashboard): add smoke test for home client dashboard (#4793)
Smoke test guarding the dashboard home client render (regression #4745/#4759). Code fix already landed via #4761; this PR's jsdom smoke test is the net-new regression guard. Integrated into release/v3.8.35.
* fix(combos): auto-promote zeroLatencyOptimizationsEnabled so legacy configs (pre-3.8.33 fallbackCompressionMode="lite") round-trip on the first GUI edit (#4774)
Auto-promote zeroLatencyOptimizationsEnabled + strip v3.8.31-era removed keys so legacy combo configs round-trip through PUT /api/combos/{id} on first GUI edit (closes #4382 followup). Pre-merge: rewrote the now-stale reject test to assert auto-promotion + added passthrough/round-trip regression guards; reconciled combos/page.tsx file-size baseline. Integrated into release/v3.8.35.
* refactor(chatCore): extrai parse + usage-stats não-streaming do executeProviderRequest (#3501) (#4762)
chatCore #3501: extract parseNonStreamingResponseBody + recordNonStreamingUsageStats. Integrated into release/v3.8.35.
* refactor(chatCore): extrai recordContextEditingTelemetryHook (#3501) (#4779)
chatCore #3501: extract recordContextEditingTelemetryHook. Integrated into release/v3.8.35.
* refactor(chatCore): extrai recordCompressionCacheStats (#3501) (#4792)
chatCore #3501: extract recordCompressionCacheStats. Integrated into release/v3.8.35.
* refactor(chatCore): extrai writeCavemanOutputAnalytics (#3501) (#4794)
chatCore #3501: extract writeCavemanOutputAnalytics. Integrated into release/v3.8.35.
* refactor(chatCore): extrai scheduleQuotaShareConsumption (POST-hook não-streaming, #3501) (#4780)
chatCore #3501: extract scheduleQuotaShareConsumption (non-streaming POST-hook). Integrated into release/v3.8.35.
* refactor(chatCore): extrai emitRequestGamificationEvent (helper compartilhado DRY, #3501) (#4776)
chatCore #3501: extract emitRequestGamificationEvent (DRY streaming/non-streaming). Integrated into release/v3.8.35.
* refactor(chatCore): extrai runPluginOnResponseHook (#3501) (#4782)
chatCore #3501: extract runPluginOnResponseHook. Integrated into release/v3.8.35.
* refactor(chatCore): extrai scheduleStreamingQuotaShareConsumption (POST-hook streaming, #3501) (#4784)
chatCore #3501: extract scheduleStreamingQuotaShareConsumption (streaming POST-hook). Integrated into release/v3.8.35.
* refactor(chatCore): extrai recordStreamingUsageStats (analytics de usage streaming, #3501) (#4791)
chatCore #3501: extract recordStreamingUsageStats. Integrated into release/v3.8.35.
* refactor(chatCore): extrai recordStreamingCost (custo por-request streaming, #3501) (#4790)
chatCore #3501: extract recordStreamingCost (per-request streaming cost). Integrated into release/v3.8.35.
* docs(readme): credit ponytail + OmniCompress; restore env-doc-sync release-green (#4799)
README compression credits (ponytail/OmniCompress) + env-doc-sync ignore for eval-only OMNIROUTE_EVAL_CREDENTIALS (restores release-green after #4720). Integrated into release/v3.8.35.
* chore(quality): trim combo-config.test.ts comments under file-size cap (#4774 follow-up) (#4800)
Restore file-size release-green. Integrated into release/v3.8.35.
* feat(api-docs): Redoc-rendered /api/docs + consolidate OpenAPI spec to docs/openapi.yaml (#4781)
Redoc /api/docs + OpenAPI spec consolidated to docs/openapi.yaml (canonical 201-path complete spec; old path → legacy fallback). All refs/gates/tests/CI updated. Integrated into release/v3.8.35.
* docs(compression): declare Phase 4 layers — Output Styles, adaptive dial, per-request control (#4801)
The README compression section listed the 9 input engines but not the Phase 4
layers now in production:
- Output Styles (output-axis steering: terse-prose / less-code / terse-cjk, lite/full/ultra)
- adaptive context-budget dial (reserve-output|percentage|absolute · floor|replace-autotrigger|off)
- per-request x-omniroute-compression precedence + the offline eval harness
Also bumped the highlights range to v3.8.35, expanded the compression feature bullet,
and marked the GUIDE's Phase 4 row Shipped (was 'Planned' — it's merged on v3.8.35).
Co-authored-by: Diego Rodrigues de Sa e Souza <souzamiriamrodrigues790@gmail.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* chore(release): finalize v3.8.35 CHANGELOG + docs reconciliation
- CHANGELOG: complete 3.8.35 section (all 35 commits since v3.8.34,
contributor attribution: @rdself @megamen32 @KooshaPari @JxnLexn)
- docs(security): align THREAT_MODEL.md refs with real code
(routeGuard.ts, tokenLimits.ts, /api/monitoring/health) — fabricated-docs gate
- check:fabricated-docs: skip docs/superpowers/specs (dated research reports)
- i18n: sync 3.8.35 section into 41 CHANGELOG mirrors (docs-sync size gate)
- ratchet rebaseline: cyclomatic 1916->1920, eslintWarnings 3907->3912
(inherited cycle drift; release-finalize diff is docs-only)
* fix(release): resolve inherited base-reds surfaced by v3.8.35 release CI
Cycle base-reds that only run on PR→main (not the PR→release fast-path):
- test(autoCombo): suffixComposition-4517 used node:test in a vitest-only dir
(#4753) → vitest found no suite. Switch to the vitest API. (Vitest job)
- test(agentSkills): openapiParser fixture wrote docs/reference/openapi.yaml;
parser reads docs/openapi.yaml since #4781 → point fixture at the new path.
(Unit/Coverage/Node24/Node26 shard 4)
- test(integration): proxy-pipeline source-scan expected inline streaming-cost
code that #4790/#3501 extracted to the recordStreamingCost leaf → assert the
delegation instead. (Integration 1/2)
- fix(chatCore): derive the log trace id from crypto, not Math.random
(CodeQL js/insecure-randomness — log-correlation id, not a secret).
- test(resilience): circuit-breaker invalid-cooldown fallback asserted t>29000,
flaking on slow CI where ~1.6s elapsed gave t=28401 → tolerate wall-clock
drift (t>25000). (Unit 6/8)
* fix(usage): derive pending-request id from crypto, not Math.random
CodeQL js/insecure-randomness (#669): the pending-request id generated in
trackPendingRequest (usageHistory.ts) flows into attempt logging and was flagged
as insecure randomness in a security context. It's a log-correlation id, not a
secret — switch to crypto RNG to clear the alert. Pairs with the chatCore traceId
fix in 37c49781a (same sink).
---------
Co-authored-by: Diego Rodrigues de Sa e Souza <souzamiriamrodrigues790@gmail.com>
Co-authored-by: Randi <55005611+rdself@users.noreply.github.com>
Co-authored-by: Demiurge The Single <megamen932@gmail.com>
Co-authored-by: KooshaPari <42529354+KooshaPari@users.noreply.github.com>
Co-authored-by: Jan Leon <Jan.gaschler@gmail.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
36 KiB
omniroute — Agent Guidelines
Project
Unified AI proxy/router — route any LLM through one endpoint. Multi-provider support with 231 provider entries (OpenAI, Anthropic, Gemini, DeepSeek, Groq, xAI, Mistral, Fireworks, Cohere, NVIDIA, Cerebras, Pollinations, Puter, Cloudflare AI, HuggingFace, DeepInfra, SambaNova, Meta Llama API, Moonshot AI, AI21 Labs, Databricks, Snowflake, and many more) with MCP Server (87 tools), A2A v0.3 Protocol, and Electron desktop app.
Live counts (v3.8.31): providers 231 · MCP tools 87 · MCP scopes 30 · A2A skills 6 · open-sse services 115 · routing strategies 15 · auto-combo scoring factors 9 · DB modules 83 · DB migrations 97 · base tables 17 · search providers 11 · i18n locales 42. Refresh with
npm run check:docs-all.
Doc Accuracy Discipline (read before writing any doc)
If
grep -rn "name" src/ open-sse/ bin/returns nothing, the name does not exist. Do not document it.
The recurring failure mode in AI-generated docs is plausible-but-unverified specifics.
Every claim in a .md file under docs/ should be verifiable against the source.
Rules (enforced by npm run check:fabricated-docs):
- Never state an API name, endpoint, path, CLI command, or env var without grepping for it first.
grep -rn "theName" src/ open-sse/ bin/ # 0 hits → do not document - Never write a line count, file size, migration count, provider count, or strategy count from memory.
wc -l <file> # exact line count ls <dir>/*.ts | wc -l # file count - Every code example should be copy-pasted from real usage or actually run — not synthesized.
Link to a real call site (
path:line) instead of inventing a signature. - Prefer citing real source (
file.ts:line) over paraphrasing behavior — verifiable and self-correcting. - A shorter doc that is 100% accurate beats a comprehensive one with fabrications. Wrong docs cost more than missing docs, because people trust and act on them.
The script scripts/check/check-fabricated-docs.mjs extracts every route path, env var, hook
name, function name, and file reference from docs/**/*.md and verifies each one against the
codebase. Run it locally before pushing docs; it runs in CI via npm run check:docs-all.
Stack
- Runtime: Next.js 16 (App Router), Node.js
>=22.0.0 <23 || >=24.0.0 <27, ES Modules ("type": "module") - Language: TypeScript 6.0 (
src/) + JavaScript (open-sse/,electron/) - Database: better-sqlite3 (SQLite) —
DATA_DIRconfigurable, default~/.omniroute/ - Streaming: SSE via
open-sseinternal workspace package - Styling: Tailwind CSS v4
- i18n: next-intl with 42 locales (
src/i18n/messages/) — refresh withls src/i18n/messages/*.json | wc -l - Desktop: Electron (cross-platform: Windows, macOS, Linux)
- Schemas: Zod v4 for all API / MCP input validation
Build, Lint, and Test Commands
| Command | Description |
|---|---|
npm run dev |
Start Next.js dev server |
npm run build |
Production build: next build → .build/next/ + assemble dist/ |
npm run build:release |
Clean rebuild + HEAD sentinel (dist/BUILD_SHA) — use for deploy |
npm run start |
Run production build |
npm run build:cli |
Build CLI package |
npm run lint |
ESLint on all source files |
npm run typecheck:core |
TypeScript core type checking |
npm run typecheck:noimplicit:core |
Strict checking (no implicit any) |
npm run check |
Run lint + test |
npm run check:cycles |
Check for circular dependencies |
npm run electron:dev |
Run Electron app in dev mode |
npm run electron:build |
Build Electron app for current OS |
Build output layout:
| Directory | Purpose | Gitignored |
|---|---|---|
src/ |
Application source (TypeScript / TSX) | No |
.build/ |
Build intermediates (distDir = .build/next) |
Yes |
dist/ |
Shippable bundle assembled by assembleStandalone |
Yes |
The pipeline is a single next build pass — intermediates land in .build/next/, the
assembled bundle in dist/. VPS deploys rsync dist/ into the remote
/usr/lib/node_modules/omniroute/app/ directory (VPS image path is unchanged).
Running Tests
# All tests (unit + vitest + ecosystem + e2e)
npm run test:all
# Single test file (Node.js native test runner — most tests use this)
node --import tsx/esm --test tests/unit/your-file.test.ts
node --import tsx/esm --test tests/unit/plan3-p0.test.ts
node --import tsx/esm --test tests/unit/fixes-p1.test.ts
node --import tsx/esm --test tests/unit/security-fase01.test.ts
# Integration tests
node --import tsx/esm --test tests/integration/*.test.ts
# Vitest (MCP server, autoCombo)
npm run test:vitest
# E2E with Playwright
npm run test:e2e
# Protocol clients E2E (MCP transports, A2A)
npm run test:protocols:e2e
# Ecosystem compatibility tests
npm run test:ecosystem
# Coverage (see CONTRIBUTING.md)
npm run test:coverage
For authoritative coverage requirements, test execution, and PR gates, see CONTRIBUTING.md.
Code Style Guidelines
Formatting (Prettier — enforced via lint-staged)
2 spaces · semicolons required · double quotes (") · 100 char width · es5 trailing commas.
Always run prettier --write on changed files.
TypeScript
- Target: ES2022 · Module:
esnext· Resolution:bundler strict: false— prefer explicit types, don't rely on inference- Path aliases:
@/*→src/,@omniroute/open-sse→open-sse/,@omniroute/open-sse/*→open-sse/*
ESLint Rules
- Security (error, everywhere):
no-eval,no-implied-eval,no-new-func - Relaxed in
open-sse/andtests/:@typescript-eslint/no-explicit-any= warn - React hooks rules and
@next/next/no-assign-module-variabledisabled inopen-sse/andtests/
Naming
| Element | Convention | Example |
|---|---|---|
| Files | camelCase / kebab-case | chatCore.ts, tokenHealthCheck.ts |
| React components | PascalCase | Dashboard.tsx, ProviderCard.tsx |
| Functions/variables | camelCase | getHealth(), switchCombo() |
| Constants | UPPER_SNAKE | MAX_RETRIES, DEFAULT_TIMEOUT |
| Interfaces | PascalCase (I prefix optional) |
ProviderConfig |
| Enums | PascalCase (members too) | LogLevel.Error |
Imports
- Order: external → internal (
@/,@omniroute/open-sse) → relative (./,../) - No barrel imports from
localDb.ts— import from the specificdb/module instead
Error Handling
- try/catch with specific error types; always log with context (pino logger)
- Never silently swallow errors in SSE streams — use abort signals for cleanup
- Return proper HTTP status codes (4xx client, 5xx server)
Security
- NEVER commit API keys, secrets, or credentials
- Validate all user inputs with Zod schemas
- Auth middleware required on all API routes
- Never log SQLite encryption keys
- Sanitize user content (dompurify for HTML)
- Public upstream OAuth identifiers (Gemini / Antigravity / Windsurf-style client_id/secret + Firebase Web keys extracted from public CLIs): use
resolvePublicCred()fromopen-sse/utils/publicCreds.ts, never as string literals. Full pattern indocs/security/PUBLIC_CREDS.md. - Error responses (HTTP / SSE / executor / MCP): use
buildErrorBody()orsanitizeErrorMessage()fromopen-sse/utils/error.ts, never put rawerr.stack/err.messagein a Response body. Full pattern indocs/security/ERROR_SANITIZATION.md. exec()/spawn()with runtime values: pass via theenvoption, never string-interpolate paths/values into the script body. Reference:src/mitm/cert/install.ts::updateNssDatabases.- Prefer secure-by-default libraries when available — see tldrsec/awesome-secure-defaults for the curated list (Helmet.js, DOMPurify, ssrf-req-filter, safe-regex, Google Tink, etc.).
Architecture
Data Layer (src/lib/db/)
All persistence uses SQLite through 83 domain-specific modules in src/lib/db/. Top modules:
- Core:
core.ts,migrationRunner.ts,encryption.ts,stateReset.ts - Providers / catalog:
providers.ts,models.ts,providerLimits.ts,compressionAnalytics.ts - Routing:
combos.ts,modelComboMappings.ts,domainState.ts,commandCodeAuth.ts - Auth:
apiKeys.ts,secrets.ts,registeredKeys.ts,sessionAccountAffinity.ts - Usage / billing:
quotaSnapshots.ts,creditBalance.ts,usage*.ts,compressionCacheStats.ts - Storage:
backup.ts,cleanup.ts,jsonMigration.ts,healthCheck.ts,databaseSettings.ts - Extension modules:
evals.ts,webhooks.ts,reasoningCache.ts,readCache.ts,tierConfig.ts,compressionCombos.ts,compressionScheduler.ts,batches.ts,files.ts,syncTokens.ts,proxies.ts,oneproxy.ts,upstreamProxy.ts,versionManager.ts,cliToolState.ts,prompts.ts,detailedLogs.ts,contextHandoffs.ts,compression.ts,stats.ts
Live count: ls src/lib/db/*.ts | wc -l (currently 83). Drift detection: npm run check:docs-counts.
Schema migrations live in db/migrations/ (97 files as of v3.8.24) and run via migrationRunner.ts.
src/lib/localDb.ts is a re-export layer only — never add logic there.
DB Internals
core.ts:getDbInstance()returns a singletonbetter-sqlite3instance with WAL journaling.SCHEMA_SQLdefines 17 base tables (verify withgrep -c "CREATE TABLE" src/lib/db/core.tsminus 1 for the bookkeeping_omniroute_migrationstable). Helpers:rowToCamel,encryptConnectionFields.migrationRunner.ts: Applies versioned SQL files fromdb/migrations/inside transactions. Tracks applied migrations in_omniroute_migrationstable.- Migrations: 97 files (
001_initial_schema.sql→099_*.sql). Each migration is idempotent and runs in a transaction. Live count:ls src/lib/db/migrations/*.sql | wc -l. - Domain modules import
getDbInstance()fromcore.tsfor all CRUD operations. Each module owns a specific table/set of tables (e.g.,providers.ts→provider_connections,combos.ts→combos). Encryption helpers protect sensitive fields at rest. localDb.tsre-exports all domain modules — consumers import from here for convenience.
API Route Layer (src/app/api/v1/)
Next.js App Router routes — each follows a consistent pattern:
Route → CORS preflight → Body validation (Zod) → Optional auth (extractApiKey/isValidApiKey)
→ API key policy enforcement (enforceApiKeyPolicy) → Handler delegation (open-sse)
| Route | Handler | Notes |
|---|---|---|
chat/completions/route.ts |
handleChat() |
+ prompt injection guard (clones request) |
responses/route.ts |
handleChat() (unified) |
Responses API format |
embeddings/route.ts |
handleEmbedding() |
Model listing + creation |
images/generations/route.ts |
handleImageGeneration() |
Model listing + creation |
audio/transcriptions/route.ts |
audio handler | Multipart form data |
audio/speech/route.ts |
TTS handler | Binary audio response |
videos/generations/route.ts |
video handler | ComfyUI/SD WebUI |
music/generations/route.ts |
music handler | ComfyUI workflows |
moderations/route.ts |
moderation handler | Content safety |
rerank/route.ts |
rerank handler | Document relevance |
search/route.ts |
search handler | Web search (12 providers per open-sse/handlers/search.ts:6) |
No global Next.js middleware file — interception is route-specific. Auth is optional
(controlled by REQUIRE_API_KEY env). Prompt injection guard is unique to chat completions.
Request Pipeline (open-sse/)
The open-sse/ workspace is the core streaming engine. Full request flow:
Client Request
→ src/app/api/v1/.../route.ts (Next.js route)
→ open-sse/handlers/chatCore.ts::handleChatCore()
→ Semantic/signature cache check
→ Rate limit check (rateLimitManager)
→ Combo routing? → open-sse/services/combo.ts::handleComboChat()
→ resolveComboTargets() → ordered ResolvedComboTarget[]
→ For each target: handleSingleModel() (wraps chatCore)
→ translateRequest() (open-sse/translator/)
→ Convert source format (e.g., OpenAI) → target format (e.g., Claude)
→ getExecutor() → provider-specific executor instance
→ executor.execute() (BaseExecutor → DefaultExecutor or provider-specific)
→ buildUrl() + buildHeaders() + transformRequest()
→ fetch() to upstream provider
→ Retry logic with exponential backoff
→ Response translation back to client format
→ If Responses API: responsesTransformer.ts TransformStream
→ SSE stream or JSON response to client
Handlers (open-sse/handlers/): chatCore.ts, responsesHandler.ts, embeddings.ts,
imageGeneration.ts, videoGeneration.ts, musicGeneration.ts, audioSpeech.ts,
audioTranscription.ts, moderations.ts, rerank.ts, search.ts.
Upstream headers: merged after default auth; same header name replaces executor value.
T5 intra-family fallback recomputes headers using only the fallback model id.
Forbidden header names: src/shared/constants/upstreamHeaders.ts — keep sanitize,
Zod schemas, and unit tests aligned when editing.
Provider Categories
- Free (4): Qoder AI, Qwen Code, Gemini CLI (deprecated), Kiro AI
- OAuth (14): Claude Code, Antigravity, Codex, GitHub Copilot, Cursor, Kimi Coding, Kilo Code, Cline, Qwen (⚠️ free tier discontinued 2026-04-15), Kiro, Qoder, Gemini, Windsurf (v3.8), GitLab Duo (v3.8)
- API Key (120+): OpenAI, Anthropic, Gemini, DeepSeek, Groq, xAI, Mistral, Perplexity, Together, Fireworks, Cerebras, Cohere, NVIDIA, Nebius, SiliconFlow, Hyperbolic, HuggingFace, OpenRouter, Vertex AI, Cloudflare AI, Scaleway, AI/ML API, Pollinations, Puter, Longcat, Alibaba, Kimi, Minimax, Blackbox, Synthetic, Kilo Gateway, Z.AI, GLM, Deepgram, AssemblyAI, ElevenLabs, Cartesia, PlayHT, Inworld, NanoBanana, SD WebUI, ComfyUI, Ollama Cloud, Perplexity Search, Serper, Brave, Exa, Tavily, OpenCode Zen/Go, Bailian Coding Plan, DeepInfra, Vercel AI Gateway, Lambda AI, SambaNova, nScale, OVHcloud AI, Baseten, PublicAI, Moonshot AI, Meta Llama API, v0 (Vercel), Morph, Featherless AI, FriendliAI, LlamaGate, Galadriel, Weights & Biases Inference, Volcengine, AI21 Labs, Venice.ai, Codestral, Upstage, Maritalk, Xiaomi MiMo, Inference.net, NanoGPT, Predibase, Bytez, Heroku AI, Databricks, Snowflake Cortex, GigaChat (Sber), CrofAI, AgentRouter, ChatGPT Web, Baidu Qianfan, AWS Polly, RunwayML, GitLab Duo, Amazon Q, Empower, Poe, and many more.
- Self-Hosted (8+): LM Studio, vLLM, Lemonade, Llamafile, Triton, Docker Model Runner, Xinference, Oobabooga
- Custom: OpenAI-compatible (
openai-compatible-*) and Anthropic-compatible (anthropic-compatible-*) prefixes
Providers are registered in src/shared/constants/providers.ts with Zod validation at module load.
Executors (open-sse/executors/)
Provider-specific request executors: base.ts, default.ts, cursor.ts, codex.ts,
antigravity.ts, github.ts, gemini-cli.ts, kiro.ts, qoder.ts, vertex.ts,
cloudflare-ai.ts, opencode.ts, pollinations.ts, puter.ts.
Executor Internals
base.ts(BaseExecutor): Abstract base withbuildUrl(),buildHeaders(),transformRequest(), retry logic (exponential backoff), andexecute(). Subclasses override URL/header/transform methods for provider-specific behavior.default.ts(DefaultExecutor extends BaseExecutor): Handles most OpenAI-compatible providers. Reads provider config fromproviderRegistry.tsto resolve base URL, auth header format, and request transformations.getExecutor()(executors/index.ts): Factory that returns the correct executor instance based on provider ID. Provider-specific executors (Cursor, Codex, Vertex, etc.) override only what differs from the default.
Translator (open-sse/translator/)
Translates between API formats (OpenAI-format ↔ Anthropic, Gemini, etc.). Includes request/response translators with helpers for image handling.
Translator Internals
translator/index.ts: ExportstranslateRequest()and format constants. Called bychatCore.tsbefore executor dispatch.- Flow:
translateRequest(body, sourceFormat, targetFormat)→ detects source format (OpenAI, Anthropic, Gemini) → applies the matching translator module → returns transformed body ready for the target provider. - Response translation runs in reverse after upstream response, converting back to the client's expected format.
Transformer (open-sse/transformer/)
responsesTransformer.ts — transforms Responses API format to/from Chat Completions format.
Transformer Internals
createResponsesApiTransformStream(): Returns aTransformStreamthat converts Chat Completions SSE chunks (data: {"choices":[...]}) into Responses API SSE events (response.output_item.added,response.output_text.delta, etc.).- Used when the client sends a Responses API request: the request is internally converted to Chat Completions format, dispatched normally, and the response is piped through this transform stream before reaching the client.
Services (open-sse/services/)
115 service modules in open-sse/services/ (top-level only; 184 including sub-dirs like autoCombo/ and compression/). Refresh: ls open-sse/services/*.ts | wc -l. Key modules:
combo.ts (routing engine), usage.ts, tokenRefresh.ts,
rateLimitManager.ts, accountFallback.ts, sessionManager.ts, wildcardRouter.ts,
autoCombo/, intentClassifier.ts, taskAwareRouter.ts, thinkingBudget.ts,
contextManager.ts, modelDeprecation.ts, modelFamilyFallback.ts,
emergencyFallback.ts, workflowFSM.ts, backgroundTaskDetector.ts, ipFilter.ts,
signatureCache.ts, volumeDetector.ts, contextHandoff.ts, compression/ (prompt
compression pipeline), and more.
Prompt Compression Pipeline (compression/)
Modular prompt compression that runs proactively before the existing reactive context manager.
strategySelector.ts: Selects compression mode based on config, compression combo assignments, combo overrides, auto-trigger thresholds, and defaults. Priority: assigned compression combo > combo override > auto-trigger > default mode > off.lite.ts: 5 lite-mode techniques:collapseWhitespace,dedupSystemPrompt,compressToolResults,removeRedundantContent,replaceImageUrls. Target: 10-15% savings at <1ms latency.caveman.ts/cavemanRules.ts: Caveman-style semantic condensation backed by built-in rules plus file-loaded language packs undercompression/rules/.engines/rtk/: Rule-based terminal/tool-output compression inspired by RTK patterns. Detects command output classes, applies JSON filter packs, deduplicates repeated lines, strips ANSI/code noise, and preserves errors/actionable context. The RTK JSON DSL supports replace, match-output short-circuit, strip/keep, per-line truncation, head/tail/max-line truncation, inline tests, trust-gated project/global custom filters, and optional redacted raw-output retention for authenticated recovery.engines/registry.ts: Registers engines (caveman,rtk) and powers stacked pipelines.stats.ts: Per-request compression stats tracking (original tokens, compressed tokens, savings %, techniques used, engine breakdown, compression combo id).types.ts:CompressionMode(off/lite/standard/aggressive/ultra/rtk/stacked),CompressionConfig,CompressionStats,CompressionResult.- DB settings in
src/lib/db/compression.ts, compression combos insrc/lib/db/compressionCombos.ts, API routes undersrc/app/api/settings/compression/,src/app/api/context/*, and preview/language-pack routes undersrc/app/api/compression/*.
Combo Routing Engine (combo.ts)
handleComboChat(): Entry point for combo-routed requests. Receives the combo config and iterates through targets in order until one succeeds or all fail.resolveComboTargets(): Expands a combo configuration into an ordered array ofResolvedComboTarget[], each specifying provider + model + account + credentials.- Strategies (15): priority, weighted, fill-first, round-robin, P2C, random, least-used, reset-aware (v3.8),
reset-window, cost-optimized, strict-random, auto, lkgp, context-optimized, context-relay. Source:
ROUTING_STRATEGY_VALUESinsrc/shared/constants/routingStrategies.ts. - Each target calls
handleSingleModel()which wrapshandleChatCore()with per-target error handling and circuit breaker checks.
Domain Layer (src/domain/)
Policy engine modules: policyEngine.ts, comboResolver.ts, costRules.ts,
degradation.ts, fallbackPolicy.ts, lockoutPolicy.ts, modelAvailability.ts,
providerExpiration.ts, quotaCache.ts, responses.ts, configAudit.ts.
MCP Server (open-sse/mcp-server/)
87 tools total (TOTAL_MCP_TOOL_COUNT, open-sse/mcp-server/server.ts): a 33-entry base registry (MCP_TOOLS in schemas/tools.ts, bundling the core / cache / compression / 1proxy / advanced tools) plus standalone module sets — memory (3), skill (4), agentSkill (3), gamification (8), plugin (8), notion (6), obsidian (22). 3 transports (stdio / SSE / Streamable HTTP). Scoped auth (30 scopes — see OMNIROUTE_MCP_SCOPES), Zod schemas. See docs/frameworks/MCP-SERVER.md.
Core tools (20): get_health, list_combos, get_combo_metrics, switch_combo, check_quota, route_request, cost_report, list_models_catalog, web_search, simulate_route, set_budget_guard, set_routing_strategy, set_resilience_profile, test_combo, get_provider_metrics, best_combo_for_task, explain_route, get_session_snapshot, db_health_check, sync_pricing.
Cache tools (2): cache_stats, cache_flush.
Compression tools (5): compression_status, compression_configure, set_compression_engine, list_compression_combos, compression_combo_stats.
1proxy tools (3): oneproxy_fetch, oneproxy_rotate, oneproxy_stats.
Memory tools (3): memory_search, memory_add, memory_clear.
Skill tools (4): skills_list, skills_enable, skills_execute, skills_executions.
Agent-skill tools (3): A2A skill discovery / invocation bridges.
Gamification tools (8): levels, badges, leaderboard, and community-federation queries.
Plugin tools (8): plugin marketplace listing, install/enable/disable, and runtime inspection.
Notion tools (6) + Obsidian tools (22): knowledge-base read/write integrations (the largest tool family — vault search, note CRUD, WebDAV-backed file ops).
MCP Internals
- Tool registration: Each tool is an object with
{ name, description, inputSchema: ZodSchema, handler: async (args) => {...} }. Zod validates inputs before the handler fires. createMcpServer()andstartMcpStdio()exported frommcp-server/index.ts.createMcpServer()wires all tool sets;startMcpStdio()launches the stdio transport.- Transports: stdio (CLI
omniroute --mcp), SSE (/api/mcp/sse), Streamable HTTP (/api/mcp/stream). All share the same tool/scope engine. - Scopes (30): Control which tool categories an API key can access. Enforcement happens before handler dispatch.
- Audit: Every tool invocation is logged to SQLite (
mcp_audittable) with tool name, args, success/failure, API key attribution, and timestamp.
A2A Server (src/lib/a2a/)
JSON-RPC 2.0, SSE streaming, Task Manager with TTL cleanup.
Agent Card at /.well-known/agent.json.
Skills (6): smartRouting.ts, quotaManagement.ts, providerDiscovery.ts, costAnalysis.ts, healthReport.ts, listCapabilities.ts.
A2A Internals
taskManager.ts: State machine lifecycle for tasks:submitted → working → completed | failed | canceled. Tasks have TTL and are cleaned up automatically.- JSON-RPC methods:
message/send(sync),message/stream(SSE),tasks/get,tasks/cancel. Dispatched viaPOST /a2a. - Skills: Registered in a DB-backed registry. Each skill receives task context
(messages, metadata) and returns structured results.
quotaManagement.tssummarizes quota;smartRouting.tsrecommends routing decisions. - Agent Card:
/.well-known/agent.jsonexposes capabilities, skills, and metadata for client auto-discovery.
ACP Module (src/lib/acp/)
Agent Communication Protocol registry and manager.
Memory System (src/lib/memory/)
Extraction, injection, retrieval, summarization, and store modules for persistent conversational memory across sessions.
Skills System (src/lib/skills/)
Extensible skill framework: registry, executor, sandbox, built-in skills, custom skill support, interception, and injection.
Skills Internals
registry.ts: DB-backed skill registration and discovery. Skills have metadata (name, description, version, enabled status) stored in SQLite.executor.ts: Execution engine with configurable timeout and retry logic. Receives skill name + input, looks up the skill, runs it in the sandbox.sandbox.ts: Isolation layer for custom (user-provided) skills. Limits resource access and execution time.- Built-in skills: Ship with OmniRoute (e.g., quota management, routing). Located alongside the registry.
- Interception/Injection: Skills can intercept requests in the pipeline (pre/post processing) or inject context into prompts.
Compliance (src/lib/compliance/)
Policy index for compliance enforcement.
MITM Proxy (src/mitm/)
MITM proxy capability with certificate management, DNS handling, and target routing.
Middleware (src/middleware/)
Request middleware including promptInjectionGuard.ts.
Guardrails (src/lib/guardrails/)
Hot-reloadable guardrails framework (3 built-in: pii-masker, prompt-injection, vision-bridge). Fail-open; per-request opt-out via header. See docs/security/GUARDRAILS.md.
Cloud Agents (src/lib/cloudAgent/)
CloudAgentBase abstract class + 3 agents (codex-cloud, devin, jules). Tasks persisted in cloud_agent_tasks; management auth required. See docs/frameworks/CLOUD_AGENT.md.
Evals (src/lib/evals/)
Generic eval framework: evalRunner.ts, runtime.ts. Targets: combo / model / suite-default. See docs/frameworks/EVALS.md.
Webhooks (src/lib/webhookDispatcher.ts)
HMAC-signed delivery, exponential backoff, auto-disable after 10 failures. 7 event types. See docs/frameworks/WEBHOOKS.md.
Authorization Pipeline (src/server/authz/)
classify → policies → enforce. 3 route classes (PUBLIC / CLIENT_API / MANAGEMENT). See docs/architecture/AUTHZ_GUIDE.md.
Reasoning Replay (src/lib/db/reasoningCache.ts + open-sse/services/reasoningCache.ts)
Hybrid in-memory + SQLite cache for reasoning_content. Re-injects on multi-turn for strict providers (DeepSeek V4, Kimi K2, Qwen-Thinking, GLM, xiaomi-mimo). See docs/routing/REASONING_REPLAY.md.
Tunnels (src/lib/{cloudflaredTunnel,ngrokTunnel}.ts + src/app/api/tunnels/)
Cloudflare Quick/Named, ngrok, Tailscale Funnel. See docs/ops/TUNNELS_GUIDE.md.
Adding a New Provider
- Register in
src/shared/constants/providers.ts - Add executor in
open-sse/executors/(if custom logic needed) - Add translator in
open-sse/translator/(if non-OpenAI format) - Add OAuth config in
src/lib/oauth/constants/oauth.ts(if OAuth-based) - Add models in
open-sse/config/providerRegistry.ts
Subdirectory AGENTS.md Files
src/lib/db/AGENTS.md— SQLite persistence, domain modules, migrationsopen-sse/services/AGENTS.md— Routing engine, combo resolution, strategy selection
Reference Documentation (docs/)
For any non-trivial change, read the matching deep-dive first:
Fork / Upstream Workflow
This repository is a fork of diegosouzapw/OmniRoute. Keep fork-only operational
changes (for example GHCR image publishing, personal deployment workflows, or local
automation) out of upstream contribution PRs.
When preparing a PR for upstream, always start the work branch from upstream/main,
not from this fork's main:
git fetch upstream
git switch -c <branch-name> upstream/main
Only cherry-pick or reapply the changes intended for the upstream PR.
Review Focus
- DB ops go through
src/lib/db/modules, never raw SQL in routes - Provider requests flow through
open-sse/handlers/ - MCP/A2A pages are tabs inside
/dashboard/endpoint, not standalone routes - No memory leaks in SSE streams (abort signals, cleanup)
- Rate limit headers must be parsed correctly
- All API inputs validated with Zod schemas
- Provider constants validated at module load via Zod (
src/shared/validation/providerSchema.ts) - Pricing data syncs from LiteLLM via
src/lib/pricingSync.ts - Memory/Skills are cross-cutting: affect MCP tools, request pipeline, and A2A skills
- ⛔ NEVER close a contributor's PR after using their code — always merge via GitHub so they get credit. See
.agents/workflows/review-prs.mdfor full policy.