@aj-archipelago/cortex 1.3.56 → 1.3.58

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 (39) hide show
  1. package/.env.sample +3 -1
  2. package/README.md +6 -0
  3. package/config.js +45 -0
  4. package/helper-apps/mogrt-handler/.env.example +24 -0
  5. package/helper-apps/mogrt-handler/README.md +166 -0
  6. package/helper-apps/mogrt-handler/glossaryHandler.js +218 -0
  7. package/helper-apps/mogrt-handler/index.js +213 -0
  8. package/helper-apps/mogrt-handler/package-lock.json +7106 -0
  9. package/helper-apps/mogrt-handler/package.json +34 -0
  10. package/helper-apps/mogrt-handler/s3Handler.js +444 -0
  11. package/helper-apps/mogrt-handler/start.js +98 -0
  12. package/helper-apps/mogrt-handler/swagger.js +42 -0
  13. package/helper-apps/mogrt-handler/swagger.yaml +436 -0
  14. package/helper-apps/mogrt-handler/tests/integration/api.test.js +226 -0
  15. package/helper-apps/mogrt-handler/tests/integration/glossary.test.js +106 -0
  16. package/helper-apps/mogrt-handler/tests/setup.js +8 -0
  17. package/helper-apps/mogrt-handler/tests/test-files/test.gif +1 -0
  18. package/helper-apps/mogrt-handler/tests/test-files/test.mogrt +1 -0
  19. package/helper-apps/mogrt-handler/tests/test-files/test.mp4 +1 -0
  20. package/helper-apps/mogrt-handler/tests/unit/glossary.unit.test.js +118 -0
  21. package/helper-apps/mogrt-handler/tests/unit/index.test.js +349 -0
  22. package/helper-apps/mogrt-handler/tests/unit/s3Handler.test.js +204 -0
  23. package/helper-apps/mogrt-handler/tests/unit/sample.test.js +28 -0
  24. package/helper-apps/mogrt-handler/vitest.config.js +15 -0
  25. package/lib/entityConstants.js +1 -1
  26. package/lib/requestExecutor.js +1 -1
  27. package/package.json +1 -1
  28. package/pathways/list_translation_models.js +67 -0
  29. package/pathways/system/workspaces/workspace_applet_edit.js +187 -0
  30. package/pathways/translate_apptek.js +44 -0
  31. package/pathways/translate_google.js +10 -0
  32. package/pathways/translate_groq.js +36 -0
  33. package/server/modelExecutor.js +12 -0
  34. package/server/plugins/apptekTranslatePlugin.js +144 -0
  35. package/server/plugins/googleTranslatePlugin.js +121 -0
  36. package/server/plugins/groqChatPlugin.js +108 -0
  37. package/tests/apptekTranslatePlugin.test.js +226 -0
  38. package/tests/integration/apptekTranslatePlugin.integration.test.js +222 -0
  39. package/tests/translate_apptek.test.js +133 -0
