@cloudbase/cloudbase-mcp 2.3.0 → 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/README.md +1 -1
- package/dist/cli.cjs +731 -141
- package/dist/index.cjs +731 -141
- package/dist/index.js +314 -106
- 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
|
/***/ }),
|
|
@@ -185485,7 +185652,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
185485
185652
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
185486
185653
|
};
|
|
185487
185654
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
185488
|
-
exports.downloadWebTemplate = downloadWebTemplate;
|
|
185489
185655
|
exports.getClaudePrompt = getClaudePrompt;
|
|
185490
185656
|
exports.registerRagTools = registerRagTools;
|
|
185491
185657
|
const adm_zip_1 = __importDefault(__webpack_require__(30283));
|
|
@@ -185503,6 +185669,58 @@ const KnowledgeBaseIdMap = {
|
|
|
185503
185669
|
scf: "scfsczskzyws_4bdc",
|
|
185504
185670
|
miniprogram: "xcxzskws_25d8",
|
|
185505
185671
|
};
|
|
185672
|
+
// ============ 缓存配置 ============
|
|
185673
|
+
const CACHE_BASE_DIR = path.join(os.homedir(), ".cloudbase-mcp");
|
|
185674
|
+
const CACHE_META_FILE = path.join(CACHE_BASE_DIR, "cache-meta.json");
|
|
185675
|
+
const DEFAULT_CACHE_TTL_MS = 24 * 60 * 60 * 1000; // 默认 24 小时
|
|
185676
|
+
// 支持环境变量 CLOUDBASE_MCP_CACHE_TTL_MS 控制缓存过期时间(毫秒)
|
|
185677
|
+
const parsedCacheTTL = process.env.CLOUDBASE_MCP_CACHE_TTL_MS
|
|
185678
|
+
? parseInt(process.env.CLOUDBASE_MCP_CACHE_TTL_MS, 10)
|
|
185679
|
+
: NaN;
|
|
185680
|
+
const CACHE_TTL_MS = Number.isNaN(parsedCacheTTL) || parsedCacheTTL < 0
|
|
185681
|
+
? DEFAULT_CACHE_TTL_MS
|
|
185682
|
+
: parsedCacheTTL;
|
|
185683
|
+
if (!Number.isNaN(parsedCacheTTL) && parsedCacheTTL >= 0) {
|
|
185684
|
+
(0, logger_js_1.debug)("[cache] Using TTL from CLOUDBASE_MCP_CACHE_TTL_MS", {
|
|
185685
|
+
ttlMs: CACHE_TTL_MS,
|
|
185686
|
+
});
|
|
185687
|
+
}
|
|
185688
|
+
else {
|
|
185689
|
+
(0, logger_js_1.debug)("[cache] Using default TTL", { ttlMs: CACHE_TTL_MS });
|
|
185690
|
+
}
|
|
185691
|
+
// 共享的下载 Promise,防止并发重复下载
|
|
185692
|
+
let resourceDownloadPromise = null;
|
|
185693
|
+
// 检查缓存是否可用(未过期)
|
|
185694
|
+
async function canUseCache() {
|
|
185695
|
+
try {
|
|
185696
|
+
const content = await fs.readFile(CACHE_META_FILE, "utf8");
|
|
185697
|
+
const meta = JSON.parse(content);
|
|
185698
|
+
if (!meta.timestamp) {
|
|
185699
|
+
(0, logger_js_1.debug)("[cache] cache-meta missing timestamp, treating as invalid", {
|
|
185700
|
+
ttlMs: CACHE_TTL_MS,
|
|
185701
|
+
});
|
|
185702
|
+
return false;
|
|
185703
|
+
}
|
|
185704
|
+
const ageMs = Date.now() - meta.timestamp;
|
|
185705
|
+
const isValid = ageMs <= CACHE_TTL_MS;
|
|
185706
|
+
(0, logger_js_1.debug)("[cache] evaluated cache meta", {
|
|
185707
|
+
timestamp: meta.timestamp,
|
|
185708
|
+
ageMs,
|
|
185709
|
+
ttlMs: CACHE_TTL_MS,
|
|
185710
|
+
valid: isValid,
|
|
185711
|
+
});
|
|
185712
|
+
return isValid;
|
|
185713
|
+
}
|
|
185714
|
+
catch (error) {
|
|
185715
|
+
(0, logger_js_1.debug)("[cache] failed to read cache meta, treating as miss", { error });
|
|
185716
|
+
return false;
|
|
185717
|
+
}
|
|
185718
|
+
}
|
|
185719
|
+
// 更新缓存时间戳
|
|
185720
|
+
async function updateCache() {
|
|
185721
|
+
await fs.mkdir(CACHE_BASE_DIR, { recursive: true });
|
|
185722
|
+
await fs.writeFile(CACHE_META_FILE, JSON.stringify({ timestamp: Date.now() }, null, 2), "utf8");
|
|
185723
|
+
}
|
|
185506
185724
|
// 安全 JSON.parse
|
|
185507
185725
|
function safeParse(str) {
|
|
185508
185726
|
try {
|
|
@@ -185529,31 +185747,141 @@ function safeStringify(obj) {
|
|
|
185529
185747
|
return "";
|
|
185530
185748
|
}
|
|
185531
185749
|
}
|
|
185532
|
-
//
|
|
185533
|
-
|
|
185750
|
+
// OpenAPI 文档 URL 列表
|
|
185751
|
+
const OPENAPI_SOURCES = [
|
|
185752
|
+
{
|
|
185753
|
+
name: "mysqldb",
|
|
185754
|
+
description: "MySQL RESTful API - 云开发 MySQL 数据库 HTTP API",
|
|
185755
|
+
url: "https://docs.cloudbase.net/openapi/mysqldb.v1.openapi.yaml",
|
|
185756
|
+
},
|
|
185757
|
+
{
|
|
185758
|
+
name: "functions",
|
|
185759
|
+
description: "Cloud Functions API - 云函数 HTTP API",
|
|
185760
|
+
url: "https://docs.cloudbase.net/openapi/functions.v1.openapi.yaml",
|
|
185761
|
+
},
|
|
185762
|
+
{
|
|
185763
|
+
name: "auth",
|
|
185764
|
+
description: "Authentication API - 身份认证 HTTP API",
|
|
185765
|
+
url: "https://docs.cloudbase.net/openapi/auth.v1.openapi.yaml",
|
|
185766
|
+
},
|
|
185767
|
+
{
|
|
185768
|
+
name: "cloudrun",
|
|
185769
|
+
description: "CloudRun API - 云托管服务 HTTP API",
|
|
185770
|
+
url: "https://docs.cloudbase.net/openapi/cloudrun.v1.openapi.yaml",
|
|
185771
|
+
},
|
|
185772
|
+
{
|
|
185773
|
+
name: "storage",
|
|
185774
|
+
description: "Storage API - 云存储 HTTP API",
|
|
185775
|
+
url: "https://docs.cloudbase.net/openapi/storage.v1.openapi.yaml",
|
|
185776
|
+
},
|
|
185777
|
+
];
|
|
185534
185778
|
async function downloadWebTemplate() {
|
|
185535
|
-
const
|
|
185536
|
-
const
|
|
185537
|
-
const extractDir = path.join(baseDir, "web-template");
|
|
185779
|
+
const zipPath = path.join(CACHE_BASE_DIR, "web-cloudbase-project.zip");
|
|
185780
|
+
const extractDir = path.join(CACHE_BASE_DIR, "web-template");
|
|
185538
185781
|
const url = "https://static.cloudbase.net/cloudbase-examples/web-cloudbase-project.zip";
|
|
185539
|
-
await fs.mkdir(baseDir, { recursive: true });
|
|
185540
|
-
// Download zip to specified path (overwrite)
|
|
185541
185782
|
const response = await fetch(url);
|
|
185542
185783
|
if (!response.ok) {
|
|
185543
185784
|
throw new Error(`下载模板失败,状态码: ${response.status}`);
|
|
185544
185785
|
}
|
|
185545
185786
|
const buffer = Buffer.from(await response.arrayBuffer());
|
|
185546
185787
|
await fs.writeFile(zipPath, buffer);
|
|
185547
|
-
// Clean and recreate extract directory
|
|
185548
185788
|
await fs.rm(extractDir, { recursive: true, force: true });
|
|
185549
185789
|
await fs.mkdir(extractDir, { recursive: true });
|
|
185550
185790
|
const zip = new adm_zip_1.default(zipPath);
|
|
185551
185791
|
zip.extractAllTo(extractDir, true);
|
|
185792
|
+
(0, logger_js_1.debug)("[downloadResources] webTemplate 下载完成");
|
|
185552
185793
|
return extractDir;
|
|
185553
185794
|
}
|
|
185554
|
-
async function
|
|
185555
|
-
const
|
|
185556
|
-
|
|
185795
|
+
async function downloadOpenAPI() {
|
|
185796
|
+
const baseDir = path.join(CACHE_BASE_DIR, "openapi");
|
|
185797
|
+
await fs.mkdir(baseDir, { recursive: true });
|
|
185798
|
+
const results = [];
|
|
185799
|
+
await Promise.all(OPENAPI_SOURCES.map(async (source) => {
|
|
185800
|
+
try {
|
|
185801
|
+
const response = await fetch(source.url);
|
|
185802
|
+
if (!response.ok) {
|
|
185803
|
+
(0, logger_js_1.warn)(`[downloadOpenAPI] Failed to download ${source.name}`, {
|
|
185804
|
+
status: response.status,
|
|
185805
|
+
});
|
|
185806
|
+
return;
|
|
185807
|
+
}
|
|
185808
|
+
const content = await response.text();
|
|
185809
|
+
const filePath = path.join(baseDir, `${source.name}.openapi.yaml`);
|
|
185810
|
+
await fs.writeFile(filePath, content, "utf8");
|
|
185811
|
+
results.push({
|
|
185812
|
+
name: source.name,
|
|
185813
|
+
description: source.description,
|
|
185814
|
+
absolutePath: filePath,
|
|
185815
|
+
});
|
|
185816
|
+
}
|
|
185817
|
+
catch (error) {
|
|
185818
|
+
(0, logger_js_1.warn)(`[downloadOpenAPI] Failed to download ${source.name}`, {
|
|
185819
|
+
error,
|
|
185820
|
+
});
|
|
185821
|
+
}
|
|
185822
|
+
}));
|
|
185823
|
+
(0, logger_js_1.debug)("[downloadOpenAPI] openAPIDocs 下载完成", {
|
|
185824
|
+
successCount: results.length,
|
|
185825
|
+
total: OPENAPI_SOURCES.length,
|
|
185826
|
+
});
|
|
185827
|
+
return results;
|
|
185828
|
+
}
|
|
185829
|
+
// 实际执行下载所有资源的函数(webTemplate 和 openAPI 并发下载)
|
|
185830
|
+
async function _doDownloadResources() {
|
|
185831
|
+
// 并发下载 webTemplate 和 openAPIDocs
|
|
185832
|
+
const [webTemplateDir, openAPIDocs] = await Promise.all([
|
|
185833
|
+
// 下载 web 模板
|
|
185834
|
+
downloadWebTemplate(),
|
|
185835
|
+
// 并发下载所有 OpenAPI 文档
|
|
185836
|
+
downloadOpenAPI(),
|
|
185837
|
+
]);
|
|
185838
|
+
(0, logger_js_1.debug)("[downloadResources] 所有资源下载完成");
|
|
185839
|
+
return { webTemplateDir, openAPIDocs };
|
|
185840
|
+
}
|
|
185841
|
+
// 下载所有资源(带缓存和共享 Promise 机制)
|
|
185842
|
+
async function downloadResources() {
|
|
185843
|
+
const webTemplateDir = path.join(CACHE_BASE_DIR, "web-template");
|
|
185844
|
+
const openAPIDir = path.join(CACHE_BASE_DIR, "openapi");
|
|
185845
|
+
// 检查缓存是否有效
|
|
185846
|
+
if (await canUseCache()) {
|
|
185847
|
+
try {
|
|
185848
|
+
// 检查两个目录都存在
|
|
185849
|
+
await Promise.all([fs.access(webTemplateDir), fs.access(openAPIDir)]);
|
|
185850
|
+
const files = await fs.readdir(openAPIDir);
|
|
185851
|
+
if (files.length > 0) {
|
|
185852
|
+
(0, logger_js_1.debug)("[downloadResources] 使用缓存");
|
|
185853
|
+
return {
|
|
185854
|
+
webTemplateDir,
|
|
185855
|
+
openAPIDocs: OPENAPI_SOURCES.map((source) => ({
|
|
185856
|
+
name: source.name,
|
|
185857
|
+
description: source.description,
|
|
185858
|
+
absolutePath: path.join(openAPIDir, `${source.name}.openapi.yaml`),
|
|
185859
|
+
})).filter((item) => files.includes(`${item.name}.openapi.yaml`)),
|
|
185860
|
+
};
|
|
185861
|
+
}
|
|
185862
|
+
}
|
|
185863
|
+
catch {
|
|
185864
|
+
// 缓存无效,需要重新下载
|
|
185865
|
+
}
|
|
185866
|
+
}
|
|
185867
|
+
// 如果已有下载任务在进行中,共享该 Promise
|
|
185868
|
+
if (resourceDownloadPromise) {
|
|
185869
|
+
(0, logger_js_1.debug)("[downloadResources] 共享已有下载任务");
|
|
185870
|
+
return resourceDownloadPromise;
|
|
185871
|
+
}
|
|
185872
|
+
// 创建新的下载任务
|
|
185873
|
+
(0, logger_js_1.debug)("[downloadResources] 开始新下载任务");
|
|
185874
|
+
await fs.mkdir(CACHE_BASE_DIR, { recursive: true });
|
|
185875
|
+
resourceDownloadPromise = _doDownloadResources()
|
|
185876
|
+
.then(async (result) => {
|
|
185877
|
+
await updateCache();
|
|
185878
|
+
(0, logger_js_1.debug)("[downloadResources] 缓存已更新");
|
|
185879
|
+
return result;
|
|
185880
|
+
})
|
|
185881
|
+
.finally(() => {
|
|
185882
|
+
resourceDownloadPromise = null;
|
|
185883
|
+
});
|
|
185884
|
+
return resourceDownloadPromise;
|
|
185557
185885
|
}
|
|
185558
185886
|
// Get CLAUDE.md prompt content
|
|
185559
185887
|
// Priority: 1. From downloaded template, 2. Fallback to embedded constant
|
|
@@ -185677,23 +186005,15 @@ async function registerRagTools(server) {
|
|
|
185677
186005
|
};
|
|
185678
186006
|
}
|
|
185679
186007
|
});
|
|
185680
|
-
let skills = [];
|
|
185681
186008
|
let openapis = [];
|
|
185682
|
-
|
|
185683
|
-
try {
|
|
185684
|
-
skills = await prepareKnowledgeBaseWebTemplate();
|
|
185685
|
-
}
|
|
185686
|
-
catch (error) {
|
|
185687
|
-
(0, logger_js_1.warn)("[searchKnowledgeBase] Failed to prepare web template", {
|
|
185688
|
-
error,
|
|
185689
|
-
});
|
|
185690
|
-
}
|
|
185691
|
-
// OpenAPI 文档准备
|
|
186009
|
+
let skills = [];
|
|
185692
186010
|
try {
|
|
185693
|
-
|
|
186011
|
+
const { webTemplateDir, openAPIDocs } = await downloadResources();
|
|
186012
|
+
openapis = openAPIDocs;
|
|
186013
|
+
skills = await collectSkillDescriptions(path.join(webTemplateDir, ".claude", "skills"));
|
|
185694
186014
|
}
|
|
185695
186015
|
catch (error) {
|
|
185696
|
-
(0, logger_js_1.warn)("[
|
|
186016
|
+
(0, logger_js_1.warn)("[downloadResources] Failed to download resources", {
|
|
185697
186017
|
error,
|
|
185698
186018
|
});
|
|
185699
186019
|
}
|
|
@@ -185860,65 +186180,6 @@ function extractDescriptionFromFrontMatter(content) {
|
|
|
185860
186180
|
.match(/^(?:decsription|description)\s*:\s*(.*)$/m);
|
|
185861
186181
|
return match ? match[1].trim() : null;
|
|
185862
186182
|
}
|
|
185863
|
-
// OpenAPI 文档 URL 列表
|
|
185864
|
-
const OPENAPI_SOURCES = [
|
|
185865
|
-
{
|
|
185866
|
-
name: "mysqldb",
|
|
185867
|
-
description: "MySQL RESTful API - 云开发 MySQL 数据库 HTTP API",
|
|
185868
|
-
url: "https://docs.cloudbase.net/openapi/mysqldb.v1.openapi.yaml",
|
|
185869
|
-
},
|
|
185870
|
-
{
|
|
185871
|
-
name: "functions",
|
|
185872
|
-
description: "Cloud Functions API - 云函数 HTTP API",
|
|
185873
|
-
url: "https://docs.cloudbase.net/openapi/functions.v1.openapi.yaml",
|
|
185874
|
-
},
|
|
185875
|
-
{
|
|
185876
|
-
name: "auth",
|
|
185877
|
-
description: "Authentication API - 身份认证 HTTP API",
|
|
185878
|
-
url: "https://docs.cloudbase.net/openapi/auth.v1.openapi.yaml",
|
|
185879
|
-
},
|
|
185880
|
-
{
|
|
185881
|
-
name: "cloudrun",
|
|
185882
|
-
description: "CloudRun API - 云托管服务 HTTP API",
|
|
185883
|
-
url: "https://docs.cloudbase.net/openapi/cloudrun.v1.openapi.yaml",
|
|
185884
|
-
},
|
|
185885
|
-
{
|
|
185886
|
-
name: "storage",
|
|
185887
|
-
description: "Storage API - 云存储 HTTP API",
|
|
185888
|
-
url: "https://docs.cloudbase.net/openapi/storage.v1.openapi.yaml",
|
|
185889
|
-
},
|
|
185890
|
-
];
|
|
185891
|
-
// 下载并准备 OpenAPI 文档
|
|
185892
|
-
async function prepareOpenAPIDocs() {
|
|
185893
|
-
const baseDir = path.join(os.homedir(), ".cloudbase-mcp", "openapi");
|
|
185894
|
-
await fs.mkdir(baseDir, { recursive: true });
|
|
185895
|
-
const results = [];
|
|
185896
|
-
await Promise.all(OPENAPI_SOURCES.map(async (source) => {
|
|
185897
|
-
try {
|
|
185898
|
-
const response = await fetch(source.url);
|
|
185899
|
-
if (!response.ok) {
|
|
185900
|
-
(0, logger_js_1.warn)(`[prepareOpenAPIDocs] Failed to download ${source.name}`, {
|
|
185901
|
-
status: response.status,
|
|
185902
|
-
});
|
|
185903
|
-
return;
|
|
185904
|
-
}
|
|
185905
|
-
const content = await response.text();
|
|
185906
|
-
const filePath = path.join(baseDir, `${source.name}.openapi.yaml`);
|
|
185907
|
-
await fs.writeFile(filePath, content, "utf8");
|
|
185908
|
-
results.push({
|
|
185909
|
-
name: source.name,
|
|
185910
|
-
description: source.description,
|
|
185911
|
-
absolutePath: filePath,
|
|
185912
|
-
});
|
|
185913
|
-
}
|
|
185914
|
-
catch (error) {
|
|
185915
|
-
(0, logger_js_1.warn)(`[prepareOpenAPIDocs] Failed to download ${source.name}`, {
|
|
185916
|
-
error,
|
|
185917
|
-
});
|
|
185918
|
-
}
|
|
185919
|
-
}));
|
|
185920
|
-
return results;
|
|
185921
|
-
}
|
|
185922
186183
|
async function collectSkillDescriptions(rootDir) {
|
|
185923
186184
|
const result = [];
|
|
185924
186185
|
async function walk(dir) {
|
|
@@ -191216,20 +191477,25 @@ function callSuccessCallback(callback, result) {
|
|
|
191216
191477
|
/***/ }),
|
|
191217
191478
|
|
|
191218
191479
|
/***/ 65607:
|
|
191219
|
-
/***/ ((__unused_webpack_module, exports) => {
|
|
191480
|
+
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
191220
191481
|
|
|
191221
191482
|
"use strict";
|
|
191222
191483
|
|
|
191223
191484
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
191224
191485
|
exports.CloudBaseContext = void 0;
|
|
191486
|
+
const constant_1 = __webpack_require__(40762);
|
|
191225
191487
|
class CloudBaseContext {
|
|
191226
|
-
constructor({ secretId = '', secretKey = '', token = '', proxy = '', region = '', envType = '' }) {
|
|
191488
|
+
constructor({ secretId = '', secretKey = '', token = '', proxy = '', region = '', envType = '', useInternalEndpoint = undefined }) {
|
|
191227
191489
|
this.secretId = secretId;
|
|
191228
191490
|
this.secretKey = secretKey;
|
|
191229
191491
|
this.token = token;
|
|
191230
191492
|
this.proxy = proxy;
|
|
191231
191493
|
this.region = region;
|
|
191232
191494
|
this.envType = envType;
|
|
191495
|
+
this.useInternalEndpoint = useInternalEndpoint;
|
|
191496
|
+
}
|
|
191497
|
+
isInternalEndpoint() {
|
|
191498
|
+
return this.useInternalEndpoint !== undefined ? this.useInternalEndpoint : constant_1.USE_INTERNAL_ENDPOINT;
|
|
191233
191499
|
}
|
|
191234
191500
|
}
|
|
191235
191501
|
exports.CloudBaseContext = CloudBaseContext;
|
|
@@ -200711,11 +200977,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
200711
200977
|
};
|
|
200712
200978
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
200713
200979
|
exports.wrapServerWithTelemetry = wrapServerWithTelemetry;
|
|
200714
|
-
const
|
|
200715
|
-
const logger_js_1 = __webpack_require__(13039);
|
|
200980
|
+
const os_1 = __importDefault(__webpack_require__(21820));
|
|
200716
200981
|
const cloudbase_manager_js_1 = __webpack_require__(3431);
|
|
200717
200982
|
const cloud_mode_js_1 = __webpack_require__(89684);
|
|
200718
|
-
const
|
|
200983
|
+
const logger_js_1 = __webpack_require__(13039);
|
|
200984
|
+
const telemetry_js_1 = __webpack_require__(45880);
|
|
200719
200985
|
/**
|
|
200720
200986
|
* 生成 GitHub Issue 创建链接
|
|
200721
200987
|
* @param toolName 工具名称
|
|
@@ -200756,7 +201022,7 @@ ${envIdSection}
|
|
|
200756
201022
|
## 环境信息
|
|
200757
201023
|
- 操作系统: ${os_1.default.type()} ${os_1.default.release()}
|
|
200758
201024
|
- Node.js版本: ${process.version}
|
|
200759
|
-
- MCP 版本:${process.env.npm_package_version || "2.
|
|
201025
|
+
- MCP 版本:${process.env.npm_package_version || "2.4.0-alpha.0" || 0}
|
|
200760
201026
|
- 系统架构: ${os_1.default.arch()}
|
|
200761
201027
|
- 时间: ${new Date().toISOString()}
|
|
200762
201028
|
- 请求ID: ${requestId}
|
|
@@ -200794,10 +201060,13 @@ function createWrappedHandler(name, handler, server) {
|
|
|
200794
201060
|
let requestId;
|
|
200795
201061
|
try {
|
|
200796
201062
|
(0, logger_js_1.debug)(`开始执行工具: ${name}`, { args: sanitizeArgs(args) });
|
|
201063
|
+
server.logger?.({ type: 'beforeToolCall', toolName: name, args: sanitizeArgs(args) });
|
|
200797
201064
|
// 执行原始处理函数
|
|
200798
201065
|
const result = await handler(args);
|
|
200799
201066
|
success = true;
|
|
200800
|
-
|
|
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 });
|
|
200801
201070
|
return result;
|
|
200802
201071
|
}
|
|
200803
201072
|
catch (error) {
|
|
@@ -200808,6 +201077,7 @@ function createWrappedHandler(name, handler, server) {
|
|
|
200808
201077
|
error: errorMessage,
|
|
200809
201078
|
duration: Date.now() - startTime
|
|
200810
201079
|
});
|
|
201080
|
+
server.logger?.({ type: 'errorToolCall', toolName: name, args: sanitizeArgs(args), message: errorMessage, duration: Date.now() - startTime });
|
|
200811
201081
|
// 生成 GitHub Issue 创建链接
|
|
200812
201082
|
const issueLink = await generateGitHubIssueLink(name, errorMessage, args, server.cloudBaseOptions, {
|
|
200813
201083
|
requestId: (typeof error === 'object' && error && 'requestId' in error) ? error.requestId : '',
|
|
@@ -203648,6 +203918,7 @@ class StorageService {
|
|
|
203648
203918
|
* 获取 COS 配置
|
|
203649
203919
|
*/
|
|
203650
203920
|
getCos(parallel = 20) {
|
|
203921
|
+
const internalEndpoint = this.environment.cloudBaseContext.isInternalEndpoint();
|
|
203651
203922
|
const { secretId, secretKey, token, proxy } = this.environment.getAuthConfig();
|
|
203652
203923
|
const cosProxy = process.env.TCB_COS_PROXY;
|
|
203653
203924
|
const cosConfig = {
|
|
@@ -203656,14 +203927,14 @@ class StorageService {
|
|
|
203656
203927
|
SecretKey: secretKey,
|
|
203657
203928
|
Proxy: cosProxy || proxy,
|
|
203658
203929
|
SecurityToken: token,
|
|
203659
|
-
Domain:
|
|
203930
|
+
Domain: internalEndpoint ? "{Bucket}.cos-internal.{Region}.tencentcos.cn" /* COS_ENDPOINT.INTERNAL */ : "{Bucket}.cos.{Region}.tencentcos.cn" /* COS_ENDPOINT.PUBLIC */,
|
|
203660
203931
|
};
|
|
203661
203932
|
if (constant_1.COS_SDK_PROTOCOL) {
|
|
203662
203933
|
cosConfig.Protocol = (constant_1.COS_SDK_PROTOCOL.endsWith(':')
|
|
203663
203934
|
? constant_1.COS_SDK_PROTOCOL.toLowerCase()
|
|
203664
203935
|
: constant_1.COS_SDK_PROTOCOL.toLowerCase() + ':');
|
|
203665
203936
|
}
|
|
203666
|
-
if (
|
|
203937
|
+
if (internalEndpoint) {
|
|
203667
203938
|
cosConfig.Protocol = 'http:';
|
|
203668
203939
|
}
|
|
203669
203940
|
// COSSDK 默认开启 KeepAlive,这里提供关闭的方式
|
|
@@ -208712,6 +208983,7 @@ async function getDatabaseInstanceId(getManager) {
|
|
|
208712
208983
|
function registerDatabaseTools(server) {
|
|
208713
208984
|
// 获取 cloudBaseOptions,如果没有则为 undefined
|
|
208714
208985
|
const cloudBaseOptions = server.cloudBaseOptions;
|
|
208986
|
+
const logger = server.logger;
|
|
208715
208987
|
// 创建闭包函数来获取 CloudBase Manager
|
|
208716
208988
|
const getManager = () => (0, cloudbase_manager_js_1.getCloudBaseManager)({ cloudBaseOptions });
|
|
208717
208989
|
// readNoSqlDatabaseStructure
|
|
@@ -208759,6 +209031,7 @@ checkIndex: 检查索引是否存在`),
|
|
|
208759
209031
|
MgoOffset: offset,
|
|
208760
209032
|
MgoLimit: limit,
|
|
208761
209033
|
});
|
|
209034
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
208762
209035
|
return {
|
|
208763
209036
|
content: [
|
|
208764
209037
|
{
|
|
@@ -208779,6 +209052,7 @@ checkIndex: 检查索引是否存在`),
|
|
|
208779
209052
|
throw new Error("检查集合时必须提供 collectionName");
|
|
208780
209053
|
}
|
|
208781
209054
|
const result = await cloudbase.database.checkCollectionExists(collectionName);
|
|
209055
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
208782
209056
|
return {
|
|
208783
209057
|
content: [
|
|
208784
209058
|
{
|
|
@@ -208800,6 +209074,7 @@ checkIndex: 检查索引是否存在`),
|
|
|
208800
209074
|
throw new Error("查看集合详情时必须提供 collectionName");
|
|
208801
209075
|
}
|
|
208802
209076
|
const result = await cloudbase.database.describeCollection(collectionName);
|
|
209077
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
208803
209078
|
return {
|
|
208804
209079
|
content: [
|
|
208805
209080
|
{
|
|
@@ -208820,6 +209095,7 @@ checkIndex: 检查索引是否存在`),
|
|
|
208820
209095
|
throw new Error("获取索引列表时必须提供 collectionName");
|
|
208821
209096
|
}
|
|
208822
209097
|
const result = await cloudbase.database.describeCollection(collectionName);
|
|
209098
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
208823
209099
|
return {
|
|
208824
209100
|
content: [
|
|
208825
209101
|
{
|
|
@@ -208840,6 +209116,7 @@ checkIndex: 检查索引是否存在`),
|
|
|
208840
209116
|
throw new Error("检查索引时必须提供 collectionName 和 indexName");
|
|
208841
209117
|
}
|
|
208842
209118
|
const result = await cloudbase.database.checkIndexExists(collectionName, indexName);
|
|
209119
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
208843
209120
|
return {
|
|
208844
209121
|
content: [
|
|
208845
209122
|
{
|
|
@@ -208900,6 +209177,7 @@ updateCollection: 更新集合`),
|
|
|
208900
209177
|
const cloudbase = await getManager();
|
|
208901
209178
|
if (action === "createCollection") {
|
|
208902
209179
|
const result = await cloudbase.database.createCollection(collectionName);
|
|
209180
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
208903
209181
|
return {
|
|
208904
209182
|
content: [
|
|
208905
209183
|
{
|
|
@@ -208919,6 +209197,7 @@ updateCollection: 更新集合`),
|
|
|
208919
209197
|
throw new Error("更新集合时必须提供 options");
|
|
208920
209198
|
}
|
|
208921
209199
|
const result = await cloudbase.database.updateCollection(collectionName, updateOptions);
|
|
209200
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
208922
209201
|
return {
|
|
208923
209202
|
content: [
|
|
208924
209203
|
{
|
|
@@ -208995,6 +209274,7 @@ updateCollection: 更新集合`),
|
|
|
208995
209274
|
Tag: instanceId,
|
|
208996
209275
|
},
|
|
208997
209276
|
});
|
|
209277
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
208998
209278
|
return {
|
|
208999
209279
|
content: [
|
|
209000
209280
|
{
|
|
@@ -209072,6 +209352,7 @@ deleteCollection: 删除数据`),
|
|
|
209072
209352
|
collectionName,
|
|
209073
209353
|
documents,
|
|
209074
209354
|
getManager,
|
|
209355
|
+
logger,
|
|
209075
209356
|
});
|
|
209076
209357
|
return {
|
|
209077
209358
|
content: [
|
|
@@ -209096,6 +209377,7 @@ deleteCollection: 删除数据`),
|
|
|
209096
209377
|
isMulti,
|
|
209097
209378
|
upsert,
|
|
209098
209379
|
getManager,
|
|
209380
|
+
logger,
|
|
209099
209381
|
});
|
|
209100
209382
|
return {
|
|
209101
209383
|
content: [
|
|
@@ -209115,6 +209397,7 @@ deleteCollection: 删除数据`),
|
|
|
209115
209397
|
query,
|
|
209116
209398
|
isMulti,
|
|
209117
209399
|
getManager,
|
|
209400
|
+
logger,
|
|
209118
209401
|
});
|
|
209119
209402
|
return {
|
|
209120
209403
|
content: [
|
|
@@ -209128,7 +209411,7 @@ deleteCollection: 删除数据`),
|
|
|
209128
209411
|
throw new Error(`不支持的操作类型: ${action}`);
|
|
209129
209412
|
});
|
|
209130
209413
|
}
|
|
209131
|
-
async function insertDocuments({ collectionName, documents, getManager, }) {
|
|
209414
|
+
async function insertDocuments({ collectionName, documents, getManager, logger, }) {
|
|
209132
209415
|
try {
|
|
209133
209416
|
const cloudbase = await getManager();
|
|
209134
209417
|
const instanceId = await getDatabaseInstanceId(getManager);
|
|
@@ -209142,6 +209425,7 @@ async function insertDocuments({ collectionName, documents, getManager, }) {
|
|
|
209142
209425
|
Tag: instanceId,
|
|
209143
209426
|
},
|
|
209144
209427
|
});
|
|
209428
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(logger, result);
|
|
209145
209429
|
return JSON.stringify({
|
|
209146
209430
|
success: true,
|
|
209147
209431
|
requestId: result.RequestId,
|
|
@@ -209157,7 +209441,7 @@ async function insertDocuments({ collectionName, documents, getManager, }) {
|
|
|
209157
209441
|
}, null, 2);
|
|
209158
209442
|
}
|
|
209159
209443
|
}
|
|
209160
|
-
async function updateDocuments({ collectionName, query, update, isMulti, upsert, getManager, }) {
|
|
209444
|
+
async function updateDocuments({ collectionName, query, update, isMulti, upsert, getManager, logger, }) {
|
|
209161
209445
|
try {
|
|
209162
209446
|
const cloudbase = await getManager();
|
|
209163
209447
|
const instanceId = await getDatabaseInstanceId(getManager);
|
|
@@ -209173,6 +209457,7 @@ async function updateDocuments({ collectionName, query, update, isMulti, upsert,
|
|
|
209173
209457
|
Tag: instanceId,
|
|
209174
209458
|
},
|
|
209175
209459
|
});
|
|
209460
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(logger, result);
|
|
209176
209461
|
return JSON.stringify({
|
|
209177
209462
|
success: true,
|
|
209178
209463
|
requestId: result.RequestId,
|
|
@@ -209190,7 +209475,7 @@ async function updateDocuments({ collectionName, query, update, isMulti, upsert,
|
|
|
209190
209475
|
}, null, 2);
|
|
209191
209476
|
}
|
|
209192
209477
|
}
|
|
209193
|
-
async function deleteDocuments({ collectionName, query, isMulti, getManager, }) {
|
|
209478
|
+
async function deleteDocuments({ collectionName, query, isMulti, getManager, logger, }) {
|
|
209194
209479
|
try {
|
|
209195
209480
|
const cloudbase = await getManager();
|
|
209196
209481
|
const instanceId = await getDatabaseInstanceId(getManager);
|
|
@@ -209204,6 +209489,7 @@ async function deleteDocuments({ collectionName, query, isMulti, getManager, })
|
|
|
209204
209489
|
Tag: instanceId,
|
|
209205
209490
|
},
|
|
209206
209491
|
});
|
|
209492
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(logger, result);
|
|
209207
209493
|
return JSON.stringify({
|
|
209208
209494
|
success: true,
|
|
209209
209495
|
requestId: result.RequestId,
|
|
@@ -215097,6 +215383,7 @@ const IDE_TYPES = [
|
|
|
215097
215383
|
"qoder", // Qoder AI编辑器
|
|
215098
215384
|
"antigravity", // Google Antigravity AI编辑器
|
|
215099
215385
|
"vscode", // Visual Studio Code
|
|
215386
|
+
"kiro", // Kiro AI编辑器
|
|
215100
215387
|
];
|
|
215101
215388
|
// IDE到文件的映射关系
|
|
215102
215389
|
// 注意:以 "/" 结尾的路径表示目录,会包含该目录下的所有文件
|
|
@@ -215130,6 +215417,7 @@ const IDE_FILE_MAPPINGS = {
|
|
|
215130
215417
|
qoder: [".qoder/rules/"],
|
|
215131
215418
|
antigravity: [".agent/rules/"],
|
|
215132
215419
|
vscode: [".vscode/mcp.json", ".vscode/settings.json"],
|
|
215420
|
+
kiro: [".kiro/settings/mcp.json", ".kiro/steering/"],
|
|
215133
215421
|
};
|
|
215134
215422
|
// 所有IDE配置文件的完整列表 - 通过IDE_FILE_MAPPINGS计算得出
|
|
215135
215423
|
const ALL_IDE_FILES = Array.from(new Set(Object.values(IDE_FILE_MAPPINGS).flat()));
|
|
@@ -215156,6 +215444,7 @@ const IDE_DESCRIPTIONS = {
|
|
|
215156
215444
|
qoder: "Qoder AI编辑器",
|
|
215157
215445
|
antigravity: "Google Antigravity AI编辑器",
|
|
215158
215446
|
vscode: "Visual Studio Code",
|
|
215447
|
+
kiro: "Kiro AI编辑器",
|
|
215159
215448
|
};
|
|
215160
215449
|
// INTEGRATION_IDE 环境变量值到 IDE 类型的映射
|
|
215161
215450
|
const INTEGRATION_IDE_MAPPING = {
|
|
@@ -215179,6 +215468,7 @@ const INTEGRATION_IDE_MAPPING = {
|
|
|
215179
215468
|
Qoder: "qoder",
|
|
215180
215469
|
Antigravity: "antigravity",
|
|
215181
215470
|
VSCode: "vscode",
|
|
215471
|
+
Kiro: "kiro",
|
|
215182
215472
|
};
|
|
215183
215473
|
// 根据 INTEGRATION_IDE 环境变量获取默认 IDE 类型
|
|
215184
215474
|
function getDefaultIDEFromEnv() {
|
|
@@ -215401,7 +215691,7 @@ function registerSetupTools(server) {
|
|
|
215401
215691
|
title: "下载项目模板",
|
|
215402
215692
|
description: `自动下载并部署CloudBase项目模板。⚠️ **MANDATORY FOR NEW PROJECTS** ⚠️
|
|
215403
215693
|
|
|
215404
|
-
**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)`,
|
|
215405
215695
|
inputSchema: {
|
|
215406
215696
|
template: zod_1.z
|
|
215407
215697
|
.enum(["react", "vue", "miniprogram", "uniapp", "rules"])
|
|
@@ -226457,6 +226747,7 @@ class CloudService {
|
|
|
226457
226747
|
this.cloudBaseContext = context;
|
|
226458
226748
|
}
|
|
226459
226749
|
get baseUrl() {
|
|
226750
|
+
const internalEndpoint = this.cloudBaseContext.isInternalEndpoint();
|
|
226460
226751
|
const tcb = process.env.TCB_BASE_URL || 'https://tcb.tencentcloudapi.com';
|
|
226461
226752
|
const urlMap = {
|
|
226462
226753
|
tcb,
|
|
@@ -226470,7 +226761,7 @@ class CloudService {
|
|
|
226470
226761
|
const intranetUrlMap = Object.keys(urlMap).map((service) => ({
|
|
226471
226762
|
[service]: `https://${service}.internal.tencentcloudapi.com`,
|
|
226472
226763
|
})).reduce((acc, cur) => (Object.assign(Object.assign({}, acc), cur)), {});
|
|
226473
|
-
if (
|
|
226764
|
+
if (internalEndpoint) {
|
|
226474
226765
|
return intranetUrlMap[this.service];
|
|
226475
226766
|
}
|
|
226476
226767
|
if (urlMap[this.service]) {
|
|
@@ -233264,6 +233555,7 @@ function registerGatewayTools(server) {
|
|
|
233264
233555
|
name,
|
|
233265
233556
|
path
|
|
233266
233557
|
});
|
|
233558
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
233267
233559
|
return {
|
|
233268
233560
|
content: [
|
|
233269
233561
|
{
|
|
@@ -270103,7 +270395,7 @@ class CloudBase {
|
|
|
270103
270395
|
}
|
|
270104
270396
|
constructor(config = {}) {
|
|
270105
270397
|
this.cloudBaseConfig = {};
|
|
270106
|
-
let { secretId, secretKey, token, envId, proxy, region, envType } = config;
|
|
270398
|
+
let { secretId, secretKey, token, envId, proxy, region, envType, useInternalEndpoint } = config;
|
|
270107
270399
|
// config 中传入的 secretId secretkey 必须同时存在
|
|
270108
270400
|
if ((secretId && !secretKey) || (!secretId && secretKey)) {
|
|
270109
270401
|
throw new Error('secretId and secretKey must be a pair');
|
|
@@ -270115,7 +270407,8 @@ class CloudBase {
|
|
|
270115
270407
|
envId,
|
|
270116
270408
|
envType,
|
|
270117
270409
|
proxy,
|
|
270118
|
-
region
|
|
270410
|
+
region,
|
|
270411
|
+
useInternalEndpoint
|
|
270119
270412
|
};
|
|
270120
270413
|
// 初始化 context
|
|
270121
270414
|
this.context = new context_1.CloudBaseContext(this.cloudBaseConfig);
|
|
@@ -270170,6 +270463,9 @@ class CloudBase {
|
|
|
270170
270463
|
getManagerConfig() {
|
|
270171
270464
|
return this.cloudBaseConfig;
|
|
270172
270465
|
}
|
|
270466
|
+
get isInternalEndpoint() {
|
|
270467
|
+
return this.context.isInternalEndpoint();
|
|
270468
|
+
}
|
|
270173
270469
|
}
|
|
270174
270470
|
module.exports = CloudBase;
|
|
270175
270471
|
|
|
@@ -272248,6 +272544,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
|
272248
272544
|
exports.FunctionService = void 0;
|
|
272249
272545
|
const fs_1 = __importDefault(__webpack_require__(29021));
|
|
272250
272546
|
const path_1 = __importDefault(__webpack_require__(39902));
|
|
272547
|
+
const lodash_1 = __importDefault(__webpack_require__(2543));
|
|
272251
272548
|
const packer_1 = __webpack_require__(5147);
|
|
272252
272549
|
const error_1 = __webpack_require__(40430);
|
|
272253
272550
|
const utils_1 = __webpack_require__(62358);
|
|
@@ -272494,20 +272791,96 @@ class FunctionService {
|
|
|
272494
272791
|
});
|
|
272495
272792
|
return data;
|
|
272496
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
|
+
}
|
|
272497
272841
|
/**
|
|
272498
272842
|
* 删除云函数
|
|
272499
272843
|
* @param {string} name 云函数名称
|
|
272500
272844
|
* @param {string} qualifier 需要删除的版本号,不填默认删除函数下全部版本。
|
|
272501
272845
|
* @returns {Promise<IResponseInfo>}
|
|
272502
272846
|
*/
|
|
272503
|
-
async deleteFunction(name
|
|
272847
|
+
async deleteFunction({ name }) {
|
|
272848
|
+
var _a;
|
|
272504
272849
|
const { namespace } = this.getFunctionConfig();
|
|
272505
|
-
|
|
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', {
|
|
272506
272862
|
FunctionName: name,
|
|
272507
|
-
Namespace: namespace
|
|
272508
|
-
Qualifier: qualifier
|
|
272863
|
+
Namespace: namespace
|
|
272509
272864
|
});
|
|
272510
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
|
+
}
|
|
272511
272884
|
/**
|
|
272512
272885
|
* 获取云函数详细信息
|
|
272513
272886
|
* @param {string} name 云函数名称
|
|
@@ -272542,13 +272915,35 @@ class FunctionService {
|
|
|
272542
272915
|
}
|
|
272543
272916
|
catch (e) {
|
|
272544
272917
|
data.VpcConfig = {
|
|
272545
|
-
vpc: '',
|
|
272546
|
-
subnet: ''
|
|
272918
|
+
vpc: 'VpcId',
|
|
272919
|
+
subnet: 'SubnetId'
|
|
272547
272920
|
};
|
|
272548
272921
|
}
|
|
272549
272922
|
}
|
|
272550
272923
|
return data;
|
|
272551
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
|
+
}
|
|
272552
272947
|
/**
|
|
272553
272948
|
* 获取函数日志
|
|
272554
272949
|
* @deprecated 请使用 getFunctionLogsV2 代替
|
|
@@ -272645,6 +273040,33 @@ class FunctionService {
|
|
|
272645
273040
|
const res = await this.tcbService.request('GetFunctionLogDetail', params);
|
|
272646
273041
|
return res;
|
|
272647
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
|
+
}
|
|
272648
273070
|
/**
|
|
272649
273071
|
* 更新云函数配置
|
|
272650
273072
|
* @param {ICloudFunction} func 云函数配置
|
|
@@ -272780,6 +273202,28 @@ class FunctionService {
|
|
|
272780
273202
|
throw new error_1.CloudBaseError(`[${name}] 调用失败:\n${e.message}`);
|
|
272781
273203
|
}
|
|
272782
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
|
+
}
|
|
272783
273227
|
/**
|
|
272784
273228
|
* 复制云函数
|
|
272785
273229
|
* @param {string} name 云函数名称
|
|
@@ -272822,12 +273266,34 @@ class FunctionService {
|
|
|
272822
273266
|
TriggerDesc: item.config
|
|
272823
273267
|
};
|
|
272824
273268
|
});
|
|
272825
|
-
|
|
272826
|
-
|
|
272827
|
-
|
|
272828
|
-
|
|
272829
|
-
|
|
272830
|
-
|
|
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);
|
|
272831
273297
|
}
|
|
272832
273298
|
/**
|
|
272833
273299
|
* 删除云函数触发器
|
|
@@ -272837,12 +273303,50 @@ class FunctionService {
|
|
|
272837
273303
|
*/
|
|
272838
273304
|
async deleteFunctionTrigger(name, triggerName) {
|
|
272839
273305
|
const { namespace } = this.getFunctionConfig();
|
|
272840
|
-
|
|
272841
|
-
|
|
272842
|
-
|
|
272843
|
-
|
|
272844
|
-
|
|
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
|
|
272845
273347
|
});
|
|
273348
|
+
// 下载文件
|
|
273349
|
+
return (0, utils_1.downloadAndExtractRemoteZip)(Url, destPath);
|
|
272846
273350
|
}
|
|
272847
273351
|
/**
|
|
272848
273352
|
* 获取云函数代码下载 链接
|
|
@@ -272868,6 +273372,68 @@ class FunctionService {
|
|
|
272868
273372
|
throw new error_1.CloudBaseError(`[${functionName}] 获取函数代码下载链接失败:\n${e.message}`);
|
|
272869
273373
|
}
|
|
272870
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
|
+
}
|
|
272871
273437
|
// 创建文件层版本
|
|
272872
273438
|
async createLayer(options) {
|
|
272873
273439
|
const { env } = this.getFunctionConfig();
|
|
@@ -272940,7 +273506,7 @@ class FunctionService {
|
|
|
272940
273506
|
Limit: limit,
|
|
272941
273507
|
Offset: offset,
|
|
272942
273508
|
SearchKey: searchKey,
|
|
272943
|
-
SearchSrc: `TCB_${env}`
|
|
273509
|
+
// SearchSrc: `TCB_${env}`
|
|
272944
273510
|
};
|
|
272945
273511
|
if (runtime) {
|
|
272946
273512
|
param.CompatibleRuntime = runtime;
|
|
@@ -273269,12 +273835,18 @@ __decorate([
|
|
|
273269
273835
|
__decorate([
|
|
273270
273836
|
(0, utils_1.preLazy)()
|
|
273271
273837
|
], FunctionService.prototype, "listFunctions", null);
|
|
273838
|
+
__decorate([
|
|
273839
|
+
(0, utils_1.preLazy)()
|
|
273840
|
+
], FunctionService.prototype, "listAllFunctions", null);
|
|
273272
273841
|
__decorate([
|
|
273273
273842
|
(0, utils_1.preLazy)()
|
|
273274
273843
|
], FunctionService.prototype, "deleteFunction", null);
|
|
273275
273844
|
__decorate([
|
|
273276
273845
|
(0, utils_1.preLazy)()
|
|
273277
273846
|
], FunctionService.prototype, "getFunctionDetail", null);
|
|
273847
|
+
__decorate([
|
|
273848
|
+
(0, utils_1.preLazy)()
|
|
273849
|
+
], FunctionService.prototype, "batchGetFunctionsDetail", null);
|
|
273278
273850
|
__decorate([
|
|
273279
273851
|
(0, utils_1.preLazy)()
|
|
273280
273852
|
], FunctionService.prototype, "getFunctionLogs", null);
|
|
@@ -273284,6 +273856,9 @@ __decorate([
|
|
|
273284
273856
|
__decorate([
|
|
273285
273857
|
(0, utils_1.preLazy)()
|
|
273286
273858
|
], FunctionService.prototype, "getFunctionLogDetail", null);
|
|
273859
|
+
__decorate([
|
|
273860
|
+
(0, utils_1.preLazy)()
|
|
273861
|
+
], FunctionService.prototype, "getCompleteFunctionLogs", null);
|
|
273287
273862
|
__decorate([
|
|
273288
273863
|
(0, utils_1.preLazy)()
|
|
273289
273864
|
], FunctionService.prototype, "updateFunctionConfig", null);
|
|
@@ -273293,6 +273868,9 @@ __decorate([
|
|
|
273293
273868
|
__decorate([
|
|
273294
273869
|
(0, utils_1.preLazy)()
|
|
273295
273870
|
], FunctionService.prototype, "invokeFunction", null);
|
|
273871
|
+
__decorate([
|
|
273872
|
+
(0, utils_1.preLazy)()
|
|
273873
|
+
], FunctionService.prototype, "batchInvokeFunctions", null);
|
|
273296
273874
|
__decorate([
|
|
273297
273875
|
(0, utils_1.preLazy)()
|
|
273298
273876
|
], FunctionService.prototype, "copyFunction", null);
|
|
@@ -273305,6 +273883,18 @@ __decorate([
|
|
|
273305
273883
|
__decorate([
|
|
273306
273884
|
(0, utils_1.preLazy)()
|
|
273307
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);
|
|
273308
273898
|
__decorate([
|
|
273309
273899
|
(0, utils_1.preLazy)()
|
|
273310
273900
|
], FunctionService.prototype, "createLayer", null);
|