plugin-document-understanding 1.1.2 → 1.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/README.md +21 -8
  2. package/client-v2.d.ts +2 -0
  3. package/client-v2.js +1 -0
  4. package/dist/client/index.js +1 -1
  5. package/dist/client-v2/794.9b984a25b2fc7c14.js +10 -0
  6. package/dist/client-v2/index.js +10 -0
  7. package/dist/externalVersion.js +7 -6
  8. package/dist/node_modules/form-data/License +19 -0
  9. package/dist/node_modules/form-data/index.d.ts +62 -0
  10. package/dist/node_modules/form-data/lib/browser.js +4 -0
  11. package/dist/node_modules/form-data/lib/form_data.js +14 -0
  12. package/dist/node_modules/form-data/lib/populate.js +10 -0
  13. package/dist/node_modules/form-data/package.json +1 -0
  14. package/dist/node_modules/mime-types/LICENSE +23 -0
  15. package/dist/node_modules/mime-types/index.js +14 -0
  16. package/dist/node_modules/mime-types/package.json +1 -0
  17. package/dist/server/actions.js +7 -6
  18. package/dist/server/collections/endpoints.js +1 -1
  19. package/dist/server/plugin.js +7 -3
  20. package/dist/server/services/AsyncJobManager.js +14 -5
  21. package/dist/server/services/DocumentUnderstandingService.js +53 -23
  22. package/dist/server/services/PipelineExecutor.js +81 -94
  23. package/package.json +49 -16
  24. package/src/client/index.tsx +9 -0
  25. package/src/client-v2/client.d.ts +249 -0
  26. package/src/client-v2/components/EndpointsTab.tsx +458 -0
  27. package/src/client-v2/components/JobsTab.tsx +259 -0
  28. package/src/client-v2/components/PipelinesTab.tsx +872 -0
  29. package/src/client-v2/components/PluginSettings.tsx +48 -0
  30. package/src/client-v2/components/ServiceConfigTab.tsx +122 -0
  31. package/src/client-v2/locale.ts +21 -0
  32. package/{dist/client/models/index.d.ts → src/client-v2/models/index.ts} +3 -2
  33. package/src/client-v2/plugin.tsx +21 -0
  34. package/src/locale/en-US.json +121 -0
  35. package/src/locale/vi-VN.json +121 -0
  36. package/src/locale/zh-CN.json +1 -0
  37. package/src/server/__tests__/actions.test.ts +98 -0
  38. package/src/server/__tests__/pipeline-executor.test.ts +33 -0
  39. package/src/server/__tests__/smoke.test.ts +55 -0
  40. package/src/server/actions.ts +176 -0
  41. package/src/server/collections/.gitkeep +0 -0
  42. package/src/server/collections/config.ts +18 -0
  43. package/src/server/collections/endpoints.ts +28 -0
  44. package/src/server/collections/jobs.ts +29 -0
  45. package/src/server/collections/pipeline-steps.ts +27 -0
  46. package/src/server/collections/pipelines.ts +19 -0
  47. package/src/server/plugin.ts +108 -0
  48. package/src/server/services/AsyncJobManager.ts +172 -0
  49. package/src/server/services/DocumentUnderstandingService.ts +264 -0
  50. package/src/server/services/ExternalApiClient.ts +143 -0
  51. package/src/server/services/PipelineExecutor.ts +502 -0
  52. package/src/server/tools/document-understanding-tool.ts +181 -0
  53. package/src/server/types.ts +73 -0
  54. package/dist/client/components/EndpointsTab.d.ts +0 -2
  55. package/dist/client/components/JobsTab.d.ts +0 -2
  56. package/dist/client/components/PipelinesTab.d.ts +0 -2
  57. package/dist/client/components/PluginSettings.d.ts +0 -2
  58. package/dist/client/components/ServiceConfigTab.d.ts +0 -2
  59. package/dist/client/locale.d.ts +0 -10
  60. package/dist/client/plugin.d.ts +0 -6
  61. package/dist/server/actions.d.ts +0 -17
  62. package/dist/server/collections/config.d.ts +0 -3
  63. package/dist/server/collections/endpoints.d.ts +0 -3
  64. package/dist/server/collections/jobs.d.ts +0 -3
  65. package/dist/server/collections/pipeline-steps.d.ts +0 -3
  66. package/dist/server/collections/pipelines.d.ts +0 -3
  67. package/dist/server/plugin.d.ts +0 -15
  68. package/dist/server/services/AsyncJobManager.d.ts +0 -27
  69. package/dist/server/services/DocumentUnderstandingService.d.ts +0 -35
  70. package/dist/server/services/ExternalApiClient.d.ts +0 -28
  71. package/dist/server/services/PipelineExecutor.d.ts +0 -24
  72. package/dist/server/tools/document-understanding-tool.d.ts +0 -8
  73. package/dist/server/types.d.ts +0 -69
  74. /package/{dist/client/index.d.ts → src/client-v2/index.tsx} +0 -0
  75. /package/{dist/index.d.ts → src/index.ts} +0 -0
  76. /package/{dist/server/index.d.ts → src/server/index.ts} +0 -0
