@adminforth/bulk-ai-flow 1.15.0 → 1.15.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.
Files changed (3) hide show
  1. package/dist/index.js +28 -7
  2. package/index.ts +26 -7
  3. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -131,7 +131,8 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
131
131
  const resp = chatResponse.response;
132
132
  const topLevelError = chatResponse.error;
133
133
  if (topLevelError || (resp === null || resp === void 0 ? void 0 : resp.error)) {
134
- jobs.set(jobId, { status: 'failed', error: `ERROR: ${JSON.stringify(topLevelError || (resp === null || resp === void 0 ? void 0 : resp.error))}` });
134
+ jobs.set(jobId, { status: 'failed', error: `ERROR: ${JSON.stringify(topLevelError.message || (resp === null || resp === void 0 ? void 0 : resp.error.message))}` });
135
+ return { ok: false, error: `ERROR: ${JSON.stringify(topLevelError.message || (resp === null || resp === void 0 ? void 0 : resp.error.message))}` };
135
136
  }
136
137
  const textOutput = (_f = (_e = (_d = (_c = (_b = (_a = resp === null || resp === void 0 ? void 0 : resp.output) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.content) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.text) !== null && _e !== void 0 ? _e : resp === null || resp === void 0 ? void 0 : resp.output_text) !== null && _f !== void 0 ? _f : (_j = (_h = (_g = resp === null || resp === void 0 ? void 0 : resp.choices) === null || _g === void 0 ? void 0 : _g[0]) === null || _h === void 0 ? void 0 : _h.message) === null || _j === void 0 ? void 0 : _j.content;
137
138
  if (!textOutput || typeof textOutput !== 'string') {
@@ -178,12 +179,12 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
178
179
  const numberOfTokens = this.options.fillPlainFieldsMaxTokens ? this.options.fillPlainFieldsMaxTokens : 1000;
179
180
  let resp;
180
181
  try {
181
- const { content: chatResponse } = yield this.options.textCompleteAdapter.complete(prompt, [], numberOfTokens);
182
- resp = chatResponse.response;
183
- const topLevelError = chatResponse.error;
182
+ const { content: chatResponse, error: topLevelError } = yield this.options.textCompleteAdapter.complete(prompt, [], numberOfTokens);
183
+ // resp = (chatResponse as any).response;
184
184
  if (topLevelError || (resp === null || resp === void 0 ? void 0 : resp.error)) {
185
185
  isError = true;
186
- jobs.set(jobId, { status: 'failed', error: `ERROR: ${JSON.stringify(topLevelError || (resp === null || resp === void 0 ? void 0 : resp.error))}` });
186
+ jobs.set(jobId, { status: 'failed', error: `ERROR: ${JSON.stringify(topLevelError)}` });
187
+ return { ok: false, error: `ERROR: ${JSON.stringify(topLevelError)}` };
187
188
  }
188
189
  resp = chatResponse;
189
190
  }
@@ -258,6 +259,11 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
258
259
  n: 1,
259
260
  size: this.options.generateImages[key].outputSize,
260
261
  });
262
+ if (resp.error) {
263
+ isError = true;
264
+ jobs.set(jobId, { status: 'failed', error: `AI provider refused to generate image: ${JSON.stringify(resp.error)}` });
265
+ return { key, images: [] };
266
+ }
261
267
  }
262
268
  catch (e) {
263
269
  jobs.set(jobId, { status: 'failed', error: "AI provider refused to generate image" });
@@ -330,6 +336,11 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
330
336
  n: 1,
331
337
  size: this.options.generateImages[fieldName].outputSize,
332
338
  });
339
+ if (resp.error) {
340
+ isError = true;
341
+ jobs.set(jobId, { status: 'failed', error: `AI provider refused to generate image: ${JSON.stringify(resp.error)}` });
342
+ return [];
343
+ }
333
344
  }
