@wowok/agent-mcp 2.3.13 → 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 (194) 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/harness/checkpoint.d.ts +8 -0
  36. package/dist/harness/checkpoint.js +129 -0
  37. package/dist/harness/index.d.ts +33 -0
  38. package/dist/harness/index.js +75 -0
  39. package/dist/harness/plan.d.ts +18 -0
  40. package/dist/harness/plan.js +252 -0
  41. package/dist/harness/recover.d.ts +17 -0
  42. package/dist/harness/recover.js +139 -0
  43. package/dist/harness/types.d.ts +137 -0
  44. package/dist/harness/types.js +1 -0
  45. package/dist/harness/verify.d.ts +42 -0
  46. package/dist/harness/verify.js +237 -0
  47. package/dist/index.js +667 -201
  48. package/dist/knowledge/acquisition-flywheel.d.ts +50 -0
  49. package/dist/knowledge/acquisition-flywheel.js +183 -0
  50. package/dist/knowledge/arbitration-trust.d.ts +24 -0
  51. package/dist/knowledge/arbitration-trust.js +117 -0
  52. package/dist/knowledge/audit-rules.d.ts +28 -0
  53. package/dist/knowledge/audit-rules.js +141 -0
  54. package/dist/knowledge/demand-matching.d.ts +29 -0
  55. package/dist/knowledge/demand-matching.js +132 -0
  56. package/dist/knowledge/dynamic-pricing.d.ts +31 -0
  57. package/dist/knowledge/dynamic-pricing.js +87 -0
  58. package/dist/knowledge/flywheel-loop.d.ts +87 -0
  59. package/dist/knowledge/flywheel-loop.js +378 -0
  60. package/dist/knowledge/glossary.d.ts +18 -0
  61. package/dist/knowledge/glossary.js +209 -0
  62. package/dist/knowledge/index.d.ts +64 -0
  63. package/dist/knowledge/index.js +66 -0
  64. package/dist/knowledge/industry-evolution.d.ts +82 -0
  65. package/dist/knowledge/industry-evolution.js +323 -0
  66. package/dist/knowledge/industry-generalizer.d.ts +17 -0
  67. package/dist/knowledge/industry-generalizer.js +381 -0
  68. package/dist/knowledge/industry-registry.d.ts +49 -0
  69. package/dist/knowledge/industry-registry.js +167 -0
  70. package/dist/knowledge/intent-metrics.d.ts +42 -0
  71. package/dist/knowledge/intent-metrics.js +566 -0
  72. package/dist/knowledge/process-model.d.ts +24 -0
  73. package/dist/knowledge/process-model.js +160 -0
  74. package/dist/knowledge/reputation-rules.d.ts +42 -0
  75. package/dist/knowledge/reputation-rules.js +99 -0
  76. package/dist/knowledge/reward-templates.d.ts +25 -0
  77. package/dist/knowledge/reward-templates.js +125 -0
  78. package/dist/knowledge/safety-rules.d.ts +36 -0
  79. package/dist/knowledge/safety-rules.js +171 -0
  80. package/dist/knowledge/tool-constraints.d.ts +30 -0
  81. package/dist/knowledge/tool-constraints.js +185 -0
  82. package/dist/knowledge/trust-metrics.d.ts +37 -0
  83. package/dist/knowledge/trust-metrics.js +138 -0
  84. package/dist/loop-engineering/aggregate.d.ts +50 -0
  85. package/dist/loop-engineering/aggregate.js +132 -0
  86. package/dist/loop-engineering/diagnose.d.ts +22 -0
  87. package/dist/loop-engineering/diagnose.js +273 -0
  88. package/dist/loop-engineering/improve.d.ts +26 -0
  89. package/dist/loop-engineering/improve.js +229 -0
  90. package/dist/loop-engineering/index.d.ts +4 -0
  91. package/dist/loop-engineering/index.js +4 -0
  92. package/dist/loop-engineering/pipeline.d.ts +17 -0
  93. package/dist/loop-engineering/pipeline.js +56 -0
  94. package/dist/mode-market/index.d.ts +3 -0
  95. package/dist/mode-market/index.js +3 -0
  96. package/dist/mode-market/registry.d.ts +53 -0
  97. package/dist/mode-market/registry.js +124 -0
  98. package/dist/mode-market/review.d.ts +27 -0
  99. package/dist/mode-market/review.js +214 -0
  100. package/dist/mode-market/submission.d.ts +25 -0
  101. package/dist/mode-market/submission.js +85 -0
  102. package/dist/project/graph.d.ts +71 -0
  103. package/dist/project/graph.js +314 -0
  104. package/dist/project/index.d.ts +62 -0
  105. package/dist/project/index.js +167 -0
  106. package/dist/project/namespace.d.ts +62 -0
  107. package/dist/project/namespace.js +181 -0
  108. package/dist/project/query.d.ts +40 -0
  109. package/dist/project/query.js +110 -0
  110. package/dist/safety/confirm-gate.d.ts +15 -0
  111. package/dist/safety/confirm-gate.js +44 -0
  112. package/dist/safety/index.d.ts +3 -0
  113. package/dist/safety/index.js +3 -0
  114. package/dist/safety/preview.d.ts +2 -0
  115. package/dist/safety/preview.js +36 -0
  116. package/dist/schema/call/allocation.d.ts +55 -40
  117. package/dist/schema/call/arbitration.d.ts +201 -186
  118. package/dist/schema/call/base.d.ts +2104 -24
  119. package/dist/schema/call/base.js +168 -22
  120. package/dist/schema/call/bridge-handler.js +36 -18
  121. package/dist/schema/call/bridge.d.ts +777 -120
  122. package/dist/schema/call/bridge.js +13 -2
  123. package/dist/schema/call/contact.d.ts +15 -0
  124. package/dist/schema/call/demand.d.ts +69 -54
  125. package/dist/schema/call/guard.d.ts +125 -80
  126. package/dist/schema/call/handler.d.ts +5 -1
  127. package/dist/schema/call/handler.js +108 -3
  128. package/dist/schema/call/index.d.ts +1 -0
  129. package/dist/schema/call/index.js +1 -0
  130. package/dist/schema/call/machine.d.ts +830 -800
  131. package/dist/schema/call/order.d.ts +27 -12
  132. package/dist/schema/call/payment.d.ts +15 -0
  133. package/dist/schema/call/permission.d.ts +15 -0
  134. package/dist/schema/call/personal.d.ts +15 -0
  135. package/dist/schema/call/progress.d.ts +21 -6
  136. package/dist/schema/call/proof.d.ts +42 -12
  137. package/dist/schema/call/proof.js +3 -3
  138. package/dist/schema/call/repository.d.ts +91 -76
  139. package/dist/schema/call/reward.d.ts +51 -36
  140. package/dist/schema/call/semantic.d.ts +24 -0
  141. package/dist/schema/call/semantic.js +981 -0
  142. package/dist/schema/call/service.d.ts +444 -429
  143. package/dist/schema/call/treasury.d.ts +219 -204
  144. package/dist/schema/common/index.js +3 -3
  145. package/dist/schema/local/index.d.ts +341 -74
  146. package/dist/schema/local/index.js +44 -7
  147. package/dist/schema/messenger/index.d.ts +1034 -92
  148. package/dist/schema/messenger/index.js +18 -0
  149. package/dist/schema/operations.d.ts +2634 -1817
  150. package/dist/schema/operations.js +16 -5
  151. package/dist/schema/query/index.d.ts +2293 -2289
  152. package/dist/schema/query/index.js +34 -28
  153. package/dist/schemas/account_operation.output.json +28 -16
  154. package/dist/schemas/account_operation.schema.json +2 -2
  155. package/dist/schemas/bridge_operation.output.json +520 -0
  156. package/dist/schemas/bridge_operation.schema.json +15 -0
  157. package/dist/schemas/guard2file.schema.json +15 -0
  158. package/dist/schemas/index.json +1 -1
  159. package/dist/schemas/local_info_operation.output.json +26 -0
  160. package/dist/schemas/local_info_operation.schema.json +1 -1
  161. package/dist/schemas/local_mark_operation.output.json +27 -1
  162. package/dist/schemas/local_mark_operation.schema.json +4 -4
  163. package/dist/schemas/machineNode2file.schema.json +15 -0
  164. package/dist/schemas/messenger_operation.output.json +549 -0
  165. package/dist/schemas/messenger_operation.schema.json +21 -0
  166. package/dist/schemas/onchain_events.output.json +3 -0
  167. package/dist/schemas/onchain_operations.output.json +814 -37
  168. package/dist/schemas/onchain_operations.schema.json +117 -40
  169. package/dist/schemas/onchain_operations_allocation.schema.json +26 -9
  170. package/dist/schemas/onchain_operations_arbitration.schema.json +26 -9
  171. package/dist/schemas/onchain_operations_contact.schema.json +26 -9
  172. package/dist/schemas/onchain_operations_demand.schema.json +26 -9
  173. package/dist/schemas/onchain_operations_gen_passport.schema.json +51 -17
  174. package/dist/schemas/onchain_operations_guard.schema.json +26 -9
  175. package/dist/schemas/onchain_operations_machine.schema.json +92 -32
  176. package/dist/schemas/onchain_operations_order.schema.json +26 -9
  177. package/dist/schemas/onchain_operations_payment.schema.json +26 -9
  178. package/dist/schemas/onchain_operations_permission.schema.json +26 -9
  179. package/dist/schemas/onchain_operations_personal.schema.json +26 -9
  180. package/dist/schemas/onchain_operations_progress.schema.json +26 -9
  181. package/dist/schemas/onchain_operations_repository.schema.json +26 -9
  182. package/dist/schemas/onchain_operations_reward.schema.json +26 -9
  183. package/dist/schemas/onchain_operations_service.schema.json +26 -9
  184. package/dist/schemas/onchain_operations_treasury.schema.json +26 -9
  185. package/dist/schemas/onchain_table_data.output.json +224 -69
  186. package/dist/schemas/onchain_table_data.schema.json +2 -2
  187. package/dist/schemas/query_toolkit.schema.json +5 -1
  188. package/dist/telemetry/index.d.ts +19 -0
  189. package/dist/telemetry/index.js +112 -0
  190. package/dist/telemetry/redact.d.ts +2 -0
  191. package/dist/telemetry/redact.js +23 -0
  192. package/dist/telemetry/storage.d.ts +8 -0
  193. package/dist/telemetry/storage.js +80 -0
  194. package/package.json +6 -3
