adaptive-memory-multi-model-router 2.3.0 → 2.4.0

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 (53) hide show
  1. package/README.md +81 -771
  2. package/package.json +1 -1
  3. package/src/skills/__tests__/skill_manager.test.ts +328 -0
  4. package/assets/benchmark-results-pro.svg +0 -1857
  5. package/assets/benchmark-results.png +0 -0
  6. package/assets/complexity-scoring-v2.png +0 -0
  7. package/assets/complexity-scoring.png +0 -0
  8. package/assets/cost-comparison-chart.png +0 -0
  9. package/assets/cost-comparison-pro.svg +0 -2708
  10. package/assets/cost-comparison-v2.png +0 -0
  11. package/assets/feature-comparison-v2.png +0 -0
  12. package/assets/feature-comparison-v3.png +0 -0
  13. package/assets/feature-matrix-pro.svg +0 -2899
  14. package/assets/growth-chart-pro.svg +0 -1050
  15. package/assets/hero-banner.svg +0 -2033
  16. package/assets/logo-icon.svg +0 -99
  17. package/assets/provider-health-chart.png +0 -0
  18. package/assets/provider-health-pro.svg +0 -2710
  19. package/assets/provider-health-v2.png +0 -0
  20. package/assets/routing-flow-pro.svg +0 -2238
  21. package/assets/routing-flow-v2.png +0 -0
  22. package/assets/routing-flow-v3.png +0 -0
  23. package/assets/routing-flow.png +0 -0
  24. package/assets/social-preview-pro.svg +0 -1685
  25. package/assets/tier-distribution-pro.svg +0 -2110
  26. package/assets/tier-distribution.png +0 -0
  27. package/dist/cache/cacheKeyGenerator.d.ts +0 -67
  28. package/dist/cache/cacheKeyGenerator.d.ts.map +0 -1
  29. package/dist/cache/cacheKeyGenerator.js +0 -211
  30. package/dist/cache/cacheKeyGenerator.js.map +0 -1
  31. package/dist/cost/preCallCostEstimator.d.ts +0 -114
  32. package/dist/cost/preCallCostEstimator.d.ts.map +0 -1
  33. package/dist/cost/preCallCostEstimator.js +0 -256
  34. package/dist/cost/preCallCostEstimator.js.map +0 -1
  35. package/dist/inference/speculativeDecoding.d.ts +0 -133
  36. package/dist/inference/speculativeDecoding.d.ts.map +0 -1
  37. package/dist/inference/speculativeDecoding.js +0 -276
  38. package/dist/inference/speculativeDecoding.js.map +0 -1
  39. package/dist/providers/providerHealth.d.ts +0 -117
  40. package/dist/providers/providerHealth.d.ts.map +0 -1
  41. package/dist/providers/providerHealth.js +0 -309
  42. package/dist/providers/providerHealth.js.map +0 -1
  43. package/dist/routing/difficultyClassifier.d.ts +0 -79
  44. package/dist/routing/difficultyClassifier.d.ts.map +0 -1
  45. package/dist/routing/difficultyClassifier.js +0 -329
  46. package/dist/routing/difficultyClassifier.js.map +0 -1
  47. package/dist/sdk.d.ts +0 -125
  48. package/docs/HN_CAMPAIGN.md +0 -785
  49. package/src/cache/cacheKeyGenerator.ts +0 -242
  50. package/src/cost/preCallCostEstimator.ts +0 -345
  51. package/src/inference/speculativeDecoding.ts +0 -373
  52. package/src/providers/providerHealth.ts +0 -397
  53. package/src/routing/difficultyClassifier.ts +0 -420
