@wowok/agent-mcp 2.3.16 → 2.4.1

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 (136) hide show
  1. package/dist/customer/index.d.ts +9 -0
  2. package/dist/customer/index.js +9 -0
  3. package/dist/customer/industry-risks.d.ts +4 -0
  4. package/dist/customer/industry-risks.js +45 -31
  5. package/dist/customer/order-monitor.js +57 -57
  6. package/dist/customer/order-strategy.js +89 -89
  7. package/dist/customer/post-purchase.js +97 -97
  8. package/dist/customer/reminder-system.js +26 -26
  9. package/dist/customer/risk-assessment.js +46 -46
  10. package/dist/customer/types.d.ts +4 -4
  11. package/dist/customer/types.js +4 -4
  12. package/dist/customer/user-preferences.d.ts +3 -0
  13. package/dist/customer/user-preferences.js +59 -50
  14. package/dist/experience/intent-distill.js +6 -6
  15. package/dist/experience/realtime-feedback.js +17 -0
  16. package/dist/index.js +360 -273
  17. package/dist/knowledge/acquisition-flywheel.d.ts +3 -0
  18. package/dist/knowledge/acquisition-flywheel.js +73 -64
  19. package/dist/knowledge/arbitration-trust.js +10 -10
  20. package/dist/knowledge/demand-matching.js +8 -8
  21. package/dist/knowledge/dynamic-pricing.js +18 -18
  22. package/dist/knowledge/flywheel-loop.js +11 -11
  23. package/dist/knowledge/glossary.js +22 -22
  24. package/dist/knowledge/guard-ledger.d.ts +19 -0
  25. package/dist/knowledge/guard-ledger.js +246 -0
  26. package/dist/knowledge/guard-lint.d.ts +76 -0
  27. package/dist/knowledge/guard-lint.js +590 -0
  28. package/dist/knowledge/guard-puzzle.d.ts +188 -0
  29. package/dist/knowledge/guard-puzzle.js +804 -0
  30. package/dist/knowledge/guard-risk.d.ts +67 -0
  31. package/dist/knowledge/guard-risk.js +1046 -0
  32. package/dist/knowledge/guard-templates.d.ts +37 -0
  33. package/dist/knowledge/guard-templates.js +329 -0
  34. package/dist/knowledge/guard-translation.d.ts +58 -0
  35. package/dist/knowledge/guard-translation.js +1118 -0
  36. package/dist/knowledge/index.d.ts +17 -0
  37. package/dist/knowledge/index.js +17 -0
  38. package/dist/knowledge/industry-evolution.js +29 -29
  39. package/dist/knowledge/industry-generalizer.js +52 -52
  40. package/dist/knowledge/industry-registry.d.ts +1 -2
  41. package/dist/knowledge/industry-registry.js +43 -36
  42. package/dist/knowledge/intent-metrics.js +67 -67
  43. package/dist/knowledge/process-model.js +80 -80
  44. package/dist/knowledge/reputation-rules.js +9 -9
  45. package/dist/knowledge/reward-templates.js +51 -51
  46. package/dist/knowledge/safety-rules.js +63 -2
  47. package/dist/knowledge/tool-constraints.js +17 -11
  48. package/dist/knowledge/trust-metrics.js +26 -26
  49. package/dist/safety/confirm-gate.d.ts +4 -2
  50. package/dist/safety/confirm-gate.js +48 -4
  51. package/dist/schema/call/allocation.d.ts +24 -14
  52. package/dist/schema/call/arbitration.d.ts +142 -132
  53. package/dist/schema/call/base.d.ts +901 -43
  54. package/dist/schema/call/base.js +77 -13
  55. package/dist/schema/call/bridge-handler.js +15 -2
  56. package/dist/schema/call/bridge.d.ts +795 -27
  57. package/dist/schema/call/bridge.js +37 -0
  58. package/dist/schema/call/contact.d.ts +10 -0
  59. package/dist/schema/call/demand.d.ts +94 -84
  60. package/dist/schema/call/guard.d.ts +229 -46
  61. package/dist/schema/call/guard.js +50 -0
  62. package/dist/schema/call/handler.js +46 -14
  63. package/dist/schema/call/machine.d.ts +158 -138
  64. package/dist/schema/call/order.d.ts +10 -0
  65. package/dist/schema/call/payment.d.ts +10 -0
  66. package/dist/schema/call/permission.d.ts +314 -304
  67. package/dist/schema/call/personal.d.ts +10 -0
  68. package/dist/schema/call/progress.d.ts +10 -0
  69. package/dist/schema/call/proof.d.ts +20 -0
  70. package/dist/schema/call/repository.d.ts +32 -22
  71. package/dist/schema/call/reward.d.ts +10 -0
  72. package/dist/schema/call/semantic.d.ts +9 -2
  73. package/dist/schema/call/semantic.js +617 -25
  74. package/dist/schema/call/service.d.ts +20 -10
  75. package/dist/schema/call/treasury.d.ts +10 -0
  76. package/dist/schema/config/index.d.ts +18 -0
  77. package/dist/schema/config/index.js +17 -0
  78. package/dist/schema/index.d.ts +6 -0
  79. package/dist/schema/index.js +5 -0
  80. package/dist/schema/local/index.d.ts +9 -9
  81. package/dist/schema/local/index.js +9 -0
  82. package/dist/schema/local/wip.d.ts +39 -19
  83. package/dist/schema/local/wip.js +5 -5
  84. package/dist/schema/messenger/index.d.ts +376 -55
  85. package/dist/schema/messenger/index.js +19 -19
  86. package/dist/schema/operations.d.ts +1881 -681
  87. package/dist/schema/operations.js +91 -96
  88. package/dist/schema/project/index.d.ts +21 -0
  89. package/dist/schema/project/index.js +32 -0
  90. package/dist/schema/query/index.d.ts +1074 -168
  91. package/dist/schema/query/index.js +8 -8
  92. package/dist/schema/schema-query/index.d.ts +33 -0
  93. package/dist/schema/schema-query/index.js +36 -0
  94. package/dist/schema/schema-version.d.ts +25 -0
  95. package/dist/schema/schema-version.js +76 -0
  96. package/dist/schema/trust/index.d.ts +407 -0
  97. package/dist/schema/trust/index.js +113 -0
  98. package/dist/schema/utils/guard-parser.js +4 -4
  99. package/dist/schema/utils/node-parser.js +14 -14
  100. package/dist/schemas/bridge_operation.output.json +233 -9
  101. package/dist/schemas/bridge_operation.schema.json +67 -8
  102. package/dist/schemas/config_operation.output.json +18 -0
  103. package/dist/schemas/config_operation.schema.json +34 -0
  104. package/dist/schemas/guard-node-schema.json +82 -0
  105. package/dist/schemas/guard2file.schema.json +8 -0
  106. package/dist/schemas/index.json +19 -1
  107. package/dist/schemas/machineNode2file.schema.json +8 -0
  108. package/dist/schemas/messenger_operation.output.json +236 -10
  109. package/dist/schemas/onchain_events.output.json +718 -0
  110. package/dist/schemas/onchain_operations.output.json +286 -11
  111. package/dist/schemas/onchain_operations.schema.json +19 -16
  112. package/dist/schemas/onchain_operations_allocation.schema.json +8 -0
  113. package/dist/schemas/onchain_operations_arbitration.schema.json +8 -0
  114. package/dist/schemas/onchain_operations_contact.schema.json +8 -0
  115. package/dist/schemas/onchain_operations_demand.schema.json +8 -0
  116. package/dist/schemas/onchain_operations_gen_passport.schema.json +16 -0
  117. package/dist/schemas/onchain_operations_guard.schema.json +11 -16
  118. package/dist/schemas/onchain_operations_machine.schema.json +8 -0
  119. package/dist/schemas/onchain_operations_order.schema.json +8 -0
  120. package/dist/schemas/onchain_operations_payment.schema.json +8 -0
  121. package/dist/schemas/onchain_operations_permission.schema.json +8 -0
  122. package/dist/schemas/onchain_operations_personal.schema.json +8 -0
  123. package/dist/schemas/onchain_operations_progress.schema.json +8 -0
  124. package/dist/schemas/onchain_operations_repository.schema.json +8 -0
  125. package/dist/schemas/onchain_operations_reward.schema.json +8 -0
  126. package/dist/schemas/onchain_operations_service.schema.json +8 -0
  127. package/dist/schemas/onchain_operations_treasury.schema.json +8 -0
  128. package/dist/schemas/onchain_table_data.output.json +718 -0
  129. package/dist/schemas/project_operation.output.json +18 -0
  130. package/dist/schemas/project_operation.schema.json +42 -0
  131. package/dist/schemas/query_toolkit.schema.json +360 -368
  132. package/dist/schemas/schema_query.schema.json +6 -3
  133. package/dist/schemas/trust_score.output.json +327 -0
  134. package/dist/schemas/trust_score.schema.json +46 -0
  135. package/dist/schemas/wip_file.output.json +24 -1
  136. package/package.json +2 -2
@@ -1,95 +1,95 @@
1
1
  export const REWARD_TEMPLATES = [
2
2
  {
3
3
  type: "first_order",
4
- name: "首单奖励",
5
- description: "新客户首次下单后获得奖励,降低尝试门槛,促进转化。",
6
- guardCondition: "Guard 验证: order_addressholder == 当前 claim 者, order.service == Service, order 是该 holder 的第一笔订单 (通过 Repository 查询历史)",
4
+ name: "First-order reward",
5
+ description: "New customers receive a reward after their first order, lowering the trial barrier and boosting conversion.",
6
+ guardCondition: "Guard verifies: order_address.holder == current claimer, and order.service == this Service, and order is the first order for this holder (via Repository history query)",
7
7
  amountRange: { min: "0.1WOW", max: "5WOW" },
8
8
  allocationStrategy: "fixed",
9
9
  parameters: [
10
- { name: "amount", type: "string", description: "奖励金额 ( '1WOW')", required: true },
11
- { name: "budget", type: "string", description: "总预算 ( '100WOW')", required: true },
10
+ { name: "amount", type: "string", description: "Reward amount (e.g., '1WOW')", required: true },
11
+ { name: "budget", type: "string", description: "Total budget (e.g., '100WOW')", required: true },
12
12
  ],
13
- example: "新客户下单购买摄影服务,首单获得 1 WOW 返还,降低首次尝试成本。",
13
+ example: "A new customer orders a photography service and receives 1 WOW cashback on the first order, lowering the first trial cost.",
14
14
  relevantGuardOps: ["query", "repository_read"],
15
15
  },
16
16
  {
17
17
  type: "referral",
18
- name: "裂变推荐奖励",
19
- description: "老客户推荐新客户下单后,双方各获得奖励,形成口碑传播飞轮。",
20
- guardCondition: "Guard 验证: 推荐人地址在 Repository 评价表中标记为 'referred_by', 且被推荐人的订单已完成 (Progress 到达终态)",
18
+ name: "Referral viral reward",
19
+ description: "Existing customers refer new customers to place an order; both parties receive a reward, creating a word-of-mouth flywheel.",
20
+ guardCondition: "Guard verifies: referrer address is marked as 'referred_by' in the Repository review table, and the referee's order is completed (Progress reached terminal state)",
21
21
  amountRange: { min: "0.5WOW", max: "10WOW" },
22
22
  allocationStrategy: "proportional",
23
23
  parameters: [
24
- { name: "referrer_reward", type: "string", description: "推荐人奖励 ( '2WOW')", required: true },
25
- { name: "referee_reward", type: "string", description: "被推荐人奖励 ( '1WOW')", required: true },
26
- { name: "max_referrals", type: "number", description: "每人最多推荐数 ( 10)", required: false },
24
+ { name: "referrer_reward", type: "string", description: "Referrer reward (e.g., '2WOW')", required: true },
25
+ { name: "referee_reward", type: "string", description: "Referee reward (e.g., '1WOW')", required: true },
26
+ { name: "max_referrals", type: "number", description: "Max referrals per person (e.g., 10)", required: false },
27
27
  ],
28
- example: "Alice 推荐 Bob 购买服务,Bob 完成首单后 Alice 2 WOWBob 1 WOW",
28
+ example: "Alice refers Bob to purchase a service; after Bob completes the first order, Alice gets 2 WOW and Bob gets 1 WOW.",
29
29
  relevantGuardOps: ["query", "repository_read", "repository_write"],
30
30
  },
31
31
  {
32
32
  type: "loyalty",
33
- name: "忠诚度阶梯奖励",
34
- description: "客户累计消费达到阶梯后解锁更高奖励,提升复购率和客单价。",
35
- guardCondition: "Guard 验证: 通过 Repository 查询该地址历史订单数 >= N, N 为当前阶梯阈值",
33
+ name: "Loyalty tiered reward",
34
+ description: "Customers unlock higher rewards after reaching cumulative spending tiers, improving repeat rate and average order value.",
35
+ guardCondition: "Guard verifies: via Repository query, the address's historical order count >= N, where N is the current tier threshold",
36
36
  amountRange: { min: "1WOW", max: "50WOW" },
37
37
  allocationStrategy: "tiered",
38
38
  parameters: [
39
- { name: "tier1_orders", type: "number", description: "第一阶梯订单数 ( 3)", required: true },
40
- { name: "tier1_reward", type: "string", description: "第一阶梯奖励 ( '1WOW')", required: true },
41
- { name: "tier2_orders", type: "number", description: "第二阶梯订单数 ( 10)", required: true },
42
- { name: "tier2_reward", type: "string", description: "第二阶梯奖励 ( '5WOW')", required: true },
43
- { name: "tier3_orders", type: "number", description: "第三阶梯订单数 ( 30)", required: false },
44
- { name: "tier3_reward", type: "string", description: "第三阶梯奖励 ( '20WOW')", required: false },
39
+ { name: "tier1_orders", type: "number", description: "Tier 1 order count (e.g., 3)", required: true },
40
+ { name: "tier1_reward", type: "string", description: "Tier 1 reward (e.g., '1WOW')", required: true },
41
+ { name: "tier2_orders", type: "number", description: "Tier 2 order count (e.g., 10)", required: true },
42
+ { name: "tier2_reward", type: "string", description: "Tier 2 reward (e.g., '5WOW')", required: true },
43
+ { name: "tier3_orders", type: "number", description: "Tier 3 order count (e.g., 30)", required: false },
44
+ { name: "tier3_reward", type: "string", description: "Tier 3 reward (e.g., '20WOW')", required: false },
45
45
  ],
46
- example: "客户累计 3 单得 1 WOW10 单得 5 WOW30 单得 20 WOW,激励持续消费。",
46
+ example: "A customer with 3 cumulative orders gets 1 WOW, 10 orders gets 5 WOW, 30 orders gets 20 WOW, incentivizing continued spending.",
47
47
  relevantGuardOps: ["query", "repository_read"],
48
48
  },
49
49
  {
50
50
  type: "flash_sale",
51
- name: "限时闪购",
52
- description: "在限定时间窗口内提供折扣或额外奖励,制造紧迫感促进即时转化。",
53
- guardCondition: "Guard 验证: 当前区块时间在 [start_time, end_time] 范围内 (Guard 时间条件)",
51
+ name: "Limited-time flash sale",
52
+ description: "Provides discounts or extra rewards within a limited time window, creating urgency to drive instant conversion.",
53
+ guardCondition: "Guard verifies: current block time is within [start_time, end_time] range (Guard time condition)",
54
54
  amountRange: { min: "0.1WOW", max: "20WOW" },
55
55
  allocationStrategy: "fixed",
56
56
  parameters: [
57
- { name: "start_time", type: "string", description: "开始时间 (Unix timestamp)", required: true },
58
- { name: "end_time", type: "string", description: "结束时间 (Unix timestamp)", required: true },
59
- { name: "amount", type: "string", description: "闪购奖励金额", required: true },
60
- { name: "max_claims", type: "number", description: "最大领取数 ( 100)", required: true },
57
+ { name: "start_time", type: "string", description: "Start time (Unix timestamp)", required: true },
58
+ { name: "end_time", type: "string", description: "End time (Unix timestamp)", required: true },
59
+ { name: "amount", type: "string", description: "Flash sale reward amount", required: true },
60
+ { name: "max_claims", type: "number", description: "Max claims (e.g., 100)", required: true },
61
61
  ],
62
- example: "周末限时 48 小时闪购,下单客户额外获得 2 WOW 返还,前 100 名有效。",
62
+ example: "Weekend 48-hour flash sale: ordering customers get an extra 2 WOW cashback, valid for the first 100.",
63
63
  relevantGuardOps: ["query", "time_condition"],
64
64
  },
65
65
  {
66
66
  type: "cashback",
67
- name: "消费返现",
68
- description: "客户完成订单后按消费比例返现,提升复购意愿。",
69
- guardCondition: "Guard 验证: order 已到达终态 (Progress completed), order.service == Service",
67
+ name: "Spending cashback",
68
+ description: "Customers receive cashback proportional to spending after completing an order, improving repeat purchase willingness.",
69
+ guardCondition: "Guard verifies: order has reached terminal state (Progress completed), and order.service == this Service",
70
70
  amountRange: { min: "0.1WOW", max: "100WOW" },
71
71
  allocationStrategy: "proportional",
72
72
  parameters: [
73
- { name: "cashback_rate", type: "string", description: "返现比例 ( '0.1' = 10%)", required: true },
74
- { name: "max_cashback", type: "string", description: "单笔最大返现 ( '10WOW')", required: true },
75
- { name: "budget", type: "string", description: "总预算 ( '500WOW')", required: true },
73
+ { name: "cashback_rate", type: "string", description: "Cashback rate (e.g., '0.1' = 10%)", required: true },
74
+ { name: "max_cashback", type: "string", description: "Max cashback per order (e.g., '10WOW')", required: true },
75
+ { name: "budget", type: "string", description: "Total budget (e.g., '500WOW')", required: true },
76
76
  ],
77
- example: "客户消费 10 WOW,按 10% 比例返现 1 WOW,下次消费可抵扣。",
77
+ example: "A customer spends 10 WOW, gets 10% cashback = 1 WOW, which can be deducted on the next purchase.",
78
78
  relevantGuardOps: ["query"],
79
79
  },
80
80
  {
81
81
  type: "milestone",
82
- name: "里程碑奖励",
83
- description: "Service 达到特定里程碑(如 100 单、1000 客户)时给早期支持者发放额外奖励。",
84
- guardCondition: "Guard 验证: Repository 查询 Service 累计订单数 >= milestone_threshold, claim 者为早期客户 (order_index < milestone)",
82
+ name: "Milestone reward",
83
+ description: "When a Service reaches a specific milestone (e.g., 100 orders, 1000 customers), early supporters receive extra rewards.",
84
+ guardCondition: "Guard verifies: Repository query shows Service cumulative order count >= milestone_threshold, and claimer is an early customer (order_index < milestone)",
85
85
  amountRange: { min: "1WOW", max: "100WOW" },
86
86
  allocationStrategy: "fixed",
87
87
  parameters: [
88
- { name: "milestone", type: "number", description: "里程碑值 ( 100)", required: true },
89
- { name: "reward_per_user", type: "string", description: "每人奖励 ( '5WOW')", required: true },
90
- { name: "max_recipients", type: "number", description: "最大受益人数 ( 50)", required: true },
88
+ { name: "milestone", type: "number", description: "Milestone value (e.g., 100)", required: true },
89
+ { name: "reward_per_user", type: "string", description: "Reward per person (e.g., '5WOW')", required: true },
90
+ { name: "max_recipients", type: "number", description: "Max beneficiaries (e.g., 50)", required: true },
91
91
  ],
92
- example: "Service 达到 100 单里程碑,前 50 名客户每人获得 5 WOW 额外奖励。",
92
+ example: "Service reaches the 100-order milestone; the first 50 customers each receive 5 WOW extra reward.",
93
93
  relevantGuardOps: ["query", "repository_read"],
94
94
  },
95
95
  ];
