@adminforth/bulk-ai-flow 1.9.1 → 1.9.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
@@ -11,5 +11,5 @@ custom/package-lock.json
11
11
  custom/package.json
12
12
  custom/tsconfig.json
13
13
 
14
- sent 184,983 bytes received 134 bytes 370,234.00 bytes/sec
15
- total size is 184,450 speedup is 1.00
14
+ sent 185,785 bytes received 134 bytes 371,838.00 bytes/sec
15
+ total size is 185,252 speedup is 1.00
@@ -406,7 +406,35 @@ async function runAiAction({
406
406
  let errorMessage = '';
407
407
  const jobsIds: { jobId: any; recordId: any; }[] = [];
408
408
  responseFlag.value = props.checkboxes.map(() => false);
409
-
409
+ let isRateLimitExceeded = false;
410
+ try {
411
+ const rateLimitRes = await callAdminForthApi({
412
+ path: `/plugin/${props.meta.pluginInstanceId}/update-rate-limits`,
413
+ method: 'POST',
414
+ body: {
415
+ actionType: actionType,
416
+ },
417
+ });
418
+ if (rateLimitRes?.error) {
419
+ isRateLimitExceeded = true;
420
+ adminforth.alert({
421
+ message: `Rate limit exceeded for "${actionType.replace('_', ' ')}" action. Please try again later.`,
422
+ variant: 'danger',
423
+ timeout: 'unlimited',
424
+ });
425
+ return;
426
+ }
427
+ } catch (e) {
428
+ adminforth.alert({
429
+ message: `Error checking rate limit for "${actionType.replace('_', ' ')}" action.`,
430
+ variant: 'danger',
431
+ timeout: 'unlimited',
432
+ });
433
+ isRateLimitExceeded = true;
434
+ }
435
+ if (isRateLimitExceeded) {
436
+ return;
437
+ };
410
438
  //creating jobs
411
439
  const tasks = props.checkboxes.map(async (checkbox, i) => {
412
440
  try {
@@ -406,7 +406,35 @@ async function runAiAction({
406
406
  let errorMessage = '';
407
407
  const jobsIds: { jobId: any; recordId: any; }[] = [];
408
408
  responseFlag.value = props.checkboxes.map(() => false);
409
-
409
+ let isRateLimitExceeded = false;
410
+ try {
411
+ const rateLimitRes = await callAdminForthApi({
412
+ path: `/plugin/${props.meta.pluginInstanceId}/update-rate-limits`,
413
+ method: 'POST',
414
+ body: {
415
+ actionType: actionType,
416
+ },
417
+ });
418
+ if (rateLimitRes?.error) {
419
+ isRateLimitExceeded = true;
420
+ adminforth.alert({
421
+ message: `Rate limit exceeded for "${actionType.replace('_', ' ')}" action. Please try again later.`,
422
+ variant: 'danger',
423
+ timeout: 'unlimited',
424
+ });
425
+ return;
426
+ }
427
+ } catch (e) {
428
+ adminforth.alert({
429
+ message: `Error checking rate limit for "${actionType.replace('_', ' ')}" action.`,
430
+ variant: 'danger',
431
+ timeout: 'unlimited',
432
+ });
433
+ isRateLimitExceeded = true;
434
+ }
435
+ if (isRateLimitExceeded) {
436
+ return;
437
+ };
410
438
  //creating jobs
411
439
  const tasks = props.checkboxes.map(async (checkbox, i) => {
412
440
  try {
package/dist/index.js CHANGED
@@ -56,15 +56,15 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
56
56
  }
57
57
  analyze_image(jobId, recordId, adminUser, headers) {
58
58
  return __awaiter(this, void 0, void 0, function* () {
59
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
59
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
60
60
  const selectedId = recordId;
61
61
  let isError = false;
62
- if (typeof ((_a = this.options.rateLimits) === null || _a === void 0 ? void 0 : _a.fillFieldsFromImages) === 'string') {
63
- if (this.checkRateLimit("fillFieldsFromImages", this.options.rateLimits.fillFieldsFromImages, headers)) {
64
- jobs.set(jobId, { status: 'failed', error: "Rate limit exceeded" });
65
- return { error: "Rate limit exceeded" };
66
- }
67
- }
62
+ // if (typeof(this.options.rateLimits?.fillFieldsFromImages) === 'string'){
63
+ // if (this.checkRateLimit("fillFieldsFromImages" ,this.options.rateLimits.fillFieldsFromImages, headers)) {
64
+ // jobs.set(jobId, { status: 'failed', error: "Rate limit exceeded" });
65
+ // return { error: "Rate limit exceeded" };
66
+ // }
67
+ // }
68
68
  // Fetch the record using the provided ID
69
69
  const primaryKeyColumn = this.resourceConfig.columns.find((col) => col.primaryKey);
70
70
  const record = yield this.adminforth.resource(this.resourceConfig.resourceId).get([Filters.EQ(primaryKeyColumn.name, selectedId)]);
@@ -98,7 +98,7 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
98
98
  if (topLevelError || (resp === null || resp === void 0 ? void 0 : resp.error)) {
99
99
  jobs.set(jobId, { status: 'failed', error: `ERROR: ${JSON.stringify(topLevelError || (resp === null || resp === void 0 ? void 0 : resp.error))}` });
100
100
  }
101
- const textOutput = (_g = (_f = (_e = (_d = (_c = (_b = resp === null || resp === void 0 ? void 0 : resp.output) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.content) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.text) !== null && _f !== void 0 ? _f : resp === null || resp === void 0 ? void 0 : resp.output_text) !== null && _g !== void 0 ? _g : (_k = (_j = (_h = resp === null || resp === void 0 ? void 0 : resp.choices) === null || _h === void 0 ? void 0 : _h[0]) === null || _j === void 0 ? void 0 : _j.message) === null || _k === void 0 ? void 0 : _k.content;
101
+ 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;
102
102
  if (!textOutput || typeof textOutput !== 'string') {
103
103
  jobs.set(jobId, { status: 'failed', error: 'Unexpected AI response format' });
104
104
  }
@@ -109,20 +109,22 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
109
109
  return { ok: true };
110
110
  }
111
111
  }
112
- ;
112
+ else {
113
+ jobs.set(jobId, { status: 'failed', error: "No attachment files found" });
114
+ return { ok: false, error: "No attachment files found" };
115
+ }
113
116
  });
114
117
  }
115
118
  analyzeNoImages(jobId, recordId, adminUser, headers) {
116
119
  return __awaiter(this, void 0, void 0, function* () {
117
- var _a;
118
120
  const selectedId = recordId;
119
121
  let isError = false;
120
- if (typeof ((_a = this.options.rateLimits) === null || _a === void 0 ? void 0 : _a.fillPlainFields) === 'string') {
121
- if (this.checkRateLimit("fillPlainFields", this.options.rateLimits.fillPlainFields, headers)) {
122
- jobs.set(jobId, { status: 'failed', error: "Rate limit exceeded" });
123
- return { error: "Rate limit exceeded" };
124
- }
125
- }
122
+ // if (typeof(this.options.rateLimits?.fillPlainFields) === 'string'){
123
+ // if (this.checkRateLimit("fillPlainFields", this.options.rateLimits.fillPlainFields, headers)) {
124
+ // jobs.set(jobId, { status: 'failed', error: "Rate limit exceeded" });
125
+ // return { error: "Rate limit exceeded" };
126
+ // }
127
+ // }
126
128
  if (STUB_MODE) {
127
129
  yield new Promise((resolve) => setTimeout(resolve, Math.floor(Math.random() * 20000) + 1000));
128
130
  jobs.set(jobId, { status: 'completed', result: {} });
@@ -163,17 +165,17 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
163
165
  }
164
166
  initialImageGenerate(jobId, recordId, adminUser, headers) {
165
167
  return __awaiter(this, void 0, void 0, function* () {
166
- var _a, _b, _c;
168
+ var _a, _b;
167
169
  const selectedId = recordId;
168
170
  let isError = false;
169
- if (typeof ((_a = this.options.rateLimits) === null || _a === void 0 ? void 0 : _a.generateImages) === 'string') {
170
- if (this.checkRateLimit("generateImages", this.options.rateLimits.generateImages, headers)) {
171
- jobs.set(jobId, { status: 'failed', error: "Rate limit exceeded" });
172
- return { error: "Rate limit exceeded" };
173
- }
174
- }
171
+ // if (typeof(this.options.rateLimits?.generateImages) === 'string'){
172
+ // if (this.checkRateLimit("generateImages", this.options.rateLimits.generateImages, headers)) {
173
+ // jobs.set(jobId, { status: 'failed', error: "Rate limit exceeded" });
174
+ // return { error: "Rate limit exceeded" };
175
+ // }
176
+ // }
175
177
  const start = +new Date();
176
- const record = yield this.adminforth.resource(this.resourceConfig.resourceId).get([Filters.EQ((_b = this.resourceConfig.columns.find(c => c.primaryKey)) === null || _b === void 0 ? void 0 : _b.name, selectedId)]);
178
+ const record = yield this.adminforth.resource(this.resourceConfig.resourceId).get([Filters.EQ((_a = this.resourceConfig.columns.find(c => c.primaryKey)) === null || _a === void 0 ? void 0 : _a.name, selectedId)]);
177
179
  let attachmentFiles;
178
180
  if (!this.options.attachFiles) {
179
181
  attachmentFiles = [];
@@ -181,7 +183,7 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
181
183
  else {
182
184
  attachmentFiles = yield this.options.attachFiles({ record });
183
185
  }
184
- const fieldTasks = Object.keys(((_c = this.options) === null || _c === void 0 ? void 0 : _c.generateImages) || {}).map((key) => __awaiter(this, void 0, void 0, function* () {
186
+ const fieldTasks = Object.keys(((_b = this.options) === null || _b === void 0 ? void 0 : _b.generateImages) || {}).map((key) => __awaiter(this, void 0, void 0, function* () {
185
187
  const prompt = this.compileGenerationFieldTemplates(record)[key];
186
188
  let images;
187
189
  if (this.options.attachFiles && attachmentFiles.length === 0) {
@@ -637,5 +639,29 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
637
639
  return { ok: true, job };
638
640
  })
639
641
  });
642
+ server.endpoint({
643
+ method: 'POST',
644
+ path: `/plugin/${this.pluginInstanceId}/update-rate-limits`,
645
+ handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, headers }) {
646
+ var _b, _c, _d;
647
+ const actionType = body.actionType;
648
+ if (actionType === 'analyze' && ((_b = this.options.rateLimits) === null || _b === void 0 ? void 0 : _b.fillFieldsFromImages)) {
649
+ if (this.checkRateLimit("fillFieldsFromImages", this.options.rateLimits.fillFieldsFromImages, headers)) {
650
+ return { ok: false, error: "Rate limit exceeded for image analyze" };
651
+ }
652
+ }
653
+ if (actionType === 'analyze_no_images' && ((_c = this.options.rateLimits) === null || _c === void 0 ? void 0 : _c.fillPlainFields)) {
654
+ if (this.checkRateLimit("fillPlainFields", this.options.rateLimits.fillPlainFields, headers)) {
655
+ return { ok: false, error: "Rate limit exceeded for plain field analyze" };
656
+ }
657
+ }
658
+ if (actionType === 'generate_images' && ((_d = this.options.rateLimits) === null || _d === void 0 ? void 0 : _d.generateImages)) {
659
+ if (this.checkRateLimit("generateImages", this.options.rateLimits.generateImages, headers)) {
660
+ return { ok: false, error: "Rate limit exceeded for image generation" };
661
+ }
662
+ }
663
+ return { ok: true };
664
+ })
665
+ });
640
666
  }
641
667
  }
package/index.ts CHANGED
@@ -70,12 +70,12 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
70
70
  private async analyze_image(jobId: string, recordId: string, adminUser: any, headers: Record<string, string | string[] | undefined>) {
71
71
  const selectedId = recordId;
72
72
  let isError = false;
73
- if (typeof(this.options.rateLimits?.fillFieldsFromImages) === 'string'){
74
- if (this.checkRateLimit("fillFieldsFromImages" ,this.options.rateLimits.fillFieldsFromImages, headers)) {
75
- jobs.set(jobId, { status: 'failed', error: "Rate limit exceeded" });
76
- return { error: "Rate limit exceeded" };
77
- }
78
- }
73
+ // if (typeof(this.options.rateLimits?.fillFieldsFromImages) === 'string'){
74
+ // if (this.checkRateLimit("fillFieldsFromImages" ,this.options.rateLimits.fillFieldsFromImages, headers)) {
75
+ // jobs.set(jobId, { status: 'failed', error: "Rate limit exceeded" });
76
+ // return { error: "Rate limit exceeded" };
77
+ // }
78
+ // }
79
79
  // Fetch the record using the provided ID
80
80
  const primaryKeyColumn = this.resourceConfig.columns.find((col) => col.primaryKey);
81
81
  const record = await this.adminforth.resource(this.resourceConfig.resourceId).get([Filters.EQ(primaryKeyColumn.name, selectedId)] );
@@ -121,18 +121,22 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
121
121
  jobs.set(jobId, { status: 'completed', result });
122
122
  return { ok: true };
123
123
  }
124
- };
124
+ } else {
125
+ jobs.set(jobId, { status: 'failed', error: "No attachment files found" });
126
+ return { ok: false, error: "No attachment files found" };
127
+ }
128
+
125
129
  }
126
130
 
127
131
  private async analyzeNoImages(jobId: string, recordId: string, adminUser: any, headers: Record<string, string | string[] | undefined>) {
128
132
  const selectedId = recordId;
129
133
  let isError = false;
130
- if (typeof(this.options.rateLimits?.fillPlainFields) === 'string'){
131
- if (this.checkRateLimit("fillPlainFields", this.options.rateLimits.fillPlainFields, headers)) {
132
- jobs.set(jobId, { status: 'failed', error: "Rate limit exceeded" });
133
- return { error: "Rate limit exceeded" };
134
- }
135
- }
134
+ // if (typeof(this.options.rateLimits?.fillPlainFields) === 'string'){
135
+ // if (this.checkRateLimit("fillPlainFields", this.options.rateLimits.fillPlainFields, headers)) {
136
+ // jobs.set(jobId, { status: 'failed', error: "Rate limit exceeded" });
137
+ // return { error: "Rate limit exceeded" };
138
+ // }
139
+ // }
136
140
  if (STUB_MODE) {
137
141
  await new Promise((resolve) => setTimeout(resolve, Math.floor(Math.random() * 20000) + 1000));
138
142
  jobs.set(jobId, { status: 'completed', result: {} });
@@ -173,12 +177,12 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
173
177
  private async initialImageGenerate(jobId: string, recordId: string, adminUser: any, headers: Record<string, string | string[] | undefined>) {
174
178
  const selectedId = recordId;
175
179
  let isError = false;
176
- if (typeof(this.options.rateLimits?.generateImages) === 'string'){
177
- if (this.checkRateLimit("generateImages", this.options.rateLimits.generateImages, headers)) {
178
- jobs.set(jobId, { status: 'failed', error: "Rate limit exceeded" });
179
- return { error: "Rate limit exceeded" };
180
- }
181
- }
180
+ // if (typeof(this.options.rateLimits?.generateImages) === 'string'){
181
+ // if (this.checkRateLimit("generateImages", this.options.rateLimits.generateImages, headers)) {
182
+ // jobs.set(jobId, { status: 'failed', error: "Rate limit exceeded" });
183
+ // return { error: "Rate limit exceeded" };
184
+ // }
185
+ // }
182
186
  const start = +new Date();
183
187
  const record = await this.adminforth.resource(this.resourceConfig.resourceId).get([Filters.EQ(this.resourceConfig.columns.find(c => c.primaryKey)?.name, selectedId)]);
184
188
  let attachmentFiles
@@ -679,5 +683,31 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
679
683
  });
680
684
 
681
685
 
686
+ server.endpoint({
687
+ method: 'POST',
688
+ path: `/plugin/${this.pluginInstanceId}/update-rate-limits`,
689
+ handler: async ({ body, adminUser, headers }) => {
690
+ const actionType = body.actionType;
691
+ if (actionType === 'analyze' && this.options.rateLimits?.fillFieldsFromImages) {
692
+ if (this.checkRateLimit("fillFieldsFromImages" ,this.options.rateLimits.fillFieldsFromImages, headers)) {
693
+ return {ok: false, error: "Rate limit exceeded for image analyze" };
694
+ }
695
+ }
696
+ if (actionType === 'analyze_no_images' && this.options.rateLimits?.fillPlainFields) {
697
+ if (this.checkRateLimit("fillPlainFields" ,this.options.rateLimits.fillPlainFields, headers)) {
698
+ return {ok: false, error: "Rate limit exceeded for plain field analyze" };
699
+ }
700
+ }
701
+ if (actionType === 'generate_images' && this.options.rateLimits?.generateImages) {
702
+ if (this.checkRateLimit("generateImages" ,this.options.rateLimits.generateImages, headers)) {
703
+ return {ok: false, error: "Rate limit exceeded for image generation" };
704
+ }
705
+ }
706
+
707
+ return { ok: true };
708
+ }
709
+ });
710
+
711
+
682
712
  }
683
713
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/bulk-ai-flow",
3
- "version": "1.9.1",
3
+ "version": "1.9.2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },