@nocobase/plugin-ai 2.1.0-beta.16 → 2.1.0-beta.19

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 (66) hide show
  1. package/dist/ai/ai-employees/atlas/prompt.md +28 -22
  2. package/dist/ai/ai-employees/viz.js +14 -88
  3. package/dist/ai/skills/business-analysis-report/SKILLS.md +8 -3
  4. package/dist/ai/skills/business-analysis-report/tools/businessReportGenerator.js +49 -8
  5. package/dist/client/280.003b9e9788599244.js +10 -0
  6. package/dist/client/486.afbed6b132b3c0dd.js +10 -0
  7. package/dist/client/646.cba98d80e9e6ea74.js +10 -0
  8. package/dist/client/ai-employees/chatbox/conversations/WorkflowTasksList.d.ts +2 -0
  9. package/dist/client/ai-employees/chatbox/hooks/useWorkflowTasks.d.ts +3 -0
  10. package/dist/client/ai-employees/chatbox/stores/workflow-tasks.d.ts +4 -0
  11. package/dist/client/index.js +5 -5
  12. package/dist/client/workflow/nodes/employee/flow-models/feedback.d.ts +1 -0
  13. package/dist/common/recommended-models.js +1 -25
  14. package/dist/externalVersion.js +14 -14
  15. package/dist/locale/en-US.json +15 -1
  16. package/dist/locale/zh-CN.json +15 -2
  17. package/dist/node_modules/fast-glob/package.json +1 -1
  18. package/dist/node_modules/flexsearch/package.json +1 -1
  19. package/dist/node_modules/fs-extra/package.json +1 -1
  20. package/dist/node_modules/jsonrepair/bin/cli.js +179 -0
  21. package/dist/node_modules/jsonrepair/lib/cjs/index.js +1 -0
  22. package/dist/node_modules/jsonrepair/lib/cjs/package.json +3 -0
  23. package/dist/node_modules/jsonrepair/lib/cjs/regular/jsonrepair.js +746 -0
  24. package/dist/node_modules/jsonrepair/lib/cjs/stream.js +13 -0
  25. package/dist/node_modules/jsonrepair/lib/cjs/streaming/buffer/InputBuffer.js +75 -0
  26. package/dist/node_modules/jsonrepair/lib/cjs/streaming/buffer/OutputBuffer.js +117 -0
  27. package/dist/node_modules/jsonrepair/lib/cjs/streaming/core.js +824 -0
  28. package/dist/node_modules/jsonrepair/lib/cjs/streaming/stack.js +51 -0
  29. package/dist/node_modules/jsonrepair/lib/cjs/streaming/stream.js +37 -0
  30. package/dist/node_modules/jsonrepair/lib/cjs/utils/JSONRepairError.js +14 -0
  31. package/dist/node_modules/jsonrepair/lib/cjs/utils/stringUtils.js +174 -0
  32. package/dist/node_modules/jsonrepair/lib/esm/index.js +4 -0
  33. package/dist/node_modules/jsonrepair/lib/esm/regular/jsonrepair.js +740 -0
  34. package/dist/node_modules/jsonrepair/lib/esm/stream.js +3 -0
  35. package/dist/node_modules/jsonrepair/lib/esm/streaming/buffer/InputBuffer.js +69 -0
  36. package/dist/node_modules/jsonrepair/lib/esm/streaming/buffer/OutputBuffer.js +111 -0
  37. package/dist/node_modules/jsonrepair/lib/esm/streaming/core.js +818 -0
  38. package/dist/node_modules/jsonrepair/lib/esm/streaming/stack.js +44 -0
  39. package/dist/node_modules/jsonrepair/lib/esm/streaming/stream.js +31 -0
  40. package/dist/node_modules/jsonrepair/lib/esm/utils/JSONRepairError.js +7 -0
  41. package/dist/node_modules/jsonrepair/lib/esm/utils/stringUtils.js +147 -0
  42. package/dist/node_modules/jsonrepair/lib/types/index.d.ts +3 -0
  43. package/dist/node_modules/jsonrepair/lib/types/regular/jsonrepair.d.ts +18 -0
  44. package/dist/node_modules/jsonrepair/lib/types/stream.d.ts +2 -0
  45. package/dist/node_modules/jsonrepair/lib/types/streaming/buffer/InputBuffer.d.ts +14 -0
  46. package/dist/node_modules/jsonrepair/lib/types/streaming/buffer/OutputBuffer.d.ts +18 -0
  47. package/dist/node_modules/jsonrepair/lib/types/streaming/core.d.ts +11 -0
  48. package/dist/node_modules/jsonrepair/lib/types/streaming/stack.d.ts +20 -0
  49. package/dist/node_modules/jsonrepair/lib/types/streaming/stream.d.ts +7 -0
  50. package/dist/node_modules/jsonrepair/lib/types/utils/JSONRepairError.d.ts +5 -0
  51. package/dist/node_modules/jsonrepair/lib/types/utils/stringUtils.d.ts +65 -0
  52. package/dist/node_modules/jsonrepair/lib/umd/jsonrepair.js +903 -0
  53. package/dist/node_modules/jsonrepair/lib/umd/jsonrepair.min.js +3 -0
  54. package/dist/node_modules/jsonrepair/lib/umd/package.json +3 -0
  55. package/dist/node_modules/jsonrepair/package.json +1 -0
  56. package/dist/node_modules/nodejs-snowflake/package.json +1 -1
  57. package/dist/node_modules/openai/package.json +1 -1
  58. package/dist/node_modules/zod/package.json +1 -1
  59. package/dist/server/collections/ai-workflow-tasks.js +1 -1
  60. package/dist/server/resource/aiEmployees.js +15 -1
  61. package/dist/server/resource/aiSkills.js +1 -1
  62. package/dist/server/workflow/nodes/employee/index.js +13 -0
  63. package/package.json +2 -2
  64. package/dist/client/280.029428b83d62155f.js +0 -10
  65. package/dist/client/486.77c26e2e7f8daf28.js +0 -10
  66. package/dist/client/646.ef9d7c2ea8641044.js +0 -10
