@lark-apaas/nestjs-capability 0.1.5 → 0.1.7
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/README.md +2 -0
- package/dist/index.cjs +262 -122
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +65 -2
- package/dist/index.d.ts +65 -2
- package/dist/index.js +236 -97
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -3,10 +3,65 @@ import { PlatformHttpClient, RequestContextService, HttpClientFactory } from '@l
|
|
|
3
3
|
import { ZodSchema } from 'zod';
|
|
4
4
|
import { Response } from 'express';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* 事件类型
|
|
8
|
+
*/
|
|
9
|
+
type EventType = 'install' | 'create_instance' | 'call';
|
|
10
|
+
/**
|
|
11
|
+
* 调用者类型
|
|
12
|
+
*/
|
|
13
|
+
type CallerType = 'client' | 'server' | 'debug';
|
|
14
|
+
/**
|
|
15
|
+
* 资源事件
|
|
16
|
+
*/
|
|
17
|
+
interface ResourceEvent {
|
|
18
|
+
resourceType: 'plugin';
|
|
19
|
+
resourceKey: string;
|
|
20
|
+
eventType: EventType;
|
|
21
|
+
details?: Record<string, string>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Call 事件详情
|
|
25
|
+
*/
|
|
26
|
+
interface CallEventDetails {
|
|
27
|
+
version: string;
|
|
28
|
+
success: string;
|
|
29
|
+
duration: string;
|
|
30
|
+
is_stream: string;
|
|
31
|
+
caller_type: string;
|
|
32
|
+
status_code: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* 插件遥测服务
|
|
36
|
+
*
|
|
37
|
+
* 负责上报插件生命周期事件到平台
|
|
38
|
+
*/
|
|
39
|
+
declare class TelemetryService {
|
|
40
|
+
private readonly client;
|
|
41
|
+
private readonly logger;
|
|
42
|
+
constructor(client: PlatformHttpClient);
|
|
43
|
+
/**
|
|
44
|
+
* 上报事件到平台
|
|
45
|
+
*
|
|
46
|
+
* @param events - 事件列表
|
|
47
|
+
* @returns 是否上报成功
|
|
48
|
+
*/
|
|
49
|
+
reportEvents(events: ResourceEvent[]): Promise<boolean>;
|
|
50
|
+
/**
|
|
51
|
+
* 上报插件调用事件
|
|
52
|
+
*
|
|
53
|
+
* @param pluginKey - 插件标识
|
|
54
|
+
* @param details - 调用详情
|
|
55
|
+
*/
|
|
56
|
+
reportCall(pluginKey: string, details: CallEventDetails): Promise<void>;
|
|
57
|
+
}
|
|
58
|
+
|
|
6
59
|
interface UserContext {
|
|
7
60
|
userId: string;
|
|
8
61
|
tenantId: string;
|
|
9
62
|
appId: string;
|
|
63
|
+
/** 是否为系统账号 */
|
|
64
|
+
isSystemAccount: boolean;
|
|
10
65
|
}
|
|
11
66
|
interface PluginActionContext {
|
|
12
67
|
/** 插件标识(如 @official/ai-chat) */
|
|
@@ -16,6 +71,8 @@ interface PluginActionContext {
|
|
|
16
71
|
userContext: UserContext;
|
|
17
72
|
/** 是否为调试模式(来自 debug controller 的调用) */
|
|
18
73
|
isDebug: boolean;
|
|
74
|
+
/** 调用来源:client=前端SDK, server=服务端内部, debug=调试面板 */
|
|
75
|
+
caller?: CallerType;
|
|
19
76
|
}
|
|
20
77
|
|
|
21
78
|
interface JSONSchema {
|
|
@@ -273,6 +330,7 @@ declare class TemplateEngineService {
|
|
|
273
330
|
|
|
274
331
|
interface PluginManifest {
|
|
275
332
|
name: string;
|
|
333
|
+
version?: string;
|
|
276
334
|
form?: {
|
|
277
335
|
refType?: 'config' | 'action';
|
|
278
336
|
schema?: unknown;
|
|
@@ -382,6 +440,7 @@ declare class CapabilityService implements OnModuleInit, OnModuleDestroy {
|
|
|
382
440
|
private readonly httpClientFactory;
|
|
383
441
|
private readonly pluginLoaderService;
|
|
384
442
|
private readonly templateEngineService;
|
|
443
|
+
private readonly telemetryService;
|
|
385
444
|
private readonly logger;
|
|
386
445
|
private readonly capabilities;
|
|
387
446
|
/** 文件路径到 capability id 的映射,用于文件删除时查找 */
|
|
@@ -389,7 +448,7 @@ declare class CapabilityService implements OnModuleInit, OnModuleDestroy {
|
|
|
389
448
|
private capabilitiesDir;
|
|
390
449
|
private fileWatcher;
|
|
391
450
|
private options;
|
|
392
|
-
constructor(requestContextService: RequestContextService, httpClientFactory: HttpClientFactory, pluginLoaderService: PluginLoaderService, templateEngineService: TemplateEngineService);
|
|
451
|
+
constructor(requestContextService: RequestContextService, httpClientFactory: HttpClientFactory, pluginLoaderService: PluginLoaderService, templateEngineService: TemplateEngineService, telemetryService: TelemetryService);
|
|
393
452
|
/**
|
|
394
453
|
* 设置模块配置
|
|
395
454
|
*/
|
|
@@ -461,6 +520,10 @@ declare class CapabilityService implements OnModuleInit, OnModuleDestroy {
|
|
|
461
520
|
* - 如果插件不支持,则包装 runStream/run 为 StreamEvent
|
|
462
521
|
*/
|
|
463
522
|
private executeCallStreamWithEvents;
|
|
523
|
+
/**
|
|
524
|
+
* 上报调用事件(fire-and-forget)
|
|
525
|
+
*/
|
|
526
|
+
private reportCallEvent;
|
|
464
527
|
/**
|
|
465
528
|
* 从错误对象提取错误信息
|
|
466
529
|
* 支持 PluginError 和 RateLimitError
|
|
@@ -595,4 +658,4 @@ interface MigrationResponse {
|
|
|
595
658
|
*/
|
|
596
659
|
declare function migrationAdaptor(promise: Promise<unknown>): Promise<MigrationResponse>;
|
|
597
660
|
|
|
598
|
-
export { ActionNotFoundError, type ActionSchema, type CapabilityConfig, type CapabilityExecutor, type CapabilityListItem, CapabilityModule, type CapabilityModuleOptions, CapabilityNotFoundError, CapabilityService, DebugController, type DebugExecuteResponseData, type DebugInfo, type ErrorCode, ErrorCodes, type ErrorResponse, type ExecuteResponseData, type FailureOutput, type JSONSchema, type ListResponseData, type MigrationResponse, type PluginActionContext, type PluginInstance, PluginLoadError, PluginLoaderService, type PluginManifest, PluginNotFoundError, type PluginPackage, type StreamContentResponse, type StreamDoneMetadata, type StreamError, type StreamErrorResponse, type StreamEvent, type StreamResponse, type SuccessResponse, TemplateEngineService, type UserContext, WebhookController, migrationAdaptor };
|
|
661
|
+
export { ActionNotFoundError, type ActionSchema, type CallEventDetails, type CallerType, type CapabilityConfig, type CapabilityExecutor, type CapabilityListItem, CapabilityModule, type CapabilityModuleOptions, CapabilityNotFoundError, CapabilityService, DebugController, type DebugExecuteResponseData, type DebugInfo, type ErrorCode, ErrorCodes, type ErrorResponse, type EventType, type ExecuteResponseData, type FailureOutput, type JSONSchema, type ListResponseData, type MigrationResponse, type PluginActionContext, type PluginInstance, PluginLoadError, PluginLoaderService, type PluginManifest, PluginNotFoundError, type PluginPackage, type ResourceEvent, type StreamContentResponse, type StreamDoneMetadata, type StreamError, type StreamErrorResponse, type StreamEvent, type StreamResponse, type SuccessResponse, TelemetryService, TemplateEngineService, type UserContext, WebhookController, migrationAdaptor };
|
package/dist/index.d.ts
CHANGED
|
@@ -3,10 +3,65 @@ import { PlatformHttpClient, RequestContextService, HttpClientFactory } from '@l
|
|
|
3
3
|
import { ZodSchema } from 'zod';
|
|
4
4
|
import { Response } from 'express';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* 事件类型
|
|
8
|
+
*/
|
|
9
|
+
type EventType = 'install' | 'create_instance' | 'call';
|
|
10
|
+
/**
|
|
11
|
+
* 调用者类型
|
|
12
|
+
*/
|
|
13
|
+
type CallerType = 'client' | 'server' | 'debug';
|
|
14
|
+
/**
|
|
15
|
+
* 资源事件
|
|
16
|
+
*/
|
|
17
|
+
interface ResourceEvent {
|
|
18
|
+
resourceType: 'plugin';
|
|
19
|
+
resourceKey: string;
|
|
20
|
+
eventType: EventType;
|
|
21
|
+
details?: Record<string, string>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Call 事件详情
|
|
25
|
+
*/
|
|
26
|
+
interface CallEventDetails {
|
|
27
|
+
version: string;
|
|
28
|
+
success: string;
|
|
29
|
+
duration: string;
|
|
30
|
+
is_stream: string;
|
|
31
|
+
caller_type: string;
|
|
32
|
+
status_code: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* 插件遥测服务
|
|
36
|
+
*
|
|
37
|
+
* 负责上报插件生命周期事件到平台
|
|
38
|
+
*/
|
|
39
|
+
declare class TelemetryService {
|
|
40
|
+
private readonly client;
|
|
41
|
+
private readonly logger;
|
|
42
|
+
constructor(client: PlatformHttpClient);
|
|
43
|
+
/**
|
|
44
|
+
* 上报事件到平台
|
|
45
|
+
*
|
|
46
|
+
* @param events - 事件列表
|
|
47
|
+
* @returns 是否上报成功
|
|
48
|
+
*/
|
|
49
|
+
reportEvents(events: ResourceEvent[]): Promise<boolean>;
|
|
50
|
+
/**
|
|
51
|
+
* 上报插件调用事件
|
|
52
|
+
*
|
|
53
|
+
* @param pluginKey - 插件标识
|
|
54
|
+
* @param details - 调用详情
|
|
55
|
+
*/
|
|
56
|
+
reportCall(pluginKey: string, details: CallEventDetails): Promise<void>;
|
|
57
|
+
}
|
|
58
|
+
|
|
6
59
|
interface UserContext {
|
|
7
60
|
userId: string;
|
|
8
61
|
tenantId: string;
|
|
9
62
|
appId: string;
|
|
63
|
+
/** 是否为系统账号 */
|
|
64
|
+
isSystemAccount: boolean;
|
|
10
65
|
}
|
|
11
66
|
interface PluginActionContext {
|
|
12
67
|
/** 插件标识(如 @official/ai-chat) */
|
|
@@ -16,6 +71,8 @@ interface PluginActionContext {
|
|
|
16
71
|
userContext: UserContext;
|
|
17
72
|
/** 是否为调试模式(来自 debug controller 的调用) */
|
|
18
73
|
isDebug: boolean;
|
|
74
|
+
/** 调用来源:client=前端SDK, server=服务端内部, debug=调试面板 */
|
|
75
|
+
caller?: CallerType;
|
|
19
76
|
}
|
|
20
77
|
|
|
21
78
|
interface JSONSchema {
|
|
@@ -273,6 +330,7 @@ declare class TemplateEngineService {
|
|
|
273
330
|
|
|
274
331
|
interface PluginManifest {
|
|
275
332
|
name: string;
|
|
333
|
+
version?: string;
|
|
276
334
|
form?: {
|
|
277
335
|
refType?: 'config' | 'action';
|
|
278
336
|
schema?: unknown;
|
|
@@ -382,6 +440,7 @@ declare class CapabilityService implements OnModuleInit, OnModuleDestroy {
|
|
|
382
440
|
private readonly httpClientFactory;
|
|
383
441
|
private readonly pluginLoaderService;
|
|
384
442
|
private readonly templateEngineService;
|
|
443
|
+
private readonly telemetryService;
|
|
385
444
|
private readonly logger;
|
|
386
445
|
private readonly capabilities;
|
|
387
446
|
/** 文件路径到 capability id 的映射,用于文件删除时查找 */
|
|
@@ -389,7 +448,7 @@ declare class CapabilityService implements OnModuleInit, OnModuleDestroy {
|
|
|
389
448
|
private capabilitiesDir;
|
|
390
449
|
private fileWatcher;
|
|
391
450
|
private options;
|
|
392
|
-
constructor(requestContextService: RequestContextService, httpClientFactory: HttpClientFactory, pluginLoaderService: PluginLoaderService, templateEngineService: TemplateEngineService);
|
|
451
|
+
constructor(requestContextService: RequestContextService, httpClientFactory: HttpClientFactory, pluginLoaderService: PluginLoaderService, templateEngineService: TemplateEngineService, telemetryService: TelemetryService);
|
|
393
452
|
/**
|
|
394
453
|
* 设置模块配置
|
|
395
454
|
*/
|
|
@@ -461,6 +520,10 @@ declare class CapabilityService implements OnModuleInit, OnModuleDestroy {
|
|
|
461
520
|
* - 如果插件不支持,则包装 runStream/run 为 StreamEvent
|
|
462
521
|
*/
|
|
463
522
|
private executeCallStreamWithEvents;
|
|
523
|
+
/**
|
|
524
|
+
* 上报调用事件(fire-and-forget)
|
|
525
|
+
*/
|
|
526
|
+
private reportCallEvent;
|
|
464
527
|
/**
|
|
465
528
|
* 从错误对象提取错误信息
|
|
466
529
|
* 支持 PluginError 和 RateLimitError
|
|
@@ -595,4 +658,4 @@ interface MigrationResponse {
|
|
|
595
658
|
*/
|
|
596
659
|
declare function migrationAdaptor(promise: Promise<unknown>): Promise<MigrationResponse>;
|
|
597
660
|
|
|
598
|
-
export { ActionNotFoundError, type ActionSchema, type CapabilityConfig, type CapabilityExecutor, type CapabilityListItem, CapabilityModule, type CapabilityModuleOptions, CapabilityNotFoundError, CapabilityService, DebugController, type DebugExecuteResponseData, type DebugInfo, type ErrorCode, ErrorCodes, type ErrorResponse, type ExecuteResponseData, type FailureOutput, type JSONSchema, type ListResponseData, type MigrationResponse, type PluginActionContext, type PluginInstance, PluginLoadError, PluginLoaderService, type PluginManifest, PluginNotFoundError, type PluginPackage, type StreamContentResponse, type StreamDoneMetadata, type StreamError, type StreamErrorResponse, type StreamEvent, type StreamResponse, type SuccessResponse, TemplateEngineService, type UserContext, WebhookController, migrationAdaptor };
|
|
661
|
+
export { ActionNotFoundError, type ActionSchema, type CallEventDetails, type CallerType, type CapabilityConfig, type CapabilityExecutor, type CapabilityListItem, CapabilityModule, type CapabilityModuleOptions, CapabilityNotFoundError, CapabilityService, DebugController, type DebugExecuteResponseData, type DebugInfo, type ErrorCode, ErrorCodes, type ErrorResponse, type EventType, type ExecuteResponseData, type FailureOutput, type JSONSchema, type ListResponseData, type MigrationResponse, type PluginActionContext, type PluginInstance, PluginLoadError, PluginLoaderService, type PluginManifest, PluginNotFoundError, type PluginPackage, type ResourceEvent, type StreamContentResponse, type StreamDoneMetadata, type StreamError, type StreamErrorResponse, type StreamEvent, type StreamResponse, type SuccessResponse, TelemetryService, TemplateEngineService, type UserContext, WebhookController, migrationAdaptor };
|