@wowok/agent-mcp 2.7.1 → 2.7.2

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 (375) hide show
  1. package/dist/config/index.js +1 -1
  2. package/dist/config/runtime.js +1 -238
  3. package/dist/customer/customer-advice.js +1 -130
  4. package/dist/customer/index.js +1 -11
  5. package/dist/customer/industry-risks.js +1 -438
  6. package/dist/customer/info-puzzle.js +1 -681
  7. package/dist/customer/order-monitor.js +1 -328
  8. package/dist/customer/order-strategy.js +1 -373
  9. package/dist/customer/post-purchase.js +1 -351
  10. package/dist/customer/preorder-compare.js +1 -34
  11. package/dist/customer/reminder-system.js +1 -316
  12. package/dist/customer/risk-assessment.js +1 -397
  13. package/dist/customer/types.js +1 -13
  14. package/dist/customer/user-preferences.js +1 -460
  15. package/dist/evaluation/arbitration-game.d.ts +9 -2
  16. package/dist/evaluation/arbitration-game.js +1 -48
  17. package/dist/evaluation/builtins/demand-match.js +1 -153
  18. package/dist/evaluation/builtins/index.js +1 -10
  19. package/dist/evaluation/builtins/service-risk.js +1 -55
  20. package/dist/evaluation/capability.js +1 -13
  21. package/dist/evaluation/composer.js +1 -40
  22. package/dist/evaluation/engine.js +1 -175
  23. package/dist/evaluation/extract.js +1 -115
  24. package/dist/evaluation/game-strategy.d.ts +27 -0
  25. package/dist/evaluation/game-strategy.js +1 -0
  26. package/dist/evaluation/gap.js +1 -100
  27. package/dist/evaluation/index.d.ts +1 -0
  28. package/dist/evaluation/index.js +1 -11
  29. package/dist/evaluation/node-game.d.ts +31 -3
  30. package/dist/evaluation/node-game.js +1 -57
  31. package/dist/evaluation/region.js +1 -36
  32. package/dist/evaluation/types.d.ts +1 -0
  33. package/dist/evaluation/types.js +1 -1
  34. package/dist/evaluation/user-injection.js +1 -27
  35. package/dist/experience/experience-reuse.js +1 -103
  36. package/dist/experience/index.js +1 -5
  37. package/dist/experience/intent-distill.js +1 -83
  38. package/dist/experience/realtime-feedback.js +1 -94
  39. package/dist/experience/types.js +1 -1
  40. package/dist/experience/user-profile.js +1 -171
  41. package/dist/extensions/business-modules.js +1 -287
  42. package/dist/extensions/capability-manifest.js +1 -781
  43. package/dist/extensions/constraint-registry.js +1 -198
  44. package/dist/extensions/index.js +1 -6
  45. package/dist/extensions/metric-registry.js +1 -257
  46. package/dist/extensions/mode-evaluator.js +1 -170
  47. package/dist/extensions/modes.js +1 -499
  48. package/dist/extensions/registry.js +1 -717
  49. package/dist/extensions/types.js +1 -1
  50. package/dist/harness/auto-escalation.js +1 -68
  51. package/dist/harness/checkpoint.js +1 -129
  52. package/dist/harness/index.js +1 -78
  53. package/dist/harness/plan.js +1 -315
  54. package/dist/harness/recover.js +1 -139
  55. package/dist/harness/types.js +1 -1
  56. package/dist/harness/verify.js +1 -237
  57. package/dist/index.js +1 -273
  58. package/dist/intent/enrich.js +1 -67
  59. package/dist/intent/index.js +1 -60
  60. package/dist/intent/matcher.js +1 -81
  61. package/dist/intent/store.js +1 -55
  62. package/dist/intent/types.js +1 -10
  63. package/dist/knowledge/acquisition-flywheel.js +1 -192
  64. package/dist/knowledge/allocation-confirm.js +1 -534
  65. package/dist/knowledge/allocation-context.js +1 -249
  66. package/dist/knowledge/allocation-ledger.js +1 -463
  67. package/dist/knowledge/allocation-puzzle.js +1 -298
  68. package/dist/knowledge/allocation-risk.js +1 -568
  69. package/dist/knowledge/allocation-templates.js +1 -970
  70. package/dist/knowledge/allocation-translation.js +1 -585
  71. package/dist/knowledge/arb-risk.js +1 -210
  72. package/dist/knowledge/arbitration-confirm.js +1 -559
  73. package/dist/knowledge/arbitration-context.js +1 -505
  74. package/dist/knowledge/arbitration-ledger.js +1 -521
  75. package/dist/knowledge/arbitration-puzzle.js +1 -304
  76. package/dist/knowledge/arbitration-risk.js +1 -423
  77. package/dist/knowledge/arbitration-templates.js +1 -276
  78. package/dist/knowledge/arbitration-translation.js +1 -487
  79. package/dist/knowledge/arbitration-trust.js +1 -117
  80. package/dist/knowledge/audit-rules.js +1 -141
  81. package/dist/knowledge/bridge-risk.js +1 -263
  82. package/dist/knowledge/contact-risk.js +1 -200
  83. package/dist/knowledge/contact-templates.js +1 -60
  84. package/dist/knowledge/demand-confirm.js +1 -206
  85. package/dist/knowledge/demand-matching.js +1 -132
  86. package/dist/knowledge/demand-risk.js +1 -240
  87. package/dist/knowledge/demand-translation.js +1 -354
  88. package/dist/knowledge/deployment-scanner.js +1 -823
  89. package/dist/knowledge/dynamic-pricing.js +1 -87
  90. package/dist/knowledge/examples-scanner-cli.js +1 -26
  91. package/dist/knowledge/examples-scanner.js +1 -843
  92. package/dist/knowledge/flywheel-loop.js +1 -404
  93. package/dist/knowledge/fund-layer.js +1 -973
  94. package/dist/knowledge/glossary.js +1 -211
  95. package/dist/knowledge/guard-confirm.js +1 -406
  96. package/dist/knowledge/guard-context.js +1 -287
  97. package/dist/knowledge/guard-design-patterns.js +1 -360
  98. package/dist/knowledge/guard-ledger.js +1 -260
  99. package/dist/knowledge/guard-lint.js +1 -670
  100. package/dist/knowledge/guard-migration.js +1 -228
  101. package/dist/knowledge/guard-puzzle.js +1 -805
  102. package/dist/knowledge/guard-render.js +1 -700
  103. package/dist/knowledge/guard-risk.js +1 -1879
  104. package/dist/knowledge/guard-submission-prompt.js +1 -171
  105. package/dist/knowledge/guard-templates.js +1 -1105
  106. package/dist/knowledge/guard-translation.js +1 -1119
  107. package/dist/knowledge/index.js +1 -436
  108. package/dist/knowledge/industry-evolution.js +1 -323
  109. package/dist/knowledge/industry-generalizer.js +1 -381
  110. package/dist/knowledge/industry-registry.js +1 -174
  111. package/dist/knowledge/intent-metrics.d.ts +4 -3
  112. package/dist/knowledge/intent-metrics.js +1 -566
  113. package/dist/knowledge/machine-confirm.js +1 -559
  114. package/dist/knowledge/machine-context.js +1 -833
  115. package/dist/knowledge/machine-ledger.js +1 -338
  116. package/dist/knowledge/machine-puzzle.js +1 -494
  117. package/dist/knowledge/machine-render.js +1 -565
  118. package/dist/knowledge/machine-risk.js +1 -669
  119. package/dist/knowledge/machine-templates.js +1 -1597
  120. package/dist/knowledge/machine-topology.js +1 -234
  121. package/dist/knowledge/machine-translation.js +1 -513
  122. package/dist/knowledge/mcp-schema-audit-cli.js +1 -45
  123. package/dist/knowledge/mcp-schema-audit.js +1 -777
  124. package/dist/knowledge/onchain-constants.js +1 -35
  125. package/dist/knowledge/order-confirm.js +1 -573
  126. package/dist/knowledge/order-context.js +1 -390
  127. package/dist/knowledge/order-ledger.js +1 -341
  128. package/dist/knowledge/order-puzzle.js +1 -255
  129. package/dist/knowledge/order-risk.js +1 -653
  130. package/dist/knowledge/order-templates.js +1 -368
  131. package/dist/knowledge/order-translation.js +1 -550
  132. package/dist/knowledge/overrides-loader.js +1 -65
  133. package/dist/knowledge/passport-confirm.js +1 -531
  134. package/dist/knowledge/passport-context.js +1 -306
  135. package/dist/knowledge/passport-ledger.js +1 -282
  136. package/dist/knowledge/passport-puzzle.js +1 -333
  137. package/dist/knowledge/passport-risk.js +1 -450
  138. package/dist/knowledge/passport-templates.js +1 -568
  139. package/dist/knowledge/passport-translation.js +1 -516
  140. package/dist/knowledge/payment-risk.js +1 -249
  141. package/dist/knowledge/permission-confirm.js +1 -426
  142. package/dist/knowledge/permission-context.js +1 -224
  143. package/dist/knowledge/permission-ledger.js +1 -403
  144. package/dist/knowledge/permission-puzzle.js +1 -173
  145. package/dist/knowledge/permission-risk.js +1 -411
  146. package/dist/knowledge/permission-templates.js +1 -234
  147. package/dist/knowledge/permission-translation.js +1 -350
  148. package/dist/knowledge/personal-risk.js +1 -212
  149. package/dist/knowledge/process-model.js +1 -160
  150. package/dist/knowledge/progress-confirm.js +1 -456
  151. package/dist/knowledge/progress-context.js +1 -452
  152. package/dist/knowledge/progress-ledger.js +1 -330
  153. package/dist/knowledge/progress-puzzle.js +1 -219
  154. package/dist/knowledge/progress-risk.js +1 -461
  155. package/dist/knowledge/progress-templates.js +1 -228
  156. package/dist/knowledge/progress-translation.js +1 -405
  157. package/dist/knowledge/proof-confirm.js +1 -187
  158. package/dist/knowledge/proof-risk.js +1 -207
  159. package/dist/knowledge/proof-translation.js +1 -283
  160. package/dist/knowledge/registrar-risk.js +1 -217
  161. package/dist/knowledge/repository-confirm.js +1 -286
  162. package/dist/knowledge/repository-risk.js +1 -373
  163. package/dist/knowledge/repository-translation.js +1 -445
  164. package/dist/knowledge/reputation-rules.js +1 -99
  165. package/dist/knowledge/resource-risk.js +1 -157
  166. package/dist/knowledge/reward-confirm.js +1 -526
  167. package/dist/knowledge/reward-context.js +1 -504
  168. package/dist/knowledge/reward-ledger.js +1 -502
  169. package/dist/knowledge/reward-puzzle.js +1 -300
  170. package/dist/knowledge/reward-risk.js +1 -627
  171. package/dist/knowledge/reward-templates.js +1 -197
  172. package/dist/knowledge/reward-translation.js +1 -501
  173. package/dist/knowledge/safety-rules.js +1 -404
  174. package/dist/knowledge/scenario-modes.js +1 -321
  175. package/dist/knowledge/service-confirm.js +1 -807
  176. package/dist/knowledge/service-context.js +1 -403
  177. package/dist/knowledge/service-ledger.js +1 -609
  178. package/dist/knowledge/service-puzzle.js +1 -236
  179. package/dist/knowledge/service-risk.js +1 -651
  180. package/dist/knowledge/service-templates.js +1 -456
  181. package/dist/knowledge/service-translation.js +1 -622
  182. package/dist/knowledge/template-registry.js +1 -353
  183. package/dist/knowledge/tool-constraints.js +1 -195
  184. package/dist/knowledge/tools-reference.js +1 -178
  185. package/dist/knowledge/treasury-confirm.js +1 -512
  186. package/dist/knowledge/treasury-context.js +1 -363
  187. package/dist/knowledge/treasury-ledger.js +1 -300
  188. package/dist/knowledge/treasury-puzzle.js +1 -216
  189. package/dist/knowledge/treasury-risk.js +1 -440
  190. package/dist/knowledge/treasury-templates.js +1 -358
  191. package/dist/knowledge/treasury-translation.js +1 -498
  192. package/dist/knowledge/trust-metrics.js +1 -198
  193. package/dist/knowledge/util-risk.js +1 -135
  194. package/dist/loop-engineering/aggregate.js +1 -132
  195. package/dist/loop-engineering/context-collect.js +1 -83
  196. package/dist/loop-engineering/diagnose.js +1 -273
  197. package/dist/loop-engineering/improve.js +1 -405
  198. package/dist/loop-engineering/index.js +1 -4
  199. package/dist/loop-engineering/pipeline.js +1 -56
  200. package/dist/mode-market/index.js +1 -3
  201. package/dist/mode-market/registry.js +1 -124
  202. package/dist/mode-market/review.js +1 -214
  203. package/dist/mode-market/submission.js +1 -85
  204. package/dist/participation/collaborator-interest.d.ts +23 -0
  205. package/dist/participation/collaborator-interest.js +1 -0
  206. package/dist/participation/customer-interest.d.ts +25 -0
  207. package/dist/participation/customer-interest.js +1 -0
  208. package/dist/participation/merchant-interest.js +1 -100
  209. package/dist/participation/radar-core.d.ts +13 -3
  210. package/dist/participation/radar-core.js +1 -269
  211. package/dist/participation/supplier-interest.d.ts +25 -0
  212. package/dist/participation/supplier-interest.js +1 -0
  213. package/dist/persona/analyzer.js +1 -66
  214. package/dist/persona/bridge.js +1 -86
  215. package/dist/persona/defaults.js +1 -195
  216. package/dist/persona/experience-bridge.js +1 -23
  217. package/dist/persona/index.js +1 -71
  218. package/dist/persona/model.js +1 -111
  219. package/dist/persona/store.js +1 -62
  220. package/dist/persona/types.d.ts +3 -1
  221. package/dist/persona/types.js +1 -5
  222. package/dist/project/business-puzzle.js +1 -383
  223. package/dist/project/context-assembly.js +1 -254
  224. package/dist/project/deployment-bridge.js +1 -120
  225. package/dist/project/deployment-doc.js +1 -1126
  226. package/dist/project/edit-planner.js +1 -1342
  227. package/dist/project/evaluation.js +1 -2011
  228. package/dist/project/game-theory.js +1 -177
  229. package/dist/project/graph-builder.js +1 -656
  230. package/dist/project/graph.js +1 -340
  231. package/dist/project/handlers.js +1 -1784
  232. package/dist/project/index.d.ts +1 -0
  233. package/dist/project/index.js +1 -301
  234. package/dist/project/intent-analyzer.js +1 -149
  235. package/dist/project/machine-nodes.js +1 -36
  236. package/dist/project/merchant-guide.js +1 -264
  237. package/dist/project/migration.js +1 -125
  238. package/dist/project/mode-actions.js +1 -309
  239. package/dist/project/namespace.js +1 -206
  240. package/dist/project/participation-radar.js +1 -428
  241. package/dist/project/pipeline-actions.js +1 -109
  242. package/dist/project/project-store.js +1 -422
  243. package/dist/project/query.js +1 -153
  244. package/dist/project/reverse-mapping.d.ts +34 -0
  245. package/dist/project/reverse-mapping.js +1 -0
  246. package/dist/project/risk-aggregator.js +1 -295
  247. package/dist/project/rollback-policy.js +1 -290
  248. package/dist/project/semantic-assembler.js +1 -345
  249. package/dist/project/semantic-graph.js +1 -292
  250. package/dist/project/stage-gate.js +1 -369
  251. package/dist/project/substep-trace.js +1 -332
  252. package/dist/project/task-tracker.js +1 -78
  253. package/dist/role/derivation.d.ts +18 -0
  254. package/dist/role/derivation.js +1 -0
  255. package/dist/role/index.d.ts +5 -0
  256. package/dist/role/index.js +1 -0
  257. package/dist/role/model.d.ts +8 -0
  258. package/dist/role/model.js +1 -0
  259. package/dist/role/resolution.d.ts +11 -0
  260. package/dist/role/resolution.js +1 -0
  261. package/dist/role/types.d.ts +11 -0
  262. package/dist/role/types.js +1 -0
  263. package/dist/rules.js +1 -52
  264. package/dist/safety/confirm-gate.js +1 -88
  265. package/dist/safety/index.js +1 -3
  266. package/dist/safety/preview.js +1 -52
  267. package/dist/schema/call/allocation.js +1 -34
  268. package/dist/schema/call/arbitration.js +1 -113
  269. package/dist/schema/call/base.d.ts +15 -15
  270. package/dist/schema/call/base.js +1 -370
  271. package/dist/schema/call/bridge-handler.js +1 -265
  272. package/dist/schema/call/bridge.d.ts +7 -7
  273. package/dist/schema/call/bridge.js +1 -458
  274. package/dist/schema/call/contact.js +1 -37
  275. package/dist/schema/call/demand.js +1 -47
  276. package/dist/schema/call/guard.js +1 -161
  277. package/dist/schema/call/handler.js +1 -322
  278. package/dist/schema/call/index.js +1 -20
  279. package/dist/schema/call/machine.js +1 -193
  280. package/dist/schema/call/order.js +1 -35
  281. package/dist/schema/call/payment.js +1 -37
  282. package/dist/schema/call/permission-handler.js +1 -54
  283. package/dist/schema/call/permission.js +1 -105
  284. package/dist/schema/call/personal.js +1 -78
  285. package/dist/schema/call/progress.js +1 -47
  286. package/dist/schema/call/proof.js +1 -33
  287. package/dist/schema/call/repository.js +1 -77
  288. package/dist/schema/call/reward.js +1 -30
  289. package/dist/schema/call/semantic.js +1 -1679
  290. package/dist/schema/call/service.js +1 -184
  291. package/dist/schema/call/treasury.js +1 -71
  292. package/dist/schema/common/index.js +1 -407
  293. package/dist/schema/config/index.js +1 -68
  294. package/dist/schema/evaluation/index.d.ts +213 -16
  295. package/dist/schema/evaluation/index.js +1 -356
  296. package/dist/schema/index.js +1 -17
  297. package/dist/schema/intent-radar/index.d.ts +13 -13
  298. package/dist/schema/intent-radar/index.js +1 -89
  299. package/dist/schema/local/index.d.ts +21 -21
  300. package/dist/schema/local/index.js +1 -927
  301. package/dist/schema/local/wip.js +1 -187
  302. package/dist/schema/messenger/index.d.ts +7 -7
  303. package/dist/schema/messenger/index.js +1 -475
  304. package/dist/schema/operations.d.ts +7 -7
  305. package/dist/schema/operations.js +1 -520
  306. package/dist/schema/persona/index.d.ts +54 -54
  307. package/dist/schema/persona/index.js +1 -148
  308. package/dist/schema/project/index.d.ts +94 -48
  309. package/dist/schema/project/index.js +1 -2057
  310. package/dist/schema/query/index.d.ts +423 -7
  311. package/dist/schema/query/index.js +1 -1646
  312. package/dist/schema/schema-query/index.js +1 -104
  313. package/dist/schema/schema-version.js +1 -76
  314. package/dist/schema/sync-layer4.js +1 -286
  315. package/dist/schema/task-status.js +1 -36
  316. package/dist/schema/trust/index.js +1 -314
  317. package/dist/schema/utils/guard-parser.js +1 -419
  318. package/dist/schema/utils/guard-query-utils.js +1 -46
  319. package/dist/schema/utils/node-parser.js +1 -369
  320. package/dist/schema/utils/object-type-utils.js +1 -35
  321. package/dist/schema/utils/permission-index-utils.js +1 -7
  322. package/dist/schema/utils/permission-machine-check.js +1 -121
  323. package/dist/schema/utils/skills-recommendation.js +1 -77
  324. package/dist/schema-query/index.js +1 -810
  325. package/dist/schemas/account_operation.output.json +5 -2
  326. package/dist/schemas/bridge_operation.output.json +5 -2
  327. package/dist/schemas/evaluation_operation.output.json +112 -7
  328. package/dist/schemas/evaluation_operation.schema.json +93 -6
  329. package/dist/schemas/index.json +1 -1
  330. package/dist/schemas/intent_radar.output.json +4 -1
  331. package/dist/schemas/intent_radar.schema.json +4 -1
  332. package/dist/schemas/local_info_operation.output.json +5 -2
  333. package/dist/schemas/local_mark_operation.output.json +5 -2
  334. package/dist/schemas/messenger_operation.output.json +5 -2
  335. package/dist/schemas/onchain_events.output.json +5 -2
  336. package/dist/schemas/onchain_operations.output.json +5 -2
  337. package/dist/schemas/onchain_operations.schema.json +4 -4
  338. package/dist/schemas/onchain_operations_allocation.schema.json +1 -1
  339. package/dist/schemas/onchain_operations_machine.schema.json +2 -2
  340. package/dist/schemas/onchain_operations_service.schema.json +1 -1
  341. package/dist/schemas/onchain_table_data.output.json +6 -3
  342. package/dist/schemas/persona_operation.output.json +4 -1
  343. package/dist/schemas/persona_operation.schema.json +4 -1
  344. package/dist/schemas/project_operation.output.json +28 -8
  345. package/dist/schemas/query_toolkit.output.json +8 -5
  346. package/dist/schemas/wowok_buildin_info.output.json +132 -0
  347. package/dist/schemas/wowok_buildin_info.schema.json +14 -0
  348. package/dist/telemetry/index.js +1 -112
  349. package/dist/telemetry/redact.js +1 -23
  350. package/dist/telemetry/storage.js +1 -80
  351. package/dist/tools/handlers/bridge.js +1 -1
  352. package/dist/tools/handlers/config.js +1 -74
  353. package/dist/tools/handlers/evaluation.js +1 -123
  354. package/dist/tools/handlers/file-export.js +1 -90
  355. package/dist/tools/handlers/intent-radar.js +1 -76
  356. package/dist/tools/handlers/local.js +1 -53
  357. package/dist/tools/handlers/messenger.js +1 -188
  358. package/dist/tools/handlers/onchain.js +1 -1180
  359. package/dist/tools/handlers/persona.js +1 -89
  360. package/dist/tools/handlers/project.js +1 -211
  361. package/dist/tools/handlers/query.js +1 -434
  362. package/dist/tools/handlers/schema-query.js +1 -176
  363. package/dist/tools/handlers/task-status.js +1 -26
  364. package/dist/tools/handlers/trust.js +1 -380
  365. package/dist/tools/handlers/wip.js +1 -90
  366. package/dist/tools/index.js +1 -1382
  367. package/dist/tools/retry.js +1 -85
  368. package/dist/tools/rules-hook.js +1 -23
  369. package/dist/tools/shared.js +1 -130
  370. package/dist/tools/types.js +1 -1
  371. package/dist/tools/upgrade-check.d.ts +19 -0
  372. package/dist/tools/upgrade-check.js +1 -0
  373. package/dist/tools/wip-deploy-assist.js +1 -306
  374. package/dist/tools/wrap.js +1 -500
  375. package/package.json +4 -2
