@xpert-ai/plugin-sdk 0.0.1 → 0.0.2
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/index.cjs.d.ts +1 -0
- package/index.cjs.js +307977 -0
- package/index.esm.d.ts +1 -0
- package/index.esm.js +307944 -0
- package/package.json +3 -3
- package/src/index.d.ts +12 -0
- package/src/lib/core/file-system.d.ts +42 -0
- package/src/lib/core/index.d.ts +3 -0
- package/src/lib/core/permissions.d.ts +74 -0
- package/src/lib/core/schema.d.ts +22 -0
- package/src/lib/integration/index.d.ts +3 -0
- package/src/lib/integration/strategy.decorator.d.ts +2 -0
- package/src/lib/integration/{strategy.interface.ts → strategy.interface.d.ts} +5 -7
- package/src/lib/integration/strategy.registry.d.ts +6 -0
- package/src/lib/knowledge/index.d.ts +3 -0
- package/src/lib/knowledge/knowledge-strategy.decorator.d.ts +2 -0
- package/src/lib/knowledge/knowledge-strategy.interface.d.ts +15 -0
- package/src/lib/knowledge/knowledge-strategy.registry.d.ts +12 -0
- package/src/lib/logger.d.ts +2 -0
- package/src/lib/plugin-metadata.d.ts +17 -0
- package/src/lib/plugin.d.ts +8 -0
- package/src/lib/{plugin.hook.ts → plugin.hook.d.ts} +0 -4
- package/src/lib/plugin.interface.d.ts +59 -0
- package/src/lib/rag/image/index.d.ts +3 -0
- package/src/lib/rag/image/strategy.decorator.d.ts +5 -0
- package/src/lib/rag/image/strategy.interface.d.ts +36 -0
- package/src/lib/rag/image/strategy.registry.d.ts +6 -0
- package/src/lib/rag/index.d.ts +6 -0
- package/src/lib/rag/retriever/index.d.ts +3 -0
- package/src/lib/rag/retriever/strategy.decorator.d.ts +5 -0
- package/src/lib/rag/retriever/strategy.interface.d.ts +30 -0
- package/src/lib/rag/retriever/strategy.registry.d.ts +6 -0
- package/src/lib/rag/source/index.d.ts +3 -0
- package/src/lib/rag/source/strategy.decorator.d.ts +5 -0
- package/src/lib/rag/source/strategy.interface.d.ts +26 -0
- package/src/lib/rag/source/strategy.registry.d.ts +6 -0
- package/src/lib/rag/textsplitter/index.d.ts +3 -0
- package/src/lib/rag/textsplitter/strategy.decorator.d.ts +2 -0
- package/src/lib/rag/textsplitter/strategy.interface.d.ts +24 -0
- package/src/lib/rag/textsplitter/strategy.registry.d.ts +6 -0
- package/src/lib/rag/transformer/index.d.ts +3 -0
- package/src/lib/rag/transformer/strategy.decorator.d.ts +5 -0
- package/src/lib/rag/transformer/strategy.interface.d.ts +40 -0
- package/src/lib/rag/transformer/strategy.registry.d.ts +6 -0
- package/src/lib/rag/types.d.ts +29 -0
- package/src/lib/strategy.d.ts +12 -0
- package/src/lib/toolset/builtin.d.ts +54 -0
- package/src/lib/toolset/index.d.ts +5 -0
- package/src/lib/toolset/strategy.decorator.d.ts +5 -0
- package/src/lib/toolset/strategy.interface.d.ts +28 -0
- package/src/lib/toolset/strategy.registry.d.ts +6 -0
- package/src/lib/toolset/toolset.d.ts +53 -0
- package/src/lib/types.d.ts +47 -0
- package/src/lib/vectorstore/index.d.ts +3 -0
- package/src/lib/vectorstore/strategy.decorator.d.ts +2 -0
- package/src/lib/vectorstore/strategy.interface.d.ts +24 -0
- package/src/lib/vectorstore/strategy.registry.d.ts +6 -0
- package/src/lib/workflow/index.d.ts +2 -0
- package/src/lib/workflow/node/index.d.ts +3 -0
- package/src/lib/workflow/node/strategy.decorator.d.ts +5 -0
- package/src/lib/workflow/node/strategy.interface.d.ts +40 -0
- package/src/lib/workflow/node/strategy.registry.d.ts +9 -0
- package/src/lib/workflow/trigger/index.d.ts +3 -0
- package/src/lib/workflow/trigger/strategy.decorator.d.ts +2 -0
- package/src/lib/workflow/trigger/strategy.interface.d.ts +22 -0
- package/src/lib/workflow/trigger/strategy.registry.d.ts +6 -0
- package/.eslintrc.json +0 -30
- package/.swcrc +0 -29
- package/PERMISSIONS.md +0 -181
- package/README.md +0 -19
- package/SCHEMA_SPECIFICATION.md +0 -332
- package/jest.config.ts +0 -28
- package/project.json +0 -29
- package/src/index.ts +0 -12
- package/src/lib/core/file-system.ts +0 -96
- package/src/lib/core/index.ts +0 -3
- package/src/lib/core/permissions.ts +0 -97
- package/src/lib/core/schema.ts +0 -23
- package/src/lib/integration/index.ts +0 -3
- package/src/lib/integration/strategy.decorator.ts +0 -6
- package/src/lib/integration/strategy.registry.ts +0 -12
- package/src/lib/knowledge/index.ts +0 -3
- package/src/lib/knowledge/knowledge-strategy.decorator.ts +0 -6
- package/src/lib/knowledge/knowledge-strategy.interface.ts +0 -15
- package/src/lib/knowledge/knowledge-strategy.registry.ts +0 -36
- package/src/lib/logger.ts +0 -18
- package/src/lib/plugin-metadata.ts +0 -20
- package/src/lib/plugin.interface.ts +0 -67
- package/src/lib/plugin.ts +0 -32
- package/src/lib/rag/image/index.ts +0 -3
- package/src/lib/rag/image/strategy.decorator.ts +0 -9
- package/src/lib/rag/image/strategy.interface.ts +0 -42
- package/src/lib/rag/image/strategy.registry.ts +0 -17
- package/src/lib/rag/index.ts +0 -6
- package/src/lib/rag/retriever/index.ts +0 -3
- package/src/lib/rag/retriever/strategy.decorator.ts +0 -9
- package/src/lib/rag/retriever/strategy.interface.ts +0 -32
- package/src/lib/rag/retriever/strategy.registry.ts +0 -12
- package/src/lib/rag/source/index.ts +0 -3
- package/src/lib/rag/source/strategy.decorator.ts +0 -9
- package/src/lib/rag/source/strategy.interface.ts +0 -28
- package/src/lib/rag/source/strategy.registry.ts +0 -17
- package/src/lib/rag/textsplitter/index.ts +0 -3
- package/src/lib/rag/textsplitter/strategy.decorator.ts +0 -6
- package/src/lib/rag/textsplitter/strategy.interface.ts +0 -28
- package/src/lib/rag/textsplitter/strategy.registry.ts +0 -17
- package/src/lib/rag/transformer/index.ts +0 -3
- package/src/lib/rag/transformer/strategy.decorator.ts +0 -9
- package/src/lib/rag/transformer/strategy.interface.ts +0 -48
- package/src/lib/rag/transformer/strategy.registry.ts +0 -14
- package/src/lib/rag/types.ts +0 -86
- package/src/lib/strategy.ts +0 -37
- package/src/lib/toolset/builtin.ts +0 -111
- package/src/lib/toolset/index.ts +0 -5
- package/src/lib/toolset/strategy.decorator.ts +0 -9
- package/src/lib/toolset/strategy.interface.ts +0 -32
- package/src/lib/toolset/strategy.registry.ts +0 -17
- package/src/lib/toolset/toolset.ts +0 -76
- package/src/lib/types.ts +0 -47
- package/src/lib/vectorstore/index.ts +0 -3
- package/src/lib/vectorstore/strategy.decorator.ts +0 -6
- package/src/lib/vectorstore/strategy.interface.ts +0 -25
- package/src/lib/vectorstore/strategy.registry.ts +0 -17
- package/src/lib/workflow/index.ts +0 -2
- package/src/lib/workflow/node/index.ts +0 -3
- package/src/lib/workflow/node/strategy.decorator.ts +0 -9
- package/src/lib/workflow/node/strategy.interface.ts +0 -49
- package/src/lib/workflow/node/strategy.registry.ts +0 -18
- package/src/lib/workflow/trigger/index.ts +0 -3
- package/src/lib/workflow/trigger/strategy.decorator.ts +0 -6
- package/src/lib/workflow/trigger/strategy.interface.ts +0 -27
- package/src/lib/workflow/trigger/strategy.registry.ts +0 -17
- package/tsconfig.json +0 -22
- package/tsconfig.lib.json +0 -10
- package/tsconfig.spec.json +0 -9
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xpert-ai/plugin-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"license": "AGPL-3.0",
|
|
5
5
|
"dependencies": {},
|
|
6
|
-
"main": "./index.cjs",
|
|
7
|
-
"module": "./index.js",
|
|
6
|
+
"main": "./index.cjs.js",
|
|
7
|
+
"module": "./index.esm.js",
|
|
8
8
|
"publishConfig": {
|
|
9
9
|
"access": "public"
|
|
10
10
|
}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from './lib/plugin';
|
|
2
|
+
export * from './lib/plugin.interface';
|
|
3
|
+
export * from './lib/plugin-metadata';
|
|
4
|
+
export * from './lib/types';
|
|
5
|
+
export * from './lib/logger';
|
|
6
|
+
export * from './lib/knowledge';
|
|
7
|
+
export * from './lib/integration/index';
|
|
8
|
+
export * from './lib/workflow/index';
|
|
9
|
+
export * from './lib/vectorstore/index';
|
|
10
|
+
export * from './lib/rag/index';
|
|
11
|
+
export * from './lib/toolset/index';
|
|
12
|
+
export * from './lib/core/index';
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { FileSystemPermission } from './permissions';
|
|
4
|
+
/**
|
|
5
|
+
* Restricted FileSystem based on granted permissions
|
|
6
|
+
*/
|
|
7
|
+
export declare class XpFileSystem {
|
|
8
|
+
private basePath;
|
|
9
|
+
private baseUrl;
|
|
10
|
+
private allowedOps;
|
|
11
|
+
private scope;
|
|
12
|
+
constructor(permission: FileSystemPermission, basePath: string, baseUrl: string);
|
|
13
|
+
/**
|
|
14
|
+
* Check if operation is allowed
|
|
15
|
+
*/
|
|
16
|
+
private ensureAllowed;
|
|
17
|
+
/**
|
|
18
|
+
* Check if path is within scope
|
|
19
|
+
*/
|
|
20
|
+
private ensureInScope;
|
|
21
|
+
fullPath(filePath: string): string;
|
|
22
|
+
/**
|
|
23
|
+
* Read file contents
|
|
24
|
+
*/
|
|
25
|
+
readFile(filePath: string, encoding?: BufferEncoding): Promise<Buffer>;
|
|
26
|
+
/**
|
|
27
|
+
* Write file contents
|
|
28
|
+
*/
|
|
29
|
+
writeFile(filePath: string, content: string | Buffer): Promise<string>;
|
|
30
|
+
/**
|
|
31
|
+
* Delete a file
|
|
32
|
+
*/
|
|
33
|
+
deleteFile(filePath: string): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* List directory contents
|
|
36
|
+
*/
|
|
37
|
+
listDir(dirPath: string): Promise<string[]>;
|
|
38
|
+
/**
|
|
39
|
+
* Utility: check if a file or directory exists
|
|
40
|
+
*/
|
|
41
|
+
exists(targetPath: string): Promise<boolean>;
|
|
42
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ===============================
|
|
3
|
+
* Unified Permissions Definition
|
|
4
|
+
* ===============================
|
|
5
|
+
* Used by Agent / Plugin developers to declare required capabilities.
|
|
6
|
+
* Core system will check and inject allowed resources accordingly.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Base Permission type
|
|
10
|
+
*/
|
|
11
|
+
export interface BasePermission {
|
|
12
|
+
type: string;
|
|
13
|
+
description?: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* 1. LLM Permission
|
|
17
|
+
* Example: { type: 'llm', provider: 'openai', capability: 'vision' }
|
|
18
|
+
*/
|
|
19
|
+
export interface LLMPermission extends BasePermission {
|
|
20
|
+
type: 'llm';
|
|
21
|
+
provider?: string;
|
|
22
|
+
capability: 'text' | 'chat' | 'vision' | 'embedding';
|
|
23
|
+
scope?: string[];
|
|
24
|
+
maxTokens?: number;
|
|
25
|
+
rateLimit?: {
|
|
26
|
+
rps: number;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* 2. Vector Store Permission
|
|
31
|
+
* Example: { type: 'vectorstore', provider: 'pinecone', operations: ['insert', 'query'] }
|
|
32
|
+
*/
|
|
33
|
+
export interface VectorStorePermission extends BasePermission {
|
|
34
|
+
type: 'vectorstore';
|
|
35
|
+
provider: string;
|
|
36
|
+
operations: Array<'insert' | 'query' | 'delete'>;
|
|
37
|
+
scope?: string[];
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* 3. Knowledge Base Permission
|
|
41
|
+
* Example: { type: 'knowledge', operations: ['read', 'write'], scope: ['kb_123'] }
|
|
42
|
+
*/
|
|
43
|
+
export interface KnowledgePermission extends BasePermission {
|
|
44
|
+
type: 'knowledge';
|
|
45
|
+
operations: Array<'read' | 'write' | 'update' | 'delete'>;
|
|
46
|
+
scope?: string[];
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* 4. File System Permission
|
|
50
|
+
* Example: { type: 'filesystem', operations: ['read', 'write'], scope: ['/documents', '/images'] }
|
|
51
|
+
*/
|
|
52
|
+
export interface FileSystemPermission extends BasePermission {
|
|
53
|
+
type: 'filesystem';
|
|
54
|
+
operations: Array<'read' | 'write' | 'delete' | 'list'>;
|
|
55
|
+
scope?: string[];
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* 5. Integration Permission
|
|
59
|
+
* Example: { type: 'integration', service: 'feishu', operations: ['read', 'write'] }
|
|
60
|
+
*/
|
|
61
|
+
export interface IntegrationPermission extends BasePermission {
|
|
62
|
+
type: 'integration';
|
|
63
|
+
service: string;
|
|
64
|
+
operations?: Array<'read' | 'write' | 'update' | 'delete'>;
|
|
65
|
+
scope?: string[];
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Union type for all permissions
|
|
69
|
+
*/
|
|
70
|
+
export type Permission = LLMPermission | VectorStorePermission | KnowledgePermission | FileSystemPermission | IntegrationPermission;
|
|
71
|
+
/**
|
|
72
|
+
* Permissions array type
|
|
73
|
+
*/
|
|
74
|
+
export type Permissions = Permission[];
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 通用 UI Schema 字段定义
|
|
3
|
+
*/
|
|
4
|
+
export interface ISchemaUIBase {
|
|
5
|
+
component: string;
|
|
6
|
+
label?: string;
|
|
7
|
+
description?: string;
|
|
8
|
+
placeholder?: string;
|
|
9
|
+
order?: number;
|
|
10
|
+
required?: boolean;
|
|
11
|
+
visibleWhen?: Record<string, any>;
|
|
12
|
+
enabledWhen?: Record<string, any>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Secret 字段扩展
|
|
16
|
+
*/
|
|
17
|
+
export interface ISchemaSecretField extends ISchemaUIBase {
|
|
18
|
+
component: 'secretInput';
|
|
19
|
+
revealable?: boolean;
|
|
20
|
+
maskSymbol?: string;
|
|
21
|
+
persist?: boolean;
|
|
22
|
+
}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { IIntegration, TIntegrationProvider } from '@metad/contracts'
|
|
2
|
-
|
|
1
|
+
import { IIntegration, TIntegrationProvider } from '@metad/contracts';
|
|
3
2
|
export type TIntegrationStrategyParams = {
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
3
|
+
query: string;
|
|
4
|
+
};
|
|
7
5
|
export interface IntegrationStrategy<T = unknown> {
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
meta: TIntegrationProvider;
|
|
7
|
+
execute(integration: IIntegration<T>, payload: TIntegrationStrategyParams): Promise<any>;
|
|
10
8
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { DiscoveryService, Reflector } from '@nestjs/core';
|
|
2
|
+
import { BaseStrategyRegistry } from '../strategy';
|
|
3
|
+
import { IntegrationStrategy } from './strategy.interface';
|
|
4
|
+
export declare class IntegrationStrategyRegistry extends BaseStrategyRegistry<IntegrationStrategy> {
|
|
5
|
+
constructor(discoveryService: DiscoveryService, reflector: Reflector);
|
|
6
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { IIntegration } from '@metad/contracts';
|
|
2
|
+
import { Document } from 'langchain/document';
|
|
3
|
+
export type TKnowledgeStrategyParams = {
|
|
4
|
+
query: string;
|
|
5
|
+
k: number;
|
|
6
|
+
filter: Record<string, any>;
|
|
7
|
+
options: {
|
|
8
|
+
knowledgebaseId: string;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
export interface KnowledgeStrategy {
|
|
12
|
+
execute(integration: IIntegration, payload: TKnowledgeStrategyParams): Promise<{
|
|
13
|
+
chunks: [Document, number][];
|
|
14
|
+
}>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { KnowledgeProviderEnum } from '@metad/contracts';
|
|
2
|
+
import { OnModuleInit } from '@nestjs/common';
|
|
3
|
+
import { DiscoveryService, Reflector } from '@nestjs/core';
|
|
4
|
+
import { KnowledgeStrategy } from './knowledge-strategy.interface';
|
|
5
|
+
export declare class KnowledgeStrategyRegistry implements OnModuleInit {
|
|
6
|
+
private discoveryService;
|
|
7
|
+
private reflector;
|
|
8
|
+
private strategies;
|
|
9
|
+
constructor(discoveryService: DiscoveryService, reflector: Reflector);
|
|
10
|
+
onModuleInit(): void;
|
|
11
|
+
get(type: KnowledgeProviderEnum): KnowledgeStrategy;
|
|
12
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Metadata keys used in plugins for defining various aspects like entities, subscribers, and configurations.
|
|
3
|
+
*/
|
|
4
|
+
export declare const PLUGIN_METADATA: {
|
|
5
|
+
/**
|
|
6
|
+
* Key representing the entities registered within the plugin.
|
|
7
|
+
*/
|
|
8
|
+
readonly ENTITIES: "entities";
|
|
9
|
+
/**
|
|
10
|
+
* Key representing event subscribers within the plugin.
|
|
11
|
+
*/
|
|
12
|
+
readonly SUBSCRIBERS: "subscribers";
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Type definition for valid plugin metadata keys.
|
|
16
|
+
*/
|
|
17
|
+
export type PluginMetadataKey = (typeof PLUGIN_METADATA)[keyof typeof PLUGIN_METADATA];
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PluginMetadata } from './plugin.interface';
|
|
2
|
+
/**
|
|
3
|
+
* Decorator function for extending NestJS features with additional metadata.
|
|
4
|
+
*
|
|
5
|
+
* @param pluginMetadata Metadata to be applied to the target class.
|
|
6
|
+
* @returns Class decorator function.
|
|
7
|
+
*/
|
|
8
|
+
export declare function XpertServerPlugin(pluginMetadata: PluginMetadata): ClassDecorator;
|
|
@@ -8,7 +8,6 @@ export interface IOnPluginBootstrap {
|
|
|
8
8
|
*/
|
|
9
9
|
onPluginBootstrap(): void | Promise<void>;
|
|
10
10
|
}
|
|
11
|
-
|
|
12
11
|
/**
|
|
13
12
|
* Interface for plugins with a destroy lifecycle method.
|
|
14
13
|
*/
|
|
@@ -19,7 +18,6 @@ export interface IOnPluginDestroy {
|
|
|
19
18
|
*/
|
|
20
19
|
onPluginDestroy(): void | Promise<void>;
|
|
21
20
|
}
|
|
22
|
-
|
|
23
21
|
/**
|
|
24
22
|
* Interface for plugins supporting basic seed operations.
|
|
25
23
|
*/
|
|
@@ -30,7 +28,6 @@ export interface IOnPluginWithBasicSeed {
|
|
|
30
28
|
*/
|
|
31
29
|
onPluginBasicSeed(): void | Promise<void>;
|
|
32
30
|
}
|
|
33
|
-
|
|
34
31
|
/**
|
|
35
32
|
* Interface for plugins supporting default seed operations.
|
|
36
33
|
*/
|
|
@@ -41,7 +38,6 @@ export interface IOnPluginWithDefaultSeed {
|
|
|
41
38
|
*/
|
|
42
39
|
onPluginDefaultSeed(): void | Promise<void>;
|
|
43
40
|
}
|
|
44
|
-
|
|
45
41
|
/**
|
|
46
42
|
* Interface for plugins supporting random seed operations.
|
|
47
43
|
*/
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { ModuleMetadata, Type } from '@nestjs/common';
|
|
2
|
+
/**
|
|
3
|
+
* Metadata definition for a plugin in NestJS.
|
|
4
|
+
*/
|
|
5
|
+
export interface PluginMetadata extends ModuleMetadata {
|
|
6
|
+
/**
|
|
7
|
+
* List of entities injected by the plugin.
|
|
8
|
+
*/
|
|
9
|
+
entities?: Array<Type<any>> | (() => Array<Type<any>>);
|
|
10
|
+
/**
|
|
11
|
+
* List of subscribers injected by the plugin.
|
|
12
|
+
*/
|
|
13
|
+
subscribers?: Array<Type<any>> | (() => Array<Type<any>>);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Interface for plugins with a bootstrap lifecycle method.
|
|
17
|
+
*/
|
|
18
|
+
export interface IOnPluginBootstrap {
|
|
19
|
+
/**
|
|
20
|
+
* Called when the plugin is being initialized.
|
|
21
|
+
* @returns A void or a Promise representing the completion of the operation.
|
|
22
|
+
*/
|
|
23
|
+
onPluginBootstrap(): void | Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Interface for plugins with a destroy lifecycle method.
|
|
27
|
+
*/
|
|
28
|
+
export interface IOnPluginDestroy {
|
|
29
|
+
/**
|
|
30
|
+
* Called when the plugin is being destroyed.
|
|
31
|
+
* @returns A void or a Promise representing the completion of the operation.
|
|
32
|
+
*/
|
|
33
|
+
onPluginDestroy(): void | Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Interface for plugins supporting various seed operations.
|
|
37
|
+
*/
|
|
38
|
+
export interface IOnPluginSeedable {
|
|
39
|
+
/**
|
|
40
|
+
* Invoked when seeding basic plugin data.
|
|
41
|
+
* @returns A void or a Promise representing the completion of the operation.
|
|
42
|
+
*/
|
|
43
|
+
onPluginBasicSeed?(): void | Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Invoked when seeding default plugin data.
|
|
46
|
+
* @returns A void or a Promise representing the completion of the operation.
|
|
47
|
+
*/
|
|
48
|
+
onPluginDefaultSeed?(): void | Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Invoked when seeding random plugin data.
|
|
51
|
+
* @returns A void or a Promise representing the completion of the operation.
|
|
52
|
+
*/
|
|
53
|
+
onPluginRandomSeed?(): void | Promise<void>;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Represents the combined lifecycle methods for a plugin.
|
|
57
|
+
* This type combines interfaces for initializing and destroying a plugin.
|
|
58
|
+
*/
|
|
59
|
+
export type PluginLifecycleMethods = IOnPluginBootstrap & IOnPluginDestroy & IOnPluginSeedable;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const IMAGE_UNDERSTANDING_STRATEGY = "IMAGE_UNDERSTANDING_STRATEGY";
|
|
2
|
+
/**
|
|
3
|
+
* Decorator to mark a provider as an Image Understanding Strategy
|
|
4
|
+
*/
|
|
5
|
+
export declare const ImageUnderstandingStrategy: (provider: string) => import("@nestjs/common").CustomDecorator<string>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
|
2
|
+
import { IDocumentUnderstandingProvider } from '@metad/contracts';
|
|
3
|
+
import { Document } from 'langchain/document';
|
|
4
|
+
import { Permissions, XpFileSystem } from '../../core/index';
|
|
5
|
+
import { ChunkMetadata, TDocumentAsset } from '../types';
|
|
6
|
+
export type TImageUnderstandingConfig = {
|
|
7
|
+
stage: 'test' | 'prod';
|
|
8
|
+
visionModel: BaseChatModel;
|
|
9
|
+
permissions?: {
|
|
10
|
+
fileSystem?: XpFileSystem;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
export type TImageUnderstandingInput = {
|
|
14
|
+
chunks: Document<ChunkMetadata>[];
|
|
15
|
+
files: TDocumentAsset[];
|
|
16
|
+
};
|
|
17
|
+
export type TImageUnderstandingResult = {
|
|
18
|
+
chunks: Document<Partial<ChunkMetadata>>[];
|
|
19
|
+
pages?: Document<Partial<ChunkMetadata>>[];
|
|
20
|
+
metadata: any;
|
|
21
|
+
};
|
|
22
|
+
export interface IImageUnderstandingStrategy<TConfig extends TImageUnderstandingConfig = TImageUnderstandingConfig> {
|
|
23
|
+
readonly permissions: Permissions;
|
|
24
|
+
/**
|
|
25
|
+
* Metadata about this strategy
|
|
26
|
+
*/
|
|
27
|
+
readonly meta: IDocumentUnderstandingProvider;
|
|
28
|
+
/**
|
|
29
|
+
* Validate the configuration
|
|
30
|
+
*/
|
|
31
|
+
validateConfig(config: TConfig): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Understand image files (e.g., OCR, VLM, Chart Parsing)
|
|
34
|
+
*/
|
|
35
|
+
understandImages(params: TImageUnderstandingInput, config: TConfig): Promise<TImageUnderstandingResult>;
|
|
36
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { DiscoveryService, Reflector } from '@nestjs/core';
|
|
2
|
+
import { BaseStrategyRegistry } from '../../strategy';
|
|
3
|
+
import { IImageUnderstandingStrategy, TImageUnderstandingConfig } from './strategy.interface';
|
|
4
|
+
export declare class ImageUnderstandingRegistry<TConfig extends TImageUnderstandingConfig = TImageUnderstandingConfig> extends BaseStrategyRegistry<IImageUnderstandingStrategy<TConfig>> {
|
|
5
|
+
constructor(discoveryService: DiscoveryService, reflector: Reflector);
|
|
6
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { VectorStore } from '@langchain/core/vectorstores';
|
|
2
|
+
import { I18nObject } from '@metad/contracts';
|
|
3
|
+
import { Document } from 'langchain/document';
|
|
4
|
+
export type TRetrieverConfig = {
|
|
5
|
+
vectorStore: VectorStore;
|
|
6
|
+
};
|
|
7
|
+
export interface IRetrieverStrategy<TConfig extends TRetrieverConfig = TRetrieverConfig> {
|
|
8
|
+
/**
|
|
9
|
+
* Metadata about this retriever
|
|
10
|
+
*/
|
|
11
|
+
readonly meta: {
|
|
12
|
+
name: string;
|
|
13
|
+
label: I18nObject;
|
|
14
|
+
configSchema: any;
|
|
15
|
+
icon: {
|
|
16
|
+
svg?: string;
|
|
17
|
+
color?: string;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Validate the configuration
|
|
22
|
+
*/
|
|
23
|
+
validateConfig(config: TConfig): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Retrieve relevant documents for a given query
|
|
26
|
+
*/
|
|
27
|
+
retrieve(query: string, options?: TConfig): Promise<{
|
|
28
|
+
documents: Document[];
|
|
29
|
+
}>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { DiscoveryService, Reflector } from '@nestjs/core';
|
|
2
|
+
import { BaseStrategyRegistry } from '../../strategy';
|
|
3
|
+
import { IRetrieverStrategy } from './strategy.interface';
|
|
4
|
+
export declare class RetrieverRegistry extends BaseStrategyRegistry<IRetrieverStrategy> {
|
|
5
|
+
constructor(discoveryService: DiscoveryService, reflector: Reflector);
|
|
6
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { IDocumentSourceProvider, IIntegration } from '@metad/contracts';
|
|
2
|
+
import { Document } from 'langchain/document';
|
|
3
|
+
import { Permissions } from '../../core';
|
|
4
|
+
export interface IDocumentSourceStrategy<TConfig = any> {
|
|
5
|
+
readonly permissions: Permissions;
|
|
6
|
+
/**
|
|
7
|
+
* Metadata about this document source
|
|
8
|
+
*/
|
|
9
|
+
readonly meta: IDocumentSourceProvider;
|
|
10
|
+
/**
|
|
11
|
+
* Validate the configuration
|
|
12
|
+
*/
|
|
13
|
+
validateConfig(config: TConfig): Promise<void>;
|
|
14
|
+
/**
|
|
15
|
+
* Test the connection to the source
|
|
16
|
+
*
|
|
17
|
+
* @param config
|
|
18
|
+
*/
|
|
19
|
+
test(config: TConfig): Promise<any>;
|
|
20
|
+
/**
|
|
21
|
+
* Load documents from the source
|
|
22
|
+
*/
|
|
23
|
+
loadDocuments(config: TConfig, context?: {
|
|
24
|
+
integration?: IIntegration;
|
|
25
|
+
}): Promise<Document[]>;
|
|
26
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { DiscoveryService, Reflector } from '@nestjs/core';
|
|
2
|
+
import { BaseStrategyRegistry } from '../../strategy';
|
|
3
|
+
import { IDocumentSourceStrategy } from './strategy.interface';
|
|
4
|
+
export declare class DocumentSourceRegistry<TConfig = any> extends BaseStrategyRegistry<IDocumentSourceStrategy<TConfig>> {
|
|
5
|
+
constructor(discoveryService: DiscoveryService, reflector: Reflector);
|
|
6
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { IDocumentChunkerProvider, KnowledgeStructureEnum } from '@metad/contracts';
|
|
2
|
+
import { Document } from 'langchain/document';
|
|
3
|
+
import { ChunkMetadata } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
* Split text content into chunks for embedding and retrieval
|
|
6
|
+
*/
|
|
7
|
+
export interface ITextSplitterStrategy<TConfig = any> {
|
|
8
|
+
/**
|
|
9
|
+
* Metadata about this splitter
|
|
10
|
+
*/
|
|
11
|
+
readonly meta: IDocumentChunkerProvider;
|
|
12
|
+
readonly structure: KnowledgeStructureEnum;
|
|
13
|
+
/**
|
|
14
|
+
* Validate the configuration
|
|
15
|
+
*/
|
|
16
|
+
validateConfig(config: TConfig): Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* Split a text into chunks and pages (if applicable)
|
|
19
|
+
*/
|
|
20
|
+
splitDocuments(documents: Document[], options?: TConfig): Promise<{
|
|
21
|
+
chunks: Document<ChunkMetadata>[];
|
|
22
|
+
pages?: Document<ChunkMetadata>[];
|
|
23
|
+
}>;
|
|
24
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { DiscoveryService, Reflector } from '@nestjs/core';
|
|
2
|
+
import { BaseStrategyRegistry } from '../../strategy';
|
|
3
|
+
import { ITextSplitterStrategy } from './strategy.interface';
|
|
4
|
+
export declare class TextSplitterRegistry<TConfig = any> extends BaseStrategyRegistry<ITextSplitterStrategy<TConfig>> {
|
|
5
|
+
constructor(discoveryService: DiscoveryService, reflector: Reflector);
|
|
6
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const DOCUMENT_TRANSFORMER_STRATEGY = "DOCUMENT_TRANSFORMER_STRATEGY";
|
|
2
|
+
/**
|
|
3
|
+
* Decorator to mark a provider as a Document Transformer Strategy
|
|
4
|
+
*/
|
|
5
|
+
export declare const DocumentTransformerStrategy: (provider: string) => import("@nestjs/common").CustomDecorator<string>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { DocumentInterface } from '@langchain/core/documents';
|
|
2
|
+
import { _TFile, IDocumentProcessorProvider, IIntegration } from '@metad/contracts';
|
|
3
|
+
import { Permissions, XpFileSystem } from '../../core/index';
|
|
4
|
+
import { ChunkMetadata, TDocumentAsset } from '../types';
|
|
5
|
+
export type TDocumentTransformerConfig = {
|
|
6
|
+
stage: 'test' | 'prod';
|
|
7
|
+
tempDir?: string;
|
|
8
|
+
permissions?: {
|
|
9
|
+
fileSystem?: XpFileSystem;
|
|
10
|
+
integration?: IIntegration;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
export type TDocumentTransformerFile = _TFile & {
|
|
14
|
+
id?: string;
|
|
15
|
+
filename: string;
|
|
16
|
+
extension: string | undefined;
|
|
17
|
+
};
|
|
18
|
+
export type TDocumentTransformerInput = TDocumentTransformerFile[] | string | string[];
|
|
19
|
+
export type TDocumentTransformerResult = {
|
|
20
|
+
id?: string;
|
|
21
|
+
chunks: DocumentInterface<ChunkMetadata>[];
|
|
22
|
+
metadata: {
|
|
23
|
+
assets?: TDocumentAsset[];
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
export interface IDocumentTransformerStrategy<TConfig extends TDocumentTransformerConfig = TDocumentTransformerConfig> {
|
|
27
|
+
/**
|
|
28
|
+
* Metadata about this transformer
|
|
29
|
+
*/
|
|
30
|
+
readonly meta: IDocumentProcessorProvider;
|
|
31
|
+
readonly permissions: Permissions;
|
|
32
|
+
/**
|
|
33
|
+
* Validate the configuration
|
|
34
|
+
*/
|
|
35
|
+
validateConfig(config: TConfig): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Transform documents (e.g., extract, OCR, normalize, enrich metadata)
|
|
38
|
+
*/
|
|
39
|
+
transformDocuments(files: TDocumentTransformerInput, config: TConfig): Promise<TDocumentTransformerResult[]>;
|
|
40
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { DiscoveryService, Reflector } from '@nestjs/core';
|
|
2
|
+
import { BaseStrategyRegistry } from '../../strategy';
|
|
3
|
+
import { IDocumentTransformerStrategy, TDocumentTransformerConfig } from './strategy.interface';
|
|
4
|
+
export declare class DocumentTransformerRegistry<TConfig extends TDocumentTransformerConfig = TDocumentTransformerConfig> extends BaseStrategyRegistry<IDocumentTransformerStrategy<TConfig>> {
|
|
5
|
+
constructor(discoveryService: DiscoveryService, reflector: Reflector);
|
|
6
|
+
}
|