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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adaptive-memory-multi-model-router",
3
- "version": "2.3.0",
3
+ "version": "2.4.0",
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.",
@@ -0,0 +1,328 @@
1
+ """
2
+ Tests for SkillManager and TMLEnhancedAgent
3
+ """
4
+
5
+ import { describe, it, expect, beforeEach, jest } from '@jest/globals';
6
+ import { SkillManager, Skill } from '../skill_manager';
7
+ import { TMLEnhancedAgent } from '../../agents/skill_enhanced_agent';
8
+ import * as fs from 'fs';
9
+ import * as path from 'path';
10
+
11
+ // Mock fs operations
12
+ jest.mock('fs');
13
+
14
+ describe('SkillManager', () => {
15
+ let skillManager: SkillManager;
16
+ const mockSkillsDir = '/mock/skills';
17
+
18
+ beforeEach(() => {
19
+ jest.clearAllMocks();
20
+ skillManager = new SkillManager(mockSkillsDir);
21
+ });
22
+
23
+ describe('initialization', () => {
24
+ it('should create skill manager instance', () => {
25
+ expect(skillManager).toBeInstanceOf(SkillManager);
26
+ expect(skillManager.skills_dir).toBeDefined();
27
+ });
28
+
29
+ it('should have empty skills initially if directory does not exist', () => {
30
+ expect(skillManager.list_skills()).toEqual([]);
31
+ });
32
+ });
33
+
34
+ describe('load_skills_metadata', () => {
35
+ it('should load skill metadata from SKILL.md files', () => {
36
+ // Mock directory listing and file reading
37
+ const mockSkillMD = `---
38
+ name: "Test Skill"
39
+ description: "A test skill for testing"
40
+ ---
41
+ # Test Skill Content`;
42
+
43
+ jest.spyOn(fs, 'existsSync').mockReturnValue(true);
44
+ jest.spyOn(Path.prototype, 'isDirectory').mockReturnValue(true);
45
+ jest.spyOn(Path.prototype, 'iterdir').mockReturnValue([
46
+ { name: 'SKILL.md', isFile: () => true }
47
+ ] as any);
48
+ jest.spyOn(fs, 'readFileSync').mockReturnValue(mockSkillMD);
49
+
50
+ skillManager.reload_skills();
51
+
52
+ expect(skillManager.list_skills()).toContain('Test Skill');
53
+ });
54
+
55
+ it('should skip directories without SKILL.md', () => {
56
+ jest.spyOn(Path.prototype, 'existsSync').mockReturnValue(false);
57
+
58
+ skillManager.reload_skills();
59
+
60
+ expect(skillManager.list_skills()).toEqual([]);
61
+ });
62
+ });
63
+
64
+ describe('get_relevant_skills', () => {
65
+ beforeEach(() => {
66
+ // Add mock skills
67
+ skillManager.skills['React Development'] = new Skill(
68
+ 'React Development',
69
+ 'Best practices for React components',
70
+ Path('/mock/react'),
71
+ {}
72
+ );
73
+
74
+ skillManager.skills['Node.js API'] = new Skill(
75
+ 'Node.js API',
76
+ 'Building backend APIs with Node.js and Express',
77
+ Path('/mock/nodejs'),
78
+ {}
79
+ );
80
+
81
+ skillManager.skills['Python Django'] = new Skill(
82
+ 'Python Django',
83
+ 'Django web framework for Python',
84
+ Path('/mock/python'),
85
+ {}
86
+ );
87
+ });
88
+
89
+ it('should find skills with keyword matching', () => {
90
+ const relevant = skillManager.get_relevant_skills(
91
+ 'Build a React component for user login',
92
+ 2
93
+ );
94
+
95
+ expect(relevant).toContain('React Development');
96
+ });
97
+
98
+ it('should return skills ordered by relevance', () => {
99
+ const relevant = skillManager.get_relevant_skills(
100
+ 'Create a React component with Node.js backend',
101
+ 3
102
+ );
103
+
104
+ // React should come first (exact match)
105
+ expect(relevant[0]).toBe('React Development');
106
+ expect(relevant).toContain('Node.js API');
107
+ });
108
+
109
+ it('should respect threshold parameter', () => {
110
+ const relevant = skillManager.get_relevant_skills(
111
+ 'Build a Go microservice',
112
+ 2,
113
+ 0.5 // Higher threshold
114
+ );
115
+
116
+ // Should return fewer or no skills due to high threshold
117
+ expect(relevant.length).toBeLessThanOrEqual(2);
118
+ });
119
+ });
120
+
121
+ describe('load_skill', () => {
122
+ it('should load full skill content on first call', () => {
123
+ const mockSkill = skillManager.skills['React Development'];
124
+ mockSkill.content = null;
125
+
126
+ const mockContent = '# React Development\n\nBest practices...';
127
+
128
+ jest.spyOn(fs, 'readFileSync').mockReturnValue(
129
+ `---\nname: "React Development"\ndescription: "Best practices"\n---\n${mockContent}`
130
+ );
131
+
132
+ const loaded = skillManager.load_skill('React Development');
133
+
134
+ expect(loaded.content).toBe(mockContent);
135
+ expect(loaded.loaded_at).toBeDefined();
136
+ });
137
+
138
+ it('should return cached content on subsequent calls', () => {
139
+ const mockSkill = skillManager.skills['React Development'];
140
+ mockSkill.content = 'Cached content';
141
+
142
+ const loaded1 = skillManager.load_skill('React Development');
143
+ const loaded2 = skillManager.load_skill('React Development');
144
+
145
+ expect(loaded1).toBe(loaded2);
146
+ expect(loaded1.content).toBe('Cached content');
147
+ });
148
+
149
+ it('should throw error for non-existent skill', () => {
150
+ expect(() => {
151
+ skillManager.load_skill('Non-existent Skill');
152
+ }).toThrow("Skill 'Non-existent Skill' not found");
153
+ });
154
+ });
155
+
156
+ describe('validate_skill', () => {
157
+ it('should return validation results for existing skill', () => {
158
+ const mockSkill = skillManager.skills['React Development'];
159
+
160
+ jest.spyOn(skillManager, 'list_additional_files').mockReturnValue([]);
161
+
162
+ const validation = skillManager.validate_skill('React Development');
163
+
164
+ expect(validation).toHaveProperty('exists', true);
165
+ expect(validation).toHaveProperty('has_name', true);
166
+ expect(validation).toHaveProperty('has_description', true);
167
+ });
168
+
169
+ it('should return all false for non-existent skill', () => {
170
+ const validation = skillManager.validate_skill('Non-existent');
171
+
172
+ expect(validation.exists).toBe(false);
173
+ expect(validation.has_skill_md).toBe(false);
174
+ });
175
+ });
176
+ });
177
+
178
+ describe('TMLEnhancedAgent', () => {
179
+ let agent: TMLEnhancedAgent;
180
+
181
+ beforeEach(() => {
182
+ agent = new TMLEnhancedAgent(
183
+ 'frontend-agent',
184
+ 'anthropic',
185
+ 'claude-sonnet-4',
186
+ 'mock-skills',
187
+ ['React Frontend Development', 'TypeScript Best Practices']
188
+ );
189
+ });
190
+
191
+ describe('initialization', () => {
192
+ it('should create agent with configuration', () => {
193
+ expect(agent.agent_id).toBe('frontend-agent');
194
+ expect(agent.provider).toBe('anthropic');
195
+ expect(agent.model).toBe('claude-sonnet-4');
196
+ });
197
+
198
+ it('should initialize with assigned skills', () => {
199
+ expect(agent.assigned_skills).toContain('React Frontend Development');
200
+ expect(agent.assigned_skills).toContain('TypeScript Best Practices');
201
+ });
202
+ });
203
+
204
+ describe('execute_task', () => {
205
+ it('should execute task with relevant skills', async () => {
206
+ const task = {
207
+ description: 'Build a React login form component',
208
+ context: 'Must include email and password fields',
209
+ requirements: 'Use TypeScript and Material-UI'
210
+ };
211
+
212
+ // Mock skill loading
213
+ jest.spyOn(agent, '_get_relevant_skills').mockReturnValue([]);
214
+
215
+ // Mock LLM call
216
+ jest.spyOn(agent, '_execute_llm_call').mockReturnValue({
217
+ success: true,
218
+ output: 'React component code...',
219
+ tokens_used: 150,
220
+ cost: 0.015,
221
+ execution_time: 3.2
222
+ });
223
+
224
+ const result = agent.execute_task(task);
225
+
226
+ expect(result.success).toBe(true);
227
+ expect(result.output).toBeDefined();
228
+ });
229
+
230
+ it('should remember successful patterns', () => {
231
+ const task = { description: 'Test task' };
232
+
233
+ jest.spyOn(agent, '_get_relevant_skills').mockReturnValue([]);
234
+ jest.spyOn(agent, '_execute_llm_call').mockReturnValue({
235
+ success: true,
236
+ output: 'Success'
237
+ });
238
+
239
+ jest.spyOn(agent, '_remember_success_pattern').mockImplementation(() => {});
240
+
241
+ agent.execute_task(task);
242
+
243
+ expect(agent._remember_success_pattern).toHaveBeenCalled();
244
+ });
245
+ });
246
+
247
+ describe('skill management', () => {
248
+ it('should add skill to agent', () => {
249
+ agent.add_skill('Jest Testing');
250
+
251
+ expect(agent.assigned_skills).toContain('Jest Testing');
252
+ });
253
+
254
+ it('should remove skill from agent', () => {
255
+ agent.remove_skill('TypeScript Best Practices');
256
+
257
+ expect(agent.assigned_skills).not.toContain('TypeScript Best Practices');
258
+ });
259
+
260
+ it('should list all available skills', () => {
261
+ jest.spyOn(agent.skill_manager, 'list_skills').mockReturnValue([
262
+ 'Skill 1',
263
+ 'Skill 2',
264
+ 'Skill 3'
265
+ ]);
266
+
267
+ const skills = agent.list_available_skills();
268
+
269
+ expect(skills).toHaveLength(3);
270
+ });
271
+ });
272
+
273
+ describe('serialization', () => {
274
+ it('should convert to dictionary', () => {
275
+ const dict = agent.to_dict();
276
+
277
+ expect(dict).toHaveProperty('agent_id', 'frontend-agent');
278
+ expect(dict).toHaveProperty('provider', 'anthropic');
279
+ expect(dict).toHaveProperty('model', 'claude-sonnet-4');
280
+ expect(dict).toHaveProperty('assigned_skills');
281
+ expect(dict).toHaveProperty('available_skills');
282
+ });
283
+ });
284
+ });
285
+
286
+ describe('TMLEnhancedAgentFactory', () => {
287
+ describe('create_from_config', () => {
288
+ it('should create agent from config', () => {
289
+ const config = {
290
+ id: 'test-agent',
291
+ provider: 'openai',
292
+ model: 'gpt-4-turbo',
293
+ skills_dir: 'test-skills',
294
+ skills: ['Test Skill']
295
+ };
296
+
297
+ const agent = TMLEnhancedAgentFactory.create_from_config(config);
298
+
299
+ expect(agent).toBeInstanceOf(TMLEnhancedAgent);
300
+ expect(agent.agent_id).toBe('test-agent');
301
+ });
302
+ });
303
+
304
+ describe('create_multiple_from_config', () => {
305
+ it('should create multiple agents from config list', () => {
306
+ const configs = [
307
+ {
308
+ id: 'agent-1',
309
+ provider: 'anthropic',
310
+ model: 'claude-sonnet-4',
311
+ skills: ['Skill A']
312
+ },
313
+ {
314
+ id: 'agent-2',
315
+ provider: 'openai',
316
+ model: 'gpt-4-turbo',
317
+ skills: ['Skill B']
318
+ }
319
+ ];
320
+
321
+ const agents = TMLEnhancedAgentFactory.create_multiple_from_config(configs);
322
+
323
+ expect(agents).toHaveLength(2);
324
+ expect(agents[0].agent_id).toBe('agent-1');
325
+ expect(agents[1].agent_id).toBe('agent-2');
326
+ });
327
+ });
328
+ });