@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.cjs
CHANGED
|
@@ -41,7 +41,8 @@ __export(index_exports, {
|
|
|
41
41
|
PluginLoaderService: () => PluginLoaderService,
|
|
42
42
|
PluginNotFoundError: () => PluginNotFoundError,
|
|
43
43
|
TemplateEngineService: () => TemplateEngineService,
|
|
44
|
-
WebhookController: () => WebhookController
|
|
44
|
+
WebhookController: () => WebhookController,
|
|
45
|
+
migrationAdaptor: () => migrationAdaptor
|
|
45
46
|
});
|
|
46
47
|
module.exports = __toCommonJS(index_exports);
|
|
47
48
|
|
|
@@ -79,9 +80,9 @@ var TemplateEngineService = class {
|
|
|
79
80
|
__name(this, "TemplateEngineService");
|
|
80
81
|
}
|
|
81
82
|
// 匹配 {{input.xxx}} 或 {{input.xxx.yyy}} 表达式
|
|
82
|
-
EXPR_REGEX = /\{\{input\.([a-zA-Z_][a-zA-Z_0-9]*(?:\.[a-zA-Z_][a-zA-Z_0-9]*)*)\}\}/g;
|
|
83
|
+
EXPR_REGEX = /\{\{\s*input\.([a-zA-Z_][a-zA-Z_0-9]*(?:\.[a-zA-Z_][a-zA-Z_0-9]*)*\s*)\}\}/g;
|
|
83
84
|
// 匹配整串单个表达式
|
|
84
|
-
WHOLE_STRING_EXPR_REGEX = /^\{\{input\.([a-zA-Z_][a-zA-Z_0-9]*(?:\.[a-zA-Z_][a-zA-Z_0-9]*)*)\}\}$/;
|
|
85
|
+
WHOLE_STRING_EXPR_REGEX = /^\{\{\s*input\.([a-zA-Z_][a-zA-Z_0-9]*(?:\.[a-zA-Z_][a-zA-Z_0-9]*)*)\s*\}\}$/;
|
|
85
86
|
resolve(template, input) {
|
|
86
87
|
if (typeof template === "string") {
|
|
87
88
|
return this.resolveString(template, input);
|
|
@@ -154,9 +155,11 @@ var PluginNotFoundError = class extends Error {
|
|
|
154
155
|
static {
|
|
155
156
|
__name(this, "PluginNotFoundError");
|
|
156
157
|
}
|
|
158
|
+
pluginKey;
|
|
157
159
|
constructor(pluginKey) {
|
|
158
160
|
super(`Plugin not found: ${pluginKey}`);
|
|
159
161
|
this.name = "PluginNotFoundError";
|
|
162
|
+
this.pluginKey = pluginKey;
|
|
160
163
|
}
|
|
161
164
|
};
|
|
162
165
|
var PluginLoadError = class extends Error {
|
|
@@ -300,6 +303,43 @@ function stringifyForLog(value, maxLength = DEFAULT_MAX_LENGTH) {
|
|
|
300
303
|
}
|
|
301
304
|
__name(stringifyForLog, "stringifyForLog");
|
|
302
305
|
|
|
306
|
+
// src/utils/migration-adaptor.ts
|
|
307
|
+
async function migrationAdaptor(promise) {
|
|
308
|
+
try {
|
|
309
|
+
const result = await promise;
|
|
310
|
+
return {
|
|
311
|
+
code: 0,
|
|
312
|
+
data: {
|
|
313
|
+
output: result,
|
|
314
|
+
outcome: "success"
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
} catch (error) {
|
|
318
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
319
|
+
const appStatusCode = error instanceof Error && "code" in error ? String(error.code) : "EXECUTION_ERROR";
|
|
320
|
+
return {
|
|
321
|
+
code: -1,
|
|
322
|
+
data: {
|
|
323
|
+
outcome: "error",
|
|
324
|
+
failureOutput: {
|
|
325
|
+
response: {
|
|
326
|
+
status: {
|
|
327
|
+
protocolStatusCode: "500",
|
|
328
|
+
appStatusCode
|
|
329
|
+
},
|
|
330
|
+
body: JSON.stringify({
|
|
331
|
+
error: errorMessage,
|
|
332
|
+
stack: error instanceof Error ? error.stack : void 0
|
|
333
|
+
})
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
},
|
|
337
|
+
message: errorMessage
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
__name(migrationAdaptor, "migrationAdaptor");
|
|
342
|
+
|
|
303
343
|
// src/services/capability.service.ts
|
|
304
344
|
function _ts_decorate3(decorators, target, key, desc) {
|
|
305
345
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -322,18 +362,24 @@ var CapabilityNotFoundError = class extends Error {
|
|
|
322
362
|
static {
|
|
323
363
|
__name(this, "CapabilityNotFoundError");
|
|
324
364
|
}
|
|
365
|
+
capabilityId;
|
|
325
366
|
constructor(capabilityId) {
|
|
326
367
|
super(`Capability not found: ${capabilityId}`);
|
|
327
368
|
this.name = "CapabilityNotFoundError";
|
|
369
|
+
this.capabilityId = capabilityId;
|
|
328
370
|
}
|
|
329
371
|
};
|
|
330
372
|
var ActionNotFoundError = class extends Error {
|
|
331
373
|
static {
|
|
332
374
|
__name(this, "ActionNotFoundError");
|
|
333
375
|
}
|
|
376
|
+
pluginKey;
|
|
377
|
+
actionName;
|
|
334
378
|
constructor(pluginKey, actionName) {
|
|
335
379
|
super(`Action '${actionName}' not found in plugin ${pluginKey}`);
|
|
336
380
|
this.name = "ActionNotFoundError";
|
|
381
|
+
this.pluginKey = pluginKey;
|
|
382
|
+
this.actionName = actionName;
|
|
337
383
|
}
|
|
338
384
|
};
|
|
339
385
|
var CapabilityService = class _CapabilityService {
|
|
@@ -810,19 +856,27 @@ var DebugController = class _DebugController {
|
|
|
810
856
|
this.pluginLoaderService = pluginLoaderService;
|
|
811
857
|
this.templateEngineService = templateEngineService;
|
|
812
858
|
}
|
|
813
|
-
list() {
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
859
|
+
list(res) {
|
|
860
|
+
try {
|
|
861
|
+
const capabilities = this.capabilityService.listCapabilities();
|
|
862
|
+
res.status(import_common4.HttpStatus.OK).json({
|
|
863
|
+
status_code: ErrorCodes.SUCCESS,
|
|
864
|
+
data: {
|
|
865
|
+
capabilities: capabilities.map((c) => ({
|
|
866
|
+
id: c.id,
|
|
867
|
+
name: c.name,
|
|
868
|
+
pluginID: c.pluginKey,
|
|
869
|
+
pluginVersion: c.pluginVersion
|
|
870
|
+
}))
|
|
871
|
+
}
|
|
872
|
+
});
|
|
873
|
+
} catch (error) {
|
|
874
|
+
this.logger.error("Failed to list capabilities", error);
|
|
875
|
+
res.status(import_common4.HttpStatus.INTERNAL_SERVER_ERROR).json({
|
|
876
|
+
status_code: ErrorCodes.EXECUTION_ERROR,
|
|
877
|
+
error_msg: `Failed to list capabilities: ${error instanceof Error ? error.message : String(error)}`
|
|
878
|
+
});
|
|
879
|
+
}
|
|
826
880
|
}
|
|
827
881
|
/**
|
|
828
882
|
* 获取 capability 配置
|
|
@@ -834,11 +888,7 @@ var DebugController = class _DebugController {
|
|
|
834
888
|
}
|
|
835
889
|
const config = this.capabilityService.getCapability(capabilityId);
|
|
836
890
|
if (!config) {
|
|
837
|
-
throw new
|
|
838
|
-
code: 1,
|
|
839
|
-
message: `Capability not found: ${capabilityId}`,
|
|
840
|
-
error: "CAPABILITY_NOT_FOUND"
|
|
841
|
-
}, import_common4.HttpStatus.NOT_FOUND);
|
|
891
|
+
throw new CapabilityNotFoundError(capabilityId);
|
|
842
892
|
}
|
|
843
893
|
return config;
|
|
844
894
|
}
|
|
@@ -853,25 +903,21 @@ var DebugController = class _DebugController {
|
|
|
853
903
|
const pluginInstance = await this.pluginLoaderService.loadPlugin(pluginKey);
|
|
854
904
|
const actions = pluginInstance.listActions();
|
|
855
905
|
if (actions.length === 0) {
|
|
856
|
-
throw new
|
|
857
|
-
code: 1,
|
|
858
|
-
message: `Plugin ${pluginKey} has no actions`,
|
|
859
|
-
error: "NO_ACTIONS"
|
|
860
|
-
}, import_common4.HttpStatus.BAD_REQUEST);
|
|
906
|
+
throw new Error(`Plugin ${pluginKey} has no actions`);
|
|
861
907
|
}
|
|
862
908
|
return actions[0];
|
|
863
909
|
}
|
|
864
|
-
async debug(capabilityId, body) {
|
|
910
|
+
async debug(capabilityId, body, res) {
|
|
865
911
|
const startTime = Date.now();
|
|
866
912
|
const params = body.params ?? {};
|
|
867
|
-
const config = this.getCapabilityConfig(capabilityId, body.capability);
|
|
868
|
-
const action = await this.getActionName(config.pluginKey, body.action);
|
|
869
|
-
const resolvedParams = this.templateEngineService.resolve(config.formValue, params);
|
|
870
913
|
try {
|
|
914
|
+
const config = this.getCapabilityConfig(capabilityId, body.capability);
|
|
915
|
+
const action = await this.getActionName(config.pluginKey, body.action);
|
|
916
|
+
const resolvedParams = this.templateEngineService.resolve(config.formValue, params);
|
|
871
917
|
const result = await this.capabilityService.loadWithConfig(config).call(action, params, {
|
|
872
918
|
isDebug: true
|
|
873
919
|
});
|
|
874
|
-
|
|
920
|
+
res.status(import_common4.HttpStatus.OK).json({
|
|
875
921
|
status_code: ErrorCodes.SUCCESS,
|
|
876
922
|
data: {
|
|
877
923
|
output: result,
|
|
@@ -883,31 +929,38 @@ var DebugController = class _DebugController {
|
|
|
883
929
|
action
|
|
884
930
|
}
|
|
885
931
|
}
|
|
886
|
-
};
|
|
932
|
+
});
|
|
887
933
|
} catch (error) {
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
934
|
+
this.logger.error("Debug execution failed", error);
|
|
935
|
+
res.status(import_common4.HttpStatus.INTERNAL_SERVER_ERROR).json(this.buildErrorResponse(error));
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
/**
|
|
939
|
+
* 构建错误响应
|
|
940
|
+
*/
|
|
941
|
+
buildErrorResponse(error) {
|
|
942
|
+
if (error instanceof CapabilityNotFoundError) {
|
|
943
|
+
return {
|
|
944
|
+
status_code: ErrorCodes.CAPABILITY_NOT_FOUND,
|
|
945
|
+
error_msg: `Capability not found: ${error.capabilityId}`
|
|
946
|
+
};
|
|
947
|
+
}
|
|
948
|
+
if (error instanceof PluginNotFoundError) {
|
|
949
|
+
return {
|
|
950
|
+
status_code: ErrorCodes.PLUGIN_NOT_FOUND,
|
|
951
|
+
error_msg: `Plugin not found, please install plugin: ${error.pluginKey}`
|
|
952
|
+
};
|
|
953
|
+
}
|
|
954
|
+
if (error instanceof ActionNotFoundError) {
|
|
955
|
+
return {
|
|
956
|
+
status_code: ErrorCodes.ACTION_NOT_FOUND,
|
|
957
|
+
error_msg: `Action '${error.actionName}' not found in plugin ${error.pluginKey}`
|
|
958
|
+
};
|
|
910
959
|
}
|
|
960
|
+
return {
|
|
961
|
+
status_code: ErrorCodes.EXECUTION_ERROR,
|
|
962
|
+
error_msg: `Execution failed: ${error instanceof Error ? error.message : String(error)}`
|
|
963
|
+
};
|
|
911
964
|
}
|
|
912
965
|
async debugStream(capabilityId, body, res) {
|
|
913
966
|
const params = body.params ?? {};
|
|
@@ -1025,18 +1078,23 @@ var DebugController = class _DebugController {
|
|
|
1025
1078
|
};
|
|
1026
1079
|
_ts_decorate4([
|
|
1027
1080
|
(0, import_common4.Get)("list"),
|
|
1081
|
+
_ts_param2(0, (0, import_common4.Res)()),
|
|
1028
1082
|
_ts_metadata2("design:type", Function),
|
|
1029
|
-
_ts_metadata2("design:paramtypes", [
|
|
1030
|
-
|
|
1083
|
+
_ts_metadata2("design:paramtypes", [
|
|
1084
|
+
typeof Response === "undefined" ? Object : Response
|
|
1085
|
+
]),
|
|
1086
|
+
_ts_metadata2("design:returntype", void 0)
|
|
1031
1087
|
], DebugController.prototype, "list", null);
|
|
1032
1088
|
_ts_decorate4([
|
|
1033
1089
|
(0, import_common4.Post)("debug/:capability_id"),
|
|
1034
1090
|
_ts_param2(0, (0, import_common4.Param)("capability_id")),
|
|
1035
1091
|
_ts_param2(1, (0, import_common4.Body)()),
|
|
1092
|
+
_ts_param2(2, (0, import_common4.Res)()),
|
|
1036
1093
|
_ts_metadata2("design:type", Function),
|
|
1037
1094
|
_ts_metadata2("design:paramtypes", [
|
|
1038
1095
|
String,
|
|
1039
|
-
typeof DebugRequestBody === "undefined" ? Object : DebugRequestBody
|
|
1096
|
+
typeof DebugRequestBody === "undefined" ? Object : DebugRequestBody,
|
|
1097
|
+
typeof Response === "undefined" ? Object : Response
|
|
1040
1098
|
]),
|
|
1041
1099
|
_ts_metadata2("design:returntype", Promise)
|
|
1042
1100
|
], DebugController.prototype, "debug", null);
|
|
@@ -1091,53 +1149,68 @@ var WebhookController = class _WebhookController {
|
|
|
1091
1149
|
constructor(capabilityService) {
|
|
1092
1150
|
this.capabilityService = capabilityService;
|
|
1093
1151
|
}
|
|
1094
|
-
list() {
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1152
|
+
list(res) {
|
|
1153
|
+
try {
|
|
1154
|
+
const capabilities = this.capabilityService.listCapabilities();
|
|
1155
|
+
res.status(import_common5.HttpStatus.OK).json({
|
|
1156
|
+
status_code: ErrorCodes.SUCCESS,
|
|
1157
|
+
data: {
|
|
1158
|
+
capabilities: capabilities.map((c) => ({
|
|
1159
|
+
id: c.id,
|
|
1160
|
+
name: c.name,
|
|
1161
|
+
pluginID: c.pluginKey,
|
|
1162
|
+
pluginVersion: c.pluginVersion
|
|
1163
|
+
}))
|
|
1164
|
+
}
|
|
1165
|
+
});
|
|
1166
|
+
} catch (error) {
|
|
1167
|
+
this.logger.error("Failed to list capabilities", error);
|
|
1168
|
+
res.status(import_common5.HttpStatus.INTERNAL_SERVER_ERROR).json({
|
|
1169
|
+
status_code: ErrorCodes.EXECUTION_ERROR,
|
|
1170
|
+
error_msg: `Failed to list capabilities: ${error instanceof Error ? error.message : String(error)}`
|
|
1171
|
+
});
|
|
1172
|
+
}
|
|
1107
1173
|
}
|
|
1108
|
-
async execute(capabilityId, body) {
|
|
1174
|
+
async execute(capabilityId, body, res) {
|
|
1109
1175
|
try {
|
|
1110
1176
|
const result = await this.capabilityService.load(capabilityId).call(body.action, body.params);
|
|
1111
|
-
|
|
1177
|
+
res.status(import_common5.HttpStatus.OK).json({
|
|
1112
1178
|
status_code: ErrorCodes.SUCCESS,
|
|
1113
1179
|
data: {
|
|
1114
1180
|
output: result
|
|
1115
1181
|
}
|
|
1116
|
-
};
|
|
1182
|
+
});
|
|
1117
1183
|
} catch (error) {
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1184
|
+
this.logger.error("Capability execution failed", error);
|
|
1185
|
+
res.status(import_common5.HttpStatus.INTERNAL_SERVER_ERROR).json(this.buildErrorResponse(error));
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
/**
|
|
1189
|
+
* 构建错误响应
|
|
1190
|
+
*/
|
|
1191
|
+
buildErrorResponse(error) {
|
|
1192
|
+
if (error instanceof CapabilityNotFoundError) {
|
|
1193
|
+
return {
|
|
1194
|
+
status_code: ErrorCodes.CAPABILITY_NOT_FOUND,
|
|
1195
|
+
error_msg: `Capability not found: ${error.capabilityId}`
|
|
1196
|
+
};
|
|
1197
|
+
}
|
|
1198
|
+
if (error instanceof PluginNotFoundError) {
|
|
1199
|
+
return {
|
|
1200
|
+
status_code: ErrorCodes.PLUGIN_NOT_FOUND,
|
|
1201
|
+
error_msg: `Plugin not found, please install plugin: ${error.pluginKey}`
|
|
1202
|
+
};
|
|
1203
|
+
}
|
|
1204
|
+
if (error instanceof ActionNotFoundError) {
|
|
1205
|
+
return {
|
|
1206
|
+
status_code: ErrorCodes.ACTION_NOT_FOUND,
|
|
1207
|
+
error_msg: `Action '${error.actionName}' not found in plugin ${error.pluginKey}`
|
|
1208
|
+
};
|
|
1140
1209
|
}
|
|
1210
|
+
return {
|
|
1211
|
+
status_code: ErrorCodes.EXECUTION_ERROR,
|
|
1212
|
+
error_msg: `Execution failed: ${error instanceof Error ? error.message : String(error)}`
|
|
1213
|
+
};
|
|
1141
1214
|
}
|
|
1142
1215
|
async executeStream(capabilityId, body, res) {
|
|
1143
1216
|
const loggerContext = {
|
|
@@ -1249,18 +1322,23 @@ var WebhookController = class _WebhookController {
|
|
|
1249
1322
|
};
|
|
1250
1323
|
_ts_decorate5([
|
|
1251
1324
|
(0, import_common5.Get)("list"),
|
|
1325
|
+
_ts_param3(0, (0, import_common5.Res)()),
|
|
1252
1326
|
_ts_metadata3("design:type", Function),
|
|
1253
|
-
_ts_metadata3("design:paramtypes", [
|
|
1254
|
-
|
|
1327
|
+
_ts_metadata3("design:paramtypes", [
|
|
1328
|
+
typeof Response === "undefined" ? Object : Response
|
|
1329
|
+
]),
|
|
1330
|
+
_ts_metadata3("design:returntype", void 0)
|
|
1255
1331
|
], WebhookController.prototype, "list", null);
|
|
1256
1332
|
_ts_decorate5([
|
|
1257
1333
|
(0, import_common5.Post)(":capability_id"),
|
|
1258
1334
|
_ts_param3(0, (0, import_common5.Param)("capability_id")),
|
|
1259
1335
|
_ts_param3(1, (0, import_common5.Body)()),
|
|
1336
|
+
_ts_param3(2, (0, import_common5.Res)()),
|
|
1260
1337
|
_ts_metadata3("design:type", Function),
|
|
1261
1338
|
_ts_metadata3("design:paramtypes", [
|
|
1262
1339
|
String,
|
|
1263
|
-
typeof ExecuteRequestBody === "undefined" ? Object : ExecuteRequestBody
|
|
1340
|
+
typeof ExecuteRequestBody === "undefined" ? Object : ExecuteRequestBody,
|
|
1341
|
+
typeof Response === "undefined" ? Object : Response
|
|
1264
1342
|
]),
|
|
1265
1343
|
_ts_metadata3("design:returntype", Promise)
|
|
1266
1344
|
], WebhookController.prototype, "execute", null);
|
|
@@ -1377,6 +1455,7 @@ CapabilityModule = _ts_decorate6([
|
|
|
1377
1455
|
PluginLoaderService,
|
|
1378
1456
|
PluginNotFoundError,
|
|
1379
1457
|
TemplateEngineService,
|
|
1380
|
-
WebhookController
|
|
1458
|
+
WebhookController,
|
|
1459
|
+
migrationAdaptor
|
|
1381
1460
|
});
|
|
1382
1461
|
//# sourceMappingURL=index.cjs.map
|