@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,9 +1,15 @@
1
1
  import { auditService } from "../../knowledge/index.js";
2
2
  import { getExperienceFeedback, recordOperationOutcome } from "../../experience/index.js";
3
3
  import { isEnabled as isRuntimeEnabled, listServices } from "../../config/index.js";
4
- import { generateReminders } from "../../customer/reminder-system.js";
4
+ import { generateReminders } from "../../customer/index.js";
5
5
  import { getProfile } from "../../experience/user-profile.js";
6
6
  import { injectEvolutionContext, recordIndustrySignal } from "../../knowledge/flywheel-loop.js";
7
+ import { WException, getMoveErrorDescription, WErrors } from "@wowok/wowok";
8
+ import { GUARDQUERY } from "@wowok/wowok";
9
+ import { assessGuardRisksForOperation, getRiskSummary } from "../../knowledge/guard-risk.js";
10
+ import { derivePuzzleFromCallData, getPuzzleStatusBooleans, getPendingQuestions, generateConfirmationText, } from "../../knowledge/guard-puzzle.js";
11
+ import { inferSceneFromAction } from "../../knowledge/guard-ledger.js";
12
+ import { matchSemanticPattern } from "../../knowledge/guard-translation.js";
7
13
  function booleanFromSignals(positive, negative) {
8
14
  if (positive)
9
15
  return true;
@@ -13,78 +19,405 @@ function booleanFromSignals(positive, negative) {
13
19
  }
14
20
  const ERROR_RULES = [
15
21
  {
16
- patterns: [/insufficient\s*(gas|balance|coin|fund)/i, /ENOTENOUGH/i, /not\s*enough\s*(coin|gas|balance)/i, /gas\s*budget/i],
22
+ patterns: [
23
+ /too\s*many\s*requests/i,
24
+ /rate\s*limit/i,
25
+ /429/i,
26
+ /throttl/i,
27
+ /faucet.*rate/i,
28
+ /request.*limit.*exceeded/i,
29
+ ],
30
+ error_code: "rate_limit",
31
+ retryable: true,
32
+ recovery_hint: "Rate limit hit (HTTP 429). Wait with exponential backoff and retry. To check existing balance, use account_balance query.",
33
+ },
34
+ {
35
+ patterns: [
36
+ /gas.*budget.*exceeded/i,
37
+ /out\s*of\s*gas/i,
38
+ /gas\s*exceeded/i,
39
+ /insufficient\s*gas/i,
40
+ /not\s*enough\s*gas/i,
41
+ /could not automatically determine a budget/i,
42
+ /dry run failed.*budget/i,
43
+ /Maximum gas/i,
44
+ ],
45
+ error_code: "gas_exceeded",
46
+ retryable: true,
47
+ recovery_hint: "Gas budget exceeded. Increase the gas_budget parameter or claim more gas tokens, then retry",
48
+ },
49
+ {
50
+ patterns: [
51
+ /insufficient\s*(balance|coin|fund)/i,
52
+ /ENOTENOUGH/i,
53
+ /not\s*enough\s*(coin|balance)/i,
54
+ /coin\s*not\s*enough/i,
55
+ /balance\s*not\s*enough/i,
56
+ /stock\s*not\s*enough/i,
57
+ /fee\s*not\s*enough/i,
58
+ /Insufficient balance/i,
59
+ ],
17
60
  error_code: "insufficient_balance",
18
61
  retryable: true,
19
62
  recovery_hint: "Claim faucet tokens via account_operation (faucet) then retry the call",
20
63
  },
21
64
  {
22
- patterns: [/network/i, /timeout/i, /ECONNRESET/i, /ETIMEDOUT/i, /RPC\s*(error|failed|unreachable)/i, /socket\s*hang\s*up/i, /fetch\s*failed/i],
65
+ patterns: [
66
+ /bcs.*(error|fail|invalid)/i,
67
+ /BCS serialization/i,
68
+ /serialization\s*(failure|error)/i,
69
+ /deserialization\s*(failure|error)/i,
70
+ /invalid bcs type/i,
71
+ /Out of range.*bcs/i,
72
+ /Length out of range/i,
73
+ /parse object content failed/i,
74
+ ],
75
+ error_code: "bcs_error",
76
+ retryable: false,
77
+ recovery_hint: "BCS serialization/deserialization error. Verify data types and structure match the expected schema",
78
+ },
79
+ {
80
+ patterns: [
81
+ /signature.*(invalid|fail|error|verif)/i,
82
+ /invalid\s*signature/i,
83
+ /signature\s*verification\s*failed/i,
84
+ /bad\s*signature/i,
85
+ /signing\s*fail/i,
86
+ /crypto.*signature/i,
87
+ /ed25519.*(fail|error|invalid)/i,
88
+ /secp256k1.*(fail|error|invalid)/i,
89
+ ],
90
+ error_code: "signature_error",
91
+ retryable: false,
92
+ recovery_hint: "Signature verification failed. Check that the correct private key and network configuration are correct",
93
+ },
94
+ {
95
+ patterns: [
96
+ /config.*(not set|not found|invalid|missing)/i,
97
+ /RPC\s*not\s*configured/i,
98
+ /network.*not\s*specified/i,
99
+ /protocol network not specified/i,
100
+ /account persistent storage not set/i,
101
+ /config persistent storage not set/i,
102
+ /account persistent storage not found/i,
103
+ /no\s*rpc\s*url/i,
104
+ ],
105
+ error_code: "config_error",
106
+ retryable: false,
107
+ recovery_hint: "Configuration error. Verify that network, RPC endpoints, and required environment variables are properly configured",
108
+ },
109
+ {
110
+ patterns: [
111
+ /network/i,
112
+ /timeout/i,
113
+ /ECONNRESET/i,
114
+ /ETIMEDOUT/i,
115
+ /ECONNREFUSED/i,
116
+ /EAI_AGAIN/i,
117
+ /RPC\s*(error|failed|unreachable)/i,
118
+ /socket\s*hang\s*up/i,
119
+ /fetch\s*failed/i,
120
+ /connection\s*(refused|reset|lost)/i,
121
+ /dns\s*(error|fail)/i,
122
+ ],
23
123
  error_code: "network_error",
24
124
  retryable: true,
25
125
  recovery_hint: "Retry the call; if it persists, switch RPC endpoint or check connectivity",
26
126
  },
27
127
  {
28
- patterns: [/faucet/i, /too\s*many\s*requests/i, /rate\s*limit/i, /429/i],
29
- error_code: "network_error",
30
- retryable: true,
31
- recovery_hint: "Faucet rate limit hit (HTTP 429). Wait a few minutes and retry. To check existing balance, use account_balance query.",
32
- },
33
- {
34
- patterns: [/guard.*(reject|fail|denied)/i, /verification\s*failed/i, /submission.*(invalid|fail|required)/i, /passport.*(invalid|fail)/i, /move[._-]?abort.*guard/i],
128
+ patterns: [
129
+ /guard.*(reject|fail|denied|verif)/i,
130
+ /verification\s*failed/i,
131
+ /submission.*(invalid|fail|required)/i,
132
+ /passport.*(invalid|fail|verif)/i,
133
+ /move[._-]?abort.*guard/i,
134
+ /Guard count exceeded limit/i,
135
+ /Submission size exceeded limit/i,
136
+ /Submission not found/i,
137
+ /Guard not found/i,
138
+ /Impact guard not found/i,
139
+ ],
35
140
  error_code: "guard_rejected",
36
141
  retryable: false,
37
142
  recovery_hint: "Fill the Guard submission data (see the 'submission' field) and resubmit via call_with_submission",
38
143
  },
39
144
  {
40
- patterns: [/already\s*publish/i, /immutable/i, /cannot\s*(modify|change|mutate)/i, /locked/i, /is\s*published/i],
145
+ patterns: [
146
+ /already\s*publish/i,
147
+ /immutable/i,
148
+ /cannot\s*(modify|change|mutate)/i,
149
+ /locked/i,
150
+ /is\s*published/i,
151
+ /Service already published/i,
152
+ /Machine already published/i,
153
+ /setting lock duration not exceeded/i,
154
+ ],
41
155
  error_code: "immutable_violation",
42
156
  retryable: false,
43
157
  recovery_hint: "Object is in an immutable state (e.g. Service already published). Recreate the object if a different config is needed",
44
158
  },
45
159
  {
46
- patterns: [/permission/i, /unauthorized/i, /forbidden/i, /not\s*(the\s*)?owner/i, /access\s*denied/i],
160
+ patterns: [
161
+ /permission/i,
162
+ /unauthorized/i,
163
+ /forbidden/i,
164
+ /not\s*(the\s*)?owner/i,
165
+ /access\s*denied/i,
166
+ /no permission/i,
167
+ /Permission denied/i,
168
+ /Not the builder/i,
169
+ /Not admin/i,
170
+ /No operation permission/i,
171
+ /Not the holder/i,
172
+ ],
47
173
  error_code: "permission_denied",
48
174
  retryable: false,
49
175
  recovery_hint: "Use an account with the required permission, or pass permission_guard IDs via env.permission_guard",
50
176
  },
51
177
  {
52
- patterns: [/not\s*found/i, /does\s*not\s*exist/i, /ENOTFOUND/i, /no\s*such\s*object/i, /unknown\s*object/i],
178
+ patterns: [
179
+ /not\s*found/i,
180
+ /does\s*not\s*exist/i,
181
+ /ENOTFOUND/i,
182
+ /no\s*such\s*object/i,
183
+ /unknown\s*object/i,
184
+ /account not found/i,
185
+ /address not found/i,
186
+ /token not found/i,
187
+ /Node not found/i,
188
+ /Policy not found/i,
189
+ /Reward not found/i,
190
+ ],
53
191
  error_code: "object_not_found",
54
192
  retryable: false,
55
193
  recovery_hint: "Verify the object ID/name with query_toolkit; local_mark names are case-sensitive",
56
194
  },
57
195
  {
58
- patterns: [/state\s*(conflict|mismatch)/i, /already\s*exist/i, /conflict/i, /duplicate/i, /version\s*mismatch/i],
196
+ patterns: [
197
+ /state\s*(conflict|mismatch)/i,
198
+ /already\s*exist/i,
199
+ /conflict/i,
200
+ /duplicate/i,
201
+ /version\s*mismatch/i,
202
+ /name exist/i,
203
+ /Duplicate forward name/i,
204
+ /Duplicate node previous/i,
205
+ /already claimed/i,
206
+ /already specified/i,
207
+ /already accomplished/i,
208
+ /already used/i,
209
+ /Status does not match/i,
210
+ /does not match/i,
211
+ ],
59
212
  error_code: "state_conflict",
60
213
  retryable: false,
61
214
  recovery_hint: "Object state conflicts with the operation. Query the current state with query_toolkit and adjust parameters",
62
215
  },
63
216
  {
64
- patterns: [/invalid/i, /missing\s*(field|param|required)/i, /required/i, /expected/i, /malformed/i, /parse\s*error/i, /type\s*mismatch/i],
217
+ patterns: [
218
+ /invalid/i,
219
+ /missing\s*(field|param|required)/i,
220
+ /required/i,
221
+ /expected/i,
222
+ /malformed/i,
223
+ /parse\s*error/i,
224
+ /type\s*mismatch/i,
225
+ /invalid argument/i,
226
+ /Invalid value/i,
227
+ /Invalid data value/i,
228
+ /Invalid string value/i,
229
+ /Invalid argument/i,
230
+ /IsValid/i,
231
+ /type does not match/i,
232
+ /value type/i,
233
+ ],
65
234
  error_code: "invalid_parameter",
66
235
  retryable: false,
67
236
  recovery_hint: "Check parameter format against the tool schema; consult wowok-tools Skill for the operation's requirements",
68
237
  },
69
238
  ];
70
- export function classifyError(errorMsg) {
239
+ const WERROR_MAPPINGS = [
240
+ {
241
+ codes: [WErrors.AccountNotFound, WErrors.AddressNotFound, WErrors.TokenNotFoundLocally],
242
+ error_code: "object_not_found",
243
+ retryable: false,
244
+ recovery_hint: "Verify the object ID/name with query_toolkit; local_mark names are case-sensitive",
245
+ },
246
+ {
247
+ codes: [WErrors.NoPermission],
248
+ error_code: "permission_denied",
249
+ retryable: false,
250
+ recovery_hint: "Use an account with the required permission, or pass permission_guard IDs via env.permission_guard",
251
+ },
252
+ {
253
+ codes: [
254
+ WErrors.IsValidDescription,
255
+ WErrors.IsValidName,
256
+ WErrors.IsValidName_AllowEmpty,
257
+ WErrors.IsValidEndpoint,
258
+ WErrors.IsValidAddress,
259
+ WErrors.IsValidArgType,
260
+ WErrors.IsValidTokenType,
261
+ WErrors.IsValidUint,
262
+ WErrors.IsValidInt,
263
+ WErrors.IsValidU8,
264
+ WErrors.IsValidU16,
265
+ WErrors.IsValidU32,
266
+ WErrors.IsValidU64,
267
+ WErrors.IsValidU128,
268
+ WErrors.IsValidU256,
269
+ WErrors.IsValidRate,
270
+ WErrors.IsValidArray,
271
+ WErrors.IsValidObjects,
272
+ WErrors.AllInvalid,
273
+ WErrors.InvalidParam,
274
+ WErrors.IsValidPermissionIndex,
275
+ WErrors.IsValidKey,
276
+ WErrors.IsValidIdentifier,
277
+ WErrors.IsValidHttpUrl,
278
+ WErrors.IsValidBizPermissionIndex,
279
+ WErrors.IsValidServiceItemName,
280
+ WErrors.IsValidCoinType,
281
+ WErrors.IsValidGuardIdentifier,
282
+ WErrors.IsValidValue,
283
+ WErrors.IsValidValueType,
284
+ WErrors.IsValidLocation,
285
+ WErrors.WitnessTypeInvalid,
286
+ ],
287
+ error_code: "invalid_parameter",
288
+ retryable: false,
289
+ recovery_hint: "Check parameter format against the tool schema; consult wowok-tools Skill for the operation's requirements",
290
+ },
291
+ {
292
+ codes: [WErrors.BcsTypeInvalid, WErrors.ParseObjectContentFailed],
293
+ error_code: "bcs_error",
294
+ retryable: false,
295
+ recovery_hint: "BCS serialization/deserialization error. Verify data types and structure match the expected schema",
296
+ },
297
+ {
298
+ codes: [WErrors.NetworkInvalid],
299
+ error_code: "config_error",
300
+ retryable: false,
301
+ recovery_hint: "Configuration error. Verify that network, RPC endpoints, and required environment variables are properly configured",
302
+ },
303
+ {
304
+ codes: [
305
+ WErrors.AccountPersistentStorageNotSet,
306
+ WErrors.ConfigPersistentStorageNotSet,
307
+ WErrors.AccountPersistentStorageNotFound,
308
+ ],
309
+ error_code: "config_error",
310
+ retryable: false,
311
+ recovery_hint: "Persistent storage not configured. Initialize account storage before performing this operation",
312
+ },
313
+ {
314
+ codes: [WErrors.AccountNameExist, WErrors.LocalMarkNameExist],
315
+ error_code: "state_conflict",
316
+ retryable: false,
317
+ recovery_hint: "Object state conflicts with the operation. Query the current state with query_toolkit and adjust parameters",
318
+ },
319
+ {
320
+ codes: [WErrors.MaxObjectsPerQuery, WErrors.ResourceTagCountExceeded, WErrors.AddressCountExceeded, WErrors.NumberCountExceeded],
321
+ error_code: "invalid_parameter",
322
+ retryable: false,
323
+ recovery_hint: "Count limit exceeded. Reduce the number of items per request and retry",
324
+ },
325
+ ];
326
+ function isWException(value) {
327
+ return value instanceof WException;
328
+ }
329
+ function classifyWException(exception) {
330
+ const code = exception.getErrorCode();
331
+ const mapping = WERROR_MAPPINGS.find((m) => m.codes.includes(code));
332
+ if (!mapping)
333
+ return undefined;
334
+ const result = {
335
+ error_code: mapping.error_code,
336
+ retryable: mapping.retryable,
337
+ recovery_hint: mapping.recovery_hint,
338
+ };
339
+ return result;
340
+ }
341
+ const WOWOK_ADDRESSES = new Set([
342
+ "0x0000000000000000000000000000000000000000000000000000000000000002",
343
+ "0x2",
344
+ ]);
345
+ function extractMoveAbortInfo(errorMsg) {
346
+ if (!errorMsg)
347
+ return undefined;
348
+ const abortCodeMatch = errorMsg.match(/MoveAbort\([^,]+,\s*(\d+)\)/);
349
+ const moduleNameMatch = errorMsg.match(/name:\s*Identifier\("([^"]+)"\)/);
350
+ const addressMatch = errorMsg.match(/address:\s*([0-9a-fA-Fx]+)/);
351
+ if (abortCodeMatch && moduleNameMatch && addressMatch) {
352
+ const code = parseInt(abortCodeMatch[1], 10);
353
+ const module = moduleNameMatch[1].toLowerCase();
354
+ const address = addressMatch[1].toLowerCase();
355
+ if (WOWOK_ADDRESSES.has(address)) {
356
+ const description = getMoveErrorDescription(module, code) ?? undefined;
357
+ return { module, code, description };
358
+ }
359
+ }
360
+ const formattedAbortCode = errorMsg.match(/abort code:\s*(\d+)/);
361
+ const formattedModule = errorMsg.match(/'0x[0-9a-fA-F]+::([^:]+)::[^']+'/);
362
+ const formattedAddress = errorMsg.match(/'(0x[0-9a-fA-F]+)::/);
363
+ if (formattedAbortCode && formattedModule && formattedAddress) {
364
+ const code = parseInt(formattedAbortCode[1], 10);
365
+ const module = formattedModule[1].toLowerCase();
366
+ const address = formattedAddress[1].toLowerCase();
367
+ if (WOWOK_ADDRESSES.has(address)) {
368
+ const description = getMoveErrorDescription(module, code) ?? undefined;
369
+ return { module, code, description };
370
+ }
371
+ }
372
+ return undefined;
373
+ }
374
+ export function classifyError(errorMsg, error) {
375
+ if (error !== undefined && isWException(error)) {
376
+ const fromWException = classifyWException(error);
377
+ if (fromWException) {
378
+ const abortInfo = extractMoveAbortInfo(errorMsg);
379
+ if (abortInfo) {
380
+ fromWException.move_abort_info = abortInfo;
381
+ if (abortInfo.description && fromWException.recovery_hint && !fromWException.recovery_hint.includes(abortInfo.description)) {
382
+ fromWException.recovery_hint = `${fromWException.recovery_hint}. Details: ${abortInfo.description}`;
383
+ }
384
+ }
385
+ return fromWException;
386
+ }
387
+ }
71
388
  if (!errorMsg) {
72
389
  return { error_code: "unknown", retryable: false };
73
390
  }
74
391
  for (const rule of ERROR_RULES) {
75
392
  if (rule.patterns.some((p) => p.test(errorMsg))) {
76
- return {
393
+ const result = {
77
394
  error_code: rule.error_code,
78
395
  retryable: rule.retryable,
79
396
  recovery_hint: rule.recovery_hint,
80
397
  };
398
+ const abortInfo = extractMoveAbortInfo(errorMsg);
399
+ if (abortInfo) {
400
+ result.move_abort_info = abortInfo;
401
+ if (abortInfo.description) {
402
+ result.recovery_hint = `${result.recovery_hint}. Details: ${abortInfo.description}`;
403
+ }
404
+ }
405
+ return result;
81
406
  }
82
407
  }
83
- return {
408
+ const abortInfo = extractMoveAbortInfo(errorMsg);
409
+ const fallback = {
84
410
  error_code: "unknown",
85
411
  retryable: false,
86
412
  recovery_hint: "Inspect the full error message; consult wowok-tools Skill for the operation's requirements",
87
413
  };
414
+ if (abortInfo) {
415
+ fallback.move_abort_info = abortInfo;
416
+ if (abortInfo.description) {
417
+ fallback.recovery_hint = `${abortInfo.description}. ${fallback.recovery_hint}`;
418
+ }
419
+ }
420
+ return fallback;
88
421
  }
89
422
  const INTENT_RULES = [
90
423
  { operation_type: "service", signals: (d) => d?.publish === true, intent: "publish_service", confidence: 0.95 },
@@ -773,11 +1106,11 @@ function buildCustomerAdvice(operation_type, data, safeResult) {
773
1106
  if (r.action)
774
1107
  recommendations.push(r.action);
775
1108
  }
776
- if (noArbitration && !recommendations.some((r) => r.includes("仲裁"))) {
777
- recommendations.push("要求商家配置 Arbitration 服务后再下单");
1109
+ if (noArbitration && !recommendations.some((r) => r.includes("arbitration"))) {
1110
+ recommendations.push("Require the merchant to configure an Arbitration service before placing the order");
778
1111
  }
779
- if (noCompensation && !recommendations.some((r) => r.includes("赔偿金"))) {
780
- recommendations.push("要求商家设置 compensation_fund(赔偿金)以保障订单失败时自动赔付");
1112
+ if (noCompensation && !recommendations.some((r) => r.includes("compensation"))) {
1113
+ recommendations.push("Require the merchant to set a compensation_fund to guarantee automatic payout when the order fails");
781
1114
  }
782
1115
  const advice = {
783
1116
  recommendations,
@@ -795,6 +1128,256 @@ function buildCustomerAdvice(operation_type, data, safeResult) {
795
1128
  advice.risk_level = riskLevel;
796
1129
  return advice;
797
1130
  }
1131
+ function buildGuardAdvice(operation_type, data, safeResult) {
1132
+ try {
1133
+ if (operation_type === "guard") {
1134
+ return buildGuardCreateAdvice(data);
1135
+ }
1136
+ if (operation_type === "gen_passport") {
1137
+ const status = safeResult?.error ? "fail" : "pass";
1138
+ return {
1139
+ current_round: "R8",
1140
+ test_result: {
1141
+ status: status,
1142
+ passport_id: status === "pass" ? safeResult?.passport : undefined,
1143
+ failure_node: status === "fail"
1144
+ ? (typeof safeResult?.error === "string" ? safeResult.error.slice(0, 120) : undefined)
1145
+ : undefined,
1146
+ },
1147
+ };
1148
+ }
1149
+ const errorStr = typeof safeResult?.error === "string" ? safeResult.error : "";
1150
+ if (errorStr.includes("GUARD") || errorStr.includes("Guard") || errorStr.includes("guard")) {
1151
+ return {
1152
+ risk_warnings: [
1153
+ `Guard verification failed: ${errorStr.slice(0, 200)}`,
1154
+ "Suggestion: check whether the submission data matches the Guard table declaration, or query the Guard definition to learn the required submission",
1155
+ ],
1156
+ };
1157
+ }
1158
+ return undefined;
1159
+ }
1160
+ catch {
1161
+ return undefined;
1162
+ }
1163
+ }
1164
+ function buildGuardCreateAdvice(data) {
1165
+ if (!data)
1166
+ return undefined;
1167
+ const puzzleInput = convertCallDataToPuzzleInput(data);
1168
+ const puzzle = derivePuzzleFromCallData(puzzleInput);
1169
+ const puzzleStatusBooleans = getPuzzleStatusBooleans(puzzle);
1170
+ let matchedScene;
1171
+ let sceneDescription;
1172
+ let sceneConstraints;
1173
+ if (data.binding_hint?.action) {
1174
+ matchedScene = inferSceneFromAction(data.binding_hint.action);
1175
+ if (matchedScene) {
1176
+ sceneDescription = matchedScene.name;
1177
+ sceneConstraints = matchedScene.special_constraints;
1178
+ }
1179
+ }
1180
+ let suggestedPatterns;
1181
+ const intentText = data.binding_hint?.rule_sentence
1182
+ || data.binding_hint?.action
1183
+ || "";
1184
+ if (intentText) {
1185
+ const matched = matchSemanticPattern(intentText);
1186
+ if (matched.length > 0) {
1187
+ suggestedPatterns = matched.map((m) => `${m.id}: ${m.pattern_name}`);
1188
+ }
1189
+ }
1190
+ let confirmationText;
1191
+ try {
1192
+ const text = generateConfirmationText(puzzle);
1193
+ if (!text.startsWith("[Puzzle incomplete]")) {
1194
+ confirmationText = text;
1195
+ }
1196
+ }
1197
+ catch {
1198
+ }
1199
+ let pendingQuestions;
1200
+ const pendingQs = getPendingQuestions(puzzle);
1201
+ if (pendingQs.length > 0) {
1202
+ pendingQuestions = pendingQs;
1203
+ }
1204
+ let availableQueries;
1205
+ if (matchedScene) {
1206
+ const sceneObjectType = mapSceneToObjectType(matchedScene);
1207
+ if (sceneObjectType) {
1208
+ const filtered = GUARDQUERY
1209
+ .filter((q) => q.objectType === sceneObjectType)
1210
+ .slice(0, 10)
1211
+ .map((q) => ({
1212
+ id: q.id,
1213
+ name: q.name,
1214
+ objectType: String(q.objectType),
1215
+ returnType: String(q.return),
1216
+ description: q.description,
1217
+ }));
1218
+ if (filtered.length > 0) {
1219
+ availableQueries = filtered;
1220
+ }
1221
+ }
1222
+ }
1223
+ const assessment = assessGuardRisksForOperation("guard", data);
1224
+ let riskAssessment;
1225
+ let riskWarnings;
1226
+ if (assessment) {
1227
+ const summary = getRiskSummary(assessment);
1228
+ riskAssessment = {
1229
+ overall_risk: summary.risk_count > 0 ? assessment.overall_risk : "info",
1230
+ risk_count: summary.risk_count,
1231
+ critical_count: summary.critical_count,
1232
+ high_count: summary.high_count,
1233
+ needs_human_review: summary.needs_human_review,
1234
+ top_risks: summary.top_risks,
1235
+ stakeholder_advice: assessment.stakeholder_advice,
1236
+ };
1237
+ const warnings = assessment.risks.map((r) => `[${r.level.toUpperCase()}] ${r.title}: ${r.description}`);
1238
+ if (warnings.length > 0) {
1239
+ riskWarnings = warnings;
1240
+ }
1241
+ }
1242
+ const advice = {
1243
+ current_round: "R7",
1244
+ puzzle_status: puzzleStatusBooleans,
1245
+ };
1246
+ if (matchedScene)
1247
+ advice.matched_scene = matchedScene.id;
1248
+ if (sceneDescription)
1249
+ advice.scene_description = sceneDescription;
1250
+ if (sceneConstraints)
1251
+ advice.scene_constraints = sceneConstraints;
1252
+ if (suggestedPatterns)
1253
+ advice.suggested_patterns = suggestedPatterns;
1254
+ if (availableQueries)
1255
+ advice.available_queries = availableQueries;
1256
+ if (riskWarnings)
1257
+ advice.risk_warnings = riskWarnings;
1258
+ if (pendingQuestions)
1259
+ advice.pending_questions = pendingQuestions;
1260
+ if (confirmationText)
1261
+ advice.confirmation_text = confirmationText;
1262
+ if (riskAssessment)
1263
+ advice.risk_assessment = riskAssessment;
1264
+ return advice;
1265
+ }
1266
+ function convertCallDataToPuzzleInput(data) {
1267
+ const result = {};
1268
+ if (Array.isArray(data.table)) {
1269
+ result.table = data.table.map((item) => ({
1270
+ identifier: item.identifier,
1271
+ b_submission: item.b_submission,
1272
+ value_type: typeof item.value_type === "string" ? item.value_type : String(item.value_type),
1273
+ value: convertValueSnapshot(item.value),
1274
+ name: item.name ?? "",
1275
+ object_type: item.object_type,
1276
+ }));
1277
+ }
1278
+ if (data.root && typeof data.root === "object") {
1279
+ const rootObj = data.root;
1280
+ if (rootObj.type !== "file" && rootObj.type !== "node") {
1281
+ result.root = convertNodeToSnapshot(data.root);
1282
+ }
1283
+ else if (rootObj.type === "node" && data.root.node) {
1284
+ result.root = convertNodeToSnapshot(data.root.node);
1285
+ }
1286
+ }
1287
+ if (data.rely && Array.isArray(data.rely.guards)) {
1288
+ result.rely = {
1289
+ guards: data.rely.guards.map((g) => typeof g === "string" ? g : String(g)),
1290
+ logic_or: data.rely.logic_or,
1291
+ };
1292
+ }
1293
+ if (data.binding_hint) {
1294
+ const bh = data.binding_hint;
1295
+ const bindingHint = {
1296
+ action: bh.action,
1297
+ host_object: bh.host_object,
1298
+ binding_field: bh.binding_field,
1299
+ };
1300
+ if (bh.rule_sentence !== undefined)
1301
+ bindingHint.rule_sentence = bh.rule_sentence;
1302
+ if (bh.failure_conditions !== undefined)
1303
+ bindingHint.failure_conditions = bh.failure_conditions;
1304
+ if (bh.circular_reference !== undefined)
1305
+ bindingHint.circular_reference = bh.circular_reference;
1306
+ result.binding_hint = bindingHint;
1307
+ }
1308
+ return result;
1309
+ }
1310
+ function convertNodeToSnapshot(node) {
1311
+ if (!node || typeof node !== "object") {
1312
+ return { type: "unknown" };
1313
+ }
1314
+ const snapshot = {
1315
+ type: String(node.type ?? "unknown"),
1316
+ };
1317
+ if (typeof node.identifier === "number") {
1318
+ snapshot.identifier = node.identifier;
1319
+ }
1320
+ if (node.query !== undefined) {
1321
+ snapshot.query = typeof node.query === "number" ? node.query : String(node.query);
1322
+ }
1323
+ if (node.object && typeof node.object === "object") {
1324
+ const obj = {
1325
+ identifier: Number(node.object.identifier),
1326
+ };
1327
+ if (typeof node.object.convert_witness === "number") {
1328
+ obj.convert_witness = node.object.convert_witness;
1329
+ }
1330
+ snapshot.object = obj;
1331
+ }
1332
+ if (Array.isArray(node.parameters)) {
1333
+ snapshot.parameters = node.parameters.map((p) => convertNodeToSnapshot(p));
1334
+ }
1335
+ if (typeof node.context === "string") {
1336
+ const ctxValue = node.context;
1337
+ if (ctxValue === "Clock" || ctxValue === "Guard" || ctxValue === "Signer") {
1338
+ snapshot.context = ctxValue;
1339
+ }
1340
+ }
1341
+ if (Array.isArray(node.nodes)) {
1342
+ snapshot.nodes = node.nodes.map((n) => convertNodeToSnapshot(n));
1343
+ }
1344
+ if (node.node) {
1345
+ snapshot.node = convertNodeToSnapshot(node.node);
1346
+ }
1347
+ if (node.nodeLeft) {
1348
+ snapshot.nodeLeft = convertNodeToSnapshot(node.nodeLeft);
1349
+ }
1350
+ if (node.nodeRight) {
1351
+ snapshot.nodeRight = convertNodeToSnapshot(node.nodeRight);
1352
+ }
1353
+ return snapshot;
1354
+ }
1355
+ function convertValueSnapshot(value) {
1356
+ if (value === undefined || value === null)
1357
+ return undefined;
1358
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
1359
+ return value;
1360
+ }
1361
+ if (Array.isArray(value)) {
1362
+ const allString = value.every((v) => typeof v === "string");
1363
+ if (allString)
1364
+ return value;
1365
+ const allNumber = value.every((v) => typeof v === "number");
1366
+ if (allNumber)
1367
+ return value;
1368
+ const allBool = value.every((v) => typeof v === "boolean");
1369
+ if (allBool)
1370
+ return value;
1371
+ return JSON.stringify(value);
1372
+ }
1373
+ return JSON.stringify(value);
1374
+ }
1375
+ function mapSceneToObjectType(scene) {
1376
+ const hostObject = scene.host_object;
1377
+ if (hostObject === "Standalone")
1378
+ return undefined;
1379
+ return hostObject;
1380
+ }
798
1381
  export function buildSemantic(safeResult, context) {
799
1382
  if (!context)
800
1383
  return undefined;
@@ -820,7 +1403,8 @@ export function buildSemantic(safeResult, context) {
820
1403
  }
821
1404
  }
822
1405
  let experience;
823
- if (isRuntimeEnabled("experience_layer")) {
1406
+ const experienceLayerEnabled = isRuntimeEnabled("experience_layer");
1407
+ if (experienceLayerEnabled) {
824
1408
  try {
825
1409
  const feedback = getExperienceFeedback(context.operation_type, context.data, intent);
826
1410
  if (feedback) {
@@ -828,7 +1412,8 @@ export function buildSemantic(safeResult, context) {
828
1412
  }
829
1413
  const outcome = status === "success" ? "success" : status === "failed" ? "failed" : "partial";
830
1414
  const referencedObjects = [...created, ...modified].map((o) => o.id).filter(Boolean);
831
- recordOperationOutcome(context.operation_type, context.data, intent, outcome, undefined, referencedObjects);
1415
+ const errCode = inferErrorCodeForSignal(safeResult);
1416
+ recordOperationOutcome(context.operation_type, context.data, intent, outcome, errCode, referencedObjects);
832
1417
  }
833
1418
  catch {
834
1419
  }
@@ -839,7 +1424,7 @@ export function buildSemantic(safeResult, context) {
839
1424
  const industryHint = (typeof context.data?.industry === "string" && context.data.industry.trim())
840
1425
  ? context.data.industry.trim()
841
1426
  : undefined;
842
- if (industryHint) {
1427
+ if (industryHint && !experienceLayerEnabled) {
843
1428
  const outcome = status === "success"
844
1429
  ? { success: true }
845
1430
  : { success: false, error_code: inferErrorCodeForSignal(safeResult) };
@@ -875,6 +1460,12 @@ export function buildSemantic(safeResult, context) {
875
1460
  }
876
1461
  catch {
877
1462
  }
1463
+ let guard_advice;
1464
+ try {
1465
+ guard_advice = buildGuardAdvice(context.operation_type, context.data, safeResult);
1466
+ }
1467
+ catch {
1468
+ }
878
1469
  return {
879
1470
  intent,
880
1471
  status,
@@ -889,6 +1480,7 @@ export function buildSemantic(safeResult, context) {
889
1480
  service_status,
890
1481
  customer_advice,
891
1482
  evolution_context,
1483
+ guard_advice,
892
1484
  };
893
1485
  }
894
1486
  function inferErrorCodeForSignal(safeResult) {