@xpert-ai/plugin-sdk 0.0.3-0 → 3.6.0-beta.10

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/package.json CHANGED
@@ -1,11 +1,24 @@
1
1
  {
2
2
  "name": "@xpert-ai/plugin-sdk",
3
- "version": "0.0.3-0",
3
+ "version": "3.6.0-beta.10",
4
4
  "license": "AGPL-3.0",
5
5
  "dependencies": {},
6
6
  "main": "./index.cjs.js",
7
7
  "module": "./index.esm.js",
8
8
  "publishConfig": {
9
9
  "access": "public"
10
+ },
11
+ "peerDependencies": {
12
+ "@langchain/core": "*",
13
+ "@metad/contracts": "*",
14
+ "@nestjs/common": "*",
15
+ "@nestjs/core": "*",
16
+ "@nestjs/microservices": "*",
17
+ "lodash-es": "*",
18
+ "i18next-fs-backend": "*",
19
+ "i18next": "*",
20
+ "zod": "*",
21
+ "fs": "*",
22
+ "path": "*"
10
23
  }
11
24
  }
@@ -0,0 +1,2 @@
1
+ import { i18n as I18nInstance } from 'i18next';
2
+ export declare function createI18nInstance(pluginDir: string, language?: string): Promise<I18nInstance>;
@@ -1,3 +1,4 @@
1
1
  export * from './file-system';
2
2
  export * from './permissions';
3
3
  export * from './schema';
4
+ export * from './i18n';
@@ -1,5 +1,5 @@
1
1
  /**
2
- * 通用 UI Schema 字段定义
2
+ * Common UI Schema field definitions
3
3
  */