@@ -0,0 +1,824 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.jsonrepairCore = jsonrepairCore;
7
+ var _JSONRepairError = require("../utils/JSONRepairError.js");
8
+ var _stringUtils = require("../utils/stringUtils.js");
9
+ var _InputBuffer = require("./buffer/InputBuffer.js");
10
+ var _OutputBuffer = require("./buffer/OutputBuffer.js");
11
+ var _stack = require("./stack.js");
12
+ const controlCharacters = {
13
+ '\b': '\\b',
14
+ '\f': '\\f',
15
+ '\n': '\\n',
16
+ '\r': '\\r',
17
+ '\t': '\\t'
18
+ };
19
+
20
+ // map with all escape characters
21
+ const escapeCharacters = {
22
+ '"': '"',
23
+ '\\': '\\',
24
+ '/': '/',
25
+ b: '\b',
26
+ f: '\f',
27
+ n: '\n',
28
+ r: '\r',
29
+ t: '\t'
30
+ // note that \u is handled separately in parseString()
31
+ };
32
+ function jsonrepairCore(_ref) {
33
+ let {
34
+ onData,
35
+ bufferSize = 65536,
36
+ chunkSize = 65536
37
+ } = _ref;
38
+ const input = (0, _InputBuffer.createInputBuffer)();
39
+ const output = (0, _OutputBuffer.createOutputBuffer)({
40
+ write: onData,
41
+ bufferSize,
42
+ chunkSize
43
+ });
44
+ let i = 0;
45
+ let iFlushed = 0;
46
+ const stack = (0, _stack.createStack)();
47
+ function flushInputBuffer() {
48
+ while (iFlushed < i - bufferSize - chunkSize) {
49
+ iFlushed += chunkSize;
50
+ input.flush(iFlushed);
51
+ }
52
+ }
53
+ function transform(chunk) {
54
+ input.push(chunk);
55
+ while (i < input.currentLength() - bufferSize && parse()) {
56
+ // loop until there is nothing more to process
57
+ }
58
+ flushInputBuffer();
59
+ }
60
+ function flush() {
61
+ input.close();
62
+ while (parse()) {
63
+ // loop until there is nothing more to process
64
+ }
65
+ output.flush();
66
+ }
67
+ function parse() {
68
+ parseWhitespaceAndSkipComments();
69
+ switch (stack.type) {
70
+ case _stack.StackType.object:
71
+ {
72
+ switch (stack.caret) {
73
+ case _stack.Caret.beforeKey:
74
+ return skipEllipsis() || parseObjectKey() || parseUnexpectedColon() || parseRepairTrailingComma() || parseRepairObjectEndOrComma();
75
+ case _stack.Caret.beforeValue:
76
+ return parseValue() || parseRepairMissingObjectValue();
77
+ case _stack.Caret.afterValue:
78
+ return parseObjectComma() || parseObjectEnd() || parseRepairObjectEndOrComma();
79
+ default:
80
+ return false;
81
+ }
82
+ }
83
+ case _stack.StackType.array:
84
+ {
85
+ switch (stack.caret) {
86
+ case _stack.Caret.beforeValue:
87
+ return skipEllipsis() || parseValue() || parseRepairTrailingComma() || parseRepairArrayEnd();
88
+ case _stack.Caret.afterValue:
89
+ return parseArrayComma() || parseArrayEnd() || parseRepairMissingComma() || parseRepairArrayEnd();
90
+ default:
91
+ return false;
92
+ }
93
+ }
94
+ case _stack.StackType.ndJson:
95
+ {
96
+ switch (stack.caret) {
97
+ case _stack.Caret.beforeValue:
98
+ return parseValue() || parseRepairTrailingComma();
99
+ case _stack.Caret.afterValue:
100
+ return parseArrayComma() || parseRepairMissingComma() || parseRepairNdJsonEnd();
101
+ default:
102
+ return false;
103
+ }
104
+ }
105
+ case _stack.StackType.functionCall:
106
+ {
107
+ switch (stack.caret) {
108
+ case _stack.Caret.beforeValue:
109
+ return parseValue();
110
+ case _stack.Caret.afterValue:
111
+ return parseFunctionCallEnd();
112
+ default:
113
+ return false;
114
+ }
115
+ }
116
+ case _stack.StackType.root:
117
+ {
118
+ switch (stack.caret) {
119
+ case _stack.Caret.beforeValue:
120
+ return parseRootStart();
121
+ case _stack.Caret.afterValue:
122
+ return parseRootEnd();
123
+ default:
124
+ return false;
125
+ }
126
+ }
127
+ default:
128
+ return false;
129
+ }
130
+ }
131
+ function parseValue() {
132
+ return parseObjectStart() || parseArrayStart() || parseString() || parseNumber() || parseKeywords() || parseRepairUnquotedString() || parseRepairRegex();
133
+ }
134
+ function parseObjectStart() {
135
+ if (parseCharacter('{')) {
136
+ parseWhitespaceAndSkipComments();
137
+ skipEllipsis();
138
+ if (skipCharacter(',')) {
139
+ parseWhitespaceAndSkipComments();
140
+ }
141
+ if (parseCharacter('}')) {
142
+ return stack.update(_stack.Caret.afterValue);
143
+ }
144
+ return stack.push(_stack.StackType.object, _stack.Caret.beforeKey);
145
+ }
146
+ return false;
147
+ }
148
+ function parseArrayStart() {
149
+ if (parseCharacter('[')) {
150
+ parseWhitespaceAndSkipComments();
151
+ skipEllipsis();
152
+ if (skipCharacter(',')) {
153
+ parseWhitespaceAndSkipComments();
154
+ }
155
+ if (parseCharacter(']')) {
156
+ return stack.update(_stack.Caret.afterValue);
157
+ }
158
+ return stack.push(_stack.StackType.array, _stack.Caret.beforeValue);
159
+ }
160
+ return false;
161
+ }
162
+ function parseRepairUnquotedString() {
163
+ let j = i;
164
+ if ((0, _stringUtils.isFunctionNameCharStart)(input.charAt(j))) {
165
+ while (!input.isEnd(j) && (0, _stringUtils.isFunctionNameChar)(input.charAt(j))) {
166
+ j++;
167
+ }
168
+ let k = j;
169
+ while ((0, _stringUtils.isWhitespace)(input, k)) {
170
+ k++;
171
+ }
172
+ if (input.charAt(k) === '(') {
173
+ // repair a MongoDB function call like NumberLong("2")
174
+ // repair a JSONP function call like callback({...});
175
+ k++;
176
+ i = k;
177
+ return stack.push(_stack.StackType.functionCall, _stack.Caret.beforeValue);
178
+ }
179
+ }
180
+ j = findNextDelimiter(false, j);
181
+ if (j !== null) {
182
+ // test start of an url like "https://..." (this would be parsed as a comment)
183
+ if (input.charAt(j - 1) === ':' && _stringUtils.regexUrlStart.test(input.substring(i, j + 2))) {
184
+ while (!input.isEnd(j) && _stringUtils.regexUrlChar.test(input.charAt(j))) {
185
+ j++;
186
+ }
187
+ }
188
+ const symbol = input.substring(i, j);
189
+ i = j;
190
+ output.push(symbol === 'undefined' ? 'null' : JSON.stringify(symbol));
191
+ if (input.charAt(i) === '"') {
192
+ // we had a missing start quote, but now we encountered the end quote, so we can skip that one
193
+ i++;
194
+ }
195
+ return stack.update(_stack.Caret.afterValue);
196
+ }
197
+ return false;
198
+ }
199
+ function parseRepairRegex() {
200
+ if (input.charAt(i) === '/') {
201
+ const start = i;
202
+ i++;
203
+ while (!input.isEnd(i) && (input.charAt(i) !== '/' || input.charAt(i - 1) === '\\')) {
204
+ i++;
205
+ }
206
+ i++;
207
+ output.push(`"${input.substring(start, i)}"`);
208
+ return stack.update(_stack.Caret.afterValue);
209
+ }
210
+ }
211
+ function parseRepairMissingObjectValue() {
212
+ // repair missing object value
213
+ output.push('null');
214
+ return stack.update(_stack.Caret.afterValue);
215
+ }
216
+ function parseRepairTrailingComma() {
217
+ // repair trailing comma
218
+ if (output.endsWithIgnoringWhitespace(',')) {
219
+ output.stripLastOccurrence(',');
220
+ return stack.update(_stack.Caret.afterValue);
221
+ }
222
+ return false;
223
+ }
224
+ function parseUnexpectedColon() {
225
+ if (input.charAt(i) === ':') {
226
+ throwObjectKeyExpected();
227
+ }
228
+ return false;
229
+ }
230
+ function parseUnexpectedEnd() {
231
+ if (input.isEnd(i)) {
232
+ throwUnexpectedEnd();
233
+ } else {
234
+ throwUnexpectedCharacter();
235
+ }
236
+ return false;
237
+ }
238
+ function parseObjectKey() {
239
+ const parsedKey = parseString() || parseUnquotedKey();
240
+ if (parsedKey) {
241
+ parseWhitespaceAndSkipComments();
242
+ if (parseCharacter(':')) {
243
+ // expect a value after the :
244
+ return stack.update(_stack.Caret.beforeValue);
245
+ }
246
+ const truncatedText = input.isEnd(i);
247
+ if ((0, _stringUtils.isStartOfValue)(input.charAt(i)) || truncatedText) {
248
+ // repair missing colon
249
+ output.insertBeforeLastWhitespace(':');
250
+ return stack.update(_stack.Caret.beforeValue);
251
+ }
252
+ throwColonExpected();
253
+ }
254
+ return false;
255
+ }
256
+ function parseObjectComma() {
257
+ if (parseCharacter(',')) {
258
+ return stack.update(_stack.Caret.beforeKey);
259
+ }
260
+ return false;
261
+ }
262
+ function parseObjectEnd() {
263
+ if (parseCharacter('}')) {
264
+ return stack.pop();
265
+ }
266
+ return false;
267
+ }
268
+ function parseRepairObjectEndOrComma() {
269
+ // repair missing object end and trailing comma
270
+ if (input.charAt(i) === '{') {
271
+ output.stripLastOccurrence(',');
272
+ output.insertBeforeLastWhitespace('}');
273
+ return stack.pop();
274
+ }
275
+
276
+ // repair missing comma
277
+ if (!input.isEnd(i) && (0, _stringUtils.isStartOfValue)(input.charAt(i))) {
278
+ output.insertBeforeLastWhitespace(',');
279
+ return stack.update(_stack.Caret.beforeKey);
280
+ }
281
+
282
+ // repair missing closing brace
283
+ output.insertBeforeLastWhitespace('}');
284
+ return stack.pop();
285
+ }
286
+ function parseArrayComma() {
287
+ if (parseCharacter(',')) {
288
+ return stack.update(_stack.Caret.beforeValue);
289
+ }
290
+ return false;
291
+ }
292
+ function parseArrayEnd() {
293
+ if (parseCharacter(']')) {
294
+ return stack.pop();
295
+ }
296
+ return false;
297
+ }
298
+ function parseRepairMissingComma() {
299
+ // repair missing comma
300
+ if (!input.isEnd(i) && (0, _stringUtils.isStartOfValue)(input.charAt(i))) {
301
+ output.insertBeforeLastWhitespace(',');
302
+ return stack.update(_stack.Caret.beforeValue);
303
+ }
304
+ return false;
305
+ }
306
+ function parseRepairArrayEnd() {
307
+ // repair missing closing bracket
308
+ output.insertBeforeLastWhitespace(']');
309
+ return stack.pop();
310
+ }
311
+ function parseRepairNdJsonEnd() {
312
+ if (input.isEnd(i)) {
313
+ output.push('\n]');
314
+ return stack.pop();
315
+ }
316
+ throwUnexpectedEnd();
317
+ return false; // just to make TS happy
318
+ }
319
+ function parseFunctionCallEnd() {
320
+ if (skipCharacter(')')) {
321
+ skipCharacter(';');
322
+ }
323
+ return stack.pop();
324
+ }
325
+ function parseRootStart() {
326
+ parseMarkdownCodeBlock(['```', '[```', '{```']);
327
+ return parseValue() || parseUnexpectedEnd();
328
+ }
329
+ function parseRootEnd() {
330
+ parseMarkdownCodeBlock(['```', '```]', '```}']);
331
+ const parsedComma = parseCharacter(',');
332
+ parseWhitespaceAndSkipComments();
333
+ if ((0, _stringUtils.isStartOfValue)(input.charAt(i)) && (output.endsWithIgnoringWhitespace(',') || output.endsWithIgnoringWhitespace('\n'))) {
334
+ // start of a new value after end of the root level object: looks like
335
+ // newline delimited JSON -> turn into a root level array
336
+ if (!parsedComma) {
337
+ // repair missing comma
338
+ output.insertBeforeLastWhitespace(',');
339
+ }
340
+ output.unshift('[\n');
341
+ return stack.push(_stack.StackType.ndJson, _stack.Caret.beforeValue);
342
+ }
343
+ if (parsedComma) {
344
+ // repair: remove trailing comma
345
+ output.stripLastOccurrence(',');
346
+ return stack.update(_stack.Caret.afterValue);
347
+ }
348
+
349
+ // repair redundant end braces and brackets
350
+ while (input.charAt(i) === '}' || input.charAt(i) === ']') {
351
+ i++;
352
+ parseWhitespaceAndSkipComments();
353
+ }
354
+ if (!input.isEnd(i)) {
355
+ throwUnexpectedCharacter();
356
+ }
357
+ return false;
358
+ }
359
+ function parseWhitespaceAndSkipComments() {
360
+ let skipNewline = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
361
+ const start = i;
362
+ let changed = parseWhitespace(skipNewline);
363
+ do {
364
+ changed = parseComment();
365
+ if (changed) {
366
+ changed = parseWhitespace(skipNewline);
367
+ }
368
+ } while (changed);
369
+ return i > start;
370
+ }
371
+ function parseWhitespace(skipNewline) {
372
+ const _isWhiteSpace = skipNewline ? _stringUtils.isWhitespace : _stringUtils.isWhitespaceExceptNewline;
373
+ let whitespace = '';
374
+ while (true) {
375
+ if (_isWhiteSpace(input, i)) {
376
+ whitespace += input.charAt(i);
377
+ i++;
378
+ } else if ((0, _stringUtils.isSpecialWhitespace)(input, i)) {
379
+ // repair special whitespace
380
+ whitespace += ' ';
381
+ i++;
382
+ } else {
383
+ break;
384
+ }
385
+ }
386
+ if (whitespace.length > 0) {
387
+ output.push(whitespace);
388
+ return true;
389
+ }
390
+ return false;
391
+ }
392
+ function parseComment() {
393
+ // find a block comment '/* ... */'
394
+ if (input.charAt(i) === '/' && input.charAt(i + 1) === '*') {
395
+ // repair block comment by skipping it
396
+ while (!input.isEnd(i) && !atEndOfBlockComment(i)) {
397
+ i++;
398
+ }
399
+ i += 2;
400
+ return true;
401
+ }
402
+
403
+ // find a line comment '// ...'
404
+ if (input.charAt(i) === '/' && input.charAt(i + 1) === '/') {
405
+ // repair line comment by skipping it
406
+ while (!input.isEnd(i) && input.charAt(i) !== '\n') {
407
+ i++;
408
+ }
409
+ return true;
410
+ }
411
+ return false;
412
+ }
413
+ function parseMarkdownCodeBlock(blocks) {
414
+ // find and skip over a Markdown fenced code block:
415
+ // ``` ... ```
416
+ // or
417
+ // ```json ... ```
418
+ if (skipMarkdownCodeBlock(blocks)) {
419
+ if ((0, _stringUtils.isFunctionNameCharStart)(input.charAt(i))) {
420
+ // strip the optional language specifier like "json"
421
+ while (!input.isEnd(i) && (0, _stringUtils.isFunctionNameChar)(input.charAt(i))) {
422
+ i++;
423
+ }
424
+ }
425
+ parseWhitespaceAndSkipComments();
426
+ return true;
427
+ }
428
+ return false;
429
+ }
430
+ function skipMarkdownCodeBlock(blocks) {
431
+ for (const block of blocks) {
432
+ const end = i + block.length;
433
+ if (input.substring(i, end) === block) {
434
+ i = end;
435
+ return true;
436
+ }
437
+ }
438
+ return false;
439
+ }
440
+ function parseCharacter(char) {
441
+ if (input.charAt(i) === char) {
442
+ output.push(input.charAt(i));
443
+ i++;
444
+ return true;
445
+ }
446
+ return false;
447
+ }
448
+ function skipCharacter(char) {
449
+ if (input.charAt(i) === char) {
450
+ i++;
451
+ return true;
452
+ }
453
+ return false;
454
+ }
455
+ function skipEscapeCharacter() {
456
+ return skipCharacter('\\');
457
+ }
458
+
459
+ /**
460
+ * Skip ellipsis like "[1,2,3,...]" or "[1,2,3,...,9]" or "[...,7,8,9]"
461
+ * or a similar construct in objects.
462
+ */
463
+ function skipEllipsis() {
464
+ parseWhitespaceAndSkipComments();
465
+ if (input.charAt(i) === '.' && input.charAt(i + 1) === '.' && input.charAt(i + 2) === '.') {
466
+ // repair: remove the ellipsis (three dots) and optionally a comma
467
+ i += 3;
468
+ parseWhitespaceAndSkipComments();
469
+ skipCharacter(',');
470
+ return true;
471
+ }
472
+ return false;
473
+ }
474
+
475
+ /**
476
+ * Parse a string enclosed by double quotes "...". Can contain escaped quotes
477
+ * Repair strings enclosed in single quotes or special quotes
478
+ * Repair an escaped string
479
+ *
480
+ * The function can run in two stages:
481
+ * - First, it assumes the string has a valid end quote
482
+ * - If it turns out that the string does not have a valid end quote followed
483
+ * by a delimiter (which should be the case), the function runs again in a
484
+ * more conservative way, stopping the string at the first next delimiter
485
+ * and fixing the string by inserting a quote there, or stopping at a
486
+ * stop index detected in the first iteration.
487
+ */
488
+ function parseString() {
489
+ let stopAtDelimiter = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
490
+ let stopAtIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : -1;
491
+ let skipEscapeChars = input.charAt(i) === '\\';
492
+ if (skipEscapeChars) {
493
+ // repair: remove the first escape character
494
+ i++;
495
+ skipEscapeChars = true;
496
+ }
497
+ if ((0, _stringUtils.isQuote)(input.charAt(i))) {
498
+ // double quotes are correct JSON,
499
+ // single quotes come from JavaScript for example, we assume it will have a correct single end quote too
500
+ // otherwise, we will match any double-quote-like start with a double-quote-like end,
501
+ // or any single-quote-like start with a single-quote-like end
502
+ const isEndQuote = (0, _stringUtils.isDoubleQuote)(input.charAt(i)) ? _stringUtils.isDoubleQuote : (0, _stringUtils.isSingleQuote)(input.charAt(i)) ? _stringUtils.isSingleQuote : (0, _stringUtils.isSingleQuoteLike)(input.charAt(i)) ? _stringUtils.isSingleQuoteLike : _stringUtils.isDoubleQuoteLike;
503
+ const iBefore = i;
504
+ const oBefore = output.length();
505
+ output.push('"');
506
+ i++;
507
+ while (true) {
508
+ if (input.isEnd(i)) {
509
+ // end of text, we have a missing quote somewhere
510
+
511
+ const iPrev = prevNonWhitespaceIndex(i - 1);
512
+ if (!stopAtDelimiter && (0, _stringUtils.isDelimiter)(input.charAt(iPrev))) {
513
+ // if the text ends with a delimiter, like ["hello],
514
+ // so the missing end quote should be inserted before this delimiter
515
+ // retry parsing the string, stopping at the first next delimiter
516
+ i = iBefore;
517
+ output.remove(oBefore);
518
+ return parseString(true);
519
+ }
520
+
521
+ // repair missing quote
522
+ output.insertBeforeLastWhitespace('"');
523
+ return stack.update(_stack.Caret.afterValue);
524
+ }
525
+ if (i === stopAtIndex) {
526
+ // use the stop index detected in the first iteration, and repair end quote
527
+ output.insertBeforeLastWhitespace('"');
528
+ return stack.update(_stack.Caret.afterValue);
529
+ }
530
+ if (isEndQuote(input.charAt(i))) {
531
+ // end quote
532
+ // let us check what is before and after the quote to verify whether this is a legit end quote
533
+ const iQuote = i;
534
+ const oQuote = output.length();
535
+ output.push('"');
536
+ i++;
537
+ parseWhitespaceAndSkipComments(false);
538
+ if (stopAtDelimiter || input.isEnd(i) || (0, _stringUtils.isDelimiter)(input.charAt(i)) || (0, _stringUtils.isQuote)(input.charAt(i)) || (0, _stringUtils.isDigit)(input.charAt(i))) {
539
+ // The quote is followed by the end of the text, a delimiter, or a next value
540
+ // so the quote is indeed the end of the string
541
+ parseConcatenatedString();
542
+ return stack.update(_stack.Caret.afterValue);
543
+ }
544
+ const iPrevChar = prevNonWhitespaceIndex(iQuote - 1);
545
+ const prevChar = input.charAt(iPrevChar);
546
+ if (prevChar === ',') {
547
+ // A comma followed by a quote, like '{"a":"b,c,"d":"e"}'.
548
+ // We assume that the quote is a start quote, and that the end quote
549
+ // should have been located right before the comma but is missing.
550
+ i = iBefore;
551
+ output.remove(oBefore);
552
+ return parseString(false, iPrevChar);
553
+ }
554
+ if ((0, _stringUtils.isDelimiter)(prevChar)) {
555
+ // This is not the right end quote: it is preceded by a delimiter,
556
+ // and NOT followed by a delimiter. So, there is an end quote missing
557
+ // parse the string again and then stop at the first next delimiter
558
+ i = iBefore;
559
+ output.remove(oBefore);
560
+ return parseString(true);
561
+ }
562
+
563
+ // revert to right after the quote but before any whitespace, and continue parsing the string
564
+ output.remove(oQuote + 1);
565
+ i = iQuote + 1;
566
+
567
+ // repair unescaped quote
568
+ output.insertAt(oQuote, '\\');
569
+ } else if (stopAtDelimiter && (0, _stringUtils.isUnquotedStringDelimiter)(input.charAt(i))) {
570
+ // we're in the mode to stop the string at the first delimiter
571
+ // because there is an end quote missing
572
+
573
+ // test start of an url like "https://..." (this would be parsed as a comment)
574
+ if (input.charAt(i - 1) === ':' && _stringUtils.regexUrlStart.test(input.substring(iBefore + 1, i + 2))) {
575
+ while (!input.isEnd(i) && _stringUtils.regexUrlChar.test(input.charAt(i))) {
576
+ output.push(input.charAt(i));
577
+ i++;
578
+ }
579
+ }
580
+
581
+ // repair missing quote
582
+ output.insertBeforeLastWhitespace('"');
583
+ parseConcatenatedString();
584
+ return stack.update(_stack.Caret.afterValue);
585
+ } else if (input.charAt(i) === '\\') {
586
+ // handle escaped content like \n or \u2605
587
+ const char = input.charAt(i + 1);
588
+ const escapeChar = escapeCharacters[char];
589
+ if (escapeChar !== undefined) {
590
+ output.push(input.substring(i, i + 2));
591
+ i += 2;
592
+ } else if (char === 'u') {
593
+ let j = 2;
594
+ while (j < 6 && (0, _stringUtils.isHex)(input.charAt(i + j))) {
595
+ j++;
596
+ }
597
+ if (j === 6) {
598
+ output.push(input.substring(i, i + 6));
599
+ i += 6;
600
+ } else if (input.isEnd(i + j)) {
601
+ // repair invalid or truncated unicode char at the end of the text
602
+ // by removing the unicode char and ending the string here
603
+ i += j;
604
+ } else {
605
+ throwInvalidUnicodeCharacter();
606
+ }
607
+ } else {
608
+ // repair invalid escape character: remove it
609
+ output.push(char);
610
+ i += 2;
611
+ }
612
+ } else {
613
+ // handle regular characters
614
+ const char = input.charAt(i);
615
+ if (char === '"' && input.charAt(i - 1) !== '\\') {
616
+ // repair unescaped double quote
617
+ output.push(`\\${char}`);
618
+ i++;
619
+ } else if ((0, _stringUtils.isControlCharacter)(char)) {
620
+ // unescaped control character
621
+ output.push(controlCharacters[char]);
622
+ i++;
623
+ } else {
624
+ if (!(0, _stringUtils.isValidStringCharacter)(char)) {
625
+ throwInvalidCharacter(char);
626
+ }
627
+ output.push(char);
628
+ i++;
629
+ }
630
+ }
631
+ if (skipEscapeChars) {
632
+ // repair: skipped escape character (nothing to do)
633
+ skipEscapeCharacter();
634
+ }
635
+ }
636
+ }
637
+ return false;
638
+ }
639
+
640
+ /**
641
+ * Repair concatenated strings like "hello" + "world", change this into "helloworld"
642
+ */
643
+ function parseConcatenatedString() {
644
+ let parsed = false;
645
+ parseWhitespaceAndSkipComments();
646
+ while (input.charAt(i) === '+') {
647
+ parsed = true;
648
+ i++;
649
+ parseWhitespaceAndSkipComments();
650
+
651
+ // repair: remove the end quote of the first string
652
+ output.stripLastOccurrence('"', true);
653
+ const start = output.length();
654
+ const parsedStr = parseString();
655
+ if (parsedStr) {
656
+ // repair: remove the start quote of the second string
657
+ output.remove(start, start + 1);
658
+ } else {
659
+ // repair: remove the + because it is not followed by a string
660
+ output.insertBeforeLastWhitespace('"');
661
+ }
662
+ }
663
+ return parsed;
664
+ }
665
+
666
+ /**
667
+ * Parse a number like 2.4 or 2.4e6
668
+ */
669
+ function parseNumber() {
670
+ const start = i;
671
+ if (input.charAt(i) === '-') {
672
+ i++;
673
+ if (atEndOfNumber()) {
674
+ repairNumberEndingWithNumericSymbol(start);
675
+ return stack.update(_stack.Caret.afterValue);
676
+ }
677
+ if (!(0, _stringUtils.isDigit)(input.charAt(i))) {
678
+ i = start;
679
+ return false;
680
+ }
681
+ }
682
+
683
+ // Note that in JSON leading zeros like "00789" are not allowed.
684
+ // We will allow all leading zeros here though and at the end of parseNumber
685
+ // check against trailing zeros and repair that if needed.
686
+ // Leading zeros can have meaning, so we should not clear them.
687
+ while ((0, _stringUtils.isDigit)(input.charAt(i))) {
688
+ i++;
689
+ }
690
+ if (input.charAt(i) === '.') {
691
+ i++;
692
+ if (atEndOfNumber()) {
693
+ repairNumberEndingWithNumericSymbol(start);
694
+ return stack.update(_stack.Caret.afterValue);
695
+ }
696
+ if (!(0, _stringUtils.isDigit)(input.charAt(i))) {
697
+ i = start;
698
+ return false;
699
+ }
700
+ while ((0, _stringUtils.isDigit)(input.charAt(i))) {
701
+ i++;
702
+ }
703
+ }
704
+ if (input.charAt(i) === 'e' || input.charAt(i) === 'E') {
705
+ i++;
706
+ if (input.charAt(i) === '-' || input.charAt(i) === '+') {
707
+ i++;
708
+ }
709
+ if (atEndOfNumber()) {
710
+ repairNumberEndingWithNumericSymbol(start);
711
+ return stack.update(_stack.Caret.afterValue);
712
+ }
713
+ if (!(0, _stringUtils.isDigit)(input.charAt(i))) {
714
+ i = start;
715
+ return false;
716
+ }
717
+ while ((0, _stringUtils.isDigit)(input.charAt(i))) {
718
+ i++;
719
+ }
720
+ }
721
+
722
+ // if we're not at the end of the number by this point, allow this to be parsed as another type
723
+ if (!atEndOfNumber()) {
724
+ i = start;
725
+ return false;
726
+ }
727
+ if (i > start) {
728
+ // repair a number with leading zeros like "00789"
729
+ const num = input.substring(start, i);
730
+ const hasInvalidLeadingZero = /^0\d/.test(num);
731
+ output.push(hasInvalidLeadingZero ? `"${num}"` : num);
732
+ return stack.update(_stack.Caret.afterValue);
733
+ }
734
+ return false;
735
+ }
736
+
737
+ /**
738
+ * Parse keywords true, false, null
739
+ * Repair Python keywords True, False, None
740
+ */
741
+ function parseKeywords() {
742
+ return parseKeyword('true', 'true') || parseKeyword('false', 'false') || parseKeyword('null', 'null') ||
743
+ // repair Python keywords True, False, None
744
+ parseKeyword('True', 'true') || parseKeyword('False', 'false') || parseKeyword('None', 'null');
745
+ }
746
+ function parseKeyword(name, value) {
747
+ if (input.substring(i, i + name.length) === name) {
748
+ output.push(value);
749
+ i += name.length;
750
+ return stack.update(_stack.Caret.afterValue);
751
+ }
752
+ return false;
753
+ }
754
+ function parseUnquotedKey() {
755
+ let end = findNextDelimiter(true, i);
756
+ if (end !== null) {
757
+ // first, go back to prevent getting trailing whitespaces in the string
758
+ while ((0, _stringUtils.isWhitespace)(input, end - 1) && end > i) {
759
+ end--;
760
+ }
761
+ const symbol = input.substring(i, end);
762
+ output.push(JSON.stringify(symbol));
763
+ i = end;
764
+ if (input.charAt(i) === '"') {
765
+ // we had a missing start quote, but now we encountered the end quote, so we can skip that one
766
+ i++;
767
+ }
768
+ return stack.update(_stack.Caret.afterValue); // we do not have a state Caret.afterKey, therefore we use afterValue here
769
+ }
770
+ return false;
771
+ }
772
+ function findNextDelimiter(isKey, start) {
773
+ // note that the symbol can end with whitespaces: we stop at the next delimiter
774
+ // also, note that we allow strings to contain a slash / in order to support repairing regular expressions
775
+ let j = start;
776
+ while (!input.isEnd(j) && !(0, _stringUtils.isUnquotedStringDelimiter)(input.charAt(j)) && !(0, _stringUtils.isQuote)(input.charAt(j)) && (!isKey || input.charAt(j) !== ':')) {
777
+ j++;
778
+ }
779
+ return j > i ? j : null;
780
+ }
781
+ function prevNonWhitespaceIndex(start) {
782
+ let prev = start;
783
+ while (prev > 0 && (0, _stringUtils.isWhitespace)(input, prev)) {
784
+ prev--;
785
+ }
786
+ return prev;
787
+ }
788
+ function atEndOfNumber() {
789
+ return input.isEnd(i) || (0, _stringUtils.isDelimiter)(input.charAt(i)) || (0, _stringUtils.isWhitespace)(input, i);
790
+ }
791
+ function repairNumberEndingWithNumericSymbol(start) {
792
+ // repair numbers cut off at the end
793
+ // this will only be called when we end after a '.', '-', or 'e' and does not
794
+ // change the number more than it needs to make it valid JSON
795
+ output.push(`${input.substring(start, i)}0`);
796
+ }
797
+ function throwInvalidCharacter(char) {
798
+ throw new _JSONRepairError.JSONRepairError(`Invalid character ${JSON.stringify(char)}`, i);
799
+ }
800
+ function throwUnexpectedCharacter() {
801
+ throw new _JSONRepairError.JSONRepairError(`Unexpected character ${JSON.stringify(input.charAt(i))}`, i);
802
+ }
803
+ function throwUnexpectedEnd() {
804
+ throw new _JSONRepairError.JSONRepairError('Unexpected end of json string', i);
805
+ }
806
+ function throwObjectKeyExpected() {
807
+ throw new _JSONRepairError.JSONRepairError('Object key expected', i);
808
+ }
809
+ function throwColonExpected() {
810
+ throw new _JSONRepairError.JSONRepairError('Colon expected', i);
811
+ }
812
+ function throwInvalidUnicodeCharacter() {
813
+ const chars = input.substring(i, i + 6);
814
+ throw new _JSONRepairError.JSONRepairError(`Invalid unicode character "${chars}"`, i);
815
+ }
816
+ function atEndOfBlockComment(i) {
817
+ return input.charAt(i) === '*' && input.charAt(i + 1) === '/';
818
+ }
819
+ return {
820
+ transform,
821
+ flush
822
+ };
823
+ }
824
+ //# sourceMappingURL=core.js.map