@wowok/agent-mcp 2.6.1 → 2.6.4

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 (246) hide show
  1. package/dist/customer/customer-advice.d.ts +31 -0
  2. package/dist/customer/customer-advice.js +129 -0
  3. package/dist/customer/index.d.ts +2 -0
  4. package/dist/customer/index.js +2 -0
  5. package/dist/customer/info-puzzle.d.ts +9 -2
  6. package/dist/customer/info-puzzle.js +34 -7
  7. package/dist/customer/order-monitor.d.ts +2 -0
  8. package/dist/customer/order-monitor.js +3 -2
  9. package/dist/customer/post-purchase.d.ts +2 -0
  10. package/dist/customer/post-purchase.js +6 -5
  11. package/dist/customer/preorder-compare.d.ts +24 -0
  12. package/dist/customer/preorder-compare.js +34 -0
  13. package/dist/customer/reminder-system.d.ts +2 -0
  14. package/dist/customer/reminder-system.js +2 -1
  15. package/dist/customer/risk-assessment.js +30 -7
  16. package/dist/customer/types.d.ts +7 -0
  17. package/dist/examples/arbitration-dispute-create.json +41 -0
  18. package/dist/examples/arbitration-vote-weighted.json +35 -0
  19. package/dist/examples/arbitration-voting-guard-add.json +38 -0
  20. package/dist/examples/demand-present-service.json +33 -0
  21. package/dist/examples/gen-passport-verify-guard.json +48 -0
  22. package/dist/examples/guard-template-balance-check.json +59 -0
  23. package/dist/examples/guard-template-time-lock.json +60 -0
  24. package/dist/examples/insurance-guard-claim-timelock.json +75 -0
  25. package/dist/examples/insurance-guard-withdraw-allocation.json +96 -0
  26. package/dist/examples/insurance-machine-create-publish.json +75 -0
  27. package/dist/examples/insurance-service-allocators-publish.json +56 -0
  28. package/dist/examples/machine-multisig-threshold.json +86 -0
  29. package/dist/examples/machine-template-7node-rental.json +119 -0
  30. package/dist/examples/payment-scenario-bound.json +45 -0
  31. package/dist/examples/rental-ziroom-machine-create.json +149 -0
  32. package/dist/examples/rental-ziroom-permission-create.json +42 -0
  33. package/dist/examples/rental-ziroom-service-create.json +89 -0
  34. package/dist/examples/retail-adv-guard-customer-win-create.json +80 -0
  35. package/dist/examples/retail-adv-guard-messenger-proof-create.json +65 -0
  36. package/dist/examples/retail-adv-guard-reward-timeout-create.json +92 -0
  37. package/dist/examples/retail-adv-reward-guard-add.json +51 -0
  38. package/dist/examples/retail-myshop-allocation-activate.json +55 -0
  39. package/dist/examples/retail-myshop-arbitration-create.json +40 -0
  40. package/dist/examples/retail-myshop-contact-create.json +43 -0
  41. package/dist/examples/retail-myshop-order-create.json +56 -0
  42. package/dist/examples/retail-myshop-progress-operate.json +38 -0
  43. package/dist/examples/retail-myshop-reward-create.json +35 -0
  44. package/dist/examples/retail-myshop-service-create.json +88 -0
  45. package/dist/examples/service-discount-issue.json +46 -0
  46. package/dist/examples/threebody-guard-create.json +56 -0
  47. package/dist/examples/threebody-machine-create.json +72 -0
  48. package/dist/examples/threebody-permission-create.json +38 -0
  49. package/dist/examples/threebody-service-allocators.json +49 -0
  50. package/dist/examples/travel-guard-time-lock.json +69 -0
  51. package/dist/examples/travel-guard-weather-oracle.json +70 -0
  52. package/dist/examples/travel-machine-create.json +136 -0
  53. package/dist/examples/travel-repository-create.json +47 -0
  54. package/dist/examples/travel-service-create.json +102 -0
  55. package/dist/examples/travel-treasury-create.json +34 -0
  56. package/dist/examples/treasury-deposit.json +37 -0
  57. package/dist/examples/treasury-withdraw.json +38 -0
  58. package/dist/extensions/business-modules.d.ts +49 -0
  59. package/dist/extensions/business-modules.js +287 -0
  60. package/dist/extensions/capability-manifest.js +216 -29
  61. package/dist/extensions/constraint-registry.js +21 -19
  62. package/dist/extensions/metric-registry.js +14 -14
  63. package/dist/extensions/mode-evaluator.js +16 -16
  64. package/dist/extensions/modes.js +141 -49
  65. package/dist/extensions/registry.d.ts +16 -9
  66. package/dist/extensions/registry.js +132 -44
  67. package/dist/extensions/types.d.ts +2 -0
  68. package/dist/index.js +50 -0
  69. package/dist/knowledge/deployment-scanner.js +1 -1
  70. package/dist/knowledge/fund-layer.d.ts +138 -0
  71. package/dist/knowledge/fund-layer.js +969 -0
  72. package/dist/knowledge/guard-render.d.ts +57 -0
  73. package/dist/knowledge/guard-render.js +700 -0
  74. package/dist/knowledge/guard-submission-prompt.d.ts +31 -0
  75. package/dist/knowledge/guard-submission-prompt.js +171 -0
  76. package/dist/knowledge/guard-templates.d.ts +10 -0
  77. package/dist/knowledge/guard-templates.js +50 -0
  78. package/dist/knowledge/index.d.ts +2 -2
  79. package/dist/knowledge/index.js +2 -2
  80. package/dist/knowledge/machine-ledger.js +1 -1
  81. package/dist/knowledge/machine-render.d.ts +41 -0
  82. package/dist/knowledge/machine-render.js +565 -0
  83. package/dist/knowledge/machine-risk.js +4 -1
  84. package/dist/knowledge/machine-templates.js +4 -4
  85. package/dist/knowledge/progress-context.js +1 -1
  86. package/dist/knowledge/progress-ledger.js +3 -3
  87. package/dist/knowledge/progress-templates.js +1 -1
  88. package/dist/knowledge/progress-translation.js +1 -1
  89. package/dist/knowledge/reward-confirm.js +2 -2
  90. package/dist/knowledge/reward-puzzle.js +1 -1
  91. package/dist/knowledge/reward-risk.js +9 -9
  92. package/dist/knowledge/reward-templates.js +2 -2
  93. package/dist/knowledge/safety-rules.d.ts +83 -1
  94. package/dist/knowledge/safety-rules.js +166 -2
  95. package/dist/knowledge/scenario-modes.d.ts +1 -1
  96. package/dist/knowledge/scenario-modes.js +13 -11
  97. package/dist/knowledge/service-confirm.d.ts +1 -1
  98. package/dist/knowledge/service-confirm.js +3 -3
  99. package/dist/knowledge/service-context.js +1 -1
  100. package/dist/knowledge/service-ledger.js +1 -1
  101. package/dist/knowledge/service-risk.d.ts +1 -1
  102. package/dist/knowledge/service-risk.js +3 -3
  103. package/dist/knowledge/service-templates.js +2 -2
  104. package/dist/knowledge/service-translation.d.ts +1 -1
  105. package/dist/knowledge/service-translation.js +7 -7
  106. package/dist/knowledge/template-registry.d.ts +48 -0
  107. package/dist/knowledge/template-registry.js +341 -0
  108. package/dist/knowledge/tool-constraints.js +6 -6
  109. package/dist/knowledge/tools-reference.js +11 -8
  110. package/dist/participation/merchant-interest.d.ts +32 -0
  111. package/dist/participation/merchant-interest.js +100 -0
  112. package/dist/participation/radar-core.d.ts +104 -0
  113. package/dist/participation/radar-core.js +269 -0
  114. package/dist/project/context-assembly.js +8 -0
  115. package/dist/project/deployment-bridge.js +6 -5
  116. package/dist/project/deployment-doc.js +5 -5
  117. package/dist/project/edit-planner.d.ts +123 -0
  118. package/dist/project/edit-planner.js +1342 -0
  119. package/dist/project/evaluation.d.ts +36 -0
  120. package/dist/project/evaluation.js +734 -68
  121. package/dist/project/game-theory.d.ts +43 -0
  122. package/dist/project/game-theory.js +177 -0
  123. package/dist/project/graph-builder.js +7 -1
  124. package/dist/project/handlers.d.ts +137 -2
  125. package/dist/project/handlers.js +423 -51
  126. package/dist/project/intent-analyzer.d.ts +71 -0
  127. package/dist/project/intent-analyzer.js +149 -0
  128. package/dist/project/machine-nodes.d.ts +2 -0
  129. package/dist/project/machine-nodes.js +36 -0
  130. package/dist/project/merchant-guide.d.ts +165 -0
  131. package/dist/project/merchant-guide.js +264 -0
  132. package/dist/project/mode-actions.d.ts +199 -0
  133. package/dist/project/mode-actions.js +309 -0
  134. package/dist/project/participation-radar.d.ts +18 -0
  135. package/dist/project/participation-radar.js +428 -0
  136. package/dist/project/pipeline-actions.d.ts +101 -0
  137. package/dist/project/pipeline-actions.js +109 -0
  138. package/dist/project/semantic-graph.d.ts +95 -0
  139. package/dist/project/semantic-graph.js +245 -0
  140. package/dist/project/stage-gate.js +4 -4
  141. package/dist/schema/call/allocation.d.ts +11 -11
  142. package/dist/schema/call/allocation.js +13 -3
  143. package/dist/schema/call/arbitration.d.ts +21 -21
  144. package/dist/schema/call/arbitration.js +30 -9
  145. package/dist/schema/call/base.d.ts +2 -2
  146. package/dist/schema/call/base.js +1 -1
  147. package/dist/schema/call/bridge.d.ts +127 -127
  148. package/dist/schema/call/bridge.js +12 -12
  149. package/dist/schema/call/contact.d.ts +3 -3
  150. package/dist/schema/call/contact.js +2 -2
  151. package/dist/schema/call/demand.d.ts +3 -3
  152. package/dist/schema/call/demand.js +2 -2
  153. package/dist/schema/call/guard.d.ts +11 -11
  154. package/dist/schema/call/guard.js +2 -2
  155. package/dist/schema/call/machine.d.ts +2072 -679
  156. package/dist/schema/call/machine.js +51 -5
  157. package/dist/schema/call/order.d.ts +7 -7
  158. package/dist/schema/call/order.js +3 -6
  159. package/dist/schema/call/payment.d.ts +3 -3
  160. package/dist/schema/call/permission.d.ts +3 -3
  161. package/dist/schema/call/permission.js +2 -2
  162. package/dist/schema/call/personal.d.ts +337 -3
  163. package/dist/schema/call/personal.js +10 -0
  164. package/dist/schema/call/progress.d.ts +177 -9
  165. package/dist/schema/call/progress.js +7 -3
  166. package/dist/schema/call/proof.d.ts +6 -6
  167. package/dist/schema/call/repository.d.ts +3 -3
  168. package/dist/schema/call/repository.js +2 -2
  169. package/dist/schema/call/reward.d.ts +57 -57
  170. package/dist/schema/call/reward.js +3 -3
  171. package/dist/schema/call/semantic.js +48 -2
  172. package/dist/schema/call/service.d.ts +285 -113
  173. package/dist/schema/call/service.js +92 -28
  174. package/dist/schema/call/treasury.d.ts +57 -57
  175. package/dist/schema/call/treasury.js +3 -3
  176. package/dist/schema/common/index.d.ts +2 -0
  177. package/dist/schema/common/index.js +46 -10
  178. package/dist/schema/local/index.js +5 -1
  179. package/dist/schema/messenger/index.js +4 -1
  180. package/dist/schema/operations.d.ts +1318 -317
  181. package/dist/schema/operations.js +76 -7
  182. package/dist/schema/project/index.d.ts +5662 -164
  183. package/dist/schema/project/index.js +1136 -5
  184. package/dist/schema/query/index.d.ts +580 -19
  185. package/dist/schema/query/index.js +88 -36
  186. package/dist/schema/schema-query/index.d.ts +59 -3
  187. package/dist/schema/schema-query/index.js +45 -6
  188. package/dist/schema/trust/index.d.ts +1012 -6
  189. package/dist/schema/trust/index.js +212 -11
  190. package/dist/schema/utils/node-parser.js +13 -0
  191. package/dist/schema/utils/object-type-utils.d.ts +12 -0
  192. package/dist/schema/utils/object-type-utils.js +35 -0
  193. package/dist/schema/utils/permission-machine-check.d.ts +49 -0
  194. package/dist/schema/utils/permission-machine-check.js +121 -0
  195. package/dist/schema/utils/skills-recommendation.d.ts +2 -0
  196. package/dist/schema/utils/skills-recommendation.js +77 -0
  197. package/dist/schema-query/index.d.ts +17 -1
  198. package/dist/schema-query/index.js +359 -3
  199. package/dist/schemas/account_operation.schema.json +1 -1
  200. package/dist/schemas/bridge_operation.schema.json +14 -7
  201. package/dist/schemas/guard2file.schema.json +2 -0
  202. package/dist/schemas/index.json +1 -1
  203. package/dist/schemas/machineNode2file.schema.json +2 -0
  204. package/dist/schemas/messenger_operation.schema.json +1 -1
  205. package/dist/schemas/onchain_events.output.json +1 -1
  206. package/dist/schemas/onchain_operations.output.json +2820 -0
  207. package/dist/schemas/onchain_operations.schema.json +255 -65
  208. package/dist/schemas/onchain_operations_allocation.schema.json +7 -6
  209. package/dist/schemas/onchain_operations_arbitration.schema.json +14 -10
  210. package/dist/schemas/onchain_operations_contact.schema.json +4 -3
  211. package/dist/schemas/onchain_operations_demand.schema.json +4 -3
  212. package/dist/schemas/onchain_operations_gen_passport.schema.json +4 -2
  213. package/dist/schemas/onchain_operations_gen_proof.schema.json +2 -0
  214. package/dist/schemas/onchain_operations_guard.schema.json +579 -1
  215. package/dist/schemas/onchain_operations_machine.schema.json +5 -4
  216. package/dist/schemas/onchain_operations_order.schema.json +7 -6
  217. package/dist/schemas/onchain_operations_payment.schema.json +2 -1
  218. package/dist/schemas/onchain_operations_permission.schema.json +3 -2
  219. package/dist/schemas/onchain_operations_personal.schema.json +37 -0
  220. package/dist/schemas/onchain_operations_progress.schema.json +91 -4
  221. package/dist/schemas/onchain_operations_proof.schema.json +2 -1
  222. package/dist/schemas/onchain_operations_repository.schema.json +4 -3
  223. package/dist/schemas/onchain_operations_reward.schema.json +7 -6
  224. package/dist/schemas/onchain_operations_service.schema.json +80 -19
  225. package/dist/schemas/onchain_operations_treasury.schema.json +5 -4
  226. package/dist/schemas/onchain_table_data.output.json +1 -1
  227. package/dist/schemas/onchain_table_data.schema.json +10 -9
  228. package/dist/schemas/project_operation.output.json +3318 -57
  229. package/dist/schemas/project_operation.schema.json +728 -4
  230. package/dist/schemas/query_toolkit.output.json +16 -16
  231. package/dist/schemas/query_toolkit.schema.json +40 -3
  232. package/dist/schemas/schema_query.output.json +65 -2
  233. package/dist/schemas/schema_query.schema.json +31 -5
  234. package/dist/schemas/trust_score.output.json +392 -1
  235. package/dist/schemas/trust_score.schema.json +275 -1
  236. package/dist/schemas/wowok_buildin_info.output.json +81 -8
  237. package/dist/schemas/wowok_buildin_info.schema.json +46 -2
  238. package/dist/tools/handlers/onchain.js +636 -6
  239. package/dist/tools/handlers/project.js +71 -2
  240. package/dist/tools/handlers/query.js +117 -2
  241. package/dist/tools/handlers/schema-query.js +65 -1
  242. package/dist/tools/handlers/trust.js +192 -6
  243. package/dist/tools/index.d.ts +8 -0
  244. package/dist/tools/index.js +229 -15
  245. package/dist/tools/wrap.js +194 -15
  246. package/package.json +2 -2
