@cloudbase/cloudbase-mcp 2.3.1 → 2.4.0-alpha.0
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/cli.cjs +553 -57
- package/dist/index.cjs +553 -57
- package/dist/index.js +136 -22
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -102,6 +102,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
102
102
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
103
103
|
exports.CloudRunService = void 0;
|
|
104
104
|
exports.codeToZip = codeToZip;
|
|
105
|
+
exports.parseObjectToDiffConfigItem = parseObjectToDiffConfigItem;
|
|
105
106
|
const archiver_1 = __importDefault(__webpack_require__(99133));
|
|
106
107
|
const fs_extra_1 = __webpack_require__(21605);
|
|
107
108
|
const path_1 = __importDefault(__webpack_require__(39902));
|
|
@@ -270,7 +271,7 @@ class CloudRunService {
|
|
|
270
271
|
/**
|
|
271
272
|
* 上传部署包
|
|
272
273
|
*/
|
|
273
|
-
const zipFile = await codeToZip(targetPath, { installDependency: true });
|
|
274
|
+
const zipFile = await codeToZip(targetPath, { installDependency: (serverConfig === null || serverConfig === void 0 ? void 0 : serverConfig.InstallDependency) !== undefined ? serverConfig.InstallDependency : true });
|
|
274
275
|
await (0, utils_1.upload)({
|
|
275
276
|
url: uploadUrl,
|
|
276
277
|
file: zipFile,
|
|
@@ -286,8 +287,14 @@ class CloudRunService {
|
|
|
286
287
|
if (await this._checkFunctionExist(serverName)) {
|
|
287
288
|
// 更新
|
|
288
289
|
const serverDetail = await this.detail({ serverName });
|
|
289
|
-
const _serverConfig = Object.assign(Object.assign(Object.assign({},
|
|
290
|
+
const _serverConfig = Object.assign(Object.assign(Object.assign({}, serverConfig), { OpenAccessTypes: ['OA', 'PUBLIC', 'MINIAPP'] }), ((serverDetail === null || serverDetail === void 0 ? void 0 : serverDetail.ServerConfig.Tag) === 'function:' ? { Port: 3000 } : {}) // 函数型不能指定端口,需要固定为3000
|
|
290
291
|
);
|
|
292
|
+
if ((serverDetail === null || serverDetail === void 0 ? void 0 : serverDetail.ServerConfig.Tag) === 'function:') {
|
|
293
|
+
deployInfo.BuildPacks = {
|
|
294
|
+
LanguageVersion: '20.18',
|
|
295
|
+
RepoLanguage: 'Node.js'
|
|
296
|
+
};
|
|
297
|
+
}
|
|
291
298
|
deployInfo.ReleaseType = 'FULL';
|
|
292
299
|
return this._upsertFunction(false, {
|
|
293
300
|
name: serverName,
|
|
@@ -315,7 +322,13 @@ class CloudRunService {
|
|
|
315
322
|
RepoLanguage: 'Node.js'
|
|
316
323
|
};
|
|
317
324
|
}
|
|
318
|
-
const _serverConfig = Object.assign(Object.assign(Object.assign({ OpenAccessTypes: ['OA', 'PUBLIC'
|
|
325
|
+
const _serverConfig = Object.assign(Object.assign(Object.assign({ OpenAccessTypes: ['OA', 'PUBLIC', 'MINIAPP'],
|
|
326
|
+
// Cpu: 0,
|
|
327
|
+
// Mem: 0,
|
|
328
|
+
MinNum: 0,
|
|
329
|
+
// MaxNum: 0,
|
|
330
|
+
// PolicyDetails: [],
|
|
331
|
+
EnvParams: JSON.stringify({}), InitialDelaySeconds: 0, CustomLogs: '', HasDockerfile: true, CreateTime: '', EnvId: envConfig.EnvId, ServerName: serverName, Port: type === 'container' ? 80 : 3000, Dockerfile: 'Dockerfile', BuildDir: '' }, serverConfig), (type === 'function' ? { Port: 3000 } : {})), { Tag: type === 'container' ? '' : 'function:' });
|
|
319
332
|
return this._upsertFunction(true, {
|
|
320
333
|
name: serverName,
|
|
321
334
|
deployInfo,
|
|
@@ -349,11 +362,12 @@ class CloudRunService {
|
|
|
349
362
|
_upsertFunction(isNew, data) {
|
|
350
363
|
const { name, deployInfo, serverConfig } = data;
|
|
351
364
|
const envConfig = this.environment.lazyEnvironmentConfig;
|
|
365
|
+
const Items = parseObjectToDiffConfigItem(serverConfig);
|
|
352
366
|
return this.tcbrService.request(isNew ? 'CreateCloudRunServer' : 'UpdateCloudRunServer', {
|
|
353
367
|
EnvId: envConfig.EnvId,
|
|
354
368
|
ServerName: name,
|
|
355
369
|
DeployInfo: deployInfo,
|
|
356
|
-
|
|
370
|
+
Items,
|
|
357
371
|
});
|
|
358
372
|
}
|
|
359
373
|
}
|
|
@@ -426,6 +440,63 @@ async function codeToZip(cwd, options) {
|
|
|
426
440
|
await archive.finalize();
|
|
427
441
|
return bufferPromise;
|
|
428
442
|
}
|
|
443
|
+
/**
|
|
444
|
+
* 提交参数变化映射
|
|
445
|
+
*/
|
|
446
|
+
const SUBMIT_DIFF_MAP = {
|
|
447
|
+
Cpu: 'CpuSpecs',
|
|
448
|
+
Mem: 'MemSpecs',
|
|
449
|
+
OpenAccessTypes: 'AccessTypes',
|
|
450
|
+
EnvParams: 'EnvParam',
|
|
451
|
+
CustomLogs: 'LogPath'
|
|
452
|
+
};
|
|
453
|
+
/**
|
|
454
|
+
* 将 object 参数转为 [{key:"Port", IntValue:80}] 的格式,并且剔除空字符串
|
|
455
|
+
*/
|
|
456
|
+
function parseObjectToDiffConfigItem(data) {
|
|
457
|
+
const kvs = Object.entries(data);
|
|
458
|
+
const Items = [];
|
|
459
|
+
kvs.forEach(([k, v]) => {
|
|
460
|
+
const Key = SUBMIT_DIFF_MAP[k] || k;
|
|
461
|
+
if ([
|
|
462
|
+
'CustomLogs',
|
|
463
|
+
'EnvParams',
|
|
464
|
+
'CreateTime',
|
|
465
|
+
'Dockerfile',
|
|
466
|
+
'BuildDir',
|
|
467
|
+
'LogType',
|
|
468
|
+
'LogSetId',
|
|
469
|
+
'LogTopicId',
|
|
470
|
+
'LogParseType',
|
|
471
|
+
'Tag',
|
|
472
|
+
'InternalAccess',
|
|
473
|
+
'InternalDomain',
|
|
474
|
+
'OperationMode',
|
|
475
|
+
'SessionAffinity'
|
|
476
|
+
].includes(k)) {
|
|
477
|
+
!!v && Items.push({ Key, Value: v });
|
|
478
|
+
}
|
|
479
|
+
else if (['MinNum', 'MaxNum', 'InitialDelaySeconds', 'Port'].includes(k)) {
|
|
480
|
+
Items.push({ Key, IntValue: v });
|
|
481
|
+
}
|
|
482
|
+
else if (['HasDockerfile'].includes(k)) {
|
|
483
|
+
Items.push({ Key, BoolValue: v });
|
|
484
|
+
}
|
|
485
|
+
else if (['Cpu', 'Mem'].includes(k)) {
|
|
486
|
+
Items.push({ Key, FloatValue: v });
|
|
487
|
+
}
|
|
488
|
+
else if (['OpenAccessTypes', 'EntryPoint', 'Cmd'].includes(k)) {
|
|
489
|
+
Items.push({ Key, ArrayValue: v });
|
|
490
|
+
}
|
|
491
|
+
else if (['PolicyDetails'].includes(k)) {
|
|
492
|
+
Items.push({ Key, PolicyDetails: v });
|
|
493
|
+
}
|
|
494
|
+
else if (['TimerScale'].includes(k)) {
|
|
495
|
+
Items.push({ Key, TimerScale: v });
|
|
496
|
+
}
|
|
497
|
+
});
|
|
498
|
+
return Items;
|
|
499
|
+
}
|
|
429
500
|
|
|
430
501
|
|
|
431
502
|
/***/ }),
|
|
@@ -1679,6 +1750,7 @@ function registerEnvTools(server) {
|
|
|
1679
1750
|
Channels: ['dcloud', 'iotenable', 'tem', 'scene_module'] // Filter special channels
|
|
1680
1751
|
}
|
|
1681
1752
|
});
|
|
1753
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
1682
1754
|
// Transform response format to match original listEnvs() format
|
|
1683
1755
|
if (result && result.EnvList) {
|
|
1684
1756
|
result = { EnvList: result.EnvList };
|
|
@@ -1690,6 +1762,7 @@ function registerEnvTools(server) {
|
|
|
1690
1762
|
// Fallback to original method if format is unexpected
|
|
1691
1763
|
(0, logger_js_1.debug)('Unexpected response format, falling back to listEnvs()');
|
|
1692
1764
|
result = await cloudbaseList.env.listEnvs();
|
|
1765
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
1693
1766
|
}
|
|
1694
1767
|
}
|
|
1695
1768
|
catch (error) {
|
|
@@ -1698,10 +1771,12 @@ function registerEnvTools(server) {
|
|
|
1698
1771
|
try {
|
|
1699
1772
|
const cloudbaseList = await (0, cloudbase_manager_js_1.getCloudBaseManager)({ cloudBaseOptions, requireEnvId: true });
|
|
1700
1773
|
result = await cloudbaseList.env.listEnvs();
|
|
1774
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
1701
1775
|
}
|
|
1702
1776
|
catch (fallbackError) {
|
|
1703
1777
|
(0, logger_js_1.debug)('降级到 listEnvs() 也失败:', fallbackError);
|
|
1704
|
-
return {
|
|
1778
|
+
return {
|
|
1779
|
+
content: [{ type: "text", text: "获取环境列表时出错: " + (fallbackError instanceof Error ? fallbackError.message : String(fallbackError)) }]
|
|
1705
1780
|
};
|
|
1706
1781
|
}
|
|
1707
1782
|
}
|
|
@@ -1709,14 +1784,17 @@ function registerEnvTools(server) {
|
|
|
1709
1784
|
case "info":
|
|
1710
1785
|
const cloudbaseInfo = await getManager();
|
|
1711
1786
|
result = await cloudbaseInfo.env.getEnvInfo();
|
|
1787
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
1712
1788
|
break;
|
|
1713
1789
|
case "domains":
|
|
1714
1790
|
const cloudbaseDomains = await getManager();
|
|
1715
1791
|
result = await cloudbaseDomains.env.getEnvAuthDomains();
|
|
1792
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
1716
1793
|
break;
|
|
1717
1794
|
case "hosting":
|
|
1718
1795
|
const cloudbaseHosting = await getManager();
|
|
1719
1796
|
result = await cloudbaseHosting.hosting.getWebsiteConfig();
|
|
1797
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
1720
1798
|
break;
|
|
1721
1799
|
default:
|
|
1722
1800
|
throw new Error(`不支持的查询类型: ${action}`);
|
|
@@ -1774,9 +1852,11 @@ function registerEnvTools(server) {
|
|
|
1774
1852
|
switch (action) {
|
|
1775
1853
|
case "create":
|
|
1776
1854
|
result = await cloudbase.env.createEnvDomain(domains);
|
|
1855
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
1777
1856
|
break;
|
|
1778
1857
|
case "delete":
|
|
1779
1858
|
result = await cloudbase.env.deleteEnvDomain(domains);
|
|
1859
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
1780
1860
|
break;
|
|
1781
1861
|
default:
|
|
1782
1862
|
throw new Error(`不支持的操作类型: ${action}`);
|
|
@@ -23414,6 +23494,8 @@ exports.getEnvId = getEnvId;
|
|
|
23414
23494
|
exports.resetCloudBaseManagerCache = resetCloudBaseManagerCache;
|
|
23415
23495
|
exports.getCloudBaseManager = getCloudBaseManager;
|
|
23416
23496
|
exports.createCloudBaseManagerWithOptions = createCloudBaseManagerWithOptions;
|
|
23497
|
+
exports.extractRequestId = extractRequestId;
|
|
23498
|
+
exports.logCloudBaseResult = logCloudBaseResult;
|
|
23417
23499
|
const manager_node_1 = __importDefault(__webpack_require__(95492));
|
|
23418
23500
|
const auth_js_1 = __webpack_require__(77291);
|
|
23419
23501
|
const interactive_js_1 = __webpack_require__(3461);
|
|
@@ -23576,6 +23658,39 @@ function createCloudBaseManagerWithOptions(cloudBaseOptions) {
|
|
|
23576
23658
|
});
|
|
23577
23659
|
return manager;
|
|
23578
23660
|
}
|
|
23661
|
+
/**
|
|
23662
|
+
* Extract RequestId from result object
|
|
23663
|
+
*/
|
|
23664
|
+
function extractRequestId(result) {
|
|
23665
|
+
if (!result || typeof result !== 'object') {
|
|
23666
|
+
return undefined;
|
|
23667
|
+
}
|
|
23668
|
+
// Try common RequestId field names
|
|
23669
|
+
if ('RequestId' in result && result.RequestId) {
|
|
23670
|
+
return String(result.RequestId);
|
|
23671
|
+
}
|
|
23672
|
+
if ('requestId' in result && result.requestId) {
|
|
23673
|
+
return String(result.requestId);
|
|
23674
|
+
}
|
|
23675
|
+
if ('request_id' in result && result.request_id) {
|
|
23676
|
+
return String(result.request_id);
|
|
23677
|
+
}
|
|
23678
|
+
return undefined;
|
|
23679
|
+
}
|
|
23680
|
+
/**
|
|
23681
|
+
* Log CloudBase manager call result with RequestId
|
|
23682
|
+
*/
|
|
23683
|
+
function logCloudBaseResult(logger, result) {
|
|
23684
|
+
if (!logger) {
|
|
23685
|
+
return;
|
|
23686
|
+
}
|
|
23687
|
+
const requestId = extractRequestId(result);
|
|
23688
|
+
logger({
|
|
23689
|
+
type: 'capiResult',
|
|
23690
|
+
requestId,
|
|
23691
|
+
result,
|
|
23692
|
+
});
|
|
23693
|
+
}
|
|
23579
23694
|
|
|
23580
23695
|
|
|
23581
23696
|
/***/ }),
|
|
@@ -23696,6 +23811,7 @@ async function _promptAndSetEnvironmentId(autoSelectSingle, server) {
|
|
|
23696
23811
|
Channels: ['dcloud', 'iotenable', 'tem', 'scene_module'] // Filter special channels
|
|
23697
23812
|
}
|
|
23698
23813
|
});
|
|
23814
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server?.logger, envResult);
|
|
23699
23815
|
// Transform response format to match original listEnvs() format
|
|
23700
23816
|
if (envResult && envResult.EnvList) {
|
|
23701
23817
|
envResult = { EnvList: envResult.EnvList };
|
|
@@ -23707,6 +23823,7 @@ async function _promptAndSetEnvironmentId(autoSelectSingle, server) {
|
|
|
23707
23823
|
// Fallback to original method if format is unexpected
|
|
23708
23824
|
(0, logger_js_1.debug)('Unexpected response format, falling back to listEnvs()');
|
|
23709
23825
|
envResult = await cloudbase.env.listEnvs();
|
|
23826
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server?.logger, envResult);
|
|
23710
23827
|
}
|
|
23711
23828
|
}
|
|
23712
23829
|
catch (error) {
|
|
@@ -23714,6 +23831,7 @@ async function _promptAndSetEnvironmentId(autoSelectSingle, server) {
|
|
|
23714
23831
|
// Fallback to original method on error
|
|
23715
23832
|
try {
|
|
23716
23833
|
envResult = await cloudbase.env.listEnvs();
|
|
23834
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server?.logger, envResult);
|
|
23717
23835
|
}
|
|
23718
23836
|
catch (fallbackError) {
|
|
23719
23837
|
(0, logger_js_1.debug)('降级到 listEnvs() 也失败:', fallbackError);
|
|
@@ -33515,6 +33633,7 @@ function registerSecurityRuleTools(server) {
|
|
|
33515
33633
|
EnvId: envId,
|
|
33516
33634
|
},
|
|
33517
33635
|
});
|
|
33636
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
33518
33637
|
}
|
|
33519
33638
|
else if (resourceType === "function") {
|
|
33520
33639
|
// 查询云函数安全规则
|
|
@@ -33525,6 +33644,7 @@ function registerSecurityRuleTools(server) {
|
|
|
33525
33644
|
EnvId: envId,
|
|
33526
33645
|
},
|
|
33527
33646
|
});
|
|
33647
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
33528
33648
|
}
|
|
33529
33649
|
else if (resourceType === "storage") {
|
|
33530
33650
|
// 查询存储安全规则
|
|
@@ -33535,6 +33655,7 @@ function registerSecurityRuleTools(server) {
|
|
|
33535
33655
|
EnvId: envId,
|
|
33536
33656
|
},
|
|
33537
33657
|
});
|
|
33658
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
33538
33659
|
}
|
|
33539
33660
|
else if (resourceType === "sqlDatabase") {
|
|
33540
33661
|
// TODO: 考虑是否有支持指定其他 instance、schema 的需求
|
|
@@ -33550,6 +33671,7 @@ function registerSecurityRuleTools(server) {
|
|
|
33550
33671
|
RoleIdentityList: ["allUser"],
|
|
33551
33672
|
},
|
|
33552
33673
|
});
|
|
33674
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
33553
33675
|
}
|
|
33554
33676
|
else {
|
|
33555
33677
|
throw new Error(`不支持的资源类型: ${resourceType}`);
|
|
@@ -33626,6 +33748,7 @@ function registerSecurityRuleTools(server) {
|
|
|
33626
33748
|
Rule: rule,
|
|
33627
33749
|
},
|
|
33628
33750
|
});
|
|
33751
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
33629
33752
|
}
|
|
33630
33753
|
else {
|
|
33631
33754
|
result = await cloudbase.commonService().call({
|
|
@@ -33636,6 +33759,7 @@ function registerSecurityRuleTools(server) {
|
|
|
33636
33759
|
AclTag: aclTag,
|
|
33637
33760
|
},
|
|
33638
33761
|
});
|
|
33762
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
33639
33763
|
}
|
|
33640
33764
|
}
|
|
33641
33765
|
else if (resourceType === "function") {
|
|
@@ -33652,6 +33776,7 @@ function registerSecurityRuleTools(server) {
|
|
|
33652
33776
|
Rule: rule,
|
|
33653
33777
|
},
|
|
33654
33778
|
});
|
|
33779
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
33655
33780
|
}
|
|
33656
33781
|
else if (resourceType === "storage") {
|
|
33657
33782
|
if (aclTag === "CUSTOM") {
|
|
@@ -33666,6 +33791,7 @@ function registerSecurityRuleTools(server) {
|
|
|
33666
33791
|
Rule: rule,
|
|
33667
33792
|
},
|
|
33668
33793
|
});
|
|
33794
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
33669
33795
|
}
|
|
33670
33796
|
else {
|
|
33671
33797
|
result = await cloudbase.commonService().call({
|
|
@@ -33676,6 +33802,7 @@ function registerSecurityRuleTools(server) {
|
|
|
33676
33802
|
AclTag: aclTag,
|
|
33677
33803
|
},
|
|
33678
33804
|
});
|
|
33805
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
33679
33806
|
}
|
|
33680
33807
|
}
|
|
33681
33808
|
else if (resourceType === "sqlDatabase") {
|
|
@@ -33708,6 +33835,7 @@ function registerSecurityRuleTools(server) {
|
|
|
33708
33835
|
PolicyList: policyList,
|
|
33709
33836
|
},
|
|
33710
33837
|
});
|
|
33838
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
33711
33839
|
function getRowPermission(policy) {
|
|
33712
33840
|
return {
|
|
33713
33841
|
READONLY: [
|
|
@@ -38354,6 +38482,7 @@ function registerSQLDatabaseTools(server) {
|
|
|
38354
38482
|
},
|
|
38355
38483
|
},
|
|
38356
38484
|
});
|
|
38485
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
38357
38486
|
return {
|
|
38358
38487
|
content: [
|
|
38359
38488
|
{
|
|
@@ -38417,6 +38546,7 @@ function registerSQLDatabaseTools(server) {
|
|
|
38417
38546
|
},
|
|
38418
38547
|
},
|
|
38419
38548
|
});
|
|
38549
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
38420
38550
|
return {
|
|
38421
38551
|
content: [
|
|
38422
38552
|
{
|
|
@@ -48545,7 +48675,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
|
48545
48675
|
exports.cloudBaseRequest = cloudBaseRequest;
|
|
48546
48676
|
const auth_1 = __webpack_require__(23506);
|
|
48547
48677
|
const http_request_1 = __webpack_require__(72088);
|
|
48548
|
-
const SUPPORT_REGIONS = ['ap-shanghai', 'ap-guangzhou'];
|
|
48678
|
+
const SUPPORT_REGIONS = ['ap-shanghai', 'ap-guangzhou', 'ap-singapore'];
|
|
48549
48679
|
async function cloudBaseRequest(options) {
|
|
48550
48680
|
// const url = 'https://tcb-admin.tencentcloudapi.com/admin'
|
|
48551
48681
|
const { config, params = {}, method = 'POST', headers = {} } = options;
|
|
@@ -48559,11 +48689,11 @@ async function cloudBaseRequest(options) {
|
|
|
48559
48689
|
let internalRegionEndpoint = '';
|
|
48560
48690
|
if (finalRegion) {
|
|
48561
48691
|
if (SUPPORT_REGIONS.includes(finalRegion)) {
|
|
48562
|
-
internetRegionEndpoint = `${finalRegion}.tcb-api.tencentcloudapi.com`;
|
|
48563
|
-
internalRegionEndpoint =
|
|
48692
|
+
internetRegionEndpoint = `${envId}.${finalRegion}.tcb-api.tencentcloudapi.com`;
|
|
48693
|
+
internalRegionEndpoint = `${envId}.internal.${finalRegion}.tcb-api.tencentcloudapi.com`;
|
|
48564
48694
|
}
|
|
48565
48695
|
else {
|
|
48566
|
-
console.warn('
|
|
48696
|
+
console.warn('当前仅支持上海,广州,新加坡地域,其他地域默认解析到固定域名(上海地域)');
|
|
48567
48697
|
internetRegionEndpoint = `tcb-api.tencentcloudapi.com`;
|
|
48568
48698
|
internalRegionEndpoint = `internal.tcb-api.tencentcloudapi.com`;
|
|
48569
48699
|
}
|
|
@@ -53485,6 +53615,7 @@ const fs_1 = __importDefault(__webpack_require__(29021));
|
|
|
53485
53615
|
const os_1 = __importDefault(__webpack_require__(21820));
|
|
53486
53616
|
const path_1 = __importDefault(__webpack_require__(39902));
|
|
53487
53617
|
const winston_1 = __importDefault(__webpack_require__(555));
|
|
53618
|
+
const cloud_mode_js_1 = __webpack_require__(89684);
|
|
53488
53619
|
// Use require for winston-daily-rotate-file to avoid webpack bundling issues
|
|
53489
53620
|
// Handle both CommonJS and ES module exports
|
|
53490
53621
|
const DailyRotateFileModule = __webpack_require__(55622);
|
|
@@ -53536,16 +53667,18 @@ if (shouldUseConsole()) {
|
|
|
53536
53667
|
stderrLevels: ['error', 'warn', 'info', 'debug'], // All logs go to stderr
|
|
53537
53668
|
}));
|
|
53538
53669
|
}
|
|
53539
|
-
|
|
53540
|
-
|
|
53541
|
-
|
|
53542
|
-
|
|
53543
|
-
|
|
53544
|
-
|
|
53545
|
-
|
|
53546
|
-
|
|
53547
|
-
|
|
53548
|
-
|
|
53670
|
+
if (!(0, cloud_mode_js_1.isCloudMode)()) {
|
|
53671
|
+
// File transport with daily rotation
|
|
53672
|
+
transports.push(new DailyRotateFile({
|
|
53673
|
+
dirname: logDir,
|
|
53674
|
+
filename: 'cloudbase-mcp-%DATE%.log',
|
|
53675
|
+
datePattern: 'YYYY-MM-DD',
|
|
53676
|
+
format: winston_1.default.format.combine(winston_1.default.format.timestamp({ format: 'YYYY-MM-DDTHH:mm:ss.SSSZ' }), logFormat),
|
|
53677
|
+
maxFiles: '30d', // Keep logs for 30 days
|
|
53678
|
+
maxSize: '20m', // Max file size before rotation
|
|
53679
|
+
zippedArchive: false, // Don't compress old logs
|
|
53680
|
+
}));
|
|
53681
|
+
}
|
|
53549
53682
|
// Create winston logger instance
|
|
53550
53683
|
const logger = winston_1.default.createLogger({
|
|
53551
53684
|
level: getLogLevel(),
|
|
@@ -87084,6 +87217,7 @@ function registerFunctionTools(server) {
|
|
|
87084
87217
|
const cloudbase = await getManager();
|
|
87085
87218
|
if (action === "list") {
|
|
87086
87219
|
const result = await cloudbase.functions.getFunctionList(limit, offset);
|
|
87220
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
87087
87221
|
return {
|
|
87088
87222
|
content: [
|
|
87089
87223
|
{
|
|
@@ -87098,6 +87232,7 @@ function registerFunctionTools(server) {
|
|
|
87098
87232
|
throw new Error("获取函数详情时,name 参数是必需的");
|
|
87099
87233
|
}
|
|
87100
87234
|
const result = await cloudbase.functions.getFunctionDetail(name, codeSecret);
|
|
87235
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
87101
87236
|
return {
|
|
87102
87237
|
content: [
|
|
87103
87238
|
{
|
|
@@ -87179,6 +87314,7 @@ function registerFunctionTools(server) {
|
|
|
87179
87314
|
functionRootPath: processedRootPath,
|
|
87180
87315
|
force
|
|
87181
87316
|
});
|
|
87317
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
87182
87318
|
return {
|
|
87183
87319
|
content: [
|
|
87184
87320
|
{
|
|
@@ -87226,6 +87362,7 @@ function registerFunctionTools(server) {
|
|
|
87226
87362
|
// 使用闭包中的 cloudBaseOptions
|
|
87227
87363
|
const cloudbase = await getManager();
|
|
87228
87364
|
const result = await cloudbase.functions.updateFunctionCode(updateParams);
|
|
87365
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
87229
87366
|
return {
|
|
87230
87367
|
content: [
|
|
87231
87368
|
{
|
|
@@ -87266,6 +87403,7 @@ function registerFunctionTools(server) {
|
|
|
87266
87403
|
// 使用闭包中的 cloudBaseOptions
|
|
87267
87404
|
const cloudbase = await getManager();
|
|
87268
87405
|
const result = await cloudbase.functions.updateFunctionConfig(funcParam);
|
|
87406
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
87269
87407
|
return {
|
|
87270
87408
|
content: [
|
|
87271
87409
|
{
|
|
@@ -87294,6 +87432,7 @@ function registerFunctionTools(server) {
|
|
|
87294
87432
|
// 使用闭包中的 cloudBaseOptions
|
|
87295
87433
|
const cloudbase = await getManager();
|
|
87296
87434
|
const result = await cloudbase.functions.invokeFunction(name, params);
|
|
87435
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
87297
87436
|
return {
|
|
87298
87437
|
content: [
|
|
87299
87438
|
{
|
|
@@ -87334,6 +87473,7 @@ function registerFunctionTools(server) {
|
|
|
87334
87473
|
}
|
|
87335
87474
|
const cloudbase = await getManager();
|
|
87336
87475
|
const result = await cloudbase.functions.getFunctionLogsV2({ name, offset, limit, startTime, endTime, requestId, qualifier });
|
|
87476
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
87337
87477
|
return {
|
|
87338
87478
|
content: [
|
|
87339
87479
|
{
|
|
@@ -87371,6 +87511,7 @@ function registerFunctionTools(server) {
|
|
|
87371
87511
|
endTime,
|
|
87372
87512
|
logRequestId: requestId
|
|
87373
87513
|
});
|
|
87514
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
87374
87515
|
return {
|
|
87375
87516
|
content: [
|
|
87376
87517
|
{
|
|
@@ -87409,6 +87550,7 @@ function registerFunctionTools(server) {
|
|
|
87409
87550
|
throw new Error("创建触发器时,triggers 参数是必需的");
|
|
87410
87551
|
}
|
|
87411
87552
|
const result = await cloudbase.functions.createFunctionTriggers(name, triggers);
|
|
87553
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
87412
87554
|
return {
|
|
87413
87555
|
content: [
|
|
87414
87556
|
{
|
|
@@ -87423,6 +87565,7 @@ function registerFunctionTools(server) {
|
|
|
87423
87565
|
throw new Error("删除触发器时,triggerName 参数是必需的");
|
|
87424
87566
|
}
|
|
87425
87567
|
const result = await cloudbase.functions.deleteFunctionTrigger(name, triggerName);
|
|
87568
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
87426
87569
|
return {
|
|
87427
87570
|
content: [
|
|
87428
87571
|
{
|
|
@@ -90156,19 +90299,20 @@ class EnvService {
|
|
|
90156
90299
|
});
|
|
90157
90300
|
}
|
|
90158
90301
|
getCos() {
|
|
90302
|
+
const internalEndpoint = this.environment.cloudBaseContext.isInternalEndpoint();
|
|
90159
90303
|
const { secretId, secretKey, token } = this.environment.getAuthConfig();
|
|
90160
90304
|
const cosConfig = {
|
|
90161
90305
|
SecretId: secretId,
|
|
90162
90306
|
SecretKey: secretKey,
|
|
90163
90307
|
SecurityToken: token,
|
|
90164
|
-
Domain:
|
|
90308
|
+
Domain: internalEndpoint ? "{Bucket}.cos-internal.{Region}.tencentcos.cn" /* COS_ENDPOINT.INTERNAL */ : "{Bucket}.cos.{Region}.tencentcos.cn" /* COS_ENDPOINT.PUBLIC */,
|
|
90165
90309
|
};
|
|
90166
90310
|
if (constant_1.COS_SDK_PROTOCOL) {
|
|
90167
90311
|
cosConfig.Protocol = (constant_1.COS_SDK_PROTOCOL.endsWith(':')
|
|
90168
90312
|
? constant_1.COS_SDK_PROTOCOL.toLowerCase()
|
|
90169
90313
|
: constant_1.COS_SDK_PROTOCOL.toLowerCase() + ':');
|
|
90170
90314
|
}
|
|
90171
|
-
if (
|
|
90315
|
+
if (internalEndpoint) {
|
|
90172
90316
|
cosConfig.Protocol = 'http:';
|
|
90173
90317
|
}
|
|
90174
90318
|
return new cos_nodejs_sdk_v5_1.default(cosConfig);
|
|
@@ -100395,7 +100539,7 @@ function parseEnabledPlugins() {
|
|
|
100395
100539
|
* await server.connect(transport);
|
|
100396
100540
|
*/
|
|
100397
100541
|
async function createCloudBaseMcpServer(options) {
|
|
100398
|
-
const { name = "cloudbase-mcp", version = "1.0.0", enableTelemetry = true, cloudBaseOptions, cloudMode = false, ide, } = options ?? {};
|
|
100542
|
+
const { name = "cloudbase-mcp", version = "1.0.0", enableTelemetry = true, cloudBaseOptions, cloudMode = false, ide, logger, } = options ?? {};
|
|
100399
100543
|
// Enable cloud mode if specified
|
|
100400
100544
|
if (cloudMode) {
|
|
100401
100545
|
(0, cloud_mode_js_1.enableCloudMode)();
|
|
@@ -100425,6 +100569,10 @@ async function createCloudBaseMcpServer(options) {
|
|
|
100425
100569
|
if (ide) {
|
|
100426
100570
|
server.ide = ide;
|
|
100427
100571
|
}
|
|
100572
|
+
// Store logger in server instance for tools to access
|
|
100573
|
+
if (logger) {
|
|
100574
|
+
server.logger = logger;
|
|
100575
|
+
}
|
|
100428
100576
|
// Enable telemetry if requested
|
|
100429
100577
|
if (enableTelemetry) {
|
|
100430
100578
|
(0, tool_wrapper_js_1.wrapServerWithTelemetry)(server);
|
|
@@ -106898,6 +107046,7 @@ function registerDataModelTools(server) {
|
|
|
106898
107046
|
Name: name,
|
|
106899
107047
|
},
|
|
106900
107048
|
});
|
|
107049
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
106901
107050
|
// 只保留基础字段,过滤掉冗余信息,并简化Schema
|
|
106902
107051
|
let simplifiedSchema = null;
|
|
106903
107052
|
// 解析并简化Schema
|
|
@@ -107036,6 +107185,7 @@ function registerDataModelTools(server) {
|
|
|
107036
107185
|
Action: "DescribeDataSourceList",
|
|
107037
107186
|
Param: listParams,
|
|
107038
107187
|
});
|
|
107188
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
107039
107189
|
const models = result.Data?.Rows || [];
|
|
107040
107190
|
// 只保留基础字段,list操作不返回Schema
|
|
107041
107191
|
const simplifiedModels = models.map((model) => ({
|
|
@@ -107072,6 +107222,7 @@ function registerDataModelTools(server) {
|
|
|
107072
107222
|
Name: name,
|
|
107073
107223
|
},
|
|
107074
107224
|
});
|
|
107225
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
107075
107226
|
if (!result.Data) {
|
|
107076
107227
|
throw new Error(`数据模型 ${name} 不存在`);
|
|
107077
107228
|
}
|
|
@@ -107276,6 +107427,7 @@ classDiagram
|
|
|
107276
107427
|
EnvId: currentEnvId,
|
|
107277
107428
|
},
|
|
107278
107429
|
});
|
|
107430
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
107279
107431
|
const taskId = result.Data?.TaskId;
|
|
107280
107432
|
if (!taskId) {
|
|
107281
107433
|
return {
|
|
@@ -107306,6 +107458,7 @@ classDiagram
|
|
|
107306
107458
|
TaskId: taskId,
|
|
107307
107459
|
},
|
|
107308
107460
|
});
|
|
107461
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, statusResult);
|
|
107309
107462
|
status = statusResult.Data?.Status || "init";
|
|
107310
107463
|
}
|
|
107311
107464
|
// 返回最终结果
|
|
@@ -115036,8 +115189,10 @@ function registerHostingTools(server) {
|
|
|
115036
115189
|
files,
|
|
115037
115190
|
ignore
|
|
115038
115191
|
});
|
|
115192
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
115039
115193
|
// 获取环境信息
|
|
115040
115194
|
const envInfo = await cloudbase.env.getEnvInfo();
|
|
115195
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, envInfo);
|
|
115041
115196
|
const staticDomain = envInfo.EnvInfo?.StaticStorages?.[0]?.StaticDomain;
|
|
115042
115197
|
const accessUrl = staticDomain ? `https://${staticDomain}/${cloudPath || ''}` : "";
|
|
115043
115198
|
// Send deployment notification to CodeBuddy IDE
|
|
@@ -115111,6 +115266,7 @@ function registerHostingTools(server) {
|
|
|
115111
115266
|
cloudPath,
|
|
115112
115267
|
isDir
|
|
115113
115268
|
});
|
|
115269
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
115114
115270
|
return {
|
|
115115
115271
|
content: [
|
|
115116
115272
|
{
|
|
@@ -115141,6 +115297,7 @@ function registerHostingTools(server) {
|
|
|
115141
115297
|
marker,
|
|
115142
115298
|
maxKeys
|
|
115143
115299
|
});
|
|
115300
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
115144
115301
|
return {
|
|
115145
115302
|
content: [
|
|
115146
115303
|
{
|
|
@@ -115206,6 +115363,7 @@ function registerHostingTools(server) {
|
|
|
115206
115363
|
domain,
|
|
115207
115364
|
certId
|
|
115208
115365
|
});
|
|
115366
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
115209
115367
|
break;
|
|
115210
115368
|
case "delete":
|
|
115211
115369
|
if (!domain) {
|
|
@@ -115214,6 +115372,7 @@ function registerHostingTools(server) {
|
|
|
115214
115372
|
result = await cloudbase.hosting.deleteHostingDomain({
|
|
115215
115373
|
domain
|
|
115216
115374
|
});
|
|
115375
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
115217
115376
|
break;
|
|
115218
115377
|
case "check":
|
|
115219
115378
|
if (!domains || domains.length === 0) {
|
|
@@ -115222,6 +115381,7 @@ function registerHostingTools(server) {
|
|
|
115222
115381
|
result = await cloudbase.hosting.tcbCheckResource({
|
|
115223
115382
|
domains
|
|
115224
115383
|
});
|
|
115384
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
115225
115385
|
break;
|
|
115226
115386
|
case "modify":
|
|
115227
115387
|
if (!domain || domainId === undefined || !domainConfig) {
|
|
@@ -115232,6 +115392,7 @@ function registerHostingTools(server) {
|
|
|
115232
115392
|
domainId,
|
|
115233
115393
|
domainConfig
|
|
115234
115394
|
});
|
|
115395
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
115235
115396
|
break;
|
|
115236
115397
|
default:
|
|
115237
115398
|
throw new Error(`不支持的操作类型: ${action}`);
|
|
@@ -130366,6 +130527,7 @@ function registerInviteCodeTools(server) {
|
|
|
130366
130527
|
Action: 'ActivateInviteCode',
|
|
130367
130528
|
Param: { InviteCode, EnvId }
|
|
130368
130529
|
});
|
|
130530
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
130369
130531
|
return {
|
|
130370
130532
|
content: [
|
|
130371
130533
|
{
|
|
@@ -135012,7 +135174,7 @@ class TelemetryReporter {
|
|
|
135012
135174
|
const nodeVersion = process.version; // Node.js版本
|
|
135013
135175
|
const arch = os_1.default.arch(); // 系统架构
|
|
135014
135176
|
// 从构建时注入的版本号获取MCP版本信息
|
|
135015
|
-
const mcpVersion = process.env.npm_package_version || "2.
|
|
135177
|
+
const mcpVersion = process.env.npm_package_version || "2.4.0-alpha.0" || 0;
|
|
135016
135178
|
return {
|
|
135017
135179
|
userAgent: `${osType} ${osRelease} ${arch} ${nodeVersion} CloudBase-MCP/${mcpVersion}`,
|
|
135018
135180
|
deviceId: this.deviceId,
|
|
@@ -179610,6 +179772,7 @@ exports.sleep = sleep;
|
|
|
179610
179772
|
exports.upperCaseStringFisrt = upperCaseStringFisrt;
|
|
179611
179773
|
exports.upperCaseObjKey = upperCaseObjKey;
|
|
179612
179774
|
exports.fetchTemplates = fetchTemplates;
|
|
179775
|
+
exports.successLog = successLog;
|
|
179613
179776
|
const archiver_1 = __importDefault(__webpack_require__(99133));
|
|
179614
179777
|
const crypto_1 = __importDefault(__webpack_require__(55511));
|
|
179615
179778
|
const fs_extra_1 = __importDefault(__webpack_require__(21605));
|
|
@@ -179888,6 +180051,10 @@ const getCompleteTimeRange = (timeRange) => {
|
|
|
179888
180051
|
};
|
|
179889
180052
|
};
|
|
179890
180053
|
exports.getCompleteTimeRange = getCompleteTimeRange;
|
|
180054
|
+
function successLog(msg) {
|
|
180055
|
+
// 空格,兼容中文字符编码长度问题
|
|
180056
|
+
console.log(`${msg}`);
|
|
180057
|
+
}
|
|
179891
180058
|
|
|
179892
180059
|
|
|
179893
180060
|
/***/ }),
|
|
@@ -191310,20 +191477,25 @@ function callSuccessCallback(callback, result) {
|
|
|
191310
191477
|
/***/ }),
|
|
191311
191478
|
|
|
191312
191479
|
/***/ 65607:
|
|
191313
|
-
/***/ ((__unused_webpack_module, exports) => {
|
|
191480
|
+
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
191314
191481
|
|
|
191315
191482
|
"use strict";
|
|
191316
191483
|
|
|
191317
191484
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
191318
191485
|
exports.CloudBaseContext = void 0;
|
|
191486
|
+
const constant_1 = __webpack_require__(40762);
|
|
191319
191487
|
class CloudBaseContext {
|
|
191320
|
-
constructor({ secretId = '', secretKey = '', token = '', proxy = '', region = '', envType = '' }) {
|
|
191488
|
+
constructor({ secretId = '', secretKey = '', token = '', proxy = '', region = '', envType = '', useInternalEndpoint = undefined }) {
|
|
191321
191489
|
this.secretId = secretId;
|
|
191322
191490
|
this.secretKey = secretKey;
|
|
191323
191491
|
this.token = token;
|
|
191324
191492
|
this.proxy = proxy;
|
|
191325
191493
|
this.region = region;
|
|
191326
191494
|
this.envType = envType;
|
|
191495
|
+
this.useInternalEndpoint = useInternalEndpoint;
|
|
191496
|
+
}
|
|
191497
|
+
isInternalEndpoint() {
|
|
191498
|
+
return this.useInternalEndpoint !== undefined ? this.useInternalEndpoint : constant_1.USE_INTERNAL_ENDPOINT;
|
|
191327
191499
|
}
|
|
191328
191500
|
}
|
|
191329
191501
|
exports.CloudBaseContext = CloudBaseContext;
|
|
@@ -200805,11 +200977,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
200805
200977
|
};
|
|
200806
200978
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
200807
200979
|
exports.wrapServerWithTelemetry = wrapServerWithTelemetry;
|
|
200808
|
-
const
|
|
200809
|
-
const logger_js_1 = __webpack_require__(13039);
|
|
200980
|
+
const os_1 = __importDefault(__webpack_require__(21820));
|
|
200810
200981
|
const cloudbase_manager_js_1 = __webpack_require__(3431);
|
|
200811
200982
|
const cloud_mode_js_1 = __webpack_require__(89684);
|
|
200812
|
-
const
|
|
200983
|
+
const logger_js_1 = __webpack_require__(13039);
|
|
200984
|
+
const telemetry_js_1 = __webpack_require__(45880);
|
|
200813
200985
|
/**
|
|
200814
200986
|
* 生成 GitHub Issue 创建链接
|
|
200815
200987
|
* @param toolName 工具名称
|
|
@@ -200850,7 +201022,7 @@ ${envIdSection}
|
|
|
200850
201022
|
## 环境信息
|
|
200851
201023
|
- 操作系统: ${os_1.default.type()} ${os_1.default.release()}
|
|
200852
201024
|
- Node.js版本: ${process.version}
|
|
200853
|
-
- MCP 版本:${process.env.npm_package_version || "2.
|
|
201025
|
+
- MCP 版本:${process.env.npm_package_version || "2.4.0-alpha.0" || 0}
|
|
200854
201026
|
- 系统架构: ${os_1.default.arch()}
|
|
200855
201027
|
- 时间: ${new Date().toISOString()}
|
|
200856
201028
|
- 请求ID: ${requestId}
|
|
@@ -200888,10 +201060,13 @@ function createWrappedHandler(name, handler, server) {
|
|
|
200888
201060
|
let requestId;
|
|
200889
201061
|
try {
|
|
200890
201062
|
(0, logger_js_1.debug)(`开始执行工具: ${name}`, { args: sanitizeArgs(args) });
|
|
201063
|
+
server.logger?.({ type: 'beforeToolCall', toolName: name, args: sanitizeArgs(args) });
|
|
200891
201064
|
// 执行原始处理函数
|
|
200892
201065
|
const result = await handler(args);
|
|
200893
201066
|
success = true;
|
|
200894
|
-
|
|
201067
|
+
const duration = Date.now() - startTime;
|
|
201068
|
+
(0, logger_js_1.debug)(`工具执行成功: ${name}`, { duration });
|
|
201069
|
+
server.logger?.({ type: 'afterToolCall', toolName: name, args: sanitizeArgs(args), result: result, duration });
|
|
200895
201070
|
return result;
|
|
200896
201071
|
}
|
|
200897
201072
|
catch (error) {
|
|
@@ -200902,6 +201077,7 @@ function createWrappedHandler(name, handler, server) {
|
|
|
200902
201077
|
error: errorMessage,
|
|
200903
201078
|
duration: Date.now() - startTime
|
|
200904
201079
|
});
|
|
201080
|
+
server.logger?.({ type: 'errorToolCall', toolName: name, args: sanitizeArgs(args), message: errorMessage, duration: Date.now() - startTime });
|
|
200905
201081
|
// 生成 GitHub Issue 创建链接
|
|
200906
201082
|
const issueLink = await generateGitHubIssueLink(name, errorMessage, args, server.cloudBaseOptions, {
|
|
200907
201083
|
requestId: (typeof error === 'object' && error && 'requestId' in error) ? error.requestId : '',
|
|
@@ -203742,6 +203918,7 @@ class StorageService {
|
|
|
203742
203918
|
* 获取 COS 配置
|
|
203743
203919
|
*/
|
|
203744
203920
|
getCos(parallel = 20) {
|
|
203921
|
+
const internalEndpoint = this.environment.cloudBaseContext.isInternalEndpoint();
|
|
203745
203922
|
const { secretId, secretKey, token, proxy } = this.environment.getAuthConfig();
|
|
203746
203923
|
const cosProxy = process.env.TCB_COS_PROXY;
|
|
203747
203924
|
const cosConfig = {
|
|
@@ -203750,14 +203927,14 @@ class StorageService {
|
|
|
203750
203927
|
SecretKey: secretKey,
|
|
203751
203928
|
Proxy: cosProxy || proxy,
|
|
203752
203929
|
SecurityToken: token,
|
|
203753
|
-
Domain:
|
|
203930
|
+
Domain: internalEndpoint ? "{Bucket}.cos-internal.{Region}.tencentcos.cn" /* COS_ENDPOINT.INTERNAL */ : "{Bucket}.cos.{Region}.tencentcos.cn" /* COS_ENDPOINT.PUBLIC */,
|
|
203754
203931
|
};
|
|
203755
203932
|
if (constant_1.COS_SDK_PROTOCOL) {
|
|
203756
203933
|
cosConfig.Protocol = (constant_1.COS_SDK_PROTOCOL.endsWith(':')
|
|
203757
203934
|
? constant_1.COS_SDK_PROTOCOL.toLowerCase()
|
|
203758
203935
|
: constant_1.COS_SDK_PROTOCOL.toLowerCase() + ':');
|
|
203759
203936
|
}
|
|
203760
|
-
if (
|
|
203937
|
+
if (internalEndpoint) {
|
|
203761
203938
|
cosConfig.Protocol = 'http:';
|
|
203762
203939
|
}
|
|
203763
203940
|
// COSSDK 默认开启 KeepAlive,这里提供关闭的方式
|
|
@@ -208806,6 +208983,7 @@ async function getDatabaseInstanceId(getManager) {
|
|
|
208806
208983
|
function registerDatabaseTools(server) {
|
|
208807
208984
|
// 获取 cloudBaseOptions,如果没有则为 undefined
|
|
208808
208985
|
const cloudBaseOptions = server.cloudBaseOptions;
|
|
208986
|
+
const logger = server.logger;
|
|
208809
208987
|
// 创建闭包函数来获取 CloudBase Manager
|
|
208810
208988
|
const getManager = () => (0, cloudbase_manager_js_1.getCloudBaseManager)({ cloudBaseOptions });
|
|
208811
208989
|
// readNoSqlDatabaseStructure
|
|
@@ -208853,6 +209031,7 @@ checkIndex: 检查索引是否存在`),
|
|
|
208853
209031
|
MgoOffset: offset,
|
|
208854
209032
|
MgoLimit: limit,
|
|
208855
209033
|
});
|
|
209034
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
208856
209035
|
return {
|
|
208857
209036
|
content: [
|
|
208858
209037
|
{
|
|
@@ -208873,6 +209052,7 @@ checkIndex: 检查索引是否存在`),
|
|
|
208873
209052
|
throw new Error("检查集合时必须提供 collectionName");
|
|
208874
209053
|
}
|
|
208875
209054
|
const result = await cloudbase.database.checkCollectionExists(collectionName);
|
|
209055
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
208876
209056
|
return {
|
|
208877
209057
|
content: [
|
|
208878
209058
|
{
|
|
@@ -208894,6 +209074,7 @@ checkIndex: 检查索引是否存在`),
|
|
|
208894
209074
|
throw new Error("查看集合详情时必须提供 collectionName");
|
|
208895
209075
|
}
|
|
208896
209076
|
const result = await cloudbase.database.describeCollection(collectionName);
|
|
209077
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
208897
209078
|
return {
|
|
208898
209079
|
content: [
|
|
208899
209080
|
{
|
|
@@ -208914,6 +209095,7 @@ checkIndex: 检查索引是否存在`),
|
|
|
208914
209095
|
throw new Error("获取索引列表时必须提供 collectionName");
|
|
208915
209096
|
}
|
|
208916
209097
|
const result = await cloudbase.database.describeCollection(collectionName);
|
|
209098
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
208917
209099
|
return {
|
|
208918
209100
|
content: [
|
|
208919
209101
|
{
|
|
@@ -208934,6 +209116,7 @@ checkIndex: 检查索引是否存在`),
|
|
|
208934
209116
|
throw new Error("检查索引时必须提供 collectionName 和 indexName");
|
|
208935
209117
|
}
|
|
208936
209118
|
const result = await cloudbase.database.checkIndexExists(collectionName, indexName);
|
|
209119
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
208937
209120
|
return {
|
|
208938
209121
|
content: [
|
|
208939
209122
|
{
|
|
@@ -208994,6 +209177,7 @@ updateCollection: 更新集合`),
|
|
|
208994
209177
|
const cloudbase = await getManager();
|
|
208995
209178
|
if (action === "createCollection") {
|
|
208996
209179
|
const result = await cloudbase.database.createCollection(collectionName);
|
|
209180
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
208997
209181
|
return {
|
|
208998
209182
|
content: [
|
|
208999
209183
|
{
|
|
@@ -209013,6 +209197,7 @@ updateCollection: 更新集合`),
|
|
|
209013
209197
|
throw new Error("更新集合时必须提供 options");
|
|
209014
209198
|
}
|
|
209015
209199
|
const result = await cloudbase.database.updateCollection(collectionName, updateOptions);
|
|
209200
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
209016
209201
|
return {
|
|
209017
209202
|
content: [
|
|
209018
209203
|
{
|
|
@@ -209089,6 +209274,7 @@ updateCollection: 更新集合`),
|
|
|
209089
209274
|
Tag: instanceId,
|
|
209090
209275
|
},
|
|
209091
209276
|
});
|
|
209277
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
209092
209278
|
return {
|
|
209093
209279
|
content: [
|
|
209094
209280
|
{
|
|
@@ -209166,6 +209352,7 @@ deleteCollection: 删除数据`),
|
|
|
209166
209352
|
collectionName,
|
|
209167
209353
|
documents,
|
|
209168
209354
|
getManager,
|
|
209355
|
+
logger,
|
|
209169
209356
|
});
|
|
209170
209357
|
return {
|
|
209171
209358
|
content: [
|
|
@@ -209190,6 +209377,7 @@ deleteCollection: 删除数据`),
|
|
|
209190
209377
|
isMulti,
|
|
209191
209378
|
upsert,
|
|
209192
209379
|
getManager,
|
|
209380
|
+
logger,
|
|
209193
209381
|
});
|
|
209194
209382
|
return {
|
|
209195
209383
|
content: [
|
|
@@ -209209,6 +209397,7 @@ deleteCollection: 删除数据`),
|
|
|
209209
209397
|
query,
|
|
209210
209398
|
isMulti,
|
|
209211
209399
|
getManager,
|
|
209400
|
+
logger,
|
|
209212
209401
|
});
|
|
209213
209402
|
return {
|
|
209214
209403
|
content: [
|
|
@@ -209222,7 +209411,7 @@ deleteCollection: 删除数据`),
|
|
|
209222
209411
|
throw new Error(`不支持的操作类型: ${action}`);
|
|
209223
209412
|
});
|
|
209224
209413
|
}
|
|
209225
|
-
async function insertDocuments({ collectionName, documents, getManager, }) {
|
|
209414
|
+
async function insertDocuments({ collectionName, documents, getManager, logger, }) {
|
|
209226
209415
|
try {
|
|
209227
209416
|
const cloudbase = await getManager();
|
|
209228
209417
|
const instanceId = await getDatabaseInstanceId(getManager);
|
|
@@ -209236,6 +209425,7 @@ async function insertDocuments({ collectionName, documents, getManager, }) {
|
|
|
209236
209425
|
Tag: instanceId,
|
|
209237
209426
|
},
|
|
209238
209427
|
});
|
|
209428
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(logger, result);
|
|
209239
209429
|
return JSON.stringify({
|
|
209240
209430
|
success: true,
|
|
209241
209431
|
requestId: result.RequestId,
|
|
@@ -209251,7 +209441,7 @@ async function insertDocuments({ collectionName, documents, getManager, }) {
|
|
|
209251
209441
|
}, null, 2);
|
|
209252
209442
|
}
|
|
209253
209443
|
}
|
|
209254
|
-
async function updateDocuments({ collectionName, query, update, isMulti, upsert, getManager, }) {
|
|
209444
|
+
async function updateDocuments({ collectionName, query, update, isMulti, upsert, getManager, logger, }) {
|
|
209255
209445
|
try {
|
|
209256
209446
|
const cloudbase = await getManager();
|
|
209257
209447
|
const instanceId = await getDatabaseInstanceId(getManager);
|
|
@@ -209267,6 +209457,7 @@ async function updateDocuments({ collectionName, query, update, isMulti, upsert,
|
|
|
209267
209457
|
Tag: instanceId,
|
|
209268
209458
|
},
|
|
209269
209459
|
});
|
|
209460
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(logger, result);
|
|
209270
209461
|
return JSON.stringify({
|
|
209271
209462
|
success: true,
|
|
209272
209463
|
requestId: result.RequestId,
|
|
@@ -209284,7 +209475,7 @@ async function updateDocuments({ collectionName, query, update, isMulti, upsert,
|
|
|
209284
209475
|
}, null, 2);
|
|
209285
209476
|
}
|
|
209286
209477
|
}
|
|
209287
|
-
async function deleteDocuments({ collectionName, query, isMulti, getManager, }) {
|
|
209478
|
+
async function deleteDocuments({ collectionName, query, isMulti, getManager, logger, }) {
|
|
209288
209479
|
try {
|
|
209289
209480
|
const cloudbase = await getManager();
|
|
209290
209481
|
const instanceId = await getDatabaseInstanceId(getManager);
|
|
@@ -209298,6 +209489,7 @@ async function deleteDocuments({ collectionName, query, isMulti, getManager, })
|
|
|
209298
209489
|
Tag: instanceId,
|
|
209299
209490
|
},
|
|
209300
209491
|
});
|
|
209492
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(logger, result);
|
|
209301
209493
|
return JSON.stringify({
|
|
209302
209494
|
success: true,
|
|
209303
209495
|
requestId: result.RequestId,
|
|
@@ -215191,6 +215383,7 @@ const IDE_TYPES = [
|
|
|
215191
215383
|
"qoder", // Qoder AI编辑器
|
|
215192
215384
|
"antigravity", // Google Antigravity AI编辑器
|
|
215193
215385
|
"vscode", // Visual Studio Code
|
|
215386
|
+
"kiro", // Kiro AI编辑器
|
|
215194
215387
|
];
|
|
215195
215388
|
// IDE到文件的映射关系
|
|
215196
215389
|
// 注意:以 "/" 结尾的路径表示目录,会包含该目录下的所有文件
|
|
@@ -215224,6 +215417,7 @@ const IDE_FILE_MAPPINGS = {
|
|
|
215224
215417
|
qoder: [".qoder/rules/"],
|
|
215225
215418
|
antigravity: [".agent/rules/"],
|
|
215226
215419
|
vscode: [".vscode/mcp.json", ".vscode/settings.json"],
|
|
215420
|
+
kiro: [".kiro/settings/mcp.json", ".kiro/steering/"],
|
|
215227
215421
|
};
|
|
215228
215422
|
// 所有IDE配置文件的完整列表 - 通过IDE_FILE_MAPPINGS计算得出
|
|
215229
215423
|
const ALL_IDE_FILES = Array.from(new Set(Object.values(IDE_FILE_MAPPINGS).flat()));
|
|
@@ -215250,6 +215444,7 @@ const IDE_DESCRIPTIONS = {
|
|
|
215250
215444
|
qoder: "Qoder AI编辑器",
|
|
215251
215445
|
antigravity: "Google Antigravity AI编辑器",
|
|
215252
215446
|
vscode: "Visual Studio Code",
|
|
215447
|
+
kiro: "Kiro AI编辑器",
|
|
215253
215448
|
};
|
|
215254
215449
|
// INTEGRATION_IDE 环境变量值到 IDE 类型的映射
|
|
215255
215450
|
const INTEGRATION_IDE_MAPPING = {
|
|
@@ -215273,6 +215468,7 @@ const INTEGRATION_IDE_MAPPING = {
|
|
|
215273
215468
|
Qoder: "qoder",
|
|
215274
215469
|
Antigravity: "antigravity",
|
|
215275
215470
|
VSCode: "vscode",
|
|
215471
|
+
Kiro: "kiro",
|
|
215276
215472
|
};
|
|
215277
215473
|
// 根据 INTEGRATION_IDE 环境变量获取默认 IDE 类型
|
|
215278
215474
|
function getDefaultIDEFromEnv() {
|
|
@@ -215495,7 +215691,7 @@ function registerSetupTools(server) {
|
|
|
215495
215691
|
title: "下载项目模板",
|
|
215496
215692
|
description: `自动下载并部署CloudBase项目模板。⚠️ **MANDATORY FOR NEW PROJECTS** ⚠️
|
|
215497
215693
|
|
|
215498
|
-
**CRITICAL**: This tool MUST be called FIRST when starting a new project.\n\n支持的模板:\n- react: React + CloudBase 全栈应用模板\n- vue: Vue + CloudBase 全栈应用模板\n- miniprogram: 微信小程序 + 云开发模板 \n- uniapp: UniApp + CloudBase 跨端应用模板\n- rules: 只包含AI编辑器配置文件(包含Cursor、WindSurf、CodeBuddy等所有主流编辑器配置),适合在已有项目中补充AI编辑器配置\n\n支持的IDE类型:\n- all: 下载所有IDE配置(默认)\n- cursor: Cursor AI编辑器\n- windsurf: WindSurf AI编辑器\n- codebuddy: CodeBuddy AI编辑器\n- claude-code: Claude Code AI编辑器\n- cline: Cline AI编辑器\n- gemini-cli: Gemini CLI\n- opencode: OpenCode AI编辑器\n- qwen-code: 通义灵码\n- baidu-comate: 百度Comate\n- openai-codex-cli: OpenAI Codex CLI\n- augment-code: Augment Code\n- github-copilot: GitHub Copilot\n- roocode: RooCode AI编辑器\n- tongyi-lingma: 通义灵码\n- trae: Trae AI编辑器\n- qoder: Qoder AI编辑器\n- antigravity: Google Antigravity AI编辑器\n- vscode: Visual Studio Code\n\n特别说明:\n- rules 模板会自动包含当前 mcp 版本号信息(版本号:${ true ? "2.
|
|
215694
|
+
**CRITICAL**: This tool MUST be called FIRST when starting a new project.\n\n支持的模板:\n- react: React + CloudBase 全栈应用模板\n- vue: Vue + CloudBase 全栈应用模板\n- miniprogram: 微信小程序 + 云开发模板 \n- uniapp: UniApp + CloudBase 跨端应用模板\n- rules: 只包含AI编辑器配置文件(包含Cursor、WindSurf、CodeBuddy等所有主流编辑器配置),适合在已有项目中补充AI编辑器配置\n\n支持的IDE类型:\n- all: 下载所有IDE配置(默认)\n- cursor: Cursor AI编辑器\n- windsurf: WindSurf AI编辑器\n- codebuddy: CodeBuddy AI编辑器\n- claude-code: Claude Code AI编辑器\n- cline: Cline AI编辑器\n- gemini-cli: Gemini CLI\n- opencode: OpenCode AI编辑器\n- qwen-code: 通义灵码\n- baidu-comate: 百度Comate\n- openai-codex-cli: OpenAI Codex CLI\n- augment-code: Augment Code\n- github-copilot: GitHub Copilot\n- roocode: RooCode AI编辑器\n- tongyi-lingma: 通义灵码\n- trae: Trae AI编辑器\n- qoder: Qoder AI编辑器\n- antigravity: Google Antigravity AI编辑器\n- vscode: Visual Studio Code\n\n特别说明:\n- rules 模板会自动包含当前 mcp 版本号信息(版本号:${ true ? "2.4.0-alpha.0" : 0}),便于后续维护和版本追踪\n- 下载 rules 模板时,如果项目中已存在 README.md 文件,系统会自动保护该文件不被覆盖(除非设置 overwrite=true)`,
|
|
215499
215695
|
inputSchema: {
|
|
215500
215696
|
template: zod_1.z
|
|
215501
215697
|
.enum(["react", "vue", "miniprogram", "uniapp", "rules"])
|
|
@@ -226551,6 +226747,7 @@ class CloudService {
|
|
|
226551
226747
|
this.cloudBaseContext = context;
|
|
226552
226748
|
}
|
|
226553
226749
|
get baseUrl() {
|
|
226750
|
+
const internalEndpoint = this.cloudBaseContext.isInternalEndpoint();
|
|
226554
226751
|
const tcb = process.env.TCB_BASE_URL || 'https://tcb.tencentcloudapi.com';
|
|
226555
226752
|
const urlMap = {
|
|
226556
226753
|
tcb,
|
|
@@ -226564,7 +226761,7 @@ class CloudService {
|
|
|
226564
226761
|
const intranetUrlMap = Object.keys(urlMap).map((service) => ({
|
|
226565
226762
|
[service]: `https://${service}.internal.tencentcloudapi.com`,
|
|
226566
226763
|
})).reduce((acc, cur) => (Object.assign(Object.assign({}, acc), cur)), {});
|
|
226567
|
-
if (
|
|
226764
|
+
if (internalEndpoint) {
|
|
226568
226765
|
return intranetUrlMap[this.service];
|
|
226569
226766
|
}
|
|
226570
226767
|
if (urlMap[this.service]) {
|
|
@@ -233358,6 +233555,7 @@ function registerGatewayTools(server) {
|
|
|
233358
233555
|
name,
|
|
233359
233556
|
path
|
|
233360
233557
|
});
|
|
233558
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
233361
233559
|
return {
|
|
233362
233560
|
content: [
|
|
233363
233561
|
{
|
|
@@ -270197,7 +270395,7 @@ class CloudBase {
|
|
|
270197
270395
|
}
|
|
270198
270396
|
constructor(config = {}) {
|
|
270199
270397
|
this.cloudBaseConfig = {};
|
|
270200
|
-
let { secretId, secretKey, token, envId, proxy, region, envType } = config;
|
|
270398
|
+
let { secretId, secretKey, token, envId, proxy, region, envType, useInternalEndpoint } = config;
|
|
270201
270399
|
// config 中传入的 secretId secretkey 必须同时存在
|
|
270202
270400
|
if ((secretId && !secretKey) || (!secretId && secretKey)) {
|
|
270203
270401
|
throw new Error('secretId and secretKey must be a pair');
|
|
@@ -270209,7 +270407,8 @@ class CloudBase {
|
|
|
270209
270407
|
envId,
|
|
270210
270408
|
envType,
|
|
270211
270409
|
proxy,
|
|
270212
|
-
region
|
|
270410
|
+
region,
|
|
270411
|
+
useInternalEndpoint
|
|
270213
270412
|
};
|
|
270214
270413
|
// 初始化 context
|
|
270215
270414
|
this.context = new context_1.CloudBaseContext(this.cloudBaseConfig);
|
|
@@ -270264,6 +270463,9 @@ class CloudBase {
|
|
|
270264
270463
|
getManagerConfig() {
|
|
270265
270464
|
return this.cloudBaseConfig;
|
|
270266
270465
|
}
|
|
270466
|
+
get isInternalEndpoint() {
|
|
270467
|
+
return this.context.isInternalEndpoint();
|
|
270468
|
+
}
|
|
270267
270469
|
}
|
|
270268
270470
|
module.exports = CloudBase;
|
|
270269
270471
|
|
|
@@ -272342,6 +272544,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
|
272342
272544
|
exports.FunctionService = void 0;
|
|
272343
272545
|
const fs_1 = __importDefault(__webpack_require__(29021));
|
|
272344
272546
|
const path_1 = __importDefault(__webpack_require__(39902));
|
|
272547
|
+
const lodash_1 = __importDefault(__webpack_require__(2543));
|
|
272345
272548
|
const packer_1 = __webpack_require__(5147);
|
|
272346
272549
|
const error_1 = __webpack_require__(40430);
|
|
272347
272550
|
const utils_1 = __webpack_require__(62358);
|
|
@@ -272588,20 +272791,96 @@ class FunctionService {
|
|
|
272588
272791
|
});
|
|
272589
272792
|
return data;
|
|
272590
272793
|
}
|
|
272794
|
+
/**
|
|
272795
|
+
* 列出所有函数
|
|
272796
|
+
* @param {IListFunctionOptions} options
|
|
272797
|
+
* @returns {Promise<Record<string, string>[]>}
|
|
272798
|
+
*/
|
|
272799
|
+
async listAllFunctions(options) {
|
|
272800
|
+
const allFunctions = [];
|
|
272801
|
+
let currentOffset = 0;
|
|
272802
|
+
const pageSize = 20;
|
|
272803
|
+
const { envId } = options;
|
|
272804
|
+
while (true) {
|
|
272805
|
+
try {
|
|
272806
|
+
const res = await this.scfService.request('ListFunctions', {
|
|
272807
|
+
Namespace: envId,
|
|
272808
|
+
Limit: pageSize,
|
|
272809
|
+
Offset: currentOffset
|
|
272810
|
+
});
|
|
272811
|
+
const { Functions = [], TotalCount } = res;
|
|
272812
|
+
if (Functions.length === 0) {
|
|
272813
|
+
break;
|
|
272814
|
+
}
|
|
272815
|
+
allFunctions.push(...Functions);
|
|
272816
|
+
// 检查是否已获取所有函数
|
|
272817
|
+
if (allFunctions.length >= TotalCount || Functions.length < pageSize) {
|
|
272818
|
+
break;
|
|
272819
|
+
}
|
|
272820
|
+
currentOffset += pageSize;
|
|
272821
|
+
}
|
|
272822
|
+
catch (error) {
|
|
272823
|
+
throw new error_1.CloudBaseError(`获取函数列表失败: ${error.message}`);
|
|
272824
|
+
}
|
|
272825
|
+
}
|
|
272826
|
+
// 格式化数据
|
|
272827
|
+
const data = [];
|
|
272828
|
+
allFunctions.forEach(func => {
|
|
272829
|
+
const { FunctionId, FunctionName, Runtime, AddTime, ModTime, Status } = func;
|
|
272830
|
+
data.push({
|
|
272831
|
+
FunctionId,
|
|
272832
|
+
FunctionName,
|
|
272833
|
+
Runtime,
|
|
272834
|
+
AddTime,
|
|
272835
|
+
ModTime,
|
|
272836
|
+
Status
|
|
272837
|
+
});
|
|
272838
|
+
});
|
|
272839
|
+
return data;
|
|
272840
|
+
}
|
|
272591
272841
|
/**
|
|
272592
272842
|
* 删除云函数
|
|
272593
272843
|
* @param {string} name 云函数名称
|
|
272594
272844
|
* @param {string} qualifier 需要删除的版本号,不填默认删除函数下全部版本。
|
|
272595
272845
|
* @returns {Promise<IResponseInfo>}
|
|
272596
272846
|
*/
|
|
272597
|
-
async deleteFunction(name
|
|
272847
|
+
async deleteFunction({ name }) {
|
|
272848
|
+
var _a;
|
|
272598
272849
|
const { namespace } = this.getFunctionConfig();
|
|
272599
|
-
|
|
272850
|
+
// 检测是否绑定了 API 网关
|
|
272851
|
+
const accessService = this.environment.getAccessService();
|
|
272852
|
+
const res = await accessService.getAccessList({
|
|
272853
|
+
name
|
|
272854
|
+
});
|
|
272855
|
+
// 删除绑定的 API 网关
|
|
272856
|
+
if (((_a = res === null || res === void 0 ? void 0 : res.APISet) === null || _a === void 0 ? void 0 : _a.length) > 0) {
|
|
272857
|
+
await accessService.deleteAccess({
|
|
272858
|
+
name
|
|
272859
|
+
});
|
|
272860
|
+
}
|
|
272861
|
+
await this.scfService.request('DeleteFunction', {
|
|
272600
272862
|
FunctionName: name,
|
|
272601
|
-
Namespace: namespace
|
|
272602
|
-
Qualifier: qualifier
|
|
272863
|
+
Namespace: namespace
|
|
272603
272864
|
});
|
|
272604
272865
|
}
|
|
272866
|
+
/**
|
|
272867
|
+
* 批量删除云函数
|
|
272868
|
+
* @param {Object} options
|
|
272869
|
+
* @param {string[]} options.names 云函数名称列表
|
|
272870
|
+
* @returns {Promise<void>}
|
|
272871
|
+
*/
|
|
272872
|
+
async batchDeleteFunctions({ names }) {
|
|
272873
|
+
const promises = names.map(name => (async () => {
|
|
272874
|
+
try {
|
|
272875
|
+
await this.deleteFunction({ name });
|
|
272876
|
+
(0, utils_1.successLog)(`[${name}] 函数删除成功!`);
|
|
272877
|
+
}
|
|
272878
|
+
catch (e) {
|
|
272879
|
+
throw new error_1.CloudBaseError(e.message);
|
|
272880
|
+
}
|
|
272881
|
+
})());
|
|
272882
|
+
await Promise.all(promises);
|
|
272883
|
+
}
|
|
272605
272884
|
/**
|
|
272606
272885
|
* 获取云函数详细信息
|
|
272607
272886
|
* @param {string} name 云函数名称
|
|
@@ -272636,13 +272915,35 @@ class FunctionService {
|
|
|
272636
272915
|
}
|
|
272637
272916
|
catch (e) {
|
|
272638
272917
|
data.VpcConfig = {
|
|
272639
|
-
vpc: '',
|
|
272640
|
-
subnet: ''
|
|
272918
|
+
vpc: 'VpcId',
|
|
272919
|
+
subnet: 'SubnetId'
|
|
272641
272920
|
};
|
|
272642
272921
|
}
|
|
272643
272922
|
}
|
|
272644
272923
|
return data;
|
|
272645
272924
|
}
|
|
272925
|
+
/**
|
|
272926
|
+
* 批量获取云函数详细信息
|
|
272927
|
+
* @param {Object} options
|
|
272928
|
+
* @param {string[]} options.names 云函数名称列表
|
|
272929
|
+
* @param {string} options.envId 环境 ID
|
|
272930
|
+
* @param {string} options.codeSecret
|
|
272931
|
+
* @returns {Promise<IFunctionInfo[]>}
|
|
272932
|
+
*/
|
|
272933
|
+
async batchGetFunctionsDetail({ names, envId, codeSecret }) {
|
|
272934
|
+
const data = [];
|
|
272935
|
+
const promises = names.map(name => (async () => {
|
|
272936
|
+
try {
|
|
272937
|
+
const info = await this.getFunctionDetail(name, codeSecret);
|
|
272938
|
+
data.push(info);
|
|
272939
|
+
}
|
|
272940
|
+
catch (e) {
|
|
272941
|
+
throw new error_1.CloudBaseError(`${name} 获取信息失败:${e.message}`);
|
|
272942
|
+
}
|
|
272943
|
+
})());
|
|
272944
|
+
await Promise.all(promises);
|
|
272945
|
+
return data;
|
|
272946
|
+
}
|
|
272646
272947
|
/**
|
|
272647
272948
|
* 获取函数日志
|
|
272648
272949
|
* @deprecated 请使用 getFunctionLogsV2 代替
|
|
@@ -272739,6 +273040,33 @@ class FunctionService {
|
|
|
272739
273040
|
const res = await this.tcbService.request('GetFunctionLogDetail', params);
|
|
272740
273041
|
return res;
|
|
272741
273042
|
}
|
|
273043
|
+
/**
|
|
273044
|
+
* 获取函数的完整调用日志
|
|
273045
|
+
* 该方法会自动完成两步操作:1. 获取日志请求ID列表。 2. 根据ID列表获取每条日志的详细内容。
|
|
273046
|
+
* @param {IFunctionLogOptionsV2} options - 查询选项
|
|
273047
|
+
* @returns {Promise<IFunctionLogDetailRes[]>} 返回包含完整日志详情的数组
|
|
273048
|
+
*/
|
|
273049
|
+
async getCompleteFunctionLogs(options) {
|
|
273050
|
+
// 调用 getFunctionLogsV2 获取日志请求ID列表
|
|
273051
|
+
const { name } = options;
|
|
273052
|
+
const logs = await this.getFunctionLogsV2(options);
|
|
273053
|
+
// 如果没有日志,直接返回空数组
|
|
273054
|
+
if (logs.LogList.length === 0) {
|
|
273055
|
+
return [];
|
|
273056
|
+
}
|
|
273057
|
+
const detailPromises = logs.LogList.map(async (log) => {
|
|
273058
|
+
// 对每一个日志ID,调用 getFunctionLogDetail
|
|
273059
|
+
const res = await this.getFunctionLogDetail({
|
|
273060
|
+
logRequestId: log.RequestId,
|
|
273061
|
+
startTime: options.startTime,
|
|
273062
|
+
endTime: options.endTime
|
|
273063
|
+
});
|
|
273064
|
+
return Object.assign(Object.assign({}, res), { RetCode: log.RetCode, FunctionName: name });
|
|
273065
|
+
});
|
|
273066
|
+
// 并发执行所有详情查询,等待它们全部完成
|
|
273067
|
+
const detailedLogs = await Promise.all(detailPromises);
|
|
273068
|
+
return detailedLogs;
|
|
273069
|
+
}
|
|
272742
273070
|
/**
|
|
272743
273071
|
* 更新云函数配置
|
|
272744
273072
|
* @param {ICloudFunction} func 云函数配置
|
|
@@ -272874,6 +273202,28 @@ class FunctionService {
|
|
|
272874
273202
|
throw new error_1.CloudBaseError(`[${name}] 调用失败:\n${e.message}`);
|
|
272875
273203
|
}
|
|
272876
273204
|
}
|
|
273205
|
+
/**
|
|
273206
|
+
* 批量调用云函数
|
|
273207
|
+
* @param {IFunctionBatchOptions} options
|
|
273208
|
+
* @returns {Promise<IFunctionInvokeRes[]>}
|
|
273209
|
+
*/
|
|
273210
|
+
async batchInvokeFunctions(options) {
|
|
273211
|
+
const { functions, envId, log = false } = options;
|
|
273212
|
+
const promises = functions.map(func => (async () => {
|
|
273213
|
+
try {
|
|
273214
|
+
const result = await this.invokeFunction(func.name, func.params);
|
|
273215
|
+
if (log) {
|
|
273216
|
+
(0, utils_1.successLog)(`[${func.name}] 调用成功\n响应结果:\n`);
|
|
273217
|
+
console.log(result);
|
|
273218
|
+
}
|
|
273219
|
+
return result;
|
|
273220
|
+
}
|
|
273221
|
+
catch (e) {
|
|
273222
|
+
throw new error_1.CloudBaseError(`${func.name} 函数调用失败:${e.message}`);
|
|
273223
|
+
}
|
|
273224
|
+
})());
|
|
273225
|
+
return Promise.all(promises);
|
|
273226
|
+
}
|
|
272877
273227
|
/**
|
|
272878
273228
|
* 复制云函数
|
|
272879
273229
|
* @param {string} name 云函数名称
|
|
@@ -272916,12 +273266,34 @@ class FunctionService {
|
|
|
272916
273266
|
TriggerDesc: item.config
|
|
272917
273267
|
};
|
|
272918
273268
|
});
|
|
272919
|
-
|
|
272920
|
-
|
|
272921
|
-
|
|
272922
|
-
|
|
272923
|
-
|
|
272924
|
-
|
|
273269
|
+
try {
|
|
273270
|
+
return await this.scfService.request('BatchCreateTrigger', {
|
|
273271
|
+
FunctionName: name,
|
|
273272
|
+
Namespace: namespace,
|
|
273273
|
+
Triggers: JSON.stringify(parsedTriggers),
|
|
273274
|
+
Count: parsedTriggers.length
|
|
273275
|
+
});
|
|
273276
|
+
}
|
|
273277
|
+
catch (e) {
|
|
273278
|
+
throw new error_1.CloudBaseError(`[${name}] 创建触发器失败:${e.message}`, {
|
|
273279
|
+
action: e.action,
|
|
273280
|
+
code: e.code
|
|
273281
|
+
});
|
|
273282
|
+
}
|
|
273283
|
+
}
|
|
273284
|
+
// 批量部署函数触发器
|
|
273285
|
+
async batchCreateTriggers(options) {
|
|
273286
|
+
const { functions, envId } = options;
|
|
273287
|
+
const promises = functions.map(func => (async () => {
|
|
273288
|
+
try {
|
|
273289
|
+
await this.createFunctionTriggers(func.name, func.triggers);
|
|
273290
|
+
(0, utils_1.successLog)(`[${func.name}] 创建云函数触发器成功!`);
|
|
273291
|
+
}
|
|
273292
|
+
catch (e) {
|
|
273293
|
+
throw new error_1.CloudBaseError(e.message);
|
|
273294
|
+
}
|
|
273295
|
+
})());
|
|
273296
|
+
await Promise.all(promises);
|
|
272925
273297
|
}
|
|
272926
273298
|
/**
|
|
272927
273299
|
* 删除云函数触发器
|
|
@@ -272931,12 +273303,50 @@ class FunctionService {
|
|
|
272931
273303
|
*/
|
|
272932
273304
|
async deleteFunctionTrigger(name, triggerName) {
|
|
272933
273305
|
const { namespace } = this.getFunctionConfig();
|
|
272934
|
-
|
|
272935
|
-
|
|
272936
|
-
|
|
272937
|
-
|
|
272938
|
-
|
|
273306
|
+
try {
|
|
273307
|
+
await this.scfService.request('DeleteTrigger', {
|
|
273308
|
+
FunctionName: name,
|
|
273309
|
+
Namespace: namespace,
|
|
273310
|
+
TriggerName: triggerName,
|
|
273311
|
+
Type: 'timer'
|
|
273312
|
+
});
|
|
273313
|
+
(0, utils_1.successLog)(`[${name}] 删除云函数触发器 ${triggerName} 成功!`);
|
|
273314
|
+
}
|
|
273315
|
+
catch (e) {
|
|
273316
|
+
throw new error_1.CloudBaseError(`[${name}] 删除触发器失败:${e.message}`);
|
|
273317
|
+
}
|
|
273318
|
+
}
|
|
273319
|
+
async batchDeleteTriggers(options) {
|
|
273320
|
+
const { functions, envId } = options;
|
|
273321
|
+
const promises = functions.map(func => (async () => {
|
|
273322
|
+
try {
|
|
273323
|
+
func.triggers.forEach(async (trigger) => {
|
|
273324
|
+
await this.deleteFunctionTrigger(func.name, trigger.name);
|
|
273325
|
+
});
|
|
273326
|
+
}
|
|
273327
|
+
catch (e) {
|
|
273328
|
+
throw new error_1.CloudBaseError(e.message);
|
|
273329
|
+
}
|
|
273330
|
+
})());
|
|
273331
|
+
await Promise.all(promises);
|
|
273332
|
+
}
|
|
273333
|
+
/**
|
|
273334
|
+
* 下载云函数代码
|
|
273335
|
+
* @param {IFunctionCodeOptions} options
|
|
273336
|
+
* @returns {Promise<void>}
|
|
273337
|
+
*/
|
|
273338
|
+
async downloadFunctionCode(options) {
|
|
273339
|
+
const { destPath, envId, functionName, codeSecret } = options;
|
|
273340
|
+
// 检验路径是否存在
|
|
273341
|
+
(0, utils_1.checkFullAccess)(destPath, true);
|
|
273342
|
+
// 获取下载链接
|
|
273343
|
+
const { Url } = await this.scfService.request('GetFunctionAddress', {
|
|
273344
|
+
FunctionName: functionName,
|
|
273345
|
+
Namespace: envId,
|
|
273346
|
+
CodeSecret: codeSecret
|
|
272939
273347
|
});
|
|
273348
|
+
// 下载文件
|
|
273349
|
+
return (0, utils_1.downloadAndExtractRemoteZip)(Url, destPath);
|
|
272940
273350
|
}
|
|
272941
273351
|
/**
|
|
272942
273352
|
* 获取云函数代码下载 链接
|
|
@@ -272962,6 +273372,68 @@ class FunctionService {
|
|
|
272962
273372
|
throw new error_1.CloudBaseError(`[${functionName}] 获取函数代码下载链接失败:\n${e.message}`);
|
|
272963
273373
|
}
|
|
272964
273374
|
}
|
|
273375
|
+
// 函数绑定文件层
|
|
273376
|
+
async attachLayer(options) {
|
|
273377
|
+
const { envId, functionName, layerName, layerVersion, codeSecret } = options;
|
|
273378
|
+
let { Layers = [] } = await this.getFunctionDetail(functionName, codeSecret);
|
|
273379
|
+
Layers = Layers.map(item => lodash_1.default.pick(item, ['LayerName', 'LayerVersion']));
|
|
273380
|
+
// 新加的文件层添加到最后
|
|
273381
|
+
Layers.push({
|
|
273382
|
+
LayerName: layerName,
|
|
273383
|
+
LayerVersion: layerVersion
|
|
273384
|
+
});
|
|
273385
|
+
const res = await this.scfService.request('UpdateFunctionConfiguration', {
|
|
273386
|
+
Layers,
|
|
273387
|
+
Namespace: envId,
|
|
273388
|
+
FunctionName: functionName
|
|
273389
|
+
});
|
|
273390
|
+
return res;
|
|
273391
|
+
}
|
|
273392
|
+
// 函数解绑文件层
|
|
273393
|
+
async unAttachLayer(options) {
|
|
273394
|
+
const { envId, functionName, layerName, layerVersion, codeSecret } = options;
|
|
273395
|
+
let { Layers } = await this.getFunctionDetail(functionName, codeSecret);
|
|
273396
|
+
Layers = Layers.map(item => lodash_1.default.pick(item, ['LayerName', 'LayerVersion']));
|
|
273397
|
+
const index = Layers.findIndex(item => item.LayerName === layerName && item.LayerVersion === layerVersion);
|
|
273398
|
+
if (index === -1) {
|
|
273399
|
+
throw new error_1.CloudBaseError('层不存在');
|
|
273400
|
+
}
|
|
273401
|
+
// 删除指定的层
|
|
273402
|
+
Layers.splice(index, 1);
|
|
273403
|
+
const apiParams = {
|
|
273404
|
+
Namespace: envId,
|
|
273405
|
+
FunctionName: functionName,
|
|
273406
|
+
Layers: Layers.length > 0 ? Layers : [{
|
|
273407
|
+
LayerName: '',
|
|
273408
|
+
LayerVersion: 0
|
|
273409
|
+
}]
|
|
273410
|
+
};
|
|
273411
|
+
return this.scfService.request('UpdateFunctionConfiguration', apiParams);
|
|
273412
|
+
}
|
|
273413
|
+
// 更新云函数层
|
|
273414
|
+
async updateFunctionLayer(options) {
|
|
273415
|
+
const { envId, functionName, layers } = options;
|
|
273416
|
+
return this.scfService.request('UpdateFunctionConfiguration', {
|
|
273417
|
+
Layers: layers,
|
|
273418
|
+
Namespace: envId,
|
|
273419
|
+
FunctionName: functionName
|
|
273420
|
+
});
|
|
273421
|
+
}
|
|
273422
|
+
// 下载文件层 ZIP 文件
|
|
273423
|
+
async downloadLayer(options) {
|
|
273424
|
+
const { name, version, destPath } = options;
|
|
273425
|
+
const res = await this.scfService.request('GetLayerVersion', {
|
|
273426
|
+
LayerName: name,
|
|
273427
|
+
LayerVersion: version
|
|
273428
|
+
});
|
|
273429
|
+
const url = res === null || res === void 0 ? void 0 : res.Location;
|
|
273430
|
+
const zipPath = path_1.default.join(destPath, `${name}-${version}.zip`);
|
|
273431
|
+
if ((0, utils_1.checkFullAccess)(zipPath)) {
|
|
273432
|
+
throw new error_1.CloudBaseError(`文件已存在:${zipPath}`);
|
|
273433
|
+
}
|
|
273434
|
+
// 下载文件
|
|
273435
|
+
return (0, utils_1.downloadAndExtractRemoteZip)(url, destPath);
|
|
273436
|
+
}
|
|
272965
273437
|
// 创建文件层版本
|
|
272966
273438
|
async createLayer(options) {
|
|
272967
273439
|
const { env } = this.getFunctionConfig();
|
|
@@ -273034,7 +273506,7 @@ class FunctionService {
|
|
|
273034
273506
|
Limit: limit,
|
|
273035
273507
|
Offset: offset,
|
|
273036
273508
|
SearchKey: searchKey,
|
|
273037
|
-
SearchSrc: `TCB_${env}`
|
|
273509
|
+
// SearchSrc: `TCB_${env}`
|
|
273038
273510
|
};
|
|
273039
273511
|
if (runtime) {
|
|
273040
273512
|
param.CompatibleRuntime = runtime;
|
|
@@ -273363,12 +273835,18 @@ __decorate([
|
|
|
273363
273835
|
__decorate([
|
|
273364
273836
|
(0, utils_1.preLazy)()
|
|
273365
273837
|
], FunctionService.prototype, "listFunctions", null);
|
|
273838
|
+
__decorate([
|
|
273839
|
+
(0, utils_1.preLazy)()
|
|
273840
|
+
], FunctionService.prototype, "listAllFunctions", null);
|
|
273366
273841
|
__decorate([
|
|
273367
273842
|
(0, utils_1.preLazy)()
|
|
273368
273843
|
], FunctionService.prototype, "deleteFunction", null);
|
|
273369
273844
|
__decorate([
|
|
273370
273845
|
(0, utils_1.preLazy)()
|
|
273371
273846
|
], FunctionService.prototype, "getFunctionDetail", null);
|
|
273847
|
+
__decorate([
|
|
273848
|
+
(0, utils_1.preLazy)()
|
|
273849
|
+
], FunctionService.prototype, "batchGetFunctionsDetail", null);
|
|
273372
273850
|
__decorate([
|
|
273373
273851
|
(0, utils_1.preLazy)()
|
|
273374
273852
|
], FunctionService.prototype, "getFunctionLogs", null);
|
|
@@ -273378,6 +273856,9 @@ __decorate([
|
|
|
273378
273856
|
__decorate([
|
|
273379
273857
|
(0, utils_1.preLazy)()
|
|
273380
273858
|
], FunctionService.prototype, "getFunctionLogDetail", null);
|
|
273859
|
+
__decorate([
|
|
273860
|
+
(0, utils_1.preLazy)()
|
|
273861
|
+
], FunctionService.prototype, "getCompleteFunctionLogs", null);
|
|
273381
273862
|
__decorate([
|
|
273382
273863
|
(0, utils_1.preLazy)()
|
|
273383
273864
|
], FunctionService.prototype, "updateFunctionConfig", null);
|
|
@@ -273387,6 +273868,9 @@ __decorate([
|
|
|
273387
273868
|
__decorate([
|
|
273388
273869
|
(0, utils_1.preLazy)()
|
|
273389
273870
|
], FunctionService.prototype, "invokeFunction", null);
|
|
273871
|
+
__decorate([
|
|
273872
|
+
(0, utils_1.preLazy)()
|
|
273873
|
+
], FunctionService.prototype, "batchInvokeFunctions", null);
|
|
273390
273874
|
__decorate([
|
|
273391
273875
|
(0, utils_1.preLazy)()
|
|
273392
273876
|
], FunctionService.prototype, "copyFunction", null);
|
|
@@ -273399,6 +273883,18 @@ __decorate([
|
|
|
273399
273883
|
__decorate([
|
|
273400
273884
|
(0, utils_1.preLazy)()
|
|
273401
273885
|
], FunctionService.prototype, "getFunctionDownloadUrl", null);
|
|
273886
|
+
__decorate([
|
|
273887
|
+
(0, utils_1.preLazy)()
|
|
273888
|
+
], FunctionService.prototype, "attachLayer", null);
|
|
273889
|
+
__decorate([
|
|
273890
|
+
(0, utils_1.preLazy)()
|
|
273891
|
+
], FunctionService.prototype, "unAttachLayer", null);
|
|
273892
|
+
__decorate([
|
|
273893
|
+
(0, utils_1.preLazy)()
|
|
273894
|
+
], FunctionService.prototype, "updateFunctionLayer", null);
|
|
273895
|
+
__decorate([
|
|
273896
|
+
(0, utils_1.preLazy)()
|
|
273897
|
+
], FunctionService.prototype, "downloadLayer", null);
|
|
273402
273898
|
__decorate([
|
|
273403
273899
|
(0, utils_1.preLazy)()
|
|
273404
273900
|
], FunctionService.prototype, "createLayer", null);
|