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,410 +1 @@
1
- import { GuardNodeSchema } from '../query/index.js';
2
- import { CallGuard_DataSchema } from '../call/guard.js';
3
- function detectFormat(text) {
4
- const trimmed = text.trim();
5
- if (trimmed.startsWith('{') || trimmed.startsWith('[')) {
6
- return 'json';
7
- }
8
- return 'markdown';
9
- }
10
- function extractJsonFromMarkdown(markdown) {
11
- const codeBlockRegex = /```(?:json)?\s*\n([\s\S]*?)```/g;
12
- let match;
13
- let lastMatch = null;
14
- while ((match = codeBlockRegex.exec(markdown)) !== null) {
15
- const jsonContent = match[1].trim();
16
- if (jsonContent.startsWith('{')) {
17
- const beforeMatch = markdown.substring(0, match.index);
18
- const lineOffset = (beforeMatch.match(/\n/g) || []).length + 1;
19
- lastMatch = { json: jsonContent, lineOffset };
20
- }
21
- }
22
- return lastMatch;
23
- }
24
- function parseMarkdownToGuardData(markdown) {
25
- const errors = [];
26
- const jsonMatch = extractJsonFromMarkdown(markdown);
27
- if (jsonMatch) {
28
- return { data: jsonMatch.json, errors: [] };
29
- }
30
- const result = {};
31
- const descriptionMatch = markdown.match(/(?:^|\n)#+\s*(?:Description|描述)[^\n]*\n+([^\n#]+)/i);
32
- if (descriptionMatch) {
33
- result.description = descriptionMatch[1].trim();
34
- }
35
- const tableMatch = markdown.match(/(?:^|\n)#+\s*(?:Table|数据表)[^\n]*\n+[\s\S]*?(?=(?:\n#+|$))/i);
36
- if (tableMatch) {
37
- const tableSection = tableMatch[0];
38
- const tableRows = tableSection.match(/\|[^\n]+\|/g);
39
- if (tableRows && tableRows.length > 2) {
40
- // Skip header row and separator row (|----|----|...)
41
- const rows = tableRows.slice(2).map(row => {
42
- const cells = row.split('|').filter(c => c.trim()).map(c => c.trim());
43
- // Match generated format: | Identifier | b_submission | value_type | value | name |
44
- // value_type can be number (6) or string ("U64" or "U64 (6)")
45
- const valueTypeCell = cells[2];
46
- let value_type;
47
- // Try to parse as number first
48
- const numericMatch = valueTypeCell.match(/\d+/);
49
- if (numericMatch) {
50
- value_type = parseInt(numericMatch[0], 10);
51
- }
52
- else {
53
- // Try to extract type name (e.g., "U64" from "U64" or "U64 (6)")
54
- const typeNameMatch = valueTypeCell.match(/^([A-Za-z]+)/);
55
- if (typeNameMatch) {
56
- value_type = typeNameMatch[1];
57
- }
58
- else {
59
- throw new Error(`Invalid value_type in table row: "${valueTypeCell}". Expected a number (0-19) or type name (e.g., "U64", "Address")`);
60
- }
61
- }
62
- return {
63
- identifier: parseInt(cells[0], 10),
64
- b_submission: cells[1].toLowerCase() === 'true',
65
- value_type,
66
- value: cells[3] === '-' ? undefined : cells[3],
67
- name: cells[4] === '-' ? undefined : cells[4]
68
- };
69
- });
70
- result.table = rows;
71
- }
72
- else {
73
- result.table = [];
74
- }
75
- }
76
- else {
77
- result.table = [];
78
- }
79
- const rootMatch = markdown.match(/(?:^|\n)#+\s*(?:Root|根节点)[^\n]*\n+([\s\S]*?)(?=(?:\n#+|$))/i);
80
- if (rootMatch) {
81
- const rootSection = rootMatch[1];
82
- const rootJsonMatch = rootSection.match(/```(?:json)?\s*\n([\s\S]*?)```/);
83
- if (rootJsonMatch) {
84
- try {
85
- result.root = JSON.parse(rootJsonMatch[1]);
86
- }
87
- catch (e) {
88
- errors.push({
89
- message: `Failed to parse root JSON: ${e.message}`,
90
- path: '/root',
91
- });
92
- }
93
- }
94
- }
95
- const relyMatch = markdown.match(/(?:^|\n)#+\s*(?:Rely|依赖)[^\n]*\n+([\s\S]*?)(?=(?:\n#+|$))/i);
96
- if (relyMatch) {
97
- const relySection = relyMatch[1];
98
- // Try to parse generated format first: "**Logic:** AND/OR" and "- guard" list
99
- const logicMatch = relySection.match(/\*\*Logic:\*\*\s*(AND|OR)/i);
100
- const guardListMatches = relySection.match(/^\s*[-*]\s*(\S+)$/gm);
101
- if (logicMatch || guardListMatches) {
102
- const logic_and = logicMatch ? logicMatch[1].toUpperCase() === 'AND' : true;
103
- const guards = guardListMatches
104
- ? guardListMatches.map(g => g.replace(/^\s*[-*]\s*/, '').trim())
105
- : [];
106
- result.rely = {
107
- guards,
108
- logic_or: !logic_and // logic_or is the opposite of logic_and
109
- };
110
- }
111
- else {
112
- // Fallback to YAML format: guards: [...] and logic_or: true/false
113
- const guardsMatch = relySection.match(/[-*]\s*guards?\s*:\s*\[([^\]]+)\]/i);
114
- const logicOrMatch = relySection.match(/[-*]\s*logic_or\s*:\s*(true|false)/i);
115
- if (guardsMatch || logicOrMatch) {
116
- result.rely = {
117
- guards: guardsMatch
118
- ? guardsMatch[1].split(',').map(g => g.trim().replace(/['"]/g, ''))
119
- : [],
120
- logic_or: logicOrMatch ? logicOrMatch[1].toLowerCase() === 'true' : undefined
121
- };
122
- }
123
- }
124
- }
125
- return { data: result, errors };
126
- }
127
- function parseJsonWithSourceMap(text, lineOffset = 0) {
128
- let pointers = {};
129
- let data;
130
- try {
131
- const lines = text.split('\n');
132
- const lineStarts = [0];
133
- for (let i = 0; i < lines.length; i++) {
134
- lineStarts.push(lineStarts[i] + lines[i].length + 1);
135
- }
136
- data = JSON.parse(text);
137
- buildPointers(data, '', pointers, text, lineStarts, lineOffset);
138
- return { data, map: { pointers } };
139
- }
140
- catch (e) {
141
- return null;
142
- }
143
- }
144
- function buildPointers(data, path, pointers, text, lineStarts, lineOffset) {
145
- if (typeof data !== 'object' || data === null) {
146
- return;
147
- }
148
- const pos = findValuePosition(text, path, lineStarts);
149
- if (pos !== undefined) {
150
- pointers[path] = {
151
- value: { line: pos.line + lineOffset, column: pos.column, pos: pos.pos }
152
- };
153
- }
154
- if (Array.isArray(data)) {
155
- data.forEach((item, index) => {
156
- buildPointers(item, `${path}/${index}`, pointers, text, lineStarts, lineOffset);
157
- });
158
- }
159
- else {
160
- Object.keys(data).forEach(key => {
161
- const escapedKey = key.replace(/~/g, '~0').replace(/\//g, '~1');
162
- buildPointers(data[key], `${path}/${escapedKey}`, pointers, text, lineStarts, lineOffset);
163
- });
164
- }
165
- }
166
- function findValuePosition(text, path, lineStarts) {
167
- if (path === '') {
168
- const match = text.match(/\S/);
169
- if (match && match.index !== undefined) {
170
- return getPosition(text, match.index, lineStarts);
171
- }
172
- return undefined;
173
- }
174
- const parts = path.split('/').slice(1);
175
- let searchPos = 0;
176
- let depth = 0;
177
- let inString = false;
178
- let escape = false;
179
- for (let i = 0; i < parts.length; i++) {
180
- const part = parts[i].replace(/~0/g, '~').replace(/~1/g, '/');
181
- let found = false;
182
- while (searchPos < text.length) {
183
- const char = text[searchPos];
184
- if (escape) {
185
- escape = false;
186
- searchPos++;
187
- continue;
188
- }
189
- if (char === '\\') {
190
- escape = true;
191
- searchPos++;
192
- continue;
193
- }
194
- if (char === '"') {
195
- inString = !inString;
196
- searchPos++;
197
- continue;
198
- }
199
- if (inString) {
200
- searchPos++;
201
- continue;
202
- }
203
- if (char === '{' || char === '[') {
204
- depth++;
205
- searchPos++;
206
- continue;
207
- }
208
- if (char === '}' || char === ']') {
209
- depth--;
210
- searchPos++;
211
- continue;
212
- }
213
- if (i < parts.length - 1 || !isNaN(Number(part))) {
214
- if (char === '"' && depth === i + 1) {
215
- const endQuote = text.indexOf('"', searchPos + 1);
216
- if (endQuote !== -1) {
217
- const key = text.slice(searchPos + 1, endQuote);
218
- if (key === part || (!isNaN(Number(part)) && key === parts[i - 1])) {
219
- searchPos = endQuote + 1;
220
- while (searchPos < text.length && (text[searchPos] === ' ' || text[searchPos] === ':' || text[searchPos] === '\n' || text[searchPos] === '\r' || text[searchPos] === '\t')) {
221
- searchPos++;
222
- }
223
- found = true;
224
- break;
225
- }
226
- }
227
- }
228
- if (!isNaN(Number(part)) && char === '[') {
229
- const arrayStart = searchPos;
230
- let arrayDepth = 1;
231
- let itemIndex = 0;
232
- let itemStart = searchPos + 1;
233
- for (let j = searchPos + 1; j < text.length; j++) {
234
- const c = text[j];
235
- if (c === '[')
236
- arrayDepth++;
237
- if (c === ']') {
238
- arrayDepth--;
239
- if (arrayDepth === 0)
240
- break;
241
- }
242
- if (c === ',' && arrayDepth === 1) {
243
- if (itemIndex === Number(part)) {
244
- searchPos = itemStart;
245
- while (searchPos < text.length && (text[searchPos] === ' ' || text[searchPos] === '\n' || text[searchPos] === '\r' || text[searchPos] === '\t')) {
246
- searchPos++;
247
- }
248
- found = true;
249
- break;
250
- }
251
- itemIndex++;
252
- itemStart = j + 1;
253
- }
254
- }
255
- if (found)
256
- break;
257
- }
258
- }
259
- searchPos++;
260
- }
261
- }
262
- while (searchPos < text.length && (text[searchPos] === ' ' || text[searchPos] === '\n' || text[searchPos] === '\r' || text[searchPos] === '\t')) {
263
- searchPos++;
264
- }
265
- return getPosition(text, searchPos, lineStarts);
266
- }
267
- function getPosition(text, pos, lineStarts) {
268
- let line = 1;
269
- for (let i = 0; i < lineStarts.length; i++) {
270
- if (lineStarts[i] > pos)
271
- break;
272
- line = i + 1;
273
- }
274
- const column = pos - lineStarts[line - 1] + 1;
275
- return { line, column, pos };
276
- }
277
- function formatZodPath(path) {
278
- return '/' + path.map(p => String(p).replace(/~/g, '~0').replace(/\//g, '~1')).join('/');
279
- }
280
- export function parseGuardFromText(text) {
281
- const errors = [];
282
- const trimmed = text.trim();
283
- const format = detectFormat(trimmed);
284
- let parsedData;
285
- let sourceMap = null;
286
- let lineOffset = 0;
287
- if (format === 'markdown') {
288
- const mdResult = parseMarkdownToGuardData(trimmed);
289
- if (mdResult.errors.length > 0) {
290
- return { success: false, errors: mdResult.errors };
291
- }
292
- if (typeof mdResult.data === 'string') {
293
- const jsonMatch = extractJsonFromMarkdown(trimmed);
294
- if (jsonMatch) {
295
- lineOffset = jsonMatch.lineOffset;
296
- const parsed = parseJsonWithSourceMap(mdResult.data, lineOffset);
297
- if (parsed) {
298
- parsedData = parsed.data;
299
- sourceMap = parsed.map;
300
- }
301
- else {
302
- errors.push({
303
- message: 'Failed to parse JSON from markdown code block',
304
- path: '/',
305
- });
306
- return { success: false, errors };
307
- }
308
- }
309
- else {
310
- parsedData = mdResult.data;
311
- }
312
- }
313
- else {
314
- parsedData = mdResult.data;
315
- }
316
- }
317
- else {
318
- try {
319
- const parsed = parseJsonWithSourceMap(trimmed, 0);
320
- if (parsed) {
321
- parsedData = parsed.data;
322
- sourceMap = parsed.map;
323
- }
324
- else {
325
- errors.push({
326
- message: 'Failed to parse JSON with source mapping',
327
- path: '/',
328
- });
329
- return { success: false, errors };
330
- }
331
- }
332
- catch (e) {
333
- const jsonError = e;
334
- const lineMatch = jsonError.message.match(/position\s+(\d+)/);
335
- let line = 1;
336
- let column = 1;
337
- if (lineMatch) {
338
- const pos = parseInt(lineMatch[1], 10);
339
- const lines = trimmed.substring(0, pos).split('\n');
340
- line = lines.length;
341
- column = lines[lines.length - 1].length + 1;
342
- }
343
- errors.push({
344
- message: `JSON parse error: ${jsonError.message}`,
345
- path: '/',
346
- line,
347
- column,
348
- });
349
- return { success: false, errors };
350
- }
351
- }
352
- const result = CallGuard_DataSchema.safeParse(parsedData);
353
- if (result.success) {
354
- return { success: true, data: result.data, errors: [] };
355
- }
356
- for (const issue of result.error.issues) {
357
- const path = formatZodPath(issue.path);
358
- let line;
359
- let column;
360
- if (sourceMap?.pointers[path]) {
361
- const pointer = sourceMap.pointers[path];
362
- if (pointer.value) {
363
- line = pointer.value.line;
364
- column = pointer.value.column;
365
- }
366
- else if (pointer.key) {
367
- line = pointer.key.line;
368
- column = pointer.key.column;
369
- }
370
- }
371
- let message = issue.message;
372
- if (issue.code === 'invalid_union') {
373
- // Zod v4 changed the structure of invalid_union issues
374
- // Now it has 'errors' property instead of 'unionErrors'
375
- const unionIssue = issue;
376
- if (unionIssue.errors) {
377
- const unionErrors = unionIssue.errors.map((e) => e.issues?.map((i) => i.message).join('; ') || e.message).join(' | ');
378
- message = `${message}. Alternatives: ${unionErrors}`;
379
- }
380
- }
381
- errors.push({
382
- message,
383
- path,
384
- line,
385
- column,
386
- });
387
- }
388
- return { success: false, errors };
389
- }
390
- export function formatGuardErrors(errors) {
391
- return errors.map(e => {
392
- let msg = `Path: ${e.path}`;
393
- if (e.line !== undefined && e.column !== undefined) {
394
- msg += ` (line ${e.line}, column ${e.column})`;
395
- }
396
- msg += `\n Error: ${e.message}`;
397
- return msg;
398
- }).join('\n\n');
399
- }
400
- export function validateGuardNode(node) {
401
- const result = GuardNodeSchema.safeParse(node);
402
- if (result.success) {
403
- return { success: true, errors: [] };
404
- }
405
- const errors = result.error.issues.map(issue => ({
406
- message: issue.message,
407
- path: formatZodPath(issue.path),
408
- }));
409
- return { success: false, errors };
410
- }
1
+ import{GuardNodeSchema}from'../query/index.js';import{CallGuard_DataSchema}from'../call/guard.js';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']('{')){const f=a['substring'](0x0,c['index']),g=(f['match'](/\n/g)||[])['length']+0x1;d={'json':e,'lineOffset':g};}}return d;}function parseMarkdownToGuardData(a){const b=[],c=extractJsonFromMarkdown(a);if(c)return{'data':c['json'],'errors':[]};const d={},f=a['match'](/(?:^|\n)#+\s*(?:Description|描述)[^\n]*\n+([^\n#]+)/i);f&&(d['description']=f[0x1]['trim']());const g=a['match'](/(?:^|\n)#+\s*(?:Table|数据表)[^\n]*\n+[\s\S]*?(?=(?:\n#+|$))/i);if(g){const j=g[0x0],k=j['match'](/\|[^\n]+\|/g);if(k&&k['length']>0x2){const l=k['slice'](0x2)['map'](m=>{const n=m['split']('|')['filter'](r=>r['trim']())['map'](r=>r['trim']()),o=n[0x2];let p;const q=o['match'](/\d+/);if(q)p=parseInt(q[0x0],0xa);else{const r=o['match'](/^([A-Za-z]+)/);if(r)p=r[0x1];else throw new Error('Invalid\x20value_type\x20in\x20table\x20row:\x20\x22'+o+'\x22.\x20Expected\x20a\x20number\x20(0-19)\x20or\x20type\x20name\x20(e.g.,\x20\x22U64\x22,\x20\x22Address\x22)');}return{'identifier':parseInt(n[0x0],0xa),'b_submission':n[0x1]['toLowerCase']()==='true','value_type':p,'value':n[0x3]==='-'?undefined:n[0x3],'name':n[0x4]==='-'?undefined:n[0x4]};});d['table']=l;}else d['table']=[];}else d['table']=[];const h=a['match'](/(?:^|\n)#+\s*(?:Root|根节点)[^\n]*\n+([\s\S]*?)(?=(?:\n#+|$))/i);if(h){const m=h[0x1],n=m['match'](/```(?:json)?\s*\n([\s\S]*?)```/);if(n)try{d['root']=JSON['parse'](n[0x1]);}catch(o){b['push']({'message':'Failed\x20to\x20parse\x20root\x20JSON:\x20'+o['message'],'path':'/root'});}}const i=a['match'](/(?:^|\n)#+\s*(?:Rely|依赖)[^\n]*\n+([\s\S]*?)(?=(?:\n#+|$))/i);if(i){const p=i[0x1],q=p['match'](/\*\*Logic:\*\*\s*(AND|OR)/i),r=p['match'](/^\s*[-*]\s*(\S+)$/gm);if(q||r){const s=q?q[0x1]['toUpperCase']()==='AND':!![],t=r?r['map'](u=>u['replace'](/^\s*[-*]\s*/,'')['trim']()):[];d['rely']={'guards':t,'logic_or':!s};}else{const u=p['match'](/[-*]\s*guards?\s*:\s*\[([^\]]+)\]/i),v=p['match'](/[-*]\s*logic_or\s*:\s*(true|false)/i);(u||v)&&(d['rely']={'guards':u?u[0x1]['split'](',')['map'](w=>w['trim']()['replace'](/['"]/g,'')):[],'logic_or':v?v[0x1]['toLowerCase']()==='true':undefined});}}return{'data':d,'errors':b};}function parseJsonWithSourceMap(a,b=0x0){let c={},d;try{const f=a['split']('\x0a'),g=[0x0];for(let h=0x0;h<f['length'];h++){g['push'](g[h]+f[h]['length']+0x1);}return d=JSON['parse'](a),buildPointers(d,'',c,a,g,b),{'data':d,'map':{'pointers':c}};}catch(j){return null;}}function buildPointers(a,b,c,d,e,f){if(typeof a!=='object'||a===null)return;const g=findValuePosition(d,b,e);g!==undefined&&(c[b]={'value':{'line':g['line']+f,'column':g['column'],'pos':g['pos']}}),Array['isArray'](a)?a['forEach']((h,i)=>{buildPointers(h,b+'/'+i,c,d,e,f);}):Object['keys'](a)['forEach'](h=>{const i=h['replace'](/~/g,'~0')['replace'](/\//g,'~1');buildPointers(a[h],b+'/'+i,c,d,e,f);});}function findValuePosition(a,b,d){if(b===''){const l=a['match'](/\S/);if(l&&l['index']!==undefined)return getPosition(a,l['index'],d);return undefined;}const e=b['split']('/')['slice'](0x1);let f=0x0,g=0x0,h=![],k=![];for(let m=0x0;m<e['length'];m++){const n=e[m]['replace'](/~0/g,'~')['replace'](/~1/g,'/');let o=![];while(f<a['length']){const p=a[f];if(k){k=![],f++;continue;}if(p==='\x5c'){k=!![],f++;continue;}if(p==='\x22'){h=!h,f++;continue;}if(h){f++;continue;}if(p==='{'||p==='['){g++,f++;continue;}if(p==='}'||p===']'){g--,f++;continue;}if(m<e['length']-0x1||!isNaN(Number(n))){if(p==='\x22'&&g===m+0x1){const q=a['indexOf']('\x22',f+0x1);if(q!==-0x1){const r=a['slice'](f+0x1,q);if(r===n||!isNaN(Number(n))&&r===e[m-0x1]){f=q+0x1;while(f<a['length']&&(a[f]==='\x20'||a[f]===':'||a[f]==='\x0a'||a[f]==='\x0d'||a[f]==='\x09')){f++;}o=!![];break;}}}if(!isNaN(Number(n))&&p==='['){const s=f;let t=0x1,u=0x0,v=f+0x1;for(let w=f+0x1;w<a['length'];w++){const x=a[w];if(x==='[')t++;if(x===']'){t--;if(t===0x0)break;}if(x===','&&t===0x1){if(u===Number(n)){f=v;while(f<a['length']&&(a[f]==='\x20'||a[f]==='\x0a'||a[f]==='\x0d'||a[f]==='\x09')){f++;}o=!![];break;}u++,v=w+0x1;}}if(o)break;}}f++;}}while(f<a['length']&&(a[f]==='\x20'||a[f]==='\x0a'||a[f]==='\x0d'||a[f]==='\x09')){f++;}return getPosition(a,f,d);}function getPosition(a,b,c){let d=0x1;for(let f=0x0;f<c['length'];f++){if(c[f]>b)break;d=f+0x1;}const e=b-c[d-0x1]+0x1;return{'line':d,'column':e,'pos':b};}function formatZodPath(a){return'/'+a['map'](b=>String(b)['replace'](/~/g,'~0')['replace'](/\//g,'~1'))['join']('/');}export function parseGuardFromText(a){const b=[],c=a['trim'](),d=detectFormat(c);let f,g=null,h=0x0;if(d==='markdown'){const j=parseMarkdownToGuardData(c);if(j['errors']['length']>0x0)return{'success':![],'errors':j['errors']};if(typeof j['data']==='string'){const k=extractJsonFromMarkdown(c);if(k){h=k['lineOffset'];const l=parseJsonWithSourceMap(j['data'],h);if(l)f=l['data'],g=l['map'];else return b['push']({'message':'Failed\x20to\x20parse\x20JSON\x20from\x20markdown\x20code\x20block','path':'/'}),{'success':![],'errors':b};}else f=j['data'];}else f=j['data'];}else try{const m=parseJsonWithSourceMap(c,0x0);if(m)f=m['data'],g=m['map'];else return b['push']({'message':'Failed\x20to\x20parse\x20JSON\x20with\x20source\x20mapping','path':'/'}),{'success':![],'errors':b};}catch(n){const o=n,p=o['message']['match'](/position\s+(\d+)/);let q=0x1,r=0x1;if(p){const s=parseInt(p[0x1],0xa),t=c['substring'](0x0,s)['split']('\x0a');q=t['length'],r=t[t['length']-0x1]['length']+0x1;}return b['push']({'message':'JSON\x20parse\x20error:\x20'+o['message'],'path':'/','line':q,'column':r}),{'success':![],'errors':b};}const i=CallGuard_DataSchema['safeParse'](f);if(i['success'])return{'success':!![],'data':i['data'],'errors':[]};for(const u of i['error']['issues']){const v=formatZodPath(u['path']);let w,x;if(g?.['pointers'][v]){const z=g['pointers'][v];if(z['value'])w=z['value']['line'],x=z['value']['column'];else z['key']&&(w=z['key']['line'],x=z['key']['column']);}let y=u['message'];if(u['code']==='invalid_union'){const A=u;if(A['errors']){const B=A['errors']['map'](C=>C['issues']?.['map'](D=>D['message'])['join'](';\x20')||C['message'])['join']('\x20|\x20');y=y+'.\x20Alternatives:\x20'+B;}}b['push']({'message':y,'path':v,'line':w,'column':x});}return{'success':![],'errors':b};}export function formatGuardErrors(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 validateGuardNode(a){const b=GuardNodeSchema['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};}
@@ -1,22 +1 @@
1
- import { GUARDQUERY } from "wowok";
2
- const validGuardQueryIds = new Set(GUARDQUERY.map(item => item.id));
3
- const validGuardQueryNames = new Set(GUARDQUERY.map(item => item.name.toLowerCase()));
4
- export const isValidGuardQueryId = (id) => {
5
- return validGuardQueryIds.has(id);
6
- };
7
- export const isValidGuardQueryName = (name) => {
8
- return validGuardQueryNames.has(name.toLowerCase());
9
- };
10
- export const isValidGuardQueryIdOrName = (input) => {
11
- if (typeof input === 'number') {
12
- return isValidGuardQueryId(input);
13
- }
14
- return isValidGuardQueryName(input);
15
- };
16
- export const getGuardQueryByIdOrName = (input) => {
17
- if (typeof input === 'number') {
18
- return GUARDQUERY.find(item => item.id === input);
19
- }
20
- return GUARDQUERY.find(item => item.name.toLowerCase() === input.toLowerCase());
21
- };
22
- export const GUARD_QUERY_NAMES = GUARDQUERY.map(item => item.name);
1
+ import{GUARDQUERY}from'wowok';const validGuardQueryIds=new Set(GUARDQUERY['map'](a=>a['id'])),validGuardQueryNames=new Set(GUARDQUERY['map'](a=>a['name']['toLowerCase']()));export const isValidGuardQueryId=a=>{return validGuardQueryIds['has'](a);};export const isValidGuardQueryName=a=>{return validGuardQueryNames['has'](a['toLowerCase']());};export const isValidGuardQueryIdOrName=a=>{if(typeof a==='number')return isValidGuardQueryId(a);return isValidGuardQueryName(a);};export const getGuardQueryByIdOrName=a=>{if(typeof a==='number')return GUARDQUERY['find'](b=>b['id']===a);return GUARDQUERY['find'](b=>b['name']['toLowerCase']()===a['toLowerCase']());};export const GUARD_QUERY_NAMES=GUARDQUERY['map'](a=>a['name']);
@@ -40,20 +40,6 @@ export interface MachineNodeFileOptions {
40
40
  machineId?: string;
41
41
  includeComments?: boolean;
42
42
  }
43
- /**
44
- * 将 MachineNode 数组生成为 JSON 格式字符串
45
- */
46
43
  export declare function machineNodesToJson(nodes: MachineNode[], options?: MachineNodeFileOptions): string;
47
- /**
48
- * 将 MachineNode 数组生成为 Markdown 格式字符串
49
- * 生成的格式与 parseMarkdownToNodeData 解析的格式匹配
50
- */
51
44
  export declare function machineNodesToMarkdown(nodes: MachineNode[], options?: MachineNodeFileOptions): string;
52
- /**
53
- * 将 MachineNode 数组保存到文件
54
- * @param nodes - MachineNode 数组
55
- * @param filePath - 文件路径
56
- * @param format - 文件格式:'json' 或 'markdown'
57
- * @param options - 可选配置
58
- */
59
45
  export declare function saveMachineNodesToFile(nodes: MachineNode[], filePath: string, format?: 'json' | 'markdown', options?: MachineNodeFileOptions): void;