@@ -0,0 +1,73 @@
1
+ export interface ServiceConfig {
2
+ id?: number;
3
+ baseUrl: string;
4
+ authType: 'api_key' | 'bearer' | 'custom_header' | 'none';
5
+ authKey?: string;
6
+ authHeaderName?: string;
7
+ defaultTimeout: number;
8
+ defaultRetries: number;
9
+ pollInterval: number;
10
+ pollTimeout: number;
11
+ webhookSecret?: string;
12
+ }
13
+
14
+ export interface EndpointDef {
15
+ id: number;
16
+ name: string;
17
+ subpath: string;
18
+ method: 'GET' | 'POST' | 'PUT';
19
+ description?: string;
20
+ requestBodySchema?: any;
21
+ responseSchema?: any;
22
+ fileInputMode: 'none' | 'multipart' | 'base64';
23
+ fileFieldName?: string;
24
+ maxFiles: number;
25
+ executionMode: 'sync' | 'polling' | 'webhook';
26
+ pollResultSubpath?: string;
27
+ pollTaskIdField?: string;
28
+ pollResultField?: string;
29
+ pollInterval?: number;
30
+ pollTimeout?: number;
31
+ pollStatusField?: string;
32
+ pollCompletedValue?: string;
33
+ customHeaders?: Record<string, string>;
34
+ enabled: boolean;
35
+ }
36
+
37
+ export interface PipelineStepDef {
38
+ id: number;
39
+ pipelineId: number;
40
+ endpointId: number;
41
+ stepOrder: number;
42
+ name: string;
43
+ inputMapping?: Record<string, any>;
44
+ outputAlias?: string;
45
+ condition?: any;
46
+ onError: 'fail' | 'skip' | 'retry';
47
+ retryCount: number;
48
+ endpoint: EndpointDef; // Associated endpoint
49
+ }
50
+
51
+ export interface PipelineDef {
52
+ id: number;
53
+ name: string;
54
+ description?: string;
55
+ inputSchema?: any;
56
+ outputMapping?: Record<string, any>;
57
+ enabled: boolean;
58
+ steps: PipelineStepDef[];
59
+ }
60
+
61
+ export interface JobState {
62
+ id: number;
63
+ pipelineId: number;
64
+ status: 'pending' | 'running' | 'polling' | 'completed' | 'failed' | 'timeout';
65
+ input: any;
66
+ currentStep: number;
67
+ stepResults: Record<string, any>;
68
+ finalResult?: any;
69
+ error?: string;
70
+ externalTaskIds: Record<string, string>;
71
+ startedAt?: Date;
72
+ completedAt?: Date;
73
+ }
@@ -1,2 +0,0 @@
1
- import React from 'react';
2
- export declare const EndpointsTab: () => React.JSX.Element;
@@ -1,2 +0,0 @@
1
- import React from 'react';
2
- export declare const JobsTab: () => React.JSX.Element;
@@ -1,2 +0,0 @@
1
- import React from 'react';
2
- export declare const PipelinesTab: () => React.JSX.Element;
@@ -1,2 +0,0 @@
1
- import React from 'react';
2
- export declare const PluginSettings: () => React.JSX.Element;
@@ -1,2 +0,0 @@
1
- import React from 'react';
2
- export declare const ServiceConfigTab: () => React.JSX.Element;
@@ -1,10 +0,0 @@
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
- export declare function useT(): (str: string) => any;
10
- export declare function tExpr(key: string): string;
@@ -1,6 +0,0 @@
1
- import { Plugin } from '@nocobase/client';
2
- export declare class PluginDocumentUnderstandingClient extends Plugin {
3
- app: any;
4
- load(): Promise<void>;
5
- }
6
- export default PluginDocumentUnderstandingClient;
@@ -1,17 +0,0 @@
1
- import type { Context } from '@nocobase/actions';
2
- export declare const defineActions: (plugin: any) => {
3
- getConfig(ctx: Context, next: () => Promise<any>): Promise<void>;
4
- updateConfig(ctx: Context, next: () => Promise<any>): Promise<void>;
5
- listEndpoints(ctx: Context, next: () => Promise<any>): Promise<void>;
6
- createEndpoint(ctx: Context, next: () => Promise<any>): Promise<void>;
7
- updateEndpoint(ctx: Context, next: () => Promise<any>): Promise<void>;
8
- deleteEndpoint(ctx: Context, next: () => Promise<any>): Promise<void>;
9
- listPipelines(ctx: Context, next: () => Promise<any>): Promise<void>;
10
- createPipeline(ctx: Context, next: () => Promise<any>): Promise<void>;
11
- updatePipeline(ctx: Context, next: () => Promise<any>): Promise<void>;
12
- deletePipeline(ctx: Context, next: () => Promise<any>): Promise<void>;
13
- executePipeline(ctx: Context, next: () => Promise<any>): Promise<void>;
14
- getJobStatus(ctx: Context, next: () => Promise<any>): Promise<void>;
15
- listJobs(ctx: Context, next: () => Promise<any>): Promise<void>;
16
- webhookCallback(ctx: Context, next: () => Promise<any>): Promise<void>;
17
- };
@@ -1,3 +0,0 @@
1
- import { CollectionOptions } from '@nocobase/database';
2
- declare const _default: CollectionOptions;
3
- export default _default;
@@ -1,3 +0,0 @@
1
- import { CollectionOptions } from '@nocobase/database';
2
- declare const _default: CollectionOptions;
3
- export default _default;
@@ -1,3 +0,0 @@
1
- import { CollectionOptions } from '@nocobase/database';
2
- declare const _default: CollectionOptions;
3
- export default _default;
@@ -1,3 +0,0 @@
1
- import { CollectionOptions } from '@nocobase/database';
2
- declare const _default: CollectionOptions;
3
- export default _default;
@@ -1,3 +0,0 @@
1
- import { CollectionOptions } from '@nocobase/database';
2
- declare const _default: CollectionOptions;
3
- export default _default;
@@ -1,15 +0,0 @@
1
- import { Plugin } from '@nocobase/server';
2
- import { DocumentUnderstandingService } from './services/DocumentUnderstandingService';
3
- export declare class PluginDocumentUnderstandingServer extends Plugin {
4
- service: DocumentUnderstandingService;
5
- afterAdd(): Promise<void>;
6
- beforeLoad(): Promise<void>;
7
- load(): Promise<void>;
8
- private registerActions;
9
- private registerAITools;
10
- install(): Promise<void>;
11
- afterEnable(): Promise<void>;
12
- afterDisable(): Promise<void>;
13
- remove(): Promise<void>;
14
- }
15
- export default PluginDocumentUnderstandingServer;
@@ -1,27 +0,0 @@
1
- import { Database } from '@nocobase/database';
2
- import { ExternalApiClient } from './ExternalApiClient';
3
- import { EndpointDef } from '../types';
4
- export declare class AsyncJobManager {
5
- private db;
6
- private apiClient;
7
- private intervals;
8
- private onJobComplete;
9
- private onJobError;
10
- constructor(db: Database, apiClient: ExternalApiClient, callbacks: {
11
- onJobComplete: (jobId: number, result: any) => Promise<void>;
12
- onJobError: (jobId: number, error: string) => Promise<void>;
13
- });
14
- startPolling(jobId: number, endpoint: EndpointDef, taskId: string, customInterval?: number, customTimeout?: number): Promise<void>;
15
- /**
16
- * Transition pending and running jobs to failed state during startup.
17
- */
18
- cleanupStuckJobs(): Promise<void>;
19
- /**
20
- * Recover polling jobs that were in-flight when server restarted.
21
- * Call this during service initialization.
22
- */
23
- recoverPollingJobs(): Promise<void>;
24
- stopPolling(jobId: number): void;
25
- destroy(): void;
26
- private getNestedValue;
27
- }
@@ -1,35 +0,0 @@
1
- import { Application } from '@nocobase/server';
2
- import { Database } from '@nocobase/database';
3
- import { FileInput } from './ExternalApiClient';
4
- import { ServiceConfig, EndpointDef, PipelineDef, JobState } from '../types';
5
- export declare class DocumentUnderstandingService {
6
- private app;
7
- private db;
8
- private apiClient;
9
- private pipelineExecutor;
10
- private jobManager;
11
- private initialized;
12
- private static readonly HEADER_NAME_RE;
13
- constructor(app: Application, db: Database);
14
- initialize(): Promise<void>;
15
- isReady(): boolean;
16
- getConfig(): Promise<ServiceConfig>;
17
- updateConfig(data: Partial<ServiceConfig>): Promise<void>;
18
- listEndpoints(): Promise<EndpointDef[]>;
19
- createEndpoint(data: Partial<EndpointDef>): Promise<EndpointDef>;
20
- updateEndpoint(id: number, data: Partial<EndpointDef>): Promise<void>;
21
- private normalizeEndpoint;
22
- private normalizeHeaders;
23
- deleteEndpoint(id: number): Promise<void>;
24
- listPipelines(): Promise<PipelineDef[]>;
25
- createPipeline(data: Partial<PipelineDef>): Promise<PipelineDef>;
26
- updatePipeline(id: number, data: Partial<PipelineDef>): Promise<void>;
27
- private validateStepAliases;
28
- deletePipeline(id: number): Promise<void>;
29
- executePipeline(pipelineId: number, input: Record<string, any>, files?: FileInput[], userId?: number): Promise<{
30
- jobId: number;
31
- }>;
32
- getJobStatus(jobId: number): Promise<JobState>;
33
- listJobs(filters?: any): Promise<JobState[]>;
34
- handleWebhook(payload: any, signature?: string): Promise<void>;
35
- }
@@ -1,28 +0,0 @@
1
- /// <reference types="node" />
2
- import { ServiceConfig, EndpointDef } from '../types';
3
- export interface FileInput {
4
- fieldName: string;
5
- buffer: Buffer;
6
- filename: string;
7
- mimeType: string;
8
- }
9
- export interface ApiCallOptions {
10
- endpoint: EndpointDef;
11
- body?: Record<string, any>;
12
- files?: FileInput[];
13
- overrideHeaders?: Record<string, string>;
14
- }
15
- export declare class ExternalApiClient {
16
- private config;
17
- private client;
18
- private static readonly HEADER_NAME_RE;
19
- constructor(config: ServiceConfig);
20
- private buildAuthHeaders;
21
- private sanitizeHeaders;
22
- call(options: ApiCallOptions): Promise<{
23
- status: number;
24
- data: any;
25
- headers: any;
26
- }>;
27
- get(url: string, overrideHeaders?: Record<string, string>): Promise<any>;
28
- }
@@ -1,24 +0,0 @@
1
- import { Database } from '@nocobase/database';
2
- import { ExternalApiClient, FileInput } from './ExternalApiClient';
3
- import { AsyncJobManager } from './AsyncJobManager';
4
- import { JobState } from '../types';
5
- export interface ExecutionContext {
6
- input: Record<string, any>;
7
- files: FileInput[];
8
- stepResults: Record<string, any>;
9
- jobId: number;
10
- }
11
- export declare class PipelineExecutor {
12
- private db;
13
- private apiClient;
14
- private jobManager;
15
- constructor(db: Database, apiClient: ExternalApiClient, jobManager: AsyncJobManager);
16
- private resolveFile;
17
- execute(pipelineId: number, input: Record<string, any>, files?: FileInput[], userId?: number): Promise<JobState>;
18
- private runSteps;
19
- resumeFromStep(jobId: number, asyncResult: any): Promise<void>;
20
- private finishJob;
21
- private resolveMapping;
22
- private evaluateCondition;
23
- private getNestedValue;
24
- }
@@ -1,8 +0,0 @@
1
- import { DocumentUnderstandingService } from '../services/DocumentUnderstandingService';
2
- /**
3
- * Dynamic tools provider: queries all enabled pipelines and registers one tool per pipeline.
4
- * Called on-demand by the AI tools manager each time tools are listed.
5
- */
6
- export declare function createDynamicPipelineToolsProvider(service: DocumentUnderstandingService): (register: {
7
- registerTools: (options: any) => void;
8
- }) => Promise<void>;
@@ -1,69 +0,0 @@
1
- export interface ServiceConfig {
2
- id?: number;
3
- baseUrl: string;
4
- authType: 'api_key' | 'bearer' | 'custom_header' | 'none';
5
- authKey?: string;
6
- authHeaderName?: string;
7
- defaultTimeout: number;
8
- defaultRetries: number;
9
- pollInterval: number;
10
- pollTimeout: number;
11
- webhookSecret?: string;
12
- }
13
- export interface EndpointDef {
14
- id: number;
15
- name: string;
16
- subpath: string;
17
- method: 'GET' | 'POST' | 'PUT';
18
- description?: string;
19
- requestBodySchema?: any;
20
- responseSchema?: any;
21
- fileInputMode: 'none' | 'multipart' | 'base64';
22
- fileFieldName?: string;
23
- maxFiles: number;
24
- executionMode: 'sync' | 'polling' | 'webhook';
25
- pollResultSubpath?: string;
26
- pollTaskIdField?: string;
27
- pollResultField?: string;
28
- pollInterval?: number;
29
- pollTimeout?: number;
30
- pollStatusField?: string;
31
- pollCompletedValue?: string;
32
- customHeaders?: Record<string, string>;
33
- enabled: boolean;
34
- }
35
- export interface PipelineStepDef {
36
- id: number;
37
- pipelineId: number;
38
- endpointId: number;
39
- stepOrder: number;
40
- name: string;
41
- inputMapping?: Record<string, any>;
42
- outputAlias?: string;
43
- condition?: any;
44
- onError: 'fail' | 'skip' | 'retry';
45
- retryCount: number;
46
- endpoint: EndpointDef;
47
- }
48
- export interface PipelineDef {
49
- id: number;
50
- name: string;
51
- description?: string;
52
- inputSchema?: any;
53
- outputMapping?: Record<string, any>;
54
- enabled: boolean;
55
- steps: PipelineStepDef[];
56
- }
57
- export interface JobState {
58
- id: number;
59
- pipelineId: number;
60
- status: 'pending' | 'running' | 'polling' | 'completed' | 'failed' | 'timeout';
61
- input: any;
62
- currentStep: number;
63
- stepResults: Record<string, any>;
64
- finalResult?: any;
65
- error?: string;
66
- externalTaskIds: Record<string, string>;
67
- startedAt?: Date;
68
- completedAt?: Date;
69
- }
File without changes
File without changes