@adminforth/bulk-ai-flow 1.0.7 → 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/build.log +2 -2
- package/custom/visionAction.vue +21 -25
- package/custom/visionTable.vue +9 -8
- package/dist/custom/visionAction.vue +21 -25
- package/dist/custom/visionTable.vue +9 -8
- package/dist/index.js +55 -29
- package/index.ts +60 -28
- package/package.json +1 -1
- package/types.ts +2 -1
package/build.log
CHANGED
|
@@ -10,5 +10,5 @@ custom/tsconfig.json
|
|
|
10
10
|
custom/visionAction.vue
|
|
11
11
|
custom/visionTable.vue
|
|
12
12
|
|
|
13
|
-
sent
|
|
14
|
-
total size is 23,
|
|
13
|
+
sent 24,032 bytes received 115 bytes 48,294.00 bytes/sec
|
|
14
|
+
total size is 23,613 speedup is 0.98
|
package/custom/visionAction.vue
CHANGED
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
:tableColumnsIndexes="tableColumnsIndexes"
|
|
26
26
|
:selected="selected"
|
|
27
27
|
:isAiResponseReceived="isAiResponseReceived"
|
|
28
|
+
:primaryKey="primaryKey"
|
|
28
29
|
/>
|
|
29
30
|
<Button
|
|
30
31
|
class="w-64"
|
|
@@ -67,6 +68,7 @@ const tableColumnsIndexes = ref([]);
|
|
|
67
68
|
const customFieldNames = ref([]);
|
|
68
69
|
const selected = ref<any[]>([]);
|
|
69
70
|
const isAiResponseReceived = ref([]);
|
|
71
|
+
const primaryKey = props.meta.primaryKey;
|
|
70
72
|
|
|
71
73
|
const openDialog = async () => {
|
|
72
74
|
confirmDialog.value.open();
|
|
@@ -82,9 +84,9 @@ const openDialog = async () => {
|
|
|
82
84
|
analyzeFields();
|
|
83
85
|
}
|
|
84
86
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
87
|
+
watch(selected, (val) => {
|
|
88
|
+
console.log('Selected changed:', val);
|
|
89
|
+
}, { deep: true });
|
|
88
90
|
|
|
89
91
|
const closeDialog = () => {
|
|
90
92
|
confirmDialog.value.close();
|
|
@@ -105,14 +107,11 @@ function generateTableHeaders(outputFields) {
|
|
|
105
107
|
headers.push({ label: 'Field name', fieldName: 'label' });
|
|
106
108
|
headers.push({ label: 'Source Images', fieldName: 'images' });
|
|
107
109
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
fieldName: key,
|
|
114
|
-
});
|
|
115
|
-
}
|
|
110
|
+
for (const key in outputFields) {
|
|
111
|
+
headers.push({
|
|
112
|
+
label: formatLabel(key),
|
|
113
|
+
fieldName: key,
|
|
114
|
+
});
|
|
116
115
|
}
|
|
117
116
|
return headers;
|
|
118
117
|
}
|
|
@@ -144,22 +143,19 @@ function generateTableColumns() {
|
|
|
144
143
|
|
|
145
144
|
function setSelected() {
|
|
146
145
|
selected.value = records.value.map(() => ({}));
|
|
147
|
-
|
|
148
146
|
records.value.forEach((record, index) => {
|
|
149
|
-
props.meta.outputFields
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
selected.value[index][key] = record[key];
|
|
157
|
-
}
|
|
147
|
+
for (const key in props.meta.outputFields) {
|
|
148
|
+
if(isInColumnEnum(key)){
|
|
149
|
+
const colEnum = props.meta.columnEnums.find(c => c.name === key);
|
|
150
|
+
const object = colEnum.enum.find(item => item.value === record[key]);
|
|
151
|
+
selected.value[index][key] = object ? record[key] : null;
|
|
152
|
+
} else {
|
|
153
|
+
selected.value[index][key] = record[key];
|
|
158
154
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
155
|
+
}
|
|
156
|
+
selected.value[index].isChecked = true;
|
|
157
|
+
selected.value[index][primaryKey] = record[primaryKey];
|
|
158
|
+
isAiResponseReceived.value[index] = true;
|
|
163
159
|
});
|
|
164
160
|
}
|
|
165
161
|
|
package/custom/visionTable.vue
CHANGED
|
@@ -44,32 +44,32 @@
|
|
|
44
44
|
</template>
|
|
45
45
|
<!-- CUSTOM FIELD TEMPLATES -->
|
|
46
46
|
<template v-for="n in customFieldNames" :key="n" #[`cell:${n}`]="{ item, column }">
|
|
47
|
-
<div v-if="isAiResponseReceived[tableColumnsIndexes.findIndex(el => el
|
|
47
|
+
<div v-if="isAiResponseReceived[tableColumnsIndexes.findIndex(el => el[primaryKey] === item[primaryKey])]">
|
|
48
48
|
<div v-if="isInColumnEnum(n)">
|
|
49
49
|
<Select
|
|
50
50
|
:options="convertColumnEnumToSelectOptions(props.meta.columnEnums, n)"
|
|
51
|
-
v-model="selected[tableColumnsIndexes.findIndex(el => el
|
|
51
|
+
v-model="selected[tableColumnsIndexes.findIndex(el => el[primaryKey] === item[primaryKey])][n]"
|
|
52
52
|
>
|
|
53
53
|
</Select>
|
|
54
54
|
</div>
|
|
55
|
-
<div v-else-if="typeof selected[tableColumnsIndexes.findIndex(el => el
|
|
55
|
+
<div v-else-if="typeof selected[tableColumnsIndexes.findIndex(el => el[primaryKey] === item[primaryKey])][n] === 'string' || typeof selected[tableColumnsIndexes.findIndex(el => el[primaryKey] === item[primaryKey])][n] === 'object'">
|
|
56
56
|
<Textarea
|
|
57
57
|
class="w-full h-full"
|
|
58
58
|
type="text"
|
|
59
|
-
v-model="selected[tableColumnsIndexes.findIndex(el => el
|
|
59
|
+
v-model="selected[tableColumnsIndexes.findIndex(el => el[primaryKey] === item[primaryKey])][n]"
|
|
60
60
|
>
|
|
61
61
|
</Textarea>
|
|
62
62
|
</div>
|
|
63
|
-
<div v-else-if="typeof selected[tableColumnsIndexes.findIndex(el => el
|
|
63
|
+
<div v-else-if="typeof selected[tableColumnsIndexes.findIndex(el => el[primaryKey] === item[primaryKey])][n] === 'boolean'">
|
|
64
64
|
<Toggle
|
|
65
|
-
v-model="selected[tableColumnsIndexes.findIndex(el => el
|
|
65
|
+
v-model="selected[tableColumnsIndexes.findIndex(el => el[primaryKey] === item[primaryKey])][n]"
|
|
66
66
|
>
|
|
67
67
|
</Toggle>
|
|
68
68
|
</div>
|
|
69
69
|
<div v-else>
|
|
70
70
|
<Input
|
|
71
71
|
type="number"
|
|
72
|
-
v-model="selected[tableColumnsIndexes.findIndex(el => el
|
|
72
|
+
v-model="selected[tableColumnsIndexes.findIndex(el => el[primaryKey] === item[primaryKey])][n]"
|
|
73
73
|
class="w-full "
|
|
74
74
|
:fullWidth="true"
|
|
75
75
|
/>
|
|
@@ -95,7 +95,8 @@ const props = defineProps<{
|
|
|
95
95
|
customFieldNames: any,
|
|
96
96
|
tableColumnsIndexes: any,
|
|
97
97
|
selected: any,
|
|
98
|
-
isAiResponseReceived: boolean[]
|
|
98
|
+
isAiResponseReceived: boolean[],
|
|
99
|
+
primaryKey: any
|
|
99
100
|
}>();
|
|
100
101
|
|
|
101
102
|
const zoomedImage = ref(null)
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
:tableColumnsIndexes="tableColumnsIndexes"
|
|
26
26
|
:selected="selected"
|
|
27
27
|
:isAiResponseReceived="isAiResponseReceived"
|
|
28
|
+
:primaryKey="primaryKey"
|
|
28
29
|
/>
|
|
29
30
|
<Button
|
|
30
31
|
class="w-64"
|
|
@@ -67,6 +68,7 @@ const tableColumnsIndexes = ref([]);
|
|
|
67
68
|
const customFieldNames = ref([]);
|
|
68
69
|
const selected = ref<any[]>([]);
|
|
69
70
|
const isAiResponseReceived = ref([]);
|
|
71
|
+
const primaryKey = props.meta.primaryKey;
|
|
70
72
|
|
|
71
73
|
const openDialog = async () => {
|
|
72
74
|
confirmDialog.value.open();
|
|
@@ -82,9 +84,9 @@ const openDialog = async () => {
|
|
|
82
84
|
analyzeFields();
|
|
83
85
|
}
|
|
84
86
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
87
|
+
watch(selected, (val) => {
|
|
88
|
+
console.log('Selected changed:', val);
|
|
89
|
+
}, { deep: true });
|
|
88
90
|
|
|
89
91
|
const closeDialog = () => {
|
|
90
92
|
confirmDialog.value.close();
|
|
@@ -105,14 +107,11 @@ function generateTableHeaders(outputFields) {
|
|
|
105
107
|
headers.push({ label: 'Field name', fieldName: 'label' });
|
|
106
108
|
headers.push({ label: 'Source Images', fieldName: 'images' });
|
|
107
109
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
fieldName: key,
|
|
114
|
-
});
|
|
115
|
-
}
|
|
110
|
+
for (const key in outputFields) {
|
|
111
|
+
headers.push({
|
|
112
|
+
label: formatLabel(key),
|
|
113
|
+
fieldName: key,
|
|
114
|
+
});
|
|
116
115
|
}
|
|
117
116
|
return headers;
|
|
118
117
|
}
|
|
@@ -144,22 +143,19 @@ function generateTableColumns() {
|
|
|
144
143
|
|
|
145
144
|
function setSelected() {
|
|
146
145
|
selected.value = records.value.map(() => ({}));
|
|
147
|
-
|
|
148
146
|
records.value.forEach((record, index) => {
|
|
149
|
-
props.meta.outputFields
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
selected.value[index][key] = record[key];
|
|
157
|
-
}
|
|
147
|
+
for (const key in props.meta.outputFields) {
|
|
148
|
+
if(isInColumnEnum(key)){
|
|
149
|
+
const colEnum = props.meta.columnEnums.find(c => c.name === key);
|
|
150
|
+
const object = colEnum.enum.find(item => item.value === record[key]);
|
|
151
|
+
selected.value[index][key] = object ? record[key] : null;
|
|
152
|
+
} else {
|
|
153
|
+
selected.value[index][key] = record[key];
|
|
158
154
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
155
|
+
}
|
|
156
|
+
selected.value[index].isChecked = true;
|
|
157
|
+
selected.value[index][primaryKey] = record[primaryKey];
|
|
158
|
+
isAiResponseReceived.value[index] = true;
|
|
163
159
|
});
|
|
164
160
|
}
|
|
165
161
|
|
|
@@ -44,32 +44,32 @@
|
|
|
44
44
|
</template>
|
|
45
45
|
<!-- CUSTOM FIELD TEMPLATES -->
|
|
46
46
|
<template v-for="n in customFieldNames" :key="n" #[`cell:${n}`]="{ item, column }">
|
|
47
|
-
<div v-if="isAiResponseReceived[tableColumnsIndexes.findIndex(el => el
|
|
47
|
+
<div v-if="isAiResponseReceived[tableColumnsIndexes.findIndex(el => el[primaryKey] === item[primaryKey])]">
|
|
48
48
|
<div v-if="isInColumnEnum(n)">
|
|
49
49
|
<Select
|
|
50
50
|
:options="convertColumnEnumToSelectOptions(props.meta.columnEnums, n)"
|
|
51
|
-
v-model="selected[tableColumnsIndexes.findIndex(el => el
|
|
51
|
+
v-model="selected[tableColumnsIndexes.findIndex(el => el[primaryKey] === item[primaryKey])][n]"
|
|
52
52
|
>
|
|
53
53
|
</Select>
|
|
54
54
|
</div>
|
|
55
|
-
<div v-else-if="typeof selected[tableColumnsIndexes.findIndex(el => el
|
|
55
|
+
<div v-else-if="typeof selected[tableColumnsIndexes.findIndex(el => el[primaryKey] === item[primaryKey])][n] === 'string' || typeof selected[tableColumnsIndexes.findIndex(el => el[primaryKey] === item[primaryKey])][n] === 'object'">
|
|
56
56
|
<Textarea
|
|
57
57
|
class="w-full h-full"
|
|
58
58
|
type="text"
|
|
59
|
-
v-model="selected[tableColumnsIndexes.findIndex(el => el
|
|
59
|
+
v-model="selected[tableColumnsIndexes.findIndex(el => el[primaryKey] === item[primaryKey])][n]"
|
|
60
60
|
>
|
|
61
61
|
</Textarea>
|
|
62
62
|
</div>
|
|
63
|
-
<div v-else-if="typeof selected[tableColumnsIndexes.findIndex(el => el
|
|
63
|
+
<div v-else-if="typeof selected[tableColumnsIndexes.findIndex(el => el[primaryKey] === item[primaryKey])][n] === 'boolean'">
|
|
64
64
|
<Toggle
|
|
65
|
-
v-model="selected[tableColumnsIndexes.findIndex(el => el
|
|
65
|
+
v-model="selected[tableColumnsIndexes.findIndex(el => el[primaryKey] === item[primaryKey])][n]"
|
|
66
66
|
>
|
|
67
67
|
</Toggle>
|
|
68
68
|
</div>
|
|
69
69
|
<div v-else>
|
|
70
70
|
<Input
|
|
71
71
|
type="number"
|
|
72
|
-
v-model="selected[tableColumnsIndexes.findIndex(el => el
|
|
72
|
+
v-model="selected[tableColumnsIndexes.findIndex(el => el[primaryKey] === item[primaryKey])][n]"
|
|
73
73
|
class="w-full "
|
|
74
74
|
:fullWidth="true"
|
|
75
75
|
/>
|
|
@@ -95,7 +95,8 @@ const props = defineProps<{
|
|
|
95
95
|
customFieldNames: any,
|
|
96
96
|
tableColumnsIndexes: any,
|
|
97
97
|
selected: any,
|
|
98
|
-
isAiResponseReceived: boolean[]
|
|
98
|
+
isAiResponseReceived: boolean[],
|
|
99
|
+
primaryKey: any
|
|
99
100
|
}>();
|
|
100
101
|
|
|
101
102
|
const zoomedImage = ref(null)
|
package/dist/index.js
CHANGED
|
@@ -16,19 +16,17 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
|
|
|
16
16
|
}
|
|
17
17
|
// Compile Handlebars templates in outputFields using record fields as context
|
|
18
18
|
compileOutputFieldsTemplates(record) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
compiled[key] = tpl(record);
|
|
25
|
-
}
|
|
26
|
-
catch (_a) {
|
|
27
|
-
compiled[key] = String(templateStr);
|
|
28
|
-
}
|
|
19
|
+
const compiled = {};
|
|
20
|
+
for (const [key, templateStr] of Object.entries(this.options.fillFieldsFromImages)) {
|
|
21
|
+
try {
|
|
22
|
+
const tpl = Handlebars.compile(String(templateStr));
|
|
23
|
+
compiled[key] = tpl(record);
|
|
29
24
|
}
|
|
30
|
-
|
|
31
|
-
|
|
25
|
+
catch (_a) {
|
|
26
|
+
compiled[key] = String(templateStr);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return compiled;
|
|
32
30
|
}
|
|
33
31
|
modifyResourceConfig(adminforth, resourceConfig) {
|
|
34
32
|
const _super = Object.create(null, {
|
|
@@ -39,30 +37,56 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
|
|
|
39
37
|
//check if options names are provided
|
|
40
38
|
const columns = this.resourceConfig.columns;
|
|
41
39
|
let columnEnums = [];
|
|
42
|
-
for (const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (column) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
throw new Error(`⚠️ No column found for key "${key}"`);
|
|
40
|
+
for (const [key, value] of Object.entries(this.options.fillFieldsFromImages)) {
|
|
41
|
+
const column = columns.find(c => c.name.toLowerCase() === key.toLowerCase());
|
|
42
|
+
if (column) {
|
|
43
|
+
if (column.enum) {
|
|
44
|
+
this.options.fillFieldsFromImages[key] = `${value} Select ${key} from the list (USE ONLY VALUE FIELD. USE ONLY VALUES FROM THIS LIST): ${JSON.stringify(column.enum)}`;
|
|
45
|
+
columnEnums.push({
|
|
46
|
+
name: key,
|
|
47
|
+
enum: column.enum,
|
|
48
|
+
});
|
|
56
49
|
}
|
|
57
50
|
}
|
|
51
|
+
else {
|
|
52
|
+
throw new Error(`⚠️ No column found for key "${key}"`);
|
|
53
|
+
}
|
|
58
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
|
+
// }
|
|
80
|
+
const primaryKeyColumn = this.resourceConfig.columns.find((col) => col.primaryKey);
|
|
81
|
+
//console.log('Primary Key Column:', primaryKeyColumn);
|
|
59
82
|
const pageInjection = {
|
|
60
83
|
file: this.componentPath('visionAction.vue'),
|
|
61
84
|
meta: {
|
|
62
85
|
pluginInstanceId: this.pluginInstanceId,
|
|
63
|
-
outputFields: this.options.
|
|
86
|
+
outputFields: this.options.fillFieldsFromImages,
|
|
64
87
|
actionName: this.options.actionName,
|
|
65
88
|
columnEnums: columnEnums,
|
|
89
|
+
primaryKey: primaryKeyColumn.name,
|
|
66
90
|
}
|
|
67
91
|
};
|
|
68
92
|
if (!this.resourceConfig.options.pageInjections) {
|
|
@@ -91,7 +115,8 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
|
|
|
91
115
|
const tasks = selectedIds.map((ID) => __awaiter(this, void 0, void 0, function* () {
|
|
92
116
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
93
117
|
// Fetch the record using the provided ID
|
|
94
|
-
const
|
|
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)]);
|
|
95
120
|
//recieve image URLs to analyze
|
|
96
121
|
const attachmentFiles = yield this.options.attachFiles({ record: record });
|
|
97
122
|
//create prompt for OpenAI
|
|
@@ -124,8 +149,9 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
|
|
|
124
149
|
path: `/plugin/${this.pluginInstanceId}/get_records`,
|
|
125
150
|
handler: (body) => __awaiter(this, void 0, void 0, function* () {
|
|
126
151
|
let records = [];
|
|
152
|
+
const primaryKeyColumn = this.resourceConfig.columns.find((col) => col.primaryKey);
|
|
127
153
|
for (const record of body.body.record) {
|
|
128
|
-
records.push(yield this.adminforth.resource(this.resourceConfig.resourceId).get([Filters.EQ(
|
|
154
|
+
records.push(yield this.adminforth.resource(this.resourceConfig.resourceId).get([Filters.EQ(primaryKeyColumn.name, record)]));
|
|
129
155
|
records[records.length - 1]._label = this.resourceConfig.recordLabel(records[records.length - 1]);
|
|
130
156
|
}
|
|
131
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);
|
|
@@ -14,19 +15,17 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
|
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
// Compile Handlebars templates in outputFields using record fields as context
|
|
17
|
-
private compileOutputFieldsTemplates(record: any): Record<string, string>
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
compiled[key] = String(templateStr);
|
|
26
|
-
}
|
|
18
|
+
private compileOutputFieldsTemplates(record: any): Record<string, string> {
|
|
19
|
+
const compiled: Record<string, string> = {};
|
|
20
|
+
for (const [key, templateStr] of Object.entries(this.options.fillFieldsFromImages)) {
|
|
21
|
+
try {
|
|
22
|
+
const tpl = Handlebars.compile(String(templateStr));
|
|
23
|
+
compiled[key] = tpl(record);
|
|
24
|
+
} catch {
|
|
25
|
+
compiled[key] = String(templateStr);
|
|
27
26
|
}
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
}
|
|
28
|
+
return compiled;
|
|
30
29
|
}
|
|
31
30
|
|
|
32
31
|
async modifyResourceConfig(adminforth: IAdminForth, resourceConfig: AdminForthResource) {
|
|
@@ -35,30 +34,61 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
|
|
|
35
34
|
//check if options names are provided
|
|
36
35
|
const columns = this.resourceConfig.columns;
|
|
37
36
|
let columnEnums = [];
|
|
38
|
-
for (const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
} else {
|
|
50
|
-
throw new Error(`⚠️ No column found for key "${key}"`);
|
|
37
|
+
for (const [key, value] of Object.entries(this.options.fillFieldsFromImages)) {
|
|
38
|
+
const column = columns.find(c => c.name.toLowerCase() === key.toLowerCase());
|
|
39
|
+
if (column) {
|
|
40
|
+
if(column.enum){
|
|
41
|
+
(this.options.fillFieldsFromImages as any)[key] = `${value} Select ${key} from the list (USE ONLY VALUE FIELD. USE ONLY VALUES FROM THIS LIST): ${JSON.stringify(column.enum)}`;
|
|
42
|
+
columnEnums.push({
|
|
43
|
+
name: key,
|
|
44
|
+
enum: column.enum,
|
|
45
|
+
});
|
|
51
46
|
}
|
|
47
|
+
} else {
|
|
48
|
+
throw new Error(`⚠️ No column found for key "${key}"`);
|
|
52
49
|
}
|
|
53
50
|
}
|
|
54
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
|
+
|
|
81
|
+
const primaryKeyColumn = this.resourceConfig.columns.find((col) => col.primaryKey);
|
|
82
|
+
//console.log('Primary Key Column:', primaryKeyColumn);
|
|
83
|
+
|
|
55
84
|
const pageInjection = {
|
|
56
85
|
file: this.componentPath('visionAction.vue'),
|
|
57
86
|
meta: {
|
|
58
87
|
pluginInstanceId: this.pluginInstanceId,
|
|
59
|
-
outputFields: this.options.
|
|
88
|
+
outputFields: this.options.fillFieldsFromImages,
|
|
60
89
|
actionName: this.options.actionName,
|
|
61
90
|
columnEnums: columnEnums,
|
|
91
|
+
primaryKey: primaryKeyColumn.name,
|
|
62
92
|
}
|
|
63
93
|
}
|
|
64
94
|
|
|
@@ -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
|
|
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(
|
|
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
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
|
-
|
|
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[]>,
|