@wowok/agent-mcp 2.3.14 → 2.3.16

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.
Files changed (156) hide show
  1. package/dist/config/index.d.ts +1 -0
  2. package/dist/config/index.js +1 -0
  3. package/dist/config/runtime.d.ts +26 -0
  4. package/dist/config/runtime.js +217 -0
  5. package/dist/customer/industry-risks.d.ts +36 -0
  6. package/dist/customer/industry-risks.js +424 -0
  7. package/dist/customer/info-puzzle.d.ts +102 -0
  8. package/dist/customer/info-puzzle.js +312 -0
  9. package/dist/customer/order-monitor.d.ts +75 -0
  10. package/dist/customer/order-monitor.js +327 -0
  11. package/dist/customer/order-strategy.d.ts +36 -0
  12. package/dist/customer/order-strategy.js +373 -0
  13. package/dist/customer/post-purchase.d.ts +42 -0
  14. package/dist/customer/post-purchase.js +350 -0
  15. package/dist/customer/reminder-system.d.ts +42 -0
  16. package/dist/customer/reminder-system.js +295 -0
  17. package/dist/customer/risk-assessment.d.ts +8 -0
  18. package/dist/customer/risk-assessment.js +337 -0
  19. package/dist/customer/types.d.ts +193 -0
  20. package/dist/customer/types.js +13 -0
  21. package/dist/customer/user-preferences.d.ts +67 -0
  22. package/dist/customer/user-preferences.js +451 -0
  23. package/dist/experience/experience-reuse.d.ts +10 -0
  24. package/dist/experience/experience-reuse.js +103 -0
  25. package/dist/experience/index.d.ts +6 -0
  26. package/dist/experience/index.js +5 -0
  27. package/dist/experience/intent-distill.d.ts +3 -0
  28. package/dist/experience/intent-distill.js +83 -0
  29. package/dist/experience/realtime-feedback.d.ts +5 -0
  30. package/dist/experience/realtime-feedback.js +77 -0
  31. package/dist/experience/types.d.ts +50 -0
  32. package/dist/experience/types.js +1 -0
  33. package/dist/experience/user-profile.d.ts +25 -0
  34. package/dist/experience/user-profile.js +171 -0
  35. package/dist/index.js +570 -186
  36. package/dist/knowledge/acquisition-flywheel.d.ts +50 -0
  37. package/dist/knowledge/acquisition-flywheel.js +183 -0
  38. package/dist/knowledge/arbitration-trust.d.ts +24 -0
  39. package/dist/knowledge/arbitration-trust.js +117 -0
  40. package/dist/knowledge/audit-rules.d.ts +28 -0
  41. package/dist/knowledge/audit-rules.js +141 -0
  42. package/dist/knowledge/demand-matching.d.ts +29 -0
  43. package/dist/knowledge/demand-matching.js +132 -0
  44. package/dist/knowledge/dynamic-pricing.d.ts +31 -0
  45. package/dist/knowledge/dynamic-pricing.js +87 -0
  46. package/dist/knowledge/flywheel-loop.d.ts +87 -0
  47. package/dist/knowledge/flywheel-loop.js +378 -0
  48. package/dist/knowledge/glossary.d.ts +18 -0
  49. package/dist/knowledge/glossary.js +209 -0
  50. package/dist/knowledge/index.d.ts +64 -0
  51. package/dist/knowledge/index.js +66 -0
  52. package/dist/knowledge/industry-evolution.d.ts +82 -0
  53. package/dist/knowledge/industry-evolution.js +323 -0
  54. package/dist/knowledge/industry-generalizer.d.ts +17 -0
  55. package/dist/knowledge/industry-generalizer.js +381 -0
  56. package/dist/knowledge/industry-registry.d.ts +49 -0
  57. package/dist/knowledge/industry-registry.js +167 -0
  58. package/dist/knowledge/intent-metrics.d.ts +42 -0
  59. package/dist/knowledge/intent-metrics.js +566 -0
  60. package/dist/knowledge/process-model.d.ts +24 -0
  61. package/dist/knowledge/process-model.js +160 -0
  62. package/dist/knowledge/reputation-rules.d.ts +42 -0
  63. package/dist/knowledge/reputation-rules.js +99 -0
  64. package/dist/knowledge/reward-templates.d.ts +25 -0
  65. package/dist/knowledge/reward-templates.js +125 -0
  66. package/dist/knowledge/safety-rules.d.ts +36 -0
  67. package/dist/knowledge/safety-rules.js +171 -0
  68. package/dist/knowledge/tool-constraints.d.ts +30 -0
  69. package/dist/knowledge/tool-constraints.js +185 -0
  70. package/dist/knowledge/trust-metrics.d.ts +37 -0
  71. package/dist/knowledge/trust-metrics.js +138 -0
  72. package/dist/loop-engineering/diagnose.d.ts +3 -2
  73. package/dist/loop-engineering/diagnose.js +94 -0
  74. package/dist/loop-engineering/improve.d.ts +1 -1
  75. package/dist/loop-engineering/improve.js +52 -1
  76. package/dist/project/graph.d.ts +71 -0
  77. package/dist/project/graph.js +314 -0
  78. package/dist/project/index.d.ts +62 -0
  79. package/dist/project/index.js +167 -0
  80. package/dist/project/namespace.d.ts +62 -0
  81. package/dist/project/namespace.js +181 -0
  82. package/dist/project/query.d.ts +40 -0
  83. package/dist/project/query.js +110 -0
  84. package/dist/safety/confirm-gate.d.ts +15 -0
  85. package/dist/safety/confirm-gate.js +44 -0
  86. package/dist/safety/index.d.ts +3 -0
  87. package/dist/safety/index.js +3 -0
  88. package/dist/safety/preview.d.ts +2 -0
  89. package/dist/safety/preview.js +36 -0
  90. package/dist/schema/call/allocation.d.ts +15 -0
  91. package/dist/schema/call/arbitration.d.ts +111 -96
  92. package/dist/schema/call/base.d.ts +1070 -44
  93. package/dist/schema/call/base.js +69 -1
  94. package/dist/schema/call/bridge.d.ts +709 -52
  95. package/dist/schema/call/bridge.js +13 -2
  96. package/dist/schema/call/contact.d.ts +15 -0
  97. package/dist/schema/call/demand.d.ts +69 -54
  98. package/dist/schema/call/guard.d.ts +125 -80
  99. package/dist/schema/call/handler.d.ts +3 -0
  100. package/dist/schema/call/handler.js +14 -0
  101. package/dist/schema/call/machine.d.ts +830 -800
  102. package/dist/schema/call/order.d.ts +15 -0
  103. package/dist/schema/call/payment.d.ts +15 -0
  104. package/dist/schema/call/permission.d.ts +15 -0
  105. package/dist/schema/call/personal.d.ts +15 -0
  106. package/dist/schema/call/progress.d.ts +15 -0
  107. package/dist/schema/call/proof.d.ts +42 -12
  108. package/dist/schema/call/proof.js +3 -3
  109. package/dist/schema/call/repository.d.ts +91 -76
  110. package/dist/schema/call/reward.d.ts +45 -30
  111. package/dist/schema/call/semantic.d.ts +1 -0
  112. package/dist/schema/call/semantic.js +217 -0
  113. package/dist/schema/call/service.d.ts +407 -392
  114. package/dist/schema/call/treasury.d.ts +15 -0
  115. package/dist/schema/common/index.js +3 -3
  116. package/dist/schema/local/index.d.ts +228 -72
  117. package/dist/schema/local/index.js +33 -6
  118. package/dist/schema/messenger/index.d.ts +668 -50
  119. package/dist/schema/messenger/index.js +9 -0
  120. package/dist/schema/operations.d.ts +1693 -1369
  121. package/dist/schema/operations.js +2 -2
  122. package/dist/schema/query/index.d.ts +1614 -1614
  123. package/dist/schema/query/index.js +30 -27
  124. package/dist/schemas/account_operation.output.json +25 -16
  125. package/dist/schemas/account_operation.schema.json +1 -1
  126. package/dist/schemas/bridge_operation.output.json +520 -0
  127. package/dist/schemas/bridge_operation.schema.json +15 -0
  128. package/dist/schemas/guard2file.schema.json +15 -0
  129. package/dist/schemas/index.json +1 -1
  130. package/dist/schemas/local_info_operation.output.json +23 -0
  131. package/dist/schemas/local_info_operation.schema.json +1 -1
  132. package/dist/schemas/local_mark_operation.output.json +24 -1
  133. package/dist/schemas/local_mark_operation.schema.json +4 -4
  134. package/dist/schemas/machineNode2file.schema.json +15 -0
  135. package/dist/schemas/messenger_operation.output.json +528 -0
  136. package/dist/schemas/onchain_operations.output.json +350 -16
  137. package/dist/schemas/onchain_operations.schema.json +96 -23
  138. package/dist/schemas/onchain_operations_allocation.schema.json +15 -0
  139. package/dist/schemas/onchain_operations_arbitration.schema.json +15 -0
  140. package/dist/schemas/onchain_operations_contact.schema.json +15 -0
  141. package/dist/schemas/onchain_operations_demand.schema.json +15 -0
  142. package/dist/schemas/onchain_operations_gen_passport.schema.json +30 -0
  143. package/dist/schemas/onchain_operations_guard.schema.json +15 -0
  144. package/dist/schemas/onchain_operations_machine.schema.json +81 -23
  145. package/dist/schemas/onchain_operations_order.schema.json +15 -0
  146. package/dist/schemas/onchain_operations_payment.schema.json +15 -0
  147. package/dist/schemas/onchain_operations_permission.schema.json +15 -0
  148. package/dist/schemas/onchain_operations_personal.schema.json +15 -0
  149. package/dist/schemas/onchain_operations_progress.schema.json +15 -0
  150. package/dist/schemas/onchain_operations_repository.schema.json +15 -0
  151. package/dist/schemas/onchain_operations_reward.schema.json +15 -0
  152. package/dist/schemas/onchain_operations_service.schema.json +15 -0
  153. package/dist/schemas/onchain_operations_treasury.schema.json +15 -0
  154. package/dist/schemas/onchain_table_data.output.json +221 -69
  155. package/dist/schemas/onchain_table_data.schema.json +2 -2
  156. package/package.json +2 -2
