@adminforth/bulk-ai-flow 1.27.0 → 1.27.1

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 +21 -42
  2. package/index.ts +25 -36
  3. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { AdminForthFilterOperators, AdminForthPlugin, parseBody, Filters } from "adminforth";
10
+ import { AdminForthFilterOperators, AdminForthPlugin, Filters } from "adminforth";
11
11
  import { suggestIfTypo, filtersTools } from "adminforth";
12
12
  import Handlebars from 'handlebars';
13
13
  import { RateLimiter } from "adminforth";
@@ -33,7 +33,7 @@ const getImageGenerationPromptsBodySchema = z.object({
33
33
  }).strict();
34
34
  const createJobBodySchema = z.object({
35
35
  actionType: z.string().nullish(),
36
- recordId: z.any().optional(),
36
+ recordId: z.union([z.string(), z.number()]).nullish(),
37
37
  customPrompt: z.string().nullish(),
38
38
  filterFilledFields: z.boolean().nullish(),
39
39
  sessionIds: z.array(z.string()).nullish(),
@@ -814,11 +814,9 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
814
814
  server.endpoint({
815
815
  method: 'POST',
816
816
  path: `/plugin/${this.pluginInstanceId}/get_records`,
817
+ request_schema: getRecordsBodySchema,
817
818
  handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, response }) {
818
- const parsed = parseBody(getRecordsBodySchema, body, response);
819
- if ('error' in parsed)
820
- return parsed.error;
821
- const data = parsed.data;
819
+ const data = body;
822
820
  if (!Array.isArray(data.record)) {
823
821
  return { records: [] };
824
822
  }
@@ -838,11 +836,9 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
838
836
  server.endpoint({
839
837
  method: 'POST',
840
838
  path: `/plugin/${this.pluginInstanceId}/get_old_data`,
839
+ request_schema: getOldDataBodySchema,
841
840
  handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, response }) {
842
- const parsed = parseBody(getOldDataBodySchema, body, response);
843
- if ('error' in parsed)
844
- return parsed.error;
845
- const data = parsed.data;
841
+ const data = body;
846
842
  const recordId = data.recordId;
847
843
  if (recordId === undefined || recordId === null) {
848
844
  return { ok: false, error: "Missing recordId" };
@@ -860,11 +856,9 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
860
856
  server.endpoint({
861
857
  method: 'POST',
862
858
  path: `/plugin/${this.pluginInstanceId}/get_images`,
859
+ request_schema: getImagesBodySchema,
863
860
  handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, response }) {
864
- const parsed = parseBody(getImagesBodySchema, body, response);
865
- if ('error' in parsed)
866
- return parsed.error;
867
- const data = parsed.data;
861
+ const data = body;
868
862
  let images = [];
869
863
  if (data.record) {
870
864
  for (const record of data.record) {
@@ -881,11 +875,9 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
881
875
  server.endpoint({
882
876
  method: 'POST',
883
877
  path: `/plugin/${this.pluginInstanceId}/update_fields`,
878
+ request_schema: updateFieldsBodySchema,
884
879
  handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, headers, response }) {
885
- const parsed = parseBody(updateFieldsBodySchema, body, response);
886
- if ('error' in parsed)
887
- return parsed.error;
888
- const data = parsed.data;
880
+ const data = body;
889
881
  let isAllowedToSave = { ok: true, error: '' };
890
882
  if (this.options.isAllowedToSave) {
891
883
  isAllowedToSave = yield this.options.isAllowedToSave({ record: {}, adminUser: adminUser, resource: this.resourceConfig });
@@ -986,12 +978,10 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
986
978
  server.endpoint({
987
979
  method: 'POST',
988
980
  path: `/plugin/${this.pluginInstanceId}/get_image_generation_prompts`,
981
+ request_schema: getImageGenerationPromptsBodySchema,
989
982
  handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, headers, response }) {
990
983
  var _b;
991
- const parsed = parseBody(getImageGenerationPromptsBodySchema, body, response);
992
- if ('error' in parsed)
993
- return parsed.error;
994
- const data = parsed.data;
984
+ const data = body;
995
985
  const Id = data.recordId || [];
996
986
  const customPrompt = data.customPrompt || null;
997
987
  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, Id)]);
@@ -1013,11 +1003,9 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
1013
1003
  server.endpoint({
1014
1004
  method: 'POST',
1015
1005
  path: `/plugin/${this.pluginInstanceId}/create-job`,
1006
+ request_schema: createJobBodySchema,
1016
1007
  handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, headers, response }) {
1017
- const parsed = parseBody(createJobBodySchema, body, response);
1018
- if ('error' in parsed)
1019
- return parsed.error;
1020
- const data = parsed.data;
1008
+ const data = body;
1021
1009
  const { actionType, recordId, customPrompt, filterFilledFields, sessionIds } = data;
1022
1010
  if (this.options.rateLimits) {
1023
1011
  if (sessionIds && sessionIds.length > 0) {
@@ -1076,11 +1064,9 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
1076
1064
  server.endpoint({
1077
1065
  method: 'POST',
1078
1066
  path: `/plugin/${this.pluginInstanceId}/get-job-status`,
1067
+ request_schema: jobStatusBodySchema,
1079
1068
  handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, headers, response }) {
1080
- const parsed = parseBody(jobStatusBodySchema, body, response);
1081
- if ('error' in parsed)
1082
- return parsed.error;
1083
- const data = parsed.data;
1069
+ const data = body;
1084
1070
  const jobId = data.jobId;
1085
1071
  if (!jobId) {
1086
1072
  response.setStatus(400);
@@ -1113,12 +1099,10 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
1113
1099
  server.endpoint({
1114
1100
  method: 'POST',
1115
1101
  path: `/plugin/${this.pluginInstanceId}/update-rate-limits`,
1102
+ request_schema: updateRateLimitsBodySchema,
1116
1103
  handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, headers, response }) {
1117
1104
  var _b, _c, _d;
1118
- const parsed = parseBody(updateRateLimitsBodySchema, body, response);
1119
- if ('error' in parsed)
1120
- return parsed.error;
1121
- const data = parsed.data;
1105
+ const data = body;
1122
1106
  const actionType = data.actionType;
1123
1107
  const sessionId = randomUUID();
1124
1108
  this.sessionIds.add(sessionId);
@@ -1144,12 +1128,10 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
1144
1128
  server.endpoint({
1145
1129
  method: 'POST',
1146
1130
  path: `/plugin/${this.pluginInstanceId}/compile_old_image_link`,
1131
+ request_schema: compileOldImageLinkBodySchema,
1147
1132
  handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, headers, response }) {
1148
1133
  var _b, _c;
1149
- const parsed = parseBody(compileOldImageLinkBodySchema, body, response);
1150
- if ('error' in parsed)
1151
- return parsed.error;
1152
- const data = parsed.data;
1134
+ const data = body;
1153
1135
  const image = data.image;
1154
1136
  const columnName = data.columnName;
1155
1137
  if (!image) {
@@ -1177,12 +1159,9 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
1177
1159
  server.endpoint({
1178
1160
  method: 'POST',
1179
1161
  path: `/plugin/${this.pluginInstanceId}/get_filtered_ids`,
1162
+ request_schema: getFilteredIdsBodySchema,
1180
1163
  handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, headers, query, cookies, requestUrl, response }) {
1181
1164
  var _b, _c;
1182
- const parsed = parseBody(getFilteredIdsBodySchema, body, response);
1183
- if ('error' in parsed)
1184
- return parsed.error;
1185
- const data = parsed.data;
1186
1165
  const resource = this.resourceConfig;
1187
1166
  for (const hook of ((_c = (_b = resource.hooks) === null || _b === void 0 ? void 0 : _b.list) === null || _c === void 0 ? void 0 : _c.beforeDatasourceRequest) || []) {
1188
1167
  const filterTools = filtersTools.get(body);
package/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { AdminForthFilterOperators, AdminForthPlugin, parseBody, Filters } from "adminforth";
1
+ import { AdminForthFilterOperators, AdminForthPlugin, Filters } from "adminforth";
2
2
  import type { IAdminForth, IHttpServer, AdminForthComponentDeclaration, AdminForthResource } from "adminforth";
3
3
  import { suggestIfTypo, filtersTools } from "adminforth";
4
4
  import type { PluginOptions } from './types.js';
@@ -32,7 +32,7 @@ const getImageGenerationPromptsBodySchema = z.object({
32
32
 
33
33
  const createJobBodySchema = z.object({
34
34
  actionType: z.string().nullish(),
35
- recordId: z.any().optional(),
35
+ recordId: z.union([z.string(), z.number()]).nullish(),
36
36
  customPrompt: z.string().nullish(),
37
37
  filterFilledFields: z.boolean().nullish(),
38
38
  sessionIds: z.array(z.string()).nullish(),
@@ -163,7 +163,7 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
163
163
  return prompt;
164
164
  }
165
165
 
166
- private async analyze_image(jobId: string, recordId: string, adminUser: any, headers: Record<string, string | string[] | undefined>, customPrompt? : string, filterFilledFields: boolean = true) {
166
+ private async analyze_image(jobId: string, recordId: string | number, adminUser: any, headers: Record<string, string | string[] | undefined>, customPrompt? : string, filterFilledFields: boolean = true) {
167
167
  // TODO: need to do correct check of rate limit
168
168
  // if (this.options.rateLimits && this.options.rateLimits.fillFieldsFromImages && await this.checkRateLimit("fillFieldsFromImages" ,this.options.rateLimits.fillFieldsFromImages, headers)) {
169
169
  // jobs.set(jobId, { status: 'failed', error: "Rate limit exceeded" });
@@ -248,7 +248,7 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
248
248
 
249
249
  }
250
250
 
251
- private async analyzeNoImages(jobId: string, recordId: string, adminUser: any, headers: Record<string, string | string[] | undefined>, customPrompt? : string, filterFilledFields: boolean = true) {
251
+ private async analyzeNoImages(jobId: string, recordId: string | number, adminUser: any, headers: Record<string, string | string[] | undefined>, customPrompt? : string, filterFilledFields: boolean = true) {
252
252
  // TODO: need to do correct check of rate limit
253
253
  // if (this.options.rateLimits && this.options.rateLimits.fillPlainFields && await this.checkRateLimit("fillPlainFields" ,this.options.rateLimits.fillPlainFields, headers)) {
254
254
  // jobs.set(jobId, { status: 'failed', error: "Rate limit exceeded" });
@@ -312,7 +312,7 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
312
312
  }
313
313
  }
314
314
 
315
- private async initialImageGenerate(jobId: string, recordId: string, adminUser: any, headers: Record<string, string | string[] | undefined>, customPrompt? : string, filterFilledFields: boolean = true) {
315
+ private async initialImageGenerate(jobId: string, recordId: string | number, adminUser: any, headers: Record<string, string | string[] | undefined>, customPrompt? : string, filterFilledFields: boolean = true) {
316
316
  // TODO: need to do correct check of rate limit
317
317
  // if (this.options.rateLimits && this.options.rateLimits.generateImages && await this.checkRateLimit("generateImages" ,this.options.rateLimits.generateImages, headers)) {
318
318
  // jobs.set(jobId, { status: 'failed', error: "Rate limit exceeded" });
@@ -424,7 +424,7 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
424
424
  }
425
425
  }
426
426
 
427
- private async regenerateImage(jobId: string, recordId: string, fieldName: string, prompt: string, adminUser: any, headers: Record<string, string | string[] | undefined>) {
427
+ private async regenerateImage(jobId: string, recordId: string | number, fieldName: string, prompt: string, adminUser: any, headers: Record<string, string | string[] | undefined>) {
428
428
  const Id = recordId;
429
429
  let isError = false;
430
430
  // TODO: need to do correct check of rate limit
@@ -832,10 +832,9 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
832
832
  server.endpoint({
833
833
  method: 'POST',
834
834
  path: `/plugin/${this.pluginInstanceId}/get_records`,
835
+ request_schema: getRecordsBodySchema,
835
836
  handler: async ({ body, response }) => {
836
- const parsed = parseBody(getRecordsBodySchema, body, response);
837
- if ('error' in parsed) return parsed.error;
838
- const data = parsed.data;
837
+ const data = body as z.infer<typeof getRecordsBodySchema>;
839
838
  if (!Array.isArray(data.record)) {
840
839
  return { records: [] };
841
840
  }
@@ -860,10 +859,9 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
860
859
  server.endpoint({
861
860
  method: 'POST',
862
861
  path: `/plugin/${this.pluginInstanceId}/get_old_data`,
862
+ request_schema: getOldDataBodySchema,
863
863
  handler: async ({ body, response }) => {
864
- const parsed = parseBody(getOldDataBodySchema, body, response);
865
- if ('error' in parsed) return parsed.error;
866
- const data = parsed.data;
864
+ const data = body as z.infer<typeof getOldDataBodySchema>;
867
865
  const recordId = data.recordId;
868
866
  if (recordId === undefined || recordId === null) {
869
867
  return { ok: false, error: "Missing recordId" };
@@ -883,10 +881,9 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
883
881
  server.endpoint({
884
882
  method: 'POST',
885
883
  path: `/plugin/${this.pluginInstanceId}/get_images`,
884
+ request_schema: getImagesBodySchema,
886
885
  handler: async ({ body, response }) => {
887
- const parsed = parseBody(getImagesBodySchema, body, response);
888
- if ('error' in parsed) return parsed.error;
889
- const data = parsed.data;
886
+ const data = body as z.infer<typeof getImagesBodySchema>;
890
887
  let images = [];
891
888
  if(data.record){
892
889
  for( const record of data.record ) {
@@ -905,10 +902,9 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
905
902
  server.endpoint({
906
903
  method: 'POST',
907
904
  path: `/plugin/${this.pluginInstanceId}/update_fields`,
905
+ request_schema: updateFieldsBodySchema,
908
906
  handler: async ({ body, adminUser, headers, response }) => {
909
- const parsed = parseBody(updateFieldsBodySchema, body, response);
910
- if ('error' in parsed) return parsed.error;
911
- const data = parsed.data;
907
+ const data = body as z.infer<typeof updateFieldsBodySchema>;
912
908
  let isAllowedToSave: any = { ok: true, error: '' };
913
909
  if(this.options.isAllowedToSave) {
914
910
  isAllowedToSave = await this.options.isAllowedToSave({ record: {}, adminUser: adminUser, resource: this.resourceConfig });
@@ -1015,10 +1011,9 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
1015
1011
  server.endpoint({
1016
1012
  method: 'POST',
1017
1013
  path: `/plugin/${this.pluginInstanceId}/get_image_generation_prompts`,
1014
+ request_schema: getImageGenerationPromptsBodySchema,
1018
1015
  handler: async ({ body, headers, response }) => {
1019
- const parsed = parseBody(getImageGenerationPromptsBodySchema, body, response);
1020
- if ('error' in parsed) return parsed.error;
1021
- const data = parsed.data;
1016
+ const data = body as z.infer<typeof getImageGenerationPromptsBodySchema>;
1022
1017
  const Id = data.recordId || [];
1023
1018
  const customPrompt = data.customPrompt || null;
1024
1019
  const record = await this.adminforth.resource(this.resourceConfig.resourceId).get([Filters.EQ(this.resourceConfig.columns.find(c => c.primaryKey)?.name, Id)]);
@@ -1044,10 +1039,9 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
1044
1039
  server.endpoint({
1045
1040
  method: 'POST',
1046
1041
  path: `/plugin/${this.pluginInstanceId}/create-job`,
1042
+ request_schema: createJobBodySchema,
1047
1043
  handler: async ({ body, adminUser, headers, response }) => {
1048
- const parsed = parseBody(createJobBodySchema, body, response);
1049
- if ('error' in parsed) return parsed.error;
1050
- const data = parsed.data;
1044
+ const data = body as z.infer<typeof createJobBodySchema>;
1051
1045
  const { actionType, recordId, customPrompt, filterFilledFields, sessionIds } = data;
1052
1046
  if (this.options.rateLimits) {
1053
1047
  if (sessionIds && sessionIds.length > 0) {
@@ -1106,10 +1100,9 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
1106
1100
  server.endpoint({
1107
1101
  method: 'POST',
1108
1102
  path: `/plugin/${this.pluginInstanceId}/get-job-status`,
1103
+ request_schema: jobStatusBodySchema,
1109
1104
  handler: async ({ body, adminUser, headers, response }) => {
1110
- const parsed = parseBody(jobStatusBodySchema, body, response);
1111
- if ('error' in parsed) return parsed.error;
1112
- const data = parsed.data;
1105
+ const data = body as z.infer<typeof jobStatusBodySchema>;
1113
1106
  const jobId = data.jobId;
1114
1107
  if (!jobId) {
1115
1108
  response.setStatus(400);
@@ -1147,10 +1140,9 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
1147
1140
  server.endpoint({
1148
1141
  method: 'POST',
1149
1142
  path: `/plugin/${this.pluginInstanceId}/update-rate-limits`,
1143
+ request_schema: updateRateLimitsBodySchema,
1150
1144
  handler: async ({ body, adminUser, headers, response }) => {
1151
- const parsed = parseBody(updateRateLimitsBodySchema, body, response);
1152
- if ('error' in parsed) return parsed.error;
1153
- const data = parsed.data;
1145
+ const data = body as z.infer<typeof updateRateLimitsBodySchema>;
1154
1146
  const actionType = data.actionType;
1155
1147
  const sessionId = randomUUID();
1156
1148
  this.sessionIds.add(sessionId);
@@ -1178,10 +1170,9 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
1178
1170
  server.endpoint({
1179
1171
  method: 'POST',
1180
1172
  path: `/plugin/${this.pluginInstanceId}/compile_old_image_link`,
1173
+ request_schema: compileOldImageLinkBodySchema,
1181
1174
  handler: async ({ body, adminUser, headers, response }) => {
1182
- const parsed = parseBody(compileOldImageLinkBodySchema, body, response);
1183
- if ('error' in parsed) return parsed.error;
1184
- const data = parsed.data;
1175
+ const data = body as z.infer<typeof compileOldImageLinkBodySchema>;
1185
1176
  const image = data.image;
1186
1177
  const columnName = data.columnName;
1187
1178
  if (!image) {
@@ -1211,10 +1202,8 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
1211
1202
  server.endpoint({
1212
1203
  method: 'POST',
1213
1204
  path: `/plugin/${this.pluginInstanceId}/get_filtered_ids`,
1205
+ request_schema: getFilteredIdsBodySchema,
1214
1206
  handler: async ({ body, adminUser, headers, query, cookies, requestUrl, response }) => {
1215
- const parsed = parseBody(getFilteredIdsBodySchema, body, response);
1216
- if ('error' in parsed) return parsed.error;
1217
- const data = parsed.data;
1218
1207
  const resource = this.resourceConfig;
1219
1208
 
1220
1209
  for (const hook of resource.hooks?.list?.beforeDatasourceRequest || []) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/bulk-ai-flow",
3
- "version": "1.27.0",
3
+ "version": "1.27.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -25,7 +25,7 @@
25
25
  "description": "Bulk AI workflow plugin for AdminForth for batch field generation and image processing",
26
26
  "devDependencies": {
27
27
  "@types/node": "latest",
28
- "adminforth": "^3.7.1",
28
+ "adminforth": "^3.8.2",
29
29
  "semantic-release": "^24.2.1",
30
30
  "semantic-release-slack-bot": "^4.0.2",
31
31
  "typescript": "^5.7.3"
@@ -36,7 +36,7 @@
36
36
  "zod": "^4.3.6"
37
37
  },
38
38
  "peerDependencies": {
39
- "adminforth": "^3.7.1"
39
+ "adminforth": "^3.8.2"
40
40
  },
41
41
  "release": {
42
42
  "plugins": [