plugin-document-understanding 1.1.15 → 2.0.0

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 (82) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +19 -25
  3. package/dist/client/169.6888909107c553c3.js +10 -0
  4. package/dist/client/379.e29f5ced467ce23d.js +10 -0
  5. package/dist/client/867.3ed3b814115181ca.js +10 -0
  6. package/dist/client/index.js +1 -1
  7. package/dist/client-v2/169.53bf1be2ec192f0c.js +10 -0
  8. package/dist/client-v2/379.e75c4829567cdb89.js +10 -0
  9. package/dist/client-v2/867.66d7291e95f1de78.js +10 -0
  10. package/dist/client-v2/index.js +1 -1
  11. package/dist/externalVersion.js +10 -8
  12. package/dist/locale/en-US.json +126 -0
  13. package/dist/locale/vi-VN.json +130 -2
  14. package/dist/locale/zh-CN.json +127 -1
  15. package/dist/node_modules/form-data/package.json +1 -1
  16. package/dist/node_modules/mime-types/package.json +1 -1
  17. package/dist/server/actions.js +211 -11
  18. package/dist/server/collections/api-keys.js +55 -0
  19. package/dist/server/collections/artifacts.js +59 -0
  20. package/dist/server/collections/config.js +9 -3
  21. package/dist/server/collections/endpoints.js +3 -0
  22. package/dist/server/collections/jobs.js +7 -4
  23. package/dist/server/collections/operations.js +76 -0
  24. package/dist/server/contracts/du-contracts.js +828 -0
  25. package/dist/server/dugate-seed.js +98 -340
  26. package/dist/server/plugin.js +49 -7
  27. package/dist/server/routes/du-gateway-router.js +443 -0
  28. package/dist/server/services/ArtifactStorageService.js +459 -0
  29. package/dist/server/services/AsyncJobManager.js +1 -1
  30. package/dist/server/services/BuiltinBusinessEngine.js +1223 -0
  31. package/dist/server/services/DocumentUnderstandingService.js +151 -25
  32. package/dist/server/services/ExternalDuReworkClient.js +210 -0
  33. package/dist/server/services/OperationOrchestrator.js +1087 -0
  34. package/dist/server/services/PipelineExecutor.js +164 -43
  35. package/dist/server/tools/document-understanding-tool.js +49 -24
  36. package/dist/server/workflow/DocumentUnderstandingInstruction.js +292 -0
  37. package/package.json +8 -4
  38. package/src/client/index.tsx +11 -0
  39. package/src/client-v2/components/ApiKeysTab.tsx +198 -0
  40. package/src/client-v2/components/EndpointsTab.tsx +39 -2
  41. package/src/client-v2/components/JobsTab.tsx +136 -21
  42. package/src/client-v2/components/OperationsTab.tsx +586 -0
  43. package/src/client-v2/components/PluginSettings.tsx +24 -8
  44. package/src/client-v2/components/ServiceConfigTab.tsx +225 -65
  45. package/src/client-v2/components/__tests__/PluginSettings.test.tsx +43 -0
  46. package/src/client-v2/locale.ts +1 -8
  47. package/src/client-v2/models/index.ts +1 -8
  48. package/src/client-v2/plugin.tsx +12 -8
  49. package/src/client-v2/types.ts +13 -1
  50. package/src/client-v2/workflow/DocumentUnderstandingFieldset.tsx +122 -0
  51. package/src/client-v2/workflow/DocumentUnderstandingInstruction.tsx +49 -0
  52. package/src/locale/en-US.json +126 -0
  53. package/src/locale/vi-VN.json +130 -2
  54. package/src/locale/zh-CN.json +127 -1
  55. package/src/server/__tests__/actions.test.ts +1 -8
  56. package/src/server/__tests__/du-rework-gateway.test.ts +462 -0
  57. package/src/server/__tests__/dugate-integration.test.ts +79 -42
  58. package/src/server/__tests__/smoke.test.ts +1 -8
  59. package/src/server/__tests__/upload-security.test.ts +1 -8
  60. package/src/server/actions.ts +252 -36
  61. package/src/server/collections/api-keys.ts +35 -0
  62. package/src/server/collections/artifacts.ts +39 -0
  63. package/src/server/collections/config.ts +18 -2
  64. package/src/server/collections/endpoints.ts +12 -0
  65. package/src/server/collections/jobs.ts +16 -4
  66. package/src/server/collections/operations.ts +56 -0
  67. package/src/server/contracts/du-contracts.ts +1026 -0
  68. package/src/server/dugate-seed.ts +126 -453
  69. package/src/server/plugin.ts +64 -14
  70. package/src/server/routes/du-gateway-router.ts +465 -0
  71. package/src/server/services/ArtifactStorageService.ts +596 -0
  72. package/src/server/services/AsyncJobManager.ts +10 -1
  73. package/src/server/services/BuiltinBusinessEngine.ts +1544 -0
  74. package/src/server/services/DocumentUnderstandingService.ts +186 -44
  75. package/src/server/services/ExternalDuReworkClient.ts +222 -0
  76. package/src/server/services/OperationOrchestrator.ts +1359 -0
  77. package/src/server/services/PipelineExecutor.ts +245 -108
  78. package/src/server/tools/document-understanding-tool.ts +63 -45
  79. package/src/server/types.ts +101 -16
  80. package/src/server/workflow/DocumentUnderstandingInstruction.ts +308 -0
  81. package/dist/client/345.e6e484fb1974c3d3.js +0 -10
  82. package/dist/client-v2/345.a8f28526ac21e02a.js +0 -10
