universal-llm-client 4.2.0 โ†’ 4.3.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 (97) hide show
  1. package/CHANGELOG.md +139 -103
  2. package/LICENSE +21 -21
  3. package/README.md +591 -591
  4. package/dist/ai-model.js.map +1 -1
  5. package/dist/auditor.js.map +1 -1
  6. package/dist/client.js.map +1 -1
  7. package/dist/http.js.map +1 -1
  8. package/dist/index.js.map +1 -1
  9. package/dist/interfaces.d.ts +20 -0
  10. package/dist/interfaces.d.ts.map +1 -1
  11. package/dist/interfaces.js.map +1 -1
  12. package/dist/mcp.js.map +1 -1
  13. package/dist/providers/anthropic.js.map +1 -1
  14. package/dist/providers/google.d.ts.map +1 -1
  15. package/dist/providers/google.js +2 -0
  16. package/dist/providers/google.js.map +1 -1
  17. package/dist/providers/index.js.map +1 -1
  18. package/dist/providers/ollama.js.map +1 -1
  19. package/dist/providers/openai.js.map +1 -1
  20. package/dist/router.js.map +1 -1
  21. package/dist/stream-decoder.js.map +1 -1
  22. package/dist/structured-output.js.map +1 -1
  23. package/dist/tools.js.map +1 -1
  24. package/dist/zod-adapter.js.map +1 -1
  25. package/package.json +115 -116
  26. package/src/ai-model.ts +0 -350
  27. package/src/auditor.ts +0 -213
  28. package/src/client.ts +0 -402
  29. package/src/debug/debug-google-streaming.ts +0 -97
  30. package/src/debug/debug-tool-execution.ts +0 -86
  31. package/src/debug/test-lmstudio-tools.ts +0 -155
  32. package/src/demos/README.md +0 -47
  33. package/src/demos/basic/universal-llm-examples.ts +0 -161
  34. package/src/demos/mcp/astrid-memory-demo.ts +0 -295
  35. package/src/demos/mcp/astrid-persona-memory.ts +0 -357
  36. package/src/demos/mcp/mcp-mongodb-demo.ts +0 -275
  37. package/src/demos/mcp/simple-astrid-memory.ts +0 -148
  38. package/src/demos/mcp/simple-mcp-demo.ts +0 -68
  39. package/src/demos/mcp/working-mcp-demo.ts +0 -62
  40. package/src/demos/model-alias-demo.ts +0 -0
  41. package/src/demos/tools/RAG_MEMORY_INTEGRATION.md +0 -267
  42. package/src/demos/tools/astrid-memory-demo.ts +0 -270
  43. package/src/demos/tools/astrid-production-memory-clean.ts +0 -785
  44. package/src/demos/tools/astrid-production-memory.ts +0 -558
  45. package/src/demos/tools/basic-translation-test.ts +0 -66
  46. package/src/demos/tools/chromadb-similarity-tuning.ts +0 -390
  47. package/src/demos/tools/clean-multilingual-conversation.ts +0 -209
  48. package/src/demos/tools/clean-translation-test.ts +0 -119
  49. package/src/demos/tools/clean-universal-multilingual-test.ts +0 -131
  50. package/src/demos/tools/complete-rag-demo.ts +0 -369
  51. package/src/demos/tools/complete-tool-demo.ts +0 -132
  52. package/src/demos/tools/demo-tool-calling.ts +0 -124
  53. package/src/demos/tools/dynamic-language-switching-test.ts +0 -251
  54. package/src/demos/tools/hybrid-thinking-test.ts +0 -154
  55. package/src/demos/tools/memory-integration-test.ts +0 -420
  56. package/src/demos/tools/multilingual-memory-system.ts +0 -802
  57. package/src/demos/tools/ondemand-translation-demo.ts +0 -655
  58. package/src/demos/tools/production-tool-demo.ts +0 -245
  59. package/src/demos/tools/revolutionary-multilingual-test.ts +0 -151
  60. package/src/demos/tools/rigorous-language-analysis.ts +0 -218
  61. package/src/demos/tools/test-universal-memory-system.ts +0 -126
  62. package/src/demos/tools/translation-integration-guide.ts +0 -346
  63. package/src/demos/tools/universal-memory-system.ts +0 -560
  64. package/src/http.ts +0 -247
  65. package/src/index.ts +0 -161
  66. package/src/interfaces.ts +0 -657
  67. package/src/mcp.ts +0 -345
  68. package/src/providers/anthropic.ts +0 -762
  69. package/src/providers/google.ts +0 -620
  70. package/src/providers/index.ts +0 -8
  71. package/src/providers/ollama.ts +0 -469
  72. package/src/providers/openai.ts +0 -392
  73. package/src/router.ts +0 -780
  74. package/src/stream-decoder.ts +0 -361
  75. package/src/structured-output.ts +0 -759
  76. package/src/test-scripts/test-advanced-tools.ts +0 -310
  77. package/src/test-scripts/test-google-streaming-enhanced.ts +0 -147
  78. package/src/test-scripts/test-google-streaming.ts +0 -63
  79. package/src/test-scripts/test-google-system-prompt-comprehensive.ts +0 -189
  80. package/src/test-scripts/test-mcp-config.ts +0 -28
  81. package/src/test-scripts/test-mcp-connection.ts +0 -29
  82. package/src/test-scripts/test-system-message-positions.ts +0 -163
  83. package/src/test-scripts/test-system-prompt-improvement-demo.ts +0 -83
  84. package/src/test-scripts/test-tool-calling.ts +0 -231
  85. package/src/tests/ai-model.test.ts +0 -1614
  86. package/src/tests/auditor.test.ts +0 -224
  87. package/src/tests/http.test.ts +0 -200
  88. package/src/tests/interfaces.test.ts +0 -117
  89. package/src/tests/providers/google.test.ts +0 -660
  90. package/src/tests/providers/ollama.test.ts +0 -954
  91. package/src/tests/providers/openai.test.ts +0 -1122
  92. package/src/tests/router.test.ts +0 -254
  93. package/src/tests/stream-decoder.test.ts +0 -179
  94. package/src/tests/structured-output.test.ts +0 -1450
  95. package/src/tests/tools.test.ts +0 -175
  96. package/src/tools.ts +0 -246
  97. package/src/zod-adapter.ts +0 -72
