@xpert-ai/plugin-sdk 3.6.0-beta.6 → 3.6.1

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 (43) hide show
  1. package/README.md +0 -1
  2. package/SCHEMA_SPECIFICATION.md +2 -0
  3. package/index.cjs.js +39393 -50530
  4. package/index.esm.js +39595 -50780
  5. package/package.json +15 -2
  6. package/src/index.d.ts +1 -1
  7. package/src/lib/ai-model/abstract-provider.d.ts +41 -0
  8. package/src/lib/ai-model/ai-model-provider.decorator.d.ts +2 -0
  9. package/src/lib/ai-model/ai-model-provider.interface.d.ts +42 -0
  10. package/src/lib/ai-model/ai-model-provider.registry.d.ts +6 -0
  11. package/src/lib/ai-model/ai-model.d.ts +33 -0
  12. package/src/lib/ai-model/entities/defaults.d.ts +3 -0
  13. package/src/lib/ai-model/entities/index.d.ts +2 -0
  14. package/src/lib/ai-model/entities/model_entities.d.ts +14 -0
  15. package/src/lib/ai-model/errors.d.ts +5 -0
  16. package/src/lib/ai-model/index.d.ts +8 -0
  17. package/src/lib/ai-model/llm.d.ts +49 -0
  18. package/src/lib/ai-model/openai-compatible/completions.d.ts +23 -0
  19. package/src/lib/ai-model/openai-compatible/index.d.ts +3 -0
  20. package/src/lib/ai-model/openai-compatible/rerank.d.ts +20 -0
  21. package/src/lib/ai-model/openai-compatible/speech2text.d.ts +17 -0
  22. package/src/lib/ai-model/types/index.d.ts +11 -0
  23. package/src/lib/ai-model/types/model.d.ts +43 -0
  24. package/src/lib/ai-model/types/rerank.d.ts +20 -0
  25. package/src/lib/ai-model/types/speech2text.d.ts +3 -0
  26. package/src/lib/ai-model/types/text-embedding-model.d.ts +7 -0
  27. package/src/lib/ai-model/types/tts.d.ts +5 -0
  28. package/src/lib/core/file-system.d.ts +13 -0
  29. package/src/lib/core/index.d.ts +1 -0
  30. package/src/lib/core/utils.d.ts +12 -0
  31. package/src/lib/rag/image/strategy.interface.d.ts +5 -10
  32. package/src/lib/rag/index.d.ts +1 -0
  33. package/src/lib/{knowledge → rag/knowledge}/knowledge-strategy.interface.d.ts +1 -1
  34. package/src/lib/rag/knowledge/knowledge-strategy.registry.d.ts +6 -0
  35. package/src/lib/rag/retriever/strategy.interface.d.ts +1 -1
  36. package/src/lib/rag/source/strategy.interface.d.ts +1 -1
  37. package/src/lib/rag/textsplitter/strategy.interface.d.ts +3 -4
  38. package/src/lib/rag/transformer/strategy.interface.d.ts +2 -1
  39. package/src/lib/rag/types.d.ts +5 -16
  40. package/src/lib/workflow/node/strategy.interface.d.ts +11 -10
  41. package/src/lib/knowledge/knowledge-strategy.registry.d.ts +0 -12
  42. /package/src/lib/{knowledge → rag/knowledge}/index.d.ts +0 -0
  43. /package/src/lib/{knowledge → rag/knowledge}/knowledge-strategy.decorator.d.ts +0 -0
package/package.json CHANGED
@@ -1,11 +1,24 @@
1
1
  {
2
2
  "name": "@xpert-ai/plugin-sdk",
3
- "version": "3.6.0-beta.6",
3
+ "version": "3.6.1",
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
+ }
package/src/index.d.ts CHANGED
@@ -3,10 +3,10 @@ export * from './lib/plugin.interface';
3
3
  export * from './lib/plugin-metadata';
4
4
  export * from './lib/types';
5
5
  export * from './lib/logger';
