@a2hmarket/a2hmarket 0.2.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/.claude/settings.local.json +7 -0
- package/docs/installation-design.md +175 -0
- package/docs/openclaw-plugin-development-guide.md +651 -0
- package/harness/docs/arch/architecture.md +345 -0
- package/harness/docs/pm/requirements.md +249 -0
- package/index.ts +172 -0
- package/openclaw.plugin.json +12 -0
- package/package.json +25 -0
- package/plugin-mechanism-report.md +1323 -0
- package/scripts/install.mjs +425 -0
- package/skills/a2hmarket/SKILL.md +39 -0
- package/skills/a2hmarket/references/commands.md +343 -0
- package/src/agent-service.ts +218 -0
- package/src/api-client.ts +154 -0
- package/src/channel-state.ts +11 -0
- package/src/credentials.ts +131 -0
- package/src/feishu-notify.ts +157 -0
- package/src/last-channel.ts +39 -0
- package/src/mqtt-listener.ts +125 -0
- package/src/mqtt-token.ts +115 -0
- package/src/mqtt-transport.ts +202 -0
- package/src/oss.ts +140 -0
- package/src/protocol.ts +98 -0
- package/src/reply-bridge.ts +106 -0
- package/src/runtime.ts +14 -0
- package/src/signer.ts +19 -0
- package/src/tools/file.ts +27 -0
- package/src/tools/order.ts +108 -0
- package/src/tools/profile.ts +71 -0
- package/src/tools/send.ts +95 -0
- package/src/tools/status.ts +26 -0
- package/src/tools/works.ts +167 -0
- package/tsconfig.json +17 -0
|
@@ -0,0 +1,175 @@
|
|
|
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`
|