wowok_agent 1.6.6 → 2.1.8

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.

Potentially problematic release.


This version of wowok_agent might be problematic. Click here for more details.

Files changed (181) hide show
  1. package/README.md +20 -40
  2. package/dist/index.d.ts +13528 -27
  3. package/dist/index.js +1026 -27
  4. package/dist/schema/call/allocation.d.ts +1370 -0
  5. package/dist/schema/call/allocation.js +27 -0
  6. package/dist/schema/call/arbitration.d.ts +1902 -0
  7. package/dist/schema/call/arbitration.js +106 -0
  8. package/dist/schema/call/base.d.ts +6381 -0
  9. package/dist/schema/call/base.js +152 -0
  10. package/dist/schema/call/contact.d.ts +898 -0
  11. package/dist/schema/call/contact.js +41 -0
  12. package/dist/schema/call/demand.d.ts +1193 -0
  13. package/dist/schema/call/demand.js +51 -0
  14. package/dist/schema/call/guard.d.ts +819 -0
  15. package/dist/schema/call/guard.js +67 -0
  16. package/dist/schema/call/handler.d.ts +80 -0
  17. package/dist/schema/call/handler.js +177 -0
  18. package/dist/schema/call/index.d.ts +18 -0
  19. package/dist/schema/call/index.js +19 -0
  20. package/dist/schema/call/machine.d.ts +3906 -0
  21. package/dist/schema/call/machine.js +164 -0
  22. package/dist/schema/call/order.d.ts +994 -0
  23. package/dist/schema/call/order.js +39 -0
  24. package/dist/schema/call/payment.d.ts +408 -0
  25. package/dist/schema/call/payment.js +20 -0
  26. package/dist/schema/call/permission.d.ts +2945 -0
  27. package/dist/schema/call/permission.js +118 -0
  28. package/dist/schema/call/personal.d.ts +1498 -0
  29. package/dist/schema/call/personal.js +81 -0
  30. package/dist/schema/call/progress.d.ts +847 -0
  31. package/dist/schema/call/progress.js +37 -0
  32. package/dist/schema/call/proof.d.ts +328 -0
  33. package/dist/schema/call/proof.js +27 -0
  34. package/dist/schema/call/repository.d.ts +2220 -0
  35. package/dist/schema/call/repository.js +85 -0
  36. package/dist/schema/call/reward.d.ts +1178 -0
  37. package/dist/schema/call/reward.js +46 -0
  38. package/dist/schema/call/service.d.ts +3534 -0
  39. package/dist/schema/call/service.js +87 -0
  40. package/dist/schema/call/treasury.d.ts +2399 -0
  41. package/dist/schema/call/treasury.js +76 -0
  42. package/dist/schema/common/index.d.ts +623 -0
  43. package/dist/schema/common/index.js +331 -0
  44. package/dist/schema/index.d.ts +7 -0
  45. package/dist/schema/index.js +8 -0
  46. package/dist/schema/local/index.d.ts +7824 -0
  47. package/dist/schema/local/index.js +913 -0
  48. package/dist/schema/local/wip.d.ts +781 -0
  49. package/dist/schema/local/wip.js +229 -0
  50. package/dist/schema/messenger/index.d.ts +3624 -0
  51. package/dist/schema/messenger/index.js +407 -0
  52. package/dist/schema/query/index.d.ts +27176 -0
  53. package/dist/schema/query/index.js +1313 -0
  54. package/dist/schema/utils/guard-parser.d.ts +20 -0
  55. package/dist/schema/utils/guard-parser.js +410 -0
  56. package/dist/schema/utils/guard-query-utils.d.ts +5 -0
  57. package/dist/schema/utils/guard-query-utils.js +22 -0
  58. package/dist/schema/utils/node-parser.d.ts +59 -0
  59. package/dist/schema/utils/node-parser.js +382 -0
  60. package/dist/schema/utils/permission-index-utils.d.ts +2 -0
  61. package/dist/schema/utils/permission-index-utils.js +10 -0
  62. package/package.json +31 -49
  63. package/LICENSE +0 -201
  64. package/dist/call/arbitration.d.ts +0 -57
  65. package/dist/call/arbitration.d.ts.map +0 -1
  66. package/dist/call/arbitration.js +0 -245
  67. package/dist/call/arbitration.js.map +0 -1
  68. package/dist/call/base.d.ts +0 -85
  69. package/dist/call/base.d.ts.map +0 -1
  70. package/dist/call/base.js +0 -231
  71. package/dist/call/base.js.map +0 -1
  72. package/dist/call/call.d.ts +0 -95
  73. package/dist/call/call.d.ts.map +0 -1
  74. package/dist/call/call.js +0 -149
  75. package/dist/call/call.js.map +0 -1
  76. package/dist/call/demand.d.ts +0 -46
  77. package/dist/call/demand.d.ts.map +0 -1
  78. package/dist/call/demand.js +0 -201
  79. package/dist/call/demand.js.map +0 -1
  80. package/dist/call/guard.d.ts +0 -53
  81. package/dist/call/guard.d.ts.map +0 -1
  82. package/dist/call/guard.js +0 -386
  83. package/dist/call/guard.js.map +0 -1
  84. package/dist/call/machine.d.ts +0 -97
  85. package/dist/call/machine.d.ts.map +0 -1
  86. package/dist/call/machine.js +0 -342
  87. package/dist/call/machine.js.map +0 -1
  88. package/dist/call/object_permission.d.ts +0 -14
  89. package/dist/call/object_permission.d.ts.map +0 -1
  90. package/dist/call/object_permission.js +0 -59
  91. package/dist/call/object_permission.js.map +0 -1
  92. package/dist/call/permission.d.ts +0 -63
  93. package/dist/call/permission.d.ts.map +0 -1
  94. package/dist/call/permission.js +0 -137
  95. package/dist/call/permission.js.map +0 -1
  96. package/dist/call/personal.d.ts +0 -47
  97. package/dist/call/personal.d.ts.map +0 -1
  98. package/dist/call/personal.js +0 -119
  99. package/dist/call/personal.js.map +0 -1
  100. package/dist/call/repository.d.ts +0 -117
  101. package/dist/call/repository.d.ts.map +0 -1
  102. package/dist/call/repository.js +0 -408
  103. package/dist/call/repository.js.map +0 -1
  104. package/dist/call/service.d.ts +0 -115
  105. package/dist/call/service.d.ts.map +0 -1
  106. package/dist/call/service.js +0 -550
  107. package/dist/call/service.js.map +0 -1
  108. package/dist/call/treasury.d.ts +0 -46
  109. package/dist/call/treasury.d.ts.map +0 -1
  110. package/dist/call/treasury.js +0 -222
  111. package/dist/call/treasury.js.map +0 -1
  112. package/dist/common.d.ts +0 -12
  113. package/dist/common.d.ts.map +0 -1
  114. package/dist/common.js +0 -71
  115. package/dist/common.js.map +0 -1
  116. package/dist/index.d.ts.map +0 -1
  117. package/dist/index.js.map +0 -1
  118. package/dist/local/.d.ts +0 -20
  119. package/dist/local/.d.ts.map +0 -1
  120. package/dist/local/.js +0 -76
  121. package/dist/local/.js.map +0 -1
  122. package/dist/local/account.d.ts +0 -42
  123. package/dist/local/account.d.ts.map +0 -1
  124. package/dist/local/account.js +0 -335
  125. package/dist/local/account.js.map +0 -1
  126. package/dist/local/cache.d.ts +0 -32
  127. package/dist/local/cache.d.ts.map +0 -1
  128. package/dist/local/cache.js +0 -77
  129. package/dist/local/cache.js.map +0 -1
  130. package/dist/local/coin.d.ts +0 -22
  131. package/dist/local/coin.d.ts.map +0 -1
  132. package/dist/local/coin.js +0 -123
  133. package/dist/local/coin.js.map +0 -1
  134. package/dist/local/config.d.ts +0 -20
  135. package/dist/local/config.d.ts.map +0 -1
  136. package/dist/local/config.js +0 -75
  137. package/dist/local/config.js.map +0 -1
  138. package/dist/local/index.d.ts +0 -110
  139. package/dist/local/index.d.ts.map +0 -1
  140. package/dist/local/index.js +0 -122
  141. package/dist/local/index.js.map +0 -1
  142. package/dist/local/local.d.ts +0 -55
  143. package/dist/local/local.d.ts.map +0 -1
  144. package/dist/local/local.js +0 -248
  145. package/dist/local/local.js.map +0 -1
  146. package/dist/query/events.d.ts +0 -65
  147. package/dist/query/events.d.ts.map +0 -1
  148. package/dist/query/events.js +0 -75
  149. package/dist/query/events.js.map +0 -1
  150. package/dist/query/objects.d.ts +0 -346
  151. package/dist/query/objects.d.ts.map +0 -1
  152. package/dist/query/objects.js +0 -472
  153. package/dist/query/objects.js.map +0 -1
  154. package/dist/query/permission.d.ts +0 -15
  155. package/dist/query/permission.d.ts.map +0 -1
  156. package/dist/query/permission.js +0 -45
  157. package/dist/query/permission.js.map +0 -1
  158. package/dist/query/received.d.ts +0 -16
  159. package/dist/query/received.d.ts.map +0 -1
  160. package/dist/query/received.js +0 -16
  161. package/dist/query/received.js.map +0 -1
  162. package/dist/schema/call.d.ts +0 -13005
  163. package/dist/schema/call.d.ts.map +0 -1
  164. package/dist/schema/call.js +0 -997
  165. package/dist/schema/call.js.map +0 -1
  166. package/dist/schema/const.d.ts +0 -254
  167. package/dist/schema/const.d.ts.map +0 -1
  168. package/dist/schema/const.js +0 -305
  169. package/dist/schema/const.js.map +0 -1
  170. package/dist/schema/local.d.ts +0 -702
  171. package/dist/schema/local.d.ts.map +0 -1
  172. package/dist/schema/local.js +0 -150
  173. package/dist/schema/local.js.map +0 -1
  174. package/dist/schema/query.d.ts +0 -1465
  175. package/dist/schema/query.d.ts.map +0 -1
  176. package/dist/schema/query.js +0 -224
  177. package/dist/schema/query.js.map +0 -1
  178. package/dist/schema/util.d.ts +0 -71
  179. package/dist/schema/util.d.ts.map +0 -1
  180. package/dist/schema/util.js +0 -139
  181. package/dist/schema/util.js.map +0 -1
