plugin-document-understanding 1.1.2 → 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.
Files changed (76) hide show
  1. package/README.md +21 -8
  2. package/client-v2.d.ts +2 -0
  3. package/client-v2.js +1 -0
  4. package/dist/client/index.js +1 -1
  5. package/dist/client-v2/794.9b984a25b2fc7c14.js +10 -0
  6. package/dist/client-v2/index.js +10 -0
  7. package/dist/externalVersion.js +7 -6
  8. package/dist/node_modules/form-data/License +19 -0
  9. package/dist/node_modules/form-data/index.d.ts +62 -0
  10. package/dist/node_modules/form-data/lib/browser.js +4 -0
  11. package/dist/node_modules/form-data/lib/form_data.js +14 -0
  12. package/dist/node_modules/form-data/lib/populate.js +10 -0
  13. package/dist/node_modules/form-data/package.json +1 -0
  14. package/dist/node_modules/mime-types/LICENSE +23 -0
  15. package/dist/node_modules/mime-types/index.js +14 -0
  16. package/dist/node_modules/mime-types/package.json +1 -0
  17. package/dist/server/actions.js +7 -6
  18. package/dist/server/collections/endpoints.js +1 -1
  19. package/dist/server/plugin.js +7 -3
  20. package/dist/server/services/AsyncJobManager.js +14 -5
  21. package/dist/server/services/DocumentUnderstandingService.js +53 -23
  22. package/dist/server/services/PipelineExecutor.js +81 -94
  23. package/package.json +49 -16
  24. package/src/client/index.tsx +9 -0
  25. package/src/client-v2/client.d.ts +249 -0
  26. package/src/client-v2/components/EndpointsTab.tsx +458 -0
  27. package/src/client-v2/components/JobsTab.tsx +259 -0
  28. package/src/client-v2/components/PipelinesTab.tsx +872 -0
  29. package/src/client-v2/components/PluginSettings.tsx +48 -0
  30. package/src/client-v2/components/ServiceConfigTab.tsx +122 -0
  31. package/src/client-v2/locale.ts +21 -0
  32. package/{dist/client/models/index.d.ts → src/client-v2/models/index.ts} +3 -2
  33. package/src/client-v2/plugin.tsx +21 -0
  34. package/src/locale/en-US.json +121 -0
  35. package/src/locale/vi-VN.json +121 -0
  36. package/src/locale/zh-CN.json +1 -0
  37. package/src/server/__tests__/actions.test.ts +98 -0
  38. package/src/server/__tests__/pipeline-executor.test.ts +33 -0
  39. package/src/server/__tests__/smoke.test.ts +55 -0
  40. package/src/server/actions.ts +176 -0
  41. package/src/server/collections/.gitkeep +0 -0
  42. package/src/server/collections/config.ts +18 -0
  43. package/src/server/collections/endpoints.ts +28 -0
  44. package/src/server/collections/jobs.ts +29 -0
  45. package/src/server/collections/pipeline-steps.ts +27 -0
  46. package/src/server/collections/pipelines.ts +19 -0
  47. package/src/server/plugin.ts +108 -0
  48. package/src/server/services/AsyncJobManager.ts +172 -0
  49. package/src/server/services/DocumentUnderstandingService.ts +264 -0
  50. package/src/server/services/ExternalApiClient.ts +143 -0
  51. package/src/server/services/PipelineExecutor.ts +502 -0
  52. package/src/server/tools/document-understanding-tool.ts +181 -0
  53. package/src/server/types.ts +73 -0
  54. package/dist/client/components/EndpointsTab.d.ts +0 -2
  55. package/dist/client/components/JobsTab.d.ts +0 -2
  56. package/dist/client/components/PipelinesTab.d.ts +0 -2
  57. package/dist/client/components/PluginSettings.d.ts +0 -2
  58. package/dist/client/components/ServiceConfigTab.d.ts +0 -2
  59. package/dist/client/locale.d.ts +0 -10
  60. package/dist/client/plugin.d.ts +0 -6
  61. package/dist/server/actions.d.ts +0 -17
  62. package/dist/server/collections/config.d.ts +0 -3
  63. package/dist/server/collections/endpoints.d.ts +0 -3
  64. package/dist/server/collections/jobs.d.ts +0 -3
  65. package/dist/server/collections/pipeline-steps.d.ts +0 -3
  66. package/dist/server/collections/pipelines.d.ts +0 -3
  67. package/dist/server/plugin.d.ts +0 -15
  68. package/dist/server/services/AsyncJobManager.d.ts +0 -27
  69. package/dist/server/services/DocumentUnderstandingService.d.ts +0 -35
  70. package/dist/server/services/ExternalApiClient.d.ts +0 -28
  71. package/dist/server/services/PipelineExecutor.d.ts +0 -24
  72. package/dist/server/tools/document-understanding-tool.d.ts +0 -8
  73. package/dist/server/types.d.ts +0 -69
  74. /package/{dist/client/index.d.ts → src/client-v2/index.tsx} +0 -0
  75. /package/{dist/index.d.ts → src/index.ts} +0 -0
  76. /package/{dist/server/index.d.ts → src/server/index.ts} +0 -0