@@ -0,0 +1,586 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+
3
+ import React, { useCallback, useEffect, useState } from 'react';
4
+ import {
5
+ Alert,
6
+ Button,
7
+ Card,
8
+ Drawer,
9
+ Form,
10
+ Input,
11
+ Modal,
12
+ Popconfirm,
13
+ Progress,
14
+ Select,
15
+ Space,
16
+ Statistic,
17
+ Switch,
18
+ Table,
19
+ Tag,
20
+ Upload,
21
+ message,
22
+ } from 'antd';
23
+ import type { ColumnsType } from 'antd/es/table';
24
+ import type { UploadFile } from 'antd/es/upload/interface';
25
+ import {
26
+ CheckOutlined,
27
+ EyeOutlined,
28
+ PlayCircleOutlined,
29
+ ReloadOutlined,
30
+ StopOutlined,
31
+ UploadOutlined,
32
+ } from '@ant-design/icons';
33
+ import { useFlowContext } from '@nocobase/flow-engine';
34
+ import { DU_BUSINESS_CATALOG, DU_OPERATION_STATES, parsePageRangeString } from '../../server/contracts/du-contracts';
35
+ import { useT } from '../locale';
36
+ import { OperationView, UsageSummaryView, errorMessage, formatDateTime, unwrapData } from '../types';
37
+
38
+ const { TextArea } = Input;
39
+
40
+ const STATE_COLORS: Record<string, string> = {
41
+ PENDING_INGESTION: 'default',
42
+ ACCEPTED: 'cyan',
43
+ QUEUED: 'blue',
44
+ RUNNING: 'processing',
45
+ WAITING_CHILDREN: 'processing',
46
+ WAITING_INPUT: 'warning',
47
+ RETRY_PENDING: 'orange',
48
+ CANCEL_REQUESTED: 'orange',
49
+ SUCCEEDED: 'success',
50
+ FAILED: 'error',
51
+ CANCELLED: 'default',
52
+ TIMED_OUT: 'error',
53
+ };
54
+
55
+ interface DetailedOperation extends OperationView {
56
+ outputPayload?: Record<string, unknown> | null;
57
+ resultEnvelope?: Record<string, unknown> | null;
58
+ }
59
+
60
+ export const OperationsTab: React.FC = () => {
61
+ const ctx = useFlowContext();
62
+ const api = ctx.api;
63
+ const t = useT();
64
+
65
+ const [operations, setOperations] = useState<OperationView[]>([]);
66
+ const [usageSummary, setUsageSummary] = useState<UsageSummaryView | null>(null);
67
+ const [loading, setLoading] = useState(false);
68
+ const [filterState, setFilterState] = useState<string>();
69
+ const [filterBusiness, setFilterBusiness] = useState<string>();
70
+
71
+ const [runVisible, setRunVisible] = useState(false);
72
+ const [submitting, setSubmitting] = useState(false);
73
+ const [runForm] = Form.useForm();
74
+ const [uploadFiles, setUploadFiles] = useState<UploadFile[]>([]);
75
+
76
+ const [drawerOpen, setDrawerOpen] = useState(false);
77
+ const [activeOp, setActiveOp] = useState<DetailedOperation | null>(null);
78
+
79
+ const [resumeOpen, setResumeOpen] = useState(false);
80
+ const [resuming, setResuming] = useState(false);
81
+ const [resumeForm] = Form.useForm();
82
+
83
+ const watchedBusiness = Form.useWatch('businessId', runForm) || 'document-core';
84
+ const watchedAction = Form.useWatch('action', runForm) || 'extract';
85
+
86
+ const fetchOperations = useCallback(async () => {
87
+ setLoading(true);
88
+ try {
89
+ const filter: Record<string, string> = {};
90
+ if (filterState) filter.state = filterState;
91
+ if (filterBusiness) filter.businessId = filterBusiness;
92
+
93
+ const [opsRes, usageRes] = await Promise.all([
94
+ api.request({
95
+ url: 'docUnderstanding:listOperations',
96
+ params: { filter: Object.keys(filter).length > 0 ? filter : undefined },
97
+ }),
98
+ api.request({ url: 'docUnderstanding:getUsageSummary' }).catch(() => null),
99
+ ]);
100
+ setOperations(unwrapData<OperationView[]>(opsRes, []));
101
+ if (usageRes) {
102
+ setUsageSummary(unwrapData<UsageSummaryView | null>(usageRes, null));
103
+ }
104
+ } finally {
105
+ setLoading(false);
106
+ }
107
+ }, [api, filterState, filterBusiness]);
108
+
109
+ useEffect(() => {
110
+ fetchOperations();
111
+ const timer = setInterval(fetchOperations, 8000);
112
+ return () => clearInterval(timer);
113
+ }, [fetchOperations]);
114
+
115
+ const openOperationDetails = async (operationId: string) => {
116
+ try {
117
+ const res = await api.request({
118
+ url: 'docUnderstanding:getOperation',
119
+ params: { filterByTk: operationId },
120
+ });
121
+ setActiveOp(unwrapData<DetailedOperation | null>(res, null));
122
+ setDrawerOpen(true);
123
+ } catch (err) {
124
+ message.error(errorMessage(err));
125
+ }
126
+ };
127
+
128
+ const handleCancelOperation = async (operationId: string) => {
129
+ try {
130
+ await api.request({
131
+ url: 'docUnderstanding:cancelOperation',
132
+ method: 'POST',
133
+ params: { filterByTk: operationId },
134
+ });
135
+ message.success(t('Operation cancellation requested'));
136
+ fetchOperations();
137
+ if (activeOp?.id === operationId) {
138
+ openOperationDetails(operationId);
139
+ }
140
+ } catch (err) {
141
+ message.error(errorMessage(err));
142
+ }
143
+ };
144
+
145
+ const openResumeModal = (op: OperationView) => {
146
+ setActiveOp(op);
147
+ resumeForm.setFieldsValue({
148
+ approved: true,
149
+ note: '',
150
+ });
151
+ setResumeOpen(true);
152
+ };
153
+
154
+ const handleResumeSubmit = async () => {
155
+ if (!activeOp) return;
156
+ setResuming(true);
157
+ try {
158
+ const values = await resumeForm.validateFields();
159
+ await api.request({
160
+ url: 'docUnderstanding:resumeOperation',
161
+ method: 'POST',
162
+ params: { filterByTk: activeOp.id },
163
+ data: {
164
+ waitId: activeOp.wait?.waitId,
165
+ expectedStateVersion: activeOp.stateVersion,
166
+ input: values,
167
+ },
168
+ });
169
+ message.success(t('Operation resumed'));
170
+ setResumeOpen(false);
171
+ fetchOperations();
172
+ openOperationDetails(activeOp.id);
173
+ } catch (err) {
174
+ message.error(errorMessage(err));
175
+ } finally {
176
+ setResuming(false);
177
+ }
178
+ };
179
+
180
+ const handleRunOperation = async () => {
181
+ setSubmitting(true);
182
+ try {
183
+ const values = await runForm.validateFields();
184
+ const extraInput = values.inputJson?.trim() ? (JSON.parse(values.inputJson) as Record<string, unknown>) : {};
185
+ const catalogMatch = DU_BUSINESS_CATALOG.find(
186
+ (c) =>
187
+ c.businessId === values.businessId &&
188
+ c.action === values.action &&
189
+ (!values.variant || c.discriminatorValue === values.variant),
190
+ );
191
+ if (catalogMatch?.discriminatorField && values.variant) {
192
+ extraInput[catalogMatch.discriminatorField] = values.variant;
193
+ }
194
+ if (values.pages?.trim()) {
195
+ // Validate page range syntax client-side before submitting
196
+ parsePageRangeString(values.pages);
197
+ extraInput.pages = values.pages.trim();
198
+ }
199
+
200
+ const formData = new FormData();
201
+ formData.append('businessId', values.businessId);
202
+ formData.append('action', values.action);
203
+ formData.append('input', JSON.stringify(extraInput));
204
+ for (const fileItem of uploadFiles) {
205
+ if (fileItem.originFileObj) {
206
+ formData.append('files', fileItem.originFileObj, fileItem.name);
207
+ }
208
+ }
209
+
210
+ const res = await api.request({
211
+ url: 'docUnderstanding:submitOperation',
212
+ method: 'POST',
213
+ data: formData,
214
+ });
215
+ const created = unwrapData<{ operationId?: string }>(res, {});
216
+ message.success(`${t('Operation submitted')}: ${created.operationId || ''}`);
217
+ setRunVisible(false);
218
+ setUploadFiles([]);
219
+ fetchOperations();
220
+ if (created.operationId) {
221
+ openOperationDetails(created.operationId);
222
+ }
223
+ } catch (err) {
224
+ message.error(errorMessage(err));
225
+ } finally {
226
+ setSubmitting(false);
227
+ }
228
+ };
229
+
230
+ const actionsForBusiness = Array.from(
231
+ new Set(DU_BUSINESS_CATALOG.filter((c) => c.businessId === watchedBusiness).map((c) => c.action)),
232
+ );
233
+ const variantsForAction = DU_BUSINESS_CATALOG.filter(
234
+ (c) => c.businessId === watchedBusiness && c.action === watchedAction && c.discriminatorValue,
235
+ );
236
+
237
+ const columns: ColumnsType<OperationView> = [
238
+ {
239
+ title: t('Operation ID'),
240
+ dataIndex: 'id',
241
+ width: 150,
242
+ render: (id: string) => <code style={{ fontSize: 11 }}>{id.slice(0, 12)}...</code>,
243
+ },
244
+ {
245
+ title: t('Business / Action'),
246
+ width: 190,
247
+ render: (_: unknown, record) => (
248
+ <Space size={4}>
249
+ <Tag color="geekblue">{record.businessId}</Tag>
250
+ <span>{record.action}</span>
251
+ </Space>
252
+ ),
253
+ },
254
+ {
255
+ title: t('State'),
256
+ dataIndex: 'state',
257
+ width: 150,
258
+ render: (state: string) => <Tag color={STATE_COLORS[state] || 'default'}>{state}</Tag>,
259
+ },
260
+ {
261
+ title: t('Progress'),
262
+ width: 130,
263
+ render: (_: unknown, record) => <Progress percent={record.progress?.percent ?? 0} size="small" />,
264
+ },
265
+ {
266
+ title: t('Tokens / Cost'),
267
+ width: 150,
268
+ render: (_: unknown, record) =>
269
+ record.usage ? (
270
+ <span style={{ fontSize: 12 }}>
271
+ {record.usage.inputTokens + record.usage.outputTokens} tok ($
272
+ {(record.usage.costMicrousd / 1_000_000).toFixed(4)})
273
+ </span>
274
+ ) : (
275
+ '-'
276
+ ),
277
+ },
278
+ {
279
+ title: t('Created'),
280
+ dataIndex: 'createdAt',
281
+ width: 165,
282
+ render: (v: string) => formatDateTime(v),
283
+ },
284
+ {
285
+ title: t('Action'),
286
+ width: 210,
287
+ render: (_: unknown, record) => {
288
+ const isTerminal = ['SUCCEEDED', 'FAILED', 'CANCELLED', 'TIMED_OUT'].includes(record.state);
289
+ return (
290
+ <Space size={4}>
291
+ <Button
292
+ size="small"
293
+ icon={<EyeOutlined />}
294
+ onClick={() => openOperationDetails(record.id)}
295
+ aria-label={`${t('View')} ${record.id}`}
296
+ >
297
+ {t('View')}
298
+ </Button>
299
+ {record.state === 'WAITING_INPUT' && (
300
+ <Button
301
+ size="small"
302
+ type="primary"
303
+ icon={<CheckOutlined />}
304
+ onClick={() => openResumeModal(record)}
305
+ aria-label={`${t('Approve / Resume')} ${record.id}`}
306
+ >
307
+ {t('Resume')}
308
+ </Button>
309
+ )}
310
+ {!isTerminal && (
311
+ <Popconfirm title={t('Cancel this operation?')} onConfirm={() => handleCancelOperation(record.id)}>
312
+ <Button size="small" danger icon={<StopOutlined />} aria-label={`${t('Cancel')} ${record.id}`} />
313
+ </Popconfirm>
314
+ )}
315
+ </Space>
316
+ );
317
+ },
318
+ },
319
+ ];
320
+
321
+ return (
322
+ <div>
323
+ {usageSummary && (
324
+ <div style={{ display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 12, marginBottom: 16 }}>
325
+ <Card size="small">
326
+ <Statistic title={t('Operations (30d)')} value={usageSummary.totalOperations} />
327
+ </Card>
328
+ <Card size="small">
329
+ <Statistic title={t('Input Tokens')} value={usageSummary.inputTokens} />
330
+ </Card>
331
+ <Card size="small">
332
+ <Statistic title={t('Output Tokens')} value={usageSummary.outputTokens} />
333
+ </Card>
334
+ <Card size="small">
335
+ <Statistic
336
+ title={t('Estimated Cost (USD)')}
337
+ value={(usageSummary.costMicrousd / 1_000_000).toFixed(4)}
338
+ prefix="$"
339
+ />
340
+ </Card>
341
+ </div>
342
+ )}
343
+
344
+ <Space style={{ marginBottom: 16 }} wrap>
345
+ <Button
346
+ type="primary"
347
+ icon={<PlayCircleOutlined />}
348
+ onClick={() => {
349
+ runForm.resetFields();
350
+ setUploadFiles([]);
351
+ setRunVisible(true);
352
+ }}
353
+ >
354
+ {t('Run Business Action')}
355
+ </Button>
356
+ <Select
357
+ allowClear
358
+ placeholder={t('Filter by state')}
359
+ aria-label={t('Filter by state')}
360
+ value={filterState}
361
+ onChange={setFilterState}
362
+ style={{ width: 180 }}
363
+ options={DU_OPERATION_STATES.map((s) => ({ value: s, label: s }))}
364
+ />
365
+ <Select
366
+ allowClear
367
+ placeholder={t('Filter by business')}
368
+ aria-label={t('Filter by business')}
369
+ value={filterBusiness}
370
+ onChange={setFilterBusiness}
371
+ style={{ width: 180 }}
372
+ options={[
373
+ { value: 'document-core', label: 'document-core' },
374
+ { value: 'lc-checker', label: 'lc-checker' },
375
+ { value: 'example-review', label: 'example-review' },
376
+ ]}
377
+ />
378
+ <Button icon={<ReloadOutlined />} onClick={fetchOperations}>
379
+ {t('Refresh')}
380
+ </Button>
381
+ </Space>
382
+
383
+ <Table
384
+ rowKey="id"
385
+ columns={columns}
386
+ dataSource={operations}
387
+ loading={loading}
388
+ size="small"
389
+ pagination={{ pageSize: 15 }}
390
+ />
391
+
392
+ {/* Run Canonical Business Action Modal */}
393
+ <Modal
394
+ title={t('Run Document Understanding Action')}
395
+ open={runVisible}
396
+ onOk={handleRunOperation}
397
+ onCancel={() => setRunVisible(false)}
398
+ confirmLoading={submitting}
399
+ okText={t('Submit Operation')}
400
+ cancelText={t('Cancel')}
401
+ width={640}
402
+ destroyOnClose
403
+ >
404
+ <Form
405
+ form={runForm}
406
+ layout="vertical"
407
+ initialValues={{ businessId: 'document-core', action: 'extract', variant: 'invoice', inputJson: '{}' }}
408
+ >
409
+ <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '0 16px' }}>
410
+ <Form.Item name="businessId" label={t('Business')} rules={[{ required: true }]}>
411
+ <Select
412
+ options={[
413
+ { value: 'document-core', label: 'document-core (v2.0.0)' },
414
+ { value: 'lc-checker', label: 'lc-checker (v1.2.0)' },
415
+ { value: 'example-review', label: 'example-review (v1.0.0)' },
416
+ ]}
417
+ />
418
+ </Form.Item>
419
+ <Form.Item name="action" label={t('Action')} rules={[{ required: true }]}>
420
+ <Select options={actionsForBusiness.map((act) => ({ value: act, label: act }))} />
421
+ </Form.Item>
422
+ </div>
423
+
424
+ {variantsForAction.length > 0 && (
425
+ <Form.Item name="variant" label={t('Variant / Mode')}>
426
+ <Select
427
+ options={variantsForAction.map((v) => ({
428
+ value: v.discriminatorValue as string,
429
+ label: `${v.discriminatorValue} — ${v.description}`,
430
+ }))}
431
+ />
432
+ </Form.Item>
433
+ )}
434
+
435
+ <Form.Item label={t('Upload Input Documents')}>
436
+ <Upload
437
+ multiple
438
+ beforeUpload={() => false}
439
+ fileList={uploadFiles}
440
+ onChange={({ fileList }) => setUploadFiles(fileList)}
441
+ >
442
+ <Button icon={<UploadOutlined />}>{t('Select Files')}</Button>
443
+ </Upload>
444
+ </Form.Item>
445
+
446
+ <Form.Item
447
+ name="pages"
448
+ label={t('Page Selection (DI-06)')}
449
+ help={t('Optional page ranges, e.g. "1-2, 5" (leave blank for all pages)')}
450
+ >
451
+ <Input placeholder="1-2" />
452
+ </Form.Item>
453
+
454
+ <Form.Item name="inputJson" label={t('Input JSON')}>
455
+ <TextArea rows={4} style={{ fontFamily: 'monospace', fontSize: 12 }} />
456
+ </Form.Item>
457
+ </Form>
458
+ </Modal>
459
+
460
+ {/* Human-in-the-Loop WAITING_INPUT Approval Modal */}
461
+ <Modal
462
+ title={`${t('Human-in-the-Loop Approval')} — ${activeOp?.id.slice(0, 12) || ''}`}
463
+ open={resumeOpen}
464
+ onOk={handleResumeSubmit}
465
+ onCancel={() => setResumeOpen(false)}
466
+ confirmLoading={resuming}
467
+ okText={t('Submit Decision')}
468
+ cancelText={t('Cancel')}
469
+ destroyOnClose
470
+ >
471
+ {activeOp?.wait?.prompt && (
472
+ <Alert message={activeOp.wait.prompt} type="warning" showIcon style={{ marginBottom: 16 }} />
473
+ )}
474
+ {activeOp?.wait?.previewData !== undefined && (
475
+ <pre
476
+ style={{
477
+ background: '#fafafa',
478
+ padding: 10,
479
+ borderRadius: 6,
480
+ maxHeight: 200,
481
+ overflow: 'auto',
482
+ fontSize: 11,
483
+ marginBottom: 16,
484
+ }}
485
+ >
486
+ {JSON.stringify(activeOp.wait.previewData, null, 2)}
487
+ </pre>
488
+ )}
489
+ <Form form={resumeForm} layout="vertical" initialValues={{ approved: true }}>
490
+ <Form.Item name="approved" label={t('Approve & Proceed')} valuePropName="checked">
491
+ <Switch checkedChildren={t('Approve')} unCheckedChildren={t('Reject')} />
492
+ </Form.Item>
493
+ <Form.Item name="note" label={t('Reviewer Note')}>
494
+ <TextArea rows={3} placeholder={t('Enter verification note...')} />
495
+ </Form.Item>
496
+ </Form>
497
+ </Modal>
498
+
499
+ {/* Operation Details Drawer */}
500
+ <Drawer
501
+ title={activeOp ? `${t('Operation')} ${activeOp.id}` : t('Operation Details')}
502
+ width={680}
503
+ open={drawerOpen}
504
+ onClose={() => setDrawerOpen(false)}
505
+ >
506
+ {activeOp && (
507
+ <div>
508
+ <Space wrap style={{ marginBottom: 16 }}>
509
+ <Tag color={STATE_COLORS[activeOp.state] || 'default'}>{activeOp.state}</Tag>
510
+ <Tag color="geekblue">
511
+ {activeOp.businessId}@{activeOp.businessVersion} / {activeOp.action}
512
+ </Tag>
513
+ <span>v{activeOp.stateVersion}</span>
514
+ {activeOp.state === 'WAITING_INPUT' && (
515
+ <Button size="small" type="primary" onClick={() => openResumeModal(activeOp)}>
516
+ {t('Approve / Resume')}
517
+ </Button>
518
+ )}
519
+ </Space>
520
+
521
+ {activeOp.outputPayload?.humanSignOffRequired === true && (
522
+ <Alert
523
+ type="warning"
524
+ showIcon
525
+ message={t('Human Sign-off Required (Trade Finance L/C Policy)')}
526
+ description={t('Automated UCP 600 / ISBP 821 findings require an authorized specialist signature.')}
527
+ style={{ marginBottom: 16 }}
528
+ />
529
+ )}
530
+
531
+ {activeOp.error && (
532
+ <Alert
533
+ type="error"
534
+ showIcon
535
+ message={`${activeOp.error.code}: ${activeOp.error.title}`}
536
+ description={activeOp.error.detail}
537
+ style={{ marginBottom: 16 }}
538
+ />
539
+ )}
540
+
541
+ {activeOp.usage && (
542
+ <>
543
+ <h4>{t('Token & Cost Usage')}</h4>
544
+ <pre style={{ background: '#f5f5f5', padding: 10, borderRadius: 6, fontSize: 12 }}>
545
+ {JSON.stringify(activeOp.usage, null, 2)}
546
+ </pre>
547
+ </>
548
+ )}
549
+
550
+ {activeOp.documentInputCoverage && (
551
+ <>
552
+ <h4>{t('Document Input Coverage (DI-06)')}</h4>
553
+ <pre
554
+ style={{
555
+ background: '#f5f5f5',
556
+ padding: 10,
557
+ borderRadius: 6,
558
+ fontSize: 11,
559
+ maxHeight: 160,
560
+ overflow: 'auto',
561
+ }}
562
+ >
563
+ {JSON.stringify(activeOp.documentInputCoverage, null, 2)}
564
+ </pre>
565
+ </>
566
+ )}
567
+
568
+ <h4>{t('Output Payload')}</h4>
569
+ <pre
570
+ style={{
571
+ background: '#f0f5ff',
572
+ padding: 12,
573
+ borderRadius: 6,
574
+ fontSize: 12,
575
+ maxHeight: 360,
576
+ overflow: 'auto',
577
+ }}
578
+ >
579
+ {activeOp.outputPayload ? JSON.stringify(activeOp.outputPayload, null, 2) : t('(not yet available)')}
580
+ </pre>
581
+ </div>
582
+ )}
583
+ </Drawer>
584
+ </div>
585
+ );
586
+ };
@@ -1,22 +1,28 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+
1
3
  import React from 'react';
