adp-openclaw 0.0.30 → 0.0.31
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/index.ts +47 -0
- package/package.json +4 -2
- package/src/adp-upload-tool.test.ts +122 -0
- package/src/adp-upload-tool.ts +911 -0
- package/src/channel.ts +1 -1
- package/src/monitor.ts +52 -4
- package/src/tool-result-message-blocks.ts +258 -0
- package/uploadfile.pb +33 -0
package/index.ts
CHANGED
|
@@ -25,6 +25,53 @@ export {
|
|
|
25
25
|
type SessionFileConfig,
|
|
26
26
|
} from "./src/session-history.js";
|
|
27
27
|
|
|
28
|
+
// Export ADP upload tool functions and types
|
|
29
|
+
export {
|
|
30
|
+
// Tool name and schema
|
|
31
|
+
ADP_UPLOAD_TOOL_NAME,
|
|
32
|
+
ADP_UPLOAD_TOOL_SCHEMA,
|
|
33
|
+
ADP_UPLOAD_TOOL_MAX_PATHS,
|
|
34
|
+
ADP_UPLOAD_TOOL_MIN_PATHS,
|
|
35
|
+
ADP_UPLOAD_TOOL_MAX_CONCURRENCY,
|
|
36
|
+
ADP_UPLOAD_VALIDATION_MESSAGE,
|
|
37
|
+
// Main functions
|
|
38
|
+
adpUploadFile,
|
|
39
|
+
adpUploadFiles,
|
|
40
|
+
adpUploadFileWithConfig,
|
|
41
|
+
adpUploadFilesWithConfig,
|
|
42
|
+
getStorageCredential,
|
|
43
|
+
uploadFileToCos,
|
|
44
|
+
getSignedDownloadUrl,
|
|
45
|
+
resolveClientToken,
|
|
46
|
+
// Class
|
|
47
|
+
AdpUploader,
|
|
48
|
+
// Tool execution functions
|
|
49
|
+
parseAdpUploadToolParams,
|
|
50
|
+
uploadFilesToAdpEndpoint,
|
|
51
|
+
executeAdpUploadTool,
|
|
52
|
+
// Types
|
|
53
|
+
type UploadResult,
|
|
54
|
+
type AdpUploadToolParams,
|
|
55
|
+
type AdpUploadToolResult,
|
|
56
|
+
type UploadedFileInfo,
|
|
57
|
+
type AdpUploadOptions,
|
|
58
|
+
type DescribeRemoteBotStorageCredentialReq,
|
|
59
|
+
type DescribeRemoteBotStorageCredentialRsp,
|
|
60
|
+
type Credentials,
|
|
61
|
+
} from "./src/adp-upload-tool.js";
|
|
62
|
+
|
|
63
|
+
// Export tool result message blocks functions
|
|
64
|
+
export {
|
|
65
|
+
dispatchToolResultToMessageBlocks,
|
|
66
|
+
buildToolResultSessionContentBlocks,
|
|
67
|
+
formatUploadResultForUser,
|
|
68
|
+
formatUploadResultAsMarkdown,
|
|
69
|
+
type ResourceLinkBlock,
|
|
70
|
+
type TextBlock,
|
|
71
|
+
type ContentBlock,
|
|
72
|
+
type MessageBlock,
|
|
73
|
+
} from "./src/tool-result-message-blocks.js";
|
|
74
|
+
|
|
28
75
|
const plugin = {
|
|
29
76
|
id: "adp-openclaw",
|
|
30
77
|
name: "ADP OpenClaw",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "adp-openclaw",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.31",
|
|
4
4
|
"description": "ADP-OpenClaw demo channel plugin (Go WebSocket backend)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"dependencies": {
|
|
@@ -8,7 +8,9 @@
|
|
|
8
8
|
"zod": "^3.22.4"
|
|
9
9
|
},
|
|
10
10
|
"devDependencies": {
|
|
11
|
-
"@types/
|
|
11
|
+
"@types/node": "^20.11.0",
|
|
12
|
+
"@types/ws": "^8.5.10",
|
|
13
|
+
"typescript": "^5.9.3"
|
|
12
14
|
},
|
|
13
15
|
"openclaw": {
|
|
14
16
|
"extensions": [
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ADP Upload Tool 测试文件
|
|
3
|
+
*
|
|
4
|
+
* 使用方式:
|
|
5
|
+
*
|
|
6
|
+
* 1. 使用环境变量(推荐,与插件配置一致):
|
|
7
|
+
* ADP_OPENCLAW_CLIENT_TOKEN=your-token npx tsx src/adp-upload-tool.test.ts <filePath>
|
|
8
|
+
*
|
|
9
|
+
* 2. 使用命令行参数:
|
|
10
|
+
* npx tsx src/adp-upload-tool.test.ts --token <botToken> <filePath>
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { AdpUploader, getStorageCredential } from "./adp-upload-tool.js";
|
|
14
|
+
|
|
15
|
+
async function main() {
|
|
16
|
+
const args = process.argv.slice(2);
|
|
17
|
+
|
|
18
|
+
let botToken: string | undefined;
|
|
19
|
+
let filePaths: string[] = [];
|
|
20
|
+
|
|
21
|
+
// 解析参数
|
|
22
|
+
for (let i = 0; i < args.length; i++) {
|
|
23
|
+
if (args[i] === "--token" && i + 1 < args.length) {
|
|
24
|
+
botToken = args[i + 1];
|
|
25
|
+
i++; // 跳过下一个参数
|
|
26
|
+
} else if (!args[i].startsWith("--")) {
|
|
27
|
+
filePaths.push(args[i]);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// 如果没有通过参数传入 token,尝试从环境变量读取
|
|
32
|
+
if (!botToken) {
|
|
33
|
+
botToken = process.env.ADP_OPENCLAW_CLIENT_TOKEN;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (filePaths.length === 0) {
|
|
37
|
+
console.log("ADP Upload Tool 测试");
|
|
38
|
+
console.log("");
|
|
39
|
+
console.log("使用方式:");
|
|
40
|
+
console.log(" 1. 使用环境变量(推荐,与插件配置一致):");
|
|
41
|
+
console.log(" ADP_OPENCLAW_CLIENT_TOKEN=your-token npx tsx src/adp-upload-tool.test.ts <filePath>");
|
|
42
|
+
console.log("");
|
|
43
|
+
console.log(" 2. 使用命令行参数:");
|
|
44
|
+
console.log(" npx tsx src/adp-upload-tool.test.ts --token <botToken> <filePath>");
|
|
45
|
+
console.log("");
|
|
46
|
+
console.log("示例:");
|
|
47
|
+
console.log(" npx tsx src/adp-upload-tool.test.ts --token my-bot-token ./test.txt");
|
|
48
|
+
console.log(" ADP_OPENCLAW_CLIENT_TOKEN=my-token npx tsx src/adp-upload-tool.test.ts ./file1.txt ./file2.pdf");
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (!botToken) {
|
|
53
|
+
console.error("错误: 未提供 botToken");
|
|
54
|
+
console.error("请通过 --token 参数或 ADP_OPENCLAW_CLIENT_TOKEN 环境变量设置");
|
|
55
|
+
process.exit(1);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
console.log("=".repeat(60));
|
|
59
|
+
console.log("ADP Upload Tool 测试");
|
|
60
|
+
console.log("=".repeat(60));
|
|
61
|
+
console.log(`Bot Token: ${botToken.substring(0, 10)}...`);
|
|
62
|
+
console.log(`文件列表: ${filePaths.join(", ")}`);
|
|
63
|
+
console.log("");
|
|
64
|
+
|
|
65
|
+
// 测试获取临时密钥
|
|
66
|
+
console.log("1. 测试获取临时密钥...");
|
|
67
|
+
try {
|
|
68
|
+
const credential = await getStorageCredential(botToken);
|
|
69
|
+
console.log(" ✓ 获取密钥成功");
|
|
70
|
+
console.log(` - Bucket: ${credential.bucket}`);
|
|
71
|
+
console.log(` - Region: ${credential.region}`);
|
|
72
|
+
console.log(` - File Path: ${credential.file_path}`);
|
|
73
|
+
console.log(` - Secret ID: ${credential.credentials.tmp_secret_id.substring(0, 10)}...`);
|
|
74
|
+
console.log(` - 有效期至: ${new Date(credential.expired_time * 1000).toLocaleString()}`);
|
|
75
|
+
console.log("");
|
|
76
|
+
} catch (error) {
|
|
77
|
+
console.log(" ✗ 获取密钥失败");
|
|
78
|
+
console.log(` - 错误: ${error instanceof Error ? error.message : error}`);
|
|
79
|
+
process.exit(1);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// 使用 AdpUploader 类测试上传
|
|
83
|
+
console.log("2. 使用 AdpUploader 测试上传...");
|
|
84
|
+
const uploader = new AdpUploader({ clientToken: botToken });
|
|
85
|
+
console.log(` - 配置状态: ${uploader.isConfigured() ? "已配置" : "未配置"}`);
|
|
86
|
+
console.log(` - Token 预览: ${uploader.getTokenPreview()}`);
|
|
87
|
+
console.log("");
|
|
88
|
+
|
|
89
|
+
if (filePaths.length === 1) {
|
|
90
|
+
// 单文件上传
|
|
91
|
+
console.log("3. 测试单文件上传...");
|
|
92
|
+
const result = await uploader.upload(filePaths[0]);
|
|
93
|
+
if (result.ok) {
|
|
94
|
+
console.log(" ✓ 上传成功");
|
|
95
|
+
console.log(` - 下载链接: ${result.fileUrl}`);
|
|
96
|
+
} else {
|
|
97
|
+
console.log(" ✗ 上传失败");
|
|
98
|
+
console.log(` - 错误: ${result.error}`);
|
|
99
|
+
}
|
|
100
|
+
} else {
|
|
101
|
+
// 批量上传
|
|
102
|
+
console.log("3. 测试批量上传...");
|
|
103
|
+
const results = await uploader.uploadMultiple(filePaths);
|
|
104
|
+
results.forEach((result, index) => {
|
|
105
|
+
const filePath = filePaths[index];
|
|
106
|
+
if (result.ok) {
|
|
107
|
+
console.log(` ✓ [${filePath}] 上传成功`);
|
|
108
|
+
console.log(` 下载链接: ${result.fileUrl}`);
|
|
109
|
+
} else {
|
|
110
|
+
console.log(` ✗ [${filePath}] 上传失败`);
|
|
111
|
+
console.log(` 错误: ${result.error}`);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
console.log("");
|
|
117
|
+
console.log("=".repeat(60));
|
|
118
|
+
console.log("测试完成");
|
|
119
|
+
console.log("=".repeat(60));
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
main().catch(console.error);
|