@wowok/agent-mcp 2.6.0 → 2.6.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 (133) hide show
  1. package/README.md +5 -3
  2. package/dist/extensions/capability-manifest.d.ts +125 -0
  3. package/dist/extensions/capability-manifest.js +594 -0
  4. package/dist/extensions/constraint-registry.d.ts +24 -0
  5. package/dist/extensions/constraint-registry.js +196 -0
  6. package/dist/extensions/index.d.ts +12 -0
  7. package/dist/extensions/index.js +6 -0
  8. package/dist/extensions/metric-registry.d.ts +26 -0
  9. package/dist/extensions/metric-registry.js +257 -0
  10. package/dist/extensions/mode-evaluator.d.ts +15 -0
  11. package/dist/extensions/mode-evaluator.js +170 -0
  12. package/dist/extensions/modes.d.ts +2 -0
  13. package/dist/extensions/modes.js +407 -0
  14. package/dist/extensions/registry.d.ts +48 -0
  15. package/dist/extensions/registry.js +629 -0
  16. package/dist/extensions/types.d.ts +218 -0
  17. package/dist/extensions/types.js +1 -0
  18. package/dist/knowledge/deployment-scanner.d.ts +3 -0
  19. package/dist/knowledge/deployment-scanner.js +64 -3
  20. package/dist/knowledge/guard-risk.d.ts +13 -0
  21. package/dist/knowledge/guard-risk.js +57 -0
  22. package/dist/knowledge/guard-templates.js +278 -0
  23. package/dist/knowledge/machine-templates.js +20 -1
  24. package/dist/knowledge/service-confirm.d.ts +14 -5
  25. package/dist/knowledge/service-confirm.js +116 -8
  26. package/dist/knowledge/tool-constraints.js +6 -2
  27. package/dist/project/deployment-bridge.d.ts +1 -1
  28. package/dist/project/deployment-bridge.js +27 -4
  29. package/dist/project/deployment-doc.d.ts +3 -0
  30. package/dist/project/deployment-doc.js +72 -10
  31. package/dist/project/evaluation.d.ts +2 -0
  32. package/dist/project/evaluation.js +569 -84
  33. package/dist/project/graph-builder.d.ts +4 -1
  34. package/dist/project/graph-builder.js +126 -61
  35. package/dist/project/graph.d.ts +1 -0
  36. package/dist/project/handlers.d.ts +219 -5
  37. package/dist/project/handlers.js +819 -9
  38. package/dist/project/stage-gate.d.ts +4 -0
  39. package/dist/project/stage-gate.js +64 -5
  40. package/dist/project/task-tracker.d.ts +26 -0
  41. package/dist/project/task-tracker.js +78 -0
  42. package/dist/safety/preview.js +16 -0
  43. package/dist/schema/call/allocation.d.ts +16 -16
  44. package/dist/schema/call/base.d.ts +21 -13
  45. package/dist/schema/call/base.js +27 -6
  46. package/dist/schema/call/bridge.d.ts +5 -5
  47. package/dist/schema/call/bridge.js +3 -1
  48. package/dist/schema/call/demand.d.ts +23 -31
  49. package/dist/schema/call/guard.js +1 -1
  50. package/dist/schema/call/machine.d.ts +402 -376
  51. package/dist/schema/call/order.d.ts +149 -228
  52. package/dist/schema/call/order.js +7 -3
  53. package/dist/schema/call/payment.d.ts +183 -3
  54. package/dist/schema/call/payment.js +21 -3
  55. package/dist/schema/call/personal.d.ts +241 -52
  56. package/dist/schema/call/progress.d.ts +53 -61
  57. package/dist/schema/call/progress.js +18 -4
  58. package/dist/schema/call/repository.d.ts +23 -31
  59. package/dist/schema/call/semantic.d.ts +1 -1
  60. package/dist/schema/call/semantic.js +30 -1
  61. package/dist/schema/call/service.d.ts +95 -119
  62. package/dist/schema/call/service.js +22 -1
  63. package/dist/schema/common/index.d.ts +11 -2
  64. package/dist/schema/common/index.js +43 -14
  65. package/dist/schema/local/index.d.ts +32 -35
  66. package/dist/schema/local/index.js +23 -5
  67. package/dist/schema/messenger/index.d.ts +274 -46
  68. package/dist/schema/operations.d.ts +680 -539
  69. package/dist/schema/operations.js +22 -0
  70. package/dist/schema/project/index.d.ts +1796 -80
  71. package/dist/schema/project/index.js +304 -14
  72. package/dist/schema/query/index.d.ts +705 -349
  73. package/dist/schema/query/index.js +164 -31
  74. package/dist/schema/schema-query/index.d.ts +15 -3
  75. package/dist/schema/schema-query/index.js +23 -5
  76. package/dist/schema/utils/node-parser.js +7 -4
  77. package/dist/schema-query/index.d.ts +7 -1
  78. package/dist/schema-query/index.js +204 -4
  79. package/dist/schemas/account_operation.output.json +7 -1
  80. package/dist/schemas/account_operation.schema.json +2 -2
  81. package/dist/schemas/bridge_operation.output.json +6 -0
  82. package/dist/schemas/bridge_operation.schema.json +1 -1
  83. package/dist/schemas/guard-templates.json +379 -0
  84. package/dist/schemas/guard2file.schema.json +1 -1
  85. package/dist/schemas/index.json +1 -1
  86. package/dist/schemas/local_info_operation.output.json +6 -0
  87. package/dist/schemas/local_mark_operation.output.json +7 -1
  88. package/dist/schemas/local_mark_operation.schema.json +1 -1
  89. package/dist/schemas/machineNode2file.schema.json +1 -1
  90. package/dist/schemas/messenger_operation.schema.json +4 -4
  91. package/dist/schemas/onchain_events.output.json +1 -1
  92. package/dist/schemas/onchain_operations.schema.json +348 -296
  93. package/dist/schemas/onchain_operations_allocation.schema.json +34 -25
  94. package/dist/schemas/onchain_operations_arbitration.schema.json +8 -8
  95. package/dist/schemas/onchain_operations_contact.schema.json +8 -8
  96. package/dist/schemas/onchain_operations_demand.schema.json +8 -8
  97. package/dist/schemas/onchain_operations_gen_passport.schema.json +14 -14
  98. package/dist/schemas/onchain_operations_gen_proof.schema.json +2 -2
  99. package/dist/schemas/onchain_operations_guard.schema.json +1 -1
  100. package/dist/schemas/onchain_operations_machine.schema.json +41 -33
  101. package/dist/schemas/onchain_operations_order.schema.json +71 -77
  102. package/dist/schemas/onchain_operations_payment.schema.json +141 -111
  103. package/dist/schemas/onchain_operations_permission.schema.json +2 -2
  104. package/dist/schemas/onchain_operations_personal.schema.json +7 -7
  105. package/dist/schemas/onchain_operations_progress.schema.json +8 -8
  106. package/dist/schemas/onchain_operations_proof.schema.json +7 -7
  107. package/dist/schemas/onchain_operations_repository.schema.json +8 -8
  108. package/dist/schemas/onchain_operations_reward.schema.json +10 -10
  109. package/dist/schemas/onchain_operations_service.schema.json +46 -35
  110. package/dist/schemas/onchain_operations_treasury.schema.json +8 -8
  111. package/dist/schemas/onchain_table_data.output.json +33 -25
  112. package/dist/schemas/onchain_table_data.schema.json +12 -12
  113. package/dist/schemas/project_operation.output.json +1175 -23
  114. package/dist/schemas/project_operation.schema.json +40 -4
  115. package/dist/schemas/query_toolkit.output.json +104 -76
  116. package/dist/schemas/query_toolkit.schema.json +9 -9
  117. package/dist/schemas/schema_query.output.json +7 -3
  118. package/dist/schemas/schema_query.schema.json +17 -3
  119. package/dist/tools/handlers/local.js +20 -5
  120. package/dist/tools/handlers/onchain.js +23 -0
  121. package/dist/tools/handlers/project.js +52 -3
  122. package/dist/tools/handlers/query.js +27 -0
  123. package/dist/tools/handlers/schema-query.js +19 -0
  124. package/dist/tools/handlers/task-status.d.ts +170 -0
  125. package/dist/tools/handlers/task-status.js +55 -0
  126. package/dist/tools/handlers/wip.js +47 -1
  127. package/dist/tools/index.js +211 -7
  128. package/dist/tools/retry.d.ts +8 -0
  129. package/dist/tools/retry.js +85 -0
  130. package/dist/tools/wip-deploy-assist.d.ts +28 -0
  131. package/dist/tools/wip-deploy-assist.js +278 -0
  132. package/package.json +2 -2
  133. package/dist/schemas/guard-node-examples.md +0 -199
