@xpert-ai/plugin-sdk 3.6.0 → 3.6.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 +65517 -4
- package/index.esm.d.ts +1 -0
- package/index.esm.js +65419 -0
- package/package.json +4 -4
- package/src/index.d.ts +13 -0
- package/src/lib/ai-model/abstract-provider.d.ts +41 -0
- package/src/lib/ai-model/ai-model-provider.decorator.d.ts +2 -0
- package/src/lib/ai-model/ai-model-provider.interface.d.ts +42 -0
- package/src/lib/ai-model/ai-model-provider.registry.d.ts +6 -0
- package/src/lib/ai-model/ai-model.d.ts +33 -0
- package/src/lib/ai-model/entities/defaults.d.ts +3 -0
- package/src/lib/ai-model/entities/index.d.ts +2 -0
- package/src/lib/ai-model/entities/model_entities.d.ts +14 -0
- package/src/lib/ai-model/errors.d.ts +5 -0
- package/src/lib/ai-model/index.d.ts +8 -0
- package/src/lib/ai-model/llm.d.ts +49 -0
- package/src/lib/ai-model/openai-compatible/completions.d.ts +23 -0
- package/src/lib/ai-model/openai-compatible/index.d.ts +3 -0
- package/src/lib/ai-model/openai-compatible/rerank.d.ts +20 -0
- package/src/lib/ai-model/openai-compatible/speech2text.d.ts +17 -0
- package/src/lib/ai-model/types/index.d.ts +11 -0
- package/src/lib/ai-model/types/model.d.ts +43 -0
- package/src/lib/ai-model/types/rerank.d.ts +20 -0
- package/src/lib/ai-model/types/speech2text.d.ts +3 -0
- package/src/lib/ai-model/types/text-embedding-model.d.ts +7 -0
- package/src/lib/ai-model/types/tts.d.ts +5 -0
- package/src/lib/core/file-system.d.ts +55 -0
- package/src/lib/core/i18n.d.ts +2 -0
- package/src/lib/core/index.d.ts +5 -0
- package/src/lib/core/permissions.d.ts +74 -0
- package/src/lib/core/schema.d.ts +22 -0
- package/src/lib/core/utils.d.ts +12 -0
- package/src/lib/data/datasource/adapter.strategy.d.ts +20 -0
- package/src/lib/data/datasource/index.d.ts +5 -0
- package/src/lib/data/datasource/strategy.decorator.d.ts +2 -0
- package/src/lib/data/datasource/strategy.interface.d.ts +19 -0
- package/src/lib/data/datasource/strategy.registry.d.ts +7 -0
- package/src/lib/data/datasource/types.d.ts +255 -0
- package/src/lib/data/index.d.ts +1 -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.d.ts +9 -0
- package/src/lib/integration/strategy.registry.d.ts +6 -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 +31 -0
- package/src/lib/rag/image/strategy.registry.d.ts +6 -0
- package/src/lib/rag/index.d.ts +7 -0
- package/src/lib/rag/knowledge/index.d.ts +3 -0
- package/src/lib/rag/knowledge/knowledge-strategy.decorator.d.ts +2 -0
- package/src/lib/rag/knowledge/knowledge-strategy.interface.d.ts +15 -0
- package/src/lib/rag/knowledge/knowledge-strategy.registry.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 +36 -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 +23 -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 +26 -0
- package/src/lib/rag/transformer/strategy.registry.d.ts +6 -0
- package/src/lib/rag/types.d.ts +18 -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 +41 -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/jest.config.ts +0 -28
- package/project.json +0 -59
- package/src/index.ts +0 -11
- package/src/lib/core/file-system.ts +0 -113
- package/src/lib/core/i18n.ts +0 -31
- package/src/lib/core/index.ts +0 -4
- 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.interface.ts +0 -11
- package/src/lib/integration/strategy.registry.ts +0 -12
- 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 -37
- package/src/lib/rag/image/strategy.registry.ts +0 -17
- package/src/lib/rag/index.ts +0 -7
- package/src/lib/rag/knowledge/index.ts +0 -3
- package/src/lib/rag/knowledge/knowledge-strategy.decorator.ts +0 -6
- package/src/lib/rag/knowledge/knowledge-strategy.interface.ts +0 -15
- package/src/lib/rag/knowledge/knowledge-strategy.registry.ts +0 -12
- 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 -36
- 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 -34
- package/src/lib/rag/transformer/strategy.registry.ts +0 -14
- package/src/lib/rag/types.ts +0 -76
- 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 -51
- 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": "3.6.
|
|
3
|
+
"version": "3.6.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
|
},
|
|
@@ -13,12 +13,12 @@
|
|
|
13
13
|
"@metad/contracts": "*",
|
|
14
14
|
"@nestjs/common": "*",
|
|
15
15
|
"@nestjs/core": "*",
|
|
16
|
-
"@nestjs/microservices": "*",
|
|
17
16
|
"lodash-es": "*",
|
|
18
17
|
"i18next-fs-backend": "*",
|
|
19
18
|
"i18next": "*",
|
|
20
19
|
"zod": "*",
|
|
21
20
|
"fs": "*",
|
|
21
|
+
"stream": "*",
|
|
22
22
|
"path": "*"
|
|
23
23
|
}
|
|
24
24
|
}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
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/integration/index';
|
|
7
|
+
export * from './lib/workflow/index';
|
|
8
|
+
export * from './lib/vectorstore/index';
|
|
9
|
+
export * from './lib/rag/index';
|
|
10
|
+
export * from './lib/toolset/index';
|
|
11
|
+
export * from './lib/core/index';
|
|
12
|
+
export * from './lib/data/index';
|
|
13
|
+
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,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,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,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,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,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,55 @@
|
|
|
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
|
+
/**
|
|
22
|
+
* Get the absolute path of file in the file system.
|
|
23
|
+
*
|
|
24
|
+
* @param filePath Relative file path
|
|
25
|
+
* @returns Absolute file path
|
|
26
|
+
*/
|
|
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;
|
|
35
|
+
/**
|
|
36
|
+
* Read file contents
|
|
37
|
+
*/
|
|
38
|
+
readFile(filePath: string, encoding?: BufferEncoding): Promise<Buffer>;
|
|
39
|
+
/**
|
|
40
|
+
* Write file contents
|
|
41
|
+
*/
|
|
42
|
+
writeFile(filePath: string, content: string | Buffer): Promise<string>;
|
|
43
|
+
/**
|
|
44
|
+
* Delete a file
|
|
45
|
+
*/
|
|
46
|
+
deleteFile(filePath: string): Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* List directory contents
|
|
49
|
+
*/
|
|
50
|
+
listDir(dirPath: string): Promise<string[]>;
|
|
51
|
+
/**
|
|
52
|
+
* Utility: check if a file or directory exists
|
|
53
|
+
*/
|
|
54
|
+
exists(targetPath: string): Promise<boolean>;
|
|
55
|
+
}
|
|
@@ -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
|
+
* Common UI Schema field definitions
|
|
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 field extensions
|
|
16
|
+
*/
|
|
17
|
+
export interface ISchemaSecretField extends ISchemaUIBase {
|
|
18
|
+
component: 'secretInput';
|
|
19
|
+
revealable?: boolean;
|
|
20
|
+
maskSymbol?: string;
|
|
21
|
+
persist?: boolean;
|
|
22
|
+
}
|
|
@@ -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;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { IDataSourceStrategy } from './strategy.interface';
|
|
2
|
+
import { AdapterBaseOptions, DBQueryRunner, DBQueryRunnerType } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Helper base class to wrap existing adapter query runner implementations
|
|
5
|
+
* into datasource strategies consumable by the plugin SDK.
|
|
6
|
+
*/
|
|
7
|
+
export declare abstract class AdapterDataSourceStrategy<TOptions extends AdapterBaseOptions = AdapterBaseOptions> implements IDataSourceStrategy<TOptions> {
|
|
8
|
+
private readonly runnerClass;
|
|
9
|
+
private readonly extraArgs;
|
|
10
|
+
abstract readonly type: string;
|
|
11
|
+
abstract readonly name: string;
|
|
12
|
+
readonly description?: string;
|
|
13
|
+
private configurationSchemaCache;
|
|
14
|
+
protected constructor(runnerClass: DBQueryRunnerType, extraArgs?: unknown[]);
|
|
15
|
+
create(options: TOptions): Promise<DBQueryRunner>;
|
|
16
|
+
configurationSchema(): Promise<Record<string, unknown>>;
|
|
17
|
+
teardown(runner: DBQueryRunner): Promise<void>;
|
|
18
|
+
protected instantiateRunner(options: TOptions | undefined): DBQueryRunner;
|
|
19
|
+
getClassType(): DBQueryRunnerType;
|
|
20
|
+
}
|