wowok_agent 2.1.37 → 2.1.39

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 (39) hide show
  1. package/dist/index.d.ts +45 -2
  2. package/dist/index.js +1 -1319
  3. package/dist/schema/call/allocation.js +1 -27
  4. package/dist/schema/call/arbitration.js +1 -106
  5. package/dist/schema/call/base.js +1 -152
  6. package/dist/schema/call/contact.js +1 -41
  7. package/dist/schema/call/demand.js +1 -51
  8. package/dist/schema/call/guard.d.ts +6 -6
  9. package/dist/schema/call/guard.js +1 -67
  10. package/dist/schema/call/handler.d.ts +0 -45
  11. package/dist/schema/call/handler.js +1 -214
  12. package/dist/schema/call/index.js +1 -19
  13. package/dist/schema/call/machine.js +1 -164
  14. package/dist/schema/call/order.js +1 -39
  15. package/dist/schema/call/payment.js +1 -20
  16. package/dist/schema/call/permission.js +1 -118
  17. package/dist/schema/call/personal.js +1 -81
  18. package/dist/schema/call/progress.js +1 -28
  19. package/dist/schema/call/proof.js +1 -27
  20. package/dist/schema/call/repository.js +1 -85
  21. package/dist/schema/call/reward.d.ts +12 -0
  22. package/dist/schema/call/reward.js +1 -46
  23. package/dist/schema/call/service.js +1 -88
  24. package/dist/schema/call/treasury.d.ts +84 -0
  25. package/dist/schema/call/treasury.js +1 -76
  26. package/dist/schema/common/index.js +1 -395
  27. package/dist/schema/index.js +1 -8
  28. package/dist/schema/local/index.js +1 -913
  29. package/dist/schema/local/wip.js +1 -230
  30. package/dist/schema/messenger/index.d.ts +0 -2
  31. package/dist/schema/messenger/index.js +1 -479
  32. package/dist/schema/query/index.d.ts +155 -0
  33. package/dist/schema/query/index.js +1 -1256
  34. package/dist/schema/utils/guard-parser.js +1 -410
  35. package/dist/schema/utils/guard-query-utils.js +1 -22
  36. package/dist/schema/utils/node-parser.d.ts +0 -14
  37. package/dist/schema/utils/node-parser.js +1 -382
  38. package/dist/schema/utils/permission-index-utils.js +1 -10
  39. package/package.json +5 -3
