Compare commits

...

83 Commits

Author SHA1 Message Date
Diego Rodrigues de Sa e Souza 05ea200170 Merge pull request #67 from diegosouzapw/release/v0.8.8
release(v0.8.8): analytics redesign, settings restructure, routing expansion, editable rate limits
2026-02-17 14:47:56 -03:00
diegosouzapw 050e289a8c release(v0.8.8): bump version, analytics redesign, settings restructure, routing expansion, editable rate limits, CLI tools state persistence, docs update 2026-02-17 14:47:06 -03:00
diegosouzapw 426c5f5e1b feat(health): add reset button to clear all circuit breaker statuses 2026-02-17 13:09:30 -03:00
diegosouzapw ba3e7c53ac feat(dashboard): enhance analytics/evals page with explanatory content, new suites, and improved design 2026-02-17 12:51:50 -03:00
diegosouzapw d7aa2801bb feat(dashboard): add import models progress modal with real-time feedback 2026-02-17 12:32:23 -03:00
Diego Rodrigues de Sa e Souza defda32df6 Merge pull request #66 from diegosouzapw/refactor/usage-to-request-logs-and-limits
refactor(dashboard): rename Usage to Request Logs and extract Limits & Quotas page
2026-02-17 12:17:19 -03:00
diegosouzapw 6b1b16a80e refactor(dashboard): rename Usage to Request Logs and extract Limits & Quotas page
- Rename 'Usage' sidebar item to 'Request Logs' with receipt_long icon
- Add new 'Limits & Quotas' sidebar item with tune icon
- Extract ProviderLimits, RateLimitStatus, SessionsTab to dedicated /dashboard/limits page
- Simplify usage page to only Logger and Proxy tabs
- Update HomePageClient Quick Start cross-reference text
2026-02-17 12:16:41 -03:00
Diego Rodrigues de Sa e Souza a3232bc00c Merge pull request #65 from diegosouzapw/fix/ci-eslint-and-test-imports
fix(ci): downgrade ESLint 10→9, fix test imports, add open-sse to eslint ignores
2026-02-17 09:09:38 -03:00
diegosouzapw b72292eeea fix(ci): downgrade ESLint 10→9, fix test imports .js→.ts, add open-sse to eslint ignores
- Downgrade eslint 10.0.0 → 9.x (incompatible with eslint-config-next)
- Update 30+ test file imports from .js to .ts (accountSelector, combo, etc.)
- Add open-sse/** to ESLint ignores (no TS parser configured for it)
- All CI steps now pass: lint , build , unit tests (368/0) 
2026-02-17 09:09:06 -03:00
Diego Rodrigues de Sa e Souza c7a77d6f62 Merge pull request #64 from diegosouzapw/fix/import-paths-js-to-ts
fix(build): update all import paths from .js to .ts
2026-02-17 09:01:50 -03:00
diegosouzapw e21fc439b8 fix(build): update all import paths from .js to .ts after TypeScript migration
- Update 294 import paths across 99 files
- Fix 'Module not found' errors from stale .js extensions
- Covers: from '.../.js', bare import '.../.js', @omniroute/open-sse/*.js
- Build now passes: npm run build exits with code 0
2026-02-17 09:00:54 -03:00
Diego Rodrigues de Sa e Souza 6d129072fe Merge pull request #63 from diegosouzapw/docs/v0.8.5-documentation
docs: comprehensive v0.8.5 documentation update
2026-02-17 08:48:33 -03:00
diegosouzapw 7296a6461a docs: comprehensive v0.8.5 documentation update
- README: expand features table from 16 to 40+ entries across 5 categories
  (Core Routing, Multi-Modal APIs, Resilience, Observability, Deployment)
- README: update tech stack to reflect 100% TypeScript codebase
- README: update Docker tag 0.6.0 → 0.8.5, release command to v0.8.5
- CHANGELOG: add detailed v0.8.5 section (40 commits categorized)
  covering TLS spoofing, SQLite logs, unified logging, full TS migration,
  Qwen fix, VPS compatibility, CI improvements, dependency bumps
- ARCHITECTURE: update all open-sse file references .js → .ts
- CODEBASE_DOCUMENTATION: update all open-sse file references .js → .ts
2026-02-17 08:47:58 -03:00
Diego Rodrigues de Sa e Souza e98d834016 Merge pull request #62 from diegosouzapw/refactor/open-sse-js-to-ts
refactor(open-sse): JS → TS migration + v0.8.5
2026-02-17 08:39:51 -03:00
diegosouzapw c164ab877f chore: bump version to 0.8.5
- Update package.json version to 0.8.5
- Update package-lock.json version to 0.8.5
- Update version references in docs/new-features
2026-02-17 08:39:16 -03:00
diegosouzapw c9a26da798 refactor(open-sse): phase 7 — zero @ts-ignore, zero TSC errors
- Remove ALL 231 @ts-ignore annotations (231 → 0)
- Fix 237 TypeScript errors with proper typings:
  - Type 30+ variable declarations as Record<string, any>
  - Add optional params: model?, provider?, retryAfter?, retryAfterHuman?
  - Replace @ts-ignore with 'as any' casts for custom Error/Array properties
  - Add EdgeRuntime global declaration for edge runtime compat
  - Import fs/path in responsesTransformer.ts
  - Fix function argument mismatches (resolveComboConfig, unavailableResponse)
- Build: tsc --noEmit passes with 0 errors
2026-02-17 08:31:52 -03:00
diegosouzapw c9f9892095 refactor(open-sse): phase 6 — reduce @ts-ignore from 231 to 186
- Remove 209 standalone @ts-ignore annotations
- Fix 11 root-cause object literals with Record<string, any> typing
- Properly type message objects in responseTranslator, kiro executor
- Re-insert 164 targeted @ts-ignore for remaining complex patterns
- Net reduction: 231 → 186 @ts-ignore (-20%)
- Zero TypeScript errors maintained
2026-02-17 07:50:48 -03:00
diegosouzapw 94175fa04a refactor(open-sse): migrate all 94 .js files to .ts
- Rename all 94 .js files to .ts across config/, utils/, services/,
  handlers/, executors/, translator/, transformer/, and root index
- Add proper TypeScript interfaces: RegistryEntry, AudioProvider, FetchOptions
- Add class property declarations to BaseExecutor
- Type key function parameters in utils layer (tlsClient, stream,
  logger, error, proxyFetch, proxyDispatcher, etc.)
- Add @ts-ignore annotations for remaining TS2339 errors (gradual migration)
- Zero TypeScript errors in open-sse/tsconfig.json
- Zero .js files remaining in open-sse/
2026-02-17 07:47:58 -03:00
Diego Rodrigues de Sa e Souza 3d4b2ca255 Merge pull request #61 from diegosouzapw/fix/ts-hardening-wave4d-dashboard
Fix/ts hardening wave4d dashboard
2026-02-17 07:09:19 -03:00
Diego Rodrigues de Sa e Souza d6b95e687d Merge pull request #60 from diegosouzapw/fix/token-refresh-connection-tests
fix(token-refresh): detect Qwen invalid_request as unrecoverable & switch broken test endpoints to checkExpiry
2026-02-17 07:08:50 -03:00
diegosouzapw a553e0aa88 fix(dashboard): resolve all TypeScript errors across dashboard pages
Wave 4d: Fix 87+ TS errors across 20+ dashboard files:
- Settings tabs (5): state typing, date arithmetic, FilterBar children
- Translator (2): provider options hook, TestBenchMode
- Usage: EvalsTab ReactNode, ProviderLimits (3 files)
- Providers (5): page, new, [id], ModelAvailabilityBadge/Panel
- CLI Tools (3): ClaudeToolCard, ClineToolCard, KiloToolCard
- Combos: missing props, saveData typing
- Endpoint: Object.entries grouped model access
- API routes: remaining type casts

Result: tsc --noEmit = 0 errors, npm run build = success
2026-02-17 06:53:52 -03:00
diegosouzapw ccd4ab6c8d chore(ts): wave 4c — type 8 files (components, SSE handlers, services) 313→252 2026-02-17 06:13:11 -03:00
diegosouzapw 7729896dc2 chore(ts): wave 4b — type 7 more API routes (providers, test, usage, nodes)
Files typed:
- providers/route.ts (POST Request, providerSpecificData typed)
- providers/[id]/test/route.ts (13 functions typed, runtime casts)
- usage/call-logs/route.ts (GET Request, filter Record)
- usage/proxy-logs/route.ts (GET Request, filters Record, error casts)
- oauth/cursor/auto-import/route.ts (tokens Record, error casts)
- usage/[connectionId]/route.ts (GET Request+params, updateData Record)
- provider-nodes/[id]/route.ts (PUT/DELETE Request+params, updates Record)

TS errors: 347 → 313 (-34)
2026-02-17 06:03:43 -03:00
diegosouzapw 3c79cd34eb chore(ts): wave 4a — type 7 API routes (providers, cli-tools, oauth)
Files typed:
- providers/[id]/route.ts (Request, params, Record, result spread)
- openclaw-settings/route.ts (Request, settings Record, error catches)
- cline-settings/route.ts (Request, globalState/secrets Record, error catches)
- droid-settings/route.ts (Request, settings Record, error catches)
- claude-settings/route.ts (Request, currentSettings Record, error catches)
- codex-settings/route.ts (Request, parsed/authData Record, TOML parser typed)
- oauth/[provider]/[action]/route.ts (Request, params, error catches)

TS errors: 419 → 347 (-72)
2026-02-17 05:59:12 -03:00
diegosouzapw f1319448ac refactor(types): Wave 3c — OAuth services + server utils typed
- oauth.ts: typed OAuthService class with config field, all method params
- antigravity.ts: typed AntigravityService class + all OAuth flow params
- iflow.ts: typed IFlowService class + Basic Auth flow params
- gemini.ts: typed GeminiCLIService class + project ID fetching
- qwen.ts: typed QwenService class + device code flow params
- cursor.ts: typed CursorService class + checksum/headers params
- server.ts: typed startLocalServer return + waitForCallback
- Fixed resolve() calls to resolve(undefined) for strict Promise

TS errors: 490 → 419 (-71)
Total reduction: 984 → 419 (-565, 57.4%)
Build:   Tests: 368/368 
2026-02-17 03:46:24 -03:00
diegosouzapw 52b025ca5a refactor(types): Wave 3b — usage, CLI runtime, SSE auth/logger typed
- callLogs.ts: typed all CRUD params + error catches
- usageHistory.ts: typed pending requests, filter/entry params
- cliRuntime.ts: typed CLI_TOOLS map + all arrow function params
- sse/auth.ts: typed credentials/fallback/mutex params + Date.getTime()
- sse/utils/logger.ts: typed all logger functions + made data optional

TS errors: 578 → 490 (-88)
Total reduction: 984 → 490 (-494, 50.2%)
Build:   Tests: 368/368 
2026-02-17 03:41:21 -03:00
diegosouzapw 859f6db36c refactor(types): Wave 3a — lib layer, db, compliance, domain typed
- proxyLogger.ts: ProxyLogEntry/ProxyLogFilters interfaces + typed params
- errorCodes.ts: ErrorCodeDef/ErrorDetails interfaces
- usageAnalytics.ts: typed computeAnalytics + helper function params
- policyEngine.ts: PolicyRequest/PolicyVerdict/Policy interfaces + typed PolicyEngine class
- db/providers.ts: typed all CRUD function params
- db/settings.ts: typed pricing/proxy/settings params + Record<> index types
- compliance/index.ts: typed audit log and noLog params
- domain/responses.ts: typed all response factory params

TS errors: 654 → 578 (-76)
Total reduction: 984 → 578 (-406, 41.3%)
Build:   Tests: 368/368 
2026-02-17 03:35:11 -03:00
diegosouzapw faedce9b4a refactor(types): Wave 2b — Zustand stores, logger, sync scheduler
- themeStore.ts: ThemeState interface for typed Zustand store
- structuredLogger.ts: typed formatEntry/createLogger params, fix correlationId
- cloudSyncScheduler.ts: typed class fields + singleton factory

TS errors: 675 → 654 (-21)
Total reduction: 984 → 654 (-330, 33.5%)
Build:   Tests: 368/368 
2026-02-17 03:21:29 -03:00
diegosouzapw 03c7f66603 refactor(types): Wave 2 — utils & services typed fields
- circuitBreaker.ts: CircuitBreakerOptions interface, typed class fields (76 errors)
- streamTracker.ts: StreamMetrics interface, typed private fields (38 errors)
- requestTelemetry.ts: PhaseTiming/TelemetrySummary interfaces, typed fields (21 errors)
- streamState.ts: StreamState/StreamTransition types, typed fields (38 errors)
- requestTimeout.ts: TimeoutOptions interface, typed generics (6 errors)
- fetchTimeout.ts: FetchTimeoutOptions interface, typed class fields (4 errors)
- api.ts: ApiOptions interface, typed function params (6 errors)

TS errors: 862 → 675 (-187)
Build:   Tests: 368/368 
2026-02-17 03:15:19 -03:00
diegosouzapw 3607eceb41 refactor(types): Wave 1 — shared component interfaces + EventTarget fixes
- Added TypeScript Props interfaces to 8 shared components:
  Badge, Input, Select, Toggle, SegmentedControl, DataTable, EmptyState, Tooltip
- Batch-fixed 15 e.target.style → e.currentTarget EventTarget issues
- Created missing src/lib/oauth/config/index.ts (getServerCredentials)
- Added module declarations for figlet, chalk, gradient-string, chalk-animation

TS errors: 984 → 862 (-122)
Build:   Tests: 368/368 
2026-02-17 03:05:59 -03:00
diegosouzapw 6bff90edf7 fix(token-refresh): detect Qwen invalid_request as unrecoverable error and switch broken test endpoints to checkExpiry
- refreshQwenToken now detects 'invalid_request' and returns sentinel error
- isUnrecoverableRefreshError expanded to match invalid_request
- Switched Qwen, IFlow, Cline test configs to checkExpiry mode (endpoints were returning 404/400/stale-auth)
- Fixed TypeScript errors in testSingleConnection (union type casts, Record<string,any>)
2026-02-17 02:52:50 -03:00
diegosouzapw 5ef97b2622 docs: update all documentation to reflect JS→TS migration
- README.md: TypeScript 5.9 in tech stack, test count 368+, evalRunner.ts
- CONTRIBUTING.md: TypeScript code examples, project structure with .ts/.tsx, PR checklist
- AGENTS.md: all src/ module references .js→.ts, TypeScript in stack
- ARCHITECTURE.md: 44 src/ path refs updated, date updated, TS/JS note
- CODEBASE_DOCUMENTATION.md: localDb.ts/usageDb.ts in app layer
- TASKS.md: 8 component/route refs updated to .tsx/.ts

open-sse/ references correctly remain .js (not yet migrated)
2026-02-17 02:04:00 -03:00
diegosouzapw 9739f41366 refactor: migrate entire src/ from JS to TypeScript
- Rename 254 .js files to .ts (domain, lib, services, stores, API routes, etc.)
- Rename 133 .js files to .tsx (components, pages, layouts)
- Fix ~230 import references (remove .js extensions from internal imports)
- Fix 10 open-sse cross-references to @/lib/ and ../../src/ paths
- Add TypeScript interfaces to Card, Modal, Button, and notificationStore
- Install tsx for test runner (handles extensionless .ts imports in Node ESM)
- Update test:unit script to use tsx/esm loader
- Update test imports from .js to .ts (20 files)
- Add typescript.ignoreBuildErrors in next.config.mjs for gradual migration
- Create src/types/global.d.ts for env vars and untyped modules
- Update tsconfig.json (jsx: preserve, forceConsistentCasingInFileNames)

Results:
- Build: ✓ compiles in ~40s
- Tests: ✓ 368/368 pass (100%)
- Zero .js files remain in src/
2026-02-17 01:53:41 -03:00
Diego Rodrigues de Sa e Souza 7ec5a0a527 Merge pull request #58 from diegosouzapw/dependabot/github_actions/actions/checkout-6
chore(deps): bump actions/checkout from 4 to 6
2026-02-17 01:04:31 -03:00
dependabot[bot] a811c66230 chore(deps): bump actions/checkout from 4 to 6
Bumps [actions/checkout](https://github.com/actions/checkout) from 4 to 6.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v4...v6)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-02-17 03:47:51 +00:00
Diego Rodrigues de Sa e Souza 62e8369a12 Merge pull request #57 from diegosouzapw/dependabot/github_actions/peter-evans/dockerhub-description-5
chore(deps): bump peter-evans/dockerhub-description from 4 to 5
2026-02-17 00:47:14 -03:00
Diego Rodrigues de Sa e Souza 5291cd3321 Merge pull request #56 from diegosouzapw/dependabot/github_actions/actions/setup-node-6
chore(deps): bump actions/setup-node from 4 to 6
2026-02-17 00:47:01 -03:00
dependabot[bot] 00253b795c chore(deps): bump peter-evans/dockerhub-description from 4 to 5
Bumps [peter-evans/dockerhub-description](https://github.com/peter-evans/dockerhub-description) from 4 to 5.
- [Release notes](https://github.com/peter-evans/dockerhub-description/releases)
- [Commits](https://github.com/peter-evans/dockerhub-description/compare/v4...v5)

---
updated-dependencies:
- dependency-name: peter-evans/dockerhub-description
  dependency-version: '5'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-02-16 23:19:39 +00:00
dependabot[bot] 1d6a918154 chore(deps): bump actions/setup-node from 4 to 6
Bumps [actions/setup-node](https://github.com/actions/setup-node) from 4 to 6.
- [Release notes](https://github.com/actions/setup-node/releases)
- [Commits](https://github.com/actions/setup-node/compare/v4...v6)

---
updated-dependencies:
- dependency-name: actions/setup-node
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-02-16 23:19:34 +00:00
Diego Rodrigues de Sa e Souza 7152691755 Merge pull request #51 from diegosouzapw/fix/ci-actions
fix(ci): lower coverage thresholds, use production server for E2E, block ESLint major upgrades
2026-02-16 20:19:02 -03:00
Diego Rodrigues de Sa e Souza e6c31bf890 Merge pull request #50 from diegosouzapw/dependabot/npm_and_yarn/development-55a9f41e4a
deps: bump eslint from 9.39.2 to 10.0.0 in the development group
2026-02-16 20:18:40 -03:00
Diego Rodrigues de Sa e Souza d0dd7b4b4c Merge pull request #49 from diegosouzapw/dependabot/npm_and_yarn/production-c9cc875c3b
deps: bump undici from 7.21.0 to 7.22.0 in the production group
2026-02-16 20:18:23 -03:00
Diego Rodrigues de Sa e Souza dc50abc060 Merge pull request #55 from diegosouzapw/feat/unified-test-logging
feat(logging): unified Logger + Proxy logging for all test flows
2026-02-16 18:19:26 -03:00
diegosouzapw 835c860585 feat(logging): unified Logger + Proxy logging for all test flows
- Add saveCallLog + logProxyEvent to testSingleConnection() so provider
  tests, API key tests, and batch tests all log to both Logger and Proxy
  tabs in the Usage dashboard
- Fix combo test getBaseUrl() to respect x-forwarded-host/proto headers,
  preventing localhost resolution behind reverse proxy on VPS
- All test flows now produce entries in both call_logs and proxy_logs
  tables alongside the existing chat/SSE pipeline logging
2026-02-16 18:18:48 -03:00
Diego Rodrigues de Sa e Souza 81f0f4d97c Merge pull request #54 from diegosouzapw/fix/batch-test-network-error-vps
fix(providers): eliminate HTTP self-calls in batch test for VPS
2026-02-16 17:58:08 -03:00
diegosouzapw f1deb98348 fix(providers): eliminate HTTP self-calls in batch test for VPS compatibility
- Extract testSingleConnection() from [id]/test/route.js as reusable export
- Rewrite test-batch/route.js to call testSingleConnection() directly
  instead of fetch(${request.nextUrl.origin}/api/...) which resolves to
  localhost behind reverse proxy, causing NETWORK_ERROR on VPS
- Add NEXT_PUBLIC_APP_URL to cloudSyncScheduler.js fallback chain
- POST handler in [id]/test/route.js now delegates to testSingleConnection()

Fixes: all 34 providers failing with NETWORK_ERROR on llms.omniroute.online
2026-02-16 17:57:30 -03:00
dependabot[bot] d8b409c257 deps: bump undici from 7.21.0 to 7.22.0 in the production group
Bumps the production group with 1 update: [undici](https://github.com/nodejs/undici).


Updates `undici` from 7.21.0 to 7.22.0
- [Release notes](https://github.com/nodejs/undici/releases)
- [Commits](https://github.com/nodejs/undici/compare/v7.21.0...v7.22.0)

---
updated-dependencies:
- dependency-name: undici
  dependency-version: 7.22.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: production
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-02-16 20:47:36 +00:00
Diego Rodrigues de Sa e Souza bc38805b51 Merge pull request #53 from diegosouzapw/feature/proxy-log-sqlite-persistence
feat(proxy): persist proxy logs to SQLite
2026-02-16 17:46:19 -03:00
diegosouzapw 22cf732f08 feat(proxy): persist proxy logs to SQLite for restart survival
- Add proxy_logs table to db/core.js schema (18 columns + 3 indexes)
- Rewrite proxyLogger.js with hybrid dual storage:
  - In-memory ring buffer for real-time performance
  - SQLite persistence for surviving server restarts
  - On startup, hydrates from DB (last 500 entries)
  - Each event writes to both memory and SQLite
  - Auto-trim keeps max 500 rows in DB
- Same external API (getProxyLogs, clearProxyLogs, etc.)
- Zero changes needed in API route or frontend
2026-02-16 17:45:33 -03:00
Diego Rodrigues de Sa e Souza 3b3dce07be Merge pull request #52 from diegosouzapw/feature/tls-fingerprint-spoofing
feat(proxy): implement TLS fingerprint spoofing via wreq-js
2026-02-16 17:13:36 -03:00
diegosouzapw 127cdc9143 feat(proxy): implement TLS fingerprint spoofing via wreq-js
- Add TlsClient module (Chrome 124 fingerprint via wreq-js)
- Integrate TLS client as opt-in layer in proxyFetch.js (ENABLE_TLS_FINGERPRINT)
- Add per-request TLS tracking via AsyncLocalStorage
- Add TLS fingerprint column and badge to Proxy Logger dashboard
- Add TLS Fingerprint section to ProxyLogDetail modal
- Add wreq-js dependency
- Document ENABLE_TLS_FINGERPRINT in .env.example

Adapted from upstream PR decolua/9router#137, preserving all
OmniRoute-specific proxy features (AsyncLocalStorage context,
proxyDispatcher, SOCKS5, Symbol-based patch state).
2026-02-16 17:12:24 -03:00
diegosouzapw d3a4f6be98 fix(e2e): correct API endpoints and response format assertions 2026-02-16 17:08:17 -03:00
diegosouzapw 23ee13818a fix(ci): lower coverage thresholds, use production server for E2E, block ESLint major upgrades 2026-02-16 17:01:50 -03:00
dependabot[bot] 9eeeb90dae deps: bump eslint from 9.39.2 to 10.0.0 in the development group
Bumps the development group with 1 update: [eslint](https://github.com/eslint/eslint).


Updates `eslint` from 9.39.2 to 10.0.0
- [Release notes](https://github.com/eslint/eslint/releases)
- [Commits](https://github.com/eslint/eslint/compare/v9.39.2...v10.0.0)

---
updated-dependencies:
- dependency-name: eslint
  dependency-version: 10.0.0
  dependency-type: direct:development
  update-type: version-update:semver-major
  dependency-group: development
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-02-16 19:06:39 +00:00
Diego Rodrigues de Sa e Souza a1137c1fa1 Merge pull request #48 from diegosouzapw/style/add-website-url
v0.8.0 — Website launch, SECURITY.md audit, docs improvements
2026-02-16 14:33:46 -03:00
diegosouzapw e962e4f558 chore: bump version to 0.8.0
- Website launch (omniroute.online)
- Comprehensive SECURITY.md
- Documentation improvements
- Updated provider count to 36+
2026-02-16 14:33:13 -03:00
diegosouzapw 6d3b4166df docs: remove all Architecture Decision Record (ADR) documents. 2026-02-16 14:31:35 -03:00
diegosouzapw 45eced0b3e docs: comprehensive SECURITY.md based on full codebase audit
Documented all security features actually implemented:
- AES-256-GCM encryption at rest (API keys, tokens)
- Prompt injection guard (5 pattern types)
- PII redaction (email, CPF, CNPJ, CC, phone, SSN)
- Secrets validator (fail-fast on weak values)
- Circuit breaker (3-state, SQLite-persisted)
- OAuth 2.0 + PKCE, CORS, IP filtering
- Rate limiting, anti-thundering herd
- Compliance (log retention, audit log, no-log)
2026-02-16 14:29:50 -03:00
diegosouzapw 1b00a6b70b docs: update SECURITY.md and add to README
- Bump supported versions: 0.7.x (active), 0.6.x (security)
- Replace fake email with GitHub Security Advisories link
- Add Security Policy to README documentation table
2026-02-16 14:27:17 -03:00
diegosouzapw 03d05e0490 docs: track USER_GUIDE, API_REFERENCE, and TROUBLESHOOTING in git
These files were referenced in README but ignored by .gitignore.
Added them to the exception list so they appear in the repository.
2026-02-16 14:25:52 -03:00
diegosouzapw 4cac582cb0 docs: add omniroute.online website URL to README, npm, and Docker
- Add Website badge to README header
- Add website link to nav, tech stack, support, and footer
- Update provider count from 28 to 36+
- Set package.json homepage to https://omniroute.online
- Add OCI image URL label to Dockerfile
2026-02-16 14:22:29 -03:00
Diego Rodrigues de Sa e Souza eb0fbccd05 Merge pull request #47 from diegosouzapw/fix/vm-onboarding-auth
fix: auto-skip onboarding and enforce login on VM deployments
2026-02-16 11:25:06 -03:00
diegosouzapw 32c0f40021 fix: auto-skip onboarding and enforce login on VM deployments
- getSettings() auto-sets setupComplete=true when INITIAL_PASSWORD env is set
- proxy.js middleware enforces login when INITIAL_PASSWORD exists (even without DB hash)
- Settings API reports hasPassword=true when INITIAL_PASSWORD is configured
- Login page hides '123456' default hint when a custom password is set

Fixes fresh Docker/VM deployments getting stuck on onboarding wizard
and being accessible without authentication.
2026-02-16 11:24:15 -03:00
Diego Rodrigues de Sa e Souza baae44f825 Merge pull request #46 from diegosouzapw/feature/release-0.7.0
chore: release v0.7.0 — Docker Hub, changelog overhaul
2026-02-16 09:49:07 -03:00
diegosouzapw 5fe53168b2 chore: bump version to 0.7.0, reorganize changelog, add Docker Hub CI/CD and README
- Bump version from 0.6.0 to 0.7.0 in package.json
- Rewrite CHANGELOG.md with comprehensive entries from v0.1.0 to v0.7.0
- Add docker-publish.yml GitHub Actions workflow for auto Docker Hub push
- Add Docker Hub badge, Docker section, and Docker Hub link to README
- Update release command example to v0.7.0
2026-02-16 09:48:35 -03:00
diegosouzapw ebdc1c214d refactor: extract CliStatusBadge component and refactor CLI tool cards
- Create shared CliStatusBadge component with support for configured,
  not_configured, not_installed, other, and unknown statuses
- Replace inline status badge markup in ClaudeToolCard and ClineToolCard
  with the new reusable component
- Add colored status dot indicator alongside badge text
- Support batch status fallback so badges render even when cards are collapsed
- Refactor model/provider selection logic in tool card configuration
2026-02-16 01:35:57 -03:00
Diego Rodrigues de Sa e Souza 467e998650 Merge pull request #45 from diegosouzapw/fix/cloud-connection-ux
fix(cloud): improve cloud connection UX
2026-02-16 01:03:23 -03:00
diegosouzapw 9a9f592f54 fix(cloud): improve cloud connection UX with GET status, toast feedback, and sidebar indicator
- Add GET handler to /api/sync/cloud for real-time status polling
- Rewrite CloudSyncStatus: clickable, event-driven updates, clearer labels
- Add inline status toast with auto-dismiss after enable/disable
- Show success animation in modal before auto-closing
- Dispatch cloud-status-changed event for instant sidebar updates
2026-02-16 01:02:52 -03:00
Diego Rodrigues de Sa e Souza c3fe96e221 Merge pull request #44 from diegosouzapw/feature/release-0.6.0
chore: release v0.6.0
2026-02-16 00:23:19 -03:00
diegosouzapw 1c6541f25d chore: bump version to 0.6.0 and update changelog 2026-02-16 00:22:55 -03:00
diegosouzapw 9f8dfa1398 feat: add costs page and enhance health provider status display
Add dedicated Costs page combining Budget and Pricing tabs with a
sidebar navigation layout. Improve Health page provider section with
status legend (Healthy/Recovering/Down) and import AI_PROVIDERS
constants for richer provider display.
2026-02-15 23:01:27 -03:00
diegosouzapw e4db9bff0e feat: add provider metrics display and model import for passthrough providers
- Fetch and display request metrics (success rate, latency, total requests) on provider overview cards
- Create /api/provider-metrics endpoint to aggregate stats from request logs
- Add /api/providers/[id]/import-models endpoint to import models from provider's /models API
- Add "Import from /models" button on passthrough provider detail pages
- Include proper PropTypes for new metrics and alias fields
2026-02-15 21:53:27 -03:00
diegosouzapw 54aba4c087 feat: redesign app icons with network node graph and new color scheme
Replace text-based "9" favicon with a network/router node graph design
across all icon sizes. Add apple-touch-icon and icon-192 SVG assets.
Update brand gradient from orange (#f97815) to red (#E54D5E).
2026-02-15 20:56:48 -03:00
Diego Rodrigues de Sa e Souza c2542b75f6 Merge pull request #43 from diegosouzapw/feature/release-0.5.0
chore: release v0.5.0
2026-02-15 19:03:37 -03:00
diegosouzapw 6572f2a1b6 chore: bump version to 0.5.0 and update changelog 2026-02-15 19:03:18 -03:00
Diego Rodrigues de Sa e Souza 2ad23f3b3c Merge pull request #42 from diegosouzapw/feature/ajustes-cosmeticos
feat: v0.5.0 - Dashboard refinements, evals framework, and combo strategies
2026-02-15 18:57:29 -03:00
diegosouzapw fa9687ae0d feat: Implement API key usage for EvalsTab LLM calls, enhance model filtering with provider aliases, and remove the random routing strategy option. 2026-02-15 18:56:33 -03:00
diegosouzapw 0ed7738c7c feat: add LLM evaluation framework with golden set testing
Introduce built-in eval system for testing LLM response quality against
golden sets. Includes eval runner with 4 match strategies (exact,
contains, regex, custom), a pre-loaded 10-case golden set, REST API
endpoints for managing and running suites, and a dashboard UI under
Analytics → Evals with real-time progress tracking and pass rate
summaries. Also adds OpenAPI tags for Audio, Moderations, and Rerank.
2026-02-15 18:37:18 -03:00
diegosouzapw a43b1c9218 feat: add random, least-used, and cost-optimized combo strategies
Extend combo routing with 3 new model selection strategies beyond the
existing priority, weighted, and round-robin options:
- random: Fisher-Yates shuffle for uniform distribution
- least-used: sorts models by request count via comboMetrics
- cost-optimized: sorts models by pricing (cheapest first)

Also enhance the dashboard provider cards with model counts and
clickable detail views for selected providers.
2026-02-15 16:57:00 -03:00
diegosouzapw 413a9f2a69 feat: add ModelAvailabilityBadge component and retheme landing page
- Add compact ModelAvailabilityBadge with popover for model status
  monitoring, cooldown clearing, and auto-refresh polling
- Retheme landing page from warm orange tones to cool blue-grey palette
  across FlowAnimation, Footer, and related components
- Update accent color from orange (#f97815) to rose (#E54D5E)
2026-02-15 16:26:01 -03:00
diegosouzapw 14714aa9f5 feat: refactor dashboard with shared UI component library
Introduce reusable shared components (Button, Card, Modal, Table,
StatusBadge, EmptyState) and refactor dashboard pages to use them.
Extract client components from server pages, centralize provider
constants, and update CI Node.js matrix from 18 to 20.
2026-02-15 16:11:56 -03:00
Diego Rodrigues de Sa e Souza ac4df197c3 Merge pull request #41 from diegosouzapw/fix/chat-completions-then-error
fix(api): resolve TypeError in chat/completions route
2026-02-15 13:25:28 -03:00
diegosouzapw 06826d4c86 fix(api): resolve TypeError in chat/completions ensureInitialized
initTranslators() is a no-op stub (translators self-register via static
imports). Wrapping the call with Promise.resolve() ensures .then() works
even when the function returns undefined instead of a Promise.
2026-02-15 13:24:54 -03:00
556 changed files with 13641 additions and 5694 deletions
+5
View File
@@ -57,6 +57,11 @@ NEXT_PUBLIC_ENABLE_SOCKS5_PROXY=true
# ALL_PROXY=socks5://127.0.0.1:7890
# NO_PROXY=localhost,127.0.0.1
# TLS fingerprint spoofing (opt-in) — mimics Chrome 124 TLS handshake via wreq-js
# Reduces risk of JA3/JA4 fingerprint-based blocking by providers (e.g., Google)
# Requires wreq-js to be installed (included in dependencies)
# ENABLE_TLS_FINGERPRINT=true
# Optional CLI runtime overrides (Docker/host integration)
# CLI_MODE=auto
# CLI_EXTRA_PATHS=/host-cli/bin
+4
View File
@@ -20,6 +20,10 @@ updates:
update-types: ["version-update:semver-major"]
- dependency-name: "next"
update-types: ["version-update:semver-major"]
- dependency-name: "eslint"
update-types: ["version-update:semver-major"]
- dependency-name: "eslint-config-next"
update-types: ["version-update:semver-major"]
- package-ecosystem: "github-actions"
directory: "/"
+14 -14
View File
@@ -15,8 +15,8 @@ jobs:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: 22
cache: npm
@@ -27,8 +27,8 @@ jobs:
name: Security Audit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: 22
cache: npm
@@ -43,10 +43,10 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18, 22]
node-version: [20, 22]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: ${{ matrix.node-version }}
cache: npm
@@ -59,13 +59,13 @@ jobs:
needs: build
strategy:
matrix:
node-version: [18, 22]
node-version: [20, 22]
env:
JWT_SECRET: ci-test-secret-with-sufficient-length-for-validation
API_KEY_SECRET: ci-test-api-key-secret-long
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: ${{ matrix.node-version }}
cache: npm
@@ -80,8 +80,8 @@ jobs:
JWT_SECRET: ci-test-secret-with-sufficient-length-for-validation
API_KEY_SECRET: ci-test-api-key-secret-long
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: 22
cache: npm
@@ -99,8 +99,8 @@ jobs:
JWT_SECRET: ci-test-secret-with-sufficient-length-for-validation
API_KEY_SECRET: ci-test-api-key-secret-long
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: 22
cache: npm
+55
View File
@@ -0,0 +1,55 @@
name: Publish to Docker Hub
on:
release:
types: [published]
permissions:
contents: read
jobs:
docker:
name: Build & Push Docker Image
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Extract version from release tag
id: version
run: |
VERSION="${GITHUB_REF_NAME}"
VERSION="${VERSION#v}"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "Publishing Docker image version: $VERSION"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
target: runner-base
push: true
tags: |
diegosouzapw/omniroute:${{ steps.version.outputs.version }}
diegosouzapw/omniroute:latest
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64
- name: Update Docker Hub description
uses: peter-evans/dockerhub-description@v5
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
repository: diegosouzapw/omniroute
short-description: "OmniRoute — Unified AI proxy. Route any LLM through one endpoint."
readme-filepath: ./README.md
+2 -2
View File
@@ -14,10 +14,10 @@ jobs:
environment: NPM_TOKEN
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v6
- name: Setup Node.js
uses: actions/setup-node@v4
uses: actions/setup-node@v6
with:
node-version: 22
registry-url: https://registry.npmjs.org
+8
View File
@@ -56,6 +56,9 @@ docs/*
!docs/ARCHITECTURE.md
!docs/CODEBASE_DOCUMENTATION.md
!docs/CONTRIBUTING.md
!docs/USER_GUIDE.md
!docs/API_REFERENCE.md
!docs/TROUBLESHOOTING.md
!docs/EXECUTION_CONTEXT_PROVIDER_SYNC.md
!docs/TASK_NEBIUS_BACKEND_ENABLEMENT.md
!docs/frontend-backend-provider-gap-report.md
@@ -80,3 +83,8 @@ test-results/
playwright-report/
blob-report/
cloud/
omnirouteCloud/
omnirouteSite/
# Security Analysis (standalone project with own git)
security-analysis/
+18 -17
View File
@@ -8,6 +8,7 @@ Unified AI proxy/router — route any LLM through one endpoint. Multi-provider s
## Stack
- **Runtime**: Next.js 16 (App Router), Node.js, ES Modules
- **Language**: TypeScript 5.9 (`src/`) + JavaScript (`open-sse/`)
- **Database**: better-sqlite3 (SQLite) — `DATA_DIR` configurable, default `~/.omniroute/`
- **Streaming**: SSE via `open-sse` internal package
- **Styling**: Tailwind CSS v4
@@ -21,15 +22,15 @@ All persistence uses SQLite through domain-specific modules:
| Module | Responsibility |
| -------------- | ------------------------------------------ |
| `core.js` | SQLite engine, migrations, WAL, encryption |
| `providers.js` | Provider connections & nodes |
| `models.js` | Model aliases, MITM aliases, custom models |
| `combos.js` | Combo configurations |
| `apiKeys.js` | API key management & validation |
| `settings.js` | Settings, pricing, proxy config |
| `backup.js` | Backup / restore operations |
| `core.ts` | SQLite engine, migrations, WAL, encryption |
| `providers.ts` | Provider connections & nodes |
| `models.ts` | Model aliases, MITM aliases, custom models |
| `combos.ts` | Combo configurations |
| `apiKeys.ts` | API key management & validation |
| `settings.ts` | Settings, pricing, proxy config |
| `backup.ts` | Backup / restore operations |
`src/lib/localDb.js` is a **re-export layer only** — all 27+ consumers import from it,
`src/lib/localDb.ts` is a **re-export layer only** — all 27+ consumers import from it,
but the real logic lives in `src/lib/db/`.
### Request Pipeline (`open-sse/`)
@@ -49,25 +50,25 @@ Translation between provider formats: `open-sse/translator/`
### OAuth & Tokens (`src/lib/oauth/`)
18 modules handling OAuth flows, token refresh, and provider credentials.
Default credentials are hardcoded in `src/lib/oauth/constants/oauth.js`,
Default credentials are hardcoded in `src/lib/oauth/constants/oauth.ts`,
overridable via env vars or `data/provider-credentials.json`.
### Supporting Systems
| System | Location |
| -------------------------- | ------------------------------------------------- |
| Usage tracking & analytics | `src/lib/usageDb.js`, `src/lib/usageAnalytics.js` |
| Token health checks | `src/lib/tokenHealthCheck.js` |
| Cloud sync | `src/lib/cloudSync.js` |
| Proxy logging | `src/lib/proxyLogger.js` |
| Data paths resolution | `src/lib/dataPaths.js` |
| Usage tracking & analytics | `src/lib/usageDb.ts`, `src/lib/usageAnalytics.ts` |
| Token health checks | `src/lib/tokenHealthCheck.ts` |
| Cloud sync | `src/lib/cloudSync.ts` |
| Proxy logging | `src/lib/proxyLogger.ts` |
| Data paths resolution | `src/lib/dataPaths.ts` |
### Adding a New Provider
1. Register in `src/shared/constants/providers.js`
1. Register in `src/shared/constants/providers.ts`
2. Add executor in `open-sse/executors/`
3. Add translator rules in `open-sse/translator/` (if non-OpenAI format)
4. Add OAuth config in `src/lib/oauth/constants/oauth.js` (if OAuth-based)
4. Add OAuth config in `src/lib/oauth/constants/oauth.ts` (if OAuth-based)
## Review Focus
@@ -83,7 +84,7 @@ overridable via env vars or `data/provider-credentials.json`.
- DB operations go through `src/lib/db/` modules, never raw SQL in routes
- Provider requests flow through `open-sse/handlers/`
- Translations use `open-sse/translator/` modules
- `localDb.js` is re-exports only — add new functions to the proper `db/*.js` module
- `localDb.ts` is re-exports only — add new functions to the proper `db/*.ts` module
### Code Quality
+190 -309
View File
@@ -2,349 +2,230 @@
All notable changes to OmniRoute are documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
---
## [Unreleased]
## [0.8.8] — 2026-02-17
### Added
#### Phase 5 — Foundation & Security
- 📊 **Analytics page redesign** — Rebuilt analytics dashboard with Recharts (SVG-based) charts replacing the previous implementation. New layout: stat cards → model usage bar chart → provider breakdown table with success rates and avg latency
- 🎯 **6 global routing strategies** — Expanded from 3 (Fill-First, Round-Robin, P2C) to 6, adding Random, Least-Used, and Cost-Optimized. All strategies now have descriptions and icons in the Settings → Routing tab
- 🔧 **Editable rate limits** — Rate limit defaults (RPM, Min Gap, Max Concurrent) are now editable in Settings → Resilience with save/cancel functionality. Values persist via the resilience API
- 📋 **Policies in Resilience tab** — Moved PoliciesPanel (circuit breaker status + locked identifiers) from Security to Resilience tab for better logical grouping
- 🧠 **Prompt Cache in AI tab** — Relocated CacheStatsCard from Advanced to AI tab alongside Thinking Budget and System Prompt
- **Domain State Persistence** — SQLite-backed persistence for 4 domain modules (fallback chains, budgets, cost history, lockout state, circuit breakers) via `domainState.js` with 5 new tables in `core.js`
- **Write-Through Cache** — `fallbackPolicy.js`, `costRules.js`, `lockoutPolicy.js`, and `circuitBreaker.js` now use in-memory Map + SQLite write-through for state survival across restarts
- **Race Condition Fix** — `route.js` `ensureInitialized()` replaced boolean flag with Promise-based singleton to prevent parallel initialization
### Changed
#### Phase 6 — Architecture Refactoring
- **OAuth Provider Extraction** — Monolithic `providers.js` (1051 → 144 lines) split into 12 individual modules under `src/lib/oauth/providers/` with a thin wrapper + registry index
- **Policy Engine** — Centralized request evaluation against lockout, budget, and fallback policies (`policyEngine.js`) with `evaluateRequest()` and `evaluateFirstAllowed()` entry points
- **Deterministic Round-Robin** — `comboResolver.js` now uses persistent `Map<string, number>` counter per combo instead of time-based modulo
- **Telemetry Window Accuracy** — `requestTelemetry.js` now adds `recordedAt` timestamps to history entries and accurately filters by `windowMs`
#### Tests
- 22 new tests: `domain-persistence.test.mjs` (16 tests), `policy-engine.test.mjs` (6 tests)
- Test isolation fix for `observability-fase04.test.mjs` — unique CircuitBreaker names prevent DB state bleed
- Total: **295+ tests passing** (up from 273 in v0.3.0)
- ♻️ **Settings page restructure** — Reorganized all settings tabs for better UX:
- **Security**: Simplified to Login/Password and IP Access Control only
- **Routing**: Expanded strategy grid with all 6 routing strategies
- **Resilience**: Reordered cards (Provider Profiles → Rate Limiting → Circuit Breakers → Policies & Locked Identifiers)
- **AI**: Now includes Thinking Budget, System Prompt, and Prompt Cache
- **Advanced**: Simplified to only Global Proxy configuration
- 🔄 **Backend routing strategies** — Implemented `random` (Fisher-Yates shuffle), `least-used` (sorted by `lastUsedAt`), `cost-optimized` (sorted by priority ascending), and fixed `p2c` (power-of-two-choices with health scoring) in `auth.ts`
- 🔌 **Resilience API updates** — GET endpoint now merges saved rate limit defaults with constants; PATCH endpoint accepts both `profiles` and `defaults`
- 📊 **Usage page split** — Refactored Usage page into "Request Logs" (with updated icon) and a new dedicated "Limits & Quotas" page
### Fixed
- **Proxy decoupling** — `proxy.js` no longer self-fetches `/api/settings`; imports `getSettings()` directly from `localDb`
- **Default password** — `.env.example` `INITIAL_PASSWORD` changed from `123456``CHANGEME`
- **Server init error handling** — `server-init.js` now uses `console.error` + `process.exit(1)` instead of silent `console.log`
- 🐛 **Provider add error**Improved error handling for API responses when adding new provider connections, with clear validation feedback
---
## [0.8.5] — 2026-02-17
### Added
- 🔒 **TLS fingerprint spoofing** — Implement browser-like TLS fingerprinting via `wreq-js` to bypass bot detection on providers that enforce TLS client fingerprint checks (`3dd0cc1`, PR #52)
- 💾 **SQLite proxy log persistence** — Proxy request/response logs now persist to SQLite database, surviving server restarts. Previously, logs were lost on restart (`f1664fe`, PR #53)
- 📋 **Unified test logging** — Shared `Logger` + Proxy logging infrastructure for all provider connection test flows. Consistent log formatting across batch and individual tests (`bce302e`, PR #55)
### Refactored
- 🔷 **Full TypeScript migration — `src/`** — Migrated the entire `src/` directory from JavaScript to TypeScript. All `.js`/`.jsx` files converted to `.ts`/`.tsx` with proper type annotations across API routes, lib modules, components, services, stores, domain layer, and shared utilities (`d0ca595`)
- **Wave 1**: Shared component interfaces + EventTarget fixes (`dfdd2a2`)
- **Wave 2**: Utils & services typed fields, Zustand stores, logger, sync scheduler (`89dd107`, `b2907cd`)
- **Wave 3a**: Lib layer, DB, compliance, domain layer typed (`9e13fe2`)
- **Wave 3b**: Usage, CLI runtime, SSE auth/logger typed (`a291abd`)
- **Wave 3c**: OAuth services + server utils typed (`d62cf8d`)
- **Wave 4a**: 7 API routes — providers, cli-tools, oauth (`7cdb923`)
- **Wave 4b**: 7 more API routes — providers, test, usage, nodes (`5592c2e`)
- **Wave 4c**: 8 files — components, SSE handlers, services (`d8ce9dc`)
- **Dashboard hardening**: Resolve all TypeScript errors across dashboard pages (`7a463a3`, PR #61)
- 🔷 **Full TypeScript migration — `open-sse/`** — Migrated all 94 `.js` files in the SSE routing engine to TypeScript (PR #62)
- **Phase 1**: Rename all 94 `.js``.ts` files (`256e443`)
- **Phase 6**: Reduce `@ts-ignore` from 231 → 186 with targeted fixes (`6a54b84`)
- **Phase 7**: Eliminate ALL `@ts-ignore` annotations (186 → 0) and ALL TypeScript errors (237 → 0) — zero `@ts-ignore`, zero errors (`7b37a3c`)
- Typing strategies: `Record<string, any>` for dynamic objects, optional function params, `as any` casts for custom Error/Array properties, `declare var EdgeRuntime` for edge compatibility, proper `fs`/`path` imports
### Fixed
- 🐛 **Qwen token refresh** — Detect `invalid_request` as unrecoverable error and switch broken test endpoints to `checkExpiry` method instead of failing silently (`1e0ffbc`, PR #60)
- 🐛 **VPS batch test compatibility** — Eliminate HTTP self-calls in batch provider connection tests for VPS environments where localhost is unreachable (`a3bbbb5`, PR #54)
- 🐛 **E2E test assertions** — Correct API endpoints and response format assertions in end-to-end tests (`92b5e66`)
- 🐛 **CI coverage thresholds** — Lower coverage thresholds, use production server for E2E, block ESLint major upgrades from breaking CI (`3ca4b6b`, PR #51)
### Changed
- 📖 **Documentation update** — Updated all documentation to reflect JS → TS migration, corrected file extensions and import paths (`7ff8aa2`)
- ⬆️ **CI/CD** — Bump `actions/checkout` v4 → v6, `actions/setup-node` v4 → v6, `peter-evans/dockerhub-description` v4 → v5
### Dependencies
- ⬆️ `undici` 7.21.0 → 7.22.0 (production)
- ⬆️ `actions/checkout` 4 → 6
- ⬆️ `actions/setup-node` 4 → 6
- ⬆️ `peter-evans/dockerhub-description` 4 → 5
- 🚫 `eslint` 10.0.0 blocked — major version incompatible with `eslint-config-next`
---
## [0.8.0] — 2026-02-16
### Added
- 🌐 **Official website** — [omniroute.online](https://omniroute.online) live with static site on Akamai VM + Cloudflare proxy
- 🛡️ **Comprehensive SECURITY.md** — Full codebase audit documenting 10+ security features (AES-256-GCM, prompt injection guard, PII redaction, circuit breaker, etc.)
- 📖 **Documentation tracking**`USER_GUIDE.md`, `API_REFERENCE.md`, `TROUBLESHOOTING.md` now tracked in git
- 🏷️ **Website badge** — Official website badge and links in README, npm, and Docker Hub
- 🔗 **36+ providers** — Updated provider count across documentation
### Changed
- 📦 **npm homepage** — Points to `omniroute.online` instead of GitHub
- 🐳 **Docker OCI labels** — Added `org.opencontainers.image.url` for Docker Hub
- 🔒 **Security policy** — Updated supported versions, replaced email with GitHub Security Advisories
---
## [0.7.0] — 2026-02-16
### Added
- 🐳 **Docker Hub public image**`diegosouzapw/omniroute` available on [Docker Hub](https://hub.docker.com/r/diegosouzapw/omniroute) with `latest` and versioned tags
- 🔄 **Docker CI/CD** — GitHub Actions workflow (`docker-publish.yml`) auto-builds and pushes Docker image on every release
- ☁️ **Akamai VM deployment** — Nanode 1GB instance created for remote hosting
- 🎯 **Provider model filtering** — Filter model suggestions by selected provider in Translator and Chat Tester
- 🔌 **CLI status badges** — Extract `CliStatusBadge` component; status visible on collapsed tool cards
- ☁️ **Cloud connection UX** — GET status endpoint, toast feedback, and sidebar indicator for cloud sync
- 🔐 **OAuth provider secrets** — Default cloud URL and OAuth provider secrets set via environment variables
-**Edge compatibility** — Replace `uuid` package with native `crypto.randomUUID()` for Cloudflare Workers compatibility
---
## [0.6.0] — 2026-02-16
### Added
- 💰 **Costs & Budget page** — Dedicated dashboard page for cost tracking and budget management
- 📊 **Provider metrics display** — Show per-provider usage metrics and statistics
- 📥 **Model import for passthrough providers** — Import models from API-compatible providers (Deepgram, AssemblyAI, NanoBanana)
- 🎨 **App icon redesign** — New network node graph icon with updated color scheme
---
## [0.5.0] — 2026-02-15
### Added
- 🧪 **LLM Evaluations (Evals)** — Golden set testing framework with 4 match strategies (`exact`, `contains`, `regex`, `custom`)
- 🎲 **Advanced combo strategies**`random`, `least-used`, and `cost-optimized` balancing strategies for combos
- 📊 **API key usage in Evals** — Evals tab uses API key auth for real LLM calls through the proxy
- 🏷️ **Model availability badge** — Visual indicator for model availability per provider
- 🎨 **Landing page retheme** — Updated landing page design with new aesthetic
- 🧩 **Shared UI component library** — Refactored dashboard with reusable component library
### Fixed
- 🐛 Fix `TypeError` in `chat/completions` `ensureInitialized` call
---
## [0.4.0] — 2026-02-15
### Added
- 🧠 **LLM Gateway Intelligence** (Phase 9) — Smart routing, semantic caching, request idempotency, progress tracking
- 📄 **Missing flows & pages** (Phase 8) — Error pages, UX components, telemetry dashboards
- 🔧 **API & code quality** (Phase 7) — API restructuring, JSDoc documentation, code quality improvements
- 📚 **Documentation restructuring** (Phase 10) — Component decomposition, docs cleanup
-**26 action items** from critical analysis resolved
### Changed
- ♻️ **Architecture refactor** (Phase 5-6) — Domain persistence, policy engine, OAuth extraction, proxy decoupling
### Fixed
- 🐛 Fix CI build and lint failures
- 🐛 Fix ghost import in `chatHelpers.js` SSE handling
---
## [0.3.0] — 2026-02-15
Major release: security hardening, domain layer architecture, pipeline integration, full frontend coverage, and resilience overhaul with circuit breaker, anti-thundering herd, and Resilience UI.
### Added
#### Security Hardening (FASE-01 to FASE-09)
- **FASE-01 to FASE-06** — Core security hardening across authentication, input validation, and access control
- **FASE-07 to FASE-09** — Advanced features including enhanced monitoring, security audit improvements, and operational hardening
#### Domain Layer & Infrastructure
- **Model Availability** — TTL-based cooldown tracking per model (`modelAvailability.js`)
- **Cost Rules** — Per-API-key budget management with daily/monthly limits (`costRules.js`)
- **Fallback Policy** — Declarative fallback chain routing with CRUD API (`fallbackPolicy.js`)
- **Error Codes Catalog** — 24 standardized error codes in 6 categories with `createErrorResponse` helper (`errorCodes.js`)
- **Correlation ID** — AsyncLocalStorage-based `x-request-id` propagation for end-to-end tracing (`requestId.js`)
- **Fetch Timeout** — AbortController wrapper with configurable `FETCH_TIMEOUT_MS` (`fetchTimeout.js`)
- **Combo Resolver** — Priority/round-robin/random/least-used strategies (`comboResolver.js`)
- **Lockout Policy** — Sliding window lockout with force-unlock capability (`lockoutPolicy.js`)
- **Request Telemetry** — 7-phase lifecycle tracking with p50/p95/p99 latency aggregation (`requestTelemetry.js`)
#### Pipeline Wiring (7 Backend Modules)
- **Circuit Breaker** integration into request pipeline for provider resilience
- **Model Availability** wired with TTL cooldowns for per-model health tracking
- **Request Telemetry** lifecycle tracking across 7 phases
- **Cost Rules** budget check and cost recording per request
- **Compliance** audit logging with `noLog` opt-out per API key
- **Fetch Timeout** via `fetchWithTimeout` replacing bare `fetch()` in proxy
- **Request ID** (`X-Request-Id` header) for end-to-end tracing
#### 9 New API Routes
- `/api/cache/stats` — GET cache stats, DELETE flush
- `/api/models/availability` — GET availability report, POST clear cooldown
- `/api/telemetry/summary` — GET p50/p95/p99 latency metrics
- `/api/usage/budget` — GET cost summary, POST set budget per key
- `/api/fallback/chains` — GET/POST/DELETE fallback chain management
- `/api/compliance/audit-log` — GET filterable audit log
- `/api/evals` — GET list suites, POST run suite
- `/api/evals/[suiteId]` — GET suite details
- `/api/policies` — GET circuit breaker + lockout status, POST force-unlock
#### Frontend — 100% Backend API Coverage (7 Batches)
- **Batch 1** — Pipeline wiring integration verified across all backend modules
- **Batch 2** — 9 API routes created for backend module access
- **Batch 3** — 6 shared UI components exported (Breadcrumbs, EmptyState, NotificationToast, FilterBar, ColumnToggle, DataTable) + `notificationStore` wired into layout
- **Batch 4** — Usage page: BudgetTelemetryCards (latency p50/p95/p99, cache, system health); Settings page: ComplianceTab (audit log), CacheStatsCard (prompt cache + flush); Combos page: EmptyState component
- **Batch 5** — Integration-wiring tests: 44 tests across 12 suites verifying all batches
- **Batch 6** — Frontend now covers every backend API surface
- **Batch 7** — Final wiring and verification pass
#### Refactoring & Decomposition
- **usageDb.js** decomposed from 969 → 40 lines into 5 focused modules: `migrations.js`, `usageHistory.js`, `costCalculator.js`, `usageStats.js`, `callLogs.js`
- **handleSingleModelChat** decomposed from 183 → 80 lines with extracted helpers (`handleNoCredentials`, `safeResolveProxy`, `safeLogEvents`)
- **Shared UI primitives** extracted: FilterBar, ColumnToggle, DataTable (3230 total lines)
#### Rate Limit Overhaul (4 Phases)
- **Phase 1** — Provider-specific resilience profiles (OAuth vs API key), exponential backoff (5s→60s), default API limits (100 RPM, 200ms minTime)
- **Phase 2** — Circuit breaker integration in combo pipeline with `canExecute()` checks, early exit when all models are OPEN, semaphore marking for 502/503/504
- **Phase 3** — Anti-thundering herd: mutex on `markAccountUnavailable`, auto rate-limit for API key providers with elevated defaults
- **Phase 4** — Resilience UI tab in settings with 3 cards: ProviderProfilesCard, CircuitBreakerCard (real-time, auto-refresh 5s, reset), RateLimitOverviewCard
- `/api/resilience` — GET (full state) + PATCH (save profiles)
- `/api/resilience/reset` — POST (reset breakers + cooldowns)
#### ADRs & Quality
- **6 Architecture Decision Records**: SQLite, Fallback Strategy, OAuth, JS+JSDoc, Single-Tenant, Translator Registry
- **Accessibility audit** — WCAG AA checker with aria-label, dialog role, alt text, label validation (`a11yAudit.js`)
- **Password Reset CLI** — Interactive admin password reset tool (`bin/reset-password.mjs`)
- **Playwright E2E specs** — Responsive viewport tests (375/768/1280) across 4 pages
- **Eval Framework** — 4 strategies (exact, contains, regex, custom) + 10-case golden set (`evalRunner.js`)
- **Compliance module** — audit_log table, `noLog` opt-out per API key, `LOG_RETENTION_DAYS` cleanup
#### Tests
- **63 new tests** for rate limit overhaul: error-classification, combo-circuit-breaker, thundering-herd
- **44 integration-wiring tests** across 12 suites
- **31 domain layer tests** for model availability, cost rules, error codes, request ID, fetch timeout
- **13 UX/telemetry tests** for error pages, breadcrumbs, empty states, telemetry, domain extraction
- **25 batch-B tests** for ADRs, eval framework, compliance, a11y, CLI, Playwright specs
- Total: **273+ tests passing** (up from ~144 in v0.2.0)
#### Documentation
- **JSDoc** coverage added to all new modules (100% exported functions documented)
- `@ts-check` added to 8 critical files
### Fixed
- **ESLint v10 → v9 downgrade** for `eslint-config-next` compatibility — rewrote flat config, removed `defineConfig`/`globalIgnores` (ESLint 10-only APIs)
- **Unrecoverable refresh token errors** — detect `refresh_token_reused` and similar errors, mark connections as expired requiring re-authentication
- **Record type annotation** added to `getAllFallbackChains` result
- **`.gitignore` cleanup** — added `.analysis/` and `antigravity-manager-analysis/`, whitelisted FASE docs
-**Resilience system** — Exponential backoff, circuit breaker, anti-thundering herd mutex, Resilience UI settings page
- 🖥️ **100% frontend API coverage** — 7 implementation batches covering all backend routes
- 📊 **9 new API routes**Budget, telemetry, compliance, tags, storage health, and more
- 🧪 **Eval framework & compliance** — ADRs, accessibility, CLI specs, Playwright test specs (46 tasks)
- 🏗️ **Pipeline integration** — 7 backend modules wired into request processing pipeline
- 🔐 **Security hardening** — Phases 0106 (input validation, CSRF, rate limiting, auth hardening)
- 🤖 **Advanced features** — Phases 0709 (domain extraction, error codes, request ID, fetch timeout)
- 🔄 **Unrecoverable token handling**Detect and mark connections as expired on fatal refresh errors
### Changed
- **Error pages** — Custom 404 and global error boundary with gradient design and dev details
- **Combo page** — Inline empty state replaced with EmptyState component
- **Layout** — Breadcrumbs rendered between Header and content, NotificationToast as global fixed overlay
- **Proxy module** — bare `fetch()` replaced with `fetchWithTimeout` (5s timeout) + `X-Request-Id` header
- ♻️ Decompose `usageDb`, `handleSingleModelChat`, and UI components for maintainability
- ⬇️ Downgrade ESLint v10 → v9 for `eslint-config-next` compatibility
---
## [0.2.0] — 2026-02-14
Major feature release: advanced routing services, security hardening, cost analytics dashboard, and pricing management overhaul.
### Added
#### Open-SSE Services
- **Account Selector** — intelligent provider account selection with priority and load-balancing strategies (`accountSelector.js`)
- **Context Manager** — request context tracking and lifecycle management (`contextManager.js`)
- **IP Filter** — allowlist/blocklist IP filtering with CIDR support (`ipFilter.js`)
- **Session Manager** — persistent session tracking across requests (`sessionManager.js`)
- **Signature Cache** — request signature caching for deduplication (`signatureCache.js`)
- **System Prompt** — global system prompt injection into all chat completions (`systemPrompt.js`)
- **Thinking Budget** — token budget management for reasoning models (`thinkingBudget.js`)
- **Wildcard Router** — pattern-based model routing with glob matching (`wildcardRouter.js`)
- Enhanced **Rate Limit Manager** with sliding-window algorithm and per-key quotas
#### Dashboard Settings
- **IP Filter** settings tab — configure allowed/blocked IPs from the UI (`IPFilterSection.js`)
- **System Prompt** settings tab — set global system prompt injection (`SystemPromptTab.js`)
- **Thinking Budget** settings tab — configure reasoning token budgets (`ThinkingBudgetTab.js`)
- **Pricing Tab** — full-page redesign with provider-centric organization, inline editing, search/filter, and save/reset per provider (`PricingTab.js`)
- **Rate Limit Status** component on Usage page (`RateLimitStatus.js`)
- **Sessions Tab** on Usage page — view and manage active sessions (`SessionsTab.js`)
#### Usage & Cost Analytics
- **Cost stat card** (amber accent) prominently displayed in analytics top row
- **Provider Cost Donut** — new chart showing cost distribution across providers
- **Daily Cost Trend** — cost line overlay (amber) on token trend chart with secondary Y-axis
- **Model Table Cost column** — sortable cost column in model breakdown table
- Cost-aware tooltip formatting throughout analytics charts
#### Pricing API
- `/api/pricing/models` endpoint — serves merged model catalog from 3 sources: registry, custom models (DB), and pricing-only models
- Custom model badge in pricing page for user-imported models
- `/api/rate-limits` endpoint for rate limit configuration
- `/api/sessions` endpoint for session management
- `/api/settings/ip-filter`, `/api/settings/system-prompt`, `/api/settings/thinking-budget` endpoints
#### Cloudflare Worker
- Cloud worker module for edge deployment (`cloud/`)
#### Tests
- Unit tests for account selector, context manager, IP filter, enhanced rate limiting, session manager, signature cache, system prompt, thinking budget, and wildcard router (9 new test files)
#### Documentation
- OpenAPI specification at `docs/openapi.yaml` covering all 89 API endpoints
- Enhanced `restart.sh` with clean build, health check, graceful shutdown (Ctrl+C), and real-time log tailing
- Updated architecture documentation and codebase docs with new services and API routes
- Model selector with autocomplete in Chat Tester and Test Bench modes
### Fixed
- Server port collision (EADDRINUSE) during restart — now kills port before `next start`
- Icon rendering corrected from `material-symbols-rounded` to `material-symbols-outlined`
- Pricing page only showed hardcoded registry models — now includes custom/imported models
### Changed
- Usage analytics layout reorganized: donuts separated into logical groupings, bottom stats simplified from 6 to 4 cards
- Daily trend chart upgraded from `BarChart` to `ComposedChart` with dual Y-axes
- Routing tab updated with new service integrations
- 🛣️ **Advanced routing services** — Priority-based routing, global strategy configuration
- 💰 **Cost analytics dashboard** — Token cost tracking and analytics visualization
- 💎 **Pricing overhaul**Comprehensive pricing data for all supported providers and models
- 📦 **npm badge & CLI options**npm version badge in README, CLI options table, automated release docs
---
## [0.0.1] — 2026-02-13
Initial public release of OmniRoute (rebranded from 9router).
## [0.1.0] — 2026-02-14
### Added
- **28 AI Providers** — OpenAI, Anthropic, Google Gemini, DeepSeek, Groq, xAI, Mistral, Perplexity, Together AI, Fireworks AI, Cerebras, Cohere, NVIDIA NIM, Nebius, GitHub Copilot, Cursor, Kiro, Kimi, MiniMax, iFlow, and more
- **OpenAI-compatible proxy** at `/api/v1/chat/completions` with automatic format translation, load balancing, and failover
- **Anthropic Messages API** at `/api/v1/messages` for Claude-native clients
- **OpenAI Responses API** at `/api/v1/responses` for modern OpenAI workflows
- **Embeddings API** at `/api/v1/embeddings` with 6 providers and 9 models
- **Image Generation API** at `/api/v1/images/generations` with 4 providers and 9 models
- **Format Translator** — automatic request/response conversion between OpenAI, Anthropic, Gemini, and OpenAI Responses formats
- **Translator Playground** with 4 modes: Playground, Chat Tester, Test Bench, Live Monitor
- **Combo Routing** — named route configurations with priority, weighted, and round-robin strategies
- **API Key Management** — create/revoke keys with usage attribution
- **Usage Dashboard** — analytics, call logs, request logger with API key filtering and cost tracking
- **Provider Health Diagnostics** — structured status (runtime errors, auth failures, token refresh) with per-connection retest
- **CLI Tools Integration** — runtime detection for Cline, Kiro, Droid, OpenClaw with backup/restore
- **OAuth Flows** — for Cursor, Kiro, Kimi, and GitHub Copilot
- **Docker Support** — multi-stage Dockerfile, docker-compose with 3 profiles (base, cli, host), production compose
- **SOCKS5 Proxy** — outbound proxy support enabled by default (`ab8d752`)
- **Unified Storage** — `DATA_DIR` / `XDG_CONFIG_HOME` resolution with auto-migration from `~/.omniroute`
- **In-app Documentation** at `/docs` with quick start, endpoint reference, and client compatibility notes
- **Dark Theme UI** — modern dashboard with glassmorphism, responsive layout
- `<think>` tag parser for reasoning models (DeepSeek, Qwen)
- Non-stream response translation for all formats
- Secure cookie handling for LAN/reverse-proxy deployments
### Fixed
- OAuth re-authentication no longer creates duplicate connections (`773f117`, `510aedd`)
- Connection test no longer corrupts valid OAuth tokens (`a2ba189`)
- Cloud sync disabled to prevent 404 log spam (`71d132e`)
- `.env.example` synced with current environment structure (`6bdc74b`)
- Select dropdown dark theme inconsistency (`1bd734d`)
### Dependencies
- `actions/github-script` bumped from 7 to 8 (`f6a994a`)
- `eslint` bumped from 9.39.2 to 10.0.0 (`ecd4aea`)
- 🎉 **Initial OmniRoute release** — Rebranded from 9router with full feature set
- 🔄 **28 AI providers** — OpenAI, Claude, Gemini, Copilot, DeepSeek, Groq, xAI, Mistral, Qwen, iFlow, and more
- 🎯 **Smart fallback** — 3-tier auto-routing (Subscription → Cheap → Free)
- 🔀 **Format translation** — Seamless OpenAI ↔ Claude ↔ Gemini format conversion
- 👥 **Multi-account support** — Multiple accounts per provider with round-robin
- 🔐 **OAuth 2.0 (PKCE)** — Automatic token management and refresh
- 📊 **Usage tracking**Real-time quota monitoring with reset countdown
- 🎨 **Custom combos** — Create model combinations with fallback chains
- ☁️ **Cloud sync**Sync configuration across devices via Cloudflare Worker
- 📖 **OpenAPI specification**Full API documentation
- 🛡️ **SOCKS5 proxy support**Outbound proxy for upstream provider calls
- 🔌 **New endpoints**`/v1/rerank`, `/v1/audio/*`, `/v1/moderations`
- 📦 **npm CLI package**`npm install -g omniroute` with auto-launch
- 🐳 **Docker support**Multi-stage Dockerfile with `base` and `cli` profiles
- 🔒 **Security policy**`SECURITY.md` with vulnerability reporting guidelines
- 🧪 **CI/CD pipeline**GitHub Actions for lint, build, test, and npm publish
---
## Pre-Release History (9router)
> The following entries document the legacy 9router project before it was
> rebranded to OmniRoute. All changes below were included in the initial
> `0.0.1` release.
### 0.2.75 — 2026-02-11
- API key attribution in usage/call logs with per-key analytics aggregates
- Usage dashboard API key observability (distribution donut, filterable table)
- In-app docs page (`/docs`) with quick start, endpoint reference, and client compatibility notes
- Unified storage path policy (`DATA_DIR``XDG_CONFIG_HOME``~/.omniroute`)
- Build-phase guard for `usageDb` (in-memory during `next build`)
- LAN/reverse-proxy cookie security detection
- Hardened Gemini 3 Flash normalization and non-stream SSE fallback parsing
- CLI tool runtime and OAuth refresh reliability improvements
- Provider health diagnostics with structured error types
### 0.2.74 — 2026-02-11
- Model resolution fallback fix for unprefixed models
- GitHub Copilot dynamic endpoint selection (Codex → `/responses`)
- Non-stream translation path for OpenAI Responses
- Updated GitHub model catalog with compatibility aliases
### 0.2.73 — 2026-02-09
- Expanded provider registry from 18 → 28 providers (DeepSeek, Groq, xAI, Mistral, Perplexity, Together AI, Fireworks AI, Cerebras, Cohere, NVIDIA NIM)
- `/v1/embeddings` endpoint with 6 providers and 9 models
- `/v1/images/generations` endpoint with 4 providers and 9 models
- `<think>` tag parser for reasoning models
- Available Endpoints card on Endpoint page (127 chat, 9 embedding, 9 image models)
### 0.2.72 — 2026-02-08
- Split Kimi into dual providers: `kimi` (OpenAI-compatible) and `kimi-coding` (Moonshot API)
- Hybrid CLI runtime support with Docker profiles (`runner-base`, `runner-cli`)
- Hardened cloud sync/auth flow with SSE fallback
### 0.2.66 — 2026-02-06
- Cursor provider end-to-end support with OAuth import flow
- `requireLogin` control and `hasPassword` state handling
- Usage/quota UX improvements
- Model support for custom providers
- Codex updates (GPT-5.3, thinking levels), Claude Opus 4.6, MiniMax Coding
- Auto-validation for provider API keys
### 0.2.56 — 2026-02-04
- Anthropic-compatible provider support
- Provider icons across dashboard
- Enhanced usage tracking pipeline
### 0.2.52 — 2026-02-02
- Codex Cursor compatibility and Next.js 16 proxy migration
- OpenAI-compatible provider nodes (CRUD/validation/test)
- Token expiration and key-validity checks
- Non-streaming response translation for multiple formats
- Kiro OAuth wiring and token refresh support
### 0.2.43 — 2026-01-27
- Fixed CLI tools model selection
- Fixed Kiro translator request handling
### 0.2.36 — 2026-01-19
- Usage dashboard page
- Outbound proxy support in Open SSE fetch pipeline
- Fixed combo fallback behavior
### 0.2.31 — 2026-01-18
- Fixed Kiro token refresh and executor behavior
- Fixed Kiro request translation handling
### 0.2.27 — 2026-01-15
- Added Kiro provider support with OAuth flow
- Fixed Codex provider behavior
### 0.2.21 — 2026-01-12
- Initial README and project setup
[0.8.8]: https://github.com/diegosouzapw/OmniRoute/compare/v0.8.5...v0.8.8
[0.8.5]: https://github.com/diegosouzapw/OmniRoute/compare/v0.8.0...v0.8.5
[0.8.0]: https://github.com/diegosouzapw/OmniRoute/compare/v0.7.0...v0.8.0
[0.7.0]: https://github.com/diegosouzapw/OmniRoute/compare/v0.6.0...v0.7.0
[0.6.0]: https://github.com/diegosouzapw/OmniRoute/compare/v0.5.0...v0.6.0
[0.5.0]: https://github.com/diegosouzapw/OmniRoute/compare/v0.4.0...v0.5.0
[0.4.0]: https://github.com/diegosouzapw/OmniRoute/compare/v0.3.0...v0.4.0
[0.3.0]: https://github.com/diegosouzapw/OmniRoute/compare/v0.2.0...v0.3.0
[0.2.0]: https://github.com/diegosouzapw/OmniRoute/compare/v0.1.0...v0.2.0
[0.1.0]: https://github.com/diegosouzapw/OmniRoute/releases/tag/v0.1.0
+25 -25
View File
@@ -123,7 +123,7 @@ npm run lint
npm run check
```
Current test status: **320+ unit tests** covering:
Current test status: **368+ unit tests** covering:
- Provider translators and format conversion
- Rate limiting, circuit breaker, and resilience
@@ -138,7 +138,7 @@ Current test status: **320+ unit tests** covering:
- **ESLint** — Run `npm run lint` before committing
- **Prettier** — Auto-formatted via `lint-staged` on commit
- **JSDoc** — Document public functions with `@param`, `@returns`, `@throws`
- **TypeScript** — All `src/` code uses `.ts`/`.tsx`; document with TSDoc (`@param`, `@returns`, `@throws`)
- **No `eval()`** — ESLint enforces `no-eval`, `no-implied-eval`, `no-new-func`
- **Zod validation** — Use Zod schemas for API input validation
@@ -147,34 +147,34 @@ Current test status: **320+ unit tests** covering:
## Project Structure
```
src/
src/ # TypeScript (.ts / .tsx)
├── app/ # Next.js App Router
│ ├── (dashboard)/ # Dashboard pages
│ ├── api/ # API routes
│ └── login/ # Auth pages
├── domain/ # Domain types and response helpers
├── lib/ # Core business logic
│ ├── (dashboard)/ # Dashboard pages (.tsx)
│ ├── api/ # API routes (.ts)
│ └── login/ # Auth pages (.tsx)
├── domain/ # Domain types and response helpers (.ts)
├── lib/ # Core business logic (.ts)
│ ├── db/ # SQLite database layer
│ ├── oauth/ # OAuth services per provider
│ ├── cacheLayer.js # LRU cache
│ ├── semanticCache.js # Semantic response cache
│ ├── idempotencyLayer.js # Request deduplication
│ └── localDb.js # LowDB (JSON) storage
│ ├── cacheLayer.ts # LRU cache
│ ├── semanticCache.ts # Semantic response cache
│ ├── idempotencyLayer.ts # Request deduplication
│ └── localDb.ts # LowDB (JSON) storage
├── shared/
│ ├── components/ # React components
│ ├── components/ # React components (.tsx)
│ ├── middleware/ # Correlation IDs, etc.
│ ├── utils/ # Circuit breaker, sanitizer, etc.
│ └── validation/ # Zod schemas
└── sse/ # SSE chat handlers
└── sse/ # SSE chat handlers (.ts)
open-sse/ # @omniroute/open-sse workspace
open-sse/ # @omniroute/open-sse workspace (JavaScript)
├── handlers/ # chatCore.js — main request handler
├── services/ # Rate limit, fallback
├── translators/ # Format converters (OpenAI ↔ Claude ↔ Gemini)
└── utils/ # Progress tracker, stream helpers
tests/
├── unit/ # Node.js test runner
├── unit/ # Node.js test runner (.test.mjs)
└── e2e/ # Playwright tests
docs/ # Documentation
@@ -191,10 +191,10 @@ docs/ # Documentation
### Step 1: OAuth Service (if using OAuth)
Create `src/lib/oauth/services/your-provider.js` extending `OAuthService`:
Create `src/lib/oauth/services/your-provider.ts` extending `OAuthService`:
```javascript
import { OAuthService } from "../OAuthService.js";
```typescript
import { OAuthService } from "../OAuthService";
export class YourProviderService extends OAuthService {
constructor() {
@@ -211,16 +211,16 @@ export class YourProviderService extends OAuthService {
### Step 2: Register Provider
Add to `src/lib/oauth/providers.js`:
Add to `src/lib/oauth/providers.ts`:
```javascript
import { YourProviderService } from "./services/your-provider.js";
```typescript
import { YourProviderService } from "./services/your-provider";
// Add to the providers map
```
### Step 3: Add Constants
Add provider constants in `src/lib/providerConstants.js`:
Add provider constants in `src/lib/providerConstants.ts`:
- Provider prefix (e.g., `yp/`)
- Default models
@@ -232,7 +232,7 @@ Create translator in `open-sse/translators/` if the provider uses a custom API f
### Step 5: Add Timeout
Add request timeout configuration in `src/shared/utils/requestTimeout.js`.
Add request timeout configuration in `src/shared/utils/requestTimeout.ts`.
### Step 6: Add Tests
@@ -249,7 +249,7 @@ Write unit tests in `tests/unit/` covering at minimum:
- [ ] Tests pass (`npm test`)
- [ ] Linting passes (`npm run lint`)
- [ ] Build succeeds (`npm run build`)
- [ ] JSDoc added for new public functions
- [ ] TypeScript types added for new public functions and interfaces
- [ ] No hardcoded secrets or fallback values
- [ ] CHANGELOG updated (if user-facing change)
- [ ] Documentation updated (if applicable)
+1
View File
@@ -12,6 +12,7 @@ WORKDIR /app
LABEL org.opencontainers.image.title="omniroute" \
org.opencontainers.image.description="Unified AI proxy — route any LLM through one endpoint" \
org.opencontainers.image.url="https://omniroute.online" \
org.opencontainers.image.source="https://github.com/diegosouzapw/OmniRoute" \
org.opencontainers.image.licenses="MIT"
+187 -25
View File
@@ -5,7 +5,7 @@
**Never stop coding. Auto-route to FREE & cheap AI models with smart fallback.**
**28 Providers • Embeddings • Image Generation • Think Tag Parsing**
**36+ Providers • Embeddings • Image Generation • Audio • Reranking • Full TypeScript**
**Free AI Provider for OpenClaw.**
@@ -16,9 +16,11 @@
> *This project is inspired by and originally forked from [9router](https://github.com/decolua/9router) by [decolua](https://github.com/decolua). Thank you for the incredible foundation!*
[![npm version](https://img.shields.io/npm/v/omniroute?color=cb3837&logo=npm)](https://www.npmjs.com/package/omniroute)
[![Docker Hub](https://img.shields.io/docker/v/diegosouzapw/omniroute?label=Docker%20Hub&logo=docker&color=2496ED)](https://hub.docker.com/r/diegosouzapw/omniroute)
[![License](https://img.shields.io/github/license/diegosouzapw/OmniRoute)](https://github.com/diegosouzapw/OmniRoute/blob/main/LICENSE)
[![Website](https://img.shields.io/badge/Website-omniroute.online-blue?logo=google-chrome&logoColor=white)](https://omniroute.online)
[🚀 Quick Start](#-quick-start) • [💡 Features](#-key-features) • [📖 Docs](#-documentation)
[🌐 Website](https://omniroute.online) • [🚀 Quick Start](#-quick-start) • [💡 Features](#-key-features) • [📖 Docs](#-documentation)
</div>
---
@@ -113,40 +115,196 @@ PORT=20128 NEXT_PUBLIC_BASE_URL=http://localhost:20128 npm run dev
---
## 🐳 Docker
OmniRoute is available as a public Docker image on [Docker Hub](https://hub.docker.com/r/diegosouzapw/omniroute).
**Quick run:**
```bash
docker run -d \
--name omniroute \
--restart unless-stopped \
-p 20128:20128 \
-v omniroute-data:/app/data \
diegosouzapw/omniroute:latest
```
**With environment file:**
```bash
# Copy and edit .env first
cp .env.example .env
docker run -d \
--name omniroute \
--restart unless-stopped \
--env-file .env \
-p 20128:20128 \
-v omniroute-data:/app/data \
diegosouzapw/omniroute:latest
```
**Using Docker Compose:**
```bash
# Base profile (no CLI tools)
docker compose --profile base up -d
# CLI profile (Claude Code, Codex, OpenClaw built-in)
docker compose --profile cli up -d
```
| Image | Tag | Size | Description |
| ------------------------ | -------- | ------ | --------------------- |
| `diegosouzapw/omniroute` | `latest` | ~250MB | Latest stable release |
| `diegosouzapw/omniroute` | `0.8.8` | ~250MB | Current version |
---
## 💡 Key Features
| Feature | What It Does |
| ------------------------------- | --------------------------------------------- |
| 🎯 **Smart 3-Tier Fallback** | Auto-route: Subscription → Cheap → Free |
| 📊 **Real-Time Quota Tracking** | Live token count + reset countdown |
| 🔄 **Format Translation** | OpenAI ↔ Claude ↔ Gemini seamless |
| 👥 **Multi-Account Support** | Multiple accounts per provider |
| 🔄 **Auto Token Refresh** | OAuth tokens refresh automatically |
| 🎨 **Custom Combos** | Create unlimited model combinations |
| 🧩 **Custom Models** | Add any model ID to any provider |
| 📝 **Request Logging** | Debug mode with full request/response logs |
| 💾 **Cloud Sync** | Sync config across devices |
| 📊 **Usage Analytics** | Track tokens, cost, trends over time |
| 🌐 **Deploy Anywhere** | Localhost, VPS, Docker, Cloudflare Workers |
| 🔌 **Circuit Breaker** | Auto-open/close per-provider with cooldowns |
| 🛡️ **Anti-Thundering Herd** | Mutex + auto rate-limit for API key providers |
| 🧠 **Semantic Cache** | Two-tier cache reduces cost & latency |
| ⚡ **Request Idempotency** | 5s dedup window for duplicate requests |
| 📈 **Progress Tracking** | Opt-in SSE progress events for streaming |
### 🧠 Core Routing & Intelligence
| Feature | What It Does |
| ------------------------------- | ------------------------------------------------------------------------------ |
| 🎯 **Smart 4-Tier Fallback** | Auto-route: Subscription → API Key → Cheap → Free |
| 📊 **Real-Time Quota Tracking** | Live token count + reset countdown per provider |
| 🔄 **Format Translation** | OpenAI ↔ Claude ↔ Gemini ↔ Cursor ↔ Kiro seamless |
| 👥 **Multi-Account Support** | Multiple accounts per provider with intelligent selection |
| 🔄 **Auto Token Refresh** | OAuth tokens refresh automatically with retry |
| 🎨 **Custom Combos** | 6 strategies: fill-first, round-robin, p2c, random, least-used, cost-optimized |
| 🧩 **Custom Models** | Add any model ID to any provider |
| 🌐 **Wildcard Router** | Route `provider/*` patterns to any provider dynamically |
| 🧠 **Thinking Budget** | Passthrough, auto, custom, and adaptive modes for reasoning models |
| 💬 **System Prompt Injection** | Global system prompt applied across all requests |
| 📄 **Responses API** | Full OpenAI Responses API (`/v1/responses`) support for Codex |
### 🎵 Multi-Modal APIs
| Feature | What It Does |
| -------------------------- | --------------------------------------------------- |
| 🖼️ **Image Generation** | `/v1/images/generations` — 4 providers, 9+ models |
| 📐 **Embeddings** | `/v1/embeddings` — 6 providers, 9+ models |
| 🎤 **Audio Transcription** | `/v1/audio/transcriptions` — Whisper-compatible |
| 🔊 **Text-to-Speech** | `/v1/audio/speech` — Multi-provider audio synthesis |
| 🛡️ **Moderations** | `/v1/moderations` — Content safety checks |
| 🔀 **Reranking** | `/v1/rerank` — Document relevance reranking |
### 🛡️ Resilience & Security
| Feature | What It Does |
| ------------------------------- | ------------------------------------------------------------- |
| 🔌 **Circuit Breaker** | Auto-open/close per-provider with configurable thresholds |
| 🛡️ **Anti-Thundering Herd** | Mutex + semaphore rate-limit for API key providers |
| 🧠 **Semantic Cache** | Two-tier cache (signature + semantic) reduces cost & latency |
| ⚡ **Request Idempotency** | 5s dedup window for duplicate requests |
| 🔒 **TLS Fingerprint Spoofing** | Bypass TLS-based bot detection via wreq-js |
| 🌐 **IP Filtering** | Allowlist/blocklist for API access control |
| 📋 **Compliance Audit Log** | Tamper-proof request logs with opt-out per API key |
| 📊 **Editable Rate Limits** | Configurable RPM, min gap, and max concurrent at system level |
### 📊 Observability & Analytics
| Feature | What It Does |
| ---------------------------- | --------------------------------------------------------------- |
| 📝 **Request Logging** | Debug mode with full request/response logs |
| 💾 **SQLite Proxy Logs** | Persistent proxy logs survive server restarts |
| 📊 **Analytics Dashboard** | Recharts-powered: stat cards, model usage chart, provider table |
| 📈 **Progress Tracking** | Opt-in SSE progress events for streaming |
| 🧪 **LLM Evaluations** | Golden set testing with 4 match strategies |
| 🔍 **Request Telemetry** | p50/p95/p99 latency aggregation + X-Request-Id tracing |
| 📋 **Request Logs + Quotas** | Dedicated pages for log browsing and limits/quotas tracking |
### ☁️ Deployment & Sync
| Feature | What It Does |
| ------------------------- | ------------------------------------------------- |
| 💾 **Cloud Sync** | Sync config across devices via Cloudflare Workers |
| 🌐 **Deploy Anywhere** | Localhost, VPS, Docker, Cloudflare Workers |
| 🔑 **API Key Management** | Generate, rotate, and scope API keys per provider |
---
## 🧪 Evaluations (Evals)
OmniRoute includes a built-in evaluation framework to test LLM response quality against a golden set. Access it via **Analytics → Evals** in the dashboard.
### Built-in Golden Set
The pre-loaded "OmniRoute Golden Set" contains 10 test cases covering:
- Greetings, math, geography, code generation
- JSON format compliance, translation, markdown
- Safety refusal (harmful content), counting, boolean logic
### How It Works
1. Click **"Run Eval"** on a suite in the dashboard
2. Each test case is sent to your proxy endpoint (`/v1/chat/completions`)
3. Real LLM responses are collected and evaluated against expected criteria
4. Results show pass/fail status, latency per case, and overall pass rate
### Evaluation Strategies
| Strategy | Description | Example |
| ---------- | ------------------------------------------------ | -------------------------------- |
| `exact` | Output must match exactly | `"4"` |
| `contains` | Output must contain substring (case-insensitive) | `"Paris"` |
| `regex` | Output must match regex pattern | `"1.*2.*3"` |
| `custom` | Custom JS function returns true/false | `(output) => output.length > 10` |
### API Usage
```bash
# List all eval suites
curl http://localhost:20128/api/evals
# Run a suite with pre-collected outputs
curl -X POST http://localhost:20128/api/evals \
-H 'Content-Type: application/json' \
-d '{"suiteId": "golden-set", "outputs": {"gs-01": "Hello there!", "gs-02": "4"}}'
# Get suite details
curl http://localhost:20128/api/evals/golden-set
```
### Custom Suites
Register custom suites programmatically via `registerSuite()` in `src/lib/evals/evalRunner.ts`:
```typescript
registerSuite({
id: "my-suite",
name: "Custom Eval Suite",
cases: [
{
id: "c-01",
name: "API response",
model: "gpt-4o",
input: { messages: [{ role: "user", content: "Say OK" }] },
expected: { strategy: "contains", value: "OK" },
},
],
});
```
---
## 🛠️ Tech Stack
- **Runtime**: Node.js 20+
- **Language**: TypeScript 5.9 — **100% TypeScript** across `src/` and `open-sse/` (v0.8.8)
- **Framework**: Next.js 16 + React 19 + Tailwind CSS 4
- **Database**: LowDB (JSON) + SQLite (domain state)
- **Database**: LowDB (JSON) + SQLite (domain state + proxy logs)
- **Streaming**: Server-Sent Events (SSE)
- **Auth**: OAuth 2.0 (PKCE) + JWT + API Keys
- **Testing**: Node.js test runner (320+ unit tests)
- **CI/CD**: GitHub Actions (auto npm publish on release)
- **Testing**: Node.js test runner (368+ unit tests)
- **CI/CD**: GitHub Actions (auto npm publish + Docker Hub on release)
- **Website**: [omniroute.online](https://omniroute.online)
- **Package**: [npmjs.com/package/omniroute](https://www.npmjs.com/package/omniroute)
- **Resilience**: Circuit breaker, exponential backoff, anti-thundering herd
- **Docker**: [hub.docker.com/r/diegosouzapw/omniroute](https://hub.docker.com/r/diegosouzapw/omniroute)
- **Resilience**: Circuit breaker, exponential backoff, anti-thundering herd, TLS spoofing
---
@@ -160,11 +318,13 @@ PORT=20128 NEXT_PUBLIC_BASE_URL=http://localhost:20128 npm run dev
| [Architecture](docs/ARCHITECTURE.md) | System architecture and internals |
| [Contributing](CONTRIBUTING.md) | Development setup and guidelines |
| [OpenAPI Spec](docs/openapi.yaml) | OpenAPI 3.0 specification |
| [Security Policy](SECURITY.md) | Vulnerability reporting and security practices |
---
## 📧 Support
- **Website**: [omniroute.online](https://omniroute.online)
- **GitHub**: [github.com/diegosouzapw/OmniRoute](https://github.com/diegosouzapw/OmniRoute)
- **Issues**: [github.com/diegosouzapw/OmniRoute/issues](https://github.com/diegosouzapw/OmniRoute/issues)
- **Original Project**: [9router by decolua](https://github.com/decolua/9router)
@@ -189,7 +349,7 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for detailed guidelines.
```bash
# Create a release — npm publish happens automatically
gh release create v0.4.0 --title "v0.4.0" --generate-notes
gh release create v0.8.8 --title "v0.8.8" --generate-notes
```
---
@@ -208,4 +368,6 @@ MIT License - see [LICENSE](LICENSE) for details.
<div align="center">
<sub>Built with ❤️ for developers who code 24/7</sub>
<br/>
<sub><a href="https://omniroute.online">omniroute.online</a></sub>
</div>
+120 -17
View File
@@ -5,7 +5,7 @@
If you discover a security vulnerability in OmniRoute, please report it responsibly:
1. **DO NOT** open a public GitHub issue
2. Email: **security@omniroute.dev** (or use GitHub Security Advisories)
2. Use [GitHub Security Advisories](https://github.com/diegosouzapw/OmniRoute/security/advisories/new)
3. Include: description, reproduction steps, and potential impact
## Response Timeline
@@ -20,47 +20,150 @@ If you discover a security vulnerability in OmniRoute, please report it responsi
| Version | Support Status |
| ------- | -------------- |
| 0.4.x | ✅ Active |
| 0.3.x | ✅ Active |
| < 0.3.0 | ❌ Unsupported |
| 0.8.x | ✅ Active |
| 0.7.x | ✅ Security |
| < 0.7.0 | ❌ Unsupported |
## Security Best Practices
---
### Required Environment Variables
## Security Architecture
All secrets must be set before starting the server. The server will **fail fast** if they are missing or weak.
OmniRoute implements a multi-layered security model:
```
Request → CORS → API Key Auth → Prompt Injection Guard → Input Sanitizer → Rate Limiter → Circuit Breaker → Provider
```
### 🔐 Authentication & Authorization
| Feature | Implementation |
| -------------------- | ---------------------------------------------------------- |
| **Dashboard Login** | Password-based auth with JWT tokens (HttpOnly cookies) |
| **API Key Auth** | HMAC-signed keys with CRC validation |
| **OAuth 2.0 + PKCE** | Secure provider auth (Claude, Codex, Gemini, Cursor, etc.) |
| **Token Refresh** | Automatic OAuth token refresh before expiry |
| **Secure Cookies** | `AUTH_COOKIE_SECURE=true` for HTTPS environments |
### 🛡️ Encryption at Rest
All sensitive data stored in SQLite is encrypted using **AES-256-GCM** with scrypt key derivation:
- API keys, access tokens, refresh tokens, and ID tokens
- Versioned format: `enc:v1:<iv>:<ciphertext>:<authTag>`
- Passthrough mode (plaintext) when `STORAGE_ENCRYPTION_KEY` is not set
```bash
# Generate strong secrets:
JWT_SECRET=$(openssl rand -base64 48)
API_KEY_SECRET=$(openssl rand -hex 32)
# Generate encryption key:
STORAGE_ENCRYPTION_KEY=$(openssl rand -hex 32)
```
### Input Protection
### 🧠 Prompt Injection Guard
OmniRoute includes built-in protection against:
Middleware that detects and blocks prompt injection attacks in LLM requests:
- **Prompt injection** — Detects system override, role hijack, delimiter injection, and DAN/jailbreak patterns
- **PII leakage** — Optional detection and redaction of emails, CPF/CNPJ, credit cards, and phone numbers
| Pattern Type | Severity | Example |
| ------------------- | -------- | ---------------------------------------------- |
| System Override | High | "ignore all previous instructions" |
| Role Hijack | High | "you are now DAN, you can do anything" |
| Delimiter Injection | Medium | Encoded separators to break context boundaries |
| DAN/Jailbreak | High | Known jailbreak prompt patterns |
| Instruction Leak | Medium | "show me your system prompt" |
Configure in `.env`:
Configure via dashboard (Settings → Security) or `.env`:
```env
INPUT_SANITIZER_ENABLED=true
INPUT_SANITIZER_MODE=block # warn | block | redact
```
### 🔒 PII Redaction
Automatic detection and optional redaction of personally identifiable information:
| PII Type | Pattern | Replacement |
| ------------- | --------------------- | ------------------ |
| Email | `user@domain.com` | `[EMAIL_REDACTED]` |
| CPF (Brazil) | `123.456.789-00` | `[CPF_REDACTED]` |
| CNPJ (Brazil) | `12.345.678/0001-00` | `[CNPJ_REDACTED]` |
| Credit Card | `4111-1111-1111-1111` | `[CC_REDACTED]` |
| Phone | `+55 11 99999-9999` | `[PHONE_REDACTED]` |
| SSN (US) | `123-45-6789` | `[SSN_REDACTED]` |
```env
PII_REDACTION_ENABLED=true
```
### Docker Security
### 🌐 Network Security
| Feature | Description |
| ------------------------ | ---------------------------------------------------------------- |
| **CORS** | Configurable origin control (`CORS_ORIGIN` env var, default `*`) |
| **IP Filtering** | Whitelist/blacklist IP ranges in dashboard |
| **Rate Limiting** | Per-provider rate limits with automatic backoff |
| **Anti-Thundering Herd** | Mutex + per-connection locking prevents cascading 502s |
### 🔌 Resilience & Availability
| Feature | Description |
| ----------------------- | ------------------------------------------------------------------ |
| **Circuit Breaker** | 3-state (Closed → Open → Half-Open) per provider, SQLite-persisted |
| **Request Idempotency** | 5-second dedup window for duplicate requests |
| **Exponential Backoff** | Automatic retry with increasing delays |
| **Health Dashboard** | Real-time provider health monitoring |
### 📋 Compliance
| Feature | Description |
| ------------------ | --------------------------------------------------- |
| **Log Retention** | Automatic cleanup after `LOG_RETENTION_DAYS` |
| **No-Log Opt-out** | Per API key `noLog` flag disables request logging |
| **Audit Log** | Administrative actions tracked in `audit_log` table |
---
## Required Environment Variables
All secrets must be set before starting the server. The server will **fail fast** if they are missing or weak.
```bash
# REQUIRED — server will not start without these:
JWT_SECRET=$(openssl rand -base64 48) # min 32 chars
API_KEY_SECRET=$(openssl rand -hex 32) # min 16 chars
# RECOMMENDED — enables encryption at rest:
STORAGE_ENCRYPTION_KEY=$(openssl rand -hex 32)
```
The server actively rejects known-weak values like `changeme`, `secret`, or `password`.
---
## Docker Security
- Use non-root user in production
- Mount secrets as read-only volumes
- Never copy `.env` files into Docker images
- Use `.dockerignore` to exclude sensitive files
- Set `AUTH_COOKIE_SECURE=true` when behind HTTPS
### Dependencies
```bash
docker run -d \
--name omniroute \
--restart unless-stopped \
--read-only \
-p 20128:20128 \
-v omniroute-data:/app/data \
-e JWT_SECRET="$(openssl rand -base64 48)" \
-e API_KEY_SECRET="$(openssl rand -hex 32)" \
-e STORAGE_ENCRYPTION_KEY="$(openssl rand -hex 32)" \
diegosouzapw/omniroute:latest
```
---
## Dependencies
- Run `npm audit` regularly
- Keep dependencies updated
- The project uses `husky` + `lint-staged` for pre-commit checks
- CI pipeline runs ESLint security rules on every push
+428
View File
@@ -0,0 +1,428 @@
# API Reference
Complete reference for all OmniRoute API endpoints.
---
## Table of Contents
- [Chat Completions](#chat-completions)
- [Embeddings](#embeddings)
- [Image Generation](#image-generation)
- [List Models](#list-models)
- [Compatibility Endpoints](#compatibility-endpoints)
- [Semantic Cache](#semantic-cache)
- [Dashboard & Management](#dashboard--management)
- [Request Processing](#request-processing)
- [Authentication](#authentication)
---
## Chat Completions
```bash
POST /v1/chat/completions
Authorization: Bearer your-api-key
Content-Type: application/json
{
"model": "cc/claude-opus-4-6",
"messages": [
{"role": "user", "content": "Write a function to..."}
],
"stream": true
}
```
### Custom Headers
| Header | Direction | Description |
| ------------------------ | --------- | --------------------------------- |
| `X-OmniRoute-No-Cache` | Request | Set to `true` to bypass cache |
| `X-OmniRoute-Progress` | Request | Set to `true` for progress events |
| `Idempotency-Key` | Request | Dedup key (5s window) |
| `X-Request-Id` | Request | Alternative dedup key |
| `X-OmniRoute-Cache` | Response | `HIT` or `MISS` (non-streaming) |
| `X-OmniRoute-Idempotent` | Response | `true` if deduplicated |
| `X-OmniRoute-Progress` | Response | `enabled` if progress tracking on |
---
## Embeddings
```bash
POST /v1/embeddings
Authorization: Bearer your-api-key
Content-Type: application/json
{
"model": "nebius/Qwen/Qwen3-Embedding-8B",
"input": "The food was delicious"
}
```
Available providers: Nebius, OpenAI, Mistral, Together AI, Fireworks, NVIDIA.
```bash
# List all embedding models
GET /v1/embeddings
```
---
## Image Generation
```bash
POST /v1/images/generations
Authorization: Bearer your-api-key
Content-Type: application/json
{
"model": "openai/dall-e-3",
"prompt": "A beautiful sunset over mountains",
"size": "1024x1024"
}
```
Available providers: OpenAI (DALL-E), xAI (Grok Image), Together AI (FLUX), Fireworks AI.
```bash
# List all image models
GET /v1/images/generations
```
---
## List Models
```bash
GET /v1/models
Authorization: Bearer your-api-key
→ Returns all chat, embedding, and image models + combos in OpenAI format
```
---
## Compatibility Endpoints
| Method | Path | Format |
| ------ | --------------------------- | ---------------------- |
| POST | `/v1/chat/completions` | OpenAI |
| POST | `/v1/messages` | Anthropic |
| POST | `/v1/responses` | OpenAI Responses |
| POST | `/v1/embeddings` | OpenAI |
| POST | `/v1/images/generations` | OpenAI |
| GET | `/v1/models` | OpenAI |
| POST | `/v1/messages/count_tokens` | Anthropic |
| GET | `/v1beta/models` | Gemini |
| POST | `/v1beta/models/{...path}` | Gemini generateContent |
| POST | `/v1/api/chat` | Ollama |
### Dedicated Provider Routes
```bash
POST /v1/providers/{provider}/chat/completions
POST /v1/providers/{provider}/embeddings
POST /v1/providers/{provider}/images/generations
```
The provider prefix is auto-added if missing. Mismatched models return `400`.
---
## Semantic Cache
```bash
# Get cache stats
GET /api/cache
# Clear all caches
DELETE /api/cache
```
Response example:
```json
{
"semanticCache": {
"memorySize": 42,
"memoryMaxSize": 500,
"dbSize": 128,
"hitRate": 0.65
},
"idempotency": {
"activeKeys": 3,
"windowMs": 5000
}
}
```
---
## Dashboard & Management
### Authentication
| Endpoint | Method | Description |
| ----------------------------- | ------- | --------------------- |
| `/api/auth/login` | POST | Login |
| `/api/auth/logout` | POST | Logout |
| `/api/settings/require-login` | GET/PUT | Toggle login required |
### Provider Management
| Endpoint | Method | Description |
| ---------------------------- | --------------- | ------------------------ |
| `/api/providers` | GET/POST | List / create providers |
| `/api/providers/[id]` | GET/PUT/DELETE | Manage a provider |
| `/api/providers/[id]/test` | POST | Test provider connection |
| `/api/providers/[id]/models` | GET | List provider models |
| `/api/providers/validate` | POST | Validate provider config |
| `/api/provider-nodes*` | Various | Provider node management |
| `/api/provider-models` | GET/POST/DELETE | Custom models |
### OAuth Flows
| Endpoint | Method | Description |
| -------------------------------- | ------- | ----------------------- |
| `/api/oauth/[provider]/[action]` | Various | Provider-specific OAuth |
### Routing & Config
| Endpoint | Method | Description |
| --------------------- | -------- | ----------------------------- |
| `/api/models/alias` | GET/POST | Model aliases |
| `/api/models/catalog` | GET | All models by provider + type |
| `/api/combos*` | Various | Combo management |
| `/api/keys*` | Various | API key management |
| `/api/pricing` | GET | Model pricing |
### Usage & Analytics
| Endpoint | Method | Description |
| --------------------------- | ------ | -------------------- |
| `/api/usage/history` | GET | Usage history |
| `/api/usage/logs` | GET | Usage logs |
| `/api/usage/request-logs` | GET | Request-level logs |
| `/api/usage/[connectionId]` | GET | Per-connection usage |
### Settings
| Endpoint | Method | Description |
| ------------------------------- | ------- | ---------------------- |
| `/api/settings` | GET/PUT | General settings |
| `/api/settings/proxy` | GET/PUT | Network proxy config |
| `/api/settings/proxy/test` | POST | Test proxy connection |
| `/api/settings/ip-filter` | GET/PUT | IP allowlist/blocklist |
| `/api/settings/thinking-budget` | GET/PUT | Reasoning token budget |
| `/api/settings/system-prompt` | GET/PUT | Global system prompt |
### Monitoring
| Endpoint | Method | Description |
| ------------------------ | ---------- | ----------------------- |
| `/api/sessions` | GET | Active session tracking |
| `/api/rate-limits` | GET | Per-account rate limits |
| `/api/monitoring/health` | GET | Health check |
| `/api/cache` | GET/DELETE | Cache stats / clear |
### Cloud Sync
| Endpoint | Method | Description |
| ---------------------- | ------- | --------------------- |
| `/api/sync/cloud` | Various | Cloud sync operations |
| `/api/sync/initialize` | POST | Initialize sync |
| `/api/cloud/*` | Various | Cloud management |
### CLI Tools
| Endpoint | Method | Description |
| ---------------------------------- | ------ | ------------------- |
| `/api/cli-tools/claude-settings` | GET | Claude CLI status |
| `/api/cli-tools/codex-settings` | GET | Codex CLI status |
| `/api/cli-tools/droid-settings` | GET | Droid CLI status |
| `/api/cli-tools/openclaw-settings` | GET | OpenClaw CLI status |
| `/api/cli-tools/runtime/[toolId]` | GET | Generic CLI runtime |
CLI responses include: `installed`, `runnable`, `command`, `commandPath`, `runtimeMode`, `reason`.
### Resilience & Rate Limits
| Endpoint | Method | Description |
| ----------------------- | ------- | ------------------------------- |
| `/api/resilience` | GET/PUT | Get/update resilience profiles |
| `/api/resilience/reset` | POST | Reset circuit breakers |
| `/api/rate-limits` | GET | Per-account rate limit status |
| `/api/rate-limit` | GET | Global rate limit configuration |
### Evals
| Endpoint | Method | Description |
| ------------ | -------- | --------------------------------- |
| `/api/evals` | GET/POST | List eval suites / run evaluation |
### Policies
| Endpoint | Method | Description |
| --------------- | --------------- | ----------------------- |
| `/api/policies` | GET/POST/DELETE | Manage routing policies |
### Compliance
| Endpoint | Method | Description |
| --------------------------- | ------ | ----------------------------- |
| `/api/compliance/audit-log` | GET | Compliance audit log (last N) |
### v1beta (Gemini-Compatible)
| Endpoint | Method | Description |
| -------------------------- | ------ | --------------------------------- |
| `/v1beta/models` | GET | List models in Gemini format |
| `/v1beta/models/{...path}` | POST | Gemini `generateContent` endpoint |
These endpoints mirror Gemini's API format for clients that expect native Gemini SDK compatibility.
### Internal / System APIs
| Endpoint | Method | Description |
| --------------- | ------ | ---------------------------------------------------- |
| `/api/init` | GET | Application initialization check (used on first run) |
| `/api/tags` | GET | Ollama-compatible model tags (for Ollama clients) |
| `/api/restart` | POST | Trigger graceful server restart |
| `/api/shutdown` | POST | Trigger graceful server shutdown |
> **Note:** These endpoints are used internally by the system or for Ollama client compatibility. They are not typically called by end users.
---
## Audio Transcription
```bash
POST /v1/audio/transcriptions
Authorization: Bearer your-api-key
Content-Type: multipart/form-data
```
Transcribe audio files using Deepgram or AssemblyAI.
**Request:**
```bash
curl -X POST http://localhost:20128/v1/audio/transcriptions \
-H "Authorization: Bearer your-api-key" \
-F "file=@recording.mp3" \
-F "model=deepgram/nova-3"
```
**Response:**
```json
{
"text": "Hello, this is the transcribed audio content.",
"task": "transcribe",
"language": "en",
"duration": 12.5
}
```
**Supported providers:** `deepgram/nova-3`, `assemblyai/best`.
**Supported formats:** `mp3`, `wav`, `m4a`, `flac`, `ogg`, `webm`.
---
## Ollama Compatibility
For clients that use Ollama's API format:
```bash
# Chat endpoint (Ollama format)
POST /v1/api/chat
# Model listing (Ollama format)
GET /api/tags
```
Requests are automatically translated between Ollama and internal formats.
---
## Telemetry
```bash
# Get latency telemetry summary (p50/p95/p99 per provider)
GET /api/telemetry/summary
```
**Response:**
```json
{
"providers": {
"claudeCode": { "p50": 245, "p95": 890, "p99": 1200, "count": 150 },
"github": { "p50": 180, "p95": 620, "p99": 950, "count": 320 }
}
}
```
---
## Budget
```bash
# Get budget status for all API keys
GET /api/usage/budget
# Set or update a budget
POST /api/usage/budget
Content-Type: application/json
{
"keyId": "key-123",
"limit": 50.00,
"period": "monthly"
}
```
---
## Model Availability
```bash
# Get real-time model availability across all providers
GET /api/models/availability
# Check availability for a specific model
POST /api/models/availability
Content-Type: application/json
{
"model": "claude-sonnet-4-5-20250929"
}
```
---
## Request Processing
1. Client sends request to `/v1/*`
2. Route handler calls `handleChat`, `handleEmbedding`, `handleAudioTranscription`, or `handleImageGeneration`
3. Model is resolved (direct provider/model or alias/combo)
4. Credentials selected from local DB with account availability filtering
5. For chat: `handleChatCore` — format detection, translation, cache check, idempotency check
6. Provider executor sends upstream request
7. Response translated back to client format (chat) or returned as-is (embeddings/images/audio)
8. Usage/logging recorded
9. Fallback applies on errors according to combo rules
Full architecture reference: [`ARCHITECTURE.md`](ARCHITECTURE.md)
---
## Authentication
- Dashboard routes (`/dashboard/*`) use `auth_token` cookie
- Login uses saved password hash; fallback to `INITIAL_PASSWORD`
- `requireLogin` toggleable via `/api/settings/require-login`
- `/v1/*` routes optionally require Bearer API key when `REQUIRE_API_KEY=true`
+86 -82
View File
@@ -1,6 +1,6 @@
# OmniRoute Architecture
_Last updated: 2026-02-15_
_Last updated: 2026-02-17_
## Executive Summary
@@ -120,18 +120,18 @@ Main directories:
Important compatibility routes:
- `src/app/api/v1/chat/completions/route.js`
- `src/app/api/v1/messages/route.js`
- `src/app/api/v1/responses/route.js`
- `src/app/api/v1/models/route.js` — includes custom models with `custom: true`
- `src/app/api/v1/embeddings/route.js` — embedding generation (6 providers)
- `src/app/api/v1/images/generations/route.js` — image generation (4+ providers incl. Antigravity/Nebius)
- `src/app/api/v1/messages/count_tokens/route.js`
- `src/app/api/v1/providers/[provider]/chat/completions/route.js` — dedicated per-provider chat
- `src/app/api/v1/providers/[provider]/embeddings/route.js` — dedicated per-provider embeddings
- `src/app/api/v1/providers/[provider]/images/generations/route.js` — dedicated per-provider images
- `src/app/api/v1beta/models/route.js`
- `src/app/api/v1beta/models/[...path]/route.js`
- `src/app/api/v1/chat/completions/route.ts`
- `src/app/api/v1/messages/route.ts`
- `src/app/api/v1/responses/route.ts`
- `src/app/api/v1/models/route.ts` — includes custom models with `custom: true`
- `src/app/api/v1/embeddings/route.ts` — embedding generation (6 providers)
- `src/app/api/v1/images/generations/route.ts` — image generation (4+ providers incl. Antigravity/Nebius)
- `src/app/api/v1/messages/count_tokens/route.ts`
- `src/app/api/v1/providers/[provider]/chat/completions/route.ts` — dedicated per-provider chat
- `src/app/api/v1/providers/[provider]/embeddings/route.ts` — dedicated per-provider embeddings
- `src/app/api/v1/providers/[provider]/images/generations/route.ts` — dedicated per-provider images
- `src/app/api/v1beta/models/route.ts`
- `src/app/api/v1beta/models/[...path]/route.ts`
Management domains:
@@ -166,89 +166,89 @@ Management domains:
Main flow modules:
- Entry: `src/sse/handlers/chat.js`
- Core orchestration: `open-sse/handlers/chatCore.js`
- Entry: `src/sse/handlers/chat.ts`
- Core orchestration: `open-sse/handlers/chatCore.ts`
- Provider execution adapters: `open-sse/executors/*`
- Format detection/provider config: `open-sse/services/provider.js`
- Model parse/resolve: `src/sse/services/model.js`, `open-sse/services/model.js`
- Account fallback logic: `open-sse/services/accountFallback.js`
- Translation registry: `open-sse/translator/index.js`
- Stream transformations: `open-sse/utils/stream.js`, `open-sse/utils/streamHandler.js`
- Usage extraction/normalization: `open-sse/utils/usageTracking.js`
- Think tag parser: `open-sse/utils/thinkTagParser.js`
- Embedding handler: `open-sse/handlers/embeddings.js`
- Embedding provider registry: `open-sse/config/embeddingRegistry.js`
- Image generation handler: `open-sse/handlers/imageGeneration.js`
- Image provider registry: `open-sse/config/imageRegistry.js`
- Format detection/provider config: `open-sse/services/provider.ts`
- Model parse/resolve: `src/sse/services/model.ts`, `open-sse/services/model.ts`
- Account fallback logic: `open-sse/services/accountFallback.ts`
- Translation registry: `open-sse/translator/index.ts`
- Stream transformations: `open-sse/utils/stream.ts`, `open-sse/utils/streamHandler.ts`
- Usage extraction/normalization: `open-sse/utils/usageTracking.ts`
- Think tag parser: `open-sse/utils/thinkTagParser.ts`
- Embedding handler: `open-sse/handlers/embeddings.ts`
- Embedding provider registry: `open-sse/config/embeddingRegistry.ts`
- Image generation handler: `open-sse/handlers/imageGeneration.ts`
- Image provider registry: `open-sse/config/imageRegistry.ts`
Services (business logic):
- Account selection/scoring: `open-sse/services/accountSelector.js`
- Context lifecycle management: `open-sse/services/contextManager.js`
- IP filter enforcement: `open-sse/services/ipFilter.js`
- Session tracking: `open-sse/services/sessionManager.js`
- Request deduplication: `open-sse/services/signatureCache.js`
- System prompt injection: `open-sse/services/systemPrompt.js`
- Thinking budget management: `open-sse/services/thinkingBudget.js`
- Wildcard model routing: `open-sse/services/wildcardRouter.js`
- Rate limit management: `open-sse/services/rateLimitManager.js`
- Circuit breaker: `open-sse/services/circuitBreaker.js`
- Account selection/scoring: `open-sse/services/accountSelector.ts`
- Context lifecycle management: `open-sse/services/contextManager.ts`
- IP filter enforcement: `open-sse/services/ipFilter.ts`
- Session tracking: `open-sse/services/sessionManager.ts`
- Request deduplication: `open-sse/services/signatureCache.ts`
- System prompt injection: `open-sse/services/systemPrompt.ts`
- Thinking budget management: `open-sse/services/thinkingBudget.ts`
- Wildcard model routing: `open-sse/services/wildcardRouter.ts`
- Rate limit management: `open-sse/services/rateLimitManager.ts`
- Circuit breaker: `open-sse/services/circuitBreaker.ts`
Domain layer modules:
- Model availability: `src/lib/domain/modelAvailability.js`
- Cost rules/budgets: `src/lib/domain/costRules.js`
- Fallback policy: `src/lib/domain/fallbackPolicy.js`
- Combo resolver: `src/lib/domain/comboResolver.js`
- Lockout policy: `src/lib/domain/lockoutPolicy.js`
- Policy engine: `src/domain/policyEngine.js` — centralized lockout → budget → fallback evaluation
- Error codes catalog: `src/lib/domain/errorCodes.js`
- Request ID: `src/lib/domain/requestId.js`
- Fetch timeout: `src/lib/domain/fetchTimeout.js`
- Request telemetry: `src/lib/domain/requestTelemetry.js`
- Compliance/audit: `src/lib/domain/compliance/index.js`
- Eval runner: `src/lib/domain/evalRunner.js`
- Domain state persistence: `src/lib/db/domainState.js` — SQLite CRUD for fallback chains, budgets, cost history, lockout state, circuit breakers
- Model availability: `src/lib/domain/modelAvailability.ts`
- Cost rules/budgets: `src/lib/domain/costRules.ts`
- Fallback policy: `src/lib/domain/fallbackPolicy.ts`
- Combo resolver: `src/lib/domain/comboResolver.ts`
- Lockout policy: `src/lib/domain/lockoutPolicy.ts`
- Policy engine: `src/domain/policyEngine.ts` — centralized lockout → budget → fallback evaluation
- Error codes catalog: `src/lib/domain/errorCodes.ts`
- Request ID: `src/lib/domain/requestId.ts`
- Fetch timeout: `src/lib/domain/fetchTimeout.ts`
- Request telemetry: `src/lib/domain/requestTelemetry.ts`
- Compliance/audit: `src/lib/domain/compliance/index.ts`
- Eval runner: `src/lib/domain/evalRunner.ts`
- Domain state persistence: `src/lib/db/domainState.ts` — SQLite CRUD for fallback chains, budgets, cost history, lockout state, circuit breakers
OAuth provider modules (12 individual files under `src/lib/oauth/providers/`):
- Registry index: `src/lib/oauth/providers/index.js`
- Individual providers: `claude.js`, `codex.js`, `gemini.js`, `antigravity.js`, `iflow.js`, `qwen.js`, `kimi-coding.js`, `github.js`, `kiro.js`, `cursor.js`, `kilocode.js`, `cline.js`
- Thin wrapper: `src/lib/oauth/providers.js` — re-exports from individual modules
- Registry index: `src/lib/oauth/providers/index.ts`
- Individual providers: `claude.ts`, `codex.ts`, `gemini.ts`, `antigravity.ts`, `iflow.ts`, `qwen.ts`, `kimi-coding.ts`, `github.ts`, `kiro.ts`, `cursor.ts`, `kilocode.ts`, `cline.ts`
- Thin wrapper: `src/lib/oauth/providers.ts` — re-exports from individual modules
## 3) Persistence Layer
Primary state DB:
- `src/lib/localDb.js`
- `src/lib/localDb.ts`
- file: `${DATA_DIR}/db.json` (or `$XDG_CONFIG_HOME/omniroute/db.json` when set, else `~/.omniroute/db.json`)
- entities: providerConnections, providerNodes, modelAliases, combos, apiKeys, settings, pricing, **customModels**, **proxyConfig**, **ipFilter**, **thinkingBudget**, **systemPrompt**
Usage DB:
- `src/lib/usageDb.js`
- `src/lib/usageDb.ts`
- files: `${DATA_DIR}/usage.json`, `${DATA_DIR}/log.txt`, `${DATA_DIR}/call_logs/`
- follows same base directory policy as `localDb` (`DATA_DIR`, then `XDG_CONFIG_HOME/omniroute` when set)
- decomposed into focused sub-modules: `migrations.js`, `usageHistory.js`, `costCalculator.js`, `usageStats.js`, `callLogs.js`
- decomposed into focused sub-modules: `migrations.ts`, `usageHistory.ts`, `costCalculator.ts`, `usageStats.ts`, `callLogs.ts`
Domain State DB (SQLite):
- `src/lib/db/domainState.js` — CRUD operations for domain state
- Tables (created in `src/lib/db/core.js`): `domain_fallback_chains`, `domain_budgets`, `domain_cost_history`, `domain_lockout_state`, `domain_circuit_breakers`
- `src/lib/db/domainState.ts` — CRUD operations for domain state
- Tables (created in `src/lib/db/core.ts`): `domain_fallback_chains`, `domain_budgets`, `domain_cost_history`, `domain_lockout_state`, `domain_circuit_breakers`
- Write-through cache pattern: in-memory Maps are authoritative at runtime; mutations are written synchronously to SQLite; state is restored from DB on cold start
## 4) Auth + Security Surfaces
- Dashboard cookie auth: `src/proxy.js`, `src/app/api/auth/login/route.js`
- API key generation/verification: `src/shared/utils/apiKey.js`
- Dashboard cookie auth: `src/proxy.ts`, `src/app/api/auth/login/route.ts`
- API key generation/verification: `src/shared/utils/apiKey.ts`
- Provider secrets persisted in `providerConnections` entries
- Outbound proxy support via `open-sse/utils/proxyFetch.js` (env vars) and `open-sse/utils/networkProxy.js` (configurable per-provider or global)
- Outbound proxy support via `open-sse/utils/proxyFetch.ts` (env vars) and `open-sse/utils/networkProxy.ts` (configurable per-provider or global)
## 5) Cloud Sync
- Scheduler init: `src/lib/initCloudSync.js`, `src/shared/services/initializeCloudSync.js`
- Periodic task: `src/shared/services/cloudSyncScheduler.js`
- Control route: `src/app/api/sync/cloud/route.js`
- Scheduler init: `src/lib/initCloudSync.ts`, `src/shared/services/initializeCloudSync.ts`
- Periodic task: `src/shared/services/cloudSyncScheduler.ts`
- Control route: `src/app/api/sync/cloud/route.ts`
## Request Lifecycle (`/v1/chat/completions`)
@@ -327,7 +327,7 @@ flowchart TD
Q -- No --> R[Return all unavailable]
```
Fallback decisions are driven by `open-sse/services/accountFallback.js` using status codes and error-message heuristics.
Fallback decisions are driven by `open-sse/services/accountFallback.ts` using status codes and error-message heuristics.
## OAuth Onboarding and Token Refresh Lifecycle
@@ -359,7 +359,7 @@ sequenceDiagram
Test-->>UI: validation result
```
Refresh during live traffic is executed inside `open-sse/handlers/chatCore.js` via executor `refreshCredentials()`.
Refresh during live traffic is executed inside `open-sse/handlers/chatCore.ts` via executor `refreshCredentials()`.
## Cloud Sync Lifecycle (Enable / Sync / Disable)
@@ -408,6 +408,9 @@ erDiagram
number stickyRoundRobinLimit
boolean requireLogin
string password_hash
string fallbackStrategy
json rateLimitDefaults
json providerProfiles
}
PROVIDER_CONNECTION {
@@ -559,25 +562,25 @@ flowchart LR
### Routing and Execution Core
- `src/sse/handlers/chat.js`: request parse, combo handling, account selection loop
- `open-sse/handlers/chatCore.js`: translation, executor dispatch, retry/refresh handling, stream setup
- `src/sse/handlers/chat.ts`: request parse, combo handling, account selection loop
- `open-sse/handlers/chatCore.ts`: translation, executor dispatch, retry/refresh handling, stream setup
- `open-sse/executors/*`: provider-specific network and format behavior
### Translation Registry and Format Converters
- `open-sse/translator/index.js`: translator registry and orchestration
- `open-sse/translator/index.ts`: translator registry and orchestration
- Request translators: `open-sse/translator/request/*`
- Response translators: `open-sse/translator/response/*`
- Format constants: `open-sse/translator/formats.js`
- Format constants: `open-sse/translator/formats.ts`
### Persistence
- `src/lib/localDb.js`: persistent config/state
- `src/lib/usageDb.js`: usage history and rolling request logs
- `src/lib/localDb.ts`: persistent config/state
- `src/lib/usageDb.ts`: usage history and rolling request logs
## Provider Executor Coverage (Strategy Pattern)
Each provider has a specialized executor extending `BaseExecutor` (in `open-sse/executors/base.js`), which provides URL building, header construction, retry with exponential backoff, credential refresh hooks, and the `execute()` orchestration method.
Each provider has a specialized executor extending `BaseExecutor` (in `open-sse/executors/base.ts`), which provides URL building, header construction, retry with exponential backoff, credential refresh hooks, and the `execute()` orchestration method.
| Executor | Provider(s) | Special Handling |
| --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------- |
@@ -648,12 +651,12 @@ Translations are selected dynamically based on source payload shape and provider
| Endpoint | Format | Handler |
| -------------------------------------------------- | ------------------ | ---------------------------------------------------- |
| `POST /v1/chat/completions` | OpenAI Chat | `src/sse/handlers/chat.js` |
| `POST /v1/chat/completions` | OpenAI Chat | `src/sse/handlers/chat.ts` |
| `POST /v1/messages` | Claude Messages | Same handler (auto-detected) |
| `POST /v1/responses` | OpenAI Responses | `open-sse/handlers/responsesHandler.js` |
| `POST /v1/embeddings` | OpenAI Embeddings | `open-sse/handlers/embeddings.js` |
| `POST /v1/responses` | OpenAI Responses | `open-sse/handlers/responsesHandler.ts` |
| `POST /v1/embeddings` | OpenAI Embeddings | `open-sse/handlers/embeddings.ts` |
| `GET /v1/embeddings` | Model listing | API route |
| `POST /v1/images/generations` | OpenAI Images | `open-sse/handlers/imageGeneration.js` |
| `POST /v1/images/generations` | OpenAI Images | `open-sse/handlers/imageGeneration.ts` |
| `GET /v1/images/generations` | Model listing | API route |
| `POST /v1/providers/{provider}/chat/completions` | OpenAI Chat | Dedicated per-provider with model validation |
| `POST /v1/providers/{provider}/embeddings` | OpenAI Embeddings | Dedicated per-provider with model validation |
@@ -668,11 +671,11 @@ Translations are selected dynamically based on source payload shape and provider
## Bypass Handler
The bypass handler (`open-sse/utils/bypassHandler.js`) intercepts known "throwaway" requests from Claude CLI — warmup pings, title extractions, and token counts — and returns a **fake response** without consuming upstream provider tokens. This is triggered only when `User-Agent` contains `claude-cli`.
The bypass handler (`open-sse/utils/bypassHandler.ts`) intercepts known "throwaway" requests from Claude CLI — warmup pings, title extractions, and token counts — and returns a **fake response** without consuming upstream provider tokens. This is triggered only when `User-Agent` contains `claude-cli`.
## Request Logger Pipeline
The request logger (`open-sse/utils/requestLogger.js`) provides a 7-stage debug logging pipeline, disabled by default, enabled via `ENABLE_REQUEST_LOGS=true`:
The request logger (`open-sse/utils/requestLogger.ts`) provides a 7-stage debug logging pipeline, disabled by default, enabled via `ENABLE_REQUEST_LOGS=true`:
```
1_req_client.json → 2_req_source.json → 3_req_openai.json → 4_req_target.json
@@ -714,7 +717,7 @@ Files are written to `<repo>/logs/<session>/` for each request session.
Runtime visibility sources:
- console logs from `src/sse/utils/logger.js`
- console logs from `src/sse/utils/logger.ts`
- per-request usage aggregates in `usage.json`
- textual request status log in `log.txt`
- optional deep request/translation logs under `logs/` when `ENABLE_REQUEST_LOGS=true`
@@ -746,12 +749,13 @@ Environment variables actively used by code:
## Known Architectural Notes
1. `usageDb` and `localDb` now share the same base directory policy (`DATA_DIR` -> `XDG_CONFIG_HOME/omniroute` -> `~/.omniroute`) with legacy file migration.
2. `/api/v1/route.js` returns a static model list and is not the main models source used by `/v1/models`.
2. `/api/v1/route.ts` returns a static model list and is not the main models source used by `/v1/models`.
3. Request logger writes full headers/body when enabled; treat log directory as sensitive.
4. Cloud behavior depends on correct `NEXT_PUBLIC_BASE_URL` and cloud endpoint reachability.
5. The `open-sse/` directory is published as the `@omniroute/open-sse` **npm workspace package**. Source code imports it via `@omniroute/open-sse/...` (resolved by Next.js `transpilePackages`). File paths in this document still use the directory name `open-sse/` for consistency.
6. Charts in the dashboard use **Recharts** (SVG-based) for accessible, interactive visualizations (bar charts, donut charts).
7. E2E tests use **Playwright** (`tests/e2e/`), run via `npm run test:e2e`. Unit tests use **Node.js test runner** (`tests/unit/`), run via `npm run test:plan3`.
6. Charts in the dashboard use **Recharts** (SVG-based) for accessible, interactive analytics visualizations (model usage bar charts, provider breakdown tables with success rates).
7. E2E tests use **Playwright** (`tests/e2e/`), run via `npm run test:e2e`. Unit tests use **Node.js test runner** (`tests/unit/`), run via `npm run test:plan3`. Source code under `src/` is **TypeScript** (`.ts`/`.tsx`); the `open-sse/` workspace remains JavaScript (`.js`).
8. Settings page is organized into 5 tabs: Security, Routing (6 global strategies: fill-first, round-robin, p2c, random, least-used, cost-optimized), Resilience (editable rate limits, circuit breaker, policies), AI (thinking budget, system prompt, prompt cache), Advanced (proxy).
## Operational Verification Checklist
+46 -46
View File
@@ -110,18 +110,18 @@ The **single source of truth** for all provider configuration.
| File | Purpose |
| ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `constants.js` | `PROVIDERS` object with base URLs, OAuth credentials (defaults), headers, and default system prompts for every provider. Also defines `HTTP_STATUS`, `ERROR_TYPES`, `COOLDOWN_MS`, `BACKOFF_CONFIG`, and `SKIP_PATTERNS`. |
| `credentialLoader.js` | Loads external credentials from `data/provider-credentials.json` and merges them over the hardcoded defaults in `PROVIDERS`. Keeps secrets out of source control while maintaining backwards compatibility. |
| `providerModels.js` | Central model registry: maps provider aliases → model IDs. Functions like `getModels()`, `getProviderByAlias()`. |
| `codexInstructions.js` | System instructions injected into Codex requests (editing constraints, sandbox rules, approval policies). |
| `defaultThinkingSignature.js` | Default "thinking" signatures for Claude and Gemini models. |
| `ollamaModels.js` | Schema definition for local Ollama models (name, size, family, quantization). |
| `constants.ts` | `PROVIDERS` object with base URLs, OAuth credentials (defaults), headers, and default system prompts for every provider. Also defines `HTTP_STATUS`, `ERROR_TYPES`, `COOLDOWN_MS`, `BACKOFF_CONFIG`, and `SKIP_PATTERNS`. |
| `credentialLoader.ts` | Loads external credentials from `data/provider-credentials.json` and merges them over the hardcoded defaults in `PROVIDERS`. Keeps secrets out of source control while maintaining backwards compatibility. |
| `providerModels.ts` | Central model registry: maps provider aliases → model IDs. Functions like `getModels()`, `getProviderByAlias()`. |
| `codexInstructions.ts` | System instructions injected into Codex requests (editing constraints, sandbox rules, approval policies). |
| `defaultThinkingSignature.ts` | Default "thinking" signatures for Claude and Gemini models. |
| `ollamaModels.ts` | Schema definition for local Ollama models (name, size, family, quantization). |
#### Credential Loading Flow
```mermaid
flowchart TD
A["App starts"] --> B["constants.js defines PROVIDERS\nwith hardcoded defaults"]
A["App starts"] --> B["constants.ts defines PROVIDERS\nwith hardcoded defaults"]
B --> C{"data/provider-credentials.json\nexists?"}
C -->|Yes| D["credentialLoader reads JSON"]
C -->|No| E["Use hardcoded defaults"]
@@ -194,15 +194,15 @@ classDiagram
| Executor | Provider | Key Specializations |
| ---------------- | ------------------------------------------ | ------------------------------------------------------------------------------------------------------------------- |
| `base.js` | — | Abstract base: URL building, headers, retry logic, credential refresh |
| `default.js` | Claude, Gemini, OpenAI, GLM, Kimi, MiniMax | Generic OAuth token refresh for standard providers |
| `antigravity.js` | Google Cloud Code | Project/session ID generation, multi-URL fallback, custom retry parsing from error messages ("reset after 2h7m23s") |
| `cursor.js` | Cursor IDE | **Most complex**: SHA-256 checksum auth, Protobuf request encoding, binary EventStream → SSE response parsing |
| `codex.js` | OpenAI Codex | Injects system instructions, manages thinking levels, removes unsupported parameters |
| `gemini-cli.js` | Google Gemini CLI | Custom URL building (`streamGenerateContent`), Google OAuth token refresh |
| `github.js` | GitHub Copilot | Dual token system (GitHub OAuth + Copilot token), VSCode header mimicking |
| `kiro.js` | AWS CodeWhisperer | AWS EventStream binary parsing, AMZN event frames, token estimation |
| `index.js` | — | Factory: maps provider name → executor class, with default fallback |
| `base.ts` | — | Abstract base: URL building, headers, retry logic, credential refresh |
| `default.ts` | Claude, Gemini, OpenAI, GLM, Kimi, MiniMax | Generic OAuth token refresh for standard providers |
| `antigravity.ts` | Google Cloud Code | Project/session ID generation, multi-URL fallback, custom retry parsing from error messages ("reset after 2h7m23s") |
| `cursor.ts` | Cursor IDE | **Most complex**: SHA-256 checksum auth, Protobuf request encoding, binary EventStream → SSE response parsing |
| `codex.ts` | OpenAI Codex | Injects system instructions, manages thinking levels, removes unsupported parameters |
| `gemini-cli.ts` | Google Gemini CLI | Custom URL building (`streamGenerateContent`), Google OAuth token refresh |
| `github.ts` | GitHub Copilot | Dual token system (GitHub OAuth + Copilot token), VSCode header mimicking |
| `kiro.ts` | AWS CodeWhisperer | AWS EventStream binary parsing, AMZN event frames, token estimation |
| `index.ts` | — | Factory: maps provider name → executor class, with default fallback |
---
@@ -212,12 +212,12 @@ The **orchestration layer** — coordinates translation, execution, streaming, a
| File | Purpose |
| --------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `chatCore.js` | **Central orchestrator** (~600 lines). Handles the complete request lifecycle: format detection → translation → executor dispatch → streaming/non-streaming response → token refresh → error handling → usage logging. |
| `responsesHandler.js` | Adapter for OpenAI's Responses API: converts Responses format → Chat Completions → sends to `chatCore` → converts SSE back to Responses format. |
| `embeddings.js` | Embedding generation handler: resolves embedding model → provider, dispatches to provider API, returns OpenAI-compatible embedding response. Supports 6+ providers. |
| `imageGeneration.js` | Image generation handler: resolves image model → provider, supports OpenAI-compatible, Gemini-image (Antigravity), and fallback (Nebius) modes. Returns base64 or URL images. |
| `chatCore.ts` | **Central orchestrator** (~600 lines). Handles the complete request lifecycle: format detection → translation → executor dispatch → streaming/non-streaming response → token refresh → error handling → usage logging. |
| `responsesHandler.ts` | Adapter for OpenAI's Responses API: converts Responses format → Chat Completions → sends to `chatCore` → converts SSE back to Responses format. |
| `embeddings.ts` | Embedding generation handler: resolves embedding model → provider, dispatches to provider API, returns OpenAI-compatible embedding response. Supports 6+ providers. |
| `imageGeneration.ts` | Image generation handler: resolves image model → provider, supports OpenAI-compatible, Gemini-image (Antigravity), and fallback (Nebius) modes. Returns base64 or URL images. |
#### Request Lifecycle (chatCore.js)
#### Request Lifecycle (chatCore.ts)
```mermaid
sequenceDiagram
@@ -262,20 +262,20 @@ Business logic that supports the handlers and executors.
| File | Purpose |
| -------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `provider.js` | **Format detection** (`detectFormat`): analyzes request body structure to identify Claude/OpenAI/Gemini/Antigravity/Responses formats (includes `max_tokens` heuristic for Claude). Also: URL building, header building, thinking config normalization. Supports `openai-compatible-*` and `anthropic-compatible-*` dynamic providers. |
| `model.js` | Model string parsing (`claude/model-name``{provider: "claude", model: "model-name"}`), alias resolution with collision detection, input sanitization (rejects path traversal/control chars), and model info resolution with async alias getter support. |
| `accountFallback.js` | Rate-limit handling: exponential backoff (1s → 2s → 4s → max 2min), account cooldown management, error classification (which errors trigger fallback vs. not). |
| `tokenRefresh.js` | OAuth token refresh for **every provider**: Google (Gemini, Antigravity), Claude, Codex, Qwen, iFlow, GitHub (OAuth + Copilot dual-token), Kiro (AWS SSO OIDC + Social Auth). Includes in-flight promise deduplication cache and retry with exponential backoff. |
| `combo.js` | **Combo models**: chains of fallback models. If model A fails with a fallback-eligible error, try model B, then C, etc. Returns actual upstream status codes. |
| `usage.js` | Fetches quota/usage data from provider APIs (GitHub Copilot quotas, Antigravity model quotas, Codex rate limits, Kiro usage breakdowns, Claude settings). |
| `accountSelector.js` | Smart account selection with scoring algorithm: considers priority, health status, round-robin position, and cooldown state to pick the optimal account for each request. |
| `contextManager.js` | Request context lifecycle management: creates and tracks per-request context objects with metadata (request ID, timestamps, provider info) for debugging and logging. |
| `ipFilter.js` | IP-based access control: supports allowlist and blocklist modes. Validates client IP against configured rules before processing API requests. |
| `sessionManager.js` | Session tracking with client fingerprinting: tracks active sessions using hashed client identifiers, monitors request counts, and provides session metrics. |
| `signatureCache.js` | Request signature-based deduplication cache: prevents duplicate requests by caching recent request signatures and returning cached responses for identical requests within a time window. |
| `systemPrompt.js` | Global system prompt injection: prepends or appends a configurable system prompt to all requests, with per-provider compatibility handling. |
| `thinkingBudget.js` | Reasoning token budget management: supports passthrough, auto (strip thinking config), custom (fixed budget), and adaptive (complexity-scaled) modes for controlling thinking/reasoning tokens. |
| `wildcardRouter.js` | Wildcard model pattern routing: resolves wildcard patterns (e.g., `*/claude-*`) to concrete provider/model pairs based on availability and priority. |
| `provider.ts` | **Format detection** (`detectFormat`): analyzes request body structure to identify Claude/OpenAI/Gemini/Antigravity/Responses formats (includes `max_tokens` heuristic for Claude). Also: URL building, header building, thinking config normalization. Supports `openai-compatible-*` and `anthropic-compatible-*` dynamic providers. |
| `model.ts` | Model string parsing (`claude/model-name``{provider: "claude", model: "model-name"}`), alias resolution with collision detection, input sanitization (rejects path traversal/control chars), and model info resolution with async alias getter support. |
| `accountFallback.ts` | Rate-limit handling: exponential backoff (1s → 2s → 4s → max 2min), account cooldown management, error classification (which errors trigger fallback vs. not). |
| `tokenRefresh.ts` | OAuth token refresh for **every provider**: Google (Gemini, Antigravity), Claude, Codex, Qwen, iFlow, GitHub (OAuth + Copilot dual-token), Kiro (AWS SSO OIDC + Social Auth). Includes in-flight promise deduplication cache and retry with exponential backoff. |
| `combo.ts` | **Combo models**: chains of fallback models. If model A fails with a fallback-eligible error, try model B, then C, etc. Returns actual upstream status codes. |
| `usage.ts` | Fetches quota/usage data from provider APIs (GitHub Copilot quotas, Antigravity model quotas, Codex rate limits, Kiro usage breakdowns, Claude settings). |
| `accountSelector.ts` | Smart account selection with scoring algorithm: considers priority, health status, round-robin position, and cooldown state to pick the optimal account for each request. |
| `contextManager.ts` | Request context lifecycle management: creates and tracks per-request context objects with metadata (request ID, timestamps, provider info) for debugging and logging. |
| `ipFilter.ts` | IP-based access control: supports allowlist and blocklist modes. Validates client IP against configured rules before processing API requests. |
| `sessionManager.ts` | Session tracking with client fingerprinting: tracks active sessions using hashed client identifiers, monitors request counts, and provides session metrics. |
| `signatureCache.ts` | Request signature-based deduplication cache: prevents duplicate requests by caching recent request signatures and returning cached responses for identical requests within a time window. |
| `systemPrompt.ts` | Global system prompt injection: prepends or appends a configurable system prompt to all requests, with per-provider compatibility handling. |
| `thinkingBudget.ts` | Reasoning token budget management: supports passthrough, auto (strip thinking config), custom (fixed budget), and adaptive (complexity-scaled) modes for controlling thinking/reasoning tokens. |
| `wildcardRouter.ts` | Wildcard model pattern routing: resolves wildcard patterns (e.g., `*/claude-*`) to concrete provider/model pairs based on availability and priority. |
#### Token Refresh Deduplication
@@ -377,8 +377,8 @@ graph TD
| `request/` | 8 translators | Convert request bodies between formats. Each file self-registers via `register(from, to, fn)` on import. |
| `response/` | 7 translators | Convert streaming response chunks between formats. Handles SSE event types, thinking blocks, tool calls. |
| `helpers/` | 6 helpers | Shared utilities: `claudeHelper` (system prompt extraction, thinking config), `geminiHelper` (parts/contents mapping), `openaiHelper` (format filtering), `toolCallHelper` (ID generation, missing response injection), `maxTokensHelper`, `responsesApiHelper`. |
| `index.js` | — | Translation engine: `translateRequest()`, `translateResponse()`, state management, registry. |
| `formats.js` | — | Format constants: `OPENAI`, `CLAUDE`, `GEMINI`, `ANTIGRAVITY`, `KIRO`, `CURSOR`, `OPENAI_RESPONSES`. |
| `index.ts` | — | Translation engine: `translateRequest()`, `translateResponse()`, state management, registry. |
| `formats.ts` | — | Format constants: `OPENAI`, `CLAUDE`, `GEMINI`, `ANTIGRAVITY`, `KIRO`, `CURSOR`, `OPENAI_RESPONSES`. |
#### Key Design: Self-Registering Plugins
@@ -397,13 +397,13 @@ import "./request/claude-to-openai.js"; // ← self-registers
| File | Purpose |
| ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `error.js` | Error response building (OpenAI-compatible format), upstream error parsing, Antigravity retry-time extraction from error messages, SSE error streaming. |
| `stream.js` | **SSE Transform Stream** — the core streaming pipeline. Two modes: `TRANSLATE` (full format translation) and `PASSTHROUGH` (normalize + extract usage). Handles chunk buffering, usage estimation, content length tracking. Per-stream encoder/decoder instances avoid shared state. |
| `streamHelpers.js` | Low-level SSE utilities: `parseSSELine` (whitespace-tolerant), `hasValuableContent` (filters empty chunks for OpenAI/Claude/Gemini), `fixInvalidId`, `formatSSE` (format-aware SSE serialization with `perf_metrics` cleanup). |
| `usageTracking.js` | Token usage extraction from any format (Claude/OpenAI/Gemini/Responses), estimation with separate tool/message char-per-token ratios, buffer addition (2000 tokens safety margin), format-specific field filtering, console logging with ANSI colors. |
| `requestLogger.js` | File-based request logging (opt-in via `ENABLE_REQUEST_LOGS=true`). Creates session folders with numbered files: `1_req_client.json``7_res_client.txt`. All I/O is async (fire-and-forget). Masks sensitive headers. |
| `bypassHandler.js` | Intercepts specific patterns from Claude CLI (title extraction, warmup, count) and returns fake responses without calling any provider. Supports both streaming and non-streaming. Intentionally limited to Claude CLI scope. |
| `networkProxy.js` | Resolves outbound proxy URL for a given provider with precedence: provider-specific config → global config → environment variables (`HTTPS_PROXY`/`HTTP_PROXY`/`ALL_PROXY`). Supports `NO_PROXY` exclusions. Caches config for 30s. |
| `error.ts` | Error response building (OpenAI-compatible format), upstream error parsing, Antigravity retry-time extraction from error messages, SSE error streaming. |
| `stream.ts` | **SSE Transform Stream** — the core streaming pipeline. Two modes: `TRANSLATE` (full format translation) and `PASSTHROUGH` (normalize + extract usage). Handles chunk buffering, usage estimation, content length tracking. Per-stream encoder/decoder instances avoid shared state. |
| `streamHelpers.ts` | Low-level SSE utilities: `parseSSELine` (whitespace-tolerant), `hasValuableContent` (filters empty chunks for OpenAI/Claude/Gemini), `fixInvalidId`, `formatSSE` (format-aware SSE serialization with `perf_metrics` cleanup). |
| `usageTracking.ts` | Token usage extraction from any format (Claude/OpenAI/Gemini/Responses), estimation with separate tool/message char-per-token ratios, buffer addition (2000 tokens safety margin), format-specific field filtering, console logging with ANSI colors. |
| `requestLogger.ts` | File-based request logging (opt-in via `ENABLE_REQUEST_LOGS=true`). Creates session folders with numbered files: `1_req_client.json``7_res_client.txt`. All I/O is async (fire-and-forget). Masks sensitive headers. |
| `bypassHandler.ts` | Intercepts specific patterns from Claude CLI (title extraction, warmup, count) and returns fake responses without calling any provider. Supports both streaming and non-streaming. Intentionally limited to Claude CLI scope. |
| `networkProxy.ts` | Resolves outbound proxy URL for a given provider with precedence: provider-specific config → global config → environment variables (`HTTPS_PROXY`/`HTTP_PROXY`/`ALL_PROXY`). Supports `NO_PROXY` exclusions. Caches config for 30s. |
#### SSE Streaming Pipeline
@@ -450,7 +450,7 @@ logs/
| Directory | Purpose |
| ------------- | ---------------------------------------------------------------------- |
| `src/app/` | Web UI, API routes, Express middleware, OAuth callback handlers |
| `src/lib/` | Database access (`localDb.js`, `usageDb.js`), authentication, shared |
| `src/lib/` | Database access (`localDb.ts`, `usageDb.ts`), authentication, shared |
| `src/mitm/` | Man-in-the-middle proxy utilities for intercepting provider traffic |
| `src/models/` | Database model definitions |
| `src/shared/` | Wrappers around open-sse functions (provider, stream, error, etc.) |
@@ -484,7 +484,7 @@ All formats translate through **OpenAI format as the hub**. Adding a new provide
### 5.2 Executor Strategy Pattern
Each provider has a dedicated executor class inheriting from `BaseExecutor`. The factory in `executors/index.js` selects the right one at runtime.
Each provider has a dedicated executor class inheriting from `BaseExecutor`. The factory in `executors/index.ts` selects the right one at runtime.
### 5.3 Self-Registering Plugin System
+56 -35
View File
@@ -8,24 +8,24 @@
### Backend Core
- [ ] `constants.js` — Substituir `COOLDOWN_MS.transient` por `transientInitial` (5s) + `transientMax` (60s)
- [ ] `constants.js` — Adicionar `PROVIDER_PROFILES` (oauth / apikey) com cooldowns diferenciados
- [ ] `constants.js` — Adicionar `DEFAULT_API_LIMITS` (100 RPM, 200ms minTime)
- [ ] `providerRegistry.js` — Criar helper `getProviderCategory(providerId)``"oauth"` | `"apikey"`
- [ ] `accountFallback.js` — Aceitar `provider` como parâmetro em `checkFallbackError`
- [ ] `accountFallback.js` — Implementar backoff exponencial para 502/503/504 transientes
- [ ] `accountFallback.js` — Calcular cooldown baseado no perfil do provedor
- [ ] `accountFallback.js` — Adicionar helper `getProviderProfile(provider)`
- [x] `constants.ts` — Substituir `COOLDOWN_MS.transient` por `transientInitial` (5s) + `transientMax` (60s)
- [x] `constants.ts` — Adicionar `PROVIDER_PROFILES` (oauth / apikey) com cooldowns diferenciados
- [x] `constants.ts` — Adicionar `DEFAULT_API_LIMITS` (100 RPM, 200ms minTime)
- [x] `providerRegistry.ts` — Criar helper `getProviderCategory(providerId)``"oauth"` | `"apikey"`
- [x] `accountFallback.ts` — Aceitar `provider` como parâmetro em `checkFallbackError`
- [x] `accountFallback.ts` — Implementar backoff exponencial para 502/503/504 transientes
- [x] `accountFallback.ts` — Calcular cooldown baseado no perfil do provedor
- [x] `accountFallback.ts` — Adicionar helper `getProviderProfile(provider)`
### Callers (propagar `provider`)
- [ ] `auth.js``markAccountUnavailable` — Passar `provider` para `checkFallbackError`
- [ ] `combo.js``handleComboChat` / `handleRoundRobinCombo` — Passar `provider` nos erros
- [x] `auth.ts``markAccountUnavailable` — Passar `provider` para `checkFallbackError`
- [x] `combo.ts``handleComboChat` / `handleRoundRobinCombo` — Passar `provider` nos erros
### Testes
- [ ] Atualizar `rate-limit-enhanced.test.mjs` — Teste "transient errors don't increase backoff" → `newBackoffLevel = 1`
- [ ] Criar `error-classification.test.mjs` — Cooldown exponencial 502, perfis OAuth/API, helper `getProviderCategory`
- [x] Atualizar `rate-limit-enhanced.test.mjs` — Teste "transient errors don't increase backoff" → `newBackoffLevel = 1`
- [x] Criar `error-classification.test.mjs` — Cooldown exponencial 502, perfis OAuth/API, helper `getProviderCategory`
---
@@ -33,15 +33,15 @@
### Backend
- [ ] `combo.js` — Importar `getCircuitBreaker` e `CircuitBreakerOpenError`
- [ ] `combo.js``handleComboChat` — Verificar `breaker.canExecute()` antes de cada modelo
- [ ] `combo.js``handleRoundRobinCombo` — Integrar breaker per-model
- [ ] `combo.js` — Marcar `semaphore.markRateLimited` para 502/503/504 (não só 429)
- [ ] `combo.js` — Implementar early exit quando todos os modelos têm breaker OPEN
- [x] `combo.ts` — Importar `getCircuitBreaker` e `CircuitBreakerOpenError`
- [x] `combo.ts``handleComboChat` — Verificar `breaker.canExecute()` antes de cada modelo
- [x] `combo.ts``handleRoundRobinCombo` — Integrar breaker per-model
- [x] `combo.ts` — Marcar `semaphore.markRateLimited` para 502/503/504 (não só 429)
- [x] `combo.ts` — Implementar early exit quando todos os modelos têm breaker OPEN
### Testes
- [ ] Criar `combo-circuit-breaker.test.mjs` — Combo skip breaker OPEN, early exit, semáforo 502
- [x] Criar `combo-circuit-breaker.test.mjs` — Combo skip breaker OPEN, early exit, semáforo 502
---
@@ -49,13 +49,13 @@
### Backend
- [ ] `rateLimitManager.js` — Auto-enable para `apikey` providers com limites elevados
- [ ] `rateLimitManager.js` — Criar limiter com defaults (100 RPM) quando não configurado
- [ ] `auth.js` — Adicionar mutex na `markAccountUnavailable` para evitar marcação paralela
- [x] `rateLimitManager.ts` — Auto-enable para `apikey` providers com limites elevados
- [x] `rateLimitManager.ts` — Criar limiter com defaults (100 RPM) quando não configurado
- [x] `auth.ts` — Adicionar mutex na `markAccountUnavailable` para evitar marcação paralela
### Testes
- [ ] Criar `thundering-herd.test.mjs` — Mutex, auto-enable, limites não restritivos
- [x] Criar `thundering-herd.test.mjs` — Mutex, auto-enable, limites não restritivos
---
@@ -63,30 +63,51 @@
### Settings Page
- [ ] `settings/page.js` — Adicionar tab "Resilience" (icon: `health_and_safety`) entre Routing e Pricing
- [x] `settings/page.tsx` — Adicionar tab "Resilience" (icon: `health_and_safety`) entre Routing e Pricing
### Novos Componentes
- [ ] Criar `ResilienceTab.js` — Layout com 3 cards
- [ ] Criar `ProviderProfilesCard.js` — Toggle OAuth/API Key, inputs para cooldowns
- [ ] Criar `CircuitBreakerCard.js` — Status real-time per-provider, auto-refresh 5s, botão reset
- [ ] Criar `RateLimitOverviewCard.js` — Tabela providers × accounts × cooldown
- [x] Criar `ResilienceTab.tsx` — Layout com 4 cards (Provider Profiles → Rate Limiting → Circuit Breakers → Policies)
- [x] Criar `ProviderProfilesCard.tsx` — Toggle OAuth/API Key, inputs para cooldowns
- [x] Criar `CircuitBreakerCard.tsx` — Status real-time per-provider, auto-refresh 5s, botão reset
- [x] Criar `RateLimitOverviewCard.tsx` — Tabela providers × accounts × cooldown**agora editável com RPM, Min Gap, Max Concurrent**
### API Routes
- [ ] Criar `api/resilience/route.js` — GET (estado completo) + PATCH (salvar perfis)
- [ ] Criar `api/resilience/reset/route.js` — POST (resetar breakers + cooldowns)
- [x] Criar `api/resilience/route.ts` — GET (estado completo + defaults mesclados) + PATCH (salvar perfis + defaults)
- [x] Criar `api/resilience/reset/route.ts` — POST (resetar breakers + cooldowns)
### Migração
- [ ] Avaliar se `PoliciesPanel.js` pode ser removido ou simplificado após nova aba
- [x] `PoliciesPanel.tsx` movido de Security para Resilience tab
---
## Fase 5 — Settings Page Restructure (v0.9.0)
### Tab Reorganization
- [x] **Security** — Simplificado para Login/Password + IP Access Control
- [x] **Routing** — Expandido para 6 estratégias globais com descrições
- [x] **Resilience** — Reordenado: Provider Profiles → Rate Limiting (editável) → Circuit Breakers → Policies
- [x] **AI** — Thinking Budget + System Prompt + Prompt Cache (movido do Advanced)
- [x] **Advanced** — Simplificado para apenas Global Proxy
### Backend Routing Strategies
- [x] `auth.ts` — Implementar `random` (Fisher-Yates shuffle)
- [x] `auth.ts` — Implementar `least-used` (sorted by lastUsedAt)
- [x] `auth.ts` — Implementar `cost-optimized` (sorted by priority)
- [x] `auth.ts` — Corrigir `p2c` (power-of-two-choices com health scoring)
- [x] `settings.ts` — Expandir tipo `fallbackStrategy` para 6 valores
---
## Verificação Final
- [ ] Rodar todos os testes unitários: `node --test tests/unit/*.test.mjs`
- [ ] Build do Next.js: `npm run build`
- [ ] Verificar aba Resilience no browser
- [ ] Testar persistência dos perfis (salvar → reload)
- [ ] Testar Reset All Breakers
- [x] Rodar todos os testes unitários: `node --test tests/unit/*.test.mjs`
- [x] Build do Next.js: `npm run build`
- [x] Verificar aba Resilience no browser
- [x] Testar persistência dos perfis (salvar → reload)
- [x] Testar Reset All Breakers
- [x] Verificar todas as 5 tabs reestruturadas
+211
View File
@@ -0,0 +1,211 @@
# Troubleshooting
Common problems and solutions for OmniRoute.
---
## Quick Fixes
| Problem | Solution |
| ----------------------------- | ------------------------------------------------------------------ |
| First login not working | Check `INITIAL_PASSWORD` in `.env` (default: `123456`) |
| Dashboard opens on wrong port | Set `PORT=20128` and `NEXT_PUBLIC_BASE_URL=http://localhost:20128` |
| No request logs under `logs/` | Set `ENABLE_REQUEST_LOGS=true` |
---
## Provider Issues
### "Language model did not provide messages"
**Cause:** Provider quota exhausted.
**Fix:**
1. Check dashboard quota tracker
2. Use a combo with fallback tiers
3. Switch to cheaper/free tier
### Rate Limiting
**Cause:** Subscription quota exhausted.
**Fix:**
- Add fallback: `cc/claude-opus-4-6 → glm/glm-4.7 → if/kimi-k2-thinking`
- Use GLM/MiniMax as cheap backup
### OAuth Token Expired
OmniRoute auto-refreshes tokens. If issues persist:
1. Dashboard → Provider → Reconnect
2. Delete and re-add the provider connection
---
## Cloud Issues
### Cloud Sync Errors
1. Verify `BASE_URL` points to your running instance (e.g., `http://localhost:20128`)
2. Verify `CLOUD_URL` points to your cloud endpoint (e.g., `https://omniroute.dev`)
3. Keep `NEXT_PUBLIC_*` values aligned with server-side values
### Cloud `stream=false` Returns 500
**Symptom:** `Unexpected token 'd'...` on cloud endpoint for non-streaming calls.
**Cause:** Upstream returns SSE payload while client expects JSON.
**Workaround:** Use `stream=true` for cloud direct calls. Local runtime includes SSE→JSON fallback.
### Cloud Says Connected but "Invalid API key"
1. Create a fresh key from local dashboard (`/api/keys`)
2. Run cloud sync: Enable Cloud → Sync Now
3. Old/non-synced keys can still return `401` on cloud
---
## Docker Issues
### CLI Tool Shows Not Installed
1. Check runtime fields: `curl http://localhost:20128/api/cli-tools/runtime/codex | jq`
2. For portable mode: use image target `runner-cli` (bundled CLIs)
3. For host mount mode: set `CLI_EXTRA_PATHS` and mount host bin directory as read-only
4. If `installed=true` and `runnable=false`: binary was found but failed healthcheck
### Quick Runtime Validation
```bash
curl -s http://localhost:20128/api/cli-tools/codex-settings | jq '{installed,runnable,commandPath,runtimeMode,reason}'
curl -s http://localhost:20128/api/cli-tools/claude-settings | jq '{installed,runnable,commandPath,runtimeMode,reason}'
curl -s http://localhost:20128/api/cli-tools/openclaw-settings | jq '{installed,runnable,commandPath,runtimeMode,reason}'
```
---
## Cost Issues
### High Costs
1. Check usage stats in Dashboard → Usage
2. Switch primary model to GLM/MiniMax
3. Use free tier (Gemini CLI, iFlow) for non-critical tasks
4. Set cost budgets per API key: Dashboard → API Keys → Budget
---
## Debugging
### Enable Request Logs
Set `ENABLE_REQUEST_LOGS=true` in your `.env` file. Logs appear under `logs/` directory.
### Check Provider Health
```bash
# Health dashboard
http://localhost:20128/dashboard/health
# API health check
curl http://localhost:20128/api/monitoring/health
```
### Runtime Storage
- Main state: `${DATA_DIR}/db.json` (providers, combos, aliases, keys, settings)
- Usage: `${DATA_DIR}/usage.json`, `${DATA_DIR}/log.txt`, `${DATA_DIR}/call_logs/`
- Request logs: `<repo>/logs/...` (when `ENABLE_REQUEST_LOGS=true`)
---
## Circuit Breaker Issues
### Provider stuck in OPEN state
When a provider's circuit breaker is OPEN, requests are blocked until the cooldown expires.
**Fix:**
1. Go to **Dashboard → Settings → Resilience**
2. Check the circuit breaker card for the affected provider
3. Click **Reset All** to clear all breakers, or wait for the cooldown to expire
4. Verify the provider is actually available before resetting
### Provider keeps tripping the circuit breaker
If a provider repeatedly enters OPEN state:
1. Check **Dashboard → Health → Provider Health** for the failure pattern
2. Go to **Settings → Resilience → Provider Profiles** and increase the failure threshold
3. Check if the provider has changed API limits or requires re-authentication
4. Review latency telemetry — high latency may cause timeout-based failures
---
## Audio Transcription Issues
### "Unsupported model" error
- Ensure you're using the correct prefix: `deepgram/nova-3` or `assemblyai/best`
- Verify the provider is connected in **Dashboard → Providers**
### Transcription returns empty or fails
- Check supported audio formats: `mp3`, `wav`, `m4a`, `flac`, `ogg`, `webm`
- Verify file size is within provider limits (typically < 25MB)
- Check provider API key validity in the provider card
---
## Translator Debugging
Use **Dashboard → Translator** to debug format translation issues:
| Mode | When to Use |
| ---------------- | -------------------------------------------------------------------------------------------- |
| **Playground** | Compare input/output formats side by side — paste a failing request to see how it translates |
| **Chat Tester** | Send live messages and inspect the full request/response payload including headers |
| **Test Bench** | Run batch tests across format combinations to find which translations are broken |
| **Live Monitor** | Watch real-time request flow to catch intermittent translation issues |
### Common format issues
- **Thinking tags not appearing** — Check if the target provider supports thinking and the thinking budget setting
- **Tool calls dropping** — Some format translations may strip unsupported fields; verify in Playground mode
- **System prompt missing** — Claude and Gemini handle system prompts differently; check translation output
---
## Resilience Settings
### Auto rate-limit not triggering
- Auto rate-limit only applies to API key providers (not OAuth/subscription)
- Verify **Settings → Resilience → Provider Profiles** has auto-rate-limit enabled
- Check if the provider returns `429` status codes or `Retry-After` headers
### Tuning exponential backoff
Provider profiles support these settings:
- **Base delay** — Initial wait time after first failure (default: 1s)
- **Max delay** — Maximum wait time cap (default: 30s)
- **Multiplier** — How much to increase delay per consecutive failure (default: 2x)
### Anti-thundering herd
When many concurrent requests hit a rate-limited provider, OmniRoute uses mutex + auto rate-limiting to serialize requests and prevent cascading failures. This is automatic for API key providers.
---
## Still Stuck?
- **GitHub Issues**: [github.com/diegosouzapw/OmniRoute/issues](https://github.com/diegosouzapw/OmniRoute/issues)
- **Architecture**: See [`docs/ARCHITECTURE.md`](ARCHITECTURE.md) for internal details
- **API Reference**: See [`docs/API_REFERENCE.md`](API_REFERENCE.md) for all endpoints
- **Health Dashboard**: Check **Dashboard → Health** for real-time system status
- **Translator**: Use **Dashboard → Translator** to debug format issues
+664
View File
@@ -0,0 +1,664 @@
# User Guide
Complete guide for configuring providers, creating combos, integrating CLI tools, and deploying OmniRoute.
---
## Table of Contents
- [Pricing at a Glance](#-pricing-at-a-glance)
- [Use Cases](#-use-cases)
- [Provider Setup](#-provider-setup)
- [CLI Integration](#-cli-integration)
- [Deployment](#-deployment)
- [Available Models](#-available-models)
- [Advanced Features](#-advanced-features)
---
## 💰 Pricing at a Glance
| Tier | Provider | Cost | Quota Reset | Best For |
| ------------------- | ----------------- | ----------- | ---------------- | -------------------- |
| **💳 SUBSCRIPTION** | Claude Code (Pro) | $20/mo | 5h + weekly | Already subscribed |
| | Codex (Plus/Pro) | $20-200/mo | 5h + weekly | OpenAI users |
| | Gemini CLI | **FREE** | 180K/mo + 1K/day | Everyone! |
| | GitHub Copilot | $10-19/mo | Monthly | GitHub users |
| **🔑 API KEY** | DeepSeek | Pay per use | None | Cheap reasoning |
| | Groq | Pay per use | None | Ultra-fast inference |
| | xAI (Grok) | Pay per use | None | Grok 4 reasoning |
| | Mistral | Pay per use | None | EU-hosted models |
| | Perplexity | Pay per use | None | Search-augmented |
| | Together AI | Pay per use | None | Open-source models |
| | Fireworks AI | Pay per use | None | Fast FLUX images |
| | Cerebras | Pay per use | None | Wafer-scale speed |
| | Cohere | Pay per use | None | Command R+ RAG |
| | NVIDIA NIM | Pay per use | None | Enterprise models |
| **💰 CHEAP** | GLM-4.7 | $0.6/1M | Daily 10AM | Budget backup |
| | MiniMax M2.1 | $0.2/1M | 5-hour rolling | Cheapest option |
| | Kimi K2 | $9/mo flat | 10M tokens/mo | Predictable cost |
| **🆓 FREE** | iFlow | $0 | Unlimited | 8 models free |
| | Qwen | $0 | Unlimited | 3 models free |
| | Kiro | $0 | Unlimited | Claude free |
**💡 Pro Tip:** Start with Gemini CLI (180K free/month) + iFlow (unlimited free) combo = $0 cost!
---
## 🎯 Use Cases
### Case 1: "I have Claude Pro subscription"
**Problem:** Quota expires unused, rate limits during heavy coding
```
Combo: "maximize-claude"
1. cc/claude-opus-4-6 (use subscription fully)
2. glm/glm-4.7 (cheap backup when quota out)
3. if/kimi-k2-thinking (free emergency fallback)
Monthly cost: $20 (subscription) + ~$5 (backup) = $25 total
vs. $20 + hitting limits = frustration
```
### Case 2: "I want zero cost"
**Problem:** Can't afford subscriptions, need reliable AI coding
```
Combo: "free-forever"
1. gc/gemini-3-flash (180K free/month)
2. if/kimi-k2-thinking (unlimited free)
3. qw/qwen3-coder-plus (unlimited free)
Monthly cost: $0
Quality: Production-ready models
```
### Case 3: "I need 24/7 coding, no interruptions"
**Problem:** Deadlines, can't afford downtime
```
Combo: "always-on"
1. cc/claude-opus-4-6 (best quality)
2. cx/gpt-5.2-codex (second subscription)
3. glm/glm-4.7 (cheap, resets daily)
4. minimax/MiniMax-M2.1 (cheapest, 5h reset)
5. if/kimi-k2-thinking (free unlimited)
Result: 5 layers of fallback = zero downtime
Monthly cost: $20-200 (subscriptions) + $10-20 (backup)
```
### Case 4: "I want FREE AI in OpenClaw"
**Problem:** Need AI assistant in messaging apps, completely free
```
Combo: "openclaw-free"
1. if/glm-4.7 (unlimited free)
2. if/minimax-m2.1 (unlimited free)
3. if/kimi-k2-thinking (unlimited free)
Monthly cost: $0
Access via: WhatsApp, Telegram, Slack, Discord, iMessage, Signal...
```
---
## 📖 Provider Setup
### 🔐 Subscription Providers
#### Claude Code (Pro/Max)
```bash
Dashboard → Providers → Connect Claude Code
→ OAuth login → Auto token refresh
→ 5-hour + weekly quota tracking
Models:
cc/claude-opus-4-6
cc/claude-sonnet-4-5-20250929
cc/claude-haiku-4-5-20251001
```
**Pro Tip:** Use Opus for complex tasks, Sonnet for speed. OmniRoute tracks quota per model!
#### OpenAI Codex (Plus/Pro)
```bash
Dashboard → Providers → Connect Codex
→ OAuth login (port 1455)
→ 5-hour + weekly reset
Models:
cx/gpt-5.2-codex
cx/gpt-5.1-codex-max
```
#### Gemini CLI (FREE 180K/month!)
```bash
Dashboard → Providers → Connect Gemini CLI
→ Google OAuth
→ 180K completions/month + 1K/day
Models:
gc/gemini-3-flash-preview
gc/gemini-2.5-pro
```
**Best Value:** Huge free tier! Use this before paid tiers.
#### GitHub Copilot
```bash
Dashboard → Providers → Connect GitHub
→ OAuth via GitHub
→ Monthly reset (1st of month)
Models:
gh/gpt-5
gh/claude-4.5-sonnet
gh/gemini-3-pro
```
### 💰 Cheap Providers
#### GLM-4.7 (Daily reset, $0.6/1M)
1. Sign up: [Zhipu AI](https://open.bigmodel.cn/)
2. Get API key from Coding Plan
3. Dashboard → Add API Key: Provider: `glm`, API Key: `your-key`
**Use:** `glm/glm-4.7`**Pro Tip:** Coding Plan offers 3× quota at 1/7 cost! Reset daily 10:00 AM.
#### MiniMax M2.1 (5h reset, $0.20/1M)
1. Sign up: [MiniMax](https://www.minimax.io/)
2. Get API key → Dashboard → Add API Key
**Use:** `minimax/MiniMax-M2.1`**Pro Tip:** Cheapest option for long context (1M tokens)!
#### Kimi K2 ($9/month flat)
1. Subscribe: [Moonshot AI](https://platform.moonshot.ai/)
2. Get API key → Dashboard → Add API Key
**Use:** `kimi/kimi-latest`**Pro Tip:** Fixed $9/month for 10M tokens = $0.90/1M effective cost!
### 🆓 FREE Providers
#### iFlow (8 FREE models)
```bash
Dashboard → Connect iFlow → OAuth login → Unlimited usage
Models: if/kimi-k2-thinking, if/qwen3-coder-plus, if/glm-4.7, if/minimax-m2, if/deepseek-r1
```
#### Qwen (3 FREE models)
```bash
Dashboard → Connect Qwen → Device code auth → Unlimited usage
Models: qw/qwen3-coder-plus, qw/qwen3-coder-flash
```
#### Kiro (Claude FREE)
```bash
Dashboard → Connect Kiro → AWS Builder ID or Google/GitHub → Unlimited
Models: kr/claude-sonnet-4.5, kr/claude-haiku-4.5
```
---
## 🎨 Combos
### Example 1: Maximize Subscription → Cheap Backup
```
Dashboard → Combos → Create New
Name: premium-coding
Models:
1. cc/claude-opus-4-6 (Subscription primary)
2. glm/glm-4.7 (Cheap backup, $0.6/1M)
3. minimax/MiniMax-M2.1 (Cheapest fallback, $0.20/1M)
Use in CLI: premium-coding
```
### Example 2: Free-Only (Zero Cost)
```
Name: free-combo
Models:
1. gc/gemini-3-flash-preview (180K free/month)
2. if/kimi-k2-thinking (unlimited)
3. qw/qwen3-coder-plus (unlimited)
Cost: $0 forever!
```
---
## 🔧 CLI Integration
### Cursor IDE
```
Settings → Models → Advanced:
OpenAI API Base URL: http://localhost:20128/v1
OpenAI API Key: [from omniroute dashboard]
Model: cc/claude-opus-4-6
```
### Claude Code
Edit `~/.claude/config.json`:
```json
{
"anthropic_api_base": "http://localhost:20128/v1",
"anthropic_api_key": "your-omniroute-api-key"
}
```
### Codex CLI
```bash
export OPENAI_BASE_URL="http://localhost:20128"
export OPENAI_API_KEY="your-omniroute-api-key"
codex "your prompt"
```
### OpenClaw
Edit `~/.openclaw/openclaw.json`:
```json
{
"agents": {
"defaults": {
"model": { "primary": "omniroute/if/glm-4.7" }
}
},
"models": {
"providers": {
"omniroute": {
"baseUrl": "http://localhost:20128/v1",
"apiKey": "your-omniroute-api-key",
"api": "openai-completions",
"models": [{ "id": "if/glm-4.7", "name": "glm-4.7" }]
}
}
}
}
```
**Or use Dashboard:** CLI Tools → OpenClaw → Auto-config
### Cline / Continue / RooCode
```
Provider: OpenAI Compatible
Base URL: http://localhost:20128/v1
API Key: [from dashboard]
Model: cc/claude-opus-4-6
```
---
## 🚀 Deployment
### VPS Deployment
```bash
git clone https://github.com/diegosouzapw/OmniRoute.git
cd OmniRoute && npm install && npm run build
export JWT_SECRET="your-secure-secret-change-this"
export INITIAL_PASSWORD="your-password"
export DATA_DIR="/var/lib/omniroute"
export PORT="20128"
export HOSTNAME="0.0.0.0"
export NODE_ENV="production"
export NEXT_PUBLIC_BASE_URL="http://localhost:20128"
export API_KEY_SECRET="endpoint-proxy-api-key-secret"
npm run start
# Or: pm2 start npm --name omniroute -- start
```
### Docker
```bash
# Build image (default = runner-cli with codex/claude/droid preinstalled)
docker build -t omniroute:cli .
# Portable mode (recommended)
docker run -d --name omniroute -p 20128:20128 --env-file ./.env -v omniroute-data:/app/data omniroute:cli
```
For host-integrated mode with CLI binaries, see the Docker section in the main docs.
### Environment Variables
| Variable | Default | Description |
| --------------------- | ------------------------------------ | ------------------------------------------------------- |
| `JWT_SECRET` | `omniroute-default-secret-change-me` | JWT signing secret (**change in production**) |
| `INITIAL_PASSWORD` | `123456` | First login password |
| `DATA_DIR` | `~/.omniroute` | Data directory (db, usage, logs) |
| `PORT` | framework default | Service port (`20128` in examples) |
| `HOSTNAME` | framework default | Bind host (Docker defaults to `0.0.0.0`) |
| `NODE_ENV` | runtime default | Set `production` for deploy |
| `BASE_URL` | `http://localhost:20128` | Server-side internal base URL |
| `CLOUD_URL` | `https://omniroute.dev` | Cloud sync endpoint base URL |
| `API_KEY_SECRET` | `endpoint-proxy-api-key-secret` | HMAC secret for generated API keys |
| `REQUIRE_API_KEY` | `false` | Enforce Bearer API key on `/v1/*` |
| `ENABLE_REQUEST_LOGS` | `false` | Enables request/response logs |
| `AUTH_COOKIE_SECURE` | `false` | Force `Secure` auth cookie (behind HTTPS reverse proxy) |
For the full environment variable reference, see the [README](../README.md).
---
## 📊 Available Models
<details>
<summary><b>View all available models</b></summary>
**Claude Code (`cc/`)** — Pro/Max: `cc/claude-opus-4-6`, `cc/claude-sonnet-4-5-20250929`, `cc/claude-haiku-4-5-20251001`
**Codex (`cx/`)** — Plus/Pro: `cx/gpt-5.2-codex`, `cx/gpt-5.1-codex-max`
**Gemini CLI (`gc/`)** — FREE: `gc/gemini-3-flash-preview`, `gc/gemini-2.5-pro`
**GitHub Copilot (`gh/`)**: `gh/gpt-5`, `gh/claude-4.5-sonnet`
**GLM (`glm/`)** — $0.6/1M: `glm/glm-4.7`
**MiniMax (`minimax/`)** — $0.2/1M: `minimax/MiniMax-M2.1`
**iFlow (`if/`)** — FREE: `if/kimi-k2-thinking`, `if/qwen3-coder-plus`, `if/deepseek-r1`
**Qwen (`qw/`)** — FREE: `qw/qwen3-coder-plus`, `qw/qwen3-coder-flash`
**Kiro (`kr/`)** — FREE: `kr/claude-sonnet-4.5`, `kr/claude-haiku-4.5`
**DeepSeek (`ds/`)**: `ds/deepseek-chat`, `ds/deepseek-reasoner`
**Groq (`groq/`)**: `groq/llama-3.3-70b-versatile`, `groq/llama-4-maverick-17b-128e-instruct`
**xAI (`xai/`)**: `xai/grok-4`, `xai/grok-4-0709-fast-reasoning`, `xai/grok-code-mini`
**Mistral (`mistral/`)**: `mistral/mistral-large-2501`, `mistral/codestral-2501`
**Perplexity (`pplx/`)**: `pplx/sonar-pro`, `pplx/sonar`
**Together AI (`together/`)**: `together/meta-llama/Llama-3.3-70B-Instruct-Turbo`
**Fireworks AI (`fireworks/`)**: `fireworks/accounts/fireworks/models/deepseek-v3p1`
**Cerebras (`cerebras/`)**: `cerebras/llama-3.3-70b`
**Cohere (`cohere/`)**: `cohere/command-r-plus-08-2024`
**NVIDIA NIM (`nvidia/`)**: `nvidia/nvidia/llama-3.3-70b-instruct`
</details>
---
## 🧩 Advanced Features
### Custom Models
Add any model ID to any provider without waiting for an app update:
```bash
# Via API
curl -X POST http://localhost:20128/api/provider-models \
-H "Content-Type: application/json" \
-d '{"provider": "openai", "modelId": "gpt-4.5-preview", "modelName": "GPT-4.5 Preview"}'
# List: curl http://localhost:20128/api/provider-models?provider=openai
# Remove: curl -X DELETE "http://localhost:20128/api/provider-models?provider=openai&model=gpt-4.5-preview"
```
Or use Dashboard: **Providers → [Provider] → Custom Models**.
### Dedicated Provider Routes
Route requests directly to a specific provider with model validation:
```bash
POST http://localhost:20128/v1/providers/openai/chat/completions
POST http://localhost:20128/v1/providers/openai/embeddings
POST http://localhost:20128/v1/providers/fireworks/images/generations
```
The provider prefix is auto-added if missing. Mismatched models return `400`.
### Network Proxy Configuration
```bash
# Set global proxy
curl -X PUT http://localhost:20128/api/settings/proxy \
-d '{"global": {"type":"http","host":"proxy.example.com","port":"8080"}}'
# Per-provider proxy
curl -X PUT http://localhost:20128/api/settings/proxy \
-d '{"providers": {"openai": {"type":"socks5","host":"proxy.example.com","port":"1080"}}}'
# Test proxy
curl -X POST http://localhost:20128/api/settings/proxy/test \
-d '{"proxy":{"type":"socks5","host":"proxy.example.com","port":"1080"}}'
```
**Precedence:** Key-specific → Combo-specific → Provider-specific → Global → Environment.
### Model Catalog API
```bash
curl http://localhost:20128/api/models/catalog
```
Returns models grouped by provider with types (`chat`, `embedding`, `image`).
### Cloud Sync
- Sync providers, combos, and settings across devices
- Automatic background sync with timeout + fail-fast
- Prefer server-side `BASE_URL`/`CLOUD_URL` in production
### LLM Gateway Intelligence (Phase 9)
- **Semantic Cache** — Auto-caches non-streaming, temperature=0 responses (bypass with `X-OmniRoute-No-Cache: true`)
- **Request Idempotency** — Deduplicates requests within 5s via `Idempotency-Key` or `X-Request-Id` header
- **Progress Tracking** — Opt-in SSE `event: progress` events via `X-OmniRoute-Progress: true` header
---
### Translator Playground
Access via **Dashboard → Translator**. Debug and visualize how OmniRoute translates API requests between providers.
| Mode | Purpose |
| ---------------- | -------------------------------------------------------------------------------------- |
| **Playground** | Select source/target formats, paste a request, and see the translated output instantly |
| **Chat Tester** | Send live chat messages through the proxy and inspect the full request/response cycle |
| **Test Bench** | Run batch tests across multiple format combinations to verify translation correctness |
| **Live Monitor** | Watch real-time translations as requests flow through the proxy |
**Use cases:**
- Debug why a specific client/provider combination fails
- Verify that thinking tags, tool calls, and system prompts translate correctly
- Compare format differences between OpenAI, Claude, Gemini, and Responses API formats
---
### Routing Strategies
Configure via **Dashboard → Settings → Routing**.
| Strategy | Description |
| ------------------------------ | ------------------------------------------------------------------------------------------------ |
| **Fill First** | Uses accounts in priority order — primary account handles all requests until unavailable |
| **Round Robin** | Cycles through all accounts with a configurable sticky limit (default: 3 calls per account) |
| **P2C (Power of Two Choices)** | Picks 2 random accounts and routes to the healthier one — balances load with awareness of health |
| **Random** | Randomly selects an account for each request using Fisher-Yates shuffle |
| **Least Used** | Routes to the account with the oldest `lastUsedAt` timestamp, distributing traffic evenly |
| **Cost Optimized** | Routes to the account with the lowest priority value, optimizing for lowest-cost providers |
#### Wildcard Model Aliases
Create wildcard patterns to remap model names:
```
Pattern: claude-sonnet-* → Target: cc/claude-sonnet-4-5-20250929
Pattern: gpt-* → Target: gh/gpt-5.1-codex
```
Wildcards support `*` (any characters) and `?` (single character).
#### Fallback Chains
Define global fallback chains that apply across all requests:
```
Chain: production-fallback
1. cc/claude-opus-4-6
2. gh/gpt-5.1-codex
3. glm/glm-4.7
```
---
### Resilience & Circuit Breakers
Configure via **Dashboard → Settings → Resilience**.
OmniRoute implements provider-level resilience with four components:
1. **Provider Profiles** — Per-provider configuration for:
- Failure threshold (how many failures before opening)
- Cooldown duration
- Rate limit detection sensitivity
- Exponential backoff parameters
2. **Editable Rate Limits** — System-level defaults configurable in the dashboard:
- **Requests Per Minute (RPM)** — Maximum requests per minute per account
- **Min Time Between Requests** — Minimum gap in milliseconds between requests
- **Max Concurrent Requests** — Maximum simultaneous requests per account
- Click **Edit** to modify, then **Save** or **Cancel**. Values persist via the resilience API.
3. **Circuit Breaker** — Tracks failures per provider and automatically opens the circuit when a threshold is reached:
- **CLOSED** (Healthy) — Requests flow normally
- **OPEN** — Provider is temporarily blocked after repeated failures
- **HALF_OPEN** — Testing if provider has recovered
4. **Policies & Locked Identifiers** — Shows circuit breaker status and locked identifiers with force-unlock capability.
5. **Rate Limit Auto-Detection** — Monitors `429` and `Retry-After` headers to proactively avoid hitting provider rate limits.
**Pro Tip:** Use **Reset All** button to clear all circuit breakers and cooldowns when a provider recovers from an outage.
---
### Settings Dashboard
The settings page is organized into 5 tabs for easy navigation:
| Tab | Contents |
| -------------- | ---------------------------------------------------------------------------------------------- |
| **Security** | Login/Password settings and IP Access Control (allowlist/blocklist) |
| **Routing** | Global routing strategy (6 options), wildcard model aliases, fallback chains, combo defaults |
| **Resilience** | Provider profiles, editable rate limits, circuit breaker status, policies & locked identifiers |
| **AI** | Thinking budget configuration, global system prompt injection, prompt cache stats |
| **Advanced** | Global proxy configuration (HTTP/SOCKS5) |
---
### Costs & Budget Management
Access via **Dashboard → Costs**.
| Tab | Purpose |
| ----------- | ---------------------------------------------------------------------------------------- |
| **Budget** | Set spending limits per API key with daily/weekly/monthly budgets and real-time tracking |
| **Pricing** | View and edit model pricing entries — cost per 1K input/output tokens per provider |
```bash
# API: Set a budget
curl -X POST http://localhost:20128/api/usage/budget \
-H "Content-Type: application/json" \
-d '{"keyId": "key-123", "limit": 50.00, "period": "monthly"}'
# API: Get current budget status
curl http://localhost:20128/api/usage/budget
```
**Cost Tracking:** Every request logs token usage and calculates cost using the pricing table. View breakdowns in **Dashboard → Usage** by provider, model, and API key.
---
### Audio Transcription
OmniRoute supports audio transcription via the OpenAI-compatible endpoint:
```bash
POST /v1/audio/transcriptions
Authorization: Bearer your-api-key
Content-Type: multipart/form-data
# Example with curl
curl -X POST http://localhost:20128/v1/audio/transcriptions \
-H "Authorization: Bearer your-api-key" \
-F "file=@audio.mp3" \
-F "model=deepgram/nova-3"
```
Available providers: **Deepgram** (`deepgram/`), **AssemblyAI** (`assemblyai/`).
Supported audio formats: `mp3`, `wav`, `m4a`, `flac`, `ogg`, `webm`.
---
### Combo Balancing Strategies
Configure per-combo balancing in **Dashboard → Combos → Create/Edit → Strategy**.
| Strategy | Description |
| ------------------ | ------------------------------------------------------------------------ |
| **Round-Robin** | Rotates through models sequentially |
| **Priority** | Always tries the first model; falls back only on error |
| **Random** | Picks a random model from the combo for each request |
| **Weighted** | Routes proportionally based on assigned weights per model |
| **Least-Used** | Routes to the model with the fewest recent requests (uses combo metrics) |
| **Cost-Optimized** | Routes to the cheapest available model (uses pricing table) |
Global combo defaults can be set in **Dashboard → Settings → Routing → Combo Defaults**.
---
### Health Dashboard
Access via **Dashboard → Health**. Real-time system health overview with 6 cards:
| Card | What It Shows |
| --------------------- | ----------------------------------------------------------- |
| **System Status** | Uptime, version, memory usage, data directory |
| **Provider Health** | Per-provider circuit breaker state (Closed/Open/Half-Open) |
| **Rate Limits** | Active rate limit cooldowns per account with remaining time |
| **Active Lockouts** | Providers temporarily blocked by the lockout policy |
| **Signature Cache** | Deduplication cache stats (active keys, hit rate) |
| **Latency Telemetry** | p50/p95/p99 latency aggregation per provider |
**Pro Tip:** The Health page auto-refreshes every 10 seconds. Use the circuit breaker card to identify which providers are experiencing issues.
-31
View File
@@ -1,31 +0,0 @@
# Architecture Decision Record Template
## ADR-XXX: [Title]
**Date:** YYYY-MM-DD
**Status:** Accepted | Superseded | Deprecated
**Deciders:** @team
## Context
What is the issue we're seeing that motivates this decision?
## Decision
What is the change that we're proposing and/or doing?
## Consequences
What becomes easier or more difficult because of this change?
### Positive
- ...
### Negative
- ...
### Neutral
- ...
-44
View File
@@ -1,44 +0,0 @@
# ADR-001: SQLite as Primary Data Store
**Date:** 2025-10-15
**Status:** Accepted
**Deciders:** @diegosouzapw
## Context
OmniRoute needs to persist usage data, call logs, API keys, and configuration. Options considered:
- PostgreSQL/MySQL — full RDBMS
- SQLite — embedded, zero-config
- JSON files (LowDB) — simple but fragile
- Redis — in-memory, ephemeral
The project targets self-hosted, single-tenant deployments where operational simplicity is paramount.
## Decision
Use **SQLite** via `better-sqlite3` as the primary data store.
- All usage tracking, call logs, API keys, and settings stored in a single `.db` file
- Synchronous reads (no async overhead for simple queries)
- WAL mode for concurrent read/write performance
- Automatic migration from legacy JSON format (`usageDb.json`) on first boot
## Consequences
### Positive
- Zero infrastructure — no database server needed
- Single-file backup (`cp data/omniroute.db backup/`)
- Fast queries for dashboard stats (< 5ms typical)
- Easy migration path from JSON format
### Negative
- Single-writer limitation (acceptable for single-tenant)
- No built-in replication
- Would need migration to PostgreSQL for multi-tenant cloud deployment
### Neutral
- File-based storage works well in Docker volumes
-36
View File
@@ -1,36 +0,0 @@
# ADR-002: Multi-Provider Fallback Strategy
**Date:** 2025-11-20
**Status:** Accepted
**Deciders:** @diegosouzapw
## Context
OmniRoute routes requests to multiple LLM providers (OpenAI, Anthropic, Google, etc.). Providers may become unavailable due to rate limiting, outages, or credential expiry. The system needs a strategy to handle these failures gracefully.
## Decision
Implement a **declarative fallback chain** with three layers:
1. **Credential Retry Loop** — Rotate through available credentials for the same provider before failing
2. **Model Fallback Policy** — Configurable fallback chain per model (e.g., `gpt-4o → azure-gpt-4o → anthropic-claude`)
3. **Circuit Breaker** — Trip open after consecutive failures to prevent cascading requests to broken providers
The fallback policy is defined in `src/domain/fallbackPolicy.js` and integrates with the circuit breaker in `src/shared/utils/circuitBreaker.js`.
## Consequences
### Positive
- Automatic failover with zero user intervention
- Per-model granularity — different models can have different fallback strategies
- Circuit breaker prevents wasting quota on broken providers
### Negative
- Fallback chain requires manual configuration per model
- Response latency increases when primary fails (retry + fallback time)
### Neutral
- Lockout policy (n consecutive failures → temporary block) complements but is separate from fallback
-47
View File
@@ -1,47 +0,0 @@
# ADR-003: OAuth Strategy — Multi-Flow Support
**Date:** 2025-11-01
**Status:** Accepted
**Deciders:** @diegosouzapw
## Context
OmniRoute supports 12+ providers, each with different OAuth implementations:
- Authorization Code + PKCE (Claude, Codex, Gemini, Antigravity, iFlow)
- Device Code Flow (Qwen, GitHub, Kiro, Kilocode, Kimi-Coding, Cline)
- Token Import (Cursor — extracted from local SQLite)
A unified approach is needed to manage authentication across all providers.
## Decision
Use a **base class + strategy pattern**:
1. `OAuthService` base class (`src/lib/oauth/services/oauth.js`) — handles common authorization code flow with PKCE
2. Provider-specific subclasses (e.g., `GitHubService`, `ClaudeService`) — override authentication methods
3. Provider registry (`src/lib/oauth/providers.js`) — declarative config per provider with `flowType`, `buildAuthUrl`, `exchangeToken`, `mapTokens`
4. Constants centralized in `src/lib/oauth/constants/oauth.js`
Each provider defines:
- `flowType`: `authorization_code_pkce` | `authorization_code` | `device_code` | `import_token`
- Required hooks: `buildAuthUrl()`, `exchangeToken()`, `mapTokens()`
- Optional hooks: `postExchange()` for provider-specific post-auth logic
## Consequences
### Positive
- Adding new providers requires only a config entry + optional subclass
- PKCE, state validation, and token exchange are shared (DRY)
- Device code flow providers share polling logic
### Negative
- Some providers have unique quirks (Kiro uses AWS SSO OIDC with client registration)
- Testing requires mocking external OAuth endpoints
### Neutral
- ~1050 lines in `providers.js` — could be further split per provider if needed
-43
View File
@@ -1,43 +0,0 @@
# ADR-004: JavaScript + JSDoc over TypeScript
**Date:** 2025-10-01
**Status:** Accepted
**Deciders:** @diegosouzapw
## Context
The project needs type safety and developer experience improvements. Options:
1. **Full TypeScript migration**`.ts` files, `tsconfig.json`, build step
2. **JavaScript + JSDoc + @ts-check** — type checking without compilation
3. **No type checking** — status quo
## Decision
Adopt **JavaScript with JSDoc annotations and `@ts-check`** instead of migrating to TypeScript.
- Add `// @ts-check` to critical module files
- Use JSDoc `@param`, `@returns`, `@typedef` for type documentation
- TypeScript compiler used only for checking (via IDE), not for building
- Zod schemas for runtime validation at API boundaries
## Consequences
### Positive
- No build step — `node src/proxy.js` runs directly
- Faster development iteration (no compile wait)
- Gradual adoption — files can be annotated one at a time
- IDE still provides autocomplete and type errors via JSDoc
- Lower barrier for contributors
### Negative
- JSDoc type syntax is more verbose than TypeScript
- Some advanced TypeScript features (generics, conditional types) are harder in JSDoc
- No `.d.ts` generation for consumers
### Neutral
- Existing Zod schemas provide runtime validation regardless of type system choice
- `@ts-check` can be added to any file without affecting others
-39
View File
@@ -1,39 +0,0 @@
# ADR-005: Single-Tenant Architecture
**Date:** 2025-10-01
**Status:** Accepted
**Deciders:** @diegosouzapw
## Context
OmniRoute needs to decide between single-tenant and multi-tenant architecture. The primary use case is individuals and small teams running their own proxy instance.
## Decision
Adopt a **single-tenant architecture** where each deployment serves one user/team.
- One SQLite database per instance
- One set of API keys and credentials per instance
- Password-based login (single admin user)
- No user management, roles, or permissions beyond admin
- Settings stored in a single `settings` table
## Consequences
### Positive
- Dramatically simpler codebase (no tenant isolation, RBAC, or data partitioning)
- SQLite is perfectly suited (no concurrent multi-tenant writes)
- Easy deployment: one Docker container = one instance
- Complete data isolation between users (separate deployments)
### Negative
- Not suitable for SaaS or shared hosting without running multiple instances
- No built-in multi-user collaboration features
- Scaling requires deploying separate instances
### Neutral
- Cloud worker mode exists as a separate deployment target with different constraints
- Future multi-tenant support would require a PostgreSQL migration (see ADR-001)
-48
View File
@@ -1,48 +0,0 @@
# ADR-006: Translator Registry Pattern
**Date:** 2025-12-01
**Status:** Accepted
**Deciders:** @diegosouzapw
## Context
OmniRoute translates requests between different LLM API formats (OpenAI ↔ Anthropic ↔ Google ↔ etc.). Each provider has a unique request/response schema. The translator must:
- Convert incoming requests to the target provider's format
- Convert streaming responses back to the client's expected format
- Handle provider-specific features (tool calls, vision, system prompts)
## Decision
Use a **registry pattern** for translators:
1. Each provider pair has a translator module in `src/sse/translators/`
2. Translators are registered by `(sourceFormat, targetFormat)` key
3. The `translateRequest()` function auto-detects source format and applies the appropriate translator
4. Translators handle both request translation and response stream mapping
Key translators:
- `openai → anthropic` (and reverse)
- `openai → google` (and reverse)
- `anthropic → google` (and reverse)
- Identity translators for same-format routing
## Consequences
### Positive
- Adding a new provider requires only a new translator module
- Each translator is independently testable
- Auto-detection reduces configuration burden on users
- Supports chained translation (A → B → C) if needed
### Negative
- O(n²) translator combinations as providers grow (mitigated by identity translators)
- Some edge cases in format conversion (e.g., tool call schemas differ significantly)
### Neutral
- The Translator Playground UI provides visual testing of translation chains
- Performance overhead is minimal (JSON transformation, no network calls)
+808 -2
View File
@@ -1,7 +1,7 @@
openapi: 3.1.0
info:
title: OmniRoute API
version: 0.4.0
version: 0.5.0
description: |
OmniRoute is a local-first AI API proxy router. It provides an OpenAI-compatible
endpoint that routes requests to multiple AI providers with load balancing,
@@ -33,6 +33,12 @@ tags:
description: Text embedding generation
- name: Images
description: Image generation
- name: Audio
description: Audio speech and transcription
- name: Moderations
description: Content moderation
- name: Rerank
description: Document reranking
- name: Models
description: Available model listing
- name: Providers
@@ -57,6 +63,12 @@ tags:
description: System management (restart, shutdown, backup)
- name: Pricing
description: Model pricing configuration
- name: Cloud
description: Cloud worker authentication and sync
- name: Fallback
description: Fallback chain management
- name: Telemetry
description: Telemetry and token health monitoring
paths:
# ─── Proxy Endpoints ──────────────────────────────────────────
@@ -114,6 +126,23 @@ paths:
"401":
$ref: "#/components/responses/Unauthorized"
/api/v1/api/chat:
post:
tags: [Chat]
summary: Ollama-compatible chat endpoint
description: Provides compatibility with Ollama's /api/chat format.
security:
- BearerAuth: []
requestBody:
required: true
content:
application/json:
schema:
type: object
responses:
"200":
description: Chat response (JSON or streaming)
/api/v1/messages:
post:
tags: [Messages]
@@ -266,6 +295,118 @@ paths:
"200":
description: Generated images
/api/v1/audio/speech:
post:
tags: [Audio]
summary: Generate speech audio
description: Text-to-speech endpoint. Routes to configured TTS providers.
security:
- BearerAuth: []
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [input]
properties:
input:
type: string
model:
type: string
voice:
type: string
responses:
"200":
description: Audio data
/api/v1/audio/transcriptions:
post:
tags: [Audio]
summary: Transcribe audio
description: Audio-to-text transcription endpoint.
security:
- BearerAuth: []
requestBody:
required: true
content:
multipart/form-data:
schema:
type: object
required: [file]
properties:
file:
type: string
format: binary
model:
type: string
responses:
"200":
description: Transcription result
/api/v1/moderations:
post:
tags: [Moderations]
summary: Create moderation
description: Content moderation endpoint. Routes to configured moderation providers.
security:
- BearerAuth: []
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [input]
properties:
input:
oneOf:
- type: string
- type: array
items:
type: string
responses:
"200":
description: Moderation result
/api/v1/rerank:
post:
tags: [Rerank]
summary: Rerank documents
description: Document reranking endpoint.
security:
- BearerAuth: []
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [query, documents]
properties:
query:
type: string
documents:
type: array
items:
type: string
model:
type: string
responses:
"200":
description: Reranked documents
/api/v1:
get:
tags: [System]
summary: API v1 root endpoint
description: Returns basic API info and status.
security:
- BearerAuth: []
responses:
"200":
description: API info
/api/v1/models:
get:
tags: [Models]
@@ -319,6 +460,22 @@ paths:
"200":
description: Complete catalog with all providers
/api/models/availability:
get:
tags: [Models]
summary: Get model availability status
description: Returns availability data for all configured models across providers.
responses:
"200":
description: Model availability map
post:
tags: [Models]
summary: Refresh model availability
description: Triggers a re-check of model availability across all providers.
responses:
"200":
description: Availability refreshed
# ─── Management Endpoints ──────────────────────────────────────
/api/providers:
@@ -631,6 +788,120 @@ paths:
"200":
description: Updated
/api/settings/ip-filter:
get:
tags: [Settings]
summary: Get IP filter configuration
description: Returns the current IP filter settings including blacklist, whitelist, and temp bans.
responses:
"200":
description: IP filter configuration
put:
tags: [Settings]
summary: Update IP filter configuration
description: |
Configure IP filtering with blacklist/whitelist modes, add/remove individual IPs, and manage temp bans.
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
enabled:
type: boolean
mode:
type: string
enum: [blacklist, whitelist]
blacklist:
type: array
items:
type: string
whitelist:
type: array
items:
type: string
addBlacklist:
type: string
removeBlacklist:
type: string
addWhitelist:
type: string
removeWhitelist:
type: string
tempBan:
type: object
properties:
ip:
type: string
durationMs:
type: integer
reason:
type: string
removeBan:
type: string
responses:
"200":
description: Updated IP filter configuration
/api/settings/system-prompt:
get:
tags: [Settings]
summary: Get system prompt configuration
description: Returns the current system prompt injection settings.
responses:
"200":
description: System prompt configuration
put:
tags: [Settings]
summary: Update system prompt configuration
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
prompt:
type: string
enabled:
type: boolean
responses:
"200":
description: Updated system prompt configuration
/api/settings/thinking-budget:
get:
tags: [Settings]
summary: Get thinking budget configuration
description: Returns the current thinking/reasoning budget settings for AI models.
responses:
"200":
description: Thinking budget configuration
put:
tags: [Settings]
summary: Update thinking budget configuration
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
mode:
type: string
description: Thinking mode (e.g., auto, manual, disabled)
customBudget:
type: integer
minimum: 0
maximum: 131072
effortLevel:
type: string
enum: [none, low, medium, high]
responses:
"200":
description: Updated thinking budget configuration
/api/rate-limit:
get:
tags: [Settings]
@@ -638,6 +909,18 @@ paths:
responses:
"200":
description: Rate limit settings
post:
tags: [Settings]
summary: Update rate limit configuration
requestBody:
required: true
content:
application/json:
schema:
type: object
responses:
"200":
description: Updated rate limit settings
/api/tags:
get:
@@ -740,6 +1023,28 @@ paths:
"200":
description: Request log entries
/api/usage/budget:
get:
tags: [Usage]
summary: Get usage budget status
description: Returns current budget limits and consumption.
responses:
"200":
description: Budget status
post:
tags: [Usage]
summary: Configure usage budget
description: Set or update budget limits for usage tracking.
requestBody:
required: true
content:
application/json:
schema:
type: object
responses:
"200":
description: Updated budget configuration
# ─── Pricing ───────────────────────────────────────────────────
/api/pricing:
@@ -764,6 +1069,15 @@ paths:
"200":
description: Default pricing data
/api/pricing/models:
get:
tags: [Pricing]
summary: Get pricing per model
description: Returns pricing information organized by model.
responses:
"200":
description: Per-model pricing data
# ─── Translator ────────────────────────────────────────────────
/api/translator/detect:
@@ -901,6 +1215,246 @@ paths:
"200":
description: Guide settings
/api/cli-tools/antigravity-mitm:
get:
tags: [CLI Tools]
summary: Get Antigravity MITM proxy settings
responses:
"200":
description: MITM proxy configuration
post:
tags: [CLI Tools]
summary: Update Antigravity MITM proxy settings
requestBody:
required: true
content:
application/json:
schema:
type: object
responses:
"200":
description: Updated MITM proxy configuration
delete:
tags: [CLI Tools]
summary: Reset Antigravity MITM proxy settings
responses:
"200":
description: MITM proxy settings reset
/api/cli-tools/antigravity-mitm/alias:
get:
tags: [CLI Tools]
summary: Get Antigravity MITM alias configuration
responses:
"200":
description: Alias configuration
put:
tags: [CLI Tools]
summary: Update Antigravity MITM alias configuration
requestBody:
required: true
content:
application/json:
schema:
type: object
responses:
"200":
description: Updated alias configuration
/api/cli-tools/claude-settings:
get:
tags: [CLI Tools]
summary: Get Claude CLI settings
responses:
"200":
description: Claude CLI configuration
post:
tags: [CLI Tools]
summary: Apply Claude CLI settings
requestBody:
required: true
content:
application/json:
schema:
type: object
responses:
"200":
description: Claude CLI settings applied
delete:
tags: [CLI Tools]
summary: Reset Claude CLI settings
responses:
"200":
description: Claude CLI settings reset
/api/cli-tools/cline-settings:
get:
tags: [CLI Tools]
summary: Get Cline CLI settings
responses:
"200":
description: Cline CLI configuration
post:
tags: [CLI Tools]
summary: Apply Cline CLI settings
requestBody:
required: true
content:
application/json:
schema:
type: object
responses:
"200":
description: Cline CLI settings applied
delete:
tags: [CLI Tools]
summary: Reset Cline CLI settings
responses:
"200":
description: Cline CLI settings reset
/api/cli-tools/codex-profiles:
get:
tags: [CLI Tools]
summary: Get Codex profiles
responses:
"200":
description: Codex profile list
post:
tags: [CLI Tools]
summary: Create Codex profile
requestBody:
required: true
content:
application/json:
schema:
type: object
responses:
"200":
description: Profile created
put:
tags: [CLI Tools]
summary: Update Codex profile
requestBody:
required: true
content:
application/json:
schema:
type: object
responses:
"200":
description: Profile updated
delete:
tags: [CLI Tools]
summary: Delete Codex profile
responses:
"200":
description: Profile deleted
/api/cli-tools/codex-settings:
get:
tags: [CLI Tools]
summary: Get Codex CLI settings
responses:
"200":
description: Codex CLI configuration
post:
tags: [CLI Tools]
summary: Apply Codex CLI settings
requestBody:
required: true
content:
application/json:
schema:
type: object
responses:
"200":
description: Codex CLI settings applied
delete:
tags: [CLI Tools]
summary: Reset Codex CLI settings
responses:
"200":
description: Codex CLI settings reset
/api/cli-tools/droid-settings:
get:
tags: [CLI Tools]
summary: Get Droid CLI settings
responses:
"200":
description: Droid CLI configuration
post:
tags: [CLI Tools]
summary: Apply Droid CLI settings
requestBody:
required: true
content:
application/json:
schema:
type: object
responses:
"200":
description: Droid CLI settings applied
delete:
tags: [CLI Tools]
summary: Reset Droid CLI settings
responses:
"200":
description: Droid CLI settings reset
/api/cli-tools/kilo-settings:
get:
tags: [CLI Tools]
summary: Get Kilo CLI settings
responses:
"200":
description: Kilo CLI configuration
post:
tags: [CLI Tools]
summary: Apply Kilo CLI settings
requestBody:
required: true
content:
application/json:
schema:
type: object
responses:
"200":
description: Kilo CLI settings applied
delete:
tags: [CLI Tools]
summary: Reset Kilo CLI settings
responses:
"200":
description: Kilo CLI settings reset
/api/cli-tools/openclaw-settings:
get:
tags: [CLI Tools]
summary: Get OpenClaw CLI settings
responses:
"200":
description: OpenClaw CLI configuration
post:
tags: [CLI Tools]
summary: Apply OpenClaw CLI settings
requestBody:
required: true
content:
application/json:
schema:
type: object
responses:
"200":
description: OpenClaw CLI settings applied
delete:
tags: [CLI Tools]
summary: Reset OpenClaw CLI settings
responses:
"200":
description: OpenClaw CLI settings reset
# ─── OAuth ─────────────────────────────────────────────────────
/api/oauth/{provider}/{action}:
@@ -926,6 +1480,209 @@ paths:
"302":
description: Redirect to provider auth page
/api/oauth/cursor/auto-import:
get:
tags: [OAuth]
summary: Auto-import Cursor OAuth credentials
description: Automatically detects and imports Cursor credentials from local config.
responses:
"200":
description: Import result
/api/oauth/cursor/import:
get:
tags: [OAuth]
summary: Get Cursor import status
responses:
"200":
description: Current import status
post:
tags: [OAuth]
summary: Import Cursor OAuth credentials
requestBody:
required: true
content:
application/json:
schema:
type: object
responses:
"200":
description: Credentials imported
/api/oauth/kiro/auto-import:
get:
tags: [OAuth]
summary: Auto-import Kiro OAuth credentials
description: Automatically detects and imports Kiro credentials from local config.
responses:
"200":
description: Import result
/api/oauth/kiro/import:
get:
tags: [OAuth]
summary: Get Kiro import status
responses:
"200":
description: Current import status
post:
tags: [OAuth]
summary: Import Kiro OAuth credentials
requestBody:
required: true
content:
application/json:
schema:
type: object
responses:
"200":
description: Credentials imported
/api/oauth/kiro/social-authorize:
get:
tags: [OAuth]
summary: Initiate Kiro social OAuth authorization
description: Starts the social OAuth flow for Kiro.
responses:
"302":
description: Redirect to OAuth provider
/api/oauth/kiro/social-exchange:
post:
tags: [OAuth]
summary: Exchange Kiro social OAuth token
description: Exchanges the authorization code for access tokens.
requestBody:
required: true
content:
application/json:
schema:
type: object
responses:
"200":
description: Token exchange result
# ─── Cloud ─────────────────────────────────────────────────────
/api/cloud/auth:
post:
tags: [Cloud]
summary: Authenticate with cloud worker
description: Authenticates with the OmniRoute cloud worker for remote access.
requestBody:
required: true
content:
application/json:
schema:
type: object
responses:
"200":
description: Authentication result
/api/cloud/credentials/update:
put:
tags: [Cloud]
summary: Update cloud worker credentials
requestBody:
required: true
content:
application/json:
schema:
type: object
responses:
"200":
description: Credentials updated
/api/cloud/model/resolve:
post:
tags: [Cloud]
summary: Resolve model via cloud
description: Resolves a model request through the cloud worker.
requestBody:
required: true
content:
application/json:
schema:
type: object
responses:
"200":
description: Resolved model info
/api/cloud/models/alias:
get:
tags: [Cloud]
summary: Get cloud model aliases
responses:
"200":
description: Cloud model alias list
put:
tags: [Cloud]
summary: Update cloud model alias
requestBody:
required: true
content:
application/json:
schema:
type: object
responses:
"200":
description: Alias updated
# ─── Fallback ──────────────────────────────────────────────────
/api/fallback/chains:
get:
tags: [Fallback]
summary: List fallback chains
description: Returns all registered fallback chains for model routing.
responses:
"200":
description: Fallback chain list
post:
tags: [Fallback]
summary: Create fallback chain
description: Registers a fallback routing chain for a model.
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [model, chain]
properties:
model:
type: string
chain:
type: array
items:
type: object
properties:
provider:
type: string
priority:
type: integer
enabled:
type: boolean
responses:
"200":
description: Fallback chain created
delete:
tags: [Fallback]
summary: Delete fallback chain
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [model]
properties:
model:
type: string
responses:
"200":
description: Fallback chain deleted
# ─── System ────────────────────────────────────────────────────
/api/auth/login:
@@ -1087,6 +1844,41 @@ paths:
"200":
description: Caches cleared
/api/cache/stats:
get:
tags: [System]
summary: Get detailed cache statistics
description: Returns detailed statistics for all cache layers.
responses:
"200":
description: Detailed cache stats
delete:
tags: [System]
summary: Clear cache statistics
responses:
"200":
description: Cache stats cleared
# ─── Telemetry & Token Health ───────────────────────────────────
/api/telemetry/summary:
get:
tags: [Telemetry]
summary: Get telemetry summary
description: Returns aggregated telemetry data including request metrics and performance stats.
responses:
"200":
description: Telemetry summary data
/api/token-health:
get:
tags: [Telemetry]
summary: Get token health status
description: Returns health status of OAuth tokens across all providers.
responses:
"200":
description: Token health status
# ─── Evals & Policies ──────────────────────────────────────────
/api/evals:
@@ -1109,6 +1901,20 @@ paths:
"200":
description: Eval results
/api/evals/{suiteId}:
get:
tags: [System]
summary: Get eval suite details
parameters:
- name: suiteId
in: path
required: true
schema:
type: string
responses:
"200":
description: Eval suite details
/api/policies:
get:
tags: [System]
@@ -1377,7 +2183,7 @@ components:
type: string
strategy:
type: string
enum: [priority, weighted, round-robin]
enum: [priority, weighted, round-robin, random, least-used, cost-optimized]
default: priority
nodes:
type: array
+1
View File
@@ -22,6 +22,7 @@ const eslintConfig = [
"scripts/**",
"bin/**",
"node_modules/**",
"open-sse/**",
],
},
];
+6
View File
@@ -4,9 +4,15 @@ const nextConfig = {
output: "standalone",
transpilePackages: ["@omniroute/open-sse"],
allowedDevOrigins: ["192.168.*"],
typescript: {
// Migration Phase: ignore TS errors during build.
// Remove after all 984 type errors are resolved.
ignoreBuildErrors: true,
},
images: {
unoptimized: true,
},
// NEXT_PUBLIC_CLOUD_URL is set in .env — do NOT hardcode here (it overrides .env)
webpack: (config, { isServer }) => {
// Ignore fs/path modules in browser bundle
@@ -6,7 +6,22 @@
* - /v1/audio/speech (TTS API)
*/
export const AUDIO_TRANSCRIPTION_PROVIDERS = {
interface AudioModel {
id: string;
name: string;
}
interface AudioProvider {
id: string;
baseUrl: string;
authType: string;
authHeader: string;
format?: string;
async?: boolean;
models: AudioModel[];
}
export const AUDIO_TRANSCRIPTION_PROVIDERS: Record<string, AudioProvider> = {
openai: {
id: "openai",
baseUrl: "https://api.openai.com/v1/audio/transcriptions",
@@ -57,7 +72,7 @@ export const AUDIO_TRANSCRIPTION_PROVIDERS = {
},
};
export const AUDIO_SPEECH_PROVIDERS = {
export const AUDIO_SPEECH_PROVIDERS: Record<string, AudioProvider> = {
openai: {
id: "openai",
baseUrl: "https://api.openai.com/v1/audio/speech",
@@ -96,21 +111,21 @@ export const AUDIO_SPEECH_PROVIDERS = {
/**
* Get transcription provider config by ID
*/
export function getTranscriptionProvider(providerId) {
export function getTranscriptionProvider(providerId: string): AudioProvider | null {
return AUDIO_TRANSCRIPTION_PROVIDERS[providerId] || null;
}
/**
* Get speech provider config by ID
*/
export function getSpeechProvider(providerId) {
export function getSpeechProvider(providerId: string): AudioProvider | null {
return AUDIO_SPEECH_PROVIDERS[providerId] || null;
}
/**
* Parse audio model string (format: "provider/model" or just "model")
*/
function parseAudioModel(modelStr, registry) {
function parseAudioModel(modelStr: string | null, registry: Record<string, AudioProvider>): { provider: string | null; model: string | null } {
if (!modelStr) return { provider: null, model: null };
for (const [providerId, config] of Object.entries(registry)) {
@@ -128,11 +143,11 @@ function parseAudioModel(modelStr, registry) {
return { provider: null, model: modelStr };
}
export function parseTranscriptionModel(modelStr) {
export function parseTranscriptionModel(modelStr: string | null) {
return parseAudioModel(modelStr, AUDIO_TRANSCRIPTION_PROVIDERS);
}
export function parseSpeechModel(modelStr) {
export function parseSpeechModel(modelStr: string | null) {
return parseAudioModel(modelStr, AUDIO_SPEECH_PROVIDERS);
}
@@ -1,4 +1,4 @@
import { loadProviderCredentials } from "./credentialLoader.js";
import { loadProviderCredentials } from "./credentialLoader.ts";
// Timeout for non-streaming fetch requests (ms). Prevents stalled connections.
export const FETCH_TIMEOUT_MS = parseInt(process.env.FETCH_TIMEOUT_MS || "120000", 10);
@@ -9,7 +9,7 @@ export const STREAM_IDLE_TIMEOUT_MS = parseInt(process.env.STREAM_IDLE_TIMEOUT_M
// Provider configurations
// OAuth credentials read from env vars with hardcoded fallbacks for backward compatibility.
// Use provider-credentials.json or env vars to override in production.
import { generateLegacyProviders } from "./providerRegistry.js";
import { generateLegacyProviders } from "./providerRegistry.ts";
export const PROVIDERS = generateLegacyProviders();
@@ -1,4 +1,4 @@
import { generateModels, generateAliasMap } from "./providerRegistry.js";
import { generateModels, generateAliasMap } from "./providerRegistry.ts";
// Provider models - Generated from providerRegistry.js (single source of truth)
export const PROVIDER_MODELS = generateModels();
@@ -6,9 +6,51 @@
* is auto-generated from this registry.
*/
// ── Types ─────────────────────────────────────────────────────────────────
export interface RegistryModel {
id: string;
name: string;
targetFormat?: string;
}
export interface RegistryOAuth {
clientIdEnv?: string;
clientIdDefault?: string;
clientSecretEnv?: string;
clientSecretDefault?: string;
tokenUrl?: string;
refreshUrl?: string;
authUrl?: string;
initiateUrl?: string;
pollUrlBase?: string;
}
export interface RegistryEntry {
id: string;
alias: string;
format: string;
executor: string;
baseUrl?: string;
baseUrls?: string[];
responsesBaseUrl?: string;
urlSuffix?: string;
urlBuilder?: (base: string, model: string, stream: boolean) => string;
authType: string;
authHeader: string;
authPrefix?: string;
headers?: Record<string, string>;
extraHeaders?: Record<string, string>;
oauth?: RegistryOAuth;
models: RegistryModel[];
chatPath?: string;
clientVersion?: string;
passthroughModels?: boolean;
}
// ── Registry ──────────────────────────────────────────────────────────────
export const REGISTRY = {
export const REGISTRY: Record<string, RegistryEntry> = {
// ─── OAuth Providers ───────────────────────────────────────────────────
claude: {
id: "claude",
@@ -760,10 +802,10 @@ export const REGISTRY = {
// ── Generator Functions ───────────────────────────────────────────────────
/** Generate legacy PROVIDERS object shape for constants.js backward compatibility */
export function generateLegacyProviders() {
const providers = {};
export function generateLegacyProviders(): Record<string, any> {
const providers: Record<string, any> = {};
for (const [id, entry] of Object.entries(REGISTRY)) {
const p = { format: entry.format };
const p: Record<string, any> = { format: entry.format };
// URL(s)
if (entry.baseUrls) {
@@ -808,8 +850,8 @@ export function generateLegacyProviders() {
}
/** Generate PROVIDER_MODELS map (alias → model list) */
export function generateModels() {
const models = {};
export function generateModels(): Record<string, RegistryModel[]> {
const models: Record<string, RegistryModel[]> = {};
for (const entry of Object.values(REGISTRY)) {
if (entry.models && entry.models.length > 0) {
const key = entry.alias || entry.id;
@@ -823,8 +865,8 @@ export function generateModels() {
}
/** Generate PROVIDER_ID_TO_ALIAS map */
export function generateAliasMap() {
const map = {};
export function generateAliasMap(): Record<string, string> {
const map: Record<string, string> = {};
for (const entry of Object.values(REGISTRY)) {
map[entry.id] = entry.alias || entry.id;
}
@@ -841,12 +883,12 @@ for (const entry of Object.values(REGISTRY)) {
}
/** Get registry entry by provider ID or alias */
export function getRegistryEntry(provider) {
export function getRegistryEntry(provider: string): RegistryEntry | null {
return REGISTRY[provider] || _byAlias.get(provider) || null;
}
/** Get all registered provider IDs */
export function getRegisteredProviders() {
export function getRegisteredProviders(): string[] {
return Object.keys(REGISTRY);
}
@@ -856,7 +898,7 @@ export function getRegisteredProviders() {
* @param {string} provider - Provider ID or alias
* @returns {"oauth"|"apikey"}
*/
export function getProviderCategory(provider) {
export function getProviderCategory(provider: string): "oauth" | "apikey" {
const entry = getRegistryEntry(provider);
if (!entry) return "apikey"; // Safe default for unknown providers
return entry.authType === "apikey" ? "apikey" : "oauth";
@@ -1,6 +1,6 @@
import crypto from "crypto";
import { BaseExecutor } from "./base.js";
import { PROVIDERS, OAUTH_ENDPOINTS, HTTP_STATUS } from "../config/constants.js";
import { BaseExecutor } from "./base.ts";
import { PROVIDERS, OAUTH_ENDPOINTS, HTTP_STATUS } from "../config/constants.ts";
const MAX_RETRY_AFTER_MS = 10000;
@@ -1,4 +1,4 @@
import { HTTP_STATUS, FETCH_TIMEOUT_MS } from "../config/constants.js";
import { HTTP_STATUS, FETCH_TIMEOUT_MS } from "../config/constants.ts";
/**
* BaseExecutor - Base class for provider executors.
@@ -6,7 +6,10 @@ import { HTTP_STATUS, FETCH_TIMEOUT_MS } from "../config/constants.js";
* (buildUrl, buildHeaders, transformRequest, etc.) for each provider.
*/
export class BaseExecutor {
constructor(provider, config) {
provider: any;
config: any;
constructor(provider: any, config: any) {
this.provider = provider;
this.config = config;
}
@@ -96,7 +99,7 @@ export class BaseExecutor {
? AbortSignal.any([signal, timeoutSignal])
: signal || timeoutSignal;
const fetchOptions = {
const fetchOptions: Record<string, any> = {
method: "POST",
headers,
body: JSON.stringify(transformedBody),
@@ -1,6 +1,6 @@
import { BaseExecutor } from "./base.js";
import { CODEX_DEFAULT_INSTRUCTIONS } from "../config/codexInstructions.js";
import { PROVIDERS } from "../config/constants.js";
import { BaseExecutor } from "./base.ts";
import { CODEX_DEFAULT_INSTRUCTIONS } from "../config/codexInstructions.ts";
import { PROVIDERS } from "../config/constants.ts";
/**
* Codex Executor - handles OpenAI Codex API (Responses API format)
@@ -1,3 +1,4 @@
declare var EdgeRuntime: any;
/**
* CursorExecutor Handles communication with the Cursor IDE API.
*
@@ -19,16 +20,16 @@
* @see cursorProtobuf.js for Protobuf encoding/decoding utilities
*/
import { BaseExecutor } from "./base.js";
import { PROVIDERS, HTTP_STATUS } from "../config/constants.js";
import { BaseExecutor } from "./base.ts";
import { PROVIDERS, HTTP_STATUS } from "../config/constants.ts";
import {
generateCursorBody,
parseConnectRPCFrame,
extractTextFromResponse,
} from "../utils/cursorProtobuf.js";
import { estimateUsage } from "../utils/usageTracking.js";
import { FORMATS } from "../translator/formats.js";
import { buildCursorRequest } from "../translator/request/openai-to-cursor.js";
} from "../utils/cursorProtobuf.ts";
import { estimateUsage } from "../utils/usageTracking.ts";
import { FORMATS } from "../translator/formats.ts";
import { buildCursorRequest } from "../translator/request/openai-to-cursor.ts";
import crypto from "crypto";
import { v5 as uuidv5 } from "uuid";
import zlib from "zlib";
@@ -226,7 +227,7 @@ export class CursorExecutor extends BaseExecutor {
return {
status: response.status,
headers: Object.fromEntries(response.headers.entries()),
headers: Object.fromEntries((response.headers as any).entries()),
body: Buffer.from(await response.arrayBuffer()),
};
}
@@ -290,7 +291,7 @@ export class CursorExecutor extends BaseExecutor {
const transformedBody = this.transformRequest(model, body, stream, credentials);
try {
const response = http2
const response: any = http2
? await this.makeHttp2Request(url, headers, transformedBody, signal)
: await this.makeFetchRequest(url, headers, transformedBody, signal);
@@ -458,8 +459,7 @@ export class CursorExecutor extends BaseExecutor {
console.log(`[CURSOR BUFFER] Final toolCalls count: ${toolCalls.length}`);
const message = {
role: "assistant",
const message: Record<string, any> = { role: "assistant",
content: totalContent || null,
};
@@ -1,6 +1,6 @@
import { BaseExecutor } from "./base.js";
import { PROVIDERS, OAUTH_ENDPOINTS } from "../config/constants.js";
import { getAccessToken } from "../services/tokenRefresh.js";
import { BaseExecutor } from "./base.ts";
import { PROVIDERS, OAUTH_ENDPOINTS } from "../config/constants.ts";
import { getAccessToken } from "../services/tokenRefresh.ts";
export class DefaultExecutor extends BaseExecutor {
constructor(provider) {
@@ -1,5 +1,5 @@
import { BaseExecutor } from "./base.js";
import { PROVIDERS, OAUTH_ENDPOINTS } from "../config/constants.js";
import { BaseExecutor } from "./base.ts";
import { PROVIDERS, OAUTH_ENDPOINTS } from "../config/constants.ts";
export class GeminiCLIExecutor extends BaseExecutor {
constructor() {
@@ -1,6 +1,6 @@
import { BaseExecutor } from "./base.js";
import { PROVIDERS, OAUTH_ENDPOINTS } from "../config/constants.js";
import { getModelTargetFormat } from "../config/providerModels.js";
import { BaseExecutor } from "./base.ts";
import { PROVIDERS, OAUTH_ENDPOINTS } from "../config/constants.ts";
import { getModelTargetFormat } from "../config/providerModels.ts";
export class GithubExecutor extends BaseExecutor {
constructor() {
-38
View File
@@ -1,38 +0,0 @@
import { AntigravityExecutor } from "./antigravity.js";
import { GeminiCLIExecutor } from "./gemini-cli.js";
import { GithubExecutor } from "./github.js";
import { KiroExecutor } from "./kiro.js";
import { CodexExecutor } from "./codex.js";
import { CursorExecutor } from "./cursor.js";
import { DefaultExecutor } from "./default.js";
const executors = {
antigravity: new AntigravityExecutor(),
"gemini-cli": new GeminiCLIExecutor(),
github: new GithubExecutor(),
kiro: new KiroExecutor(),
codex: new CodexExecutor(),
cursor: new CursorExecutor(),
cu: new CursorExecutor(), // Alias for cursor
};
const defaultCache = new Map();
export function getExecutor(provider) {
if (executors[provider]) return executors[provider];
if (!defaultCache.has(provider)) defaultCache.set(provider, new DefaultExecutor(provider));
return defaultCache.get(provider);
}
export function hasSpecializedExecutor(provider) {
return !!executors[provider];
}
export { BaseExecutor } from "./base.js";
export { AntigravityExecutor } from "./antigravity.js";
export { GeminiCLIExecutor } from "./gemini-cli.js";
export { GithubExecutor } from "./github.js";
export { KiroExecutor } from "./kiro.js";
export { CodexExecutor } from "./codex.js";
export { CursorExecutor } from "./cursor.js";
export { DefaultExecutor } from "./default.js";
+38
View File
@@ -0,0 +1,38 @@
import { AntigravityExecutor } from "./antigravity.ts";
import { GeminiCLIExecutor } from "./gemini-cli.ts";
import { GithubExecutor } from "./github.ts";
import { KiroExecutor } from "./kiro.ts";
import { CodexExecutor } from "./codex.ts";
import { CursorExecutor } from "./cursor.ts";
import { DefaultExecutor } from "./default.ts";
const executors = {
antigravity: new AntigravityExecutor(),
"gemini-cli": new GeminiCLIExecutor(),
github: new GithubExecutor(),
kiro: new KiroExecutor(),
codex: new CodexExecutor(),
cursor: new CursorExecutor(),
cu: new CursorExecutor(), // Alias for cursor
};
const defaultCache = new Map();
export function getExecutor(provider) {
if (executors[provider]) return executors[provider];
if (!defaultCache.has(provider)) defaultCache.set(provider, new DefaultExecutor(provider));
return defaultCache.get(provider);
}
export function hasSpecializedExecutor(provider) {
return !!executors[provider];
}
export { BaseExecutor } from "./base.ts";
export { AntigravityExecutor } from "./antigravity.ts";
export { GeminiCLIExecutor } from "./gemini-cli.ts";
export { GithubExecutor } from "./github.ts";
export { KiroExecutor } from "./kiro.ts";
export { CodexExecutor } from "./codex.ts";
export { CursorExecutor } from "./cursor.ts";
export { DefaultExecutor } from "./default.ts";
@@ -1,7 +1,7 @@
import { BaseExecutor } from "./base.js";
import { PROVIDERS } from "../config/constants.js";
import { BaseExecutor } from "./base.ts";
import { PROVIDERS } from "../config/constants.ts";
import { v4 as uuidv4 } from "uuid";
import { refreshKiroToken } from "../services/tokenRefresh.js";
import { refreshKiroToken } from "../services/tokenRefresh.ts";
// ── CRC32 lookup table (IEEE polynomial, no dependency) ──
const CRC32_TABLE = new Uint32Array(256);
@@ -83,8 +83,7 @@ export class KiroExecutor extends BaseExecutor {
let chunkIndex = 0;
const responseId = `chatcmpl-${Date.now()}`;
const created = Math.floor(Date.now() / 1000);
const state = {
endDetected: false,
const state: Record<string, any> = { endDetected: false,
finishEmitted: false,
hasToolCalls: false,
toolCallIndex: 0,
@@ -126,7 +125,7 @@ export class KiroExecutor extends BaseExecutor {
const content = event.payload.content;
state.totalContentLength += content.length;
const chunk = {
const chunk: Record<string, any> = {
id: responseId,
object: "chat.completion.chunk",
created,
@@ -145,7 +144,7 @@ export class KiroExecutor extends BaseExecutor {
// Handle codeEvent
if (eventType === "codeEvent" && event.payload?.content) {
const chunk = {
const chunk: Record<string, any> = {
id: responseId,
object: "chat.completion.chunk",
created,
@@ -257,7 +256,7 @@ export class KiroExecutor extends BaseExecutor {
// Handle messageStopEvent
if (eventType === "messageStopEvent") {
const chunk = {
const chunk: Record<string, any> = {
id: responseId,
object: "chat.completion.chunk",
created,
@@ -330,7 +329,7 @@ export class KiroExecutor extends BaseExecutor {
};
}
const finishChunk = {
const finishChunk: Record<string, any> = {
id: responseId,
object: "chat.completion.chunk",
created,
@@ -10,8 +10,8 @@
* - Deepgram: POST { text } with model via query param, Token auth
*/
import { getSpeechProvider, parseSpeechModel } from "../config/audioRegistry.js";
import { errorResponse } from "../utils/error.js";
import { getSpeechProvider, parseSpeechModel } from "../config/audioRegistry.ts";
import { errorResponse } from "../utils/error.ts";
/**
* Build auth header for a speech provider
@@ -100,12 +100,13 @@ async function handleDeepgramSpeech(providerConfig, body, modelId, token) {
* @param {Object} options.credentials - Provider credentials { apiKey }
* @returns {Response}
*/
/** @returns {Promise<any>} */
export async function handleAudioSpeech({ body, credentials }) {
if (!body.model) {
return errorResponse("model is required", 400);
return errorResponse(400, "model is required");
}
if (!body.input) {
return errorResponse("input is required", 400);
return errorResponse(400, "input is required");
}
const { provider: providerId, model: modelId } = parseSpeechModel(body.model);
@@ -113,14 +114,14 @@ export async function handleAudioSpeech({ body, credentials }) {
if (!providerConfig) {
return errorResponse(
`No speech provider found for model "${body.model}". Available: openai, hyperbolic, deepgram`,
400
400,
`No speech provider found for model "${body.model}". Available: openai, hyperbolic, deepgram`
);
}
const token = credentials?.apiKey || credentials?.accessToken;
if (!token) {
return errorResponse(`No credentials for speech provider: ${providerId}`, 401);
return errorResponse(401, `No credentials for speech provider: ${providerId}`);
}
try {
@@ -168,6 +169,6 @@ export async function handleAudioSpeech({ body, credentials }) {
},
});
} catch (err) {
return errorResponse(`Speech request failed: ${err.message}`, 500);
return errorResponse(500, `Speech request failed: ${err.message}`);
}
}
@@ -10,8 +10,8 @@
* - AssemblyAI: async workflow (upload submit poll)
*/
import { getTranscriptionProvider, parseTranscriptionModel } from "../config/audioRegistry.js";
import { errorResponse } from "../utils/error.js";
import { getTranscriptionProvider, parseTranscriptionModel } from "../config/audioRegistry.ts";
import { errorResponse } from "../utils/error.ts";
/**
* Build auth header for a transcription provider
@@ -129,11 +129,11 @@ async function handleAssemblyAITranscription(providerConfig, file, modelId, toke
}
if (result.status === "error") {
return errorResponse(result.error || "AssemblyAI transcription failed", 500);
return errorResponse(500, result.error || "AssemblyAI transcription failed");
}
}
return errorResponse("AssemblyAI transcription timed out after 120s", 504);
return errorResponse(504, "AssemblyAI transcription timed out after 120s");
}
/**
@@ -144,15 +144,16 @@ async function handleAssemblyAITranscription(providerConfig, file, modelId, toke
* @param {Object} options.credentials - Provider credentials { apiKey }
* @returns {Response}
*/
/** @returns {Promise<any>} */
export async function handleAudioTranscription({ formData, credentials }) {
const model = formData.get("model");
if (!model) {
return errorResponse("model is required", 400);
return errorResponse(400, "model is required");
}
const file = formData.get("file");
if (!file) {
return errorResponse("file is required", 400);
return errorResponse(400, "file is required");
}
const { provider: providerId, model: modelId } = parseTranscriptionModel(model);
@@ -160,14 +161,14 @@ export async function handleAudioTranscription({ formData, credentials }) {
if (!providerConfig) {
return errorResponse(
`No transcription provider found for model "${model}". Available: openai, groq, deepgram, assemblyai`,
400
400,
`No transcription provider found for model "${model}". Available: openai, groq, deepgram, assemblyai`
);
}
const token = credentials?.apiKey || credentials?.accessToken;
if (!token) {
return errorResponse(`No credentials for transcription provider: ${providerId}`, 401);
return errorResponse(401, `No credentials for transcription provider: ${providerId}`);
}
// Route to provider-specific handler
@@ -181,7 +182,7 @@ export async function handleAudioTranscription({ formData, credentials }) {
// Default: OpenAI/Groq-compatible multipart proxy
const upstreamForm = new FormData();
upstreamForm.append("file", file, file.name || "audio.wav");
upstreamForm.append("file", /** @type {Blob} */ (file), /** @type {any} */ (file).name || "audio.wav");
upstreamForm.append("model", modelId);
// Forward optional parameters
@@ -194,7 +195,7 @@ export async function handleAudioTranscription({ formData, credentials }) {
]) {
const val = formData.get(key);
if (val !== null && val !== undefined) {
upstreamForm.append(key, val);
upstreamForm.append(key, /** @type {string} */ (val));
}
}
@@ -221,6 +222,6 @@ export async function handleAudioTranscription({ formData, credentials }) {
headers: { "Content-Type": contentType, "Access-Control-Allow-Origin": "*" },
});
} catch (err) {
return errorResponse(`Transcription request failed: ${err.message}`, 500);
return errorResponse(500, `Transcription request failed: ${err.message}`);
}
}
@@ -1,42 +1,42 @@
import { detectFormat, getTargetFormat } from "../services/provider.js";
import { translateRequest, needsTranslation } from "../translator/index.js";
import { FORMATS } from "../translator/formats.js";
import { detectFormat, getTargetFormat } from "../services/provider.ts";
import { translateRequest, needsTranslation } from "../translator/index.ts";
import { FORMATS } from "../translator/formats.ts";
import {
createSSETransformStreamWithLogger,
createPassthroughStreamWithLogger,
COLORS,
} from "../utils/stream.js";
import { createStreamController, pipeWithDisconnect } from "../utils/streamHandler.js";
import { addBufferToUsage, filterUsageForFormat, estimateUsage } from "../utils/usageTracking.js";
import { refreshWithRetry } from "../services/tokenRefresh.js";
import { createRequestLogger } from "../utils/requestLogger.js";
import { getModelTargetFormat, PROVIDER_ID_TO_ALIAS } from "../config/providerModels.js";
import { createErrorResult, parseUpstreamError, formatProviderError } from "../utils/error.js";
import { HTTP_STATUS } from "../config/constants.js";
import { handleBypassRequest } from "../utils/bypassHandler.js";
} from "../utils/stream.ts";
import { createStreamController, pipeWithDisconnect } from "../utils/streamHandler.ts";
import { addBufferToUsage, filterUsageForFormat, estimateUsage } from "../utils/usageTracking.ts";
import { refreshWithRetry } from "../services/tokenRefresh.ts";
import { createRequestLogger } from "../utils/requestLogger.ts";
import { getModelTargetFormat, PROVIDER_ID_TO_ALIAS } from "../config/providerModels.ts";
import { createErrorResult, parseUpstreamError, formatProviderError } from "../utils/error.ts";
import { HTTP_STATUS } from "../config/constants.ts";
import { handleBypassRequest } from "../utils/bypassHandler.ts";
import {
saveRequestUsage,
trackPendingRequest,
appendRequestLog,
saveCallLog,
} from "@/lib/usageDb.js";
import { getExecutor } from "../executors/index.js";
import { translateNonStreamingResponse } from "./responseTranslator.js";
import { extractUsageFromResponse } from "./usageExtractor.js";
import { parseSSEToOpenAIResponse, parseSSEToResponsesOutput } from "./sseParser.js";
} from "@/lib/usageDb";
import { getExecutor } from "../executors/index.ts";
import { translateNonStreamingResponse } from "./responseTranslator.ts";
import { extractUsageFromResponse } from "./usageExtractor.ts";
import { parseSSEToOpenAIResponse, parseSSEToResponsesOutput } from "./sseParser.ts";
import {
withRateLimit,
updateFromHeaders,
initializeRateLimits,
} from "../services/rateLimitManager.js";
} from "../services/rateLimitManager.ts";
import {
generateSignature,
getCachedResponse,
setCachedResponse,
isCacheable,
} from "@/lib/semanticCache.js";
import { getIdempotencyKey, checkIdempotency, saveIdempotency } from "@/lib/idempotencyLayer.js";
import { createProgressTransform, wantsProgress } from "../utils/progressTracker.js";
} from "@/lib/semanticCache";
import { getIdempotencyKey, checkIdempotency, saveIdempotency } from "@/lib/idempotencyLayer";
import { createProgressTransform, wantsProgress } from "../utils/progressTracker.ts";
/**
* Core chat handler - shared between SSE and Worker
@@ -52,6 +52,7 @@ import { createProgressTransform, wantsProgress } from "../utils/progressTracker
* @param {string} options.connectionId - Connection ID for usage tracking
* @param {object} options.apiKeyInfo - API key metadata for usage attribution
*/
/** @param {any} options */
export async function handleChatCore({
body,
modelInfo,
@@ -13,8 +13,8 @@
* }
*/
import { getEmbeddingProvider, parseEmbeddingModel } from "../config/embeddingRegistry.js";
import { saveCallLog } from "@/lib/usageDb.js";
import { getEmbeddingProvider, parseEmbeddingModel } from "../config/embeddingRegistry.ts";
import { saveCallLog } from "@/lib/usageDb";
/**
* Handle embedding request
@@ -52,7 +52,7 @@ export async function handleEmbedding({ body, credentials, log }) {
}
// Build upstream request
const upstreamBody = {
const upstreamBody: Record<string, any> = {
model: model,
input: body.input,
};
@@ -15,8 +15,8 @@
* }
*/
import { getImageProvider, parseImageModel } from "../config/imageRegistry.js";
import { saveCallLog } from "@/lib/usageDb.js";
import { getImageProvider, parseImageModel } from "../config/imageRegistry.ts";
import { saveCallLog } from "@/lib/usageDb";
/**
* Handle image generation request
@@ -232,7 +232,7 @@ async function handleOpenAIImageGeneration({
};
// Build upstream request (OpenAI-compatible format)
const upstreamBody = {
const upstreamBody: Record<string, any> = {
model: model,
prompt: body.prompt,
};
@@ -4,8 +4,8 @@
* Handles POST /v1/moderations (OpenAI Moderations API format).
*/
import { getModerationProvider, parseModerationModel } from "../config/moderationRegistry.js";
import { errorResponse } from "../utils/error.js";
import { getModerationProvider, parseModerationModel } from "../config/moderationRegistry.ts";
import { errorResponse } from "../utils/error.ts";
/**
* Handle moderation request
@@ -15,9 +15,10 @@ import { errorResponse } from "../utils/error.js";
* @param {Object} options.credentials - Provider credentials { apiKey }
* @returns {Response}
*/
/** @returns {Promise<any>} */
export async function handleModeration({ body, credentials }) {
if (!body.input) {
return errorResponse("input is required", 400);
return errorResponse(400, "input is required");
}
// Default to latest moderation model
@@ -27,14 +28,14 @@ export async function handleModeration({ body, credentials }) {
if (!providerConfig) {
return errorResponse(
`No moderation provider found for model "${model}". Available: openai`,
400
400,
`No moderation provider found for model "${model}". Available: openai`
);
}
const token = credentials?.apiKey || credentials?.accessToken;
if (!token) {
return errorResponse(`No credentials for moderation provider: ${providerId}`, 401);
return errorResponse(401, `No credentials for moderation provider: ${providerId}`);
}
try {
@@ -63,6 +64,6 @@ export async function handleModeration({ body, credentials }) {
headers: { "Access-Control-Allow-Origin": "*" },
});
} catch (err) {
return errorResponse(`Moderation request failed: ${err.message}`, 500);
return errorResponse(500, `Moderation request failed: ${err.message}`);
}
}
@@ -5,8 +5,8 @@
* Routes to the appropriate provider based on the model prefix or lookup.
*/
import { getRerankProvider, parseRerankModel } from "../config/rerankRegistry.js";
import { errorResponse } from "../utils/error.js";
import { getRerankProvider, parseRerankModel } from "../config/rerankRegistry.ts";
import { errorResponse } from "../utils/error.ts";
/**
* Build authorization header for a rerank provider
@@ -69,6 +69,7 @@ function transformResponseFromProvider(providerConfig, data) {
* @param {Object} options.credentials - Provider credentials { apiKey, accessToken }
* @returns {Response}
*/
/** @returns {Promise<any>} */
export async function handleRerank({
model,
query,
@@ -77,10 +78,10 @@ export async function handleRerank({
return_documents,
credentials,
}) {
if (!model) return errorResponse("model is required", 400);
if (!query) return errorResponse("query is required", 400);
if (!model) return errorResponse(400, "model is required");
if (!query) return errorResponse(400, "query is required");
if (!documents || !Array.isArray(documents) || documents.length === 0) {
return errorResponse("documents must be a non-empty array", 400);
return errorResponse(400, "documents must be a non-empty array");
}
const { provider: providerId, model: modelId } = parseRerankModel(model);
@@ -88,14 +89,14 @@ export async function handleRerank({
if (!providerConfig) {
return errorResponse(
`No rerank provider found for model "${model}". Available: cohere, together, nvidia, fireworks`,
400
400,
`No rerank provider found for model "${model}". Available: cohere, together, nvidia, fireworks`
);
}
const token = credentials?.apiKey || credentials?.accessToken;
if (!token) {
return errorResponse(`No credentials for rerank provider: ${providerId}`, 401);
return errorResponse(401, `No credentials for rerank provider: ${providerId}`);
}
const requestBody = transformRequestForProvider(providerConfig, {
@@ -119,8 +120,8 @@ export async function handleRerank({
if (!res.ok) {
const errData = await res.json().catch(() => ({}));
return errorResponse(
errData.message || errData.error?.message || `Provider returned HTTP ${res.status}`,
res.status
res.status,
errData.message || errData.error?.message || `Provider returned HTTP ${res.status}`
);
}
@@ -131,6 +132,6 @@ export async function handleRerank({
headers: { "Access-Control-Allow-Origin": "*" },
});
} catch (err) {
return errorResponse(`Rerank request failed: ${err.message}`, 500);
return errorResponse(500, `Rerank request failed: ${err.message}`);
}
}
@@ -1,4 +1,4 @@
import { FORMATS } from "../translator/formats.js";
import { FORMATS } from "../translator/formats.ts";
/**
* Translate non-streaming response to OpenAI format
@@ -56,7 +56,7 @@ export function translateNonStreamingResponse(responseBody, targetFormat, source
}
}
const message = { role: "assistant" };
const message: Record<string, any> = { role: "assistant" };
if (textContent) {
message.content = textContent;
}
@@ -74,7 +74,7 @@ export function translateNonStreamingResponse(responseBody, targetFormat, source
const model = response?.model || responseBody?.model || "openai-responses";
const finishReason = toolCalls.length > 0 ? "tool_calls" : "stop";
const result = {
const result: Record<string, any> = {
id: `chatcmpl-${response?.id || Date.now()}`,
object: "chat.completion",
created: createdAt,
@@ -162,7 +162,7 @@ export function translateNonStreamingResponse(responseBody, targetFormat, source
}
// Build OpenAI format message
const message = { role: "assistant" };
const message: Record<string, any> = { role: "assistant" };
if (textContent) {
message.content = textContent;
}
@@ -183,7 +183,7 @@ export function translateNonStreamingResponse(responseBody, targetFormat, source
finishReason = "tool_calls";
}
const result = {
const result: Record<string, any> = {
id: `chatcmpl-${response.responseId || Date.now()}`,
object: "chat.completion",
created: Math.floor(new Date(response.createTime || Date.now()).getTime() / 1000),
@@ -241,7 +241,7 @@ export function translateNonStreamingResponse(responseBody, targetFormat, source
}
}
const message = { role: "assistant" };
const message: Record<string, any> = { role: "assistant" };
if (textContent) {
message.content = textContent;
}
@@ -259,7 +259,7 @@ export function translateNonStreamingResponse(responseBody, targetFormat, source
if (finishReason === "end_turn") finishReason = "stop";
if (finishReason === "tool_use") finishReason = "tool_calls";
const result = {
const result: Record<string, any> = {
id: `chatcmpl-${responseBody.id || Date.now()}`,
object: "chat.completion",
created: Math.floor(Date.now() / 1000),
@@ -3,9 +3,9 @@
* Converts Chat Completions to Codex Responses API format
*/
import { handleChatCore } from "./chatCore.js";
import { convertResponsesApiFormat } from "../translator/helpers/responsesApiHelper.js";
import { createResponsesApiTransformStream } from "../transformer/responsesTransformer.js";
import { handleChatCore } from "./chatCore.ts";
import { convertResponsesApiFormat } from "../translator/helpers/responsesApiHelper.ts";
import { createResponsesApiTransformStream } from "../transformer/responsesTransformer.ts";
/**
* Handle /v1/responses request
@@ -45,8 +45,11 @@ export async function handleResponsesCore({
onCredentialsRefreshed,
onRequestSuccess,
onDisconnect,
clientRawRequest: null,
connectionId,
});
userAgent: null,
comboName: null,
} as any);
if (!result.success || !result.response) {
return result;
@@ -44,15 +44,14 @@ export function parseSSEToOpenAIResponse(rawSSE, fallbackModel) {
}
}
const message = {
role: "assistant",
const message: Record<string, any> = { role: "assistant",
content: contentParts.join(""),
};
if (reasoningParts.length > 0) {
message.reasoning_content = reasoningParts.join("");
}
const result = {
const result: Record<string, any> = {
id: first.id || `chatcmpl-${Date.now()}`,
object: "chat.completion",
created: first.created || Math.floor(Date.now() / 1000),
+26 -26
View File
@@ -1,5 +1,5 @@
// Patch global fetch with proxy support (must be first)
import "./utils/proxyFetch.js";
import "./utils/proxyFetch.ts";
// Config
export {
@@ -10,7 +10,7 @@ export {
CLAUDE_SYSTEM_PROMPT,
COOLDOWN_MS,
BACKOFF_CONFIG,
} from "./config/constants.js";
} from "./config/constants.ts";
export {
PROVIDER_MODELS,
getProviderModels,
@@ -20,10 +20,10 @@ export {
getModelTargetFormat,
PROVIDER_ID_TO_ALIAS,
getModelsByProviderId,
} from "./config/providerModels.js";
} from "./config/providerModels.ts";
// Translator
export { FORMATS } from "./translator/formats.js";
export { FORMATS } from "./translator/formats.ts";
export {
register,
translateRequest,
@@ -31,7 +31,7 @@ export {
needsTranslation,
initState,
initTranslators,
} from "./translator/index.js";
} from "./translator/index.ts";
// Services
export {
@@ -40,16 +40,16 @@ export {
buildProviderUrl,
buildProviderHeaders,
getTargetFormat,
} from "./services/provider.js";
} from "./services/provider.ts";
export { parseModel, resolveModelAliasFromMap, getModelInfoCore } from "./services/model.js";
export { parseModel, resolveModelAliasFromMap, getModelInfoCore } from "./services/model.ts";
export {
checkFallbackError,
isAccountUnavailable,
getUnavailableUntil,
filterAvailableAccounts,
} from "./services/accountFallback.js";
} from "./services/accountFallback.ts";
export {
TOKEN_EXPIRY_BUFFER_MS,
@@ -63,43 +63,43 @@ export {
refreshCopilotToken,
getAccessToken,
refreshTokenByProvider,
} from "./services/tokenRefresh.js";
} from "./services/tokenRefresh.ts";
// Handlers
export { handleChatCore, isTokenExpiringSoon } from "./handlers/chatCore.js";
export { handleChatCore, isTokenExpiringSoon } from "./handlers/chatCore.ts";
export {
createStreamController,
pipeWithDisconnect,
createDisconnectAwareStream,
} from "./utils/streamHandler.js";
} from "./utils/streamHandler.ts";
// Executors
export { getExecutor, hasSpecializedExecutor } from "./executors/index.js";
export { getExecutor, hasSpecializedExecutor } from "./executors/index.ts";
// Utils
export { errorResponse, formatProviderError } from "./utils/error.js";
export { errorResponse, formatProviderError } from "./utils/error.ts";
export {
createSSETransformStreamWithLogger,
createPassthroughStreamWithLogger,
} from "./utils/stream.js";
} from "./utils/stream.ts";
// Embeddings
export { handleEmbedding } from "./handlers/embeddings.js";
export { handleEmbedding } from "./handlers/embeddings.ts";
export {
EMBEDDING_PROVIDERS,
getEmbeddingProvider,
parseEmbeddingModel,
getAllEmbeddingModels,
} from "./config/embeddingRegistry.js";
} from "./config/embeddingRegistry.ts";
// Image Generation
export { handleImageGeneration } from "./handlers/imageGeneration.js";
export { handleImageGeneration } from "./handlers/imageGeneration.ts";
export {
IMAGE_PROVIDERS,
getImageProvider,
parseImageModel,
getAllImageModels,
} from "./config/imageRegistry.js";
} from "./config/imageRegistry.ts";
// Think Tag Parser
export {
@@ -107,20 +107,20 @@ export {
extractThinkTags,
processStreamingThinkDelta,
flushThinkBuffer,
} from "./utils/thinkTagParser.js";
} from "./utils/thinkTagParser.ts";
// Rerank
export { handleRerank } from "./handlers/rerank.js";
export { handleRerank } from "./handlers/rerank.ts";
export {
RERANK_PROVIDERS,
getRerankProvider,
parseRerankModel,
getAllRerankModels,
} from "./config/rerankRegistry.js";
} from "./config/rerankRegistry.ts";
// Audio (Transcription + Speech)
export { handleAudioTranscription } from "./handlers/audioTranscription.js";
export { handleAudioSpeech } from "./handlers/audioSpeech.js";
export { handleAudioTranscription } from "./handlers/audioTranscription.ts";
export { handleAudioSpeech } from "./handlers/audioSpeech.ts";
export {
AUDIO_TRANSCRIPTION_PROVIDERS,
AUDIO_SPEECH_PROVIDERS,
@@ -129,13 +129,13 @@ export {
parseTranscriptionModel,
parseSpeechModel,
getAllAudioModels,
} from "./config/audioRegistry.js";
} from "./config/audioRegistry.ts";
// Moderations
export { handleModeration } from "./handlers/moderations.js";
export { handleModeration } from "./handlers/moderations.ts";
export {
MODERATION_PROVIDERS,
getModerationProvider,
parseModerationModel,
getAllModerationModels,
} from "./config/moderationRegistry.js";
} from "./config/moderationRegistry.ts";
@@ -5,8 +5,8 @@ import {
RateLimitReason,
HTTP_STATUS,
PROVIDER_PROFILES,
} from "../config/constants.js";
import { getProviderCategory } from "../config/providerRegistry.js";
} from "../config/constants.ts";
import { getProviderCategory } from "../config/providerRegistry.ts";
// ─── Provider Profile Helper ────────────────────────────────────────────────
@@ -504,7 +504,7 @@ export function applyErrorState(account, status, errorText, provider = null) {
* @param {object} account
* @returns {number} score 0 = unhealthy, 100 = perfectly healthy
*/
export function getAccountHealth(account) {
export function getAccountHealth(account, model?: any) {
if (!account) return 0;
let score = 100;
score -= (account.backoffLevel || 0) * 10;
@@ -5,7 +5,7 @@
* Uses account health scores from accountFallback.js.
*/
import { getAccountHealth } from "./accountFallback.js";
import { getAccountHealth } from "./accountFallback.ts";
/**
* P2C selection: pick 2 random candidates, return the healthier one.
@@ -43,7 +43,7 @@ export function selectAccountP2C(accounts, model = null) {
* @param {string} [model] - Model name
* @returns {{ account: object|null, state: object }}
*/
export function selectAccount(accounts, strategy = "fill-first", state = {}, model = null) {
export function selectAccount(accounts, strategy = "fill-first", state: any = {}, model = null) {
if (!accounts || accounts.length === 0) {
return { account: null, state };
}
@@ -1,15 +1,15 @@
/**
* Shared combo (model combo) handling with fallback support
* Supports: priority (sequential), weighted (probabilistic), and round-robin (circular) strategies
* Supports: priority, weighted, round-robin, random, least-used, and cost-optimized strategies
*/
import { checkFallbackError, formatRetryAfter, getProviderProfile } from "./accountFallback.js";
import { unavailableResponse } from "../utils/error.js";
import { recordComboRequest } from "./comboMetrics.js";
import { resolveComboConfig, getDefaultComboConfig } from "./comboConfig.js";
import * as semaphore from "./rateLimitSemaphore.js";
import { getCircuitBreaker } from "../../src/shared/utils/circuitBreaker.js";
import { parseModel } from "./model.js";
import { checkFallbackError, formatRetryAfter, getProviderProfile } from "./accountFallback.ts";
import { unavailableResponse } from "../utils/error.ts";
import { recordComboRequest, getComboMetrics } from "./comboMetrics.ts";
import { resolveComboConfig, getDefaultComboConfig } from "./comboConfig.ts";
import * as semaphore from "./rateLimitSemaphore.ts";
import { getCircuitBreaker } from "../../src/shared/utils/circuitBreaker";
import { parseModel } from "./model.ts";
// Status codes that should mark semaphore + record circuit breaker failures
const TRANSIENT_FOR_BREAKER = [429, 502, 503, 504];
@@ -150,9 +150,69 @@ function orderModelsForWeightedFallback(models, selectedModel) {
return [selected, ...rest].filter(Boolean).map((e) => e.model);
}
/**
* Fisher-Yates shuffle (in-place)
* @param {Array} arr
* @returns {Array} The shuffled array
*/
function shuffleArray(arr) {
for (let i = arr.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[arr[i], arr[j]] = [arr[j], arr[i]];
}
return arr;
}
/**
* Sort models by pricing (cheapest first) for cost-optimized strategy
* @param {Array<string>} models - Model strings in "provider/model" format
* @returns {Promise<Array<string>>} Sorted model strings
*/
async function sortModelsByCost(models) {
try {
const { getPricingForModel } = await import("../../src/lib/localDb");
const withCost = await Promise.all(
models.map(async (modelStr) => {
const parsed = parseModel(modelStr);
const provider = parsed.provider || parsed.providerAlias || "unknown";
const model = parsed.model || modelStr;
try {
const pricing = await getPricingForModel(provider, model);
return { modelStr, cost: pricing?.input ?? Infinity };
} catch {
return { modelStr, cost: Infinity };
}
})
);
withCost.sort((a, b) => a.cost - b.cost);
return withCost.map((e) => e.modelStr);
} catch {
// If pricing lookup fails entirely, return original order
return models;
}
}
/**
* Sort models by usage count (least-used first) for least-used strategy
* @param {Array<string>} models - Model strings
* @param {string} comboName - Combo name for metrics lookup
* @returns {Array<string>} Sorted model strings
*/
function sortModelsByUsage(models, comboName) {
const metrics = getComboMetrics(comboName);
if (!metrics || !metrics.byModel) return models;
const withUsage = models.map((modelStr) => ({
modelStr,
requests: metrics.byModel[modelStr]?.requests ?? 0,
}));
withUsage.sort((a, b) => a.requests - b.requests);
return withUsage.map((e) => e.modelStr);
}
/**
* Handle combo chat with fallback
* Supports priority (sequential) and weighted (probabilistic) strategies
* Supports all 6 strategies: priority, weighted, round-robin, random, least-used, cost-optimized
* @param {Object} options
* @param {Object} options.body - Request body
* @param {Object} options.combo - Full combo object { name, models, strategy, config }
@@ -161,6 +221,7 @@ function orderModelsForWeightedFallback(models, selectedModel) {
* @param {Object} options.log - Logger object
* @returns {Promise<Response>}
*/
/** @param {any} options */
export async function handleComboChat({
body,
combo,
@@ -215,7 +276,7 @@ export async function handleComboChat({
);
} else {
orderedModels = flatModels;
log.info("COMBO", `Priority with nested resolution: ${orderedModels.length} total models`);
log.info("COMBO", `${strategy} with nested resolution: ${orderedModels.length} total models`);
}
} else if (strategy === "weighted") {
const selected = selectWeightedModel(models);
@@ -225,6 +286,18 @@ export async function handleComboChat({
orderedModels = models.map((m) => normalizeModelEntry(m).model);
}
// Apply strategy-specific ordering
if (strategy === "random") {
orderedModels = shuffleArray([...orderedModels]);
log.info("COMBO", `Random shuffle: ${orderedModels.length} models`);
} else if (strategy === "least-used") {
orderedModels = sortModelsByUsage(orderedModels, combo.name);
log.info("COMBO", `Least-used ordering: ${orderedModels[0]} has fewest requests`);
} else if (strategy === "cost-optimized") {
orderedModels = await sortModelsByCost(orderedModels);
log.info("COMBO", `Cost-optimized ordering: cheapest first (${orderedModels[0]})`);
}
let lastError = null;
let earliestRetryAfter = null;
let lastStatus = null;
@@ -27,7 +27,7 @@ const DEFAULT_COMBO_CONFIG = {
* @param {string} [provider] - Optional provider to apply provider-level overrides
* @returns {Object} Resolved config
*/
export function resolveComboConfig(combo, settings, provider) {
export function resolveComboConfig(combo, settings, provider?: any) {
const global = settings?.comboDefaults || {};
const providerOverride = provider ? settings?.providerOverrides?.[provider] || {} : {};
const comboConfig = combo?.config || {};
@@ -35,7 +35,7 @@ export function recordComboRequest(
});
}
const combo = metrics.get(comboName);
const combo: any = metrics.get(comboName);
combo.totalRequests++;
combo.totalLatencyMs += latencyMs;
combo.totalFallbacks += fallbackCount;
@@ -81,7 +81,7 @@ export function recordComboRequest(
* @returns {Object|null}
*/
export function getComboMetrics(comboName) {
const combo = metrics.get(comboName);
const combo: any = metrics.get(comboName);
if (!combo) return null;
return {
@@ -93,7 +93,7 @@ export function getComboMetrics(comboName) {
fallbackRate:
combo.totalRequests > 0 ? Math.round((combo.totalFallbacks / combo.totalRequests) * 100) : 0,
byModel: Object.fromEntries(
Object.entries(combo.byModel).map(([model, m]) => [
Object.entries(combo.byModel).map(([model, m]: [string, any]) => [
model,
{
...m,
@@ -110,7 +110,7 @@ export function getComboMetrics(comboName) {
* @returns {Object} Map of comboName metrics
*/
export function getAllComboMetrics() {
const result = {};
const result: Record<string, any> = {};
for (const [name] of metrics) {
result[name] = getComboMetrics(name);
}
@@ -51,7 +51,7 @@ export function getTokenLimit(provider, model = null) {
* @param {object} options - { provider?, model?, maxTokens?, reserveTokens? }
* @returns {{ body: object, compressed: boolean, stats: object }}
*/
export function compressContext(body, options = {}) {
export function compressContext(body, options: any = {}) {
if (!body || !body.messages || !Array.isArray(body.messages)) {
return { body, compressed: false, stats: {} };
}
@@ -1,4 +1,4 @@
import { PROVIDER_ID_TO_ALIAS, PROVIDER_MODELS } from "../config/providerModels.js";
import { PROVIDER_ID_TO_ALIAS, PROVIDER_MODELS } from "../config/providerModels.ts";
// Derive alias→provider mapping from the single source of truth (PROVIDER_ID_TO_ALIAS)
// This prevents the two maps from drifting out of sync
@@ -1,5 +1,5 @@
import { PROVIDERS } from "../config/constants.js";
import { getRegistryEntry } from "../config/providerRegistry.js";
import { PROVIDERS } from "../config/constants.ts";
import { getRegistryEntry } from "../config/providerRegistry.ts";
const OPENAI_COMPATIBLE_PREFIX = "openai-compatible-";
const OPENAI_COMPATIBLE_DEFAULTS = {
@@ -156,7 +156,7 @@ export function getProviderFallbackCount(provider) {
}
// Build provider URL
export function buildProviderUrl(provider, model, stream = true, options = {}) {
export function buildProviderUrl(provider, model, stream = true, options: any = {}) {
if (isOpenAICompatible(provider)) {
const apiType = getOpenAICompatibleType(provider);
const baseUrl = options?.baseUrl || OPENAI_COMPATIBLE_DEFAULTS.baseUrl;
@@ -9,9 +9,9 @@
*/
import Bottleneck from "bottleneck";
import { parseRetryAfterFromBody, lockModel } from "./accountFallback.js";
import { getProviderCategory } from "../config/providerRegistry.js";
import { DEFAULT_API_LIMITS } from "../config/constants.js";
import { parseRetryAfterFromBody, lockModel } from "./accountFallback.ts";
import { getProviderCategory } from "../config/providerRegistry.ts";
import { DEFAULT_API_LIMITS } from "../config/constants.ts";
// Store limiters keyed by "provider:connectionId" (and optionally ":model")
const limiters = new Map();
@@ -40,7 +40,7 @@ export async function initializeRateLimits() {
initialized = true;
try {
const { getProviderConnections } = await import("@/lib/localDb.js");
const { getProviderConnections } = await import("@/lib/localDb");
const connections = await getProviderConnections();
let explicitCount = 0;
let autoCount = 0;
@@ -293,7 +293,7 @@ export function updateFromHeaders(provider, connectionId, headers, status, model
// Calculate optimal minTime from RPM limit
const minTime = Math.max(0, Math.floor(60000 / limit) - 10); // Small buffer
const updates = { minTime };
const updates: Record<string, any> = { minTime };
// If remaining is low (< 10% of limit), set reservoir to throttle immediately
if (!isNaN(remaining)) {
@@ -348,7 +348,7 @@ export function getRateLimitStatus(provider, connectionId) {
* Get all active limiters status (for dashboard overview)
*/
export function getAllRateLimitStatus() {
const result = {};
const result: Record<string, any> = {};
for (const [key, limiter] of limiters) {
const counts = limiter.counts();
result[key] = {
@@ -117,7 +117,7 @@ export function acquire(modelStr, { maxConcurrency = 3, timeoutMs = 30000 } = {}
const idx = gate.queue.findIndex((item) => item.timer === timer);
if (idx !== -1) gate.queue.splice(idx, 1);
const err = new Error(`Semaphore timeout after ${timeoutMs}ms for ${modelStr}`);
err.code = "SEMAPHORE_TIMEOUT";
(err as any).code = "SEMAPHORE_TIMEOUT";
reject(err);
}, timeoutMs);
@@ -36,7 +36,7 @@ _cleanupTimer.unref();
* @param {object} [options] - Extra context
* @returns {string} Session ID (hex hash)
*/
export function generateSessionId(body, options = {}) {
export function generateSessionId(body, options: any = {}) {
const parts = [];
// Model contributes to fingerprint
@@ -34,7 +34,7 @@ const MAX_PATTERNS_PER_KEY = 50;
* @param {object} context - { tool?, modelFamily?, sessionId? }
* @returns {string[]} Array of unique signature patterns
*/
export function getSignatures(context = {}) {
export function getSignatures(context: any = {}) {
const patterns = new Set(DEFAULT_SIGNATURES);
// Layer 1: Tool (e.g., "cursor", "cline", "antigravity")
@@ -61,7 +61,7 @@ export function getSignatures(context = {}) {
* @param {string} pattern - The signature pattern (e.g., "<antThinking>")
* @param {object} context - { tool?, modelFamily?, sessionId? }
*/
export function addSignature(pattern, context = {}) {
export function addSignature(pattern: any, context: any = {}) {
if (!pattern || typeof pattern !== "string") return;
const addToLayer = (layer, key) => {
@@ -93,7 +93,7 @@ export function addSignature(pattern, context = {}) {
* @param {object} context - { tool?, modelFamily?, sessionId? }
* @returns {{ found: string[], cleaned: string }} Detected tags and cleaned text
*/
export function detectAndLearn(text, context = {}) {
export function detectAndLearn(text: any, context: any = {}) {
if (!text || typeof text !== "string") return { found: [], cleaned: text };
const found = [];
@@ -1,4 +1,4 @@
import { PROVIDERS, OAUTH_ENDPOINTS } from "../config/constants.js";
import { PROVIDERS, OAUTH_ENDPOINTS } from "../config/constants.ts";
import { createHash } from "node:crypto";
// Token expiry buffer (refresh if expires within 5 minutes)
@@ -312,6 +312,23 @@ export async function refreshQwenToken(refreshToken, log) {
};
} else {
const errorText = await response.text().catch(() => "");
// Detect unrecoverable invalid_request (expired/revoked refresh token or bad client_id)
let errorCode = null;
try {
const parsed = JSON.parse(errorText);
errorCode = parsed?.error;
} catch {
// not JSON, ignore
}
if (errorCode === "invalid_request") {
log?.error?.("TOKEN_REFRESH", "Qwen refresh token is invalid or expired. Re-authentication required.", {
status: response.status,
});
return { error: "invalid_request" };
}
log?.warn?.("TOKEN_REFRESH", `Error with Qwen endpoint`, {
status: response.status,
error: errorText,
@@ -703,7 +720,8 @@ export function supportsTokenRefresh(provider) {
* Callers should stop retrying and request re-authentication.
*/
export function isUnrecoverableRefreshError(result) {
return result && typeof result === "object" && result.error === "refresh_token_reused";
return result && typeof result === "object" &&
(result.error === "refresh_token_reused" || result.error === "invalid_request");
}
/**
@@ -2,7 +2,7 @@
* Usage Fetcher - Get usage data from provider APIs
*/
import { PROVIDERS } from "../config/constants.js";
import { PROVIDERS } from "../config/constants.ts";
// GitHub API config
const GITHUB_CONFIG = {
@@ -38,7 +38,7 @@ const CLAUDE_CONFIG = {
/**
* Get usage data for a provider connection
* @param {Object} connection - Provider connection with accessToken
* @returns {Object} Usage data with quotas
* @returns {Promise<any>} Usage data with quotas
*/
export async function getUsageForProvider(connection) {
const { provider, accessToken, providerSpecificData } = connection;
@@ -49,7 +49,7 @@ export async function getUsageForProvider(connection) {
case "gemini-cli":
return await getGeminiUsage(accessToken);
case "antigravity":
return await getAntigravityUsage(accessToken);
return await getAntigravityUsage(accessToken, undefined);
case "claude":
return await getClaudeUsage(accessToken);
case "codex":
@@ -311,7 +311,7 @@ async function getAntigravityUsage(accessToken, providerSpecificData) {
}
const data = await response.json();
const quotas = {};
const quotas: Record<string, any> = {};
// Parse model quotas (inspired by vscode-antigravity-cockpit)
if (data.models) {
@@ -328,7 +328,7 @@ async function getAntigravityUsage(accessToken, providerSpecificData) {
"gemini-2.5-flash",
];
for (const [modelKey, info] of Object.entries(data.models)) {
for (const [modelKey, info] of Object.entries(data.models) as [string, any][]) {
// Skip models without quota info
if (!info.quotaInfo) {
continue;
@@ -1,3 +1,5 @@
import * as fs from 'fs';
import * as path from 'path';
/**
* Responses API Transformer
* Converts OpenAI Chat Completions SSE to Codex Responses API SSE format
@@ -1,5 +1,5 @@
// Claude helper functions for translator
import { DEFAULT_THINKING_CLAUDE_SIGNATURE } from "../../config/defaultThinkingSignature.js";
import { DEFAULT_THINKING_CLAUDE_SIGNATURE } from "../../config/defaultThinkingSignature.ts";
// Check if message has valid non-empty content
export function hasValidContent(msg) {
@@ -193,7 +193,7 @@ function mergeAllOf(obj) {
if (!obj || typeof obj !== "object") return;
if (obj.allOf && Array.isArray(obj.allOf)) {
const merged = {};
const merged: Record<string, any> = {};
for (const item of obj.allOf) {
if (item.properties) {
@@ -1,4 +1,4 @@
import { DEFAULT_MAX_TOKENS, DEFAULT_MIN_TOKENS } from "../../config/constants.js";
import { DEFAULT_MAX_TOKENS, DEFAULT_MIN_TOKENS } from "../../config/constants.ts";
/**
* Adjust max_tokens based on request context
@@ -1,9 +1,9 @@
import { FORMATS } from "./formats.js";
import { ensureToolCallIds, fixMissingToolResponses } from "./helpers/toolCallHelper.js";
import { prepareClaudeRequest } from "./helpers/claudeHelper.js";
import { filterToOpenAIFormat } from "./helpers/openaiHelper.js";
import { normalizeThinkingConfig } from "../services/provider.js";
import { applyThinkingBudget } from "../services/thinkingBudget.js";
import { FORMATS } from "./formats.ts";
import { ensureToolCallIds, fixMissingToolResponses } from "./helpers/toolCallHelper.ts";
import { prepareClaudeRequest } from "./helpers/claudeHelper.ts";
import { filterToOpenAIFormat } from "./helpers/openaiHelper.ts";
import { normalizeThinkingConfig } from "../services/provider.ts";
import { applyThinkingBudget } from "../services/thinkingBudget.ts";
// Registry for translators.
// NOTE: translator modules import this file and call register() at module-load time.
@@ -88,24 +88,24 @@ export function register(from, to, requestFn, responseFn) {
}
// Translator modules self-register via register() on import
import "./request/claude-to-openai.js";
import "./request/openai-to-claude.js";
import "./request/gemini-to-openai.js";
import "./request/openai-to-gemini.js";
import "./request/antigravity-to-openai.js";
import "./request/openai-responses.js";
import "./request/openai-to-kiro.js";
import "./request/openai-to-cursor.js";
import "./request/claude-to-gemini.js";
import "./request/claude-to-openai.ts";
import "./request/openai-to-claude.ts";
import "./request/gemini-to-openai.ts";
import "./request/openai-to-gemini.ts";
import "./request/antigravity-to-openai.ts";
import "./request/openai-responses.ts";
import "./request/openai-to-kiro.ts";
import "./request/openai-to-cursor.ts";
import "./request/claude-to-gemini.ts";
import "./response/claude-to-openai.js";
import "./response/openai-to-claude.js";
import "./response/gemini-to-openai.js";
import "./response/gemini-to-claude.js";
import "./response/openai-to-antigravity.js";
import "./response/openai-responses.js";
import "./response/kiro-to-openai.js";
import "./response/cursor-to-openai.js";
import "./response/claude-to-openai.ts";
import "./response/openai-to-claude.ts";
import "./response/gemini-to-openai.ts";
import "./response/gemini-to-claude.ts";
import "./response/openai-to-antigravity.ts";
import "./response/openai-responses.ts";
import "./response/kiro-to-openai.ts";
import "./response/cursor-to-openai.ts";
// Translate request: source -> openai -> target
export function translateRequest(
@@ -234,7 +234,7 @@ export function translateResponse(targetFormat, sourceFormat, chunk, state) {
// Attach OpenAI intermediate results for logging
if (openaiResults && sourceFormat !== FORMATS.OPENAI && targetFormat !== FORMATS.OPENAI) {
results._openaiIntermediate = openaiResults;
(results as any)._openaiIntermediate = openaiResults;
}
return results;
@@ -1,12 +1,12 @@
import { register } from "../index.js";
import { FORMATS } from "../formats.js";
import { adjustMaxTokens } from "../helpers/maxTokensHelper.js";
import { register } from "../index.ts";
import { FORMATS } from "../formats.ts";
import { adjustMaxTokens } from "../helpers/maxTokensHelper.ts";
// Convert Antigravity request to OpenAI format
// Antigravity body: { project, model, userAgent, requestType, requestId, request: { contents, systemInstruction, tools, toolConfig, generationConfig, sessionId } }
export function antigravityToOpenAIRequest(model, body, stream) {
const req = body.request || body;
const result = {
const result: Record<string, any> = {
model: model,
messages: [],
stream: stream,
@@ -190,7 +190,7 @@ function convertContent(content) {
// Assistant with tool calls
if (toolCalls.length > 0) {
const msg = { role: "assistant" };
const msg: Record<string, any> = { role: "assistant" };
if (textParts.length > 0) {
msg.content =
textParts.length === 1 && textParts[0].type === "text" ? textParts[0].text : textParts;
@@ -204,7 +204,7 @@ function convertContent(content) {
// Regular message
if (textParts.length > 0 || reasoningContent) {
const msg = { role };
const msg: Record<string, any> = { role };
if (textParts.length > 0) {
msg.content =
textParts.length === 1 && textParts[0].type === "text" ? textParts[0].text : textParts;
@@ -1,7 +1,7 @@
import { register } from "../index.js";
import { FORMATS } from "../formats.js";
import { DEFAULT_SAFETY_SETTINGS, tryParseJSON } from "../helpers/geminiHelper.js";
import { DEFAULT_THINKING_GEMINI_SIGNATURE } from "../../config/defaultThinkingSignature.js";
import { register } from "../index.ts";
import { FORMATS } from "../formats.ts";
import { DEFAULT_SAFETY_SETTINGS, tryParseJSON } from "../helpers/geminiHelper.ts";
import { DEFAULT_THINKING_GEMINI_SIGNATURE } from "../../config/defaultThinkingSignature.ts";
/**
* Direct Claude Gemini request translator.
@@ -9,7 +9,7 @@ import { DEFAULT_THINKING_GEMINI_SIGNATURE } from "../../config/defaultThinkingS
* skipping the OpenAI hub intermediate step.
*/
export function claudeToGeminiRequest(model, body, stream) {
const result = {
const result: Record<string, any> = {
model: model,
contents: [],
generationConfig: {},
@@ -1,10 +1,10 @@
import { register } from "../index.js";
import { FORMATS } from "../formats.js";
import { adjustMaxTokens } from "../helpers/maxTokensHelper.js";
import { register } from "../index.ts";
import { FORMATS } from "../formats.ts";
import { adjustMaxTokens } from "../helpers/maxTokensHelper.ts";
// Convert Claude request to OpenAI format
export function claudeToOpenAIRequest(model, body, stream) {
const result = {
const result: Record<string, any> = {
model: model,
messages: [],
stream: stream,
@@ -186,7 +186,7 @@ function convertClaudeMessage(msg) {
// If has tool calls, return assistant message with tool_calls
if (toolCalls.length > 0) {
const result = { role: "assistant" };
const result: Record<string, any> = { role: "assistant" };
if (parts.length > 0) {
result.content = parts.length === 1 && parts[0].type === "text" ? parts[0].text : parts;
}
@@ -1,10 +1,10 @@
import { register } from "../index.js";
import { FORMATS } from "../formats.js";
import { adjustMaxTokens } from "../helpers/maxTokensHelper.js";
import { register } from "../index.ts";
import { FORMATS } from "../formats.ts";
import { adjustMaxTokens } from "../helpers/maxTokensHelper.ts";
// Convert Gemini request to OpenAI format
export function geminiToOpenAIRequest(model, body, stream) {
const result = {
const result: Record<string, any> = {
model: model,
messages: [],
stream: stream,
@@ -116,7 +116,7 @@ function convertGeminiContent(content) {
}
if (toolCalls.length > 0) {
const result = { role: "assistant" };
const result: Record<string, any> = { role: "assistant" };
if (parts.length > 0) {
result.content = parts.length === 1 ? parts[0].text : parts;
}
@@ -4,8 +4,8 @@
* Responses API uses: { input: [...], instructions: "..." }
* Chat API uses: { messages: [...] }
*/
import { register } from "../index.js";
import { FORMATS } from "../formats.js";
import { register } from "../index.ts";
import { FORMATS } from "../formats.ts";
/**
* Convert OpenAI Responses API request to OpenAI Chat Completions format
@@ -21,8 +21,8 @@ export function openaiResponsesToOpenAIRequest(model, body, stream, credentials)
const error = new Error(
`Unsupported Responses API feature: ${tool.type} tool type is not supported by omniroute`
);
error.statusCode = 400;
error.errorType = "unsupported_feature";
(error as any).statusCode = 400;
(error as any).errorType = "unsupported_feature";
throw error;
}
}
@@ -31,12 +31,12 @@ export function openaiResponsesToOpenAIRequest(model, body, stream, credentials)
const error = new Error(
"Unsupported Responses API feature: background mode is not supported by omniroute"
);
error.statusCode = 400;
error.errorType = "unsupported_feature";
(error as any).statusCode = 400;
(error as any).errorType = "unsupported_feature";
throw error;
}
const result = { ...body };
const result: Record<string, any> = { ...body };
result.messages = [];
// Convert instructions to system message
@@ -159,7 +159,7 @@ export function openaiResponsesToOpenAIRequest(model, body, stream, credentials)
* Convert OpenAI Chat Completions to OpenAI Responses API format
*/
export function openaiToOpenAIResponsesRequest(model, body, stream, credentials) {
const result = {
const result: Record<string, any> = {
model,
input: [],
stream: true,
@@ -1,8 +1,8 @@
import { register } from "../index.js";
import { FORMATS } from "../formats.js";
import { CLAUDE_SYSTEM_PROMPT } from "../../config/constants.js";
import { adjustMaxTokens } from "../helpers/maxTokensHelper.js";
import { DEFAULT_THINKING_CLAUDE_SIGNATURE } from "../../config/defaultThinkingSignature.js";
import { register } from "../index.ts";
import { FORMATS } from "../formats.ts";
import { CLAUDE_SYSTEM_PROMPT } from "../../config/constants.ts";
import { adjustMaxTokens } from "../helpers/maxTokensHelper.ts";
import { DEFAULT_THINKING_CLAUDE_SIGNATURE } from "../../config/defaultThinkingSignature.ts";
// Prefix for Claude OAuth tool names to avoid conflicts
const CLAUDE_OAUTH_TOOL_PREFIX = "proxy_";
@@ -11,7 +11,7 @@ const CLAUDE_OAUTH_TOOL_PREFIX = "proxy_";
export function openaiToClaudeRequest(model, body, stream) {
// Tool name mapping for Claude OAuth (capitalizedName → originalName)
const toolNameMap = new Map();
const result = {
const result: Record<string, any> = {
model: model,
max_tokens: adjustMaxTokens(body),
stream: stream,
@@ -2,8 +2,8 @@
* OpenAI to Cursor Request Translator
* Converts OpenAI messages to Cursor simple format
*/
import { register } from "../index.js";
import { FORMATS } from "../formats.js";
import { register } from "../index.ts";
import { FORMATS } from "../formats.ts";
/**
* Convert OpenAI messages to Cursor format with native tool_results support
@@ -66,7 +66,7 @@ function convertMessages(messages) {
// Keep tool_calls structure for assistant messages
if (msg.role === "assistant" && msg.tool_calls && msg.tool_calls.length > 0) {
const assistantMsg = { role: "assistant" };
const assistantMsg: Record<string, any> = { role: "assistant" };
if (content) {
assistantMsg.content = content;
}
@@ -80,8 +80,7 @@ function convertMessages(messages) {
result.push(assistantMsg);
} else if (content || pendingToolResults.length > 0) {
const msgObj = {
role: msg.role,
const msgObj: Record<string, any> = { role: msg.role,
content: content || "",
};
@@ -1,8 +1,8 @@
import { register } from "../index.js";
import { FORMATS } from "../formats.js";
import { DEFAULT_THINKING_GEMINI_SIGNATURE } from "../../config/defaultThinkingSignature.js";
import { ANTIGRAVITY_DEFAULT_SYSTEM } from "../../config/constants.js";
import { openaiToClaudeRequestForAntigravity } from "./openai-to-claude.js";
import { register } from "../index.ts";
import { FORMATS } from "../formats.ts";
import { DEFAULT_THINKING_GEMINI_SIGNATURE } from "../../config/defaultThinkingSignature.ts";
import { ANTIGRAVITY_DEFAULT_SYSTEM } from "../../config/constants.ts";
import { openaiToClaudeRequestForAntigravity } from "./openai-to-claude.ts";
function generateUUID() {
return crypto.randomUUID();
@@ -17,11 +17,11 @@ import {
generateSessionId,
generateProjectId,
cleanJSONSchemaForAntigravity,
} from "../helpers/geminiHelper.js";
} from "../helpers/geminiHelper.ts";
// Core: Convert OpenAI request to Gemini format (base for all variants)
function openaiToGeminiBase(model, body, stream) {
const result = {
const result: Record<string, any> = {
model: model,
contents: [],
generationConfig: {},
@@ -253,7 +253,7 @@ export function openaiToGeminiCLIRequest(model, body, stream) {
function wrapInCloudCodeEnvelope(model, geminiCLI, credentials = null, isAntigravity = false) {
const projectId = credentials?.projectId || generateProjectId();
const envelope = {
const envelope: Record<string, any> = {
project: projectId,
model: model,
userAgent: isAntigravity ? "antigravity" : "gemini-cli",
@@ -272,7 +272,7 @@ function wrapInCloudCodeEnvelope(model, geminiCLI, credentials = null, isAntigra
envelope.requestType = "agent";
// Inject required default system prompt for Antigravity
const defaultPart = { text: ANTIGRAVITY_DEFAULT_SYSTEM };
const defaultPart: Record<string, any> = { text: ANTIGRAVITY_DEFAULT_SYSTEM };
if (envelope.request.systemInstruction?.parts) {
envelope.request.systemInstruction.parts.unshift(defaultPart);
} else {
@@ -297,7 +297,7 @@ function wrapInCloudCodeEnvelope(model, geminiCLI, credentials = null, isAntigra
function wrapInCloudCodeEnvelopeForClaude(model, claudeRequest, credentials = null) {
const projectId = credentials?.projectId || generateProjectId();
const envelope = {
const envelope: Record<string, any> = {
project: projectId,
model: model,
userAgent: "antigravity",
@@ -2,8 +2,8 @@
* OpenAI to Kiro Request Translator
* Converts OpenAI Chat Completions format to Kiro/AWS CodeWhisperer format
*/
import { register } from "../index.js";
import { FORMATS } from "../formats.js";
import { register } from "../index.ts";
import { FORMATS } from "../formats.ts";
import { v4 as uuidv4 } from "uuid";
/**
@@ -22,7 +22,7 @@ function convertMessages(messages, tools, model) {
const flushPending = () => {
if (currentRole === "user") {
const content = pendingUserContent.join("\n\n").trim() || "continue";
const userMsg = {
const userMsg: Record<string, any> = {
userInputMessage: {
content: content,
modelId: "",
@@ -255,7 +255,7 @@ export function buildKiroPayload(model, body, stream, credentials) {
const timestamp = new Date().toISOString();
finalContent = `[Context: Current time is ${timestamp}]\n\n${finalContent}`;
const payload = {
const payload: Record<string, any> = {
conversationState: {
chatTriggerType: "MANUAL",
conversationId: uuidv4(),
@@ -1,5 +1,5 @@
import { register } from "../index.js";
import { FORMATS } from "../formats.js";
import { register } from "../index.ts";
import { FORMATS } from "../formats.ts";
// Create OpenAI chunk helper
function createChunk(state, delta, finishReason = null) {
@@ -133,7 +133,7 @@ export function claudeToOpenAIResponse(chunk, state) {
if (chunk.delta?.stop_reason) {
state.finishReason = convertStopReason(chunk.delta.stop_reason);
const finalChunk = {
const finalChunk: Record<string, any> = {
id: `chatcmpl-${state.messageId}`,
object: "chat.completion.chunk",
created: Math.floor(Date.now() / 1000),
@@ -2,8 +2,8 @@
* Cursor to OpenAI Response Translator
* CursorExecutor already emits OpenAI format - this is a passthrough
*/
import { register } from "../index.js";
import { FORMATS } from "../formats.js";
import { register } from "../index.ts";
import { FORMATS } from "../formats.ts";
/**
* Convert Cursor response to OpenAI format

Some files were not shown because too many files have changed in this diff Show More