@cloudbase/cloudbase-mcp 2.3.1 → 2.4.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 +973 -72
- package/dist/index.cjs +973 -72
- package/dist/index.js +8715 -8515
- package/package.json +2 -1
package/dist/index.cjs
CHANGED
|
@@ -101,6 +101,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
101
101
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
102
102
|
exports.CloudRunService = void 0;
|
|
103
103
|
exports.codeToZip = codeToZip;
|
|
104
|
+
exports.parseObjectToDiffConfigItem = parseObjectToDiffConfigItem;
|
|
104
105
|
const archiver_1 = __importDefault(__webpack_require__(99133));
|
|
105
106
|
const fs_extra_1 = __webpack_require__(21605);
|
|
106
107
|
const path_1 = __importDefault(__webpack_require__(39902));
|
|
@@ -269,7 +270,7 @@ class CloudRunService {
|
|
|
269
270
|
/**
|
|
270
271
|
* 上传部署包
|
|
271
272
|
*/
|
|
272
|
-
const zipFile = await codeToZip(targetPath, { installDependency: true });
|
|
273
|
+
const zipFile = await codeToZip(targetPath, { installDependency: (serverConfig === null || serverConfig === void 0 ? void 0 : serverConfig.InstallDependency) !== undefined ? serverConfig.InstallDependency : true });
|
|
273
274
|
await (0, utils_1.upload)({
|
|
274
275
|
url: uploadUrl,
|
|
275
276
|
file: zipFile,
|
|
@@ -285,8 +286,14 @@ class CloudRunService {
|
|
|
285
286
|
if (await this._checkFunctionExist(serverName)) {
|
|
286
287
|
// 更新
|
|
287
288
|
const serverDetail = await this.detail({ serverName });
|
|
288
|
-
const _serverConfig = Object.assign(Object.assign(Object.assign({},
|
|
289
|
+
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
|
|
289
290
|
);
|
|
291
|
+
if ((serverDetail === null || serverDetail === void 0 ? void 0 : serverDetail.ServerConfig.Tag) === 'function:') {
|
|
292
|
+
deployInfo.BuildPacks = {
|
|
293
|
+
LanguageVersion: '20.18',
|
|
294
|
+
RepoLanguage: 'Node.js'
|
|
295
|
+
};
|
|
296
|
+
}
|
|
290
297
|
deployInfo.ReleaseType = 'FULL';
|
|
291
298
|
return this._upsertFunction(false, {
|
|
292
299
|
name: serverName,
|
|
@@ -314,7 +321,13 @@ class CloudRunService {
|
|
|
314
321
|
RepoLanguage: 'Node.js'
|
|
315
322
|
};
|
|
316
323
|
}
|
|
317
|
-
const _serverConfig = Object.assign(Object.assign(Object.assign({ OpenAccessTypes: ['OA', 'PUBLIC'
|
|
324
|
+
const _serverConfig = Object.assign(Object.assign(Object.assign({ OpenAccessTypes: ['OA', 'PUBLIC', 'MINIAPP'],
|
|
325
|
+
// Cpu: 0,
|
|
326
|
+
// Mem: 0,
|
|
327
|
+
MinNum: 0,
|
|
328
|
+
// MaxNum: 0,
|
|
329
|
+
// PolicyDetails: [],
|
|
330
|
+
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:' });
|
|
318
331
|
return this._upsertFunction(true, {
|
|
319
332
|
name: serverName,
|
|
320
333
|
deployInfo,
|
|
@@ -348,11 +361,12 @@ class CloudRunService {
|
|
|
348
361
|
_upsertFunction(isNew, data) {
|
|
349
362
|
const { name, deployInfo, serverConfig } = data;
|
|
350
363
|
const envConfig = this.environment.lazyEnvironmentConfig;
|
|
364
|
+
const Items = parseObjectToDiffConfigItem(serverConfig);
|
|
351
365
|
return this.tcbrService.request(isNew ? 'CreateCloudRunServer' : 'UpdateCloudRunServer', {
|
|
352
366
|
EnvId: envConfig.EnvId,
|
|
353
367
|
ServerName: name,
|
|
354
368
|
DeployInfo: deployInfo,
|
|
355
|
-
|
|
369
|
+
Items,
|
|
356
370
|
});
|
|
357
371
|
}
|
|
358
372
|
}
|
|
@@ -425,6 +439,63 @@ async function codeToZip(cwd, options) {
|
|
|
425
439
|
await archive.finalize();
|
|
426
440
|
return bufferPromise;
|
|
427
441
|
}
|
|
442
|
+
/**
|
|
443
|
+
* 提交参数变化映射
|
|
444
|
+
*/
|
|
445
|
+
const SUBMIT_DIFF_MAP = {
|
|
446
|
+
Cpu: 'CpuSpecs',
|
|
447
|
+
Mem: 'MemSpecs',
|
|
448
|
+
OpenAccessTypes: 'AccessTypes',
|
|
449
|
+
EnvParams: 'EnvParam',
|
|
450
|
+
CustomLogs: 'LogPath'
|
|
451
|
+
};
|
|
452
|
+
/**
|
|
453
|
+
* 将 object 参数转为 [{key:"Port", IntValue:80}] 的格式,并且剔除空字符串
|
|
454
|
+
*/
|
|
455
|
+
function parseObjectToDiffConfigItem(data) {
|
|
456
|
+
const kvs = Object.entries(data);
|
|
457
|
+
const Items = [];
|
|
458
|
+
kvs.forEach(([k, v]) => {
|
|
459
|
+
const Key = SUBMIT_DIFF_MAP[k] || k;
|
|
460
|
+
if ([
|
|
461
|
+
'CustomLogs',
|
|
462
|
+
'EnvParams',
|
|
463
|
+
'CreateTime',
|
|
464
|
+
'Dockerfile',
|
|
465
|
+
'BuildDir',
|
|
466
|
+
'LogType',
|
|
467
|
+
'LogSetId',
|
|
468
|
+
'LogTopicId',
|
|
469
|
+
'LogParseType',
|
|
470
|
+
'Tag',
|
|
471
|
+
'InternalAccess',
|
|
472
|
+
'InternalDomain',
|
|
473
|
+
'OperationMode',
|
|
474
|
+
'SessionAffinity'
|
|
475
|
+
].includes(k)) {
|
|
476
|
+
!!v && Items.push({ Key, Value: v });
|
|
477
|
+
}
|
|
478
|
+
else if (['MinNum', 'MaxNum', 'InitialDelaySeconds', 'Port'].includes(k)) {
|
|
479
|
+
Items.push({ Key, IntValue: v });
|
|
480
|
+
}
|
|
481
|
+
else if (['HasDockerfile'].includes(k)) {
|
|
482
|
+
Items.push({ Key, BoolValue: v });
|
|
483
|
+
}
|
|
484
|
+
else if (['Cpu', 'Mem'].includes(k)) {
|
|
485
|
+
Items.push({ Key, FloatValue: v });
|
|
486
|
+
}
|
|
487
|
+
else if (['OpenAccessTypes', 'EntryPoint', 'Cmd'].includes(k)) {
|
|
488
|
+
Items.push({ Key, ArrayValue: v });
|
|
489
|
+
}
|
|
490
|
+
else if (['PolicyDetails'].includes(k)) {
|
|
491
|
+
Items.push({ Key, PolicyDetails: v });
|
|
492
|
+
}
|
|
493
|
+
else if (['TimerScale'].includes(k)) {
|
|
494
|
+
Items.push({ Key, TimerScale: v });
|
|
495
|
+
}
|
|
496
|
+
});
|
|
497
|
+
return Items;
|
|
498
|
+
}
|
|
428
499
|
|
|
429
500
|
|
|
430
501
|
/***/ }),
|
|
@@ -1678,6 +1749,7 @@ function registerEnvTools(server) {
|
|
|
1678
1749
|
Channels: ['dcloud', 'iotenable', 'tem', 'scene_module'] // Filter special channels
|
|
1679
1750
|
}
|
|
1680
1751
|
});
|
|
1752
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
1681
1753
|
// Transform response format to match original listEnvs() format
|
|
1682
1754
|
if (result && result.EnvList) {
|
|
1683
1755
|
result = { EnvList: result.EnvList };
|
|
@@ -1689,6 +1761,7 @@ function registerEnvTools(server) {
|
|
|
1689
1761
|
// Fallback to original method if format is unexpected
|
|
1690
1762
|
(0, logger_js_1.debug)('Unexpected response format, falling back to listEnvs()');
|
|
1691
1763
|
result = await cloudbaseList.env.listEnvs();
|
|
1764
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
1692
1765
|
}
|
|
1693
1766
|
}
|
|
1694
1767
|
catch (error) {
|
|
@@ -1697,10 +1770,12 @@ function registerEnvTools(server) {
|
|
|
1697
1770
|
try {
|
|
1698
1771
|
const cloudbaseList = await (0, cloudbase_manager_js_1.getCloudBaseManager)({ cloudBaseOptions, requireEnvId: true });
|
|
1699
1772
|
result = await cloudbaseList.env.listEnvs();
|
|
1773
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
1700
1774
|
}
|
|
1701
1775
|
catch (fallbackError) {
|
|
1702
1776
|
(0, logger_js_1.debug)('降级到 listEnvs() 也失败:', fallbackError);
|
|
1703
|
-
return {
|
|
1777
|
+
return {
|
|
1778
|
+
content: [{ type: "text", text: "获取环境列表时出错: " + (fallbackError instanceof Error ? fallbackError.message : String(fallbackError)) }]
|
|
1704
1779
|
};
|
|
1705
1780
|
}
|
|
1706
1781
|
}
|
|
@@ -1708,14 +1783,17 @@ function registerEnvTools(server) {
|
|
|
1708
1783
|
case "info":
|
|
1709
1784
|
const cloudbaseInfo = await getManager();
|
|
1710
1785
|
result = await cloudbaseInfo.env.getEnvInfo();
|
|
1786
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
1711
1787
|
break;
|
|
1712
1788
|
case "domains":
|
|
1713
1789
|
const cloudbaseDomains = await getManager();
|
|
1714
1790
|
result = await cloudbaseDomains.env.getEnvAuthDomains();
|
|
1791
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
1715
1792
|
break;
|
|
1716
1793
|
case "hosting":
|
|
1717
1794
|
const cloudbaseHosting = await getManager();
|
|
1718
1795
|
result = await cloudbaseHosting.hosting.getWebsiteConfig();
|
|
1796
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
1719
1797
|
break;
|
|
1720
1798
|
default:
|
|
1721
1799
|
throw new Error(`不支持的查询类型: ${action}`);
|
|
@@ -1773,9 +1851,11 @@ function registerEnvTools(server) {
|
|
|
1773
1851
|
switch (action) {
|
|
1774
1852
|
case "create":
|
|
1775
1853
|
result = await cloudbase.env.createEnvDomain(domains);
|
|
1854
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
1776
1855
|
break;
|
|
1777
1856
|
case "delete":
|
|
1778
1857
|
result = await cloudbase.env.deleteEnvDomain(domains);
|
|
1858
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
1779
1859
|
break;
|
|
1780
1860
|
default:
|
|
1781
1861
|
throw new Error(`不支持的操作类型: ${action}`);
|
|
@@ -23413,6 +23493,8 @@ exports.getEnvId = getEnvId;
|
|
|
23413
23493
|
exports.resetCloudBaseManagerCache = resetCloudBaseManagerCache;
|
|
23414
23494
|
exports.getCloudBaseManager = getCloudBaseManager;
|
|
23415
23495
|
exports.createCloudBaseManagerWithOptions = createCloudBaseManagerWithOptions;
|
|
23496
|
+
exports.extractRequestId = extractRequestId;
|
|
23497
|
+
exports.logCloudBaseResult = logCloudBaseResult;
|
|
23416
23498
|
const manager_node_1 = __importDefault(__webpack_require__(95492));
|
|
23417
23499
|
const auth_js_1 = __webpack_require__(77291);
|
|
23418
23500
|
const interactive_js_1 = __webpack_require__(3461);
|
|
@@ -23575,6 +23657,39 @@ function createCloudBaseManagerWithOptions(cloudBaseOptions) {
|
|
|
23575
23657
|
});
|
|
23576
23658
|
return manager;
|
|
23577
23659
|
}
|
|
23660
|
+
/**
|
|
23661
|
+
* Extract RequestId from result object
|
|
23662
|
+
*/
|
|
23663
|
+
function extractRequestId(result) {
|
|
23664
|
+
if (!result || typeof result !== 'object') {
|
|
23665
|
+
return undefined;
|
|
23666
|
+
}
|
|
23667
|
+
// Try common RequestId field names
|
|
23668
|
+
if ('RequestId' in result && result.RequestId) {
|
|
23669
|
+
return String(result.RequestId);
|
|
23670
|
+
}
|
|
23671
|
+
if ('requestId' in result && result.requestId) {
|
|
23672
|
+
return String(result.requestId);
|
|
23673
|
+
}
|
|
23674
|
+
if ('request_id' in result && result.request_id) {
|
|
23675
|
+
return String(result.request_id);
|
|
23676
|
+
}
|
|
23677
|
+
return undefined;
|
|
23678
|
+
}
|
|
23679
|
+
/**
|
|
23680
|
+
* Log CloudBase manager call result with RequestId
|
|
23681
|
+
*/
|
|
23682
|
+
function logCloudBaseResult(logger, result) {
|
|
23683
|
+
if (!logger) {
|
|
23684
|
+
return;
|
|
23685
|
+
}
|
|
23686
|
+
const requestId = extractRequestId(result);
|
|
23687
|
+
logger({
|
|
23688
|
+
type: 'capiResult',
|
|
23689
|
+
requestId,
|
|
23690
|
+
result,
|
|
23691
|
+
});
|
|
23692
|
+
}
|
|
23578
23693
|
|
|
23579
23694
|
|
|
23580
23695
|
/***/ }),
|
|
@@ -23695,6 +23810,7 @@ async function _promptAndSetEnvironmentId(autoSelectSingle, server) {
|
|
|
23695
23810
|
Channels: ['dcloud', 'iotenable', 'tem', 'scene_module'] // Filter special channels
|
|
23696
23811
|
}
|
|
23697
23812
|
});
|
|
23813
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server?.logger, envResult);
|
|
23698
23814
|
// Transform response format to match original listEnvs() format
|
|
23699
23815
|
if (envResult && envResult.EnvList) {
|
|
23700
23816
|
envResult = { EnvList: envResult.EnvList };
|
|
@@ -23706,6 +23822,7 @@ async function _promptAndSetEnvironmentId(autoSelectSingle, server) {
|
|
|
23706
23822
|
// Fallback to original method if format is unexpected
|
|
23707
23823
|
(0, logger_js_1.debug)('Unexpected response format, falling back to listEnvs()');
|
|
23708
23824
|
envResult = await cloudbase.env.listEnvs();
|
|
23825
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server?.logger, envResult);
|
|
23709
23826
|
}
|
|
23710
23827
|
}
|
|
23711
23828
|
catch (error) {
|
|
@@ -23713,6 +23830,7 @@ async function _promptAndSetEnvironmentId(autoSelectSingle, server) {
|
|
|
23713
23830
|
// Fallback to original method on error
|
|
23714
23831
|
try {
|
|
23715
23832
|
envResult = await cloudbase.env.listEnvs();
|
|
23833
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server?.logger, envResult);
|
|
23716
23834
|
}
|
|
23717
23835
|
catch (fallbackError) {
|
|
23718
23836
|
(0, logger_js_1.debug)('降级到 listEnvs() 也失败:', fallbackError);
|
|
@@ -33514,6 +33632,7 @@ function registerSecurityRuleTools(server) {
|
|
|
33514
33632
|
EnvId: envId,
|
|
33515
33633
|
},
|
|
33516
33634
|
});
|
|
33635
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
33517
33636
|
}
|
|
33518
33637
|
else if (resourceType === "function") {
|
|
33519
33638
|
// 查询云函数安全规则
|
|
@@ -33524,6 +33643,7 @@ function registerSecurityRuleTools(server) {
|
|
|
33524
33643
|
EnvId: envId,
|
|
33525
33644
|
},
|
|
33526
33645
|
});
|
|
33646
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
33527
33647
|
}
|
|
33528
33648
|
else if (resourceType === "storage") {
|
|
33529
33649
|
// 查询存储安全规则
|
|
@@ -33534,6 +33654,7 @@ function registerSecurityRuleTools(server) {
|
|
|
33534
33654
|
EnvId: envId,
|
|
33535
33655
|
},
|
|
33536
33656
|
});
|
|
33657
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
33537
33658
|
}
|
|
33538
33659
|
else if (resourceType === "sqlDatabase") {
|
|
33539
33660
|
// TODO: 考虑是否有支持指定其他 instance、schema 的需求
|
|
@@ -33549,6 +33670,7 @@ function registerSecurityRuleTools(server) {
|
|
|
33549
33670
|
RoleIdentityList: ["allUser"],
|
|
33550
33671
|
},
|
|
33551
33672
|
});
|
|
33673
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
33552
33674
|
}
|
|
33553
33675
|
else {
|
|
33554
33676
|
throw new Error(`不支持的资源类型: ${resourceType}`);
|
|
@@ -33625,6 +33747,7 @@ function registerSecurityRuleTools(server) {
|
|
|
33625
33747
|
Rule: rule,
|
|
33626
33748
|
},
|
|
33627
33749
|
});
|
|
33750
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
33628
33751
|
}
|
|
33629
33752
|
else {
|
|
33630
33753
|
result = await cloudbase.commonService().call({
|
|
@@ -33635,6 +33758,7 @@ function registerSecurityRuleTools(server) {
|
|
|
33635
33758
|
AclTag: aclTag,
|
|
33636
33759
|
},
|
|
33637
33760
|
});
|
|
33761
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
33638
33762
|
}
|
|
33639
33763
|
}
|
|
33640
33764
|
else if (resourceType === "function") {
|
|
@@ -33651,6 +33775,7 @@ function registerSecurityRuleTools(server) {
|
|
|
33651
33775
|
Rule: rule,
|
|
33652
33776
|
},
|
|
33653
33777
|
});
|
|
33778
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
33654
33779
|
}
|
|
33655
33780
|
else if (resourceType === "storage") {
|
|
33656
33781
|
if (aclTag === "CUSTOM") {
|
|
@@ -33665,6 +33790,7 @@ function registerSecurityRuleTools(server) {
|
|
|
33665
33790
|
Rule: rule,
|
|
33666
33791
|
},
|
|
33667
33792
|
});
|
|
33793
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
33668
33794
|
}
|
|
33669
33795
|
else {
|
|
33670
33796
|
result = await cloudbase.commonService().call({
|
|
@@ -33675,6 +33801,7 @@ function registerSecurityRuleTools(server) {
|
|
|
33675
33801
|
AclTag: aclTag,
|
|
33676
33802
|
},
|
|
33677
33803
|
});
|
|
33804
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
33678
33805
|
}
|
|
33679
33806
|
}
|
|
33680
33807
|
else if (resourceType === "sqlDatabase") {
|
|
@@ -33707,6 +33834,7 @@ function registerSecurityRuleTools(server) {
|
|
|
33707
33834
|
PolicyList: policyList,
|
|
33708
33835
|
},
|
|
33709
33836
|
});
|
|
33837
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
33710
33838
|
function getRowPermission(policy) {
|
|
33711
33839
|
return {
|
|
33712
33840
|
READONLY: [
|
|
@@ -38353,6 +38481,7 @@ function registerSQLDatabaseTools(server) {
|
|
|
38353
38481
|
},
|
|
38354
38482
|
},
|
|
38355
38483
|
});
|
|
38484
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
38356
38485
|
return {
|
|
38357
38486
|
content: [
|
|
38358
38487
|
{
|
|
@@ -38416,6 +38545,7 @@ function registerSQLDatabaseTools(server) {
|
|
|
38416
38545
|
},
|
|
38417
38546
|
},
|
|
38418
38547
|
});
|
|
38548
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
38419
38549
|
return {
|
|
38420
38550
|
content: [
|
|
38421
38551
|
{
|
|
@@ -48544,7 +48674,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
|
48544
48674
|
exports.cloudBaseRequest = cloudBaseRequest;
|
|
48545
48675
|
const auth_1 = __webpack_require__(23506);
|
|
48546
48676
|
const http_request_1 = __webpack_require__(72088);
|
|
48547
|
-
const SUPPORT_REGIONS = ['ap-shanghai', 'ap-guangzhou'];
|
|
48677
|
+
const SUPPORT_REGIONS = ['ap-shanghai', 'ap-guangzhou', 'ap-singapore'];
|
|
48548
48678
|
async function cloudBaseRequest(options) {
|
|
48549
48679
|
// const url = 'https://tcb-admin.tencentcloudapi.com/admin'
|
|
48550
48680
|
const { config, params = {}, method = 'POST', headers = {} } = options;
|
|
@@ -48558,11 +48688,11 @@ async function cloudBaseRequest(options) {
|
|
|
48558
48688
|
let internalRegionEndpoint = '';
|
|
48559
48689
|
if (finalRegion) {
|
|
48560
48690
|
if (SUPPORT_REGIONS.includes(finalRegion)) {
|
|
48561
|
-
internetRegionEndpoint = `${finalRegion}.tcb-api.tencentcloudapi.com`;
|
|
48562
|
-
internalRegionEndpoint =
|
|
48691
|
+
internetRegionEndpoint = `${envId}.${finalRegion}.tcb-api.tencentcloudapi.com`;
|
|
48692
|
+
internalRegionEndpoint = `${envId}.internal.${finalRegion}.tcb-api.tencentcloudapi.com`;
|
|
48563
48693
|
}
|
|
48564
48694
|
else {
|
|
48565
|
-
console.warn('
|
|
48695
|
+
console.warn('当前仅支持上海,广州,新加坡地域,其他地域默认解析到固定域名(上海地域)');
|
|
48566
48696
|
internetRegionEndpoint = `tcb-api.tencentcloudapi.com`;
|
|
48567
48697
|
internalRegionEndpoint = `internal.tcb-api.tencentcloudapi.com`;
|
|
48568
48698
|
}
|
|
@@ -53484,6 +53614,7 @@ const fs_1 = __importDefault(__webpack_require__(29021));
|
|
|
53484
53614
|
const os_1 = __importDefault(__webpack_require__(21820));
|
|
53485
53615
|
const path_1 = __importDefault(__webpack_require__(39902));
|
|
53486
53616
|
const winston_1 = __importDefault(__webpack_require__(555));
|
|
53617
|
+
const cloud_mode_js_1 = __webpack_require__(89684);
|
|
53487
53618
|
// Use require for winston-daily-rotate-file to avoid webpack bundling issues
|
|
53488
53619
|
// Handle both CommonJS and ES module exports
|
|
53489
53620
|
const DailyRotateFileModule = __webpack_require__(55622);
|
|
@@ -53535,16 +53666,18 @@ if (shouldUseConsole()) {
|
|
|
53535
53666
|
stderrLevels: ['error', 'warn', 'info', 'debug'], // All logs go to stderr
|
|
53536
53667
|
}));
|
|
53537
53668
|
}
|
|
53538
|
-
|
|
53539
|
-
|
|
53540
|
-
|
|
53541
|
-
|
|
53542
|
-
|
|
53543
|
-
|
|
53544
|
-
|
|
53545
|
-
|
|
53546
|
-
|
|
53547
|
-
|
|
53669
|
+
if (!(0, cloud_mode_js_1.isCloudMode)()) {
|
|
53670
|
+
// File transport with daily rotation
|
|
53671
|
+
transports.push(new DailyRotateFile({
|
|
53672
|
+
dirname: logDir,
|
|
53673
|
+
filename: 'cloudbase-mcp-%DATE%.log',
|
|
53674
|
+
datePattern: 'YYYY-MM-DD',
|
|
53675
|
+
format: winston_1.default.format.combine(winston_1.default.format.timestamp({ format: 'YYYY-MM-DDTHH:mm:ss.SSSZ' }), logFormat),
|
|
53676
|
+
maxFiles: '30d', // Keep logs for 30 days
|
|
53677
|
+
maxSize: '20m', // Max file size before rotation
|
|
53678
|
+
zippedArchive: false, // Don't compress old logs
|
|
53679
|
+
}));
|
|
53680
|
+
}
|
|
53548
53681
|
// Create winston logger instance
|
|
53549
53682
|
const logger = winston_1.default.createLogger({
|
|
53550
53683
|
level: getLogLevel(),
|
|
@@ -87083,6 +87216,7 @@ function registerFunctionTools(server) {
|
|
|
87083
87216
|
const cloudbase = await getManager();
|
|
87084
87217
|
if (action === "list") {
|
|
87085
87218
|
const result = await cloudbase.functions.getFunctionList(limit, offset);
|
|
87219
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
87086
87220
|
return {
|
|
87087
87221
|
content: [
|
|
87088
87222
|
{
|
|
@@ -87097,6 +87231,7 @@ function registerFunctionTools(server) {
|
|
|
87097
87231
|
throw new Error("获取函数详情时,name 参数是必需的");
|
|
87098
87232
|
}
|
|
87099
87233
|
const result = await cloudbase.functions.getFunctionDetail(name, codeSecret);
|
|
87234
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
87100
87235
|
return {
|
|
87101
87236
|
content: [
|
|
87102
87237
|
{
|
|
@@ -87178,6 +87313,7 @@ function registerFunctionTools(server) {
|
|
|
87178
87313
|
functionRootPath: processedRootPath,
|
|
87179
87314
|
force
|
|
87180
87315
|
});
|
|
87316
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
87181
87317
|
return {
|
|
87182
87318
|
content: [
|
|
87183
87319
|
{
|
|
@@ -87225,6 +87361,7 @@ function registerFunctionTools(server) {
|
|
|
87225
87361
|
// 使用闭包中的 cloudBaseOptions
|
|
87226
87362
|
const cloudbase = await getManager();
|
|
87227
87363
|
const result = await cloudbase.functions.updateFunctionCode(updateParams);
|
|
87364
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
87228
87365
|
return {
|
|
87229
87366
|
content: [
|
|
87230
87367
|
{
|
|
@@ -87265,6 +87402,7 @@ function registerFunctionTools(server) {
|
|
|
87265
87402
|
// 使用闭包中的 cloudBaseOptions
|
|
87266
87403
|
const cloudbase = await getManager();
|
|
87267
87404
|
const result = await cloudbase.functions.updateFunctionConfig(funcParam);
|
|
87405
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
87268
87406
|
return {
|
|
87269
87407
|
content: [
|
|
87270
87408
|
{
|
|
@@ -87293,6 +87431,7 @@ function registerFunctionTools(server) {
|
|
|
87293
87431
|
// 使用闭包中的 cloudBaseOptions
|
|
87294
87432
|
const cloudbase = await getManager();
|
|
87295
87433
|
const result = await cloudbase.functions.invokeFunction(name, params);
|
|
87434
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
87296
87435
|
return {
|
|
87297
87436
|
content: [
|
|
87298
87437
|
{
|
|
@@ -87333,6 +87472,7 @@ function registerFunctionTools(server) {
|
|
|
87333
87472
|
}
|
|
87334
87473
|
const cloudbase = await getManager();
|
|
87335
87474
|
const result = await cloudbase.functions.getFunctionLogsV2({ name, offset, limit, startTime, endTime, requestId, qualifier });
|
|
87475
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
87336
87476
|
return {
|
|
87337
87477
|
content: [
|
|
87338
87478
|
{
|
|
@@ -87370,6 +87510,7 @@ function registerFunctionTools(server) {
|
|
|
87370
87510
|
endTime,
|
|
87371
87511
|
logRequestId: requestId
|
|
87372
87512
|
});
|
|
87513
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
87373
87514
|
return {
|
|
87374
87515
|
content: [
|
|
87375
87516
|
{
|
|
@@ -87408,6 +87549,7 @@ function registerFunctionTools(server) {
|
|
|
87408
87549
|
throw new Error("创建触发器时,triggers 参数是必需的");
|
|
87409
87550
|
}
|
|
87410
87551
|
const result = await cloudbase.functions.createFunctionTriggers(name, triggers);
|
|
87552
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
87411
87553
|
return {
|
|
87412
87554
|
content: [
|
|
87413
87555
|
{
|
|
@@ -87422,6 +87564,7 @@ function registerFunctionTools(server) {
|
|
|
87422
87564
|
throw new Error("删除触发器时,triggerName 参数是必需的");
|
|
87423
87565
|
}
|
|
87424
87566
|
const result = await cloudbase.functions.deleteFunctionTrigger(name, triggerName);
|
|
87567
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
87425
87568
|
return {
|
|
87426
87569
|
content: [
|
|
87427
87570
|
{
|
|
@@ -90155,19 +90298,20 @@ class EnvService {
|
|
|
90155
90298
|
});
|
|
90156
90299
|
}
|
|
90157
90300
|
getCos() {
|
|
90301
|
+
const internalEndpoint = this.environment.cloudBaseContext.isInternalEndpoint();
|
|
90158
90302
|
const { secretId, secretKey, token } = this.environment.getAuthConfig();
|
|
90159
90303
|
const cosConfig = {
|
|
90160
90304
|
SecretId: secretId,
|
|
90161
90305
|
SecretKey: secretKey,
|
|
90162
90306
|
SecurityToken: token,
|
|
90163
|
-
Domain:
|
|
90307
|
+
Domain: internalEndpoint ? "{Bucket}.cos-internal.{Region}.tencentcos.cn" /* COS_ENDPOINT.INTERNAL */ : "{Bucket}.cos.{Region}.tencentcos.cn" /* COS_ENDPOINT.PUBLIC */,
|
|
90164
90308
|
};
|
|
90165
90309
|
if (constant_1.COS_SDK_PROTOCOL) {
|
|
90166
90310
|
cosConfig.Protocol = (constant_1.COS_SDK_PROTOCOL.endsWith(':')
|
|
90167
90311
|
? constant_1.COS_SDK_PROTOCOL.toLowerCase()
|
|
90168
90312
|
: constant_1.COS_SDK_PROTOCOL.toLowerCase() + ':');
|
|
90169
90313
|
}
|
|
90170
|
-
if (
|
|
90314
|
+
if (internalEndpoint) {
|
|
90171
90315
|
cosConfig.Protocol = 'http:';
|
|
90172
90316
|
}
|
|
90173
90317
|
return new cos_nodejs_sdk_v5_1.default(cosConfig);
|
|
@@ -100394,7 +100538,7 @@ function parseEnabledPlugins() {
|
|
|
100394
100538
|
* await server.connect(transport);
|
|
100395
100539
|
*/
|
|
100396
100540
|
async function createCloudBaseMcpServer(options) {
|
|
100397
|
-
const { name = "cloudbase-mcp", version = "1.0.0", enableTelemetry = true, cloudBaseOptions, cloudMode = false, ide, } = options ?? {};
|
|
100541
|
+
const { name = "cloudbase-mcp", version = "1.0.0", enableTelemetry = true, cloudBaseOptions, cloudMode = false, ide, logger, } = options ?? {};
|
|
100398
100542
|
// Enable cloud mode if specified
|
|
100399
100543
|
if (cloudMode) {
|
|
100400
100544
|
(0, cloud_mode_js_1.enableCloudMode)();
|
|
@@ -100424,6 +100568,10 @@ async function createCloudBaseMcpServer(options) {
|
|
|
100424
100568
|
if (ide) {
|
|
100425
100569
|
server.ide = ide;
|
|
100426
100570
|
}
|
|
100571
|
+
// Store logger in server instance for tools to access
|
|
100572
|
+
if (logger) {
|
|
100573
|
+
server.logger = logger;
|
|
100574
|
+
}
|
|
100427
100575
|
// Enable telemetry if requested
|
|
100428
100576
|
if (enableTelemetry) {
|
|
100429
100577
|
(0, tool_wrapper_js_1.wrapServerWithTelemetry)(server);
|
|
@@ -106747,6 +106895,7 @@ function registerDataModelTools(server) {
|
|
|
106747
106895
|
Name: name,
|
|
106748
106896
|
},
|
|
106749
106897
|
});
|
|
106898
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
106750
106899
|
// 只保留基础字段,过滤掉冗余信息,并简化Schema
|
|
106751
106900
|
let simplifiedSchema = null;
|
|
106752
106901
|
// 解析并简化Schema
|
|
@@ -106885,6 +107034,7 @@ function registerDataModelTools(server) {
|
|
|
106885
107034
|
Action: "DescribeDataSourceList",
|
|
106886
107035
|
Param: listParams,
|
|
106887
107036
|
});
|
|
107037
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
106888
107038
|
const models = result.Data?.Rows || [];
|
|
106889
107039
|
// 只保留基础字段,list操作不返回Schema
|
|
106890
107040
|
const simplifiedModels = models.map((model) => ({
|
|
@@ -106921,6 +107071,7 @@ function registerDataModelTools(server) {
|
|
|
106921
107071
|
Name: name,
|
|
106922
107072
|
},
|
|
106923
107073
|
});
|
|
107074
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
106924
107075
|
if (!result.Data) {
|
|
106925
107076
|
throw new Error(`数据模型 ${name} 不存在`);
|
|
106926
107077
|
}
|
|
@@ -107125,6 +107276,7 @@ classDiagram
|
|
|
107125
107276
|
EnvId: currentEnvId,
|
|
107126
107277
|
},
|
|
107127
107278
|
});
|
|
107279
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
107128
107280
|
const taskId = result.Data?.TaskId;
|
|
107129
107281
|
if (!taskId) {
|
|
107130
107282
|
return {
|
|
@@ -107155,6 +107307,7 @@ classDiagram
|
|
|
107155
107307
|
TaskId: taskId,
|
|
107156
107308
|
},
|
|
107157
107309
|
});
|
|
107310
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, statusResult);
|
|
107158
107311
|
status = statusResult.Data?.Status || "init";
|
|
107159
107312
|
}
|
|
107160
107313
|
// 返回最终结果
|
|
@@ -114885,8 +115038,10 @@ function registerHostingTools(server) {
|
|
|
114885
115038
|
files,
|
|
114886
115039
|
ignore
|
|
114887
115040
|
});
|
|
115041
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
114888
115042
|
// 获取环境信息
|
|
114889
115043
|
const envInfo = await cloudbase.env.getEnvInfo();
|
|
115044
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, envInfo);
|
|
114890
115045
|
const staticDomain = envInfo.EnvInfo?.StaticStorages?.[0]?.StaticDomain;
|
|
114891
115046
|
const accessUrl = staticDomain ? `https://${staticDomain}/${cloudPath || ''}` : "";
|
|
114892
115047
|
// Send deployment notification to CodeBuddy IDE
|
|
@@ -114960,6 +115115,7 @@ function registerHostingTools(server) {
|
|
|
114960
115115
|
cloudPath,
|
|
114961
115116
|
isDir
|
|
114962
115117
|
});
|
|
115118
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
114963
115119
|
return {
|
|
114964
115120
|
content: [
|
|
114965
115121
|
{
|
|
@@ -114990,6 +115146,7 @@ function registerHostingTools(server) {
|
|
|
114990
115146
|
marker,
|
|
114991
115147
|
maxKeys
|
|
114992
115148
|
});
|
|
115149
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
114993
115150
|
return {
|
|
114994
115151
|
content: [
|
|
114995
115152
|
{
|
|
@@ -115055,6 +115212,7 @@ function registerHostingTools(server) {
|
|
|
115055
115212
|
domain,
|
|
115056
115213
|
certId
|
|
115057
115214
|
});
|
|
115215
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
115058
115216
|
break;
|
|
115059
115217
|
case "delete":
|
|
115060
115218
|
if (!domain) {
|
|
@@ -115063,6 +115221,7 @@ function registerHostingTools(server) {
|
|
|
115063
115221
|
result = await cloudbase.hosting.deleteHostingDomain({
|
|
115064
115222
|
domain
|
|
115065
115223
|
});
|
|
115224
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
115066
115225
|
break;
|
|
115067
115226
|
case "check":
|
|
115068
115227
|
if (!domains || domains.length === 0) {
|
|
@@ -115071,6 +115230,7 @@ function registerHostingTools(server) {
|
|
|
115071
115230
|
result = await cloudbase.hosting.tcbCheckResource({
|
|
115072
115231
|
domains
|
|
115073
115232
|
});
|
|
115233
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
115074
115234
|
break;
|
|
115075
115235
|
case "modify":
|
|
115076
115236
|
if (!domain || domainId === undefined || !domainConfig) {
|
|
@@ -115081,6 +115241,7 @@ function registerHostingTools(server) {
|
|
|
115081
115241
|
domainId,
|
|
115082
115242
|
domainConfig
|
|
115083
115243
|
});
|
|
115244
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
115084
115245
|
break;
|
|
115085
115246
|
default:
|
|
115086
115247
|
throw new Error(`不支持的操作类型: ${action}`);
|
|
@@ -130215,6 +130376,7 @@ function registerInviteCodeTools(server) {
|
|
|
130215
130376
|
Action: 'ActivateInviteCode',
|
|
130216
130377
|
Param: { InviteCode, EnvId }
|
|
130217
130378
|
});
|
|
130379
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
130218
130380
|
return {
|
|
130219
130381
|
content: [
|
|
130220
130382
|
{
|
|
@@ -134861,7 +135023,7 @@ class TelemetryReporter {
|
|
|
134861
135023
|
const nodeVersion = process.version; // Node.js版本
|
|
134862
135024
|
const arch = os_1.default.arch(); // 系统架构
|
|
134863
135025
|
// 从构建时注入的版本号获取MCP版本信息
|
|
134864
|
-
const mcpVersion = process.env.npm_package_version || "2.
|
|
135026
|
+
const mcpVersion = process.env.npm_package_version || "2.4.0" || 0;
|
|
134865
135027
|
return {
|
|
134866
135028
|
userAgent: `${osType} ${osRelease} ${arch} ${nodeVersion} CloudBase-MCP/${mcpVersion}`,
|
|
134867
135029
|
deviceId: this.deviceId,
|
|
@@ -179459,6 +179621,7 @@ exports.sleep = sleep;
|
|
|
179459
179621
|
exports.upperCaseStringFisrt = upperCaseStringFisrt;
|
|
179460
179622
|
exports.upperCaseObjKey = upperCaseObjKey;
|
|
179461
179623
|
exports.fetchTemplates = fetchTemplates;
|
|
179624
|
+
exports.successLog = successLog;
|
|
179462
179625
|
const archiver_1 = __importDefault(__webpack_require__(99133));
|
|
179463
179626
|
const crypto_1 = __importDefault(__webpack_require__(55511));
|
|
179464
179627
|
const fs_extra_1 = __importDefault(__webpack_require__(21605));
|
|
@@ -179737,6 +179900,10 @@ const getCompleteTimeRange = (timeRange) => {
|
|
|
179737
179900
|
};
|
|
179738
179901
|
};
|
|
179739
179902
|
exports.getCompleteTimeRange = getCompleteTimeRange;
|
|
179903
|
+
function successLog(msg) {
|
|
179904
|
+
// 空格,兼容中文字符编码长度问题
|
|
179905
|
+
console.log(`${msg}`);
|
|
179906
|
+
}
|
|
179740
179907
|
|
|
179741
179908
|
|
|
179742
179909
|
/***/ }),
|
|
@@ -185338,6 +185505,7 @@ exports.getClaudePrompt = getClaudePrompt;
|
|
|
185338
185505
|
exports.registerRagTools = registerRagTools;
|
|
185339
185506
|
const adm_zip_1 = __importDefault(__webpack_require__(30283));
|
|
185340
185507
|
const fs = __importStar(__webpack_require__(79748));
|
|
185508
|
+
const lockfile_1 = __importDefault(__webpack_require__(80127));
|
|
185341
185509
|
const os = __importStar(__webpack_require__(21820));
|
|
185342
185510
|
const path = __importStar(__webpack_require__(39902));
|
|
185343
185511
|
const zod_1 = __webpack_require__(21614);
|
|
@@ -185354,7 +185522,39 @@ const KnowledgeBaseIdMap = {
|
|
|
185354
185522
|
// ============ 缓存配置 ============
|
|
185355
185523
|
const CACHE_BASE_DIR = path.join(os.homedir(), ".cloudbase-mcp");
|
|
185356
185524
|
const CACHE_META_FILE = path.join(CACHE_BASE_DIR, "cache-meta.json");
|
|
185525
|
+
const LOCK_FILE = path.join(CACHE_BASE_DIR, ".download.lock");
|
|
185357
185526
|
const DEFAULT_CACHE_TTL_MS = 24 * 60 * 60 * 1000; // 默认 24 小时
|
|
185527
|
+
// Promise wrapper for lockfile methods
|
|
185528
|
+
function acquireLock(lockPath, options) {
|
|
185529
|
+
return new Promise((resolve, reject) => {
|
|
185530
|
+
if (options) {
|
|
185531
|
+
lockfile_1.default.lock(lockPath, options, (err) => {
|
|
185532
|
+
if (err)
|
|
185533
|
+
reject(err);
|
|
185534
|
+
else
|
|
185535
|
+
resolve();
|
|
185536
|
+
});
|
|
185537
|
+
}
|
|
185538
|
+
else {
|
|
185539
|
+
lockfile_1.default.lock(lockPath, (err) => {
|
|
185540
|
+
if (err)
|
|
185541
|
+
reject(err);
|
|
185542
|
+
else
|
|
185543
|
+
resolve();
|
|
185544
|
+
});
|
|
185545
|
+
}
|
|
185546
|
+
});
|
|
185547
|
+
}
|
|
185548
|
+
function releaseLock(lockPath) {
|
|
185549
|
+
return new Promise((resolve, reject) => {
|
|
185550
|
+
lockfile_1.default.unlock(lockPath, (err) => {
|
|
185551
|
+
if (err)
|
|
185552
|
+
reject(err);
|
|
185553
|
+
else
|
|
185554
|
+
resolve();
|
|
185555
|
+
});
|
|
185556
|
+
});
|
|
185557
|
+
}
|
|
185358
185558
|
// 支持环境变量 CLOUDBASE_MCP_CACHE_TTL_MS 控制缓存过期时间(毫秒)
|
|
185359
185559
|
const parsedCacheTTL = process.env.CLOUDBASE_MCP_CACHE_TTL_MS
|
|
185360
185560
|
? parseInt(process.env.CLOUDBASE_MCP_CACHE_TTL_MS, 10)
|
|
@@ -185524,14 +185724,19 @@ async function _doDownloadResources() {
|
|
|
185524
185724
|
async function downloadResources() {
|
|
185525
185725
|
const webTemplateDir = path.join(CACHE_BASE_DIR, "web-template");
|
|
185526
185726
|
const openAPIDir = path.join(CACHE_BASE_DIR, "openapi");
|
|
185527
|
-
//
|
|
185727
|
+
// 如果已有下载任务在进行中,共享该 Promise
|
|
185728
|
+
if (resourceDownloadPromise) {
|
|
185729
|
+
(0, logger_js_1.debug)("[downloadResources] 共享已有下载任务");
|
|
185730
|
+
return resourceDownloadPromise;
|
|
185731
|
+
}
|
|
185732
|
+
// 先快速检查缓存(不需要锁,因为只是读取)
|
|
185528
185733
|
if (await canUseCache()) {
|
|
185529
185734
|
try {
|
|
185530
185735
|
// 检查两个目录都存在
|
|
185531
185736
|
await Promise.all([fs.access(webTemplateDir), fs.access(openAPIDir)]);
|
|
185532
185737
|
const files = await fs.readdir(openAPIDir);
|
|
185533
185738
|
if (files.length > 0) {
|
|
185534
|
-
(0, logger_js_1.debug)("[downloadResources]
|
|
185739
|
+
(0, logger_js_1.debug)("[downloadResources] 使用缓存(快速路径)");
|
|
185535
185740
|
return {
|
|
185536
185741
|
webTemplateDir,
|
|
185537
185742
|
openAPIDocs: OPENAPI_SOURCES.map((source) => ({
|
|
@@ -185546,21 +185751,61 @@ async function downloadResources() {
|
|
|
185546
185751
|
// 缓存无效,需要重新下载
|
|
185547
185752
|
}
|
|
185548
185753
|
}
|
|
185549
|
-
//
|
|
185550
|
-
if (resourceDownloadPromise) {
|
|
185551
|
-
(0, logger_js_1.debug)("[downloadResources] 共享已有下载任务");
|
|
185552
|
-
return resourceDownloadPromise;
|
|
185553
|
-
}
|
|
185554
|
-
// 创建新的下载任务
|
|
185754
|
+
// 创建新的下载任务,使用文件锁保护
|
|
185555
185755
|
(0, logger_js_1.debug)("[downloadResources] 开始新下载任务");
|
|
185556
185756
|
await fs.mkdir(CACHE_BASE_DIR, { recursive: true });
|
|
185557
|
-
resourceDownloadPromise =
|
|
185558
|
-
|
|
185559
|
-
|
|
185560
|
-
|
|
185561
|
-
|
|
185562
|
-
|
|
185563
|
-
|
|
185757
|
+
resourceDownloadPromise = (async () => {
|
|
185758
|
+
// 尝试获取文件锁,最多等待 6 秒(30 次 × 200ms),每 200ms 轮询一次
|
|
185759
|
+
let lockAcquired = false;
|
|
185760
|
+
try {
|
|
185761
|
+
await acquireLock(LOCK_FILE, {
|
|
185762
|
+
wait: 30 * 200, // 总等待时间:6000ms (6 秒)
|
|
185763
|
+
pollPeriod: 200, // 轮询间隔:200ms
|
|
185764
|
+
stale: 5 * 60 * 1000, // 5 分钟,如果锁文件超过这个时间认为是过期的
|
|
185765
|
+
});
|
|
185766
|
+
lockAcquired = true;
|
|
185767
|
+
(0, logger_js_1.debug)("[downloadResources] 文件锁已获取");
|
|
185768
|
+
// 在持有锁的情况下再次检查缓存(可能其他进程已经下载完成)
|
|
185769
|
+
if (await canUseCache()) {
|
|
185770
|
+
try {
|
|
185771
|
+
// 检查两个目录都存在
|
|
185772
|
+
await Promise.all([fs.access(webTemplateDir), fs.access(openAPIDir)]);
|
|
185773
|
+
const files = await fs.readdir(openAPIDir);
|
|
185774
|
+
if (files.length > 0) {
|
|
185775
|
+
(0, logger_js_1.debug)("[downloadResources] 使用缓存(在锁保护下检查)");
|
|
185776
|
+
return {
|
|
185777
|
+
webTemplateDir,
|
|
185778
|
+
openAPIDocs: OPENAPI_SOURCES.map((source) => ({
|
|
185779
|
+
name: source.name,
|
|
185780
|
+
description: source.description,
|
|
185781
|
+
absolutePath: path.join(openAPIDir, `${source.name}.openapi.yaml`),
|
|
185782
|
+
})).filter((item) => files.includes(`${item.name}.openapi.yaml`)),
|
|
185783
|
+
};
|
|
185784
|
+
}
|
|
185785
|
+
}
|
|
185786
|
+
catch {
|
|
185787
|
+
// 缓存无效,需要重新下载
|
|
185788
|
+
}
|
|
185789
|
+
}
|
|
185790
|
+
// 执行下载
|
|
185791
|
+
const result = await _doDownloadResources();
|
|
185792
|
+
await updateCache();
|
|
185793
|
+
(0, logger_js_1.debug)("[downloadResources] 缓存已更新");
|
|
185794
|
+
return result;
|
|
185795
|
+
}
|
|
185796
|
+
finally {
|
|
185797
|
+
// 释放文件锁
|
|
185798
|
+
if (lockAcquired) {
|
|
185799
|
+
try {
|
|
185800
|
+
await releaseLock(LOCK_FILE);
|
|
185801
|
+
(0, logger_js_1.debug)("[downloadResources] 文件锁已释放");
|
|
185802
|
+
}
|
|
185803
|
+
catch (error) {
|
|
185804
|
+
(0, logger_js_1.warn)("[downloadResources] 释放文件锁失败", { error });
|
|
185805
|
+
}
|
|
185806
|
+
}
|
|
185807
|
+
}
|
|
185808
|
+
})().finally(() => {
|
|
185564
185809
|
resourceDownloadPromise = null;
|
|
185565
185810
|
});
|
|
185566
185811
|
return resourceDownloadPromise;
|
|
@@ -191159,20 +191404,25 @@ function callSuccessCallback(callback, result) {
|
|
|
191159
191404
|
/***/ }),
|
|
191160
191405
|
|
|
191161
191406
|
/***/ 65607:
|
|
191162
|
-
/***/ ((__unused_webpack_module, exports) => {
|
|
191407
|
+
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
191163
191408
|
|
|
191164
191409
|
"use strict";
|
|
191165
191410
|
|
|
191166
191411
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
191167
191412
|
exports.CloudBaseContext = void 0;
|
|
191413
|
+
const constant_1 = __webpack_require__(40762);
|
|
191168
191414
|
class CloudBaseContext {
|
|
191169
|
-
constructor({ secretId = '', secretKey = '', token = '', proxy = '', region = '', envType = '' }) {
|
|
191415
|
+
constructor({ secretId = '', secretKey = '', token = '', proxy = '', region = '', envType = '', useInternalEndpoint = undefined }) {
|
|
191170
191416
|
this.secretId = secretId;
|
|
191171
191417
|
this.secretKey = secretKey;
|
|
191172
191418
|
this.token = token;
|
|
191173
191419
|
this.proxy = proxy;
|
|
191174
191420
|
this.region = region;
|
|
191175
191421
|
this.envType = envType;
|
|
191422
|
+
this.useInternalEndpoint = useInternalEndpoint;
|
|
191423
|
+
}
|
|
191424
|
+
isInternalEndpoint() {
|
|
191425
|
+
return this.useInternalEndpoint !== undefined ? this.useInternalEndpoint : constant_1.USE_INTERNAL_ENDPOINT;
|
|
191176
191426
|
}
|
|
191177
191427
|
}
|
|
191178
191428
|
exports.CloudBaseContext = CloudBaseContext;
|
|
@@ -200654,11 +200904,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
200654
200904
|
};
|
|
200655
200905
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
200656
200906
|
exports.wrapServerWithTelemetry = wrapServerWithTelemetry;
|
|
200657
|
-
const
|
|
200658
|
-
const logger_js_1 = __webpack_require__(13039);
|
|
200907
|
+
const os_1 = __importDefault(__webpack_require__(21820));
|
|
200659
200908
|
const cloudbase_manager_js_1 = __webpack_require__(3431);
|
|
200660
200909
|
const cloud_mode_js_1 = __webpack_require__(89684);
|
|
200661
|
-
const
|
|
200910
|
+
const logger_js_1 = __webpack_require__(13039);
|
|
200911
|
+
const telemetry_js_1 = __webpack_require__(45880);
|
|
200662
200912
|
/**
|
|
200663
200913
|
* 生成 GitHub Issue 创建链接
|
|
200664
200914
|
* @param toolName 工具名称
|
|
@@ -200699,7 +200949,7 @@ ${envIdSection}
|
|
|
200699
200949
|
## 环境信息
|
|
200700
200950
|
- 操作系统: ${os_1.default.type()} ${os_1.default.release()}
|
|
200701
200951
|
- Node.js版本: ${process.version}
|
|
200702
|
-
- MCP 版本:${process.env.npm_package_version || "2.
|
|
200952
|
+
- MCP 版本:${process.env.npm_package_version || "2.4.0" || 0}
|
|
200703
200953
|
- 系统架构: ${os_1.default.arch()}
|
|
200704
200954
|
- 时间: ${new Date().toISOString()}
|
|
200705
200955
|
- 请求ID: ${requestId}
|
|
@@ -200737,10 +200987,13 @@ function createWrappedHandler(name, handler, server) {
|
|
|
200737
200987
|
let requestId;
|
|
200738
200988
|
try {
|
|
200739
200989
|
(0, logger_js_1.debug)(`开始执行工具: ${name}`, { args: sanitizeArgs(args) });
|
|
200990
|
+
server.logger?.({ type: 'beforeToolCall', toolName: name, args: sanitizeArgs(args) });
|
|
200740
200991
|
// 执行原始处理函数
|
|
200741
200992
|
const result = await handler(args);
|
|
200742
200993
|
success = true;
|
|
200743
|
-
|
|
200994
|
+
const duration = Date.now() - startTime;
|
|
200995
|
+
(0, logger_js_1.debug)(`工具执行成功: ${name}`, { duration });
|
|
200996
|
+
server.logger?.({ type: 'afterToolCall', toolName: name, args: sanitizeArgs(args), result: result, duration });
|
|
200744
200997
|
return result;
|
|
200745
200998
|
}
|
|
200746
200999
|
catch (error) {
|
|
@@ -200751,6 +201004,7 @@ function createWrappedHandler(name, handler, server) {
|
|
|
200751
201004
|
error: errorMessage,
|
|
200752
201005
|
duration: Date.now() - startTime
|
|
200753
201006
|
});
|
|
201007
|
+
server.logger?.({ type: 'errorToolCall', toolName: name, args: sanitizeArgs(args), message: errorMessage, duration: Date.now() - startTime });
|
|
200754
201008
|
// 生成 GitHub Issue 创建链接
|
|
200755
201009
|
const issueLink = await generateGitHubIssueLink(name, errorMessage, args, server.cloudBaseOptions, {
|
|
200756
201010
|
requestId: (typeof error === 'object' && error && 'requestId' in error) ? error.requestId : '',
|
|
@@ -203591,6 +203845,7 @@ class StorageService {
|
|
|
203591
203845
|
* 获取 COS 配置
|
|
203592
203846
|
*/
|
|
203593
203847
|
getCos(parallel = 20) {
|
|
203848
|
+
const internalEndpoint = this.environment.cloudBaseContext.isInternalEndpoint();
|
|
203594
203849
|
const { secretId, secretKey, token, proxy } = this.environment.getAuthConfig();
|
|
203595
203850
|
const cosProxy = process.env.TCB_COS_PROXY;
|
|
203596
203851
|
const cosConfig = {
|
|
@@ -203599,14 +203854,14 @@ class StorageService {
|
|
|
203599
203854
|
SecretKey: secretKey,
|
|
203600
203855
|
Proxy: cosProxy || proxy,
|
|
203601
203856
|
SecurityToken: token,
|
|
203602
|
-
Domain:
|
|
203857
|
+
Domain: internalEndpoint ? "{Bucket}.cos-internal.{Region}.tencentcos.cn" /* COS_ENDPOINT.INTERNAL */ : "{Bucket}.cos.{Region}.tencentcos.cn" /* COS_ENDPOINT.PUBLIC */,
|
|
203603
203858
|
};
|
|
203604
203859
|
if (constant_1.COS_SDK_PROTOCOL) {
|
|
203605
203860
|
cosConfig.Protocol = (constant_1.COS_SDK_PROTOCOL.endsWith(':')
|
|
203606
203861
|
? constant_1.COS_SDK_PROTOCOL.toLowerCase()
|
|
203607
203862
|
: constant_1.COS_SDK_PROTOCOL.toLowerCase() + ':');
|
|
203608
203863
|
}
|
|
203609
|
-
if (
|
|
203864
|
+
if (internalEndpoint) {
|
|
203610
203865
|
cosConfig.Protocol = 'http:';
|
|
203611
203866
|
}
|
|
203612
203867
|
// COSSDK 默认开启 KeepAlive,这里提供关闭的方式
|
|
@@ -208655,6 +208910,7 @@ async function getDatabaseInstanceId(getManager) {
|
|
|
208655
208910
|
function registerDatabaseTools(server) {
|
|
208656
208911
|
// 获取 cloudBaseOptions,如果没有则为 undefined
|
|
208657
208912
|
const cloudBaseOptions = server.cloudBaseOptions;
|
|
208913
|
+
const logger = server.logger;
|
|
208658
208914
|
// 创建闭包函数来获取 CloudBase Manager
|
|
208659
208915
|
const getManager = () => (0, cloudbase_manager_js_1.getCloudBaseManager)({ cloudBaseOptions });
|
|
208660
208916
|
// readNoSqlDatabaseStructure
|
|
@@ -208702,6 +208958,7 @@ checkIndex: 检查索引是否存在`),
|
|
|
208702
208958
|
MgoOffset: offset,
|
|
208703
208959
|
MgoLimit: limit,
|
|
208704
208960
|
});
|
|
208961
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
208705
208962
|
return {
|
|
208706
208963
|
content: [
|
|
208707
208964
|
{
|
|
@@ -208722,6 +208979,7 @@ checkIndex: 检查索引是否存在`),
|
|
|
208722
208979
|
throw new Error("检查集合时必须提供 collectionName");
|
|
208723
208980
|
}
|
|
208724
208981
|
const result = await cloudbase.database.checkCollectionExists(collectionName);
|
|
208982
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
208725
208983
|
return {
|
|
208726
208984
|
content: [
|
|
208727
208985
|
{
|
|
@@ -208743,6 +209001,7 @@ checkIndex: 检查索引是否存在`),
|
|
|
208743
209001
|
throw new Error("查看集合详情时必须提供 collectionName");
|
|
208744
209002
|
}
|
|
208745
209003
|
const result = await cloudbase.database.describeCollection(collectionName);
|
|
209004
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
208746
209005
|
return {
|
|
208747
209006
|
content: [
|
|
208748
209007
|
{
|
|
@@ -208763,6 +209022,7 @@ checkIndex: 检查索引是否存在`),
|
|
|
208763
209022
|
throw new Error("获取索引列表时必须提供 collectionName");
|
|
208764
209023
|
}
|
|
208765
209024
|
const result = await cloudbase.database.describeCollection(collectionName);
|
|
209025
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
208766
209026
|
return {
|
|
208767
209027
|
content: [
|
|
208768
209028
|
{
|
|
@@ -208783,6 +209043,7 @@ checkIndex: 检查索引是否存在`),
|
|
|
208783
209043
|
throw new Error("检查索引时必须提供 collectionName 和 indexName");
|
|
208784
209044
|
}
|
|
208785
209045
|
const result = await cloudbase.database.checkIndexExists(collectionName, indexName);
|
|
209046
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
208786
209047
|
return {
|
|
208787
209048
|
content: [
|
|
208788
209049
|
{
|
|
@@ -208843,6 +209104,7 @@ updateCollection: 更新集合`),
|
|
|
208843
209104
|
const cloudbase = await getManager();
|
|
208844
209105
|
if (action === "createCollection") {
|
|
208845
209106
|
const result = await cloudbase.database.createCollection(collectionName);
|
|
209107
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
208846
209108
|
return {
|
|
208847
209109
|
content: [
|
|
208848
209110
|
{
|
|
@@ -208862,6 +209124,7 @@ updateCollection: 更新集合`),
|
|
|
208862
209124
|
throw new Error("更新集合时必须提供 options");
|
|
208863
209125
|
}
|
|
208864
209126
|
const result = await cloudbase.database.updateCollection(collectionName, updateOptions);
|
|
209127
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
208865
209128
|
return {
|
|
208866
209129
|
content: [
|
|
208867
209130
|
{
|
|
@@ -208938,6 +209201,7 @@ updateCollection: 更新集合`),
|
|
|
208938
209201
|
Tag: instanceId,
|
|
208939
209202
|
},
|
|
208940
209203
|
});
|
|
209204
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
208941
209205
|
return {
|
|
208942
209206
|
content: [
|
|
208943
209207
|
{
|
|
@@ -209015,6 +209279,7 @@ deleteCollection: 删除数据`),
|
|
|
209015
209279
|
collectionName,
|
|
209016
209280
|
documents,
|
|
209017
209281
|
getManager,
|
|
209282
|
+
logger,
|
|
209018
209283
|
});
|
|
209019
209284
|
return {
|
|
209020
209285
|
content: [
|
|
@@ -209039,6 +209304,7 @@ deleteCollection: 删除数据`),
|
|
|
209039
209304
|
isMulti,
|
|
209040
209305
|
upsert,
|
|
209041
209306
|
getManager,
|
|
209307
|
+
logger,
|
|
209042
209308
|
});
|
|
209043
209309
|
return {
|
|
209044
209310
|
content: [
|
|
@@ -209058,6 +209324,7 @@ deleteCollection: 删除数据`),
|
|
|
209058
209324
|
query,
|
|
209059
209325
|
isMulti,
|
|
209060
209326
|
getManager,
|
|
209327
|
+
logger,
|
|
209061
209328
|
});
|
|
209062
209329
|
return {
|
|
209063
209330
|
content: [
|
|
@@ -209071,7 +209338,7 @@ deleteCollection: 删除数据`),
|
|
|
209071
209338
|
throw new Error(`不支持的操作类型: ${action}`);
|
|
209072
209339
|
});
|
|
209073
209340
|
}
|
|
209074
|
-
async function insertDocuments({ collectionName, documents, getManager, }) {
|
|
209341
|
+
async function insertDocuments({ collectionName, documents, getManager, logger, }) {
|
|
209075
209342
|
try {
|
|
209076
209343
|
const cloudbase = await getManager();
|
|
209077
209344
|
const instanceId = await getDatabaseInstanceId(getManager);
|
|
@@ -209085,6 +209352,7 @@ async function insertDocuments({ collectionName, documents, getManager, }) {
|
|
|
209085
209352
|
Tag: instanceId,
|
|
209086
209353
|
},
|
|
209087
209354
|
});
|
|
209355
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(logger, result);
|
|
209088
209356
|
return JSON.stringify({
|
|
209089
209357
|
success: true,
|
|
209090
209358
|
requestId: result.RequestId,
|
|
@@ -209100,7 +209368,7 @@ async function insertDocuments({ collectionName, documents, getManager, }) {
|
|
|
209100
209368
|
}, null, 2);
|
|
209101
209369
|
}
|
|
209102
209370
|
}
|
|
209103
|
-
async function updateDocuments({ collectionName, query, update, isMulti, upsert, getManager, }) {
|
|
209371
|
+
async function updateDocuments({ collectionName, query, update, isMulti, upsert, getManager, logger, }) {
|
|
209104
209372
|
try {
|
|
209105
209373
|
const cloudbase = await getManager();
|
|
209106
209374
|
const instanceId = await getDatabaseInstanceId(getManager);
|
|
@@ -209116,6 +209384,7 @@ async function updateDocuments({ collectionName, query, update, isMulti, upsert,
|
|
|
209116
209384
|
Tag: instanceId,
|
|
209117
209385
|
},
|
|
209118
209386
|
});
|
|
209387
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(logger, result);
|
|
209119
209388
|
return JSON.stringify({
|
|
209120
209389
|
success: true,
|
|
209121
209390
|
requestId: result.RequestId,
|
|
@@ -209133,7 +209402,7 @@ async function updateDocuments({ collectionName, query, update, isMulti, upsert,
|
|
|
209133
209402
|
}, null, 2);
|
|
209134
209403
|
}
|
|
209135
209404
|
}
|
|
209136
|
-
async function deleteDocuments({ collectionName, query, isMulti, getManager, }) {
|
|
209405
|
+
async function deleteDocuments({ collectionName, query, isMulti, getManager, logger, }) {
|
|
209137
209406
|
try {
|
|
209138
209407
|
const cloudbase = await getManager();
|
|
209139
209408
|
const instanceId = await getDatabaseInstanceId(getManager);
|
|
@@ -209147,6 +209416,7 @@ async function deleteDocuments({ collectionName, query, isMulti, getManager, })
|
|
|
209147
209416
|
Tag: instanceId,
|
|
209148
209417
|
},
|
|
209149
209418
|
});
|
|
209419
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(logger, result);
|
|
209150
209420
|
return JSON.stringify({
|
|
209151
209421
|
success: true,
|
|
209152
209422
|
requestId: result.RequestId,
|
|
@@ -215040,6 +215310,7 @@ const IDE_TYPES = [
|
|
|
215040
215310
|
"qoder", // Qoder AI编辑器
|
|
215041
215311
|
"antigravity", // Google Antigravity AI编辑器
|
|
215042
215312
|
"vscode", // Visual Studio Code
|
|
215313
|
+
"kiro", // Kiro AI编辑器
|
|
215043
215314
|
];
|
|
215044
215315
|
// IDE到文件的映射关系
|
|
215045
215316
|
// 注意:以 "/" 结尾的路径表示目录,会包含该目录下的所有文件
|
|
@@ -215073,6 +215344,7 @@ const IDE_FILE_MAPPINGS = {
|
|
|
215073
215344
|
qoder: [".qoder/rules/"],
|
|
215074
215345
|
antigravity: [".agent/rules/"],
|
|
215075
215346
|
vscode: [".vscode/mcp.json", ".vscode/settings.json"],
|
|
215347
|
+
kiro: [".kiro/settings/mcp.json", ".kiro/steering/"],
|
|
215076
215348
|
};
|
|
215077
215349
|
// 所有IDE配置文件的完整列表 - 通过IDE_FILE_MAPPINGS计算得出
|
|
215078
215350
|
const ALL_IDE_FILES = Array.from(new Set(Object.values(IDE_FILE_MAPPINGS).flat()));
|
|
@@ -215099,6 +215371,7 @@ const IDE_DESCRIPTIONS = {
|
|
|
215099
215371
|
qoder: "Qoder AI编辑器",
|
|
215100
215372
|
antigravity: "Google Antigravity AI编辑器",
|
|
215101
215373
|
vscode: "Visual Studio Code",
|
|
215374
|
+
kiro: "Kiro AI编辑器",
|
|
215102
215375
|
};
|
|
215103
215376
|
// INTEGRATION_IDE 环境变量值到 IDE 类型的映射
|
|
215104
215377
|
const INTEGRATION_IDE_MAPPING = {
|
|
@@ -215122,6 +215395,7 @@ const INTEGRATION_IDE_MAPPING = {
|
|
|
215122
215395
|
Qoder: "qoder",
|
|
215123
215396
|
Antigravity: "antigravity",
|
|
215124
215397
|
VSCode: "vscode",
|
|
215398
|
+
Kiro: "kiro",
|
|
215125
215399
|
};
|
|
215126
215400
|
// 根据 INTEGRATION_IDE 环境变量获取默认 IDE 类型
|
|
215127
215401
|
function getDefaultIDEFromEnv() {
|
|
@@ -215344,7 +215618,7 @@ function registerSetupTools(server) {
|
|
|
215344
215618
|
title: "下载项目模板",
|
|
215345
215619
|
description: `自动下载并部署CloudBase项目模板。⚠️ **MANDATORY FOR NEW PROJECTS** ⚠️
|
|
215346
215620
|
|
|
215347
|
-
**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.
|
|
215621
|
+
**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" : 0}),便于后续维护和版本追踪\n- 下载 rules 模板时,如果项目中已存在 README.md 文件,系统会自动保护该文件不被覆盖(除非设置 overwrite=true)`,
|
|
215348
215622
|
inputSchema: {
|
|
215349
215623
|
template: zod_1.z
|
|
215350
215624
|
.enum(["react", "vue", "miniprogram", "uniapp", "rules"])
|
|
@@ -224435,6 +224709,333 @@ function resolveIds(schema) {
|
|
|
224435
224709
|
}
|
|
224436
224710
|
|
|
224437
224711
|
|
|
224712
|
+
/***/ }),
|
|
224713
|
+
|
|
224714
|
+
/***/ 80127:
|
|
224715
|
+
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
224716
|
+
|
|
224717
|
+
var fs = __webpack_require__(29021)
|
|
224718
|
+
|
|
224719
|
+
var wx = 'wx'
|
|
224720
|
+
if (process.version.match(/^v0\.[0-6]/)) {
|
|
224721
|
+
var c = __webpack_require__(81115)
|
|
224722
|
+
wx = c.O_TRUNC | c.O_CREAT | c.O_WRONLY | c.O_EXCL
|
|
224723
|
+
}
|
|
224724
|
+
|
|
224725
|
+
var os = __webpack_require__(21820)
|
|
224726
|
+
exports.filetime = 'ctime'
|
|
224727
|
+
if (os.platform() == "win32") {
|
|
224728
|
+
exports.filetime = 'mtime'
|
|
224729
|
+
}
|
|
224730
|
+
|
|
224731
|
+
var debug
|
|
224732
|
+
var util = __webpack_require__(28354)
|
|
224733
|
+
if (util.debuglog)
|
|
224734
|
+
debug = util.debuglog('LOCKFILE')
|
|
224735
|
+
else if (/\blockfile\b/i.test(process.env.NODE_DEBUG))
|
|
224736
|
+
debug = function() {
|
|
224737
|
+
var msg = util.format.apply(util, arguments)
|
|
224738
|
+
console.error('LOCKFILE %d %s', process.pid, msg)
|
|
224739
|
+
}
|
|
224740
|
+
else
|
|
224741
|
+
debug = function() {}
|
|
224742
|
+
|
|
224743
|
+
var locks = {}
|
|
224744
|
+
|
|
224745
|
+
function hasOwnProperty (obj, prop) {
|
|
224746
|
+
return Object.prototype.hasOwnProperty.call(obj, prop)
|
|
224747
|
+
}
|
|
224748
|
+
|
|
224749
|
+
var onExit = __webpack_require__(29468)
|
|
224750
|
+
onExit(function () {
|
|
224751
|
+
debug('exit listener')
|
|
224752
|
+
// cleanup
|
|
224753
|
+
Object.keys(locks).forEach(exports.unlockSync)
|
|
224754
|
+
})
|
|
224755
|
+
|
|
224756
|
+
// XXX https://github.com/joyent/node/issues/3555
|
|
224757
|
+
// Remove when node 0.8 is deprecated.
|
|
224758
|
+
if (/^v0\.[0-8]\./.test(process.version)) {
|
|
224759
|
+
debug('uncaughtException, version = %s', process.version)
|
|
224760
|
+
process.on('uncaughtException', function H (er) {
|
|
224761
|
+
debug('uncaughtException')
|
|
224762
|
+
var l = process.listeners('uncaughtException').filter(function (h) {
|
|
224763
|
+
return h !== H
|
|
224764
|
+
})
|
|
224765
|
+
if (!l.length) {
|
|
224766
|
+
// cleanup
|
|
224767
|
+
try { Object.keys(locks).forEach(exports.unlockSync) } catch (e) {}
|
|
224768
|
+
process.removeListener('uncaughtException', H)
|
|
224769
|
+
throw er
|
|
224770
|
+
}
|
|
224771
|
+
})
|
|
224772
|
+
}
|
|
224773
|
+
|
|
224774
|
+
exports.unlock = function (path, cb) {
|
|
224775
|
+
debug('unlock', path)
|
|
224776
|
+
// best-effort. unlocking an already-unlocked lock is a noop
|
|
224777
|
+
delete locks[path]
|
|
224778
|
+
fs.unlink(path, function (unlinkEr) { cb && cb() })
|
|
224779
|
+
}
|
|
224780
|
+
|
|
224781
|
+
exports.unlockSync = function (path) {
|
|
224782
|
+
debug('unlockSync', path)
|
|
224783
|
+
// best-effort. unlocking an already-unlocked lock is a noop
|
|
224784
|
+
try { fs.unlinkSync(path) } catch (er) {}
|
|
224785
|
+
delete locks[path]
|
|
224786
|
+
}
|
|
224787
|
+
|
|
224788
|
+
|
|
224789
|
+
// if the file can be opened in readonly mode, then it's there.
|
|
224790
|
+
// if the error is something other than ENOENT, then it's not.
|
|
224791
|
+
exports.check = function (path, opts, cb) {
|
|
224792
|
+
if (typeof opts === 'function') cb = opts, opts = {}
|
|
224793
|
+
debug('check', path, opts)
|
|
224794
|
+
fs.open(path, 'r', function (er, fd) {
|
|
224795
|
+
if (er) {
|
|
224796
|
+
if (er.code !== 'ENOENT') return cb(er)
|
|
224797
|
+
return cb(null, false)
|
|
224798
|
+
}
|
|
224799
|
+
|
|
224800
|
+
if (!opts.stale) {
|
|
224801
|
+
return fs.close(fd, function (er) {
|
|
224802
|
+
return cb(er, true)
|
|
224803
|
+
})
|
|
224804
|
+
}
|
|
224805
|
+
|
|
224806
|
+
fs.fstat(fd, function (er, st) {
|
|
224807
|
+
if (er) return fs.close(fd, function (er2) {
|
|
224808
|
+
return cb(er)
|
|
224809
|
+
})
|
|
224810
|
+
|
|
224811
|
+
fs.close(fd, function (er) {
|
|
224812
|
+
var age = Date.now() - st[exports.filetime].getTime()
|
|
224813
|
+
return cb(er, age <= opts.stale)
|
|
224814
|
+
})
|
|
224815
|
+
})
|
|
224816
|
+
})
|
|
224817
|
+
}
|
|
224818
|
+
|
|
224819
|
+
exports.checkSync = function (path, opts) {
|
|
224820
|
+
opts = opts || {}
|
|
224821
|
+
debug('checkSync', path, opts)
|
|
224822
|
+
if (opts.wait) {
|
|
224823
|
+
throw new Error('opts.wait not supported sync for obvious reasons')
|
|
224824
|
+
}
|
|
224825
|
+
|
|
224826
|
+
try {
|
|
224827
|
+
var fd = fs.openSync(path, 'r')
|
|
224828
|
+
} catch (er) {
|
|
224829
|
+
if (er.code !== 'ENOENT') throw er
|
|
224830
|
+
return false
|
|
224831
|
+
}
|
|
224832
|
+
|
|
224833
|
+
if (!opts.stale) {
|
|
224834
|
+
try { fs.closeSync(fd) } catch (er) {}
|
|
224835
|
+
return true
|
|
224836
|
+
}
|
|
224837
|
+
|
|
224838
|
+
// file exists. however, might be stale
|
|
224839
|
+
if (opts.stale) {
|
|
224840
|
+
try {
|
|
224841
|
+
var st = fs.fstatSync(fd)
|
|
224842
|
+
} finally {
|
|
224843
|
+
fs.closeSync(fd)
|
|
224844
|
+
}
|
|
224845
|
+
var age = Date.now() - st[exports.filetime].getTime()
|
|
224846
|
+
return (age <= opts.stale)
|
|
224847
|
+
}
|
|
224848
|
+
}
|
|
224849
|
+
|
|
224850
|
+
|
|
224851
|
+
|
|
224852
|
+
var req = 1
|
|
224853
|
+
exports.lock = function (path, opts, cb) {
|
|
224854
|
+
if (typeof opts === 'function') cb = opts, opts = {}
|
|
224855
|
+
opts.req = opts.req || req++
|
|
224856
|
+
debug('lock', path, opts)
|
|
224857
|
+
opts.start = opts.start || Date.now()
|
|
224858
|
+
|
|
224859
|
+
if (typeof opts.retries === 'number' && opts.retries > 0) {
|
|
224860
|
+
debug('has retries', opts.retries)
|
|
224861
|
+
var retries = opts.retries
|
|
224862
|
+
opts.retries = 0
|
|
224863
|
+
cb = (function (orig) { return function cb (er, fd) {
|
|
224864
|
+
debug('retry-mutated callback')
|
|
224865
|
+
retries -= 1
|
|
224866
|
+
if (!er || retries < 0) return orig(er, fd)
|
|
224867
|
+
|
|
224868
|
+
debug('lock retry', path, opts)
|
|
224869
|
+
|
|
224870
|
+
if (opts.retryWait) setTimeout(retry, opts.retryWait)
|
|
224871
|
+
else retry()
|
|
224872
|
+
|
|
224873
|
+
function retry () {
|
|
224874
|
+
opts.start = Date.now()
|
|
224875
|
+
debug('retrying', opts.start)
|
|
224876
|
+
exports.lock(path, opts, cb)
|
|
224877
|
+
}
|
|
224878
|
+
}})(cb)
|
|
224879
|
+
}
|
|
224880
|
+
|
|
224881
|
+
// try to engage the lock.
|
|
224882
|
+
// if this succeeds, then we're in business.
|
|
224883
|
+
fs.open(path, wx, function (er, fd) {
|
|
224884
|
+
if (!er) {
|
|
224885
|
+
debug('locked', path, fd)
|
|
224886
|
+
locks[path] = fd
|
|
224887
|
+
return fs.close(fd, function () {
|
|
224888
|
+
return cb()
|
|
224889
|
+
})
|
|
224890
|
+
}
|
|
224891
|
+
|
|
224892
|
+
debug('failed to acquire lock', er)
|
|
224893
|
+
|
|
224894
|
+
// something other than "currently locked"
|
|
224895
|
+
// maybe eperm or something.
|
|
224896
|
+
if (er.code !== 'EEXIST') {
|
|
224897
|
+
debug('not EEXIST error', er)
|
|
224898
|
+
return cb(er)
|
|
224899
|
+
}
|
|
224900
|
+
|
|
224901
|
+
// someone's got this one. see if it's valid.
|
|
224902
|
+
if (!opts.stale) return notStale(er, path, opts, cb)
|
|
224903
|
+
|
|
224904
|
+
return maybeStale(er, path, opts, false, cb)
|
|
224905
|
+
})
|
|
224906
|
+
debug('lock return')
|
|
224907
|
+
}
|
|
224908
|
+
|
|
224909
|
+
|
|
224910
|
+
// Staleness checking algorithm
|
|
224911
|
+
// 1. acquire $lock, fail
|
|
224912
|
+
// 2. stat $lock, find that it is stale
|
|
224913
|
+
// 3. acquire $lock.STALE
|
|
224914
|
+
// 4. stat $lock, assert that it is still stale
|
|
224915
|
+
// 5. unlink $lock
|
|
224916
|
+
// 6. link $lock.STALE $lock
|
|
224917
|
+
// 7. unlink $lock.STALE
|
|
224918
|
+
// On any failure, clean up whatever we've done, and raise the error.
|
|
224919
|
+
function maybeStale (originalEr, path, opts, hasStaleLock, cb) {
|
|
224920
|
+
fs.stat(path, function (statEr, st) {
|
|
224921
|
+
if (statEr) {
|
|
224922
|
+
if (statEr.code === 'ENOENT') {
|
|
224923
|
+
// expired already!
|
|
224924
|
+
opts.stale = false
|
|
224925
|
+
debug('lock stale enoent retry', path, opts)
|
|
224926
|
+
exports.lock(path, opts, cb)
|
|
224927
|
+
return
|
|
224928
|
+
}
|
|
224929
|
+
return cb(statEr)
|
|
224930
|
+
}
|
|
224931
|
+
|
|
224932
|
+
var age = Date.now() - st[exports.filetime].getTime()
|
|
224933
|
+
if (age <= opts.stale) return notStale(originalEr, path, opts, cb)
|
|
224934
|
+
|
|
224935
|
+
debug('lock stale', path, opts)
|
|
224936
|
+
if (hasStaleLock) {
|
|
224937
|
+
exports.unlock(path, function (er) {
|
|
224938
|
+
if (er) return cb(er)
|
|
224939
|
+
debug('lock stale retry', path, opts)
|
|
224940
|
+
fs.link(path + '.STALE', path, function (er) {
|
|
224941
|
+
fs.unlink(path + '.STALE', function () {
|
|
224942
|
+
// best effort. if the unlink fails, oh well.
|
|
224943
|
+
cb(er)
|
|
224944
|
+
})
|
|
224945
|
+
})
|
|
224946
|
+
})
|
|
224947
|
+
} else {
|
|
224948
|
+
debug('acquire .STALE file lock', opts)
|
|
224949
|
+
exports.lock(path + '.STALE', opts, function (er) {
|
|
224950
|
+
if (er) return cb(er)
|
|
224951
|
+
maybeStale(originalEr, path, opts, true, cb)
|
|
224952
|
+
})
|
|
224953
|
+
}
|
|
224954
|
+
})
|
|
224955
|
+
}
|
|
224956
|
+
|
|
224957
|
+
function notStale (er, path, opts, cb) {
|
|
224958
|
+
debug('notStale', path, opts)
|
|
224959
|
+
|
|
224960
|
+
// if we can't wait, then just call it a failure
|
|
224961
|
+
if (typeof opts.wait !== 'number' || opts.wait <= 0) {
|
|
224962
|
+
debug('notStale, wait is not a number')
|
|
224963
|
+
return cb(er)
|
|
224964
|
+
}
|
|
224965
|
+
|
|
224966
|
+
// poll for some ms for the lock to clear
|
|
224967
|
+
var now = Date.now()
|
|
224968
|
+
var start = opts.start || now
|
|
224969
|
+
var end = start + opts.wait
|
|
224970
|
+
|
|
224971
|
+
if (end <= now)
|
|
224972
|
+
return cb(er)
|
|
224973
|
+
|
|
224974
|
+
debug('now=%d, wait until %d (delta=%d)', start, end, end-start)
|
|
224975
|
+
var wait = Math.min(end - start, opts.pollPeriod || 100)
|
|
224976
|
+
var timer = setTimeout(poll, wait)
|
|
224977
|
+
|
|
224978
|
+
function poll () {
|
|
224979
|
+
debug('notStale, polling', path, opts)
|
|
224980
|
+
exports.lock(path, opts, cb)
|
|
224981
|
+
}
|
|
224982
|
+
}
|
|
224983
|
+
|
|
224984
|
+
exports.lockSync = function (path, opts) {
|
|
224985
|
+
opts = opts || {}
|
|
224986
|
+
opts.req = opts.req || req++
|
|
224987
|
+
debug('lockSync', path, opts)
|
|
224988
|
+
if (opts.wait || opts.retryWait) {
|
|
224989
|
+
throw new Error('opts.wait not supported sync for obvious reasons')
|
|
224990
|
+
}
|
|
224991
|
+
|
|
224992
|
+
try {
|
|
224993
|
+
var fd = fs.openSync(path, wx)
|
|
224994
|
+
locks[path] = fd
|
|
224995
|
+
try { fs.closeSync(fd) } catch (er) {}
|
|
224996
|
+
debug('locked sync!', path, fd)
|
|
224997
|
+
return
|
|
224998
|
+
} catch (er) {
|
|
224999
|
+
if (er.code !== 'EEXIST') return retryThrow(path, opts, er)
|
|
225000
|
+
|
|
225001
|
+
if (opts.stale) {
|
|
225002
|
+
var st = fs.statSync(path)
|
|
225003
|
+
var ct = st[exports.filetime].getTime()
|
|
225004
|
+
if (!(ct % 1000) && (opts.stale % 1000)) {
|
|
225005
|
+
// probably don't have subsecond resolution.
|
|
225006
|
+
// round up the staleness indicator.
|
|
225007
|
+
// Yes, this will be wrong 1/1000 times on platforms
|
|
225008
|
+
// with subsecond stat precision, but that's acceptable
|
|
225009
|
+
// in exchange for not mistakenly removing locks on
|
|
225010
|
+
// most other systems.
|
|
225011
|
+
opts.stale = 1000 * Math.ceil(opts.stale / 1000)
|
|
225012
|
+
}
|
|
225013
|
+
var age = Date.now() - ct
|
|
225014
|
+
if (age > opts.stale) {
|
|
225015
|
+
debug('lockSync stale', path, opts, age)
|
|
225016
|
+
exports.unlockSync(path)
|
|
225017
|
+
return exports.lockSync(path, opts)
|
|
225018
|
+
}
|
|
225019
|
+
}
|
|
225020
|
+
|
|
225021
|
+
// failed to lock!
|
|
225022
|
+
debug('failed to lock', path, opts, er)
|
|
225023
|
+
return retryThrow(path, opts, er)
|
|
225024
|
+
}
|
|
225025
|
+
}
|
|
225026
|
+
|
|
225027
|
+
function retryThrow (path, opts, er) {
|
|
225028
|
+
if (typeof opts.retries === 'number' && opts.retries > 0) {
|
|
225029
|
+
var newRT = opts.retries - 1
|
|
225030
|
+
debug('retryThrow', path, opts, newRT)
|
|
225031
|
+
opts.retries = newRT
|
|
225032
|
+
return exports.lockSync(path, opts)
|
|
225033
|
+
}
|
|
225034
|
+
throw er
|
|
225035
|
+
}
|
|
225036
|
+
|
|
225037
|
+
|
|
225038
|
+
|
|
224438
225039
|
/***/ }),
|
|
224439
225040
|
|
|
224440
225041
|
/***/ 80280:
|
|
@@ -226446,6 +227047,7 @@ class CloudService {
|
|
|
226446
227047
|
this.cloudBaseContext = context;
|
|
226447
227048
|
}
|
|
226448
227049
|
get baseUrl() {
|
|
227050
|
+
const internalEndpoint = this.cloudBaseContext.isInternalEndpoint();
|
|
226449
227051
|
const tcb = process.env.TCB_BASE_URL || 'https://tcb.tencentcloudapi.com';
|
|
226450
227052
|
const urlMap = {
|
|
226451
227053
|
tcb,
|
|
@@ -226459,7 +227061,7 @@ class CloudService {
|
|
|
226459
227061
|
const intranetUrlMap = Object.keys(urlMap).map((service) => ({
|
|
226460
227062
|
[service]: `https://${service}.internal.tencentcloudapi.com`,
|
|
226461
227063
|
})).reduce((acc, cur) => (Object.assign(Object.assign({}, acc), cur)), {});
|
|
226462
|
-
if (
|
|
227064
|
+
if (internalEndpoint) {
|
|
226463
227065
|
return intranetUrlMap[this.service];
|
|
226464
227066
|
}
|
|
226465
227067
|
if (urlMap[this.service]) {
|
|
@@ -233253,6 +233855,7 @@ function registerGatewayTools(server) {
|
|
|
233253
233855
|
name,
|
|
233254
233856
|
path
|
|
233255
233857
|
});
|
|
233858
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
233256
233859
|
return {
|
|
233257
233860
|
content: [
|
|
233258
233861
|
{
|
|
@@ -270092,7 +270695,7 @@ class CloudBase {
|
|
|
270092
270695
|
}
|
|
270093
270696
|
constructor(config = {}) {
|
|
270094
270697
|
this.cloudBaseConfig = {};
|
|
270095
|
-
let { secretId, secretKey, token, envId, proxy, region, envType } = config;
|
|
270698
|
+
let { secretId, secretKey, token, envId, proxy, region, envType, useInternalEndpoint } = config;
|
|
270096
270699
|
// config 中传入的 secretId secretkey 必须同时存在
|
|
270097
270700
|
if ((secretId && !secretKey) || (!secretId && secretKey)) {
|
|
270098
270701
|
throw new Error('secretId and secretKey must be a pair');
|
|
@@ -270104,7 +270707,8 @@ class CloudBase {
|
|
|
270104
270707
|
envId,
|
|
270105
270708
|
envType,
|
|
270106
270709
|
proxy,
|
|
270107
|
-
region
|
|
270710
|
+
region,
|
|
270711
|
+
useInternalEndpoint
|
|
270108
270712
|
};
|
|
270109
270713
|
// 初始化 context
|
|
270110
270714
|
this.context = new context_1.CloudBaseContext(this.cloudBaseConfig);
|
|
@@ -270159,6 +270763,9 @@ class CloudBase {
|
|
|
270159
270763
|
getManagerConfig() {
|
|
270160
270764
|
return this.cloudBaseConfig;
|
|
270161
270765
|
}
|
|
270766
|
+
get isInternalEndpoint() {
|
|
270767
|
+
return this.context.isInternalEndpoint();
|
|
270768
|
+
}
|
|
270162
270769
|
}
|
|
270163
270770
|
module.exports = CloudBase;
|
|
270164
270771
|
|
|
@@ -272237,6 +272844,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
|
272237
272844
|
exports.FunctionService = void 0;
|
|
272238
272845
|
const fs_1 = __importDefault(__webpack_require__(29021));
|
|
272239
272846
|
const path_1 = __importDefault(__webpack_require__(39902));
|
|
272847
|
+
const lodash_1 = __importDefault(__webpack_require__(2543));
|
|
272240
272848
|
const packer_1 = __webpack_require__(5147);
|
|
272241
272849
|
const error_1 = __webpack_require__(40430);
|
|
272242
272850
|
const utils_1 = __webpack_require__(62358);
|
|
@@ -272483,20 +273091,96 @@ class FunctionService {
|
|
|
272483
273091
|
});
|
|
272484
273092
|
return data;
|
|
272485
273093
|
}
|
|
273094
|
+
/**
|
|
273095
|
+
* 列出所有函数
|
|
273096
|
+
* @param {IListFunctionOptions} options
|
|
273097
|
+
* @returns {Promise<Record<string, string>[]>}
|
|
273098
|
+
*/
|
|
273099
|
+
async listAllFunctions(options) {
|
|
273100
|
+
const allFunctions = [];
|
|
273101
|
+
let currentOffset = 0;
|
|
273102
|
+
const pageSize = 20;
|
|
273103
|
+
const { envId } = options;
|
|
273104
|
+
while (true) {
|
|
273105
|
+
try {
|
|
273106
|
+
const res = await this.scfService.request('ListFunctions', {
|
|
273107
|
+
Namespace: envId,
|
|
273108
|
+
Limit: pageSize,
|
|
273109
|
+
Offset: currentOffset
|
|
273110
|
+
});
|
|
273111
|
+
const { Functions = [], TotalCount } = res;
|
|
273112
|
+
if (Functions.length === 0) {
|
|
273113
|
+
break;
|
|
273114
|
+
}
|
|
273115
|
+
allFunctions.push(...Functions);
|
|
273116
|
+
// 检查是否已获取所有函数
|
|
273117
|
+
if (allFunctions.length >= TotalCount || Functions.length < pageSize) {
|
|
273118
|
+
break;
|
|
273119
|
+
}
|
|
273120
|
+
currentOffset += pageSize;
|
|
273121
|
+
}
|
|
273122
|
+
catch (error) {
|
|
273123
|
+
throw new error_1.CloudBaseError(`获取函数列表失败: ${error.message}`);
|
|
273124
|
+
}
|
|
273125
|
+
}
|
|
273126
|
+
// 格式化数据
|
|
273127
|
+
const data = [];
|
|
273128
|
+
allFunctions.forEach(func => {
|
|
273129
|
+
const { FunctionId, FunctionName, Runtime, AddTime, ModTime, Status } = func;
|
|
273130
|
+
data.push({
|
|
273131
|
+
FunctionId,
|
|
273132
|
+
FunctionName,
|
|
273133
|
+
Runtime,
|
|
273134
|
+
AddTime,
|
|
273135
|
+
ModTime,
|
|
273136
|
+
Status
|
|
273137
|
+
});
|
|
273138
|
+
});
|
|
273139
|
+
return data;
|
|
273140
|
+
}
|
|
272486
273141
|
/**
|
|
272487
273142
|
* 删除云函数
|
|
272488
273143
|
* @param {string} name 云函数名称
|
|
272489
273144
|
* @param {string} qualifier 需要删除的版本号,不填默认删除函数下全部版本。
|
|
272490
273145
|
* @returns {Promise<IResponseInfo>}
|
|
272491
273146
|
*/
|
|
272492
|
-
async deleteFunction(name
|
|
273147
|
+
async deleteFunction({ name }) {
|
|
273148
|
+
var _a;
|
|
272493
273149
|
const { namespace } = this.getFunctionConfig();
|
|
272494
|
-
|
|
273150
|
+
// 检测是否绑定了 API 网关
|
|
273151
|
+
const accessService = this.environment.getAccessService();
|
|
273152
|
+
const res = await accessService.getAccessList({
|
|
273153
|
+
name
|
|
273154
|
+
});
|
|
273155
|
+
// 删除绑定的 API 网关
|
|
273156
|
+
if (((_a = res === null || res === void 0 ? void 0 : res.APISet) === null || _a === void 0 ? void 0 : _a.length) > 0) {
|
|
273157
|
+
await accessService.deleteAccess({
|
|
273158
|
+
name
|
|
273159
|
+
});
|
|
273160
|
+
}
|
|
273161
|
+
await this.scfService.request('DeleteFunction', {
|
|
272495
273162
|
FunctionName: name,
|
|
272496
|
-
Namespace: namespace
|
|
272497
|
-
Qualifier: qualifier
|
|
273163
|
+
Namespace: namespace
|
|
272498
273164
|
});
|
|
272499
273165
|
}
|
|
273166
|
+
/**
|
|
273167
|
+
* 批量删除云函数
|
|
273168
|
+
* @param {Object} options
|
|
273169
|
+
* @param {string[]} options.names 云函数名称列表
|
|
273170
|
+
* @returns {Promise<void>}
|
|
273171
|
+
*/
|
|
273172
|
+
async batchDeleteFunctions({ names }) {
|
|
273173
|
+
const promises = names.map(name => (async () => {
|
|
273174
|
+
try {
|
|
273175
|
+
await this.deleteFunction({ name });
|
|
273176
|
+
(0, utils_1.successLog)(`[${name}] 函数删除成功!`);
|
|
273177
|
+
}
|
|
273178
|
+
catch (e) {
|
|
273179
|
+
throw new error_1.CloudBaseError(e.message);
|
|
273180
|
+
}
|
|
273181
|
+
})());
|
|
273182
|
+
await Promise.all(promises);
|
|
273183
|
+
}
|
|
272500
273184
|
/**
|
|
272501
273185
|
* 获取云函数详细信息
|
|
272502
273186
|
* @param {string} name 云函数名称
|
|
@@ -272531,13 +273215,35 @@ class FunctionService {
|
|
|
272531
273215
|
}
|
|
272532
273216
|
catch (e) {
|
|
272533
273217
|
data.VpcConfig = {
|
|
272534
|
-
vpc: '',
|
|
272535
|
-
subnet: ''
|
|
273218
|
+
vpc: 'VpcId',
|
|
273219
|
+
subnet: 'SubnetId'
|
|
272536
273220
|
};
|
|
272537
273221
|
}
|
|
272538
273222
|
}
|
|
272539
273223
|
return data;
|
|
272540
273224
|
}
|
|
273225
|
+
/**
|
|
273226
|
+
* 批量获取云函数详细信息
|
|
273227
|
+
* @param {Object} options
|
|
273228
|
+
* @param {string[]} options.names 云函数名称列表
|
|
273229
|
+
* @param {string} options.envId 环境 ID
|
|
273230
|
+
* @param {string} options.codeSecret
|
|
273231
|
+
* @returns {Promise<IFunctionInfo[]>}
|
|
273232
|
+
*/
|
|
273233
|
+
async batchGetFunctionsDetail({ names, envId, codeSecret }) {
|
|
273234
|
+
const data = [];
|
|
273235
|
+
const promises = names.map(name => (async () => {
|
|
273236
|
+
try {
|
|
273237
|
+
const info = await this.getFunctionDetail(name, codeSecret);
|
|
273238
|
+
data.push(info);
|
|
273239
|
+
}
|
|
273240
|
+
catch (e) {
|
|
273241
|
+
throw new error_1.CloudBaseError(`${name} 获取信息失败:${e.message}`);
|
|
273242
|
+
}
|
|
273243
|
+
})());
|
|
273244
|
+
await Promise.all(promises);
|
|
273245
|
+
return data;
|
|
273246
|
+
}
|
|
272541
273247
|
/**
|
|
272542
273248
|
* 获取函数日志
|
|
272543
273249
|
* @deprecated 请使用 getFunctionLogsV2 代替
|
|
@@ -272634,6 +273340,33 @@ class FunctionService {
|
|
|
272634
273340
|
const res = await this.tcbService.request('GetFunctionLogDetail', params);
|
|
272635
273341
|
return res;
|
|
272636
273342
|
}
|
|
273343
|
+
/**
|
|
273344
|
+
* 获取函数的完整调用日志
|
|
273345
|
+
* 该方法会自动完成两步操作:1. 获取日志请求ID列表。 2. 根据ID列表获取每条日志的详细内容。
|
|
273346
|
+
* @param {IFunctionLogOptionsV2} options - 查询选项
|
|
273347
|
+
* @returns {Promise<IFunctionLogDetailRes[]>} 返回包含完整日志详情的数组
|
|
273348
|
+
*/
|
|
273349
|
+
async getCompleteFunctionLogs(options) {
|
|
273350
|
+
// 调用 getFunctionLogsV2 获取日志请求ID列表
|
|
273351
|
+
const { name } = options;
|
|
273352
|
+
const logs = await this.getFunctionLogsV2(options);
|
|
273353
|
+
// 如果没有日志,直接返回空数组
|
|
273354
|
+
if (logs.LogList.length === 0) {
|
|
273355
|
+
return [];
|
|
273356
|
+
}
|
|
273357
|
+
const detailPromises = logs.LogList.map(async (log) => {
|
|
273358
|
+
// 对每一个日志ID,调用 getFunctionLogDetail
|
|
273359
|
+
const res = await this.getFunctionLogDetail({
|
|
273360
|
+
logRequestId: log.RequestId,
|
|
273361
|
+
startTime: options.startTime,
|
|
273362
|
+
endTime: options.endTime
|
|
273363
|
+
});
|
|
273364
|
+
return Object.assign(Object.assign({}, res), { RetCode: log.RetCode, FunctionName: name });
|
|
273365
|
+
});
|
|
273366
|
+
// 并发执行所有详情查询,等待它们全部完成
|
|
273367
|
+
const detailedLogs = await Promise.all(detailPromises);
|
|
273368
|
+
return detailedLogs;
|
|
273369
|
+
}
|
|
272637
273370
|
/**
|
|
272638
273371
|
* 更新云函数配置
|
|
272639
273372
|
* @param {ICloudFunction} func 云函数配置
|
|
@@ -272769,6 +273502,28 @@ class FunctionService {
|
|
|
272769
273502
|
throw new error_1.CloudBaseError(`[${name}] 调用失败:\n${e.message}`);
|
|
272770
273503
|
}
|
|
272771
273504
|
}
|
|
273505
|
+
/**
|
|
273506
|
+
* 批量调用云函数
|
|
273507
|
+
* @param {IFunctionBatchOptions} options
|
|
273508
|
+
* @returns {Promise<IFunctionInvokeRes[]>}
|
|
273509
|
+
*/
|
|
273510
|
+
async batchInvokeFunctions(options) {
|
|
273511
|
+
const { functions, envId, log = false } = options;
|
|
273512
|
+
const promises = functions.map(func => (async () => {
|
|
273513
|
+
try {
|
|
273514
|
+
const result = await this.invokeFunction(func.name, func.params);
|
|
273515
|
+
if (log) {
|
|
273516
|
+
(0, utils_1.successLog)(`[${func.name}] 调用成功\n响应结果:\n`);
|
|
273517
|
+
console.log(result);
|
|
273518
|
+
}
|
|
273519
|
+
return result;
|
|
273520
|
+
}
|
|
273521
|
+
catch (e) {
|
|
273522
|
+
throw new error_1.CloudBaseError(`${func.name} 函数调用失败:${e.message}`);
|
|
273523
|
+
}
|
|
273524
|
+
})());
|
|
273525
|
+
return Promise.all(promises);
|
|
273526
|
+
}
|
|
272772
273527
|
/**
|
|
272773
273528
|
* 复制云函数
|
|
272774
273529
|
* @param {string} name 云函数名称
|
|
@@ -272811,12 +273566,34 @@ class FunctionService {
|
|
|
272811
273566
|
TriggerDesc: item.config
|
|
272812
273567
|
};
|
|
272813
273568
|
});
|
|
272814
|
-
|
|
272815
|
-
|
|
272816
|
-
|
|
272817
|
-
|
|
272818
|
-
|
|
272819
|
-
|
|
273569
|
+
try {
|
|
273570
|
+
return await this.scfService.request('BatchCreateTrigger', {
|
|
273571
|
+
FunctionName: name,
|
|
273572
|
+
Namespace: namespace,
|
|
273573
|
+
Triggers: JSON.stringify(parsedTriggers),
|
|
273574
|
+
Count: parsedTriggers.length
|
|
273575
|
+
});
|
|
273576
|
+
}
|
|
273577
|
+
catch (e) {
|
|
273578
|
+
throw new error_1.CloudBaseError(`[${name}] 创建触发器失败:${e.message}`, {
|
|
273579
|
+
action: e.action,
|
|
273580
|
+
code: e.code
|
|
273581
|
+
});
|
|
273582
|
+
}
|
|
273583
|
+
}
|
|
273584
|
+
// 批量部署函数触发器
|
|
273585
|
+
async batchCreateTriggers(options) {
|
|
273586
|
+
const { functions, envId } = options;
|
|
273587
|
+
const promises = functions.map(func => (async () => {
|
|
273588
|
+
try {
|
|
273589
|
+
await this.createFunctionTriggers(func.name, func.triggers);
|
|
273590
|
+
(0, utils_1.successLog)(`[${func.name}] 创建云函数触发器成功!`);
|
|
273591
|
+
}
|
|
273592
|
+
catch (e) {
|
|
273593
|
+
throw new error_1.CloudBaseError(e.message);
|
|
273594
|
+
}
|
|
273595
|
+
})());
|
|
273596
|
+
await Promise.all(promises);
|
|
272820
273597
|
}
|
|
272821
273598
|
/**
|
|
272822
273599
|
* 删除云函数触发器
|
|
@@ -272826,12 +273603,50 @@ class FunctionService {
|
|
|
272826
273603
|
*/
|
|
272827
273604
|
async deleteFunctionTrigger(name, triggerName) {
|
|
272828
273605
|
const { namespace } = this.getFunctionConfig();
|
|
272829
|
-
|
|
272830
|
-
|
|
272831
|
-
|
|
272832
|
-
|
|
272833
|
-
|
|
273606
|
+
try {
|
|
273607
|
+
await this.scfService.request('DeleteTrigger', {
|
|
273608
|
+
FunctionName: name,
|
|
273609
|
+
Namespace: namespace,
|
|
273610
|
+
TriggerName: triggerName,
|
|
273611
|
+
Type: 'timer'
|
|
273612
|
+
});
|
|
273613
|
+
(0, utils_1.successLog)(`[${name}] 删除云函数触发器 ${triggerName} 成功!`);
|
|
273614
|
+
}
|
|
273615
|
+
catch (e) {
|
|
273616
|
+
throw new error_1.CloudBaseError(`[${name}] 删除触发器失败:${e.message}`);
|
|
273617
|
+
}
|
|
273618
|
+
}
|
|
273619
|
+
async batchDeleteTriggers(options) {
|
|
273620
|
+
const { functions, envId } = options;
|
|
273621
|
+
const promises = functions.map(func => (async () => {
|
|
273622
|
+
try {
|
|
273623
|
+
func.triggers.forEach(async (trigger) => {
|
|
273624
|
+
await this.deleteFunctionTrigger(func.name, trigger.name);
|
|
273625
|
+
});
|
|
273626
|
+
}
|
|
273627
|
+
catch (e) {
|
|
273628
|
+
throw new error_1.CloudBaseError(e.message);
|
|
273629
|
+
}
|
|
273630
|
+
})());
|
|
273631
|
+
await Promise.all(promises);
|
|
273632
|
+
}
|
|
273633
|
+
/**
|
|
273634
|
+
* 下载云函数代码
|
|
273635
|
+
* @param {IFunctionCodeOptions} options
|
|
273636
|
+
* @returns {Promise<void>}
|
|
273637
|
+
*/
|
|
273638
|
+
async downloadFunctionCode(options) {
|
|
273639
|
+
const { destPath, envId, functionName, codeSecret } = options;
|
|
273640
|
+
// 检验路径是否存在
|
|
273641
|
+
(0, utils_1.checkFullAccess)(destPath, true);
|
|
273642
|
+
// 获取下载链接
|
|
273643
|
+
const { Url } = await this.scfService.request('GetFunctionAddress', {
|
|
273644
|
+
FunctionName: functionName,
|
|
273645
|
+
Namespace: envId,
|
|
273646
|
+
CodeSecret: codeSecret
|
|
272834
273647
|
});
|
|
273648
|
+
// 下载文件
|
|
273649
|
+
return (0, utils_1.downloadAndExtractRemoteZip)(Url, destPath);
|
|
272835
273650
|
}
|
|
272836
273651
|
/**
|
|
272837
273652
|
* 获取云函数代码下载 链接
|
|
@@ -272857,6 +273672,68 @@ class FunctionService {
|
|
|
272857
273672
|
throw new error_1.CloudBaseError(`[${functionName}] 获取函数代码下载链接失败:\n${e.message}`);
|
|
272858
273673
|
}
|
|
272859
273674
|
}
|
|
273675
|
+
// 函数绑定文件层
|
|
273676
|
+
async attachLayer(options) {
|
|
273677
|
+
const { envId, functionName, layerName, layerVersion, codeSecret } = options;
|
|
273678
|
+
let { Layers = [] } = await this.getFunctionDetail(functionName, codeSecret);
|
|
273679
|
+
Layers = Layers.map(item => lodash_1.default.pick(item, ['LayerName', 'LayerVersion']));
|
|
273680
|
+
// 新加的文件层添加到最后
|
|
273681
|
+
Layers.push({
|
|
273682
|
+
LayerName: layerName,
|
|
273683
|
+
LayerVersion: layerVersion
|
|
273684
|
+
});
|
|
273685
|
+
const res = await this.scfService.request('UpdateFunctionConfiguration', {
|
|
273686
|
+
Layers,
|
|
273687
|
+
Namespace: envId,
|
|
273688
|
+
FunctionName: functionName
|
|
273689
|
+
});
|
|
273690
|
+
return res;
|
|
273691
|
+
}
|
|
273692
|
+
// 函数解绑文件层
|
|
273693
|
+
async unAttachLayer(options) {
|
|
273694
|
+
const { envId, functionName, layerName, layerVersion, codeSecret } = options;
|
|
273695
|
+
let { Layers } = await this.getFunctionDetail(functionName, codeSecret);
|
|
273696
|
+
Layers = Layers.map(item => lodash_1.default.pick(item, ['LayerName', 'LayerVersion']));
|
|
273697
|
+
const index = Layers.findIndex(item => item.LayerName === layerName && item.LayerVersion === layerVersion);
|
|
273698
|
+
if (index === -1) {
|
|
273699
|
+
throw new error_1.CloudBaseError('层不存在');
|
|
273700
|
+
}
|
|
273701
|
+
// 删除指定的层
|
|
273702
|
+
Layers.splice(index, 1);
|
|
273703
|
+
const apiParams = {
|
|
273704
|
+
Namespace: envId,
|
|
273705
|
+
FunctionName: functionName,
|
|
273706
|
+
Layers: Layers.length > 0 ? Layers : [{
|
|
273707
|
+
LayerName: '',
|
|
273708
|
+
LayerVersion: 0
|
|
273709
|
+
}]
|
|
273710
|
+
};
|
|
273711
|
+
return this.scfService.request('UpdateFunctionConfiguration', apiParams);
|
|
273712
|
+
}
|
|
273713
|
+
// 更新云函数层
|
|
273714
|
+
async updateFunctionLayer(options) {
|
|
273715
|
+
const { envId, functionName, layers } = options;
|
|
273716
|
+
return this.scfService.request('UpdateFunctionConfiguration', {
|
|
273717
|
+
Layers: layers,
|
|
273718
|
+
Namespace: envId,
|
|
273719
|
+
FunctionName: functionName
|
|
273720
|
+
});
|
|
273721
|
+
}
|
|
273722
|
+
// 下载文件层 ZIP 文件
|
|
273723
|
+
async downloadLayer(options) {
|
|
273724
|
+
const { name, version, destPath } = options;
|
|
273725
|
+
const res = await this.scfService.request('GetLayerVersion', {
|
|
273726
|
+
LayerName: name,
|
|
273727
|
+
LayerVersion: version
|
|
273728
|
+
});
|
|
273729
|
+
const url = res === null || res === void 0 ? void 0 : res.Location;
|
|
273730
|
+
const zipPath = path_1.default.join(destPath, `${name}-${version}.zip`);
|
|
273731
|
+
if ((0, utils_1.checkFullAccess)(zipPath)) {
|
|
273732
|
+
throw new error_1.CloudBaseError(`文件已存在:${zipPath}`);
|
|
273733
|
+
}
|
|
273734
|
+
// 下载文件
|
|
273735
|
+
return (0, utils_1.downloadAndExtractRemoteZip)(url, destPath);
|
|
273736
|
+
}
|
|
272860
273737
|
// 创建文件层版本
|
|
272861
273738
|
async createLayer(options) {
|
|
272862
273739
|
const { env } = this.getFunctionConfig();
|
|
@@ -272929,7 +273806,7 @@ class FunctionService {
|
|
|
272929
273806
|
Limit: limit,
|
|
272930
273807
|
Offset: offset,
|
|
272931
273808
|
SearchKey: searchKey,
|
|
272932
|
-
SearchSrc: `TCB_${env}`
|
|
273809
|
+
// SearchSrc: `TCB_${env}`
|
|
272933
273810
|
};
|
|
272934
273811
|
if (runtime) {
|
|
272935
273812
|
param.CompatibleRuntime = runtime;
|
|
@@ -273258,12 +274135,18 @@ __decorate([
|
|
|
273258
274135
|
__decorate([
|
|
273259
274136
|
(0, utils_1.preLazy)()
|
|
273260
274137
|
], FunctionService.prototype, "listFunctions", null);
|
|
274138
|
+
__decorate([
|
|
274139
|
+
(0, utils_1.preLazy)()
|
|
274140
|
+
], FunctionService.prototype, "listAllFunctions", null);
|
|
273261
274141
|
__decorate([
|
|
273262
274142
|
(0, utils_1.preLazy)()
|
|
273263
274143
|
], FunctionService.prototype, "deleteFunction", null);
|
|
273264
274144
|
__decorate([
|
|
273265
274145
|
(0, utils_1.preLazy)()
|
|
273266
274146
|
], FunctionService.prototype, "getFunctionDetail", null);
|
|
274147
|
+
__decorate([
|
|
274148
|
+
(0, utils_1.preLazy)()
|
|
274149
|
+
], FunctionService.prototype, "batchGetFunctionsDetail", null);
|
|
273267
274150
|
__decorate([
|
|
273268
274151
|
(0, utils_1.preLazy)()
|
|
273269
274152
|
], FunctionService.prototype, "getFunctionLogs", null);
|
|
@@ -273273,6 +274156,9 @@ __decorate([
|
|
|
273273
274156
|
__decorate([
|
|
273274
274157
|
(0, utils_1.preLazy)()
|
|
273275
274158
|
], FunctionService.prototype, "getFunctionLogDetail", null);
|
|
274159
|
+
__decorate([
|
|
274160
|
+
(0, utils_1.preLazy)()
|
|
274161
|
+
], FunctionService.prototype, "getCompleteFunctionLogs", null);
|
|
273276
274162
|
__decorate([
|
|
273277
274163
|
(0, utils_1.preLazy)()
|
|
273278
274164
|
], FunctionService.prototype, "updateFunctionConfig", null);
|
|
@@ -273282,6 +274168,9 @@ __decorate([
|
|
|
273282
274168
|
__decorate([
|
|
273283
274169
|
(0, utils_1.preLazy)()
|
|
273284
274170
|
], FunctionService.prototype, "invokeFunction", null);
|
|
274171
|
+
__decorate([
|
|
274172
|
+
(0, utils_1.preLazy)()
|
|
274173
|
+
], FunctionService.prototype, "batchInvokeFunctions", null);
|
|
273285
274174
|
__decorate([
|
|
273286
274175
|
(0, utils_1.preLazy)()
|
|
273287
274176
|
], FunctionService.prototype, "copyFunction", null);
|
|
@@ -273294,6 +274183,18 @@ __decorate([
|
|
|
273294
274183
|
__decorate([
|
|
273295
274184
|
(0, utils_1.preLazy)()
|
|
273296
274185
|
], FunctionService.prototype, "getFunctionDownloadUrl", null);
|
|
274186
|
+
__decorate([
|
|
274187
|
+
(0, utils_1.preLazy)()
|
|
274188
|
+
], FunctionService.prototype, "attachLayer", null);
|
|
274189
|
+
__decorate([
|
|
274190
|
+
(0, utils_1.preLazy)()
|
|
274191
|
+
], FunctionService.prototype, "unAttachLayer", null);
|
|
274192
|
+
__decorate([
|
|
274193
|
+
(0, utils_1.preLazy)()
|
|
274194
|
+
], FunctionService.prototype, "updateFunctionLayer", null);
|
|
274195
|
+
__decorate([
|
|
274196
|
+
(0, utils_1.preLazy)()
|
|
274197
|
+
], FunctionService.prototype, "downloadLayer", null);
|
|
273297
274198
|
__decorate([
|
|
273298
274199
|
(0, utils_1.preLazy)()
|
|
273299
274200
|
], FunctionService.prototype, "createLayer", null);
|