@@ -0,0 +1,382 @@
1
+ import { NodeSchema } from '../call/machine.js';
2
+ import { MachineNodeSchema } from '../query/index.js';
3
+ import { writeFileSync } from 'fs';
4
+ function detectFormat(text) {
5
+ const trimmed = text.trim();
6
+ if (trimmed.startsWith('{') || trimmed.startsWith('[')) {
7
+ return 'json';
8
+ }
9
+ return 'markdown';
10
+ }
11
+ function extractJsonFromMarkdown(markdown) {
12
+ const codeBlockRegex = /```(?:json)?\s*\n([\s\S]*?)```/g;
13
+ let match;
14
+ let lastMatch = null;
15
+ while ((match = codeBlockRegex.exec(markdown)) !== null) {
16
+ const jsonContent = match[1].trim();
17
+ if (jsonContent.startsWith('[') || jsonContent.startsWith('{')) {
18
+ const beforeMatch = markdown.substring(0, match.index);
19
+ const lineOffset = (beforeMatch.match(/\n/g) || []).length + 1;
20
+ lastMatch = { json: jsonContent, lineOffset };
21
+ }
22
+ }
23
+ return lastMatch;
24
+ }
25
+ function parseMarkdownToNodeData(markdown) {
26
+ const errors = [];
27
+ // Try to extract JSON from markdown code block first
28
+ const jsonMatch = extractJsonFromMarkdown(markdown);
29
+ if (jsonMatch) {
30
+ try {
31
+ const data = JSON.parse(jsonMatch.json);
32
+ return { data, errors: [] };
33
+ }
34
+ catch (e) {
35
+ errors.push({
36
+ message: `Failed to parse JSON from markdown: ${e.message}`,
37
+ path: '/',
38
+ });
39
+ return { data: null, errors };
40
+ }
41
+ }
42
+ // Parse markdown structure
43
+ const result = { op: 'add' };
44
+ const nodes = [];
45
+ // Parse operation type
46
+ const opMatch = markdown.match(/(?:^|\n)#+\s*(?:Operation|操作类型)[^\n]*\n+[-*]\s*op\s*:\s*(\w+)/i);
47
+ if (opMatch) {
48
+ result.op = opMatch[1].toLowerCase();
49
+ }
50
+ // Parse bReplace option
51
+ const replaceMatch = markdown.match(/(?:^|\n)#+\s*(?:Options|选项)[^\n]*\n+[-*]\s*bReplace\s*:\s*(true|false)/i);
52
+ if (replaceMatch) {
53
+ result.bReplace = replaceMatch[1].toLowerCase() === 'true';
54
+ }
55
+ // Parse node sections - match "## Node: name" format
56
+ const nodeSections = markdown.split(/(?=^##\s*(?:Node|节点)[:\s])/m);
57
+ for (const section of nodeSections.slice(1)) {
58
+ const nodeNameMatch = section.match(/^##\s*(?:Node|节点)[:\s]+(.+?)(?:\n|$)/im);
59
+ if (!nodeNameMatch)
60
+ continue;
61
+ const nodeName = nodeNameMatch[1].trim();
62
+ const node = { name: nodeName, pairs: [] };
63
+ // Parse pair sections - match "### Pair: prev_node" format
64
+ const pairSections = section.split(/(?=^###\s*(?:Pair|节点对|Previous Node)[:\s])/m);
65
+ for (const pairSection of pairSections.slice(1)) {
66
+ // Support both "prev_node: value" and "Previous Node: value" formats
67
+ const prevNodeMatch = pairSection.match(/(?:^|\n)[-*]\s*prev_node\s*[::]\s*(.+?)(?:\n|$)/im) ||
68
+ pairSection.match(/^###\s*(?:Pair|节点对|Previous Node)[:\s]+(.+?)(?:\n|$)/im);
69
+ const thresholdMatch = pairSection.match(/(?:^|\n)[-*]\s*threshold\s*[::]\s*(\d+)/i);
70
+ if (!prevNodeMatch)
71
+ continue;
72
+ const pair = {
73
+ prev_node: prevNodeMatch[1].trim(),
74
+ threshold: thresholdMatch ? parseInt(thresholdMatch[1], 10) : 0,
75
+ forwards: []
76
+ };
77
+ // Parse forwards from table format
78
+ const tableRows = pairSection.match(/\|[^\n]+\|/g);
79
+ if (tableRows && tableRows.length > 2) {
80
+ // Skip header and separator rows
81
+ for (const row of tableRows.slice(2)) {
82
+ const cells = row.split('|').filter(c => c.trim()).map(c => c.trim());
83
+ if (cells.length >= 2) {
84
+ const forward = {
85
+ name: cells[0],
86
+ weight: parseInt(cells[1], 10) || 0
87
+ };
88
+ if (cells.length >= 3 && cells[2] && cells[2] !== '-') {
89
+ forward.namedOperator = cells[2];
90
+ }
91
+ if (cells.length >= 4 && cells[3] && cells[3] !== '-') {
92
+ forward.permissionIndex = parseInt(cells[3], 10);
93
+ }
94
+ if (cells.length >= 5 && cells[4] && cells[4] !== '-') {
95
+ forward.guard = cells[4];
96
+ }
97
+ pair.forwards.push(forward);
98
+ }
99
+ }
100
+ }
101
+ // Also parse forwards from list format
102
+ const forwardMatches = pairSection.matchAll(/(?:^|\n)[-*]\s*(?:forward)?\s*[::]?\s*\n?([\s\S]*?)(?=(?:\n[-*]\s*(?:forward|prev_node|threshold))|\n###|\n##|$)/gi);
103
+ for (const forwardMatch of forwardMatches) {
104
+ const forwardSection = forwardMatch[1];
105
+ const nameMatch = forwardSection.match(/\s*name\s*[::]\s*(.+?)(?:\n|$)/im);
106
+ const weightMatch = forwardSection.match(/\s*weight\s*[::]\s*(\d+)/i);
107
+ if (nameMatch && weightMatch) {
108
+ const forward = {
109
+ name: nameMatch[1].trim(),
110
+ weight: parseInt(weightMatch[1], 10)
111
+ };
112
+ const namedOperatorMatch = forwardSection.match(/\s*namedOperator\s*[::]\s*(.+?)(?:\n|$)/im);
113
+ const permissionIndexMatch = forwardSection.match(/\s*permissionIndex\s*[::]\s*(\d+)/i);
114
+ const guardMatch = forwardSection.match(/\s*guard\s*[::]\s*(.+?)(?:\n|$)/im);
115
+ if (namedOperatorMatch) {
116
+ forward.namedOperator = namedOperatorMatch[1].trim();
117
+ }
118
+ if (permissionIndexMatch) {
119
+ forward.permissionIndex = parseInt(permissionIndexMatch[1], 10);
120
+ }
121
+ if (guardMatch) {
122
+ forward.guard = guardMatch[1].trim();
123
+ }
124
+ pair.forwards.push(forward);
125
+ }
126
+ }
127
+ node.pairs.push(pair);
128
+ }
129
+ nodes.push(node);
130
+ }
131
+ if (nodes.length > 0) {
132
+ result.nodes = nodes;
133
+ }
134
+ return { data: result, errors };
135
+ }
136
+ function formatZodPath(path) {
137
+ return '/' + path.map(p => String(p).replace(/~/g, '~0').replace(/\//g, '~1')).join('/');
138
+ }
139
+ function parseJsonWithErrors(text) {
140
+ const errors = [];
141
+ try {
142
+ const data = JSON.parse(text);
143
+ return { data, errors: [] };
144
+ }
145
+ catch (e) {
146
+ const jsonError = e;
147
+ const lineMatch = jsonError.message.match(/position\s+(\d+)/);
148
+ let line = 1;
149
+ let column = 1;
150
+ if (lineMatch) {
151
+ const pos = parseInt(lineMatch[1], 10);
152
+ const lines = text.substring(0, pos).split('\n');
153
+ line = lines.length;
154
+ column = lines[lines.length - 1].length + 1;
155
+ }
156
+ errors.push({
157
+ message: `JSON parse error: ${jsonError.message}`,
158
+ path: '/',
159
+ line,
160
+ column,
161
+ });
162
+ return { data: null, errors };
163
+ }
164
+ }
165
+ function validateWithZod(schema, data, basePath = '') {
166
+ const errors = [];
167
+ const result = schema.safeParse(data);
168
+ if (result.success) {
169
+ return { success: true, data: result.data, errors: [] };
170
+ }
171
+ for (const issue of result.error.issues) {
172
+ const path = basePath + formatZodPath(issue.path);
173
+ errors.push({
174
+ message: issue.message,
175
+ path,
176
+ });
177
+ }
178
+ return { success: false, errors };
179
+ }
180
+ export function parseNodeFromText(text) {
181
+ const trimmed = text.trim();
182
+ const format = detectFormat(trimmed);
183
+ let parsedData;
184
+ let errors = [];
185
+ if (format === 'markdown') {
186
+ const mdResult = parseMarkdownToNodeData(trimmed);
187
+ if (mdResult.errors.length > 0) {
188
+ return { success: false, errors: mdResult.errors };
189
+ }
190
+ parsedData = mdResult.data;
191
+ }
192
+ else {
193
+ const jsonResult = parseJsonWithErrors(trimmed);
194
+ if (jsonResult.errors.length > 0) {
195
+ return { success: false, errors: jsonResult.errors };
196
+ }
197
+ parsedData = jsonResult.data;
198
+ }
199
+ const validation = validateWithZod(NodeSchema, parsedData);
200
+ return {
201
+ success: validation.success,
202
+ data: validation.data,
203
+ errors: validation.errors,
204
+ };
205
+ }
206
+ export function parseMachineNodesFromText(text) {
207
+ const trimmed = text.trim();
208
+ const format = detectFormat(trimmed);
209
+ let parsedData;
210
+ let errors = [];
211
+ if (format === 'markdown') {
212
+ const mdResult = parseMarkdownToNodeData(trimmed);
213
+ if (mdResult.errors.length > 0) {
214
+ return { success: false, errors: mdResult.errors };
215
+ }
216
+ // If markdown contains { nodes: [...] }, extract nodes array
217
+ if (typeof mdResult.data === 'object' && mdResult.data !== null && 'nodes' in mdResult.data) {
218
+ parsedData = mdResult.data.nodes;
219
+ }
220
+ else {
221
+ parsedData = mdResult.data;
222
+ }
223
+ }
224
+ else {
225
+ const jsonResult = parseJsonWithErrors(trimmed);
226
+ if (jsonResult.errors.length > 0) {
227
+ return { success: false, errors: jsonResult.errors };
228
+ }
229
+ parsedData = jsonResult.data;
230
+ }
231
+ // Validate that parsedData is an array
232
+ if (!Array.isArray(parsedData)) {
233
+ if (typeof parsedData === 'object' && parsedData !== null && 'op' in parsedData) {
234
+ return {
235
+ success: false,
236
+ errors: [{
237
+ message: 'Expected JSON array of nodes for json_or_markdown mode. Use schema mode for operations with "op" field.',
238
+ path: '/',
239
+ }]
240
+ };
241
+ }
242
+ return {
243
+ success: false,
244
+ errors: [{
245
+ message: 'Expected JSON array of nodes',
246
+ path: '/',
247
+ }]
248
+ };
249
+ }
250
+ // Validate each node
251
+ const nodes = [];
252
+ for (let i = 0; i < parsedData.length; i++) {
253
+ const nodeData = parsedData[i];
254
+ const validation = validateWithZod(MachineNodeSchema, nodeData, `/${i}`);
255
+ if (validation.success && validation.data) {
256
+ nodes.push(validation.data);
257
+ }
258
+ else {
259
+ errors.push(...validation.errors);
260
+ }
261
+ }
262
+ if (errors.length > 0) {
263
+ return { success: false, errors };
264
+ }
265
+ return { success: true, data: nodes, errors: [] };
266
+ }
267
+ export function formatNodeErrors(errors) {
268
+ return errors.map(e => {
269
+ let msg = `Path: ${e.path}`;
270
+ if (e.line !== undefined && e.column !== undefined) {
271
+ msg += ` (line ${e.line}, column ${e.column})`;
272
+ }
273
+ msg += `\n Error: ${e.message}`;
274
+ return msg;
275
+ }).join('\n\n');
276
+ }
277
+ export function validateMachineNode(node) {
278
+ return validateWithZod(MachineNodeSchema, node);
279
+ }
280
+ export function validateMachineNodePair(pair) {
281
+ const result = MachineNodeSchema.shape.pairs.element.safeParse(pair);
282
+ if (result.success) {
283
+ return { success: true, errors: [] };
284
+ }
285
+ const errors = result.error.issues.map(issue => ({
286
+ message: issue.message,
287
+ path: formatZodPath(issue.path),
288
+ }));
289
+ return { success: false, errors };
290
+ }
291
+ export function validateMachineForward(forward) {
292
+ const result = MachineNodeSchema.shape.pairs.element.shape.forwards.element.safeParse(forward);
293
+ if (result.success) {
294
+ return { success: true, errors: [] };
295
+ }
296
+ const errors = result.error.issues.map(issue => ({
297
+ message: issue.message,
298
+ path: formatZodPath(issue.path),
299
+ }));
300
+ return { success: false, errors };
301
+ }
302
+ /**
303
+ * 将 MachineNode 数组生成为 JSON 格式字符串
304
+ */
305
+ export function machineNodesToJson(nodes, options = {}) {
306
+ const { machineId, includeComments = true } = options;
307
+ let result = '';
308
+ if (includeComments && machineId) {
309
+ result += `// Machine ID: ${machineId}\n`;
310
+ }
311
+ result += JSON.stringify(nodes, null, 2);
312
+ return result;
313
+ }
314
+ /**
315
+ * 将 MachineNode 数组生成为 Markdown 格式字符串
316
+ * 生成的格式与 parseMarkdownToNodeData 解析的格式匹配
317
+ */
318
+ export function machineNodesToMarkdown(nodes, options = {}) {
319
+ const { machineName, machineAddress, machineId, includeComments = true } = options;
320
+ let md = `# Machine Node Definition\n\n`;
321
+ if (machineName) {
322
+ md += `**Machine:** ${machineName}\n\n`;
323
+ }
324
+ if (machineAddress) {
325
+ md += `**Address:** ${machineAddress}\n\n`;
326
+ }
327
+ if (machineId) {
328
+ md += `**ID:** ${machineId}\n\n`;
329
+ }
330
+ md += `**Total Nodes:** ${nodes.length}\n\n`;
331
+ md += `---\n\n`;
332
+ for (const node of nodes) {
333
+ md += `## Node: ${node.name}\n\n`;
334
+ if (includeComments) {
335
+ md += `<!-- Node definition with pairs and forwards -->\n\n`;
336
+ }
337
+ for (const pair of node.pairs) {
338
+ md += `### Pair: ${pair.prev_node}\n\n`;
339
+ md += `- **prev_node**: ${pair.prev_node}\n`;
340
+ md += `- **threshold**: ${pair.threshold}\n\n`;
341
+ if (pair.forwards && pair.forwards.length > 0) {
342
+ md += `#### Forwards\n\n`;
343
+ // 使用表格格式展示 forwards
344
+ md += `| name | weight | namedOperator | permissionIndex | guard |\n`;
345
+ md += `|------|--------|---------------|-----------------|-------|\n`;
346
+ for (const forward of pair.forwards) {
347
+ const namedOp = forward.namedOperator || '';
348
+ const permIdx = forward.permissionIndex?.toString() || '';
349
+ const guard = forward.guard?.guard || '';
350
+ md += `| ${forward.name} | ${forward.weight} | ${namedOp} | ${permIdx} | ${guard} |\n`;
351
+ }
352
+ md += `\n`;
353
+ }
354
+ }
355
+ md += `---\n\n`;
356
+ }
357
+ // 在末尾添加 JSON 代码块(便于复制和解析)
358
+ md += `## JSON Definition\n\n`;
359
+ if (includeComments) {
360
+ md += `<!-- You can also use the JSON format below -->\n\n`;
361
+ }
362
+ md += `\`\`\`json\n`;
363
+ if (includeComments && machineId) {
364
+ md += `// Machine ID: ${machineId}\n`;
365
+ }
366
+ md += JSON.stringify(nodes, null, 2);
367
+ md += `\n\`\`\`\n`;
368
+ return md;
369
+ }
370
+ /**
371
+ * 将 MachineNode 数组保存到文件
372
+ * @param nodes - MachineNode 数组
373
+ * @param filePath - 文件路径
374
+ * @param format - 文件格式:'json' 或 'markdown'
375
+ * @param options - 可选配置
376
+ */
377
+ export function saveMachineNodesToFile(nodes, filePath, format = 'json', options = {}) {
378
+ const content = format === 'json'
379
+ ? machineNodesToJson(nodes, options)
380
+ : machineNodesToMarkdown(nodes, options);
381
+ writeFileSync(filePath, content, 'utf-8');
382
+ }
@@ -0,0 +1,2 @@
1
+ export declare const getValidBuiltinPermissionIndexes: () => Set<number>;
2
+ export declare const isValidPermissionIndex: (index: number) => boolean;
@@ -0,0 +1,10 @@
1
+ // 使用npm link的wowok包
2
+ import { BuiltinPermissionIndex } from "wowok";
3
+ // 提取所有有效的内置权限索引值并存储在 Set 中(查询更快)
4
+ export const getValidBuiltinPermissionIndexes = () => {
5
+ return new Set(Object.values(BuiltinPermissionIndex).filter(value => typeof value === 'number'));
6
+ };
7
+ // 验证权限索引是否有效
8
+ export const isValidPermissionIndex = (index) => {
9
+ return getValidBuiltinPermissionIndexes().has(index) || (index >= 1000 && index <= 65535);
10
+ };
package/package.json CHANGED
@@ -1,65 +1,47 @@
1
1
  {
2
2
  "name": "wowok_agent",
3
- "version": "1.6.6",
4
- "description": "Agent for WoWok: Unlock Co-Creation, Lighting Transaction, Empower Potential.",
5
- "main": "./dist/index.js",
6
- "types": "./dist/index.d.ts",
3
+ "version": "2.1.8",
4
+ "description": "Making It Easy for Agents to Communicate, Collaborate, Trade, and Trust.",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
7
  "module": "node",
8
8
  "type": "module",
9
9
  "scripts": {
10
+ "clean": "rm -rf dist",
10
11
  "build": "tsc",
11
- "build2": "tsc && webpack --mode production"
12
+ "watch": "tsc --watch",
13
+ "start": "tsx src/index.ts"
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "bin": {
19
+ "wowok_agent": "dist/index.js"
12
20
  },
13
21
  "keywords": [
14
22
  "web3",
15
23
  "AI",
16
24
  "wowok",
17
- "sui",
18
- "collaboration",
19
- "protocol",
20
- "WOW",
21
- "permission",
22
- "guard",
23
- "service",
24
- "order",
25
- "machine",
26
- "progress",
27
- "passport",
28
- "demand",
29
- "reward",
30
- "discount",
31
- "mark",
32
- "message",
33
- "vote",
34
- "tags",
35
- "entity",
36
- "resource",
37
- "grantor",
38
- "grantee",
39
- "move language",
40
- "move",
41
- "treasury",
42
- "payment",
43
- "arbitration",
44
- "oracle",
45
- "AI agent tool"
25
+ "wow",
26
+ "blockchain",
27
+ "mcp server",
28
+ "personal",
29
+ "merchant",
30
+ "finance",
31
+ "watch",
32
+ "messenger"
46
33
  ],
47
- "author": "wowok",
34
+ "author": "wowok <build@wowok.net>",
48
35
  "license": "Apache-2.0",
49
- "devDependencies": {
50
- "@types/node": "^20.12.12",
51
- "@types/node-rsa": "^1.1.4",
52
- "ts-loader": "^9.5.2",
53
- "typescript": "^5.8.2"
54
- },
55
36
  "dependencies": {
56
- "level": "^9.0.0",
57
- "node-rsa": "^1.1.1",
58
- "wowok": "^1.8.3",
59
- "zod": "^3.25.57",
60
- "zod-to-json-schema": "^3.24.6"
37
+ "@modelcontextprotocol/sdk": "^1.29.0",
38
+ "lodash": "^4.18.1",
39
+ "wowok": "file:d:/wowok/wchain/sdk/ts-sdks/packages/typescript",
40
+ "zod": "^3.25.76"
61
41
  },
62
- "files": [
63
- "dist"
64
- ]
42
+ "devDependencies": {
43
+ "@types/node": "^22.7.5",
44
+ "tsx": "^4.21.0",
45
+ "typescript": "^5.8.2"
46
+ }
65
47
  }