@@ -0,0 +1,259 @@
1
+ import React, { useEffect, useState, useCallback } from 'react';
2
+ import { Table, Tag, Button, Drawer, Select, Space, Badge } from 'antd';
3
+ import { EyeOutlined, ReloadOutlined } from '@ant-design/icons';
4
+ import { useApp } from '@nocobase/client-v2';
5
+
6
+ const STATUS_CONFIG: Record<string, { color: string; label: string }> = {
7
+ pending: { color: 'default', label: 'Pending' },
8
+ running: { color: 'processing', label: 'Running' },
9
+ polling: { color: 'processing', label: 'Polling' },
10
+ completed: { color: 'success', label: 'Completed' },
11
+ failed: { color: 'error', label: 'Failed' },
12
+ timeout: { color: 'error', label: 'Timeout' },
13
+ };
14
+
15
+ export const JobsTab = () => {
16
+ const app = useApp();
17
+ const api = app.apiClient;
18
+ const [data, setData] = useState<any[]>([]);
19
+ const [pipelines, setPipelines] = useState<any[]>([]);
20
+ const [loading, setLoading] = useState(false);
21
+ const [drawerVisible, setDrawerVisible] = useState(false);
22
+ const [activeJob, setActiveJob] = useState<any>(null);
23
+ const [filterStatus, setFilterStatus] = useState<string | undefined>(undefined);
24
+ const [filterPipeline, setFilterPipeline] = useState<number | undefined>(undefined);
25
+
26
+ const fetchJobs = useCallback(async () => {
27
+ setLoading(true);
28
+ try {
29
+ const filter: any = {};
30
+ if (filterStatus) filter.status = filterStatus;
31
+ if (filterPipeline) filter.pipelineId = filterPipeline;
32
+
33
+ const res = await api.request({
34
+ url: 'docUnderstanding:listJobs',
35
+ params: { filter: Object.keys(filter).length > 0 ? filter : undefined },
36
+ });
37
+ setData(res.data?.data || []);
38
+ } finally {
39
+ setLoading(false);
40
+ }
41
+ }, [api, filterStatus, filterPipeline]);
42
+
43
+ const fetchPipelines = useCallback(async () => {
44
+ try {
45
+ const res = await api.request({ url: 'docUnderstanding:listPipelines' });
46
+ setPipelines(res.data?.data || []);
47
+ } catch {
48
+ // ignore
49
+ }
50
+ }, [api]);
51
+
52
+ useEffect(() => {
53
+ fetchPipelines();
54
+ }, [fetchPipelines]);
55
+
56
+ useEffect(() => {
57
+ fetchJobs();
58
+ const timer = setInterval(fetchJobs, 10000);
59
+ return () => clearInterval(timer);
60
+ }, [fetchJobs]);
61
+
62
+ const pipelineMap = new Map(pipelines.map((p: any) => [p.id, p.name]));
63
+
64
+ const viewDetails = async (record: any) => {
65
+ // Fetch fresh job data for detail view
66
+ try {
67
+ const res = await api.request({
68
+ url: 'docUnderstanding:getJobStatus',
69
+ params: { filterByTk: record.id },
70
+ });
71
+ setActiveJob(res.data?.data || record);
72
+ } catch {
73
+ setActiveJob(record);
74
+ }
75
+ setDrawerVisible(true);
76
+ };
77
+
78
+ const columns = [
79
+ { title: 'ID', dataIndex: 'id', width: 60 },
80
+ {
81
+ title: 'Pipeline',
82
+ dataIndex: 'pipelineId',
83
+ width: 180,
84
+ render: (id: number) => pipelineMap.get(id) || `#${id}`,
85
+ },
86
+ {
87
+ title: 'Status',
88
+ dataIndex: 'status',
89
+ width: 100,
90
+ render: (status: string) => {
91
+ const cfg = STATUS_CONFIG[status] || { color: 'default', label: status };
92
+ return <Tag color={cfg.color}>{cfg.label}</Tag>;
93
+ },
94
+ },
95
+ {
96
+ title: 'Current Step',
97
+ dataIndex: 'currentStep',
98
+ width: 90,
99
+ render: (v: number, record: any) => {
100
+ if (record.status === 'completed') return <Tag color="success">Done</Tag>;
101
+ if (record.status === 'failed') return <Tag color="error">Step {v}</Tag>;
102
+ return <Badge status="processing" text={`Step ${v}`} />;
103
+ },
104
+ },
105
+ {
106
+ title: 'Started',
107
+ dataIndex: 'startedAt',
108
+ width: 160,
109
+ render: (val: string) => (val ? new Date(val).toLocaleString() : '-'),
110
+ },
111
+ {
112
+ title: 'Completed',
113
+ dataIndex: 'completedAt',
114
+ width: 160,
115
+ render: (val: string) => (val ? new Date(val).toLocaleString() : '-'),
116
+ },
117
+ {
118
+ title: 'Action',
119
+ width: 80,
120
+ render: (_: any, record: any) => (
121
+ <Button size="small" icon={<EyeOutlined />} onClick={() => viewDetails(record)}>
122
+ View
123
+ </Button>
124
+ ),
125
+ },
126
+ ];
127
+
128
+ return (
129
+ <div>
130
+ <Space style={{ marginBottom: 16 }} wrap>
131
+ <Select
132
+ allowClear
133
+ placeholder="Filter by status"
134
+ value={filterStatus}
135
+ onChange={setFilterStatus}
136
+ style={{ width: 160 }}
137
+ options={Object.entries(STATUS_CONFIG).map(([k, v]) => ({ value: k, label: v.label }))}
138
+ />
139
+ <Select
140
+ allowClear
141
+ placeholder="Filter by pipeline"
142
+ value={filterPipeline}
143
+ onChange={setFilterPipeline}
144
+ style={{ width: 200 }}
145
+ options={pipelines.map((p: any) => ({ value: p.id, label: p.name }))}
146
+ />
147
+ <Button icon={<ReloadOutlined />} onClick={fetchJobs}>
148
+ Refresh
149
+ </Button>
150
+ </Space>
151
+
152
+ <Table
153
+ rowKey="id"
154
+ columns={columns}
155
+ dataSource={data}
156
+ loading={loading}
157
+ size="small"
158
+ pagination={{ pageSize: 20 }}
159
+ />
160
+
161
+ <Drawer
162
+ title={
163
+ activeJob ? `Job #${activeJob.id} — ${pipelineMap.get(activeJob.pipelineId) || 'Unknown'}` : 'Job Details'
164
+ }
165
+ width={640}
166
+ open={drawerVisible}
167
+ onClose={() => setDrawerVisible(false)}
168
+ >
169
+ {activeJob && (
170
+ <div>
171
+ <div style={{ marginBottom: 16 }}>
172
+ <Space>
173
+ <Tag color={STATUS_CONFIG[activeJob.status]?.color}>{activeJob.status}</Tag>
174
+ {activeJob.startedAt && <span>Started: {new Date(activeJob.startedAt).toLocaleString()}</span>}
175
+ {activeJob.completedAt && <span>Completed: {new Date(activeJob.completedAt).toLocaleString()}</span>}
176
+ </Space>
177
+ </div>
178
+
179
+ {activeJob.error && (
180
+ <div
181
+ style={{
182
+ background: '#fff2f0',
183
+ border: '1px solid #ffccc7',
184
+ borderRadius: 6,
185
+ padding: 12,
186
+ marginBottom: 16,
187
+ }}
188
+ >
189
+ <strong style={{ color: '#cf1322' }}>Error:</strong>
190
+ <pre style={{ margin: '4px 0 0', whiteSpace: 'pre-wrap', color: '#cf1322' }}>{activeJob.error}</pre>
191
+ </div>
192
+ )}
193
+
194
+ <h4>Input</h4>
195
+ <pre
196
+ style={{
197
+ background: '#f5f5f5',
198
+ padding: 12,
199
+ borderRadius: 6,
200
+ fontSize: 12,
201
+ maxHeight: 200,
202
+ overflow: 'auto',
203
+ }}
204
+ >
205
+ {JSON.stringify(activeJob.input, null, 2)}
206
+ </pre>
207
+
208
+ <h4 style={{ marginTop: 16 }}>Step Results</h4>
209
+ {activeJob.stepResults && Object.keys(activeJob.stepResults).length > 0 ? (
210
+ Object.entries(activeJob.stepResults).map(([key, val]) => (
211
+ <div key={key} style={{ marginBottom: 8 }}>
212
+ <Tag color="blue">{key}</Tag>
213
+ <pre
214
+ style={{
215
+ background: '#f5f5f5',
216
+ padding: 8,
217
+ borderRadius: 4,
218
+ fontSize: 11,
219
+ maxHeight: 150,
220
+ overflow: 'auto',
221
+ marginTop: 4,
222
+ }}
223
+ >
224
+ {JSON.stringify(val, null, 2)}
225
+ </pre>
226
+ </div>
227
+ ))
228
+ ) : (
229
+ <div style={{ color: '#999' }}>No step results yet</div>
230
+ )}
231
+
232
+ <h4 style={{ marginTop: 16 }}>Final Result</h4>
233
+ <pre
234
+ style={{
235
+ background: '#f0f5ff',
236
+ padding: 12,
237
+ borderRadius: 6,
238
+ fontSize: 12,
239
+ maxHeight: 300,
240
+ overflow: 'auto',
241
+ }}
242
+ >
243
+ {activeJob.finalResult ? JSON.stringify(activeJob.finalResult, null, 2) : '(not yet available)'}
244
+ </pre>
245
+
246
+ {activeJob.externalTaskIds && Object.keys(activeJob.externalTaskIds).length > 0 && (
247
+ <>
248
+ <h4 style={{ marginTop: 16 }}>External Task IDs</h4>
249
+ <pre style={{ background: '#f5f5f5', padding: 8, borderRadius: 4, fontSize: 11 }}>
250
+ {JSON.stringify(activeJob.externalTaskIds, null, 2)}
251
+ </pre>
252
+ </>
253
+ )}
254
+ </div>
255
+ )}
256
+ </Drawer>
257
+ </div>
258
+ );
259
+ };