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,48 @@
1
+ import React from 'react';
2
+ import { Tabs } from 'antd';
3
+ import { useT } from '../locale';
4
+ import { ServiceConfigTab } from './ServiceConfigTab';
5
+ import { EndpointsTab } from './EndpointsTab';
6
+ import { PipelinesTab } from './PipelinesTab';
7
+ import { JobsTab } from './JobsTab';
8
+
9
+ export const PluginSettings = () => {
10
+ const t = useT();
11
+
12
+ 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' }}>
20
+ <Tabs
21
+ defaultActiveKey="config"
22
+ items={[
23
+ {
24
+ key: 'config',
25
+ label: t('Service Config'),
26
+ children: <ServiceConfigTab />,
27
+ },
28
+ {
29
+ key: 'endpoints',
30
+ label: t('Endpoints'),
31
+ children: <EndpointsTab />,
32
+ },
33
+ {
34
+ key: 'pipelines',
35
+ label: t('Pipelines'),
36
+ children: <PipelinesTab />,
37
+ },
38
+ {
39
+ key: 'jobs',
40
+ label: t('Jobs history'),
41
+ children: <JobsTab />,
42
+ },
43
+ ]}
44
+ />
45
+ </div>
46
+ </div>
47
+ );
48
+ };
@@ -0,0 +1,122 @@
1
+ import React, { useEffect, useState } from 'react';
2
+ import { Form, Input, Select, Button, message, InputNumber, Spin, Alert, Space } from 'antd';
3
+ import { SaveOutlined, LinkOutlined } from '@ant-design/icons';
4
+ import { useApp } from '@nocobase/client-v2';
5
+
6
+ export const ServiceConfigTab = () => {
7
+ const [form] = Form.useForm();
8
+ const app = useApp();
9
+ const api = app.apiClient;
10
+ const [loading, setLoading] = useState(true);
11
+ const [saving, setSaving] = useState(false);
12
+
13
+ useEffect(() => {
14
+ api
15
+ .request({ url: 'docUnderstanding:getConfig' })
16
+ .then(({ data }) => {
17
+ form.setFieldsValue(data?.data || {});
18
+ setLoading(false);
19
+ })
20
+ .catch(() => setLoading(false));
21
+ }, [api, form]);
22
+
23
+ const onFinish = async (values: any) => {
24
+ setSaving(true);
25
+ try {
26
+ await api.request({
27
+ url: 'docUnderstanding:updateConfig',
28
+ method: 'POST',
29
+ data: values,
30
+ });
31
+ message.success('Configuration saved successfully');
32
+ } catch {
33
+ message.error('Failed to save config');
34
+ } finally {
35
+ setSaving(false);
36
+ }
37
+ };
38
+
39
+ if (loading) return <Spin style={{ marginTop: 40 }} />;
40
+
41
+ return (
42
+ <Form form={form} layout="vertical" onFinish={onFinish} style={{ maxWidth: 600 }}>
43
+ <Alert
44
+ message="Service Connection"
45
+ description="Configure the connection to your external document processing service. All endpoints will use this base URL and authentication."
46
+ type="info"
47
+ showIcon
48
+ style={{ marginBottom: 24 }}
49
+ />
50
+
51
+ <Form.Item
52
+ name="baseUrl"
53
+ label="Base URL"
54
+ rules={[{ required: true, message: 'Base URL is required' }]}
55
+ help="The root URL of your document processing API"
56
+ >
57
+ <Input prefix={<LinkOutlined />} placeholder="http://my-ocr-service:8000" />
58
+ </Form.Item>
59
+
60
+ <Form.Item name="authType" label="Authentication Type" initialValue="none">
61
+ <Select>
62
+ <Select.Option value="none">None</Select.Option>
63
+ <Select.Option value="api_key">API Key</Select.Option>
64
+ <Select.Option value="bearer">Bearer Token</Select.Option>
65
+ <Select.Option value="custom_header">Custom Header</Select.Option>
66
+ </Select>
67
+ </Form.Item>
68
+
69
+ <Form.Item noStyle dependencies={['authType']}>
70
+ {() => {
71
+ const type = form.getFieldValue('authType');
72
+ if (type === 'none') return null;
73
+ return (
74
+ <>
75
+ {type === 'custom_header' && (
76
+ <Form.Item name="authHeaderName" label="Custom Header Name" rules={[{ required: true }]}>
77
+ <Input placeholder="X-Api-Key" />
78
+ </Form.Item>
79
+ )}
80
+ <Form.Item
81
+ name="authKey"
82
+ label={type === 'bearer' ? 'Bearer Token' : 'API Key'}
83
+ rules={[{ required: true }]}
84
+ >
85
+ <Input.Password placeholder="Enter key or token" />
86
+ </Form.Item>
87
+ </>
88
+ );
89
+ }}
90
+ </Form.Item>
91
+
92
+ <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '0 16px' }}>
93
+ <Form.Item name="defaultTimeout" label="Request Timeout (ms)" initialValue={30000}>
94
+ <InputNumber style={{ width: '100%' }} min={1000} step={1000} />
95
+ </Form.Item>
96
+ <Form.Item name="defaultRetries" label="Default Retries" initialValue={2}>
97
+ <InputNumber style={{ width: '100%' }} min={0} max={10} />
98
+ </Form.Item>
99
+ <Form.Item name="pollInterval" label="Poll Interval (ms)" initialValue={5000}>
100
+ <InputNumber style={{ width: '100%' }} min={1000} step={1000} />
101
+ </Form.Item>
102
+ <Form.Item name="pollTimeout" label="Poll Timeout (ms)" initialValue={300000}>
103
+ <InputNumber style={{ width: '100%' }} min={5000} step={5000} />
104
+ </Form.Item>
105
+ </div>
106
+
107
+ <Form.Item
108
+ name="webhookSecret"
109
+ label="Webhook Secret"
110
+ help="Used to verify HMAC-SHA256 signatures on incoming webhook callbacks"
111
+ >
112
+ <Input.Password placeholder="Optional: secret for webhook signature verification" />
113
+ </Form.Item>
114
+
115
+ <Form.Item>
116
+ <Button type="primary" htmlType="submit" icon={<SaveOutlined />} loading={saving}>
117
+ Save Configuration
118
+ </Button>
119
+ </Form.Item>
120
+ </Form>
121
+ );
122
+ };
@@ -0,0 +1,21 @@
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
+ import { tExpr as _tExpr, useFlowEngine } from '@nocobase/flow-engine';
11
+ // @ts-ignore
12
+ import pkg from './../../package.json';
13
+
14
+ export function useT() {
15
+ const engine = useFlowEngine();
16
+ return (str: string) => engine.context.t(str, { ns: [pkg.name, 'client'] });
17
+ }
18
+
19
+ export function tExpr(key: string) {
20
+ return _tExpr(key, { ns: [pkg.name, 'client'] });
21
+ }
@@ -6,6 +6,7 @@
6
6
  * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
