plugin-document-understanding 1.1.8 → 1.1.11

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