@@ -1,420 +0,0 @@
1
- /**
2
- * RAG Memory System Integration Test
3
- *
4
- * Objective validation of memory storage, recall, and filtering capabilities
5
- * using production ChromaDB and MongoDB services.
6
- */
7
-
8
- import '@dotenvx/dotenvx/config';
9
-
10
- import { AIModelFactory, ToolBuilder, LLMChatMessage } from '../../index';
11
- import { ChromaDBService } from '../../../../../src/services/ChromaDBService.js';
12
- import { DatabaseConnection } from '../../../../../src/database/connection.js';
13
- import { UserModel, UserGender, UserSexualOrientation } from '../../../../../src/models/User.js';
14
-
15
- // Core test validation metrics
16
- interface TestResults {
17
- storageTests: {
18
- meaningfulDataStored: number;
19
- trivialDataFiltered: number;
20
- emotionalContextCaptured: number;
21
- };
22
- recallTests: {
23
- freshSessionRecalls: number;
24
- searchQueriesSuccessful: number;
25
- categoryFiltersWorking: number;
26
- };
27
- integrationTests: {
28
- mongoDbConnected: boolean;
29
- chromaDbConnected: boolean;
30
- userCreationWorking: boolean;
31
- memoryPersistence: boolean;
32
- };
33
- overallScore: number;
34
- }
35
-
36
- function createTestMemoryTools(chromaService: ChromaDBService, userMongoId: string, testResults: TestResults) {
37
- const storeMemoryTool = ToolBuilder.createTool<{
38
- category: string;
39
- information: string;
40
- importance: 'low' | 'medium' | 'high';
41
- emotional_context?: string;
42
- relationship_stage?: string;
43
- }>(
44
- 'store_memory',
45
- 'Store important personal information for testing',
46
- {
47
- properties: {
48
- category: {
49
- type: 'string',
50
- description: 'Category of information',
51
- enum: ['interests', 'work', 'family', 'dreams', 'preferences', 'experiences', 'personality', 'relationships', 'fears', 'goals', 'values']
52
- },
53
- information: {
54
- type: 'string',
55
- description: 'The information to remember'
56
- },
57
- importance: {
58
- type: 'string',
59
- enum: ['low', 'medium', 'high'],
60
- description: 'Importance level'
61
- },
62
- emotional_context: {
63
- type: 'string',
64
- description: 'Emotional context when shared'
65
- },
66
- relationship_stage: {
67
- type: 'string',
68
- description: 'Relationship stage when shared'
69
- }
70
- },
71
- required: ['category', 'information', 'importance']
72
- },
73
- async (args) => {
74
- try {
75
- const conversationId = `test_chat_${Date.now()}`;
76
- const confidence = args.importance === 'high' ? 0.9 : args.importance === 'medium' ? 0.7 : 0.5;
77
-
78
- const insightId = await chromaService.addInsight(
79
- userMongoId,
80
- args.information,
81
- args.category,
82
- conversationId,
83
- confidence,
84
- '', // userPersonaId - empty for test
85
- '', // basePersonaId - empty for test
86
- 'user_insight',
87
- undefined,
88
- args.emotional_context,
89
- args.relationship_stage
90
- );
91
-
92
- console.log(`โœ… STORAGE TEST: Stored ${args.category} data successfully`);
93
- testResults.storageTests.meaningfulDataStored++;
94
-
95
- if (args.emotional_context) {
96
- testResults.storageTests.emotionalContextCaptured++;
97
- }
98
-
99
- return {
100
- success: true,
101
- insight_id: insightId,
102
- message: `Stored ${args.importance} importance ${args.category}`
103
- };
104
- } catch (error) {
105
- console.log(`โŒ STORAGE TEST: Failed - ${(error as Error).message}`);
106
- return {
107
- success: false,
108
- error: `Storage failed: ${(error as Error).message}`
109
- };
110
- }
111
- }
112
- );
113
-
114
- const recallMemoryTool = ToolBuilder.createTool<{
115
- search_query?: string;
116
- category?: string;
117
- limit?: number;
118
- }>(
119
- 'recall_memories',
120
- 'Retrieve stored memories for testing',
121
- {
122
- properties: {
123
- search_query: {
124
- type: 'string',
125
- description: 'Search for specific memories'
126
- },
127
- category: {
128
- type: 'string',
129
- description: 'Filter by category',
130
- enum: ['interests', 'work', 'family', 'dreams', 'preferences', 'experiences', 'personality', 'relationships', 'fears', 'goals', 'values']
131
- },
132
- limit: {
133
- type: 'number',
134
- description: 'Maximum memories to retrieve',
135
- default: 5
136
- }
137
- }
138
- },
139
- async (args) => {
140
- try {
141
- console.log(`๐Ÿ” RECALL TEST: "${args.search_query || args.category || 'all'}"`);
142
-
143
- let insights;
144
-
145
- if (args.search_query) {
146
- const result = await chromaService.searchSimilarInsights(
147
- userMongoId,
148
- args.search_query,
149
- args.limit || 5
150
- );
151
- insights = result.insights;
152
- testResults.recallTests.searchQueriesSuccessful++;
153
- } else {
154
- insights = await chromaService.getUserInsightsByCategory(
155
- userMongoId,
156
- args.category,
157
- '', // userPersonaId - empty for test
158
- args.limit || 5
159
- );
160
- testResults.recallTests.categoryFiltersWorking++;
161
- }
162
-
163
- console.log(` ๐Ÿ“Š Found ${insights.length} memories`);
164
-
165
- return {
166
- memories: insights.map(insight => ({
167
- category: insight.category,
168
- information: insight.content,
169
- emotional_context: insight.emotionalContext,
170
- confidence: insight.confidence
171
- })),
172
- total_found: insights.length
173
- };
174
- } catch (error) {
175
- console.log(` โŒ RECALL TEST: Failed - ${(error as Error).message}`);
176
- return {
177
- memories: [],
178
- total_found: 0,
179
- error: `Recall failed: ${(error as Error).message}`
180
- };
181
- }
182
- }
183
- );
184
-
185
- return [storeMemoryTool, recallMemoryTool];
186
- }
187
-
188
- async function createTestUser(userId: string): Promise<boolean> {
189
- try {
190
- const existingUser = await UserModel.findOne({ userId });
191
- if (existingUser) {
192
- console.log(`โœ… Test user already exists`);
193
- return true;
194
- }
195
-
196
- const testUser = new UserModel({
197
- userId,
198
- preferences: {
199
- userName: 'Test User',
200
- userGender: UserGender.PREFER_NOT_TO_SAY,
201
- userSexualOrientation: UserSexualOrientation.OTHER,
202
- preferredLanguage: 'en'
203
- }
204
- });
205
-
206
- await testUser.save();
207
- console.log(`โœ… Created test user`);
208
- return true;
209
- } catch (error) {
210
- console.error(`โŒ Failed to create test user: ${(error as Error).message}`);
211
- return false;
212
- }
213
- }
214
-
215
- async function runMemoryIntegrationTest() {
216
- console.log('๐Ÿงช RAG Memory System Integration Test\n');
217
-
218
- const testResults: TestResults = {
219
- storageTests: {
220
- meaningfulDataStored: 0,
221
- trivialDataFiltered: 0,
222
- emotionalContextCaptured: 0
223
- },
224
- recallTests: {
225
- freshSessionRecalls: 0,
226
- searchQueriesSuccessful: 0,
227
- categoryFiltersWorking: 0
228
- },
229
- integrationTests: {
230
- mongoDbConnected: false,
231
- chromaDbConnected: false,
232
- userCreationWorking: false,
233
- memoryPersistence: false
234
- },
235
- overallScore: 0
236
- };
237
-
238
- let userId: string = '';
239
- let userMongoId: string = '';
240
- let astrid: any = null;
241
-
242
- try {
243
- // Test 1: MongoDB Connection
244
- console.log('๐Ÿ”ง Test 1: MongoDB Connection');
245
- const dbConnection = DatabaseConnection.getInstance();
246
- await dbConnection.connect();
247
- testResults.integrationTests.mongoDbConnected = true;
248
- console.log('โœ… MongoDB: PASS\n');
249
-
250
- // Test 2: ChromaDB Connection
251
- console.log('๐Ÿ”ง Test 2: ChromaDB Connection');
252
- const chromaService = new ChromaDBService();
253
- await chromaService.initialize();
254
- testResults.integrationTests.chromaDbConnected = true;
255
- console.log('โœ… ChromaDB: PASS\n');
256
-
257
- // Test 3: User Management
258
- console.log('๐Ÿ”ง Test 3: User Management');
259
- userId = `test_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
260
- const userCreated = await createTestUser(userId);
261
- if (!userCreated) throw new Error('User creation failed');
262
-
263
- const user = await UserModel.findOne({ userId });
264
- if (!user || !user._id) throw new Error('User not found');
265
-
266
- userMongoId = user._id.toString();
267
- testResults.integrationTests.userCreationWorking = true;
268
- console.log('โœ… User Management: PASS\n');
269
-
270
- // Test 4: Memory Tools Setup
271
- console.log('๐Ÿ”ง Test 4: Memory Tools Setup');
272
- astrid = AIModelFactory.createOllamaChatModel('qwen3:8b');
273
- const memoryTools = createTestMemoryTools(chromaService, userMongoId, testResults);
274
- astrid.registerTools(memoryTools);
275
- await astrid.ensureReady();
276
- console.log('โœ… Memory Tools: PASS\n');
277
-
278
- // Test 5: Storage Functionality
279
- console.log('๐Ÿ”ง Test 5: Storage Tests');
280
-
281
- const storageTests = [
282
- {
283
- input: "I'm a software engineer specializing in healthcare AI",
284
- category: "work",
285
- importance: "high" as const,
286
- expected: "meaningful"
287
- },
288
- {
289
- input: "My sister has a rare genetic condition",
290
- category: "family",
291
- importance: "high" as const,
292
- emotional_context: "concerned",
293
- expected: "meaningful"
294
- },
295
- {
296
- input: "I love hiking in mountains",
297
- category: "interests",
298
- importance: "medium" as const,
299
- expected: "meaningful"
300
- }
301
- ];
302
-
303
- for (const test of storageTests) {
304
- const response = await astrid.chatWithTools([
305
- {
306
- role: 'system',
307
- content: `You are a test assistant. When given personal information, store it using the store_memory tool. Store meaningful information only.`
308
- },
309
- {
310
- role: 'user',
311
- content: test.input
312
- }
313
- ]);
314
- console.log(` ๐Ÿ“ Storage test: "${test.input.substring(0, 40)}..."`);
315
- }
316
-
317
- // Test 6: Recall Functionality
318
- console.log('\n๐Ÿ”ง Test 6: Recall Tests');
319
-
320
- const recallTests = [
321
- { query: "work healthcare", type: "search" },
322
- { category: "family", type: "category" },
323
- { category: "interests", type: "category" }
324
- ];
325
-
326
- for (const test of recallTests) {
327
- const response = await astrid.chatWithTools([
328
- {
329
- role: 'system',
330
- content: `You are a test assistant. Use recall_memories to find information about the user.`
331
- },
332
- {
333
- role: 'user',
334
- content: test.type === 'search'
335
- ? `Find memories related to: ${test.query}`
336
- : `Find memories in category: ${test.category}`
337
- }
338
- ]);
339
- console.log(` ๐Ÿ” Recall test: ${test.type} - ${test.query || test.category}`);
340
- testResults.recallTests.freshSessionRecalls++;
341
- }
342
-
343
- // Test 7: Memory Persistence
344
- console.log('\n๐Ÿ”ง Test 7: Memory Persistence');
345
- const allMemories = await chromaService.getUserInsightsByCategory(
346
- userMongoId,
347
- undefined,
348
- '' // userPersonaId - empty for test
349
- );
350
-
351
- if (allMemories.length > 0) {
352
- testResults.integrationTests.memoryPersistence = true;
353
- console.log(`โœ… Memory Persistence: PASS (${allMemories.length} memories stored)`);
354
- } else {
355
- console.log('โŒ Memory Persistence: FAIL (no memories found)');
356
- }
357
-
358
- // Calculate overall score
359
- const totalChecks = Object.values(testResults.integrationTests).length +
360
- testResults.storageTests.meaningfulDataStored +
361
- testResults.recallTests.freshSessionRecalls;
362
-
363
- const passedChecks = Object.values(testResults.integrationTests).filter(Boolean).length +
364
- testResults.storageTests.meaningfulDataStored +
365
- testResults.recallTests.freshSessionRecalls;
366
-
367
- testResults.overallScore = Math.round((passedChecks / totalChecks) * 100);
368
-
369
- // Final Results
370
- console.log('\n๐Ÿ“Š === TEST RESULTS ===');
371
- console.log(`Overall Score: ${testResults.overallScore}%`);
372
- console.log('\n๐Ÿ”ง Integration Tests:');
373
- console.log(` MongoDB Connected: ${testResults.integrationTests.mongoDbConnected ? 'โœ…' : 'โŒ'}`);
374
- console.log(` ChromaDB Connected: ${testResults.integrationTests.chromaDbConnected ? 'โœ…' : 'โŒ'}`);
375
- console.log(` User Creation: ${testResults.integrationTests.userCreationWorking ? 'โœ…' : 'โŒ'}`);
376
- console.log(` Memory Persistence: ${testResults.integrationTests.memoryPersistence ? 'โœ…' : 'โŒ'}`);
377
-
378
- console.log('\n๐Ÿ’พ Storage Tests:');
379
- console.log(` Meaningful Data Stored: ${testResults.storageTests.meaningfulDataStored}`);
380
- console.log(` Emotional Context Captured: ${testResults.storageTests.emotionalContextCaptured}`);
381
-
382
- console.log('\n๐Ÿ” Recall Tests:');
383
- console.log(` Fresh Session Recalls: ${testResults.recallTests.freshSessionRecalls}`);
384
- console.log(` Search Queries Successful: ${testResults.recallTests.searchQueriesSuccessful}`);
385
- console.log(` Category Filters Working: ${testResults.recallTests.categoryFiltersWorking}`);
386
-
387
- console.log('\n๐Ÿ’พ Stored Memories:');
388
- allMemories.forEach((memory, index) => {
389
- console.log(` ${index + 1}. [${memory.category?.toUpperCase()}] ${memory.content.substring(0, 80)}...`);
390
- });
391
-
392
- } catch (error) {
393
- console.error(`โŒ Test failed: ${(error as Error).message}`);
394
- testResults.overallScore = 0;
395
- } finally {
396
- // Cleanup
397
- if (astrid) astrid.dispose();
398
-
399
- if (userId) {
400
- try {
401
- await UserModel.deleteOne({ userId });
402
- console.log('\n๐Ÿ—‘๏ธ Test user cleaned up');
403
- } catch (cleanupError) {
404
- console.warn(`โš ๏ธ Cleanup warning: ${(cleanupError as Error).message}`);
405
- }
406
- }
407
-
408
- console.log('\n๐Ÿงช Memory integration test completed!\n');
409
- }
410
-
411
- return testResults;
412
- }
413
-
414
- // Export the test function
415
- export { runMemoryIntegrationTest };
416
-
417
- // Run if called directly
418
- if (require.main === module) {
419
- runMemoryIntegrationTest().catch(console.error);
420
- }