@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
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { DocumentInterface } from '@langchain/core/documents';
|
|
2
|
+
export type TDocumentAsset = {
|
|
3
|
+
type: 'image' | 'video' | 'audio' | 'file';
|
|
4
|
+
url: string;
|
|
5
|
+
filePath: string;
|
|
6
|
+
};
|
|
7
|
+
export interface ChunkMetadata {
|
|
8
|
+
documentId?: string;
|
|
9
|
+
pageId?: string;
|
|
10
|
+
chunkId: string;
|
|
11
|
+
parentId?: string;
|
|
12
|
+
chunkIndex?: number;
|
|
13
|
+
startOffset?: number;
|
|
14
|
+
endOffset?: number;
|
|
15
|
+
type?: 'parent' | 'child';
|
|
16
|
+
children?: DocumentInterface<ChunkMetadata>[];
|
|
17
|
+
assets?: TDocumentAsset[];
|
|
18
|
+
[key: string]: any;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Merge parent chunks with their child chunks based on metadata (parentId and chunkId)
|
|
22
|
+
* @param chunks
|
|
23
|
+
* @param children
|
|
24
|
+
* @returns
|
|
25
|
+
*/
|
|
26
|
+
export declare function mergeParentChildChunks(chunks: DocumentInterface<ChunkMetadata>[], // Parent chunks
|
|
27
|
+
children: DocumentInterface<ChunkMetadata>[]): DocumentInterface<ChunkMetadata>[];
|
|
28
|
+
export declare function isRemoteFile(path: string): boolean;
|
|
29
|
+
export declare function downloadRemoteFile(url: string, dest: string): Promise<string>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { OnModuleInit } from "@nestjs/common";
|
|
2
|
+
import { DiscoveryService, Reflector } from "@nestjs/core";
|
|
3
|
+
export declare class BaseStrategyRegistry<S> implements OnModuleInit {
|
|
4
|
+
protected readonly strategyKey: string;
|
|
5
|
+
protected discoveryService: DiscoveryService;
|
|
6
|
+
protected reflector: Reflector;
|
|
7
|
+
protected strategies: Map<string, S>;
|
|
8
|
+
constructor(strategyKey: string, discoveryService: DiscoveryService, reflector: Reflector);
|
|
9
|
+
onModuleInit(): void;
|
|
10
|
+
get(type: string): S;
|
|
11
|
+
list(): S[];
|
|
12
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { StructuredToolInterface } from '@langchain/core/tools';
|
|
2
|
+
import { BaseStore } from '@langchain/langgraph';
|
|
3
|
+
import { I18nObject, IXpertToolset, ToolProviderCredentials, TToolCredentials, TToolsetParams, XpertToolsetCategoryEnum } from '@metad/contracts';
|
|
4
|
+
import { Logger } from '@nestjs/common';
|
|
5
|
+
import { CommandBus, QueryBus } from '@nestjs/cqrs';
|
|
6
|
+
import { BaseToolset } from './toolset';
|
|
7
|
+
/**
|
|
8
|
+
* The context params of creating toolset
|
|
9
|
+
*/
|
|
10
|
+
export type TBuiltinToolsetParams = TToolsetParams & {
|
|
11
|
+
commandBus: CommandBus;
|
|
12
|
+
queryBus: QueryBus;
|
|
13
|
+
store?: BaseStore;
|
|
14
|
+
};
|
|
15
|
+
export interface IBuiltinToolset {
|
|
16
|
+
validateCredentials(credentials: TToolCredentials): Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
export declare abstract class BuiltinToolset<T extends StructuredToolInterface = StructuredToolInterface, C = TToolCredentials> extends BaseToolset<T> implements IBuiltinToolset {
|
|
19
|
+
providerName: string;
|
|
20
|
+
protected toolset?: IXpertToolset;
|
|
21
|
+
protected params?: TBuiltinToolsetParams;
|
|
22
|
+
static provider: string;
|
|
23
|
+
protected logger: Logger;
|
|
24
|
+
providerType: XpertToolsetCategoryEnum.BUILTIN;
|
|
25
|
+
credentialsSchema?: {
|
|
26
|
+
[key: string]: ToolProviderCredentials;
|
|
27
|
+
};
|
|
28
|
+
get tenantId(): string;
|
|
29
|
+
get organizationId(): string;
|
|
30
|
+
get commandBus(): CommandBus<import("@nestjs/cqrs").ICommand>;
|
|
31
|
+
get queryBus(): QueryBus<import("@nestjs/cqrs").IQuery>;
|
|
32
|
+
get xpertId(): string;
|
|
33
|
+
constructor(providerName: string, toolset?: IXpertToolset, params?: TBuiltinToolsetParams);
|
|
34
|
+
validateCredentials(credentials: C): Promise<void>;
|
|
35
|
+
_validateCredentials(credentials: C): Promise<void>;
|
|
36
|
+
getId(): string;
|
|
37
|
+
getCredentials(): C;
|
|
38
|
+
getToolTitle(name: string): string | I18nObject;
|
|
39
|
+
/**
|
|
40
|
+
* Get credentials schema
|
|
41
|
+
*
|
|
42
|
+
* @returns Credentials schema
|
|
43
|
+
*/
|
|
44
|
+
getCredentialsSchema(): {
|
|
45
|
+
[key: string]: ToolProviderCredentials;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Get toolset entity
|
|
49
|
+
*
|
|
50
|
+
* @returns XpertToolset
|
|
51
|
+
*/
|
|
52
|
+
getToolset(): IXpertToolset;
|
|
53
|
+
getName(): string;
|
|
54
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { DynamicStructuredTool } from '@langchain/core/tools';
|
|
2
|
+
import { I18nObject } from '@metad/contracts';
|
|
3
|
+
import { ZodSchema } from 'zod';
|
|
4
|
+
import { BuiltinToolset } from './builtin';
|
|
5
|
+
export interface IToolsetStrategy<TConfig = any> {
|
|
6
|
+
/**
|
|
7
|
+
* Metadata about this toolset
|
|
8
|
+
*/
|
|
9
|
+
readonly meta: {
|
|
10
|
+
author: string;
|
|
11
|
+
tags: string[];
|
|
12
|
+
name: string;
|
|
13
|
+
label: I18nObject;
|
|
14
|
+
description?: I18nObject;
|
|
15
|
+
configSchema: any;
|
|
16
|
+
icon?: {
|
|
17
|
+
svg?: string;
|
|
18
|
+
png?: string;
|
|
19
|
+
color?: string;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Validate the configuration
|
|
24
|
+
*/
|
|
25
|
+
validateConfig(config: TConfig): Promise<void>;
|
|
26
|
+
create(config: TConfig): Promise<BuiltinToolset>;
|
|
27
|
+
createTools(): DynamicStructuredTool<ZodSchema>[];
|
|
28
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { DiscoveryService, Reflector } from '@nestjs/core';
|
|
2
|
+
import { IToolsetStrategy } from './strategy.interface';
|
|
3
|
+
import { BaseStrategyRegistry } from '../strategy';
|
|
4
|
+
export declare class ToolsetRegistry<TConfig = any> extends BaseStrategyRegistry<IToolsetStrategy<TConfig>> {
|
|
5
|
+
constructor(discoveryService: DiscoveryService, reflector: Reflector);
|
|
6
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { BaseToolkit, StructuredTool, StructuredToolInterface } from "@langchain/core/tools";
|
|
2
|
+
import { I18nObject, TStateVariable, TToolsetParams } from "@metad/contracts";
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
type ZodObjectAny = z.ZodObject<any, any, any, any>;
|
|
5
|
+
/**
|
|
6
|
+
* Base ability for all toolsets
|
|
7
|
+
*/
|
|
8
|
+
export declare abstract class BaseToolset<T extends StructuredToolInterface = StructuredToolInterface> extends BaseToolkit {
|
|
9
|
+
protected params?: TToolsetParams;
|
|
10
|
+
abstract providerName: string;
|
|
11
|
+
tools: T[];
|
|
12
|
+
stateVariables: TStateVariable[];
|
|
13
|
+
constructor(params?: TToolsetParams);
|
|
14
|
+
/**
|
|
15
|
+
* Async init tools
|
|
16
|
+
*
|
|
17
|
+
* @returns
|
|
18
|
+
*/
|
|
19
|
+
initTools(): Promise<T[]>;
|
|
20
|
+
/**
|
|
21
|
+
* Get ID of the toolset
|
|
22
|
+
*/
|
|
23
|
+
abstract getId(): string;
|
|
24
|
+
/**
|
|
25
|
+
* Get name of the toolset
|
|
26
|
+
*/
|
|
27
|
+
abstract getName(): string;
|
|
28
|
+
/**
|
|
29
|
+
* Get one tool
|
|
30
|
+
*
|
|
31
|
+
* @param toolName
|
|
32
|
+
* @returns
|
|
33
|
+
*/
|
|
34
|
+
getTool(toolName: string): StructuredToolInterface<import("@langchain/core/tools").ToolSchemaBase, any, any>;
|
|
35
|
+
/**
|
|
36
|
+
* Get state variables config
|
|
37
|
+
*
|
|
38
|
+
* @returns State variables
|
|
39
|
+
*/
|
|
40
|
+
getVariables(): Promise<TStateVariable[]>;
|
|
41
|
+
/**
|
|
42
|
+
* Get title of tool
|
|
43
|
+
*/
|
|
44
|
+
abstract getToolTitle(name: string): string | I18nObject;
|
|
45
|
+
/**
|
|
46
|
+
* Close all (connections).
|
|
47
|
+
*/
|
|
48
|
+
close(): Promise<void>;
|
|
49
|
+
}
|
|
50
|
+
export declare abstract class BaseTool<T extends ZodObjectAny = ZodObjectAny> extends StructuredTool<T> {
|
|
51
|
+
schema: any;
|
|
52
|
+
}
|
|
53
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { PluginMeta } from '@metad/contracts';
|
|
2
|
+
import type { DynamicModule, INestApplicationContext } from '@nestjs/common';
|
|
3
|
+
import type { ZodSchema } from 'zod';
|
|
4
|
+
export interface PluginLifecycle {
|
|
5
|
+
/** 在模块注册完成但应用启动前调用 */
|
|
6
|
+
onInit?(ctx: PluginContext): Promise<void> | void;
|
|
7
|
+
/** 在应用启动后调用(可开始对外服务) */
|
|
8
|
+
onStart?(ctx: PluginContext): Promise<void> | void;
|
|
9
|
+
/** 优雅停机时调用 */
|
|
10
|
+
onStop?(ctx: PluginContext): Promise<void> | void;
|
|
11
|
+
}
|
|
12
|
+
export interface PluginHealth {
|
|
13
|
+
/** 返回健康状态与可选的依赖检查详情 */
|
|
14
|
+
checkHealth?(ctx: PluginContext): Promise<{
|
|
15
|
+
status: 'up' | 'down';
|
|
16
|
+
details?: any;
|
|
17
|
+
}> | {
|
|
18
|
+
status: 'up' | 'down';
|
|
19
|
+
details?: any;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export interface PluginConfigSpec<T extends object = any> {
|
|
23
|
+
/** 插件级配置的 zod 校验 schema(可选) */
|
|
24
|
+
schema?: ZodSchema<T>;
|
|
25
|
+
/** 默认配置 */
|
|
26
|
+
defaults?: Partial<T>;
|
|
27
|
+
}
|
|
28
|
+
export interface XpertPlugin<TConfig extends object = any> extends PluginLifecycle, PluginHealth {
|
|
29
|
+
meta: PluginMeta;
|
|
30
|
+
config?: PluginConfigSpec<TConfig>;
|
|
31
|
+
/** 返回要挂载到主应用的 DynamicModule(可设为 global) */
|
|
32
|
+
register(ctx: PluginContext<TConfig>): DynamicModule;
|
|
33
|
+
}
|
|
34
|
+
export interface PluginContext<TConfig extends object = any> {
|
|
35
|
+
app: INestApplicationContext;
|
|
36
|
+
logger: PluginLogger;
|
|
37
|
+
config: TConfig;
|
|
38
|
+
/** 访问容器中其他 Provider 的辅助方法 */
|
|
39
|
+
resolve<TInput = any, TResult = TInput>(token: any): TResult;
|
|
40
|
+
}
|
|
41
|
+
export interface PluginLogger {
|
|
42
|
+
child(meta: Record<string, any>): PluginLogger;
|
|
43
|
+
debug(msg: string, meta?: any): void;
|
|
44
|
+
log(msg: string, meta?: any): void;
|
|
45
|
+
warn(msg: string, meta?: any): void;
|
|
46
|
+
error(msg: string, meta?: any): void;
|
|
47
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { EmbeddingsInterface } from '@langchain/core/embeddings';
|
|
2
|
+
import { VectorStore } from '@langchain/core/vectorstores';
|
|
3
|
+
/**
|
|
4
|
+
* Interface for VectorStore strategy。
|
|
5
|
+
*
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
export interface IVectorStoreStrategy<TConfig extends {
|
|
9
|
+
collectionName?: string;
|
|
10
|
+
}> {
|
|
11
|
+
/**
|
|
12
|
+
* Metadata about the strategy
|
|
13
|
+
*/
|
|
14
|
+
readonly name: string;
|
|
15
|
+
readonly description?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Validate configuration for VectorStore
|
|
18
|
+
*/
|
|
19
|
+
validateConfig(config: TConfig): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Create a VectorStore with given config
|
|
22
|
+
*/
|
|
23
|
+
createStore(embeddings: EmbeddingsInterface, config: TConfig): Promise<VectorStore>;
|
|
24
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { DiscoveryService, Reflector } from '@nestjs/core';
|
|
2
|
+
import { BaseStrategyRegistry } from '../strategy';
|
|
3
|
+
import { IVectorStoreStrategy } from './strategy.interface';
|
|
4
|
+
export declare class VectorStoreRegistry<TConfig = any> extends BaseStrategyRegistry<IVectorStoreStrategy<TConfig>> {
|
|
5
|
+
constructor(discoveryService: DiscoveryService, reflector: Reflector);
|
|
6
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Runnable } from '@langchain/core/runnables';
|
|
2
|
+
import { BaseChannel } from '@langchain/langgraph';
|
|
3
|
+
import { IEnvironment, IWorkflowNode, TWorkflowNodeMeta, TXpertGraph, TXpertParameter, TXpertTeamNode } from '@metad/contracts';
|
|
4
|
+
export type TWorkflowNodeParams<TConfig = any> = {
|
|
5
|
+
xpertId: string;
|
|
6
|
+
agentKey?: string;
|
|
7
|
+
node: TXpertTeamNode;
|
|
8
|
+
config: TConfig;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Workflow Node Strategy interface
|
|
12
|
+
*/
|
|
13
|
+
export interface IWorkflowNodeStrategy<TConfig = any, TResult = any> {
|
|
14
|
+
/**
|
|
15
|
+
* Metadata describing the node (type, label, description, config schema, etc.)
|
|
16
|
+
*/
|
|
17
|
+
meta: TWorkflowNodeMeta;
|
|
18
|
+
/**
|
|
19
|
+
* Create the node subgraph
|
|
20
|
+
*/
|
|
21
|
+
create(payload: {
|
|
22
|
+
graph: TXpertGraph;
|
|
23
|
+
node: TXpertTeamNode & {
|
|
24
|
+
type: 'workflow';
|
|
25
|
+
};
|
|
26
|
+
xpertId: string;
|
|
27
|
+
environment: IEnvironment;
|
|
28
|
+
isDraft: boolean;
|
|
29
|
+
}): {
|
|
30
|
+
name?: string;
|
|
31
|
+
graph: Runnable;
|
|
32
|
+
ends: string[];
|
|
33
|
+
channel: {
|
|
34
|
+
name: string;
|
|
35
|
+
annotation: BaseChannel;
|
|
36
|
+
};
|
|
37
|
+
navigator?: (state: any, config: any) => Promise<any>;
|
|
38
|
+
};
|
|
39
|
+
outputVariables(entity: IWorkflowNode): TXpertParameter[];
|
|
40
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DiscoveryService, Reflector } from '@nestjs/core';
|
|
2
|
+
import { BaseStrategyRegistry } from '../../strategy';
|
|
3
|
+
import { IWorkflowNodeStrategy } from './strategy.interface';
|
|
4
|
+
/**
|
|
5
|
+
* Registry for Workflow Node Strategies
|
|
6
|
+
*/
|
|
7
|
+
export declare class WorkflowNodeRegistry<TConfig = any, TResult = any> extends BaseStrategyRegistry<IWorkflowNodeStrategy<TConfig, TResult>> {
|
|
8
|
+
constructor(discoveryService: DiscoveryService, reflector: Reflector);
|
|
9
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { TWorkflowTriggerMeta, TXpertTeamNode } from '@metad/contracts';
|
|
2
|
+
export type TWorkflowTriggerParams<T> = {
|
|
3
|
+
xpertId: string;
|
|
4
|
+
agentKey?: string;
|
|
5
|
+
node?: TXpertTeamNode;
|
|
6
|
+
config: T;
|
|
7
|
+
};
|
|
8
|
+
export interface IWorkflowTriggerStrategy<T> {
|
|
9
|
+
meta: TWorkflowTriggerMeta;
|
|
10
|
+
validate(payload: TWorkflowTriggerParams<T>): Promise<any[]>;
|
|
11
|
+
/**
|
|
12
|
+
* Initialize the trigger when publish xpert workflow
|
|
13
|
+
*
|
|
14
|
+
* @param payload
|
|
15
|
+
* @param callback
|
|
16
|
+
*/
|
|
17
|
+
publish(payload: TWorkflowTriggerParams<T>, callback: (payload: any) => void): Promise<any> | void;
|
|
18
|
+
/**
|
|
19
|
+
* Stop the trigger
|
|
20
|
+
*/
|
|
21
|
+
stop(payload: TWorkflowTriggerParams<T>): void;
|
|
22
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { DiscoveryService, Reflector } from '@nestjs/core';
|
|
2
|
+
import { BaseStrategyRegistry } from '../../strategy';
|
|
3
|
+
import { IWorkflowTriggerStrategy } from './strategy.interface';
|
|
4
|
+
export declare class WorkflowTriggerRegistry<T = any> extends BaseStrategyRegistry<IWorkflowTriggerStrategy<T>> {
|
|
5
|
+
constructor(discoveryService: DiscoveryService, reflector: Reflector);
|
|
6
|
+
}
|
package/.eslintrc.json
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": ["../../.eslintrc.json"],
|
|
3
|
-
"ignorePatterns": ["!**/*"],
|
|
4
|
-
"overrides": [
|
|
5
|
-
{
|
|
6
|
-
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
|
|
7
|
-
"rules": {}
|
|
8
|
-
},
|
|
9
|
-
{
|
|
10
|
-
"files": ["*.ts", "*.tsx"],
|
|
11
|
-
"rules": {}
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
"files": ["*.js", "*.jsx"],
|
|
15
|
-
"rules": {}
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
"files": ["*.json"],
|
|
19
|
-
"parser": "jsonc-eslint-parser",
|
|
20
|
-
"rules": {
|
|
21
|
-
"@nx/dependency-checks": [
|
|
22
|
-
"error",
|
|
23
|
-
{
|
|
24
|
-
"ignoredFiles": ["{projectRoot}/rollup.config.{js,ts,mjs,mts}"]
|
|
25
|
-
}
|
|
26
|
-
]
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
]
|
|
30
|
-
}
|
package/.swcrc
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"jsc": {
|
|
3
|
-
"target": "es2017",
|
|
4
|
-
"parser": {
|
|
5
|
-
"syntax": "typescript",
|
|
6
|
-
"decorators": true,
|
|
7
|
-
"dynamicImport": true
|
|
8
|
-
},
|
|
9
|
-
"transform": {
|
|
10
|
-
"decoratorMetadata": true,
|
|
11
|
-
"legacyDecorator": true
|
|
12
|
-
},
|
|
13
|
-
"keepClassNames": true,
|
|
14
|
-
"externalHelpers": true,
|
|
15
|
-
"loose": true
|
|
16
|
-
},
|
|
17
|
-
"module": {
|
|
18
|
-
"type": "es6"
|
|
19
|
-
},
|
|
20
|
-
"sourceMaps": true,
|
|
21
|
-
"exclude": [
|
|
22
|
-
"jest.config.ts",
|
|
23
|
-
".*\\.spec.tsx?$",
|
|
24
|
-
".*\\.test.tsx?$",
|
|
25
|
-
"./src/jest-setup.ts$",
|
|
26
|
-
"./**/jest-setup.ts$",
|
|
27
|
-
".*.js$"
|
|
28
|
-
]
|
|
29
|
-
}
|
package/PERMISSIONS.md
DELETED
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
# 插件权限设计指南
|
|
2
|
-
|
|
3
|
-
:::tip
|
|
4
|
-
在 meta 中设计一套可以向核心系统反向请求 大模型 调用权限的(如请求一个 OpenAI Client实例)的配置,例如在 meta中声明大模型的权限请求,在 configSchema 中设计属性让用户配置具体的模型提供商和模型名称,核心系统在识别到权限请求时会根据 config 中用户配置的具体参数实例化大模型 Client 通过 config 传入到 understandImages 这个方法:
|
|
5
|
-
:::
|
|
6
|
-
|
|
7
|
-
👌明白了,你希望 **在插件 Strategy 的 meta 中声明依赖的大模型权限请求**,核心系统解析后根据用户配置(模型提供商 + 模型名称 + 其他参数)自动注入一个 `client` 到 `config`,这样插件不用自己创建 OpenAI / Anthropic / 其他 VLM 客户端。
|
|
8
|
-
|
|
9
|
-
我帮你重新设计 `OpenAIGPT4VStrategy` 的 meta 和 configSchema,使它能 **反向请求核心系统提供的 Client**。
|
|
10
|
-
|
|
11
|
-
---
|
|
12
|
-
|
|
13
|
-
## 新版 Strategy
|
|
14
|
-
|
|
15
|
-
```ts
|
|
16
|
-
import { Injectable } from '@nestjs/common';
|
|
17
|
-
import { Document } from 'langchain/document';
|
|
18
|
-
import {
|
|
19
|
-
ImageUnderstandingStrategy,
|
|
20
|
-
IImageUnderstandingStrategy,
|
|
21
|
-
TImageUnderstandingFile,
|
|
22
|
-
TImageUnderstandingResult
|
|
23
|
-
} from './strategy.interface';
|
|
24
|
-
|
|
25
|
-
@Injectable()
|
|
26
|
-
@ImageUnderstandingStrategy('openai-gpt4v')
|
|
27
|
-
export class OpenAIGPT4VStrategy implements IImageUnderstandingStrategy<any> {
|
|
28
|
-
readonly meta = {
|
|
29
|
-
name: 'openai-gpt4v',
|
|
30
|
-
label: { en: 'OpenAI GPT-4 Vision', zh: 'OpenAI GPT-4 图像理解' },
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* 权限声明:告诉核心系统,这个插件需要一个 "llm" 权限,
|
|
34
|
-
* 提供方是 openai,能力是 vision。
|
|
35
|
-
* 核心系统识别后会根据 config.provider + config.model 实例化对应的 Client,
|
|
36
|
-
* 并注入到 config.client
|
|
37
|
-
*/
|
|
38
|
-
permissions: [
|
|
39
|
-
{
|
|
40
|
-
type: 'llm',
|
|
41
|
-
provider: 'openai',
|
|
42
|
-
capability: 'vision',
|
|
43
|
-
},
|
|
44
|
-
],
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* 配置 schema,用户需要填写 provider 和 model,
|
|
48
|
-
* 核心系统会根据 provider + model + 用户账号 API Key,
|
|
49
|
-
* 实例化好 Client 注入。
|
|
50
|
-
*/
|
|
51
|
-
configSchema: {
|
|
52
|
-
type: 'object',
|
|
53
|
-
properties: {
|
|
54
|
-
provider: {
|
|
55
|
-
type: 'string',
|
|
56
|
-
enum: ['openai'],
|
|
57
|
-
description: '模型提供商'
|
|
58
|
-
},
|
|
59
|
-
model: {
|
|
60
|
-
type: 'string',
|
|
61
|
-
default: 'gpt-4-vision-preview',
|
|
62
|
-
description: '大模型名称'
|
|
63
|
-
},
|
|
64
|
-
prompt: {
|
|
65
|
-
type: 'string',
|
|
66
|
-
default: 'Describe this image in detail.',
|
|
67
|
-
description: '提示词(可以自定义理解任务)'
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
required: ['provider', 'model']
|
|
71
|
-
},
|
|
72
|
-
|
|
73
|
-
icon: {
|
|
74
|
-
svg: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20"><circle cx="10" cy="10" r="8" stroke="black" fill="none"/><text x="6" y="14">VLM</text></svg>',
|
|
75
|
-
color: '#10a37f'
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
async validateConfig(config: any): Promise<void> {
|
|
80
|
-
if (!config.client) {
|
|
81
|
-
throw new Error('Missing injected LLM client in config. Core system must inject client.');
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
async understandImages(
|
|
86
|
-
files: TImageUnderstandingFile[],
|
|
87
|
-
config: any
|
|
88
|
-
): Promise<TImageUnderstandingResult[]> {
|
|
89
|
-
const client = config.client; // ✅ 已由核心系统注入
|
|
90
|
-
const results: TImageUnderstandingResult[] = [];
|
|
91
|
-
|
|
92
|
-
for (const file of files) {
|
|
93
|
-
const description = await this.runGPT4V(client, file.path, config);
|
|
94
|
-
|
|
95
|
-
const doc = new Document({
|
|
96
|
-
pageContent: description,
|
|
97
|
-
metadata: {
|
|
98
|
-
chunkId: `img-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
|
|
99
|
-
parentChunkId: file.parentChunkId,
|
|
100
|
-
imagePath: file.path,
|
|
101
|
-
source: file.filename,
|
|
102
|
-
type: 'vlm',
|
|
103
|
-
engine: config.model
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
results.push({
|
|
108
|
-
docs: [doc],
|
|
109
|
-
metadata: { engine: config.model, file: file.filename }
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return results;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
private async runGPT4V(client: any, imagePath: string, config: any): Promise<string> {
|
|
117
|
-
// client 已经是 openai client,由核心系统实例化
|
|
118
|
-
const response = await client.chat.completions.create({
|
|
119
|
-
model: config.model,
|
|
120
|
-
messages: [
|
|
121
|
-
{
|
|
122
|
-
role: 'user',
|
|
123
|
-
content: [
|
|
124
|
-
{ type: 'text', text: config.prompt || 'Describe this image in detail.' },
|
|
125
|
-
{ type: 'image_url', image_url: { url: imagePath } }
|
|
126
|
-
]
|
|
127
|
-
}
|
|
128
|
-
],
|
|
129
|
-
max_tokens: 500
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
return response.choices[0]?.message?.content || '';
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
---
|
|
138
|
-
|
|
139
|
-
## 🔑 核心系统如何处理
|
|
140
|
-
|
|
141
|
-
* 解析插件的 `meta.permissions`,发现需要:
|
|
142
|
-
|
|
143
|
-
```json
|
|
144
|
-
{ "type": "llm", "provider": "openai", "capability": "vision" }
|
|
145
|
-
```
|
|
146
|
-
* 根据用户 `config.provider = "openai"`, `config.model = "gpt-4-vision-preview"`
|
|
147
|
-
实例化 `OpenAI({ apiKey: userApiKey })`
|
|
148
|
-
* 将 client 注入到 `config.client`
|
|
149
|
-
* 调用 `strategy.understandImages(files, config)`
|
|
150
|
-
|
|
151
|
-
---
|
|
152
|
-
|
|
153
|
-
## 📌 使用示例
|
|
154
|
-
|
|
155
|
-
```ts
|
|
156
|
-
const strategy = this.imageUnderstandingRegistry.get('openai-gpt4v');
|
|
157
|
-
const result = await strategy.understandImages(
|
|
158
|
-
[
|
|
159
|
-
{
|
|
160
|
-
path: 'https://example.com/chart.png',
|
|
161
|
-
filename: 'chart.png',
|
|
162
|
-
extname: 'png',
|
|
163
|
-
parentChunkId: 'uuid-123'
|
|
164
|
-
}
|
|
165
|
-
],
|
|
166
|
-
{
|
|
167
|
-
provider: 'openai',
|
|
168
|
-
model: 'gpt-4-vision-preview',
|
|
169
|
-
prompt: '请用中文详细描述这张图片。',
|
|
170
|
-
client: openaiClient // ✅ 核心系统注入
|
|
171
|
-
}
|
|
172
|
-
);
|
|
173
|
-
|
|
174
|
-
console.log(result[0].docs[0].pageContent);
|
|
175
|
-
```
|
|
176
|
-
|
|
177
|
-
---
|
|
178
|
-
|
|
179
|
-
这样插件本身不依赖任何 `openai` 包装逻辑,**只声明权限 + 要求 provider/model**,核心系统就能注入合适的 client。
|
|
180
|
-
|
|
181
|
-
要不要我帮你写一个 **抽象的权限声明接口 (例如 ILLMPermissionRequest)**,这样 OCR/VLM/Embedding 插件都可以统一声明依赖?
|
package/README.md
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
# plugin-sdk
|
|
2
|
-
|
|
3
|
-
This library was generated with [Nx](https://nx.dev).
|
|
4
|
-
|
|
5
|
-
## Building
|
|
6
|
-
|
|
7
|
-
Run `nx build plugin-sdk` to build the library.
|
|
8
|
-
|
|
9
|
-
## Running unit tests
|
|
10
|
-
|
|
11
|
-
Run `nx test plugin-sdk` to execute the unit tests via [Jest](https://jestjs.io).
|
|
12
|
-
|
|
13
|
-
## Schema config
|
|
14
|
-
|
|
15
|
-
[Schema UI 扩展规范](./SCHEMA_SPECIFICATION.md)
|
|
16
|
-
|
|
17
|
-
## Permissions
|
|
18
|
-
|
|
19
|
-
[插件权限设计指南](./PERMISSIONS.md)
|