clawchain-wallet 1.0.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/SKILL.md +243 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +89 -0
- package/dist/src/executor.d.ts +23 -0
- package/dist/src/executor.js +65 -0
- package/dist/src/tools.d.ts +41 -0
- package/dist/src/tools.js +528 -0
- package/dist/src/types.d.ts +40 -0
- package/dist/src/types.js +4 -0
- package/index.ts +103 -0
- package/openclaw.plugin.json +16 -0
- package/package.json +76 -0
- package/python/clawchain_cli.py +1193 -0
- package/python/requirements.txt +2 -0
- package/scripts/postinstall.js +243 -0
- package/src/executor.ts +88 -0
- package/src/tools.ts +623 -0
- package/src/types.ts +45 -0
- package/tsconfig.json +15 -0
package/SKILL.md
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: clawchain-wallet
|
|
3
|
+
version: 1.0.0
|
|
4
|
+
description: ClawChain 私有链钱包管理工具 - 创建钱包、管理钱包、余额查询、转账、领取空投
|
|
5
|
+
homepage: https://github.com/your-repo/clawchain-wallet
|
|
6
|
+
metadata:
|
|
7
|
+
{
|
|
8
|
+
"clawchain":
|
|
9
|
+
{
|
|
10
|
+
"emoji": "💎",
|
|
11
|
+
"category": "blockchain",
|
|
12
|
+
"chain_name": "ClawChain",
|
|
13
|
+
"token_symbol": "CLAW",
|
|
14
|
+
"rpc_url": "https://n1.clawchain.net",
|
|
15
|
+
"chain_id": 1911,
|
|
16
|
+
},
|
|
17
|
+
"openclaw":
|
|
18
|
+
{
|
|
19
|
+
"requires": { "bins": ["python3"] },
|
|
20
|
+
"install":
|
|
21
|
+
[
|
|
22
|
+
{
|
|
23
|
+
"id": "npm",
|
|
24
|
+
"kind": "node",
|
|
25
|
+
"package": "clawchain-wallet",
|
|
26
|
+
"label": "Install ClawChain Wallet (npm)",
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
},
|
|
30
|
+
}
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
# ClawChain Wallet
|
|
34
|
+
|
|
35
|
+
ClawChain 私有链钱包管理工具,支持创建钱包、导入钱包、余额查询、转账等功能。
|
|
36
|
+
|
|
37
|
+
## 快速安装
|
|
38
|
+
|
|
39
|
+
**一键安装**(推荐):
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
npm install -g clawchain-wallet
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
安装过程会自动:
|
|
46
|
+
1. 安装 Python 依赖 (web3, eth-account)
|
|
47
|
+
2. 编译 TypeScript
|
|
48
|
+
3. 注册到 OpenClaw(如果已安装)
|
|
49
|
+
|
|
50
|
+
**或者手动安装**:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
# 克隆仓库
|
|
54
|
+
git clone https://github.com/your-repo/clawchain-wallet.git
|
|
55
|
+
cd clawchain-wallet
|
|
56
|
+
|
|
57
|
+
# 安装依赖
|
|
58
|
+
npm install
|
|
59
|
+
pip3 install -r python/requirements.txt
|
|
60
|
+
|
|
61
|
+
# 注册到 OpenClaw
|
|
62
|
+
openclaw plugins install .
|
|
63
|
+
openclaw plugins enable clawchain-wallet
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## 链信息
|
|
67
|
+
|
|
68
|
+
| 配置项 | 值 |
|
|
69
|
+
|--------|-----|
|
|
70
|
+
| 链名称 | ClawChain |
|
|
71
|
+
| 代币符号 | CLAW |
|
|
72
|
+
| RPC URL | https://n1.clawchain.net |
|
|
73
|
+
| Chain ID | 1911 |
|
|
74
|
+
|
|
75
|
+
## 可用工具
|
|
76
|
+
|
|
77
|
+
安装后,OpenClaw Agent 可以使用以下工具:
|
|
78
|
+
|
|
79
|
+
### 钱包管理
|
|
80
|
+
|
|
81
|
+
| 工具名 | 功能 | 示例用法 |
|
|
82
|
+
|--------|------|----------|
|
|
83
|
+
| `clawchain_wallet_create` | 创建新钱包 | "帮我创建一个叫'主钱包'的钱包" |
|
|
84
|
+
| `clawchain_wallet_import` | 导入已有钱包 | "导入私钥 0x1234..." |
|
|
85
|
+
| `clawchain_wallet_list` | 列出所有钱包 | "显示我所有的钱包" |
|
|
86
|
+
| `clawchain_wallet_info` | 查看钱包详情 | "查看主钱包的详细信息" |
|
|
87
|
+
| `clawchain_wallet_delete` | 删除钱包 | "删除测试钱包" |
|
|
88
|
+
| `clawchain_wallet_rename` | 重命名钱包 | "把钱包-1改名为储蓄钱包" |
|
|
89
|
+
| `clawchain_wallet_export` | 导出私钥 | "导出主钱包的私钥" |
|
|
90
|
+
|
|
91
|
+
### 余额与转账
|
|
92
|
+
|
|
93
|
+
| 工具名 | 功能 | 示例用法 |
|
|
94
|
+
|--------|------|----------|
|
|
95
|
+
| `clawchain_balance` | 查询余额 | "查看主钱包的余额" |
|
|
96
|
+
| `clawchain_transfer` | 转账 CLAW | "从主钱包转 10 CLAW 到储蓄钱包" |
|
|
97
|
+
|
|
98
|
+
### 查询功能
|
|
99
|
+
|
|
100
|
+
| 工具名 | 功能 | 示例用法 |
|
|
101
|
+
|--------|------|----------|
|
|
102
|
+
| `clawchain_tx_info` | 查询交易详情 | "查看交易 0xabc... 的状态" |
|
|
103
|
+
| `clawchain_tx_history` | 查询交易历史 | "显示主钱包的最近交易" |
|
|
104
|
+
| `clawchain_info` | 获取链信息 | "ClawChain 现在什么状态" |
|
|
105
|
+
| `clawchain_block_info` | 查询区块信息 | "查看最新区块" |
|
|
106
|
+
|
|
107
|
+
### 空投领取
|
|
108
|
+
|
|
109
|
+
| 工具名 | 功能 | 示例用法 |
|
|
110
|
+
|--------|------|----------|
|
|
111
|
+
| `clawchain_claim_airdrop` | 领取 CLAW 空投 | "帮我领取空投" |
|
|
112
|
+
|
|
113
|
+
## 使用示例
|
|
114
|
+
|
|
115
|
+
### 创建钱包
|
|
116
|
+
|
|
117
|
+
```
|
|
118
|
+
用户: 帮我创建一个 ClawChain 钱包
|
|
119
|
+
|
|
120
|
+
Agent: 好的,我来创建一个新钱包。
|
|
121
|
+
[调用 clawchain_wallet_create]
|
|
122
|
+
|
|
123
|
+
创建成功!
|
|
124
|
+
- 钱包名称: wallet-01
|
|
125
|
+
- 地址: 0x1234...abcd
|
|
126
|
+
- 私钥: 0xabcd...1234
|
|
127
|
+
|
|
128
|
+
⚠️ 请妥善保管私钥!
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### 查询余额
|
|
132
|
+
|
|
133
|
+
```
|
|
134
|
+
用户: 查看 wallet-01 的余额
|
|
135
|
+
|
|
136
|
+
Agent: 让我查询一下。
|
|
137
|
+
[调用 clawchain_balance(address="wallet-01")]
|
|
138
|
+
|
|
139
|
+
wallet-01 (0x1234...abcd) 的余额:100 CLAW
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### 转账
|
|
143
|
+
|
|
144
|
+
```
|
|
145
|
+
用户: 从 wallet-01 转 10 CLAW 到 0x5678...efgh
|
|
146
|
+
|
|
147
|
+
Agent: 好的,执行转账。
|
|
148
|
+
[调用 clawchain_transfer(from_wallet="wallet-01", to="0x5678...efgh", amount=10)]
|
|
149
|
+
|
|
150
|
+
转账成功!
|
|
151
|
+
- 发送方: wallet-01 (0x1234...)
|
|
152
|
+
- 接收方: 0x5678...efgh
|
|
153
|
+
- 金额: 10 CLAW
|
|
154
|
+
- 交易哈希: 0xdef...
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### 领取空投
|
|
158
|
+
|
|
159
|
+
领取 CLAW 空投需要完成以下步骤:
|
|
160
|
+
|
|
161
|
+
1. **确保有钱包**:调用 `clawchain_wallet_list` 或 `clawchain_wallet_create`
|
|
162
|
+
2. **发布帖子**:在 moltbook 发布包含钱包地址的帖子
|
|
163
|
+
3. **调用空投工具**:将帖子 URL 传给 `clawchain_claim_airdrop`
|
|
164
|
+
|
|
165
|
+
```
|
|
166
|
+
用户: 帮我领取 CLAW 空投
|
|
167
|
+
|
|
168
|
+
Agent: 好的,让我按步骤执行。
|
|
169
|
+
|
|
170
|
+
1. 检查钱包 → 找到 wallet-01: 0x1234...
|
|
171
|
+
2. 发布帖子 → "申请 CLAW 空投,钱包: 0x1234..."
|
|
172
|
+
3. 领取空投 → [调用 clawchain_claim_airdrop(post_url="...")]
|
|
173
|
+
|
|
174
|
+
🎉 空投领取成功!
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## 钱包存储
|
|
178
|
+
|
|
179
|
+
钱包文件默认存储在 `~/.clawchain/wallets/` 目录:
|
|
180
|
+
|
|
181
|
+
```
|
|
182
|
+
~/.clawchain/wallets/
|
|
183
|
+
├── index.json # 钱包索引
|
|
184
|
+
├── wallet-01_1234567890.json
|
|
185
|
+
├── 主钱包_1234567891.json
|
|
186
|
+
└── deleted/ # 已删除钱包的备份
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
## 安全提示
|
|
190
|
+
|
|
191
|
+
1. **私钥安全**:私钥存储在本地文件中,请确保文件系统安全
|
|
192
|
+
2. **定期备份**:建议定期备份 `~/.clawchain/wallets/` 目录
|
|
193
|
+
3. **删除保护**:删除的钱包会自动备份到 `deleted/` 目录
|
|
194
|
+
|
|
195
|
+
## 环境要求
|
|
196
|
+
|
|
197
|
+
| 依赖 | 版本要求 |
|
|
198
|
+
|------|----------|
|
|
199
|
+
| Node.js | >= 18.0.0 |
|
|
200
|
+
| Python | >= 3.8 |
|
|
201
|
+
| OpenClaw | >= 2026.1.0 |
|
|
202
|
+
|
|
203
|
+
## 故障排查
|
|
204
|
+
|
|
205
|
+
### Python 依赖问题
|
|
206
|
+
|
|
207
|
+
```bash
|
|
208
|
+
# 确保使用 Python 3
|
|
209
|
+
pip3 install web3 eth-account
|
|
210
|
+
|
|
211
|
+
# 或使用虚拟环境
|
|
212
|
+
python3 -m venv venv
|
|
213
|
+
source venv/bin/activate
|
|
214
|
+
pip install -r python/requirements.txt
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### 连接问题
|
|
218
|
+
|
|
219
|
+
如果无法连接到 ClawChain:
|
|
220
|
+
- 检查网络连接
|
|
221
|
+
- 确认 RPC URL (https://n1.clawchain.net) 可访问
|
|
222
|
+
- 使用 `clawchain_info` 工具测试连接
|
|
223
|
+
|
|
224
|
+
### 插件未加载
|
|
225
|
+
|
|
226
|
+
```bash
|
|
227
|
+
# 检查插件状态
|
|
228
|
+
openclaw plugins list
|
|
229
|
+
|
|
230
|
+
# 重新安装并启用
|
|
231
|
+
openclaw plugins install /path/to/clawchain-wallet
|
|
232
|
+
openclaw plugins enable clawchain-wallet
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
## 更新日志
|
|
236
|
+
|
|
237
|
+
### v1.0.0
|
|
238
|
+
- 初始版本
|
|
239
|
+
- 支持 14 个 Agent 工具
|
|
240
|
+
- 钱包创建、导入、管理功能
|
|
241
|
+
- 余额查询和转账功能
|
|
242
|
+
- 交易和区块查询功能
|
|
243
|
+
- CLAW 空投领取功能
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ClawChain Plugin for OpenClaw
|
|
3
|
+
*
|
|
4
|
+
* ClawChain 私有链钱包管理插件
|
|
5
|
+
* 支持创建钱包、导入钱包、余额查询、转账等功能
|
|
6
|
+
*
|
|
7
|
+
* 特性:
|
|
8
|
+
* - 按 Agent 隔离钱包存储(每个 agent 的钱包存储在其工作区的 .wallets 目录)
|
|
9
|
+
*
|
|
10
|
+
* 固定配置:
|
|
11
|
+
* - RPC URL: https://n1.clawchain.net
|
|
12
|
+
* - Chain ID: 1911
|
|
13
|
+
* - 代币名称: CLAW
|
|
14
|
+
* - 链名称: ClawChain
|
|
15
|
+
*/
|
|
16
|
+
import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
|
|
17
|
+
declare const plugin: {
|
|
18
|
+
id: string;
|
|
19
|
+
name: string;
|
|
20
|
+
description: string;
|
|
21
|
+
version: string;
|
|
22
|
+
register(api: OpenClawPluginApi): void;
|
|
23
|
+
};
|
|
24
|
+
export default plugin;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ClawChain Plugin for OpenClaw
|
|
3
|
+
*
|
|
4
|
+
* ClawChain 私有链钱包管理插件
|
|
5
|
+
* 支持创建钱包、导入钱包、余额查询、转账等功能
|
|
6
|
+
*
|
|
7
|
+
* 特性:
|
|
8
|
+
* - 按 Agent 隔离钱包存储(每个 agent 的钱包存储在其工作区的 .wallets 目录)
|
|
9
|
+
*
|
|
10
|
+
* 固定配置:
|
|
11
|
+
* - RPC URL: https://n1.clawchain.net
|
|
12
|
+
* - Chain ID: 1911
|
|
13
|
+
* - 代币名称: CLAW
|
|
14
|
+
* - 链名称: ClawChain
|
|
15
|
+
*/
|
|
16
|
+
import path from "node:path";
|
|
17
|
+
import { fileURLToPath } from "node:url";
|
|
18
|
+
import { createClawChainToolFactories } from "./src/tools.js";
|
|
19
|
+
// 获取当前文件所在目录
|
|
20
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
21
|
+
const __dirname = path.dirname(__filename);
|
|
22
|
+
const plugin = {
|
|
23
|
+
id: "clawchain-wallet",
|
|
24
|
+
name: "ClawChain Wallet",
|
|
25
|
+
description: "ClawChain 私有链钱包管理工具 - 支持创建钱包、导入钱包、余额查询、转账等功能",
|
|
26
|
+
version: "1.0.0",
|
|
27
|
+
register(api) {
|
|
28
|
+
const pluginConfig = api.pluginConfig;
|
|
29
|
+
// Python 脚本路径
|
|
30
|
+
const pythonScript = path.join(__dirname, "python", "clawchain_cli.py");
|
|
31
|
+
// 显式配置的钱包存储目录(可选,优先级最高)
|
|
32
|
+
const walletsDir = pluginConfig?.walletsDir;
|
|
33
|
+
api.logger.info("[ClawChain] Plugin initializing...");
|
|
34
|
+
api.logger.info(`[ClawChain] Python script: ${pythonScript}`);
|
|
35
|
+
if (walletsDir) {
|
|
36
|
+
api.logger.info(`[ClawChain] Configured wallets directory: ${walletsDir}`);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
api.logger.info("[ClawChain] Wallets will be stored in each agent's workspace (.wallets)");
|
|
40
|
+
}
|
|
41
|
+
// 创建基础执行器选项
|
|
42
|
+
const baseExecutorOptions = {
|
|
43
|
+
pythonScript,
|
|
44
|
+
walletsDir,
|
|
45
|
+
timeout: 60000,
|
|
46
|
+
};
|
|
47
|
+
// 获取所有工具工厂并注册
|
|
48
|
+
const toolFactories = createClawChainToolFactories(baseExecutorOptions);
|
|
49
|
+
const toolNames = [
|
|
50
|
+
"clawchain_wallet_create",
|
|
51
|
+
"clawchain_wallet_import",
|
|
52
|
+
"clawchain_wallet_list",
|
|
53
|
+
"clawchain_wallet_info",
|
|
54
|
+
"clawchain_wallet_delete",
|
|
55
|
+
"clawchain_wallet_rename",
|
|
56
|
+
"clawchain_wallet_export",
|
|
57
|
+
"clawchain_balance",
|
|
58
|
+
"clawchain_transfer",
|
|
59
|
+
"clawchain_tx_info",
|
|
60
|
+
"clawchain_tx_history",
|
|
61
|
+
"clawchain_info",
|
|
62
|
+
"clawchain_block_info",
|
|
63
|
+
"clawchain_claim_airdrop",
|
|
64
|
+
];
|
|
65
|
+
for (let i = 0; i < toolFactories.length; i++) {
|
|
66
|
+
const factory = toolFactories[i];
|
|
67
|
+
// 注册工厂函数,OpenClaw 会在调用时传入上下文
|
|
68
|
+
api.registerTool(factory, { name: toolNames[i] });
|
|
69
|
+
api.logger.info(`[ClawChain] Registered tool: ${toolNames[i]}`);
|
|
70
|
+
}
|
|
71
|
+
api.logger.info(`[ClawChain] Plugin loaded successfully. ${toolFactories.length} tools registered.`);
|
|
72
|
+
api.logger.info("[ClawChain] Available tools:");
|
|
73
|
+
api.logger.info(" - clawchain_wallet_create: 创建新钱包");
|
|
74
|
+
api.logger.info(" - clawchain_wallet_import: 导入钱包");
|
|
75
|
+
api.logger.info(" - clawchain_wallet_list: 列出所有钱包");
|
|
76
|
+
api.logger.info(" - clawchain_wallet_info: 获取钱包详情");
|
|
77
|
+
api.logger.info(" - clawchain_wallet_delete: 删除钱包");
|
|
78
|
+
api.logger.info(" - clawchain_wallet_rename: 重命名钱包");
|
|
79
|
+
api.logger.info(" - clawchain_wallet_export: 导出钱包私钥");
|
|
80
|
+
api.logger.info(" - clawchain_balance: 查询余额");
|
|
81
|
+
api.logger.info(" - clawchain_transfer: 转账 CLAW");
|
|
82
|
+
api.logger.info(" - clawchain_tx_info: 查询交易详情");
|
|
83
|
+
api.logger.info(" - clawchain_tx_history: 查询交易历史");
|
|
84
|
+
api.logger.info(" - clawchain_info: 获取链信息");
|
|
85
|
+
api.logger.info(" - clawchain_block_info: 查询区块信息");
|
|
86
|
+
api.logger.info(" - clawchain_claim_airdrop: 领取 CLAW 空投");
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
export default plugin;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ClawChain Python CLI 执行器
|
|
3
|
+
*
|
|
4
|
+
* 使用 JSON stdin 传递参数,避免命令注入风险
|
|
5
|
+
*/
|
|
6
|
+
import type { CommandResult } from "./types.js";
|
|
7
|
+
export interface ExecutorOptions {
|
|
8
|
+
pythonScript: string;
|
|
9
|
+
walletsDir?: string;
|
|
10
|
+
timeout?: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* 命令参数类型定义
|
|
14
|
+
*/
|
|
15
|
+
export interface CommandArgs {
|
|
16
|
+
[key: string]: string | number | boolean | undefined;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* 执行 ClawChain CLI 命令
|
|
20
|
+
*
|
|
21
|
+
* 通过 stdin 传递 JSON 格式的参数,避免命令行注入风险
|
|
22
|
+
*/
|
|
23
|
+
export declare function executeCommand(options: ExecutorOptions, command: string, args?: CommandArgs): CommandResult;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ClawChain Python CLI 执行器
|
|
3
|
+
*
|
|
4
|
+
* 使用 JSON stdin 传递参数,避免命令注入风险
|
|
5
|
+
*/
|
|
6
|
+
import { execSync } from "node:child_process";
|
|
7
|
+
/**
|
|
8
|
+
* 执行 ClawChain CLI 命令
|
|
9
|
+
*
|
|
10
|
+
* 通过 stdin 传递 JSON 格式的参数,避免命令行注入风险
|
|
11
|
+
*/
|
|
12
|
+
export function executeCommand(options, command, args = {}) {
|
|
13
|
+
const { pythonScript, walletsDir, timeout = 60000 } = options;
|
|
14
|
+
// 构建 JSON 输入
|
|
15
|
+
const inputData = {
|
|
16
|
+
command,
|
|
17
|
+
wallets_dir: walletsDir,
|
|
18
|
+
args,
|
|
19
|
+
};
|
|
20
|
+
const jsonInput = JSON.stringify(inputData);
|
|
21
|
+
try {
|
|
22
|
+
const output = execSync(`python3 "${pythonScript}" --json-stdin`, {
|
|
23
|
+
encoding: "utf-8",
|
|
24
|
+
timeout,
|
|
25
|
+
input: jsonInput,
|
|
26
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
27
|
+
});
|
|
28
|
+
// 解析 JSON 输出
|
|
29
|
+
try {
|
|
30
|
+
return JSON.parse(output.trim());
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
// 如果不是 JSON,返回原始输出
|
|
34
|
+
return {
|
|
35
|
+
success: true,
|
|
36
|
+
output: output.trim(),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
const execError = error;
|
|
42
|
+
// 尝试从 stdout 解析 JSON 结果(某些情况下错误也会输出到 stdout)
|
|
43
|
+
if (execError.stdout) {
|
|
44
|
+
try {
|
|
45
|
+
return JSON.parse(execError.stdout.trim());
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
// 继续尝试 stderr
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
// 尝试从 stderr 解析 JSON 错误
|
|
52
|
+
if (execError.stderr) {
|
|
53
|
+
try {
|
|
54
|
+
return JSON.parse(execError.stderr.trim());
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
// 返回原始错误
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
success: false,
|
|
62
|
+
error: execError.message || "命令执行失败",
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ClawChain Agent Tools 定义
|
|
3
|
+
*
|
|
4
|
+
* 使用 OpenClaw Plugin SDK 的类型和辅助函数
|
|
5
|
+
* 支持按 Agent 隔离钱包存储
|
|
6
|
+
*/
|
|
7
|
+
import type { AgentToolResult } from "@mariozechner/pi-agent-core";
|
|
8
|
+
import type { ExecutorOptions } from "./executor.js";
|
|
9
|
+
/**
|
|
10
|
+
* Plugin 工具上下文类型
|
|
11
|
+
* 匹配 OpenClaw 的 OpenClawPluginToolContext
|
|
12
|
+
*/
|
|
13
|
+
export interface ToolContext {
|
|
14
|
+
workspaceDir?: string;
|
|
15
|
+
agentId?: string;
|
|
16
|
+
agentDir?: string;
|
|
17
|
+
sessionKey?: string;
|
|
18
|
+
messageChannel?: string;
|
|
19
|
+
sandboxed?: boolean;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Agent 工具类型定义
|
|
23
|
+
*/
|
|
24
|
+
export interface AgentToolDef {
|
|
25
|
+
name: string;
|
|
26
|
+
label: string;
|
|
27
|
+
description: string;
|
|
28
|
+
parameters: unknown;
|
|
29
|
+
execute: (toolCallId: string, args: Record<string, unknown>) => Promise<AgentToolResult<unknown>>;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* 工具工厂函数类型
|
|
33
|
+
* 匹配 OpenClaw 的 OpenClawPluginToolFactory
|
|
34
|
+
*/
|
|
35
|
+
export type ToolFactory = (ctx: ToolContext) => AgentToolDef | null;
|
|
36
|
+
/**
|
|
37
|
+
* 创建所有 ClawChain 工具工厂
|
|
38
|
+
*
|
|
39
|
+
* 每个工厂函数会根据当前 agent 上下文确定钱包存储目录
|
|
40
|
+
*/
|
|
41
|
+
export declare function createClawChainToolFactories(baseOptions: ExecutorOptions): ToolFactory[];
|