Skip to content

Commit c63259d

Browse files
committed
feat: Gate 0 - modular route-based server architecture
Refactor monolithic proxyServer.ts (1128 lines) into pluggable handlers: - NEW src/server/router.ts: Route registry + request handler factory - NEW src/server/state.ts: Shared request logs + cost tracking - NEW src/server/metrics.ts: Prometheus-compatible metrics - NEW src/server/handlers/chatHandler.ts: POST /v1/chat/completions - NEW src/server/handlers/completionsHandler.ts: POST /v1/completions - NEW src/server/handlers/embeddingsHandler.ts: POST /v1/embeddings - NEW src/server/handlers/modelsHandler.ts: GET /v1/models - NEW src/server/handlers/healthHandler.ts: GET /health - NEW src/server/handlers/metricsHandler.ts: GET /metrics - proxyServer.ts: now uses registerRoute() + createRequestHandler() New endpoint addition = 2 lines (import + registerRoute call). Also: - Fix skill_manager.test.ts Python docstring -> TypeScript JSDoc - Update README with new server architecture + API endpoints - Bump version to 2.15.0 - npm publish adaptive-memory-multi-model-router@2.15.0
1 parent 2fb51a7 commit c63259d

117 files changed

Lines changed: 2863 additions & 1020 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎README.md‎

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,28 @@ A3M Router operates as a stateless proxy between client applications and LLM pro
109109
3. **Routing decision** — Multi-signal heuristic scoring assigns a complexity score (0.0–1.0) to the query. The score maps to a provider tier. The router selects the cheapest available provider in that tier.
110110
4. **Execution** — The LLM call is issued to the selected provider. Results are returned with routing metadata.
111111

112+
### Server Architecture
113+
114+
The proxy server uses a modular route-based architecture for maintainability and extensibility:
115+
116+
```
117+
src/server/
118+
├── proxyServer.ts # Entry point + route registration
119+
├── router.ts # Route registry + request handler factory
120+
├── state.ts # Shared request logs + cost tracking
121+
├── metrics.ts # Prometheus-compatible metrics
122+
├── modelMapper.ts # Model resolution + provider selection
123+
└── handlers/
124+
├── chatHandler.ts # POST /v1/chat/completions
125+
├── completionsHandler.ts # POST /v1/completions
126+
├── embeddingsHandler.ts # POST /v1/embeddings
127+
├── modelsHandler.ts # GET /v1/models
128+
├── healthHandler.ts # GET /health
129+
└── metricsHandler.ts # GET /metrics
130+
```
131+
132+
Adding a new endpoint = 2 lines: import the handler + call `registerRoute()`.
133+
112134
### Routing Signals
113135

114136
The complexity score is computed as a weighted sum across five signal dimensions:
@@ -257,9 +279,12 @@ npx a3m-router health # provider health status and lat
257279
| Method | Endpoint | Description |
258280
|--------|----------|-------------|
259281
| POST | `/v1/chat/completions` | OpenAI-compatible chat (streaming + non-streaming) |
282+
| POST | `/v1/completions` | OpenAI-compatible completions |
283+
| POST | `/v1/embeddings` | OpenAI-compatible embeddings |
260284
| POST | `/v1/route` | Routing decision without LLM call |
261285
| GET | `/v1/models` | Available models with pricing |
262-
| GET | `/health` | Provider health scores |
286+
| GET | `/health` | Health check with provider status + recent requests |
287+
| GET | `/metrics` | Prometheus-compatible metrics |
263288

264289
Full documentation: [`docs/API.md`](docs/API.md)
265290

‎dist/analytics/costAnalytics.d.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,4 @@ export declare class CostAnalytics {
7575
private getDaysCovered;
7676
}
7777
export declare function createCostAnalytics(maxRecords?: number): CostAnalytics;
78+
//# sourceMappingURL=costAnalytics.d.ts.map

‎dist/benchmark/comprehensive.d.ts‎

Lines changed: 4 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,7 @@
11
/**
22
* A3M Router — Comprehensive Local Benchmark Suite
3-
*
4-
* Tests 4 dimensions where A3M claims leadership:
5-
* 1. Routing Accuracy (tier assignment)
6-
* 2. Memory Persistence (cross-session recall)
7-
* 3. Robustness (failover, circuit breaker, provider health)
8-
* 4. Cost Efficiency (vs always-premium baseline)
9-
*
10-
* Run: npx ts-node src/benchmark/comprehensive.ts
3+
* Tests: Routing Accuracy, Memory Persistence, Robustness, Cost Efficiency
4+
* Run: npx ts-node -P tsconfig.build.json src/benchmark/comprehensive.ts
115
*/
12-
interface RoutingResult {
13-
query: string;
14-
actualTier: string;
15-
routedTier: string;
16-
model: string;
17-
complexity: number;
18-
cost: number;
19-
correct: boolean;
20-
offByOne: boolean;
21-
}
22-
declare function runRoutingAccuracy(): {
23-
results: RoutingResult[];
24-
summary: any;
25-
};
26-
interface MemoryTestResult {
27-
test: string;
28-
passed: boolean;
29-
details: string;
30-
}
31-
declare function runMemoryBenchmark(): {
32-
results: MemoryTestResult[];
33-
summary: any;
34-
};
35-
interface RobustnessResult {
36-
test: string;
37-
passed: boolean;
38-
details: string;
39-
}
40-
declare function runRobustnessBenchmark(): {
41-
results: RobustnessResult[];
42-
summary: any;
43-
};
44-
interface CostResult {
45-
scenario: string;
46-
a3mCost: number;
47-
alwaysPremiumCost: number;
48-
savings: number;
49-
savingsPct: number;
50-
}
51-
declare function runCostBenchmark(): {
52-
results: CostResult[];
53-
summary: any;
54-
};
55-
export declare function runComprehensiveBenchmark(): void;
56-
export { runRoutingAccuracy, runMemoryBenchmark, runRobustnessBenchmark, runCostBenchmark };
6+
export {};
7+
//# sourceMappingURL=comprehensive.d.ts.map

‎dist/benchmark/comprehensive.d.ts.map‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)