@@ -0,0 +1,50 @@
1
+ export interface FlywheelAction {
2
+ action: string;
3
+ purpose: string;
4
+ mutableField: string;
5
+ metricToWatch: string;
6
+ }
7
+ export interface AcquisitionFlywheel {
8
+ industry: string;
9
+ trustSellingPoints: string[];
10
+ keyActions: FlywheelAction[];
11
+ rewardStrategy: string;
12
+ discountStrategy: string;
13
+ trustDescription: string;
14
+ }
15
+ export interface TrustDescriptionParams {
16
+ industry?: string;
17
+ orderCount?: number;
18
+ completedRate?: number;
19
+ avgCompletionTime?: number;
20
+ hasCompensationFund?: boolean;
21
+ hasArbitration?: boolean;
22
+ reviewLikeRate?: number;
23
+ reviewCount?: number;
24
+ }
25
+ export declare const ACQUISITION_FLYWHEEL_VERSION = 1;
26
+ export declare const INDUSTRY_FLYWHEELS: AcquisitionFlywheel[];
27
+ export declare function getFlywheelForIndustry(industry: string): AcquisitionFlywheel | undefined;
28
+ export declare function listIndustries(): string[];
29
+ export declare function suggestAcquisitionActions(industry: string): FlywheelAction[];
30
+ export declare function generateTrustDescription(params: TrustDescriptionParams): string;
31
+ export interface AcquisitionDashboard {
32
+ metrics: {
33
+ orderCount: number;
34
+ completedRate: number;
35
+ avgCompletionTime?: number;
36
+ repeatCustomerRate?: number;
37
+ reviewLikeRate?: number;
38
+ reviewCount?: number;
39
+ };
40
+ suggestions: string[];
41
+ flywheelStage: "cold_start" | "growing" | "mature" | "optimization";
42
+ }
43
+ export declare function buildAcquisitionDashboard(params: {
44
+ orderCount: number;
45
+ completedRate?: number;
46
+ avgCompletionTime?: number;
47
+ repeatCustomerRate?: number;
48
+ reviewLikeRate?: number;
49
+ reviewCount?: number;
50
+ }): AcquisitionDashboard;
@@ -0,0 +1,183 @@
1
+ export const ACQUISITION_FLYWHEEL_VERSION = 1;
2
+ export const INDUSTRY_FLYWHEELS = [
3
+ {
4
+ industry: "freelance",
5
+ trustSellingPoints: [
6
+ "交付验收 + 资金托管 + 仲裁保障",
7
+ "流程透明:Machine 定义清晰的交付节点",
8
+ "compensation_fund 资金安全保障客户权益",
9
+ ],
10
+ keyActions: [
11
+ { action: "设置 Reward 首单奖励", purpose: "吸引新客户下单", mutableField: "rewards", metricToWatch: "新客下单率" },
12
+ { action: "累计金额阶梯 Reward", purpose: "激励复购", mutableField: "rewards", metricToWatch: "复购率" },
13
+ { action: "调整 Machine 节点", purpose: "优化交付流程速度", mutableField: "description", metricToWatch: "平均完成时间" },
14
+ { action: "增加 compensation_fund", purpose: "提升信任分", mutableField: "compensation_fund", metricToWatch: "信任分" },
15
+ ],
16
+ rewardStrategy: "首单奖励 + 累计金额阶梯(如满 5 单送折扣)",
17
+ discountStrategy: "包月折扣 + 长期合作优惠",
18
+ trustDescription: "资金托管 + 交付验收 + 仲裁保障",
19
+ },
20
+ {
21
+ industry: "rental",
22
+ trustSellingPoints: [
23
+ "押金托管 + 损伤 Guard + 退还流程",
24
+ "Guard 验证物品状况,防纠纷",
25
+ "compensation_fund 覆盖损坏风险",
26
+ ],
27
+ keyActions: [
28
+ { action: "设置 Discount 长租优惠", purpose: "激励长期租赁", mutableField: "discount", metricToWatch: "长租比例" },
29
+ { action: "信用累计 Reward", purpose: "多次租赁信用积累", mutableField: "rewards", metricToWatch: "复租率" },
30
+ { action: "配置损伤 Guard", purpose: "降低纠纷率", mutableField: "buy_guard", metricToWatch: "纠纷率" },
31
+ { action: "增加 compensation_fund", purpose: "覆盖损坏风险", mutableField: "compensation_fund", metricToWatch: "信任分" },
32
+ ],
33
+ rewardStrategy: "信用累计 + 长租折扣 + 推荐返现",
34
+ discountStrategy: "月租 9 折 + 季租 8 折 + 年租 7 折",
35
+ trustDescription: "押金托管 + Guard 验证 + 退还保障",
36
+ },
37
+ {
38
+ industry: "education",
39
+ trustSellingPoints: [
40
+ "课程进度透明 + 退款 Guard",
41
+ "Machine 定义学习阶段和验收节点",
42
+ ],
43
+ keyActions: [
44
+ { action: "设置里程碑 Reward", purpose: "激励完成课程", mutableField: "rewards", metricToWatch: "完课率" },
45
+ { action: "推荐返现 Reward", purpose: "裂变获客", mutableField: "rewards", metricToWatch: "推荐率" },
46
+ ],
47
+ rewardStrategy: "里程碑奖励 + 推荐返现 + 试听折扣",
48
+ discountStrategy: "早鸟价 + 团购价 + 助学折扣",
49
+ trustDescription: "进度透明 + 退款保障 + 验收节点",
50
+ },
51
+ {
52
+ industry: "travel",
53
+ trustSellingPoints: [
54
+ "行程托管 + 取消 Guard + 仲裁保障",
55
+ "Guard 验证行程变更条件",
56
+ ],
57
+ keyActions: [
58
+ { action: "限时闪购 Reward", purpose: "清仓促销", mutableField: "rewards", metricToWatch: "转化率" },
59
+ { action: "消费返现 Reward", purpose: "提升复购", mutableField: "rewards", metricToWatch: "复购率" },
60
+ ],
61
+ rewardStrategy: "限时闪购 + 消费返现 + 推荐返佣",
62
+ discountStrategy: "早鸟价 + 拼团价 + 会员价",
63
+ trustDescription: "行程托管 + 取消保障 + 仲裁",
64
+ },
65
+ {
66
+ industry: "subscription",
67
+ trustSellingPoints: [
68
+ "订阅透明 + 自动续费 Guard + 随时取消",
69
+ "Machine 定义计费周期和自动扣款",
70
+ ],
71
+ keyActions: [
72
+ { action: "忠诚度 Reward", purpose: "长期留存", mutableField: "rewards", metricToWatch: "续费率" },
73
+ { action: "推荐返现 Reward", purpose: "裂变获客", mutableField: "rewards", metricToWatch: "推荐率" },
74
+ ],
75
+ rewardStrategy: "忠诚度奖励 + 推荐返现 + 首月折扣",
76
+ discountStrategy: "年付折扣 + 团队折扣 + 升级折扣",
77
+ trustDescription: "订阅透明 + 续费保障 + 随时取消",
78
+ },
79
+ {
80
+ industry: "retail",
81
+ trustSellingPoints: [
82
+ "交易托管 + 物流 Guard + 退款保障",
83
+ "Guard 验证发货和收货",
84
+ ],
85
+ keyActions: [
86
+ { action: "首单折扣", purpose: "吸引新客", mutableField: "discount", metricToWatch: "新客下单率" },
87
+ { action: "消费返现 Reward", purpose: "提升复购", mutableField: "rewards", metricToWatch: "复购率" },
88
+ ],
89
+ rewardStrategy: "首单折扣 + 消费返现 + 满减",
90
+ discountStrategy: "满减 + 限时折扣 + 会员价",
91
+ trustDescription: "交易托管 + 物流 Guard + 退款保障",
92
+ },
93
+ ];
94
+ export function getFlywheelForIndustry(industry) {
95
+ return INDUSTRY_FLYWHEELS.find((f) => f.industry === industry.toLowerCase());
96
+ }
97
+ export function listIndustries() {
98
+ return INDUSTRY_FLYWHEELS.map((f) => f.industry);
99
+ }
100
+ export function suggestAcquisitionActions(industry) {
101
+ const flywheel = getFlywheelForIndustry(industry);
102
+ return flywheel?.keyActions ?? [];
103
+ }
104
+ export function generateTrustDescription(params) {
105
+ const parts = [];
106
+ if (params.industry) {
107
+ const flywheel = getFlywheelForIndustry(params.industry);
108
+ if (flywheel) {
109
+ parts.push(flywheel.trustDescription);
110
+ }
111
+ }
112
+ if (params.orderCount !== undefined && params.orderCount > 0) {
113
+ parts.push(`已完成 ${params.orderCount} 单`);
114
+ }
115
+ if (params.completedRate !== undefined) {
116
+ parts.push(`完成率 ${Math.round(params.completedRate * 100)}%`);
117
+ }
118
+ if (params.avgCompletionTime !== undefined) {
119
+ if (params.avgCompletionTime < 1) {
120
+ parts.push(`平均完成时间 ${Math.round(params.avgCompletionTime * 60)} 分钟`);
121
+ }
122
+ else {
123
+ parts.push(`平均完成时间 ${Math.round(params.avgCompletionTime)} 小时`);
124
+ }
125
+ }
126
+ if (params.hasCompensationFund) {
127
+ parts.push("赔偿金充足");
128
+ }
129
+ if (params.hasArbitration) {
130
+ parts.push("第三方仲裁保障");
131
+ }
132
+ if (params.reviewCount !== undefined && params.reviewCount > 0 && params.reviewLikeRate !== undefined) {
133
+ parts.push(`好评率 ${Math.round(params.reviewLikeRate * 100)}% (${params.reviewCount} 条评价)`);
134
+ }
135
+ return parts.join(";") || "暂无信任数据";
136
+ }
137
+ export function buildAcquisitionDashboard(params) {
138
+ const { orderCount, completedRate, avgCompletionTime, repeatCustomerRate, reviewLikeRate, reviewCount } = params;
139
+ let stage = "cold_start";
140
+ if (orderCount >= 50)
141
+ stage = "optimization";
142
+ else if (orderCount >= 20)
143
+ stage = "mature";
144
+ else if (orderCount >= 5)
145
+ stage = "growing";
146
+ const suggestions = [];
147
+ if (stage === "cold_start") {
148
+ suggestions.push("冷启动阶段:设置首单 Reward 吸引新客户");
149
+ suggestions.push("增加 compensation_fund 提升初始信任");
150
+ }
151
+ else if (stage === "growing") {
152
+ suggestions.push("成长阶段:设置推荐返现 Reward 裂变获客");
153
+ if (repeatCustomerRate !== undefined && repeatCustomerRate < 0.2) {
154
+ suggestions.push("复购率偏低,考虑设置累计金额阶梯 Reward");
155
+ }
156
+ }
157
+ else if (stage === "mature") {
158
+ if (reviewLikeRate !== undefined && reviewLikeRate > 0.8) {
159
+ suggestions.push("好评率高,可在 description 中突出信任指标");
160
+ }
161
+ if (repeatCustomerRate !== undefined && repeatCustomerRate > 0.3) {
162
+ suggestions.push("复购率高,考虑设置忠诚度 Reward 激励长期客户");
163
+ }
164
+ }
165
+ else {
166
+ suggestions.push("优化阶段:精细化调整定价和 Reward 策略");
167
+ if (avgCompletionTime !== undefined && avgCompletionTime > 48) {
168
+ suggestions.push("完成时间偏长,考虑优化 Machine 流程");
169
+ }
170
+ }
171
+ return {
172
+ metrics: {
173
+ orderCount,
174
+ completedRate: completedRate ?? 0,
175
+ avgCompletionTime,
176
+ repeatCustomerRate,
177
+ reviewLikeRate,
178
+ reviewCount,
179
+ },
180
+ suggestions,
181
+ flywheelStage: stage,
182
+ };
183
+ }
@@ -0,0 +1,24 @@
1
+ export interface ArbMetrics {
2
+ totalCases: number;
3
+ timelyResolutions: number;
4
+ acceptedVerdicts: number;
5
+ disputedVerdicts: number;
6
+ avgResponseHours: number;
7
+ compensationLocked?: bigint;
8
+ hasVerifiedIdentity: boolean;
9
+ }
10
+ export interface TrustScore {
11
+ score: number;
12
+ components: TrustComponent[];
13
+ level: "high_risk" | "caution" | "moderate" | "trusted";
14
+ warnings: string[];
15
+ }
16
+ export interface TrustComponent {
17
+ name: string;
18
+ maxPoints: number;
19
+ earnedPoints: number;
20
+ reason: string;
21
+ }
22
+ export declare function computeTrustScore(metrics: ArbMetrics): TrustScore;
23
+ export declare function quickRiskAssessment(score: number): string;
24
+ export declare const ARBITRATION_TRUST_VERSION = 1;
@@ -0,0 +1,117 @@
1
+ const WEIGHTS = {
2
+ acceptanceRate: 35,
3
+ timeliness: 20,
4
+ volume: 15,
5
+ responseSpeed: 10,
6
+ compensation: 10,
7
+ identity: 10,
8
+ };
9
+ export function computeTrustScore(metrics) {
10
+ const components = [];
11
+ const acceptanceRate = metrics.totalCases > 0
12
+ ? metrics.acceptedVerdicts / metrics.totalCases
13
+ : 0;
14
+ const acceptancePoints = Math.round(acceptanceRate * WEIGHTS.acceptanceRate);
15
+ components.push({
16
+ name: "verdict_acceptance",
17
+ maxPoints: WEIGHTS.acceptanceRate,
18
+ earnedPoints: acceptancePoints,
19
+ reason: `${metrics.acceptedVerdicts}/${metrics.totalCases} verdicts accepted without dispute`,
20
+ });
21
+ const timelyRate = metrics.totalCases > 0
22
+ ? metrics.timelyResolutions / metrics.totalCases
23
+ : 0;
24
+ const timelyPoints = Math.round(timelyRate * WEIGHTS.timeliness);
25
+ components.push({
26
+ name: "timeliness",
27
+ maxPoints: WEIGHTS.timeliness,
28
+ earnedPoints: timelyPoints,
29
+ reason: `${metrics.timelyResolutions}/${metrics.totalCases} cases resolved in time`,
30
+ });
31
+ const volumePoints = Math.min(WEIGHTS.volume, Math.round((metrics.totalCases / 20) * WEIGHTS.volume));
32
+ components.push({
33
+ name: "case_volume",
34
+ maxPoints: WEIGHTS.volume,
35
+ earnedPoints: volumePoints,
36
+ reason: `${metrics.totalCases} total cases handled`,
37
+ });
38
+ let responsePoints = 0;
39
+ if (metrics.avgResponseHours <= 1)
40
+ responsePoints = 10;
41
+ else if (metrics.avgResponseHours <= 6)
42
+ responsePoints = 7;
43
+ else if (metrics.avgResponseHours <= 24)
44
+ responsePoints = 5;
45
+ else if (metrics.avgResponseHours <= 72)
46
+ responsePoints = 3;
47
+ components.push({
48
+ name: "response_speed",
49
+ maxPoints: WEIGHTS.responseSpeed,
50
+ earnedPoints: responsePoints,
51
+ reason: `Average response: ${metrics.avgResponseHours}h`,
52
+ });
53
+ const compPoints = (metrics.compensationLocked !== undefined && metrics.compensationLocked > 0n)
54
+ ? WEIGHTS.compensation
55
+ : 0;
56
+ components.push({
57
+ name: "compensation_fund",
58
+ maxPoints: WEIGHTS.compensation,
59
+ earnedPoints: compPoints,
60
+ reason: metrics.compensationLocked
61
+ ? `Compensation fund: ${metrics.compensationLocked} smallest unit`
62
+ : "No compensation fund locked",
63
+ });
64
+ const identityPoints = metrics.hasVerifiedIdentity ? WEIGHTS.identity : 0;
65
+ components.push({
66
+ name: "verified_identity",
67
+ maxPoints: WEIGHTS.identity,
68
+ earnedPoints: identityPoints,
69
+ reason: metrics.hasVerifiedIdentity
70
+ ? "Has verified on-chain Personal identity"
71
+ : "No verified on-chain identity",
72
+ });
73
+ const score = components.reduce((sum, c) => sum + c.earnedPoints, 0);
74
+ const level = scoreLevel(score);
75
+ const warnings = buildWarnings(score, metrics, components);
76
+ return { score, components, level, warnings };
77
+ }
78
+ function scoreLevel(score) {
79
+ if (score < 25)
80
+ return "high_risk";
81
+ if (score < 50)
82
+ return "caution";
83
+ if (score < 75)
84
+ return "moderate";
85
+ return "trusted";
86
+ }
87
+ function buildWarnings(score, metrics, components) {
88
+ const warnings = [];
89
+ if (score < 50) {
90
+ warnings.push(`仲裁员信任分较低 (${score}/100, ${scoreLevel(score)})。` +
91
+ `建议客户谨慎选择此仲裁员。数据使用权在用户,系统不阻止使用。`);
92
+ }
93
+ if (metrics.disputedVerdicts > 0 && metrics.totalCases > 0) {
94
+ const disputeRate = metrics.disputedVerdicts / metrics.totalCases;
95
+ if (disputeRate > 0.3) {
96
+ warnings.push(`争议率较高 (${(disputeRate * 100).toFixed(1)}%):` +
97
+ `${metrics.disputedVerdicts}/${metrics.totalCases} 案件出现争议。`);
98
+ }
99
+ }
100
+ if (!metrics.hasVerifiedIdentity) {
101
+ warnings.push("仲裁员未验证链上身份(无 Personal 对象),建议核实其真实性。");
102
+ }
103
+ if (metrics.avgResponseHours > 72) {
104
+ warnings.push(`仲裁员平均响应时间较长 (${metrics.avgResponseHours}h),可能影响纠纷解决效率。`);
105
+ }
106
+ return warnings;
107
+ }
108
+ export function quickRiskAssessment(score) {
109
+ const level = scoreLevel(score);
110
+ switch (level) {
111
+ case "high_risk": return "高风险:建议更换仲裁员或增加补偿金保障";
112
+ case "caution": return "注意:信任分偏低,建议谨慎评估";
113
+ case "moderate": return "中等信任:可接受,建议持续观察";
114
+ case "trusted": return "高信任:仲裁员表现良好";
115
+ }
116
+ }
117
+ export const ARBITRATION_TRUST_VERSION = 1;
@@ -0,0 +1,28 @@
1
+ export type AuditSeverity = "error" | "warning" | "info";
2
+ export interface AuditFinding {
3
+ rule_id: string;
4
+ severity: AuditSeverity;
5
+ field?: string;
6
+ message: string;
7
+ recommendation?: string;
8
+ }
9
+ export interface AuditRule {
10
+ id: string;
11
+ description: string;
12
+ severity: AuditSeverity;
13
+ check: (data: any, context?: AuditContext) => boolean;
14
+ message: (data: any) => string;
15
+ recommendation?: string;
16
+ }
17
+ export interface AuditContext {
18
+ graph?: any;
19
+ hasName?: boolean;
20
+ userConfirmed?: boolean;
21
+ }
22
+ export declare const AUDIT_RULES: AuditRule[];
23
+ export declare function auditService(data: any, context?: AuditContext): AuditFinding[];
24
+ export declare function hasBlockingErrors(findings: AuditFinding[]): boolean;
25
+ export declare function getErrors(findings: AuditFinding[]): AuditFinding[];
26
+ export declare function getWarnings(findings: AuditFinding[]): AuditFinding[];
27
+ export declare function summarizeFindings(findings: AuditFinding[]): string;
28
+ export declare const AUDIT_RULES_VERSION = 1;
@@ -0,0 +1,141 @@
1
+ export const AUDIT_RULES = [
2
+ {
3
+ id: "audit_machine_bound",
4
+ description: "Service should have a Machine workflow bound before publish",
5
+ severity: "warning",
6
+ check: (d, ctx) => {
7
+ if (!d?.publish)
8
+ return true;
9
+ return !!d?.machine;
10
+ },
11
+ message: () => "Publishing a service without a Machine workflow. Customers won't have a structured order process.",
12
+ recommendation: "Create a Machine (workflow template) and bind it to the service before publishing. The machine field becomes IMMUTABLE after publish.",
13
+ },
14
+ {
15
+ id: "audit_order_allocators",
16
+ description: "Service should have order_allocators for fund distribution",
17
+ severity: "warning",
18
+ check: (d) => {
19
+ if (!d?.publish)
20
+ return true;
21
+ return Array.isArray(d?.order_allocators) && d.order_allocators.length > 0;
22
+ },
23
+ message: () => "Publishing a service without order_allocators. Order funds cannot be auto-distributed to suppliers.",
24
+ recommendation: "Configure order_allocators before publishing — this field becomes IMMUTABLE after publish.",
25
+ },
26
+ {
27
+ id: "audit_buy_guard",
28
+ description: "Service should have a buy_guard for customer screening",
29
+ severity: "info",
30
+ check: (d) => !!d?.buy_guard,
31
+ message: () => "No buy_guard configured — anyone can purchase this service without verification.",
32
+ recommendation: "Consider adding a Guard to verify customer eligibility (e.g., identity, wallet balance, location).",
33
+ },
34
+ {
35
+ id: "audit_compensation_fund",
36
+ description: "Service should have a compensation_fund for trust",
37
+ severity: "warning",
38
+ check: (d) => !!d?.compensation_fund,
39
+ message: () => "No compensation_fund configured. Customers have no financial protection if you fail to deliver.",
40
+ recommendation: "Lock a compensation_fund (Treasury) to build trust. The fund deters fraud and enables arbitration claims.",
41
+ },
42
+ {
43
+ id: "audit_arbitrations",
44
+ description: "Service should have arbitration options for dispute resolution",
45
+ severity: "info",
46
+ check: (d) => Array.isArray(d?.arbitrations) && d.arbitrations.length > 0,
47
+ message: () => "No arbitration configured. Disputes cannot be resolved through a third party.",
48
+ recommendation: "Add at least one Arb object to enable on-chain dispute resolution.",
49
+ },
50
+ {
51
+ id: "audit_price",
52
+ description: "Service should have a price set",
53
+ severity: "error",
54
+ check: (d) => d?.price !== undefined && d?.price !== null,
55
+ message: () => "Service has no price. Customers cannot place orders without knowing the cost.",
56
+ recommendation: "Set the price field before publishing.",
57
+ },
58
+ {
59
+ id: "audit_description",
60
+ description: "Service should have a description",
61
+ severity: "warning",
62
+ check: (d) => typeof d?.description === "string" && d.description.length > 0,
63
+ message: () => "Service has no description. Customers won't understand what you're offering.",
64
+ recommendation: "Write a clear description of the service, including deliverables, timelines, and terms.",
65
+ },
66
+ {
67
+ id: "audit_named_new_name",
68
+ description: "Service being created should have a name",
69
+ severity: "warning",
70
+ check: (d) => !!d?.namedNew?.name || typeof d?.object === "string",
71
+ message: () => "Creating a service without a name makes it hard to reference and organize.",
72
+ recommendation: "Set namedNew.name following the convention: <projectPrefix>_<service>_<purpose>.",
73
+ },
74
+ {
75
+ id: "audit_dangling_deps",
76
+ description: "Service dependencies should be fully created",
77
+ severity: "error",
78
+ check: (d, ctx) => {
79
+ if (!d?.publish)
80
+ return true;
81
+ if (!ctx?.graph)
82
+ return true;
83
+ const dangling = ctx.graph?.findDanglingDependencies?.() ?? [];
84
+ return dangling.length === 0;
85
+ },
86
+ message: (d) => "Service references objects that are not yet created. Publishing will lock these references.",
87
+ recommendation: "Ensure all referenced objects (machine, allocators, guards) are created and finalized before publishing.",
88
+ },
89
+ {
90
+ id: "audit_type_parameter",
91
+ description: "Service should have a token type specified",
92
+ severity: "info",
93
+ check: (d) => !!d?.type_parameter || !!d?.namedNew?.type_parameter,
94
+ message: () => "No payment token type specified. Defaulting to WOW (0x2::wow::WOW).",
95
+ recommendation: "Explicitly set type_parameter if you want to accept non-WOW tokens (e.g., USDT, ETH).",
96
+ },
97
+ ];
98
+ const RULE_INDEX = new Map(AUDIT_RULES.map((r) => [r.id, r]));
99
+ export function auditService(data, context) {
100
+ const findings = [];
101
+ for (const rule of AUDIT_RULES) {
102
+ try {
103
+ if (!rule.check(data, context)) {
104
+ findings.push({
105
+ rule_id: rule.id,
106
+ severity: rule.severity,
107
+ message: rule.message(data),
108
+ recommendation: rule.recommendation,
109
+ });
110
+ }
111
+ }
112
+ catch {
113
+ }
114
+ }
115
+ return findings;
116
+ }
117
+ export function hasBlockingErrors(findings) {
118
+ return findings.some((f) => f.severity === "error");
119
+ }
120
+ export function getErrors(findings) {
121
+ return findings.filter((f) => f.severity === "error");
122
+ }
123
+ export function getWarnings(findings) {
124
+ return findings.filter((f) => f.severity === "warning");
125
+ }
126
+ export function summarizeFindings(findings) {
127
+ if (findings.length === 0)
128
+ return "All audit checks passed.";
129
+ const errors = getErrors(findings);
130
+ const warnings = getWarnings(findings);
131
+ const infos = findings.filter((f) => f.severity === "info");
132
+ const parts = [];
133
+ if (errors.length > 0)
134
+ parts.push(`${errors.length} error(s)`);
135
+ if (warnings.length > 0)
136
+ parts.push(`${warnings.length} warning(s)`);
137
+ if (infos.length > 0)
138
+ parts.push(`${infos.length} info`);
139
+ return `Audit: ${parts.join(", ")}. Review before publishing.`;
140
+ }
141
+ export const AUDIT_RULES_VERSION = 1;
@@ -0,0 +1,29 @@
1
+ export interface ServiceInfo {
2
+ id: string;
3
+ name?: string;
4
+ tags?: string[];
5
+ price?: string;
6
+ priceToken?: string;
7
+ description?: string;
8
+ scenario?: string;
9
+ trustScore?: number;
10
+ location?: string;
11
+ published?: boolean;
12
+ }
13
+ export interface DemandInfo {
14
+ tags?: string[];
15
+ maxPrice?: string;
16
+ scenario?: string;
17
+ location?: string;
18
+ minTrustScore?: number;
19
+ keywords?: string[];
20
+ }
21
+ export interface DemandMatch {
22
+ service: ServiceInfo;
23
+ score: number;
24
+ reasons: string[];
25
+ warnings: string[];
26
+ }
27
+ export declare const DEMAND_MATCHING_VERSION = 1;
28
+ export declare function matchDemand(demand: DemandInfo, services: ServiceInfo[], limit?: number): DemandMatch[];
29
+ export declare function extractDemandInfo(demandData: any): DemandInfo;