plugin-document-understanding 1.1.16 → 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.
- package/LICENSE +201 -0
- package/README.md +19 -25
- package/dist/client/169.6888909107c553c3.js +10 -0
- package/dist/client/379.e29f5ced467ce23d.js +10 -0
- package/dist/client/867.3ed3b814115181ca.js +10 -0
- package/dist/client/index.js +1 -1
- package/dist/client-v2/169.53bf1be2ec192f0c.js +10 -0
- package/dist/client-v2/379.e75c4829567cdb89.js +10 -0
- package/dist/client-v2/867.66d7291e95f1de78.js +10 -0
- package/dist/client-v2/index.js +1 -1
- package/dist/externalVersion.js +9 -7
- package/dist/locale/en-US.json +126 -0
- package/dist/locale/vi-VN.json +130 -2
- package/dist/locale/zh-CN.json +127 -1
- package/dist/node_modules/form-data/package.json +1 -1
- package/dist/node_modules/mime-types/package.json +1 -1
- package/dist/server/actions.js +211 -11
- package/dist/server/collections/api-keys.js +55 -0
- package/dist/server/collections/artifacts.js +59 -0
- package/dist/server/collections/config.js +9 -3
- package/dist/server/collections/endpoints.js +3 -0
- package/dist/server/collections/jobs.js +7 -4
- package/dist/server/collections/operations.js +76 -0
- package/dist/server/contracts/du-contracts.js +828 -0
- package/dist/server/dugate-seed.js +98 -340
- package/dist/server/plugin.js +49 -7
- package/dist/server/routes/du-gateway-router.js +443 -0
- package/dist/server/services/ArtifactStorageService.js +459 -0
- package/dist/server/services/AsyncJobManager.js +1 -1
- package/dist/server/services/BuiltinBusinessEngine.js +1223 -0
- package/dist/server/services/DocumentUnderstandingService.js +151 -25
- package/dist/server/services/ExternalDuReworkClient.js +210 -0
- package/dist/server/services/OperationOrchestrator.js +1087 -0
- package/dist/server/services/PipelineExecutor.js +164 -43
- package/dist/server/tools/document-understanding-tool.js +49 -24
- package/dist/server/workflow/DocumentUnderstandingInstruction.js +292 -0
- package/package.json +8 -4
- package/src/client/index.tsx +11 -0
- package/src/client-v2/components/ApiKeysTab.tsx +198 -0
- package/src/client-v2/components/EndpointsTab.tsx +39 -2
- package/src/client-v2/components/JobsTab.tsx +136 -21
- package/src/client-v2/components/OperationsTab.tsx +586 -0
- package/src/client-v2/components/PluginSettings.tsx +12 -0
- package/src/client-v2/components/ServiceConfigTab.tsx +225 -65
- package/src/client-v2/components/__tests__/PluginSettings.test.tsx +4 -0
- package/src/client-v2/locale.ts +1 -8
- package/src/client-v2/models/index.ts +1 -8
- package/src/client-v2/plugin.tsx +12 -8
- package/src/client-v2/types.ts +13 -1
- package/src/client-v2/workflow/DocumentUnderstandingFieldset.tsx +122 -0
- package/src/client-v2/workflow/DocumentUnderstandingInstruction.tsx +49 -0
- package/src/locale/en-US.json +126 -0
- package/src/locale/vi-VN.json +130 -2
- package/src/locale/zh-CN.json +127 -1
- package/src/server/__tests__/actions.test.ts +1 -8
- package/src/server/__tests__/du-rework-gateway.test.ts +462 -0
- package/src/server/__tests__/dugate-integration.test.ts +79 -42
- package/src/server/__tests__/smoke.test.ts +1 -8
- package/src/server/__tests__/upload-security.test.ts +1 -8
- package/src/server/actions.ts +252 -36
- package/src/server/collections/api-keys.ts +35 -0
- package/src/server/collections/artifacts.ts +39 -0
- package/src/server/collections/config.ts +18 -2
- package/src/server/collections/endpoints.ts +12 -0
- package/src/server/collections/jobs.ts +16 -4
- package/src/server/collections/operations.ts +56 -0
- package/src/server/contracts/du-contracts.ts +1026 -0
- package/src/server/dugate-seed.ts +126 -453
- package/src/server/plugin.ts +64 -14
- package/src/server/routes/du-gateway-router.ts +465 -0
- package/src/server/services/ArtifactStorageService.ts +596 -0
- package/src/server/services/AsyncJobManager.ts +10 -1
- package/src/server/services/BuiltinBusinessEngine.ts +1544 -0
- package/src/server/services/DocumentUnderstandingService.ts +186 -44
- package/src/server/services/ExternalDuReworkClient.ts +222 -0
- package/src/server/services/OperationOrchestrator.ts +1359 -0
- package/src/server/services/PipelineExecutor.ts +245 -108
- package/src/server/tools/document-understanding-tool.ts +63 -45
- package/src/server/types.ts +101 -16
- package/src/server/workflow/DocumentUnderstandingInstruction.ts +308 -0
- package/dist/client/345.277fbb2b97424db5.js +0 -10
- package/dist/client-v2/345.2fa9834b46dd4531.js +0 -10
|
@@ -1,11 +1,4 @@
|
|
|
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
|
-
*/
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
9
2
|
|
|
10
3
|
import { createMockServer, type MockServer } from '@nocobase/test';
|
|
11
4
|
import { afterAll, beforeAll, beforeEach, expect, it, vi } from 'vitest';
|
package/src/server/actions.ts
CHANGED
|
@@ -1,16 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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 type { Context } from '@nocobase/actions';
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
|
|
3
|
+
import type { Context, Next } from '@nocobase/actions';
|
|
11
4
|
import { koaMulter } from '@nocobase/utils';
|
|
12
5
|
import { DocumentUnderstandingService } from './services/DocumentUnderstandingService';
|
|
13
6
|
import { FileInput } from './services/ExternalApiClient';
|
|
7
|
+
import { DU_BUSINESS_CATALOG } from './contracts/du-contracts';
|
|
14
8
|
|
|
15
9
|
interface LoggerLike {
|
|
16
10
|
warn: (...args: unknown[]) => void;
|
|
@@ -29,6 +23,11 @@ const uploadDocuments = koaMulter({
|
|
|
29
23
|
limits: { files: 5, fileSize: 20 * 1024 * 1024, fields: 2, fieldSize: 1024 * 1024, parts: 8 },
|
|
30
24
|
}).any();
|
|
31
25
|
|
|
26
|
+
const uploadOperationDocuments = koaMulter({
|
|
27
|
+
storage: koaMulter.memoryStorage(),
|
|
28
|
+
limits: { files: 20, fileSize: 64 * 1024 * 1024, fields: 10, fieldSize: 2 * 1024 * 1024 },
|
|
29
|
+
}).any();
|
|
30
|
+
|
|
32
31
|
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
33
32
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
34
33
|
}
|
|
@@ -37,69 +36,269 @@ export const defineActions = (plugin: DocumentUnderstandingPluginLike) => {
|
|
|
37
36
|
const service = plugin.service;
|
|
38
37
|
|
|
39
38
|
return {
|
|
40
|
-
async getConfig(ctx: Context, next:
|
|
39
|
+
async getConfig(ctx: Context, next: Next) {
|
|
41
40
|
ctx.body = await service.getConfigForClient();
|
|
42
41
|
await next();
|
|
43
42
|
},
|
|
44
43
|
|
|
45
|
-
async updateConfig(ctx: Context, next:
|
|
44
|
+
async updateConfig(ctx: Context, next: Next) {
|
|
46
45
|
const { values } = ctx.action.params;
|
|
47
46
|
await service.updateConfig(values);
|
|
48
47
|
ctx.body = await service.getConfig();
|
|
49
48
|
await next();
|
|
50
49
|
},
|
|
51
50
|
|
|
52
|
-
async
|
|
51
|
+
async getHealth(ctx: Context, next: Next) {
|
|
52
|
+
ctx.body = await service.getGatewayHealth();
|
|
53
|
+
await next();
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
async listLlmServices(ctx: Context, next: Next) {
|
|
57
|
+
await service.ensureInitialized();
|
|
58
|
+
ctx.body = await service.orchestrator.builtinEngine.listAvailableLlmServices();
|
|
59
|
+
await next();
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
async listCatalog(ctx: Context, next: Next) {
|
|
63
|
+
ctx.body = DU_BUSINESS_CATALOG;
|
|
64
|
+
await next();
|
|
65
|
+
},
|
|
66
|
+
|
|
67
|
+
async syncCatalog(ctx: Context, next: Next) {
|
|
68
|
+
ctx.body = await service.syncCatalog();
|
|
69
|
+
await next();
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
async listApiKeys(ctx: Context, next: Next) {
|
|
73
|
+
await service.ensureInitialized();
|
|
74
|
+
ctx.body = await service.orchestrator.listApiKeys();
|
|
75
|
+
await next();
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
async issueApiKey(ctx: Context, next: Next) {
|
|
79
|
+
await service.ensureInitialized();
|
|
80
|
+
const { values } = ctx.action.params;
|
|
81
|
+
if (!isRecord(values)) {
|
|
82
|
+
ctx.throw(400, ctx.t('Invalid API key payload.', { ns: 'plugin-document-understanding' }));
|
|
83
|
+
}
|
|
84
|
+
ctx.set('Cache-Control', 'no-store');
|
|
85
|
+
ctx.body = await service.orchestrator.issueApiKey({
|
|
86
|
+
name: String(values.name || ''),
|
|
87
|
+
tenantId: typeof values.tenantId === 'string' ? values.tenantId : 'default',
|
|
88
|
+
allowedBusinesses: Array.isArray(values.allowedBusinesses) ? values.allowedBusinesses.map(String) : ['*'],
|
|
89
|
+
allowedActions: Array.isArray(values.allowedActions) ? values.allowedActions.map(String) : ['*'],
|
|
90
|
+
requestDefaults: isRecord(values.requestDefaults) ? values.requestDefaults : null,
|
|
91
|
+
lockedFields: Array.isArray(values.lockedFields) ? values.lockedFields.map(String) : null,
|
|
92
|
+
expiresAt: typeof values.expiresAt === 'string' ? values.expiresAt : null,
|
|
93
|
+
userId: ctx.state?.currentUser?.id,
|
|
94
|
+
});
|
|
95
|
+
await next();
|
|
96
|
+
},
|
|
97
|
+
|
|
98
|
+
async revokeApiKey(ctx: Context, next: Next) {
|
|
99
|
+
await service.ensureInitialized();
|
|
100
|
+
const { filterByTk } = ctx.action.params;
|
|
101
|
+
await service.orchestrator.revokeApiKey(Number(filterByTk));
|
|
102
|
+
ctx.body = { message: 'ok' };
|
|
103
|
+
await next();
|
|
104
|
+
},
|
|
105
|
+
|
|
106
|
+
async listOperations(ctx: Context, next: Next) {
|
|
107
|
+
await service.ensureInitialized();
|
|
108
|
+
const { filter } = ctx.action.params;
|
|
109
|
+
const filterObj = isRecord(filter) ? filter : {};
|
|
110
|
+
const res = await service.orchestrator.listOperations({
|
|
111
|
+
tenantId: typeof filterObj.tenantId === 'string' ? filterObj.tenantId : '*',
|
|
112
|
+
state: typeof filterObj.state === 'string' ? filterObj.state : undefined,
|
|
113
|
+
businessId: typeof filterObj.businessId === 'string' ? filterObj.businessId : undefined,
|
|
114
|
+
action: typeof filterObj.action === 'string' ? filterObj.action : undefined,
|
|
115
|
+
limit: 50,
|
|
116
|
+
});
|
|
117
|
+
ctx.body = res.items;
|
|
118
|
+
await next();
|
|
119
|
+
},
|
|
120
|
+
|
|
121
|
+
async getOperation(ctx: Context, next: Next) {
|
|
122
|
+
await service.ensureInitialized();
|
|
123
|
+
const { filterByTk } = ctx.action.params;
|
|
124
|
+
const op = await service.orchestrator.getOperationRecordOrThrow('*', String(filterByTk));
|
|
125
|
+
ctx.body = {
|
|
126
|
+
...service.orchestrator.toOperationView(op),
|
|
127
|
+
outputPayload: op.outputPayload ?? null,
|
|
128
|
+
resultEnvelope: op.resultEnvelope ?? null,
|
|
129
|
+
};
|
|
130
|
+
await next();
|
|
131
|
+
},
|
|
132
|
+
|
|
133
|
+
async submitOperation(ctx: Context, next: Next) {
|
|
134
|
+
await service.ensureInitialized();
|
|
135
|
+
let payload: unknown = ctx.action.params.values;
|
|
136
|
+
const uploadedArtifactIds: string[] = [];
|
|
137
|
+
|
|
138
|
+
if (ctx.request.is('multipart/form-data')) {
|
|
139
|
+
await uploadOperationDocuments(ctx, async () => undefined);
|
|
140
|
+
payload = ctx.request.body;
|
|
141
|
+
const files: unknown = (ctx.request as typeof ctx.request & { files?: unknown }).files;
|
|
142
|
+
if (Array.isArray(files)) {
|
|
143
|
+
for (const file of files) {
|
|
144
|
+
if (isRecord(file) && Buffer.isBuffer(file.buffer)) {
|
|
145
|
+
const art = await service.orchestrator.artifactStorage.createReadyArtifactFromBuffer({
|
|
146
|
+
tenantId: 'default',
|
|
147
|
+
fileName: String(file.originalname || 'document.bin'),
|
|
148
|
+
mimeType: String(file.mimetype || 'application/octet-stream'),
|
|
149
|
+
buffer: file.buffer,
|
|
150
|
+
userId: ctx.state?.currentUser?.id,
|
|
151
|
+
});
|
|
152
|
+
uploadedArtifactIds.push(art.artifactId);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (!isRecord(payload)) {
|
|
159
|
+
ctx.throw(400, ctx.t('Invalid operation payload.', { ns: 'plugin-document-understanding' }));
|
|
160
|
+
}
|
|
161
|
+
const businessId = String(payload.businessId || 'document-core');
|
|
162
|
+
const action = String(payload.action || 'ingest');
|
|
163
|
+
let inputObj: unknown = payload.input ?? {};
|
|
164
|
+
if (typeof inputObj === 'string') {
|
|
165
|
+
try {
|
|
166
|
+
inputObj = JSON.parse(inputObj);
|
|
167
|
+
} catch {
|
|
168
|
+
ctx.throw(400, ctx.t('Invalid JSON input.', { ns: 'plugin-document-understanding' }));
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
let docSel: unknown = payload.documentSelection;
|
|
172
|
+
if (typeof docSel === 'string' && docSel.trim()) {
|
|
173
|
+
try {
|
|
174
|
+
docSel = JSON.parse(docSel);
|
|
175
|
+
} catch {
|
|
176
|
+
ctx.throw(400, ctx.t('Invalid JSON input.', { ns: 'plugin-document-understanding' }));
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const explicitArtifacts = Array.isArray(payload.artifacts)
|
|
181
|
+
? (payload.artifacts as Array<{ artifactId: string }>)
|
|
182
|
+
: [];
|
|
183
|
+
const mergedArtifacts = [
|
|
184
|
+
...explicitArtifacts,
|
|
185
|
+
...uploadedArtifactIds.map((artifactId) => ({ artifactId, role: 'input' as const })),
|
|
186
|
+
];
|
|
187
|
+
|
|
188
|
+
ctx.body = await service.orchestrator.submitOperation({
|
|
189
|
+
principal: {
|
|
190
|
+
kind: 'nocobase_user',
|
|
191
|
+
tenantId: typeof payload.tenantId === 'string' ? payload.tenantId : 'default',
|
|
192
|
+
userId: ctx.state?.currentUser?.id,
|
|
193
|
+
allowedBusinesses: ['*'],
|
|
194
|
+
allowedActions: ['*'],
|
|
195
|
+
},
|
|
196
|
+
businessId,
|
|
197
|
+
action,
|
|
198
|
+
submission: {
|
|
199
|
+
input: isRecord(inputObj) ? inputObj : {},
|
|
200
|
+
artifacts: mergedArtifacts,
|
|
201
|
+
documentSelection: isRecord(docSel) ? (docSel as never) : undefined,
|
|
202
|
+
},
|
|
203
|
+
});
|
|
204
|
+
await next();
|
|
205
|
+
},
|
|
206
|
+
|
|
207
|
+
async cancelOperation(ctx: Context, next: Next) {
|
|
208
|
+
await service.ensureInitialized();
|
|
209
|
+
const { filterByTk } = ctx.action.params;
|
|
210
|
+
ctx.body = await service.orchestrator.cancelOperation('*', String(filterByTk));
|
|
211
|
+
await next();
|
|
212
|
+
},
|
|
213
|
+
|
|
214
|
+
async resumeOperation(ctx: Context, next: Next) {
|
|
215
|
+
await service.ensureInitialized();
|
|
216
|
+
const { filterByTk, values } = ctx.action.params;
|
|
217
|
+
const body = isRecord(values) ? values : {};
|
|
218
|
+
const input = isRecord(body.input) ? body.input : body;
|
|
219
|
+
const currentUser = ctx.state?.currentUser as
|
|
220
|
+
| { email?: string; username?: string; nickname?: string }
|
|
221
|
+
| undefined;
|
|
222
|
+
const resumedBy = currentUser?.email || currentUser?.username || currentUser?.nickname;
|
|
223
|
+
ctx.body = await service.orchestrator.resumeOperation({
|
|
224
|
+
tenantId: '*',
|
|
225
|
+
operationId: String(filterByTk),
|
|
226
|
+
waitId: typeof body.waitId === 'string' ? body.waitId : undefined,
|
|
227
|
+
expectedStateVersion: body.expectedStateVersion !== undefined ? Number(body.expectedStateVersion) : undefined,
|
|
228
|
+
input,
|
|
229
|
+
resumedBy,
|
|
230
|
+
});
|
|
231
|
+
await next();
|
|
232
|
+
},
|
|
233
|
+
|
|
234
|
+
async getUsageSummary(ctx: Context, next: Next) {
|
|
235
|
+
await service.ensureInitialized();
|
|
236
|
+
const now = new Date();
|
|
237
|
+
const defaultFrom = new Date(now.getTime() - 30 * 24 * 60 * 60 * 1000).toISOString();
|
|
238
|
+
const from = typeof ctx.action.params.from === 'string' ? ctx.action.params.from : defaultFrom;
|
|
239
|
+
const to =
|
|
240
|
+
typeof ctx.action.params.to === 'string'
|
|
241
|
+
? ctx.action.params.to
|
|
242
|
+
: new Date(now.getTime() + 60_000).toISOString();
|
|
243
|
+
ctx.body = await service.orchestrator.getUsageSummary({
|
|
244
|
+
tenantId: '*',
|
|
245
|
+
from,
|
|
246
|
+
to,
|
|
247
|
+
});
|
|
248
|
+
await next();
|
|
249
|
+
},
|
|
250
|
+
|
|
251
|
+
async listEndpoints(ctx: Context, next: Next) {
|
|
53
252
|
ctx.body = await service.listEndpoints();
|
|
54
253
|
await next();
|
|
55
254
|
},
|
|
56
255
|
|
|
57
|
-
async createEndpoint(ctx: Context, next:
|
|
256
|
+
async createEndpoint(ctx: Context, next: Next) {
|
|
58
257
|
const { values } = ctx.action.params;
|
|
59
258
|
ctx.body = await service.createEndpoint(values);
|
|
60
259
|
await next();
|
|
61
260
|
},
|
|
62
261
|
|
|
63
|
-
async updateEndpoint(ctx: Context, next:
|
|
262
|
+
async updateEndpoint(ctx: Context, next: Next) {
|
|
64
263
|
const { filterByTk, values } = ctx.action.params;
|
|
65
264
|
await service.updateEndpoint(Number(filterByTk), values);
|
|
66
265
|
ctx.body = { message: 'ok' };
|
|
67
266
|
await next();
|
|
68
267
|
},
|
|
69
268
|
|
|
70
|
-
async deleteEndpoint(ctx: Context, next:
|
|
269
|
+
async deleteEndpoint(ctx: Context, next: Next) {
|
|
71
270
|
const { filterByTk } = ctx.action.params;
|
|
72
271
|
await service.deleteEndpoint(Number(filterByTk));
|
|
73
272
|
ctx.body = { message: 'ok' };
|
|
74
273
|
await next();
|
|
75
274
|
},
|
|
76
275
|
|
|
77
|
-
async listPipelines(ctx: Context, next:
|
|
276
|
+
async listPipelines(ctx: Context, next: Next) {
|
|
78
277
|
ctx.body = await service.listPipelines();
|
|
79
278
|
await next();
|
|
80
279
|
},
|
|
81
280
|
|
|
82
|
-
async createPipeline(ctx: Context, next:
|
|
281
|
+
async createPipeline(ctx: Context, next: Next) {
|
|
83
282
|
const { values } = ctx.action.params;
|
|
84
283
|
ctx.body = await service.createPipeline(values);
|
|
85
284
|
await next();
|
|
86
285
|
},
|
|
87
286
|
|
|
88
|
-
async updatePipeline(ctx: Context, next:
|
|
287
|
+
async updatePipeline(ctx: Context, next: Next) {
|
|
89
288
|
const { filterByTk, values } = ctx.action.params;
|
|
90
289
|
await service.updatePipeline(Number(filterByTk), values);
|
|
91
290
|
ctx.body = { message: 'ok' };
|
|
92
291
|
await next();
|
|
93
292
|
},
|
|
94
293
|
|
|
95
|
-
async deletePipeline(ctx: Context, next:
|
|
294
|
+
async deletePipeline(ctx: Context, next: Next) {
|
|
96
295
|
const { filterByTk } = ctx.action.params;
|
|
97
296
|
await service.deletePipeline(Number(filterByTk));
|
|
98
297
|
ctx.body = { message: 'ok' };
|
|
99
298
|
await next();
|
|
100
299
|
},
|
|
101
300
|
|
|
102
|
-
async executePipeline(ctx: Context, next:
|
|
301
|
+
async executePipeline(ctx: Context, next: Next) {
|
|
103
302
|
let values: unknown = ctx.action.params.values;
|
|
104
303
|
const multipartFiles: FileInput[] = [];
|
|
105
304
|
if (ctx.request.is('multipart/form-data')) {
|
|
@@ -144,33 +343,50 @@ export const defineActions = (plugin: DocumentUnderstandingPluginLike) => {
|
|
|
144
343
|
await next();
|
|
145
344
|
},
|
|
146
345
|
|
|
147
|
-
async getJobStatus(ctx: Context, next:
|
|
346
|
+
async getJobStatus(ctx: Context, next: Next) {
|
|
148
347
|
const { filterByTk } = ctx.action.params;
|
|
149
348
|
ctx.body = await service.getJobStatus(Number(filterByTk));
|
|
150
349
|
await next();
|
|
151
350
|
},
|
|
152
351
|
|
|
153
|
-
async listJobs(ctx: Context, next:
|
|
352
|
+
async listJobs(ctx: Context, next: Next) {
|
|
154
353
|
const { filter } = ctx.action.params;
|
|
155
354
|
ctx.body = await service.listJobs(filter);
|
|
156
355
|
await next();
|
|
157
356
|
},
|
|
158
357
|
|
|
159
|
-
async
|
|
160
|
-
const
|
|
161
|
-
|
|
358
|
+
async cancelJob(ctx: Context, next: Next) {
|
|
359
|
+
const { filterByTk } = ctx.action.params;
|
|
360
|
+
ctx.body = await service.cancelJob(Number(filterByTk));
|
|
361
|
+
await next();
|
|
362
|
+
},
|
|
363
|
+
|
|
364
|
+
async resumeJob(ctx: Context, next: Next) {
|
|
365
|
+
const { filterByTk, values } = ctx.action.params;
|
|
366
|
+
const body = isRecord(values) ? values : {};
|
|
367
|
+
const currentUser = ctx.state?.currentUser as { email?: string; username?: string } | undefined;
|
|
368
|
+
ctx.body = await service.resumeJob(Number(filterByTk), body, currentUser?.email || currentUser?.username);
|
|
369
|
+
await next();
|
|
370
|
+
},
|
|
371
|
+
|
|
372
|
+
async webhookCallback(ctx: Context, next: Next) {
|
|
373
|
+
const legacySig = ctx.get('x-webhook-signature') || undefined;
|
|
374
|
+
const duSig = ctx.get('x-du-signature') || undefined;
|
|
375
|
+
const duTimestamp = ctx.get('x-du-timestamp') || undefined;
|
|
376
|
+
const duDeliveryId = ctx.get('x-du-delivery-id') || undefined;
|
|
377
|
+
const rawPayload = ctx.action.params.values || ctx.request.body;
|
|
162
378
|
try {
|
|
163
|
-
await service.handleWebhook(
|
|
379
|
+
await service.handleWebhook(isRecord(rawPayload) ? rawPayload : {}, legacySig, {
|
|
380
|
+
signature: duSig,
|
|
381
|
+
timestamp: duTimestamp,
|
|
382
|
+
deliveryId: duDeliveryId,
|
|
383
|
+
});
|
|
164
384
|
ctx.body = { received: true };
|
|
165
|
-
} catch (err:
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
} else {
|
|
171
|
-
ctx.status = 400;
|
|
172
|
-
ctx.body = { error: err.message };
|
|
173
|
-
}
|
|
385
|
+
} catch (err: unknown) {
|
|
386
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
387
|
+
plugin.app.logger.warn(`Webhook callback error: ${msg}`);
|
|
388
|
+
ctx.status = msg.includes('signature') ? 401 : 400;
|
|
389
|
+
ctx.body = { error: msg };
|
|
174
390
|
}
|
|
175
391
|
await next();
|
|
176
392
|
},
|
|
@@ -0,0 +1,35 @@
|
|
|
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 { CollectionOptions } from '@nocobase/database';
|
|
11
|
+
|
|
12
|
+
export default {
|
|
13
|
+
name: 'doc_understanding_api_keys',
|
|
14
|
+
title: 'Document Understanding API Keys',
|
|
15
|
+
fields: [
|
|
16
|
+
{ type: 'string', name: 'name', length: 200 },
|
|
17
|
+
{ type: 'string', name: 'keyPrefix', length: 32 },
|
|
18
|
+
{ type: 'string', name: 'keyHash', unique: true, length: 128 },
|
|
19
|
+
{ type: 'string', name: 'tenantId', length: 100, defaultValue: 'default' },
|
|
20
|
+
{ type: 'json', name: 'allowedBusinesses' },
|
|
21
|
+
{ type: 'json', name: 'allowedActions' },
|
|
22
|
+
{ type: 'json', name: 'requestDefaults' },
|
|
23
|
+
{ type: 'json', name: 'lockedFields' },
|
|
24
|
+
{ type: 'string', name: 'status', length: 20, defaultValue: 'active' },
|
|
25
|
+
{ type: 'date', name: 'expiresAt' },
|
|
26
|
+
{ type: 'date', name: 'lastUsedAt' },
|
|
27
|
+
{
|
|
28
|
+
type: 'belongsTo',
|
|
29
|
+
name: 'createdBy',
|
|
30
|
+
target: 'users',
|
|
31
|
+
foreignKey: 'createdById',
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
indexes: [{ fields: ['tenantId'] }, { fields: ['status'] }],
|
|
35
|
+
} as CollectionOptions;
|
|
@@ -0,0 +1,39 @@
|
|
|
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 { CollectionOptions } from '@nocobase/database';
|
|
11
|
+
|
|
12
|
+
export default {
|
|
13
|
+
name: 'doc_understanding_artifacts',
|
|
14
|
+
title: 'Document Understanding Artifacts',
|
|
15
|
+
fields: [
|
|
16
|
+
{ type: 'string', name: 'artifactId', unique: true, length: 64 },
|
|
17
|
+
{ type: 'string', name: 'tenantId', length: 100, defaultValue: 'default' },
|
|
18
|
+
{ type: 'string', name: 'operationId', length: 64 },
|
|
19
|
+
{ type: 'string', name: 'role', length: 30, defaultValue: 'input' },
|
|
20
|
+
{ type: 'string', name: 'state', length: 20, defaultValue: 'UPLOADING' },
|
|
21
|
+
{ type: 'string', name: 'fileName', length: 500 },
|
|
22
|
+
{ type: 'string', name: 'mimeType', length: 150 },
|
|
23
|
+
{ type: 'integer', name: 'sizeBytes', defaultValue: 0 },
|
|
24
|
+
{ type: 'string', name: 'hashSha256', length: 64 },
|
|
25
|
+
{ type: 'string', name: 'storagePath', length: 1000 },
|
|
26
|
+
{ type: 'string', name: 'idempotencyKey', length: 200 },
|
|
27
|
+
{
|
|
28
|
+
type: 'belongsTo',
|
|
29
|
+
name: 'createdBy',
|
|
30
|
+
target: 'users',
|
|
31
|
+
foreignKey: 'createdById',
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
indexes: [
|
|
35
|
+
{ fields: ['tenantId', 'artifactId'] },
|
|
36
|
+
{ fields: ['operationId'] },
|
|
37
|
+
{ fields: ['tenantId', 'idempotencyKey'] },
|
|
38
|
+
],
|
|
39
|
+
} as CollectionOptions;
|
|
@@ -1,12 +1,20 @@
|
|
|
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
|
+
|
|
1
10
|
import { CollectionOptions } from '@nocobase/database';
|
|
2
11
|
|
|
3
12
|
export default {
|
|
4
13
|
name: 'doc_understanding_config',
|
|
5
14
|
title: 'Document Understanding Config',
|
|
6
|
-
// Model name can be explicitly generated by NocoBase, but we define collection fields.
|
|
7
15
|
fields: [
|
|
8
16
|
{ type: 'string', name: 'baseUrl', length: 500 },
|
|
9
|
-
{ type: 'string', name: 'authType', length: 20 },
|
|
17
|
+
{ type: 'string', name: 'authType', length: 20 },
|
|
10
18
|
{ type: 'string', name: 'authKey', length: 500 },
|
|
11
19
|
{ type: 'string', name: 'authHeaderName', length: 100 },
|
|
12
20
|
{ type: 'integer', name: 'defaultTimeout', defaultValue: 30000 },
|
|
@@ -14,5 +22,13 @@ export default {
|
|
|
14
22
|
{ type: 'integer', name: 'pollInterval', defaultValue: 5000 },
|
|
15
23
|
{ type: 'integer', name: 'pollTimeout', defaultValue: 300000 },
|
|
16
24
|
{ type: 'string', name: 'webhookSecret', length: 500 },
|
|
25
|
+
{ type: 'string', name: 'engineMode', length: 30, defaultValue: 'builtin' },
|
|
26
|
+
{ type: 'string', name: 'llmService', length: 120 },
|
|
27
|
+
{ type: 'string', name: 'llmModel', length: 120 },
|
|
28
|
+
{ type: 'string', name: 'visionLlmService', length: 120 },
|
|
29
|
+
{ type: 'string', name: 'visionLlmModel', length: 120 },
|
|
30
|
+
{ type: 'integer', name: 'maxFileSizeBytes', defaultValue: 10485760 },
|
|
31
|
+
{ type: 'integer', name: 'maxFilesPerRequest', defaultValue: 20 },
|
|
32
|
+
{ type: 'boolean', name: 'publicGatewayEnabled', defaultValue: true },
|
|
17
33
|
],
|
|
18
34
|
} as CollectionOptions;
|
|
@@ -1,3 +1,12 @@
|
|
|
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
|
+
|
|
1
10
|
import { CollectionOptions } from '@nocobase/database';
|
|
2
11
|
|
|
3
12
|
export default {
|
|
@@ -14,6 +23,9 @@ export default {
|
|
|
14
23
|
{ type: 'string', name: 'fileFieldName', length: 100, defaultValue: 'file' },
|
|
15
24
|
{ type: 'integer', name: 'maxFiles', defaultValue: 1 },
|
|
16
25
|
{ type: 'string', name: 'executionMode', length: 20 },
|
|
26
|
+
{ type: 'string', name: 'protocolMode', length: 30, defaultValue: 'legacy_rest' },
|
|
27
|
+
{ type: 'string', name: 'businessId', length: 100 },
|
|
28
|
+
{ type: 'string', name: 'actionName', length: 100 },
|
|
17
29
|
{ type: 'string', name: 'discriminatorField', length: 50 },
|
|
18
30
|
{ type: 'string', name: 'discriminatorValue', length: 100 },
|
|
19
31
|
{ type: 'string', name: 'syncQueryParam', length: 50 },
|
|
@@ -1,3 +1,12 @@
|
|
|
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
|
+
|
|
1
10
|
import { CollectionOptions } from '@nocobase/database';
|
|
2
11
|
|
|
3
12
|
export default {
|
|
@@ -10,18 +19,18 @@ export default {
|
|
|
10
19
|
target: 'doc_understanding_pipelines',
|
|
11
20
|
foreignKey: 'pipelineId',
|
|
12
21
|
},
|
|
13
|
-
{ type: 'string', name: 'status', length:
|
|
22
|
+
{ type: 'string', name: 'status', length: 30, defaultValue: 'pending' },
|
|
14
23
|
{ type: 'json', name: 'input' },
|
|
15
24
|
{ type: 'integer', name: 'currentStep' },
|
|
16
25
|
{ type: 'json', name: 'stepResults' },
|
|
17
26
|
{ type: 'json', name: 'finalResult' },
|
|
18
27
|
{ type: 'text', name: 'error' },
|
|
19
28
|
{ type: 'json', name: 'externalTaskIds' },
|
|
29
|
+
{ type: 'string', name: 'operationId', length: 64 },
|
|
30
|
+
{ type: 'json', name: 'waitState' },
|
|
31
|
+
{ type: 'json', name: 'usage' },
|
|
20
32
|
{ type: 'date', name: 'startedAt' },
|
|
21
33
|
{ type: 'date', name: 'completedAt' },
|
|
22
|
-
// Cluster ownership: which node is executing/polling this job, and until when
|
|
23
|
-
// its lease is valid. Orphaned jobs (owner restarted or lease expired) are
|
|
24
|
-
// failed or re-adopted by the maintenance sweep.
|
|
25
34
|
{ type: 'string', name: 'ownedBy', length: 255 },
|
|
26
35
|
{ type: 'date', name: 'leaseExpiresAt' },
|
|
27
36
|
{
|
|
@@ -38,5 +47,8 @@ export default {
|
|
|
38
47
|
{
|
|
39
48
|
fields: ['leaseExpiresAt'],
|
|
40
49
|
},
|
|
50
|
+
{
|
|
51
|
+
fields: ['operationId'],
|
|
52
|
+
},
|
|
41
53
|
],
|
|
42
54
|
} as CollectionOptions;
|
|
@@ -0,0 +1,56 @@
|
|
|
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 { CollectionOptions } from '@nocobase/database';
|
|
11
|
+
|
|
12
|
+
export default {
|
|
13
|
+
name: 'doc_understanding_operations',
|
|
14
|
+
title: 'Document Understanding Operations',
|
|
15
|
+
fields: [
|
|
16
|
+
{ type: 'string', name: 'operationId', unique: true, length: 64 },
|
|
17
|
+
{ type: 'string', name: 'tenantId', length: 100, defaultValue: 'default' },
|
|
18
|
+
{ type: 'string', name: 'businessId', length: 100 },
|
|
19
|
+
{ type: 'string', name: 'businessVersion', length: 32 },
|
|
20
|
+
{ type: 'string', name: 'action', length: 100 },
|
|
21
|
+
{ type: 'string', name: 'variant', length: 100 },
|
|
22
|
+
{ type: 'string', name: 'state', length: 32, defaultValue: 'ACCEPTED' },
|
|
23
|
+
{ type: 'integer', name: 'stateVersion', defaultValue: 1 },
|
|
24
|
+
{ type: 'string', name: 'correlationId', length: 128 },
|
|
25
|
+
{ type: 'string', name: 'clientReference', length: 255 },
|
|
26
|
+
{ type: 'string', name: 'idempotencyKey', length: 200 },
|
|
27
|
+
{ type: 'string', name: 'requestFingerprint', length: 64 },
|
|
28
|
+
{ type: 'json', name: 'submission' },
|
|
29
|
+
{ type: 'json', name: 'progress' },
|
|
30
|
+
{ type: 'json', name: 'waitState' },
|
|
31
|
+
{ type: 'json', name: 'documentInputPlan' },
|
|
32
|
+
{ type: 'json', name: 'documentInputCoverage' },
|
|
33
|
+
{ type: 'json', name: 'resultEnvelope' },
|
|
34
|
+
{ type: 'json', name: 'outputPayload' },
|
|
35
|
+
{ type: 'json', name: 'usage' },
|
|
36
|
+
{ type: 'json', name: 'warnings' },
|
|
37
|
+
{ type: 'json', name: 'errorProblem' },
|
|
38
|
+
{ type: 'string', name: 'externalOperationId', length: 128 },
|
|
39
|
+
{ type: 'date', name: 'deadlineAt' },
|
|
40
|
+
{ type: 'date', name: 'completedAt' },
|
|
41
|
+
{ type: 'string', name: 'ownedBy', length: 255 },
|
|
42
|
+
{ type: 'date', name: 'leaseExpiresAt' },
|
|
43
|
+
{
|
|
44
|
+
type: 'belongsTo',
|
|
45
|
+
name: 'createdBy',
|
|
46
|
+
target: 'users',
|
|
47
|
+
foreignKey: 'createdById',
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
indexes: [
|
|
51
|
+
{ fields: ['tenantId', 'state'] },
|
|
52
|
+
{ fields: ['tenantId', 'businessId', 'action'] },
|
|
53
|
+
{ fields: ['tenantId', 'idempotencyKey'] },
|
|
54
|
+
{ fields: ['leaseExpiresAt'] },
|
|
55
|
+
],
|
|
56
|
+
} as CollectionOptions;
|