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.
- 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 +10 -8
- 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 +24 -8
- package/src/client-v2/components/ServiceConfigTab.tsx +225 -65
- package/src/client-v2/components/__tests__/PluginSettings.test.tsx +43 -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.e6e484fb1974c3d3.js +0 -10
- package/dist/client-v2/345.a8f28526ac21e02a.js +0 -10
|
@@ -29,381 +29,139 @@ __export(dugate_seed_exports, {
|
|
|
29
29
|
seedDugateEndpoints: () => seedDugateEndpoints
|
|
30
30
|
});
|
|
31
31
|
module.exports = __toCommonJS(dugate_seed_exports);
|
|
32
|
+
var import_du_contracts = require("./contracts/du-contracts");
|
|
32
33
|
const DEFAULT_POLL_INTERVAL = 3e3;
|
|
33
34
|
const DEFAULT_POLL_TIMEOUT = 3e5;
|
|
34
|
-
|
|
35
|
-
taskIdExtractPath: "name",
|
|
36
|
-
taskIdExtractRegex: "operations/([^/]+)",
|
|
37
|
-
pollResultSubpath: "/api/v1/operations/{taskId}",
|
|
38
|
-
pollTaskIdField: "id",
|
|
39
|
-
pollResultField: "result",
|
|
40
|
-
pollStatusField: "metadata.state",
|
|
41
|
-
pollCompletedValue: "SUCCEEDED",
|
|
42
|
-
pollInterval: DEFAULT_POLL_INTERVAL,
|
|
43
|
-
pollTimeout: DEFAULT_POLL_TIMEOUT
|
|
44
|
-
};
|
|
45
|
-
function coreEndpoint(service, discriminatorValue, overrides) {
|
|
46
|
-
const { name, ...rest } = overrides;
|
|
35
|
+
function toEndpointValues(entry, sortOrder) {
|
|
47
36
|
return {
|
|
48
|
-
name,
|
|
49
|
-
subpath: `/api/v1/
|
|
37
|
+
name: entry.endpointName,
|
|
38
|
+
subpath: `/api/v1/businesses/${entry.businessId}/actions/${entry.action}`,
|
|
50
39
|
method: "POST",
|
|
40
|
+
description: entry.description,
|
|
41
|
+
requestBodySchema: entry.inputSchema,
|
|
51
42
|
fileInputMode: "multipart",
|
|
52
43
|
fileFieldName: "files[]",
|
|
53
|
-
maxFiles:
|
|
44
|
+
maxFiles: entry.maxFiles,
|
|
54
45
|
executionMode: "sync",
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
maxFiles: 10,
|
|
73
|
-
executionMode: "sync",
|
|
74
|
-
// Will detect 202 and switch to polling automatically
|
|
75
|
-
discriminatorField: "process",
|
|
76
|
-
discriminatorValue: process,
|
|
77
|
-
syncQueryParam: "sync",
|
|
78
|
-
...asyncConfig,
|
|
79
|
-
...rest
|
|
46
|
+
protocolMode: "builtin_du",
|
|
47
|
+
businessId: entry.businessId,
|
|
48
|
+
actionName: entry.action,
|
|
49
|
+
discriminatorField: entry.discriminatorField || null,
|
|
50
|
+
discriminatorValue: entry.discriminatorValue || null,
|
|
51
|
+
syncQueryParam: null,
|
|
52
|
+
taskIdExtractPath: "operationId",
|
|
53
|
+
taskIdExtractRegex: null,
|
|
54
|
+
pollResultSubpath: "/api/v1/operations/{taskId}",
|
|
55
|
+
pollTaskIdField: "operationId",
|
|
56
|
+
pollResultField: "data",
|
|
57
|
+
pollStatusField: "state",
|
|
58
|
+
pollCompletedValue: "SUCCEEDED",
|
|
59
|
+
pollInterval: DEFAULT_POLL_INTERVAL,
|
|
60
|
+
pollTimeout: DEFAULT_POLL_TIMEOUT,
|
|
61
|
+
enabled: true,
|
|
62
|
+
sortOrder
|
|
80
63
|
};
|
|
81
64
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
fileFieldName: "files[]",
|
|
94
|
-
maxFiles: 5
|
|
95
|
-
}),
|
|
96
|
-
coreEndpoint("ingest", "digitize", {
|
|
97
|
-
name: "dugate-ingest-digitize",
|
|
98
|
-
description: "Digitize handwritten forms, checkboxes.",
|
|
99
|
-
fileFieldName: "files[]",
|
|
100
|
-
maxFiles: 5
|
|
101
|
-
}),
|
|
102
|
-
coreEndpoint("ingest", "split", {
|
|
103
|
-
name: "dugate-ingest-split",
|
|
104
|
-
description: 'Split/merge PDF pages. Use pages parameter (e.g. "1-5").',
|
|
105
|
-
fileFieldName: "file",
|
|
106
|
-
maxFiles: 1
|
|
107
|
-
}),
|
|
108
|
-
// ── extract ──
|
|
109
|
-
coreEndpoint("extract", "invoice", {
|
|
110
|
-
name: "dugate-extract-invoice",
|
|
111
|
-
description: "Extract structured data from Vietnamese VAT invoices / general invoices.",
|
|
112
|
-
fileFieldName: "files[]",
|
|
113
|
-
maxFiles: 5
|
|
114
|
-
}),
|
|
115
|
-
coreEndpoint("extract", "contract", {
|
|
116
|
-
name: "dugate-extract-contract",
|
|
117
|
-
description: "Extract parties, terms, obligations, penalties, signatures from contracts.",
|
|
118
|
-
fileFieldName: "files[]",
|
|
119
|
-
maxFiles: 5
|
|
120
|
-
}),
|
|
121
|
-
coreEndpoint("extract", "id-card", {
|
|
122
|
-
name: "dugate-extract-id-card",
|
|
123
|
-
description: "Extract identity information from CCCD/Passport.",
|
|
124
|
-
fileFieldName: "files[]",
|
|
125
|
-
maxFiles: 5
|
|
126
|
-
}),
|
|
127
|
-
coreEndpoint("extract", "receipt", {
|
|
128
|
-
name: "dugate-extract-receipt",
|
|
129
|
-
description: "Extract merchant, items, totals from receipts.",
|
|
130
|
-
fileFieldName: "files[]",
|
|
131
|
-
maxFiles: 5
|
|
132
|
-
}),
|
|
133
|
-
coreEndpoint("extract", "table", {
|
|
134
|
-
name: "dugate-extract-table",
|
|
135
|
-
description: "Extract all tables from documents as structured data.",
|
|
136
|
-
fileFieldName: "files[]",
|
|
137
|
-
maxFiles: 5
|
|
138
|
-
}),
|
|
139
|
-
coreEndpoint("extract", "custom", {
|
|
140
|
-
name: "dugate-extract-custom",
|
|
141
|
-
description: "Extract custom fields using dynamic schema. Use fields (comma-separated) or schema (JSON Schema string).",
|
|
142
|
-
fileFieldName: "files[]",
|
|
143
|
-
maxFiles: 5
|
|
144
|
-
}),
|
|
145
|
-
// ── analyze ──
|
|
146
|
-
coreEndpoint("analyze", "classify", {
|
|
147
|
-
name: "dugate-analyze-classify",
|
|
148
|
-
description: "Classify documents by taxonomy. Provide categories parameter.",
|
|
149
|
-
maxFiles: 5
|
|
150
|
-
}),
|
|
151
|
-
coreEndpoint("analyze", "sentiment", {
|
|
152
|
-
name: "dugate-analyze-sentiment",
|
|
153
|
-
description: "Analyze document sentiment: positive, negative, neutral.",
|
|
154
|
-
maxFiles: 5
|
|
155
|
-
}),
|
|
156
|
-
coreEndpoint("analyze", "compliance", {
|
|
157
|
-
name: "dugate-analyze-compliance",
|
|
158
|
-
description: "Check document compliance against criteria. Provide criteria parameter (semicolon-separated rules).",
|
|
159
|
-
maxFiles: 5
|
|
160
|
-
}),
|
|
161
|
-
coreEndpoint("analyze", "fact-check", {
|
|
162
|
-
name: "dugate-analyze-fact-check",
|
|
163
|
-
description: "Cross-reference document claims against reference data. Provide reference_data and extract_fields.",
|
|
164
|
-
maxFiles: 5
|
|
165
|
-
}),
|
|
166
|
-
coreEndpoint("analyze", "quality", {
|
|
167
|
-
name: "dugate-analyze-quality",
|
|
168
|
-
description: "Score document writing quality against criteria.",
|
|
169
|
-
maxFiles: 5
|
|
170
|
-
}),
|
|
171
|
-
coreEndpoint("analyze", "risk", {
|
|
172
|
-
name: "dugate-analyze-risk",
|
|
173
|
-
description: "Assess document risk level.",
|
|
174
|
-
maxFiles: 5
|
|
175
|
-
}),
|
|
176
|
-
coreEndpoint("analyze", "summarize-eval", {
|
|
177
|
-
name: "dugate-analyze-summarize-eval",
|
|
178
|
-
description: "Generate expert summary and evaluation of document.",
|
|
179
|
-
maxFiles: 5
|
|
180
|
-
}),
|
|
181
|
-
// ── transform ──
|
|
182
|
-
coreEndpoint("transform", "convert", {
|
|
183
|
-
name: "dugate-transform-convert",
|
|
184
|
-
description: "Convert document format (DOCX -> MD/HTML). Use output_format parameter.",
|
|
185
|
-
fileFieldName: "file",
|
|
186
|
-
maxFiles: 1
|
|
187
|
-
}),
|
|
188
|
-
coreEndpoint("transform", "translate", {
|
|
189
|
-
name: "dugate-transform-translate",
|
|
190
|
-
description: "Translate document to target language. Use target_language and tone parameters.",
|
|
191
|
-
fileFieldName: "file",
|
|
192
|
-
maxFiles: 1
|
|
193
|
-
}),
|
|
194
|
-
coreEndpoint("transform", "rewrite", {
|
|
195
|
-
name: "dugate-transform-rewrite",
|
|
196
|
-
description: "Rewrite/paraphrase document. Use style (academic/executive/simplified/bullet_points) and tone parameters.",
|
|
197
|
-
fileFieldName: "file",
|
|
198
|
-
maxFiles: 1
|
|
199
|
-
}),
|
|
200
|
-
coreEndpoint("transform", "redact", {
|
|
201
|
-
name: "dugate-transform-redact",
|
|
202
|
-
description: "Redact PII from document. Use redact_patterns parameter.",
|
|
203
|
-
fileFieldName: "file",
|
|
204
|
-
maxFiles: 1
|
|
205
|
-
}),
|
|
206
|
-
coreEndpoint("transform", "template", {
|
|
207
|
-
name: "dugate-transform-template",
|
|
208
|
-
description: "Mail merge using template. Use template parameter (JSON).",
|
|
209
|
-
fileFieldName: "file",
|
|
210
|
-
maxFiles: 1
|
|
211
|
-
}),
|
|
212
|
-
// ── generate ──
|
|
213
|
-
coreEndpoint("generate", "summary", {
|
|
214
|
-
name: "dugate-generate-summary",
|
|
215
|
-
description: "Generate condensed summary. Parameters: format (paragraph/bullets/numbered/table/mind_map), max_words, audience.",
|
|
216
|
-
fileFieldName: "files[]",
|
|
217
|
-
maxFiles: 5
|
|
218
|
-
}),
|
|
219
|
-
coreEndpoint("generate", "outline", {
|
|
220
|
-
name: "dugate-generate-outline",
|
|
221
|
-
description: "Extract H1/H2/H3 table of contents.",
|
|
222
|
-
fileFieldName: "files[]",
|
|
223
|
-
maxFiles: 5
|
|
224
|
-
}),
|
|
225
|
-
coreEndpoint("generate", "report", {
|
|
226
|
-
name: "dugate-generate-report",
|
|
227
|
-
description: "Generate expert analysis report.",
|
|
228
|
-
fileFieldName: "files[]",
|
|
229
|
-
maxFiles: 5
|
|
230
|
-
}),
|
|
231
|
-
coreEndpoint("generate", "email", {
|
|
232
|
-
name: "dugate-generate-email",
|
|
233
|
-
description: "Draft email response based on document. Use tone parameter.",
|
|
234
|
-
fileFieldName: "files[]",
|
|
235
|
-
maxFiles: 5
|
|
236
|
-
}),
|
|
237
|
-
coreEndpoint("generate", "minutes", {
|
|
238
|
-
name: "dugate-generate-minutes",
|
|
239
|
-
description: "Generate meeting minutes with action items. Use format parameter.",
|
|
240
|
-
fileFieldName: "files[]",
|
|
241
|
-
maxFiles: 5
|
|
242
|
-
}),
|
|
243
|
-
coreEndpoint("generate", "qa", {
|
|
244
|
-
name: "dugate-generate-qa",
|
|
245
|
-
description: "Ask questions about document content (RAG-like). Use questions parameter (JSON array).",
|
|
246
|
-
fileFieldName: "files[]",
|
|
247
|
-
maxFiles: 5
|
|
248
|
-
}),
|
|
249
|
-
// ── compare ──
|
|
250
|
-
coreEndpoint("compare", "diff", {
|
|
251
|
-
name: "dugate-compare-diff",
|
|
252
|
-
description: "Line-by-line text diff (git-diff style). Requires 2 files via files[]. Use output_format parameter.",
|
|
253
|
-
fileFieldName: "files[]",
|
|
254
|
-
maxFiles: 2
|
|
255
|
-
}),
|
|
256
|
-
coreEndpoint("compare", "semantic", {
|
|
257
|
-
name: "dugate-compare-semantic",
|
|
258
|
-
description: "Semantic/legal comparison. Requires 2 files. Use focus parameter for specific concerns.",
|
|
259
|
-
fileFieldName: "files[]",
|
|
260
|
-
maxFiles: 2
|
|
261
|
-
}),
|
|
262
|
-
coreEndpoint("compare", "version", {
|
|
263
|
-
name: "dugate-compare-version",
|
|
264
|
-
description: "Summarized changelog between versions. Requires 2 files. Use output_format parameter.",
|
|
265
|
-
fileFieldName: "files[]",
|
|
266
|
-
maxFiles: 2
|
|
267
|
-
})
|
|
268
|
-
];
|
|
269
|
-
const WORKFLOW_ENDPOINTS = [
|
|
270
|
-
workflowEndpoint("disbursement", {
|
|
271
|
-
name: "dugate-workflow-disbursement",
|
|
272
|
-
description: "Disbursement reconciliation: classify files, extract data, cross-check resolution, generate disbursement memo.",
|
|
273
|
-
maxFiles: 10
|
|
274
|
-
}),
|
|
275
|
-
workflowEndpoint("lc-checker", {
|
|
276
|
-
name: "dugate-workflow-lc-checker",
|
|
277
|
-
description: "Letter of Credit document checking: validate documents against LC terms, detect discrepancies per UCP 600.",
|
|
278
|
-
maxFiles: 10
|
|
279
|
-
}),
|
|
280
|
-
workflowEndpoint("doc-compare", {
|
|
281
|
-
name: "dugate-workflow-doc-compare",
|
|
282
|
-
description: "Advanced document comparison: OCR, extract TOC, compare sections, generate comparison report. Requires exactly 2 files.",
|
|
283
|
-
maxFiles: 2
|
|
284
|
-
})
|
|
285
|
-
];
|
|
286
|
-
function buildPipelines(epNames) {
|
|
287
|
-
return epNames.map((epName) => ({
|
|
288
|
-
name: epName.replace(/^dugate-/, "").replace(/-/g, " ").replace(/\b\w/g, (c) => c.toUpperCase()),
|
|
289
|
-
description: `Execute the DUGate ${epName.replace(/^dugate-/, "")} profile.`,
|
|
290
|
-
enabled: true,
|
|
291
|
-
steps: [
|
|
292
|
-
{
|
|
293
|
-
stepOrder: 1,
|
|
294
|
-
name: "Call DUGate API",
|
|
295
|
-
endpointName: epName,
|
|
296
|
-
outputAlias: "result",
|
|
297
|
-
inputMapping: {
|
|
298
|
-
file_urls: "$input.file_urls",
|
|
299
|
-
output_format: "$input.output_format",
|
|
300
|
-
language: "$input.language",
|
|
301
|
-
categories: "$input.categories",
|
|
302
|
-
criteria: "$input.criteria",
|
|
303
|
-
reference_data: "$input.reference_data",
|
|
304
|
-
fields: "$input.fields",
|
|
305
|
-
schema: "$input.schema",
|
|
306
|
-
questions: "$input.questions",
|
|
307
|
-
target_language: "$input.target_language",
|
|
308
|
-
tone: "$input.tone",
|
|
309
|
-
style: "$input.style",
|
|
310
|
-
redact_patterns: "$input.redact_patterns",
|
|
311
|
-
template: "$input.template",
|
|
312
|
-
format: "$input.format",
|
|
313
|
-
max_words: "$input.max_words",
|
|
314
|
-
audience: "$input.audience",
|
|
315
|
-
focus: "$input.focus",
|
|
316
|
-
pages: "$input.pages",
|
|
317
|
-
resolution_data: "$input.resolution_data",
|
|
318
|
-
extract_fields: "$input.extract_fields"
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
],
|
|
322
|
-
outputMapping: {
|
|
323
|
-
content: "$step[result].response.content",
|
|
324
|
-
extracted_data: "$step[result].response.extracted_data",
|
|
325
|
-
usage: "$step[result].response.usage"
|
|
326
|
-
}
|
|
327
|
-
}));
|
|
65
|
+
function buildInputMappingFromSchema(entry) {
|
|
66
|
+
const props = entry.inputSchema && typeof entry.inputSchema.properties === "object" && entry.inputSchema.properties !== null ? entry.inputSchema.properties : {};
|
|
67
|
+
const mapping = {};
|
|
68
|
+
for (const key of Object.keys(props)) {
|
|
69
|
+
if (key === entry.discriminatorField) continue;
|
|
70
|
+
mapping[key] = `$input.${key}`;
|
|
71
|
+
}
|
|
72
|
+
if (entry.action !== "ingest" || entry.discriminatorValue !== "split") {
|
|
73
|
+
mapping.pages = "$input.pages";
|
|
74
|
+
}
|
|
75
|
+
return mapping;
|
|
328
76
|
}
|
|
329
77
|
async function seedDugateEndpoints(db) {
|
|
330
78
|
const endpointsRepo = db.getRepository("doc_understanding_endpoints");
|
|
331
79
|
const pipelinesRepo = db.getRepository("doc_understanding_pipelines");
|
|
332
80
|
const stepsRepo = db.getRepository("doc_understanding_pipeline_steps");
|
|
333
|
-
const allEndpoints = [...CORE_ENDPOINTS, ...WORKFLOW_ENDPOINTS];
|
|
334
81
|
const endpointNameToId = /* @__PURE__ */ new Map();
|
|
335
|
-
for (
|
|
336
|
-
const
|
|
337
|
-
|
|
82
|
+
for (let index = 0; index < import_du_contracts.DU_BUSINESS_CATALOG.length; index += 1) {
|
|
83
|
+
const entry = import_du_contracts.DU_BUSINESS_CATALOG[index];
|
|
84
|
+
const values = toEndpointValues(entry, index + 1);
|
|
85
|
+
let existing = await endpointsRepo.findOne({ filter: { name: entry.endpointName } });
|
|
86
|
+
if (!existing && entry.legacyEndpointName) {
|
|
87
|
+
existing = await endpointsRepo.findOne({ filter: { name: entry.legacyEndpointName } });
|
|
88
|
+
}
|
|
89
|
+
let recordId;
|
|
338
90
|
if (existing) {
|
|
339
|
-
await endpointsRepo.update({ filterByTk: existing.id, values
|
|
340
|
-
|
|
91
|
+
await endpointsRepo.update({ filterByTk: existing.id, values });
|
|
92
|
+
recordId = Number(existing.id);
|
|
341
93
|
} else {
|
|
342
|
-
|
|
94
|
+
const created = await endpointsRepo.create({ values });
|
|
95
|
+
recordId = Number(created.id);
|
|
343
96
|
}
|
|
344
|
-
endpointNameToId.set(
|
|
97
|
+
endpointNameToId.set(entry.endpointName, recordId);
|
|
345
98
|
}
|
|
346
|
-
const
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
const
|
|
99
|
+
for (const entry of import_du_contracts.DU_BUSINESS_CATALOG) {
|
|
100
|
+
const endpointId = endpointNameToId.get(entry.endpointName);
|
|
101
|
+
if (!endpointId) continue;
|
|
102
|
+
const description = `[${entry.businessId}@${entry.businessVersion}] ${entry.description}`;
|
|
103
|
+
const inputMapping = buildInputMappingFromSchema(entry);
|
|
104
|
+
const outputMapping = {
|
|
105
|
+
data: "$step[result].response.data",
|
|
106
|
+
markdown: "$step[result].response.markdown",
|
|
107
|
+
text: "$step[result].response.text",
|
|
108
|
+
report: "$step[result].response.report",
|
|
109
|
+
verdict: "$step[result].response.verdict",
|
|
110
|
+
discrepancies: "$step[result].response.discrepancies",
|
|
111
|
+
usage: "$step[result].response.usage"
|
|
112
|
+
};
|
|
113
|
+
const existingPipeline = await pipelinesRepo.findOne({ filter: { name: entry.pipelineName } });
|
|
350
114
|
if (existingPipeline) {
|
|
351
115
|
await stepsRepo.destroy({ filter: { pipelineId: existingPipeline.id } });
|
|
352
116
|
await pipelinesRepo.update({
|
|
353
117
|
filterByTk: existingPipeline.id,
|
|
354
118
|
values: {
|
|
355
|
-
description
|
|
356
|
-
enabled:
|
|
357
|
-
inputSchema:
|
|
358
|
-
outputMapping
|
|
119
|
+
description,
|
|
120
|
+
enabled: existingPipeline.enabled ?? true,
|
|
121
|
+
inputSchema: entry.inputSchema,
|
|
122
|
+
outputMapping
|
|
359
123
|
}
|
|
360
124
|
});
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
outputAlias: step.outputAlias || null,
|
|
372
|
-
onError: step.onError || "fail",
|
|
373
|
-
retryCount: step.retryCount ?? 0
|
|
374
|
-
}
|
|
375
|
-
});
|
|
125
|
+
await stepsRepo.create({
|
|
126
|
+
values: {
|
|
127
|
+
pipelineId: existingPipeline.id,
|
|
128
|
+
stepOrder: 1,
|
|
129
|
+
name: `${entry.businessId}/${entry.action}`,
|
|
130
|
+
endpointId,
|
|
131
|
+
inputMapping,
|
|
132
|
+
outputAlias: "result",
|
|
133
|
+
onError: "fail",
|
|
134
|
+
retryCount: 0
|
|
376
135
|
}
|
|
377
|
-
}
|
|
136
|
+
});
|
|
378
137
|
} else {
|
|
379
138
|
const created = await pipelinesRepo.create({
|
|
380
139
|
values: {
|
|
381
|
-
name:
|
|
382
|
-
description
|
|
383
|
-
enabled:
|
|
384
|
-
inputSchema:
|
|
385
|
-
outputMapping
|
|
140
|
+
name: entry.pipelineName,
|
|
141
|
+
description,
|
|
142
|
+
enabled: true,
|
|
143
|
+
inputSchema: entry.inputSchema,
|
|
144
|
+
outputMapping
|
|
386
145
|
}
|
|
387
146
|
});
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
outputAlias: step.outputAlias || null,
|
|
399
|
-
onError: step.onError || "fail",
|
|
400
|
-
retryCount: step.retryCount ?? 0
|
|
401
|
-
}
|
|
402
|
-
});
|
|
147
|
+
await stepsRepo.create({
|
|
148
|
+
values: {
|
|
149
|
+
pipelineId: created.id,
|
|
150
|
+
stepOrder: 1,
|
|
151
|
+
name: `${entry.businessId}/${entry.action}`,
|
|
152
|
+
endpointId,
|
|
153
|
+
inputMapping,
|
|
154
|
+
outputAlias: "result",
|
|
155
|
+
onError: "fail",
|
|
156
|
+
retryCount: 0
|
|
403
157
|
}
|
|
404
|
-
}
|
|
158
|
+
});
|
|
405
159
|
}
|
|
406
160
|
}
|
|
161
|
+
return {
|
|
162
|
+
endpoints: import_du_contracts.DU_BUSINESS_CATALOG.length,
|
|
163
|
+
pipelines: import_du_contracts.DU_BUSINESS_CATALOG.length
|
|
164
|
+
};
|
|
407
165
|
}
|
|
408
166
|
// Annotate the CommonJS export names for ESM import in node:
|
|
409
167
|
0 && (module.exports = {
|
package/dist/server/plugin.js
CHANGED
|
@@ -36,6 +36,8 @@ var import_DocumentUnderstandingService = require("./services/DocumentUnderstand
|
|
|
36
36
|
var import_actions = require("./actions");
|
|
37
37
|
var import_document_understanding_tool = require("./tools/document-understanding-tool");
|
|
38
38
|
var import_dugate_seed = require("./dugate-seed");
|
|
39
|
+
var import_du_gateway_router = require("./routes/du-gateway-router");
|
|
40
|
+
var import_DocumentUnderstandingInstruction = require("./workflow/DocumentUnderstandingInstruction");
|
|
39
41
|
const isAiManagerLike = (manager) => {
|
|
40
42
|
var _a;
|
|
41
43
|
const candidate = manager;
|
|
@@ -54,7 +56,22 @@ class PluginDocumentUnderstandingServer extends import_server.Plugin {
|
|
|
54
56
|
}
|
|
55
57
|
async load() {
|
|
56
58
|
this.service = new import_DocumentUnderstandingService.DocumentUnderstandingService(this.app, this.db);
|
|
59
|
+
const runtimeState = this.app;
|
|
60
|
+
runtimeState.documentUnderstandingService = this.service;
|
|
61
|
+
this.app.use((0, import_du_gateway_router.createDuDisableBodyParserMiddleware)(), {
|
|
62
|
+
tag: "docUnderstandingDisableBodyParser",
|
|
63
|
+
before: "bodyParser"
|
|
64
|
+
});
|
|
65
|
+
this.app.use(
|
|
66
|
+
(0, import_du_gateway_router.createDuGatewayRouter)(() => this.service),
|
|
67
|
+
{
|
|
68
|
+
tag: "docUnderstandingPublicGateway",
|
|
69
|
+
before: "dataSource",
|
|
70
|
+
after: "dataWrapping"
|
|
71
|
+
}
|
|
72
|
+
);
|
|
57
73
|
this.registerActions();
|
|
74
|
+
this.registerWorkflowInstruction();
|
|
58
75
|
this.registerAITools();
|
|
59
76
|
this.app.on("afterStart", this.registerAIToolsAfterStart);
|
|
60
77
|
this.app.acl.registerSnippet({
|
|
@@ -64,12 +81,24 @@ class PluginDocumentUnderstandingServer extends import_server.Plugin {
|
|
|
64
81
|
}
|
|
65
82
|
registerActions() {
|
|
66
83
|
const actions = (0, import_actions.defineActions)(this);
|
|
67
|
-
const resourceName = "docUnderstanding";
|
|
68
84
|
this.app.resource({
|
|
69
|
-
name:
|
|
85
|
+
name: "docUnderstanding",
|
|
70
86
|
actions: {
|
|
71
87
|
getConfig: actions.getConfig,
|
|
72
88
|
updateConfig: actions.updateConfig,
|
|
89
|
+
getHealth: actions.getHealth,
|
|
90
|
+
listLlmServices: actions.listLlmServices,
|
|
91
|
+
listCatalog: actions.listCatalog,
|
|
92
|
+
syncCatalog: actions.syncCatalog,
|
|
93
|
+
listApiKeys: actions.listApiKeys,
|
|
94
|
+
issueApiKey: actions.issueApiKey,
|
|
95
|
+
revokeApiKey: actions.revokeApiKey,
|
|
96
|
+
listOperations: actions.listOperations,
|
|
97
|
+
getOperation: actions.getOperation,
|
|
98
|
+
submitOperation: actions.submitOperation,
|
|
99
|
+
cancelOperation: actions.cancelOperation,
|
|
100
|
+
resumeOperation: actions.resumeOperation,
|
|
101
|
+
getUsageSummary: actions.getUsageSummary,
|
|
73
102
|
listEndpoints: actions.listEndpoints,
|
|
74
103
|
createEndpoint: actions.createEndpoint,
|
|
75
104
|
updateEndpoint: actions.updateEndpoint,
|
|
@@ -81,16 +110,29 @@ class PluginDocumentUnderstandingServer extends import_server.Plugin {
|
|
|
81
110
|
executePipeline: actions.executePipeline,
|
|
82
111
|
getJobStatus: actions.getJobStatus,
|
|
83
112
|
listJobs: actions.listJobs,
|
|
113
|
+
cancelJob: actions.cancelJob,
|
|
114
|
+
resumeJob: actions.resumeJob,
|
|
84
115
|
webhookCallback: actions.webhookCallback
|
|
85
116
|
}
|
|
86
117
|
});
|
|
87
118
|
}
|
|
119
|
+
registerWorkflowInstruction() {
|
|
120
|
+
var _a, _b, _c, _d;
|
|
121
|
+
try {
|
|
122
|
+
const workflow = ((_b = (_a = this.app.pm) == null ? void 0 : _a.get) == null ? void 0 : _b.call(_a, "workflow")) || ((_d = (_c = this.app.pm) == null ? void 0 : _c.get) == null ? void 0 : _d.call(_c, "@nocobase/plugin-workflow"));
|
|
123
|
+
if (workflow == null ? void 0 : workflow.registerInstruction) {
|
|
124
|
+
workflow.registerInstruction("document-understanding", new import_DocumentUnderstandingInstruction.DocumentUnderstandingWorkflowInstruction(workflow));
|
|
125
|
+
}
|
|
126
|
+
} catch (err) {
|
|
127
|
+
this.app.logger.warn("Document Understanding: skipped workflow instruction registration.", err);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
88
130
|
registerAITools() {
|
|
131
|
+
var _a, _b, _c, _d, _e, _f;
|
|
89
132
|
if (this.aiToolsRegistered) return;
|
|
90
133
|
try {
|
|
91
|
-
const aiManager = this.app.aiManager;
|
|
134
|
+
const aiManager = this.app.aiManager || ((_c = (_b = (_a = this.app.pm) == null ? void 0 : _a.get) == null ? void 0 : _b.call(_a, "@nocobase/plugin-ai")) == null ? void 0 : _c.aiManager) || ((_f = (_e = (_d = this.app.pm) == null ? void 0 : _d.get) == null ? void 0 : _e.call(_d, "ai")) == null ? void 0 : _f.aiManager);
|
|
92
135
|
if (!isAiManagerLike(aiManager)) {
|
|
93
|
-
this.app.logger.warn("Document Understanding: plugin-ai not available, skip AI tool registration.");
|
|
94
136
|
return;
|
|
95
137
|
}
|
|
96
138
|
const runtimeState = this.app;
|
|
@@ -104,7 +146,6 @@ class PluginDocumentUnderstandingServer extends import_server.Plugin {
|
|
|
104
146
|
runtimeState.documentUnderstandingToolProviderRegistered = true;
|
|
105
147
|
}
|
|
106
148
|
this.aiToolsRegistered = true;
|
|
107
|
-
this.app.logger.info("Document Understanding: Dynamic pipeline tools provider registered.");
|
|
108
149
|
} catch (err) {
|
|
109
150
|
this.app.logger.warn("Document Understanding: Failed to register AI tools, continue without it.", err);
|
|
110
151
|
}
|
|
@@ -112,15 +153,16 @@ class PluginDocumentUnderstandingServer extends import_server.Plugin {
|
|
|
112
153
|
async afterStart() {
|
|
113
154
|
try {
|
|
114
155
|
await this.service.initialize({ recoverJobs: true });
|
|
156
|
+
await (0, import_dugate_seed.seedDugateEndpoints)(this.db);
|
|
115
157
|
} catch (err) {
|
|
116
|
-
this.app.logger.warn("Document Understanding
|
|
158
|
+
this.app.logger.warn("Document Understanding startup initialization / catalog sync warning:", err);
|
|
117
159
|
}
|
|
118
160
|
}
|
|
119
161
|
async install() {
|
|
120
162
|
try {
|
|
121
163
|
await (0, import_dugate_seed.seedDugateEndpoints)(this.db);
|
|
122
164
|
} catch (err) {
|
|
123
|
-
this.app.logger.warn("Document Understanding:
|
|
165
|
+
this.app.logger.warn("Document Understanding: catalog seed data could not be installed.", err);
|
|
124
166
|
}
|
|
125
167
|
}
|
|
126
168
|
async afterEnable() {
|