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

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 (51) hide show
  1. package/README.md +146 -105
  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.js +64 -264
  25. package/dist/integrations/langchainAdapter.d.ts +0 -1
  26. package/dist/integrations/oauth.d.ts +0 -1
  27. package/dist/memory/autoFetch.d.ts +0 -1
  28. package/dist/memory/memoryTree.d.ts +0 -1
  29. package/dist/memory/obsidianVault.d.ts +0 -1
  30. package/dist/providers/providerConfig.d.ts +0 -1
  31. package/dist/providers/providerConfig.js +0 -2
  32. package/dist/providers/registry.js +128 -126
  33. package/dist/routing/advancedRouter.js +427 -310
  34. package/dist/sdk.js +100 -109
  35. package/dist/security/guardrails.d.ts +0 -1
  36. package/dist/server/dashboard.d.ts +0 -1
  37. package/dist/server/modelMapper.d.ts +0 -1
  38. package/dist/server/proxyServer.d.ts +0 -1
  39. package/package.json +96 -389
  40. package/scripts/run-mmlu-benchmark.js +176 -0
  41. package/scripts/run-provider-benchmark.js +244 -0
  42. package/src/cache/semanticCache.ts +0 -148
  43. package/src/index.ts +99 -0
  44. package/test/provider-test.js +70 -91
  45. package/test.js +41 -67
  46. package/tsconfig.json +5 -15
  47. package/dist/index.d.ts.map +0 -1
  48. package/dist/index.js.map +0 -1
  49. package/dist/sdk.d.ts.map +0 -1
  50. package/dist/sdk.js.map +0 -1
  51. package/test.js.bak +0 -376
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