@aj-archipelago/cortex 1.3.32 → 1.3.34

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 (34) hide show
  1. package/helper-apps/cortex-autogen/OAI_CONFIG_LIST +1 -1
  2. package/lib/encodeCache.js +22 -10
  3. package/lib/pathwayTools.js +10 -3
  4. package/lib/requestExecutor.js +1 -1
  5. package/lib/util.js +136 -1
  6. package/package.json +2 -2
  7. package/pathways/system/entity/memory/sys_memory_manager.js +2 -1
  8. package/pathways/system/entity/sys_entity_continue.js +10 -2
  9. package/pathways/system/entity/sys_entity_start.js +12 -10
  10. package/pathways/system/entity/sys_router_tool.js +2 -2
  11. package/server/chunker.js +23 -3
  12. package/server/pathwayResolver.js +2 -5
  13. package/server/plugins/claude3VertexPlugin.js +2 -3
  14. package/server/plugins/cohereGeneratePlugin.js +1 -1
  15. package/server/plugins/gemini15ChatPlugin.js +1 -1
  16. package/server/plugins/geminiChatPlugin.js +1 -1
  17. package/server/plugins/localModelPlugin.js +1 -1
  18. package/server/plugins/modelPlugin.js +332 -77
  19. package/server/plugins/openAiChatPlugin.js +1 -1
  20. package/server/plugins/openAiCompletionPlugin.js +1 -1
  21. package/server/plugins/palmChatPlugin.js +1 -1
  22. package/server/plugins/palmCodeCompletionPlugin.js +1 -1
  23. package/server/plugins/palmCompletionPlugin.js +1 -1
  24. package/tests/chunkfunction.test.js +9 -6
  25. package/tests/claude3VertexPlugin.test.js +81 -3
  26. package/tests/data/largecontent.txt +1 -0
  27. package/tests/data/mixedcontent.txt +1 -0
  28. package/tests/encodeCache.test.js +47 -14
  29. package/tests/modelPlugin.test.js +21 -0
  30. package/tests/multimodal_conversion.test.js +1 -1
  31. package/tests/subscription.test.js +7 -1
  32. package/tests/tokenHandlingTests.test.js +587 -0
  33. package/tests/truncateMessages.test.js +404 -46
  34. package/tests/util.test.js +146 -0
@@ -2,8 +2,22 @@ import test from 'ava';
2
2
  import Claude3VertexPlugin from '../server/plugins/claude3VertexPlugin.js';
3
3
  import { mockPathwayResolverMessages } from './mocks.js';
4
4
  import { config } from '../config.js';
5
+ import fs from 'fs';
6
+ import path from 'path';
5
7
 
6
- const { pathway, modelName, model } = mockPathwayResolverMessages;
8
+ // Helper function to load test data from files
9
+ function loadTestData(filename) {
10
+ try {
11
+ const filePath = path.join(process.cwd(), 'tests', 'data', filename);
12
+ return fs.readFileSync(filePath, 'utf8');
13
+ } catch (error) {
14
+ console.error(`Error loading test data file ${filename}:`, error);
15
+ // Return a smaller fallback test string if file loading fails
16
+ return 'a '.repeat(1000);
17
+ }
18
+ }
19
+
20
+ const { pathway, model } = mockPathwayResolverMessages;
7
21
 
