Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 19 additions & 18 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 |

`src/lib/localDb.js` is a **re-export layer only** — all 27+ consumers import from it,
| `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.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/`)
Expand All @@ -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

Expand All @@ -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

Expand Down
50 changes: 25 additions & 25 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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() {
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,9 @@ curl http://localhost:20128/api/evals/golden-set

### Custom Suites

Register custom suites programmatically via `registerSuite()` in `src/lib/evals/evalRunner.js`:
Register custom suites programmatically via `registerSuite()` in `src/lib/evals/evalRunner.ts`:

```javascript
```typescript
registerSuite({
id: "my-suite",
name: "Custom Eval Suite",
Expand All @@ -254,11 +254,12 @@ registerSuite({
## 🛠️ Tech Stack

- **Runtime**: Node.js 20+
- **Language**: TypeScript 5.9 (src/) + JavaScript (open-sse/)
- **Framework**: Next.js 16 + React 19 + Tailwind CSS 4
- **Database**: LowDB (JSON) + SQLite (domain state)
- **Streaming**: Server-Sent Events (SSE)
- **Auth**: OAuth 2.0 (PKCE) + JWT + API Keys
- **Testing**: Node.js test runner (320+ unit tests)
- **Testing**: Node.js test runner (368+ unit tests)
- **CI/CD**: GitHub Actions (auto npm publish on release)
- **Website**: [omniroute.online](https://omniroute.online)
- **Package**: [npmjs.com/package/omniroute](https://www.npmjs.com/package/omniroute)
Expand Down
Loading