@xpert-ai/plugin-sdk 3.6.0 β 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.
- package/index.cjs.d.ts +1 -0
- package/index.cjs.js +45273 -5
- package/index.esm.d.ts +1 -0
- package/index.esm.js +45192 -0
- package/package.json +3 -3
- package/src/index.d.ts +12 -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/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
|
@@ -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,41 @@
|
|
|
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
|
+
export type TWorkflowNodeResult = {
|
|
11
|
+
name?: string;
|
|
12
|
+
graph: Runnable;
|
|
13
|
+
ends: string[];
|
|
14
|
+
channel?: {
|
|
15
|
+
name: string;
|
|
16
|
+
annotation: BaseChannel;
|
|
17
|
+
};
|
|
18
|
+
navigator?: (state: any, config: any) => Promise<any>;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Workflow Node Strategy interface
|
|
22
|
+
*/
|
|
23
|
+
export interface IWorkflowNodeStrategy<TConfig = any, TResult = any> {
|
|
24
|
+
/**
|
|
25
|
+
* Metadata describing the node (type, label, description, config schema, etc.)
|
|
26
|
+
*/
|
|
27
|
+
meta: TWorkflowNodeMeta;
|
|
28
|
+
/**
|
|
29
|
+
* Create the node subgraph
|
|
30
|
+
*/
|
|
31
|
+
create(payload: {
|
|
32
|
+
graph: TXpertGraph;
|
|
33
|
+
node: TXpertTeamNode & {
|
|
34
|
+
type: 'workflow';
|
|
35
|
+
};
|
|
36
|
+
xpertId: string;
|
|
37
|
+
environment: IEnvironment;
|
|
38
|
+
isDraft: boolean;
|
|
39
|
+
}): TWorkflowNodeResult;
|
|
40
|
+
outputVariables(entity: IWorkflowNode): TXpertParameter[];
|
|
41
|
+
}
|
|
@@ -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/jest.config.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
import { readFileSync } from 'fs'
|
|
3
|
-
|
|
4
|
-
// Reading the SWC compilation config and remove the "exclude"
|
|
5
|
-
// for the test files to be compiled by SWC
|
|
6
|
-
const { exclude: _, ...swcJestConfig } = JSON.parse(readFileSync(`${__dirname}/.swcrc`, 'utf-8'))
|
|
7
|
-
|
|
8
|
-
// disable .swcrc look-up by SWC core because we're passing in swcJestConfig ourselves.
|
|
9
|
-
// If we do not disable this, SWC Core will read .swcrc and won't transform our test files due to "exclude"
|
|
10
|
-
if (swcJestConfig.swcrc === undefined) {
|
|
11
|
-
swcJestConfig.swcrc = false
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
// Uncomment if using global setup/teardown files being transformed via swc
|
|
15
|
-
// https://nx.dev/packages/jest/documents/overview#global-setup/teardown-with-nx-libraries
|
|
16
|
-
// jest needs EsModule Interop to find the default exported setup/teardown functions
|
|
17
|
-
// swcJestConfig.module.noInterop = false;
|
|
18
|
-
|
|
19
|
-
export default {
|
|
20
|
-
displayName: 'plugin-sdk',
|
|
21
|
-
preset: '../../jest.preset.js',
|
|
22
|
-
transform: {
|
|
23
|
-
'^.+\\.[tj]s$': ['@swc/jest', swcJestConfig]
|
|
24
|
-
},
|
|
25
|
-
moduleFileExtensions: ['ts', 'js', 'html'],
|
|
26
|
-
testEnvironment: 'node',
|
|
27
|
-
coverageDirectory: '../../coverage/packages/plugin-sdk'
|
|
28
|
-
}
|
package/project.json
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "plugin-sdk",
|
|
3
|
-
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
|
4
|
-
"sourceRoot": "packages/plugin-sdk/src",
|
|
5
|
-
"projectType": "library",
|
|
6
|
-
"tags": [],
|
|
7
|
-
"targets": {
|
|
8
|
-
"build": {
|
|
9
|
-
"executor": "@nx/rollup:rollup",
|
|
10
|
-
"outputs": ["{options.outputPath}"],
|
|
11
|
-
"options": {
|
|
12
|
-
"outputPath": "packages/plugin-sdk/dist",
|
|
13
|
-
"main": "packages/plugin-sdk/src/index.ts",
|
|
14
|
-
"tsConfig": "packages/plugin-sdk/tsconfig.lib.json",
|
|
15
|
-
"assets": [
|
|
16
|
-
{
|
|
17
|
-
"glob": "*.md",
|
|
18
|
-
"input": "packages/plugin-sdk/",
|
|
19
|
-
"output": "."
|
|
20
|
-
}
|
|
21
|
-
],
|
|
22
|
-
"project": "packages/plugin-sdk/package.json",
|
|
23
|
-
"compiler": "swc",
|
|
24
|
-
"format": ["cjs", "esm"],
|
|
25
|
-
"external": [
|
|
26
|
-
"@langchain/core",
|
|
27
|
-
"@metad/contracts",
|
|
28
|
-
"@nestjs/common",
|
|
29
|
-
"@nestjs/core",
|
|
30
|
-
"@nestjs/microservices",
|
|
31
|
-
"lodash-es",
|
|
32
|
-
"i18next-fs-backend",
|
|
33
|
-
"i18next",
|
|
34
|
-
"kafkajs",
|
|
35
|
-
"amqplib",
|
|
36
|
-
"mqtt",
|
|
37
|
-
"nats",
|
|
38
|
-
"zod",
|
|
39
|
-
"fs",
|
|
40
|
-
"path"
|
|
41
|
-
]
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
"test": {
|
|
45
|
-
"executor": "@nx/jest:jest",
|
|
46
|
-
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
|
|
47
|
-
"options": {
|
|
48
|
-
"jestConfig": "packages/plugin-sdk/jest.config.ts"
|
|
49
|
-
}
|
|
50
|
-
},
|
|
51
|
-
"nx-release-publish": {
|
|
52
|
-
"executor": "@nx/js:release-publish",
|
|
53
|
-
"options": {
|
|
54
|
-
"packageRoot": "packages/plugin-sdk/dist",
|
|
55
|
-
"access": "public"
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
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'
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import fsPromises from 'fs/promises'
|
|
2
|
-
import path from 'path'
|
|
3
|
-
import { FileSystemPermission } from './permissions'
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Restricted FileSystem based on granted permissions
|
|
8
|
-
*/
|
|
9
|
-
export class XpFileSystem {
|
|
10
|
-
private allowedOps: Set<'read' | 'write' | 'delete' | 'list'>
|
|
11
|
-
private scope: string[] | undefined
|
|
12
|
-
|
|
13
|
-
constructor(permission: FileSystemPermission, private basePath: string, private baseUrl: string) {
|
|
14
|
-
this.allowedOps = new Set(permission.operations)
|
|
15
|
-
this.scope = permission.scope
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Check if operation is allowed
|
|
20
|
-
*/
|
|
21
|
-
private ensureAllowed(op: 'read' | 'write' | 'delete' | 'list') {
|
|
22
|
-
if (!this.allowedOps.has(op)) {
|
|
23
|
-
throw new Error(`Permission denied: ${op} operation not allowed`)
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Check if path is within scope
|
|
29
|
-
*/
|
|
30
|
-
private ensureInScope(targetPath: string) {
|
|
31
|
-
if (!this.scope || this.scope.length === 0) return
|
|
32
|
-
const resolved = path.resolve(targetPath)
|
|
33
|
-
for (const s of this.scope) {
|
|
34
|
-
const absScope = path.resolve(s)
|
|
35
|
-
if (resolved.startsWith(absScope)) return
|
|
36
|
-
}
|
|
37
|
-
throw new Error(`Permission denied: path "${targetPath}" is out of scope`)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Get the absolute path of file in the file system.
|
|
42
|
-
*
|
|
43
|
-
* @param filePath Relative file path
|
|
44
|
-
* @returns Absolute file path
|
|
45
|
-
*/
|
|
46
|
-
fullPath(filePath: string): string {
|
|
47
|
-
return path.join(this.basePath, filePath)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Get web url for a given file path in the file system.
|
|
52
|
-
*
|
|
53
|
-
* @param filePath Relative file path
|
|
54
|
-
* @returns Web URL of file
|
|
55
|
-
*/
|
|
56
|
-
fullUrl(filePath: string): string {
|
|
57
|
-
const url = new URL(filePath, this.baseUrl)
|
|
58
|
-
return url.href
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Read file contents
|
|
63
|
-
*/
|
|
64
|
-
async readFile(filePath: string, encoding: BufferEncoding = 'utf-8') {
|
|
65
|
-
this.ensureAllowed('read')
|
|
66
|
-
const fullPath = this.fullPath(filePath)
|
|
67
|
-
this.ensureInScope(fullPath)
|
|
68
|
-
return await fsPromises.readFile(fullPath)
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Write file contents
|
|
73
|
-
*/
|
|
74
|
-
async writeFile(filePath: string, content: string | Buffer): Promise<string> {
|
|
75
|
-
this.ensureAllowed('write')
|
|
76
|
-
const fullPath = this.fullPath(filePath)
|
|
77
|
-
this.ensureInScope(fullPath)
|
|
78
|
-
await fsPromises.mkdir(path.dirname(fullPath), { recursive: true })
|
|
79
|
-
await fsPromises.writeFile(fullPath, content)
|
|
80
|
-
const url = new URL(filePath, this.baseUrl)
|
|
81
|
-
return url.href
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Delete a file
|
|
86
|
-
*/
|
|
87
|
-
async deleteFile(filePath: string): Promise<void> {
|
|
88
|
-
this.ensureAllowed('delete')
|
|
89
|
-
this.ensureInScope(filePath)
|
|
90
|
-
await fsPromises.unlink(filePath)
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* List directory contents
|
|
95
|
-
*/
|
|
96
|
-
async listDir(dirPath: string): Promise<string[]> {
|
|
97
|
-
this.ensureAllowed('list')
|
|
98
|
-
this.ensureInScope(dirPath)
|
|
99
|
-
return fsPromises.readdir(dirPath)
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Utility: check if a file or directory exists
|
|
104
|
-
*/
|
|
105
|
-
async exists(targetPath: string): Promise<boolean> {
|
|
106
|
-
try {
|
|
107
|
-
await fsPromises.access(targetPath)
|
|
108
|
-
return true
|
|
109
|
-
} catch {
|
|
110
|
-
return false
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
package/src/lib/core/i18n.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { createInstance, i18n as I18nInstance } from 'i18next'
|
|
2
|
-
import FsBackend from 'i18next-fs-backend'
|
|
3
|
-
import path from 'path'
|
|
4
|
-
import fs from 'fs'
|
|
5
|
-
|
|
6
|
-
export async function createI18nInstance(pluginDir: string, language?: string): Promise<I18nInstance> {
|
|
7
|
-
const instance = createInstance()
|
|
8
|
-
const i18nDir = path.join(pluginDir, 'i18n')
|
|
9
|
-
|
|
10
|
-
// detect available languages dynamically
|
|
11
|
-
const lngs = fs
|
|
12
|
-
.readdirSync(i18nDir)
|
|
13
|
-
.filter((f) => f.endsWith('.json'))
|
|
14
|
-
.map((f) => f.replace('.json', ''))
|
|
15
|
-
|
|
16
|
-
await instance
|
|
17
|
-
.use(FsBackend)
|
|
18
|
-
.init({
|
|
19
|
-
lng: language,
|
|
20
|
-
fallbackLng: 'en',
|
|
21
|
-
preload: lngs,
|
|
22
|
-
ns: ['default'],
|
|
23
|
-
defaultNS: 'default',
|
|
24
|
-
backend: {
|
|
25
|
-
loadPath: path.join(i18nDir, '{{lng}}.json'),
|
|
26
|
-
},
|
|
27
|
-
interpolation: { escapeValue: false },
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
return instance
|
|
31
|
-
}
|
package/src/lib/core/index.ts
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
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
|
-
/**
|
|
10
|
-
* Base Permission type
|
|
11
|
-
*/
|
|
12
|
-
export interface BasePermission {
|
|
13
|
-
type: string; // Discriminator
|
|
14
|
-
description?: string; // Optional description for UI
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* 1. LLM Permission
|
|
19
|
-
* Example: { type: 'llm', provider: 'openai', capability: 'vision' }
|
|
20
|
-
*/
|
|
21
|
-
export interface LLMPermission extends BasePermission {
|
|
22
|
-
type: 'llm';
|
|
23
|
-
provider?: string; // e.g. "openai", "anthropic", "azure", "ollama"
|
|
24
|
-
capability: 'text' | 'chat' | 'vision' | 'embedding';
|
|
25
|
-
scope?: string[]; // Allowed model names, e.g. ["gpt-4", "gpt-4-vision-preview"]
|
|
26
|
-
maxTokens?: number; // Maximum output tokens allowed
|
|
27
|
-
rateLimit?: { rps: number }; // Rate limit per second
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* 2. Vector Store Permission
|
|
32
|
-
* Example: { type: 'vectorstore', provider: 'pinecone', operations: ['insert', 'query'] }
|
|
33
|
-
*/
|
|
34
|
-
export interface VectorStorePermission extends BasePermission {
|
|
35
|
-
type: 'vectorstore';
|
|
36
|
-
provider: string; // "pinecone" | "milvus" | "chromadb" | ...
|
|
37
|
-
operations: Array<'insert' | 'query' | 'delete'>;
|
|
38
|
-
scope?: string[]; // Restrict to index / collection
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* 3. Knowledge Base Permission
|
|
43
|
-
* Example: { type: 'knowledge', operations: ['read', 'write'], scope: ['kb_123'] }
|
|
44
|
-
*/
|
|
45
|
-
export interface KnowledgePermission extends BasePermission {
|
|
46
|
-
type: 'knowledge';
|
|
47
|
-
operations: Array<'read' | 'write' | 'update' | 'delete'>;
|
|
48
|
-
scope?: string[]; // Restrict to certain KB IDs
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* 4. File System Permission
|
|
53
|
-
* Example: { type: 'filesystem', operations: ['read', 'write'], scope: ['/documents', '/images'] }
|
|
54
|
-
*/
|
|
55
|
-
export interface FileSystemPermission extends BasePermission {
|
|
56
|
-
type: 'filesystem';
|
|
57
|
-
operations: Array<'read' | 'write' | 'delete' | 'list'>;
|
|
58
|
-
scope?: string[]; // Restrict to certain directories or file types
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* 5. Integration Permission
|
|
63
|
-
* Example: { type: 'integration', service: 'feishu', operations: ['read', 'write'] }
|
|
64
|
-
*/
|
|
65
|
-
export interface IntegrationPermission extends BasePermission {
|
|
66
|
-
type: 'integration';
|
|
67
|
-
service: string; // e.g. 'slack', 'feishu', 'jira', 'sap', etc.
|
|
68
|
-
operations?: Array<'read' | 'write' | 'update' | 'delete'>;
|
|
69
|
-
scope?: string[];
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// /**
|
|
73
|
-
// * 4. Document Permission
|
|
74
|
-
// * Example: { type: 'document', formats: ['pdf'], operations: ['load', 'transform'] }
|
|
75
|
-
// */
|
|
76
|
-
// export interface DocumentPermission extends BasePermission {
|
|
77
|
-
// type: 'document';
|
|
78
|
-
// formats: string[]; // ['pdf', 'pptx', 'docx', 'image', 'html', 'md']
|
|
79
|
-
// operations: Array<'load' | 'transform' | 'ocr' | 'imageUnderstanding'>;
|
|
80
|
-
// }
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Union type for all permissions
|
|
84
|
-
*/
|
|
85
|
-
export type Permission =
|
|
86
|
-
| LLMPermission
|
|
87
|
-
| VectorStorePermission
|
|
88
|
-
| KnowledgePermission
|
|
89
|
-
| FileSystemPermission
|
|
90
|
-
| IntegrationPermission
|
|
91
|
-
// | DocumentPermission
|
|
92
|
-
// | ExternalPermission;
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Permissions array type
|
|
96
|
-
*/
|
|
97
|
-
export type Permissions = Permission[];
|
package/src/lib/core/schema.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Common UI Schema field definitions
|
|
3
|
-
*/
|
|
4
|
-
export interface ISchemaUIBase {
|
|
5
|
-
component: string; // UI component type
|
|
6
|
-
label?: string; // Field label
|
|
7
|
-
description?: string; // Field description
|
|
8
|
-
placeholder?: string; // Input placeholder
|
|
9
|
-
order?: number; // UI display order
|
|
10
|
-
required?: boolean; // Whether the field is required
|
|
11
|
-
visibleWhen?: Record<string, any>; // Conditional rendering
|
|
12
|
-
enabledWhen?: Record<string, any>; // Conditional enabling
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Secret field extensions
|
|
17
|
-
*/
|
|
18
|
-
export interface ISchemaSecretField extends ISchemaUIBase {
|
|
19
|
-
component: 'secretInput'; // Fixed component type
|
|
20
|
-
revealable?: boolean; // Whether plaintext display is allowed (π button)
|
|
21
|
-
maskSymbol?: string; // Mask symbol (default *)
|
|
22
|
-
persist?: boolean; // Whether to persist, false means only used at runtime
|
|
23
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { IIntegration, TIntegrationProvider } from '@metad/contracts'
|
|
2
|
-
|
|
3
|
-
export type TIntegrationStrategyParams = {
|
|
4
|
-
query: string
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export interface IntegrationStrategy<T = unknown> {
|
|
8
|
-
meta: TIntegrationProvider
|
|
9
|
-
execute(integration: IIntegration<T>, payload: TIntegrationStrategyParams): Promise<any>
|
|
10
|
-
validateConfig?(config: T): Promise<void>
|
|
11
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Injectable } from '@nestjs/common'
|
|
2
|
-
import { DiscoveryService, Reflector } from '@nestjs/core'
|
|
3
|
-
import { BaseStrategyRegistry } from '../strategy'
|
|
4
|
-
import { INTEGRATION_STRATEGY } from './strategy.decorator'
|
|
5
|
-
import { IntegrationStrategy } from './strategy.interface'
|
|
6
|
-
|
|
7
|
-
@Injectable()
|
|
8
|
-
export class IntegrationStrategyRegistry extends BaseStrategyRegistry<IntegrationStrategy> {
|
|
9
|
-
constructor(discoveryService: DiscoveryService, reflector: Reflector) {
|
|
10
|
-
super(INTEGRATION_STRATEGY, discoveryService, reflector)
|
|
11
|
-
}
|
|
12
|
-
}
|
package/src/lib/logger.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Logger } from '@nestjs/common';
|
|
2
|
-
import type { PluginLogger } from './types';
|
|
3
|
-
|
|
4
|
-
export function createPluginLogger(scope: string, baseMeta: Record<string, any> = {}): PluginLogger {
|
|
5
|
-
const nestLogger = new Logger(scope);
|
|
6
|
-
const wrap = (level: keyof Logger, msg: string, meta?: any) => {
|
|
7
|
-
const payload = meta ? { ...baseMeta, ...meta } : baseMeta;
|
|
8
|
-
// δΏζδΈ Nest Logger ζ₯ε£ε―Ήι½
|
|
9
|
-
(nestLogger as any)[level]?.(msg + (Object.keys(payload).length ? ` ${JSON.stringify(payload)}` : ''));
|
|
10
|
-
};
|
|
11
|
-
return {
|
|
12
|
-
child(meta) { return createPluginLogger(scope, { ...baseMeta, ...meta }); },
|
|
13
|
-
debug: (msg, meta) => wrap('debug' as any, msg, meta),
|
|
14
|
-
log: (msg, meta) => wrap('log', msg, meta),
|
|
15
|
-
warn: (msg, meta) => wrap('warn', msg, meta),
|
|
16
|
-
error: (msg, meta) => wrap('error', msg, meta),
|
|
17
|
-
};
|
|
18
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Metadata keys used in plugins for defining various aspects like entities, subscribers, and configurations.
|
|
3
|
-
*/
|
|
4
|
-
export const PLUGIN_METADATA = {
|
|
5
|
-
/**
|
|
6
|
-
* Key representing the entities registered within the plugin.
|
|
7
|
-
*/
|
|
8
|
-
ENTITIES: 'entities',
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Key representing event subscribers within the plugin.
|
|
12
|
-
*/
|
|
13
|
-
SUBSCRIBERS: 'subscribers',
|
|
14
|
-
|
|
15
|
-
} as const;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Type definition for valid plugin metadata keys.
|
|
19
|
-
*/
|
|
20
|
-
export type PluginMetadataKey = (typeof PLUGIN_METADATA)[keyof typeof PLUGIN_METADATA];
|