adaptive-memory-multi-model-router 2.2.6 → 2.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/README.md +132 -94
  2. package/assets/benchmark-results.png +0 -0
  3. package/assets/complexity-scoring-v2.png +0 -0
  4. package/assets/complexity-scoring.png +0 -0
  5. package/assets/cost-comparison-chart.png +0 -0
  6. package/assets/cost-comparison-v2.png +0 -0
  7. package/assets/feature-comparison-v2.png +0 -0
  8. package/assets/feature-comparison-v3.png +0 -0
  9. package/assets/provider-health-chart.png +0 -0
  10. package/assets/provider-health-v2.png +0 -0
  11. package/assets/routing-flow-v2.png +0 -0
  12. package/assets/routing-flow-v3.png +0 -0
  13. package/assets/routing-flow.png +0 -0
  14. package/assets/tier-distribution.png +0 -0
  15. package/benchmark-results.json +620 -46
  16. package/dist/analytics/costAnalytics.d.ts +0 -1
  17. package/dist/cache/semanticCache.d.ts +0 -41
  18. package/dist/cache/semanticCache.d.ts.map +1 -1
  19. package/dist/cache/semanticCache.js +0 -142
  20. package/dist/cache/semanticCache.js.map +1 -1
  21. package/dist/cli.js +478 -35
  22. package/dist/cost/costTracker.js +3 -0
  23. package/dist/index.d.ts +0 -16
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +64 -264
  26. package/dist/index.js.map +1 -1
  27. package/dist/integrations/langchainAdapter.d.ts +0 -1
  28. package/dist/integrations/oauth.d.ts +0 -1
  29. package/dist/memory/autoFetch.d.ts +0 -1
  30. package/dist/memory/memoryTree.d.ts +0 -1
  31. package/dist/memory/obsidianVault.d.ts +0 -1
  32. package/dist/providers/providerConfig.d.ts +0 -1
  33. package/dist/providers/providerConfig.js +0 -2
  34. package/dist/providers/registry.js +128 -126
  35. package/dist/routing/advancedRouter.js +427 -310
  36. package/dist/sdk.js +100 -109
  37. package/dist/security/guardrails.d.ts +0 -1
  38. package/dist/server/dashboard.d.ts +0 -1
  39. package/dist/server/modelMapper.d.ts +0 -1
  40. package/dist/server/proxyServer.d.ts +0 -1
  41. package/package.json +3 -325
  42. package/scripts/run-mmlu-benchmark.js +176 -0
  43. package/scripts/run-provider-benchmark.js +244 -0
  44. package/src/cache/semanticCache.ts +0 -148
  45. package/src/index.ts +99 -0
  46. package/test/provider-test.js +70 -91
  47. package/test.js +41 -67
  48. package/tsconfig.json +5 -15
package/dist/sdk.js CHANGED
@@ -5,127 +5,118 @@
5
5
  * Clean wrapper class providing a better DX than raw exports.
6
6
  *
7
7
  * Usage:
8
- * import { A3MRouter } from 'adaptive-memory-multi-model-router/sdk';
9
- *
8
+ * const { A3MRouter } = require('adaptive-memory-multi-model-router/sdk');
10
9
  * const router = new A3MRouter();
11
- *
12
- * // Route a query (no execution, just model selection)
13
10
  * const decision = router.route("What is 2+2?");
14
11
  * console.log(decision.model, decision.tier, decision.cost);
15
- *
16
- * // Start the OpenAI-compatible proxy server
17
- * const proxyURL = await router.serve(8787);
18
- *
19
- * // Use with any OpenAI SDK
20
- * import OpenAI from 'openai';
21
- * const client = new OpenAI({ baseURL: router.proxyURL });
22
- * const response = await client.chat.completions.create({
23
- * model: 'auto',
24
- * messages: [{ role: 'user', content: 'Hello' }]
25
- * });
26
12
  */
27
- Object.defineProperty(exports, "__esModule", { value: true });
28
- exports.A3MRouter = void 0;
29
- exports.createSDK = createSDK;
30
- const advancedRouter_1 = require("./routing/advancedRouter");
31
- const proxyServer_1 = require("./server/proxyServer");
13
+
14
+ const advancedRouter = require("./routing/advancedRouter");
15
+ const proxyServer = require("./server/proxyServer");
16
+
32
17
  // ============================================================
33
18
  // A3MRouter SDK Class
34
19
  // ============================================================
