plugin-document-understanding 1.1.14 → 1.1.16
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 +29 -29
- package/client-v2.d.ts +2 -2
- package/client-v2.js +1 -1
- package/dist/client/{345.e6e484fb1974c3d3.js → 345.277fbb2b97424db5.js} +1 -1
- package/dist/client/index.js +1 -1
- package/dist/client-v2/{345.a8f28526ac21e02a.js → 345.2fa9834b46dd4531.js} +1 -1
- package/dist/client-v2/index.js +1 -1
- package/dist/externalVersion.js +8 -7
- package/dist/locale/en-US.json +3 -1
- package/dist/locale/zh-CN.json +3 -1
- package/dist/node_modules/form-data/lib/form_data.js +2 -2
- package/dist/node_modules/form-data/node_modules/es-define-property/.eslintrc +13 -0
- package/dist/node_modules/form-data/node_modules/es-define-property/.github/FUNDING.yml +12 -0
- package/dist/node_modules/form-data/node_modules/es-define-property/.nycrc +9 -0
- package/dist/node_modules/form-data/node_modules/es-define-property/index.d.ts +3 -0
- package/dist/node_modules/form-data/node_modules/es-define-property/index.js +14 -0
- package/dist/node_modules/form-data/node_modules/es-define-property/package.json +81 -0
- package/dist/node_modules/form-data/node_modules/es-define-property/test/index.js +56 -0
- package/dist/node_modules/form-data/node_modules/es-object-atoms/.eslintrc +16 -0
- package/dist/node_modules/form-data/node_modules/es-object-atoms/.github/FUNDING.yml +12 -0
- package/dist/node_modules/form-data/node_modules/es-object-atoms/RequireObjectCoercible.d.ts +3 -0
- package/dist/node_modules/form-data/node_modules/es-object-atoms/RequireObjectCoercible.js +11 -0
- package/dist/node_modules/form-data/node_modules/es-object-atoms/ToObject.d.ts +7 -0
- package/dist/node_modules/form-data/node_modules/es-object-atoms/ToObject.js +10 -0
- package/dist/node_modules/form-data/node_modules/es-object-atoms/index.d.ts +3 -0
- package/dist/node_modules/form-data/node_modules/es-object-atoms/index.js +4 -0
- package/dist/node_modules/form-data/node_modules/es-object-atoms/isObject.d.ts +3 -0
- package/dist/node_modules/form-data/node_modules/es-object-atoms/isObject.js +6 -0
- package/dist/node_modules/form-data/node_modules/es-object-atoms/package.json +80 -0
- package/dist/node_modules/form-data/node_modules/es-object-atoms/test/index.js +38 -0
- package/dist/node_modules/form-data/node_modules/es-set-tostringtag/.eslintrc +13 -0
- package/dist/node_modules/form-data/node_modules/es-set-tostringtag/.nycrc +9 -0
- package/dist/node_modules/form-data/node_modules/es-set-tostringtag/index.d.ts +10 -0
- package/dist/node_modules/form-data/node_modules/es-set-tostringtag/index.js +35 -0
- package/dist/node_modules/form-data/node_modules/es-set-tostringtag/node_modules/hasown/.eslintrc +5 -0
- package/dist/node_modules/form-data/node_modules/es-set-tostringtag/node_modules/hasown/.github/FUNDING.yml +12 -0
- package/dist/node_modules/form-data/node_modules/es-set-tostringtag/node_modules/hasown/.nycrc +13 -0
- package/dist/node_modules/form-data/node_modules/es-set-tostringtag/node_modules/hasown/index.d.ts +3 -0
- package/dist/node_modules/form-data/node_modules/es-set-tostringtag/node_modules/hasown/index.js +8 -0
- package/dist/node_modules/form-data/node_modules/es-set-tostringtag/node_modules/hasown/package.json +92 -0
- package/dist/node_modules/form-data/node_modules/es-set-tostringtag/package.json +78 -0
- package/dist/node_modules/form-data/node_modules/es-set-tostringtag/test/index.js +85 -0
- package/dist/node_modules/form-data/node_modules/get-intrinsic/.eslintrc +42 -0
- package/dist/node_modules/form-data/node_modules/get-intrinsic/.github/FUNDING.yml +12 -0
- package/dist/node_modules/form-data/node_modules/get-intrinsic/.nycrc +9 -0
- package/dist/node_modules/form-data/node_modules/get-intrinsic/index.js +378 -0
- package/dist/node_modules/form-data/node_modules/get-intrinsic/node_modules/has-symbols/.eslintrc +11 -0
- package/dist/node_modules/form-data/node_modules/get-intrinsic/node_modules/has-symbols/.github/FUNDING.yml +12 -0
- package/dist/node_modules/form-data/node_modules/get-intrinsic/node_modules/has-symbols/.nycrc +9 -0
- package/dist/node_modules/form-data/node_modules/get-intrinsic/node_modules/has-symbols/index.d.ts +3 -0
- package/dist/node_modules/form-data/node_modules/get-intrinsic/node_modules/has-symbols/index.js +14 -0
- package/dist/node_modules/form-data/node_modules/get-intrinsic/node_modules/has-symbols/package.json +111 -0
- package/dist/node_modules/form-data/node_modules/get-intrinsic/node_modules/has-symbols/shams.d.ts +3 -0
- package/dist/node_modules/form-data/node_modules/get-intrinsic/node_modules/has-symbols/shams.js +45 -0
- package/dist/node_modules/form-data/node_modules/get-intrinsic/node_modules/has-symbols/test/index.js +22 -0
- package/dist/node_modules/form-data/node_modules/get-intrinsic/node_modules/has-symbols/test/shams/core-js.js +29 -0
- package/dist/node_modules/form-data/node_modules/get-intrinsic/node_modules/has-symbols/test/shams/get-own-property-symbols.js +29 -0
- package/dist/node_modules/form-data/node_modules/get-intrinsic/node_modules/has-symbols/test/tests.js +58 -0
- package/dist/node_modules/form-data/node_modules/get-intrinsic/node_modules/hasown/.eslintrc +5 -0
- package/dist/node_modules/form-data/node_modules/get-intrinsic/node_modules/hasown/.github/FUNDING.yml +12 -0
- package/dist/node_modules/form-data/node_modules/get-intrinsic/node_modules/hasown/.nycrc +13 -0
- package/dist/node_modules/form-data/node_modules/get-intrinsic/node_modules/hasown/index.d.ts +3 -0
- package/dist/node_modules/form-data/node_modules/get-intrinsic/node_modules/hasown/index.js +8 -0
- package/dist/node_modules/form-data/node_modules/get-intrinsic/node_modules/hasown/package.json +92 -0
- package/dist/node_modules/form-data/node_modules/get-intrinsic/package.json +97 -0
- package/dist/node_modules/form-data/node_modules/get-intrinsic/test/GetIntrinsic.js +274 -0
- package/dist/node_modules/form-data/node_modules/gopd/.eslintrc +16 -0
- package/dist/node_modules/form-data/node_modules/gopd/.github/FUNDING.yml +12 -0
- package/dist/node_modules/form-data/node_modules/gopd/gOPD.d.ts +1 -0
- package/dist/node_modules/form-data/node_modules/gopd/gOPD.js +4 -0
- package/dist/node_modules/form-data/node_modules/gopd/index.d.ts +5 -0
- package/dist/node_modules/form-data/node_modules/gopd/index.js +15 -0
- package/dist/node_modules/form-data/node_modules/gopd/package.json +77 -0
- package/dist/node_modules/form-data/node_modules/gopd/test/index.js +36 -0
- package/dist/node_modules/form-data/node_modules/has-tostringtag/.eslintrc +5 -0
- package/dist/node_modules/form-data/node_modules/has-tostringtag/.github/FUNDING.yml +12 -0
- package/dist/node_modules/form-data/node_modules/has-tostringtag/.nycrc +13 -0
- package/dist/node_modules/form-data/node_modules/has-tostringtag/index.d.ts +3 -0
- package/dist/node_modules/form-data/node_modules/has-tostringtag/index.js +8 -0
- package/dist/node_modules/form-data/node_modules/has-tostringtag/package.json +108 -0
- package/dist/node_modules/form-data/node_modules/has-tostringtag/shams.d.ts +3 -0
- package/dist/node_modules/form-data/node_modules/has-tostringtag/shams.js +8 -0
- package/dist/node_modules/form-data/node_modules/has-tostringtag/test/index.js +21 -0
- package/dist/node_modules/form-data/node_modules/has-tostringtag/test/shams/core-js.js +31 -0
- package/dist/node_modules/form-data/node_modules/has-tostringtag/test/shams/get-own-property-symbols.js +30 -0
- package/dist/node_modules/form-data/node_modules/has-tostringtag/test/tests.js +15 -0
- package/dist/node_modules/form-data/node_modules/hasown/.github/FUNDING.yml +12 -0
- package/dist/node_modules/form-data/node_modules/hasown/.nycrc +13 -0
- package/dist/node_modules/form-data/node_modules/hasown/index.d.ts +3 -0
- package/dist/node_modules/form-data/node_modules/hasown/index.js +8 -0
- package/dist/node_modules/form-data/node_modules/hasown/package.json +91 -0
- package/dist/node_modules/form-data/package.json +1 -1
- package/dist/node_modules/mime-types/index.js +3 -3
- package/dist/node_modules/mime-types/package.json +1 -1
- package/dist/server/actions.js +45 -35
- package/package.json +57 -46
- package/src/client/index.tsx +15 -15
- package/src/client-v2/components/EndpointsTab.tsx +578 -578
- package/src/client-v2/components/JobsTab.tsx +294 -294
- package/src/client-v2/components/PipelinesTab.tsx +962 -962
- package/src/client-v2/components/PluginSettings.tsx +54 -50
- package/src/client-v2/components/ServiceConfigTab.tsx +139 -139
- package/src/client-v2/components/__tests__/PluginSettings.test.tsx +39 -0
- package/src/client-v2/index.tsx +1 -1
- package/src/client-v2/locale.ts +21 -21
- package/src/client-v2/models/index.ts +12 -12
- package/src/client-v2/plugin.tsx +31 -21
- package/src/client-v2/types.ts +32 -32
- package/src/index.ts +2 -2
- package/src/locale/en-US.json +3 -1
- package/src/locale/zh-CN.json +3 -1
- package/src/server/__tests__/actions.test.ts +121 -98
- package/src/server/__tests__/cluster-safety.test.ts +259 -259
- package/src/server/__tests__/document-understanding-service.test.ts +82 -82
- package/src/server/__tests__/dugate-integration.test.ts +221 -221
- package/src/server/__tests__/smoke.test.ts +78 -55
- package/src/server/__tests__/upload-security.test.ts +128 -0
- package/src/server/actions.ts +53 -51
- package/src/server/collections/config.ts +18 -18
- package/src/server/collections/endpoints.ts +33 -33
- package/src/server/collections/jobs.ts +42 -42
- package/src/server/collections/pipeline-steps.ts +27 -27
- package/src/server/collections/pipelines.ts +19 -19
- package/src/server/dugate-seed.ts +491 -491
- package/src/server/index.ts +1 -1
- package/src/server/plugin.ts +143 -143
- package/src/server/services/AsyncJobManager.ts +238 -238
- package/src/server/services/DocumentUnderstandingService.ts +332 -332
- package/src/server/services/ExternalApiClient.ts +178 -178
- package/src/server/services/PipelineExecutor.ts +593 -593
- package/src/server/tools/document-understanding-tool.ts +181 -181
- package/src/server/types.ts +90 -90
|
@@ -1,294 +1,294 @@
|
|
|
1
|
-
import React, { useEffect, useState, useCallback } from 'react';
|
|
2
|
-
import { Table, Tag, Button, Drawer, Select, Space, Badge } from 'antd';
|
|
3
|
-
import type { ColumnsType } from 'antd/es/table';
|
|
4
|
-
import { EyeOutlined, ReloadOutlined } from '@ant-design/icons';
|
|
5
|
-
import { useFlowContext } from '@nocobase/flow-engine';
|
|
6
|
-
import { useT } from '../locale';
|
|
7
|
-
import { JobState, PipelineDef, formatDateTime, unwrapData } from '../types';
|
|
8
|
-
|
|
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',
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
interface JobFilter {
|
|
19
|
-
status?: string;
|
|
20
|
-
pipelineId?: number;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export const JobsTab = () => {
|
|
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[]>([]);
|
|
29
|
-
const [loading, setLoading] = useState(false);
|
|
30
|
-
const [drawerVisible, setDrawerVisible] = useState(false);
|
|
31
|
-
const [activeJob, setActiveJob] = useState<JobState | null>(null);
|
|
32
|
-
const [filterStatus, setFilterStatus] = useState<string | undefined>(undefined);
|
|
33
|
-
const [filterPipeline, setFilterPipeline] = useState<number | undefined>(undefined);
|
|
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
|
-
|
|
44
|
-
const fetchJobs = useCallback(async () => {
|
|
45
|
-
setLoading(true);
|
|
46
|
-
try {
|
|
47
|
-
const filter: JobFilter = {};
|
|
48
|
-
if (filterStatus) filter.status = filterStatus;
|
|
49
|
-
if (filterPipeline) filter.pipelineId = filterPipeline;
|
|
50
|
-
|
|
51
|
-
const res = await api.request({
|
|
52
|
-
url: 'docUnderstanding:listJobs',
|
|
53
|
-
params: { filter: Object.keys(filter).length > 0 ? filter : undefined },
|
|
54
|
-
});
|
|
55
|
-
setData(unwrapData<JobState[]>(res, []));
|
|
56
|
-
} finally {
|
|
57
|
-
setLoading(false);
|
|
58
|
-
}
|
|
59
|
-
}, [api, filterStatus, filterPipeline]);
|
|
60
|
-
|
|
61
|
-
const fetchPipelines = useCallback(async () => {
|
|
62
|
-
try {
|
|
63
|
-
const res = await api.request({ url: 'docUnderstanding:listPipelines' });
|
|
64
|
-
setPipelines(unwrapData<PipelineDef[]>(res, []));
|
|
65
|
-
} catch {
|
|
66
|
-
// Pipeline names are only used to label rows; failing to load them is not fatal.
|
|
67
|
-
}
|
|
68
|
-
}, [api]);
|
|
69
|
-
|
|
70
|
-
useEffect(() => {
|
|
71
|
-
fetchPipelines();
|
|
72
|
-
}, [fetchPipelines]);
|
|
73
|
-
|
|
74
|
-
useEffect(() => {
|
|
75
|
-
fetchJobs();
|
|
76
|
-
const timer = setInterval(fetchJobs, 10000);
|
|
77
|
-
return () => clearInterval(timer);
|
|
78
|
-
}, [fetchJobs]);
|
|
79
|
-
|
|
80
|
-
const pipelineMap = new Map(pipelines.map((p) => [p.id, p.name]));
|
|
81
|
-
|
|
82
|
-
const viewDetails = async (record: JobState) => {
|
|
83
|
-
try {
|
|
84
|
-
const res = await api.request({
|
|
85
|
-
url: 'docUnderstanding:getJobStatus',
|
|
86
|
-
params: { filterByTk: record.id },
|
|
87
|
-
});
|
|
88
|
-
setActiveJob(unwrapData<JobState>(res, record));
|
|
89
|
-
} catch {
|
|
90
|
-
setActiveJob(record);
|
|
91
|
-
}
|
|
92
|
-
setDrawerVisible(true);
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
const columns: ColumnsType<JobState> = [
|
|
96
|
-
{ title: t('ID'), dataIndex: 'id', width: 60 },
|
|
97
|
-
{
|
|
98
|
-
title: t('Pipeline'),
|
|
99
|
-
dataIndex: 'pipelineId',
|
|
100
|
-
width: 180,
|
|
101
|
-
render: (id: number) => pipelineMap.get(id) || `#${id}`,
|
|
102
|
-
},
|
|
103
|
-
{
|
|
104
|
-
title: t('Status'),
|
|
105
|
-
dataIndex: 'status',
|
|
106
|
-
width: 100,
|
|
107
|
-
render: (status: string) => (
|
|
108
|
-
<Tag color={STATUS_COLORS[status] || 'default'}>{statusLabels[status] || status}</Tag>
|
|
109
|
-
),
|
|
110
|
-
},
|
|
111
|
-
{
|
|
112
|
-
title: t('Current Step'),
|
|
113
|
-
dataIndex: 'currentStep',
|
|
114
|
-
width: 90,
|
|
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}`} />;
|
|
119
|
-
},
|
|
120
|
-
},
|
|
121
|
-
{
|
|
122
|
-
title: t('Started'),
|
|
123
|
-
dataIndex: 'startedAt',
|
|
124
|
-
width: 160,
|
|
125
|
-
render: (val: string) => formatDateTime(val),
|
|
126
|
-
},
|
|
127
|
-
{
|
|
128
|
-
title: t('Completed'),
|
|
129
|
-
dataIndex: 'completedAt',
|
|
130
|
-
width: 160,
|
|
131
|
-
render: (val: string) => formatDateTime(val),
|
|
132
|
-
},
|
|
133
|
-
{
|
|
134
|
-
title: t('Action'),
|
|
135
|
-
width: 80,
|
|
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')}
|
|
144
|
-
</Button>
|
|
145
|
-
),
|
|
146
|
-
},
|
|
147
|
-
];
|
|
148
|
-
|
|
149
|
-
return (
|
|
150
|
-
<div>
|
|
151
|
-
<Space style={{ marginBottom: 16 }} wrap>
|
|
152
|
-
<Select
|
|
153
|
-
allowClear
|
|
154
|
-
placeholder={t('Filter by status')}
|
|
155
|
-
aria-label={t('Filter by status')}
|
|
156
|
-
value={filterStatus}
|
|
157
|
-
onChange={setFilterStatus}
|
|
158
|
-
style={{ width: 160 }}
|
|
159
|
-
options={Object.keys(STATUS_COLORS).map((key) => ({ value: key, label: statusLabels[key] }))}
|
|
160
|
-
/>
|
|
161
|
-
<Select
|
|
162
|
-
allowClear
|
|
163
|
-
placeholder={t('Filter by pipeline')}
|
|
164
|
-
aria-label={t('Filter by pipeline')}
|
|
165
|
-
value={filterPipeline}
|
|
166
|
-
onChange={setFilterPipeline}
|
|
167
|
-
style={{ width: 200 }}
|
|
168
|
-
options={pipelines.map((p) => ({ value: p.id, label: p.name }))}
|
|
169
|
-
/>
|
|
170
|
-
<Button icon={<ReloadOutlined />} onClick={fetchJobs}>
|
|
171
|
-
{t('Refresh')}
|
|
172
|
-
</Button>
|
|
173
|
-
</Space>
|
|
174
|
-
|
|
175
|
-
<Table
|
|
176
|
-
rowKey="id"
|
|
177
|
-
columns={columns}
|
|
178
|
-
dataSource={data}
|
|
179
|
-
loading={loading}
|
|
180
|
-
size="small"
|
|
181
|
-
pagination={{ pageSize: 20 }}
|
|
182
|
-
/>
|
|
183
|
-
|
|
184
|
-
<Drawer
|
|
185
|
-
title={
|
|
186
|
-
activeJob
|
|
187
|
-
? `${t('Job')} #${activeJob.id} — ${pipelineMap.get(activeJob.pipelineId) || t('Unknown')}`
|
|
188
|
-
: t('Job Details')
|
|
189
|
-
}
|
|
190
|
-
width={640}
|
|
191
|
-
open={drawerVisible}
|
|
192
|
-
onClose={() => setDrawerVisible(false)}
|
|
193
|
-
>
|
|
194
|
-
{activeJob && (
|
|
195
|
-
<div>
|
|
196
|
-
<div style={{ marginBottom: 16 }}>
|
|
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
|
-
)}
|
|
211
|
-
</Space>
|
|
212
|
-
</div>
|
|
213
|
-
|
|
214
|
-
{activeJob.error && (
|
|
215
|
-
<div
|
|
216
|
-
style={{
|
|
217
|
-
background: '#fff2f0',
|
|
218
|
-
border: '1px solid #ffccc7',
|
|
219
|
-
borderRadius: 6,
|
|
220
|
-
padding: 12,
|
|
221
|
-
marginBottom: 16,
|
|
222
|
-
}}
|
|
223
|
-
>
|
|
224
|
-
<strong style={{ color: '#cf1322' }}>{t('Error')}:</strong>
|
|
225
|
-
<pre style={{ margin: '4px 0 0', whiteSpace: 'pre-wrap', color: '#cf1322' }}>{activeJob.error}</pre>
|
|
226
|
-
</div>
|
|
227
|
-
)}
|
|
228
|
-
|
|
229
|
-
<h4>{t('Input')}</h4>
|
|
230
|
-
<pre
|
|
231
|
-
style={{
|
|
232
|
-
background: '#f5f5f5',
|
|
233
|
-
padding: 12,
|
|
234
|
-
borderRadius: 6,
|
|
235
|
-
fontSize: 12,
|
|
236
|
-
maxHeight: 200,
|
|
237
|
-
overflow: 'auto',
|
|
238
|
-
}}
|
|
239
|
-
>
|
|
240
|
-
{JSON.stringify(activeJob.input, null, 2)}
|
|
241
|
-
</pre>
|
|
242
|
-
|
|
243
|
-
<h4 style={{ marginTop: 16 }}>{t('Step Results')}</h4>
|
|
244
|
-
{activeJob.stepResults && Object.keys(activeJob.stepResults).length > 0 ? (
|
|
245
|
-
Object.entries(activeJob.stepResults).map(([key, val]) => (
|
|
246
|
-
<div key={key} style={{ marginBottom: 8 }}>
|
|
247
|
-
<Tag color="blue">{key}</Tag>
|
|
248
|
-
<pre
|
|
249
|
-
style={{
|
|
250
|
-
background: '#f5f5f5',
|
|
251
|
-
padding: 8,
|
|
252
|
-
borderRadius: 4,
|
|
253
|
-
fontSize: 11,
|
|
254
|
-
maxHeight: 150,
|
|
255
|
-
overflow: 'auto',
|
|
256
|
-
marginTop: 4,
|
|
257
|
-
}}
|
|
258
|
-
>
|
|
259
|
-
{JSON.stringify(val, null, 2)}
|
|
260
|
-
</pre>
|
|
261
|
-
</div>
|
|
262
|
-
))
|
|
263
|
-
) : (
|
|
264
|
-
<div style={{ color: '#999' }}>{t('No step results yet')}</div>
|
|
265
|
-
)}
|
|
266
|
-
|
|
267
|
-
<h4 style={{ marginTop: 16 }}>{t('Final Result')}</h4>
|
|
268
|
-
<pre
|
|
269
|
-
style={{
|
|
270
|
-
background: '#f0f5ff',
|
|
271
|
-
padding: 12,
|
|
272
|
-
borderRadius: 6,
|
|
273
|
-
fontSize: 12,
|
|
274
|
-
maxHeight: 300,
|
|
275
|
-
overflow: 'auto',
|
|
276
|
-
}}
|
|
277
|
-
>
|
|
278
|
-
{activeJob.finalResult ? JSON.stringify(activeJob.finalResult, null, 2) : t('(not yet available)')}
|
|
279
|
-
</pre>
|
|
280
|
-
|
|
281
|
-
{activeJob.externalTaskIds && Object.keys(activeJob.externalTaskIds).length > 0 && (
|
|
282
|
-
<>
|
|
283
|
-
<h4 style={{ marginTop: 16 }}>{t('External Task IDs')}</h4>
|
|
284
|
-
<pre style={{ background: '#f5f5f5', padding: 8, borderRadius: 4, fontSize: 11 }}>
|
|
285
|
-
{JSON.stringify(activeJob.externalTaskIds, null, 2)}
|
|
286
|
-
</pre>
|
|
287
|
-
</>
|
|
288
|
-
)}
|
|
289
|
-
</div>
|
|
290
|
-
)}
|
|
291
|
-
</Drawer>
|
|
292
|
-
</div>
|
|
293
|
-
);
|
|
294
|
-
};
|
|
1
|
+
import React, { useEffect, useState, useCallback } from 'react';
|
|
2
|
+
import { Table, Tag, Button, Drawer, Select, Space, Badge } from 'antd';
|
|
3
|
+
import type { ColumnsType } from 'antd/es/table';
|
|
4
|
+
import { EyeOutlined, ReloadOutlined } from '@ant-design/icons';
|
|
5
|
+
import { useFlowContext } from '@nocobase/flow-engine';
|
|
6
|
+
import { useT } from '../locale';
|
|
7
|
+
import { JobState, PipelineDef, formatDateTime, unwrapData } from '../types';
|
|
8
|
+
|
|
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',
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
interface JobFilter {
|
|
19
|
+
status?: string;
|
|
20
|
+
pipelineId?: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const JobsTab = () => {
|
|
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[]>([]);
|
|
29
|
+
const [loading, setLoading] = useState(false);
|
|
30
|
+
const [drawerVisible, setDrawerVisible] = useState(false);
|
|
31
|
+
const [activeJob, setActiveJob] = useState<JobState | null>(null);
|
|
32
|
+
const [filterStatus, setFilterStatus] = useState<string | undefined>(undefined);
|
|
33
|
+
const [filterPipeline, setFilterPipeline] = useState<number | undefined>(undefined);
|
|
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
|
+
|
|
44
|
+
const fetchJobs = useCallback(async () => {
|
|
45
|
+
setLoading(true);
|
|
46
|
+
try {
|
|
47
|
+
const filter: JobFilter = {};
|
|
48
|
+
if (filterStatus) filter.status = filterStatus;
|
|
49
|
+
if (filterPipeline) filter.pipelineId = filterPipeline;
|
|
50
|
+
|
|
51
|
+
const res = await api.request({
|
|
52
|
+
url: 'docUnderstanding:listJobs',
|
|
53
|
+
params: { filter: Object.keys(filter).length > 0 ? filter : undefined },
|
|
54
|
+
});
|
|
55
|
+
setData(unwrapData<JobState[]>(res, []));
|
|
56
|
+
} finally {
|
|
57
|
+
setLoading(false);
|
|
58
|
+
}
|
|
59
|
+
}, [api, filterStatus, filterPipeline]);
|
|
60
|
+
|
|
61
|
+
const fetchPipelines = useCallback(async () => {
|
|
62
|
+
try {
|
|
63
|
+
const res = await api.request({ url: 'docUnderstanding:listPipelines' });
|
|
64
|
+
setPipelines(unwrapData<PipelineDef[]>(res, []));
|
|
65
|
+
} catch {
|
|
66
|
+
// Pipeline names are only used to label rows; failing to load them is not fatal.
|
|
67
|
+
}
|
|
68
|
+
}, [api]);
|
|
69
|
+
|
|
70
|
+
useEffect(() => {
|
|
71
|
+
fetchPipelines();
|
|
72
|
+
}, [fetchPipelines]);
|
|
73
|
+
|
|
74
|
+
useEffect(() => {
|
|
75
|
+
fetchJobs();
|
|
76
|
+
const timer = setInterval(fetchJobs, 10000);
|
|
77
|
+
return () => clearInterval(timer);
|
|
78
|
+
}, [fetchJobs]);
|
|
79
|
+
|
|
80
|
+
const pipelineMap = new Map(pipelines.map((p) => [p.id, p.name]));
|
|
81
|
+
|
|
82
|
+
const viewDetails = async (record: JobState) => {
|
|
83
|
+
try {
|
|
84
|
+
const res = await api.request({
|
|
85
|
+
url: 'docUnderstanding:getJobStatus',
|
|
86
|
+
params: { filterByTk: record.id },
|
|
87
|
+
});
|
|
88
|
+
setActiveJob(unwrapData<JobState>(res, record));
|
|
89
|
+
} catch {
|
|
90
|
+
setActiveJob(record);
|
|
91
|
+
}
|
|
92
|
+
setDrawerVisible(true);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const columns: ColumnsType<JobState> = [
|
|
96
|
+
{ title: t('ID'), dataIndex: 'id', width: 60 },
|
|
97
|
+
{
|
|
98
|
+
title: t('Pipeline'),
|
|
99
|
+
dataIndex: 'pipelineId',
|
|
100
|
+
width: 180,
|
|
101
|
+
render: (id: number) => pipelineMap.get(id) || `#${id}`,
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
title: t('Status'),
|
|
105
|
+
dataIndex: 'status',
|
|
106
|
+
width: 100,
|
|
107
|
+
render: (status: string) => (
|
|
108
|
+
<Tag color={STATUS_COLORS[status] || 'default'}>{statusLabels[status] || status}</Tag>
|
|
109
|
+
),
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
title: t('Current Step'),
|
|
113
|
+
dataIndex: 'currentStep',
|
|
114
|
+
width: 90,
|
|
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}`} />;
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
title: t('Started'),
|
|
123
|
+
dataIndex: 'startedAt',
|
|
124
|
+
width: 160,
|
|
125
|
+
render: (val: string) => formatDateTime(val),
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
title: t('Completed'),
|
|
129
|
+
dataIndex: 'completedAt',
|
|
130
|
+
width: 160,
|
|
131
|
+
render: (val: string) => formatDateTime(val),
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
title: t('Action'),
|
|
135
|
+
width: 80,
|
|
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')}
|
|
144
|
+
</Button>
|
|
145
|
+
),
|
|
146
|
+
},
|
|
147
|
+
];
|
|
148
|
+
|
|
149
|
+
return (
|
|
150
|
+
<div>
|
|
151
|
+
<Space style={{ marginBottom: 16 }} wrap>
|
|
152
|
+
<Select
|
|
153
|
+
allowClear
|
|
154
|
+
placeholder={t('Filter by status')}
|
|
155
|
+
aria-label={t('Filter by status')}
|
|
156
|
+
value={filterStatus}
|
|
157
|
+
onChange={setFilterStatus}
|
|
158
|
+
style={{ width: 160 }}
|
|
159
|
+
options={Object.keys(STATUS_COLORS).map((key) => ({ value: key, label: statusLabels[key] }))}
|
|
160
|
+
/>
|
|
161
|
+
<Select
|
|
162
|
+
allowClear
|
|
163
|
+
placeholder={t('Filter by pipeline')}
|
|
164
|
+
aria-label={t('Filter by pipeline')}
|
|
165
|
+
value={filterPipeline}
|
|
166
|
+
onChange={setFilterPipeline}
|
|
167
|
+
style={{ width: 200 }}
|
|
168
|
+
options={pipelines.map((p) => ({ value: p.id, label: p.name }))}
|
|
169
|
+
/>
|
|
170
|
+
<Button icon={<ReloadOutlined />} onClick={fetchJobs}>
|
|
171
|
+
{t('Refresh')}
|
|
172
|
+
</Button>
|
|
173
|
+
</Space>
|
|
174
|
+
|
|
175
|
+
<Table
|
|
176
|
+
rowKey="id"
|
|
177
|
+
columns={columns}
|
|
178
|
+
dataSource={data}
|
|
179
|
+
loading={loading}
|
|
180
|
+
size="small"
|
|
181
|
+
pagination={{ pageSize: 20 }}
|
|
182
|
+
/>
|
|
183
|
+
|
|
184
|
+
<Drawer
|
|
185
|
+
title={
|
|
186
|
+
activeJob
|
|
187
|
+
? `${t('Job')} #${activeJob.id} — ${pipelineMap.get(activeJob.pipelineId) || t('Unknown')}`
|
|
188
|
+
: t('Job Details')
|
|
189
|
+
}
|
|
190
|
+
width={640}
|
|
191
|
+
open={drawerVisible}
|
|
192
|
+
onClose={() => setDrawerVisible(false)}
|
|
193
|
+
>
|
|
194
|
+
{activeJob && (
|
|
195
|
+
<div>
|
|
196
|
+
<div style={{ marginBottom: 16 }}>
|
|
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
|
+
)}
|
|
211
|
+
</Space>
|
|
212
|
+
</div>
|
|
213
|
+
|
|
214
|
+
{activeJob.error && (
|
|
215
|
+
<div
|
|
216
|
+
style={{
|
|
217
|
+
background: '#fff2f0',
|
|
218
|
+
border: '1px solid #ffccc7',
|
|
219
|
+
borderRadius: 6,
|
|
220
|
+
padding: 12,
|
|
221
|
+
marginBottom: 16,
|
|
222
|
+
}}
|
|
223
|
+
>
|
|
224
|
+
<strong style={{ color: '#cf1322' }}>{t('Error')}:</strong>
|
|
225
|
+
<pre style={{ margin: '4px 0 0', whiteSpace: 'pre-wrap', color: '#cf1322' }}>{activeJob.error}</pre>
|
|
226
|
+
</div>
|
|
227
|
+
)}
|
|
228
|
+
|
|
229
|
+
<h4>{t('Input')}</h4>
|
|
230
|
+
<pre
|
|
231
|
+
style={{
|
|
232
|
+
background: '#f5f5f5',
|
|
233
|
+
padding: 12,
|
|
234
|
+
borderRadius: 6,
|
|
235
|
+
fontSize: 12,
|
|
236
|
+
maxHeight: 200,
|
|
237
|
+
overflow: 'auto',
|
|
238
|
+
}}
|
|
239
|
+
>
|
|
240
|
+
{JSON.stringify(activeJob.input, null, 2)}
|
|
241
|
+
</pre>
|
|
242
|
+
|
|
243
|
+
<h4 style={{ marginTop: 16 }}>{t('Step Results')}</h4>
|
|
244
|
+
{activeJob.stepResults && Object.keys(activeJob.stepResults).length > 0 ? (
|
|
245
|
+
Object.entries(activeJob.stepResults).map(([key, val]) => (
|
|
246
|
+
<div key={key} style={{ marginBottom: 8 }}>
|
|
247
|
+
<Tag color="blue">{key}</Tag>
|
|
248
|
+
<pre
|
|
249
|
+
style={{
|
|
250
|
+
background: '#f5f5f5',
|
|
251
|
+
padding: 8,
|
|
252
|
+
borderRadius: 4,
|
|
253
|
+
fontSize: 11,
|
|
254
|
+
maxHeight: 150,
|
|
255
|
+
overflow: 'auto',
|
|
256
|
+
marginTop: 4,
|
|
257
|
+
}}
|
|
258
|
+
>
|
|
259
|
+
{JSON.stringify(val, null, 2)}
|
|
260
|
+
</pre>
|
|
261
|
+
</div>
|
|
262
|
+
))
|
|
263
|
+
) : (
|
|
264
|
+
<div style={{ color: '#999' }}>{t('No step results yet')}</div>
|
|
265
|
+
)}
|
|
266
|
+
|
|
267
|
+
<h4 style={{ marginTop: 16 }}>{t('Final Result')}</h4>
|
|
268
|
+
<pre
|
|
269
|
+
style={{
|
|
270
|
+
background: '#f0f5ff',
|
|
271
|
+
padding: 12,
|
|
272
|
+
borderRadius: 6,
|
|
273
|
+
fontSize: 12,
|
|
274
|
+
maxHeight: 300,
|
|
275
|
+
overflow: 'auto',
|
|
276
|
+
}}
|
|
277
|
+
>
|
|
278
|
+
{activeJob.finalResult ? JSON.stringify(activeJob.finalResult, null, 2) : t('(not yet available)')}
|
|
279
|
+
</pre>
|
|
280
|
+
|
|
281
|
+
{activeJob.externalTaskIds && Object.keys(activeJob.externalTaskIds).length > 0 && (
|
|
282
|
+
<>
|
|
283
|
+
<h4 style={{ marginTop: 16 }}>{t('External Task IDs')}</h4>
|
|
284
|
+
<pre style={{ background: '#f5f5f5', padding: 8, borderRadius: 4, fontSize: 11 }}>
|
|
285
|
+
{JSON.stringify(activeJob.externalTaskIds, null, 2)}
|
|
286
|
+
</pre>
|
|
287
|
+
</>
|
|
288
|
+
)}
|
|
289
|
+
</div>
|
|
290
|
+
)}
|
|
291
|
+
</Drawer>
|
|
292
|
+
</div>
|
|
293
|
+
);
|
|
294
|
+
};
|