6
- export * from './lib/knowledge';
7
6
  export * from './lib/integration/index';
8
7
  export * from './lib/workflow/index';
9
8
  export * from './lib/vectorstore/index';
10
9
  export * from './lib/rag/index';
11
10
  export * from './lib/toolset/index';
12
11
  export * from './lib/core/index';
12
+ export * from './lib/ai-model/index';
@@ -0,0 +1,41 @@
1
+ import { Embeddings } from '@langchain/core/embeddings';
2
+ import { BaseLanguageModel } from '@langchain/core/language_models/base';
3
+ import { BaseChatModel } from '@langchain/core/language_models/chat_models';
4
+ import { AIModelEntity, AiModelTypeEnum, IAiProviderEntity, ICopilotModel, ProviderModel } from '@metad/contracts';
5
+ import { Logger } from '@nestjs/common';
6
+ import { AIModel } from './ai-model';
7
+ import { IAIModelProviderStrategy } from './ai-model-provider.interface';
8
+ import { TChatModelOptions, IRerank } from './types/';
9
+ export declare abstract class ModelProvider implements IAIModelProviderStrategy {
10
+ readonly logger: Logger;
11
+ protected _name?: string;
12
+ protected _meta?: IAiProviderEntity;
13
+ get name(): string;
14
+ protected modelManagers: Map<AiModelTypeEnum, AIModel>;
15
+ private dir?;
16
+ constructor();
17
+ validateCredentials(credentials: Record<string, any>): Promise<void>;
18
+ abstract getAuthorization(credentials: Record<string, any>): string;
19
+ abstract getBaseUrl(credentials: Record<string, any>): string;
20
+ abstract validateProviderCredentials(credentials: Record<string, any>): Promise<void>;
21
+ /**
22
+ * Get provider lib root path.
23
+ *
24
+ * @returns Root of library
25
+ */
26
+ getProviderServerPath(): string;
27
+ getProviderSchema(): IAiProviderEntity;
28
+ getModels(modelType: AiModelTypeEnum): Promise<AIModelEntity[]>;
29
+ registerAIModelInstance(modelType: AiModelTypeEnum, modelInstance: AIModel): void;
30
+ getModelManager<T extends AIModel>(modelType: AiModelTypeEnum): T;
31
+ /**
32
+ * Get provider models.
33
+ * @param modelType - model type
34
+ * @param onlyActive - only active models
35
+ * @return provider models
36
+ */
37
+ getProviderModels(modelType?: AiModelTypeEnum, onlyActive?: boolean): ProviderModel[];
38
+ getSystemProviderModels(modelTypes: AiModelTypeEnum[]): any[];
39
+ getChatModel(copilotModel: ICopilotModel, options?: TChatModelOptions): BaseChatModel<import("@langchain/core/language_models/chat_models").BaseChatModelCallOptions, import("@langchain/core/messages").AIMessageChunk>;
40
+ getModelInstance(type: AiModelTypeEnum, copilotModel: ICopilotModel, options?: TChatModelOptions): Promise<BaseLanguageModel | BaseChatModel | Embeddings | IRerank>;
41
+ }
@@ -0,0 +1,2 @@
1
+ export declare const AI_MODEL_PROVIDER = "AI_MODEL_PROVIDER";
2
+ export declare function AIModelProviderStrategy(provider: string): (target: any) => void;
@@ -0,0 +1,42 @@
1
+ import { AiModelTypeEnum, IAiProviderEntity, ICopilotModel, ProviderModel, AIModelEntity } from '@metad/contracts';
2
+ import { BaseLanguageModel } from '@langchain/core/language_models/base';
3
+ import { Embeddings } from '@langchain/core/embeddings';
4
+ import { BaseChatModel } from '@langchain/core/language_models/chat_models';
5
+ import { IRerank } from './types';
6
+ import { AIModel } from './ai-model';
7
+ export interface IAIModelProviderStrategy {
8
+ /**
9
+ * Provider metadata
10
+ */
11
+ /**
12
+ * Validate whether the credentials are valid
13
+ */
14
+ validateCredentials(credentials: Record<string, any>): Promise<void>;
15
+ /**
16
+ * @deprecated use validateCredentials instead
17
+ */
18
+ validateProviderCredentials(credentials: Record<string, any>): Promise<void>;
19
+ /**
20
+ * Get the provider's Base URL
21
+ */
22
+ getBaseUrl(credentials: Record<string, any>): string;
23
+ /**
24
+ * Get authorization information, such as API Key, Token, etc.
25
+ */
26
+ getAuthorization(credentials: Record<string, any>): string;
27
+ /**
28
+ * Get the list of models supported by the provider
29
+ */
30
+ getModels(modelType: AiModelTypeEnum): Promise<AIModelEntity[]>;
31
+ /**
32
+ * Return a directly usable model instance (LLM / Embedding / TTS / Rerank)
33
+ */
34
+ getModelInstance(type: AiModelTypeEnum, copilotModel: ICopilotModel, options?: Record<string, any>): Promise<BaseLanguageModel | BaseChatModel | Embeddings | IRerank>;
35
+ /**
36
+ * Return the defined provider models (metadata)
37
+ */
38
+ getProviderModels?(modelType?: AiModelTypeEnum, onlyActive?: boolean): ProviderModel[];
39
+ getProviderSchema(): IAiProviderEntity;
40
+ getProviderServerPath(): string;
41
+ getModelManager<T extends AIModel>(modelType: AiModelTypeEnum): T;
42
+ }
@@ -0,0 +1,6 @@
1
+ import { DiscoveryService, Reflector } from '@nestjs/core';
2
+ import { BaseStrategyRegistry } from '../strategy';
3
+ import { IAIModelProviderStrategy } from './ai-model-provider.interface';
4
+ export declare class AIModelProviderRegistry extends BaseStrategyRegistry<IAIModelProviderStrategy> {
5
+ constructor(discoveryService: DiscoveryService, reflector: Reflector);
6
+ }
@@ -0,0 +1,33 @@
1
+ import { BaseChatModel } from '@langchain/core/language_models/chat_models';
2
+ import { AIModelEntity, AiModelTypeEnum, ICopilotModel, ParameterRule, PriceInfo, PriceType } from '@metad/contracts';
3
+ import { Logger } from '@nestjs/common';
4
+ import { IAIModel, TChatModelOptions } from './types/';
5
+ import { ModelProvider } from './abstract-provider';
6
+ export declare abstract class AIModel implements IAIModel {
7
+ protected readonly modelProvider: ModelProvider;
8
+ modelType: AiModelTypeEnum;
9
+ protected logger: Logger;
10
+ protected modelSchemas: AIModelEntity[] | null;
11
+ private positions;
12
+ constructor(modelProvider: ModelProvider, modelType: AiModelTypeEnum);
13
+ abstract validateCredentials(model: string, credentials: Record<string, any>): Promise<void>;
14
+ getChatModel(copilotModel: ICopilotModel, options?: TChatModelOptions): BaseChatModel;
15
+ getPrice(model: string, credentials: Record<string, any>, priceType: PriceType, tokens: number): PriceInfo;
16
+ protected getModelPath(): string;
17
+ predefinedModels(): AIModelEntity[];
18
+ getModelSchema(model: string, credentials?: Record<string, any>): AIModelEntity | null;
19
+ /**
20
+ * Get customizable model schema.
21
+ * Implement this method in ai model sub class that can customize model
22
+ *
23
+ * @param model model name
24
+ * @param credentials model credentials
25
+ * @returns model schema
26
+ */
27
+ protected getCustomizableModelSchemaFromCredentials(model: string, credentials: Record<string, any>): AIModelEntity | null;
28
+ private processParameterRules;
29
+ private processLabel;
30
+ private sortModelSchemas;
31
+ protected _commonParameterRules(model: string): ParameterRule[];
32
+ getParameterRules(model: string, credentials: Record<string, string>): ParameterRule[];
33
+ }
@@ -0,0 +1,3 @@
1
+ import { ParameterRule } from "@metad/contracts";
2
+ import { DefaultParameterName } from "./model_entities";
3
+ export declare const PARAMETER_RULE_TEMPLATE: Record<DefaultParameterName, ParameterRule>;
@@ -0,0 +1,2 @@
1
+ export * from './defaults';
2
+ export * from './model_entities';
@@ -0,0 +1,14 @@
1
+ export declare function valueOf<T>(enumObj: T, value: string): T[keyof T];
2
+ export declare enum DefaultParameterName {
3
+ TEMPERATURE = "temperature",
4
+ TOP_P = "top_p",
5
+ TOP_K = "top_k",
6
+ PRESENCE_PENALTY = "presence_penalty",
7
+ FREQUENCY_PENALTY = "frequency_penalty",
8
+ MAX_TOKENS = "max_tokens",
9
+ RESPONSE_FORMAT = "response_format",
10
+ JSON_SCHEMA = "json_schema"
11
+ }
12
+ export interface ModelUsage {
13
+ token?: number;
14
+ }
@@ -0,0 +1,5 @@
1
+ import { ForbiddenException, NotFoundException } from "@nestjs/common";
2
+ export declare class AiModelNotFoundException extends NotFoundException {
3
+ }
4
+ export declare class CredentialsValidateFailedError extends ForbiddenException {
5
+ }
@@ -0,0 +1,8 @@
1
+ export * from './ai-model-provider.interface';
2
+ export * from './ai-model-provider.decorator';
3
+ export * from './ai-model-provider.registry';
4
+ export * from './abstract-provider';
5
+ export * from './types';
6
+ export * from './llm';
7
+ export * from './errors';
8
+ export * from './openai-compatible';
@@ -0,0 +1,49 @@
1
+ import { AIModelEntity, ICopilot, ILLMUsage, ParameterRule, TTokenUsage } from '@metad/contracts';
2
+ import { Logger } from '@nestjs/common';
3
+ import { LLMResult } from '@langchain/core/outputs';
4
+ import { AIModel } from './ai-model';
5
+ import { TChatModelOptions } from './types/';
6
+ export type CommonChatModelParameters = {
7
+ temperature: number;
8
+ maxRetries?: number | null;
9
+ };
10
+ export declare class LLMUsage implements ILLMUsage {
11
+ /**
12
+ * Model class for llm usage.
13
+ */
14
+ promptTokens: number;
15
+ promptUnitPrice: number;
16
+ promptPriceUnit: number;
17
+ promptPrice: number;
18
+ completionTokens: number;
19
+ completionUnitPrice: number;
20
+ completionPriceUnit: number;
21
+ completionPrice: number;
22
+ totalTokens: number;
23
+ totalPrice: number;
24
+ currency: string;
25
+ latency: number;
26
+ constructor(promptTokens: number, promptUnitPrice: number, promptPriceUnit: number, promptPrice: number, completionTokens: number, completionUnitPrice: number, completionPriceUnit: number, completionPrice: number, totalTokens: number, totalPrice: number, currency: string, latency: number);
27
+ static emptyUsage(): LLMUsage;
28
+ plus(other: LLMUsage): LLMUsage;
29
+ add(other: LLMUsage): LLMUsage;
30
+ }
31
+ export declare abstract class LargeLanguageModel extends AIModel {
32
+ #private;
33
+ protected startedAt: DOMHighResTimeStamp;
34
+ protected _commonParameterRules(model: string): ParameterRule[];
35
+ protected calcResponseUsage(model: string, credentials: Record<string, any>, promptTokens: number, completionTokens: number): ILLMUsage;
36
+ createHandleUsageCallbacks(copilot: ICopilot, model: string, credentials: any, handleLLMTokens: TChatModelOptions['handleLLMTokens']): {
37
+ handleLLMStart: () => void;
38
+ handleLLMEnd: (output: any) => void;
39
+ }[];
40
+ createHandleLLMErrorCallbacks(fields: any, logger?: Logger): {
41
+ handleLLMError: (err: any) => void;
42
+ };
43
+ protected getCustomizableModelSchemaFromCredentials(model: string, credentials: Record<string, any>): AIModelEntity | null;
44
+ }
45
+ export declare function calcTokenUsage(output: LLMResult): TTokenUsage;
46
+ /**
47
+ * @deprecated use calcTokenUsage
48
+ */
49
+ export declare function sumTokenUsage(output: LLMResult): number;
@@ -0,0 +1,23 @@
1
+ import { ChatOpenAICompletions, ChatOpenAIFields, ClientOptions, OpenAIClient } from '@langchain/openai';
2
+ export type TOAIAPICompatLLMParams = ChatOpenAIFields & {
3
+ configuration: ClientOptions;
4
+ };
5
+ /**
6
+ * A model extended from ChatOpenAICompletions, compatible with OpenAI-style chat completions,
7
+ * and supports structuring content within `<think>` reasoning tags into the `reasoning_content` field.
8
+ *
9
+ * This class overrides the `_convertCompletionsDeltaToBaseMessageChunk` method to detect `<think>` and `</think>` tags in the completion stream:
10
+ * - When `<think>` is encountered, it enters reasoning content collection mode. Subsequent content is collected into the `reasoning_content` field and does not appear in the main `content` field.
11
+ * - When `</think>` is encountered, reasoning content collection ends.
12
+ * - In other cases, the `reasoning_content` field is directly assigned from the `reasoning_content` in the delta.
13
+ *
14
+ * In this way, the reasoning process in the model output can be separated from the main content, making it easier for subsequent structured processing and display.
15
+ */
16
+ export declare class ChatOAICompatReasoningModel extends ChatOpenAICompletions {
17
+ private thinking;
18
+ /**
19
+ *
20
+ */
21
+ protected _convertCompletionsDeltaToBaseMessageChunk(delta: Record<string, any>, rawResponse: OpenAIClient.ChatCompletionChunk, defaultRole?: 'function' | 'user' | 'system' | 'developer' | 'assistant' | 'tool'): import("@langchain/core/messages").AIMessageChunk | import("@langchain/core/messages").HumanMessageChunk | import("@langchain/core/messages").SystemMessageChunk | import("@langchain/core/messages").FunctionMessageChunk | import("@langchain/core/messages").ToolMessageChunk | import("@langchain/core/messages").ChatMessageChunk;
22
+ protected _convertCompletionsMessageToBaseMessage(message: OpenAIClient.ChatCompletionMessage, rawResponse: OpenAIClient.ChatCompletion): import("@langchain/core/messages").BaseMessage;
23
+ }
@@ -0,0 +1,3 @@
1
+ export * from './completions';
2
+ export * from './rerank';
3
+ export * from './speech2text';
@@ -0,0 +1,20 @@
1
+ import { Document } from '@langchain/core/documents';
2
+ import { IRerank, RerankResult } from '../types';
3
+ export declare class OpenAICompatibleReranker implements IRerank {
4
+ credentials: {
5
+ endpointUrl: string;
6
+ apiKey: string;
7
+ endpointModelName?: string;
8
+ };
9
+ constructor(credentials: {
10
+ endpointUrl: string;
11
+ apiKey: string;
12
+ endpointModelName?: string;
13
+ });
14
+ rerank(docs: Document<Record<string, any>>[], query: string, options: {
15
+ topN?: number;
16
+ scoreThreshold?: number;
17
+ model: string;
18
+ returnDocuments?: boolean;
19
+ }): Promise<RerankResult[]>;
20
+ }
@@ -0,0 +1,17 @@
1
+ import { CallbackManagerForLLMRun } from '@langchain/core/callbacks/manager';
2
+ import { BaseChatModel, BaseChatModelParams } from '@langchain/core/language_models/chat_models';
3
+ import { BaseMessage } from '@langchain/core/messages';
4
+ import { ChatResult } from '@langchain/core/outputs';
5
+ export interface ChatSpeech2TextInput extends BaseChatModelParams {
6
+ /**
7
+ */
8
+ apiKey?: string;
9
+ model: string;
10
+ }
11
+ export declare class Speech2TextChatModel extends BaseChatModel {
12
+ private fields?;
13
+ _llmType(): string;
14
+ protected apiKey: string;
15
+ constructor(fields?: Partial<ChatSpeech2TextInput>);
16
+ _generate(messages: BaseMessage[], options: this['ParsedCallOptions'], runManager?: CallbackManagerForLLMRun): Promise<ChatResult>;
17
+ }
@@ -0,0 +1,11 @@
1
+ export * from './text-embedding-model';
2
+ export * from './rerank';
3
+ export * from './model';
4
+ export * from './speech2text';
5
+ export * from './tts';
6
+ export declare const PROVIDE_AI_MODEL_LLM = "provide_ai_model_llm";
7
+ export declare const PROVIDE_AI_MODEL_MODERATION = "provide_ai_model_moderation";
8
+ export declare const PROVIDE_AI_MODEL_SPEECH2TEXT = "provide_ai_model_speech2text";
9
+ export declare const PROVIDE_AI_MODEL_TEXT_EMBEDDING = "provide_ai_model_text_embedding";
10
+ export declare const PROVIDE_AI_MODEL_TTS = "provide_ai_model_tts";
11
+ export declare const PROVIDE_AI_MODEL_RERANK = "provide_ai_model_rerank";
@@ -0,0 +1,43 @@
1
+ import { BaseChatModel } from "@langchain/core/language_models/chat_models";
2
+ import { AIModelEntity, ICopilot, ICopilotModel, ILLMUsage, ParameterType } from "@metad/contracts";
3
+ export type TChatModelOptions = {
4
+ modelProperties: Record<string, any>;
5
+ handleLLMTokens: (input: {
6
+ copilot: ICopilot;
7
+ model?: string;
8
+ usage?: ILLMUsage;
9
+ /**
10
+ * @deprecated use usage
11
+ */
12
+ tokenUsed?: number;
13
+ }) => void;
14
+ verbose: boolean;
15
+ };
16
+ export interface IAIModel {
17
+ validateCredentials(model: string, credentials: Record<string, any>): Promise<void>;
18
+ getChatModel(copilotModel: ICopilotModel, options?: TChatModelOptions): BaseChatModel;
19
+ predefinedModels(): AIModelEntity[];
20
+ }
21
+ export declare const CommonParameterRules: {
22
+ name: string;
23
+ label: {
24
+ zh_Hans: string;
25
+ en_US: string;
26
+ };
27
+ type: ParameterType;
28
+ help: {
29
+ zh_Hans: string;
30
+ en_US: string;
31
+ };
32
+ required: boolean;
33
+ default: number;
34
+ min: number;
35
+ max: number;
36
+ precision: number;
37
+ }[];
38
+ export declare function mergeCredentials(credentials: any, modelProperties: any): any;
39
+ export type TModelProperties = {
40
+ endpoint_url: string;
41
+ api_key: string;
42
+ endpoint_model_name?: string;
43
+ };
@@ -0,0 +1,20 @@
1
+ import { Document } from '@langchain/core/documents';
2
+ import { ICopilotModel } from '@metad/contracts';
3
+ import { AIModel } from '../ai-model';
4
+ import { TChatModelOptions } from './model';
5
+ export type RerankResult = {
6
+ index: number;
7
+ relevanceScore: number;
8
+ document?: Document<Record<string, any>>;
9
+ };
10
+ export declare abstract class RerankModel extends AIModel {
11
+ validateCredentials(model: string, credentials: Record<string, any>): Promise<void>;
12
+ abstract getReranker(copilotModel: ICopilotModel, options?: TChatModelOptions): Promise<IRerank>;
13
+ }
14
+ export interface IRerank {
15
+ rerank(docs: Document<Record<string, any>>[], query: string, options: {
16
+ topN?: number;
17
+ scoreThreshold?: number;
18
+ model?: string;
19
+ }): Promise<RerankResult[]>;
20
+ }
@@ -0,0 +1,3 @@
1
+ import { AIModel } from "../ai-model";
2
+ export declare abstract class SpeechToTextModel extends AIModel {
3
+ }
@@ -0,0 +1,7 @@
1
+ import { Embeddings } from '@langchain/core/embeddings';
2
+ import { ICopilotModel } from '@metad/contracts';
3
+ import { AIModel } from '../ai-model';
4
+ import { TChatModelOptions } from './model';
5
+ export declare abstract class TextEmbeddingModelManager extends AIModel {
6
+ abstract getEmbeddingInstance(copilotModel: ICopilotModel, options?: TChatModelOptions): Embeddings;
7
+ }
@@ -0,0 +1,5 @@
1
+ import { ParameterRule } from '@metad/contracts';
2
+ import { AIModel } from '../ai-model';
3
+ export declare abstract class TextToSpeechModel extends AIModel {
4
+ getParameterRules(model: string, credentials: Record<string, string>): ParameterRule[];
5
+ }
@@ -18,7 +18,20 @@ export declare class XpFileSystem {
18
18
  * Check if path is within scope
19
19
  */
20
20
  private ensureInScope;
21
+ /**
22
+ * Get the absolute path of file in the file system.
23
+ *
24
+ * @param filePath Relative file path
25
+ * @returns Absolute file path
26
+ */
21
27
  fullPath(filePath: string): string;
28
+ /**
29
+ * Get web url for a given file path in the file system.
30
+ *
31
+ * @param filePath Relative file path
32
+ * @returns Web URL of file
33
+ */
34
+ fullUrl(filePath: string): string;
22
35
  /**
23
36
  * Read file contents
24
37
  */
@@ -2,3 +2,4 @@ export * from './file-system';
2
2
  export * from './permissions';
3
3
  export * from './schema';
4
4
  export * from './i18n';
5
+ export * from './utils';
@@ -0,0 +1,12 @@
1
+ import { Logger } from '@nestjs/common';
2
+ export declare function loadYamlFile<T>(filePath: string, logger?: Logger, ignoreError?: boolean, defaultValue?: T): T;
3
+ /**
4
+ * Get the mapping from name to index from a YAML file
5
+ *
6
+ * @param folderPath
7
+ * @param fileName the YAML file name, default to '_position.yaml'
8
+ * @return a dict with name as key and index as value
9
+ */
10
+ export declare function getPositionMap(folderPath: string, fileName?: string, logger?: Logger): Record<string, number>;
11
+ export declare function getPositionList(folderPath: string, fileName?: string, logger?: Logger): string[];
12
+ export declare function getErrorMessage(err: any): string;
@@ -1,8 +1,8 @@
1
+ import { DocumentInterface } 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,13 +10,8 @@ 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
- chunks: Document<Partial<ChunkMetadata>>[];
19
- pages?: Document<Partial<ChunkMetadata>>[];
14
+ chunks: DocumentInterface<Partial<ChunkMetadata>>[];
20
15
  metadata: any;
21
16
  };
