@lark-apaas/nestjs-capability 0.0.1-alpha.12 → 0.0.1-alpha.14
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 +178 -99
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +81 -5
- package/dist/index.d.ts +81 -5
- package/dist/index.js +178 -100
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -228,6 +228,7 @@ declare class TemplateEngineService {
|
|
|
228
228
|
}
|
|
229
229
|
|
|
230
230
|
declare class PluginNotFoundError extends Error {
|
|
231
|
+
readonly pluginKey: string;
|
|
231
232
|
constructor(pluginKey: string);
|
|
232
233
|
}
|
|
233
234
|
declare class PluginLoadError extends Error {
|
|
@@ -264,9 +265,12 @@ declare class PluginLoaderService {
|
|
|
264
265
|
}
|
|
265
266
|
|
|
266
267
|
declare class CapabilityNotFoundError extends Error {
|
|
268
|
+
readonly capabilityId: string;
|
|
267
269
|
constructor(capabilityId: string);
|
|
268
270
|
}
|
|
269
271
|
declare class ActionNotFoundError extends Error {
|
|
272
|
+
readonly pluginKey: string;
|
|
273
|
+
readonly actionName: string;
|
|
270
274
|
constructor(pluginKey: string, actionName: string);
|
|
271
275
|
}
|
|
272
276
|
interface CapabilityExecutor {
|
|
@@ -396,7 +400,7 @@ declare class DebugController {
|
|
|
396
400
|
private readonly templateEngineService;
|
|
397
401
|
private readonly logger;
|
|
398
402
|
constructor(capabilityService: CapabilityService, pluginLoaderService: PluginLoaderService, templateEngineService: TemplateEngineService);
|
|
399
|
-
list():
|
|
403
|
+
list(res: Response): void;
|
|
400
404
|
/**
|
|
401
405
|
* 获取 capability 配置
|
|
402
406
|
* 优先使用 body.capability,否则从服务获取
|
|
@@ -407,7 +411,11 @@ declare class DebugController {
|
|
|
407
411
|
* 优先使用传入的 action,否则使用插件第一个 action
|
|
408
412
|
*/
|
|
409
413
|
private getActionName;
|
|
410
|
-
debug(capabilityId: string, body: DebugRequestBody): Promise<
|
|
414
|
+
debug(capabilityId: string, body: DebugRequestBody, res: Response): Promise<void>;
|
|
415
|
+
/**
|
|
416
|
+
* 构建错误响应
|
|
417
|
+
*/
|
|
418
|
+
private buildErrorResponse;
|
|
411
419
|
debugStream(capabilityId: string, body: DebugRequestBody, res: Response): Promise<void>;
|
|
412
420
|
}
|
|
413
421
|
|
|
@@ -419,8 +427,12 @@ declare class WebhookController {
|
|
|
419
427
|
private readonly capabilityService;
|
|
420
428
|
private readonly logger;
|
|
421
429
|
constructor(capabilityService: CapabilityService);
|
|
422
|
-
list():
|
|
423
|
-
execute(capabilityId: string, body: ExecuteRequestBody): Promise<
|
|
430
|
+
list(res: Response): void;
|
|
431
|
+
execute(capabilityId: string, body: ExecuteRequestBody, res: Response): Promise<void>;
|
|
432
|
+
/**
|
|
433
|
+
* 构建错误响应
|
|
434
|
+
*/
|
|
435
|
+
private buildErrorResponse;
|
|
424
436
|
executeStream(capabilityId: string, body: ExecuteRequestBody, res: Response): Promise<void>;
|
|
425
437
|
}
|
|
426
438
|
|
|
@@ -428,4 +440,68 @@ declare class CapabilityModule {
|
|
|
428
440
|
static forRoot(options?: CapabilityModuleOptions): DynamicModule;
|
|
429
441
|
}
|
|
430
442
|
|
|
431
|
-
|
|
443
|
+
/**
|
|
444
|
+
* Migration Adaptor
|
|
445
|
+
*
|
|
446
|
+
* 用于迁移老版本 capability 调用代码,将新版本的返回结果包装为老版本的 Response 结构
|
|
447
|
+
*/
|
|
448
|
+
/**
|
|
449
|
+
* 失败输出结构
|
|
450
|
+
*/
|
|
451
|
+
interface FailureOutput {
|
|
452
|
+
response: {
|
|
453
|
+
status: {
|
|
454
|
+
/** 协议层返回码(如 HTTP 状态码) */
|
|
455
|
+
protocolStatusCode: string;
|
|
456
|
+
/** 业务应用状态码 */
|
|
457
|
+
appStatusCode: string;
|
|
458
|
+
};
|
|
459
|
+
/** 返回体(JSON 字符串形式) */
|
|
460
|
+
body: string;
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* 老版本 capability 调用的 Response 结构
|
|
465
|
+
*
|
|
466
|
+
* 注意:output 使用 any 类型以简化迁移代码,避免类型断言
|
|
467
|
+
*/
|
|
468
|
+
interface MigrationResponse {
|
|
469
|
+
/** 当 code=0 时表示执行成功,当 code!=0 时表示执行失败 */
|
|
470
|
+
code: number;
|
|
471
|
+
data?: {
|
|
472
|
+
/** 执行成功时的输出结果(any 类型,兼容迁移场景) */
|
|
473
|
+
output?: any;
|
|
474
|
+
/** 执行结果,'success' 或 'error' */
|
|
475
|
+
outcome?: 'success' | 'error';
|
|
476
|
+
/** 执行失败时的输出结果 */
|
|
477
|
+
failureOutput?: FailureOutput;
|
|
478
|
+
};
|
|
479
|
+
/** 发生错误时的错误信息 */
|
|
480
|
+
message?: string;
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
* 迁移适配器
|
|
484
|
+
*
|
|
485
|
+
* 将 CapabilityService.load().call() 的返回结果包装为老版本的 Response 结构
|
|
486
|
+
*
|
|
487
|
+
* @example
|
|
488
|
+
* // 老代码
|
|
489
|
+
* const result = await generateTaskDescription(params);
|
|
490
|
+
*
|
|
491
|
+
* // 新代码
|
|
492
|
+
* const result = await migrationAdaptor(
|
|
493
|
+
* this.capabilityService.load('ai_generate_task_description').call('run', params)
|
|
494
|
+
* );
|
|
495
|
+
*
|
|
496
|
+
* // result 结构
|
|
497
|
+
* // {
|
|
498
|
+
* // code: 0,
|
|
499
|
+
* // data: {
|
|
500
|
+
* // output: { ... }, // 能力执行结果
|
|
501
|
+
* // outcome: 'success'
|
|
502
|
+
* // }
|
|
503
|
+
* // }
|
|
504
|
+
*/
|
|
505
|
+
declare function migrationAdaptor(promise: Promise<unknown>): Promise<MigrationResponse>;
|
|
506
|
+
|
|
507
|
+
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, PluginNotFoundError, type PluginPackage, type StreamContentResponse, type StreamDoneMetadata, type StreamError, type StreamErrorResponse, type StreamEvent, type StreamResponse, type SuccessResponse, TemplateEngineService, type UserContext, WebhookController, migrationAdaptor };
|
package/dist/index.js
CHANGED
|
@@ -31,9 +31,9 @@ var TemplateEngineService = class {
|
|
|
31
31
|
__name(this, "TemplateEngineService");
|
|
32
32
|
}
|
|
33
33
|
// 匹配 {{input.xxx}} 或 {{input.xxx.yyy}} 表达式
|
|
34
|
-
EXPR_REGEX = /\{\{input\.([a-zA-Z_][a-zA-Z_0-9]*(?:\.[a-zA-Z_][a-zA-Z_0-9]*)*)\}\}/g;
|
|
34
|
+
EXPR_REGEX = /\{\{\s*input\.([a-zA-Z_][a-zA-Z_0-9]*(?:\.[a-zA-Z_][a-zA-Z_0-9]*)*\s*)\}\}/g;
|
|
35
35
|
// 匹配整串单个表达式
|
|
36
|
-
WHOLE_STRING_EXPR_REGEX = /^\{\{input\.([a-zA-Z_][a-zA-Z_0-9]*(?:\.[a-zA-Z_][a-zA-Z_0-9]*)*)\}\}$/;
|
|
36
|
+
WHOLE_STRING_EXPR_REGEX = /^\{\{\s*input\.([a-zA-Z_][a-zA-Z_0-9]*(?:\.[a-zA-Z_][a-zA-Z_0-9]*)*)\s*\}\}$/;
|
|
37
37
|
resolve(template, input) {
|
|
38
38
|
if (typeof template === "string") {
|
|
39
39
|
return this.resolveString(template, input);
|
|
@@ -106,9 +106,11 @@ var PluginNotFoundError = class extends Error {
|
|
|
106
106
|
static {
|
|
107
107
|
__name(this, "PluginNotFoundError");
|
|
108
108
|
}
|
|
109
|
+
pluginKey;
|
|
109
110
|
constructor(pluginKey) {
|
|
110
111
|
super(`Plugin not found: ${pluginKey}`);
|
|
111
112
|
this.name = "PluginNotFoundError";
|
|
113
|
+
this.pluginKey = pluginKey;
|
|
112
114
|
}
|
|
113
115
|
};
|
|
114
116
|
var PluginLoadError = class extends Error {
|
|
@@ -252,6 +254,43 @@ function stringifyForLog(value, maxLength = DEFAULT_MAX_LENGTH) {
|
|
|
252
254
|
}
|
|
253
255
|
__name(stringifyForLog, "stringifyForLog");
|
|
254
256
|
|
|
257
|
+
// src/utils/migration-adaptor.ts
|
|
258
|
+
async function migrationAdaptor(promise) {
|
|
259
|
+
try {
|
|
260
|
+
const result = await promise;
|
|
261
|
+
return {
|
|
262
|
+
code: 0,
|
|
263
|
+
data: {
|
|
264
|
+
output: result,
|
|
265
|
+
outcome: "success"
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
} catch (error) {
|
|
269
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
270
|
+
const appStatusCode = error instanceof Error && "code" in error ? String(error.code) : "EXECUTION_ERROR";
|
|
271
|
+
return {
|
|
272
|
+
code: -1,
|
|
273
|
+
data: {
|
|
274
|
+
outcome: "error",
|
|
275
|
+
failureOutput: {
|
|
276
|
+
response: {
|
|
277
|
+
status: {
|
|
278
|
+
protocolStatusCode: "500",
|
|
279
|
+
appStatusCode
|
|
280
|
+
},
|
|
281
|
+
body: JSON.stringify({
|
|
282
|
+
error: errorMessage,
|
|
283
|
+
stack: error instanceof Error ? error.stack : void 0
|
|
284
|
+
})
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
},
|
|
288
|
+
message: errorMessage
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
__name(migrationAdaptor, "migrationAdaptor");
|
|
293
|
+
|
|
255
294
|
// src/services/capability.service.ts
|
|
256
295
|
function _ts_decorate3(decorators, target, key, desc) {
|
|
257
296
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -274,18 +313,24 @@ var CapabilityNotFoundError = class extends Error {
|
|
|
274
313
|
static {
|
|
275
314
|
__name(this, "CapabilityNotFoundError");
|
|
276
315
|
}
|
|
316
|
+
capabilityId;
|
|
277
317
|
constructor(capabilityId) {
|
|
278
318
|
super(`Capability not found: ${capabilityId}`);
|
|
279
319
|
this.name = "CapabilityNotFoundError";
|
|
320
|
+
this.capabilityId = capabilityId;
|
|
280
321
|
}
|
|
281
322
|
};
|
|
282
323
|
var ActionNotFoundError = class extends Error {
|
|
283
324
|
static {
|
|
284
325
|
__name(this, "ActionNotFoundError");
|
|
285
326
|
}
|
|
327
|
+
pluginKey;
|
|
328
|
+
actionName;
|
|
286
329
|
constructor(pluginKey, actionName) {
|
|
287
330
|
super(`Action '${actionName}' not found in plugin ${pluginKey}`);
|
|
288
331
|
this.name = "ActionNotFoundError";
|
|
332
|
+
this.pluginKey = pluginKey;
|
|
333
|
+
this.actionName = actionName;
|
|
289
334
|
}
|
|
290
335
|
};
|
|
291
336
|
var CapabilityService = class _CapabilityService {
|
|
@@ -731,7 +776,7 @@ CapabilityService = _ts_decorate3([
|
|
|
731
776
|
], CapabilityService);
|
|
732
777
|
|
|
733
778
|
// src/controllers/debug.controller.ts
|
|
734
|
-
import { Controller, Post, Get, Param, Body, Res,
|
|
779
|
+
import { Controller, Post, Get, Param, Body, Res, HttpStatus, Logger as Logger3 } from "@nestjs/common";
|
|
735
780
|
function _ts_decorate4(decorators, target, key, desc) {
|
|
736
781
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
737
782
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -762,19 +807,27 @@ var DebugController = class _DebugController {
|
|
|
762
807
|
this.pluginLoaderService = pluginLoaderService;
|
|
763
808
|
this.templateEngineService = templateEngineService;
|
|
764
809
|
}
|
|
765
|
-
list() {
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
810
|
+
list(res) {
|
|
811
|
+
try {
|
|
812
|
+
const capabilities = this.capabilityService.listCapabilities();
|
|
813
|
+
res.status(HttpStatus.OK).json({
|
|
814
|
+
status_code: ErrorCodes.SUCCESS,
|
|
815
|
+
data: {
|
|
816
|
+
capabilities: capabilities.map((c) => ({
|
|
817
|
+
id: c.id,
|
|
818
|
+
name: c.name,
|
|
819
|
+
pluginID: c.pluginKey,
|
|
820
|
+
pluginVersion: c.pluginVersion
|
|
821
|
+
}))
|
|
822
|
+
}
|
|
823
|
+
});
|
|
824
|
+
} catch (error) {
|
|
825
|
+
this.logger.error("Failed to list capabilities", error);
|
|
826
|
+
res.status(HttpStatus.INTERNAL_SERVER_ERROR).json({
|
|
827
|
+
status_code: ErrorCodes.EXECUTION_ERROR,
|
|
828
|
+
error_msg: `Failed to list capabilities: ${error instanceof Error ? error.message : String(error)}`
|
|
829
|
+
});
|
|
830
|
+
}
|
|
778
831
|
}
|
|
779
832
|
/**
|
|
780
833
|
* 获取 capability 配置
|
|
@@ -786,11 +839,7 @@ var DebugController = class _DebugController {
|
|
|
786
839
|
}
|
|
787
840
|
const config = this.capabilityService.getCapability(capabilityId);
|
|
788
841
|
if (!config) {
|
|
789
|
-
throw new
|
|
790
|
-
code: 1,
|
|
791
|
-
message: `Capability not found: ${capabilityId}`,
|
|
792
|
-
error: "CAPABILITY_NOT_FOUND"
|
|
793
|
-
}, HttpStatus.NOT_FOUND);
|
|
842
|
+
throw new CapabilityNotFoundError(capabilityId);
|
|
794
843
|
}
|
|
795
844
|
return config;
|
|
796
845
|
}
|
|
@@ -805,25 +854,21 @@ var DebugController = class _DebugController {
|
|
|
805
854
|
const pluginInstance = await this.pluginLoaderService.loadPlugin(pluginKey);
|
|
806
855
|
const actions = pluginInstance.listActions();
|
|
807
856
|
if (actions.length === 0) {
|
|
808
|
-
throw new
|
|
809
|
-
code: 1,
|
|
810
|
-
message: `Plugin ${pluginKey} has no actions`,
|
|
811
|
-
error: "NO_ACTIONS"
|
|
812
|
-
}, HttpStatus.BAD_REQUEST);
|
|
857
|
+
throw new Error(`Plugin ${pluginKey} has no actions`);
|
|
813
858
|
}
|
|
814
859
|
return actions[0];
|
|
815
860
|
}
|
|
816
|
-
async debug(capabilityId, body) {
|
|
861
|
+
async debug(capabilityId, body, res) {
|
|
817
862
|
const startTime = Date.now();
|
|
818
863
|
const params = body.params ?? {};
|
|
819
|
-
const config = this.getCapabilityConfig(capabilityId, body.capability);
|
|
820
|
-
const action = await this.getActionName(config.pluginKey, body.action);
|
|
821
|
-
const resolvedParams = this.templateEngineService.resolve(config.formValue, params);
|
|
822
864
|
try {
|
|
865
|
+
const config = this.getCapabilityConfig(capabilityId, body.capability);
|
|
866
|
+
const action = await this.getActionName(config.pluginKey, body.action);
|
|
867
|
+
const resolvedParams = this.templateEngineService.resolve(config.formValue, params);
|
|
823
868
|
const result = await this.capabilityService.loadWithConfig(config).call(action, params, {
|
|
824
869
|
isDebug: true
|
|
825
870
|
});
|
|
826
|
-
|
|
871
|
+
res.status(HttpStatus.OK).json({
|
|
827
872
|
status_code: ErrorCodes.SUCCESS,
|
|
828
873
|
data: {
|
|
829
874
|
output: result,
|
|
@@ -835,31 +880,38 @@ var DebugController = class _DebugController {
|
|
|
835
880
|
action
|
|
836
881
|
}
|
|
837
882
|
}
|
|
838
|
-
};
|
|
883
|
+
});
|
|
839
884
|
} catch (error) {
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
885
|
+
this.logger.error("Debug execution failed", error);
|
|
886
|
+
res.status(HttpStatus.INTERNAL_SERVER_ERROR).json(this.buildErrorResponse(error));
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
/**
|
|
890
|
+
* 构建错误响应
|
|
891
|
+
*/
|
|
892
|
+
buildErrorResponse(error) {
|
|
893
|
+
if (error instanceof CapabilityNotFoundError) {
|
|
894
|
+
return {
|
|
895
|
+
status_code: ErrorCodes.CAPABILITY_NOT_FOUND,
|
|
896
|
+
error_msg: `Capability not found: ${error.capabilityId}`
|
|
897
|
+
};
|
|
898
|
+
}
|
|
899
|
+
if (error instanceof PluginNotFoundError) {
|
|
900
|
+
return {
|
|
901
|
+
status_code: ErrorCodes.PLUGIN_NOT_FOUND,
|
|
902
|
+
error_msg: `Plugin not found, please install plugin: ${error.pluginKey}`
|
|
903
|
+
};
|
|
904
|
+
}
|
|
905
|
+
if (error instanceof ActionNotFoundError) {
|
|
906
|
+
return {
|
|
907
|
+
status_code: ErrorCodes.ACTION_NOT_FOUND,
|
|
908
|
+
error_msg: `Action '${error.actionName}' not found in plugin ${error.pluginKey}`
|
|
909
|
+
};
|
|
862
910
|
}
|
|
911
|
+
return {
|
|
912
|
+
status_code: ErrorCodes.EXECUTION_ERROR,
|
|
913
|
+
error_msg: `Execution failed: ${error instanceof Error ? error.message : String(error)}`
|
|
914
|
+
};
|
|
863
915
|
}
|
|
864
916
|
async debugStream(capabilityId, body, res) {
|
|
865
917
|
const params = body.params ?? {};
|
|
@@ -977,18 +1029,23 @@ var DebugController = class _DebugController {
|
|
|
977
1029
|
};
|
|
978
1030
|
_ts_decorate4([
|
|
979
1031
|
Get("list"),
|
|
1032
|
+
_ts_param2(0, Res()),
|
|
980
1033
|
_ts_metadata2("design:type", Function),
|
|
981
|
-
_ts_metadata2("design:paramtypes", [
|
|
982
|
-
|
|
1034
|
+
_ts_metadata2("design:paramtypes", [
|
|
1035
|
+
typeof Response === "undefined" ? Object : Response
|
|
1036
|
+
]),
|
|
1037
|
+
_ts_metadata2("design:returntype", void 0)
|
|
983
1038
|
], DebugController.prototype, "list", null);
|
|
984
1039
|
_ts_decorate4([
|
|
985
1040
|
Post("debug/:capability_id"),
|
|
986
1041
|
_ts_param2(0, Param("capability_id")),
|
|
987
1042
|
_ts_param2(1, Body()),
|
|
1043
|
+
_ts_param2(2, Res()),
|
|
988
1044
|
_ts_metadata2("design:type", Function),
|
|
989
1045
|
_ts_metadata2("design:paramtypes", [
|
|
990
1046
|
String,
|
|
991
|
-
typeof DebugRequestBody === "undefined" ? Object : DebugRequestBody
|
|
1047
|
+
typeof DebugRequestBody === "undefined" ? Object : DebugRequestBody,
|
|
1048
|
+
typeof Response === "undefined" ? Object : Response
|
|
992
1049
|
]),
|
|
993
1050
|
_ts_metadata2("design:returntype", Promise)
|
|
994
1051
|
], DebugController.prototype, "debug", null);
|
|
@@ -1016,7 +1073,7 @@ DebugController = _ts_decorate4([
|
|
|
1016
1073
|
], DebugController);
|
|
1017
1074
|
|
|
1018
1075
|
// src/controllers/webhook.controller.ts
|
|
1019
|
-
import { Controller as Controller2, Get as Get2, Post as Post2, Param as Param2, Body as Body2, Res as Res2,
|
|
1076
|
+
import { Controller as Controller2, Get as Get2, Post as Post2, Param as Param2, Body as Body2, Res as Res2, HttpStatus as HttpStatus2, Logger as Logger4 } from "@nestjs/common";
|
|
1020
1077
|
function _ts_decorate5(decorators, target, key, desc) {
|
|
1021
1078
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1022
1079
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -1043,53 +1100,68 @@ var WebhookController = class _WebhookController {
|
|
|
1043
1100
|
constructor(capabilityService) {
|
|
1044
1101
|
this.capabilityService = capabilityService;
|
|
1045
1102
|
}
|
|
1046
|
-
list() {
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1103
|
+
list(res) {
|
|
1104
|
+
try {
|
|
1105
|
+
const capabilities = this.capabilityService.listCapabilities();
|
|
1106
|
+
res.status(HttpStatus2.OK).json({
|
|
1107
|
+
status_code: ErrorCodes.SUCCESS,
|
|
1108
|
+
data: {
|
|
1109
|
+
capabilities: capabilities.map((c) => ({
|
|
1110
|
+
id: c.id,
|
|
1111
|
+
name: c.name,
|
|
1112
|
+
pluginID: c.pluginKey,
|
|
1113
|
+
pluginVersion: c.pluginVersion
|
|
1114
|
+
}))
|
|
1115
|
+
}
|
|
1116
|
+
});
|
|
1117
|
+
} catch (error) {
|
|
1118
|
+
this.logger.error("Failed to list capabilities", error);
|
|
1119
|
+
res.status(HttpStatus2.INTERNAL_SERVER_ERROR).json({
|
|
1120
|
+
status_code: ErrorCodes.EXECUTION_ERROR,
|
|
1121
|
+
error_msg: `Failed to list capabilities: ${error instanceof Error ? error.message : String(error)}`
|
|
1122
|
+
});
|
|
1123
|
+
}
|
|
1059
1124
|
}
|
|
1060
|
-
async execute(capabilityId, body) {
|
|
1125
|
+
async execute(capabilityId, body, res) {
|
|
1061
1126
|
try {
|
|
1062
1127
|
const result = await this.capabilityService.load(capabilityId).call(body.action, body.params);
|
|
1063
|
-
|
|
1128
|
+
res.status(HttpStatus2.OK).json({
|
|
1064
1129
|
status_code: ErrorCodes.SUCCESS,
|
|
1065
1130
|
data: {
|
|
1066
1131
|
output: result
|
|
1067
1132
|
}
|
|
1068
|
-
};
|
|
1133
|
+
});
|
|
1069
1134
|
} catch (error) {
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1135
|
+
this.logger.error("Capability execution failed", error);
|
|
1136
|
+
res.status(HttpStatus2.INTERNAL_SERVER_ERROR).json(this.buildErrorResponse(error));
|
|
1137
|
+
}
|
|
1138
|
+
}
|
|
1139
|
+
/**
|
|
1140
|
+
* 构建错误响应
|
|
1141
|
+
*/
|
|
1142
|
+
buildErrorResponse(error) {
|
|
1143
|
+
if (error instanceof CapabilityNotFoundError) {
|
|
1144
|
+
return {
|
|
1145
|
+
status_code: ErrorCodes.CAPABILITY_NOT_FOUND,
|
|
1146
|
+
error_msg: `Capability not found: ${error.capabilityId}`
|
|
1147
|
+
};
|
|
1148
|
+
}
|
|
1149
|
+
if (error instanceof PluginNotFoundError) {
|
|
1150
|
+
return {
|
|
1151
|
+
status_code: ErrorCodes.PLUGIN_NOT_FOUND,
|
|
1152
|
+
error_msg: `Plugin not found, please install plugin: ${error.pluginKey}`
|
|
1153
|
+
};
|
|
1154
|
+
}
|
|
1155
|
+
if (error instanceof ActionNotFoundError) {
|
|
1156
|
+
return {
|
|
1157
|
+
status_code: ErrorCodes.ACTION_NOT_FOUND,
|
|
1158
|
+
error_msg: `Action '${error.actionName}' not found in plugin ${error.pluginKey}`
|
|
1159
|
+
};
|
|
1092
1160
|
}
|
|
1161
|
+
return {
|
|
1162
|
+
status_code: ErrorCodes.EXECUTION_ERROR,
|
|
1163
|
+
error_msg: `Execution failed: ${error instanceof Error ? error.message : String(error)}`
|
|
1164
|
+
};
|
|
1093
1165
|
}
|
|
1094
1166
|
async executeStream(capabilityId, body, res) {
|
|
1095
1167
|
const loggerContext = {
|
|
@@ -1201,18 +1273,23 @@ var WebhookController = class _WebhookController {
|
|
|
1201
1273
|
};
|
|
1202
1274
|
_ts_decorate5([
|
|
1203
1275
|
Get2("list"),
|
|
1276
|
+
_ts_param3(0, Res2()),
|
|
1204
1277
|
_ts_metadata3("design:type", Function),
|
|
1205
|
-
_ts_metadata3("design:paramtypes", [
|
|
1206
|
-
|
|
1278
|
+
_ts_metadata3("design:paramtypes", [
|
|
1279
|
+
typeof Response === "undefined" ? Object : Response
|
|
1280
|
+
]),
|
|
1281
|
+
_ts_metadata3("design:returntype", void 0)
|
|
1207
1282
|
], WebhookController.prototype, "list", null);
|
|
1208
1283
|
_ts_decorate5([
|
|
1209
1284
|
Post2(":capability_id"),
|
|
1210
1285
|
_ts_param3(0, Param2("capability_id")),
|
|
1211
1286
|
_ts_param3(1, Body2()),
|
|
1287
|
+
_ts_param3(2, Res2()),
|
|
1212
1288
|
_ts_metadata3("design:type", Function),
|
|
1213
1289
|
_ts_metadata3("design:paramtypes", [
|
|
1214
1290
|
String,
|
|
1215
|
-
typeof ExecuteRequestBody === "undefined" ? Object : ExecuteRequestBody
|
|
1291
|
+
typeof ExecuteRequestBody === "undefined" ? Object : ExecuteRequestBody,
|
|
1292
|
+
typeof Response === "undefined" ? Object : Response
|
|
1216
1293
|
]),
|
|
1217
1294
|
_ts_metadata3("design:returntype", Promise)
|
|
1218
1295
|
], WebhookController.prototype, "execute", null);
|
|
@@ -1328,6 +1405,7 @@ export {
|
|
|
1328
1405
|
PluginLoaderService,
|
|
1329
1406
|
PluginNotFoundError,
|
|
1330
1407
|
TemplateEngineService,
|
|
1331
|
-
WebhookController
|
|
1408
|
+
WebhookController,
|
|
1409
|
+
migrationAdaptor
|
|
1332
1410
|
};
|
|
1333
1411
|
//# sourceMappingURL=index.js.map
|