@aj-archipelago/cortex 1.4.0 → 1.4.1

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 (32) hide show
  1. package/config.js +25 -4
  2. package/helper-apps/cortex-autogen2/agents.py +19 -6
  3. package/helper-apps/cortex-autogen2/services/azure_ai_search.py +115 -0
  4. package/helper-apps/cortex-autogen2/services/run_analyzer.py +594 -0
  5. package/helper-apps/cortex-autogen2/task_processor.py +98 -2
  6. package/lib/crypto.js +66 -1
  7. package/lib/doubleEncryptionStorageClient.js +97 -0
  8. package/lib/entityConstants.js +12 -35
  9. package/lib/util.js +33 -6
  10. package/package.json +2 -1
  11. package/pathways/system/entity/memory/sys_memory_manager.js +1 -0
  12. package/pathways/system/entity/memory/sys_memory_process.js +4 -3
  13. package/pathways/system/entity/memory/sys_memory_update.js +4 -3
  14. package/pathways/system/entity/memory/sys_read_memory.js +12 -4
  15. package/pathways/system/entity/memory/sys_save_memory.js +16 -9
  16. package/pathways/system/entity/memory/sys_search_memory.js +5 -4
  17. package/pathways/system/entity/sys_entity_agent.js +2 -1
  18. package/pathways/system/entity/tools/sys_tool_bing_search.js +2 -2
  19. package/pathways/system/entity/tools/sys_tool_bing_search_afagent.js +1 -2
  20. package/pathways/system/entity/tools/sys_tool_callmodel.js +2 -1
  21. package/pathways/system/entity/tools/sys_tool_coding.js +1 -2
  22. package/pathways/system/entity/tools/sys_tool_grok_x_search.js +1 -1
  23. package/pathways/system/entity/tools/sys_tool_image.js +2 -1
  24. package/pathways/system/entity/tools/sys_tool_image_gemini.js +3 -3
  25. package/pathways/system/entity/tools/sys_tool_mermaid.js +187 -38
  26. package/pathways/system/entity/tools/sys_tool_reasoning.js +2 -0
  27. package/pathways/system/entity/tools/sys_tool_verify.js +1 -1
  28. package/pathways/transcribe_gemini.js +3 -2
  29. package/server/graphql.js +1 -1
  30. package/server/pathwayResolver.js +8 -7
  31. package/server/plugins/veoVideoPlugin.js +29 -1
  32. package/tests/unit/core/crypto.test.js +163 -0
