adp-openclaw 0.0.43 → 0.0.45

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adp-openclaw",
3
- "version": "0.0.43",
3
+ "version": "0.0.45",
4
4
  "description": "ADP-OpenClaw demo channel plugin (Go WebSocket backend)",
5
5
  "type": "module",
6
6
  "dependencies": {
@@ -66,42 +66,65 @@ const REQUEST_TIMEOUT_MS = 30000;
66
66
 
67
67
  // ==================== 工具函数 ====================
68
68
 
69
+ /** 扩展名到 MIME 类型的映射 */
70
+ const EXT_TO_MIME_MAP: Record<string, string> = {
71
+ ".txt": "text/plain",
72
+ ".md": "text/markdown",
73
+ ".json": "application/json",
74
+ ".html": "text/html",
75
+ ".css": "text/css",
76
+ ".js": "text/javascript",
77
+ ".ts": "text/x.typescript",
78
+ ".xml": "application/xml",
79
+ ".yaml": "application/yaml",
80
+ ".yml": "application/yaml",
81
+ ".pdf": "application/pdf",
82
+ ".png": "image/png",
83
+ ".jpg": "image/jpeg",
84
+ ".jpeg": "image/jpeg",
85
+ ".gif": "image/gif",
86
+ ".webp": "image/webp",
87
+ ".svg": "image/svg+xml",
88
+ ".csv": "text/csv",
89
+ ".zip": "application/zip",
90
+ ".doc": "application/msword",
91
+ ".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
92
+ ".xls": "application/vnd.ms-excel",
93
+ ".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
94
+ ".ppt": "application/vnd.ms-powerpoint",
95
+ ".pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
96
+ ".mp3": "audio/mpeg",
97
+ ".mp4": "video/mp4",
98
+ ".wav": "audio/wav",
99
+ };
100
+
101
+ /** MIME 类型到扩展名的映射(反向映射) */
102
+ const MIME_TO_EXT_MAP: Record<string, string> = Object.fromEntries(
103
+ Object.entries(EXT_TO_MIME_MAP).map(([ext, mime]) => [mime, ext.slice(1)]) // 去掉 "." 前缀
104
+ );
105
+
69
106
  /**
70
107
  * 根据文件扩展名推断 MIME 类型
71
- */
108
+ */
72
109
  function inferMimeType(fileName: string): string {
73
110
  const ext = extname(fileName).toLowerCase();
74
- const mimeMap: Record<string, string> = {
75
- ".txt": "text/plain",
76
- ".md": "text/markdown",
77
- ".json": "application/json",
78
- ".html": "text/html",
79
- ".css": "text/css",
80
- ".js": "text/javascript",
81
- ".ts": "text/x.typescript",
82
- ".xml": "application/xml",
83
- ".yaml": "application/yaml",
84
- ".yml": "application/yaml",
85
- ".pdf": "application/pdf",
86
- ".png": "image/png",
87
- ".jpg": "image/jpeg",
88
- ".jpeg": "image/jpeg",
89
- ".gif": "image/gif",
90
- ".webp": "image/webp",
91
- ".svg": "image/svg+xml",
92
- ".csv": "text/csv",
93
- ".zip": "application/zip",
94
- ".doc": "application/msword",
95
- ".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
96
- ".xls": "application/vnd.ms-excel",
97
- ".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
98
- ".ppt": "application/vnd.ms-powerpoint",
99
- ".pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
100
- ".mp3": "audio/mpeg",
101
- ".mp4": "video/mp4",
102
- ".wav": "audio/wav",
103
- };
104
- return mimeMap[ext] || "application/octet-stream";
111
+ return EXT_TO_MIME_MAP[ext] || "application/octet-stream";
112
+ }
113
+
114
+ /**
115
+ * 把 MIME 类型或扩展名转换为纯扩展名(不带点)
116
+ * 服务端 API 期望的是文件扩展名,而不是 MIME 类型
117
+ */
118
+ function toFileExtension(fileTypeOrMime: string): string {
119
+ if (!fileTypeOrMime) return "";
120
+
121
+ // 如果已经是扩展名格式(不包含 /),直接返回(去掉可能的前导点)
122
+ if (!fileTypeOrMime.includes("/")) {
123
+ return fileTypeOrMime.replace(/^\./, "");
124
+ }
125
+
126
+ // 如果是 MIME 类型,转换为扩展名
127
+ return MIME_TO_EXT_MAP[fileTypeOrMime] || fileTypeOrMime;
105
128
  }
106
129
 
107
130
  /**
@@ -163,13 +186,16 @@ export async function getStorageCredential(
163
186
  token: string,
164
187
  fileType?: string
165
188
  ): Promise<DescribeRemoteBotStorageCredentialRsp> {
189
+ // 把 MIME 类型转换为文件扩展名,服务端 API 期望的是扩展名
190
+ const fileExtension = toFileExtension(fileType || "");
191
+
166
192
  const requestBody: DescribeRemoteBotStorageCredentialReq = {
167
193
  token,
168
- file_type: fileType || "",
194
+ file_type: fileExtension,
169
195
  };
170
196
 
171
197
  console.log(`[ADP-UPLOAD] Calling credential API: ${CREDENTIAL_API_URL}`);
172
- console.log(`[ADP-UPLOAD] Request body: token=${token.substring(0, 10)}..., file_type=${fileType || ""}`);
198
+ console.log(`[ADP-UPLOAD] Request body: token=${token.substring(0, 10)}..., file_type=${fileExtension} (original: ${fileType || ""})`);
173
199
 
174
200
  const response = await fetchWithTimeout(
175
201
  CREDENTIAL_API_URL,
@@ -236,7 +262,7 @@ export async function uploadFileToCos(
236
262
  const fileUrl = credential.file_url;
237
263
 
238
264
  console.log(`[ADP-UPLOAD] upload_url: ${uploadUrl.substring(0, 100)}...`);
239
- console.log(`[ADP-UPLOAD] file_url (download): ${fileUrl.substring(0, 100)}...`);
265
+ console.log(`[ADP-UPLOAD] file_url (download): ${fileUrl}...`);
240
266
 
241
267
  // 4. 执行上传(直接PUT到预签名URL,不需要额外签名)
242
268
  const response = await fetchWithTimeout(
@@ -257,7 +283,7 @@ export async function uploadFileToCos(
257
283
  throw new Error(`上传文件失败: ${response.status} ${errorText}`);
258
284
  }
259
285
 
260
- console.log(`[ADP-UPLOAD] Upload success, returning file_url: ${fileUrl.substring(0, 100)}...`);
286
+ console.log(`[ADP-UPLOAD] Upload success, returning file_url: ${fileUrl}...`);
261
287
 
262
288
  // 5. 返回下载URL
263
289
  return fileUrl;
package/src/monitor.ts CHANGED
@@ -452,6 +452,11 @@ async function connectAndHandle(params: ConnectParams): Promise<void> {
452
452
  if (toolName === ADP_UPLOAD_TOOL_NAME && toolResult && typeof toolResult === "object") {
453
453
  const result = toolResult as AdpUploadToolResult;
454
454
  if (result.ok && result.files && result.files.length > 0) {
455
+ // Debug: print full downloadUrl before formatting
456
+ for (const file of result.files) {
457
+ log?.info(`[adp-openclaw] File downloadUrl (full): ${file.downloadUrl}`);
458
+ }
459
+
455
460
  // Format upload result as user-readable message
456
461
  const uploadMessage = formatUploadResultAsMarkdown(result);
457
462
 
@@ -247,6 +247,7 @@ export const formatUploadResultAsMarkdown = (result: AdpUploadToolResult): strin
247
247
 
248
248
  const lines: string[] = ["**文件上传成功**:"];
249
249
  for (const file of result.files) {
250
+ console.log(`[ADP-UPLOAD] formatUploadResultAsMarkdown - file.downloadUrl: ${file.downloadUrl}`);
250
251
  if (file.downloadUrl) {
251
252
  lines.push(`- [${file.name}](${file.downloadUrl})`);
252
253
  } else {