@@ -0,0 +1,213 @@
1
+ import { uploadToS3, getManifest, saveManifest, removeFromMasterManifest } from './s3Handler.js';
2
+ import Busboy from 'busboy';
3
+ import { v4 as uuidv4 } from 'uuid';
4
+ import path from 'path';
5
+
6
+ const ALLOWED_EXTENSIONS = {
7
+ MOGRT: '.mogrt',
8
+ PREVIEW: ['.gif', '.mp4']
9
+ };
10
+
11
+ const validateFiles = (files) => {
12
+ const hasMogrt = files.some(f => path.extname(f.filename).toLowerCase() === ALLOWED_EXTENSIONS.MOGRT);
13
+ const hasPreview = files.some(f => ALLOWED_EXTENSIONS.PREVIEW.includes(path.extname(f.filename).toLowerCase()));
14
+ console.log('Validating files:', hasMogrt, hasPreview);
15
+ if (!hasMogrt || !hasPreview) {
16
+ throw new Error('Both MOGRT and preview files (GIF or MP4) are required');
17
+ }
18
+ };
19
+
20
+ async function MogrtHandler(context, req) {
21
+ const { method } = req;
22
+ const { manifestId } = req.query;
23
+ const id = req.params?.id;
24
+
25
+ try {
26
+ // GET request to fetch manifest
27
+ if (method === 'GET') {
28
+ const manifest = await getManifest(manifestId || 'master');
29
+ context.res = {
30
+ status: 200,
31
+ body: manifest
32
+ };
33
+ return;
34
+ }
35
+
36
+ // DELETE request to remove MOGRT item
37
+ if (method === 'DELETE' && id) {
38
+ console.log(`Attempting to delete MOGRT with ID: ${id} from manifest: ${manifestId || 'master'}`);
39
+ try {
40
+ // Use the new removeFromMasterManifest function
41
+ const removed = await removeFromMasterManifest(id);
42
+
43
+ // If the item was not found
44
+ if (!removed) {
45
+ console.log(`MOGRT with ID ${id} not found in manifest`);
46
+ context.res = {
47
+ status: 404,
48
+ body: { error: `MOGRT with ID ${id} not found` }
49
+ };
50
+ return;
51
+ }
52
+
53
+ console.log(`Successfully deleted MOGRT with ID: ${id}`);
54
+
55
+ context.res = {
56
+ status: 200,
57
+ body: {
58
+ success: true,
59
+ message: `MOGRT with ID ${id} successfully deleted`
60
+ }
61
+ };
62
+ return;
63
+ } catch (error) {
64
+ console.error(`Error deleting MOGRT with ID ${id}:`, error);
65
+ context.res = {
66
+ status: 500,
67
+ body: { error: `Failed to delete MOGRT: ${error.message}` }
68
+ };
69
+ return;
70
+ }
71
+ }
72
+
73
+ // POST request to upload files
74
+ if (method === 'POST') {
75
+ const files = [];
76
+ const uploadId = uuidv4();
77
+ let name = null;
78
+ console.log('Generated uploadId:', uploadId);
79
+
80
+ const busboy = Busboy({
81
+ headers: {
82
+ 'content-type': req.headers['content-type']
83
+ },
84
+ limits: {
85
+ fileSize: 50 * 1024 * 1024, // 50MB limit
86
+ files: 2 // Expect exactly 2 files
87
+ }
88
+ });
89
+
90
+ return new Promise((resolve, reject) => {
91
+ busboy.on('file', (fieldname, file, fileInfo) => {
92
+ console.log('Processing file:', fieldname, fileInfo.filename);
93
+ const ext = path.extname(fileInfo.filename).toLowerCase();
94
+
95
+ if (ext !== ALLOWED_EXTENSIONS.MOGRT && !ALLOWED_EXTENSIONS.PREVIEW.includes(ext)) {
96
+ const error = new Error('Invalid file type. Only .mogrt, .gif and .mp4 files are allowed.');
97
+ file.resume(); // Drain this file
98
+ reject(error);
99
+ return;
100
+ }
101
+
102
+ const chunks = [];
103
+ file.on('data', chunk => {
104
+ console.log('Received chunk of size:', chunk.length);
105
+ chunks.push(chunk);
106
+ });
107
+
108
+ file.on('end', () => {
109
+ console.log('File upload complete:', fileInfo.filename);
110
+ const buffer = Buffer.concat(chunks);
111
+ files.push({
112
+ fieldname,
113
+ filename: fileInfo.filename,
114
+ buffer
115
+ });
116
+ });
117
+ });
118
+
119
+ busboy.on('field', (fieldname, value) => {
120
+ console.log('Received field:', fieldname, value);
121
+ if (fieldname === 'name') {
122
+ name = value;
123
+ }
124
+ });
125
+
126
+ busboy.on('finish', async () => {
127
+ console.log('All files processed, total files:', files.length);
128
+ try {
129
+ validateFiles(files);
130
+
131
+ const uploadPromises = files.map(file => {
132
+ const key = `${uploadId}/${file.filename}`;
133
+ const ext = path.extname(file.filename).toLowerCase();
134
+ let contentType;
135
+ if (ext === '.mogrt') {
136
+ contentType = 'application/octet-stream';
137
+ } else if (ext === '.gif') {
138
+ contentType = 'image/gif';
139
+ } else if (ext === '.mp4') {
140
+ contentType = 'video/mp4';
141
+ } else {
142
+ contentType = 'application/octet-stream';
143
+ }
144
+ return uploadToS3(key, file.buffer, contentType);
145
+ });
146
+
147
+ const uploadResults = await Promise.all(uploadPromises);
148
+ console.log('Upload results:', uploadResults);
149
+
150
+ const manifest = {
151
+ id: uploadId,
152
+ name: name || uploadId, // Use uploadId as fallback if name not provided
153
+ mogrtFile: uploadResults.find(r => path.extname(r.key).toLowerCase() === ALLOWED_EXTENSIONS.MOGRT)?.key,
154
+ previewFile: uploadResults.find(r => ALLOWED_EXTENSIONS.PREVIEW.includes(path.extname(r.key).toLowerCase()))?.key,
155
+ uploadDate: new Date().toISOString()
156
+ };
157
+
158
+ await saveManifest(manifest);
159
+ console.log('Manifest saved:', manifest);
160
+
161
+ const masterManifest = await getManifest('master');
162
+ context.res = {
163
+ status: 200,
164
+ body: {
165
+ manifest,
166
+ masterManifest
167
+ }
168
+ };
169
+ resolve();
170
+ } catch (error) {
171
+ console.error('Error processing files:', error);
172
+ context.res = {
173
+ status: 500,
174
+ body: { error: error.message }
175
+ };
176
+ reject(error);
177
+ }
178
+ });
179
+
180
+ busboy.on('error', (error) => {
181
+ console.error('Busboy error:', error);
182
+ reject(error);
183
+ });
184
+
185
+ // Handle the request data
186
+ try {
187
+ if (typeof req.body === 'string') {
188
+ busboy.end(Buffer.from(req.body));
189
+ } else if (req.body instanceof Buffer) {
190
+ busboy.end(req.body);
191
+ } else if (req.rawBody) {
192
+ busboy.end(req.rawBody);
193
+ } else {
194
+ req.pipe(busboy);
195
+ }
196
+ } catch (error) {
197
+ console.error('Error handling request:', error);
198
+ reject(error);
199
+ }
200
+ });
201
+ }
202
+
203
+ throw new Error('Method not allowed');
204
+ } catch (error) {
205
+ console.error('Handler error:', error);
206
+ context.res = {
207
+ status: error.status || 500,
208
+ body: { error: error.message }
209
+ };
210
+ }
211
+ }
212
+
213
+ export default MogrtHandler;