22
17
  export interface IImageUnderstandingStrategy<TConfig extends TImageUnderstandingConfig = TImageUnderstandingConfig> {
@@ -32,5 +27,5 @@ export interface IImageUnderstandingStrategy<TConfig extends TImageUnderstanding
32
27
  /**
33
28
  * Understand image files (e.g., OCR, VLM, Chart Parsing)
34
29
  */
35
- understandImages(params: TImageUnderstandingInput, config: TConfig): Promise<TImageUnderstandingResult>;
30
+ understandImages(doc: IKnowledgeDocument<ChunkMetadata>, config: TConfig): Promise<TImageUnderstandingResult>;
36
31
  }
@@ -4,3 +4,4 @@ export * from './transformer/index';
4
4
  export * from './retriever/index';
5
5
  export * from './types';
6
6
  export * from './image/index';
7
+ export * from './knowledge/index';
@@ -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;
@@ -0,0 +1,6 @@
1
+ import { DiscoveryService, Reflector } from '@nestjs/core';
2
+ import { BaseStrategyRegistry } from '../../strategy';
3
+ import { KnowledgeStrategy } from './knowledge-strategy.interface';
4
+ export declare class KnowledgeStrategyRegistry extends BaseStrategyRegistry<KnowledgeStrategy> {
5
+ constructor(discoveryService: DiscoveryService, reflector: Reflector);
6
+ }
@@ -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;
@@ -1,5 +1,5 @@
1
1
  import { IDocumentChunkerProvider, KnowledgeStructureEnum } from '@metad/contracts';