4
4
  export interface ISchemaUIBase {
5
5
  component: string;
@@ -12,7 +12,7 @@ export interface ISchemaUIBase {
12
12
  enabledWhen?: Record<string, any>;
13
13
  }
14
14
  /**
15
- * Secret 字段扩展
15
+ * Secret field extensions
16
16
  */
17
17
  export interface ISchemaSecretField extends ISchemaUIBase {
18
18
  component: 'secretInput';
@@ -5,4 +5,5 @@ export type TIntegrationStrategyParams = {
5
5
  export interface IntegrationStrategy<T = unknown> {
6
6
  meta: TIntegrationProvider;
7
7
  execute(integration: IIntegration<T>, payload: TIntegrationStrategyParams): Promise<any>;
8
+ validateConfig?(config: T): Promise<void>;
8
9
  }
@@ -1,5 +1,5 @@
1
1
  import { IIntegration } from '@metad/contracts';
2
- import { Document } from 'langchain/document';
2
+ import { Document } from '@langchain/core/documents';
3
3
  export type TKnowledgeStrategyParams = {
4
4
  query: string;
5
5
  k: number;
@@ -1,8 +1,8 @@
1
+ import { Document } from '@langchain/core/documents';
1
2
  import { BaseChatModel } from '@langchain/core/language_models/chat_models';
2
- import { IDocumentUnderstandingProvider } from '@metad/contracts';
3
- import { Document } from 'langchain/document';
3
+ import { IDocumentUnderstandingProvider, IKnowledgeDocument } from '@metad/contracts';
4
4
  import { Permissions, XpFileSystem } from '../../core/index';
5
- import { ChunkMetadata, TDocumentAsset } from '../types';
5
+ import { ChunkMetadata } from '../types';
6
6
  export type TImageUnderstandingConfig = {
7
7
  stage: 'test' | 'prod';
8
8
  visionModel: BaseChatModel;
@@ -10,10 +10,6 @@ export type TImageUnderstandingConfig = {
10
10
  fileSystem?: XpFileSystem;
11
11
  };
12
12
  };
13
- export type TImageUnderstandingInput = {
14
- chunks: Document<ChunkMetadata>[];
15
- files: TDocumentAsset[];
16
- };
17
13
  export type TImageUnderstandingResult = {
18
14
  chunks: Document<Partial<ChunkMetadata>>[];
19
15
  pages?: Document<Partial<ChunkMetadata>>[];
@@ -32,5 +28,5 @@ export interface IImageUnderstandingStrategy<TConfig extends TImageUnderstanding
32
28
  /**
33
29
  * Understand image files (e.g., OCR, VLM, Chart Parsing)
34
30
  */
35
- understandImages(params: TImageUnderstandingInput, config: TConfig): Promise<TImageUnderstandingResult>;
31
+ understandImages(doc: IKnowledgeDocument<ChunkMetadata>, config: TConfig): Promise<TImageUnderstandingResult>;
36
32
  }
@@ -1,6 +1,6 @@
1
1
  import { VectorStore } from '@langchain/core/vectorstores';
2
2
  import { I18nObject } from '@metad/contracts';
3
- import { Document } from 'langchain/document';
3
+ import { Document } from '@langchain/core/documents';
4
4
  export type TRetrieverConfig = {
5
5
  vectorStore: VectorStore;
6
6
  };
@@ -1,5 +1,5 @@
1
1
  import { IDocumentSourceProvider, IIntegration } from '@metad/contracts';
2
- import { Document } from 'langchain/document';
2
+ import { Document } from '@langchain/core/documents';
3
3
  import { Permissions } from '../../core';
4
4
  export interface IDocumentSourceStrategy<TConfig = any> {
5
5
  readonly permissions: Permissions;
@@ -23,4 +23,14 @@ export interface IDocumentSourceStrategy<TConfig = any> {
23
23
  loadDocuments(config: TConfig, context?: {
24
24
  integration?: IIntegration;
25
25
  }): Promise<Document[]>;
26
+ /**
27
+ * Load a single document by its ID
28
+ *
29
+ * @deprecated Planning
30
+ * @param documentId
31
+ * @param context
32
+ */
33
+ loadDocument?(document: Document, context: {
34
+ integration?: IIntegration;
35
+ }): Promise<Document>;
26
36
  }
@@ -1,5 +1,5 @@
1
1
  import { IDocumentChunkerProvider, KnowledgeStructureEnum } from '@metad/contracts';
2
- import { Document } from 'langchain/document';
2
+ import { Document } from '@langchain/core/documents';
3
3
  import { ChunkMetadata } from '../types';
4
4
  /**
5
5
  * Split text content into chunks for embedding and retrieval
@@ -1,7 +1,6 @@
1
- import { DocumentInterface } from '@langchain/core/documents';
2
- import { _TFile, IDocumentProcessorProvider, IIntegration } from '@metad/contracts';
1
+ import { IDocumentProcessorProvider, IIntegration, IKnowledgeDocument } from '@metad/contracts';
3
2
  import { Permissions, XpFileSystem } from '../../core/index';
4
- import { ChunkMetadata, TDocumentAsset } from '../types';
3
+ import { ChunkMetadata } from '../types';
5
4
  export type TDocumentTransformerConfig = {
6
5
  stage: 'test' | 'prod';
7
6
  tempDir?: string;
@@ -10,19 +9,6 @@ export type TDocumentTransformerConfig = {
10
9
  integration?: IIntegration;
11
10
  };
12
11
  };
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
12
  export interface IDocumentTransformerStrategy<TConfig extends TDocumentTransformerConfig = TDocumentTransformerConfig> {
27
13
  /**
28
14
  * Metadata about this transformer
@@ -36,5 +22,5 @@ export interface IDocumentTransformerStrategy<TConfig extends TDocumentTransform
36
22
  /**
37
23
  * Transform documents (e.g., extract, OCR, normalize, enrich metadata)
38
24
  */
39
- transformDocuments(files: TDocumentTransformerInput, config: TConfig): Promise<TDocumentTransformerResult[]>;
25
+ transformDocuments(files: Partial<IKnowledgeDocument>[], config: TConfig): Promise<Partial<IKnowledgeDocument<ChunkMetadata>>[]>;
40
26
  }
@@ -13,7 +13,15 @@ export interface ChunkMetadata {
13
13
  startOffset?: number;
14
14
  endOffset?: number;
15
15
  type?: 'parent' | 'child';
16
+ /**
17
+ * Default to 'text'. Indicates the original media type of the chunk.
18
+ * @default text
19
+ */
20
+ mediaType?: 'text' | 'image' | 'video' | 'audio';
16
21
  children?: DocumentInterface<ChunkMetadata>[];
22
+ /**
23
+ * Associated assets like images, videos, etc.
24
+ */
17
25
  assets?: TDocumentAsset[];
18
26
  [key: string]: any;
19
27
  }
@@ -2,15 +2,15 @@ import { PluginMeta } from '@metad/contracts';
2
2
  import type { DynamicModule, INestApplicationContext } from '@nestjs/common';
3
3
  import type { ZodSchema } from 'zod';
4
4
  export interface PluginLifecycle {
5
- /** 在模块注册完成但应用启动前调用 */
5
+ /** Called after module registration but before application startup */
6
6
  onInit?(ctx: PluginContext): Promise<void> | void;
7
- /** 在应用启动后调用(可开始对外服务) */
7
+ /** Called after application startup (can start serving externally) */
8
8
  onStart?(ctx: PluginContext): Promise<void> | void;
9
- /** 优雅停机时调用 */
9
+ /** Called during graceful shutdown */
10
10
  onStop?(ctx: PluginContext): Promise<void> | void;
11
11
  }
12
12
  export interface PluginHealth {
13
- /** 返回健康状态与可选的依赖检查详情 */
13
+ /** Returns health status and optional dependency check details */
14
14
  checkHealth?(ctx: PluginContext): Promise<{
15
15
  status: 'up' | 'down';
16
16
  details?: any;
@@ -20,22 +20,22 @@ export interface PluginHealth {
20
20
  };
21
21
  }
22
22
  export interface PluginConfigSpec<T extends object = any> {
23
- /** 插件级配置的 zod 校验 schema(可选) */
23
+ /** Zod validation schema for plugin-level config (optional) */
24
24
  schema?: ZodSchema<T>;
25
- /** 默认配置 */
25
+ /** Default configuration */
26
26
  defaults?: Partial<T>;
27
27
  }
28
28
  export interface XpertPlugin<TConfig extends object = any> extends PluginLifecycle, PluginHealth {
29
29
  meta: PluginMeta;
30
30
  config?: PluginConfigSpec<TConfig>;
31
- /** 返回要挂载到主应用的 DynamicModule(可设为 global */
31
+ /** Returns the DynamicModule to be mounted to the main application (can be set as global) */
32
32
  register(ctx: PluginContext<TConfig>): DynamicModule;
33
33
  }
34
34
  export interface PluginContext<TConfig extends object = any> {
35
35
  app: INestApplicationContext;
36
36
  logger: PluginLogger;
37
37
  config: TConfig;
38
- /** 访问容器中其他 Provider 的辅助方法 */
38
+ /** Helper method to access other Providers in the container */
39
39
  resolve<TInput = any, TResult = TInput>(token: any): TResult;
40
40
  }
41
41
  export interface PluginLogger {