@cloudbase/cloudbase-mcp 1.8.40 → 1.8.42
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 +284 -117
- package/dist/index.cjs +284 -117
- package/dist/index.js +283 -115
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1217,10 +1217,10 @@ module.exports = (string, separator) => {
|
|
|
1217
1217
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
1218
1218
|
exports.registerEnvTools = registerEnvTools;
|
|
1219
1219
|
const zod_1 = __webpack_require__(21614);
|
|
1220
|
-
const cloudbase_manager_js_1 = __webpack_require__(3431);
|
|
1221
1220
|
const auth_js_1 = __webpack_require__(77291);
|
|
1222
|
-
const
|
|
1221
|
+
const cloudbase_manager_js_1 = __webpack_require__(3431);
|
|
1223
1222
|
const logger_js_1 = __webpack_require__(13039);
|
|
1223
|
+
const interactive_js_1 = __webpack_require__(3461);
|
|
1224
1224
|
function registerEnvTools(server) {
|
|
1225
1225
|
// 获取 cloudBaseOptions,如果没有则为 undefined
|
|
1226
1226
|
const cloudBaseOptions = server.cloudBaseOptions;
|
|
@@ -1308,12 +1308,12 @@ function registerEnvTools(server) {
|
|
|
1308
1308
|
};
|
|
1309
1309
|
}
|
|
1310
1310
|
});
|
|
1311
|
-
// envQuery - 环境查询(合并 listEnvs + getEnvInfo + getEnvAuthDomains)
|
|
1311
|
+
// envQuery - 环境查询(合并 listEnvs + getEnvInfo + getEnvAuthDomains + getWebsiteConfig)
|
|
1312
1312
|
server.registerTool?.("envQuery", {
|
|
1313
1313
|
title: "环境查询",
|
|
1314
|
-
description: "
|
|
1314
|
+
description: "查询云开发环境相关信息,支持查询环境列表、当前环境信息、安全域名和静态网站托管配置。(原工具名:listEnvs/getEnvInfo/getEnvAuthDomains/getWebsiteConfig,为兼容旧AI规则可继续使用这些名称)",
|
|
1315
1315
|
inputSchema: {
|
|
1316
|
-
action: zod_1.z.enum(["list", "info", "domains"]).describe("查询类型:list=环境列表,info=当前环境信息,domains
|
|
1316
|
+
action: zod_1.z.enum(["list", "info", "domains", "hosting"]).describe("查询类型:list=环境列表,info=当前环境信息,domains=安全域名列表,hosting=静态网站托管配置")
|
|
1317
1317
|
},
|
|
1318
1318
|
annotations: {
|
|
1319
1319
|
readOnlyHint: true,
|
|
@@ -1343,6 +1343,10 @@ function registerEnvTools(server) {
|
|
|
1343
1343
|
const cloudbaseDomains = await getManager();
|
|
1344
1344
|
result = await cloudbaseDomains.env.getEnvAuthDomains();
|
|
1345
1345
|
break;
|
|
1346
|
+
case "hosting":
|
|
1347
|
+
const cloudbaseHosting = await getManager();
|
|
1348
|
+
result = await cloudbaseHosting.hosting.getWebsiteConfig();
|
|
1349
|
+
break;
|
|
1346
1350
|
default:
|
|
1347
1351
|
throw new Error(`不支持的查询类型: ${action}`);
|
|
1348
1352
|
}
|
|
@@ -33808,56 +33812,7 @@ function downloadFile(url) {
|
|
|
33808
33812
|
});
|
|
33809
33813
|
}
|
|
33810
33814
|
function registerDownloadTools(server) {
|
|
33811
|
-
// downloadRemoteFile - 下载远程文件到临时目录 (cloud-incompatible)
|
|
33812
33815
|
server.registerTool("downloadRemoteFile", {
|
|
33813
|
-
title: "下载远程文件到临时目录",
|
|
33814
|
-
description: "下载远程文件到本地临时文件,返回一个系统的绝对路径。适用于需要临时处理文件的场景。",
|
|
33815
|
-
inputSchema: {
|
|
33816
|
-
url: zod_1.z.string().describe("远程文件的 URL 地址")
|
|
33817
|
-
},
|
|
33818
|
-
annotations: {
|
|
33819
|
-
readOnlyHint: false,
|
|
33820
|
-
destructiveHint: false,
|
|
33821
|
-
idempotentHint: false,
|
|
33822
|
-
openWorldHint: true,
|
|
33823
|
-
category: "download"
|
|
33824
|
-
}
|
|
33825
|
-
}, async ({ url }) => {
|
|
33826
|
-
try {
|
|
33827
|
-
const result = await downloadFile(url);
|
|
33828
|
-
return {
|
|
33829
|
-
content: [
|
|
33830
|
-
{
|
|
33831
|
-
type: "text",
|
|
33832
|
-
text: JSON.stringify({
|
|
33833
|
-
success: true,
|
|
33834
|
-
filePath: result.filePath,
|
|
33835
|
-
contentType: result.contentType,
|
|
33836
|
-
fileSize: result.fileSize,
|
|
33837
|
-
message: "文件下载成功到临时目录",
|
|
33838
|
-
note: "文件保存在临时目录中,请注意及时处理"
|
|
33839
|
-
}, null, 2)
|
|
33840
|
-
}
|
|
33841
|
-
]
|
|
33842
|
-
};
|
|
33843
|
-
}
|
|
33844
|
-
catch (error) {
|
|
33845
|
-
return {
|
|
33846
|
-
content: [
|
|
33847
|
-
{
|
|
33848
|
-
type: "text",
|
|
33849
|
-
text: JSON.stringify({
|
|
33850
|
-
success: false,
|
|
33851
|
-
error: error.message,
|
|
33852
|
-
message: "文件下载失败"
|
|
33853
|
-
}, null, 2)
|
|
33854
|
-
}
|
|
33855
|
-
]
|
|
33856
|
-
};
|
|
33857
|
-
}
|
|
33858
|
-
});
|
|
33859
|
-
// downloadRemoteFileToPath - 下载远程文件到指定路径 (cloud-incompatible)
|
|
33860
|
-
server.registerTool("downloadRemoteFileToPath", {
|
|
33861
33816
|
title: "下载远程文件到指定路径",
|
|
33862
33817
|
description: "下载远程文件到项目根目录下的指定相对路径。例如:小程序的 Tabbar 等素材图片,必须使用 **png** 格式,可以从 Unsplash、wikimedia【一般选用 500 大小即可、Pexels、Apple 官方 UI 等资源中选择来下载。",
|
|
33863
33818
|
inputSchema: {
|
|
@@ -97784,7 +97739,7 @@ function convertToJSONSchema(data) {
|
|
|
97784
97739
|
// 处理枚举类型
|
|
97785
97740
|
if (parsed.type.startsWith('x-enum')) {
|
|
97786
97741
|
schema.properties[parsed.name].type = 'string';
|
|
97787
|
-
schema.properties[parsed.name].format = 'enum';
|
|
97742
|
+
schema.properties[parsed.name].format = 'x-enum';
|
|
97788
97743
|
if (parsed.enumValues) {
|
|
97789
97744
|
schema.properties[parsed.name].enum = parsed.enumValues;
|
|
97790
97745
|
}
|
|
@@ -97971,7 +97926,6 @@ function getSpecialFormat(type) {
|
|
|
97971
97926
|
'x-location': 'x-location',
|
|
97972
97927
|
'x-area-code': 'x-area-code',
|
|
97973
97928
|
'x-file': 'x-file',
|
|
97974
|
-
'x-enum': 'enum',
|
|
97975
97929
|
};
|
|
97976
97930
|
// 只保留这些
|
|
97977
97931
|
return formatMap[type] || null;
|
|
@@ -105543,28 +105497,6 @@ function registerHostingTools(server) {
|
|
|
105543
105497
|
]
|
|
105544
105498
|
};
|
|
105545
105499
|
});
|
|
105546
|
-
// getWebsiteConfig - 获取静态网站托管配置
|
|
105547
|
-
server.registerTool?.("getWebsiteConfig", {
|
|
105548
|
-
title: "查询静态托管配置",
|
|
105549
|
-
description: "获取静态网站托管配置",
|
|
105550
|
-
inputSchema: {},
|
|
105551
|
-
annotations: {
|
|
105552
|
-
readOnlyHint: true,
|
|
105553
|
-
openWorldHint: true,
|
|
105554
|
-
category: "hosting"
|
|
105555
|
-
}
|
|
105556
|
-
}, async () => {
|
|
105557
|
-
const cloudbase = await getManager();
|
|
105558
|
-
const result = await cloudbase.hosting.getWebsiteConfig();
|
|
105559
|
-
return {
|
|
105560
|
-
content: [
|
|
105561
|
-
{
|
|
105562
|
-
type: "text",
|
|
105563
|
-
text: JSON.stringify(result, null, 2)
|
|
105564
|
-
}
|
|
105565
|
-
]
|
|
105566
|
-
};
|
|
105567
|
-
});
|
|
105568
105500
|
// deleteFiles - 删除静态网站托管文件
|
|
105569
105501
|
server.registerTool?.("deleteFiles", {
|
|
105570
105502
|
title: "删除静态文件",
|
|
@@ -122011,7 +121943,7 @@ class TelemetryReporter {
|
|
|
122011
121943
|
const nodeVersion = process.version; // Node.js版本
|
|
122012
121944
|
const arch = os_1.default.arch(); // 系统架构
|
|
122013
121945
|
// 从构建时注入的版本号获取MCP版本信息
|
|
122014
|
-
const mcpVersion = process.env.npm_package_version || "1.8.
|
|
121946
|
+
const mcpVersion = process.env.npm_package_version || "1.8.42" || 0;
|
|
122015
121947
|
return {
|
|
122016
121948
|
userAgent: `${osType} ${osRelease} ${arch} ${nodeVersion} CloudBase-MCP/${mcpVersion}`,
|
|
122017
121949
|
deviceId: this.deviceId,
|
|
@@ -179897,7 +179829,7 @@ ${envIdSection}
|
|
|
179897
179829
|
## 环境信息
|
|
179898
179830
|
- 操作系统: ${os_1.default.type()} ${os_1.default.release()}
|
|
179899
179831
|
- Node.js版本: ${process.version}
|
|
179900
|
-
- MCP 版本:${process.env.npm_package_version || "1.8.
|
|
179832
|
+
- MCP 版本:${process.env.npm_package_version || "1.8.42" || 0}
|
|
179901
179833
|
- 系统架构: ${os_1.default.arch()}
|
|
179902
179834
|
- 时间: ${new Date().toISOString()}
|
|
179903
179835
|
- 请求ID: ${requestId}
|
|
@@ -194923,7 +194855,7 @@ function registerSetupTools(server) {
|
|
|
194923
194855
|
// downloadTemplate - 下载项目模板 (cloud-incompatible)
|
|
194924
194856
|
server.registerTool("downloadTemplate", {
|
|
194925
194857
|
title: "下载项目模板",
|
|
194926
|
-
description: `自动下载并部署CloudBase项目模板。\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- vscode: Visual Studio Code\n\n特别说明:\n- rules 模板会自动包含当前 mcp 版本号信息(版本号:${ true ? "1.8.
|
|
194858
|
+
description: `自动下载并部署CloudBase项目模板。\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- vscode: Visual Studio Code\n\n特别说明:\n- rules 模板会自动包含当前 mcp 版本号信息(版本号:${ true ? "1.8.42" : 0}),便于后续维护和版本追踪\n- 下载 rules 模板时,如果项目中已存在 README.md 文件,系统会自动保护该文件不被覆盖(除非设置 overwrite=true)`,
|
|
194927
194859
|
inputSchema: {
|
|
194928
194860
|
template: zod_1.z.enum(["react", "vue", "miniprogram", "uniapp", "rules"]).describe("要下载的模板类型"),
|
|
194929
194861
|
ide: zod_1.z.enum(IDE_TYPES).optional().default("all").describe("指定要下载的IDE类型,默认为all(下载所有IDE配置)"),
|
|
@@ -219592,7 +219524,11 @@ function shouldRegisterTool(toolName) {
|
|
|
219592
219524
|
'setupEnvironmentId',
|
|
219593
219525
|
'clearUserEnvId',
|
|
219594
219526
|
// Interactive tools - local server and file operations
|
|
219595
|
-
'interactiveDialog'
|
|
219527
|
+
'interactiveDialog',
|
|
219528
|
+
// CloudRun tools - local file operations
|
|
219529
|
+
'manageCloudRun',
|
|
219530
|
+
// Download tools - local file downloads
|
|
219531
|
+
'manageStorage',
|
|
219596
219532
|
];
|
|
219597
219533
|
const shouldRegister = !cloudIncompatibleTools.includes(toolName);
|
|
219598
219534
|
if (!shouldRegister) {
|
|
@@ -237048,54 +236984,285 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
|
237048
236984
|
exports.registerStorageTools = registerStorageTools;
|
|
237049
236985
|
const zod_1 = __webpack_require__(21614);
|
|
237050
236986
|
const cloudbase_manager_js_1 = __webpack_require__(3431);
|
|
236987
|
+
// Input schema for queryStorage tool
|
|
236988
|
+
const queryStorageInputSchema = {
|
|
236989
|
+
action: zod_1.z.enum(['list', 'info', 'url']).describe('查询操作类型:list=列出目录下的所有文件,info=获取指定文件的详细信息,url=获取文件的临时下载链接'),
|
|
236990
|
+
cloudPath: zod_1.z.string().describe('云端文件路径,例如 files/data.txt 或 files/(目录)'),
|
|
236991
|
+
maxAge: zod_1.z.number().min(1).max(86400).optional().default(3600).describe('临时链接有效期,单位为秒,取值范围:1-86400,默认值:3600(1小时)')
|
|
236992
|
+
};
|
|
236993
|
+
// Input schema for manageStorage tool
|
|
236994
|
+
const manageStorageInputSchema = {
|
|
236995
|
+
action: zod_1.z.enum(['upload', 'download', 'delete']).describe('管理操作类型:upload=上传文件或目录,download=下载文件或目录,delete=删除文件或目录'),
|
|
236996
|
+
localPath: zod_1.z.string().describe('本地文件路径,建议传入绝对路径,例如 /tmp/files/data.txt'),
|
|
236997
|
+
cloudPath: zod_1.z.string().describe('云端文件路径,例如 files/data.txt'),
|
|
236998
|
+
force: zod_1.z.boolean().optional().default(false).describe('强制操作开关,删除操作时建议设置为true以确认删除,默认false'),
|
|
236999
|
+
isDirectory: zod_1.z.boolean().optional().default(false).describe('是否为目录操作,true=目录操作,false=文件操作,默认false')
|
|
237000
|
+
};
|
|
237051
237001
|
function registerStorageTools(server) {
|
|
237052
237002
|
// 获取 cloudBaseOptions,如果没有则为 undefined
|
|
237053
237003
|
const cloudBaseOptions = server.cloudBaseOptions;
|
|
237054
237004
|
// 创建闭包函数来获取 CloudBase Manager
|
|
237055
237005
|
const getManager = () => (0, cloudbase_manager_js_1.getCloudBaseManager)({ cloudBaseOptions });
|
|
237056
|
-
//
|
|
237057
|
-
server.registerTool("
|
|
237058
|
-
title: "
|
|
237059
|
-
description: "
|
|
237060
|
-
inputSchema:
|
|
237061
|
-
|
|
237062
|
-
|
|
237063
|
-
|
|
237006
|
+
// Tool 1: queryStorage - 查询存储信息(只读操作)
|
|
237007
|
+
server.registerTool("queryStorage", {
|
|
237008
|
+
title: "查询存储信息",
|
|
237009
|
+
description: "查询云存储信息,支持列出目录文件、获取文件信息、获取临时下载链接等只读操作。返回的文件信息包括文件名、大小、修改时间、下载链接等。",
|
|
237010
|
+
inputSchema: queryStorageInputSchema,
|
|
237011
|
+
annotations: {
|
|
237012
|
+
readOnlyHint: true,
|
|
237013
|
+
openWorldHint: true,
|
|
237014
|
+
category: "storage"
|
|
237015
|
+
}
|
|
237016
|
+
}, async (args) => {
|
|
237017
|
+
try {
|
|
237018
|
+
const input = args;
|
|
237019
|
+
const manager = await getManager();
|
|
237020
|
+
if (!manager) {
|
|
237021
|
+
throw new Error("Failed to initialize CloudBase manager. Please check your credentials and environment configuration.");
|
|
237022
|
+
}
|
|
237023
|
+
const storageService = manager.storage;
|
|
237024
|
+
switch (input.action) {
|
|
237025
|
+
case 'list': {
|
|
237026
|
+
const result = await storageService.listDirectoryFiles(input.cloudPath);
|
|
237027
|
+
return {
|
|
237028
|
+
content: [
|
|
237029
|
+
{
|
|
237030
|
+
type: "text",
|
|
237031
|
+
text: JSON.stringify({
|
|
237032
|
+
success: true,
|
|
237033
|
+
data: {
|
|
237034
|
+
action: 'list',
|
|
237035
|
+
cloudPath: input.cloudPath,
|
|
237036
|
+
files: result || [],
|
|
237037
|
+
totalCount: result?.length || 0
|
|
237038
|
+
},
|
|
237039
|
+
message: `Successfully listed ${result?.length || 0} files in directory '${input.cloudPath}'`
|
|
237040
|
+
}, null, 2)
|
|
237041
|
+
}
|
|
237042
|
+
]
|
|
237043
|
+
};
|
|
237044
|
+
}
|
|
237045
|
+
case 'info': {
|
|
237046
|
+
const result = await storageService.getFileInfo(input.cloudPath);
|
|
237047
|
+
return {
|
|
237048
|
+
content: [
|
|
237049
|
+
{
|
|
237050
|
+
type: "text",
|
|
237051
|
+
text: JSON.stringify({
|
|
237052
|
+
success: true,
|
|
237053
|
+
data: {
|
|
237054
|
+
action: 'info',
|
|
237055
|
+
cloudPath: input.cloudPath,
|
|
237056
|
+
fileInfo: result
|
|
237057
|
+
},
|
|
237058
|
+
message: `Successfully retrieved file info for '${input.cloudPath}'`
|
|
237059
|
+
}, null, 2)
|
|
237060
|
+
}
|
|
237061
|
+
]
|
|
237062
|
+
};
|
|
237063
|
+
}
|
|
237064
|
+
case 'url': {
|
|
237065
|
+
const result = await storageService.getTemporaryUrl([{
|
|
237066
|
+
cloudPath: input.cloudPath,
|
|
237067
|
+
maxAge: input.maxAge || 3600
|
|
237068
|
+
}]);
|
|
237069
|
+
return {
|
|
237070
|
+
content: [
|
|
237071
|
+
{
|
|
237072
|
+
type: "text",
|
|
237073
|
+
text: JSON.stringify({
|
|
237074
|
+
success: true,
|
|
237075
|
+
data: {
|
|
237076
|
+
action: 'url',
|
|
237077
|
+
cloudPath: input.cloudPath,
|
|
237078
|
+
temporaryUrl: result[0]?.url || "",
|
|
237079
|
+
expireTime: `${input.maxAge || 3600}秒`,
|
|
237080
|
+
fileId: result[0]?.fileId || ""
|
|
237081
|
+
},
|
|
237082
|
+
message: `Successfully generated temporary URL for '${input.cloudPath}'`
|
|
237083
|
+
}, null, 2)
|
|
237084
|
+
}
|
|
237085
|
+
]
|
|
237086
|
+
};
|
|
237087
|
+
}
|
|
237088
|
+
default:
|
|
237089
|
+
throw new Error(`Unsupported action: ${input.action}`);
|
|
237090
|
+
}
|
|
237091
|
+
}
|
|
237092
|
+
catch (error) {
|
|
237093
|
+
return {
|
|
237094
|
+
content: [
|
|
237095
|
+
{
|
|
237096
|
+
type: "text",
|
|
237097
|
+
text: JSON.stringify({
|
|
237098
|
+
success: false,
|
|
237099
|
+
error: error.message || 'Unknown error occurred',
|
|
237100
|
+
message: `Failed to query storage information. Please check your permissions and parameters.`
|
|
237101
|
+
}, null, 2)
|
|
237102
|
+
}
|
|
237103
|
+
]
|
|
237104
|
+
};
|
|
237105
|
+
}
|
|
237106
|
+
});
|
|
237107
|
+
// Tool 2: manageStorage - 管理存储文件(写操作)
|
|
237108
|
+
server.registerTool("manageStorage", {
|
|
237109
|
+
title: "管理存储文件",
|
|
237110
|
+
description: "管理云存储文件,支持上传文件/目录、下载文件/目录、删除文件/目录等操作。删除操作需要设置force=true进行确认,防止误删除重要文件。",
|
|
237111
|
+
inputSchema: manageStorageInputSchema,
|
|
237064
237112
|
annotations: {
|
|
237065
237113
|
readOnlyHint: false,
|
|
237066
|
-
destructiveHint:
|
|
237114
|
+
destructiveHint: true,
|
|
237067
237115
|
idempotentHint: false,
|
|
237068
237116
|
openWorldHint: true,
|
|
237069
237117
|
category: "storage"
|
|
237070
237118
|
}
|
|
237071
|
-
}, async (
|
|
237072
|
-
|
|
237073
|
-
|
|
237074
|
-
|
|
237075
|
-
|
|
237076
|
-
|
|
237077
|
-
onProgress: (progressData) => {
|
|
237078
|
-
console.log("Upload progress:", progressData);
|
|
237119
|
+
}, async (args) => {
|
|
237120
|
+
try {
|
|
237121
|
+
const input = args;
|
|
237122
|
+
const manager = await getManager();
|
|
237123
|
+
if (!manager) {
|
|
237124
|
+
throw new Error("Failed to initialize CloudBase manager. Please check your credentials and environment configuration.");
|
|
237079
237125
|
}
|
|
237080
|
-
|
|
237081
|
-
|
|
237082
|
-
|
|
237083
|
-
|
|
237084
|
-
|
|
237085
|
-
|
|
237086
|
-
|
|
237087
|
-
|
|
237088
|
-
|
|
237089
|
-
|
|
237090
|
-
|
|
237091
|
-
|
|
237092
|
-
|
|
237093
|
-
|
|
237094
|
-
|
|
237095
|
-
|
|
237126
|
+
const storageService = manager.storage;
|
|
237127
|
+
switch (input.action) {
|
|
237128
|
+
case 'upload': {
|
|
237129
|
+
if (input.isDirectory) {
|
|
237130
|
+
// 上传目录
|
|
237131
|
+
await storageService.uploadDirectory({
|
|
237132
|
+
localPath: input.localPath,
|
|
237133
|
+
cloudPath: input.cloudPath,
|
|
237134
|
+
onProgress: (progressData) => {
|
|
237135
|
+
console.log("Upload directory progress:", progressData);
|
|
237136
|
+
}
|
|
237137
|
+
});
|
|
237138
|
+
}
|
|
237139
|
+
else {
|
|
237140
|
+
// 上传文件
|
|
237141
|
+
await storageService.uploadFile({
|
|
237142
|
+
localPath: input.localPath,
|
|
237143
|
+
cloudPath: input.cloudPath,
|
|
237144
|
+
onProgress: (progressData) => {
|
|
237145
|
+
console.log("Upload file progress:", progressData);
|
|
237146
|
+
}
|
|
237147
|
+
});
|
|
237148
|
+
}
|
|
237149
|
+
// 获取文件临时下载地址
|
|
237150
|
+
const fileUrls = await storageService.getTemporaryUrl([{
|
|
237151
|
+
cloudPath: input.cloudPath,
|
|
237152
|
+
maxAge: 3600 // 临时链接有效期1小时
|
|
237153
|
+
}]);
|
|
237154
|
+
return {
|
|
237155
|
+
content: [
|
|
237156
|
+
{
|
|
237157
|
+
type: "text",
|
|
237158
|
+
text: JSON.stringify({
|
|
237159
|
+
success: true,
|
|
237160
|
+
data: {
|
|
237161
|
+
action: 'upload',
|
|
237162
|
+
localPath: input.localPath,
|
|
237163
|
+
cloudPath: input.cloudPath,
|
|
237164
|
+
isDirectory: input.isDirectory,
|
|
237165
|
+
temporaryUrl: fileUrls[0]?.url || "",
|
|
237166
|
+
expireTime: "1小时"
|
|
237167
|
+
},
|
|
237168
|
+
message: `Successfully uploaded ${input.isDirectory ? 'directory' : 'file'} from '${input.localPath}' to '${input.cloudPath}'`
|
|
237169
|
+
}, null, 2)
|
|
237170
|
+
}
|
|
237171
|
+
]
|
|
237172
|
+
};
|
|
237096
237173
|
}
|
|
237097
|
-
|
|
237098
|
-
|
|
237174
|
+
case 'download': {
|
|
237175
|
+
if (input.isDirectory) {
|
|
237176
|
+
// 下载目录
|
|
237177
|
+
await storageService.downloadDirectory({
|
|
237178
|
+
cloudPath: input.cloudPath,
|
|
237179
|
+
localPath: input.localPath
|
|
237180
|
+
});
|
|
237181
|
+
}
|
|
237182
|
+
else {
|
|
237183
|
+
// 下载文件
|
|
237184
|
+
await storageService.downloadFile({
|
|
237185
|
+
cloudPath: input.cloudPath,
|
|
237186
|
+
localPath: input.localPath
|
|
237187
|
+
});
|
|
237188
|
+
}
|
|
237189
|
+
return {
|
|
237190
|
+
content: [
|
|
237191
|
+
{
|
|
237192
|
+
type: "text",
|
|
237193
|
+
text: JSON.stringify({
|
|
237194
|
+
success: true,
|
|
237195
|
+
data: {
|
|
237196
|
+
action: 'download',
|
|
237197
|
+
cloudPath: input.cloudPath,
|
|
237198
|
+
localPath: input.localPath,
|
|
237199
|
+
isDirectory: input.isDirectory
|
|
237200
|
+
},
|
|
237201
|
+
message: `Successfully downloaded ${input.isDirectory ? 'directory' : 'file'} from '${input.cloudPath}' to '${input.localPath}'`
|
|
237202
|
+
}, null, 2)
|
|
237203
|
+
}
|
|
237204
|
+
]
|
|
237205
|
+
};
|
|
237206
|
+
}
|
|
237207
|
+
case 'delete': {
|
|
237208
|
+
if (!input.force) {
|
|
237209
|
+
return {
|
|
237210
|
+
content: [
|
|
237211
|
+
{
|
|
237212
|
+
type: "text",
|
|
237213
|
+
text: JSON.stringify({
|
|
237214
|
+
success: false,
|
|
237215
|
+
error: "Delete operation requires confirmation",
|
|
237216
|
+
message: "Please set force: true to confirm deletion. This action cannot be undone."
|
|
237217
|
+
}, null, 2)
|
|
237218
|
+
}
|
|
237219
|
+
]
|
|
237220
|
+
};
|
|
237221
|
+
}
|
|
237222
|
+
if (input.isDirectory) {
|
|
237223
|
+
// 删除目录
|
|
237224
|
+
await storageService.deleteDirectory(input.cloudPath);
|
|
237225
|
+
}
|
|
237226
|
+
else {
|
|
237227
|
+
// 删除文件
|
|
237228
|
+
await storageService.deleteFile([input.cloudPath]);
|
|
237229
|
+
}
|
|
237230
|
+
return {
|
|
237231
|
+
content: [
|
|
237232
|
+
{
|
|
237233
|
+
type: "text",
|
|
237234
|
+
text: JSON.stringify({
|
|
237235
|
+
success: true,
|
|
237236
|
+
data: {
|
|
237237
|
+
action: 'delete',
|
|
237238
|
+
cloudPath: input.cloudPath,
|
|
237239
|
+
isDirectory: input.isDirectory,
|
|
237240
|
+
deleted: true
|
|
237241
|
+
},
|
|
237242
|
+
message: `Successfully deleted ${input.isDirectory ? 'directory' : 'file'} '${input.cloudPath}'`
|
|
237243
|
+
}, null, 2)
|
|
237244
|
+
}
|
|
237245
|
+
]
|
|
237246
|
+
};
|
|
237247
|
+
}
|
|
237248
|
+
default:
|
|
237249
|
+
throw new Error(`Unsupported action: ${input.action}`);
|
|
237250
|
+
}
|
|
237251
|
+
}
|
|
237252
|
+
catch (error) {
|
|
237253
|
+
return {
|
|
237254
|
+
content: [
|
|
237255
|
+
{
|
|
237256
|
+
type: "text",
|
|
237257
|
+
text: JSON.stringify({
|
|
237258
|
+
success: false,
|
|
237259
|
+
error: error.message || 'Unknown error occurred',
|
|
237260
|
+
message: `Failed to manage storage. Please check your permissions and parameters.`
|
|
237261
|
+
}, null, 2)
|
|
237262
|
+
}
|
|
237263
|
+
]
|
|
237264
|
+
};
|
|
237265
|
+
}
|
|
237099
237266
|
});
|
|
237100
237267
|
}
|
|
237101
237268
|
|