@lark-apaas/nestjs-capability 0.0.1-alpha.4 → 0.0.1-alpha.6
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/dist/index.cjs +272 -114
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +177 -64
- package/dist/index.d.ts +177 -64
- package/dist/index.js +271 -114
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -13,6 +13,143 @@ interface PluginActionContext {
|
|
|
13
13
|
userContext: UserContext;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
interface JSONSchema {
|
|
17
|
+
type?: string;
|
|
18
|
+
properties?: Record<string, JSONSchema>;
|
|
19
|
+
required?: string[];
|
|
20
|
+
items?: JSONSchema;
|
|
21
|
+
[key: string]: unknown;
|
|
22
|
+
}
|
|
23
|
+
interface CapabilityConfig {
|
|
24
|
+
id: string;
|
|
25
|
+
pluginKey: string;
|
|
26
|
+
pluginVersion: string;
|
|
27
|
+
name: string;
|
|
28
|
+
description: string;
|
|
29
|
+
paramsSchema: JSONSchema;
|
|
30
|
+
formValue: Record<string, unknown>;
|
|
31
|
+
createdAt: number;
|
|
32
|
+
updatedAt: number;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 成功响应基础结构
|
|
37
|
+
*/
|
|
38
|
+
interface SuccessResponse<T> {
|
|
39
|
+
status_code: '0';
|
|
40
|
+
data: T;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* 错误响应结构
|
|
44
|
+
*/
|
|
45
|
+
interface ErrorResponse {
|
|
46
|
+
status_code: string;
|
|
47
|
+
error_msg: string;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Debug 信息
|
|
51
|
+
*/
|
|
52
|
+
interface DebugInfo {
|
|
53
|
+
capabilityConfig: CapabilityConfig;
|
|
54
|
+
resolvedParams: unknown;
|
|
55
|
+
duration: number;
|
|
56
|
+
pluginID: string;
|
|
57
|
+
action: string;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* 执行接口响应 data 结构
|
|
61
|
+
*/
|
|
62
|
+
interface ExecuteResponseData {
|
|
63
|
+
output: unknown;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Debug 执行接口响应 data 结构
|
|
67
|
+
*/
|
|
68
|
+
interface DebugExecuteResponseData {
|
|
69
|
+
output: unknown;
|
|
70
|
+
debug: DebugInfo;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* 能力列表项
|
|
74
|
+
*/
|
|
75
|
+
interface CapabilityListItem {
|
|
76
|
+
id: string;
|
|
77
|
+
name: string;
|
|
78
|
+
pluginID: string;
|
|
79
|
+
pluginVersion: string;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* 列表接口响应 data 结构
|
|
83
|
+
*/
|
|
84
|
+
interface ListResponseData {
|
|
85
|
+
capabilities: CapabilityListItem[];
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* 流式内容响应
|
|
89
|
+
*/
|
|
90
|
+
interface StreamContentResponse {
|
|
91
|
+
status_code: '0';
|
|
92
|
+
data: {
|
|
93
|
+
type: 'content';
|
|
94
|
+
delta: {
|
|
95
|
+
content: unknown;
|
|
96
|
+
};
|
|
97
|
+
finished?: boolean;
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* 流式错误响应
|
|
102
|
+
*/
|
|
103
|
+
interface StreamErrorResponse {
|
|
104
|
+
status_code: '0';
|
|
105
|
+
data: {
|
|
106
|
+
type: 'error';
|
|
107
|
+
error: {
|
|
108
|
+
code: number;
|
|
109
|
+
message: string;
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* 流式响应类型
|
|
115
|
+
*/
|
|
116
|
+
type StreamResponse = StreamContentResponse | StreamErrorResponse;
|
|
117
|
+
/**
|
|
118
|
+
* 流完成元数据
|
|
119
|
+
*/
|
|
120
|
+
interface StreamDoneMetadata {
|
|
121
|
+
/** chunk 总数 */
|
|
122
|
+
chunks: number;
|
|
123
|
+
/** 流持续时间 (ms) */
|
|
124
|
+
duration: number;
|
|
125
|
+
/** 聚合结果(可选) */
|
|
126
|
+
aggregated?: unknown;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* 流错误信息
|
|
130
|
+
*/
|
|
131
|
+
interface StreamError {
|
|
132
|
+
code: string;
|
|
133
|
+
message: string;
|
|
134
|
+
details?: unknown;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* 流事件类型
|
|
138
|
+
* - data: 数据事件,包含单个 chunk
|
|
139
|
+
* - done: 完成事件,包含元数据
|
|
140
|
+
* - error: 错误事件,包含错误信息
|
|
141
|
+
*/
|
|
142
|
+
type StreamEvent<T> = {
|
|
143
|
+
type: 'data';
|
|
144
|
+
data: T;
|
|
145
|
+
} | {
|
|
146
|
+
type: 'done';
|
|
147
|
+
metadata: StreamDoneMetadata;
|
|
148
|
+
} | {
|
|
149
|
+
type: 'error';
|
|
150
|
+
error: StreamError;
|
|
151
|
+
};
|
|
152
|
+
|
|
16
153
|
interface ActionSchema {
|
|
17
154
|
input: ZodSchema | ((config: unknown) => ZodSchema);
|
|
18
155
|
output?: ZodSchema | ((input: unknown, config: unknown) => ZodSchema);
|
|
@@ -30,8 +167,10 @@ interface PluginInstance {
|
|
|
30
167
|
getOutputSchema(actionName: string, input: unknown, config?: unknown): ZodSchema | undefined;
|
|
31
168
|
/** 列出所有 action */
|
|
32
169
|
listActions(): string[];
|
|
33
|
-
/** 流式执行指定 action */
|
|
170
|
+
/** 流式执行指定 action,返回原始流 */
|
|
34
171
|
runStream?(actionName: string, context: PluginActionContext, input: unknown): AsyncIterable<unknown>;
|
|
172
|
+
/** 流式执行指定 action,返回带事件协议的流(推荐) */
|
|
173
|
+
runStreamWithEvents?(actionName: string, context: PluginActionContext, input: unknown): AsyncIterable<StreamEvent<unknown>>;
|
|
35
174
|
/** 检查 action 是否为流式 */
|
|
36
175
|
isStreamAction?(actionName: string): boolean;
|
|
37
176
|
/** 聚合流式结果(可选,插件自定义聚合逻辑) */
|
|
@@ -41,24 +180,24 @@ interface PluginPackage {
|
|
|
41
180
|
create(): PluginInstance;
|
|
42
181
|
}
|
|
43
182
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
183
|
+
/**
|
|
184
|
+
* Capability 模块错误码
|
|
185
|
+
*/
|
|
186
|
+
declare const ErrorCodes: {
|
|
187
|
+
/** 成功 */
|
|
188
|
+
readonly SUCCESS: "0";
|
|
189
|
+
/** 能力不存在 */
|
|
190
|
+
readonly CAPABILITY_NOT_FOUND: "k_ec_cap_001";
|
|
191
|
+
/** 插件不存在 */
|
|
192
|
+
readonly PLUGIN_NOT_FOUND: "k_ec_cap_002";
|
|
193
|
+
/** Action 不存在 */
|
|
194
|
+
readonly ACTION_NOT_FOUND: "k_ec_cap_003";
|
|
195
|
+
/** 参数验证失败 */
|
|
196
|
+
readonly PARAMS_VALIDATION_ERROR: "k_ec_cap_004";
|
|
197
|
+
/** 执行失败 */
|
|
198
|
+
readonly EXECUTION_ERROR: "k_ec_cap_005";
|
|
199
|
+
};
|
|
200
|
+
type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];
|
|
62
201
|
|
|
63
202
|
/**
|
|
64
203
|
* 模板引擎服务
|
|
@@ -115,11 +254,18 @@ interface CapabilityExecutor {
|
|
|
115
254
|
*/
|
|
116
255
|
call(actionName: string, input: unknown, context?: Partial<PluginActionContext>): Promise<unknown>;
|
|
117
256
|
/**
|
|
118
|
-
* 流式调用 capability
|
|
257
|
+
* 流式调用 capability,返回原始流
|
|
119
258
|
* - 返回原始 AsyncIterable
|
|
120
259
|
* - 如果 action 是 unary,包装为单次 yield
|
|
121
260
|
*/
|
|
122
261
|
callStream(actionName: string, input: unknown, context?: Partial<PluginActionContext>): AsyncIterable<unknown>;
|
|
262
|
+
/**
|
|
263
|
+
* 流式调用 capability,返回带事件协议的流(推荐)
|
|
264
|
+
* - 返回 StreamEvent 类型的 AsyncIterable
|
|
265
|
+
* - 支持 data/done/error 三种事件类型
|
|
266
|
+
* - Controller 层应优先使用此方法实现边收边发
|
|
267
|
+
*/
|
|
268
|
+
callStreamWithEvents(actionName: string, input: unknown, context?: Partial<PluginActionContext>): AsyncIterable<StreamEvent<unknown>>;
|
|
123
269
|
/**
|
|
124
270
|
* 检查 action 是否为流式
|
|
125
271
|
*/
|
|
@@ -165,6 +311,12 @@ declare class CapabilityService implements OnModuleInit {
|
|
|
165
311
|
* - unary action: 包装为单次 yield
|
|
166
312
|
*/
|
|
167
313
|
private executeCallStream;
|
|
314
|
+
/**
|
|
315
|
+
* 流式执行 capability,返回带事件协议的流
|
|
316
|
+
* - 优先使用 pluginInstance.runStreamWithEvents
|
|
317
|
+
* - 如果插件不支持,则包装 runStream/run 为 StreamEvent
|
|
318
|
+
*/
|
|
319
|
+
private executeCallStreamWithEvents;
|
|
168
320
|
private buildActionContext;
|
|
169
321
|
private getUserContext;
|
|
170
322
|
}
|
|
@@ -174,34 +326,12 @@ interface DebugRequestBody {
|
|
|
174
326
|
params?: Record<string, unknown>;
|
|
175
327
|
capability?: CapabilityConfig;
|
|
176
328
|
}
|
|
177
|
-
interface DebugResponse {
|
|
178
|
-
code: number;
|
|
179
|
-
message: string;
|
|
180
|
-
data: unknown;
|
|
181
|
-
debug?: {
|
|
182
|
-
capabilityConfig: unknown;
|
|
183
|
-
resolvedParams: unknown;
|
|
184
|
-
duration: number;
|
|
185
|
-
pluginKey: string;
|
|
186
|
-
action: string;
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
interface ListResponse$1 {
|
|
190
|
-
code: number;
|
|
191
|
-
message: string;
|
|
192
|
-
data: Array<{
|
|
193
|
-
id: string;
|
|
194
|
-
name: string;
|
|
195
|
-
pluginKey: string;
|
|
196
|
-
pluginVersion: string;
|
|
197
|
-
}>;
|
|
198
|
-
}
|
|
199
329
|
declare class DebugController {
|
|
200
330
|
private readonly capabilityService;
|
|
201
331
|
private readonly pluginLoaderService;
|
|
202
332
|
private readonly templateEngineService;
|
|
203
333
|
constructor(capabilityService: CapabilityService, pluginLoaderService: PluginLoaderService, templateEngineService: TemplateEngineService);
|
|
204
|
-
list():
|
|
334
|
+
list(): SuccessResponse<ListResponseData>;
|
|
205
335
|
/**
|
|
206
336
|
* 获取 capability 配置
|
|
207
337
|
* 优先使用 body.capability,否则从服务获取
|
|
@@ -212,7 +342,7 @@ declare class DebugController {
|
|
|
212
342
|
* 优先使用传入的 action,否则使用插件第一个 action
|
|
213
343
|
*/
|
|
214
344
|
private getActionName;
|
|
215
|
-
debug(capabilityId: string, body: DebugRequestBody): Promise<
|
|
345
|
+
debug(capabilityId: string, body: DebugRequestBody): Promise<SuccessResponse<DebugExecuteResponseData> | ErrorResponse>;
|
|
216
346
|
debugStream(capabilityId: string, body: DebugRequestBody, res: Response): Promise<void>;
|
|
217
347
|
}
|
|
218
348
|
|
|
@@ -220,28 +350,11 @@ interface ExecuteRequestBody {
|
|
|
220
350
|
action: string;
|
|
221
351
|
params: Record<string, unknown>;
|
|
222
352
|
}
|
|
223
|
-
interface ExecuteResponse {
|
|
224
|
-
code: number;
|
|
225
|
-
message: string;
|
|
226
|
-
data: unknown;
|
|
227
|
-
}
|
|
228
|
-
interface CapabilityInfo {
|
|
229
|
-
id: string;
|
|
230
|
-
name: string;
|
|
231
|
-
description: string;
|
|
232
|
-
pluginKey: string;
|
|
233
|
-
pluginVersion: string;
|
|
234
|
-
}
|
|
235
|
-
interface ListResponse {
|
|
236
|
-
code: number;
|
|
237
|
-
message: string;
|
|
238
|
-
data: CapabilityInfo[];
|
|
239
|
-
}
|
|
240
353
|
declare class WebhookController {
|
|
241
354
|
private readonly capabilityService;
|
|
242
355
|
constructor(capabilityService: CapabilityService);
|
|
243
|
-
list():
|
|
244
|
-
execute(capabilityId: string, body: ExecuteRequestBody): Promise<
|
|
356
|
+
list(): SuccessResponse<ListResponseData>;
|
|
357
|
+
execute(capabilityId: string, body: ExecuteRequestBody): Promise<SuccessResponse<ExecuteResponseData> | ErrorResponse>;
|
|
245
358
|
executeStream(capabilityId: string, body: ExecuteRequestBody, res: Response): Promise<void>;
|
|
246
359
|
}
|
|
247
360
|
|
|
@@ -249,4 +362,4 @@ declare class CapabilityModule {
|
|
|
249
362
|
static forRoot(options?: CapabilityModuleOptions): DynamicModule;
|
|
250
363
|
}
|
|
251
364
|
|
|
252
|
-
export { ActionNotFoundError, type ActionSchema, type CapabilityConfig, type CapabilityExecutor, CapabilityModule, type CapabilityModuleOptions, CapabilityNotFoundError, CapabilityService, DebugController, type JSONSchema, type PluginActionContext, type PluginInstance, PluginLoadError, PluginLoaderService, PluginNotFoundError, type PluginPackage, TemplateEngineService, type UserContext, WebhookController };
|
|
365
|
+
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 JSONSchema, type ListResponseData, type PluginActionContext, type PluginInstance, PluginLoadError, PluginLoaderService, PluginNotFoundError, type PluginPackage, type StreamContentResponse, type StreamDoneMetadata, type StreamError, type StreamErrorResponse, type StreamEvent, type StreamResponse, type SuccessResponse, TemplateEngineService, type UserContext, WebhookController };
|