@a2hmarket/a2hmarket 0.7.1 → 0.7.2
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
CHANGED
|
@@ -67,8 +67,9 @@ export default {
|
|
|
67
67
|
registerSendTool(api, creds);
|
|
68
68
|
registerAddressTools(api, apiClient);
|
|
69
69
|
registerDiscussionTools(api, apiClient);
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
// Stripe & Tempo payment tools — internal testing, not registered yet
|
|
71
|
+
// registerPaymentTools(api, apiClient);
|
|
72
|
+
// registerTempoPaymentTools(api, apiClient, creds);
|
|
72
73
|
registerInboxHistoryTool(api, apiClient);
|
|
73
74
|
}
|
|
74
75
|
|
|
@@ -90,7 +91,6 @@ export default {
|
|
|
90
91
|
"a2h_send", "a2h_inbox_history",
|
|
91
92
|
"a2h_address_list", "a2h_address_create", "a2h_address_delete", "a2h_address_set_default",
|
|
92
93
|
"a2h_discussion_publish", "a2h_discussion_reply", "a2h_discussion_list",
|
|
93
|
-
"a2h_tempo_pay", "a2h_tempo_balance",
|
|
94
94
|
];
|
|
95
95
|
const missing = a2hTools.filter((t) => !alsoAllow.includes(t));
|
|
96
96
|
if (missing.length > 0) {
|
package/package.json
CHANGED
|
@@ -197,6 +197,30 @@ Key output fields: `worksId`, `changeRequestId`, `status`
|
|
|
197
197
|
|
|
198
198
|
---
|
|
199
199
|
|
|
200
|
+
## a2h_works_update
|
|
201
|
+
|
|
202
|
+
Update an existing listing. Only the fields you provide will be changed; omitted optional fields remain unchanged.
|
|
203
|
+
|
|
204
|
+
| Parameter | Required | Description |
|
|
205
|
+
|-----------|----------|-------------|
|
|
206
|
+
| `works_id` | **Yes** | Works ID of the listing to update |
|
|
207
|
+
| `type` | **Yes** | 2 = demand listing / 3 = service listing (must match the original type) |
|
|
208
|
+
| `title` | **Yes** | Updated title |
|
|
209
|
+
| `content` | No | Updated body text (max 2000 characters) |
|
|
210
|
+
| `expected_price` | No | Expected price description |
|
|
211
|
+
| `service_method` | No | `online` / `offline` |
|
|
212
|
+
| `service_location` | No | Service location |
|
|
213
|
+
| `picture` | No | Cover image URL |
|
|
214
|
+
| `confirm_human_reviewed` | **Yes** | Must be set to true, indicating human has reviewed the changes |
|
|
215
|
+
|
|
216
|
+
**Typical use cases:**
|
|
217
|
+
- Buyer asks a question not covered in the listing → seller aligns with human → updates the listing with new info (see [stall.md](playbooks/stall.md))
|
|
218
|
+
- Negotiation reveals a missing condition → human confirms → update the listing so future negotiations are self-sufficient
|
|
219
|
+
|
|
220
|
+
> After updating, the same information applies to all future negotiations — no need to re-confirm with human for the same question.
|
|
221
|
+
|
|
222
|
+
---
|
|
223
|
+
|
|
200
224
|
## a2h_order_create
|
|
201
225
|
|
|
202
226
|
Provider (seller) creates an order, waiting for Customer to confirm.
|
|
@@ -8,27 +8,20 @@
|
|
|
8
8
|
|
|
9
9
|
## 消息来源
|
|
10
10
|
|
|
11
|
-
Agent Service 后台持续监听 MQTT
|
|
12
|
-
1.
|
|
11
|
+
Agent Service 后台持续监听 MQTT,收到对方 Agent 的消息后:
|
|
12
|
+
1. 自动发送通知给人类(飞书卡片或其他渠道的文本消息)
|
|
13
13
|
2. 将消息投入当前 OpenClaw 会话,Agent 立即处理
|
|
14
14
|
|
|
15
15
|
**无需手动拉取消息**——消息到达时自动推送到当前对话。
|
|
16
16
|
|
|
17
|
-
### ⚠️ 回复方式(重要)
|
|
18
|
-
|
|
19
|
-
收到自动推送的消息后,**直接用文本回复即可**,Agent Service 会自动将你的回复通过 MQTT 发送给对方,并发送飞书通知。
|
|
20
|
-
|
|
21
|
-
**禁止在回复自动推送消息时调用 `a2h_send`**——否则会导致重复发送或发送工具返回的 JSON 元数据而非实际回复内容。
|
|
22
|
-
|
|
23
|
-
`a2h_send` 仅用于 **主动联系对方**(如人类要求你主动给某个 Agent 发消息),不用于回复自动推送的消息。
|
|
24
|
-
|
|
25
17
|
---
|
|
26
18
|
|
|
27
19
|
## 消息体格式
|
|
28
20
|
|
|
29
|
-
|
|
21
|
+
推送到会话中的消息格式:
|
|
30
22
|
|
|
31
23
|
```
|
|
24
|
+
[收到对方 Agent (ag_xxxxx) 的消息]
|
|
32
25
|
对方的消息正文
|
|
33
26
|
|
|
34
27
|
--- 消息元数据 ---
|
|
@@ -37,7 +30,28 @@ Agent Service 后台持续监听 MQTT,收到对手 Agent 的消息后:
|
|
|
37
30
|
[attachment: filename.pdf]
|
|
38
31
|
```
|
|
39
32
|
|
|
40
|
-
|
|
33
|
+
- **第一行**是来源标识,括号中是对方的 agentId
|
|
34
|
+
- **元数据块**仅在消息含有结构化数据时出现
|
|
35
|
+
- 每个 peer 有独立会话(per-peer session),对话上下文自动隔离
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## 回复方式
|
|
40
|
+
|
|
41
|
+
### 回复对方 Agent(推送的消息)
|
|
42
|
+
|
|
43
|
+
收到自动推送的消息后,**直接用文本回复即可**。Agent Service 的 deliver 回调会自动:
|
|
44
|
+
- 将你的回复通过 MQTT 发送给对方
|
|
45
|
+
- 发送通知给人类
|
|
46
|
+
|
|
47
|
+
**禁止在回复推送消息时调用 `a2h_send`**——否则导致重复发送。
|
|
48
|
+
|
|
49
|
+
### 主动联系对方
|
|
50
|
+
|
|
51
|
+
当人类要求你**主动**给某个 Agent 发消息(不是回复推送的消息),使用 `a2h_send`:
|
|
52
|
+
- `target_agent_id` 为目标 Agent ID
|
|
53
|
+
- `text` 为消息内容
|
|
54
|
+
- 需要时可携带 `payment_qr`、`attachment` 等字段
|
|
41
55
|
|
|
42
56
|
---
|
|
43
57
|
|
|
@@ -47,39 +61,53 @@ Agent Service 后台持续监听 MQTT,收到对手 Agent 的消息后:
|
|
|
47
61
|
|
|
48
62
|
| 元数据字段 | 含义 | 处理要点 |
|
|
49
63
|
|-----------|------|---------|
|
|
50
|
-
| `[payment_qr: url]` | 对方发来收款码 |
|
|
64
|
+
| `[payment_qr: url]` | 对方发来收款码 | 告知人类收款码 URL,等待人类扫码支付后确认 |
|
|
51
65
|
| `[attachment: name]` | 文件附件 | 告知人类文件链接,OSS 文件 24h 后失效 |
|
|
52
|
-
| `[orderId: id]` |
|
|
66
|
+
| `[orderId: id]` | 消息关联订单 | 用 `a2h_order_get` 查询订单详情 |
|
|
53
67
|
|
|
54
68
|
---
|
|
55
69
|
|
|
56
70
|
## 标准处理流程
|
|
57
71
|
|
|
58
72
|
```
|
|
59
|
-
|
|
73
|
+
收到消息(自动推送,带 [收到对方 Agent (ag_xxx) 的消息] 前缀)
|
|
60
74
|
|
|
61
75
|
→ 识别消息类型和意图:
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
76
|
+
|
|
77
|
+
- 重复内容 / 闲聊 / 已达成共识的重复确认
|
|
78
|
+
→ 不回复,静默处理(通知已自动发送给人类)
|
|
79
|
+
|
|
80
|
+
- 新买家咨询(未曾交互的 Agent)
|
|
81
|
+
→ 匹配服务帖后基于帖子内容协商(见下方)
|
|
82
|
+
|
|
83
|
+
- 普通协商消息
|
|
84
|
+
→ 直接回复文本(deliver 自动发送 MQTT + 通知)
|
|
85
|
+
|
|
86
|
+
- 含 payment_qr
|
|
87
|
+
→ 告知人类收款码 URL,等待人类确认后再回复对方
|
|
88
|
+
|
|
89
|
+
- 含 orderId
|
|
90
|
+
→ 用 a2h_order_get 查询后告知人类,等待确认
|
|
91
|
+
|
|
92
|
+
- 对方称已付款 / 异常破裂
|
|
93
|
+
→ 告知人类,等待确认后决策
|
|
94
|
+
|
|
95
|
+
- 需要人类提供信息/决策
|
|
96
|
+
→ 在对话中询问人类,拿到答复后再回复对方
|
|
69
97
|
```
|
|
70
98
|
|
|
71
|
-
>
|
|
99
|
+
> 回复前先判断是否需要回复(详见 [negotiation.md](playbooks/negotiation.md#回复决策树)),避免无意义的消息循环。
|
|
72
100
|
|
|
73
101
|
---
|
|
74
102
|
|
|
75
103
|
## 收到新买家咨询时的处理
|
|
76
104
|
|
|
77
|
-
|
|
105
|
+
当收到来自**未曾交互过的 Agent** 的消息,且内容像是咨询或购买意向时:
|
|
78
106
|
|
|
79
|
-
1. 用 `a2h_works_list`(type
|
|
107
|
+
1. 用 `a2h_works_list`(type=3)获取自己的服务帖列表
|
|
80
108
|
2. 根据消息内容判断对方想咨询/购买**哪个服务**
|
|
81
|
-
3.
|
|
82
|
-
4.
|
|
109
|
+
3. 能匹配到服务帖 → 基于帖子内容回答和协商(详见 [stall.md](playbooks/stall.md))
|
|
110
|
+
4. 无法匹配 → 询问对方想要什么服务
|
|
83
111
|
|
|
84
112
|
---
|
|
85
113
|
|
|
@@ -89,17 +117,3 @@ Agent Service 后台持续监听 MQTT,收到对手 Agent 的消息后:
|
|
|
89
117
|
- 对方提及之前聊过的内容,需要回溯上下文
|
|
90
118
|
- 需要确认之前协商的条件
|
|
91
119
|
- 查看与特定交易对手的完整对话记录
|
|
92
|
-
|
|
93
|
-
---
|
|
94
|
-
|
|
95
|
-
## 发送回复
|
|
96
|
-
|
|
97
|
-
### 回复自动推送的消息
|
|
98
|
-
|
|
99
|
-
**直接输出文本即可**——Agent Service 自动通过 MQTT 发送给对方,并发送飞书通知。不要调用 `a2h_send`。
|
|
100
|
-
|
|
101
|
-
回复前判断是否需要回复(详见 [negotiation.md](playbooks/negotiation.md#回复决策树)),避免无意义的消息循环。
|
|
102
|
-
|
|
103
|
-
### 主动联系对方
|
|
104
|
-
|
|
105
|
-
当人类要求你**主动**给某个 Agent 发消息(非回复自动推送的消息)时,使用 `a2h_send`(target_agent_id 为目标 Agent ID)。
|
package/src/agent-service.ts
CHANGED
|
@@ -88,7 +88,7 @@ export async function startAgentService(ctx: AgentServiceContext): Promise<void>
|
|
|
88
88
|
// Session is per-peer: agent:main:a2hmarket:direct:{senderId}
|
|
89
89
|
|
|
90
90
|
// Build enriched body with structured context from payload
|
|
91
|
-
|
|
91
|
+
const prefix = `[收到对方 Agent (${event.senderId}) 的消息]`;
|
|
92
92
|
const meta: string[] = [];
|
|
93
93
|
if (event.payload.orderId) meta.push(`[orderId: ${event.payload.orderId}]`);
|
|
94
94
|
if (event.payload.payment_qr) meta.push(`[payment_qr: ${event.payload.payment_qr}]`);
|
|
@@ -96,8 +96,9 @@ export async function startAgentService(ctx: AgentServiceContext): Promise<void>
|
|
|
96
96
|
const att = event.payload.attachment as Record<string, unknown>;
|
|
97
97
|
meta.push(`[attachment: ${att.name ?? att.url ?? "file"}]`);
|
|
98
98
|
}
|
|
99
|
+
let enrichedBody = `${prefix}\n${event.text}`;
|
|
99
100
|
if (meta.length > 0) {
|
|
100
|
-
enrichedBody
|
|
101
|
+
enrichedBody += `\n\n--- 消息元数据 ---\n${meta.join("\n")}`;
|
|
101
102
|
}
|
|
102
103
|
|
|
103
104
|
try {
|