@@ -102,22 +102,22 @@ export function listRewardTemplates() {
102
102
  }
103
103
  export function suggestRewardTemplate(intent) {
104
104
  const lower = intent.toLowerCase();
105
- if (lower.includes("首单") || lower.includes("new") || lower.includes("first")) {
105
+ if (lower.includes("first order") || lower.includes("new") || lower.includes("first")) {
106
106
  return getRewardTemplate("first_order");
107
107
  }
108
- if (lower.includes("推荐") || lower.includes("裂变") || lower.includes("referral")) {
108
+ if (lower.includes("referral") || lower.includes("viral") || lower.includes("referral")) {
109
109
  return getRewardTemplate("referral");
110
110
  }
111
- if (lower.includes("复购") || lower.includes("忠诚") || lower.includes("loyalty")) {
111
+ if (lower.includes("repeat") || lower.includes("loyalty") || lower.includes("loyalty")) {
112
112
  return getRewardTemplate("loyalty");
113
113
  }
114
- if (lower.includes("限时") || lower.includes("闪购") || lower.includes("flash")) {
114
+ if (lower.includes("limited-time") || lower.includes("flash") || lower.includes("flash")) {
115
115
  return getRewardTemplate("flash_sale");
116
116
  }
117
- if (lower.includes("返现") || lower.includes("cashback")) {
117
+ if (lower.includes("cashback") || lower.includes("cashback")) {
118
118
  return getRewardTemplate("cashback");
119
119
  }
120
- if (lower.includes("里程碑") || lower.includes("milestone")) {
120
+ if (lower.includes("milestone") || lower.includes("milestone")) {
121
121
  return getRewardTemplate("milestone");
122
122
  }
123
123
  return undefined;
@@ -146,10 +146,71 @@ export const CONFIRMATION_RULES = [
146
146
  bypass_on_explicit_intent: [
147
147
  "use default account",
148
148
  "default account is fine",
149
- "用默认账户",
150
- "用默认账户即可",
149
+ "use the default account",
150
+ "default account works fine",
151
151
  ],
152
152
  },
153
+ {
154
+ id: "guard_create_immutable",
155
+ when: (ot, data, _env) => {
156
+ if (ot === "guard")
157
+ return true;
158
+ return false;
159
+ },
160
+ level: "irreversible",
161
+ preview: (ot, data, env) => {
162
+ const table = data?.table ?? [];
163
+ const root = data?.root;
164
+ const rely = data?.rely;
165
+ const rootType = typeof root === 'object' && root !== null && 'type' in root
166
+ ? root.type
167
+ : typeof root === 'object' && root !== null && 'type' in root && root.type === 'file'
168
+ ? 'file'
169
+ : 'unknown';
170
+ const immutable_fields = ['table', 'root'];
171
+ if (rely)
172
+ immutable_fields.push('rely');
173
+ return {
174
+ level: "irreversible",
175
+ operation: ot,
176
+ object: data?.namedNew?.name,
177
+ network: env?.network,
178
+ account: env?.account ?? "",
179
+ immutable_after: immutable_fields,
180
+ irreversible: true,
181
+ warnings: [
182
+ ...collectDefaultWarnings(env, data),
183
+ `Guard is CREATE-only and immutable — cannot be edited or deleted after creation`,
184
+ `Table entries: ${table.length} (max 256)`,
185
+ `Root node type: ${rootType} (must return Bool)`,
186
+ ...(rely ? [`Rely dependencies: ${rely.guards?.length ?? 0} (max 4, AND/OR logic)`] : []),
187
+ `To modify later: export via guard2file → edit → CREATE new → rebind`,
188
+ ],
189
+ };
190
+ },
191
+ bypass_on_explicit_intent: [],
192
+ },
193
+ {
194
+ id: "guard_gen_passport_test",
195
+ when: (ot, _data, _env) => {
196
+ if (ot === "gen_passport")
197
+ return true;
198
+ return false;
199
+ },
200
+ level: "standard",
201
+ preview: (ot, data, env) => ({
202
+ level: "standard",
203
+ operation: ot,
204
+ object: data?.guard,
205
+ network: env?.network,
206
+ account: env?.account ?? "",
207
+ warnings: [
208
+ ...collectDefaultWarnings(env, data),
209
+ "gen_passport will consume gas for static testing",
210
+ ],
211
+ }),
212
+ bypass_on_explicit_intent: ["test guard", "testing guard", "gen passport", "generate passport"],
213
+ },
153
214
  ];
154
215
  function extractAmount(data) {
155
216
  if (!data)
@@ -26,10 +26,16 @@ export const TOOL_CONSTRAINTS = [
26
26
  constraints: [
27
27
  {
28
28
  field: "node.nodes",
29
- description: "Machine must have at least one node",
29
+ description: "Machine must have at least one node when published",
30
30
  severity: "error",
31
- check: (d) => Array.isArray(d?.node?.nodes) && d.node.nodes.length > 0,
32
- message: () => "Machine has no nodes. A workflow template requires at least one node.",
31
+ check: (d) => {
32
+ if (typeof d?.object === "string")
33
+ return true;
34
+ if (!d?.publish)
35
+ return true;
36
+ return Array.isArray(d?.node?.nodes) && d.node.nodes.length > 0;
37
+ },
38
+ message: () => "Publishing a Machine without nodes — a workflow template requires at least one node. Consider adding nodes before publish, or publish later after adding nodes.",
33
39
  },
34
40
  ],
35
41
  },
@@ -57,11 +63,11 @@ export const TOOL_CONSTRAINTS = [
57
63
  operation_type: "order",
58
64
  constraints: [
59
65
  {
60
- field: "service",
61
- description: "Order must reference a service",
66
+ field: "object",
67
+ description: "Order requires an existing Order object reference",
62
68
  severity: "error",
63
- check: (d) => !!d?.service,
64
- message: () => "Order requires a 'service' field pointing to the service being ordered.",
69
+ check: (d) => !!d?.object,
70
+ message: () => "Order requires 'object' field (Order object ID or name).",
65
71
  },
66
72
  ],
67
73
  },
@@ -122,11 +128,11 @@ export const TOOL_CONSTRAINTS = [
122
128
  operation_type: "progress",
123
129
  constraints: [
124
130
  {
125
- field: "parent",
126
- description: "Progress must reference a parent machine",
131
+ field: "object",
132
+ description: "Progress requires an existing Progress object reference",
127
133
  severity: "error",
128
- check: (d) => !!d?.parent,
129
- message: () => "Progress requires a 'parent' field pointing to the Machine.",
134
+ check: (d) => !!d?.object,
135
+ message: () => "Progress requires 'object' field (Progress object ID or name).",
130
136
  },
131
137
  ],
132
138
  },
@@ -1,9 +1,9 @@
1
1
  export const TRUST_METRICS_VERSION = 1;
2
2
  const TRUST_LEVELS = [
3
- { min: 75, level: "trusted", label: "高信任" },
4
- { min: 50, level: "moderate", label: "中等信任" },
5
- { min: 25, level: "caution", label: "需注意" },
6
- { min: 0, level: "high_risk", label: "高风险" },
3
+ { min: 75, level: "trusted", label: "High trust" },
4
+ { min: 50, level: "moderate", label: "Moderate trust" },
5
+ { min: 25, level: "caution", label: "Needs attention" },
6
+ { min: 0, level: "high_risk", label: "High risk" },
7
7
  ];
8
8
  export function computeServiceTrustScore(metrics) {
9
9
  const breakdown = [];
@@ -11,49 +11,49 @@ export function computeServiceTrustScore(metrics) {
11
11
  const arbScore = computeArbitrationDimension(metrics);
12
12
  breakdown.push(arbScore);
13
13
  if (arbScore.score < arbScore.maxScore * 0.3) {
14
- warnings.push("仲裁信任分较低,建议检查仲裁记录");
14
+ warnings.push("Arbitration trust score is low; recommend checking arbitration records");
15
15
  }
16
16
  const reviewScore = computeReviewDimension(metrics);
17
17
  breakdown.push(reviewScore);
18
18
  if (reviewScore.score < reviewScore.maxScore * 0.3 && metrics.reviewStats) {
19
- warnings.push(`好评率较低 (${metrics.reviewStats.likes}/${metrics.reviewStats.totalReviews})`);
19
+ warnings.push(`Low like rate (${metrics.reviewStats.likes}/${metrics.reviewStats.totalReviews})`);
20
20
  }
21
21
  const fulfillmentScore = computeFulfillmentDimension(metrics);
22
22
  breakdown.push(fulfillmentScore);
23
23
  if (metrics.completedRate !== undefined && metrics.completedRate < 0.7) {
24
- warnings.push(`完成率仅 ${Math.round(metrics.completedRate * 100)}%`);
24
+ warnings.push(`Completion rate only ${Math.round(metrics.completedRate * 100)}%`);
25
25
  }
26
26
  const fundScore = computeFundDimension(metrics);
27
27
  breakdown.push(fundScore);
28
28
  if (metrics.compensationFundBalance === undefined || metrics.compensationFundBalance === 0n) {
29
- warnings.push("无赔偿金,客户权益保障不足");
29
+ warnings.push("No compensation fund; insufficient protection of customer rights");
30
30
  }
31
31
  const transparencyScore = computeTransparencyDimension(metrics);
32
32
  breakdown.push(transparencyScore);
33
33
  const totalScore = breakdown.reduce((sum, d) => sum + d.score, 0);
34
34
  const level = TRUST_LEVELS.find((l) => totalScore >= l.min)?.level ?? "high_risk";
35
- const label = TRUST_LEVELS.find((l) => totalScore >= l.min)?.label ?? "高风险";
35
+ const label = TRUST_LEVELS.find((l) => totalScore >= l.min)?.label ?? "High risk";
36
36
  const summary = buildSummary(totalScore, label, metrics, breakdown);
37
37
  return { score: totalScore, level, breakdown, summary, warnings };
38
38
  }
39
39
  function computeArbitrationDimension(metrics) {
40
40
  const maxScore = 30;
41
41
  if (metrics.arbitrationScore === undefined) {
42
- return { name: "arbitration", score: maxScore * 0.5, maxScore, description: "仲裁信任分(无数据,默认中等)", humanReadable: "仲裁记录: 无数据" };
42
+ return { name: "arbitration", score: maxScore * 0.5, maxScore, description: "Arbitration trust score (no data, default moderate)", humanReadable: "Arbitration record: no data" };
43
43
  }
44
44
  const score = Math.round((metrics.arbitrationScore / 100) * maxScore);
45
45
  return {
46
46
  name: "arbitration",
47
47
  score,
48
48
  maxScore,
49
- description: `仲裁信任分 ${metrics.arbitrationScore}/100`,
50
- humanReadable: `仲裁信任: ${metrics.arbitrationScore}/100${metrics.arbitrationCases !== undefined ? ` (${metrics.arbitrationCases} 案件)` : ""}`,
49
+ description: `Arbitration trust score ${metrics.arbitrationScore}/100`,
50
+ humanReadable: `Arbitration trust: ${metrics.arbitrationScore}/100${metrics.arbitrationCases !== undefined ? ` (${metrics.arbitrationCases} cases)` : ""}`,
51
51
  };
52
52
  }
53
53
  function computeReviewDimension(metrics) {
54
54
  const maxScore = 25;
55
55
  if (!metrics.reviewStats || metrics.reviewStats.totalReviews === 0) {
56
- return { name: "reviews", score: maxScore * 0.5, maxScore, description: "评价声誉(无评价数据)", humanReadable: "评价: 无数据" };
56
+ return { name: "reviews", score: maxScore * 0.5, maxScore, description: "Review reputation (no review data)", humanReadable: "Reviews: no data" };
57
57
  }
58
58
  const { likes, dislikes, verifiedReviews, totalReviews } = metrics.reviewStats;
59
59
  const likeRate = likes / Math.max(1, totalReviews);
@@ -63,14 +63,14 @@ function computeReviewDimension(metrics) {
63
63
  name: "reviews",
64
64
  score: Math.min(maxScore, score),
65
65
  maxScore,
66
- description: `好评率 ${Math.round(likeRate * 100)}% (${totalReviews} 条评价, ${verifiedReviews} 条带凭证)`,
67
- humanReadable: `好评率 ${Math.round(likeRate * 100)}% (${totalReviews} 评价)`,
66
+ description: `Like rate ${Math.round(likeRate * 100)}% (${totalReviews} reviews, ${verifiedReviews} verified)`,
67
+ humanReadable: `Like rate ${Math.round(likeRate * 100)}% (${totalReviews} reviews)`,
68
68
  };
69
69
  }
70
70
  function computeFulfillmentDimension(metrics) {
71
71
  const maxScore = 20;
72
72
  if (metrics.orderCount === undefined) {
73
- return { name: "fulfillment", score: maxScore * 0.5, maxScore, description: "履约记录(无订单数据)", humanReadable: "履约: 无数据" };
73
+ return { name: "fulfillment", score: maxScore * 0.5, maxScore, description: "Fulfillment record (no order data)", humanReadable: "Fulfillment: no data" };
74
74
  }
75
75
  let score = 0;
76
76
  const orderScore = Math.min(10, Math.floor(metrics.orderCount / 5));
@@ -85,14 +85,14 @@ function computeFulfillmentDimension(metrics) {
85
85
  name: "fulfillment",
86
86
  score: Math.min(maxScore, score),
87
87
  maxScore,
88
- description: `已完成 ${metrics.orderCount} 单, 完成率 ${metrics.completedRate !== undefined ? Math.round(metrics.completedRate * 100) + "%" : "未知"}`,
89
- humanReadable: `履约: ${metrics.orderCount} 单${metrics.avgCompletionTime !== undefined ? `, 平均 ${metrics.avgCompletionTime}h` : ""}`,
88
+ description: `Completed ${metrics.orderCount} orders, completion rate ${metrics.completedRate !== undefined ? Math.round(metrics.completedRate * 100) + "%" : "unknown"}`,
89
+ humanReadable: `Fulfillment: ${metrics.orderCount} orders${metrics.avgCompletionTime !== undefined ? `, avg ${metrics.avgCompletionTime}h` : ""}`,
90
90
  };
91
91
  }
92
92
  function computeFundDimension(metrics) {
93
93
  const maxScore = 15;
94
94
  if (metrics.compensationFundBalance === undefined || metrics.compensationFundBalance === 0n) {
95
- return { name: "fund_safety", score: 0, maxScore, description: "无赔偿金", humanReadable: "赔偿金: " };
95
+ return { name: "fund_safety", score: 0, maxScore, description: "No compensation fund", humanReadable: "Compensation fund: none" };
96
96
  }
97
97
  const threshold = 1000000000000n;
98
98
  const ratio = Number(metrics.compensationFundBalance * 100n / threshold) / 100;
@@ -101,8 +101,8 @@ function computeFundDimension(metrics) {
101
101
  name: "fund_safety",
102
102
  score,
103
103
  maxScore,
104
- description: `赔偿金 ${metrics.compensationFundBalance} 最小单位`,
105
- humanReadable: `赔偿金: 充足`,
104
+ description: `Compensation fund ${metrics.compensationFundBalance} smallest unit`,
105
+ humanReadable: `Compensation fund: sufficient`,
106
106
  };
107
107
  }
108
108
  function computeTransparencyDimension(metrics) {
@@ -118,12 +118,12 @@ function computeTransparencyDimension(metrics) {
118
118
  name: "transparency",
119
119
  score: Math.min(maxScore, score),
120
120
  maxScore,
121
- description: `链上事件 ${metrics.hasPublishedEvents ? "✓" : "✗"}, Machine ${metrics.hasMachineBound ? "✓" : "✗"}, Guard ${metrics.hasBuyGuard ? "✓" : "✗"}`,
122
- humanReadable: `透明度: ${["事件", "Machine", "Guard"].filter((_, i) => [metrics.hasPublishedEvents, metrics.hasMachineBound, metrics.hasBuyGuard][i]).join("+") || ""}`,
121
+ description: `On-chain events ${metrics.hasPublishedEvents ? "✓" : "✗"}, Machine ${metrics.hasMachineBound ? "✓" : "✗"}, Guard ${metrics.hasBuyGuard ? "✓" : "✗"}`,
122
+ humanReadable: `Transparency: ${["Events", "Machine", "Guard"].filter((_, i) => [metrics.hasPublishedEvents, metrics.hasMachineBound, metrics.hasBuyGuard][i]).join("+") || "none"}`,
123
123
  };
124
124
  }
125
125
  function buildSummary(score, label, metrics, breakdown) {
126
- const parts = [`信任分 ${score}/100 (${label})`];
126
+ const parts = [`Trust score ${score}/100 (${label})`];
127
127
  for (const d of breakdown) {
128
128
  parts.push(`${d.humanReadable}`);
129
129
  }
@@ -132,7 +132,7 @@ function buildSummary(score, label, metrics, breakdown) {
132
132
  export function quickTrustCheck(metrics) {
133
133
  const result = computeServiceTrustScore(metrics);
134
134
  if (result.score < 25) {
135
- return { pass: false, reason: `信任分 ${result.score}/100,高风险: ${result.warnings.join("; ")}` };
135
+ return { pass: false, reason: `Trust score ${result.score}/100, high risk: ${result.warnings.join("; ")}` };
136
136
  }
137
- return { pass: true, reason: `信任分 ${result.score}/100 (${result.level})` };
137
+ return { pass: true, reason: `Trust score ${result.score}/100 (${result.level})` };
138
138
  }
@@ -1,14 +1,16 @@
1
1
  import type { CallEnv } from "../schema/call/base.js";
2
- import { type ConfirmationRule, type OperationPreview } from "../knowledge/safety-rules.js";
2
+ import { type ConfirmLevel, type OperationPreview } from "../knowledge/safety-rules.js";
3
3
  export declare function isConfirmGateEnabled(): boolean;
4
+ export type FailMode = "open" | "closed";
4
5
  export type ConfirmResult = {
5
6
  pass: true;
6
7
  } | {
7
8
  pass: false;
8
- level: ConfirmationRule["level"];
9
+ level: ConfirmLevel;
9
10
  preview: OperationPreview;
10
11
  rule_id: string;
11
12
  };
13
+ export declare function getFailMode(level: ConfirmLevel): FailMode;
12
14
  export declare function confirmGate(operation_type: string, data: any, env: any, userIntentPhrases?: string[]): ConfirmResult;
13
15
  export declare function isExplicitlyConfirmed(env: CallEnv & {
14
16
  confirmed?: boolean;
@@ -3,24 +3,64 @@ import { isEnabled as isRuntimeEnabled } from "../config/index.js";
3
3
  export function isConfirmGateEnabled() {
4
4
  return isRuntimeEnabled("confirm_gate");
5
5
  }
6
+ const internalErrorCounts = {};
7
+ function logInternalError(context, error) {
8
+ const key = context;
9
+ internalErrorCounts[key] = (internalErrorCounts[key] ?? 0) + 1;
10
+ const count = internalErrorCounts[key];
11
+ console.warn(`[ConfirmGate] internal_error context="${context}" count=${count} error=${error instanceof Error ? error.message : String(error)}`);
12
+ }
13
+ export function getFailMode(level) {
14
+ switch (level) {
15
+ case "irreversible":
16
+ case "publish":
17
+ case "amount":
18
+ return "closed";
19
+ case "standard":
20
+ case "none":
21
+ default:
22
+ return "open";
23
+ }
24
+ }
25
+ function buildInternalErrorResult() {
26
+ return {
27
+ pass: false,
28
+ level: "irreversible",
29
+ preview: {
30
+ level: "irreversible",
31
+ operation: "unknown",
32
+ irreversible: true,
33
+ },
34
+ rule_id: "internal_error",
35
+ };
36
+ }
6
37
  export function confirmGate(operation_type, data, env, userIntentPhrases) {
7
38
  if (!isConfirmGateEnabled())
8
39
  return { pass: true };
9
40
  if (env?.confirmed === true)
10
41
  return { pass: true };
11
42
  let matched;
43
+ let ruleSearchError = null;
12
44
  try {
13
45
  matched = CONFIRMATION_RULES.find((r) => {
14
46
  try {
15
47
  return r.when(operation_type, data, env);
16
48
  }
17
- catch {
49
+ catch (e) {
50
+ logInternalError(`rule_when:${r.id}`, e);
51
+ if (getFailMode(r.level) === "closed") {
52
+ throw e;
53
+ }
18
54
  return false;
19
55
  }
20
56
  });
21
57
  }
22
- catch {
23
- return { pass: true };
58
+ catch (e) {
59
+ ruleSearchError = e;
60
+ }
61
+ if (ruleSearchError) {
62
+ logInternalError("rule_search", ruleSearchError);
63
+ return buildInternalErrorResult();
24
64
  }
25
65
  if (!matched)
26
66
  return { pass: true };
@@ -34,7 +74,11 @@ export function confirmGate(operation_type, data, env, userIntentPhrases) {
34
74
  try {
35
75
  preview = matched.preview(operation_type, data, env);
36
76
  }
37
- catch {
77
+ catch (e) {
78
+ logInternalError(`rule_preview:${matched.id}`, e);
79
+ if (getFailMode(matched.level) === "closed") {
80
+ return buildInternalErrorResult();
81
+ }
38
82
  return { pass: true };
39
83
  }
40
84
  return { pass: false, level: matched.level, preview, rule_id: matched.id };