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.
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 +9 -7
  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 +12 -0
  44. package/src/client-v2/components/ServiceConfigTab.tsx +225 -65
  45. package/src/client-v2/components/__tests__/PluginSettings.test.tsx +4 -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.277fbb2b97424db5.js +0 -10
  82. package/dist/client-v2/345.2fa9834b46dd4531.js +0 -10
@@ -0,0 +1,828 @@
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
+ var __defProp = Object.defineProperty;
11
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
+ var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __export = (target, all) => {
15
+ for (var name in all)
16
+ __defProp(target, name, { get: all[name], enumerable: true });
17
+ };
18
+ var __copyProps = (to, from, except, desc) => {
19
+ if (from && typeof from === "object" || typeof from === "function") {
20
+ for (let key of __getOwnPropNames(from))
21
+ if (!__hasOwnProp.call(to, key) && key !== except)
22
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
+ }
24
+ return to;
25
+ };
26
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
+ var du_contracts_exports = {};
28
+ __export(du_contracts_exports, {
29
+ DU_BUSINESS_CATALOG: () => DU_BUSINESS_CATALOG,
30
+ DU_OPERATION_STATES: () => DU_OPERATION_STATES,
31
+ LC_RULESET_ID: () => LC_RULESET_ID,
32
+ LC_RULESET_VERSION: () => LC_RULESET_VERSION,
33
+ TERMINAL_OPERATION_STATES: () => TERMINAL_OPERATION_STATES,
34
+ UCP600_ISBP821_RULES: () => UCP600_ISBP821_RULES,
35
+ VALID_LC_RULE_IDS: () => VALID_LC_RULE_IDS,
36
+ createProblem: () => createProblem,
37
+ expandPageRanges: () => expandPageRanges,
38
+ parsePageRangeString: () => parsePageRangeString
39
+ });
40
+ module.exports = __toCommonJS(du_contracts_exports);
41
+ const DU_OPERATION_STATES = [
42
+ "PENDING_INGESTION",
43
+ "ACCEPTED",
44
+ "QUEUED",
45
+ "RUNNING",
46
+ "WAITING_CHILDREN",
47
+ "WAITING_INPUT",
48
+ "RETRY_PENDING",
49
+ "CANCEL_REQUESTED",
50
+ "SUCCEEDED",
51
+ "FAILED",
52
+ "CANCELLED",
53
+ "TIMED_OUT"
54
+ ];
55
+ const TERMINAL_OPERATION_STATES = /* @__PURE__ */ new Set([
56
+ "SUCCEEDED",
57
+ "FAILED",
58
+ "CANCELLED",
59
+ "TIMED_OUT"
60
+ ]);
61
+ function createProblem(status, code, title, options = {}) {
62
+ return {
63
+ type: `urn:du:error:${code.toLowerCase()}`,
64
+ title,
65
+ status,
66
+ code,
67
+ ...options.detail ? { detail: options.detail } : {},
68
+ ...options.correlationId ? { correlationId: options.correlationId } : {},
69
+ ...options.errors && options.errors.length > 0 ? { errors: options.errors } : {}
70
+ };
71
+ }
72
+ function parsePageRangeString(spec, maxPages = 500) {
73
+ const trimmed = spec.trim();
74
+ if (!trimmed || trimmed.toLowerCase() === "all") {
75
+ return [];
76
+ }
77
+ const ranges = [];
78
+ let selectedCount = 0;
79
+ for (const rawPart of trimmed.split(",")) {
80
+ const part = rawPart.trim();
81
+ if (!part) continue;
82
+ const match = /^(\d+)(?:\s*-\s*(\d+))?$/.exec(part);
83
+ if (!match) {
84
+ throw new Error(`Invalid page range segment "${part}". Expected "1-5" or "1,3-5".`);
85
+ }
86
+ const from = Number(match[1]);
87
+ const to = match[2] ? Number(match[2]) : from;
88
+ if (!Number.isSafeInteger(from) || !Number.isSafeInteger(to) || from < 1 || to < from) {
89
+ throw new Error(`Invalid page range "${part}": page numbers must be >= 1 and from <= to.`);
90
+ }
91
+ selectedCount += to - from + 1;
92
+ if (selectedCount > maxPages) {
93
+ throw new Error(`Selected page count (${selectedCount}) exceeds maximum allowed (${maxPages}).`);
94
+ }
95
+ ranges.push({ from, to });
96
+ }
97
+ return ranges;
98
+ }
99
+ function expandPageRanges(spec, totalPages) {
100
+ if (totalPages <= 0) return [];
101
+ if (spec.kind === "all") {
102
+ return Array.from({ length: totalPages }, (_, idx) => idx + 1);
103
+ }
104
+ const pageSet = /* @__PURE__ */ new Set();
105
+ for (const range of spec.ranges) {
106
+ if (range.from < 1 || range.to < range.from || range.to > totalPages) {
107
+ throw new Error(`Requested page range ${range.from}-${range.to} exceeds document page count (${totalPages}).`);
108
+ }
109
+ for (let p = range.from; p <= range.to; p += 1) {
110
+ pageSet.add(p);
111
+ }
112
+ }
113
+ return Array.from(pageSet).sort((a, b) => a - b);
114
+ }
115
+ const LC_RULESET_ID = "lc-rules-base";
116
+ const LC_RULESET_VERSION = "ucp600-isbp821-v1";
117
+ const UCP600_ISBP821_RULES = [
118
+ {
119
+ ruleId: "UCP600-ART14-A",
120
+ standard: "UCP 600",
121
+ title: "Standard for Examination of Documents",
122
+ description: "Nominated/issuing bank must determine on the basis of the documents alone whether they appear on their face to constitute a complying presentation."
123
+ },
124
+ {
125
+ ruleId: "UCP600-ART14-D",
126
+ standard: "UCP 600",
127
+ title: "Non-conflicting Data Across Documents",
128
+ description: "Data in a document, when read in context with the credit, the document itself and international standard banking practice, need not be identical to, but must not conflict with, data in that document, any other stipulated document or the credit."
129
+ },
130
+ {
131
+ ruleId: "UCP600-ART14-E",
132
+ standard: "UCP 600",
133
+ title: "Description of Goods in Non-Invoice Documents",
134
+ description: "In documents other than the commercial invoice, the description of the goods, services or performance, if stated, may be in general terms not conflicting with their description in the credit."
135
+ },
136
+ {
137
+ ruleId: "UCP600-ART14-I",
138
+ standard: "UCP 600",
139
+ title: "Document Dates vs Presentation Date",
140
+ description: "A document may be dated prior to the issuance date of the credit, but must not be dated later than its date of presentation."
141
+ },
142
+ {
143
+ ruleId: "UCP600-ART18-A",
144
+ standard: "UCP 600",
145
+ title: "Commercial Invoice Issuer & Beneficiary",
146
+ description: "A commercial invoice must appear to have been issued by the beneficiary, made out in the name of the applicant, and in the same currency as the credit."
147
+ },
148
+ {
149
+ ruleId: "UCP600-ART18-B",
150
+ standard: "UCP 600",
151
+ title: "Commercial Invoice Amount Within Credit Limit",
152
+ description: "Commercial invoice amount must not exceed the amount permitted by the credit."
153
+ },
154
+ {
155
+ ruleId: "UCP600-ART18-C",
156
+ standard: "UCP 600",
157
+ title: "Exact Goods Description in Commercial Invoice",
158
+ description: "The description of the goods, services or performance in a commercial invoice must correspond with that appearing in the credit."
159
+ },
160
+ {
161
+ ruleId: "UCP600-ART20-A-I",
162
+ standard: "UCP 600",
163
+ title: "Bill of Lading Carrier Identification & Signature",
164
+ description: "A bill of lading must indicate the name of the carrier and be signed by the carrier, master, or named agent.",
165
+ requiresVisualCheck: true
166
+ },
167
+ {
168
+ ruleId: "UCP600-ART20-A-II",
169
+ standard: "UCP 600",
170
+ title: "Bill of Lading Shipped On Board Notation & Date",
171
+ description: "Bill of lading must indicate that the goods have been shipped on board a named vessel at the port of loading stated in the credit with an on-board date."
172
+ },
173
+ {
174
+ ruleId: "UCP600-ART20-A-III",
175
+ standard: "UCP 600",
176
+ title: "Port of Loading and Discharge Match",
177
+ description: "Bill of lading must indicate shipment from the port of loading to the port of discharge stated in the credit."
178
+ },
179
+ {
180
+ ruleId: "UCP600-ART27",
181
+ standard: "UCP 600",
182
+ title: "Clean Transport Document",
183
+ description: "A bank will only accept a clean transport document bearing no clause or notation expressly declaring a defective condition of the goods or packaging."
184
+ },
185
+ {
186
+ ruleId: "UCP600-ART28-A",
187
+ standard: "UCP 600",
188
+ title: "Insurance Document Signature & Coverage",
189
+ description: "Insurance document must appear to be issued and signed by an insurance company, underwriter or their agent/proxy, and cover at least 110% of CIF/CIP value when unspecified.",
190
+ requiresVisualCheck: true
191
+ },
192
+ {
193
+ ruleId: "ISBP821-A35",
194
+ standard: "ISBP 821",
195
+ title: "Signatures, Stamps and Endorsements",
196
+ description: "Required manual/facsimile signatures, stamps, or bill of lading endorsements must be visually verifiable when stipulated.",
197
+ requiresVisualCheck: true
198
+ },
199
+ {
200
+ ruleId: "ISBP821-C3",
201
+ standard: "ISBP 821",
202
+ title: "Invoice Value & Trade Terms Consistency",
203
+ description: "Incoterms and invoice line items/totals must match the credit terms without unpermitted charges."
204
+ }
205
+ ];
206
+ const VALID_LC_RULE_IDS = new Set(UCP600_ISBP821_RULES.map((r) => r.ruleId));
207
+ function coreSchema(discriminatorField, discriminatorValue, extraProperties, required = []) {
208
+ return {
209
+ type: "object",
210
+ properties: {
211
+ [discriminatorField]: { type: "string", enum: [discriminatorValue], default: discriminatorValue },
212
+ ...extraProperties
213
+ },
214
+ required: [discriminatorField, ...required]
215
+ };
216
+ }
217
+ const DU_BUSINESS_CATALOG = [
218
+ // ── 1. document-core / ingest (4) ──────────────────────────────────────────────
219
+ {
220
+ endpointName: "du-ingest-parse",
221
+ legacyEndpointName: "dugate-ingest-parse",
222
+ pipelineName: "Ingest Parse",
223
+ businessId: "document-core",
224
+ businessVersion: "2.0.0",
225
+ action: "ingest",
226
+ discriminatorField: "mode",
227
+ discriminatorValue: "parse",
228
+ maxFiles: 10,
229
+ description: "Parse digital documents (PDF, DOCX, XLSX, PPTX, TXT, CSV, HTML) into clean Markdown/text.",
230
+ inputSchema: coreSchema("mode", "parse", {
231
+ language: { type: "string", default: "vi" },
232
+ pages: { type: "string", description: 'Page ranges, e.g. "1-5" or "all"' },
233
+ outputFormat: { type: "string", enum: ["md", "text", "json"], default: "md" }
234
+ })
235
+ },
236
+ {
237
+ endpointName: "du-ingest-ocr",
238
+ legacyEndpointName: "dugate-ingest-ocr",
239
+ pipelineName: "Ingest Ocr",
240
+ businessId: "document-core",
241
+ businessVersion: "2.0.0",
242
+ action: "ingest",
243
+ discriminatorField: "mode",
244
+ discriminatorValue: "ocr",
245
+ maxFiles: 10,
246
+ description: "OCR scanned PDFs and images into Markdown and plain text.",
247
+ inputSchema: coreSchema("mode", "ocr", {
248
+ language: { type: "string", default: "vi" },
249
+ pages: { type: "string", description: 'Page ranges, e.g. "1-5"' },
250
+ outputFormat: { type: "string", enum: ["md", "text"], default: "md" }
251
+ })
252
+ },
253
+ {
254
+ endpointName: "du-ingest-digitize",
255
+ legacyEndpointName: "dugate-ingest-digitize",
256
+ pipelineName: "Ingest Digitize",
257
+ businessId: "document-core",
258
+ businessVersion: "2.0.0",
259
+ action: "ingest",
260
+ discriminatorField: "mode",
261
+ discriminatorValue: "digitize",
262
+ maxFiles: 5,
263
+ description: "Digitize handwritten forms, checkboxes, and structured form fields.",
264
+ inputSchema: coreSchema("mode", "digitize", {
265
+ language: { type: "string", default: "vi" },
266
+ outputFormat: { type: "string", enum: ["md", "json"], default: "json" }
267
+ })
268
+ },
269
+ {
270
+ endpointName: "du-ingest-split",
271
+ legacyEndpointName: "dugate-ingest-split",
272
+ pipelineName: "Ingest Split",
273
+ businessId: "document-core",
274
+ businessVersion: "2.0.0",
275
+ action: "ingest",
276
+ discriminatorField: "mode",
277
+ discriminatorValue: "split",
278
+ maxFiles: 1,
279
+ description: "Split a multi-page document by page ranges (up to 500 selected pages) into separate output artifacts.",
280
+ inputSchema: coreSchema("mode", "split", {
281
+ pages: { type: "string", default: "1-2", description: 'Comma-separated page ranges, e.g. "1-2,3-5"' }
282
+ })
283
+ },
284
+ // ── 2. document-core / extract (6) ─────────────────────────────────────────────
285
+ {
286
+ endpointName: "du-extract-invoice",
287
+ legacyEndpointName: "dugate-extract-invoice",
288
+ pipelineName: "Extract Invoice",
289
+ businessId: "document-core",
290
+ businessVersion: "2.0.0",
291
+ action: "extract",
292
+ discriminatorField: "type",
293
+ discriminatorValue: "invoice",
294
+ maxFiles: 5,
295
+ description: "Extract structured VAT/commercial invoice data (supplier, buyer, invoiceNumber, lineItems, totals).",
296
+ inputSchema: coreSchema("type", "invoice", {
297
+ outputFormat: { type: "string", enum: ["json"], default: "json" }
298
+ })
299
+ },
300
+ {
301
+ endpointName: "du-extract-contract",
302
+ legacyEndpointName: "dugate-extract-contract",
303
+ pipelineName: "Extract Contract",
304
+ businessId: "document-core",
305
+ businessVersion: "2.0.0",
306
+ action: "extract",
307
+ discriminatorField: "type",
308
+ discriminatorValue: "contract",
309
+ maxFiles: 5,
310
+ description: "Extract parties, effectiveDate, value, obligations, and penaltyClauses from contracts.",
311
+ inputSchema: coreSchema("type", "contract", {
312
+ outputFormat: { type: "string", enum: ["json"], default: "json" }
313
+ })
314
+ },
315
+ {
316
+ endpointName: "du-extract-id-card",
317
+ legacyEndpointName: "dugate-extract-id-card",
318
+ pipelineName: "Extract Id Card",
319
+ businessId: "document-core",
320
+ businessVersion: "2.0.0",
321
+ action: "extract",
322
+ discriminatorField: "type",
323
+ discriminatorValue: "id-card",
324
+ maxFiles: 5,
325
+ description: "Extract identity information (ID number, fullName, dateOfBirth, address, expiryDate) from CCCD/Passport.",
326
+ inputSchema: coreSchema("type", "id-card", {
327
+ outputFormat: { type: "string", enum: ["json"], default: "json" }
328
+ })
329
+ },
330
+ {
331
+ endpointName: "du-extract-receipt",
332
+ legacyEndpointName: "dugate-extract-receipt",
333
+ pipelineName: "Extract Receipt",
334
+ businessId: "document-core",
335
+ businessVersion: "2.0.0",
336
+ action: "extract",
337
+ discriminatorField: "type",
338
+ discriminatorValue: "receipt",
339
+ maxFiles: 5,
340
+ description: "Extract merchant, receipt date, items, payment method, and total from receipts.",
341
+ inputSchema: coreSchema("type", "receipt", {
342
+ outputFormat: { type: "string", enum: ["json"], default: "json" }
343
+ })
344
+ },
345
+ {
346
+ endpointName: "du-extract-table",
347
+ legacyEndpointName: "dugate-extract-table",
348
+ pipelineName: "Extract Table",
349
+ businessId: "document-core",
350
+ businessVersion: "2.0.0",
351
+ action: "extract",
352
+ discriminatorField: "type",
353
+ discriminatorValue: "table",
354
+ maxFiles: 5,
355
+ description: "Extract all tables from documents as structured JSON headers and rows.",
356
+ inputSchema: coreSchema("type", "table", {
357
+ outputFormat: { type: "string", enum: ["json"], default: "json" }
358
+ })
359
+ },
360
+ {
361
+ endpointName: "du-extract-custom",
362
+ legacyEndpointName: "dugate-extract-custom",
363
+ pipelineName: "Extract Custom",
364
+ businessId: "document-core",
365
+ businessVersion: "2.0.0",
366
+ action: "extract",
367
+ discriminatorField: "type",
368
+ discriminatorValue: "custom",
369
+ maxFiles: 5,
370
+ description: "Extract custom entities matching a caller-supplied JSON Schema or field list.",
371
+ inputSchema: coreSchema("type", "custom", {
372
+ fields: { type: "array", items: { type: "string" }, description: "Field names when schema is omitted" },
373
+ schema: { type: "object", description: "Target JSON Schema for structured output" },
374
+ outputFormat: { type: "string", enum: ["json"], default: "json" }
375
+ })
376
+ },
377
+ // ── 3. document-core / analyze (7) ─────────────────────────────────────────────
378
+ {
379
+ endpointName: "du-analyze-classify",
380
+ legacyEndpointName: "dugate-analyze-classify",
381
+ pipelineName: "Analyze Classify",
382
+ businessId: "document-core",
383
+ businessVersion: "2.0.0",
384
+ action: "analyze",
385
+ discriminatorField: "task",
386
+ discriminatorValue: "classify",
387
+ maxFiles: 5,
388
+ description: "Classify documents into categories with 0-1 confidence scores.",
389
+ inputSchema: coreSchema("task", "classify", {
390
+ categories: { type: "array", items: { type: "string" } }
391
+ })
392
+ },
393
+ {
394
+ endpointName: "du-analyze-sentiment",
395
+ legacyEndpointName: "dugate-analyze-sentiment",
396
+ pipelineName: "Analyze Sentiment",
397
+ businessId: "document-core",
398
+ businessVersion: "2.0.0",
399
+ action: "analyze",
400
+ discriminatorField: "task",
401
+ discriminatorValue: "sentiment",
402
+ maxFiles: 5,
403
+ description: "Analyze sentiment polarity, confidence, and key phrases.",
404
+ inputSchema: coreSchema("task", "sentiment", {})
405
+ },
406
+ {
407
+ endpointName: "du-analyze-compliance",
408
+ legacyEndpointName: "dugate-analyze-compliance",
409
+ pipelineName: "Analyze Compliance",
410
+ businessId: "document-core",
411
+ businessVersion: "2.0.0",
412
+ action: "analyze",
413
+ discriminatorField: "task",
414
+ discriminatorValue: "compliance",
415
+ maxFiles: 5,
416
+ description: "Check regulatory/policy compliance (PASS/FAIL/WARNING + violations).",
417
+ inputSchema: coreSchema("task", "compliance", {
418
+ criteria: { type: "array", items: { type: "string" } }
419
+ })
420
+ },
421
+ {
422
+ endpointName: "du-analyze-fact-check",
423
+ legacyEndpointName: "dugate-analyze-fact-check",
424
+ pipelineName: "Analyze Fact Check",
425
+ businessId: "document-core",
426
+ businessVersion: "2.0.0",
427
+ action: "analyze",
428
+ discriminatorField: "task",
429
+ discriminatorValue: "fact-check",
430
+ maxFiles: 5,
431
+ description: "Cross-check document facts against authoritative referenceData.",
432
+ inputSchema: coreSchema("task", "fact-check", {
433
+ referenceData: { type: "object", description: "Expected key-value facts to verify against" }
434
+ })
435
+ },
436
+ {
437
+ endpointName: "du-analyze-quality",
438
+ legacyEndpointName: "dugate-analyze-quality",
439
+ pipelineName: "Analyze Quality",
440
+ businessId: "document-core",
441
+ businessVersion: "2.0.0",
442
+ action: "analyze",
443
+ discriminatorField: "task",
444
+ discriminatorValue: "quality",
445
+ maxFiles: 5,
446
+ description: "Score document completeness and writing quality from 0 to 100.",
447
+ inputSchema: coreSchema("task", "quality", {
448
+ criteria: { type: "array", items: { type: "string" } }
449
+ })
450
+ },
451
+ {
452
+ endpointName: "du-analyze-risk",
453
+ legacyEndpointName: "dugate-analyze-risk",
454
+ pipelineName: "Analyze Risk",
455
+ businessId: "document-core",
456
+ businessVersion: "2.0.0",
457
+ action: "analyze",
458
+ discriminatorField: "task",
459
+ discriminatorValue: "risk",
460
+ maxFiles: 5,
461
+ description: "Assess legal/financial contract risk level (LOW, MEDIUM, HIGH, CRITICAL) and risk factors.",
462
+ inputSchema: coreSchema("task", "risk", {
463
+ focus: { type: "string" }
464
+ })
465
+ },
466
+ {
467
+ endpointName: "du-analyze-summarize-eval",
468
+ legacyEndpointName: "dugate-analyze-summarize-eval",
469
+ pipelineName: "Analyze Summarize Eval",
470
+ businessId: "document-core",
471
+ businessVersion: "2.0.0",
472
+ action: "analyze",
473
+ discriminatorField: "task",
474
+ discriminatorValue: "summarize-eval",
475
+ maxFiles: 5,
476
+ description: "Summarize document and evaluate author perspective, strengths, and gaps.",
477
+ inputSchema: coreSchema("task", "summarize-eval", {})
478
+ },
479
+ // ── 4. document-core / transform (5) ───────────────────────────────────────────
480
+ {
481
+ endpointName: "du-transform-convert",
482
+ legacyEndpointName: "dugate-transform-convert",
483
+ pipelineName: "Transform Convert",
484
+ businessId: "document-core",
485
+ businessVersion: "2.0.0",
486
+ action: "transform",
487
+ discriminatorField: "variant",
488
+ discriminatorValue: "convert",
489
+ maxFiles: 1,
490
+ description: "Convert document content locally between Markdown, HTML, plain text, and JSON.",
491
+ inputSchema: coreSchema("variant", "convert", {
492
+ outputFormat: { type: "string", enum: ["md", "html", "text", "json"], default: "md" }
493
+ })
494
+ },
495
+ {
496
+ endpointName: "du-transform-translate",
497
+ legacyEndpointName: "dugate-transform-translate",
498
+ pipelineName: "Transform Translate",
499
+ businessId: "document-core",
500
+ businessVersion: "2.0.0",
501
+ action: "transform",
502
+ discriminatorField: "variant",
503
+ discriminatorValue: "translate",
504
+ maxFiles: 1,
505
+ description: "Translate document into targetLanguage while preserving formatting.",
506
+ inputSchema: coreSchema("variant", "translate", {
507
+ targetLanguage: { type: "string", default: "en" },
508
+ tone: { type: "string", default: "professional" }
509
+ })
510
+ },
511
+ {
512
+ endpointName: "du-transform-rewrite",
513
+ legacyEndpointName: "dugate-transform-rewrite",
514
+ pipelineName: "Transform Rewrite",
515
+ businessId: "document-core",
516
+ businessVersion: "2.0.0",
517
+ action: "transform",
518
+ discriminatorField: "variant",
519
+ discriminatorValue: "rewrite",
520
+ maxFiles: 1,
521
+ description: "Rewrite document in academic, executive, simplified, or bullet_points style.",
522
+ inputSchema: coreSchema("variant", "rewrite", {
523
+ style: {
524
+ type: "string",
525
+ enum: ["academic", "executive", "simplified", "bullet_points"],
526
+ default: "executive"
527
+ },
528
+ tone: { type: "string" }
529
+ })
530
+ },
531
+ {
532
+ endpointName: "du-transform-redact",
533
+ legacyEndpointName: "dugate-transform-redact",
534
+ pipelineName: "Transform Redact",
535
+ businessId: "document-core",
536
+ businessVersion: "2.0.0",
537
+ action: "transform",
538
+ discriminatorField: "variant",
539
+ discriminatorValue: "redact",
540
+ maxFiles: 1,
541
+ description: "Mask PII (CCCD, PHONE_NUMBER, EMAIL, BANK_ACCOUNT, TAX_ID, or custom patterns) in text/documents.",
542
+ inputSchema: coreSchema("variant", "redact", {
543
+ text: { type: "string" },
544
+ redactPatterns: {
545
+ type: "array",
546
+ items: { type: "string" },
547
+ default: ["CCCD", "PHONE_NUMBER", "EMAIL"]
548
+ },
549
+ useAi: { type: "boolean", default: false },
550
+ outputFormat: { type: "string", enum: ["text", "md"], default: "text" }
551
+ })
552
+ },
553
+ {
554
+ endpointName: "du-transform-template",
555
+ legacyEndpointName: "dugate-transform-template",
556
+ pipelineName: "Transform Template",
557
+ businessId: "document-core",
558
+ businessVersion: "2.0.0",
559
+ action: "transform",
560
+ discriminatorField: "variant",
561
+ discriminatorValue: "template",
562
+ maxFiles: 1,
563
+ description: "Merge structured JSON variables into a {{placeholder}} document template.",
564
+ inputSchema: coreSchema("variant", "template", {
565
+ templateText: { type: "string" },
566
+ variables: { type: "object", description: "Key-value map merged into {{key}} placeholders" }
567
+ })
568
+ },
569
+ // ── 5. document-core / generate (6) ────────────────────────────────────────────
570
+ {
571
+ endpointName: "du-generate-summary",
572
+ legacyEndpointName: "dugate-generate-summary",
573
+ pipelineName: "Generate Summary",
574
+ businessId: "document-core",
575
+ businessVersion: "2.0.0",
576
+ action: "generate",
577
+ discriminatorField: "task",
578
+ discriminatorValue: "summary",
579
+ maxFiles: 5,
580
+ description: "Generate a concise summary constrained by maxWords, format, and target audience.",
581
+ inputSchema: coreSchema("task", "summary", {
582
+ format: {
583
+ type: "string",
584
+ enum: ["paragraph", "bullets", "numbered", "table", "mind_map"],
585
+ default: "bullets"
586
+ },
587
+ maxWords: { type: "integer", default: 300 },
588
+ audience: { type: "string" }
589
+ })
590
+ },
591
+ {
592
+ endpointName: "du-generate-outline",
593
+ legacyEndpointName: "dugate-generate-outline",
594
+ pipelineName: "Generate Outline",
595
+ businessId: "document-core",
596
+ businessVersion: "2.0.0",
597
+ action: "generate",
598
+ discriminatorField: "task",
599
+ discriminatorValue: "outline",
600
+ maxFiles: 5,
601
+ description: "Extract hierarchical H1/H2/H3 outline and section structure.",
602
+ inputSchema: coreSchema("task", "outline", {})
603
+ },
604
+ {
605
+ endpointName: "du-generate-report",
606
+ legacyEndpointName: "dugate-generate-report",
607
+ pipelineName: "Generate Report",
608
+ businessId: "document-core",
609
+ businessVersion: "2.0.0",
610
+ action: "generate",
611
+ discriminatorField: "task",
612
+ discriminatorValue: "report",
613
+ maxFiles: 10,
614
+ description: "Synthesize an executive analytical report across uploaded documents.",
615
+ inputSchema: coreSchema("task", "report", {
616
+ focus: { type: "string" },
617
+ language: { type: "string", default: "vi" }
618
+ })
619
+ },
620
+ {
621
+ endpointName: "du-generate-email",
622
+ legacyEndpointName: "dugate-generate-email",
623
+ pipelineName: "Generate Email",
624
+ businessId: "document-core",
625
+ businessVersion: "2.0.0",
626
+ action: "generate",
627
+ discriminatorField: "task",
628
+ discriminatorValue: "email",
629
+ maxFiles: 5,
630
+ description: "Draft a professional email based on the uploaded documents.",
631
+ inputSchema: coreSchema("task", "email", {
632
+ tone: { type: "string", default: "formal" },
633
+ recipientRole: { type: "string" }
634
+ })
635
+ },
636
+ {
637
+ endpointName: "du-generate-minutes",
638
+ legacyEndpointName: "dugate-generate-minutes",
639
+ pipelineName: "Generate Minutes",
640
+ businessId: "document-core",
641
+ businessVersion: "2.0.0",
642
+ action: "generate",
643
+ discriminatorField: "task",
644
+ discriminatorValue: "minutes",
645
+ maxFiles: 5,
646
+ description: "Generate structured meeting minutes with decisions, action items, and owners.",
647
+ inputSchema: coreSchema("task", "minutes", {
648
+ format: { type: "string", enum: ["md", "json"], default: "json" }
649
+ })
650
+ },
651
+ {
652
+ endpointName: "du-generate-qa",
653
+ legacyEndpointName: "dugate-generate-qa",
654
+ pipelineName: "Generate Qa",
655
+ businessId: "document-core",
656
+ businessVersion: "2.0.0",
657
+ action: "generate",
658
+ discriminatorField: "task",
659
+ discriminatorValue: "qa",
660
+ maxFiles: 5,
661
+ description: "Answer questions grounded in the document with verbatim evidence quotes and confidence.",
662
+ inputSchema: coreSchema("task", "qa", {
663
+ questions: { type: "array", items: { type: "string" } }
664
+ })
665
+ },
666
+ // ── 6. document-core / compare (3) ─────────────────────────────────────────────
667
+ {
668
+ endpointName: "du-compare-diff",
669
+ legacyEndpointName: "dugate-compare-diff",
670
+ pipelineName: "Compare Diff",
671
+ businessId: "document-core",
672
+ businessVersion: "2.0.0",
673
+ action: "compare",
674
+ discriminatorField: "mode",
675
+ discriminatorValue: "diff",
676
+ maxFiles: 2,
677
+ description: "Compute deterministic line-by-line lexical diff between source and target documents.",
678
+ inputSchema: coreSchema("mode", "diff", {
679
+ outputFormat: { type: "string", enum: ["unified", "json"], default: "json" }
680
+ })
681
+ },
682
+ {
683
+ endpointName: "du-compare-semantic",
684
+ legacyEndpointName: "dugate-compare-semantic",
685
+ pipelineName: "Compare Semantic",
686
+ businessId: "document-core",
687
+ businessVersion: "2.0.0",
688
+ action: "compare",
689
+ discriminatorField: "mode",
690
+ discriminatorValue: "semantic",
691
+ maxFiles: 2,
692
+ description: "Compare two documents semantically and assess legal significance (NEGLIGIBLE, MODERATE, HIGH).",
693
+ inputSchema: coreSchema("mode", "semantic", {
694
+ focus: { type: "string" }
695
+ })
696
+ },
697
+ {
698
+ endpointName: "du-compare-version",
699
+ legacyEndpointName: "dugate-compare-version",
700
+ pipelineName: "Compare Version",
701
+ businessId: "document-core",
702
+ businessVersion: "2.0.0",
703
+ action: "compare",
704
+ discriminatorField: "mode",
705
+ discriminatorValue: "version",
706
+ maxFiles: 2,
707
+ description: "Generate a structured version changelog between two document revisions.",
708
+ inputSchema: coreSchema("mode", "version", {})
709
+ },
710
+ // ── 7. document-core / multi-step workflows (3) ────────────────────────────────
711
+ {
712
+ endpointName: "du-workflow-disbursement",
713
+ legacyEndpointName: "dugate-workflow-disbursement",
714
+ pipelineName: "Workflow Disbursement",
715
+ businessId: "document-core",
716
+ businessVersion: "2.0.0",
717
+ action: "disbursement",
718
+ maxFiles: 20,
719
+ description: "Credit disbursement appraisal: parallel classify & extract, optional HITL approval (WAITING_INPUT), cross-check against referenceData, and memo generation.",
720
+ inputSchema: {
721
+ type: "object",
722
+ properties: {
723
+ inputVersion: { type: "string", default: "disbursement-input-v1" },
724
+ referenceData: {
725
+ type: "array",
726
+ items: {
727
+ type: "object",
728
+ properties: {
729
+ key: { type: "string" },
730
+ expected: {}
731
+ }
732
+ }
733
+ },
734
+ maxConcurrency: { type: "integer", default: 4, minimum: 1, maximum: 8 },
735
+ requireApproval: { type: "boolean", default: false },
736
+ failurePolicy: { type: "string", enum: ["fail-closed", "continue"], default: "fail-closed" }
737
+ }
738
+ }
739
+ },
740
+ {
741
+ endpointName: "du-workflow-doc-compare",
742
+ legacyEndpointName: "dugate-workflow-doc-compare",
743
+ pipelineName: "Workflow Doc Compare",
744
+ businessId: "document-core",
745
+ businessVersion: "2.0.0",
746
+ action: "doc-compare",
747
+ maxFiles: 2,
748
+ description: "Long-document deep comparison: section chunking, structureClaims & referenceClaims verification, optional HITL review.",
749
+ inputSchema: {
750
+ type: "object",
751
+ properties: {
752
+ inputVersion: { type: "string", default: "doc-compare-input-v1" },
753
+ chunkSizeChars: { type: "integer", default: 8e3, minimum: 200, maximum: 2e5 },
754
+ requireHumanReview: { type: "boolean", default: false },
755
+ focus: { type: "string" }
756
+ }
757
+ }
758
+ },
759
+ {
760
+ endpointName: "du-workflow-schema",
761
+ pipelineName: "Workflow Schema",
762
+ businessId: "document-core",
763
+ businessVersion: "2.0.0",
764
+ action: "schema-workflow",
765
+ maxFiles: 10,
766
+ description: "Execute a provisioned dynamic pipeline/DAG workflow by pipelineName or pipelineId.",
767
+ inputSchema: {
768
+ type: "object",
769
+ properties: {
770
+ pipelineName: { type: "string" },
771
+ pipelineId: { type: "integer" },
772
+ parameters: { type: "object" }
773
+ }
774
+ }
775
+ },
776
+ // ── 8. lc-checker@1.2.0 (Trade Finance L/C Document Checking) ──────────────────
777
+ {
778
+ endpointName: "du-lc-checker",
779
+ legacyEndpointName: "dugate-workflow-lc-checker",
780
+ pipelineName: "Workflow Lc Checker",
781
+ businessId: "lc-checker",
782
+ businessVersion: "1.2.0",
783
+ action: "lc-checker",
784
+ maxFiles: 50,
785
+ description: "5-step Trade Finance L/C examination (OCR -> Screen -> Visual -> Adjudicate UCP 600 / ISBP 821 -> Vietnamese Report) with mandatory rule citations and humanSignOffRequired.",
786
+ inputSchema: {
787
+ type: "object",
788
+ properties: {
789
+ inputVersion: { type: "string", default: "lc-checker-input-v1" },
790
+ ruleSetVersion: { type: "string", default: LC_RULESET_VERSION },
791
+ maxConcurrency: { type: "integer", default: 4, minimum: 1, maximum: 8 },
792
+ failurePolicy: { type: "string", enum: ["fail-closed", "continue"], default: "fail-closed" }
793
+ }
794
+ }
795
+ },
796
+ // ── 9. example-review@1.0.0 (Multi-Document Compliance Review) ─────────────────
797
+ {
798
+ endpointName: "du-example-review",
799
+ pipelineName: "Example Review",
800
+ businessId: "example-review",
801
+ businessVersion: "1.0.0",
802
+ action: "review",
803
+ maxFiles: 10,
804
+ description: "Multi-document compliance review (1..10 PDF/DOCX/XLSX/JSON files) with fan-out item review and optional HITL approval.",
805
+ inputSchema: {
806
+ type: "object",
807
+ properties: {
808
+ reviewId: { type: "string" },
809
+ requireApproval: { type: "boolean", default: false },
810
+ useAi: { type: "boolean", default: true },
811
+ criteria: { type: "array", items: { type: "string" } }
812
+ }
813
+ }
814
+ }
815
+ ];
816
+ // Annotate the CommonJS export names for ESM import in node:
817
+ 0 && (module.exports = {
818
+ DU_BUSINESS_CATALOG,
819
+ DU_OPERATION_STATES,
820
+ LC_RULESET_ID,
821
+ LC_RULESET_VERSION,
822
+ TERMINAL_OPERATION_STATES,
823
+ UCP600_ISBP821_RULES,
824
+ VALID_LC_RULE_IDS,
825
+ createProblem,
826
+ expandPageRanges,
827
+ parsePageRangeString
828
+ });