@@ -0,0 +1,278 @@
1
+ export function classifyWipPath(path) {
2
+ if (!path || typeof path !== "string") {
3
+ return {
4
+ type: "unknown",
5
+ is_local: false,
6
+ is_network: false,
7
+ description: "Empty or invalid path",
8
+ };
9
+ }
10
+ if (path.startsWith("data:")) {
11
+ return {
12
+ type: "data_url",
13
+ is_local: false,
14
+ is_network: true,
15
+ description: "Data URL — embedded content, globally reachable",
16
+ };
17
+ }
18
+ if (path.startsWith("ipfs://")) {
19
+ return {
20
+ type: "ipfs",
21
+ is_local: false,
22
+ is_network: true,
23
+ description: "IPFS URI — resolve via any public gateway",
24
+ };
25
+ }
26
+ const ipfsGateways = [
27
+ /^https?:\/\/ipfs\.io\//i,
28
+ /^https?:\/\/cloudflare-ipfs\.com\//i,
29
+ /^https?:\/\/gateway\.pinata\.cloud\//i,
30
+ /^https?:\/\/dweb\.link\//i,
31
+ /^https?:\/\/[^/]*pinata\.cloud\//i,
32
+ ];
33
+ if (ipfsGateways.some((re) => re.test(path))) {
34
+ return {
35
+ type: "ipfs",
36
+ is_local: false,
37
+ is_network: true,
38
+ description: "IPFS HTTP gateway URL — globally reachable",
39
+ };
40
+ }
41
+ if (/^https?:\/\//i.test(path)) {
42
+ return {
43
+ type: "http_url",
44
+ is_local: false,
45
+ is_network: true,
46
+ description: "HTTP(S) URL — globally reachable if server returns 200",
47
+ };
48
+ }
49
+ if (/^[A-Za-z]:[\\/]/.test(path)) {
50
+ return {
51
+ type: "local_windows",
52
+ is_local: true,
53
+ is_network: false,
54
+ description: "Windows local path — NOT reachable by customers/AI",
55
+ };
56
+ }
57
+ if (path.startsWith("/")) {
58
+ return {
59
+ type: "local_unix",
60
+ is_local: true,
61
+ is_network: false,
62
+ description: "Unix local path — NOT reachable by customers/AI",
63
+ };
64
+ }
65
+ if (path.startsWith("./") || path.startsWith("../") || path === "." || path === "..") {
66
+ return {
67
+ type: "local_relative",
68
+ is_local: true,
69
+ is_network: false,
70
+ description: "Relative local path — NOT reachable by customers/AI",
71
+ };
72
+ }
73
+ if (!path.includes("://") && !path.startsWith("data:")) {
74
+ return {
75
+ type: "local_relative",
76
+ is_local: true,
77
+ is_network: false,
78
+ description: "Local file path (no scheme) — NOT reachable by customers/AI",
79
+ };
80
+ }
81
+ return {
82
+ type: "unknown",
83
+ is_local: false,
84
+ is_network: false,
85
+ description: "Unrecognized path format",
86
+ };
87
+ }
88
+ export function getDeployOptions(localFilePath) {
89
+ const safePath = localFilePath.replace(/'/g, "'\\''");
90
+ const basename = localFilePath.split(/[\\/]/).pop() || "file.wip";
91
+ return [
92
+ {
93
+ name: "GitHub Pages (Recommended)",
94
+ description: "Upload the .wip file to a GitHub repository and serve it via GitHub Pages. " +
95
+ "Free, stable, HTTPS-enabled, no expiration.",
96
+ difficulty: "easy",
97
+ free: true,
98
+ result_url_pattern: "https://<your-username>.github.io/<repo>/<file>.wip",
99
+ steps: [
100
+ "// 1. Create a new GitHub repository (e.g., 'wowok-wip') via https://github.com/new",
101
+ "// 2. Make it PUBLIC so the file is world-readable.",
102
+ `// 3. Copy your local WIP file into the repo:`,
103
+ `git clone https://github.com/<your-username>/wowok-wip.git`,
104
+ `cp '${safePath}' wowok-wip/${basename}`,
105
+ `cd wowok-wip`,
106
+ `git add ${basename}`,
107
+ `git commit -m "Add WIP file"`,
108
+ `git push origin main`,
109
+ "// 4. Enable GitHub Pages: repo → Settings → Pages → Source → 'main' branch → /(root) → Save",
110
+ "// 5. Wait 30-60 seconds for deployment, then verify the URL is reachable:",
111
+ `curl -I https://<your-username>.github.io/wowok-wip/${basename}`,
112
+ "// 6. Update your Service on-chain with the new public URL:",
113
+ "// Call onchain_operations { operation_type: 'service', data: { object: '<service-id>', sales: { op: 'set', sales: [{ ..., wip_url: 'https://...', wip_hash: '<hash>' }] } } }",
114
+ ],
115
+ notes: [
116
+ "If the repo already has Pages enabled on the main branch, step 4 can be skipped.",
117
+ "GitHub Pages serves files up to 25 MB — well above typical WIP sizes (< 1 MB).",
118
+ "URL is case-sensitive; ensure the filename in the URL matches exactly.",
119
+ ],
120
+ },
121
+ {
122
+ name: "IPFS via Pinata (Free gateway)",
123
+ description: "Upload the .wip file to IPFS through Pinata's free gateway. " +
124
+ "Content-addressed — the CID hash also serves as an integrity check.",
125
+ difficulty: "medium",
126
+ free: true,
127
+ result_url_pattern: "https://gateway.pinata.cloud/ipfs/<CID> (or https://ipfs.io/ipfs/<CID>)",
128
+ steps: [
129
+ "// 1. Sign up for a free Pinata account at https://app.pinata.cloud/ (1 GB free storage).",
130
+ "// 2. Get your API key from https://app.pinata.cloud/keys (generate a new key with 'pinFileToIPFS' scope).",
131
+ `// 3. Upload your local WIP file via curl:`,
132
+ `curl -X POST https://api.pinata.cloud/pinning/pinFileToIPFS \\`,
133
+ ` -H "Authorization: Bearer <YOUR_PINATA_API_KEY>" \\`,
134
+ ` -F "file=@'${safePath}'"`,
135
+ "// 4. Pinata returns JSON with 'IpfsHash' (the CID). Extract it:",
136
+ `// Example response: { "IpfsHash": "QmXYZ...", "PinSize": 12345, "Timestamp": "..." }`,
137
+ "// 5. Verify the file is reachable via the public gateway:",
138
+ `curl -I https://gateway.pinata.cloud/ipfs/<CID>`,
139
+ "// 6. (Optional) Use ipfs://<CID> as the wip_url — the SDK resolves it.",
140
+ "// 7. Update your Service on-chain with the IPFS URL or CID:",
141
+ "// Call onchain_operations { operation_type: 'service', data: { object: '<service-id>', sales: { op: 'set', sales: [{ ..., wip_url: 'https://gateway.pinata.cloud/ipfs/<CID>', wip_hash: '<hash>' }] } } }",
142
+ ],
143
+ notes: [
144
+ "Pinata free tier: 1 GB storage, 100 uploads/day — sufficient for WIP files.",
145
+ "For long-term durability, also pin via another gateway (e.g., nft.storage).",
146
+ "IPFS CIDs are content-addressed — if the file changes, the CID changes. This is a feature, not a bug.",
147
+ ],
148
+ },
149
+ {
150
+ name: "User's own website / static host",
151
+ description: "If you already operate a website or static host (e.g., nginx, Vercel, Netlify, Cloudflare Pages), " +
152
+ "upload the .wip file there and use its public URL.",
153
+ difficulty: "medium",
154
+ free: true,
155
+ result_url_pattern: "https://<your-domain>/<path>/<file>.wip",
156
+ steps: [
157
+ `// 1. Copy your local WIP file to your web server's static directory:`,
158
+ `scp '${safePath}' user@your-server:/var/www/html/wowok/${basename}`,
159
+ "// 2. Ensure the server sets Content-Type: application/json (or application/octet-stream) for .wip files.",
160
+ "// For nginx, add to your server block:",
161
+ "// location ~ \\.wip$ { default_type application/json; }",
162
+ "// 3. Verify the file is reachable:",
163
+ `curl -I https://<your-domain>/wowok/${basename}`,
164
+ "// 4. Update your Service on-chain with the new public URL:",
165
+ "// Call onchain_operations { operation_type: 'service', data: { object: '<service-id>', sales: { op: 'set', sales: [{ ..., wip_url: 'https://<your-domain>/wowok/<file>.wip', wip_hash: '<hash>' }] } } }",
166
+ ],
167
+ notes: [
168
+ "Make sure CORS is permissive if the verifier fetches via browser (Access-Control-Allow-Origin: *).",
169
+ "Ensure HTTPS is enabled — most verifiers reject plain HTTP.",
170
+ ],
171
+ },
172
+ {
173
+ name: "Data URL embedding (small files only)",
174
+ description: "Embed the entire WIP file as a base64 data URL directly in the wip_url field. " +
175
+ "No external hosting required, but on-chain storage cost grows with file size.",
176
+ difficulty: "easy",
177
+ free: true,
178
+ result_url_pattern: "data:application/json;base64,<base64-encoded-content>",
179
+ steps: [
180
+ `// 1. Encode your local WIP file as a base64 data URL:`,
181
+ `// On Linux/macOS:`,
182
+ `echo "data:application/json;base64,$(base64 -w0 '${safePath}')"`,
183
+ `// On Windows (PowerShell):`,
184
+ `$bytes = [System.IO.File]::ReadAllBytes('${localFilePath}'); $b64 = [System.Convert]::ToBase64String($bytes); Write-Output "data:application/json;base64,$b64"`,
185
+ "// 2. Use the resulting data URL as the wip_url field when updating the Service.",
186
+ "// 3. Note: data URLs are NOT recommended for files > 50 KB due to on-chain storage cost.",
187
+ ],
188
+ notes: [
189
+ "Only suitable for very small WIP files (typically < 10 KB).",
190
+ "Data URLs cannot be updated without an on-chain transaction — content is literally embedded.",
191
+ "Prefer GitHub Pages or IPFS for files > 10 KB.",
192
+ ],
193
+ },
194
+ ];
195
+ }
196
+ export function analyzeWipDeployment(path) {
197
+ const classification = classifyWipPath(path);
198
+ const needsDeployment = classification.is_local;
199
+ let reason;
200
+ let options = [];
201
+ if (needsDeployment) {
202
+ reason =
203
+ `The WIP path '${path}' is a LOCAL ${classification.type} path. ` +
204
+ "Local paths stored on-chain are unreachable by customers and verifiers. " +
205
+ "Deploy the .wip file to a public host (GitHub Pages, IPFS, or your own website) " +
206
+ "and update the Service's wip_url with the public URL.";
207
+ options = getDeployOptions(path);
208
+ }
209
+ else if (classification.type === "http_url") {
210
+ reason =
211
+ "The WIP path is an HTTP(S) URL — verify the server returns 200. " +
212
+ "If the URL returns 404/403, the file may have been moved or deleted.";
213
+ options = [];
214
+ }
215
+ else if (classification.type === "ipfs") {
216
+ reason =
217
+ "The WIP path is an IPFS URL — verify the gateway is responsive. " +
218
+ "If the CID is unreachable, the file may have been unpinned.";
219
+ options = [];
220
+ }
221
+ else if (classification.type === "data_url") {
222
+ reason = "The WIP path is a data URL — content is embedded, no deployment needed.";
223
+ options = [];
224
+ }
225
+ else {
226
+ reason = `Unrecognized WIP path format: '${path}'`;
227
+ options = [];
228
+ }
229
+ return {
230
+ path,
231
+ classification,
232
+ needs_deployment: needsDeployment,
233
+ reason,
234
+ options,
235
+ remind_update_hash: needsDeployment,
236
+ };
237
+ }
238
+ export function formatDeployHints(suggestion) {
239
+ if (!suggestion.needs_deployment && suggestion.options.length === 0) {
240
+ return "";
241
+ }
242
+ const lines = [];
243
+ lines.push("=== WIP Deployment Assistance ===");
244
+ lines.push("");
245
+ lines.push(`Path: ${suggestion.path}`);
246
+ lines.push(`Type: ${suggestion.classification.description}`);
247
+ lines.push(`Reason: ${suggestion.reason}`);
248
+ lines.push("");
249
+ if (suggestion.options.length > 0) {
250
+ lines.push("Recommended deployment options:");
251
+ lines.push("");
252
+ for (const opt of suggestion.options) {
253
+ lines.push(`▶ ${opt.name} (difficulty: ${opt.difficulty}, free: ${opt.free})`);
254
+ lines.push(` ${opt.description}`);
255
+ lines.push(` Resulting URL pattern: ${opt.result_url_pattern}`);
256
+ lines.push(" Steps:");
257
+ for (const step of opt.steps) {
258
+ lines.push(` ${step}`);
259
+ }
260
+ if (opt.notes && opt.notes.length > 0) {
261
+ lines.push(" Notes:");
262
+ for (const note of opt.notes) {
263
+ lines.push(` - ${note}`);
264
+ }
265
+ }
266
+ lines.push("");
267
+ }
268
+ }
269
+ if (suggestion.remind_update_hash) {
270
+ lines.push("⚠️ After deploying, compute the new WIP hash and update the Service:");
271
+ lines.push(" 1. Re-run wip_file { type: 'verify', wipFilePath: '<new-public-url>' } to confirm the file is reachable.");
272
+ lines.push(" 2. Extract the meta.hash from the WIP file (or use wip_file { type: 'verify' } result).");
273
+ lines.push(" 3. Update the Service on-chain: onchain_operations { operation_type: 'service', data: { object: '<service-id>', sales: { op: 'set', sales: [{ ..., wip_url: '<new-public-url>', wip_hash: '<hash>' }] } } }");
274
+ lines.push("");
275
+ }
276
+ lines.push("===============================");
277
+ return lines.join("\n");
278
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wowok/agent-mcp",
3
- "version": "2.6.0",
3
+ "version": "2.6.1",
4
4
  "description": "Making It Easy for AI Agents to Communicate, Collaborate, Trade, and Trust.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -50,7 +50,7 @@
50
50
  "license": "Apache-2.0",
51
51
  "dependencies": {
52
52
  "@modelcontextprotocol/sdk": "^1.29.0",
53
- "@wowok/wowok": "2.6.0",
53
+ "@wowok/wowok": "2.6.1",
54
54
  "lodash": "^4.18.1",
55
55
  "zod": "^3.25.76",
56
56
  "zod-to-json-schema": "^3.25.2"
@@ -1,199 +0,0 @@
1
- # GuardNode Usage Guide
2
-
3
- This document provides practical examples of GuardNode usage for AI agents.
4
-
5
- ## Overview
6
-
7
- A GuardNode is a computational tree node that represents an operation returning a typed value. Nodes can be nested to build complex validation logic. The root node of a Guard MUST return a `Bool` value (pass/fail).
8
-
9
- ## Common Patterns
10
-
11
- ### Pattern 1: Verify Transaction Signer is Order Owner
12
-
13
- ```json
14
- {
15
- "type": "logic_equal",
16
- "nodes": [
17
- { "type": "context", "context": "Signer" },
18
- {
19
- "type": "query",
20
- "query": 1562,
21
- "object": { "identifier": 0 },
22
- "parameters": []
23
- }
24
- ]
25
- }
26
- ```
27
-
28
- **Explanation:**
29
- - `context: Signer` returns the transaction sender's address
30
- - `query: 1562` gets the order owner (order.owner query)
31
- - `logic_equal` compares the two addresses
32
-
33
- ### Pattern 2: Verify Order Progress Node
34
-
35
- ```json
36
- {
37
- "type": "logic_equal",
38
- "nodes": [
39
- {
40
- "type": "query",
41
- "query": 1253,
42
- "object": { "identifier": 0, "convert_witness": 100 },
43
- "parameters": []
44
- },
45
- { "type": "identifier", "identifier": 1 }
46
- ]
47
- }
48
- ```
49
-
50
- **Explanation:**
51
- - `query: 1253` gets the current progress node name
52
- - `convert_witness: 100` (TypeOrderProgress) converts the object for progress query
53
- - Compares with the expected node name stored at identifier 1
54
-
55
- ### Pattern 3: Verify Reward Not Claimed
56
-
57
- ```json
58
- {
59
- "type": "logic_not",
60
- "node": {
61
- "type": "query_reward_record_exists",
62
- "object": { "identifier": 0 },
63
- "recipient": { "identifier": 1 },
64
- "where": {}
65
- }
66
- }
67
- ```
68
-
69
- **Explanation:**
70
- - `query_reward_record_exists` checks if a reward record exists for the recipient
71
- - `logic_not` inverts the result (returns true if NO record exists)
72
- - This verifies the reward has NOT been claimed
73
-
74
- ### Pattern 4: Combined Validation (Reward Guard)
75
-
76
- ```json
77
- {
78
- "type": "logic_and",
79
- "nodes": [
80
- {
81
- "type": "logic_equal",
82
- "nodes": [
83
- {
84
- "type": "query",
85
- "query": 1253,
86
- "object": { "identifier": 0, "convert_witness": 100 },
87
- "parameters": []
88
- },
89
- { "type": "identifier", "identifier": 1 }
90
- ]
91
- },
92
- {
93
- "type": "logic_equal",
94
- "nodes": [
95
- { "type": "context", "context": "Signer" },
96
- {
97
- "type": "query",
98
- "query": 1562,
99
- "object": { "identifier": 0 },
100
- "parameters": []
101
- }
102
- ]
103
- },
104
- {
105
- "type": "logic_not",
106
- "node": {
107
- "type": "query_reward_record_exists",
108
- "object": { "identifier": 2 },
109
- "recipient": { "identifier": 3 },
110
- "where": {}
111
- }
112
- }
113
- ]
114
- }
115
- ```
116
-
117
- **Explanation:**
118
- This is a complete Reward Guard that verifies:
119
- 1. Order is at expected progress node (e.g., "delivered")
120
- 2. Transaction signer is the order owner
121
- 3. Order has NOT claimed the reward yet
122
-
123
- ## Query Instruction Reference
124
-
125
- | Query ID | Name | Description | Parameters | Returns |
126
- |----------|------|-------------|------------|---------|
127
- | 1253 | order.progress.node | Get current progress node name | None | String |
128
- | 1562 | order.owner | Get order owner address | None | Address |
129
- | 1563 | order.service | Get order service address | None | Address |
130
- | 1564 | order.payer | Get order payer address | None | Address |
131
-
132
- ## Witness Types
133
-
134
- | Witness ID | Name | Description |
135
- |------------|------|-------------|
136
- | 100 | TypeOrderProgress | Access order progress data |
137
- | 200 | TypeOrder | Access order data |
138
-
139
- ## Node Return Types
140
-
141
- ### Logic Nodes (Return Bool)
142
- - `logic_and`, `logic_or`, `logic_not`
143
- - `logic_equal`, `logic_as_u256_equal`
144
- - `logic_as_u256_greater`, `logic_as_u256_lesser`
145
- - `logic_as_u256_greater_or_equal`, `logic_as_u256_lesser_or_equal`
146
- - `logic_string_contains`, `logic_string_nocase_contains`, `logic_string_nocase_equal`
147
-
148
- ### Calculation Nodes (Return Numeric)
149
- - `calc_number_add`, `calc_number_subtract`, `calc_number_multiply`, `calc_number_divide`, `calc_number_mod` → U256
150
- - `calc_string_length` → U64
151
- - `calc_string_contains`, `calc_string_nocase_contains`, `calc_string_nocase_equal` → Bool
152
- - `calc_string_indexof`, `calc_string_nocase_indexof` → U64
153
-
154
- ### Conversion Nodes
155
- - `convert_number_address` → Address
156
- - `convert_address_number` → U64
157
- - `convert_number_string` → String
158
- - `convert_string_number` → U256
159
- - `convert_safe_u8`, `convert_safe_u16`, `convert_safe_u32`, `convert_safe_u64`, `convert_safe_u128`, `convert_safe_u256` → Respective type
160
-
161
- ### Query Nodes (Return Varies)
162
- - `query` → Depends on query instruction
163
- - `query_reward_record_find`, `query_reward_record_count` → U64
164
- - `query_reward_record_exists` → Bool
165
- - `query_progress_history_find`, `query_progress_history_session_find`, `query_progress_history_session_forward_find` → U64
166
- - `query_progress_history_session_count`, `query_progress_history_session_forward_count`, `query_progress_history_session_forward_retained_submission_count` → U64
167
-
168
- ### Context Nodes
169
- - `context: Signer` → Address
170
- - `context: Clock` → U64 (timestamp)
171
- - `context: Guard` → Address
172
-
173
- ### Vector Nodes
174
- - `vec_length` → U64
175
- - `vec_contains_bool`, `vec_contains_address`, `vec_contains_string`, `vec_contains_string_nocase`, `vec_contains_number` → Bool
176
-
177
- ## Best Practices
178
-
179
- 1. **Root node must return Bool**: Always use a logic node (logic_and, logic_or) as the root.
180
-
181
- 2. **Use logic_and for multiple conditions**: Most common pattern for combining validations.
182
-
183
- 3. **Check node return types**: Ensure child nodes return the expected type for the parent node.
184
- - Logic nodes expect Bool children
185
- - Calculation nodes expect numeric children
186
- - Comparison nodes expect matching types
187
-
188
- 4. **Use identifier references**: Store constants (addresses, strings, numbers) in the Guard table and reference them by identifier.
189
-
190
- 5. **Query with convert_witness**: When querying object data, use the appropriate witness type to access the data you need.
191
-
192
- 6. **Handle optional fields**: In where clauses, only include fields you want to filter by. Omitting a field means "don't filter by this field".
193
-
194
- ## Common Errors
195
-
196
- 1. **Type mismatch**: Trying to compare incompatible types (e.g., Address with String).
197
- 2. **Missing identifier**: Referencing an identifier that doesn't exist in the Guard table.
198
- 3. **Wrong return type**: Using a non-Bool node as the root or as a child of a logic node.
199
- 4. **Invalid query ID**: Using a query instruction ID that doesn't exist.