8
22
  test('constructor', (t) => {
9
23
  const plugin = new Claude3VertexPlugin(pathway, model);
@@ -11,13 +25,14 @@ test('constructor', (t) => {
11
25
  t.is(plugin.pathwayPrompt, mockPathwayResolverMessages.pathway.prompt);
12
26
  });
13
27
 
28
+
14
29
  test('getRequestParameters', async (t) => {
15
30
  const plugin = new Claude3VertexPlugin(pathway, model);
16
31
  const text = 'Help me';
17
32
  const parameters = { name: 'John', age: 30, stream: false };
18
33
  const prompt = mockPathwayResolverMessages.pathway.prompt;
19
34
 
20
- const result = await plugin.getRequestParameters(text, parameters, prompt, { messages: [] });
35
+ const result = await plugin.getRequestParameters(text, parameters, prompt);
21
36
  t.deepEqual(result, {
22
37
  system: '',
23
38
  messages: [
@@ -56,6 +71,69 @@ test('getRequestParameters', async (t) => {
56
71
  });
57
72
  });
58
73
 
74
+ test('getRequestParameters with long message in chatHistory', async (t) => {
75
+ const plugin = new Claude3VertexPlugin(pathway, model);
76
+ const text = 'Final message';
77
+
78
+ // Load long content from file
79
+ const longContent = loadTestData('largecontent.txt');
80
+
81
+ // Set up chatHistory with a long message
82
+ const chatHistory = [
83
+ { role: 'user', content: 'Short message' },
84
+ { role: 'assistant', content: 'Short response' },
85
+ { role: 'user', content: longContent },
86
+ { role: 'assistant', content: 'Long content response' },
87
+ { role: 'user', content: 'Final message' }
88
+ ];
89
+
90
+ // Create a custom prompt that includes the chatHistory
91
+ const prompt = {
92
+ ...mockPathwayResolverMessages.pathway.prompt,
93
+ messages: chatHistory
94
+ };
95
+
96
+ const parameters = { stream: false };
97
+ plugin.promptParameters.manageTokenLength = true;
98
+
99
+ const result = await plugin.getRequestParameters(text, parameters, prompt);
100
+
101
+ // Verify we have messages in the result
102
+ t.truthy(result.messages);
103
+
104
+ // Check that the long message was truncated (should be shorter than original)
105
+ const userMessages = result.messages.filter(msg =>
106
+ msg.role === 'user' &&
107
+ msg.content[0].type === 'text'
108
+ );
109
+
110
+ // Verify we have user messages in the result
111
+ t.true(userMessages.length > 0, 'Should include user messages');
112
+
113
+ // Find the long message that was truncated
114
+ const longMessage = userMessages.find(msg =>
115
+ msg.content[0].text.length < longContent.length &&
116
+ msg.content[0].text.length > 100 // Ensure it's the long message, not other short ones
117
+ );
118
+
119
+ // Verify the long message was truncated
120
+ t.truthy(longMessage, 'Long user message should be truncated');
121
+ t.true(longMessage.content[0].text.length < longContent.length, 'Truncated message should be shorter than original');
122
+
123
+ // Verify the final user input message is included
124
+ const finalInputMessage = result.messages.find(msg =>
125
+ msg.role === 'user' &&
126
+ msg.content[0].type === 'text' &&
127
+ msg.content[0].text.includes(text)
128
+ );
129
+
130
+ t.truthy(finalInputMessage, 'Final user input should be included');
131
+
132
+ // Log token counts for debugging/verification
133
+ console.log(`Original content length: ${longContent.length} chars`);
134
+ console.log(`Truncated content length: ${longMessage.content[0].text.length} chars`);
135
+ });
136
+
59
137
  test('parseResponse', (t) => {
60
138
  const plugin = new Claude3VertexPlugin(pathway, model);
61
139
 
@@ -199,7 +277,7 @@ test('convertMessagesToClaudeVertex system message with user message', async (t)
199
277
  test('convertMessagesToClaudeVertex user message with unsupported image type', async (t) => {
200
278
  const plugin = new Claude3VertexPlugin(pathway, model);
201
279
  // Test with unsupported image type
202
- const messages = [{ role: 'user', content: { type: 'image_url', image_url: 'https://unec.edu.az/application/uploads/2014/12/pdf-sample.pdf' } }];
280
+ const messages = [{ role: 'user', content: { type: 'image_url', image_url: 'https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf' } }];
203
281
  const output = await plugin.convertMessagesToClaudeVertex(messages);
204
282
  t.deepEqual(output, { system: '', modifiedMessages: [{role: 'user', content: [] }] });
205
283
  });