@@ -1,428 +1 @@
1
- import { LocalMark, query_objects, query_table, watch_conversations, } from "@wowok/wowok";
2
- import { analyzeOrderParticipation, aggregateRadar, isConsequenceNode, } from "../participation/radar-core.js";
3
- import { monitorOrder } from "../customer/order-monitor.js";
4
- import { analyzeMerchantInterest } from "../participation/merchant-interest.js";
5
- import { fetchMachineNodes } from "./machine-nodes.js";
6
- import { extractGenericTokenType, registryDisplayHint } from "../knowledge/fund-layer.js";
7
- const QUERY_BATCH = 50;
8
- function fld(obj, key) {
9
- return (obj?.[key] ?? obj?.data?.[key]);
10
- }
11
- async function resolveAddress(nameOrAddress, what) {
12
- const addr = await LocalMark.Instance().get_address(nameOrAddress);
13
- if (!addr) {
14
- throw new Error(`Cannot resolve ${what} '${nameOrAddress}' — not a valid address and no LocalMark entry found. ` +
15
- `Register it via local_mark_operation or pass the 0x address directly.`);
16
- }
17
- return addr;
18
- }
19
- function balanceStr(v) {
20
- if (v == null)
21
- return undefined;
22
- if (typeof v === "object" && "balance" in v)
23
- return String(v.balance);
24
- return String(v);
25
- }
26
- function balanceToken(v) {
27
- if (v != null && typeof v === "object" && typeof v.token_type === "string") {
28
- return v.token_type;
29
- }
30
- return undefined;
31
- }
32
- function summarizeAllocation(raw, account) {
33
- const list = Array.isArray(raw)
34
- ? raw
35
- : Array.isArray(raw?.allocators)
36
- ? raw.allocators
37
- : [];
38
- if (list.length === 0)
39
- return undefined;
40
- let recipient_slots = 0;
41
- let guard_gated_slots = 0;
42
- let direct_to_me_slots = 0;
43
- let to_payer_slots = 0;
44
- const me = account.toLowerCase();
45
- for (const allocator of list) {
46
- for (const s of allocator?.sharing ?? []) {
47
- recipient_slots++;
48
- const who = s?.who;
49
- if (who == null)
50
- continue;
51
- if (typeof who === "object" && "GuardIdentifier" in who)
52
- guard_gated_slots++;
53
- else if (typeof who === "object" && "Signer" in who)
54
- to_payer_slots++;
55
- else if (typeof who === "object" && "Entity" in who) {
56
- const entity = who.Entity;
57
- const addr = typeof entity === "string" ? entity : entity?.name_or_address;
58
- if (typeof addr === "string" && addr.toLowerCase() === me)
59
- direct_to_me_slots++;
60
- }
61
- else if (typeof who === "string" && who.toLowerCase() === me) {
62
- direct_to_me_slots++;
63
- }
64
- }
65
- }
66
- return { recipient_slots, guard_gated_slots, direct_to_me_slots, to_payer_slots };
67
- }
68
- async function queryObjectsBatched(addresses, network) {
69
- const out = [];
70
- for (let i = 0; i < addresses.length; i += QUERY_BATCH) {
71
- const batch = addresses.slice(i, i + QUERY_BATCH);
72
- const res = await query_objects({ objects: batch, network });
73
- out.push(...(res?.objects ?? []));
74
- }
75
- return out;
76
- }
77
- async function fetchEntityPermissions(permissionAddress, network) {
78
- const map = new Map();
79
- const fieldIds = [];
80
- let cursor = undefined;
81
- for (;;) {
82
- const tableResult = await query_table({
83
- parent: permissionAddress,
84
- cursor: cursor ?? undefined,
85
- network,
86
- });
87
- if (!tableResult?.items || tableResult.items.length === 0)
88
- break;
89
- for (const item of tableResult.items) {
90
- if (item.object)
91
- fieldIds.push(item.object);
92
- }
93
- if (!tableResult.hasNextPage || !tableResult.nextCursor)
94
- break;
95
- cursor = tableResult.nextCursor;
96
- }
97
- const items = (await queryObjectsBatched(fieldIds, network));
98
- for (const item of items) {
99
- if (item?.type !== "TableItem_PermissionPerm")
100
- continue;
101
- const entity = fld(item, "address");
102
- const permRaw = fld(item, "perm") ?? [];
103
- const indexes = permRaw
104
- .map(p => (typeof p === "number" ? p : typeof p?.index === "number" ? p.index : null))
105
- .filter((p) => p !== null);
106
- if (entity)
107
- map.set(entity, indexes);
108
- }
109
- return map;
110
- }
111
- function toRadarMachineNodes(raw) {
112
- return raw.map(n => ({
113
- name: n.name,
114
- pairs: (Array.isArray(n.value) ? n.value : []).map(pair => ({
115
- prev_node: pair.prev_node,
116
- forwards: (pair.forwards ?? []).map(f => ({
117
- name: f.name,
118
- permissionIndex: f.permissionIndex ?? null,
119
- namedOperator: f.namedOperator ?? null,
120
- guard: f.guard?.guard ?? (typeof f.guard === "string" ? f.guard : null),
121
- weight: f.weight ?? null,
122
- })),
123
- })),
124
- }));
125
- }
126
- export async function handleParticipationRadar(v) {
127
- if (!v.radar_account) {
128
- throw new Error("'radar_account' is required for participation_radar");
129
- }
130
- if (!v.radar_targets || v.radar_targets.length === 0) {
131
- throw new Error("'radar_targets' (1-20 in-flight orders) is required for participation_radar");
132
- }
133
- const network = (v.network ?? "testnet");
134
- const includeAlerts = v.radar_include_alerts ?? true;
135
- const gaps = [];
136
- const account = await resolveAddress(v.radar_account, "radar_account");
137
- const targets = await Promise.all(v.radar_targets.map(async (t) => ({
138
- progress: await resolveAddress(t.progress, "progress"),
139
- order: t.order ? await resolveAddress(t.order, "order") : undefined,
140
- })));
141
- const allAddrs = targets.flatMap(t => (t.order ? [t.progress, t.order] : [t.progress]));
142
- const objects = await queryObjectsBatched(allAddrs, network);
143
- const byAddress = new Map();
144
- for (const o of objects) {
145
- const addr = fld(o, "object");
146
- if (addr)
147
- byAddress.set(addr, o);
148
- }
149
- const progressObjs = new Map();
150
- const orderObjs = new Map();
151
- for (const t of targets) {
152
- const p = byAddress.get(t.progress);
153
- if (!p) {
154
- gaps.push(`Progress ${t.progress} not found on ${network} — target skipped.`);
155
- continue;
156
- }
157
- progressObjs.set(t.progress, p);
158
- if (t.order) {
159
- const o = byAddress.get(t.order);
160
- if (o)
161
- orderObjs.set(t.order, o);
162
- else
163
- gaps.push(`Order ${t.order} not found on ${network} — order-holder detection disabled for ${t.progress}.`);
164
- }
165
- }
166
- if (targets.length > 0 && progressObjs.size === 0) {
167
- gaps.push(`NETWORK MISMATCH SUSPECTED: 0/${targets.length} radar targets exist on network='${network}'. ` +
168
- `These objects most likely live on a different network — re-run with the matching 'network' parameter.`);
169
- }
170
- const machineAddrs = [...new Set([...progressObjs.values()].map(p => fld(p, "machine")).filter((x) => !!x))];
171
- const serviceAddrs = [...new Set([...orderObjs.values()].map(o => fld(o, "service")).filter((x) => !!x))];
172
- const arbAddrs = [...new Set([...orderObjs.values()].flatMap(o => {
173
- const d = fld(o, "dispute");
174
- return Array.isArray(d) ? d : [];
175
- }))];
176
- const machineObjs = new Map();
177
- const machineNodes = new Map();
178
- const serviceObjs = new Map();
179
- const arbObjs = new Map();
180
- await Promise.all([
181
- ...machineAddrs.map(async (addr) => {
182
- try {
183
- const [objArr, nodes] = await Promise.all([
184
- queryObjectsBatched([addr], network),
185
- fetchMachineNodes(addr, network),
186
- ]);
187
- if (objArr[0])
188
- machineObjs.set(addr, objArr[0]);
189
- machineNodes.set(addr, toRadarMachineNodes(nodes));
190
- }
191
- catch (e) {
192
- gaps.push(`Machine ${addr} fetch failed: ${e.message} — workflow unknown for its orders.`);
193
- }
194
- }),
195
- (async () => {
196
- if (serviceAddrs.length === 0)
197
- return;
198
- try {
199
- const arr = await queryObjectsBatched(serviceAddrs, network);
200
- for (const s of arr) {
201
- const addr = fld(s, "object");
202
- if (addr)
203
- serviceObjs.set(addr, s);
204
- }
205
- }
206
- catch (e) {
207
- gaps.push(`Service query failed: ${e.message} — compensation/reward context degraded.`);
208
- }
209
- })(),
210
- (async () => {
211
- if (arbAddrs.length === 0)
212
- return;
213
- try {
214
- const arr = await queryObjectsBatched(arbAddrs, network);
215
- for (const a of arr) {
216
- const addr = fld(a, "object");
217
- if (addr)
218
- arbObjs.set(addr, a);
219
- }
220
- }
221
- catch (e) {
222
- gaps.push(`Arb query failed: ${e.message} — compensation claim detection disabled.`);
223
- }
224
- })(),
225
- ]);
226
- const permissionByMachine = new Map();
227
- const permAddrs = [...new Set(machineAddrs.map(a => fld(machineObjs.get(a), "permission")).filter((x) => !!x))];
228
- const permData = new Map();
229
- await Promise.all(permAddrs.map(async (addr) => {
230
- try {
231
- const [objArr, entityPermissions] = await Promise.all([
232
- queryObjectsBatched([addr], network),
233
- fetchEntityPermissions(addr, network),
234
- ]);
235
- const permObj = objArr[0];
236
- permData.set(addr, {
237
- address: addr,
238
- entity_count: fld(permObj, "entity_count"),
239
- perm_remark: fld(permObj, "perm_remark"),
240
- entityPermissions,
241
- });
242
- }
243
- catch (e) {
244
- gaps.push(`Permission ${addr} fetch failed: ${e.message} — operator permission matching degraded.`);
245
- }
246
- }));
247
- for (const mAddr of machineAddrs) {
248
- const pAddr = fld(machineObjs.get(mAddr), "permission");
249
- if (pAddr && permData.has(pAddr))
250
- permissionByMachine.set(mAddr, permData.get(pAddr));
251
- }
252
- let unreadTotal = 0;
253
- const unreadByPeer = new Map();
254
- try {
255
- const convos = await watch_conversations({
256
- account,
257
- unreadOnly: true,
258
- previewMessageCount: 0,
259
- skipAutoMarkViewed: true,
260
- });
261
- const list = Array.isArray(convos) ? convos : convos?.conversations ?? [];
262
- for (const c of list) {
263
- const peer = c?.peerAddress;
264
- const n = typeof c?.unreadCount === "number" ? c.unreadCount : 0;
265
- if (typeof peer === "string" && n > 0) {
266
- unreadByPeer.set(peer.toLowerCase(), n);
267
- unreadTotal += n;
268
- }
269
- }
270
- }
271
- catch {
272
- gaps.push("Messenger unread unavailable (radar account is not a local messenger account, or messenger storage offline) " +
273
- "— unread_messages_total reported as 0.");
274
- }
275
- const results = [];
276
- const now = Date.now();
277
- for (const t of targets) {
278
- const progress = progressObjs.get(t.progress);
279
- if (!progress)
280
- continue;
281
- const order = t.order ? orderObjs.get(t.order) : undefined;
282
- const machineAddr = fld(progress, "machine");
283
- const currentNode = fld(progress, "current") ?? "";
284
- const namedOperators = fld(progress, "namedOperator") ?? [];
285
- const namedAccounts = {};
286
- for (const n of namedOperators) {
287
- if (n?.name)
288
- namedAccounts[n.name] = Array.isArray(n.operators) ? n.operators : [];
289
- }
290
- const serviceAddr = order ? fld(order, "service") : undefined;
291
- const service = serviceAddr ? serviceObjs.get(serviceAddr) : undefined;
292
- let pendingCompensation;
293
- const builder = order ? fld(order, "builder") : undefined;
294
- if (order && builder === account) {
295
- const disputes = fld(order, "dispute") ?? [];
296
- for (const arbAddr of disputes) {
297
- const arb = arbObjs.get(arbAddr);
298
- if (!arb)
299
- continue;
300
- const indemnity = fld(arb, "indemnity");
301
- if (indemnity) {
302
- pendingCompensation = {
303
- arbitration: fld(arb, "arbitration") ?? arbAddr,
304
- note: `Arbitration verdict recorded an indemnity (Arb ${arbAddr}). ` +
305
- `Claim via service op='compensation_claim' — paid directly from the Service compensation_fund. ` +
306
- `(Claimed-status is not readable from the Arb object; the contract rejects double-claims.)`,
307
- };
308
- break;
309
- }
310
- }
311
- }
312
- const claimableRewards = [];
313
- if (service && builder === account) {
314
- const rewards = fld(service, "rewards") ?? [];
315
- for (const r of rewards) {
316
- claimableRewards.push({
317
- address: r,
318
- description: `Service reward ${r} (guard-gated — eligibility verified at claim time)`,
319
- });
320
- }
321
- }
322
- const completed = isConsequenceNode(currentNode, "completed");
323
- const refunded = isConsequenceNode(currentNode, "refunded");
324
- let orderUnread = 0;
325
- if (unreadByPeer.size > 0) {
326
- const counterparties = new Set();
327
- if (builder)
328
- counterparties.add(builder.toLowerCase());
329
- for (const ops of Object.values(namedAccounts)) {
330
- for (const op of ops)
331
- counterparties.add(op.toLowerCase());
332
- }
333
- counterparties.delete(account.toLowerCase());
334
- for (const peer of counterparties) {
335
- orderUnread += unreadByPeer.get(peer) ?? 0;
336
- }
337
- }
338
- const radarInput = {
339
- account,
340
- progress_address: t.progress,
341
- order_address: t.order,
342
- current_node: currentNode,
343
- order_holder: builder,
344
- machine_nodes: machineAddr ? machineNodes.get(machineAddr) : undefined,
345
- permission: machineAddr ? permissionByMachine.get(machineAddr) ?? null : null,
346
- named_accounts: namedAccounts,
347
- claimable_rewards: claimableRewards.length > 0 ? claimableRewards : undefined,
348
- pending_compensation: pendingCompensation,
349
- rating_pending: completed && builder === account,
350
- unread_messages: orderUnread > 0 ? orderUnread : undefined,
351
- last_progress_at: fld(progress, "current_time") ?? undefined,
352
- now,
353
- };
354
- const result = analyzeOrderParticipation(radarInput);
355
- if (result.perspective === "operator") {
356
- result.interest_analysis = analyzeMerchantInterest({
357
- account,
358
- current_node: currentNode,
359
- operable: result.operable,
360
- waiting_on: result.waiting_on,
361
- order_amount: balanceStr(fld(order, "amount")),
362
- token_type: balanceToken(fld(order, "amount")),
363
- allocation: summarizeAllocation(fld(service, "order_allocators"), account),
364
- compensation_fund: balanceStr(fld(service, "compensation_fund")),
365
- arbitration_bound: (fld(service, "arbitrations") ?? []).length > 0,
366
- rewards_count: (fld(service, "rewards") ?? []).length,
367
- stalled_hours: radarInput.last_progress_at != null
368
- ? (now - radarInput.last_progress_at) / 3_600_000
369
- : undefined,
370
- terminal: completed ? "completed" : refunded ? "refunded" : null,
371
- unread_messages: orderUnread > 0 ? orderUnread : undefined,
372
- });
373
- }
374
- if (includeAlerts && order) {
375
- const snapshot = {
376
- order_id: t.order,
377
- service_id: serviceAddr ?? "",
378
- current_node: currentNode || undefined,
379
- created_at: Number(fld(order, "time") ?? now) || now,
380
- last_progress_at: fld(progress, "current_time") ?? undefined,
381
- now,
382
- order_amount: (() => { try {
383
- return BigInt(fld(order, "amount") ?? 0);
384
- }
385
- catch {
386
- return undefined;
387
- } })(),
388
- compensation_balance: (() => { try {
389
- const c = fld(service, "compensation_fund");
390
- return c != null ? BigInt(c) : undefined;
391
- }
392
- catch {
393
- return undefined;
394
- } })(),
395
- token: registryDisplayHint(extractGenericTokenType(fld(service, "type_raw"))),
396
- has_arbitration: (fld(service, "arbitrations") ?? []).length > 0,
397
- pending_user_action: result.operable.some(f => f.execution_path === "order_holder"),
398
- completed,
399
- refunded,
400
- };
401
- try {
402
- const alerts = monitorOrder({
403
- current: snapshot,
404
- thresholds: v.radar_monitor_thresholds,
405
- });
406
- if (alerts.length > 0) {
407
- result.attached_alerts = alerts;
408
- }
409
- }
410
- catch (e) {
411
- gaps.push(`Order monitor failed for ${t.order}: ${e.message}.`);
412
- }
413
- }
414
- results.push(result);
415
- }
416
- const dashboard = aggregateRadar(results, unreadTotal);
417
- return {
418
- action: "participation_radar",
419
- account,
420
- orders_analyzed: dashboard.orders_analyzed,
421
- actionable: dashboard.actionable,
422
- waiting: dashboard.waiting,
423
- all_pending_claims: dashboard.all_pending_claims,
424
- unread_messages_total: dashboard.unread_messages_total,
425
- data_gaps: gaps,
426
- summary: dashboard.summary,
427
- };
428
- }
1
+ import{LocalMark,query_objects,query_table,watch_conversations}from'@wowok/wowok';import{analyzeOrderParticipation,aggregateRadar,isConsequenceNode}from'../participation/radar-core.js';import{monitorOrder}from'../customer/order-monitor.js';import{analyzeMerchantInterest}from'../participation/merchant-interest.js';import{analyzeCustomerInterest}from'../participation/customer-interest.js';import{analyzeSupplierInterest}from'../participation/supplier-interest.js';import{analyzeCollaboratorInterest}from'../participation/collaborator-interest.js';import{fetchMachineNodes}from'./machine-nodes.js';import{extractGenericTokenType,registryDisplayHint}from'../knowledge/fund-layer.js';const QUERY_BATCH=0x32;function fld(a,b){return a?.[b]??a?.['data']?.[b];}async function resolveAddress(a,b){const c=await LocalMark['Instance']()['get_address'](a);if(!c)throw new Error('Cannot\x20resolve\x20'+b+'\x20\x27'+a+'\x27\x20—\x20not\x20a\x20valid\x20address\x20and\x20no\x20LocalMark\x20entry\x20found.\x20'+'Register\x20it\x20via\x20local_mark_operation\x20or\x20pass\x20the\x200x\x20address\x20directly.');return c;}function balanceStr(a){if(a==null)return undefined;if(typeof a==='object'&&'balance'in a)return String(a['balance']);return String(a);}function balanceToken(a){if(a!=null&&typeof a==='object'&&typeof a['token_type']==='string')return a['token_type'];return undefined;}function summarizeAllocation(a,b){const c=Array['isArray'](a)?a:Array['isArray'](a?.['allocators'])?a['allocators']:[];if(c['length']===0x0)return undefined;let d=0x0,e=0x0,f=0x0,g=0x0;const h=b['toLowerCase']();for(const i of c){for(const j of i?.['sharing']??[]){d++;const k=j?.['who'];if(k==null)continue;if(typeof k==='object'&&'GuardIdentifier'in k)e++;else{if(typeof k==='object'&&'Signer'in k)g++;else{if(typeof k==='object'&&'Entity'in k){const l=k['Entity'],m=typeof l==='string'?l:l?.['name_or_address'];if(typeof m==='string'&&m['toLowerCase']()===h)f++;}else typeof k==='string'&&k['toLowerCase']()===h&&f++;}}}}return{'recipient_slots':d,'guard_gated_slots':e,'direct_to_me_slots':f,'to_payer_slots':g};}async function queryObjectsBatched(a,b){const c=[];for(let d=0x0;d<a['length'];d+=QUERY_BATCH){const e=a['slice'](d,d+QUERY_BATCH),f=await query_objects({'objects':e,'network':b});c['push'](...f?.['objects']??[]);}return c;}async function fetchEntityPermissions(a,b){const c=new Map(),d=[];let e=undefined;for(;;){const g=await query_table({'parent':a,'cursor':e??undefined,'network':b});if(!g?.['items']||g['items']['length']===0x0)break;for(const h of g['items']){if(h['object'])d['push'](h['object']);}if(!g['hasNextPage']||!g['nextCursor'])break;e=g['nextCursor'];}const f=await queryObjectsBatched(d,b);for(const i of f){if(i?.['type']!=='TableItem_PermissionPerm')continue;const j=fld(i,'address'),k=fld(i,'perm')??[],l=k['map'](m=>typeof m==='number'?m:typeof m?.['index']==='number'?m['index']:null)['filter'](m=>m!==null);if(j)c['set'](j,l);}return c;}function toRadarMachineNodes(a){return a['map'](b=>({'name':b['name'],'pairs':(Array['isArray'](b['value'])?b['value']:[])['map'](c=>({'prev_node':c['prev_node'],'threshold':c['threshold']??undefined,'forwards':(c['forwards']??[])['map'](d=>({'name':d['name'],'permissionIndex':d['permissionIndex']??null,'namedOperator':d['namedOperator']??null,'guard':d['guard']?.['guard']??(typeof d['guard']==='string'?d['guard']:null),'weight':d['weight']??null}))}))}));}export async function handleParticipationRadar(a){if(!a['radar_account'])throw new Error('\x27radar_account\x27\x20is\x20required\x20for\x20participation_radar');if(!a['radar_targets']||a['radar_targets']['length']===0x0)throw new Error('\x27radar_targets\x27\x20(1-20\x20in-flight\x20orders)\x20is\x20required\x20for\x20participation_radar');const b=a['network']??'testnet',d=a['radar_include_alerts']??!![],f=[],g=await resolveAddress(a['radar_account'],'radar_account'),h=await Promise['all'](a['radar_targets']['map'](async I=>({'progress':await resolveAddress(I['progress'],'progress'),'order':I['order']?await resolveAddress(I['order'],'order'):undefined}))),i=h['flatMap'](I=>I['order']?[I['progress'],I['order']]:[I['progress']]),j=await queryObjectsBatched(i,b),k=new Map();for(const I of j){const J=fld(I,'object');if(J)k['set'](J,I);}const l=new Map(),m=new Map();for(const K of h){const L=k['get'](K['progress']);if(!L){f['push']('Progress\x20'+K['progress']+'\x20not\x20found\x20on\x20'+b+'\x20—\x20target\x20skipped.');continue;}l['set'](K['progress'],L);if(K['order']){const M=k['get'](K['order']);if(M)m['set'](K['order'],M);else f['push']('Order\x20'+K['order']+'\x20not\x20found\x20on\x20'+b+'\x20—\x20order-holder\x20detection\x20disabled\x20for\x20'+K['progress']+'.');}}h['length']>0x0&&l['size']===0x0&&f['push']('NETWORK\x20MISMATCH\x20SUSPECTED:\x200/'+h['length']+'\x20radar\x20targets\x20exist\x20on\x20network=\x27'+b+'\x27.\x20'+'These\x20objects\x20most\x20likely\x20live\x20on\x20a\x20different\x20network\x20—\x20re-run\x20with\x20the\x20matching\x20\x27network\x27\x20parameter.');const q=[...new Set([...l['values']()]['map'](N=>fld(N,'machine'))['filter'](N=>!!N))],s=[...new Set([...m['values']()]['map'](N=>fld(N,'service'))['filter'](N=>!!N))],u=[...new Set([...m['values']()]['flatMap'](N=>{const O=fld(N,'dispute');return Array['isArray'](O)?O:[];}))],w=new Map(),x=new Map(),y=new Map(),z=new Map();await Promise['all']([...q['map'](async N=>{try{const [O,P]=await Promise['all']([queryObjectsBatched([N],b),fetchMachineNodes(N,b)]);if(O[0x0])w['set'](N,O[0x0]);x['set'](N,toRadarMachineNodes(P));}catch(Q){f['push']('Machine\x20'+N+'\x20fetch\x20failed:\x20'+Q['message']+'\x20—\x20workflow\x20unknown\x20for\x20its\x20orders.');}}),((async()=>{if(s['length']===0x0)return;try{const N=await queryObjectsBatched(s,b);for(const O of N){const P=fld(O,'object');if(P)y['set'](P,O);}}catch(Q){f['push']('Service\x20query\x20failed:\x20'+Q['message']+'\x20—\x20compensation/reward\x20context\x20degraded.');}})()),((async()=>{if(u['length']===0x0)return;try{const N=await queryObjectsBatched(u,b);for(const O of N){const P=fld(O,'object');if(P)z['set'](P,O);}}catch(Q){f['push']('Arb\x20query\x20failed:\x20'+Q['message']+'\x20—\x20compensation\x20claim\x20detection\x20disabled.');}})())]);const A=new Map(),B=[...new Set(q['map'](N=>fld(w['get'](N),'permission'))['filter'](N=>!!N))],C=new Map();await Promise['all'](B['map'](async N=>{try{const [O,P]=await Promise['all']([queryObjectsBatched([N],b),fetchEntityPermissions(N,b)]),Q=O[0x0];C['set'](N,{'address':N,'entity_count':fld(Q,'entity_count'),'perm_remark':fld(Q,'perm_remark'),'entityPermissions':P,'owner':fld(Q,'builder')});}catch(R){f['push']('Permission\x20'+N+'\x20fetch\x20failed:\x20'+R['message']+'\x20—\x20operator\x20permission\x20matching\x20degraded.');}}));for(const N of q){const O=fld(w['get'](N),'permission');if(O&&C['has'](O))A['set'](N,C['get'](O));}let D=0x0;const E=new Map();try{const P=await watch_conversations({'account':g,'unreadOnly':!![],'previewMessageCount':0x0,'skipAutoMarkViewed':!![]}),Q=Array['isArray'](P)?P:P?.['conversations']??[];for(const R of Q){const S=R?.['peerAddress'],T=typeof R?.['unreadCount']==='number'?R['unreadCount']:0x0;typeof S==='string'&&T>0x0&&(E['set'](S['toLowerCase'](),T),D+=T);}}catch{f['push']('Messenger\x20unread\x20unavailable\x20(radar\x20account\x20is\x20not\x20a\x20local\x20messenger\x20account,\x20or\x20messenger\x20storage\x20offline)\x20'+'—\x20unread_messages_total\x20reported\x20as\x200.');}const F=[],G=Date['now']();for(const U of h){const V=l['get'](U['progress']);if(!V)continue;const W=U['order']?m['get'](U['order']):undefined,X=fld(V,'machine'),Y=fld(V,'current')??'',Z=fld(V,'namedOperator')??[],a0={};for(const ae of Z){if(ae?.['name'])a0[ae['name']]=Array['isArray'](ae['operators'])?ae['operators']:[];}const a1=W?fld(W,'service'):undefined,a2=a1?y['get'](a1):undefined;let a3;const a4=W?fld(W,'builder'):undefined;if(W&&a4===g){const af=fld(W,'dispute')??[];for(const ag of af){const ah=z['get'](ag);if(!ah)continue;const ai=fld(ah,'indemnity');if(ai){a3={'arbitration':fld(ah,'arbitration')??ag,'note':'Arbitration\x20verdict\x20recorded\x20an\x20indemnity\x20(Arb\x20'+ag+').\x20'+'Claim\x20via\x20service\x20op=\x27compensation_claim\x27\x20—\x20paid\x20directly\x20from\x20the\x20Service\x20compensation_fund.\x20'+'(Claimed-status\x20is\x20not\x20readable\x20from\x20the\x20Arb\x20object;\x20the\x20contract\x20rejects\x20double-claims.)'};break;}}}const a5=[];if(a2&&a4===g){const aj=fld(a2,'rewards')??[];for(const ak of aj){a5['push']({'address':ak,'description':'Service\x20reward\x20'+ak+'\x20(guard-gated\x20—\x20eligibility\x20verified\x20at\x20claim\x20time)'});}}const a6=isConsequenceNode(Y,'completed'),a7=isConsequenceNode(Y,'refunded');let a8=0x0;if(E['size']>0x0){const al=new Set();if(a4)al['add'](a4['toLowerCase']());for(const am of Object['values'](a0)){for(const an of am)al['add'](an['toLowerCase']());}al['delete'](g['toLowerCase']());for(const ao of al){a8+=E['get'](ao)??0x0;}}const a9={'account':g,'progress_address':U['progress'],'order_address':U['order'],'current_node':Y,'order_holder':a4,'machine_nodes':X?x['get'](X):undefined,'permission':X?A['get'](X)??null:null,'named_accounts':a0,'service_builder':X?A['get'](X)?.['owner']:undefined,'claimable_rewards':a5['length']>0x0?a5:undefined,'pending_compensation':a3,'rating_pending':a6&&a4===g,'unread_messages':a8>0x0?a8:undefined,'last_progress_at':fld(V,'current_time')??undefined,'now':G},aa=analyzeOrderParticipation(a9),ab=(fld(a2,'arbitrations')??[])['length']>0x0,ac=a6?'completed':a7?'refunded':null,ad=a9['last_progress_at']!=null?(G-a9['last_progress_at'])/0x36ee80:undefined;if(aa['perspective']==='merchant')aa['interest_analysis']=analyzeMerchantInterest({'account':g,'current_node':Y,'operable':aa['operable'],'waiting_on':aa['waiting_on'],'order_amount':balanceStr(fld(W,'amount')),'token_type':balanceToken(fld(W,'amount')),'allocation':summarizeAllocation(fld(a2,'order_allocators'),g),'compensation_fund':balanceStr(fld(a2,'compensation_fund')),'arbitration_bound':ab,'rewards_count':(fld(a2,'rewards')??[])['length'],'stalled_hours':ad,'terminal':ac,'unread_messages':a8>0x0?a8:undefined});else{if(aa['perspective']==='supplier')aa['interest_analysis']=analyzeSupplierInterest({'account':g,'current_node':Y,'operable':aa['operable'],'waiting_on':aa['waiting_on'],'order_amount':balanceStr(fld(W,'amount')),'token_type':balanceToken(fld(W,'amount')),'arbitration_bound':ab,'compensation_fund':balanceStr(fld(a2,'compensation_fund')),'terminal':ac,'stalled_hours':ad,'unread_messages':a8>0x0?a8:undefined});else{if(aa['perspective']==='collaborator')aa['interest_analysis']=analyzeCollaboratorInterest({'account':g,'current_node':Y,'operable':aa['operable'],'waiting_on':aa['waiting_on'],'collaborator_kind':aa['collaborator_kind'],'arbitration_bound':ab,'terminal':ac,'stalled_hours':ad,'unread_messages':a8>0x0?a8:undefined});else aa['perspective']==='customer'&&(aa['interest_analysis']=analyzeCustomerInterest({'account':g,'current_node':Y,'operable':aa['operable'],'waiting_on':aa['waiting_on'],'order_amount':balanceStr(fld(W,'amount')),'token_type':balanceToken(fld(W,'amount')),'compensation_fund':balanceStr(fld(a2,'compensation_fund')),'arbitration_bound':ab,'terminal':ac,'stalled_hours':ad,'unread_messages':a8>0x0?a8:undefined}));}}if(d&&W){const ap={'order_id':U['order'],'service_id':a1??'','current_node':Y||undefined,'created_at':Number(fld(W,'time')??G)||G,'last_progress_at':fld(V,'current_time')??undefined,'now':G,'order_amount':((()=>{try{return BigInt(fld(W,'amount')??0x0);}catch{return undefined;}})()),'compensation_balance':((()=>{try{const aq=fld(a2,'compensation_fund');return aq!=null?BigInt(aq):undefined;}catch{return undefined;}})()),'token':registryDisplayHint(extractGenericTokenType(fld(a2,'type_raw'))),'has_arbitration':(fld(a2,'arbitrations')??[])['length']>0x0,'pending_user_action':aa['operable']['some'](aq=>aq['execution_path']==='order_holder'),'completed':a6,'refunded':a7};try{const aq=monitorOrder({'current':ap,'thresholds':a['radar_monitor_thresholds']});aq['length']>0x0&&(aa['attached_alerts']=aq);}catch(ar){f['push']('Order\x20monitor\x20failed\x20for\x20'+U['order']+':\x20'+ar['message']+'.');}}F['push'](aa);}const H=aggregateRadar(F,D);return{'action':'participation_radar','account':g,'orders_analyzed':H['orders_analyzed'],'actionable':H['actionable'],'waiting':H['waiting'],'all_pending_claims':H['all_pending_claims'],'unread_messages_total':H['unread_messages_total'],'data_gaps':f,'summary':H['summary']};}
@@ -1,109 +1 @@
1
- import { analyzeBusinessIntent } from "./business-puzzle.js";
2
- import { aggregateProjectRisks } from "./risk-aggregator.js";
3
- import { traceSubsteps } from "./substep-trace.js";
4
- import { updateStageCache } from "./index.js";
5
- import { checkObjectReuseRules, checkImmutabilityRules, } from "../knowledge/safety-rules.js";
6
- export function handleAnalyzeIntent(v) {
7
- const user_intent = (v.intent ?? v.project_description ?? v.project_name ?? "").trim();
8
- if (!user_intent) {
9
- throw new Error("analyze_intent requires 'intent' (business description text). " +
10
- "Example: intent='I want to open an online toy store with escrow and dispute resolution'.");
11
- }
12
- const result = analyzeBusinessIntent({
13
- user_intent,
14
- project_name: v.project_name,
15
- target_objects: v.target_objects,
16
- industry: v.project_industry,
17
- });
18
- const project_prefix = (v.project ?? "").trim();
19
- if (project_prefix) {
20
- updateStageCache(project_prefix, (v.version ?? "v1").trim(), {
21
- stage: 2,
22
- puzzles: result.puzzles,
23
- business_intent: user_intent,
24
- industry: result.intent_parsed.industry,
25
- });
26
- }
27
- return { action: "analyze_intent", ...result };
28
- }
29
- export function handleAggregateRisks(v) {
30
- const project_prefix = (v.project ?? "").trim();
31
- if (!project_prefix) {
32
- throw new Error("aggregate_risks requires 'project' (project prefix, e.g. 'myshop'). " +
33
- "Use the same prefix as create_project so findings map to the project namespace.");
34
- }
35
- const version = (v.version ?? "v1").trim();
36
- let puzzles;
37
- let intent_echo;
38
- if (v.puzzles) {
39
- puzzles = Object.fromEntries(Object.entries(v.puzzles).map(([k, e]) => [
40
- k,
41
- { puzzle: e.puzzle, completeness: e.completeness, missing_dimensions: e.missing_dimensions },
42
- ]));
43
- }
44
- else {
45
- const user_intent = (v.intent ?? v.project_description ?? v.project_name ?? "").trim();
46
- if (!user_intent) {
47
- throw new Error("aggregate_risks requires 'puzzles' (from a prior analyze_intent result) " +
48
- "OR 'intent' (business description — analyze_intent runs automatically first).");
49
- }
50
- const analyzed = analyzeBusinessIntent({
51
- user_intent,
52
- project_name: v.project_name,
53
- industry: v.project_industry,
54
- });
55
- puzzles = analyzed.puzzles;
56
- intent_echo = {
57
- primary_object: analyzed.intent_parsed.primary_object,
58
- industry: analyzed.intent_parsed.industry,
59
- overall_completeness: analyzed.overall_completeness,
60
- };
61
- }
62
- const result = aggregateProjectRisks({
63
- project_prefix,
64
- version,
65
- industry: v.project_industry,
66
- puzzles,
67
- severity_threshold: v.severity_threshold,
68
- user_confirmed_high_risks: v.user_confirmed_high_risks,
69
- });
70
- const safety_findings = [
71
- ...(v.planned_objects ? checkObjectReuseRules(v.planned_objects) : []),
72
- ...(v.planned_operations ? checkImmutabilityRules(v.planned_operations) : []),
73
- ];
74
- updateStageCache(project_prefix, version, {
75
- stage: 3,
76
- risk_status: result.status,
77
- risk_can_proceed: result.status === "RISK_PASSED",
78
- });
79
- return {
80
- action: "aggregate_risks",
81
- ...result,
82
- ...(safety_findings.length > 0 ? { safety_findings } : {}),
83
- ...(intent_echo ? { intent_echo } : {}),
84
- };
85
- }
86
- export function handleTraceSubsteps(v) {
87
- const project_prefix = (v.project ?? "").trim();
88
- if (!project_prefix) {
89
- throw new Error("trace_substeps requires 'project' (project prefix, e.g. 'myshop').");
90
- }
91
- if (!v.substeps || v.substeps.length === 0) {
92
- throw new Error("trace_substeps requires 'substeps' (non-empty array of substep execution records, " +
93
- "63-spec §2.1). Construct them from your deployment execution trace: each onchain_operations " +
94
- "call = one substep with step_id 'T<step>.<substep>', input_refs pointing at upstream substeps.");
95
- }
96
- const result = traceSubsteps({
97
- project_prefix,
98
- version: (v.version ?? "v1").trim(),
99
- network: v.network ?? "testnet",
100
- substeps: v.substeps,
101
- edges: v.substep_edges,
102
- });
103
- updateStageCache(project_prefix, (v.version ?? "v1").trim(), {
104
- stage: 5,
105
- trace_coherent: result.coherent,
106
- trace_can_proceed: result.coherent,
107
- });
108
- return { action: "trace_substeps", ...result };
109
- }
1
+ import{analyzeBusinessIntent}from'./business-puzzle.js';import{aggregateProjectRisks}from'./risk-aggregator.js';import{traceSubsteps}from'./substep-trace.js';import{updateStageCache}from'./index.js';import{checkObjectReuseRules,checkImmutabilityRules}from'../knowledge/safety-rules.js';export function handleAnalyzeIntent(a){const b=(a['intent']??a['project_description']??a['project_name']??'')['trim']();if(!b)throw new Error('analyze_intent\x20requires\x20\x27intent\x27\x20(business\x20description\x20text).\x20'+'Example:\x20intent=\x27I\x20want\x20to\x20open\x20an\x20online\x20toy\x20store\x20with\x20escrow\x20and\x20dispute\x20resolution\x27.');const c=analyzeBusinessIntent({'user_intent':b,'project_name':a['project_name'],'target_objects':a['target_objects'],'industry':a['project_industry']}),d=(a['project']??'')['trim']();return d&&updateStageCache(d,(a['version']??'v1')['trim'](),{'stage':0x2,'puzzles':c['puzzles'],'business_intent':b,'industry':c['intent_parsed']['industry']}),{'action':'analyze_intent',...c};}export function handleAggregateRisks(a){const b=(a['project']??'')['trim']();if(!b)throw new Error('aggregate_risks\x20requires\x20\x27project\x27\x20(project\x20prefix,\x20e.g.\x20\x27myshop\x27).\x20'+'Use\x20the\x20same\x20prefix\x20as\x20create_project\x20so\x20findings\x20map\x20to\x20the\x20project\x20namespace.');const c=(a['version']??'v1')['trim']();let d,e;if(a['puzzles'])d=Object['fromEntries'](Object['entries'](a['puzzles'])['map'](([h,i])=>[h,{'puzzle':i['puzzle'],'completeness':i['completeness'],'missing_dimensions':i['missing_dimensions']}]));else{const h=(a['intent']??a['project_description']??a['project_name']??'')['trim']();if(!h)throw new Error('aggregate_risks\x20requires\x20\x27puzzles\x27\x20(from\x20a\x20prior\x20analyze_intent\x20result)\x20'+'OR\x20\x27intent\x27\x20(business\x20description\x20—\x20analyze_intent\x20runs\x20automatically\x20first).');const i=analyzeBusinessIntent({'user_intent':h,'project_name':a['project_name'],'industry':a['project_industry']});d=i['puzzles'],e={'primary_object':i['intent_parsed']['primary_object'],'industry':i['intent_parsed']['industry'],'overall_completeness':i['overall_completeness']};}const f=aggregateProjectRisks({'project_prefix':b,'version':c,'industry':a['project_industry'],'puzzles':d,'severity_threshold':a['severity_threshold'],'user_confirmed_high_risks':a['user_confirmed_high_risks']}),g=[...a['planned_objects']?checkObjectReuseRules(a['planned_objects']):[],...a['planned_operations']?checkImmutabilityRules(a['planned_operations']):[]];return updateStageCache(b,c,{'stage':0x3,'risk_status':f['status'],'risk_can_proceed':f['status']==='RISK_PASSED'}),{'action':'aggregate_risks',...f,...g['length']>0x0?{'safety_findings':g}:{},...e?{'intent_echo':e}:{}};}export function handleTraceSubsteps(a){const b=(a['project']??'')['trim']();if(!b)throw new Error('trace_substeps\x20requires\x20\x27project\x27\x20(project\x20prefix,\x20e.g.\x20\x27myshop\x27).');if(!a['substeps']||a['substeps']['length']===0x0)throw new Error('trace_substeps\x20requires\x20\x27substeps\x27\x20(non-empty\x20array\x20of\x20substep\x20execution\x20records,\x20'+'63-spec\x20§2.1).\x20Construct\x20them\x20from\x20your\x20deployment\x20execution\x20trace:\x20each\x20onchain_operations\x20'+'call\x20=\x20one\x20substep\x20with\x20step_id\x20\x27T<step>.<substep>\x27,\x20input_refs\x20pointing\x20at\x20upstream\x20substeps.');const c=traceSubsteps({'project_prefix':b,'version':(a['version']??'v1')['trim'](),'network':a['network']??'testnet','substeps':a['substeps'],'edges':a['substep_edges']});return updateStageCache(b,(a['version']??'v1')['trim'](),{'stage':0x5,'trace_coherent':c['coherent'],'trace_can_proceed':c['coherent']}),{'action':'trace_substeps',...c};}