20
+
35
21
  class A3MRouter {
36
- config;
37
- _proxyURL = null;
38
- constructor(config = {}) {
39
- this.config = config;
40
- }
41
- /**
42
- * Route a query — returns model selection without executing it.
43
- *
44
- * @param query - The user prompt to route
45
- * @returns Routing decision with model, tier, cost, complexity
46
- */
47
- route(query) {
48
- const features = (0, advancedRouter_1.extractQueryFeatures)(query);
49
- const result = (0, advancedRouter_1.routeQuery)(query, this.config.providers);
50
- return {
51
- model: result.primary_model || 'unknown',
52
- tier: this.classifyTier(features.complexity),
53
- cost: result.estimated_cost || 0,
54
- complexity: features.complexity,
55
- reasoning: result.reasoning || '',
56
- fallbackModels: result.fallback_models || [],
57
- isFree: (result.estimated_cost || 0) === 0,
58
- isExpert: features.complexity >= 0.65,
59
- };
60
- }
61
- /**
62
- * Route multiple queries in batch.
63
- *
64
- * @param queries - Array of user prompts
65
- * @returns Array of routing decisions
66
- */
67
- routeBatch(queries) {
68
- (0, advancedRouter_1.routeBatch)(queries); // warm the internal cache
69
- return queries.map((q) => this.route(q));
70
- }
71
- /**
72
- * Get model recommendation for a task description.
73
- *
74
- * @param task - Task description (e.g. "code generation", "summarization")
75
- * @returns Routing decision
76
- */
77
- recommend(task) {
78
- (0, advancedRouter_1.recommendForTask)(task);
79
- return this.route(task);
80
- }
81
- /**
82
- * Start the OpenAI-compatible proxy server.
83
- *
84
- * @param port - Port to listen on (default: 8787)
85
- * @returns The proxy base URL (e.g. "http://localhost:8787/v1")
86
- */
87
- async serve(port = 8787) {
88
- (0, proxyServer_1.createProxyServer)(port);
89
- this._proxyURL = `http://localhost:${port}/v1`;
90
- return this._proxyURL;
91
- }
92
- /**
93
- * Get the proxy URL. Available after serve() is called,
94
- * otherwise returns the default.
95
- */
96
- get proxyURL() {
97
- return this._proxyURL || 'http://localhost:8787/v1';
98
- }
99
- /**
100
- * Extract features from a query for debugging or analysis.
101
- *
102
- * @param query - The user prompt to analyze
103
- * @returns Detailed feature breakdown
104
- */
105
- analyze(query) {
106
- return (0, advancedRouter_1.extractQueryFeatures)(query);
107
- }
108
- /**
109
- * Classify a complexity score into a named tier.
110
- */
111
- classifyTier(complexity) {
112
- if (complexity < 0.20)
113
- return 'free';
114
- if (complexity < 0.45)
115
- return 'cheap';
116
- if (complexity < 0.65)
117
- return 'mid';
118
- return 'premium';
119
- }
22
+ constructor(config = {}) {
23
+ this.config = config;
24
+ this._proxyURL = null;
25
+ }
26
+
27
+ /**
28
+ * Route a query — returns model selection without executing it.
29
+ *
30
+ * @param {string} query - The user prompt to route
31
+ * @returns {object} Routing decision with model, tier, cost, complexity
32
+ */
33
+ route(query) {
34
+ const features = advancedRouter.extractQueryFeatures(query);
35
+ const result = advancedRouter.routeQuery(query, this.config.providers);
36
+
37
+ return {
38
+ model: result.primary_model || 'unknown',
39
+ tier: this.classifyTier(features.complexity),
40
+ cost: result.estimated_cost || 0,
41
+ complexity: features.complexity,
42
+ reasoning: result.reasoning || '',
43
+ fallbackModels: result.fallback_models || [],
44
+ isFree: (result.estimated_cost || 0) === 0,
45
+ isExpert: features.complexity >= 0.65,
46
+ };
47
+ }
48
+
49
+ /**
50
+ * Route multiple queries in batch.
51
+ *
52
+ * @param {string[]} queries - Array of user prompts
53
+ * @returns {object[]} Array of routing decisions
54
+ */
55
+ routeBatch(queries) {
56
+ advancedRouter.routeBatch(queries); // warm the internal cache
57
+ return queries.map((q) => this.route(q));
58
+ }
59
+
60
+ /**
61
+ * Get model recommendation for a task description.
62
+ *
63
+ * @param {string} task - Task description
64
+ * @returns {object} Routing decision
65
+ */
66
+ recommend(task) {
67
+ advancedRouter.recommendForTask(task);
68
+ return this.route(task);
69
+ }
70
+
71
+ /**
72
+ * Start the OpenAI-compatible proxy server.
73
+ *
74
+ * @param {number} port - Port to listen on (default: 8787)
75
+ * @returns {Promise<string>} The proxy base URL
76
+ */
77
+ async serve(port = 8787) {
78
+ proxyServer.createProxyServer(port);
79
+ this._proxyURL = `http://localhost:${port}/v1`;
80
+ return this._proxyURL;
81
+ }
82
+
83
+ /**
84
+ * Get the proxy URL. Available after serve() is called.
85
+ */
86
+ get proxyURL() {
87
+ return this._proxyURL || 'http://localhost:8787/v1';
88
+ }
89
+
90
+ /**
91
+ * Extract features from a query for debugging or analysis.
92
+ *
93
+ * @param {string} query - The user prompt to analyze
94
+ * @returns {object} Detailed feature breakdown
95
+ */
96
+ analyze(query) {
97
+ return advancedRouter.extractQueryFeatures(query);
98
+ }
99
+
100
+ /**
101
+ * Classify a complexity score into a named tier.
102
+ */
103
+ classifyTier(complexity) {
104
+ if (complexity < 0.20) return 'free';
105
+ if (complexity < 0.45) return 'cheap';
106
+ if (complexity < 0.65) return 'mid';
107
+ return 'premium';
108
+ }
120
109
  }
