plugin-document-understanding 1.1.3 → 1.1.4
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/README.md +21 -8
- package/client-v2.d.ts +2 -0
- package/client-v2.js +1 -0
- package/dist/client/index.js +1 -1
- package/dist/client-v2/794.9b984a25b2fc7c14.js +10 -0
- package/dist/client-v2/index.js +10 -0
- package/dist/externalVersion.js +7 -6
- package/dist/node_modules/form-data/License +19 -0
- package/dist/node_modules/form-data/index.d.ts +62 -0
- package/dist/node_modules/form-data/lib/browser.js +4 -0
- package/dist/node_modules/form-data/lib/form_data.js +14 -0
- package/dist/node_modules/form-data/lib/populate.js +10 -0
- package/dist/node_modules/form-data/package.json +1 -0
- package/dist/node_modules/mime-types/LICENSE +23 -0
- package/dist/node_modules/mime-types/index.js +14 -0
- package/dist/node_modules/mime-types/package.json +1 -0
- package/dist/server/actions.js +7 -6
- package/dist/server/collections/endpoints.js +1 -1
- package/dist/server/plugin.js +7 -3
- package/dist/server/services/AsyncJobManager.js +14 -5
- package/dist/server/services/DocumentUnderstandingService.js +53 -23
- package/dist/server/services/PipelineExecutor.js +81 -94
- package/package.json +49 -16
- package/src/client/index.tsx +9 -0
- package/src/client-v2/client.d.ts +249 -0
- package/src/client-v2/components/EndpointsTab.tsx +458 -0
- package/src/client-v2/components/JobsTab.tsx +259 -0
- package/src/client-v2/components/PipelinesTab.tsx +872 -0
- package/src/client-v2/components/PluginSettings.tsx +48 -0
- package/src/client-v2/components/ServiceConfigTab.tsx +122 -0
- package/src/client-v2/locale.ts +21 -0
- package/{dist/client/models/index.d.ts → src/client-v2/models/index.ts} +3 -2
- package/src/client-v2/plugin.tsx +21 -0
- package/src/locale/en-US.json +121 -0
- package/src/locale/vi-VN.json +121 -0
- package/src/locale/zh-CN.json +1 -0
- package/src/server/__tests__/actions.test.ts +98 -0
- package/src/server/__tests__/pipeline-executor.test.ts +33 -0
- package/src/server/__tests__/smoke.test.ts +55 -0
- package/src/server/actions.ts +176 -0
- package/src/server/collections/.gitkeep +0 -0
- package/src/server/collections/config.ts +18 -0
- package/src/server/collections/endpoints.ts +28 -0
- package/src/server/collections/jobs.ts +29 -0
- package/src/server/collections/pipeline-steps.ts +27 -0
- package/src/server/collections/pipelines.ts +19 -0
- package/src/server/plugin.ts +108 -0
- package/src/server/services/AsyncJobManager.ts +172 -0
- package/src/server/services/DocumentUnderstandingService.ts +264 -0
- package/src/server/services/ExternalApiClient.ts +143 -0
- package/src/server/services/PipelineExecutor.ts +502 -0
- package/src/server/tools/document-understanding-tool.ts +181 -0
- package/src/server/types.ts +73 -0
- package/dist/client/components/EndpointsTab.d.ts +0 -2
- package/dist/client/components/JobsTab.d.ts +0 -2
- package/dist/client/components/PipelinesTab.d.ts +0 -2
- package/dist/client/components/PluginSettings.d.ts +0 -2
- package/dist/client/components/ServiceConfigTab.d.ts +0 -2
- package/dist/client/locale.d.ts +0 -10
- package/dist/client/plugin.d.ts +0 -6
- package/dist/server/actions.d.ts +0 -17
- package/dist/server/collections/config.d.ts +0 -3
- package/dist/server/collections/endpoints.d.ts +0 -3
- package/dist/server/collections/jobs.d.ts +0 -3
- package/dist/server/collections/pipeline-steps.d.ts +0 -3
- package/dist/server/collections/pipelines.d.ts +0 -3
- package/dist/server/plugin.d.ts +0 -15
- package/dist/server/services/AsyncJobManager.d.ts +0 -27
- package/dist/server/services/DocumentUnderstandingService.d.ts +0 -35
- package/dist/server/services/ExternalApiClient.d.ts +0 -28
- package/dist/server/services/PipelineExecutor.d.ts +0 -24
- package/dist/server/tools/document-understanding-tool.d.ts +0 -8
- package/dist/server/types.d.ts +0 -69
- /package/{dist/client/index.d.ts → src/client-v2/index.tsx} +0 -0
- /package/{dist/index.d.ts → src/index.ts} +0 -0
- /package/{dist/server/index.d.ts → src/server/index.ts} +0 -0
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
// CSS modules
|
|
11
|
+
type CSSModuleClasses = { readonly [key: string]: string };
|
|
12
|
+
|
|
13
|
+
declare module '*.module.css' {
|
|
14
|
+
const classes: CSSModuleClasses;
|
|
15
|
+
export default classes;
|
|
16
|
+
}
|
|
17
|
+
declare module '*.module.scss' {
|
|
18
|
+
const classes: CSSModuleClasses;
|
|
19
|
+
export default classes;
|
|
20
|
+
}
|
|
21
|
+
declare module '*.module.sass' {
|
|
22
|
+
const classes: CSSModuleClasses;
|
|
23
|
+
export default classes;
|
|
24
|
+
}
|
|
25
|
+
declare module '*.module.less' {
|
|
26
|
+
const classes: CSSModuleClasses;
|
|
27
|
+
export default classes;
|
|
28
|
+
}
|
|
29
|
+
declare module '*.module.styl' {
|
|
30
|
+
const classes: CSSModuleClasses;
|
|
31
|
+
export default classes;
|
|
32
|
+
}
|
|
33
|
+
declare module '*.module.stylus' {
|
|
34
|
+
const classes: CSSModuleClasses;
|
|
35
|
+
export default classes;
|
|
36
|
+
}
|
|
37
|
+
declare module '*.module.pcss' {
|
|
38
|
+
const classes: CSSModuleClasses;
|
|
39
|
+
export default classes;
|
|
40
|
+
}
|
|
41
|
+
declare module '*.module.sss' {
|
|
42
|
+
const classes: CSSModuleClasses;
|
|
43
|
+
export default classes;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// CSS
|
|
47
|
+
declare module '*.css' { }
|
|
48
|
+
declare module '*.scss' { }
|
|
49
|
+
declare module '*.sass' { }
|
|
50
|
+
declare module '*.less' { }
|
|
51
|
+
declare module '*.styl' { }
|
|
52
|
+
declare module '*.stylus' { }
|
|
53
|
+
declare module '*.pcss' { }
|
|
54
|
+
declare module '*.sss' { }
|
|
55
|
+
|
|
56
|
+
// Built-in asset types
|
|
57
|
+
// see `src/node/constants.ts`
|
|
58
|
+
|
|
59
|
+
// images
|
|
60
|
+
declare module '*.apng' {
|
|
61
|
+
const src: string;
|
|
62
|
+
export default src;
|
|
63
|
+
}
|
|
64
|
+
declare module '*.png' {
|
|
65
|
+
const src: string;
|
|
66
|
+
export default src;
|
|
67
|
+
}
|
|
68
|
+
declare module '*.jpg' {
|
|
69
|
+
const src: string;
|
|
70
|
+
export default src;
|
|
71
|
+
}
|
|
72
|
+
declare module '*.jpeg' {
|
|
73
|
+
const src: string;
|
|
74
|
+
export default src;
|
|
75
|
+
}
|
|
76
|
+
declare module '*.jfif' {
|
|
77
|
+
const src: string;
|
|
78
|
+
export default src;
|
|
79
|
+
}
|
|
80
|
+
declare module '*.pjpeg' {
|
|
81
|
+
const src: string;
|
|
82
|
+
export default src;
|
|
83
|
+
}
|
|
84
|
+
declare module '*.pjp' {
|
|
85
|
+
const src: string;
|
|
86
|
+
export default src;
|
|
87
|
+
}
|
|
88
|
+
declare module '*.gif' {
|
|
89
|
+
const src: string;
|
|
90
|
+
export default src;
|
|
91
|
+
}
|
|
92
|
+
declare module '*.svg' {
|
|
93
|
+
const src: string;
|
|
94
|
+
export default src;
|
|
95
|
+
}
|
|
96
|
+
declare module '*.ico' {
|
|
97
|
+
const src: string;
|
|
98
|
+
export default src;
|
|
99
|
+
}
|
|
100
|
+
declare module '*.webp' {
|
|
101
|
+
const src: string;
|
|
102
|
+
export default src;
|
|
103
|
+
}
|
|
104
|
+
declare module '*.avif' {
|
|
105
|
+
const src: string;
|
|
106
|
+
export default src;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// media
|
|
110
|
+
declare module '*.mp4' {
|
|
111
|
+
const src: string;
|
|
112
|
+
export default src;
|
|
113
|
+
}
|
|
114
|
+
declare module '*.webm' {
|
|
115
|
+
const src: string;
|
|
116
|
+
export default src;
|
|
117
|
+
}
|
|
118
|
+
declare module '*.ogg' {
|
|
119
|
+
const src: string;
|
|
120
|
+
export default src;
|
|
121
|
+
}
|
|
122
|
+
declare module '*.mp3' {
|
|
123
|
+
const src: string;
|
|
124
|
+
export default src;
|
|
125
|
+
}
|
|
126
|
+
declare module '*.wav' {
|
|
127
|
+
const src: string;
|
|
128
|
+
export default src;
|
|
129
|
+
}
|
|
130
|
+
declare module '*.flac' {
|
|
131
|
+
const src: string;
|
|
132
|
+
export default src;
|
|
133
|
+
}
|
|
134
|
+
declare module '*.aac' {
|
|
135
|
+
const src: string;
|
|
136
|
+
export default src;
|
|
137
|
+
}
|
|
138
|
+
declare module '*.opus' {
|
|
139
|
+
const src: string;
|
|
140
|
+
export default src;
|
|
141
|
+
}
|
|
142
|
+
declare module '*.mov' {
|
|
143
|
+
const src: string;
|
|
144
|
+
export default src;
|
|
145
|
+
}
|
|
146
|
+
declare module '*.m4a' {
|
|
147
|
+
const src: string;
|
|
148
|
+
export default src;
|
|
149
|
+
}
|
|
150
|
+
declare module '*.vtt' {
|
|
151
|
+
const src: string;
|
|
152
|
+
export default src;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// fonts
|
|
156
|
+
declare module '*.woff' {
|
|
157
|
+
const src: string;
|
|
158
|
+
export default src;
|
|
159
|
+
}
|
|
160
|
+
declare module '*.woff2' {
|
|
161
|
+
const src: string;
|
|
162
|
+
export default src;
|
|
163
|
+
}
|
|
164
|
+
declare module '*.eot' {
|
|
165
|
+
const src: string;
|
|
166
|
+
export default src;
|
|
167
|
+
}
|
|
168
|
+
declare module '*.ttf' {
|
|
169
|
+
const src: string;
|
|
170
|
+
export default src;
|
|
171
|
+
}
|
|
172
|
+
declare module '*.otf' {
|
|
173
|
+
const src: string;
|
|
174
|
+
export default src;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// other
|
|
178
|
+
declare module '*.webmanifest' {
|
|
179
|
+
const src: string;
|
|
180
|
+
export default src;
|
|
181
|
+
}
|
|
182
|
+
declare module '*.pdf' {
|
|
183
|
+
const src: string;
|
|
184
|
+
export default src;
|
|
185
|
+
}
|
|
186
|
+
declare module '*.txt' {
|
|
187
|
+
const src: string;
|
|
188
|
+
export default src;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// wasm?init
|
|
192
|
+
declare module '*.wasm?init' {
|
|
193
|
+
const initWasm: (options?: WebAssembly.Imports) => Promise<WebAssembly.Instance>;
|
|
194
|
+
export default initWasm;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// web worker
|
|
198
|
+
declare module '*?worker' {
|
|
199
|
+
const workerConstructor: {
|
|
200
|
+
new(options?: { name?: string }): Worker;
|
|
201
|
+
};
|
|
202
|
+
export default workerConstructor;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
declare module '*?worker&inline' {
|
|
206
|
+
const workerConstructor: {
|
|
207
|
+
new(options?: { name?: string }): Worker;
|
|
208
|
+
};
|
|
209
|
+
export default workerConstructor;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
declare module '*?worker&url' {
|
|
213
|
+
const src: string;
|
|
214
|
+
export default src;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
declare module '*?sharedworker' {
|
|
218
|
+
const sharedWorkerConstructor: {
|
|
219
|
+
new(options?: { name?: string }): SharedWorker;
|
|
220
|
+
};
|
|
221
|
+
export default sharedWorkerConstructor;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
declare module '*?sharedworker&inline' {
|
|
225
|
+
const sharedWorkerConstructor: {
|
|
226
|
+
new(options?: { name?: string }): SharedWorker;
|
|
227
|
+
};
|
|
228
|
+
export default sharedWorkerConstructor;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
declare module '*?sharedworker&url' {
|
|
232
|
+
const src: string;
|
|
233
|
+
export default src;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
declare module '*?raw' {
|
|
237
|
+
const src: string;
|
|
238
|
+
export default src;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
declare module '*?url' {
|
|
242
|
+
const src: string;
|
|
243
|
+
export default src;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
declare module '*?inline' {
|
|
247
|
+
const src: string;
|
|
248
|
+
export default src;
|
|
249
|
+
}
|
|
@@ -0,0 +1,458 @@
|
|
|
1
|
+
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Table,
|
|
4
|
+
Button,
|
|
5
|
+
Modal,
|
|
6
|
+
Form,
|
|
7
|
+
Input,
|
|
8
|
+
Select,
|
|
9
|
+
Switch,
|
|
10
|
+
message,
|
|
11
|
+
InputNumber,
|
|
12
|
+
Tabs,
|
|
13
|
+
Space,
|
|
14
|
+
Tag,
|
|
15
|
+
Popconfirm,
|
|
16
|
+
} from 'antd';
|
|
17
|
+
import { PlusOutlined, DeleteOutlined, EditOutlined } from '@ant-design/icons';
|
|
18
|
+
import { useApp } from '@nocobase/client-v2';
|
|
19
|
+
|
|
20
|
+
const { TextArea } = Input;
|
|
21
|
+
|
|
22
|
+
const KeyValueEditor: React.FC<{ value?: Record<string, string>; onChange?: (v: Record<string, string>) => void }> = ({
|
|
23
|
+
value = {},
|
|
24
|
+
onChange,
|
|
25
|
+
}) => {
|
|
26
|
+
const [rows, setRows] = useState<Array<{ id: string; key: string; value: string }>>([]);
|
|
27
|
+
const localChangeRef = useRef(false);
|
|
28
|
+
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
if (localChangeRef.current) {
|
|
31
|
+
localChangeRef.current = false;
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
setRows(
|
|
35
|
+
Object.entries(value || {}).map(([key, rowValue], index) => ({
|
|
36
|
+
id: `${key}_${index}`,
|
|
37
|
+
key,
|
|
38
|
+
value: String(rowValue ?? ''),
|
|
39
|
+
})),
|
|
40
|
+
);
|
|
41
|
+
}, [value]);
|
|
42
|
+
|
|
43
|
+
const emit = (nextRows: Array<{ id: string; key: string; value: string }>) => {
|
|
44
|
+
setRows(nextRows);
|
|
45
|
+
const nextValue = nextRows.reduce<Record<string, string>>((acc, row) => {
|
|
46
|
+
const key = row.key.trim();
|
|
47
|
+
if (key) {
|
|
48
|
+
acc[key] = row.value;
|
|
49
|
+
}
|
|
50
|
+
return acc;
|
|
51
|
+
}, {});
|
|
52
|
+
localChangeRef.current = true;
|
|
53
|
+
onChange?.(nextValue);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const update = (idx: number, key: string, val: string) => {
|
|
57
|
+
const nextRows = [...rows];
|
|
58
|
+
nextRows[idx] = { ...nextRows[idx], key, value: val };
|
|
59
|
+
emit(nextRows);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const add = () => setRows([...rows, { id: `new_${Date.now()}_${Math.random()}`, key: '', value: '' }]);
|
|
63
|
+
|
|
64
|
+
const remove = (idx: number) => {
|
|
65
|
+
const nextRows = rows.filter((_, rowIndex) => rowIndex !== idx);
|
|
66
|
+
emit(nextRows);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<div>
|
|
71
|
+
{rows.map((row, i) => (
|
|
72
|
+
<Space key={row.id} style={{ display: 'flex', marginBottom: 4 }}>
|
|
73
|
+
<Input
|
|
74
|
+
placeholder="Header name"
|
|
75
|
+
value={row.key}
|
|
76
|
+
onChange={(e) => update(i, e.target.value, row.value)}
|
|
77
|
+
style={{ width: 180 }}
|
|
78
|
+
/>
|
|
79
|
+
<Input
|
|
80
|
+
placeholder="Value"
|
|
81
|
+
value={row.value}
|
|
82
|
+
onChange={(e) => update(i, row.key, e.target.value)}
|
|
83
|
+
style={{ width: 220 }}
|
|
84
|
+
/>
|
|
85
|
+
<Button size="small" danger icon={<DeleteOutlined />} onClick={() => remove(i)} />
|
|
86
|
+
</Space>
|
|
87
|
+
))}
|
|
88
|
+
<Button size="small" type="dashed" icon={<PlusOutlined />} onClick={add}>
|
|
89
|
+
Add Header
|
|
90
|
+
</Button>
|
|
91
|
+
</div>
|
|
92
|
+
);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const JsonEditor: React.FC<{ value?: any; onChange?: (v: any) => void; placeholder?: string }> = ({
|
|
96
|
+
value,
|
|
97
|
+
onChange,
|
|
98
|
+
placeholder,
|
|
99
|
+
}) => {
|
|
100
|
+
const [text, setText] = useState('');
|
|
101
|
+
const [error, setError] = useState('');
|
|
102
|
+
|
|
103
|
+
useEffect(() => {
|
|
104
|
+
if (!value) {
|
|
105
|
+
setText('');
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
try {
|
|
109
|
+
setText(typeof value === 'string' ? JSON.stringify(JSON.parse(value), null, 2) : JSON.stringify(value, null, 2));
|
|
110
|
+
} catch (e) {
|
|
111
|
+
setText(typeof value === 'string' ? value : '');
|
|
112
|
+
}
|
|
113
|
+
}, [value]);
|
|
114
|
+
|
|
115
|
+
const handleBlur = () => {
|
|
116
|
+
if (!text.trim()) {
|
|
117
|
+
setError('');
|
|
118
|
+
onChange?.(null);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
try {
|
|
122
|
+
const parsed = JSON.parse(text);
|
|
123
|
+
setError('');
|
|
124
|
+
onChange?.(parsed);
|
|
125
|
+
} catch {
|
|
126
|
+
setError('Invalid JSON');
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
return (
|
|
131
|
+
<div>
|
|
132
|
+
<TextArea
|
|
133
|
+
rows={6}
|
|
134
|
+
value={text}
|
|
135
|
+
onChange={(e) => setText(e.target.value)}
|
|
136
|
+
onBlur={handleBlur}
|
|
137
|
+
placeholder={placeholder || '{}'}
|
|
138
|
+
style={{ fontFamily: 'monospace', fontSize: 12 }}
|
|
139
|
+
/>
|
|
140
|
+
{error && <div style={{ color: '#ff4d4f', fontSize: 12 }}>{error}</div>}
|
|
141
|
+
</div>
|
|
142
|
+
);
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
export const EndpointsTab = () => {
|
|
146
|
+
const app = useApp();
|
|
147
|
+
const api = app.apiClient;
|
|
148
|
+
const [data, setData] = useState<any[]>([]);
|
|
149
|
+
const [loading, setLoading] = useState(false);
|
|
150
|
+
const [visible, setVisible] = useState(false);
|
|
151
|
+
const [form] = Form.useForm();
|
|
152
|
+
const [editingId, setEditingId] = useState<number | null>(null);
|
|
153
|
+
|
|
154
|
+
const fetchEndpoints = useCallback(async () => {
|
|
155
|
+
setLoading(true);
|
|
156
|
+
try {
|
|
157
|
+
const res = await api.request({ url: 'docUnderstanding:listEndpoints' });
|
|
158
|
+
setData(res.data?.data || []);
|
|
159
|
+
} finally {
|
|
160
|
+
setLoading(false);
|
|
161
|
+
}
|
|
162
|
+
}, [api]);
|
|
163
|
+
|
|
164
|
+
useEffect(() => {
|
|
165
|
+
fetchEndpoints();
|
|
166
|
+
}, [fetchEndpoints]);
|
|
167
|
+
|
|
168
|
+
const openEdit = (record: any) => {
|
|
169
|
+
setEditingId(record.id);
|
|
170
|
+
form.setFieldsValue(record);
|
|
171
|
+
setVisible(true);
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
const openAdd = () => {
|
|
175
|
+
setEditingId(null);
|
|
176
|
+
form.resetFields();
|
|
177
|
+
setVisible(true);
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
const handleDelete = async (id: number) => {
|
|
181
|
+
await api.request({
|
|
182
|
+
url: 'docUnderstanding:deleteEndpoint',
|
|
183
|
+
method: 'POST',
|
|
184
|
+
params: { filterByTk: id },
|
|
185
|
+
});
|
|
186
|
+
message.success('Deleted');
|
|
187
|
+
fetchEndpoints();
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
const handleSave = async () => {
|
|
191
|
+
try {
|
|
192
|
+
const values = await form.validateFields();
|
|
193
|
+
values.customHeaders = sanitizeHeaders(values.customHeaders);
|
|
194
|
+
if (editingId) {
|
|
195
|
+
await api.request({
|
|
196
|
+
url: 'docUnderstanding:updateEndpoint',
|
|
197
|
+
method: 'POST',
|
|
198
|
+
params: { filterByTk: editingId },
|
|
199
|
+
data: values,
|
|
200
|
+
});
|
|
201
|
+
} else {
|
|
202
|
+
await api.request({
|
|
203
|
+
url: 'docUnderstanding:createEndpoint',
|
|
204
|
+
method: 'POST',
|
|
205
|
+
data: values,
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
message.success('Saved');
|
|
209
|
+
setVisible(false);
|
|
210
|
+
fetchEndpoints();
|
|
211
|
+
} catch {
|
|
212
|
+
// validation error
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
const sanitizeHeaders = (headers?: Record<string, string>) => {
|
|
217
|
+
return Object.entries(headers || {}).reduce<Record<string, string>>((acc, [key, value]) => {
|
|
218
|
+
const headerName = key.trim();
|
|
219
|
+
if (headerName) {
|
|
220
|
+
acc[headerName] = value;
|
|
221
|
+
}
|
|
222
|
+
return acc;
|
|
223
|
+
}, {});
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
const columns = [
|
|
227
|
+
{ title: 'Name', dataIndex: 'name', width: 150 },
|
|
228
|
+
{ title: 'Subpath', dataIndex: 'subpath', width: 200 },
|
|
229
|
+
{
|
|
230
|
+
title: 'Method',
|
|
231
|
+
dataIndex: 'method',
|
|
232
|
+
width: 80,
|
|
233
|
+
render: (v: string) => <Tag>{v}</Tag>,
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
title: 'Execution',
|
|
237
|
+
dataIndex: 'executionMode',
|
|
238
|
+
width: 100,
|
|
239
|
+
render: (v: string) => {
|
|
240
|
+
const colors: Record<string, string> = { sync: 'green', polling: 'blue', webhook: 'purple' };
|
|
241
|
+
return <Tag color={colors[v]}>{v}</Tag>;
|
|
242
|
+
},
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
title: 'File',
|
|
246
|
+
dataIndex: 'fileInputMode',
|
|
247
|
+
width: 90,
|
|
248
|
+
render: (v: string) => (v === 'none' ? '-' : v),
|
|
249
|
+
},
|
|
250
|
+
{
|
|
251
|
+
title: 'Enabled',
|
|
252
|
+
dataIndex: 'enabled',
|
|
253
|
+
width: 70,
|
|
254
|
+
render: (v: boolean) => (v ? <Tag color="success">Yes</Tag> : <Tag>No</Tag>),
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
title: 'Action',
|
|
258
|
+
width: 120,
|
|
259
|
+
render: (_: any, record: any) => (
|
|
260
|
+
<Space>
|
|
261
|
+
<Button type="link" size="small" icon={<EditOutlined />} onClick={() => openEdit(record)}>
|
|
262
|
+
Edit
|
|
263
|
+
</Button>
|
|
264
|
+
<Popconfirm title="Delete this endpoint?" onConfirm={() => handleDelete(record.id)}>
|
|
265
|
+
<Button type="link" size="small" danger icon={<DeleteOutlined />}>
|
|
266
|
+
Delete
|
|
267
|
+
</Button>
|
|
268
|
+
</Popconfirm>
|
|
269
|
+
</Space>
|
|
270
|
+
),
|
|
271
|
+
},
|
|
272
|
+
];
|
|
273
|
+
|
|
274
|
+
return (
|
|
275
|
+
<div>
|
|
276
|
+
<div style={{ marginBottom: 16 }}>
|
|
277
|
+
<Button type="primary" icon={<PlusOutlined />} onClick={openAdd}>
|
|
278
|
+
Add Endpoint
|
|
279
|
+
</Button>
|
|
280
|
+
</div>
|
|
281
|
+
<Table rowKey="id" columns={columns} dataSource={data} loading={loading} size="small" />
|
|
282
|
+
|
|
283
|
+
<Modal
|
|
284
|
+
title={editingId ? 'Edit Endpoint' : 'Add Endpoint'}
|
|
285
|
+
open={visible}
|
|
286
|
+
onOk={handleSave}
|
|
287
|
+
onCancel={() => setVisible(false)}
|
|
288
|
+
width={680}
|
|
289
|
+
destroyOnClose
|
|
290
|
+
>
|
|
291
|
+
<Form form={form} layout="vertical" preserve={false}>
|
|
292
|
+
<Tabs
|
|
293
|
+
size="small"
|
|
294
|
+
items={[
|
|
295
|
+
{
|
|
296
|
+
key: 'basic',
|
|
297
|
+
label: 'Basic',
|
|
298
|
+
children: (
|
|
299
|
+
<>
|
|
300
|
+
<Form.Item name="name" label="Unique Name" rules={[{ required: true }]}>
|
|
301
|
+
<Input placeholder="ocr, classify, extract..." />
|
|
302
|
+
</Form.Item>
|
|
303
|
+
<Form.Item name="subpath" label="Subpath" rules={[{ required: true }]}>
|
|
304
|
+
<Input placeholder="/api/v1/ocr" />
|
|
305
|
+
</Form.Item>
|
|
306
|
+
<Form.Item name="description" label="Description">
|
|
307
|
+
<TextArea rows={2} placeholder="What this endpoint does" />
|
|
308
|
+
</Form.Item>
|
|
309
|
+
<Space size="large">
|
|
310
|
+
<Form.Item name="method" label="HTTP Method" initialValue="POST">
|
|
311
|
+
<Select style={{ width: 120 }}>
|
|
312
|
+
<Select.Option value="GET">GET</Select.Option>
|
|
313
|
+
<Select.Option value="POST">POST</Select.Option>
|
|
314
|
+
<Select.Option value="PUT">PUT</Select.Option>
|
|
315
|
+
</Select>
|
|
316
|
+
</Form.Item>
|
|
317
|
+
<Form.Item name="enabled" label="Enabled" valuePropName="checked" initialValue={true}>
|
|
318
|
+
<Switch />
|
|
319
|
+
</Form.Item>
|
|
320
|
+
</Space>
|
|
321
|
+
</>
|
|
322
|
+
),
|
|
323
|
+
},
|
|
324
|
+
{
|
|
325
|
+
key: 'file',
|
|
326
|
+
label: 'File Input',
|
|
327
|
+
children: (
|
|
328
|
+
<>
|
|
329
|
+
<Form.Item name="fileInputMode" label="File Input Mode" initialValue="none">
|
|
330
|
+
<Select style={{ width: 200 }}>
|
|
331
|
+
<Select.Option value="none">None</Select.Option>
|
|
332
|
+
<Select.Option value="multipart">Multipart Upload</Select.Option>
|
|
333
|
+
<Select.Option value="base64">Base64 in JSON</Select.Option>
|
|
334
|
+
</Select>
|
|
335
|
+
</Form.Item>
|
|
336
|
+
<Form.Item noStyle dependencies={['fileInputMode']}>
|
|
337
|
+
{() =>
|
|
338
|
+
form.getFieldValue('fileInputMode') !== 'none' ? (
|
|
339
|
+
<>
|
|
340
|
+
<Form.Item name="fileFieldName" label="File Field Name" initialValue="file">
|
|
341
|
+
<Input placeholder="file" style={{ width: 200 }} />
|
|
342
|
+
</Form.Item>
|
|
343
|
+
<Form.Item name="maxFiles" label="Max Files" initialValue={1}>
|
|
344
|
+
<InputNumber min={1} max={20} style={{ width: 120 }} />
|
|
345
|
+
</Form.Item>
|
|
346
|
+
</>
|
|
347
|
+
) : null
|
|
348
|
+
}
|
|
349
|
+
</Form.Item>
|
|
350
|
+
</>
|
|
351
|
+
),
|
|
352
|
+
},
|
|
353
|
+
{
|
|
354
|
+
key: 'async',
|
|
355
|
+
label: 'Async Config',
|
|
356
|
+
children: (
|
|
357
|
+
<>
|
|
358
|
+
<Form.Item name="executionMode" label="Execution Mode" initialValue="sync">
|
|
359
|
+
<Select style={{ width: 200 }}>
|
|
360
|
+
<Select.Option value="sync">Synchronous</Select.Option>
|
|
361
|
+
<Select.Option value="polling">Polling</Select.Option>
|
|
362
|
+
<Select.Option value="webhook">Webhook</Select.Option>
|
|
363
|
+
</Select>
|
|
364
|
+
</Form.Item>
|
|
365
|
+
<Form.Item noStyle dependencies={['executionMode']}>
|
|
366
|
+
{() => {
|
|
367
|
+
const mode = form.getFieldValue('executionMode');
|
|
368
|
+
if (mode === 'sync') return null;
|
|
369
|
+
return (
|
|
370
|
+
<>
|
|
371
|
+
<Form.Item
|
|
372
|
+
name="pollTaskIdField"
|
|
373
|
+
label="Task ID Field"
|
|
374
|
+
help="Field in response containing the async task ID"
|
|
375
|
+
initialValue="task_id"
|
|
376
|
+
>
|
|
377
|
+
<Input placeholder="task_id" />
|
|
378
|
+
</Form.Item>
|
|
379
|
+
|
|
380
|
+
{mode === 'polling' && (
|
|
381
|
+
<>
|
|
382
|
+
<Form.Item
|
|
383
|
+
name="pollResultSubpath"
|
|
384
|
+
label="Poll Result Subpath"
|
|
385
|
+
help="URL to poll for result. Use {taskId} as placeholder."
|
|
386
|
+
rules={[{ required: true, message: 'Required for polling mode' }]}
|
|
387
|
+
>
|
|
388
|
+
<Input placeholder="/api/v1/tasks/{taskId}/result" />
|
|
389
|
+
</Form.Item>
|
|
390
|
+
<Form.Item
|
|
391
|
+
name="pollResultField"
|
|
392
|
+
label="Result Field"
|
|
393
|
+
help="Field in poll response containing the actual result"
|
|
394
|
+
>
|
|
395
|
+
<Input placeholder="result" />
|
|
396
|
+
</Form.Item>
|
|
397
|
+
<Form.Item
|
|
398
|
+
name="pollStatusField"
|
|
399
|
+
label="Status Field (optional)"
|
|
400
|
+
help="Field to check completion status. If empty, any non-null result = complete."
|
|
401
|
+
>
|
|
402
|
+
<Input placeholder="status" />
|
|
403
|
+
</Form.Item>
|
|
404
|
+
<Form.Item
|
|
405
|
+
name="pollCompletedValue"
|
|
406
|
+
label="Completed Value"
|
|
407
|
+
help="Value of status field that means 'done'"
|
|
408
|
+
initialValue="completed"
|
|
409
|
+
>
|
|
410
|
+
<Input placeholder="completed" />
|
|
411
|
+
</Form.Item>
|
|
412
|
+
<Space size="large">
|
|
413
|
+
<Form.Item name="pollInterval" label="Poll Interval (ms)" help="Override default">
|
|
414
|
+
<InputNumber min={1000} step={1000} placeholder="5000" style={{ width: 150 }} />
|
|
415
|
+
</Form.Item>
|
|
416
|
+
<Form.Item name="pollTimeout" label="Poll Timeout (ms)" help="Override default">
|
|
417
|
+
<InputNumber min={5000} step={5000} placeholder="300000" style={{ width: 150 }} />
|
|
418
|
+
</Form.Item>
|
|
419
|
+
</Space>
|
|
420
|
+
</>
|
|
421
|
+
)}
|
|
422
|
+
</>
|
|
423
|
+
);
|
|
424
|
+
}}
|
|
425
|
+
</Form.Item>
|
|
426
|
+
</>
|
|
427
|
+
),
|
|
428
|
+
},
|
|
429
|
+
{
|
|
430
|
+
key: 'schema',
|
|
431
|
+
label: 'Schema',
|
|
432
|
+
children: (
|
|
433
|
+
<>
|
|
434
|
+
<Form.Item name="requestBodySchema" label="Request Body Schema (JSON Schema)">
|
|
435
|
+
<JsonEditor placeholder='{ "type": "object", "properties": { ... } }' />
|
|
436
|
+
</Form.Item>
|
|
437
|
+
<Form.Item name="responseSchema" label="Response Schema (JSON Schema)">
|
|
438
|
+
<JsonEditor placeholder='{ "type": "object", "properties": { ... } }' />
|
|
439
|
+
</Form.Item>
|
|
440
|
+
</>
|
|
441
|
+
),
|
|
442
|
+
},
|
|
443
|
+
{
|
|
444
|
+
key: 'headers',
|
|
445
|
+
label: 'Custom Headers',
|
|
446
|
+
children: (
|
|
447
|
+
<Form.Item name="customHeaders" label="Additional Headers">
|
|
448
|
+
<KeyValueEditor />
|
|
449
|
+
</Form.Item>
|
|
450
|
+
),
|
|
451
|
+
},
|
|
452
|
+
]}
|
|
453
|
+
/>
|
|
454
|
+
</Form>
|
|
455
|
+
</Modal>
|
|
456
|
+
</div>
|
|
457
|
+
);
|
|
458
|
+
};
|