@xpert-ai/plugin-sdk 3.6.2 → 3.6.5
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.js +1204 -64540
- package/index.esm.js +1163 -64506
- package/package.json +16 -4
- package/src/lib/ai-model/errors.d.ts +2 -0
- package/src/lib/ai-model/index.d.ts +1 -0
- package/src/lib/ai-model/utils/index.d.ts +1 -0
- package/src/lib/ai-model/utils/tokenizer.d.ts +10 -0
- package/src/lib/core/context/index.d.ts +2 -0
- package/src/lib/core/context/request-context.d.ts +46 -0
- package/src/lib/core/context/request-context.middleware.d.ts +10 -0
- package/src/lib/core/index.d.ts +1 -0
- package/src/lib/data/datasource/adapter.strategy.d.ts +9 -1
- package/src/lib/data/datasource/strategy.interface.d.ts +1 -1
- package/src/lib/data/datasource/types.d.ts +79 -0
- package/src/lib/rag/image/strategy.interface.d.ts +1 -1
package/package.json
CHANGED
|
@@ -1,13 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xpert-ai/plugin-sdk",
|
|
3
|
-
"version": "3.6.
|
|
3
|
+
"version": "3.6.5",
|
|
4
4
|
"license": "AGPL-3.0",
|
|
5
|
-
"
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/xpert-ai/xpert.git"
|
|
8
|
+
},
|
|
9
|
+
"bugs": {
|
|
10
|
+
"url": "https://github.com/xpert-ai/xpert/issues"
|
|
11
|
+
},
|
|
6
12
|
"main": "./index.cjs.js",
|
|
7
13
|
"module": "./index.esm.js",
|
|
8
14
|
"publishConfig": {
|
|
9
15
|
"access": "public"
|
|
10
16
|
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"js-tiktoken": "^1.0.21"
|
|
19
|
+
},
|
|
11
20
|
"peerDependencies": {
|
|
12
21
|
"@langchain/core": "*",
|
|
13
22
|
"@metad/contracts": "*",
|
|
@@ -16,9 +25,12 @@
|
|
|
16
25
|
"lodash-es": "*",
|
|
17
26
|
"i18next-fs-backend": "*",
|
|
18
27
|
"i18next": "*",
|
|
19
|
-
"
|
|
28
|
+
"jsonwebtoken": "*",
|
|
20
29
|
"fs": "*",
|
|
30
|
+
"path": "*",
|
|
31
|
+
"passport-jwt": "*",
|
|
21
32
|
"stream": "*",
|
|
22
|
-
"
|
|
33
|
+
"yaml": "*",
|
|
34
|
+
"zod": "*"
|
|
23
35
|
}
|
|
24
36
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './tokenizer';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { TiktokenEncoding } from 'js-tiktoken';
|
|
2
|
+
/**
|
|
3
|
+
* Count tokens in text
|
|
4
|
+
* 1) Preferred: js-tiktoken precise encoding
|
|
5
|
+
* 2) Fallback: estimated token count
|
|
6
|
+
*/
|
|
7
|
+
export declare function countTokensSafe(text: string, opts?: {
|
|
8
|
+
model?: string;
|
|
9
|
+
encodingName?: TiktokenEncoding | string;
|
|
10
|
+
}): number;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { IUser, LanguagesEnum, PermissionsEnum, RolesEnum } from '@metad/contracts';
|
|
4
|
+
import type { IncomingMessage, ServerResponse } from 'http';
|
|
5
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
6
|
+
export declare class RequestContext {
|
|
7
|
+
readonly request: IncomingMessage;
|
|
8
|
+
readonly response: ServerResponse;
|
|
9
|
+
readonly reqId: string;
|
|
10
|
+
readonly userId?: string;
|
|
11
|
+
readonly extras: Record<string, any>;
|
|
12
|
+
constructor(request: IncomingMessage, response: ServerResponse, reqId: string, userId?: string, extras?: Record<string, any>);
|
|
13
|
+
static currentRequestContext(): RequestContext;
|
|
14
|
+
static currentRequest(): IncomingMessage;
|
|
15
|
+
static currentTenantId(): string;
|
|
16
|
+
static currentUserId(): string;
|
|
17
|
+
static currentRoleId(): string;
|
|
18
|
+
static currentUser(throwError?: boolean): IUser;
|
|
19
|
+
static hasPermission(permission: PermissionsEnum | string, throwError?: boolean): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Retrieves the language code from the headers of the current request.
|
|
22
|
+
* @returns The language code (LanguagesEnum) extracted from the headers, or the default language (ENGLISH) if not found.
|
|
23
|
+
*/
|
|
24
|
+
static getLanguageCode(): LanguagesEnum;
|
|
25
|
+
static getOrganizationId(): string;
|
|
26
|
+
static hasPermissions(findPermissions: Array<PermissionsEnum | string>, throwError?: boolean): boolean;
|
|
27
|
+
static hasAnyPermission(findPermissions: PermissionsEnum[], throwError?: boolean): boolean;
|
|
28
|
+
static currentToken(throwError?: boolean): any;
|
|
29
|
+
/**
|
|
30
|
+
* Checks if the current user has a specific role.
|
|
31
|
+
* @param {RolesEnum} role - The role to check.
|
|
32
|
+
* @param {boolean} throwError - Flag indicating whether to throw an error if the role is not granted.
|
|
33
|
+
* @returns {boolean} - True if the user has the role, otherwise false.
|
|
34
|
+
*/
|
|
35
|
+
static hasRole(role: RolesEnum, throwError?: boolean): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Checks if the current request context has any of the specified roles.
|
|
38
|
+
*
|
|
39
|
+
* @param roles - An array of roles to check.
|
|
40
|
+
* @param throwError - Whether to throw an error if no roles are found.
|
|
41
|
+
* @returns True if any of the required roles are found, otherwise false.
|
|
42
|
+
*/
|
|
43
|
+
static hasRoles(roles: RolesEnum[], throwError?: boolean): boolean;
|
|
44
|
+
}
|
|
45
|
+
export declare const als: AsyncLocalStorage<RequestContext>;
|
|
46
|
+
export declare function getRequestContext(): RequestContext;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { IUser } from '@metad/contracts';
|
|
3
|
+
import { NestMiddleware } from '@nestjs/common';
|
|
4
|
+
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
5
|
+
export declare class RequestContextMiddleware implements NestMiddleware {
|
|
6
|
+
use(req: IncomingMessage, _res: ServerResponse, next: () => void): void;
|
|
7
|
+
}
|
|
8
|
+
export declare function runWithRequestContext(req: Partial<IncomingMessage> & {
|
|
9
|
+
user?: IUser;
|
|
10
|
+
}, res: Partial<ServerResponse>, next: () => void): void;
|
package/src/lib/core/index.d.ts
CHANGED
|
@@ -11,8 +11,16 @@ export declare abstract class AdapterDataSourceStrategy<TOptions extends Adapter
|
|
|
11
11
|
abstract readonly name: string;
|
|
12
12
|
readonly description?: string;
|
|
13
13
|
private configurationSchemaCache;
|
|
14
|
+
private runners;
|
|
14
15
|
protected constructor(runnerClass: DBQueryRunnerType, extraArgs?: unknown[]);
|
|
15
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Get from cache or create new instance of DB adapter.
|
|
18
|
+
*
|
|
19
|
+
* @param options
|
|
20
|
+
* @param id
|
|
21
|
+
* @returns
|
|
22
|
+
*/
|
|
23
|
+
create(options: TOptions, id?: string): Promise<DBQueryRunner>;
|
|
16
24
|
configurationSchema(): Promise<Record<string, unknown>>;
|
|
17
25
|
teardown(runner: DBQueryRunner): Promise<void>;
|
|
18
26
|
protected instantiateRunner(options: TOptions | undefined): DBQueryRunner;
|
|
@@ -6,7 +6,7 @@ export interface IDataSourceStrategy<TOptions extends AdapterBaseOptions = Adapt
|
|
|
6
6
|
/**
|
|
7
7
|
* Create a query runner for the given data source options.
|
|
8
8
|
*/
|
|
9
|
-
create(options: TOptions): Promise<DBQueryRunner> | DBQueryRunner;
|
|
9
|
+
create(options: TOptions, id?: string): Promise<DBQueryRunner> | DBQueryRunner;
|
|
10
10
|
/**
|
|
11
11
|
* Optional configuration schema description for UI generation.
|
|
12
12
|
*/
|
|
@@ -36,6 +36,7 @@ export declare enum DBProtocolEnum {
|
|
|
36
36
|
export interface QueryOptions {
|
|
37
37
|
catalog?: string;
|
|
38
38
|
headers?: Record<string, string>;
|
|
39
|
+
params?: Record<string, any>[];
|
|
39
40
|
}
|
|
40
41
|
export interface QueryResult<T = unknown> {
|
|
41
42
|
status: 'OK' | 'ERROR';
|
|
@@ -59,6 +60,7 @@ export interface DBQueryRunner {
|
|
|
59
60
|
jdbcDriver: string;
|
|
60
61
|
configurationSchema: Record<string, unknown>;
|
|
61
62
|
jdbcUrl(schema?: string): string;
|
|
63
|
+
initPool?(options: AdapterBaseOptions): Promise<void>;
|
|
62
64
|
/**
|
|
63
65
|
* Execute a sql query
|
|
64
66
|
*
|
|
@@ -116,6 +118,11 @@ export interface DBQueryRunner {
|
|
|
116
118
|
* @param options
|
|
117
119
|
*/
|
|
118
120
|
dropTable(name: string, options?: QueryOptions): Promise<void>;
|
|
121
|
+
/**
|
|
122
|
+
* Unified table operation executor
|
|
123
|
+
*/
|
|
124
|
+
tableOp(action: DBTableAction, params: DBTableOperationParams, options?: QueryOptions): Promise<any>;
|
|
125
|
+
tableDataOp<T = any>(action: DBTableDataAction, params: DBTableDataParams, options?: QueryOptions): Promise<T[] | number | any>;
|
|
119
126
|
/**
|
|
120
127
|
* Teardown all resources:
|
|
121
128
|
* - close connection
|
|
@@ -135,12 +142,22 @@ export interface ColumnDef {
|
|
|
135
142
|
fieldName: string;
|
|
136
143
|
/**
|
|
137
144
|
* Object value type, convert to db type
|
|
145
|
+
* - string
|
|
146
|
+
* - number
|
|
147
|
+
* - boolean
|
|
148
|
+
* - date
|
|
149
|
+
* - datetime
|
|
150
|
+
* - object
|
|
138
151
|
*/
|
|
139
152
|
type: string;
|
|
140
153
|
/**
|
|
141
154
|
* Is primary key column
|
|
142
155
|
*/
|
|
143
156
|
isKey: boolean;
|
|
157
|
+
/**
|
|
158
|
+
* Is required column
|
|
159
|
+
*/
|
|
160
|
+
required?: boolean;
|
|
144
161
|
/**
|
|
145
162
|
* length of type for column: varchar, decimal ...
|
|
146
163
|
*/
|
|
@@ -190,6 +207,8 @@ export declare abstract class BaseQueryRunner<T extends AdapterBaseOptions = Ada
|
|
|
190
207
|
catalog?: string;
|
|
191
208
|
}): Promise<void>;
|
|
192
209
|
dropTable(name: string, options?: any): Promise<void>;
|
|
210
|
+
tableOp(action: DBTableAction, params: DBTableOperationParams, options?: QueryOptions): Promise<any>;
|
|
211
|
+
tableDataOp(action: DBTableDataAction, params: DBTableDataParams, options?: QueryOptions): Promise<any>;
|
|
193
212
|
abstract teardown(): Promise<void>;
|
|
194
213
|
}
|
|
195
214
|
export interface HttpAdapterOptions extends AdapterBaseOptions {
|
|
@@ -253,3 +272,63 @@ export interface File {
|
|
|
253
272
|
/** `MemoryStorage` only: A Buffer containing the entire file. */
|
|
254
273
|
buffer: Buffer;
|
|
255
274
|
}
|
|
275
|
+
export declare enum DBTableAction {
|
|
276
|
+
LIST_TABLES = "listTables",
|
|
277
|
+
TABLE_EXISTS = "tableExists",
|
|
278
|
+
CREATE_TABLE = "createTable",
|
|
279
|
+
DROP_TABLE = "dropTable",
|
|
280
|
+
RENAME_TABLE = "renameTable",
|
|
281
|
+
TRUNCATE_TABLE = "truncateTable",
|
|
282
|
+
ADD_COLUMN = "addColumn",
|
|
283
|
+
DROP_COLUMN = "dropColumn",
|
|
284
|
+
MODIFY_COLUMN = "modifyColumn",
|
|
285
|
+
CREATE_INDEX = "createIndex",
|
|
286
|
+
DROP_INDEX = "dropIndex",
|
|
287
|
+
GET_TABLE_INFO = "getTableInfo",
|
|
288
|
+
CLONE_TABLE_STRUCTURE = "cloneTableStructure",
|
|
289
|
+
CLONE_TABLE = "cloneTable",
|
|
290
|
+
OPTIMIZE_TABLE = "optimizeTable"
|
|
291
|
+
}
|
|
292
|
+
export interface DBTableOperationParams {
|
|
293
|
+
schema?: string;
|
|
294
|
+
table?: string;
|
|
295
|
+
newTable?: string;
|
|
296
|
+
columns?: ColumnDef[];
|
|
297
|
+
column?: ColumnDef;
|
|
298
|
+
columnName?: string;
|
|
299
|
+
index?: DBIndexDefinition;
|
|
300
|
+
indexName?: string;
|
|
301
|
+
createMode?: DBCreateTableMode;
|
|
302
|
+
}
|
|
303
|
+
export interface DBIndexDefinition {
|
|
304
|
+
name: string;
|
|
305
|
+
columns: string[];
|
|
306
|
+
unique?: boolean;
|
|
307
|
+
type?: 'btree' | 'hash' | 'gin' | 'bitmap' | 'fulltext' | string;
|
|
308
|
+
}
|
|
309
|
+
export declare enum DBCreateTableMode {
|
|
310
|
+
ERROR = "error",// 表已存在 → 报错
|
|
311
|
+
IGNORE = "ignore",// 表已存在 → 什么也不做
|
|
312
|
+
UPGRADE = "upgrade"
|
|
313
|
+
}
|
|
314
|
+
export declare enum DBTableDataAction {
|
|
315
|
+
INSERT = "insert",
|
|
316
|
+
UPDATE = "update",
|
|
317
|
+
UPSERT = "upsert",
|
|
318
|
+
DELETE = "delete",
|
|
319
|
+
SELECT = "select",
|
|
320
|
+
BULK_INSERT = "bulkInsert"
|
|
321
|
+
}
|
|
322
|
+
export interface DBTableDataParams {
|
|
323
|
+
schema?: string;
|
|
324
|
+
table: string;
|
|
325
|
+
columns?: Partial<ColumnDef>[];
|
|
326
|
+
where?: Record<string, any> | string;
|
|
327
|
+
orderBy?: string;
|
|
328
|
+
limit?: number;
|
|
329
|
+
offset?: number;
|
|
330
|
+
values?: Record<string, any> | Array<Record<string, any>>;
|
|
331
|
+
set?: Record<string, any>;
|
|
332
|
+
deleteWhere?: Record<string, any> | string;
|
|
333
|
+
conflictKeys?: string[];
|
|
334
|
+
}
|
|
@@ -27,5 +27,5 @@ export interface IImageUnderstandingStrategy<TConfig extends TImageUnderstanding
|
|
|
27
27
|
/**
|
|
28
28
|
* Understand image files (e.g., OCR, VLM, Chart Parsing)
|
|
29
29
|
*/
|
|
30
|
-
understandImages(doc: IKnowledgeDocument
|
|
30
|
+
understandImages(doc: IKnowledgeDocument, config: TConfig): Promise<TImageUnderstandingResult>;
|
|
31
31
|
}
|