@adminforth/bulk-ai-flow 1.1.0 → 1.1.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.
package/dist/index.js CHANGED
@@ -52,8 +52,33 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
52
52
  throw new Error(`⚠️ No column found for key "${key}"`);
53
53
  }
54
54
  }
55
+ // if (this.options.generateImages) {
56
+ // const resource = adminforth.config.resources.find(r => r.resourceId === this.options.generateImages!.attachmentResource);
57
+ // if (!resource) {
58
+ // throw new Error(`Resource '${this.options.generateImages!.attachmentResource}' not found`);
59
+ // }
60
+ // this.attachmentResource = resource;
61
+ // const field = resource.columns.find(c => c.name === this.options.generateImages!.attachmentFieldName);
62
+ // if (!field) {
63
+ // throw new Error(`Field '${this.options.generateImages!.attachmentFieldName}' not found in resource '${this.options.generateImages!.attachmentResource}'`);
64
+ // }
65
+ // const plugin = adminforth.activatedPlugins.find(p =>
66
+ // p.resourceConfig!.resourceId === this.options.attachments!.attachmentResource &&
67
+ // p.pluginOptions.pathColumnName === this.options.attachments!.attachmentFieldName
68
+ // );
69
+ // if (!plugin) {
70
+ // throw new Error(`Plugin for attachment field '${this.options.attachments!.attachmentFieldName}' not found in resource '${this.options.attachments!.attachmentResource}', please check if Upload Plugin is installed on the field ${this.options.attachments!.attachmentFieldName}`);
71
+ // }
72
+ // if (!plugin.pluginOptions.storageAdapter.objectCanBeAccesedPublicly()) {
73
+ // throw new Error(`Upload Plugin for attachment field '${this.options.attachments!.attachmentFieldName}' in resource '${this.options.attachments!.attachmentResource}'
74
+ // uses adapter which is not configured to store objects in public way, so it will produce only signed private URLs which can not be used in HTML text of blog posts.
75
+ // Please configure adapter in such way that it will store objects publicly (e.g. for S3 use 'public-read' ACL).
76
+ // `);
77
+ // }
78
+ // this.uploadPlugin = plugin;
79
+ // }
55
80
  const primaryKeyColumn = this.resourceConfig.columns.find((col) => col.primaryKey);