@@ -0,0 +1,163 @@
1
+ // crypto.test.js
2
+ // Tests for encryption and decryption functions in cortex/lib/crypto.js
3
+
4
+ import test from 'ava';
5
+ import { encrypt, decrypt, doubleEncrypt, doubleDecrypt } from '../../../lib/crypto.js';
6
+
7
+ // Test data
8
+ const testData = 'Hello, this is test data!';
9
+ const systemKey = '1234567890123456789012345678901234567890123456789012345678901234'; // 64 hex chars
10
+ const userKey = 'abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890'; // 64 hex chars
11
+ const wrongUserKey = '0000000000000000000000000000000000000000000000000000000000000000'; // 64 hex chars
12
+ const wrongSystemKey = 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'; // 64 hex chars
13
+
14
+ // Basic encryption/decryption tests
15
+ test('encrypt should encrypt data with valid key', t => {
16
+ const encrypted = encrypt(testData, systemKey);
17
+ t.truthy(encrypted);
18
+ t.not(encrypted, testData);
19
+ t.true(encrypted.includes(':'));
20
+ });
21
+
22
+ test('decrypt should decrypt data with correct key', t => {
23
+ const encrypted = encrypt(testData, systemKey);
24
+ const decrypted = decrypt(encrypted, systemKey);
25
+ t.is(decrypted, testData);
26
+ });
27
+
28
+ test('encrypt should return original data when no key provided', t => {
29
+ const result = encrypt(testData, null);
30
+ t.is(result, testData);
31
+ });
32
+
33
+ test('decrypt should return original data when no key provided', t => {
34
+ const result = decrypt(testData, null);
35
+ t.is(result, testData);
36
+ });
37
+
38
+ // Double encryption tests
39
+ test('doubleEncrypt should encrypt with system key only when no user key', t => {
40
+ const encrypted = doubleEncrypt(testData, null, systemKey);
41
+ t.truthy(encrypted);
42
+ t.not(encrypted, testData);
43
+
44
+ // Should be decryptable with system key only
45
+ const decrypted = decrypt(encrypted, systemKey);
46
+ t.is(decrypted, testData);
47
+ });
48
+
49
+ test('doubleEncrypt should encrypt with both keys when user key provided', t => {
50
+ const encrypted = doubleEncrypt(testData, userKey, systemKey);
51
+ t.truthy(encrypted);
52
+ t.not(encrypted, testData);
53
+
54
+ // Should NOT be decryptable with system key only (it will be user-encrypted data)
55
+ const systemOnlyDecrypted = decrypt(encrypted, systemKey);
56
+ t.not(systemOnlyDecrypted, testData);
57
+ t.truthy(systemOnlyDecrypted); // Should return user-encrypted data, not null
58
+ });
59
+
60
+ test('doubleEncrypt should fail when no system key provided', t => {
61
+ const encrypted = doubleEncrypt(testData, userKey, null);
62
+ t.is(encrypted, null);
63
+ });
64
+
65
+ test('doubleEncrypt should fallback to system key when user encryption fails', t => {
66
+ // Use invalid user key to force fallback
67
+ const invalidUserKey = 'invalid';
68
+ const encrypted = doubleEncrypt(testData, invalidUserKey, systemKey);
69
+ t.truthy(encrypted);
70
+
71
+ // Should be decryptable with system key only (fallback behavior)
72
+ const decrypted = decrypt(encrypted, systemKey);
73
+ t.is(decrypted, testData);
74
+ });
75
+
76
+ // Double decryption tests
77
+ test('doubleDecrypt should decrypt with system key only when no user key', t => {
78
+ const encrypted = encrypt(testData, systemKey);
79
+ const decrypted = doubleDecrypt(encrypted, null, systemKey);
80
+ t.is(decrypted, testData);
81
+ });
82
+
83
+ test('doubleDecrypt should decrypt double-encrypted data with both keys', t => {
84
+ const encrypted = doubleEncrypt(testData, userKey, systemKey);
85
+ const decrypted = doubleDecrypt(encrypted, userKey, systemKey);
86
+ t.is(decrypted, testData);
87
+ });
88
+
89
+ test('doubleDecrypt should handle single-encrypted data when user key provided', t => {
90
+ // This is the key scenario we fixed!
91
+ const singleEncrypted = encrypt(testData, systemKey);
92
+ const decrypted = doubleDecrypt(singleEncrypted, userKey, systemKey);
93
+ t.is(decrypted, testData);
94
+ });
95
+
96
+ test('doubleDecrypt should fail when no system key provided', t => {
97
+ const encrypted = encrypt(testData, systemKey);
98
+ const decrypted = doubleDecrypt(encrypted, userKey, null);
99
+ t.is(decrypted, null);
100
+ });
101
+
102
+ test('doubleDecrypt should fail when system decryption fails', t => {
103
+ const encrypted = encrypt(testData, systemKey);
104
+ const wrongSystemKey = 'wrongkey123456789012345678901234567890123456789012345678901234567890';
105
+ const decrypted = doubleDecrypt(encrypted, userKey, wrongSystemKey);
106
+ t.is(decrypted, null);
107
+ });
108
+
109
+ test('doubleDecrypt should return system-decrypted data when user decryption fails for double-encrypted data', t => {
110
+ const encrypted = doubleEncrypt(testData, userKey, systemKey);
111
+ const decrypted = doubleDecrypt(encrypted, wrongUserKey, systemKey);
112
+ // Should return the user-encrypted data (system decryption succeeded, user decryption failed)
113
+ t.not(decrypted, testData); // Should not be the original data
114
+ t.truthy(decrypted); // Should return some data (user-encrypted)
115
+ });
116
+
117
+ // Edge cases and error handling
118
+ test('encrypt should handle empty string', t => {
119
+ const encrypted = encrypt('', systemKey);
120
+ t.truthy(encrypted);
121
+ const decrypted = decrypt(encrypted, systemKey);
122
+ t.is(decrypted, '');
123
+ });
124
+
125
+ test('encrypt should handle special characters', t => {
126
+ const specialData = 'Special chars: !@#$%^&*()_+-=[]{}|;:,.<>?';
127
+ const encrypted = encrypt(specialData, systemKey);
128
+ const decrypted = decrypt(encrypted, systemKey);
129
+ t.is(decrypted, specialData);
130
+ });
131
+
132
+ test('encrypt should handle unicode characters', t => {
133
+ const unicodeData = 'Unicode: 🚀 🌟 ñáéíóú 中文 العربية';
134
+ const encrypted = encrypt(unicodeData, systemKey);
135
+ const decrypted = decrypt(encrypted, systemKey);
136
+ t.is(decrypted, unicodeData);
137
+ });
138
+
139
+ test('doubleEncrypt should handle JSON data', t => {
140
+ const jsonData = JSON.stringify({ message: 'test', number: 42, array: [1, 2, 3] });
141
+ const encrypted = doubleEncrypt(jsonData, userKey, systemKey);
142
+ const decrypted = doubleDecrypt(encrypted, userKey, systemKey);
143
+ t.is(decrypted, jsonData);
144
+ });
145
+
146
+ // Integration test for the specific scenario we fixed
147
+ test('CRITICAL: doubleDecrypt should handle mixed encryption states', t => {
148
+ // Simulate a migration scenario where some data is single-encrypted
149
+ // and some is double-encrypted, but we always pass both keys
150
+
151
+ // Single-encrypted data (old format)
152
+ const singleEncrypted = encrypt(testData, systemKey);
153
+
154
+ // Double-encrypted data (new format)
155
+ const doubleEncrypted = doubleEncrypt(testData, userKey, systemKey);
156
+
157
+ // Both should be readable with both keys provided
158
+ const singleDecrypted = doubleDecrypt(singleEncrypted, userKey, systemKey);
159
+ const doubleDecrypted = doubleDecrypt(doubleEncrypted, userKey, systemKey);
160
+
161
+ t.is(singleDecrypted, testData, 'Single-encrypted data should be readable with both keys');
162
+ t.is(doubleDecrypted, testData, 'Double-encrypted data should be readable with both keys');
163
+ });