2
- import { Document } from 'langchain/document';
2
+ import { DocumentInterface } from '@langchain/core/documents';
3
3
  import { ChunkMetadata } from '../types';
4
4
  /**
5
5
  * Split text content into chunks for embedding and retrieval
@@ -17,8 +17,7 @@ export interface ITextSplitterStrategy<TConfig = any> {
17
17
  /**
18
18
  * Split a text into chunks and pages (if applicable)
19
19
  */
20
- splitDocuments(documents: Document[], options?: TConfig): Promise<{
21
- chunks: Document<ChunkMetadata>[];
22
- pages?: Document<ChunkMetadata>[];
20
+ splitDocuments(documents: DocumentInterface[], options?: TConfig): Promise<{
21
+ chunks: DocumentInterface<ChunkMetadata>[];
23
22
  }>;
24
23
  }
@@ -1,5 +1,6 @@
1
1
  import { IDocumentProcessorProvider, IIntegration, IKnowledgeDocument } from '@metad/contracts';
2
2
  import { Permissions, XpFileSystem } from '../../core/index';
3
+ import { ChunkMetadata } from '../types';
3
4
  export type TDocumentTransformerConfig = {
4
5
  stage: 'test' | 'prod';
5
6
  tempDir?: string;
@@ -21,5 +22,5 @@ export interface IDocumentTransformerStrategy<TConfig extends TDocumentTransform
21
22
  /**
22
23
  * Transform documents (e.g., extract, OCR, normalize, enrich metadata)
23
24
  */
24
- transformDocuments(files: Partial<IKnowledgeDocument>[], config: TConfig): Promise<Partial<IKnowledgeDocument>[]>;
25
+ transformDocuments(files: Partial<IKnowledgeDocument>[], config: TConfig): Promise<Partial<IKnowledgeDocument<ChunkMetadata>>[]>;
25
26
  }
@@ -1,27 +1,16 @@
1
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;
2
+ import { IDocChunkMetadata } from '@metad/contracts';
3
+ export { TDocumentAsset } from '@metad/contracts';
4
+ export interface ChunkMetadata extends IDocChunkMetadata {
13
5
  startOffset?: number;
14
6
  endOffset?: number;
15
7
  type?: 'parent' | 'child';
16
- children?: DocumentInterface<ChunkMetadata>[];
17
- assets?: TDocumentAsset[];
18
8
  [key: string]: any;
19
9
  }
20
10
  /**
21
11
  * Merge parent chunks with their child chunks based on metadata (parentId and chunkId)
22
- * @param chunks
23
- * @param children
24
- * @returns
12
+ *
13
+ * @deprecated use buildChunkTreeAndFindLeaves instead
25
14
  */
26
15
  export declare function mergeParentChildChunks(chunks: DocumentInterface<ChunkMetadata>[], // Parent chunks
27
16
  children: DocumentInterface<ChunkMetadata>[]): DocumentInterface<ChunkMetadata>[];