56
- console.log('Primary Key Column:', primaryKeyColumn);
81
+ //console.log('Primary Key Column:', primaryKeyColumn);
57
82
  const pageInjection = {
58
83
  file: this.componentPath('visionAction.vue'),
59
84
  meta: {
@@ -90,7 +115,8 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
90
115
  const tasks = selectedIds.map((ID) => __awaiter(this, void 0, void 0, function* () {
91
116
  var _a, _b, _c, _d, _e, _f, _g, _h, _j;
92
117
  // Fetch the record using the provided ID
93
- const record = yield this.adminforth.resource(this.resourceConfig.resourceId).get([Filters.EQ('id', ID)]);
118
+ const primaryKeyColumn = this.resourceConfig.columns.find((col) => col.primaryKey);
119
+ const record = yield this.adminforth.resource(this.resourceConfig.resourceId).get([Filters.EQ(primaryKeyColumn.name, ID)]);
94
120
  //recieve image URLs to analyze
95
121
  const attachmentFiles = yield this.options.attachFiles({ record: record });
96
122
  //create prompt for OpenAI
@@ -123,8 +149,9 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
123
149
  path: `/plugin/${this.pluginInstanceId}/get_records`,
124
150
  handler: (body) => __awaiter(this, void 0, void 0, function* () {
125
151
  let records = [];
152
+ const primaryKeyColumn = this.resourceConfig.columns.find((col) => col.primaryKey);
126
153
  for (const record of body.body.record) {
127
- records.push(yield this.adminforth.resource(this.resourceConfig.resourceId).get([Filters.EQ('id', record)]));
154
+ records.push(yield this.adminforth.resource(this.resourceConfig.resourceId).get([Filters.EQ(primaryKeyColumn.name, record)]));
128
155
  records[records.length - 1]._label = this.resourceConfig.recordLabel(records[records.length - 1]);
129
156
  }
130
157
  return {
package/index.ts CHANGED
@@ -7,6 +7,7 @@ import Handlebars from 'handlebars';
7
7
 
8
8
  export default class BulkAiFlowPlugin extends AdminForthPlugin {
9
9
  options: PluginOptions;
10
+ uploadPlugin: AdminForthPlugin;
10
11
 
11
12
  constructor(options: PluginOptions) {
12
13
  super(options, import.meta.url);
@@ -48,8 +49,37 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
48
49
  }
49
50
  }
50
51
 
52
+
53
+ // if (this.options.generateImages) {
54
+ // const resource = adminforth.config.resources.find(r => r.resourceId === this.options.generateImages!.attachmentResource);
55
+ // if (!resource) {
56
+ // throw new Error(`Resource '${this.options.generateImages!.attachmentResource}' not found`);
57
+ // }
58
+ // this.attachmentResource = resource;
59
+ // const field = resource.columns.find(c => c.name === this.options.generateImages!.attachmentFieldName);
60
+ // if (!field) {
61
+ // throw new Error(`Field '${this.options.generateImages!.attachmentFieldName}' not found in resource '${this.options.generateImages!.attachmentResource}'`);
62
+ // }
63
+ // const plugin = adminforth.activatedPlugins.find(p =>
64
+ // p.resourceConfig!.resourceId === this.options.attachments!.attachmentResource &&
65
+ // p.pluginOptions.pathColumnName === this.options.attachments!.attachmentFieldName
66
+ // );
67
+ // if (!plugin) {
68
+ // throw new Error(`Plugin for attachment field '${this.options.attachments!.attachmentFieldName}' not found in resource '${this.options.attachments!.attachmentResource}', please check if Upload Plugin is installed on the field ${this.options.attachments!.attachmentFieldName}`);
69
+ // }
70
+
71
+ // if (!plugin.pluginOptions.storageAdapter.objectCanBeAccesedPublicly()) {
72
+ // throw new Error(`Upload Plugin for attachment field '${this.options.attachments!.attachmentFieldName}' in resource '${this.options.attachments!.attachmentResource}'
73
+ // uses adapter which is not configured to store objects in public way, so it will produce only signed private URLs which can not be used in HTML text of blog posts.
74
+ // Please configure adapter in such way that it will store objects publicly (e.g. for S3 use 'public-read' ACL).
75
+ // `);
76
+ // }
77
+ // this.uploadPlugin = plugin;
78
+ // }
79
+
80
+
51
81
  const primaryKeyColumn = this.resourceConfig.columns.find((col) => col.primaryKey);
52
- console.log('Primary Key Column:', primaryKeyColumn);
82
+ //console.log('Primary Key Column:', primaryKeyColumn);
53
83
 
54
84
  const pageInjection = {
55
85
  file: this.componentPath('visionAction.vue'),
@@ -90,7 +120,8 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
90
120
  const selectedIds = body.selectedIds || [];
91
121
  const tasks = selectedIds.map(async (ID) => {
92
122
  // Fetch the record using the provided ID
93
- const record = await this.adminforth.resource(this.resourceConfig.resourceId).get( [Filters.EQ('id', ID)] );
123
+ const primaryKeyColumn = this.resourceConfig.columns.find((col) => col.primaryKey);
124
+ const record = await this.adminforth.resource(this.resourceConfig.resourceId).get( [Filters.EQ(primaryKeyColumn.name, ID)] );
94
125
 
95
126
  //recieve image URLs to analyze
96
127
  const attachmentFiles = await this.options.attachFiles({ record: record });
@@ -131,8 +162,9 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
131
162
  path: `/plugin/${this.pluginInstanceId}/get_records`,
132
163
  handler: async ( body ) => {
133
164
  let records = [];
165
+ const primaryKeyColumn = this.resourceConfig.columns.find((col) => col.primaryKey);
134
166
  for( const record of body.body.record ) {
135
- records.push(await this.adminforth.resource(this.resourceConfig.resourceId).get( [Filters.EQ('id', record)] ));
167
+ records.push(await this.adminforth.resource(this.resourceConfig.resourceId).get( [Filters.EQ(primaryKeyColumn.name, record)] ));
136
168
  records[records.length - 1]._label = this.resourceConfig.recordLabel(records[records.length - 1]);
137
169
  }
138
170
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/bulk-ai-flow",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/types.ts CHANGED
@@ -4,7 +4,8 @@ import { ImageVisionAdapter, AdminUser, IAdminForth, StorageAdapter } from "admi
4
4
  export interface PluginOptions {
5
5
  actionName: string,
6
6
  visionAdapter: ImageVisionAdapter,
7
- fillFieldsFromImages: Record<string, string>,
7
+ fillFieldsFromImages?: Record<string, string>, // can analyze what is on image and fill fields, typical tasks "find dominant color", "describe what is on image", "clasify to one enum item, e.g. what is on image dog/cat/plant"
8
+ generateImages?: Record<string, string>, // can generate from images or just from another fields, e.g. "remove text from images", "improve image quality", "turn image into ghibli style"
8
9
  attachFiles?: ({ record }: {
9
10
  record: any,
10
11
  }) => string[] | Promise<string[]>,