2
4
  import { Tabs } from 'antd';
3
5
  import { useT } from '../locale';
4
6
  import { ServiceConfigTab } from './ServiceConfigTab';
7
+ import { OperationsTab } from './OperationsTab';
8
+ import { ApiKeysTab } from './ApiKeysTab';
5
9
  import { EndpointsTab } from './EndpointsTab';
6
10
  import { PipelinesTab } from './PipelinesTab';
7
11
  import { JobsTab } from './JobsTab';
8
12
 
9
- export const PluginSettings = () => {
13
+ export const PluginSettings = ({ embedded = false }: { embedded?: boolean }) => {
10
14
  const t = useT();
11
15
 
12
16
  return (
13
- <div style={{ backgroundColor: 'var(--nb-box-bg)', minHeight: '100vh' }}>
14
- <div style={{ padding: '16px 24px', backgroundColor: '#fff', borderBottom: '1px solid #f0f0f0' }}>
15
- <h2 style={{ margin: 0, fontSize: 20, fontWeight: 500 }}>
16
- {t('Document Understanding - Pipeline Orchestrator')}
17
- </h2>
18
- </div>
19
- <div style={{ padding: '0 24px 24px' }}>
17
+ <div style={{ backgroundColor: 'var(--nb-box-bg)', minHeight: embedded ? undefined : '100vh' }}>
18
+ {!embedded && (
19
+ <div style={{ padding: '16px 24px', backgroundColor: '#fff', borderBottom: '1px solid #f0f0f0' }}>
20
+ <h2 style={{ margin: 0, fontSize: 20, fontWeight: 500 }}>
21
+ {t('Document Understanding - Pipeline Orchestrator')}
22
+ </h2>
23
+ </div>
24
+ )}
25
+ <div style={{ padding: embedded ? 0 : '0 24px 24px' }}>
20
26
  <Tabs
21
27
  defaultActiveKey="config"
22
28
  items={[
@@ -25,6 +31,16 @@ export const PluginSettings = () => {
25
31
  label: t('Service Config'),
26
32
  children: <ServiceConfigTab />,
27
33
  },
34
+ {
35
+ key: 'operations',
36
+ label: t('Operations'),
37
+ children: <OperationsTab />,
38
+ },
39
+ {
40
+ key: 'api-keys',
41
+ label: t('API Keys'),
42
+ children: <ApiKeysTab />,
43
+ },
28
44
  {
29
45
  key: 'endpoints',
30
46
  label: t('Endpoints'),