@adminforth/bulk-ai-flow 1.14.0 → 1.14.2

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.
package/build.log CHANGED
@@ -13,5 +13,5 @@ custom/package-lock.json
13
13
  custom/package.json
14
14
  custom/tsconfig.json
15
15
 
16
- sent 74,113 bytes received 172 bytes 148,570.00 bytes/sec
16
+ sent 74,104 bytes received 172 bytes 148,552.00 bytes/sec
17
17
  total size is 73,472 speedup is 0.99
@@ -1,7 +1,7 @@
1
1
 
2
2
  <template>
3
3
  <!-- Main modal -->
4
- <div tabindex="-1" class="[scrollbar-gutter:stable] fixed inset-0 z-10 flex justify-center items-center bg-gray-800/50 dark:bg-gray-900/50 overflow-y-auto">
4
+ <div tabindex="-1" class="[scrollbar-gutter:stable] fixed inset-0 z-20 flex justify-center items-center bg-gray-800/50 dark:bg-gray-900/50 overflow-y-auto">
5
5
  <div class="relative p-4 w-full max-w-[1600px]">
6
6
  <!-- Modal content -->
7
7
  <div class="relative bg-white rounded-lg shadow-xl dark:bg-gray-700">
@@ -1,7 +1,7 @@
1
1
 
2
2
  <template>
3
3
  <!-- Main modal -->
4
- <div tabindex="-1" class="[scrollbar-gutter:stable] fixed inset-0 z-10 flex justify-center items-center bg-gray-800/50 dark:bg-gray-900/50 overflow-y-auto">
4
+ <div tabindex="-1" class="[scrollbar-gutter:stable] fixed inset-0 z-20 flex justify-center items-center bg-gray-800/50 dark:bg-gray-900/50 overflow-y-auto">
5
5
  <div class="relative p-4 w-full max-w-[1600px]">
6
6
  <!-- Modal content -->
7
7
  <div class="relative bg-white rounded-lg shadow-xl dark:bg-gray-700">
package/dist/index.js CHANGED
@@ -80,6 +80,15 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
80
80
  return {};
81
81
  }
82
82
  else if (attachmentFiles.length !== 0) {
83
+ try {
84
+ for (const fileUrl of attachmentFiles) {
85
+ new URL(fileUrl);
86
+ }
87
+ }
88
+ catch (e) {
89
+ jobs.set(jobId, { status: 'failed', error: 'One of the image URLs is not valid' });
90
+ return { ok: false, error: 'One of the image URLs is not valid' };
91
+ }
83
92
  //create prompt for OpenAI
84
93
  const compiledOutputFields = this.compileOutputFieldsTemplates(record);
85
94
  const prompt = `Analyze the following image(s) and return a single JSON in format like: {'param1': 'value1', 'param2': 'value2'}.
@@ -107,7 +116,14 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
107
116
  jobs.set(jobId, { status: 'failed', error: 'Unexpected AI response format' });
108
117
  }
109
118
  //parse response and update record
110
- const resData = JSON.parse(textOutput);
119
+ let resData;
120
+ try {
121
+ resData = JSON.parse(textOutput);
122
+ }
123
+ catch (e) {
124
+ jobs.set(jobId, { status: 'failed', error: 'AI response is not valid JSON. Probably attached invalid image URL' });
125
+ return { ok: false, error: 'AI response is not valid JSON. Probably attached invalid image URL' };
126
+ }
111
127
  const result = resData;
112
128
  jobs.set(jobId, { status: 'completed', result });
113
129
  return { ok: true };
@@ -174,6 +190,15 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
174
190
  }
175
191
  else {
176
192
  attachmentFiles = yield this.options.attachFiles({ record });
193
+ try {
194
+ for (const fileUrl of attachmentFiles) {
195
+ new URL(fileUrl);
196
+ }
197
+ }
198
+ catch (e) {
199
+ jobs.set(jobId, { status: 'failed', error: 'One of the image URLs is not valid' });
200
+ return { ok: false, error: 'One of the image URLs is not valid' };
201
+ }
177
202
  }
178
203
  const fieldTasks = Object.keys(((_b = this.options) === null || _b === void 0 ? void 0 : _b.generateImages) || {}).map((key) => __awaiter(this, void 0, void 0, function* () {
179
204
  const prompt = this.compileGenerationFieldTemplates(record)[key];
@@ -228,9 +253,9 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
228
253
  recordResult[key] = images;
229
254
  });
230
255
  const result = recordResult;
231
- this.totalCalls++;
232
- this.totalDuration += (+new Date() - start) / 1000;
233
256
  if (!isError) {
257
+ this.totalCalls++;
258
+ this.totalDuration += (+new Date() - start) / 1000;
234
259
  jobs.set(jobId, { status: 'completed', result });
235
260
  return { ok: true };
236
261
  }
@@ -291,9 +316,9 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
291
316
  }
292
317
  return resp.imageURLs[0];
293
318
  })));
294
- this.totalCalls++;
295
- this.totalDuration += (+new Date() - start) / 1000;
296
319
  if (!isError) {
320
+ this.totalCalls++;
321
+ this.totalDuration += (+new Date() - start) / 1000;
297
322
  jobs.set(jobId, { status: 'completed', result: { [fieldName]: images } });
298
323
  return { ok: true };
299
324
  }
@@ -563,10 +588,10 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
563
588
  }
564
589
  catch (e) {
565
590
  // file might be e.g. already deleted, so we catch error
566
- console.error(`Error setting tag to true for object ${oldRecord[value]}. File will not be auto-cleaned up`, e);
591
+ console.error(`Error setting tag to true for object ${oldRecord[value]}. File will not be auto-cleaned up`);
567
592
  }
568
593
  }
569
- if (fieldsToUpdate[idx][key] && fieldsToUpdate[idx][key] !== null) {
594
+ if (fieldsToUpdate[idx][value] && fieldsToUpdate[idx][value] !== null) {
570
595
  // remove tag from new file
571
596
  // in this case we let it crash if it fails: this is a new file which just was uploaded.
572
597
  yield columnPlugin.pluginOptions.storageAdapter.markKeyForNotDeletation(fieldsToUpdate[idx][value]);
package/index.ts CHANGED
@@ -89,6 +89,14 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
89
89
  }
90
90
  return {};
91
91
  } else if (attachmentFiles.length !== 0) {
92
+ try {
93
+ for (const fileUrl of attachmentFiles) {
94
+ new URL(fileUrl);
95
+ }
96
+ } catch (e) {
97
+ jobs.set(jobId, { status: 'failed', error: 'One of the image URLs is not valid' });
98
+ return { ok: false, error: 'One of the image URLs is not valid' };
99
+ }
92
100
  //create prompt for OpenAI
93
101
  const compiledOutputFields = this.compileOutputFieldsTemplates(record);
94
102
  const prompt = `Analyze the following image(s) and return a single JSON in format like: {'param1': 'value1', 'param2': 'value2'}.
@@ -118,7 +126,13 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
118
126
  }