121
- exports.A3MRouter = A3MRouter;
110
+
122
111
  /**
123
112
  * Convenience: create an A3MRouter instance.
124
113
  *
125
- * @param config - Optional configuration
126
- * @returns Configured A3MRouter instance
114
+ * @param {object} config - Optional configuration
115
+ * @returns {A3MRouter} Configured instance
127
116
  */
128
117
  function createSDK(config) {
129
- return new A3MRouter(config);
118
+ return new A3MRouter(config);
130
119
  }
131
- //# sourceMappingURL=sdk.js.map
120
+
121
+ module.exports = { A3MRouter, createSDK };
122
+ module.exports.default = A3MRouter;
@@ -74,4 +74,3 @@ export declare class GuardrailEngine {
74
74
  }
75
75
  export declare function createGuardrails(config?: Partial<GuardrailConfig>): GuardrailEngine;
76
76
  export {};
77
- //# sourceMappingURL=guardrails.d.ts.map
@@ -56,4 +56,3 @@ export declare function registerProvider(id: string, name: string): void;
56
56
  */
57
57
  export declare function handleDashboardRequest(req: http.IncomingMessage, res: http.ServerResponse): boolean;
58
58
  export declare function getDashboardHTML(): string;
59
- //# sourceMappingURL=dashboard.d.ts.map
@@ -41,4 +41,3 @@ export declare function listAvailableModels(): Array<{
41
41
  created: number;
42
42
  owned_by: string;
43
43
  }>;
44
- //# sourceMappingURL=modelMapper.d.ts.map
@@ -39,4 +39,3 @@ declare const costTracker: any;
39
39
  export declare function createProxyServer(port?: number): http.Server;
40
40
  export { CostTracker, costTracker, requestLogs };
41
41
  export default createProxyServer;
42
- //# sourceMappingURL=proxyServer.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adaptive-memory-multi-model-router",
3
- "version": "2.2.6",
3
+ "version": "2.2.7",
4
4
  "shortName": "A3M Router",
5
5
  "displayName": "A3M Router - Adaptive Memory Multi-Model Router",
6
6
  "description": "LLM router & AI gateway with 99.5% routing accuracy — supports 47 providers including DeepSeek, Kimi (Moonshot), Qwen, Zhipu GLM, Yi, Baichuan, MiniMax, StepFun. Zero ML, 19.5KB. Multi-signal routing, semantic cache, guardrails, cost analytics. MIT. TypeScript SDK + Python SDK + OpenAI proxy.",
@@ -53,142 +53,6 @@
53
53
  }
54
54
  },
55
55
  "keywords": [
56
- "adaptive-router",
57
- "agent",
58
- "agent-framework",
59
- "ai-agent-tools",
60
- "ai-assistant",
61
- "ai-discoverability",
62
- "ai-routing",
63
- "airtable",
64
- "amplitude",
65
- "api-gateway",
66
- "asana",
67
- "automation",
68
- "autonomous-agents",
69
- "aws-bedrock",
70
- "batch-processing",
71
- "bitbucket",
72
- "circuit-breaker",
73
- "claude-code",
74
- "cli",
75
- "cloud",
76
- "code-generation",
77
- "cohere",
78
- "content-filtering",
79
- "copilot",
80
- "cost-analytics",
81
- "datadog",
82
- "deepinfra",
83
- "developer-experience",
84
- "developer-tools",
85
- "devops",
86
- "discord",
87
- "dropbox",
88
- "dx",
89
- "edge-computing",
90
- "embedding",
91
- "enterprise",
92
- "fallback",
93
- "fine-tuning",
94
- "fireworks",
95
- "gemini",
96
- "generative-engine-optimization",
97
- "geo",
98
- "github",
99
- "gitlab",
100
- "gmail",
101
- "google",
102
- "google-calendar",
103
- "gpt-4",
104
- "graphql",
105
- "high-availability",
106
- "hubspot",
107
- "huggingface",
108
- "inference",
109
- "input-validation",
110
- "intent-mapping",
111
- "intercom",
112
- "javascript",
113
- "jira",
114
- "latency-optimization",
115
- "linear",
116
- "llamaindex",
117
- "llm-intent",
118
- "llm-tools",
119
- "llmlingua",
120
- "load-balancing",
121
- "logging",
122
- "machine-learning",
123
- "mailchimp",
124
- "mcp",
125
- "medusa",
126
- "memory-tree",
127
- "middleware",
128
- "mixpanel",
129
- "monitoring",
130
- "multi-model",
131
- "natural-language-processing",
132
- "netlify",
133
- "nodejs",
134
- "notion",
135
- "npm",
136
- "observability",
137
- "open-source",
138
- "orchestration",
139
- "parallel-execution",
140
- "performance",
141
- "perplexity",
142
- "pii-detection",
143
- "pinecone",
144
- "posthog",
145
- "prefix-caching",
146
- "production",
147
- "prompt-engineering",
148
- "prompt-injection",
149
- "provider-registry",
150
- "proxy",
151
- "proxy-server",
152
- "python",
153
- "radix-attention",
154
- "rag",
155
- "rate-limiting",
156
- "real-time",
157
- "rest-api",
158
- "retrieval-augmented-generation",
159
- "retry",
160
- "route-quality",
161
- "routellm",
162
- "router",
163
- "s3",
164
- "salesforce",
165
- "sanitization",
166
- "scalability",
167
- "sdk",
168
- "security",
169
- "segment",
170
- "sendgrid",
171
- "sentry",
172
- "serverless",
173
- "shopify",
174
- "slack",
175
- "speculative-decoding",
176
- "streaming",
177
- "stripe",
178
- "telegram",
179
- "testing",
180
- "together-ai",
181
- "token-compression",
182
- "tools",
183
- "tracing",
184
- "transformer",
185
- "trello",
186
- "typescript",
187
- "vector-database",
188
- "vercel",
189
- "websocket",
190
- "xai",
191
- "zendesk",
192
56
  "llm-proxy",
193
57
  "claude",
194
58
  "ai",
@@ -271,191 +135,7 @@
271
135
  "semantic-cache",
272
136
  "langchain",
273
137
  "ai-guardrails",
274
- "chatbot",
275
- "a3m",
276
- "a3m-router",
277
- "adaptive",
278
- "memory-based",
279
- "multi-model-router",
280
- "memory-based-router",
281
- "treequest",
282
- "parallel-ai",
283
- "agent-orchestration",
284
- "multi-agent",
285
- "parallel",
286
- "cost-tracking",
287
- "cache",
288
- "caching",
289
- "exponential-backoff",
290
- "mcts",
291
- "monte-carlo-tree-search",
292
- "workflow-optimization",
293
- "hierarchical-planning",
294
- "halo",
295
- "episodic-memory",
296
- "semantic-memory",
297
- "agent-memory",
298
- "python-bindings",
299
- "pypi",
300
- "autogen",
301
- "crewai",
302
- "transformers",
303
- "agent-codegen",
304
- "ai-coding",
305
- "zai",
306
- "llama",
307
- "ai-agents",
308
- "memory-based-llm-router",
309
- "multi-llm-router",
310
- "llm-memory-router",
311
- "adaptive-llm-router",
312
- "intelligent-router",
313
- "intelligent-llm-router",
314
- "learning-router",
315
- "contextual-router",
316
- "context-aware-router",
317
- "task-aware-router",
318
- "memory-augmented",
319
- "memory-augmented-llm",
320
- "episodic-memory-router",
321
- "semantic-memory-router",
322
- "task-memory",
323
- "cross-context-memory",
324
- "context-compression",
325
- "ison-format",
326
- "message-truncation",
327
- "context-management",
328
- "local-llm",
329
- "lmstudio",
330
- "local-model",
331
- "privacy-llm",
332
- "priority-queue",
333
- "token-counting",
334
- "cost-estimation",
335
- "cost-prediction",
336
- "intelligent-failover",
337
- "kv-cache",
338
- "pagedattention",
339
- "kv-cache-quantization",
340
- "streamingllm",
341
- "multimodel-orchestration",
342
- "multi-agent-debate",
343
- "self-consistency",
344
- "tensor-parallelism",
345
- "continuous-batching",
346
- "arxiv",
347
- "research-backed",
348
- "icml",
349
- "neurips",
350
- "iclr",
351
- "pi-extension",
352
- "pi",
353
- "pi-package",
354
- "pi-coding-agent",
355
- "pi-agent",
356
- "agent-discoverable",
357
- "ai-native",
358
- "01-ai",
359
- "01ai",
360
- "128k上下文",
361
- "ai-gateway-cn",
362
- "ai路由",
363
- "aliyun",
364
- "baichuan-ai",
365
- "baichuan2",
366
- "baichuan2-flash",
367
- "baiducloud",
368
- "chinese-ai-proxy",
369
- "chinese-api-gateway",
370
- "chinese-chatgpt",
371
- "chinese-language-model",
372
- "chinese-llm-proxy",
373
- "chinese-models",
374
- "chinese-nlp",
375
- "chinesellm",
376
- "chinesellm-routing",
377
- "deepseek-ai",
378
- "deepseek-api",
379
- "deepseek-chat",
380
- "deepseek-coder",
381
- "deepseek-reasoner",
382
- "embedding-model",
383
- "glm-4",
384
- "glm-4-air",
385
- "glm-4-flash",
386
- "glm-4-long",
387
- "glm-4-plus",
388
- "huawei-cloud",
389
- "langchain-cn",
390
- "lingyi",
391
- "lingyi-wanwu",
392
- "llamaindex-cn",
393
- "llm-gateway-cn",
394
- "long-context-model",
395
- "minimax-ai",
396
- "minimax-api",
397
- "minimax-chat",
398
- "minimax-turbo",
399
- "moonshot-ai",
400
- "moonshot-v1",
401
- "moonshot-v1-128k",
402
- "moonshot-v1-32k",
403
- "moonshot-v1-8k",
404
- "multimodal",
405
- "qianwen",
406
- "qwen-long",
407
- "qwen-max",
408
- "qwen-plus",
409
- "qwen-turbo",
410
- "qwen2",
411
- "qwen3",
412
- "step-1",
413
- "step-1v",
414
- "step-2",
415
- "tencentcloud",
416
- "tongji",
417
- "tongyi",
418
- "tongyi-qianwen",
419
- "vision-model",
420
- "volcengine",
421
- "wu-yuan",
422
- "wuyuan",
423
- "yi-ai",
424
- "yi-large",
425
- "yi-lightning",
426
- "yi-medium",
427
- "zai-glm",
428
- "zai-glm-4",
429
- "zhipu-ai",
430
- "中国ai",
431
- "中国大模型",
432
- "中文chatgpt",
433
- "中文embedding",
434
- "中文langchain",
435
- "中文llamaindex",
436
- "中文nlp",
437
- "中文seo",
438
- "中文多模态",
439
- "中文大模型",
440
- "中文搜索引擎优化",
441
- "中文模型",
442
- "华为云",
443
- "向量化",
444
- "国产ai",
445
- "国产大模型",
446
- "多模型路由",
447
- "多模态",
448
- "大模型路由",
449
- "字节ai",
450
- "智能路由",
451
- "火山引擎",
452
- "百度ai",
453
- "百度云",
454
- "腾讯ai",
455
- "腾讯云",
456
- "长上下文",
457
- "阿里ai",
458
- "阿里云"
138
+ "chatbot"
459
139
  ],
460
140
  "author": "Das-rebel <subho@example.com>",
461
141
  "license": "MIT",
@@ -471,8 +151,7 @@
471
151
  "test": "node test.js && node test/provider-test.js",
472
152
  "test:providers": "node test/provider-test.js",
473
153
  "benchmark": "node test/benchmark.js",
474
- "benchmark:verbose": "node test/benchmark.js --verbose",
475
- "build": "tsc"
154
+ "benchmark:verbose": "node test/benchmark.js --verbose"
476
155
  },
477
156
  "engines": {
478
157
  "node": ">=18.0.0"
@@ -490,7 +169,6 @@
490
169
  },
491
170
  "devDependencies": {
492
171
  "@types/node": "^25.8.0",
493
- "tsx": "^4.22.3",
494
172
  "typescript": "^6.0.3"
495
173
  }
496
174
  }