@@ -0,0 +1,350 @@
1
+ import { CUSTOMER_INTELLIGENCE_VERSION } from "./types.js";
2
+ export function generatePostPurchaseAdvice(ctx) {
3
+ switch (ctx.phase) {
4
+ case "refund_tracking":
5
+ return trackRefund(ctx);
6
+ case "quality_issue":
7
+ return handleQualityIssue(ctx);
8
+ case "merchant_unreachable":
9
+ return handleMerchantUnreachable(ctx);
10
+ case "arbitration_support":
11
+ return arbitrationSupport(ctx);
12
+ }
13
+ }
14
+ export function trackRefund(ctx) {
15
+ const actions = [];
16
+ const orderAmount = ctx.order_amount ?? 0n;
17
+ const refunded = ctx.refunded_amount ?? 0n;
18
+ if (orderAmount > 0n && refunded >= orderAmount) {
19
+ actions.push({
20
+ id: "refund_complete",
21
+ phase: "refund_tracking",
22
+ priority: "info",
23
+ title: "退款已完成",
24
+ message: `✅ 订单 ${ctx.order_id} 退款已全额到账(${refunded} 最小单位)`,
25
+ next_step: "可关闭售后跟踪,建议提交订单评价",
26
+ });
27
+ return actions;
28
+ }
29
+ if (refunded > 0n && refunded < orderAmount) {
30
+ const diff = orderAmount - refunded;
31
+ actions.push({
32
+ id: "refund_partial",
33
+ phase: "refund_tracking",
34
+ priority: "required",
35
+ title: "退款不完整",
36
+ message: `⚠️ 订单 ${ctx.order_id} 仅退款 ${refunded}/${orderAmount},差额 ${diff} 最小单位未到账`,
37
+ next_step: "通过 Messenger 催促商家补足差额,或发起仲裁追回",
38
+ tool: "messenger_send",
39
+ });
40
+ return actions;
41
+ }
42
+ if (refunded === 0n && ctx.refund_requested === true) {
43
+ actions.push({
44
+ id: "refund_waiting",
45
+ phase: "refund_tracking",
46
+ priority: "recommended",
47
+ title: "等待商家退款",
48
+ message: `⏳ 订单 ${ctx.order_id} 已申请退款,等待商家触发退款 Allocator`,
49
+ next_step: "若 48 小时内未到账,建议通过 Messenger 催促或发起仲裁",
50
+ tool: "query_toolkit",
51
+ });
52
+ return actions;
53
+ }
54
+ const hasRefundPath = ctx.puzzle?.workflow_analysis?.has_refund_path ?? false;
55
+ if (refunded === 0n && ctx.refund_requested !== true && hasRefundPath) {
56
+ actions.push({
57
+ id: "refund_trigger_available",
58
+ phase: "refund_tracking",
59
+ priority: "recommended",
60
+ title: "可通过 Allocator 触发退款",
61
+ message: `ℹ️ 订单 ${ctx.order_id} 存在退款路径,可触发 refund Allocator 退款`,
62
+ next_step: "通过 query_toolkit 查询 refund Allocator 触发条件并申请退款",
63
+ tool: "query_toolkit",
64
+ });
65
+ return actions;
66
+ }
67
+ actions.push({
68
+ id: "refund_no_path",
69
+ phase: "refund_tracking",
70
+ priority: "required",
71
+ title: "无退款路径,需通过仲裁",
72
+ message: `🔴 订单 ${ctx.order_id} 无退款 Allocator 路径,需通过仲裁追回资金`,
73
+ next_step: "切换到 arbitration_support 阶段,发起仲裁申请",
74
+ tool: "mark_arbitration",
75
+ });
76
+ return actions;
77
+ }
78
+ export function handleQualityIssue(ctx) {
79
+ const actions = [];
80
+ if (ctx.original_wip_hash &&
81
+ ctx.wip_hash &&
82
+ ctx.original_wip_hash !== ctx.wip_hash) {
83
+ actions.push({
84
+ id: "quality_wip_mismatch",
85
+ phase: "quality_issue",
86
+ priority: "required",
87
+ title: "检测到 WIP hash 不一致",
88
+ message: `🔴 订单 ${ctx.order_id} 的 WIP hash 与下单时不一致,可能存在交付物变更。\n` +
89
+ ` 原始:${ctx.original_wip_hash}\n` +
90
+ ` 当前:${ctx.wip_hash}`,
91
+ next_step: "通过 query_toolkit 复核 WIP,并立即发起仲裁",
92
+ tool: "query_toolkit",
93
+ });
94
+ }
95
+ if (!ctx.wip_hash) {
96
+ actions.push({
97
+ id: "quality_wip_missing",
98
+ phase: "quality_issue",
99
+ priority: "recommended",
100
+ title: "要求商家提供 WIP hash 验证",
101
+ message: `⚠️ 订单 ${ctx.order_id} 缺少当前 WIP hash,无法验证交付物完整性`,
102
+ next_step: "通过 Messenger 索取最新 WIP hash 并与原始 hash 对比",
103
+ tool: "messenger_send",
104
+ });
105
+ }
106
+ const evidenceCount = ctx.evidence?.length ?? 0;
107
+ if (evidenceCount === 0) {
108
+ actions.push({
109
+ id: "quality_collect_evidence",
110
+ phase: "quality_issue",
111
+ priority: "recommended",
112
+ title: "收集证据:截图、聊天记录、交付物样品",
113
+ message: `📋 订单 ${ctx.order_id} 暂无证据收集记录。建议立即收集:\n` +
114
+ ` • 交付物截图 / 录屏\n` +
115
+ ` • Messenger 聊天记录(导出 WTS 凭证)\n` +
116
+ ` • 交付物样品或测试结果`,
117
+ next_step: "通过 messenger_mark_evidence 生成 WTS 证据文件",
118
+ tool: "messenger_mark_evidence",
119
+ });
120
+ }
121
+ else if (evidenceCount < 3) {
122
+ actions.push({
123
+ id: "quality_supplement_evidence",
124
+ phase: "quality_issue",
125
+ priority: "recommended",
126
+ title: `补充更多证据(当前 ${evidenceCount} 项,建议 ≥3 项)`,
127
+ message: `⚠️ 订单 ${ctx.order_id} 已收集 ${evidenceCount} 项证据,建议补充至 3 项以上以增强仲裁胜算。\n` +
128
+ ` 当前证据:${ctx.evidence?.join(" / ") ?? "无"}`,
129
+ next_step: "补充截图、聊天记录或第三方鉴定报告",
130
+ tool: "messenger_mark_evidence",
131
+ });
132
+ }
133
+ if (actions.length === 0) {
134
+ actions.push({
135
+ id: "quality_ok",
136
+ phase: "quality_issue",
137
+ priority: "info",
138
+ title: "质量验证通过",
139
+ message: `✅ 订单 ${ctx.order_id} 的 WIP hash 与原始一致,证据齐全(${evidenceCount} 项)`,
140
+ next_step: "可正常推进验收流程",
141
+ });
142
+ }
143
+ return actions;
144
+ }
145
+ export function handleMerchantUnreachable(ctx) {
146
+ const actions = [];
147
+ const lastReply = ctx.last_merchant_reply_at;
148
+ const days = lastReply !== undefined
149
+ ? Math.floor((ctx.now - lastReply) / (24 * 60 * 60 * 1000))
150
+ : Infinity;
151
+ const hasArbitration = ctx.has_arbitration ?? ctx.puzzle?.workflow_analysis?.has_arbitration_path ?? false;
152
+ if (days > 7) {
153
+ if (hasArbitration) {
154
+ actions.push({
155
+ id: "unreachable_arb_recommend",
156
+ phase: "merchant_unreachable",
157
+ priority: "required",
158
+ title: "建议发起仲裁",
159
+ message: `🔴 订单 ${ctx.order_id} 商家已失联 ${days} 天,资金可能冻结。建议立即发起仲裁。`,
160
+ next_step: "切换到 arbitration_support 阶段,提交仲裁申请",
161
+ tool: "mark_arbitration",
162
+ });
163
+ }
164
+ else {
165
+ actions.push({
166
+ id: "unreachable_no_arb",
167
+ phase: "merchant_unreachable",
168
+ priority: "required",
169
+ title: "无仲裁通道,资金可能冻结,建议联系 WoWok 官方",
170
+ message: `🔴 订单 ${ctx.order_id} 商家已失联 ${days} 天,且未配置仲裁通道,资金可能长期冻结。建议联系 WoWok 官方协助处理。`,
171
+ next_step: "联系 WoWok 官方支持并提供订单与沟通记录",
172
+ });
173
+ }
174
+ return actions;
175
+ }
176
+ if (days > 3) {
177
+ actions.push({
178
+ id: "unreachable_urge",
179
+ phase: "merchant_unreachable",
180
+ priority: "recommended",
181
+ title: "持续无响应,发送催促消息",
182
+ message: `⚠️ 订单 ${ctx.order_id} 商家已 ${days} 天未回复,建议通过 Messenger 发送催促消息并保留记录`,
183
+ next_step: "若 3 天内仍无回复,发起仲裁",
184
+ tool: "messenger_send",
185
+ });
186
+ return actions;
187
+ }
188
+ actions.push({
189
+ id: "unreachable_wait",
190
+ phase: "merchant_unreachable",
191
+ priority: "info",
192
+ title: "商家可能忙碌,等待回复",
193
+ message: `ℹ️ 订单 ${ctx.order_id} 商家 ${days === Infinity ? "尚未回复" : `已 ${days} 天未回复`},可能正在忙碌。建议再等待 1-2 天`,
194
+ next_step: "若 3 天后仍无回复,发送催促消息",
195
+ });
196
+ return actions;
197
+ }
198
+ export function arbitrationSupport(ctx) {
199
+ const actions = [];
200
+ const initiated = ctx.arbitration_initiated === true;
201
+ const evidenceCount = ctx.evidence?.length ?? 0;
202
+ const arbWindowDays = ctx.arb_window_days ?? 0;
203
+ if (!initiated) {
204
+ actions.push({
205
+ id: "arb_not_initiated",
206
+ phase: "arbitration_support",
207
+ priority: "required",
208
+ title: "建议发起仲裁申请",
209
+ message: `🔔 订单 ${ctx.order_id} 尚未发起仲裁。建议立即生成仲裁申请模板并提交。`,
210
+ next_step: "调用 generateArbitrationTemplate 生成申请模板",
211
+ tool: "mark_arbitration",
212
+ });
213
+ if (arbWindowDays > 0 && arbWindowDays <= 7) {
214
+ actions.push({
215
+ id: "arb_window_closing_soon",
216
+ phase: "arbitration_support",
217
+ priority: "required",
218
+ title: `仲裁窗口将在 ${arbWindowDays} 天后关闭`,
219
+ message: `⏰ 订单 ${ctx.order_id} 的仲裁申请窗口仅剩 ${arbWindowDays} 天,请尽快提交仲裁申请`,
220
+ next_step: "立即提交仲裁申请",
221
+ deadline: ctx.now + arbWindowDays * 24 * 60 * 60 * 1000,
222
+ });
223
+ }
224
+ return actions;
225
+ }
226
+ if (arbWindowDays > 0 && arbWindowDays <= 3) {
227
+ actions.push({
228
+ id: "arb_window_urgent",
229
+ phase: "arbitration_support",
230
+ priority: "required",
231
+ title: "仲裁窗口即将关闭",
232
+ message: `⏰ 订单 ${ctx.order_id} 的仲裁窗口仅剩 ${arbWindowDays} 天,请尽快补充证据并跟进投票进度`,
233
+ next_step: "立即补充证据并查询仲裁进度",
234
+ tool: "query_toolkit",
235
+ deadline: ctx.now + arbWindowDays * 24 * 60 * 60 * 1000,
236
+ });
237
+ }
238
+ if (evidenceCount === 0) {
239
+ actions.push({
240
+ id: "arb_no_evidence",
241
+ phase: "arbitration_support",
242
+ priority: "required",
243
+ title: "补充证据",
244
+ message: `📋 订单 ${ctx.order_id} 已发起仲裁但无证据记录。建议立即收集:\n` +
245
+ ` • Messenger 聊天记录\n` +
246
+ ` • WIP hash 对比记录\n` +
247
+ ` • Progress 停滞截图`,
248
+ next_step: "通过 messenger_mark_evidence 生成证据文件并提交",
249
+ tool: "messenger_mark_evidence",
250
+ });
251
+ }
252
+ else if (evidenceCount < 3) {
253
+ actions.push({
254
+ id: "arb_supplement_evidence",
255
+ phase: "arbitration_support",
256
+ priority: "recommended",
257
+ title: `补充更多证据以增强仲裁胜算(当前 ${evidenceCount} 项)`,
258
+ message: `⚠️ 订单 ${ctx.order_id} 已提交 ${evidenceCount} 项证据,建议补充至 3 项以上。\n` +
259
+ ` 当前证据:${ctx.evidence?.join(" / ") ?? "无"}`,
260
+ next_step: "补充第三方鉴定、聊天记录或交付物截图",
261
+ tool: "messenger_mark_evidence",
262
+ });
263
+ }
264
+ if (evidenceCount >= 3 && (arbWindowDays === 0 || arbWindowDays > 3)) {
265
+ actions.push({
266
+ id: "arb_monitor_progress",
267
+ phase: "arbitration_support",
268
+ priority: "info",
269
+ title: "仲裁进行中,持续监控投票进度",
270
+ message: `📊 订单 ${ctx.order_id} 仲裁已发起,证据 ${evidenceCount} 项齐全。建议定期查询投票进度并准备补充证据。`,
271
+ next_step: "通过 query_toolkit 查询仲裁投票状态",
272
+ tool: "query_toolkit",
273
+ });
274
+ }
275
+ return actions;
276
+ }
277
+ export function generateArbitrationTemplate(ctx) {
278
+ const phaseLabel = phaseToLabel(ctx.phase);
279
+ const evidenceCount = ctx.evidence?.length ?? 0;
280
+ const title = `订单 ${ctx.order_id} 仲裁申请 — ${phaseLabel}`;
281
+ const descriptionParts = [];
282
+ descriptionParts.push(`订单 ID:${ctx.order_id}`);
283
+ descriptionParts.push(`Service ID:${ctx.service_id}`);
284
+ descriptionParts.push(`纠纷类型:${phaseLabel}`);
285
+ switch (ctx.phase) {
286
+ case "refund_tracking":
287
+ descriptionParts.push(`纠纷概述:商家未按要求退款。订单金额 ${ctx.order_amount ?? "未知"} 最小单位,已退款 ${ctx.refunded_amount ?? 0n} 最小单位。`);
288
+ break;
289
+ case "quality_issue":
290
+ descriptionParts.push(`纠纷概述:交付物质量存在问题。WIP hash 原始:${ctx.original_wip_hash ?? "未知"},当前:${ctx.wip_hash ?? "未知"}。`);
291
+ break;
292
+ case "merchant_unreachable":
293
+ descriptionParts.push(`纠纷概述:商家长期失联。最后回复时间:${ctx.last_merchant_reply_at ? new Date(ctx.last_merchant_reply_at).toISOString() : "未知"}。`);
294
+ break;
295
+ case "arbitration_support":
296
+ descriptionParts.push("纠纷概述:详见上述阶段记录。");
297
+ break;
298
+ }
299
+ descriptionParts.push(`已收集证据:${evidenceCount} 项`);
300
+ const description = descriptionParts.join("\n");
301
+ const evidence_required = [
302
+ "Messenger 沟通记录(导出 WTS 证据文件)",
303
+ "订单创建与支付凭证",
304
+ "Progress 节点推进记录",
305
+ ];
306
+ switch (ctx.phase) {
307
+ case "quality_issue":
308
+ evidence_required.push("WIP hash 对比记录(原始 vs 当前)");
309
+ evidence_required.push("交付物截图或样品");
310
+ break;
311
+ case "merchant_unreachable":
312
+ evidence_required.push("失联时长记录(基于 last_merchant_reply_at)");
313
+ evidence_required.push("催促消息发送记录");
314
+ break;
315
+ case "refund_tracking":
316
+ evidence_required.push("退款申请记录");
317
+ evidence_required.push("退款差额计算凭证");
318
+ break;
319
+ }
320
+ const claim = buildClaim(ctx);
321
+ return { title, description, evidence_required, claim };
322
+ }
323
+ function phaseToLabel(phase) {
324
+ switch (phase) {
325
+ case "refund_tracking": return "退款纠纷";
326
+ case "quality_issue": return "质量问题";
327
+ case "merchant_unreachable": return "商家失联";
328
+ case "arbitration_support": return "仲裁支持";
329
+ }
330
+ }
331
+ function buildClaim(ctx) {
332
+ switch (ctx.phase) {
333
+ case "refund_tracking": {
334
+ const orderAmount = ctx.order_amount ?? 0n;
335
+ const refunded = ctx.refunded_amount ?? 0n;
336
+ const diff = orderAmount - refunded;
337
+ if (refunded === 0n) {
338
+ return `请求仲裁商家全额退款(${orderAmount} 最小单位)。`;
339
+ }
340
+ return `请求仲裁商家补足退款差额(${diff} 最小单位)。`;
341
+ }
342
+ case "quality_issue":
343
+ return "请求仲裁商家重新交付符合约定的交付物,或全额退款。";
344
+ case "merchant_unreachable":
345
+ return "请求仲裁商家履行订单义务或退还全部款项,并赔偿因失联造成的损失。";
346
+ case "arbitration_support":
347
+ return "请求仲裁支持本方诉求,依据所附证据判定商家违约并赔偿。";
348
+ }
349
+ }
350
+ export { CUSTOMER_INTELLIGENCE_VERSION };
@@ -0,0 +1,42 @@
1
+ import type { Reminder, RiskLevel } from "./types.js";
2
+ import { CUSTOMER_INTELLIGENCE_VERSION } from "./types.js";
3
+ export type ReminderStage = "browse" | "evaluate" | "preorder" | "in_progress" | "complete" | "after_sale";
4
+ export interface ReminderContext {
5
+ stage: ReminderStage;
6
+ service_id?: string;
7
+ order_id?: string;
8
+ review_count?: number;
9
+ like_rate?: number;
10
+ avg_market_price?: bigint;
11
+ service_price?: bigint;
12
+ has_arbitration?: boolean;
13
+ has_compensation?: boolean;
14
+ compensation_balance?: bigint;
15
+ compensation_ratio?: number;
16
+ risk_score?: number;
17
+ risk_level?: RiskLevel;
18
+ has_refund_path?: boolean;
19
+ has_user_operable?: boolean;
20
+ has_messenger?: boolean;
21
+ ambiguous_guards?: string[];
22
+ current_node?: string;
23
+ expected_progress_hours?: number;
24
+ hours_since_last_progress?: number;
25
+ hours_since_messenger_reply?: number;
26
+ completed_at?: number;
27
+ review_window_days?: number;
28
+ arb_window_days?: number;
29
+ user_min_trust_score?: number;
30
+ user_require_arbitration?: boolean;
31
+ user_require_compensation?: boolean;
32
+ }
33
+ export declare function generateReminders(ctx: ReminderContext): Reminder[];
34
+ export declare function sortAndCapReminders(reminders: Reminder[]): Reminder[];
35
+ export declare function generateMultiStageReminders(ctx: Partial<ReminderContext> & {
36
+ stage: ReminderStage;
37
+ }, additionalStages?: ReminderStage[]): Reminder[];
38
+ export declare function isBlocking(reminder: Reminder): boolean;
39
+ export declare function getBlockingReminders(reminders: Reminder[]): Reminder[];
40
+ export declare function summarizeReminders(reminders: Reminder[]): string;
41
+ export declare function topReminders(reminders: Reminder[], n?: number): Reminder[];
42
+ export { CUSTOMER_INTELLIGENCE_VERSION };
@@ -0,0 +1,295 @@
1
+ import { CUSTOMER_INTELLIGENCE_VERSION } from "./types.js";
2
+ const REMINDER_RULES = [
3
+ {
4
+ id: "browse_reviews_summary",
5
+ stage: "browse",
6
+ priority: "info",
7
+ message: (ctx) => `This Service has ${ctx.review_count} reviews, like rate ${Math.round((ctx.like_rate ?? 0) * 100)}%`,
8
+ applies: (ctx) => (ctx.review_count ?? 0) > 0,
9
+ dedup_key: "reviews_summary",
10
+ },
11
+ {
12
+ id: "browse_price_anomaly_low",
13
+ stage: "browse",
14
+ priority: "recommended",
15
+ message: (ctx) => {
16
+ if (!ctx.avg_market_price || !ctx.service_price || ctx.avg_market_price === 0n) {
17
+ return "⚠️ 价格异常低,请警惕质量风险";
18
+ }
19
+ const ratio = Number(ctx.service_price * 100n / ctx.avg_market_price) / 100;
20
+ const below = Math.round((1 - ratio) * 100);
21
+ return `⚠️ 价格低于同类均价 ${below}%,请警惕质量风险`;
22
+ },
23
+ applies: (ctx) => {
24
+ if (!ctx.avg_market_price || !ctx.service_price)
25
+ return false;
26
+ if (ctx.avg_market_price === 0n)
27
+ return false;
28
+ const ratio = Number(ctx.service_price * 100n / ctx.avg_market_price) / 100;
29
+ return ratio < 0.6;
30
+ },
31
+ dedup_key: "price_anomaly",
32
+ },
33
+ {
34
+ id: "browse_no_arbitration",
35
+ stage: "browse",
36
+ priority: "recommended",
37
+ message: "⚠️ 该 Service 未配置仲裁,纠纷无解决通道",
38
+ applies: (ctx) => ctx.has_arbitration === false,
39
+ dedup_key: "no_arbitration",
40
+ },
41
+ {
42
+ id: "browse_no_compensation",
43
+ stage: "browse",
44
+ priority: "recommended",
45
+ message: "⚠️ 该 Service 无赔偿金,订单失败时无自动赔付来源",
46
+ applies: (ctx) => ctx.has_compensation === false,
47
+ dedup_key: "no_compensation",
48
+ },
49
+ {
50
+ id: "evaluate_checklist",
51
+ stage: "evaluate",
52
+ priority: "info",
53
+ message: "📋 Running 4-dimension risk check (workflow/fund/trust/behavior)...",
54
+ applies: () => true,
55
+ dedup_key: "checklist_start",
56
+ },
57
+ {
58
+ id: "evaluate_high_risk",
59
+ stage: "evaluate",
60
+ priority: "required",
61
+ message: (ctx) => `🔴 Composite risk score ${ctx.risk_score}/100, strongly recommend not purchasing`,
62
+ applies: (ctx) => (ctx.risk_level ?? "low") === "high",
63
+ dedup_key: "high_risk_score",
64
+ },
65
+ {
66
+ id: "evaluate_medium_high_risk",
67
+ stage: "evaluate",
68
+ priority: "recommended",
69
+ message: (ctx) => `🟠 综合风险分 ${ctx.risk_score}/100,谨慎购买,需重点关注 2-3 项风险`,
70
+ applies: (ctx) => (ctx.risk_level ?? "low") === "medium_high",
71
+ dedup_key: "medium_high_risk",
72
+ },
73
+ {
74
+ id: "evaluate_ambiguous_guard",
75
+ stage: "evaluate",
76
+ priority: "required",
77
+ message: (ctx) => `🔴 检测到 ${ctx.ambiguous_guards?.length ?? 0} 个模糊 Guard,必须人工审查后才能继续:${ctx.ambiguous_guards?.join(", ") ?? ""}`,
78
+ applies: (ctx) => (ctx.ambiguous_guards?.length ?? 0) > 0,
79
+ dedup_key: "ambiguous_guard",
80
+ },
81
+ {
82
+ id: "evaluate_no_refund_path",
83
+ stage: "evaluate",
84
+ priority: "recommended",
85
+ message: "⚠️ 无退款路径:若交付失败,资金可能无法回收。建议 Messenger 协商退款条款",
86
+ applies: (ctx) => ctx.has_refund_path === false,
87
+ dedup_key: "no_refund_path",
88
+ },
89
+ {
90
+ id: "evaluate_no_user_operable",
91
+ stage: "evaluate",
92
+ priority: "required",
93
+ message: "🔴 流程中无任何用户可操作步骤:订单进度完全依赖商家",
94
+ applies: (ctx) => ctx.has_user_operable === false,
95
+ dedup_key: "no_user_operable",
96
+ },
97
+ {
98
+ id: "evaluate_below_min_trust",
99
+ stage: "evaluate",
100
+ priority: "required",
101
+ message: (ctx) => `🔴 Risk score ${ctx.risk_score} is below your minimum requirement of ${ctx.user_min_trust_score}`,
102
+ applies: (ctx) => ctx.user_min_trust_score !== undefined &&
103
+ ctx.risk_score !== undefined &&
104
+ ctx.risk_score < ctx.user_min_trust_score,
105
+ dedup_key: "below_min_trust",
106
+ },
107
+ {
108
+ id: "preorder_payment_confirm",
109
+ stage: "preorder",
110
+ priority: "required",
111
+ message: (ctx) => `🔔 即将支付 ${ctx.service_price} 最小单位到托管账户,请确认`,
112
+ applies: (ctx) => ctx.service_price !== undefined,
113
+ dedup_key: "payment_confirm",
114
+ },
115
+ {
116
+ id: "preorder_compensation_insufficient",
117
+ stage: "preorder",
118
+ priority: "recommended",
119
+ message: (ctx) => `⚠️ Compensation balance only covers ${Math.round((ctx.compensation_ratio ?? 0) * 100)}% of the order amount`,
120
+ applies: (ctx) => (ctx.compensation_ratio ?? 1) < 1,
121
+ dedup_key: "compensation_insufficient",
122
+ },
123
+ {
124
+ id: "preorder_user_require_arb_missing",
125
+ stage: "preorder",
126
+ priority: "required",
127
+ message: "🔴 您的偏好要求必备仲裁,但该 Service 未配置",
128
+ applies: (ctx) => ctx.user_require_arbitration === true && ctx.has_arbitration === false,
129
+ dedup_key: "user_require_arb_missing",
130
+ },
131
+ {
132
+ id: "preorder_user_require_comp_missing",
133
+ stage: "preorder",
134
+ priority: "required",
135
+ message: "🔴 您的偏好要求必备赔偿金,但该 Service 无",
136
+ applies: (ctx) => ctx.user_require_compensation === true && ctx.has_compensation === false,
137
+ dedup_key: "user_require_comp_missing",
138
+ },
139
+ {
140
+ id: "preorder_no_messenger",
141
+ stage: "preorder",
142
+ priority: "recommended",
143
+ message: "⚠️ 商家无 Messenger 通道,下单后无法协商或售后",
144
+ applies: (ctx) => ctx.has_messenger === false,
145
+ dedup_key: "no_messenger",
146
+ },
147
+ {
148
+ id: "in_progress_progress_stalled",
149
+ stage: "in_progress",
150
+ priority: "recommended",
151
+ message: (ctx) => `⚠️ 订单已停留在节点 ${ctx.current_node} 超过 ${ctx.hours_since_last_progress} 小时,建议联系商家`,
152
+ applies: (ctx) => {
153
+ const stallHours = ctx.hours_since_last_progress ?? 0;
154
+ const expected = ctx.expected_progress_hours ?? 24;
155
+ return stallHours > expected * 2;
156
+ },
157
+ dedup_key: "progress_stalled",
158
+ },
159
+ {
160
+ id: "in_progress_compensation_drop",
161
+ stage: "in_progress",
162
+ priority: "recommended",
163
+ message: "⚠️ 商家赔偿金余额下降 30%,请注意",
164
+ applies: () => false,
165
+ dedup_key: "compensation_drop",
166
+ },
167
+ {
168
+ id: "in_progress_user_action_required",
169
+ stage: "in_progress",
170
+ priority: "reminder",
171
+ message: (ctx) => `🔔 订单推进到节点 ${ctx.current_node},需要您操作`,
172
+ applies: (ctx) => ctx.current_node !== undefined && ctx.current_node !== "",
173
+ dedup_key: "user_action_required",
174
+ },
175
+ {
176
+ id: "in_progress_messenger_unanswered",
177
+ stage: "in_progress",
178
+ priority: "recommended",
179
+ message: (ctx) => `⚠️ 商家已 ${ctx.hours_since_messenger_reply} 小时未回复 Messenger,可考虑发起仲裁`,
180
+ applies: (ctx) => (ctx.hours_since_messenger_reply ?? 0) > 24,
181
+ dedup_key: "messenger_unanswered",
182
+ },
183
+ {
184
+ id: "complete_review_reminder",
185
+ stage: "complete",
186
+ priority: "info",
187
+ message: "💡 订单已完成,是否要提交评价?",
188
+ applies: () => true,
189
+ dedup_key: "review_reminder",
190
+ },
191
+ {
192
+ id: "complete_review_window",
193
+ stage: "complete",
194
+ priority: "reminder",
195
+ message: (ctx) => `⏰ 评价窗口将在 ${ctx.review_window_days} 天后关闭`,
196
+ applies: (ctx) => (ctx.review_window_days ?? 0) > 0,
197
+ dedup_key: "review_window",
198
+ },
199
+ {
200
+ id: "after_sale_arb_window",
201
+ stage: "after_sale",
202
+ priority: "reminder",
203
+ message: (ctx) => `⏰ 仲裁申请窗口将在 ${ctx.arb_window_days} 天后关闭`,
204
+ applies: (ctx) => (ctx.arb_window_days ?? 0) > 0,
205
+ dedup_key: "arb_window",
206
+ },
207
+ {
208
+ id: "after_sale_refund_received",
209
+ stage: "after_sale",
210
+ priority: "info",
211
+ message: "✅ 退款已到账",
212
+ applies: () => false,
213
+ dedup_key: "refund_received",
214
+ },
215
+ ];
216
+ export function generateReminders(ctx) {
217
+ const stageRules = REMINDER_RULES.filter((r) => r.stage === ctx.stage);
218
+ const byKey = new Map();
219
+ for (const rule of stageRules) {
220
+ if (!rule.applies(ctx))
221
+ continue;
222
+ const existing = byKey.get(rule.dedup_key);
223
+ if (!existing || priorityRank(rule.priority) > priorityRank(existing.priority)) {
224
+ byKey.set(rule.dedup_key, rule);
225
+ }
226
+ }
227
+ const reminders = Array.from(byKey.values()).map((rule) => ({
228
+ id: rule.id,
229
+ stage: rule.stage,
230
+ priority: rule.priority,
231
+ message: typeof rule.message === "function" ? rule.message(ctx) : rule.message,
232
+ action: rule.action,
233
+ }));
234
+ return sortAndCapReminders(reminders);
235
+ }
236
+ export function sortAndCapReminders(reminders) {
237
+ const sorted = [...reminders].sort((a, b) => priorityRank(b.priority) - priorityRank(a.priority));
238
+ const highRisk = sorted.filter((r) => r.priority === "required" || r.priority === "recommended");
239
+ const others = sorted.filter((r) => r.priority === "info" || r.priority === "reminder");
240
+ const cappedHighRisk = highRisk.slice(0, 3);
241
+ return [...cappedHighRisk, ...others];
242
+ }
243
+ function priorityRank(p) {
244
+ switch (p) {
245
+ case "required": return 4;
246
+ case "recommended": return 3;
247
+ case "info": return 2;
248
+ case "reminder": return 1;
249
+ }
250
+ }
251
+ export function generateMultiStageReminders(ctx, additionalStages = []) {
252
+ const stages = [ctx.stage, ...additionalStages];
253
+ const all = [];
254
+ const seenKeys = new Set();
255
+ for (const stage of stages) {
256
+ const stageCtx = { ...ctx, stage };
257
+ const stageReminders = generateReminders(stageCtx);
258
+ for (const r of stageReminders) {
259
+ const key = `${stage}:${r.id}`;
260
+ if (!seenKeys.has(key)) {
261
+ seenKeys.add(key);
262
+ all.push(r);
263
+ }
264
+ }
265
+ }
266
+ return all;
267
+ }
268
+ export function isBlocking(reminder) {
269
+ return reminder.priority === "required";
270
+ }
271
+ export function getBlockingReminders(reminders) {
272
+ return reminders.filter(isBlocking);
273
+ }
274
+ export function summarizeReminders(reminders) {
275
+ if (reminders.length === 0)
276
+ return "无提醒";
277
+ const required = reminders.filter((r) => r.priority === "required");
278
+ const recommended = reminders.filter((r) => r.priority === "recommended");
279
+ const info = reminders.filter((r) => r.priority === "info");
280
+ const reminderOnly = reminders.filter((r) => r.priority === "reminder");
281
+ const parts = [];
282
+ if (required.length)
283
+ parts.push(`🔴 必读 ${required.length} 条`);
284
+ if (recommended.length)
285
+ parts.push(`⚠️ 建议 ${recommended.length} 条`);
286
+ if (info.length)
287
+ parts.push(`💡 提示 ${info.length} 条`);
288
+ if (reminderOnly.length)
289
+ parts.push(`🔔 提醒 ${reminderOnly.length} 条`);
290
+ return parts.join(",");
291
+ }
292
+ export function topReminders(reminders, n = 5) {
293
+ return sortAndCapReminders(reminders).slice(0, n);
294
+ }
295
+ export { CUSTOMER_INTELLIGENCE_VERSION };