334
345
  catch (e) {
335
346
  jobs.set(jobId, { status: 'failed', error: "AI provider refused to generate image" });
@@ -612,7 +623,12 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
612
623
  if (oldRecord[value]) {
613
624
  // put tag to delete old file
614
625
  try {
615
- yield columnPlugin.pluginOptions.storageAdapter.markKeyForDeletation(oldRecord[value]);
626
+ if (columnPlugin.pluginOptions.storageAdapter.markKeyForDeletion !== undefined) {
627
+ yield columnPlugin.pluginOptions.storageAdapter.markKeyForDeletion(oldRecord[value]);
628
+ }
629
+ else {
630
+ yield columnPlugin.pluginOptions.storageAdapter.markKeyForDeletation(oldRecord[value]);
631
+ }
616
632
  }
617
633
  catch (e) {
618
634
  // file might be e.g. already deleted, so we catch error
@@ -622,7 +638,12 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
622
638
  if (fieldsToUpdate[idx][value] && fieldsToUpdate[idx][value] !== null) {
623
639
  // remove tag from new file
624
640
  // in this case we let it crash if it fails: this is a new file which just was uploaded.
625
- yield columnPlugin.pluginOptions.storageAdapter.markKeyForNotDeletation(fieldsToUpdate[idx][value]);
641
+ if (columnPlugin.pluginOptions.storageAdapter.markKeyForNotDeletion !== undefined) {
642
+ yield columnPlugin.pluginOptions.storageAdapter.markKeyForNotDeletion(fieldsToUpdate[idx][value]);
643
+ }
644
+ else {
645
+ yield columnPlugin.pluginOptions.storageAdapter.markKeyForNotDeletation(fieldsToUpdate[idx][value]);
646
+ }
626
647
  }
627
648
  }
628
649
  }
package/index.ts CHANGED
@@ -125,7 +125,8 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
125
125
  const resp: any = (chatResponse as any).response;
126
126
  const topLevelError = (chatResponse as any).error;
127
127
  if (topLevelError || resp?.error) {
128
- jobs.set(jobId, { status: 'failed', error: `ERROR: ${JSON.stringify(topLevelError || resp?.error)}` });
128
+ jobs.set(jobId, { status: 'failed', error: `ERROR: ${JSON.stringify(topLevelError.message || resp?.error.message)}` });
129
+ return { ok: false, error: `ERROR: ${JSON.stringify(topLevelError.message || resp?.error.message)}` };
129
130
  }
130
131
 
131
132
  const textOutput = resp?.output?.[0]?.content?.[0]?.text ?? resp?.output_text ?? resp?.choices?.[0]?.message?.content;
@@ -172,12 +173,12 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
172
173
  const numberOfTokens = this.options.fillPlainFieldsMaxTokens ? this.options.fillPlainFieldsMaxTokens : 1000;
173
174
  let resp: any;
174
175
  try {
175
- const { content: chatResponse } = await this.options.textCompleteAdapter.complete(prompt, [], numberOfTokens);
176
- resp = (chatResponse as any).response;
177
- const topLevelError = (chatResponse as any).error;
176
+ const { content: chatResponse, error: topLevelError } = await this.options.textCompleteAdapter.complete(prompt, [], numberOfTokens);
177
+ // resp = (chatResponse as any).response;
178
178
  if (topLevelError || resp?.error) {
179
179
  isError = true;
180
- jobs.set(jobId, { status: 'failed', error: `ERROR: ${JSON.stringify(topLevelError || resp?.error)}` });
180
+ jobs.set(jobId, { status: 'failed', error: `ERROR: ${JSON.stringify(topLevelError)}` });
181
+ return { ok: false, error: `ERROR: ${JSON.stringify(topLevelError)}` };
181
182
  }
182
183
  resp = chatResponse
183
184
  } catch (e) {
@@ -245,6 +246,11 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
245
246
  size: this.options.generateImages[key].outputSize,
246
247
  }
247
248
  )
249
+ if (resp.error) {
250
+ isError = true;
251
+ jobs.set(jobId, { status: 'failed', error: `AI provider refused to generate image: ${JSON.stringify(resp.error)}` });
252
+ return { key, images: [] };
253
+ }
248
254
  } catch (e) {
249
255
  jobs.set(jobId, { status: 'failed', error: "AI provider refused to generate image" });
250
256
  isError = true;
@@ -319,6 +325,11 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
319
325
  size: this.options.generateImages[fieldName].outputSize,
320
326
  }
321
327
  )
328
+ if (resp.error) {
329
+ isError = true;
330
+ jobs.set(jobId, { status: 'failed', error: `AI provider refused to generate image: ${JSON.stringify(resp.error)}` });
331
+ return [];
332
+ }
322
333
  } catch (e) {
323
334
  jobs.set(jobId, { status: 'failed', error: "AI provider refused to generate image" });
324
335
  isError = true;
@@ -625,7 +636,11 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
625
636
  if (oldRecord[value]) {
626
637
  // put tag to delete old file
627
638
  try {
628
- await columnPlugin.pluginOptions.storageAdapter.markKeyForDeletation(oldRecord[value]);
639
+ if (columnPlugin.pluginOptions.storageAdapter.markKeyForDeletion !== undefined) {
640
+ await columnPlugin.pluginOptions.storageAdapter.markKeyForDeletion(oldRecord[value]);
641
+ } else {
642
+ await columnPlugin.pluginOptions.storageAdapter.markKeyForDeletation(oldRecord[value]);
643
+ }
629
644
  } catch (e) {
630
645
  // file might be e.g. already deleted, so we catch error
631
646
  console.error(`Error setting tag to true for object ${oldRecord[value]}. File will not be auto-cleaned up`);
@@ -634,7 +649,11 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
634
649
  if (fieldsToUpdate[idx][value] && fieldsToUpdate[idx][value] !== null) {
635
650
  // remove tag from new file
636
651
  // in this case we let it crash if it fails: this is a new file which just was uploaded.
637
- await columnPlugin.pluginOptions.storageAdapter.markKeyForNotDeletation(fieldsToUpdate[idx][value]);
652
+ if (columnPlugin.pluginOptions.storageAdapter.markKeyForNotDeletion !== undefined) {
653
+ await columnPlugin.pluginOptions.storageAdapter.markKeyForNotDeletion(fieldsToUpdate[idx][value]);
654
+ } else {
655
+ await columnPlugin.pluginOptions.storageAdapter.markKeyForNotDeletation(fieldsToUpdate[idx][value]);
656
+ }
638
657
  }
639
658
  }
640
659
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/bulk-ai-flow",
3
- "version": "1.15.0",
3
+ "version": "1.15.2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "@types/handlebars": "^4.0.40",
30
- "adminforth": "^2.4.0-next.222",
30
+ "adminforth": "^2.4.0-next.315",
31
31
  "handlebars": "^4.7.8"
32
32
  },
33
33
  "release": {