@@ -1,309 +0,0 @@
1
- "use strict";
2
- /**
3
- * A3M Router - Provider Health Score
4
- *
5
- * Probabilistic health scoring (not binary up/down).
6
- * Uses latency history, error rate, partial failure patterns, queue depth estimates.
7
- *
8
- * Usage:
9
- * const healthMonitor = new ProviderHealthMonitor();
10
- * healthMonitor.recordLatency('groq', 250);
11
- * healthMonitor.recordError('groq', 'rate_limit');
12
- * const score = healthMonitor.getHealthScore('groq');
13
- * console.log(score); // { score: 0.85, confidence: 0.7, status: 'healthy' }
14
- */
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.ProviderHealthMonitor = void 0;
17
- exports.createProviderHealthMonitor = createProviderHealthMonitor;
18
- const DEFAULT_CONFIG = {
19
- latencyAlpha: 0.3,
20
- errorAlpha: 0.2,
21
- anomalyWindow: 20,
22
- anomalyThreshold: 2.0,
23
- healthyThreshold: 0.75,
24
- degradedThreshold: 0.4,
25
- };
26
- // ============================================================
27
- // ProviderHealthMonitor
28
- // ============================================================
29
- class ProviderHealthMonitor {
30
- records = new Map();
31
- config;
32
- ewmaLatency = new Map();
33
- ewmaErrorRate = new Map();
34
- anomalyScores = new Map();
35
- constructor(config = {}) {
36
- this.config = { ...DEFAULT_CONFIG, ...config };
37
- }
38
- /**
39
- * Record a successful request with latency.
40
- */
41
- recordSuccess(providerId, latencyMs) {
42
- this.addRecord(providerId, {
43
- timestamp: Date.now(),
44
- latency: latencyMs,
45
- success: true,
46
- });
47
- this.updateEwmaLatency(providerId, latencyMs);
48
- this.updateEwmaErrorRate(providerId, false);
49
- this.updateAnomalyScore(providerId, latencyMs);
50
- }
51
- /**
52
- * Record a failed request.
53
- */
54
- recordError(providerId, errorType = 'unknown') {
55
- this.addRecord(providerId, {
56
- timestamp: Date.now(),
57
- success: false,
58
- errorType,
59
- });
60
- this.updateEwmaErrorRate(providerId, true);
61
- }
62
- /**
63
- * Record a partial failure (slow response, incomplete output, etc).
64
- */
65
- recordPartialFailure(providerId, latencyMs) {
66
- this.addRecord(providerId, {
67
- timestamp: Date.now(),
68
- latency: latencyMs,
69
- success: false,
70
- partialFailure: true,
71
- });
72
- if (latencyMs !== undefined) {
73
- this.updateEwmaLatency(providerId, latencyMs);
74
- this.updateAnomalyScore(providerId, latencyMs);
75
- }
76
- // Partial failures count as half an error
77
- this.updateEwmaErrorRate(providerId, false, 0.5);
78
- }
79
- /**
80
- * Record queue depth estimate (when available from provider metadata).
81
- */
82
- recordQueueDepth(providerId, depth) {
83
- // Queue depth affects latency estimation but doesn't directly
84
- // impact the health score unless it's extremely high
85
- const maxQueueDepth = 100;
86
- const queueFactor = 1 + Math.min(depth / maxQueueDepth, 1.0) * 0.5;
87
- const currentLatency = this.ewmaLatency.get(providerId) || 0;
88
- if (currentLatency > 0) {
89
- this.ewmaLatency.set(providerId, currentLatency * queueFactor);
90
- }
91
- }
92
- /**
93
- * Get the current health score for a provider.
94
- */
95
- getHealthScore(providerId) {
96
- const records = this.getRecords(providerId);
97
- const sampleSize = records.length;
98
- const now = Date.now();
99
- // Not enough data
100
- if (sampleSize < 3) {
101
- return {
102
- score: sampleSize === 0 ? 1.0 : 0.8,
103
- confidence: sampleSize / 10, // 0 at 0 samples, 0.3 at 3 samples
104
- status: sampleSize === 0 ? 'healthy' : 'degraded',
105
- components: { latency: 1.0, errorRate: 1.0, recentTrend: 1.0 },
106
- lastUpdated: now,
107
- metadata: { sampleSize, isAnomaly: false },
108
- };
109
- }
110
- const latencyScore = this.calculateLatencyScore(providerId);
111
- const errorScore = this.calculateErrorScore(providerId);
112
- const trendScore = this.calculateTrendScore(providerId);
113
- // Weighted combination
114
- const score = latencyScore * 0.35 +
115
- errorScore * 0.45 +
116
- trendScore * 0.20;
117
- // Determine status
118
- let status;
119
- if (score >= this.config.healthyThreshold) {
120
- status = 'healthy';
121
- }
122
- else if (score >= this.config.degradedThreshold) {
123
- status = 'degraded';
124
- }
125
- else {
126
- status = 'critical';
127
- }
128
- // Anomaly detection
129
- const anomalyScore = this.anomalyScores.get(providerId) || 0;
130
- const isAnomaly = anomalyScore > this.config.anomalyThreshold;
131
- const anomalyReason = isAnomaly
132
- ? `Anomaly detected: score ${anomalyScore.toFixed(2)} > threshold ${this.config.anomalyThreshold}`
133
- : undefined;
134
- // Confidence based on sample size and anomaly status
135
- const baseConfidence = Math.min(sampleSize / 30, 1.0);
136
- const confidence = isAnomaly
137
- ? Math.min(baseConfidence * 0.5, 0.5) // Lower confidence when anomalous
138
- : baseConfidence;
139
- return {
140
- score: Math.round(score * 1000) / 1000,
141
- confidence: Math.round(confidence * 1000) / 1000,
142
- status,
143
- components: {
144
- latency: Math.round(latencyScore * 1000) / 1000,
145
- errorRate: Math.round(errorScore * 1000) / 1000,
146
- recentTrend: Math.round(trendScore * 1000) / 1000,
147
- },
148
- lastUpdated: now,
149
- metadata: {
150
- sampleSize,
151
- isAnomaly,
152
- anomalyReason,
153
- },
154
- };
155
- }
156
- /**
157
- * Get health scores for all tracked providers.
158
- */
159
- getAllHealthScores() {
160
- const result = {};
161
- for (const providerId of this.records.keys()) {
162
- result[providerId] = this.getHealthScore(providerId);
163
- }
164
- return result;
165
- }
166
- /**
167
- * Get the recommended provider based on health scores.
168
- * Excludes providers that are 'critical'.
169
- */
170
- getRecommendedProvider(providers) {
171
- const candidates = providers.filter(p => {
172
- const score = this.getHealthScore(p.id);
173
- return score.status !== 'critical';
174
- });
175
- if (candidates.length === 0)
176
- return null;
177
- // Sort by health score, then by priority (if available)
178
- candidates.sort((a, b) => {
179
- const scoreA = this.getHealthScore(a.id).score;
180
- const scoreB = this.getHealthScore(b.id).score;
181
- if (Math.abs(scoreA - scoreB) > 0.1) {
182
- return scoreB - scoreA; // Higher score first
183
- }
184
- return (a.priority || 50) - (b.priority || 50); // Lower priority first
185
- });
186
- return candidates[0].id;
187
- }
188
- /**
189
- * Clear all records for a provider.
190
- */
191
- clearProvider(providerId) {
192
- this.records.delete(providerId);
193
- this.ewmaLatency.delete(providerId);
194
- this.ewmaErrorRate.delete(providerId);
195
- this.anomalyScores.delete(providerId);
196
- }
197
- /**
198
- * Clear all records for all providers.
199
- */
200
- clearAll() {
201
- this.records.clear();
202
- this.ewmaLatency.clear();
203
- this.ewmaErrorRate.clear();
204
- this.anomalyScores.clear();
205
- }
206
- // ---- Private methods ----
207
- addRecord(providerId, record) {
208
- if (!this.records.has(providerId)) {
209
- this.records.set(providerId, []);
210
- }
211
- const records = this.records.get(providerId);
212
- records.push(record);
213
- // Keep only recent records (last hour)
214
- const oneHourAgo = Date.now() - 3600000;
215
- const filtered = records.filter(r => r.timestamp >= oneHourAgo);
216
- this.records.set(providerId, filtered);
217
- }
218
- getRecords(providerId) {
219
- return this.records.get(providerId) || [];
220
- }
221
- updateEwmaLatency(providerId, latency) {
222
- const current = this.ewmaLatency.get(providerId);
223
- if (current === undefined) {
224
- this.ewmaLatency.set(providerId, latency);
225
- }
226
- else {
227
- this.ewmaLatency.set(providerId, this.config.latencyAlpha * latency + (1 - this.config.latencyAlpha) * current);
228
- }
229
- }
230
- updateEwmaErrorRate(providerId, isError, weight = 1.0) {
231
- const current = this.ewmaErrorRate.get(providerId) || 0;
232
- const errorValue = isError ? 1.0 * weight : 0;
233
- if (current === 0 && !isError) {
234
- this.ewmaErrorRate.set(providerId, 0);
235
- }
236
- else {
237
- this.ewmaErrorRate.set(providerId, this.config.errorAlpha * errorValue + (1 - this.config.errorAlpha) * current);
238
- }
239
- }
240
- updateAnomalyScore(providerId, latency) {
241
- const records = this.getRecords(providerId).filter(r => r.latency !== undefined);
242
- if (records.length < 3)
243
- return;
244
- // Calculate standard deviation of recent latencies
245
- const recentLatencies = records
246
- .slice(-this.config.anomalyWindow)
247
- .map(r => r.latency)
248
- .filter(l => l !== undefined);
249
- if (recentLatencies.length < 3)
250
- return;
251
- const mean = recentLatencies.reduce((a, b) => a + b, 0) / recentLatencies.length;
252
- const variance = recentLatencies.reduce((sum, l) => sum + Math.pow(l - mean, 2), 0) /
253
- recentLatencies.length;
254
- const stdDev = Math.sqrt(variance);
255
- // Z-score of current latency
256
- const zScore = stdDev > 0 ? Math.abs(latency - mean) / stdDev : 0;
257
- // Update anomaly score with decay
258
- const currentScore = this.anomalyScores.get(providerId) || 0;
259
- const newScore = currentScore * 0.9 + zScore * 0.1;
260
- this.anomalyScores.set(providerId, newScore);
261
- }
262
- calculateLatencyScore(providerId) {
263
- const latency = this.ewmaLatency.get(providerId);
264
- if (latency === undefined)
265
- return 1.0;
266
- // Score based on latency brackets (ms)
267
- // Tier-appropriate expectations
268
- if (latency < 200)
269
- return 1.0;
270
- if (latency < 500)
271
- return 0.95;
272
- if (latency < 800)
273
- return 0.85;
274
- if (latency < 1500)
275
- return 0.7;
276
- if (latency < 3000)
277
- return 0.5;
278
- return Math.max(0.1, 1 - latency / 10000);
279
- }
280
- calculateErrorScore(providerId) {
281
- const errorRate = this.ewmaErrorRate.get(providerId) || 0;
282
- // Score: 1 - errorRate, but with floor
283
- return Math.max(0.05, 1 - errorRate);
284
- }
285
- calculateTrendScore(providerId) {
286
- const records = this.getRecords(providerId).filter(r => r.latency !== undefined);
287
- if (records.length < 5)
288
- return 1.0;
289
- // Compare recent 5 vs previous 5
290
- const recent = records.slice(-5);
291
- const previous = records.slice(-10, -5);
292
- if (previous.length === 0)
293
- return 1.0;
294
- const recentAvg = recent.reduce((sum, r) => sum + (r.latency || 0), 0) / recent.length;
295
- const previousAvg = previous.reduce((sum, r) => sum + (r.latency || 0), 0) / previous.length;
296
- // If improving (lower latency), score > 1
297
- // If degrading, score < 1
298
- const ratio = previousAvg / recentAvg;
299
- return Math.min(1.2, Math.max(0.6, ratio));
300
- }
301
- }
302
- exports.ProviderHealthMonitor = ProviderHealthMonitor;
303
- // ============================================================
304
- // Factory
305
- // ============================================================
306
- function createProviderHealthMonitor(config) {
307
- return new ProviderHealthMonitor(config);
308
- }
309
- //# sourceMappingURL=providerHealth.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"providerHealth.js","sourceRoot":"","sources":["../../src/providers/providerHealth.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;AA8XH,kEAEC;AAxUD,MAAM,cAAc,GAA2B;IAC7C,YAAY,EAAE,GAAG;IACjB,UAAU,EAAE,GAAG;IACf,aAAa,EAAE,EAAE;IACjB,gBAAgB,EAAE,GAAG;IACrB,gBAAgB,EAAE,IAAI;IACtB,iBAAiB,EAAE,GAAG;CACvB,CAAC;AAEF,+DAA+D;AAC/D,wBAAwB;AACxB,+DAA+D;AAE/D,MAAa,qBAAqB;IACxB,OAAO,GAAgC,IAAI,GAAG,EAAE,CAAC;IACjD,MAAM,CAAyB;IAC/B,WAAW,GAAwB,IAAI,GAAG,EAAE,CAAC;IAC7C,aAAa,GAAwB,IAAI,GAAG,EAAE,CAAC;IAC/C,aAAa,GAAwB,IAAI,GAAG,EAAE,CAAC;IAEvD,YAAY,SAAuB,EAAE;QACnC,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,MAAM,EAAE,CAAC;IACjD,CAAC;IAED;;OAEG;IACH,aAAa,CAAC,UAAkB,EAAE,SAAi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AC3C,CAAC"}
@@ -1,79 +0,0 @@
1
- /**
2
- * A3M Router - Difficulty Classifier
3
- *
4
- * Classifies queries as simple/medium/complex based on features.
5
- * Used to route queries to appropriate model tiers.
6
- *
7
- * Usage:
8
- * const classifier = new DifficultyClassifier();
9
- * const result = classifier.classify("What is Python?");
10
- * console.log(result); // { level: 'simple', confidence: 0.85, signals: [...] }
11
- *
12
- * const complex = classifier.classify("Implement a red-black tree in Rust with full tests");
13
- * console.log(complex); // { level: 'complex', confidence: 0.92, signals: [...] }
14
- */
15
- import { ProviderTier } from '../providers/providerConfig';
16
- export type DifficultyLevel = 'simple' | 'medium' | 'complex';
17
- export interface ClassificationResult {
18
- /** Difficulty level */
19
- level: DifficultyLevel;
20
- /** Confidence score 0-1 */
21
- confidence: number;
22
- /** Signals that contributed to the classification */
23
- signals: string[];
24
- /** Feature scores for each dimension */
25
- features: {
26
- length: number;
27
- keywords: number;
28
- reasoning: number;
29
- language: number;
30
- code: number;
31
- };
32
- /** Recommended model tier */
33
- recommendedTier: ProviderTier;
34
- /** Alternative tiers (in order of preference) */
35
- alternativeTiers: ProviderTier[];
36
- }
37
- export interface ClassifierConfig {
38
- /** Thresholds for classification */
39
- thresholds?: {
40
- simpleMax?: number;
41
- mediumMax?: number;
42
- };
43
- /** Enable keyword-based classification */
44
- useKeywords?: boolean;
45
- /** Enable linguistic complexity analysis */
46
- useLinguistic?: boolean;
47
- }
48
- export declare class DifficultyClassifier {
49
- private config;
50
- private trainingData;
51
- constructor(config?: ClassifierConfig);
52
- /**
53
- * Classify a query's difficulty.
54
- */
55
- classify(query: string): ClassificationResult;
56
- /**
57
- * Classify multiple queries.
58
- */
59
- classifyBatch(queries: string[]): ClassificationResult[];
60
- /**
61
- * Add training example for future improvements.
62
- */
63
- addTrainingExample(query: string, level: DifficultyLevel): void;
64
- /**
65
- * Get distribution of difficulties in a batch.
66
- */
67
- getDistribution(queries: string[]): Record<DifficultyLevel, number>;
68
- private calculateLengthScore;
69
- private calculateKeywordScore;
70
- private calculateReasoningScore;
71
- private calculateLanguageScore;
72
- private calculateCodeScore;
73
- private determineLevel;
74
- private calculateConfidence;
75
- private generateSignals;
76
- private determineTier;
77
- }
78
- export declare function createDifficultyClassifier(config?: ClassifierConfig): DifficultyClassifier;
79
- //# sourceMappingURL=difficultyClassifier.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"difficultyClassifier.d.ts","sourceRoot":"","sources":["../../src/routing/difficultyClassifier.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAM3D,MAAM,MAAM,eAAe,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,CAAC;AAE9D,MAAM,WAAW,oBAAoB;IACnC,uBAAuB;IACvB,KAAK,EAAE,eAAe,CAAC;IACvB,2BAA2B;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,qDAAqD;IACrD,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,wCAAwC;IACxC,QAAQ,EAAE;QACR,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,EAAE,MAAM,CAAC;QACjB,SAAS,EAAE,MAAM,CAAC;QAClB,QAAQ,EAAE,MAAM,CAAC;QACjB,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;IACF,6BAA6B;IAC7B,eAAe,EAAE,YAAY,CAAC;IAC9B,iDAAiD;IACjD,gBAAgB,EAAE,YAAY,EAAE,CAAC;CAClC;AAED,MAAM,WAAW,gBAAgB;IAC/B,oCAAoC;IACpC,UAAU,CAAC,EAAE;QACX,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC;IACF,0CAA0C;IAC1C,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,4CAA4C;IAC5C,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAmED,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,MAAM,CAA6B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