@lark-apaas/nestjs-capability 0.0.1-alpha.11 → 0.0.1-alpha.13
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 +186 -99
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +79 -5
- package/dist/index.d.ts +79 -5
- package/dist/index.js +186 -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,66 @@ 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
|
+
interface MigrationResponse<T = unknown> {
|
|
467
|
+
/** 当 code=0 时表示执行成功,当 code!=0 时表示执行失败 */
|
|
468
|
+
code: number;
|
|
469
|
+
data?: {
|
|
470
|
+
/** 执行成功时的输出结果 */
|
|
471
|
+
output?: T;
|
|
472
|
+
/** 执行结果,'success' 或 'error' */
|
|
473
|
+
outcome?: 'success' | 'error';
|
|
474
|
+
/** 执行失败时的输出结果 */
|
|
475
|
+
failureOutput?: FailureOutput;
|
|
476
|
+
};
|
|
477
|
+
/** 发生错误时的错误信息 */
|
|
478
|
+
message?: string;
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* 迁移适配器
|
|
482
|
+
*
|
|
483
|
+
* 将 CapabilityService.load().call() 的返回结果包装为老版本的 Response 结构
|
|
484
|
+
*
|
|
485
|
+
* @example
|
|
486
|
+
* // 老代码
|
|
487
|
+
* const result = await generateTaskDescription(params);
|
|
488
|
+
*
|
|
489
|
+
* // 新代码
|
|
490
|
+
* const result = await migrationAdaptor(
|
|
491
|
+
* this.capabilityService.load('ai_generate_task_description').call('run', params)
|
|
492
|
+
* );
|
|
493
|
+
*
|
|
494
|
+
* // result 结构
|
|
495
|
+
* // {
|
|
496
|
+
* // code: 0,
|
|
497
|
+
* // data: {
|
|
498
|
+
* // output: { ... }, // 能力执行结果
|
|
499
|
+
* // outcome: 'success'
|
|
500
|
+
* // }
|
|
501
|
+
* // }
|
|
502
|
+
*/
|
|
503
|
+
declare function migrationAdaptor<T = unknown>(promise: Promise<T>): Promise<MigrationResponse<T>>;
|
|
504
|
+
|
|
505
|
+
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 {
|
|
@@ -381,6 +426,14 @@ var CapabilityService = class _CapabilityService {
|
|
|
381
426
|
this.logger.log(`Capability file added: ${filePath}`);
|
|
382
427
|
try {
|
|
383
428
|
this.loadCapabilityFromFile(filePath);
|
|
429
|
+
const capabilityId = this.filePathToId.get(filePath);
|
|
430
|
+
if (capabilityId) {
|
|
431
|
+
const config = this.capabilities.get(capabilityId);
|
|
432
|
+
if (config?.pluginKey) {
|
|
433
|
+
this.pluginLoaderService.clearCache(config.pluginKey);
|
|
434
|
+
this.logger.log(`Cleared plugin cache for new capability: ${config.pluginKey}`);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
384
437
|
} catch (error) {
|
|
385
438
|
this.logger.error(`Failed to load new capability: ${filePath}`, error);
|
|
386
439
|
}
|
|
@@ -723,7 +776,7 @@ CapabilityService = _ts_decorate3([
|
|
|
723
776
|
], CapabilityService);
|
|
724
777
|
|
|
725
778
|
// src/controllers/debug.controller.ts
|
|
726
|
-
import { Controller, Post, Get, Param, Body, Res,
|
|
779
|
+
import { Controller, Post, Get, Param, Body, Res, HttpStatus, Logger as Logger3 } from "@nestjs/common";
|
|
727
780
|
function _ts_decorate4(decorators, target, key, desc) {
|
|
728
781
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
729
782
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -754,19 +807,27 @@ var DebugController = class _DebugController {
|
|
|
754
807
|
this.pluginLoaderService = pluginLoaderService;
|
|
755
808
|
this.templateEngineService = templateEngineService;
|
|
756
809
|
}
|
|
757
|
-
list() {
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
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
|
+
}
|
|
770
831
|
}
|
|
771
832
|
/**
|
|
772
833
|
* 获取 capability 配置
|
|
@@ -778,11 +839,7 @@ var DebugController = class _DebugController {
|
|
|
778
839
|
}
|
|
779
840
|
const config = this.capabilityService.getCapability(capabilityId);
|
|
780
841
|
if (!config) {
|
|
781
|
-
throw new
|
|
782
|
-
code: 1,
|
|
783
|
-
message: `Capability not found: ${capabilityId}`,
|
|
784
|
-
error: "CAPABILITY_NOT_FOUND"
|
|
785
|
-
}, HttpStatus.NOT_FOUND);
|
|
842
|
+
throw new CapabilityNotFoundError(capabilityId);
|
|
786
843
|
}
|
|
787
844
|
return config;
|
|
788
845
|
}
|
|
@@ -797,25 +854,21 @@ var DebugController = class _DebugController {
|
|
|
797
854
|
const pluginInstance = await this.pluginLoaderService.loadPlugin(pluginKey);
|
|
798
855
|
const actions = pluginInstance.listActions();
|
|
799
856
|
if (actions.length === 0) {
|
|
800
|
-
throw new
|
|
801
|
-
code: 1,
|
|
802
|
-
message: `Plugin ${pluginKey} has no actions`,
|
|
803
|
-
error: "NO_ACTIONS"
|
|
804
|
-
}, HttpStatus.BAD_REQUEST);
|
|
857
|
+
throw new Error(`Plugin ${pluginKey} has no actions`);
|
|
805
858
|
}
|
|
806
859
|
return actions[0];
|
|
807
860
|
}
|
|
808
|
-
async debug(capabilityId, body) {
|
|
861
|
+
async debug(capabilityId, body, res) {
|
|
809
862
|
const startTime = Date.now();
|
|
810
863
|
const params = body.params ?? {};
|
|
811
|
-
const config = this.getCapabilityConfig(capabilityId, body.capability);
|
|
812
|
-
const action = await this.getActionName(config.pluginKey, body.action);
|
|
813
|
-
const resolvedParams = this.templateEngineService.resolve(config.formValue, params);
|
|
814
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);
|
|
815
868
|
const result = await this.capabilityService.loadWithConfig(config).call(action, params, {
|
|
816
869
|
isDebug: true
|
|
817
870
|
});
|
|
818
|
-
|
|
871
|
+
res.status(HttpStatus.OK).json({
|
|
819
872
|
status_code: ErrorCodes.SUCCESS,
|
|
820
873
|
data: {
|
|
821
874
|
output: result,
|
|
@@ -827,31 +880,38 @@ var DebugController = class _DebugController {
|
|
|
827
880
|
action
|
|
828
881
|
}
|
|
829
882
|
}
|
|
830
|
-
};
|
|
883
|
+
});
|
|
831
884
|
} catch (error) {
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
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
|
+
};
|
|
854
910
|
}
|
|
911
|
+
return {
|
|
912
|
+
status_code: ErrorCodes.EXECUTION_ERROR,
|
|
913
|
+
error_msg: `Execution failed: ${error instanceof Error ? error.message : String(error)}`
|
|
914
|
+
};
|
|
855
915
|
}
|
|
856
916
|
async debugStream(capabilityId, body, res) {
|
|
857
917
|
const params = body.params ?? {};
|
|
@@ -969,18 +1029,23 @@ var DebugController = class _DebugController {
|
|
|
969
1029
|
};
|
|
970
1030
|
_ts_decorate4([
|
|
971
1031
|
Get("list"),
|
|
1032
|
+
_ts_param2(0, Res()),
|
|
972
1033
|
_ts_metadata2("design:type", Function),
|
|
973
|
-
_ts_metadata2("design:paramtypes", [
|
|
974
|
-
|
|
1034
|
+
_ts_metadata2("design:paramtypes", [
|
|
1035
|
+
typeof Response === "undefined" ? Object : Response
|
|
1036
|
+
]),
|
|
1037
|
+
_ts_metadata2("design:returntype", void 0)
|
|
975
1038
|
], DebugController.prototype, "list", null);
|
|
976
1039
|
_ts_decorate4([
|
|
977
1040
|
Post("debug/:capability_id"),
|
|
978
1041
|
_ts_param2(0, Param("capability_id")),
|
|
979
1042
|
_ts_param2(1, Body()),
|
|
1043
|
+
_ts_param2(2, Res()),
|
|
980
1044
|
_ts_metadata2("design:type", Function),
|
|
981
1045
|
_ts_metadata2("design:paramtypes", [
|
|
982
1046
|
String,
|
|
983
|
-
typeof DebugRequestBody === "undefined" ? Object : DebugRequestBody
|
|
1047
|
+
typeof DebugRequestBody === "undefined" ? Object : DebugRequestBody,
|
|
1048
|
+
typeof Response === "undefined" ? Object : Response
|
|
984
1049
|
]),
|
|
985
1050
|
_ts_metadata2("design:returntype", Promise)
|
|
986
1051
|
], DebugController.prototype, "debug", null);
|
|
@@ -1008,7 +1073,7 @@ DebugController = _ts_decorate4([
|
|
|
1008
1073
|
], DebugController);
|
|
1009
1074
|
|
|
1010
1075
|
// src/controllers/webhook.controller.ts
|
|
1011
|
-
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";
|
|
1012
1077
|
function _ts_decorate5(decorators, target, key, desc) {
|
|
1013
1078
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1014
1079
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -1035,53 +1100,68 @@ var WebhookController = class _WebhookController {
|
|
|
1035
1100
|
constructor(capabilityService) {
|
|
1036
1101
|
this.capabilityService = capabilityService;
|
|
1037
1102
|
}
|
|
1038
|
-
list() {
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
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
|
+
}
|
|
1051
1124
|
}
|
|
1052
|
-
async execute(capabilityId, body) {
|
|
1125
|
+
async execute(capabilityId, body, res) {
|
|
1053
1126
|
try {
|
|
1054
1127
|
const result = await this.capabilityService.load(capabilityId).call(body.action, body.params);
|
|
1055
|
-
|
|
1128
|
+
res.status(HttpStatus2.OK).json({
|
|
1056
1129
|
status_code: ErrorCodes.SUCCESS,
|
|
1057
1130
|
data: {
|
|
1058
1131
|
output: result
|
|
1059
1132
|
}
|
|
1060
|
-
};
|
|
1133
|
+
});
|
|
1061
1134
|
} catch (error) {
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
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
|
+
};
|
|
1084
1160
|
}
|
|
1161
|
+
return {
|
|
1162
|
+
status_code: ErrorCodes.EXECUTION_ERROR,
|
|
1163
|
+
error_msg: `Execution failed: ${error instanceof Error ? error.message : String(error)}`
|
|
1164
|
+
};
|
|
1085
1165
|
}
|
|
1086
1166
|
async executeStream(capabilityId, body, res) {
|
|
1087
1167
|
const loggerContext = {
|
|
@@ -1193,18 +1273,23 @@ var WebhookController = class _WebhookController {
|
|
|
1193
1273
|
};
|
|
1194
1274
|
_ts_decorate5([
|
|
1195
1275
|
Get2("list"),
|
|
1276
|
+
_ts_param3(0, Res2()),
|
|
1196
1277
|
_ts_metadata3("design:type", Function),
|
|
1197
|
-
_ts_metadata3("design:paramtypes", [
|
|
1198
|
-
|
|
1278
|
+
_ts_metadata3("design:paramtypes", [
|
|
1279
|
+
typeof Response === "undefined" ? Object : Response
|
|
1280
|
+
]),
|
|
1281
|
+
_ts_metadata3("design:returntype", void 0)
|
|
1199
1282
|
], WebhookController.prototype, "list", null);
|
|
1200
1283
|
_ts_decorate5([
|
|
1201
1284
|
Post2(":capability_id"),
|
|
1202
1285
|
_ts_param3(0, Param2("capability_id")),
|
|
1203
1286
|
_ts_param3(1, Body2()),
|
|
1287
|
+
_ts_param3(2, Res2()),
|
|
1204
1288
|
_ts_metadata3("design:type", Function),
|
|
1205
1289
|
_ts_metadata3("design:paramtypes", [
|
|
1206
1290
|
String,
|
|
1207
|
-
typeof ExecuteRequestBody === "undefined" ? Object : ExecuteRequestBody
|
|
1291
|
+
typeof ExecuteRequestBody === "undefined" ? Object : ExecuteRequestBody,
|
|
1292
|
+
typeof Response === "undefined" ? Object : Response
|
|
1208
1293
|
]),
|
|
1209
1294
|
_ts_metadata3("design:returntype", Promise)
|
|
1210
1295
|
], WebhookController.prototype, "execute", null);
|
|
@@ -1320,6 +1405,7 @@ export {
|
|
|
1320
1405
|
PluginLoaderService,
|
|
1321
1406
|
PluginNotFoundError,
|
|
1322
1407
|
TemplateEngineService,
|
|
1323
|
-
WebhookController
|
|
1408
|
+
WebhookController,
|
|
1409
|
+
migrationAdaptor
|
|
1324
1410
|
};
|
|
1325
1411
|
//# sourceMappingURL=index.js.map
|