@a2hmarket/a2hmarket 0.3.2 → 0.3.4

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,7 +1,14 @@
1
1
  {
2
2
  "name": "@a2hmarket/a2hmarket",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
4
4
  "type": "module",
5
+ "files": [
6
+ "index.ts",
7
+ "openclaw.plugin.json",
8
+ "scripts/",
9
+ "skills/",
10
+ "src/"
11
+ ],
5
12
  "description": "A2H Market OpenClaw plugin — AI agent marketplace with A2A messaging via MQTT.",
6
13
  "license": "MIT-0",
7
14
  "main": "index.ts",
@@ -162,12 +162,64 @@ async function pollForAuth(code) {
162
162
 
163
163
  // ── Main ─────────────────────────────────────────────────────────────────
164
164
 
165
+ // ── Uninstall ────────────────────────────────────────────────────────────
166
+
167
+ async function runUninstall() {
168
+ log(`\n${BOLD}🏪 A2H Market — Uninstall${RESET}\n`);
169
+
170
+ const prompt = createPrompt();
171
+ const confirm = await prompt.ask("确认卸载 a2hmarket 插件及所有数据? (y/N)", "N");
172
+ prompt.close();
173
+ if (confirm.toLowerCase() !== "y") {
174
+ log(` 取消卸载。`);
175
+ process.exit(0);
176
+ }
177
+
178
+ // 1. Uninstall plugin
179
+ log(` 卸载插件...`);
180
+ try {
181
+ execSync('echo y | openclaw plugins uninstall a2hmarket 2>&1', { encoding: "utf-8", stdio: "pipe" });
182
+ log(` ${CHECK} 插件已卸载`);
183
+ } catch {
184
+ log(` ${WARN} 插件卸载失败(可能已卸载)`);
185
+ }
186
+
187
+ // 2. Remove runtime data
188
+ if (existsSync(DATA_DIR)) {
189
+ try {
190
+ execSync(`rm -rf "${DATA_DIR}"`, { stdio: "pipe" });
191
+ log(` ${CHECK} 数据目录已删除: ${DATA_DIR}`);
192
+ } catch {
193
+ log(` ${WARN} 数据目录删除失败: ${DATA_DIR}`);
194
+ }
195
+ }
196
+
197
+ // 3. Restart gateway
198
+ try {
199
+ execSync("openclaw gateway restart 2>&1", { encoding: "utf-8", stdio: "pipe" });
200
+ log(` ${CHECK} Gateway 已重启`);
201
+ } catch {
202
+ log(` ${WARN} 请手动执行: openclaw gateway restart`);
203
+ }
204
+
205
+ log(`\n${GREEN}${BOLD}卸载完成${RESET}\n`);
206
+ }
207
+
208
+ // ── Main ─────────────────────────────────────────────────────────────────
209
+
165
210
  async function main() {
166
211
  const args = process.argv.slice(2);
167
- if (!args.includes("install")) {
212
+ const cmd = args[0];
213
+
214
+ if (cmd === "uninstall") {
215
+ return await runUninstall();
216
+ }
217
+
218
+ if (cmd !== "install") {
168
219
  log(`\n${BOLD}A2H Market — OpenClaw Plugin${RESET}\n`);
169
- log(` 安装: npx -y ${NPM_SPEC} install`);
170
- log(` 快速: npx -y ${NPM_SPEC} install --agent ag_xxx:key\n`);
220
+ log(` 安装: npx -y ${NPM_SPEC} install`);
221
+ log(` 快速: npx -y ${NPM_SPEC} install --agent ag_xxx:key`);
222
+ log(` 卸载: npx -y ${NPM_SPEC} uninstall\n`);
171
223
  process.exit(0);
172
224
  }
173
225
 
@@ -1,7 +0,0 @@
1
- {
2
- "permissions": {
3
- "allow": [
4
- "Bash(tar czf:*)"
5
- ]
6
- }
7
- }
@@ -1,175 +0,0 @@
1
- # a2hmarket-plugin 安装方案设计
2
-
3
- ## 标准做法分析
4
-
5
- 通过研究 feishu 插件的实现:
6
-
7
- | 维度 | feishu 的做法 | 我们应该怎么做 |
8
- |------|-------------|--------------|
9
- | 安装方式 | `openclaw plugins install @openclaw/feishu` (npm) | `openclaw plugins install @a2hmarket/openclaw-plugin` |
10
- | 凭证存储 | `openclaw.json` → `channels.feishu.appId/appSecret` | `openclaw.json` → `plugins.entries.a2hmarket.{agentId,agentKey,...}` |
11
- | 运行时数据 | `~/.openclaw/feishu/dedup/` | `~/.openclaw/a2hmarket/` |
12
- | 插件代码 | `~/.openclaw/extensions/feishu/` (npm 安装后) | `~/.openclaw/extensions/a2hmarket/` |
13
- | openclaw/plugin-sdk | 不需要依赖/symlink,OpenClaw 运行时自动 resolve | 同上 |
14
- | 配置引导 | `openclaw configure` 交互式向导 | 我们提供 `npx @a2hmarket/openclaw-plugin install` |
15
-
16
- ---
17
-
18
- ## 存储规划
19
-
20
- ### 凭证 → `~/.openclaw/a2hmarket/credentials.json`
21
-
22
- ```json
23
- {
24
- "agent_id": "ag_xxx",
25
- "agent_key": "xxxxxx",
26
- "api_url": "https://api.a2hmarket.ai",
27
- "mqtt_url": "mqtts://post-cn-xxx.mqtt.aliyuncs.com:8883",
28
- "notify": {
29
- "channel": "feishu",
30
- "target": "ou_xxx"
31
- }
32
- }
33
- ```
34
-
35
- > 注:OpenClaw 的 `plugins.entries` schema 不允许自定义字段,因此凭证存在 stateDir 下的文件中。
36
- > 加载优先级:`~/.openclaw/a2hmarket/` > 插件目录 > `~/.a2hmarket/`(旧版兼容)
37
-
38
- ### 运行时数据 → `~/.openclaw/a2hmarket/`
39
-
40
- ```
41
- ~/.openclaw/a2hmarket/
42
- ├── reply-bridge.json # 飞书卡片 messageId → a2hmarket peerId 映射
43
- ├── last-channel.json # 用户最后活跃 channel 记录
44
- └── strategies/ # 交易经验策略(后续扩展)
45
- ```
46
-
47
- 代码通过 `join(ctx.stateDir, "a2hmarket")` 获取路径。
48
-
49
- ### 废弃
50
-
51
- | 原位置 | 处理 |
52
- |--------|------|
53
- | `~/.a2hmarket/credentials.json` | 迁移到 `openclaw.json` pluginConfig |
54
- | `~/.a2hmarket/plugin-inbox.json` | 不再需要(inbox 已内化到代码) |
55
- | 插件目录 `.last-channel.json` | 迁移到 `~/.openclaw/a2hmarket/` |
56
- | 插件目录 `.reply-bridge.json` | 迁移到 `~/.openclaw/a2hmarket/` |
57
- | 插件目录 `credentials.json` | 迁移到 `openclaw.json` pluginConfig |
58
-
59
- ---
60
-
61
- ## 安装流程设计
62
-
63
- ### 用户执行一行命令
64
-
65
- ```bash
66
- npx -y @a2hmarket/openclaw-plugin install
67
- ```
68
-
69
- ### install 脚本做什么
70
-
71
- ```
72
- 1. 检查 openclaw 是否已安装
73
- 2. 调用 openclaw plugins install @a2hmarket/openclaw-plugin
74
- 3. 交互式提问:
75
- - 你的 Agent ID? (ag_xxx)
76
- - 你的 Agent Key? (xxxxxx)
77
- - MQTT URL? (默认值自动填充)
78
- - 飞书通知目标? (可选,ou_xxx)
79
- 4. 创建 ~/.openclaw/a2hmarket/ 目录
80
- 5. 写入凭证到 ~/.openclaw/a2hmarket/credentials.json
81
- 6. openclaw gateway restart
82
- 7. 验证: openclaw plugins info a2hmarket
83
- ```
84
-
85
- ---
86
-
87
- ## npm 包结构
88
-
89
- ```
90
- @a2hmarket/openclaw-plugin/
91
- ├── package.json
92
- ├── index.ts # 插件入口
93
- ├── openclaw.plugin.json # 插件清单
94
- ├── scripts/
95
- │ └── install.mjs # npx install 交互式脚本
96
- ├── skills/
97
- │ └── a2hmarket/
98
- │ ├── SKILL.md
99
- │ └── references/
100
- │ └── commands.md
101
- └── src/
102
- ├── agent-service.ts
103
- ├── credentials.ts
104
- ├── feishu-notify.ts
105
- ├── runtime.ts
106
- ├── channel-state.ts
107
- ├── last-channel.ts
108
- ├── reply-bridge.ts
109
- ├── api-client.ts
110
- ├── mqtt-listener.ts
111
- ├── mqtt-transport.ts
112
- ├── mqtt-token.ts
113
- ├── protocol.ts
114
- ├── signer.ts
115
- ├── oss.ts
116
- └── tools/
117
- ├── status.ts
118
- ├── profile.ts
119
- ├── file.ts
120
- ├── works.ts
121
- ├── order.ts
122
- └── send.ts
123
- ```
124
-
125
- ### package.json
126
-
127
- ```json
128
- {
129
- "name": "@a2hmarket/openclaw-plugin",
130
- "version": "2.0.0",
131
- "type": "module",
132
- "description": "A2H Market OpenClaw plugin — AI agent marketplace with A2A messaging via MQTT.",
133
- "license": "MIT-0",
134
- "main": "index.ts",
135
- "bin": {
136
- "a2hmarket-install": "./scripts/install.mjs"
137
- },
138
- "dependencies": {
139
- "mqtt": "^5.10.0"
140
- },
141
- "openclaw": {
142
- "extensions": ["./index.ts"],
143
- "install": {
144
- "npmSpec": "@a2hmarket/openclaw-plugin",
145
- "defaultChoice": "npm"
146
- }
147
- }
148
- }
149
- ```
150
-
151
- ---
152
-
153
- ## 代码改动清单
154
-
155
- ### 1. `src/credentials.ts` ✅ 已改
156
-
157
- 凭证加载优先级:`~/.openclaw/a2hmarket/` > 插件目录 > `~/.a2hmarket/`
158
-
159
- ### 2. `index.ts` ✅ 已改
160
-
161
- Service 中使用 `ctx.stateDir` 初始化 reply-bridge 和 last-channel 存储。
162
-
163
- ### 3. `package.json` ✅ 已改
164
-
165
- 添加 `openclaw` 元数据和 `bin` 字段。
166
-
167
- ### 4. `scripts/install.mjs` — 待实现
168
-
169
- 交互式安装脚本。
170
-
171
- ### 5. `.gitignore` ✅ 已改
172
-
173
- ### 6. 废弃文件 ✅ 已清理
174
- - `src/inbox.ts`, `src/tools/inbox-tools.ts`, `skills/a2hmarket/references/inbox.md`
175
- - 插件目录下的 `.last-channel.json`, `.reply-bridge.json`