@@ -1,3 +1,4 @@
1
+ import { UserModeStorage } from "@wowok/wowok";
1
2
  import { CapabilityRegistry } from "./capability-manifest.js";
2
3
  import { ModeEvaluator } from "./mode-evaluator.js";
3
4
  import { MetricRegistry } from "./metric-registry.js";
@@ -10,6 +11,8 @@ export class IndustryModeRegistry {
10
11
  aliases = new Map();
11
12
  evaluator;
12
13
  initialized = false;
14
+ persistence = new UserModeStorage();
15
+ userModesLoaded = false;
13
16
  static Instance() {
14
17
  if (!IndustryModeRegistry.instance) {
15
18
  IndustryModeRegistry.instance = new IndustryModeRegistry();
@@ -100,7 +103,8 @@ export class IndustryModeRegistry {
100
103
  }
101
104
  return this.evaluator.evaluateMigration(source, target);
102
105
  }
103
- registerUserMode(mode, userId) {
106
+ async registerUserMode(mode, userId) {
107
+ await this.ensureUserModesLoaded();
104
108
  if (!mode.name || !mode.owner || !mode.machine_shape)
105
109
  return false;
106
110
  if (mode.source !== "custom")
@@ -116,13 +120,15 @@ export class IndustryModeRegistry {
116
120
  mode.evolution_history = [{
117
121
  version: mode.version || "v1",
118
122
  changed_at: Date.now(),
119
- changes: ["初始注册(registerUserMode)"],
123
+ changes: ["Initial registration (registerUserMode)"],
120
124
  }];
121
125
  }
122
126
  this.userModes.set(userKey, mode);
127
+ await this.persistUserMode(mode);
123
128
  return true;
124
129
  }
125
- deriveMode(sourceMode, modifications, userId, newName, newDisplayName) {
130
+ async deriveMode(sourceMode, modifications, userId, newName, newDisplayName) {
131
+ await this.ensureUserModesLoaded();
126
132
  const source = this.getMode(sourceMode);
127
133
  if (!source)
128
134
  return undefined;
@@ -161,13 +167,15 @@ export class IndustryModeRegistry {
161
167
  evolution_history: [{
162
168
  version: "v1",
163
169
  changed_at: Date.now(),
164
- changes: [`从 builtin '${sourceMode}' 派生`],
170
+ changes: [`Derived from builtin '${sourceMode}'`],
165
171
  }],
166
172
  };
167
173
  this.userModes.set(userKey, derived);
174
+ await this.persistUserMode(derived);
168
175
  return derived;
169
176
  }
170
- evolveMode(modeName, updates, userId, changeDescription, bumpVersion = true) {
177
+ async evolveMode(modeName, updates, userId, changeDescription, bumpVersion = true) {
178
+ await this.ensureUserModesLoaded();
171
179
  const userKey = this.userModeKey(userId, modeName);
172
180
  const existing = this.userModes.get(userKey);
173
181
  if (!existing)
@@ -193,9 +201,11 @@ export class IndustryModeRegistry {
193
201
  version: newVersion,
194
202
  };
195
203
  this.userModes.set(userKey, evolved);
204
+ await this.persistUserMode(evolved);
196
205
  return evolved;
197
206
  }
198
- listUserModes(userId) {
207
+ async listUserModes(userId) {
208
+ await this.ensureUserModesLoaded();
199
209
  const result = [];
200
210
  for (const mode of this.userModes.values()) {
201
211
  if (mode.owner === userId) {
@@ -204,26 +214,71 @@ export class IndustryModeRegistry {
204
214
  }
205
215
  return result;
206
216
  }
207
- getUserMode(modeName, userId) {
217
+ async getUserMode(modeName, userId) {
218
+ await this.ensureUserModesLoaded();
208
219
  const userKey = this.userModeKey(userId, modeName);
209
220
  return this.userModes.get(userKey);
210
221
  }
211
- unregisterUserMode(modeName, userId) {
222
+ async unregisterUserMode(modeName, userId) {
223
+ await this.ensureUserModesLoaded();
212
224
  const userKey = this.userModeKey(userId, modeName);
213
- return this.userModes.delete(userKey);
225
+ const removed = this.userModes.delete(userKey);
226
+ if (removed) {
227
+ await this.unpersistUserMode(userId, modeName);
228
+ }
229
+ return removed;
214
230
  }
215
231
  userModeKey(owner, name) {
216
232
  return `${owner}:${name}`;
217
233
  }
234
+ async ensureUserModesLoaded() {
235
+ if (this.userModesLoaded)
236
+ return;
237
+ this.userModesLoaded = true;
238
+ try {
239
+ const rows = await this.persistence.list();
240
+ for (const row of rows) {
241
+ try {
242
+ const mode = JSON.parse(row.data);
243
+ if (mode?.name && mode?.owner && mode?.machine_shape) {
244
+ this.userModes.set(this.userModeKey(row.owner, row.name), mode);
245
+ }
246
+ }
247
+ catch {
248
+ console.warn(`[IndustryModeRegistry] Skipping corrupt user_modes row '${row.owner}:${row.name}'.`);
249
+ }
250
+ }
251
+ }
252
+ catch (err) {
253
+ console.warn("[IndustryModeRegistry] Failed to load persisted user modes:", err.message);
254
+ }
255
+ }
256
+ async persistUserMode(mode) {
257
+ try {
258
+ await this.persistence.save(mode.owner, mode.name, JSON.stringify(mode));
259
+ }
260
+ catch (err) {
261
+ console.warn(`[IndustryModeRegistry] Failed to persist user mode '${mode.owner}:${mode.name}':`, err.message);
262
+ }
263
+ }
264
+ async unpersistUserMode(owner, name) {
265
+ try {
266
+ await this.persistence.delete(owner, name);
267
+ }
268
+ catch (err) {
269
+ console.warn(`[IndustryModeRegistry] Failed to delete persisted user mode '${owner}:${name}':`, err.message);
270
+ }
271
+ }
218
272
  bumpPatchVersion(version) {
219
- const parts = version.replace(/^v/, "").split(".");
273
+ const stripped = version.replace(/^v/, "");
274
+ const parts = stripped.split(".");
220
275
  if (parts.length < 2)
221
- return `v${version}.1`;
276
+ return `v${stripped}.1`;
222
277
  const patch = parseInt(parts[1] ?? "0", 10);
223
278
  parts[1] = String(patch + 1);
224
279
  return `v${parts.join(".")}`;
225
280
  }
226
- applyTemplate(name, intent, context) {
281
+ async applyTemplate(name, intent, context) {
227
282
  const builtinMode = this.getMode(name);
228
283
  if (builtinMode) {
229
284
  const blueprint = this.doApplyTemplate(builtinMode, intent, context);
@@ -232,7 +287,7 @@ export class IndustryModeRegistry {
232
287
  }
233
288
  if (name.includes(":")) {
234
289
  const [owner, modeName] = name.split(":", 2);
235
- const userMode = this.getUserMode(modeName, owner);
290
+ const userMode = await this.getUserMode(modeName, owner);
236
291
  if (userMode) {
237
292
  const blueprint = this.doApplyTemplate(userMode, intent, context);
238
293
  this.recordCapabilitiesUsed(userMode);
@@ -247,8 +302,8 @@ export class IndustryModeRegistry {
247
302
  this.recordCapabilitiesUsed(general);
248
303
  return blueprint;
249
304
  }
250
- applyUserMode(modeName, userId, intent, context) {
251
- const userMode = this.getUserMode(modeName, userId);
305
+ async applyUserMode(modeName, userId, intent, context) {
306
+ const userMode = await this.getUserMode(modeName, userId);
252
307
  if (!userMode) {
253
308
  throw new Error(`User mode '${modeName}' not found for user '${userId}'`);
254
309
  }
@@ -333,22 +388,33 @@ export class IndustryModeRegistry {
333
388
  const objects = [];
334
389
  objects.push(this.makeObject("permission", `${prefix}_permission`, {
335
390
  name: `${prefix}_permission`,
336
- description: `Permission: 角色权限索引(${mode.display_name})`,
391
+ description: `Permission: role permission index (${mode.display_name})`,
337
392
  permission_indexes: this.buildPermissionIndexes(mode),
338
393
  tags: [`industry:${mode.name}`],
339
394
  }));
340
- objects.push(this.makeObject("guard", `${prefix}_guard_buy`, {
341
- name: `${prefix}_guard_buy`,
342
- description: `Guard: 下单验证(${mode.display_name})`,
343
- host: "service",
344
- templates: mode.guards.filter(g => g.host === "service").map(g => g.template_id),
345
- tags: [`industry:${mode.name}`],
346
- }));
395
+ const serviceGuardName = this.getFirstServiceGuardName(mode, prefix);
396
+ for (const guard of mode.guards) {
397
+ const shortName = this.deriveGuardShortName(guard.template_id);
398
+ const guardName = `${prefix}_guard_${shortName}`;
399
+ objects.push(this.makeObject("guard", guardName, {
400
+ name: guardName,
401
+ description: `Guard: ${guard.purpose} (${mode.display_name})`,
402
+ host: guard.host,
403
+ template_id: guard.template_id,
404
+ tags: [`industry:${mode.name}`, `host:${guard.host}`],
405
+ }));
406
+ }
347
407
  objects.push(this.makeObject("machine", `${prefix}_machine`, {
348
408
  name: `${prefix}_machine`,
349
- description: `Machine: 工作流拓扑(${mode.display_name})— ${mode.machine_shape.length} 节点`,
409
+ description: `Machine: workflow topology (${mode.display_name}) — ${mode.machine_shape.length} nodes`,
350
410
  nodes: mode.machine_shape.map(n => ({ name: n.name, role: n.role })),
351
- guard_templates: mode.guards.filter(g => g.host === "machine").map(g => g.template_id),
411
+ guard_objects: mode.guards
412
+ .filter(g => g.host === "machine")
413
+ .map(g => ({
414
+ template_id: g.template_id,
415
+ object_name: `${prefix}_guard_${this.deriveGuardShortName(g.template_id)}`,
416
+ purpose: g.purpose,
417
+ })),
352
418
  permission: `${prefix}_permission`,
353
419
  entry_node_forward_hint: {
354
420
  entry_node_name: mode.machine_shape[0]?.name ?? "paid",
@@ -366,31 +432,32 @@ export class IndustryModeRegistry {
366
432
  }, true));
367
433
  objects.push(this.makeObject("treasury", `${prefix}_treasury`, {
368
434
  name: `${prefix}_treasury`,
369
- description: `Treasury: 资金托管(${mode.display_name})`,
435
+ description: `Treasury: fund escrow (${mode.display_name})`,
370
436
  owner_receive: true,
371
437
  tags: [`industry:${mode.name}`],
372
438
  }));
373
439
  objects.push(this.makeObject("allocation", `${prefix}_allocation`, {
374
440
  name: `${prefix}_allocation`,
375
- description: `Allocation: 分账策略(${mode.display_name})— ${mode.allocator.description}`,
441
+ description: `Allocation: allocation strategy (${mode.display_name}) — ${mode.allocator.description}`,
376
442
  strategy: mode.allocator,
377
443
  treasury: `${prefix}_treasury`,
378
- guard: `${prefix}_guard_buy`,
444
+ guard: serviceGuardName,
379
445
  tags: [`industry:${mode.name}`],
380
446
  }));
381
447
  objects.push(this.makeObject("service", `${prefix}_service`, {
382
448
  name: `${prefix}_service`,
383
- description: `Service: 业务服务(${mode.display_name})— ${intent.slice(0, 100)}`,
449
+ description: `Service: business service (${mode.display_name}) — ${intent.slice(0, 100)}`,
384
450
  machine: `${prefix}_machine`,
385
- buy_guard: `${prefix}_guard_buy`,
451
+ buy_guard: serviceGuardName,
386
452
  permission: `${prefix}_permission`,
387
453
  order_allocators: [`${prefix}_allocation`],
388
454
  compensation_fund_balance: 0,
389
455
  compensation_fund_required: mode.risk_constraints?.require_compensation_fund ?? false,
456
+ compensation_fund_coverage_ratio: mode.risk_constraints?.compensation_fund_coverage_ratio ?? 5,
390
457
  compensation_fund_add_hint: "Call service.compensation_fund_add with a Coin<T> to deposit. " +
391
458
  "The compensation_fund is a Balance<T> (numeric), not a Treasury object reference. " +
392
459
  "Without deposit, arbitration rulings that award refunds to buyers cannot be paid out. " +
393
- "Recommend 5× the max single-order amount (P1-1 evaluation rule).",
460
+ `Recommend ${mode.risk_constraints?.compensation_fund_coverage_ratio ?? 5}× the max single-order amount (P1-1 evaluation rule, industry: ${mode.name}).`,
394
461
  arbitrations: [`${prefix}_arb`],
395
462
  rewards: [`${prefix}_reward`],
396
463
  business_intent: intent,
@@ -399,25 +466,25 @@ export class IndustryModeRegistry {
399
466
  }, true));
400
467
  objects.push(this.makeObject("progress", `${prefix}_progress`, {
401
468
  name: `${prefix}_progress`,
402
- description: `Progress: 订单履约进度(${mode.display_name})`,
469
+ description: `Progress: order fulfillment progress (${mode.display_name})`,
403
470
  parent: `${prefix}_machine`,
404
471
  tags: [`industry:${mode.name}`],
405
472
  }));
406
473
  objects.push(this.makeObject("arb", `${prefix}_arb`, {
407
474
  name: `${prefix}_arb`,
408
- description: `Arbitration: 仲裁规则(${mode.display_name})— ${mode.key_risk}`,
475
+ description: `Arbitration: arbitration rules (${mode.display_name}) — ${mode.key_risk}`,
409
476
  guard: `${prefix}_guard_buy`,
410
477
  tags: [`industry:${mode.name}`],
411
478
  }));
412
479
  objects.push(this.makeObject("reward", `${prefix}_reward`, {
413
480
  name: `${prefix}_reward`,
414
- description: `Reward: 激励规则(${mode.display_name})`,
481
+ description: `Reward: incentive rules (${mode.display_name})`,
415
482
  claim_guard: `${prefix}_guard_buy`,
416
483
  tags: [`industry:${mode.name}`],
417
484
  }));
418
485
  objects.push(this.makeObject("contact", `${prefix}_contact`, {
419
486
  name: `${prefix}_contact`,
420
- description: `Contact: 客服联系(${mode.display_name})`,
487
+ description: `Contact: customer service contact (${mode.display_name})`,
421
488
  tags: [`industry:${mode.name}`],
422
489
  }));
423
490
  return objects;
@@ -501,21 +568,21 @@ export class IndustryModeRegistry {
501
568
  ?? "";
502
569
  const service = find(`${prefix}_service`);
503
570
  const machine = find(`${prefix}_machine`);
504
- const guard = find(`${prefix}_guard_buy`);
505
571
  const permission = find(`${prefix}_permission`);
506
572
  const allocation = find(`${prefix}_allocation`);
507
573
  const treasury = find(`${prefix}_treasury`);
508
574
  const arb = find(`${prefix}_arb`);
509
575
  const reward = find(`${prefix}_reward`);
510
576
  const progress = find(`${prefix}_progress`);
511
- if (!service || !machine || !guard || !permission) {
577
+ const allGuards = objects.filter(o => o.object_type === "guard");
578
+ const serviceGuard = allGuards.find(g => g.config?.host === "service");
579
+ const machineGuards = allGuards.filter(g => g.config?.host === "machine");
580
+ if (!service || !machine || !permission) {
512
581
  const missing = [];
513
582
  if (!service)
514
583
  missing.push("service");
515
584
  if (!machine)
516
585
  missing.push("machine");
517
- if (!guard)
518
- missing.push("guard");
519
586
  if (!permission)
520
587
  missing.push("permission");
521
588
  console.warn(`[buildEdges] Missing core objects: ${missing.join(", ")}. ` +
@@ -524,7 +591,9 @@ export class IndustryModeRegistry {
524
591
  return edges;
525
592
  }
526
593
  edges.push(this.makeEdge(service, machine, "machine", "service.machine", true));
527
- edges.push(this.makeEdge(service, guard, "buy_guard", "service.buy_guard", true));
594
+ if (serviceGuard) {
595
+ edges.push(this.makeEdge(service, serviceGuard, "buy_guard", "service.buy_guard", true));
596
+ }
528
597
  edges.push(this.makeEdge(service, permission, "permission", "service.permission", true));
529
598
  if (allocation)
530
599
  edges.push(this.makeEdge(service, allocation, "order_allocators", "service.order_allocators", true));
@@ -533,12 +602,15 @@ export class IndustryModeRegistry {
533
602
  if (reward)
534
603
  edges.push(this.makeEdge(service, reward, "rewards", "service.rewards", false));
535
604
  edges.push(this.makeEdge(machine, permission, "permission", "machine.permission", false));
605
+ for (const mg of machineGuards) {
606
+ edges.push(this.makeEdge(machine, mg, "guard", "machine.forwards.guard", false));
607
+ }
536
608
  if (progress)
537
609
  edges.push(this.makeEdge(progress, machine, "parent", "progress.parent", false));
538
610
  if (allocation && treasury)
539
611
  edges.push(this.makeEdge(allocation, treasury, "treasury", "allocation.treasury", false));
540
- if (allocation && guard)
541
- edges.push(this.makeEdge(allocation, guard, "buy_guard", "allocation.guard", false));
612
+ if (allocation && serviceGuard)
613
+ edges.push(this.makeEdge(allocation, serviceGuard, "buy_guard", "allocation.guard", false));
542
614
  return edges;
543
615
  }
544
616
  makeEdge(from, to, edge_kind, field_path, required_at_publish) {
@@ -590,7 +662,7 @@ export class IndustryModeRegistry {
590
662
  const service = objects.find(o => o.object_type === "service");
591
663
  return [{
592
664
  scenario_id: `${mode.name}_primary`,
593
- description: `${mode.display_name} 主流程:${intent.slice(0, 80)}`,
665
+ description: `${mode.display_name} main flow: ${intent.slice(0, 80)}`,
594
666
  primary_object: service?.entry_id ?? "",
595
667
  supporting_objects: objects.filter(o => o.object_type !== "service").map(o => o.entry_id),
596
668
  }];
@@ -607,6 +679,22 @@ export class IndustryModeRegistry {
607
679
  catch {
608
680
  }
609
681
  }
682
+ deriveGuardShortName(templateId) {
683
+ if (templateId.startsWith("tpl_")) {
684
+ const parts = templateId.split("_");
685
+ return parts[parts.length - 1] || templateId;
686
+ }
687
+ const match = templateId.match(/^([a-z]+)_guard_/);
688
+ if (match)
689
+ return match[1];
690
+ return templateId.split("_")[0] || templateId;
691
+ }
692
+ getFirstServiceGuardName(mode, prefix) {
693
+ const serviceGuard = mode.guards.find(g => g.host === "service");
694
+ if (!serviceGuard)
695
+ return "";
696
+ return `${prefix}_guard_${this.deriveGuardShortName(serviceGuard.template_id)}`;
697
+ }
610
698
  makeObject(type, name, config, publish_required = false) {
611
699
  return {
612
700
  entry_id: `${type}:${name}`,
@@ -626,4 +714,4 @@ export class IndustryModeRegistry {
626
714
  export function getIndustryModeRegistry() {
627
715
  return IndustryModeRegistry.Instance();
628
716
  }
629
- export const INDUSTRY_MODE_REGISTRY_VERSION = 2.1;
717
+ export const INDUSTRY_MODE_REGISTRY_VERSION = 2.2;
@@ -68,6 +68,7 @@ export interface ModeRiskConstraints {
68
68
  require_compensation_fund: boolean;
69
69
  require_wip_evidence: boolean;
70
70
  max_single_transaction?: number;
71
+ compensation_fund_coverage_ratio?: number;
71
72
  other_constraints?: string[];
72
73
  }
73
74
  export interface ModeApplicableConditions {
@@ -110,6 +111,7 @@ export interface IndustryMode {
110
111
  applicable_conditions: ModeApplicableConditions;
111
112
  similar_industries?: string[];
112
113
  novel_capabilities?: string[];
114
+ disabled_builtin_constraints?: string[];
113
115
  }
114
116
  export interface UserDefinedMode extends IndustryMode {
115
117
  owner: string;
package/dist/index.js CHANGED
@@ -14,6 +14,47 @@ import { registerAllTools } from "./tools/index.js";
14
14
  if (process.env.WOWOK_TELEMETRY === "false" || process.env.WOWOK_TELEMETRY === "0") {
15
15
  setTelemetryEnabled(false);
16
16
  }
17
+ process.on("unhandledRejection", (reason, promise) => {
18
+ const reasonStr = reason instanceof Error
19
+ ? `${reason.name}: ${reason.message}\n${reason.stack ?? ""}`
20
+ : String(reason);
21
+ console.error(`[unhandledRejection] ${new Date().toISOString()}`);
22
+ console.error(` reason: ${reasonStr}`);
23
+ });
24
+ process.on("uncaughtException", (error) => {
25
+ console.error(`[uncaughtException] ${new Date().toISOString()}`);
26
+ console.error(` name: ${error.name}`);
27
+ console.error(` message: ${error.message}`);
28
+ console.error(` stack: ${error.stack ?? ""}`);
29
+ });
30
+ process.on("beforeExit", (code) => {
31
+ console.error(`[beforeExit] ${new Date().toISOString()} code=${code} — event loop empty, process would exit`);
32
+ console.error(` active handles: ${process._getActiveHandles?.()?.length ?? "?"}`);
33
+ console.error(` active requests: ${process._getActiveRequests?.()?.length ?? "?"}`);
34
+ });
35
+ process.on("exit", (code) => {
36
+ console.error(`[exit] ${new Date().toISOString()} code=${code} — process exiting`);
37
+ });
38
+ process.stdin.on("end", () => {
39
+ console.error(`[stdin end] ${new Date().toISOString()} — MCP client closed stdin`);
40
+ });
41
+ process.stdin.on("close", () => {
42
+ console.error(`[stdin close] ${new Date().toISOString()} — stdin stream closed`);
43
+ });
44
+ let keepaliveTimer = null;
45
+ function startKeepalive() {
46
+ if (keepaliveTimer)
47
+ return;
48
+ keepaliveTimer = setInterval(() => {
49
+ const mem = process.memoryUsage();
50
+ const heapUsedMB = Math.round(mem.heapUsed / 1024 / 1024);
51
+ const heapTotalMB = Math.round(mem.heapTotal / 1024 / 1024);
52
+ const rssMB = Math.round(mem.rss / 1024 / 1024);
53
+ const level = heapUsedMB > 1200 ? "WARNING" : heapUsedMB > 800 ? "INFO" : "DEBUG";
54
+ console.error(`[memory ${level}] heap=${heapUsedMB}MB/${heapTotalMB}MB rss=${rssMB}MB`);
55
+ }, 60_000);
56
+ }
57
+ startKeepalive();
17
58
  const SERVER_DESCRIPTION = `WoWok MCP Server - Making It Easy for AI Agents to Communicate, Collaborate, Trade, and Trust.
18
59
 
19
60
  ## CRITICAL: Unified Single-Tool Architecture
@@ -210,5 +251,14 @@ async function main() {
210
251
  await server.close();
211
252
  process.exit(0);
212
253
  });
254
+ process.on("SIGTERM", async () => {
255
+ console.error(`[SIGTERM] ${new Date().toISOString()} — graceful shutdown`);
256
+ try {
257
+ await server.close();
258
+ }
259
+ catch {
260
+ }
261
+ process.exit(0);
262
+ });
213
263
  }
214
264
  main().catch(console.error);
@@ -672,7 +672,7 @@ export function analyzeMachineAndServiceReadiness(input) {
672
672
  add(findings, "D-20", "warning", `No Service block in the deployment doc includes a compensation_fund_add step. ` +
673
673
  `Without deposit, arbitration rulings that award refunds to buyers cannot be paid out from the Service. ` +
674
674
  `Industries like freelance may not require this (info), but rental/travel/education typically do.`, "§3.2 / §4.2 Service blocks", `Add a compensation_fund_add step for the Service (e.g., data.compensation_fund_add = {balance: <amount>}). ` +
675
- `Recommended: 5× the max single-order amount (P1-1 evaluation rule).`);
675
+ `Recommended: 3-10× the max single-order amount, depending on industry (subscription: 3×, retail: 5×, rental: 10×). See P1-1 evaluation rule.`);
676
676
  }
677
677
  }
678
678
  }
@@ -0,0 +1,138 @@
1
+ import type { ENTRYPOINT } from "@wowok/wowok";
2
+ export interface OfficialTokenEntry {
3
+ type: string;
4
+ symbol: string;
5
+ decimals: number;
6
+ name: string;
7
+ description: string;
8
+ }
9
+ export type TokenNetwork = "gas" | "testnet" | "mainnet";
10
+ export declare const OFFICIAL_TOKEN_REGISTRY: Record<TokenNetwork, OfficialTokenEntry[]>;
11
+ export declare function getRegistryForNetwork(network?: string): OfficialTokenEntry[];
12
+ export type TokenSource = "registry" | "cache" | "onchain";
13
+ export interface TokenResolution {
14
+ type: string;
15
+ symbol: string;
16
+ decimals: number;
17
+ name: string;
18
+ source: TokenSource;
19
+ verified: boolean;
20
+ }
21
+ export declare function findInRegistryByType(tokenType: string, network?: string): OfficialTokenEntry | undefined;
22
+ export declare function findInRegistryBySymbol(symbol: string, network?: string): OfficialTokenEntry[];
23
+ export declare function resolveTokenByType(tokenType: string, network?: ENTRYPOINT): Promise<TokenResolution | undefined>;
24
+ export declare function resolveTokensBySymbol(symbol: string, network?: ENTRYPOINT, preferredType?: string): Promise<TokenResolution[]>;
25
+ export interface ParsedAmount {
26
+ smallestUnit: bigint;
27
+ displayAmount: string;
28
+ originalInput: string | number;
29
+ tokenType: string;
30
+ tokenSymbol: string;
31
+ decimals: number;
32
+ converted: boolean;
33
+ source: TokenSource;
34
+ verified: boolean;
35
+ precision_known: boolean;
36
+ }
37
+ export declare function isAmountWithSymbol(value: unknown): boolean;
38
+ export declare function parseAmount(amount: string | number, tokenType: string, network?: ENTRYPOINT): Promise<ParsedAmount>;
39
+ export declare function smallestToDisplay(value: bigint, decimals: number): string;
40
+ export declare function displayStringToSmallest(display: string, decimals: number): bigint;
41
+ export interface FundFieldConfirmation {
42
+ path: string;
43
+ displayAmount: string;
44
+ tokenType: string;
45
+ tokenSymbol: string;
46
+ verified: boolean;
47
+ source: TokenSource;
48
+ converted: boolean;
49
+ context: string;
50
+ }
51
+ export interface TokenAmbiguity {
52
+ symbol: string;
53
+ candidates: {
54
+ type: string;
55
+ decimals: number;
56
+ source: TokenSource;
57
+ verified: boolean;
58
+ }[];
59
+ }
60
+ export interface FundConfirmationRequest {
61
+ requiresConfirmation: boolean;
62
+ reason: string;
63
+ fields: FundFieldConfirmation[];
64
+ ambiguities: TokenAmbiguity[];
65
+ message: string;
66
+ }
67
+ export declare function generateFundConfirmation(fields: FundFieldConfirmation[], ambiguities?: TokenAmbiguity[]): FundConfirmationRequest;
68
+ export interface FundProcessResult {
69
+ convertedData: any;
70
+ warnings: string[];
71
+ errors: string[];
72
+ confirmation: FundConfirmationRequest | null;
73
+ }
74
+ export interface FundProcessOptions {
75
+ objectTokenType?: string;
76
+ }
77
+ export declare function processFundOperation(data: any, operationType: string, network?: ENTRYPOINT, options?: FundProcessOptions): Promise<FundProcessResult>;
78
+ export declare function generateSkillsHint(confirmation: FundConfirmationRequest | null): string | null;
79
+ export interface ChainValueDisplay {
80
+ raw: string;
81
+ display: string;
82
+ symbol?: string;
83
+ decimals?: number;
84
+ token_type: string;
85
+ precision_known: boolean;
86
+ text: string;
87
+ }
88
+ export declare function formatChainValue(raw: string | number | bigint, tokenType: string, network?: ENTRYPOINT): Promise<ChainValueDisplay>;
89
+ export interface TokenDisplayHint {
90
+ decimals?: number;
91
+ symbol?: string;
92
+ }
93
+ export declare function registryDisplayHint(tokenType: string | undefined, network?: string): TokenDisplayHint | undefined;
94
+ export declare function clearFundResolutionCaches(): void;
95
+ export declare function knownTokenSuggestions(network?: string): string;
96
+ export declare function formatAmountText(raw: string | number | bigint, decimals?: number, symbol?: string): string;
97
+ export interface TokenValueConversion {
98
+ token_type: string;
99
+ symbol?: string;
100
+ decimals?: number;
101
+ precision_known: boolean;
102
+ direction: "raw_to_unit" | "unit_to_raw";
103
+ input: string;
104
+ output: string;
105
+ error?: string;
106
+ text: string;
107
+ }
108
+ export declare function convertTokenValue(tokenType: string, value: {
109
+ raw?: string | number | bigint;
110
+ unit?: string | number;
111
+ }, network?: ENTRYPOINT): Promise<TokenValueConversion>;
112
+ export declare const TOKEN_GENERIC_OBJECT_TYPES: readonly string[];
113
+ export declare function extractGenericTokenType(typeRaw: string | null | undefined): string | undefined;
114
+ export interface ObjectTokenResolution {
115
+ tokenType?: string;
116
+ objectType?: string;
117
+ typeRaw?: string;
118
+ }
119
+ export declare function resolveObjectTokenType(objectRef: string, network?: ENTRYPOINT): Promise<ObjectTokenResolution | undefined>;
120
+ export declare function resolveOperationObjectTokenType(data: any, operationType: string, network?: ENTRYPOINT): Promise<string | undefined>;
121
+ export interface TokenMatchValidation {
122
+ errors: string[];
123
+ warnings: string[];
124
+ objectTokenType?: string;
125
+ }
126
+ export declare function validateOperationTokenMatch(data: any, operationType: string, objectTokenType?: string, network?: ENTRYPOINT): Promise<TokenMatchValidation>;
127
+ export declare function annotateObjectMonetaryFields(obj: any, network?: ENTRYPOINT): Promise<void>;
128
+ export declare function resolveParentObjectTokenType(parentRef: string, network?: ENTRYPOINT): Promise<string | undefined>;
129
+ export declare function annotateTableItemMonetaryFields(item: any, parentTokenType: string | undefined, network?: ENTRYPOINT): Promise<void>;
130
+ export declare function annotateEventMonetaryFields(event: any, network?: ENTRYPOINT): Promise<void>;
131
+ export declare function annotateEventsMonetaryFields(events: any[], network?: ENTRYPOINT): Promise<void>;
132
+ export declare function annotateBalanceChanges(changes: any[], network?: ENTRYPOINT): Promise<void>;
133
+ export interface PreparedFundOperation extends FundProcessResult {
134
+ matchErrors: string[];
135
+ objectTokenType?: string;
136
+ blockingErrors: string[];
137
+ }
138
+ export declare function prepareFundOperation(data: any, operationType: string, network?: ENTRYPOINT): Promise<PreparedFundOperation>;