+
9
10
  import { ModelConstructor } from '@nocobase/flow-engine';
10
- declare const _default: Record<string, ModelConstructor>;
11
- export default _default;
11
+
12
+ export default {} as Record<string, ModelConstructor>;
@@ -0,0 +1,21 @@
1
+ import { Application, Plugin } from '@nocobase/client-v2';
2
+
3
+ export class PluginDocumentUnderstandingClient extends Plugin<Record<string, never>, Application> {
4
+ async load() {
5
+ this.pluginSettingsManager.addMenuItem({
6
+ key: 'document-understanding',
7
+ title: this.t('Document Understanding'),
8
+ icon: 'FileSearchOutlined',
9
+ aclSnippet: 'pm.document-understanding',
10
+ });
11
+
12
+ this.pluginSettingsManager.addPageTabItem({
13
+ menuKey: 'document-understanding',
14
+ key: 'index',
15
+ title: this.t('Document Understanding'),
16
+ componentLoader: () => import('./components/PluginSettings'),
17
+ });
18
+ }
19
+ }
20
+
21
+ export default PluginDocumentUnderstandingClient;
@@ -0,0 +1,121 @@
1
+ {
2
+ "Document Understanding": "Document Understanding",
3
+ "Document Understanding - Pipeline Orchestrator": "Document Understanding - Pipeline Orchestrator",
4
+ "Service Connection": "Service Connection",
5
+ "Service Config": "Service Config",
6
+ "Endpoints": "Endpoints",
7
+ "Pipelines": "Pipelines",
8
+ "Jobs history": "Jobs history",
9
+ "Base URL": "Base URL",
10
+ "Authentication Type": "Authentication Type",
11
+ "Auth Type": "Auth Type",
12
+ "None": "None",
13
+ "API Key": "API Key",
14
+ "Bearer Token": "Bearer Token",
15
+ "Custom Header": "Custom Header",
16
+ "Custom Header Name": "Custom Header Name",
17
+ "API Key / Token": "API Key / Token",
18
+ "Request Timeout (ms)": "Request Timeout (ms)",
19
+ "Default Retries": "Default Retries",
20
+ "Poll Interval (ms)": "Poll Interval (ms)",
21
+ "Poll Timeout (ms)": "Poll Timeout (ms)",
22
+ "Webhook Secret": "Webhook Secret",
23
+ "Save Configuration": "Save Configuration",
24
+ "Configuration saved successfully": "Configuration saved successfully",
25
+ "Failed to save config": "Failed to save config",
26
+ "Add Endpoint": "Add Endpoint",
27
+ "Edit Endpoint": "Edit Endpoint",
28
+ "Basic": "Basic",
29
+ "File Input": "File Input",
30
+ "Async Config": "Async Config",
31
+ "Schema": "Schema",
32
+ "Custom Headers": "Custom Headers",
33
+ "Unique Name": "Unique Name",
34
+ "Subpath": "Subpath",
35
+ "HTTP Method": "HTTP Method",
36
+ "Execution Mode": "Execution Mode",
37
+ "Synchronous": "Synchronous",
38
+ "Polling": "Polling",
39
+ "Webhook": "Webhook",
40
+ "File Input Mode": "File Input Mode",
41
+ "Multipart Upload": "Multipart Upload",
42
+ "Base64 in JSON": "Base64 in JSON",
43
+ "Max Files": "Max Files",
44
+ "Task ID Field": "Task ID Field",
45
+ "Poll Result Subpath": "Poll Result Subpath",
46
+ "Result Field": "Result Field",
47
+ "Status Field": "Status Field",
48
+ "Completed Value": "Completed Value",
49
+ "Poll Task ID Field": "Poll Task ID Field",
50
+ "Poll Result Field": "Poll Result Field",
51
+ "Poll Status Field": "Poll Status Field",
52
+ "Poll Completed Value": "Poll Completed Value",
53
+ "Request Body Schema (JSON Schema)": "Request Body Schema (JSON Schema)",
54
+ "Response Schema (JSON Schema)": "Response Schema (JSON Schema)",
55
+ "Additional Headers": "Additional Headers",
56
+ "Add Header": "Add Header",
57
+ "Enabled": "Enabled",
58
+ "Action": "Action",
59
+ "Edit": "Edit",
60
+ "Delete": "Delete",
61
+ "Deleted": "Deleted",
62
+ "Saved": "Saved",
63
+ "Add Pipeline": "Add Pipeline",
64
+ "Edit Pipeline": "Edit Pipeline",
65
+ "New Pipeline": "New Pipeline",
66
+ "Pipeline Name": "Pipeline Name",
67
+ "Description": "Description",
68
+ "Pipeline Steps": "Pipeline Steps",
69
+ "Add Step": "Add Step",
70
+ "Add First Step": "Add First Step",
71
+ "No steps yet": "No steps yet",
72
+ "Step Name": "Step Name",
73
+ "Endpoint": "Endpoint",
74
+ "Output Alias": "Output Alias",
75
+ "On Error": "On Error",
76
+ "Fail": "Fail",
77
+ "Skip": "Skip",
78
+ "Retry": "Retry",
79
+ "Input Mapping (JSON)": "Input Mapping (JSON)",
80
+ "Condition (optional JSON)": "Condition (optional JSON)",
81
+ "Input Schema (JSON Schema)": "Input Schema (JSON Schema)",
82
+ "Output Mapping (JSON)": "Output Mapping (JSON)",
83
+ "Advanced: Input Schema & Output Mapping": "Advanced: Input Schema & Output Mapping",
84
+ "AI Tool": "AI Tool",
85
+ "Active": "Active",
86
+ "Inactive": "Inactive",
87
+ "Steps": "Steps",
88
+ "Job Details": "Job Details",
89
+ "Status": "Status",
90
+ "Current Step": "Current Step",
91
+ "Started": "Started",
92
+ "Completed": "Completed",
93
+ "Error": "Error",
94
+ "Input": "Input",
95
+ "Step Results": "Step Results",
96
+ "Final Result": "Final Result",
97
+ "External Task IDs": "External Task IDs",
98
+ "View": "View",
99
+ "Refresh": "Refresh",
100
+ "Filter by status": "Filter by status",
101
+ "Filter by pipeline": "Filter by pipeline",
102
+ "Pipeline": "Pipeline",
103
+ "ID": "ID",
104
+ "Name": "Name",
105
+ "Method": "Method",
106
+ "Execution": "Execution",
107
+ "File": "File",
108
+ "Done": "Done",
109
+ "Pending": "Pending",
110
+ "Running": "Running",
111
+ "Failed": "Failed",
112
+ "Timeout": "Timeout",
113
+ "All steps must have a name": "All steps must have a name",
114
+ "Step output aliases must be unique": "Step output aliases must be unique",
115
+ "Delete this endpoint?": "Delete this endpoint?",
116
+ "Delete this pipeline?": "Delete this pipeline?",
117
+ "Remove step?": "Remove step?",
118
+ "skip on error": "skip on error",
119
+ "conditional": "conditional",
120
+ "Invalid JSON": "Invalid JSON"
121
+ }
@@ -0,0 +1,121 @@
1
+ {
2
+ "Document Understanding": "Hiểu Tài Liệu",
3
+ "Document Understanding - Pipeline Orchestrator": "Hiểu Tài Liệu - Bộ Điều Phối Pipeline",
4
+ "Service Connection": "Kết nối dịch vụ",
5
+ "Service Config": "Cấu hình dịch vụ",
6
+ "Endpoints": "Endpoints",
7
+ "Pipelines": "Pipelines",
8
+ "Jobs history": "Lịch sử công việc",
9
+ "Base URL": "URL gốc",
10
+ "Authentication Type": "Loại xác thực",
11
+ "Auth Type": "Loại xác thực",
12
+ "None": "Không",
13
+ "API Key": "Khóa API",
14
+ "Bearer Token": "Token Bearer",
15
+ "Custom Header": "Header tùy chỉnh",
16
+ "Custom Header Name": "Tên Header tùy chỉnh",
17
+ "API Key / Token": "Khóa API / Token",
18
+ "Request Timeout (ms)": "Timeout request (ms)",
19
+ "Default Retries": "Số lần thử lại mặc định",
20
+ "Poll Interval (ms)": "Khoảng thời gian poll (ms)",
21
+ "Poll Timeout (ms)": "Timeout poll (ms)",
22
+ "Webhook Secret": "Mã bí mật Webhook",
23
+ "Save Configuration": "Lưu cấu hình",
24
+ "Configuration saved successfully": "Đã lưu cấu hình thành công",
25
+ "Failed to save config": "Lưu cấu hình thất bại",
26
+ "Add Endpoint": "Thêm Endpoint",
27
+ "Edit Endpoint": "Sửa Endpoint",
28
+ "Basic": "Cơ bản",
29
+ "File Input": "File đầu vào",
30
+ "Async Config": "Cấu hình bất đồng bộ",
31
+ "Schema": "Schema",
32
+ "Custom Headers": "Headers tùy chỉnh",
33
+ "Unique Name": "Tên duy nhất",
34
+ "Subpath": "Đường dẫn con",
35
+ "HTTP Method": "Phương thức HTTP",
36
+ "Execution Mode": "Chế độ thực thi",
37
+ "Synchronous": "Đồng bộ",
38
+ "Polling": "Polling",
39
+ "Webhook": "Webhook",
40
+ "File Input Mode": "Chế độ nhập file",
41
+ "Multipart Upload": "Upload Multipart",
42
+ "Base64 in JSON": "Base64 trong JSON",
43
+ "Max Files": "Số file tối đa",
44
+ "Task ID Field": "Trường Task ID",
45
+ "Poll Result Subpath": "Đường dẫn poll kết quả",
46
+ "Result Field": "Trường kết quả",
47
+ "Status Field": "Trường trạng thái",
48
+ "Completed Value": "Giá trị hoàn thành",
49
+ "Poll Task ID Field": "Trường Task ID khi poll",
50
+ "Poll Result Field": "Trường kết quả khi poll",
51
+ "Poll Status Field": "Trường trạng thái khi poll",
52
+ "Poll Completed Value": "Giá trị hoàn thành khi poll",
53
+ "Request Body Schema (JSON Schema)": "Schema body request (JSON Schema)",
54
+ "Response Schema (JSON Schema)": "Schema response (JSON Schema)",
55
+ "Additional Headers": "Headers bổ sung",
56
+ "Add Header": "Thêm Header",
57
+ "Enabled": "Bật",
58
+ "Action": "Hành động",
59
+ "Edit": "Sửa",
60
+ "Delete": "Xóa",
61
+ "Deleted": "Đã xóa",
62
+ "Saved": "Đã lưu",
63
+ "Add Pipeline": "Thêm Pipeline",
64
+ "Edit Pipeline": "Sửa Pipeline",
65
+ "New Pipeline": "Pipeline mới",
66
+ "Pipeline Name": "Tên Pipeline",
67
+ "Description": "Mô tả",
68
+ "Pipeline Steps": "Các bước Pipeline",
69
+ "Add Step": "Thêm bước",
70
+ "Add First Step": "Thêm bước đầu tiên",
71
+ "No steps yet": "Chưa có bước nào",
72
+ "Step Name": "Tên bước",
73
+ "Endpoint": "Endpoint",
74
+ "Output Alias": "Alias đầu ra",
75
+ "On Error": "Khi lỗi",
76
+ "Fail": "Dừng",
77
+ "Skip": "Bỏ qua",
78
+ "Retry": "Thử lại",
79
+ "Input Mapping (JSON)": "Ánh xạ đầu vào (JSON)",
80
+ "Condition (optional JSON)": "Điều kiện (JSON, tùy chọn)",
81
+ "Input Schema (JSON Schema)": "Schema đầu vào (JSON Schema)",
82
+ "Output Mapping (JSON)": "Ánh xạ đầu ra (JSON)",
83
+ "Advanced: Input Schema & Output Mapping": "Nâng cao: Schema đầu vào & Ánh xạ đầu ra",
84
+ "AI Tool": "Công cụ AI",
85
+ "Active": "Đang hoạt động",
86
+ "Inactive": "Không hoạt động",
87
+ "Steps": "Các bước",
88
+ "Job Details": "Chi tiết công việc",
89
+ "Status": "Trạng thái",
90
+ "Current Step": "Bước hiện tại",
91
+ "Started": "Bắt đầu",
92
+ "Completed": "Hoàn thành",
93
+ "Error": "Lỗi",
94
+ "Input": "Dữ liệu đầu vào",
95
+ "Step Results": "Kết quả từng bước",
96
+ "Final Result": "Kết quả cuối cùng",
97
+ "External Task IDs": "ID tác vụ ngoài",
98
+ "View": "Xem",
99
+ "Refresh": "Làm mới",
100
+ "Filter by status": "Lọc theo trạng thái",
101
+ "Filter by pipeline": "Lọc theo pipeline",
102
+ "Pipeline": "Pipeline",
103
+ "ID": "ID",
104
+ "Name": "Tên",
105
+ "Method": "Phương thức",
106
+ "Execution": "Thực thi",
107
+ "File": "File",
108
+ "Done": "Xong",
109
+ "Pending": "Đang chờ",
110
+ "Running": "Đang chạy",
111
+ "Failed": "Thất bại",
112
+ "Timeout": "Hết thời gian",
113
+ "All steps must have a name": "Tất cả các bước phải có tên",
114
+ "Step output aliases must be unique": "Alias đầu ra của các bước phải khác nhau",
115
+ "Delete this endpoint?": "Xóa endpoint này?",
116
+ "Delete this pipeline?": "Xóa pipeline này?",
117
+ "Remove step?": "Xóa bước này?",
118
+ "skip on error": "bỏ qua khi lỗi",
119
+ "conditional": "có điều kiện",
120
+ "Invalid JSON": "JSON không hợp lệ"
121
+ }
@@ -0,0 +1 @@
1
+ {}
@@ -0,0 +1,98 @@
1
+ import { createMockServer } from '@nocobase/test';
2
+ import PluginDocumentUnderstandingServer from '../plugin';
3
+
4
+ describe('Document Understanding actions', () => {
5
+ let app;
6
+ let agent;
7
+
8
+ beforeEach(async () => {
9
+ app = await createMockServer({
10
+ plugins: ['nocobase', PluginDocumentUnderstandingServer],
11
+ acl: false,
12
+ });
13
+ await app.install();
14
+
15
+ const adminUser = await app.db.getRepository('users').findOne();
16
+ agent = app.agent();
17
+ if (adminUser) {
18
+ await agent.login(adminUser);
19
+ }
20
+ });
21
+
22
+ afterEach(async () => {
23
+ await app?.destroy();
24
+ });
25
+
26
+ it('creates, lists, updates, and deletes endpoints', async () => {
27
+ const createRes = await agent.resource('docUnderstanding').createEndpoint({
28
+ values: {
29
+ name: 'ocr',
30
+ subpath: '/ocr',
31
+ method: 'POST',
32
+ fileInputMode: 'multipart',
33
+ executionMode: 'sync',
34
+ customHeaders: { 'X-Test': '1' },
35
+ enabled: true,
36
+ },
37
+ });
38
+ expect(createRes.status).toBe(200);
39
+ expect(createRes.body.data.name).toBe('ocr');
40
+
41
+ const listRes = await agent.resource('docUnderstanding').listEndpoints();
42
+ expect(listRes.status).toBe(200);
43
+ expect(listRes.body.data).toHaveLength(1);
44
+
45
+ const id = createRes.body.data.id;
46
+ const updateRes = await agent.resource('docUnderstanding').updateEndpoint({
47
+ filterByTk: id,
48
+ values: { description: 'OCR endpoint' },
49
+ });
50
+ expect(updateRes.status).toBe(200);
51
+
52
+ const deleteRes = await agent.resource('docUnderstanding').deleteEndpoint({ filterByTk: id });
53
+ expect(deleteRes.status).toBe(200);
54
+ });
55
+
56
+ it('rejects invalid custom header names', async () => {
57
+ const res = await agent.resource('docUnderstanding').createEndpoint({
58
+ values: {
59
+ name: 'bad-header',
60
+ subpath: '/bad',
61
+ method: 'POST',
62
+ fileInputMode: 'none',
63
+ executionMode: 'sync',
64
+ customHeaders: { 'Bad Header': '1' },
65
+ enabled: true,
66
+ },
67
+ });
68
+
69
+ expect(res.status).toBeGreaterThanOrEqual(400);
70
+ });
71
+
72
+ it('rejects duplicate pipeline step output aliases', async () => {
73
+ const endpointRes = await agent.resource('docUnderstanding').createEndpoint({
74
+ values: {
75
+ name: 'extract',
76
+ subpath: '/extract',
77
+ method: 'POST',
78
+ fileInputMode: 'none',
79
+ executionMode: 'sync',
80
+ enabled: true,
81
+ },
82
+ });
83
+
84
+ const endpointId = endpointRes.body.data.id;
85
+ const res = await agent.resource('docUnderstanding').createPipeline({
86
+ values: {
87
+ name: 'duplicate-aliases',
88
+ enabled: true,
89
+ steps: [
90
+ { stepOrder: 1, name: 'first', endpointId, outputAlias: 'same', onError: 'fail', retryCount: 0 },
91
+ { stepOrder: 2, name: 'second', endpointId, outputAlias: 'same', onError: 'fail', retryCount: 0 },
92
+ ],
93
+ },
94
+ });
95
+
96
+ expect(res.status).toBeGreaterThanOrEqual(400);
97
+ });
98
+ });
@@ -0,0 +1,33 @@
1
+ import { mkdirSync, rmSync, writeFileSync } from 'fs';
2
+ import { resolve } from 'path';
3
+ import { resolveUploadFilePath } from '../services/PipelineExecutor';
4
+
5
+ describe('PipelineExecutor upload path resolution', () => {
6
+ const uploadsRoot = resolve(process.cwd(), 'storage', 'uploads');
7
+ const samplePath = resolve(uploadsRoot, 'du-test', 'sample.txt');
8
+
9
+ beforeEach(() => {
10
+ mkdirSync(resolve(uploadsRoot, 'du-test'), { recursive: true });
11
+ writeFileSync(samplePath, 'sample');
12
+ });
13
+
14
+ afterEach(() => {
15
+ rmSync(resolve(uploadsRoot, 'du-test'), { recursive: true, force: true });
16
+ });
17
+
18
+ it('resolves upload-relative paths inside the upload root', () => {
19
+ expect(resolveUploadFilePath('uploads/du-test/sample.txt')).toBe(samplePath);
20
+ expect(resolveUploadFilePath('/uploads/du-test/sample.txt')).toBe(samplePath);
21
+ expect(resolveUploadFilePath('storage/uploads/du-test/sample.txt')).toBe(samplePath);
22
+ });
23
+
24
+ it('rejects traversal and absolute filesystem paths', () => {
25
+ expect(resolveUploadFilePath('uploads/../package.json')).toBeNull();
26
+ expect(resolveUploadFilePath('storage/uploads/../../package.json')).toBeNull();
27
+ expect(resolveUploadFilePath(resolve(process.cwd(), 'package.json'))).toBeNull();
28
+ });
29
+
30
+ it('maps upload URLs by pathname only', () => {
31
+ expect(resolveUploadFilePath('https://example.com/uploads/du-test/sample.txt?token=secret')).toBe(samplePath);
32
+ });
33
+ });
@@ -0,0 +1,55 @@
1
+ import { createMockServer } from '@nocobase/test';
2
+ import PluginDocumentUnderstandingServer from '../plugin';
3
+
4
+ describe('Document Understanding plugin smoke', () => {
5
+ let app;
6
+ let agent;
7
+
8
+ beforeEach(async () => {
9
+ app = await createMockServer({
10
+ plugins: ['nocobase', PluginDocumentUnderstandingServer],
11
+ acl: false,
12
+ });
13
+ await app.install();
14
+
15
+ const adminUser = await app.db.getRepository('users').findOne();
16
+ agent = app.agent();
17
+ if (adminUser) {
18
+ await agent.login(adminUser);
19
+ }
20
+ });
21
+
22
+ afterEach(async () => {
23
+ await app?.destroy();
24
+ });
25
+
26
+ it('registers collections', async () => {
27
+ for (const name of [
28
+ 'doc_understanding_config',
29
+ 'doc_understanding_endpoints',
30
+ 'doc_understanding_pipelines',
31
+ 'doc_understanding_pipeline_steps',
32
+ 'doc_understanding_jobs',
33
+ ]) {
34
+ expect(app.db.getCollection(name)).toBeTruthy();
35
+ }
36
+ });
37
+
38
+ it('returns and updates default config through actions', async () => {
39
+ const getRes = await agent.resource('docUnderstanding').getConfig();
40
+ expect(getRes.status).toBe(200);
41
+ expect(getRes.body.data.baseUrl).toBe('http://localhost:8000');
42
+ expect(getRes.body.data.authType).toBe('none');
43
+
44
+ const updateRes = await agent.resource('docUnderstanding').updateConfig({
45
+ values: {
46
+ baseUrl: 'https://processor.example.com',
47
+ authType: 'bearer',
48
+ authKey: 'test-token',
49
+ },
50
+ });
51
+ expect(updateRes.status).toBe(200);
52
+ expect(updateRes.body.data.baseUrl).toBe('https://processor.example.com');
53
+ expect(updateRes.body.data.authType).toBe('bearer');
54
+ });
55
+ });