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

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 (63) hide show
  1. package/README.md +17 -22
  2. package/README.md.bak +836 -0
  3. package/dist/analytics/costAnalytics.d.ts +1 -0
  4. package/dist/cache/cacheKeyGenerator.d.ts +67 -0
  5. package/dist/cache/cacheKeyGenerator.d.ts.map +1 -0
  6. package/dist/cache/cacheKeyGenerator.js +211 -0
  7. package/dist/cache/cacheKeyGenerator.js.map +1 -0
  8. package/dist/cache/semanticCache.d.ts +41 -0
  9. package/dist/cache/semanticCache.d.ts.map +1 -1
  10. package/dist/cache/semanticCache.js +142 -0
  11. package/dist/cache/semanticCache.js.map +1 -1
  12. package/dist/cli.js +35 -478
  13. package/dist/cost/costTracker.js +0 -3
  14. package/dist/cost/preCallCostEstimator.d.ts +114 -0
  15. package/dist/cost/preCallCostEstimator.d.ts.map +1 -0
  16. package/dist/cost/preCallCostEstimator.js +256 -0
  17. package/dist/cost/preCallCostEstimator.js.map +1 -0
  18. package/dist/index.d.ts +16 -0
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +264 -64
  21. package/dist/index.js.map +1 -1
  22. package/dist/inference/speculativeDecoding.d.ts +133 -0
  23. package/dist/inference/speculativeDecoding.d.ts.map +1 -0
  24. package/dist/inference/speculativeDecoding.js +276 -0
  25. package/dist/inference/speculativeDecoding.js.map +1 -0
  26. package/dist/integrations/langchainAdapter.d.ts +1 -0
  27. package/dist/integrations/oauth.d.ts +1 -0
  28. package/dist/memory/autoFetch.d.ts +1 -0
  29. package/dist/memory/memoryTree.d.ts +1 -0
  30. package/dist/memory/obsidianVault.d.ts +1 -0
  31. package/dist/providers/providerConfig.d.ts +1 -0
  32. package/dist/providers/providerConfig.js +2 -0
  33. package/dist/providers/providerHealth.d.ts +117 -0
  34. package/dist/providers/providerHealth.d.ts.map +1 -0
  35. package/dist/providers/providerHealth.js +309 -0
  36. package/dist/providers/providerHealth.js.map +1 -0
  37. package/dist/providers/registry.js +126 -128
  38. package/dist/routing/advancedRouter.js +310 -427
  39. package/dist/routing/difficultyClassifier.d.ts +79 -0
  40. package/dist/routing/difficultyClassifier.d.ts.map +1 -0
  41. package/dist/routing/difficultyClassifier.js +329 -0
  42. package/dist/routing/difficultyClassifier.js.map +1 -0
  43. package/dist/sdk.d.ts +125 -0
  44. package/dist/sdk.d.ts.map +1 -0
  45. package/dist/sdk.js +109 -100
  46. package/dist/sdk.js.map +1 -0
  47. package/dist/security/guardrails.d.ts +1 -0
  48. package/dist/server/dashboard.d.ts +1 -0
  49. package/dist/server/modelMapper.d.ts +1 -0
  50. package/dist/server/proxyServer.d.ts +1 -0
  51. package/package.json +106 -3
  52. package/src/cache/cacheKeyGenerator.ts +242 -0
  53. package/src/cache/semanticCache.ts +148 -0
  54. package/src/cost/preCallCostEstimator.ts +345 -0
  55. package/src/inference/speculativeDecoding.ts +373 -0
  56. package/src/providers/providerHealth.ts +397 -0
  57. package/src/routing/difficultyClassifier.ts +420 -0
  58. package/test/provider-test.js +2 -2
  59. package/test.js +7 -7
  60. package/test.js.bak +376 -0
  61. package/tsconfig.json +15 -5
  62. package/src/index.ts +0 -99
  63. package/src/skills/__tests__/skill_manager.test.ts +0 -328
@@ -1,328 +0,0 @@
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
- });