@@ -1,382 +1 @@
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
- }
1
+ import{NodeSchema}from'../call/machine.js';import{MachineNodeSchema}from'../query/index.js';import{writeFileSync}from'fs';function detectFormat(a){const b=a['trim']();if(b['startsWith']('{')||b['startsWith']('['))return'json';return'markdown';}function extractJsonFromMarkdown(a){const b=/```(?:json)?\s*\n([\s\S]*?)```/g;let c,d=null;while((c=b['exec'](a))!==null){const e=c[0x1]['trim']();if(e['startsWith']('[')||e['startsWith']('{')){const f=a['substring'](0x0,c['index']),g=(f['match'](/\n/g)||[])['length']+0x1;d={'json':e,'lineOffset':g};}}return d;}function parseMarkdownToNodeData(a){const b=[],c=extractJsonFromMarkdown(a);if(c)try{const j=JSON['parse'](c['json']);return{'data':j,'errors':[]};}catch(k){return b['push']({'message':'Failed\x20to\x20parse\x20JSON\x20from\x20markdown:\x20'+k['message'],'path':'/'}),{'data':null,'errors':b};}const d={'op':'add'},f=[],g=a['match'](/(?:^|\n)#+\s*(?:Operation|操作类型)[^\n]*\n+[-*]\s*op\s*:\s*(\w+)/i);g&&(d['op']=g[0x1]['toLowerCase']());const h=a['match'](/(?:^|\n)#+\s*(?:Options|选项)[^\n]*\n+[-*]\s*bReplace\s*:\s*(true|false)/i);h&&(d['bReplace']=h[0x1]['toLowerCase']()==='true');const i=a['split'](/(?=^##\s*(?:Node|节点)[:\s])/m);for(const l of i['slice'](0x1)){const m=l['match'](/^##\s*(?:Node|节点)[:\s]+(.+?)(?:\n|$)/im);if(!m)continue;const n=m[0x1]['trim'](),o={'name':n,'pairs':[]},p=l['split'](/(?=^###\s*(?:Pair|节点对|Previous Node)[:\s])/m);for(const q of p['slice'](0x1)){const r=q['match'](/(?:^|\n)[-*]\s*prev_node\s*[::]\s*(.+?)(?:\n|$)/im)||q['match'](/^###\s*(?:Pair|节点对|Previous Node)[:\s]+(.+?)(?:\n|$)/im),s=q['match'](/(?:^|\n)[-*]\s*threshold\s*[::]\s*(\d+)/i);if(!r)continue;const t={'prev_node':r[0x1]['trim'](),'threshold':s?parseInt(s[0x1],0xa):0x0,'forwards':[]},u=q['match'](/\|[^\n]+\|/g);if(u&&u['length']>0x2)for(const w of u['slice'](0x2)){const x=w['split']('|')['filter'](y=>y['trim']())['map'](y=>y['trim']());if(x['length']>=0x2){const y={'name':x[0x0],'weight':parseInt(x[0x1],0xa)||0x0};x['length']>=0x3&&x[0x2]&&x[0x2]!=='-'&&(y['namedOperator']=x[0x2]),x['length']>=0x4&&x[0x3]&&x[0x3]!=='-'&&(y['permissionIndex']=parseInt(x[0x3],0xa)),x['length']>=0x5&&x[0x4]&&x[0x4]!=='-'&&(y['guard']=x[0x4]),t['forwards']['push'](y);}}const v=q['matchAll'](/(?:^|\n)[-*]\s*(?:forward)?\s*[::]?\s*\n?([\s\S]*?)(?=(?:\n[-*]\s*(?:forward|prev_node|threshold))|\n###|\n##|$)/gi);for(const z of v){const A=z[0x1],B=A['match'](/\s*name\s*[::]\s*(.+?)(?:\n|$)/im),C=A['match'](/\s*weight\s*[::]\s*(\d+)/i);if(B&&C){const D={'name':B[0x1]['trim'](),'weight':parseInt(C[0x1],0xa)},E=A['match'](/\s*namedOperator\s*[::]\s*(.+?)(?:\n|$)/im),F=A['match'](/\s*permissionIndex\s*[::]\s*(\d+)/i),G=A['match'](/\s*guard\s*[::]\s*(.+?)(?:\n|$)/im);E&&(D['namedOperator']=E[0x1]['trim']()),F&&(D['permissionIndex']=parseInt(F[0x1],0xa)),G&&(D['guard']=G[0x1]['trim']()),t['forwards']['push'](D);}}o['pairs']['push'](t);}f['push'](o);}return f['length']>0x0&&(d['nodes']=f),{'data':d,'errors':b};}function formatZodPath(a){return'/'+a['map'](b=>String(b)['replace'](/~/g,'~0')['replace'](/\//g,'~1'))['join']('/');}function parseJsonWithErrors(a){const b=[];try{const c=JSON['parse'](a);return{'data':c,'errors':[]};}catch(d){const f=d,g=f['message']['match'](/position\s+(\d+)/);let h=0x1,i=0x1;if(g){const j=parseInt(g[0x1],0xa),k=a['substring'](0x0,j)['split']('\x0a');h=k['length'],i=k[k['length']-0x1]['length']+0x1;}return b['push']({'message':'JSON\x20parse\x20error:\x20'+f['message'],'path':'/','line':h,'column':i}),{'data':null,'errors':b};}}function validateWithZod(a,b,c=''){const d=[],e=a['safeParse'](b);if(e['success'])return{'success':!![],'data':e['data'],'errors':[]};for(const f of e['error']['issues']){const g=c+formatZodPath(f['path']);d['push']({'message':f['message'],'path':g});}return{'success':![],'errors':d};}export function parseNodeFromText(a){const b=a['trim'](),c=detectFormat(b);let d,e=[];if(c==='markdown'){const g=parseMarkdownToNodeData(b);if(g['errors']['length']>0x0)return{'success':![],'errors':g['errors']};d=g['data'];}else{const h=parseJsonWithErrors(b);if(h['errors']['length']>0x0)return{'success':![],'errors':h['errors']};d=h['data'];}const f=validateWithZod(NodeSchema,d);return{'success':f['success'],'data':f['data'],'errors':f['errors']};}export function parseMachineNodesFromText(a){const b=a['trim'](),c=detectFormat(b);let d,e=[];if(c==='markdown'){const g=parseMarkdownToNodeData(b);if(g['errors']['length']>0x0)return{'success':![],'errors':g['errors']};typeof g['data']==='object'&&g['data']!==null&&'nodes'in g['data']?d=g['data']['nodes']:d=g['data'];}else{const h=parseJsonWithErrors(b);if(h['errors']['length']>0x0)return{'success':![],'errors':h['errors']};d=h['data'];}if(!Array['isArray'](d)){if(typeof d==='object'&&d!==null&&'op'in d)return{'success':![],'errors':[{'message':'Expected\x20JSON\x20array\x20of\x20nodes\x20for\x20json_or_markdown\x20mode.\x20Use\x20schema\x20mode\x20for\x20operations\x20with\x20\x22op\x22\x20field.','path':'/'}]};return{'success':![],'errors':[{'message':'Expected\x20JSON\x20array\x20of\x20nodes','path':'/'}]};}const f=[];for(let j=0x0;j<d['length'];j++){const k=d[j],l=validateWithZod(MachineNodeSchema,k,'/'+j);l['success']&&l['data']?f['push'](l['data']):e['push'](...l['errors']);}if(e['length']>0x0)return{'success':![],'errors':e};return{'success':!![],'data':f,'errors':[]};}export function formatNodeErrors(a){return a['map'](b=>{let c='Path:\x20'+b['path'];return b['line']!==undefined&&b['column']!==undefined&&(c+='\x20(line\x20'+b['line']+',\x20column\x20'+b['column']+')'),c+='\x0a\x20\x20Error:\x20'+b['message'],c;})['join']('\x0a\x0a');}export function validateMachineNode(a){return validateWithZod(MachineNodeSchema,a);}export function validateMachineNodePair(a){const b=MachineNodeSchema['shape']['pairs']['element']['safeParse'](a);if(b['success'])return{'success':!![],'errors':[]};const c=b['error']['issues']['map'](d=>({'message':d['message'],'path':formatZodPath(d['path'])}));return{'success':![],'errors':c};}export function validateMachineForward(a){const b=MachineNodeSchema['shape']['pairs']['element']['shape']['forwards']['element']['safeParse'](a);if(b['success'])return{'success':!![],'errors':[]};const c=b['error']['issues']['map'](d=>({'message':d['message'],'path':formatZodPath(d['path'])}));return{'success':![],'errors':c};}export function machineNodesToJson(a,b={}){const {machineId:c,includeComments:includeComments=!![]}=b;let d='';return includeComments&&c&&(d+='//\x20Machine\x20ID:\x20'+c+'\x0a'),d+=JSON['stringify'](a,null,0x2),d;}export function machineNodesToMarkdown(a,b={}){const {machineName:c,machineAddress:d,machineId:e,includeComments:includeComments=!![]}=b;let f='#\x20Machine\x20Node\x20Definition\x0a\x0a';c&&(f+='**Machine:**\x20'+c+'\x0a\x0a');d&&(f+='**Address:**\x20'+d+'\x0a\x0a');e&&(f+='**ID:**\x20'+e+'\x0a\x0a');f+='**Total\x20Nodes:**\x20'+a['length']+'\x0a\x0a',f+='---\x0a\x0a';for(const g of a){f+='##\x20Node:\x20'+g['name']+'\x0a\x0a';includeComments&&(f+='<!--\x20Node\x20definition\x20with\x20pairs\x20and\x20forwards\x20-->\x0a\x0a');for(const h of g['pairs']){f+='###\x20Pair:\x20'+h['prev_node']+'\x0a\x0a',f+='-\x20**prev_node**:\x20'+h['prev_node']+'\x0a',f+='-\x20**threshold**:\x20'+h['threshold']+'\x0a\x0a';if(h['forwards']&&h['forwards']['length']>0x0){f+='####\x20Forwards\x0a\x0a',f+='|\x20name\x20|\x20weight\x20|\x20namedOperator\x20|\x20permissionIndex\x20|\x20guard\x20|\x0a',f+='|------|--------|---------------|-----------------|-------|\x0a';for(const i of h['forwards']){const j=i['namedOperator']||'',k=i['permissionIndex']?.['toString']()||'',l=i['guard']?.['guard']||'';f+='|\x20'+i['name']+'\x20|\x20'+i['weight']+'\x20|\x20'+j+'\x20|\x20'+k+'\x20|\x20'+l+'\x20|\x0a';}f+='\x0a';}}f+='---\x0a\x0a';}return f+='##\x20JSON\x20Definition\x0a\x0a',includeComments&&(f+='<!--\x20You\x20can\x20also\x20use\x20the\x20JSON\x20format\x20below\x20-->\x0a\x0a'),f+='```json\x0a',includeComments&&e&&(f+='//\x20Machine\x20ID:\x20'+e+'\x0a'),f+=JSON['stringify'](a,null,0x2),f+='\x0a```\x0a',f;}export function saveMachineNodesToFile(a,b,c='json',d={}){const e=c==='json'?machineNodesToJson(a,d):machineNodesToMarkdown(a,d);writeFileSync(b,e,'utf-8');}
@@ -1,10 +1 @@
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
- };
1
+ import{BuiltinPermissionIndex}from'wowok';export const getValidBuiltinPermissionIndexes=()=>{return new Set(Object['values'](BuiltinPermissionIndex)['filter'](a=>typeof a==='number'));};export const isValidPermissionIndex=a=>{return getValidBuiltinPermissionIndexes()['has'](a)||a>=0x3e8&&a<=0xffff;};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wowok_agent",
3
- "version": "2.1.37",
3
+ "version": "2.1.39",
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",
@@ -30,17 +30,19 @@
30
30
  "dependencies": {
31
31
  "@modelcontextprotocol/sdk": "^1.29.0",
32
32
  "lodash": "^4.18.1",
33
- "wowok": "2.1.37",
33
+ "wowok": "2.1.40",
34
34
  "zod": "^3.25.76"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@types/node": "^22.19.17",
38
+ "javascript-obfuscator": "^4.1.1",
38
39
  "tsx": "^4.21.0",
39
40
  "typescript": "^5.8.2"
40
41
  },
41
42
  "scripts": {
42
43
  "clean": "rm -rf dist",
43
- "build": "tsc",
44
+ "build": "tsc && npm run obfuscate",
45
+ "obfuscate": "javascript-obfuscator dist --output dist --config obfuscator.json",
44
46
  "watch": "tsc --watch",
45
47
  "start": "tsx src/index.ts"
46
48
  }