@seasonkoh/webaz 0.1.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/README.md +189 -0
- package/dist/cron-enforcement.js +83 -0
- package/dist/demo-agent.js +167 -0
- package/dist/index.js +182 -0
- package/dist/layer0-foundation/L0-1-database/schema.js +179 -0
- package/dist/layer0-foundation/L0-2-state-machine/engine.js +183 -0
- package/dist/layer0-foundation/L0-2-state-machine/transitions.js +197 -0
- package/dist/layer0-foundation/L0-5-manifest/manifest.js +306 -0
- package/dist/layer1-agent/L1-1-mcp-server/auth.js +21 -0
- package/dist/layer1-agent/L1-1-mcp-server/server.js +1062 -0
- package/dist/layer2-business/L2-6-notifications/notification-engine.js +217 -0
- package/dist/layer3-trust/L3-1-dispute-engine/dispute-engine.js +678 -0
- package/dist/layer4-economics/L4-3-reputation/reputation-engine.js +205 -0
- package/dist/layer4-economics/L4-4-skill-market/skill-engine.js +258 -0
- package/dist/mcp.js +11 -0
- package/dist/pwa/server.js +760 -0
- package/dist/test-dispute.js +153 -0
- package/dist/test-manifest.js +61 -0
- package/dist/test-mcp-tools.js +135 -0
- package/dist/test-reputation.js +116 -0
- package/dist/test-skill-market.js +101 -0
- package/package.json +60 -0
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* L0-5 · Protocol Manifest
|
|
3
|
+
*
|
|
4
|
+
* WebAZ的机器可读规范。
|
|
5
|
+
* 任何 AI Agent 读完这份 Manifest 就能立即参与协议,
|
|
6
|
+
* 无需人工引导、无需试错、无需查文档。
|
|
7
|
+
*
|
|
8
|
+
* 输出格式:结构化 JSON,可通过以下方式获取:
|
|
9
|
+
* 1. MCP Resource:webaz://protocol/manifest
|
|
10
|
+
* 2. HTTP GET:<server>/api/manifest
|
|
11
|
+
* 3. webaz_info 工具返回值中的 manifest 字段
|
|
12
|
+
*/
|
|
13
|
+
export const MANIFEST_VERSION = '0.1.0';
|
|
14
|
+
export const MANIFEST_URI = 'webaz://protocol/manifest';
|
|
15
|
+
// ─── 协议常量(与状态机保持同步)────────────────────────────
|
|
16
|
+
const DEADLINES = {
|
|
17
|
+
pay: { hours: 24, label: '24h', description: '买家下单后需在此时间内完成付款' },
|
|
18
|
+
accept: { hours: 24, label: '24h', description: '卖家收到订单通知后需在此时间内接单,否则自动退款并记录违约' },
|
|
19
|
+
ship: { hours: 72, label: '72h', description: '接单后卖家需在此时间内完成发货(含物流单号证明)' },
|
|
20
|
+
pickup: { hours: 48, label: '48h', description: '卖家标记发货后,物流方需在此时间内完成揽收' },
|
|
21
|
+
delivery: { hours: 168, label: '7天', description: '揽收后物流需在此时间内完成投递(含投递照片证明)' },
|
|
22
|
+
confirm: { hours: 72, label: '72h', description: '投递后买家需在此时间内确认收货,超时系统自动确认并结算' },
|
|
23
|
+
};
|
|
24
|
+
// ─── 状态机完整描述 ───────────────────────────────────────────
|
|
25
|
+
const STATE_MACHINE = {
|
|
26
|
+
states: {
|
|
27
|
+
created: { label: '待付款', responsible: 'buyer', terminal: false, description: '订单已创建,等待买家付款' },
|
|
28
|
+
paid: { label: '待接单', responsible: 'seller', terminal: false, description: '资金已托管,等待卖家 24h 内接单' },
|
|
29
|
+
accepted: { label: '待发货', responsible: 'seller', terminal: false, description: '卖家已接单,需在 72h 内发货' },
|
|
30
|
+
shipped: { label: '已发货', responsible: 'logistics', terminal: false, description: '包裹已交物流,等待揽收' },
|
|
31
|
+
picked_up: { label: '已揽收', responsible: 'logistics', terminal: false, description: '物流已揽收,正在运输' },
|
|
32
|
+
in_transit: { label: '运输中', responsible: 'logistics', terminal: false, description: '包裹运输中,等待投递' },
|
|
33
|
+
delivered: { label: '待确认', responsible: 'buyer', terminal: false, description: '包裹已投递,等待买家 72h 内确认收货' },
|
|
34
|
+
confirmed: { label: '已确认', responsible: 'system', terminal: false, description: '买家确认收货,触发自动结算' },
|
|
35
|
+
completed: { label: '已完成', responsible: null, terminal: true, description: '交易完成,资金已按比例分配' },
|
|
36
|
+
cancelled: { label: '已取消', responsible: null, terminal: true, description: '订单取消,资金退回(如有托管)' },
|
|
37
|
+
disputed: { label: '争议中', responsible: 'arbitrator', terminal: false, description: '争议冻结中,等待仲裁员介入' },
|
|
38
|
+
fault_seller: { label: '卖家违约', responsible: 'system', terminal: false, description: '卖家超时判责,正在退款买家' },
|
|
39
|
+
fault_logistics: { label: '物流违约', responsible: 'system', terminal: false, description: '物流方超时判责,正在处置赔付' },
|
|
40
|
+
fault_buyer: { label: '买家违约', responsible: 'system', terminal: false, description: '买家超时判责,资金转给卖家' },
|
|
41
|
+
},
|
|
42
|
+
// 所有合法转移(从 transitions.ts 同步)
|
|
43
|
+
transitions: [
|
|
44
|
+
{ from: 'created', to: 'paid', actor: 'buyer', deadline: 'pay', auto_fault: 'cancelled', evidence: false, description: '买家完成付款,资金进入协议托管' },
|
|
45
|
+
{ from: 'created', to: 'cancelled', actor: 'buyer/seller/system', deadline: null, auto_fault: null, evidence: false, description: '付款前取消订单,无需费用' },
|
|
46
|
+
{ from: 'paid', to: 'accepted', actor: 'seller', deadline: 'accept', auto_fault: 'fault_seller', evidence: false, description: '卖家接单,承诺按时发货' },
|
|
47
|
+
{ from: 'paid', to: 'cancelled', actor: 'buyer', deadline: null, auto_fault: null, evidence: false, description: '接单前买家可取消,全额退款' },
|
|
48
|
+
{ from: 'paid', to: 'disputed', actor: 'buyer/seller', deadline: null, auto_fault: null, evidence: true, description: '付款后发现问题,立即发起争议' },
|
|
49
|
+
{ from: 'accepted', to: 'shipped', actor: 'seller', deadline: 'ship', auto_fault: 'fault_seller', evidence: true, evidence_hint: '物流单号截图 + 包裹照片', description: '卖家发货,提交物流凭证' },
|
|
50
|
+
{ from: 'accepted', to: 'disputed', actor: 'buyer/seller', deadline: null, auto_fault: null, evidence: true, description: '接单后发现问题' },
|
|
51
|
+
{ from: 'shipped', to: 'picked_up', actor: 'logistics', deadline: 'pickup', auto_fault: 'fault_logistics', evidence: true, evidence_hint: '揽收扫描 + GPS', description: '物流揽收包裹' },
|
|
52
|
+
{ from: 'shipped', to: 'disputed', actor: 'buyer/seller/logistics', deadline: null, auto_fault: null, evidence: true, description: '发货后发现问题' },
|
|
53
|
+
{ from: 'picked_up', to: 'in_transit', actor: 'logistics/system', deadline: null, auto_fault: null, evidence: false, description: '开始运输' },
|
|
54
|
+
{ from: 'picked_up', to: 'disputed', actor: 'any', deadline: null, auto_fault: null, evidence: true, description: '揽收后发现包裹问题' },
|
|
55
|
+
{ from: 'in_transit', to: 'delivered', actor: 'logistics', deadline: 'delivery', auto_fault: 'fault_logistics', evidence: true, evidence_hint: '投递照片(含门牌号)+ 签收记录', description: '物流完成投递' },
|
|
56
|
+
{ from: 'in_transit', to: 'disputed', actor: 'any', deadline: null, auto_fault: null, evidence: true, description: '运输中出现问题' },
|
|
57
|
+
{ from: 'delivered', to: 'confirmed', actor: 'buyer/system', deadline: 'confirm', auto_fault: 'auto_confirmed', evidence: false, description: '买家确认收货(超时自动确认)' },
|
|
58
|
+
{ from: 'delivered', to: 'disputed', actor: 'buyer', deadline: null, auto_fault: null, evidence: true, evidence_hint: '收货照片 + 问题描述', description: '买家收货后发现问题' },
|
|
59
|
+
{ from: 'confirmed', to: 'completed', actor: 'system', deadline: null, auto_fault: null, evidence: false, description: '系统自动结算,交易完成' },
|
|
60
|
+
{ from: 'disputed', to: 'completed', actor: 'arbitrator/system', deadline: null, auto_fault: null, evidence: false, description: '仲裁裁定:资金释放给卖家' },
|
|
61
|
+
{ from: 'disputed', to: 'cancelled', actor: 'arbitrator/system', deadline: null, auto_fault: null, evidence: false, description: '仲裁裁定:退款买家' },
|
|
62
|
+
],
|
|
63
|
+
// 超时截止时间配置(从下单到结束每个阶段的 hours)
|
|
64
|
+
deadline_config: DEADLINES,
|
|
65
|
+
};
|
|
66
|
+
// ─── 经济模型 ─────────────────────────────────────────────────
|
|
67
|
+
const ECONOMICS = {
|
|
68
|
+
fees: {
|
|
69
|
+
protocol: { rate: '2%', description: '协议运营费,每笔成交后从卖家收益中扣除' },
|
|
70
|
+
logistics: { rate: '5%', description: '物流服务费,成交后自动分配给物流方' },
|
|
71
|
+
promoter: { rate: '3%', description: '推荐佣金,如果买家通过推荐链接下单,推荐人获得' },
|
|
72
|
+
skill_ref: { rate: '0.5%', description: 'Skill 推荐佣金:买家订阅了卖家的 catalog_sync Skill,成交后 Skill 发布者获得' },
|
|
73
|
+
},
|
|
74
|
+
seller_net: '成交额 × (100% - 2% - 5% - 3%推荐[可选]) = 约 90~93%',
|
|
75
|
+
stakes: {
|
|
76
|
+
seller: {
|
|
77
|
+
base_rate: '15%',
|
|
78
|
+
description: '卖家上架商品时需质押商品价格的 15%(声誉越高折扣越大,最低降至 5%)',
|
|
79
|
+
fate_on_success: '交易完成后100%返还给卖家',
|
|
80
|
+
fate_on_fault: '违约时扣除部分质押赔付买家',
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
escrow: {
|
|
84
|
+
description: '买家付款后资金立即进入协议托管,不经任何人手',
|
|
85
|
+
release_condition: '仅在买家确认收货或仲裁完成后自动释放',
|
|
86
|
+
currency: 'WAZ(Phase 0 为模拟代币,Phase 2 接入链上稳定币)',
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
// ─── 角色描述 ─────────────────────────────────────────────────
|
|
90
|
+
const ROLES = {
|
|
91
|
+
buyer: {
|
|
92
|
+
label: '买家',
|
|
93
|
+
description: '浏览搜索商品,下单付款,确认收货。如有问题可发起争议。',
|
|
94
|
+
stake_required: false,
|
|
95
|
+
entry_action: 'webaz_register(role=buyer)',
|
|
96
|
+
workflow: [
|
|
97
|
+
'webaz_search(query="...") → 搜索商品',
|
|
98
|
+
'webaz_place_order(product_id, shipping_address) → 下单,资金自动托管',
|
|
99
|
+
'webaz_get_status(order_id) → 追踪订单进展',
|
|
100
|
+
'webaz_update_order(action=confirm) → 确认收货,触发结算',
|
|
101
|
+
'webaz_update_order(action=dispute, evidence) → 如有问题发起争议',
|
|
102
|
+
],
|
|
103
|
+
key_rights: ['72h 内不确认可超时自动确认', '任何阶段可发起争议(需提供证据)', '卖家/物流违约自动退款'],
|
|
104
|
+
key_duties: ['24h 内完成付款', '72h 内确认收货或发起争议', '争议需提供真实证据'],
|
|
105
|
+
},
|
|
106
|
+
seller: {
|
|
107
|
+
label: '卖家',
|
|
108
|
+
description: '上架商品,接单,按时发货。质押保证金确保履约。',
|
|
109
|
+
stake_required: true,
|
|
110
|
+
entry_action: 'webaz_register(role=seller)',
|
|
111
|
+
workflow: [
|
|
112
|
+
'webaz_list_product(title, description, price, stock) → 上架商品(需质押 15% 保证金)',
|
|
113
|
+
'webaz_notifications(unread=true) → 定期检查新订单通知',
|
|
114
|
+
'webaz_update_order(action=accept, order_id) → 接单(24h 内必须)',
|
|
115
|
+
'webaz_update_order(action=ship, evidence="物流单号+照片") → 发货(72h 内必须)',
|
|
116
|
+
'webaz_skill(action=publish, skill_type=auto_accept) → 可选:发布自动接单 Skill',
|
|
117
|
+
],
|
|
118
|
+
key_rights: ['自动结算无需人工干预', '声誉升级降低质押比例', '发布 Skill 获得额外推荐佣金'],
|
|
119
|
+
key_duties: ['24h 内接单(否则自动退款 + 违约记录)', '72h 内发货(需上传证据)', '争议需在 48h 内提交反驳证据'],
|
|
120
|
+
},
|
|
121
|
+
logistics: {
|
|
122
|
+
label: '物流方',
|
|
123
|
+
description: '揽收包裹,更新运输状态,完成投递。每笔成交获得 5% 物流费。',
|
|
124
|
+
stake_required: false,
|
|
125
|
+
entry_action: 'webaz_register(role=logistics)',
|
|
126
|
+
workflow: [
|
|
127
|
+
'webaz_update_order(action=pickup, order_id, evidence="揽收凭证") → 揽收(48h 内)',
|
|
128
|
+
'webaz_update_order(action=transit, order_id) → 更新运输状态',
|
|
129
|
+
'webaz_update_order(action=deliver, order_id, evidence="投递照片") → 确认投递(7天内)',
|
|
130
|
+
],
|
|
131
|
+
key_rights: ['每笔成交自动获得 5% 物流费', '违约赔付有责任上限'],
|
|
132
|
+
key_duties: ['48h 内揽收', '7天内完成投递', '必须上传揽收和投递证明'],
|
|
133
|
+
},
|
|
134
|
+
arbitrator: {
|
|
135
|
+
label: '仲裁员',
|
|
136
|
+
description: '处理争议案件,做出裁定。需要公正客观,裁定结果永久上链。',
|
|
137
|
+
stake_required: false,
|
|
138
|
+
entry_action: 'webaz_register(role=arbitrator)',
|
|
139
|
+
workflow: [
|
|
140
|
+
'webaz_dispute(action=list_open) → 查看所有待处理争议',
|
|
141
|
+
'webaz_dispute(action=view, dispute_id) → 查看争议详情和双方证据',
|
|
142
|
+
'webaz_dispute(action=arbitrate, ruling=refund_buyer|release_seller|partial_refund, ruling_reason) → 做出裁定',
|
|
143
|
+
],
|
|
144
|
+
key_rights: ['查看所有争议详情', '做出三种裁定选择', '仲裁超时后系统自动裁定(保护所有人)'],
|
|
145
|
+
key_duties: ['120h 内完成裁定(否则系统自动退款买家)', '裁定必须提供理由(永久记录)', '保持公正客观'],
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
// ─── 信任保障 ─────────────────────────────────────────────────
|
|
149
|
+
const TRUST_GUARANTEES = [
|
|
150
|
+
{
|
|
151
|
+
guarantee: '资金自动托管,任何人无法单方面转移',
|
|
152
|
+
mechanism: '买家付款后资金锁定在协议层,仅在双方达成共识或仲裁完成后释放',
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
guarantee: '每个状态转移都需要责任方的操作证明',
|
|
156
|
+
mechanism: '状态机拦截所有非法转移;关键步骤(发货/投递)强制要求证据',
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
guarantee: '超时自动判责,无需任何人主动触发',
|
|
160
|
+
mechanism: 'cron 进程每 5 分钟扫描,超时方自动判违约并执行处置',
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
guarantee: '争议 48h 无响应自动判原告胜诉',
|
|
164
|
+
mechanism: '被告超时不回应,协议自动裁定:买家发起则退款,卖家发起则释放资金',
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
guarantee: '仲裁员 120h 不裁定自动退款买家',
|
|
168
|
+
mechanism: '买家保护原则:仲裁员失职时,协议默认保护资金弱势方',
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
guarantee: '声誉系统防止恶意行为者反复违约',
|
|
172
|
+
mechanism: '违约每次扣 40 分,累积负面记录,声誉低的参与者需支付更高质押',
|
|
173
|
+
},
|
|
174
|
+
];
|
|
175
|
+
// ─── 争议系统 ─────────────────────────────────────────────────
|
|
176
|
+
const DISPUTE_SYSTEM = {
|
|
177
|
+
description: '任何参与方对交易有异议时,可在有效阶段发起争议。争议启动后资金冻结直至裁定。',
|
|
178
|
+
timelines: {
|
|
179
|
+
defendant_response: '48h — 被告方提交反驳证据的截止时间',
|
|
180
|
+
arbitrator_ruling: '120h — 仲裁员做出裁定的截止时间',
|
|
181
|
+
},
|
|
182
|
+
rulings: {
|
|
183
|
+
refund_buyer: '全额退款买家,扣押卖家 50% 质押作为违约金',
|
|
184
|
+
release_seller: '释放资金给卖家,扣押部分买家押金',
|
|
185
|
+
partial_refund: '按指定金额部分退款,适用于质量争议',
|
|
186
|
+
},
|
|
187
|
+
auto_escalation: [
|
|
188
|
+
'被告 48h 不响应 → 原告自动胜诉(无需仲裁员)',
|
|
189
|
+
'仲裁员 120h 不裁定 → 系统默认退款买家(买家保护原则)',
|
|
190
|
+
],
|
|
191
|
+
};
|
|
192
|
+
// ─── Skill 市场摘要 ───────────────────────────────────────────
|
|
193
|
+
const SKILL_MARKET = {
|
|
194
|
+
description: 'Skill 市场让卖家发布可复用的 Agent 能力插件,买家订阅后自动享受增值服务。解决协议冷启动的核心机制。',
|
|
195
|
+
skill_types: [
|
|
196
|
+
{ type: 'catalog_sync', label: '目录同步', benefit: '买家订阅后搜索时优先看到你的商品,成交额 0.5% 作为推荐佣金' },
|
|
197
|
+
{ type: 'auto_accept', label: '自动接单', benefit: '买家下单后立即接受,无需等待 24h,大幅提升买家体验' },
|
|
198
|
+
{ type: 'price_negotiation', label: '价格协商', benefit: '允许买家 Agent 在限定范围内自动议价,减少沟通成本' },
|
|
199
|
+
{ type: 'quality_guarantee', label: '质量承诺', benefit: '额外质押 WAZ 作为品质担保,增强买家信任' },
|
|
200
|
+
{ type: 'instant_ship', label: '极速发货', benefit: '承诺 24h 内发货,违约自动赔付' },
|
|
201
|
+
],
|
|
202
|
+
};
|
|
203
|
+
// ─── 声誉系统摘要 ─────────────────────────────────────────────
|
|
204
|
+
const REPUTATION = {
|
|
205
|
+
description: '声誉积分是参与者在协议中的无形资产,影响质押折扣、搜索排序和买家信任度。',
|
|
206
|
+
levels: [
|
|
207
|
+
{ key: 'new', label: '新手 🌱', min_points: 0, stake_discount: '0%', search_boost: '0%' },
|
|
208
|
+
{ key: 'trusted', label: '可信 ⭐', min_points: 200, stake_discount: '-5%', search_boost: '+10%' },
|
|
209
|
+
{ key: 'quality', label: '优质 🌟', min_points: 800, stake_discount: '-10%', search_boost: '+25%' },
|
|
210
|
+
{ key: 'star', label: '明星 💫', min_points: 2000, stake_discount: '-15%', search_boost: '+50%' },
|
|
211
|
+
{ key: 'legend', label: '传奇 🔥', min_points: 5000, stake_discount: '-20%', search_boost: '置顶' },
|
|
212
|
+
],
|
|
213
|
+
earning_events: [
|
|
214
|
+
{ event: '交易完成', seller: '+10', buyer: '+5', logistics: '+8' },
|
|
215
|
+
{ event: '极速接单(6h内)', seller: '+5', buyer: '-', logistics: '-' },
|
|
216
|
+
{ event: '准时发货', seller: '+5', buyer: '-', logistics: '-' },
|
|
217
|
+
{ event: '准时投递', seller: '-', buyer: '-', logistics: '+5' },
|
|
218
|
+
{ event: '及时确认收货', seller: '-', buyer: '+2', logistics: '-' },
|
|
219
|
+
{ event: '争议胜诉', all: '+8' },
|
|
220
|
+
{ event: '争议败诉', all: '-25' },
|
|
221
|
+
{ event: '超时违约', all: '-40' },
|
|
222
|
+
],
|
|
223
|
+
};
|
|
224
|
+
// ─── Agent 操作指南(直接嵌入 Manifest,供 LLM 读取)──────────
|
|
225
|
+
const AGENT_GUIDE = {
|
|
226
|
+
for_llm: `你是一个 AI Agent,正在读取 WebAZ的机器可读规范。
|
|
227
|
+
以下是你需要知道的核心要点:
|
|
228
|
+
|
|
229
|
+
1. WebAZ 是一个 Agent 原生的商业协议。你可以作为买家、卖家或物流方参与交易。
|
|
230
|
+
2. 调用 webaz_register 获取 api_key,后续所有操作都用这个 key 认证。
|
|
231
|
+
3. 每笔交易的资金自动托管,超时自动判责,你不需要担心对方违约。
|
|
232
|
+
4. 发货/揽收/投递必须上传证据,否则会被认定为未操作。
|
|
233
|
+
5. 如发现问题,立即调用 webaz_update_order(action=dispute) 发起争议,不要等待。
|
|
234
|
+
6. 使用 webaz_notifications(unread=true, mark_read=true) 定期检查待处理事项。
|
|
235
|
+
|
|
236
|
+
⚠️ 关键规则:所有截止时间都是硬性规定,超时自动判责,与对方沟通无法延期。`,
|
|
237
|
+
decision_tree: {
|
|
238
|
+
'我是买家,想购买某件商品': ['webaz_search → webaz_place_order → 等通知 → webaz_update_order(confirm)'],
|
|
239
|
+
'我是卖家,有新订单通知': ['webaz_get_status → webaz_update_order(accept) → webaz_update_order(ship, evidence)'],
|
|
240
|
+
'我是物流,需要揽收': ['webaz_update_order(pickup, evidence) → webaz_update_order(deliver, evidence)'],
|
|
241
|
+
'收到货物有问题': ['立即 webaz_update_order(dispute, evidence_description) → webaz_dispute(respond)'],
|
|
242
|
+
'我是仲裁员': ['webaz_dispute(list_open) → webaz_dispute(view) → webaz_dispute(arbitrate, ruling, reason)'],
|
|
243
|
+
},
|
|
244
|
+
};
|
|
245
|
+
// ─── 生成 Manifest ────────────────────────────────────────────
|
|
246
|
+
export function generateManifest(db) {
|
|
247
|
+
// 如果传入 db,可以附加实时统计数据
|
|
248
|
+
const stats = db ? getLiveStats(db) : null;
|
|
249
|
+
return {
|
|
250
|
+
$schema: 'https://dcp-protocol.io/schema/manifest/v1',
|
|
251
|
+
$uri: MANIFEST_URI,
|
|
252
|
+
generated_at: new Date().toISOString(),
|
|
253
|
+
protocol: {
|
|
254
|
+
name: 'WebAZ',
|
|
255
|
+
full_name: 'WebAZ',
|
|
256
|
+
version: MANIFEST_VERSION,
|
|
257
|
+
tagline: 'AI Agent 原生商业协议 — 任何 Agent 可以买货、卖货、送货',
|
|
258
|
+
description: 'WebAZ 是一个专为 AI Agent 设计的去中心化商业协议。协议通过状态机强制每个参与方按时举证,超时自动判责,资金自动结算。任何 AI Agent 接入 MCP 工具后即可立即参与真实商业交易。',
|
|
259
|
+
phase: 'Phase 0 — 概念验证(SQLite 模拟,无需真实货币)',
|
|
260
|
+
roadmap: {
|
|
261
|
+
phase0: '✅ 完成 — 状态机、资金托管、争议仲裁、通知、Skill 市场、声誉积分',
|
|
262
|
+
phase1: '⏳ 进行中 — MCP 市场发布,接入真实卖家',
|
|
263
|
+
phase2: '⬜ 计划中 — 链上资产托管,去中心化节点',
|
|
264
|
+
},
|
|
265
|
+
},
|
|
266
|
+
agent_guide: AGENT_GUIDE,
|
|
267
|
+
roles: ROLES,
|
|
268
|
+
state_machine: STATE_MACHINE,
|
|
269
|
+
economics: ECONOMICS,
|
|
270
|
+
trust_guarantees: TRUST_GUARANTEES,
|
|
271
|
+
dispute_system: DISPUTE_SYSTEM,
|
|
272
|
+
skill_market: SKILL_MARKET,
|
|
273
|
+
reputation: REPUTATION,
|
|
274
|
+
// 实时统计(可选)
|
|
275
|
+
live_stats: stats,
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
function getLiveStats(db) {
|
|
279
|
+
try {
|
|
280
|
+
const users = db.prepare('SELECT COUNT(*) as n FROM users WHERE role != ?').get('system').n;
|
|
281
|
+
const products = db.prepare("SELECT COUNT(*) as n FROM products WHERE status = 'active'").get().n;
|
|
282
|
+
const orders = db.prepare('SELECT COUNT(*) as n FROM orders').get().n;
|
|
283
|
+
const completed = db.prepare("SELECT COUNT(*) as n FROM orders WHERE status = 'completed'").get().n;
|
|
284
|
+
const disputes = db.prepare('SELECT COUNT(*) as n FROM disputes').get().n;
|
|
285
|
+
const skills = db.prepare("SELECT COUNT(*) as n FROM skills WHERE active = 1").get().n;
|
|
286
|
+
const totalVolume = db.prepare("SELECT COALESCE(SUM(total_amount),0) as v FROM orders WHERE status = 'completed'").get().v;
|
|
287
|
+
return { users, active_products: products, total_orders: orders, completed_orders: completed, total_disputes: disputes, active_skills: skills, total_volume_dcp: totalVolume };
|
|
288
|
+
}
|
|
289
|
+
catch {
|
|
290
|
+
return null;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
// ─── 格式化输出(供 webaz_info 使用)──────────────────────────
|
|
294
|
+
export function getManifestSummary() {
|
|
295
|
+
return {
|
|
296
|
+
name: 'WebAZ',
|
|
297
|
+
version: MANIFEST_VERSION,
|
|
298
|
+
tagline: 'AI Agent 原生商业协议',
|
|
299
|
+
roles_count: Object.keys(ROLES).length,
|
|
300
|
+
states_count: Object.keys(STATE_MACHINE.states).length,
|
|
301
|
+
transitions_count: STATE_MACHINE.transitions.length,
|
|
302
|
+
trust_guarantees_count: TRUST_GUARANTEES.length,
|
|
303
|
+
manifest_uri: MANIFEST_URI,
|
|
304
|
+
manifest_http_hint: '通过 GET /api/manifest 获取完整规范(需要 PWA 服务器运行)',
|
|
305
|
+
};
|
|
306
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* L1-7 · Agent 身份验证
|
|
3
|
+
* Agent 调用任何需要权限的工具时,必须提供 api_key。
|
|
4
|
+
* api_key 在注册时生成,绑定到用户角色。
|
|
5
|
+
*/
|
|
6
|
+
export function authenticate(db, apiKey) {
|
|
7
|
+
if (!apiKey || apiKey === '')
|
|
8
|
+
return null;
|
|
9
|
+
return db
|
|
10
|
+
.prepare('SELECT id, name, role, api_key FROM users WHERE api_key = ?')
|
|
11
|
+
.get(apiKey);
|
|
12
|
+
}
|
|
13
|
+
export function requireAuth(db, apiKey) {
|
|
14
|
+
const user = authenticate(db, apiKey);
|
|
15
|
+
if (!user) {
|
|
16
|
+
return {
|
|
17
|
+
error: '身份验证失败:api_key 无效。请先用 dcp_register 注册并保存你的 api_key。'
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
return { user };
|
|
21
|
+
}
|