119
127
 
120
128
  //parse response and update record
121
- const resData = JSON.parse(textOutput);
129
+ let resData;
130
+ try {
131
+ resData = JSON.parse(textOutput);
132
+ } catch (e) {
133
+ jobs.set(jobId, { status: 'failed', error: 'AI response is not valid JSON. Probably attached invalid image URL' });
134
+ return { ok: false, error: 'AI response is not valid JSON. Probably attached invalid image URL' };
135
+ }
122
136
  const result = resData;
123
137
  jobs.set(jobId, { status: 'completed', result });
124
138
  return { ok: true };
@@ -180,6 +194,14 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
180
194
  attachmentFiles = [];
181
195
  } else {
182
196
  attachmentFiles = await this.options.attachFiles({ record });
197
+ try {
198
+ for (const fileUrl of attachmentFiles) {
199
+ new URL(fileUrl);
200
+ }
201
+ } catch (e) {
202
+ jobs.set(jobId, { status: 'failed', error: 'One of the image URLs is not valid' });
203
+ return { ok: false, error: 'One of the image URLs is not valid' };
204
+ }
183
205
  }
184
206
  const fieldTasks = Object.keys(this.options?.generateImages || {}).map(async (key) => {
185
207
  const prompt = this.compileGenerationFieldTemplates(record)[key];
@@ -235,9 +257,9 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
235
257
 
236
258
  const result = recordResult;
237
259
 
238
- this.totalCalls++;
239
- this.totalDuration += (+new Date() - start) / 1000;
240
260
  if (!isError) {
261
+ this.totalCalls++;
262
+ this.totalDuration += (+new Date() - start) / 1000;
241
263
  jobs.set(jobId, { status: 'completed', result });
242
264
  return { ok: true }
243
265
  } else {
@@ -297,9 +319,10 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
297
319
  return resp.imageURLs[0]
298
320
  })
299
321
  );
300
- this.totalCalls++;
301
- this.totalDuration += (+new Date() - start) / 1000;
322
+
302
323
  if (!isError) {
324
+ this.totalCalls++;
325
+ this.totalDuration += (+new Date() - start) / 1000;
303
326
  jobs.set(jobId, { status: 'completed', result: { [fieldName]: images } });
304
327
  return { ok: true };
305
328
  } else {
@@ -591,10 +614,10 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
591
614
  await columnPlugin.pluginOptions.storageAdapter.markKeyForDeletation(oldRecord[value]);
592
615
  } catch (e) {
593
616
  // file might be e.g. already deleted, so we catch error
594
- console.error(`Error setting tag to true for object ${oldRecord[value]}. File will not be auto-cleaned up`, e);
617
+ console.error(`Error setting tag to true for object ${oldRecord[value]}. File will not be auto-cleaned up`);
595
618
  }
596
619
  }
597
- if (fieldsToUpdate[idx][key] && fieldsToUpdate[idx][key] !== null) {
620
+ if (fieldsToUpdate[idx][value] && fieldsToUpdate[idx][value] !== null) {
598
621
  // remove tag from new file
599
622
  // in this case we let it crash if it fails: this is a new file which just was uploaded.
600
623
  await columnPlugin.pluginOptions.storageAdapter.markKeyForNotDeletation(fieldsToUpdate[idx][value]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/bulk-ai-flow",
3
- "version": "1.14.0",
3
+ "version": "1.14.2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },