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,20 @@
1
+ import { CallGuard_Data } from '../call/guard.js';
2
+ export interface GuardParseError {
3
+ message: string;
4
+ path: string;
5
+ line?: number;
6
+ column?: number;
7
+ start?: number;
8
+ end?: number;
9
+ }
10
+ export interface GuardParseResult {
11
+ success: boolean;
12
+ data?: CallGuard_Data;
13
+ errors: GuardParseError[];
14
+ }
15
+ export declare function parseGuardFromText(text: string): GuardParseResult;
16
+ export declare function formatGuardErrors(errors: GuardParseError[]): string;
17
+ export declare function validateGuardNode(node: unknown): {
18
+ success: boolean;
19
+ errors: GuardParseError[];
20
+ };
@@ -0,0 +1,410 @@
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
+ }
@@ -0,0 +1,5 @@
1
+ export declare const isValidGuardQueryId: (id: number) => boolean;
2
+ export declare const isValidGuardQueryName: (name: string) => boolean;
3
+ export declare const isValidGuardQueryIdOrName: (input: number | string) => boolean;
4
+ export declare const getGuardQueryByIdOrName: (input: number | string) => any;
5
+ export declare const GUARD_QUERY_NAMES: any;
@@ -0,0 +1,22 @@
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);
@@ -0,0 +1,59 @@
1
+ import { z } from 'zod';
2
+ import { NodeSchema } from '../call/machine.js';
3
+ import type { MachineNode } from '../query/index.js';
4
+ export interface NodeParseError {
5
+ message: string;
6
+ path: string;
7
+ line?: number;
8
+ column?: number;
9
+ start?: number;
10
+ end?: number;
11
+ }
12
+ export interface NodeParseResult {
13
+ success: boolean;
14
+ data?: z.infer<typeof NodeSchema>;
15
+ errors: NodeParseError[];
16
+ }
17
+ export interface MachineNodesParseResult {
18
+ success: boolean;
19
+ data?: MachineNode[];
20
+ errors: NodeParseError[];
21
+ }
22
+ export declare function parseNodeFromText(text: string): NodeParseResult;
23
+ export declare function parseMachineNodesFromText(text: string): MachineNodesParseResult;
24
+ export declare function formatNodeErrors(errors: NodeParseError[]): string;
25
+ export declare function validateMachineNode(node: unknown): {
26
+ success: boolean;
27
+ errors: NodeParseError[];
28
+ };
29
+ export declare function validateMachineNodePair(pair: unknown): {
30
+ success: boolean;
31
+ errors: NodeParseError[];
32
+ };
33
+ export declare function validateMachineForward(forward: unknown): {
34
+ success: boolean;
35
+ errors: NodeParseError[];
36
+ };
37
+ export interface MachineNodeFileOptions {
38
+ machineName?: string;
39
+ machineAddress?: string;
40
+ machineId?: string;
41
+ includeComments?: boolean;
42
+ }
43
+ /**
44
+ * 将 MachineNode 数组生成为 JSON 格式字符串
45
+ */
46
+ export declare function machineNodesToJson(nodes: MachineNode[], options?: MachineNodeFileOptions): string;
47
+ /**
48
+ * 将 MachineNode 数组生成为 Markdown 格式字符串
49
+ * 生成的格式与 parseMarkdownToNodeData 解析的格式匹配
50
+ */
51
+ 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
+ export declare function saveMachineNodesToFile(nodes: MachineNode[], filePath: string, format?: 'json' | 'markdown', options?: MachineNodeFileOptions): void;