@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/cli.cjs
CHANGED
|
@@ -1218,10 +1218,10 @@ module.exports = (string, separator) => {
|
|
|
1218
1218
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
1219
1219
|
exports.registerEnvTools = registerEnvTools;
|
|
1220
1220
|
const zod_1 = __webpack_require__(21614);
|
|
1221
|
-
const cloudbase_manager_js_1 = __webpack_require__(3431);
|
|
1222
1221
|
const auth_js_1 = __webpack_require__(77291);
|
|
1223
|
-
const
|
|
1222
|
+
const cloudbase_manager_js_1 = __webpack_require__(3431);
|
|
1224
1223
|
const logger_js_1 = __webpack_require__(13039);
|
|
1224
|
+
const interactive_js_1 = __webpack_require__(3461);
|
|
1225
1225
|
function registerEnvTools(server) {
|
|
1226
1226
|
// 获取 cloudBaseOptions,如果没有则为 undefined
|
|
1227
1227
|
const cloudBaseOptions = server.cloudBaseOptions;
|
|
@@ -1309,12 +1309,12 @@ function registerEnvTools(server) {
|
|
|
1309
1309
|
};
|
|
1310
1310
|
}
|
|
1311
1311
|
});
|
|
1312
|
-
// envQuery - 环境查询(合并 listEnvs + getEnvInfo + getEnvAuthDomains)
|
|
1312
|
+
// envQuery - 环境查询(合并 listEnvs + getEnvInfo + getEnvAuthDomains + getWebsiteConfig)
|
|
1313
1313
|
server.registerTool?.("envQuery", {
|
|
1314
1314
|
title: "环境查询",
|
|
1315
|
-
description: "
|
|
1315
|
+
description: "查询云开发环境相关信息,支持查询环境列表、当前环境信息、安全域名和静态网站托管配置。(原工具名:listEnvs/getEnvInfo/getEnvAuthDomains/getWebsiteConfig,为兼容旧AI规则可继续使用这些名称)",
|
|
1316
1316
|
inputSchema: {
|
|
1317
|
-
action: zod_1.z.enum(["list", "info", "domains"]).describe("查询类型:list=环境列表,info=当前环境信息,domains
|
|
1317
|
+
action: zod_1.z.enum(["list", "info", "domains", "hosting"]).describe("查询类型:list=环境列表,info=当前环境信息,domains=安全域名列表,hosting=静态网站托管配置")
|
|
1318
1318
|
},
|
|
1319
1319
|
annotations: {
|
|
1320
1320
|
readOnlyHint: true,
|
|
@@ -1344,6 +1344,10 @@ function registerEnvTools(server) {
|
|
|
1344
1344
|
const cloudbaseDomains = await getManager();
|
|
1345
1345
|
result = await cloudbaseDomains.env.getEnvAuthDomains();
|
|
1346
1346
|
break;
|
|
1347
|
+
case "hosting":
|
|
1348
|
+
const cloudbaseHosting = await getManager();
|
|
1349
|
+
result = await cloudbaseHosting.hosting.getWebsiteConfig();
|
|
1350
|
+
break;
|
|
1347
1351
|
default:
|
|
1348
1352
|
throw new Error(`不支持的查询类型: ${action}`);
|
|
1349
1353
|
}
|
|
@@ -33809,56 +33813,7 @@ function downloadFile(url) {
|
|
|
33809
33813
|
});
|
|
33810
33814
|
}
|
|
33811
33815
|
function registerDownloadTools(server) {
|
|
33812
|
-
// downloadRemoteFile - 下载远程文件到临时目录 (cloud-incompatible)
|
|
33813
33816
|
server.registerTool("downloadRemoteFile", {
|
|
33814
|
-
title: "下载远程文件到临时目录",
|
|
33815
|
-
description: "下载远程文件到本地临时文件,返回一个系统的绝对路径。适用于需要临时处理文件的场景。",
|
|
33816
|
-
inputSchema: {
|
|
33817
|
-
url: zod_1.z.string().describe("远程文件的 URL 地址")
|
|
33818
|
-
},
|
|
33819
|
-
annotations: {
|
|
33820
|
-
readOnlyHint: false,
|
|
33821
|
-
destructiveHint: false,
|
|
33822
|
-
idempotentHint: false,
|
|
33823
|
-
openWorldHint: true,
|
|
33824
|
-
category: "download"
|
|
33825
|
-
}
|
|
33826
|
-
}, async ({ url }) => {
|
|
33827
|
-
try {
|
|
33828
|
-
const result = await downloadFile(url);
|
|
33829
|
-
return {
|
|
33830
|
-
content: [
|
|
33831
|
-
{
|
|
33832
|
-
type: "text",
|
|
33833
|
-
text: JSON.stringify({
|
|
33834
|
-
success: true,
|
|
33835
|
-
filePath: result.filePath,
|
|
33836
|
-
contentType: result.contentType,
|
|
33837
|
-
fileSize: result.fileSize,
|
|
33838
|
-
message: "文件下载成功到临时目录",
|
|
33839
|
-
note: "文件保存在临时目录中,请注意及时处理"
|
|
33840
|
-
}, null, 2)
|
|
33841
|
-
}
|
|
33842
|
-
]
|
|
33843
|
-
};
|
|
33844
|
-
}
|
|
33845
|
-
catch (error) {
|
|
33846
|
-
return {
|
|
33847
|
-
content: [
|
|
33848
|
-
{
|
|
33849
|
-
type: "text",
|
|
33850
|
-
text: JSON.stringify({
|
|
33851
|
-
success: false,
|
|
33852
|
-
error: error.message,
|
|
33853
|
-
message: "文件下载失败"
|
|
33854
|
-
}, null, 2)
|
|
33855
|
-
}
|
|
33856
|
-
]
|
|
33857
|
-
};
|
|
33858
|
-
}
|
|
33859
|
-
});
|
|
33860
|
-
// downloadRemoteFileToPath - 下载远程文件到指定路径 (cloud-incompatible)
|
|
33861
|
-
server.registerTool("downloadRemoteFileToPath", {
|
|
33862
33817
|
title: "下载远程文件到指定路径",
|
|
33863
33818
|
description: "下载远程文件到项目根目录下的指定相对路径。例如:小程序的 Tabbar 等素材图片,必须使用 **png** 格式,可以从 Unsplash、wikimedia【一般选用 500 大小即可、Pexels、Apple 官方 UI 等资源中选择来下载。",
|
|
33864
33819
|
inputSchema: {
|
|
@@ -97933,7 +97888,7 @@ function convertToJSONSchema(data) {
|
|
|
97933
97888
|
// 处理枚举类型
|
|
97934
97889
|
if (parsed.type.startsWith('x-enum')) {
|
|
97935
97890
|
schema.properties[parsed.name].type = 'string';
|
|
97936
|
-
schema.properties[parsed.name].format = 'enum';
|
|
97891
|
+
schema.properties[parsed.name].format = 'x-enum';
|
|
97937
97892
|
if (parsed.enumValues) {
|
|
97938
97893
|
schema.properties[parsed.name].enum = parsed.enumValues;
|
|
97939
97894
|
}
|
|
@@ -98120,7 +98075,6 @@ function getSpecialFormat(type) {
|
|
|
98120
98075
|
'x-location': 'x-location',
|
|
98121
98076
|
'x-area-code': 'x-area-code',
|
|
98122
98077
|
'x-file': 'x-file',
|
|
98123
|
-
'x-enum': 'enum',
|
|
98124
98078
|
};
|
|
98125
98079
|
// 只保留这些
|
|
98126
98080
|
return formatMap[type] || null;
|
|
@@ -105692,28 +105646,6 @@ function registerHostingTools(server) {
|
|
|
105692
105646
|
]
|
|
105693
105647
|
};
|
|
105694
105648
|
});
|
|
105695
|
-
// getWebsiteConfig - 获取静态网站托管配置
|
|
105696
|
-
server.registerTool?.("getWebsiteConfig", {
|
|
105697
|
-
title: "查询静态托管配置",
|
|
105698
|
-
description: "获取静态网站托管配置",
|
|
105699
|
-
inputSchema: {},
|
|
105700
|
-
annotations: {
|
|
105701
|
-
readOnlyHint: true,
|
|
105702
|
-
openWorldHint: true,
|
|
105703
|
-
category: "hosting"
|
|
105704
|
-
}
|
|
105705
|
-
}, async () => {
|
|
105706
|
-
const cloudbase = await getManager();
|
|
105707
|
-
const result = await cloudbase.hosting.getWebsiteConfig();
|
|
105708
|
-
return {
|
|
105709
|
-
content: [
|
|
105710
|
-
{
|
|
105711
|
-
type: "text",
|
|
105712
|
-
text: JSON.stringify(result, null, 2)
|
|
105713
|
-
}
|
|
105714
|
-
]
|
|
105715
|
-
};
|
|
105716
|
-
});
|
|
105717
105649
|
// deleteFiles - 删除静态网站托管文件
|
|
105718
105650
|
server.registerTool?.("deleteFiles", {
|
|
105719
105651
|
title: "删除静态文件",
|
|
@@ -122160,7 +122092,7 @@ class TelemetryReporter {
|
|
|
122160
122092
|
const nodeVersion = process.version; // Node.js版本
|
|
122161
122093
|
const arch = os_1.default.arch(); // 系统架构
|
|
122162
122094
|
// 从构建时注入的版本号获取MCP版本信息
|
|
122163
|
-
const mcpVersion = process.env.npm_package_version || "1.8.
|
|
122095
|
+
const mcpVersion = process.env.npm_package_version || "1.8.42" || 0;
|
|
122164
122096
|
return {
|
|
122165
122097
|
userAgent: `${osType} ${osRelease} ${arch} ${nodeVersion} CloudBase-MCP/${mcpVersion}`,
|
|
122166
122098
|
deviceId: this.deviceId,
|
|
@@ -180046,7 +179978,7 @@ ${envIdSection}
|
|
|
180046
179978
|
## 环境信息
|
|
180047
179979
|
- 操作系统: ${os_1.default.type()} ${os_1.default.release()}
|
|
180048
179980
|
- Node.js版本: ${process.version}
|
|
180049
|
-
- MCP 版本:${process.env.npm_package_version || "1.8.
|
|
179981
|
+
- MCP 版本:${process.env.npm_package_version || "1.8.42" || 0}
|
|
180050
179982
|
- 系统架构: ${os_1.default.arch()}
|
|
180051
179983
|
- 时间: ${new Date().toISOString()}
|
|
180052
179984
|
- 请求ID: ${requestId}
|
|
@@ -195072,7 +195004,7 @@ function registerSetupTools(server) {
|
|
|
195072
195004
|
// downloadTemplate - 下载项目模板 (cloud-incompatible)
|
|
195073
195005
|
server.registerTool("downloadTemplate", {
|
|
195074
195006
|
title: "下载项目模板",
|
|
195075
|
-
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.
|
|
195007
|
+
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)`,
|
|
195076
195008
|
inputSchema: {
|
|
195077
195009
|
template: zod_1.z.enum(["react", "vue", "miniprogram", "uniapp", "rules"]).describe("要下载的模板类型"),
|
|
195078
195010
|
ide: zod_1.z.enum(IDE_TYPES).optional().default("all").describe("指定要下载的IDE类型,默认为all(下载所有IDE配置)"),
|
|
@@ -219696,7 +219628,11 @@ function shouldRegisterTool(toolName) {
|
|
|
219696
219628
|
'setupEnvironmentId',
|
|
219697
219629
|
'clearUserEnvId',
|
|
219698
219630
|
// Interactive tools - local server and file operations
|
|
219699
|
-
'interactiveDialog'
|
|
219631
|
+
'interactiveDialog',
|
|
219632
|
+
// CloudRun tools - local file operations
|
|
219633
|
+
'manageCloudRun',
|
|
219634
|
+
// Download tools - local file downloads
|
|
219635
|
+
'manageStorage',
|
|
219700
219636
|
];
|
|
219701
219637
|
const shouldRegister = !cloudIncompatibleTools.includes(toolName);
|
|
219702
219638
|
if (!shouldRegister) {
|
|
@@ -237152,54 +237088,285 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
|
237152
237088
|
exports.registerStorageTools = registerStorageTools;
|
|
237153
237089
|
const zod_1 = __webpack_require__(21614);
|
|
237154
237090
|
const cloudbase_manager_js_1 = __webpack_require__(3431);
|
|
237091
|
+
// Input schema for queryStorage tool
|
|
237092
|
+
const queryStorageInputSchema = {
|
|
237093
|
+
action: zod_1.z.enum(['list', 'info', 'url']).describe('查询操作类型:list=列出目录下的所有文件,info=获取指定文件的详细信息,url=获取文件的临时下载链接'),
|
|
237094
|
+
cloudPath: zod_1.z.string().describe('云端文件路径,例如 files/data.txt 或 files/(目录)'),
|
|
237095
|
+
maxAge: zod_1.z.number().min(1).max(86400).optional().default(3600).describe('临时链接有效期,单位为秒,取值范围:1-86400,默认值:3600(1小时)')
|
|
237096
|
+
};
|
|
237097
|
+
// Input schema for manageStorage tool
|
|
237098
|
+
const manageStorageInputSchema = {
|
|
237099
|
+
action: zod_1.z.enum(['upload', 'download', 'delete']).describe('管理操作类型:upload=上传文件或目录,download=下载文件或目录,delete=删除文件或目录'),
|
|
237100
|
+
localPath: zod_1.z.string().describe('本地文件路径,建议传入绝对路径,例如 /tmp/files/data.txt'),
|
|
237101
|
+
cloudPath: zod_1.z.string().describe('云端文件路径,例如 files/data.txt'),
|
|
237102
|
+
force: zod_1.z.boolean().optional().default(false).describe('强制操作开关,删除操作时建议设置为true以确认删除,默认false'),
|
|
237103
|
+
isDirectory: zod_1.z.boolean().optional().default(false).describe('是否为目录操作,true=目录操作,false=文件操作,默认false')
|
|
237104
|
+
};
|
|
237155
237105
|
function registerStorageTools(server) {
|
|
237156
237106
|
// 获取 cloudBaseOptions,如果没有则为 undefined
|
|
237157
237107
|
const cloudBaseOptions = server.cloudBaseOptions;
|
|
237158
237108
|
// 创建闭包函数来获取 CloudBase Manager
|
|
237159
237109
|
const getManager = () => (0, cloudbase_manager_js_1.getCloudBaseManager)({ cloudBaseOptions });
|
|
237160
|
-
//
|
|
237161
|
-
server.registerTool("
|
|
237162
|
-
title: "
|
|
237163
|
-
description: "
|
|
237164
|
-
inputSchema:
|
|
237165
|
-
|
|
237166
|
-
|
|
237167
|
-
|
|
237110
|
+
// Tool 1: queryStorage - 查询存储信息(只读操作)
|
|
237111
|
+
server.registerTool("queryStorage", {
|
|
237112
|
+
title: "查询存储信息",
|
|
237113
|
+
description: "查询云存储信息,支持列出目录文件、获取文件信息、获取临时下载链接等只读操作。返回的文件信息包括文件名、大小、修改时间、下载链接等。",
|
|
237114
|
+
inputSchema: queryStorageInputSchema,
|
|
237115
|
+
annotations: {
|
|
237116
|
+
readOnlyHint: true,
|
|
237117
|
+
openWorldHint: true,
|
|
237118
|
+
category: "storage"
|
|
237119
|
+
}
|
|
237120
|
+
}, async (args) => {
|
|
237121
|
+
try {
|
|
237122
|
+
const input = args;
|
|
237123
|
+
const manager = await getManager();
|
|
237124
|
+
if (!manager) {
|
|
237125
|
+
throw new Error("Failed to initialize CloudBase manager. Please check your credentials and environment configuration.");
|
|
237126
|
+
}
|
|
237127
|
+
const storageService = manager.storage;
|
|
237128
|
+
switch (input.action) {
|
|
237129
|
+
case 'list': {
|
|
237130
|
+
const result = await storageService.listDirectoryFiles(input.cloudPath);
|
|
237131
|
+
return {
|
|
237132
|
+
content: [
|
|
237133
|
+
{
|
|
237134
|
+
type: "text",
|
|
237135
|
+
text: JSON.stringify({
|
|
237136
|
+
success: true,
|
|
237137
|
+
data: {
|
|
237138
|
+
action: 'list',
|
|
237139
|
+
cloudPath: input.cloudPath,
|
|
237140
|
+
files: result || [],
|
|
237141
|
+
totalCount: result?.length || 0
|
|
237142
|
+
},
|
|
237143
|
+
message: `Successfully listed ${result?.length || 0} files in directory '${input.cloudPath}'`
|
|
237144
|
+
}, null, 2)
|
|
237145
|
+
}
|
|
237146
|
+
]
|
|
237147
|
+
};
|
|
237148
|
+
}
|
|
237149
|
+
case 'info': {
|
|
237150
|
+
const result = await storageService.getFileInfo(input.cloudPath);
|
|
237151
|
+
return {
|
|
237152
|
+
content: [
|
|
237153
|
+
{
|
|
237154
|
+
type: "text",
|
|
237155
|
+
text: JSON.stringify({
|
|
237156
|
+
success: true,
|
|
237157
|
+
data: {
|
|
237158
|
+
action: 'info',
|
|
237159
|
+
cloudPath: input.cloudPath,
|
|
237160
|
+
fileInfo: result
|
|
237161
|
+
},
|
|
237162
|
+
message: `Successfully retrieved file info for '${input.cloudPath}'`
|
|
237163
|
+
}, null, 2)
|
|
237164
|
+
}
|
|
237165
|
+
]
|
|
237166
|
+
};
|
|
237167
|
+
}
|
|
237168
|
+
case 'url': {
|
|
237169
|
+
const result = await storageService.getTemporaryUrl([{
|
|
237170
|
+
cloudPath: input.cloudPath,
|
|
237171
|
+
maxAge: input.maxAge || 3600
|
|
237172
|
+
}]);
|
|
237173
|
+
return {
|
|
237174
|
+
content: [
|
|
237175
|
+
{
|
|
237176
|
+
type: "text",
|
|
237177
|
+
text: JSON.stringify({
|
|
237178
|
+
success: true,
|
|
237179
|
+
data: {
|
|
237180
|
+
action: 'url',
|
|
237181
|
+
cloudPath: input.cloudPath,
|
|
237182
|
+
temporaryUrl: result[0]?.url || "",
|
|
237183
|
+
expireTime: `${input.maxAge || 3600}秒`,
|
|
237184
|
+
fileId: result[0]?.fileId || ""
|
|
237185
|
+
},
|
|
237186
|
+
message: `Successfully generated temporary URL for '${input.cloudPath}'`
|
|
237187
|
+
}, null, 2)
|
|
237188
|
+
}
|
|
237189
|
+
]
|
|
237190
|
+
};
|
|
237191
|
+
}
|
|
237192
|
+
default:
|
|
237193
|
+
throw new Error(`Unsupported action: ${input.action}`);
|
|
237194
|
+
}
|
|
237195
|
+
}
|
|
237196
|
+
catch (error) {
|
|
237197
|
+
return {
|
|
237198
|
+
content: [
|
|
237199
|
+
{
|
|
237200
|
+
type: "text",
|
|
237201
|
+
text: JSON.stringify({
|
|
237202
|
+
success: false,
|
|
237203
|
+
error: error.message || 'Unknown error occurred',
|
|
237204
|
+
message: `Failed to query storage information. Please check your permissions and parameters.`
|
|
237205
|
+
}, null, 2)
|
|
237206
|
+
}
|
|
237207
|
+
]
|
|
237208
|
+
};
|
|
237209
|
+
}
|
|
237210
|
+
});
|
|
237211
|
+
// Tool 2: manageStorage - 管理存储文件(写操作)
|
|
237212
|
+
server.registerTool("manageStorage", {
|
|
237213
|
+
title: "管理存储文件",
|
|
237214
|
+
description: "管理云存储文件,支持上传文件/目录、下载文件/目录、删除文件/目录等操作。删除操作需要设置force=true进行确认,防止误删除重要文件。",
|
|
237215
|
+
inputSchema: manageStorageInputSchema,
|
|
237168
237216
|
annotations: {
|
|
237169
237217
|
readOnlyHint: false,
|
|
237170
|
-
destructiveHint:
|
|
237218
|
+
destructiveHint: true,
|
|
237171
237219
|
idempotentHint: false,
|
|
237172
237220
|
openWorldHint: true,
|
|
237173
237221
|
category: "storage"
|
|
237174
237222
|
}
|
|
237175
|
-
}, async (
|
|
237176
|
-
|
|
237177
|
-
|
|
237178
|
-
|
|
237179
|
-
|
|
237180
|
-
|
|
237181
|
-
onProgress: (progressData) => {
|
|
237182
|
-
console.log("Upload progress:", progressData);
|
|
237223
|
+
}, async (args) => {
|
|
237224
|
+
try {
|
|
237225
|
+
const input = args;
|
|
237226
|
+
const manager = await getManager();
|
|
237227
|
+
if (!manager) {
|
|
237228
|
+
throw new Error("Failed to initialize CloudBase manager. Please check your credentials and environment configuration.");
|
|
237183
237229
|
}
|
|
237184
|
-
|
|
237185
|
-
|
|
237186
|
-
|
|
237187
|
-
|
|
237188
|
-
|
|
237189
|
-
|
|
237190
|
-
|
|
237191
|
-
|
|
237192
|
-
|
|
237193
|
-
|
|
237194
|
-
|
|
237195
|
-
|
|
237196
|
-
|
|
237197
|
-
|
|
237198
|
-
|
|
237199
|
-
|
|
237230
|
+
const storageService = manager.storage;
|
|
237231
|
+
switch (input.action) {
|
|
237232
|
+
case 'upload': {
|
|
237233
|
+
if (input.isDirectory) {
|
|
237234
|
+
// 上传目录
|
|
237235
|
+
await storageService.uploadDirectory({
|
|
237236
|
+
localPath: input.localPath,
|
|
237237
|
+
cloudPath: input.cloudPath,
|
|
237238
|
+
onProgress: (progressData) => {
|
|
237239
|
+
console.log("Upload directory progress:", progressData);
|
|
237240
|
+
}
|
|
237241
|
+
});
|
|
237242
|
+
}
|
|
237243
|
+
else {
|
|
237244
|
+
// 上传文件
|
|
237245
|
+
await storageService.uploadFile({
|
|
237246
|
+
localPath: input.localPath,
|
|
237247
|
+
cloudPath: input.cloudPath,
|
|
237248
|
+
onProgress: (progressData) => {
|
|
237249
|
+
console.log("Upload file progress:", progressData);
|
|
237250
|
+
}
|
|
237251
|
+
});
|
|
237252
|
+
}
|
|
237253
|
+
// 获取文件临时下载地址
|
|
237254
|
+
const fileUrls = await storageService.getTemporaryUrl([{
|
|
237255
|
+
cloudPath: input.cloudPath,
|
|
237256
|
+
maxAge: 3600 // 临时链接有效期1小时
|
|
237257
|
+
}]);
|
|
237258
|
+
return {
|
|
237259
|
+
content: [
|
|
237260
|
+
{
|
|
237261
|
+
type: "text",
|
|
237262
|
+
text: JSON.stringify({
|
|
237263
|
+
success: true,
|
|
237264
|
+
data: {
|
|
237265
|
+
action: 'upload',
|
|
237266
|
+
localPath: input.localPath,
|
|
237267
|
+
cloudPath: input.cloudPath,
|
|
237268
|
+
isDirectory: input.isDirectory,
|
|
237269
|
+
temporaryUrl: fileUrls[0]?.url || "",
|
|
237270
|
+
expireTime: "1小时"
|
|
237271
|
+
},
|
|
237272
|
+
message: `Successfully uploaded ${input.isDirectory ? 'directory' : 'file'} from '${input.localPath}' to '${input.cloudPath}'`
|
|
237273
|
+
}, null, 2)
|
|
237274
|
+
}
|
|
237275
|
+
]
|
|
237276
|
+
};
|
|
237200
237277
|
}
|
|
237201
|
-
|
|
237202
|
-
|
|
237278
|
+
case 'download': {
|
|
237279
|
+
if (input.isDirectory) {
|
|
237280
|
+
// 下载目录
|
|
237281
|
+
await storageService.downloadDirectory({
|
|
237282
|
+
cloudPath: input.cloudPath,
|
|
237283
|
+
localPath: input.localPath
|
|
237284
|
+
});
|
|
237285
|
+
}
|
|
237286
|
+
else {
|
|
237287
|
+
// 下载文件
|
|
237288
|
+
await storageService.downloadFile({
|
|
237289
|
+
cloudPath: input.cloudPath,
|
|
237290
|
+
localPath: input.localPath
|
|
237291
|
+
});
|
|
237292
|
+
}
|
|
237293
|
+
return {
|
|
237294
|
+
content: [
|
|
237295
|
+
{
|
|
237296
|
+
type: "text",
|
|
237297
|
+
text: JSON.stringify({
|
|
237298
|
+
success: true,
|
|
237299
|
+
data: {
|
|
237300
|
+
action: 'download',
|
|
237301
|
+
cloudPath: input.cloudPath,
|
|
237302
|
+
localPath: input.localPath,
|
|
237303
|
+
isDirectory: input.isDirectory
|
|
237304
|
+
},
|
|
237305
|
+
message: `Successfully downloaded ${input.isDirectory ? 'directory' : 'file'} from '${input.cloudPath}' to '${input.localPath}'`
|
|
237306
|
+
}, null, 2)
|
|
237307
|
+
}
|
|
237308
|
+
]
|
|
237309
|
+
};
|
|
237310
|
+
}
|
|
237311
|
+
case 'delete': {
|
|
237312
|
+
if (!input.force) {
|
|
237313
|
+
return {
|
|
237314
|
+
content: [
|
|
237315
|
+
{
|
|
237316
|
+
type: "text",
|
|
237317
|
+
text: JSON.stringify({
|
|
237318
|
+
success: false,
|
|
237319
|
+
error: "Delete operation requires confirmation",
|
|
237320
|
+
message: "Please set force: true to confirm deletion. This action cannot be undone."
|
|
237321
|
+
}, null, 2)
|
|
237322
|
+
}
|
|
237323
|
+
]
|
|
237324
|
+
};
|
|
237325
|
+
}
|
|
237326
|
+
if (input.isDirectory) {
|
|
237327
|
+
// 删除目录
|
|
237328
|
+
await storageService.deleteDirectory(input.cloudPath);
|
|
237329
|
+
}
|
|
237330
|
+
else {
|
|
237331
|
+
// 删除文件
|
|
237332
|
+
await storageService.deleteFile([input.cloudPath]);
|
|
237333
|
+
}
|
|
237334
|
+
return {
|
|
237335
|
+
content: [
|
|
237336
|
+
{
|
|
237337
|
+
type: "text",
|
|
237338
|
+
text: JSON.stringify({
|
|
237339
|
+
success: true,
|
|
237340
|
+
data: {
|
|
237341
|
+
action: 'delete',
|
|
237342
|
+
cloudPath: input.cloudPath,
|
|
237343
|
+
isDirectory: input.isDirectory,
|
|
237344
|
+
deleted: true
|
|
237345
|
+
},
|
|
237346
|
+
message: `Successfully deleted ${input.isDirectory ? 'directory' : 'file'} '${input.cloudPath}'`
|
|
237347
|
+
}, null, 2)
|
|
237348
|
+
}
|
|
237349
|
+
]
|
|
237350
|
+
};
|
|
237351
|
+
}
|
|
237352
|
+
default:
|
|
237353
|
+
throw new Error(`Unsupported action: ${input.action}`);
|
|
237354
|
+
}
|
|
237355
|
+
}
|
|
237356
|
+
catch (error) {
|
|
237357
|
+
return {
|
|
237358
|
+
content: [
|
|
237359
|
+
{
|
|
237360
|
+
type: "text",
|
|
237361
|
+
text: JSON.stringify({
|
|
237362
|
+
success: false,
|
|
237363
|
+
error: error.message || 'Unknown error occurred',
|
|
237364
|
+
message: `Failed to manage storage. Please check your permissions and parameters.`
|
|
237365
|
+
}, null, 2)
|
|
237366
|
+
}
|
|
237367
|
+
]
|
|
237368
|
+
};
|
|
237369
|
+
}
|
|
237203
237370
|
});
|
|
237204
237371
|
}
|
|
237205
237372
|
|