@adminforth/bulk-ai-flow 1.0.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.
@@ -0,0 +1,13 @@
1
+
2
+ #!/bin/bash
3
+
4
+ # write npm run output both to console and to build.log
5
+ npm run build 2>&1 | tee build.log
6
+ build_status=${PIPESTATUS[0]}
7
+
8
+ # if exist status from the npm run build is not 0
9
+ # then exit with the status code from the npm run build
10
+ if [ $build_status -ne 0 ]; then
11
+ echo "Build failed. Exiting with status code $build_status"
12
+ exit $build_status
13
+ fi
@@ -0,0 +1,44 @@
1
+ #!/bin/sh
2
+
3
+ set -x
4
+
5
+ COMMIT_SHORT_SHA=$(echo $CI_COMMIT_SHA | cut -c1-8)
6
+
7
+
8
+ if [ "$CI_PREV_PIPELINE_STATUS" = "success" ]; then
9
+ MESSAGE="Did a build without issues on \`$CI_REPO_NAME/$CI_COMMIT_BRANCH\`. Commit: _${CI_COMMIT_MESSAGE}_ (<$CI_COMMIT_URL|$COMMIT_SHORT_SHA>)"
10
+
11
+ curl -s -X POST -H "Content-Type: application/json" -d '{
12
+ "username": "'"$CI_COMMIT_AUTHOR"'",
13
+ "icon_url": "'"$CI_COMMIT_AUTHOR_AVATAR"'",
14
+ "attachments": [
15
+ {
16
+ "mrkdwn_in": ["text", "pretext"],
17
+ "color": "#36a64f",
18
+ "text": "'"$MESSAGE"'"
19
+ }
20
+ ]
21
+ }' "$DEVELOPERS_SLACK_WEBHOOK"
22
+ exit 0
23
+ fi
24
+ export BUILD_LOG=$(cat ./build.log)
25
+
26
+ BUILD_LOG=$(echo $BUILD_LOG | sed 's/"/\\"/g')
27
+
28
+ MESSAGE="Broke \`$CI_REPO_NAME/$CI_COMMIT_BRANCH\` with commit _${CI_COMMIT_MESSAGE}_ (<$CI_COMMIT_URL|$COMMIT_SHORT_SHA>)"
29
+ CODE_BLOCK="\`\`\`$BUILD_LOG\n\`\`\`"
30
+
31
+ echo "Sending slack message to developers $MESSAGE"
32
+ # Send the message
33
+ curl -sS -X POST -H "Content-Type: application/json" -d '{
34
+ "username": "'"$CI_COMMIT_AUTHOR"'",
35
+ "icon_url": "'"$CI_COMMIT_AUTHOR_AVATAR"'",
36
+ "attachments": [
37
+ {
38
+ "mrkdwn_in": ["text", "pretext"],
39
+ "color": "#8A1C12",
40
+ "text": "'"$CODE_BLOCK"'",
41
+ "pretext": "'"$MESSAGE"'"
42
+ }
43
+ ]
44
+ }' "$DEVELOPERS_SLACK_WEBHOOK" 2>&1
@@ -0,0 +1,40 @@
1
+ clone:
2
+ git:
3
+ image: woodpeckerci/plugin-git
4
+ settings:
5
+ partial: false
6
+ depth: 5
7
+
8
+ steps:
9
+ init-secrets:
10
+ when:
11
+ - event: push
12
+ image: infisical/cli
13
+ environment:
14
+ INFISICAL_TOKEN:
15
+ from_secret: VAULT_TOKEN
16
+ commands:
17
+ - infisical export --domain https://vault.devforth.io/api --format=dotenv-export --env="prod" > /woodpecker/deploy.vault.env
18
+
19
+ release:
20
+ image: node:20
21
+ when:
22
+ - event: push
23
+ commands:
24
+ - apt update && apt install -y rsync
25
+ - export $(cat /woodpecker/deploy.vault.env | xargs)
26
+ - npm clean-install
27
+ - /bin/bash ./.woodpecker/buildRelease.sh
28
+ - npm audit signatures
29
+ - npx semantic-release
30
+
31
+ slack-on-failure:
32
+ when:
33
+ - event: push
34
+ status: [failure, success]
35
+ - event: push
36
+ image: curlimages/curl
37
+ commands:
38
+ - export $(cat /woodpecker/deploy.vault.env | xargs)
39
+ - /bin/sh ./.woodpecker/buildSlackNotify.sh
40
+
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Devforth.io
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ Readme
package/build.log ADDED
@@ -0,0 +1,12 @@
1
+
2
+ > @adminforth/bulk-ai-flow@1.0.1 build
3
+ > tsc && rsync -av --exclude 'node_modules' custom dist/
4
+
5
+ sending incremental file list
6
+ custom/
7
+ custom/tsconfig.json
8
+ custom/visionAction.vue
9
+ custom/visionTable.vue
10
+
11
+ sent 11,736 bytes received 77 bytes 23,626.00 bytes/sec
12
+ total size is 11,450 speedup is 0.97
@@ -0,0 +1,19 @@
1
+ {
2
+ "compilerOptions": {
3
+ "baseUrl": ".", // This should point to your project root
4
+ "paths": {
5
+ "@/*": [
6
+ // "node_modules/adminforth/dist/spa/src/*"
7
+ "../../../spa/src/*"
8
+ ],
9
+ "*": [
10
+ // "node_modules/adminforth/dist/spa/node_modules/*"
11
+ "../../../spa/node_modules/*"
12
+ ],
13
+ "@@/*": [
14
+ // "node_modules/adminforth/dist/spa/src/*"
15
+ "."
16
+ ]
17
+ }
18
+ }
19
+ }
@@ -0,0 +1,254 @@
1
+ <template>
2
+ <div @click="openDialog">
3
+ <p class="">{{ props.meta.actionName }}</p>
4
+ </div>
5
+ <Dialog ref="confirmDialog">
6
+ <div
7
+ class="fixed inset-0 z-50 flex items-center justify-center bg-black/40"
8
+ @click="closeDialog"
9
+ >
10
+ <div
11
+ class="relative max-w-[95vw] max-h-[90vh] bg-white dark:bg-gray-900 rounded-md shadow-2xl overflow-hidden"
12
+ @click.stop
13
+ >
14
+ <div class="flex flex-col items-end justify-evenly gap-4 w-full h-full p-6 overflow-y-auto">
15
+ <VisionTable
16
+ v-if="records && props.checkboxes.length"
17
+ :checkbox="props.checkboxes"
18
+ :records="records"
19
+ :index="0"
20
+ :meta="props.meta"
21
+ :images="images"
22
+ :tableHeaders="tableHeaders"
23
+ :tableColumns="tableColumns"
24
+ :customFieldNames="customFieldNames"
25
+ :tableColumnsIndexes="tableColumnsIndexes"
26
+ :selected="selected"
27
+ :isAiResponseReceived="isAiResponseReceived"
28
+ />
29
+ <Button
30
+ class="w-64"
31
+ @click="saveData"
32
+ >
33
+ {{ props.checkboxes.length > 1 ? 'Save fields' : 'Save field' }}
34
+ </Button>
35
+ </div>
36
+ </div>
37
+ </div>
38
+ </Dialog>
39
+ </template>
40
+
41
+ <script lang="ts" setup>
42
+ import { callAdminForthApi } from '@/utils';
43
+ import { ref, watch } from 'vue'
44
+ import { Dialog, Button } from '@/afcl';
45
+ import VisionTable from './visionTable.vue'
46
+
47
+ const props = defineProps<{
48
+ checkboxes: any,
49
+ meta: any,
50
+ resource: any,
51
+ adminUser: any,
52
+ updateList: {
53
+ type: Function,
54
+ required: true
55
+ },
56
+ clearCheckboxes: {
57
+ type: Function
58
+ }
59
+ }>();
60
+
61
+ const confirmDialog = ref(null);
62
+ const records = ref<any[]>([]);
63
+ const images = ref<any[]>([]);
64
+ const tableHeaders = ref([]);
65
+ const tableColumns = ref([]);
66
+ const tableColumnsIndexes = ref([]);
67
+ const customFieldNames = ref([]);
68
+ const selected = ref<any[]>([]);
69
+ const isAiResponseReceived = ref([]);
70
+
71
+ const openDialog = async () => {
72
+ confirmDialog.value.open();
73
+ await getRecords();
74
+ await getImages();
75
+ tableHeaders.value = generateTableHeaders(props.meta.outputFields);
76
+ const result = generateTableColumns();
77
+ tableColumns.value = result.tableData;
78
+ tableColumnsIndexes.value = result.indexes;
79
+
80
+ customFieldNames.value = tableHeaders.value.slice(3).map(h => h.fieldName);
81
+ setSelected();
82
+ analyzeFields();
83
+ }
84
+
85
+ // watch(selected, (val) => {
86
+ // console.log('Selected changed:', val);
87
+ // }, { deep: true });
88
+
89
+ const closeDialog = () => {
90
+ confirmDialog.value.close();
91
+ isAiResponseReceived.value = [];
92
+ }
93
+
94
+ function formatLabel(str) {
95
+ return str
96
+ .split('_')
97
+ .map(word => word.charAt(0).toUpperCase() + word.slice(1))
98
+ .join(' ');
99
+ }
100
+
101
+ function generateTableHeaders(outputFields) {
102
+ const headers = [];
103
+
104
+ headers.push({ label: 'Checkboxes', fieldName: 'checkboxes' });
105
+ headers.push({ label: 'Field name', fieldName: 'label' });
106
+ headers.push({ label: 'Source Images', fieldName: 'images' });
107
+
108
+ if (outputFields.length > 0) {
109
+ const sampleField = outputFields[0];
110
+ for (const key in sampleField) {
111
+ headers.push({
112
+ label: formatLabel(key),
113
+ fieldName: key,
114
+ });
115
+ }
116
+ }
117
+ return headers;
118
+ }
119
+
120
+ function generateTableColumns() {
121
+ const fields = [];
122
+ const tableData = [];
123
+ const indexes = [];
124
+ for (const field of tableHeaders.value) {
125
+ fields.push( field.fieldName );
126
+ }
127
+ for (const [index, checkbox] of props.checkboxes.entries()) {
128
+ const record = records.value[index];
129
+ let reqFields: any = {};
130
+ for (const field of fields) {
131
+ reqFields[field] = record[field] || '';
132
+ }
133
+ reqFields.label = record._label;
134
+ reqFields.images = images.value[index];
135
+ reqFields.id = record.id;
136
+ indexes.push({
137
+ id: record.id,
138
+ label: record._label,
139
+ });
140
+ tableData.push(reqFields);
141
+ }
142
+ return { tableData, indexes };
143
+ }
144
+
145
+ function setSelected() {
146
+ selected.value = records.value.map(() => ({}));
147
+
148
+ records.value.forEach((record, index) => {
149
+ props.meta.outputFields.forEach((fieldObj, i) => {
150
+ for (const key in fieldObj) {
151
+ if(isInColumnEnum(key)){
152
+ const colEnum = props.meta.columnEnums.find(c => c.name === key);
153
+ const object = colEnum.enum.find(item => item.value === record[key]);
154
+ selected.value[index][key] = object ? record[key] : null;
155
+ } else {
156
+ selected.value[index][key] = record[key];
157
+ }
158
+ }
159
+ selected.value[index].isChecked = true;
160
+ selected.value[index].id = record.id;
161
+ isAiResponseReceived.value[index] = true;
162
+ });
163
+ });
164
+ }
165
+
166
+ function isInColumnEnum(key: string): boolean {
167
+ const colEnum = props.meta.columnEnums?.find(c => c.name === key);
168
+ if (!colEnum) {
169
+ return false;
170
+ }
171
+ return true;
172
+ }
173
+
174
+ async function getRecords() {
175
+ const res = await callAdminForthApi({
176
+ path: `/plugin/${props.meta.pluginInstanceId}/get_records`,
177
+ method: 'POST',
178
+ body: {
179
+ record: props.checkboxes,
180
+ },
181
+ });
182
+ records.value = res.records;
183
+ }
184
+
185
+ async function getImages() {
186
+ const res = await callAdminForthApi({
187
+ path: `/plugin/${props.meta.pluginInstanceId}/get_images`,
188
+ method: 'POST',
189
+ body: {
190
+ record: records.value,
191
+ },
192
+ });
193
+
194
+ images.value = res.images;
195
+ }
196
+
197
+ function prepareDataForSave() {
198
+ const checkedItems = selected.value
199
+ .filter(item => item.isChecked === true)
200
+ .map(item => {
201
+ const { isChecked, id, ...itemWithoutIsCheckedAndId } = item;
202
+ return itemWithoutIsCheckedAndId;
203
+ });
204
+ const checkedItemsIDs = selected.value
205
+ .filter(item => item.isChecked === true)
206
+ .map(item => item.id);
207
+ return [checkedItemsIDs, checkedItems];
208
+ }
209
+
210
+ async function analyzeFields() {
211
+ isAiResponseReceived.value = props.checkboxes.map(() => false);
212
+
213
+ const res = await callAdminForthApi({
214
+ path: `/plugin/${props.meta.pluginInstanceId}/analyze`,
215
+ method: 'POST',
216
+ body: {
217
+ selectedIds: props.checkboxes,
218
+ },
219
+ });
220
+
221
+ isAiResponseReceived.value = props.checkboxes.map(() => true);
222
+
223
+ selected.value.splice(
224
+ 0,
225
+ selected.value.length,
226
+ ...res.result.map((item, idx) => ({
227
+ ...item,
228
+ isChecked: true,
229
+ id: selected.value[idx]?.id,
230
+ }))
231
+ )
232
+ }
233
+
234
+ async function saveData() {
235
+ const [checkedItemsIDs, reqData] = prepareDataForSave();
236
+
237
+ const res = await callAdminForthApi({
238
+ path: `/plugin/${props.meta.pluginInstanceId}/update_fields`,
239
+ method: 'POST',
240
+ body: {
241
+ selectedIds: checkedItemsIDs,
242
+ fields: reqData,
243
+ },
244
+ });
245
+
246
+ if(res.ok) {
247
+ confirmDialog.value.close();
248
+ props.updateList();
249
+ props.clearCheckboxes();
250
+ } else {
251
+ console.error('Error saving data:', res);
252
+ }
253
+ }
254
+ </script>
@@ -0,0 +1,140 @@
1
+ <template>
2
+ <div>
3
+ <Table
4
+ :columns="tableHeaders"
5
+ :data="tableColumns"
6
+ :pageSize="8"
7
+ >
8
+ <!-- HEADER TEMPLATE -->
9
+ <template #header:checkboxes="{ item }">
10
+ MARK FOR SAVE
11
+ </template>
12
+ <!-- CHECKBOX CELL TEMPLATE -->
13
+ <template #cell:checkboxes="{ item }">
14
+ <div class="flex items-center justify-center">
15
+ <Checkbox
16
+ v-model="selected[tableColumnsIndexes.findIndex(el => el.label === item.label)].isChecked"
17
+ />
18
+ </div>
19
+ </template>
20
+ <!-- IMAGE CELL TEMPLATE -->
21
+ <template #cell:images="{item}">
22
+ <div class="flex flex-shrink-0 gap-2">
23
+ <div v-for="image in item.images" :key="image">
24
+ <div class="mt-2 flex items-center justify-center gap-2">
25
+ <img
26
+ :src="image"
27
+ class="w-20 h-20 object-cover rounded cursor-pointer border hover:border-blue-500 transition"
28
+ @click="zoomImage(image)"
29
+ />
30
+ </div>
31
+ <div
32
+ v-if="zoomedImage"
33
+ class="fixed inset-0 z-50 flex items-center justify-center bg-black/60"
34
+ @click.self="closeZoom"
35
+ >
36
+ <img
37
+ :src="zoomedImage"
38
+ ref="zoomedImg"
39
+ class="max-w-full max-h-full rounded-lg object-contain cursor-grab z-75"
40
+ />
41
+ </div>
42
+ </div>
43
+ </div>
44
+ </template>
45
+ <!-- CUSTOM FIELD TEMPLATES -->
46
+ <template v-for="n in customFieldNames" :key="n" #[`cell:${n}`]="{ item, column }">
47
+ <div v-if="isAiResponseReceived[tableColumnsIndexes.findIndex(el => el.id === item.id)]">
48
+ <div v-if="isInColumnEnum(n)">
49
+ <Select
50
+ :options="convertColumnEnumToSelectOptions(props.meta.columnEnums, n)"
51
+ v-model="selected[tableColumnsIndexes.findIndex(el => el.id === item.id)][n]"
52
+ >
53
+ </Select>
54
+ </div>
55
+ <div v-else-if="typeof selected[tableColumnsIndexes.findIndex(el => el.id === item.id)][n] === 'string' || typeof selected[tableColumnsIndexes.findIndex(el => el.id === item.id)][n] === 'object'">
56
+ <Textarea
57
+ class="w-full h-full"
58
+ type="text"
59
+ v-model="selected[tableColumnsIndexes.findIndex(el => el.id === item.id)][n]"
60
+ >
61
+ </Textarea>
62
+ </div>
63
+ <div v-else-if="typeof selected[tableColumnsIndexes.findIndex(el => el.id === item.id)][n] === 'boolean'">
64
+ <Toggle
65
+ v-model="selected[tableColumnsIndexes.findIndex(el => el.id === item.id)][n]"
66
+ >
67
+ </Toggle>
68
+ </div>
69
+ <div v-else>
70
+ <Input
71
+ type="number"
72
+ v-model="selected[tableColumnsIndexes.findIndex(el => el.id === item.id)][n]"
73
+ class="w-full "
74
+ :fullWidth="true"
75
+ />
76
+ </div>
77
+ </div>
78
+ <div v-else>
79
+ <Skeleton class="w-full h-6" />
80
+ </div>
81
+ </template>
82
+ </Table>
83
+ </div>
84
+ </template>
85
+
86
+ <script lang="ts" setup>
87
+ import { ref, nextTick, watch } from 'vue'
88
+ import mediumZoom from 'medium-zoom'
89
+ import { Select, Input, Textarea, Table, Checkbox, Skeleton, Toggle } from '@/afcl'
90
+
91
+ const props = defineProps<{
92
+ meta: any,
93
+ tableHeaders: any,
94
+ tableColumns: any,
95
+ customFieldNames: any,
96
+ tableColumnsIndexes: any,
97
+ selected: any,
98
+ isAiResponseReceived: boolean[]
99
+ }>();
100
+
101
+ const zoomedImage = ref(null)
102
+ const zoomedImg = ref(null)
103
+
104
+ function zoomImage(img) {
105
+ zoomedImage.value = img
106
+ }
107
+
108
+ function closeZoom() {
109
+ zoomedImage.value = null
110
+ }
111
+
112
+ watch(zoomedImage, async (val) => {
113
+ await nextTick()
114
+ if (val && zoomedImg.value) {
115
+ mediumZoom(zoomedImg.value, {
116
+ margin: 24,
117
+ background: 'rgba(0, 0, 0, 0.9)',
118
+ scrollOffset: 150
119
+ }).show()
120
+ }
121
+ })
122
+
123
+ function isInColumnEnum(key: string): boolean {
124
+ const colEnum = props.meta.columnEnums?.find(c => c.name === key);
125
+ if (!colEnum) {
126
+ return false;
127
+ }
128
+ return true;
129
+ }
130
+
131
+ function convertColumnEnumToSelectOptions(columnEnumArray: any[], key: string) {
132
+ const col = columnEnumArray.find(c => c.name === key);
133
+ if (!col) return [];
134
+ return col.enum.map(item => ({
135
+ label: item.label,
136
+ value: item.value
137
+ }));
138
+ }
139
+
140
+ </script>
@@ -0,0 +1,19 @@
1
+ {
2
+ "compilerOptions": {
3
+ "baseUrl": ".", // This should point to your project root
4
+ "paths": {
5
+ "@/*": [
6
+ // "node_modules/adminforth/dist/spa/src/*"
7
+ "../../../spa/src/*"
8
+ ],
9
+ "*": [
10
+ // "node_modules/adminforth/dist/spa/node_modules/*"
11
+ "../../../spa/node_modules/*"
12
+ ],
13
+ "@@/*": [
14
+ // "node_modules/adminforth/dist/spa/src/*"
15
+ "."
16
+ ]
17
+ }
18
+ }
19
+ }