@botpress/zai 1.0.1-beta.5 → 1.0.1-beta.7

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 (72) hide show
  1. package/dist/{node/adapters → adapters}/botpress-table.js +3 -4
  2. package/dist/index.js +9 -1743
  3. package/dist/{node/operations → operations}/check.js +1 -2
  4. package/dist/{node/operations → operations}/extract.js +1 -2
  5. package/dist/{node/operations → operations}/filter.js +3 -5
  6. package/dist/{node/operations → operations}/label.js +4 -8
  7. package/dist/{node/operations → operations}/rewrite.js +1 -2
  8. package/dist/{node/operations → operations}/summarize.js +1 -2
  9. package/dist/{node/operations → operations}/text.js +1 -2
  10. package/dist/{node/zai.js → zai.js} +2 -3
  11. package/package.json +5 -8
  12. package/dist/browser/index.js +0 -4068
  13. package/dist/node/adapters/adapter.d.js +0 -0
  14. package/dist/node/adapters/botpress-table.d.js +0 -1
  15. package/dist/node/adapters/memory.d.js +0 -0
  16. package/dist/node/index.d.js +0 -9
  17. package/dist/node/index.js +0 -9
  18. package/dist/node/models.d.js +0 -0
  19. package/dist/node/operations/check.d.js +0 -1
  20. package/dist/node/operations/check.test.d.js +0 -1
  21. package/dist/node/operations/constants.d.js +0 -0
  22. package/dist/node/operations/errors.d.js +0 -0
  23. package/dist/node/operations/extract.d.js +0 -1
  24. package/dist/node/operations/extract.test.d.js +0 -1
  25. package/dist/node/operations/filter.d.js +0 -1
  26. package/dist/node/operations/filter.test.d.js +0 -1
  27. package/dist/node/operations/label.d.js +0 -1
  28. package/dist/node/operations/label.test.d.js +0 -1
  29. package/dist/node/operations/rewrite.d.js +0 -1
  30. package/dist/node/operations/rewrite.test.d.js +0 -1
  31. package/dist/node/operations/summarize.d.js +0 -1
  32. package/dist/node/operations/summarize.test.d.js +0 -1
  33. package/dist/node/operations/text.d.js +0 -1
  34. package/dist/node/operations/text.test.d.js +0 -1
  35. package/dist/node/operations/zai-learn.test.d.js +0 -1
  36. package/dist/node/operations/zai-retry.test.d.js +0 -1
  37. package/dist/node/utils.d.js +0 -0
  38. package/dist/node/zai.d.js +0 -1
  39. package/src/adapters/adapter.d.ts +0 -27
  40. package/src/adapters/botpress-table.d.ts +0 -153
  41. package/src/adapters/memory.d.ts +0 -7
  42. package/src/index.d.ts +0 -9
  43. package/src/models.d.ts +0 -351
  44. package/src/operations/__tests/index.d.ts +0 -20
  45. package/src/operations/check.d.ts +0 -36
  46. package/src/operations/check.test.d.ts +0 -1
  47. package/src/operations/constants.d.ts +0 -2
  48. package/src/operations/errors.d.ts +0 -5
  49. package/src/operations/extract.d.ts +0 -20
  50. package/src/operations/extract.test.d.ts +0 -1
  51. package/src/operations/filter.d.ts +0 -39
  52. package/src/operations/filter.test.d.ts +0 -1
  53. package/src/operations/label.d.ts +0 -79
  54. package/src/operations/label.test.d.ts +0 -1
  55. package/src/operations/rewrite.d.ts +0 -34
  56. package/src/operations/rewrite.test.d.ts +0 -1
  57. package/src/operations/summarize.d.ts +0 -46
  58. package/src/operations/summarize.test.d.ts +0 -1
  59. package/src/operations/text.d.ts +0 -16
  60. package/src/operations/text.test.d.ts +0 -1
  61. package/src/operations/zai-learn.test.d.ts +0 -1
  62. package/src/operations/zai-retry.test.d.ts +0 -1
  63. package/src/sdk-interfaces/llm/generateContent.d.ts +0 -128
  64. package/src/sdk-interfaces/llm/listLanguageModels.d.ts +0 -25
  65. package/src/utils.d.ts +0 -52
  66. package/src/zai.d.ts +0 -99
  67. /package/dist/{node/adapters → adapters}/adapter.js +0 -0
  68. /package/dist/{node/adapters → adapters}/memory.js +0 -0
  69. /package/dist/{node/models.js → models.js} +0 -0
  70. /package/dist/{node/operations → operations}/constants.js +0 -0
  71. /package/dist/{node/operations → operations}/errors.js +0 -0
  72. /package/dist/{node/utils.js → utils.js} +0 -0
@@ -1,4068 +0,0 @@
1
- (() => {
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __defProps = Object.defineProperties;
5
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7
- var __getOwnPropNames = Object.getOwnPropertyNames;
8
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
- var __getProtoOf = Object.getPrototypeOf;
10
- var __hasOwnProp = Object.prototype.hasOwnProperty;
11
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
12
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13
- var __spreadValues = (a, b) => {
14
- for (var prop in b || (b = {}))
15
- if (__hasOwnProp.call(b, prop))
16
- __defNormalProp(a, prop, b[prop]);
17
- if (__getOwnPropSymbols)
18
- for (var prop of __getOwnPropSymbols(b)) {
19
- if (__propIsEnum.call(b, prop))
20
- __defNormalProp(a, prop, b[prop]);
21
- }
22
- return a;
23
- };
24
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
25
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
26
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
27
- }) : x)(function(x) {
28
- if (typeof require !== "undefined") return require.apply(this, arguments);
29
- throw Error('Dynamic require of "' + x + '" is not supported');
30
- });
31
- var __commonJS = (cb, mod) => function __require2() {
32
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
33
- };
34
- var __copyProps = (to, from, except, desc) => {
35
- if (from && typeof from === "object" || typeof from === "function") {
36
- for (let key of __getOwnPropNames(from))
37
- if (!__hasOwnProp.call(to, key) && key !== except)
38
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
39
- }
40
- return to;
41
- };
42
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
43
- // If the importer is in node compatibility mode or this is not an ESM
44
- // file that has been converted to a CommonJS file using a Babel-
45
- // compatible transform (i.e. "__esModule" has not been set), then set
46
- // "default" to the CommonJS "module.exports" for node compatibility.
47
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
48
- mod
49
- ));
50
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
51
-
52
- // node_modules/.pnpm/json5@2.2.3/node_modules/json5/dist/index.js
53
- var require_dist = __commonJS({
54
- "node_modules/.pnpm/json5@2.2.3/node_modules/json5/dist/index.js"(exports, module) {
55
- (function(global2, factory) {
56
- typeof exports === "object" && typeof module !== "undefined" ? module.exports = factory() : typeof define === "function" && define.amd ? define(factory) : global2.JSON5 = factory();
57
- })(exports, function() {
58
- "use strict";
59
- function createCommonjsModule(fn, module2) {
60
- return module2 = { exports: {} }, fn(module2, module2.exports), module2.exports;
61
- }
62
- var _global = createCommonjsModule(function(module2) {
63
- var global2 = module2.exports = typeof window != "undefined" && window.Math == Math ? window : typeof self != "undefined" && self.Math == Math ? self : Function("return this")();
64
- if (typeof __g == "number") {
65
- __g = global2;
66
- }
67
- });
68
- var _core = createCommonjsModule(function(module2) {
69
- var core = module2.exports = { version: "2.6.5" };
70
- if (typeof __e == "number") {
71
- __e = core;
72
- }
73
- });
74
- var _core_1 = _core.version;
75
- var _isObject = function(it) {
76
- return typeof it === "object" ? it !== null : typeof it === "function";
77
- };
78
- var _anObject = function(it) {
79
- if (!_isObject(it)) {
80
- throw TypeError(it + " is not an object!");
81
- }
82
- return it;
83
- };
84
- var _fails = function(exec) {
85
- try {
86
- return !!exec();
87
- } catch (e) {
88
- return true;
89
- }
90
- };
91
- var _descriptors = !_fails(function() {
92
- return Object.defineProperty({}, "a", { get: function() {
93
- return 7;
94
- } }).a != 7;
95
- });
96
- var document = _global.document;
97
- var is = _isObject(document) && _isObject(document.createElement);
98
- var _domCreate = function(it) {
99
- return is ? document.createElement(it) : {};
100
- };
101
- var _ie8DomDefine = !_descriptors && !_fails(function() {
102
- return Object.defineProperty(_domCreate("div"), "a", { get: function() {
103
- return 7;
104
- } }).a != 7;
105
- });
106
- var _toPrimitive = function(it, S) {
107
- if (!_isObject(it)) {
108
- return it;
109
- }
110
- var fn, val;
111
- if (S && typeof (fn = it.toString) == "function" && !_isObject(val = fn.call(it))) {
112
- return val;
113
- }
114
- if (typeof (fn = it.valueOf) == "function" && !_isObject(val = fn.call(it))) {
115
- return val;
116
- }
117
- if (!S && typeof (fn = it.toString) == "function" && !_isObject(val = fn.call(it))) {
118
- return val;
119
- }
120
- throw TypeError("Can't convert object to primitive value");
121
- };
122
- var dP = Object.defineProperty;
123
- var f = _descriptors ? Object.defineProperty : function defineProperty(O, P, Attributes) {
124
- _anObject(O);
125
- P = _toPrimitive(P, true);
126
- _anObject(Attributes);
127
- if (_ie8DomDefine) {
128
- try {
129
- return dP(O, P, Attributes);
130
- } catch (e) {
131
- }
132
- }
133
- if ("get" in Attributes || "set" in Attributes) {
134
- throw TypeError("Accessors not supported!");
135
- }
136
- if ("value" in Attributes) {
137
- O[P] = Attributes.value;
138
- }
139
- return O;
140
- };
141
- var _objectDp = {
142
- f
143
- };
144
- var _propertyDesc = function(bitmap, value) {
145
- return {
146
- enumerable: !(bitmap & 1),
147
- configurable: !(bitmap & 2),
148
- writable: !(bitmap & 4),
149
- value
150
- };
151
- };
152
- var _hide = _descriptors ? function(object, key2, value) {
153
- return _objectDp.f(object, key2, _propertyDesc(1, value));
154
- } : function(object, key2, value) {
155
- object[key2] = value;
156
- return object;
157
- };
158
- var hasOwnProperty2 = {}.hasOwnProperty;
159
- var _has = function(it, key2) {
160
- return hasOwnProperty2.call(it, key2);
161
- };
162
- var id = 0;
163
- var px = Math.random();
164
- var _uid = function(key2) {
165
- return "Symbol(".concat(key2 === void 0 ? "" : key2, ")_", (++id + px).toString(36));
166
- };
167
- var _library = false;
168
- var _shared = createCommonjsModule(function(module2) {
169
- var SHARED = "__core-js_shared__";
170
- var store = _global[SHARED] || (_global[SHARED] = {});
171
- (module2.exports = function(key2, value) {
172
- return store[key2] || (store[key2] = value !== void 0 ? value : {});
173
- })("versions", []).push({
174
- version: _core.version,
175
- mode: _library ? "pure" : "global",
176
- copyright: "\xA9 2019 Denis Pushkarev (zloirock.ru)"
177
- });
178
- });
179
- var _functionToString = _shared("native-function-to-string", Function.toString);
180
- var _redefine = createCommonjsModule(function(module2) {
181
- var SRC = _uid("src");
182
- var TO_STRING = "toString";
183
- var TPL = ("" + _functionToString).split(TO_STRING);
184
- _core.inspectSource = function(it) {
185
- return _functionToString.call(it);
186
- };
187
- (module2.exports = function(O, key2, val, safe) {
188
- var isFunction2 = typeof val == "function";
189
- if (isFunction2) {
190
- _has(val, "name") || _hide(val, "name", key2);
191
- }
192
- if (O[key2] === val) {
193
- return;
194
- }
195
- if (isFunction2) {
196
- _has(val, SRC) || _hide(val, SRC, O[key2] ? "" + O[key2] : TPL.join(String(key2)));
197
- }
198
- if (O === _global) {
199
- O[key2] = val;
200
- } else if (!safe) {
201
- delete O[key2];
202
- _hide(O, key2, val);
203
- } else if (O[key2]) {
204
- O[key2] = val;
205
- } else {
206
- _hide(O, key2, val);
207
- }
208
- })(Function.prototype, TO_STRING, function toString() {
209
- return typeof this == "function" && this[SRC] || _functionToString.call(this);
210
- });
211
- });
212
- var _aFunction = function(it) {
213
- if (typeof it != "function") {
214
- throw TypeError(it + " is not a function!");
215
- }
216
- return it;
217
- };
218
- var _ctx = function(fn, that, length) {
219
- _aFunction(fn);
220
- if (that === void 0) {
221
- return fn;
222
- }
223
- switch (length) {
224
- case 1:
225
- return function(a) {
226
- return fn.call(that, a);
227
- };
228
- case 2:
229
- return function(a, b) {
230
- return fn.call(that, a, b);
231
- };
232
- case 3:
233
- return function(a, b, c2) {
234
- return fn.call(that, a, b, c2);
235
- };
236
- }
237
- return function() {
238
- return fn.apply(that, arguments);
239
- };
240
- };
241
- var PROTOTYPE = "prototype";
242
- var $export = function(type, name, source2) {
243
- var IS_FORCED = type & $export.F;
244
- var IS_GLOBAL = type & $export.G;
245
- var IS_STATIC = type & $export.S;
246
- var IS_PROTO = type & $export.P;
247
- var IS_BIND = type & $export.B;
248
- var target = IS_GLOBAL ? _global : IS_STATIC ? _global[name] || (_global[name] = {}) : (_global[name] || {})[PROTOTYPE];
249
- var exports2 = IS_GLOBAL ? _core : _core[name] || (_core[name] = {});
250
- var expProto = exports2[PROTOTYPE] || (exports2[PROTOTYPE] = {});
251
- var key2, own, out, exp;
252
- if (IS_GLOBAL) {
253
- source2 = name;
254
- }
255
- for (key2 in source2) {
256
- own = !IS_FORCED && target && target[key2] !== void 0;
257
- out = (own ? target : source2)[key2];
258
- exp = IS_BIND && own ? _ctx(out, _global) : IS_PROTO && typeof out == "function" ? _ctx(Function.call, out) : out;
259
- if (target) {
260
- _redefine(target, key2, out, type & $export.U);
261
- }
262
- if (exports2[key2] != out) {
263
- _hide(exports2, key2, exp);
264
- }
265
- if (IS_PROTO && expProto[key2] != out) {
266
- expProto[key2] = out;
267
- }
268
- }
269
- };
270
- _global.core = _core;
271
- $export.F = 1;
272
- $export.G = 2;
273
- $export.S = 4;
274
- $export.P = 8;
275
- $export.B = 16;
276
- $export.W = 32;
277
- $export.U = 64;
278
- $export.R = 128;
279
- var _export = $export;
280
- var ceil = Math.ceil;
281
- var floor = Math.floor;
282
- var _toInteger = function(it) {
283
- return isNaN(it = +it) ? 0 : (it > 0 ? floor : ceil)(it);
284
- };
285
- var _defined = function(it) {
286
- if (it == void 0) {
287
- throw TypeError("Can't call method on " + it);
288
- }
289
- return it;
290
- };
291
- var _stringAt = function(TO_STRING) {
292
- return function(that, pos2) {
293
- var s = String(_defined(that));
294
- var i = _toInteger(pos2);
295
- var l = s.length;
296
- var a, b;
297
- if (i < 0 || i >= l) {
298
- return TO_STRING ? "" : void 0;
299
- }
300
- a = s.charCodeAt(i);
301
- return a < 55296 || a > 56319 || i + 1 === l || (b = s.charCodeAt(i + 1)) < 56320 || b > 57343 ? TO_STRING ? s.charAt(i) : a : TO_STRING ? s.slice(i, i + 2) : (a - 55296 << 10) + (b - 56320) + 65536;
302
- };
303
- };
304
- var $at = _stringAt(false);
305
- _export(_export.P, "String", {
306
- // 21.1.3.3 String.prototype.codePointAt(pos)
307
- codePointAt: function codePointAt2(pos2) {
308
- return $at(this, pos2);
309
- }
310
- });
311
- var codePointAt = _core.String.codePointAt;
312
- var max = Math.max;
313
- var min = Math.min;
314
- var _toAbsoluteIndex = function(index, length) {
315
- index = _toInteger(index);
316
- return index < 0 ? max(index + length, 0) : min(index, length);
317
- };
318
- var fromCharCode = String.fromCharCode;
319
- var $fromCodePoint = String.fromCodePoint;
320
- _export(_export.S + _export.F * (!!$fromCodePoint && $fromCodePoint.length != 1), "String", {
321
- // 21.1.2.2 String.fromCodePoint(...codePoints)
322
- fromCodePoint: function fromCodePoint2(x) {
323
- var arguments$1 = arguments;
324
- var res = [];
325
- var aLen = arguments.length;
326
- var i = 0;
327
- var code;
328
- while (aLen > i) {
329
- code = +arguments$1[i++];
330
- if (_toAbsoluteIndex(code, 1114111) !== code) {
331
- throw RangeError(code + " is not a valid code point");
332
- }
333
- res.push(
334
- code < 65536 ? fromCharCode(code) : fromCharCode(((code -= 65536) >> 10) + 55296, code % 1024 + 56320)
335
- );
336
- }
337
- return res.join("");
338
- }
339
- });
340
- var fromCodePoint = _core.String.fromCodePoint;
341
- var Space_Separator = /[\u1680\u2000-\u200A\u202F\u205F\u3000]/;
342
- var ID_Start = /[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u0860-\u086A\u08A0-\u08B4\u08B6-\u08BD\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u09FC\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C60\u0C61\u0C80\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D54-\u0D56\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u1884\u1887-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1C80-\u1C88\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312E\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FEA\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AE\uA7B0-\uA7B7\uA7F7-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDE80-\uDE9C\uDEA0-\uDED0\uDF00-\uDF1F\uDF2D-\uDF4A\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE4\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC03-\uDC37\uDC83-\uDCAF\uDCD0-\uDCE8\uDD03-\uDD26\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE2B\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEDE\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF50\uDF5D-\uDF61]|\uD805[\uDC00-\uDC34\uDC47-\uDC4A\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDD80-\uDDAE\uDDD8-\uDDDB\uDE00-\uDE2F\uDE44\uDE80-\uDEAA\uDF00-\uDF19]|\uD806[\uDCA0-\uDCDF\uDCFF\uDE00\uDE0B-\uDE32\uDE3A\uDE50\uDE5C-\uDE83\uDE86-\uDE89\uDEC0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC2E\uDC40\uDC72-\uDC8F\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD30\uDD46]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD81C-\uD820\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50\uDF93-\uDF9F\uDFE0\uDFE1]|\uD821[\uDC00-\uDFEC]|\uD822[\uDC00-\uDEF2]|\uD82C[\uDC00-\uDD1E\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB]|\uD83A[\uDC00-\uDCC4\uDD00-\uDD43]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0]|\uD87E[\uDC00-\uDE1D]/;
343
- var ID_Continue = /[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0300-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u0483-\u0487\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u05D0-\u05EA\u05F0-\u05F2\u0610-\u061A\u0620-\u0669\u066E-\u06D3\u06D5-\u06DC\u06DF-\u06E8\u06EA-\u06FC\u06FF\u0710-\u074A\u074D-\u07B1\u07C0-\u07F5\u07FA\u0800-\u082D\u0840-\u085B\u0860-\u086A\u08A0-\u08B4\u08B6-\u08BD\u08D4-\u08E1\u08E3-\u0963\u0966-\u096F\u0971-\u0983\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BC-\u09C4\u09C7\u09C8\u09CB-\u09CE\u09D7\u09DC\u09DD\u09DF-\u09E3\u09E6-\u09F1\u09FC\u0A01-\u0A03\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A59-\u0A5C\u0A5E\u0A66-\u0A75\u0A81-\u0A83\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABC-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AD0\u0AE0-\u0AE3\u0AE6-\u0AEF\u0AF9-\u0AFF\u0B01-\u0B03\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3C-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B5C\u0B5D\u0B5F-\u0B63\u0B66-\u0B6F\u0B71\u0B82\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD0\u0BD7\u0BE6-\u0BEF\u0C00-\u0C03\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C58-\u0C5A\u0C60-\u0C63\u0C66-\u0C6F\u0C80-\u0C83\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBC-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CDE\u0CE0-\u0CE3\u0CE6-\u0CEF\u0CF1\u0CF2\u0D00-\u0D03\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D44\u0D46-\u0D48\u0D4A-\u0D4E\u0D54-\u0D57\u0D5F-\u0D63\u0D66-\u0D6F\u0D7A-\u0D7F\u0D82\u0D83\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DE6-\u0DEF\u0DF2\u0DF3\u0E01-\u0E3A\u0E40-\u0E4E\u0E50-\u0E59\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB9\u0EBB-\u0EBD\u0EC0-\u0EC4\u0EC6\u0EC8-\u0ECD\u0ED0-\u0ED9\u0EDC-\u0EDF\u0F00\u0F18\u0F19\u0F20-\u0F29\u0F35\u0F37\u0F39\u0F3E-\u0F47\u0F49-\u0F6C\u0F71-\u0F84\u0F86-\u0F97\u0F99-\u0FBC\u0FC6\u1000-\u1049\u1050-\u109D\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u135D-\u135F\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1714\u1720-\u1734\u1740-\u1753\u1760-\u176C\u176E-\u1770\u1772\u1773\u1780-\u17D3\u17D7\u17DC\u17DD\u17E0-\u17E9\u180B-\u180D\u1810-\u1819\u1820-\u1877\u1880-\u18AA\u18B0-\u18F5\u1900-\u191E\u1920-\u192B\u1930-\u193B\u1946-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u19D0-\u19D9\u1A00-\u1A1B\u1A20-\u1A5E\u1A60-\u1A7C\u1A7F-\u1A89\u1A90-\u1A99\u1AA7\u1AB0-\u1ABD\u1B00-\u1B4B\u1B50-\u1B59\u1B6B-\u1B73\u1B80-\u1BF3\u1C00-\u1C37\u1C40-\u1C49\u1C4D-\u1C7D\u1C80-\u1C88\u1CD0-\u1CD2\u1CD4-\u1CF9\u1D00-\u1DF9\u1DFB-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u203F\u2040\u2054\u2071\u207F\u2090-\u209C\u20D0-\u20DC\u20E1\u20E5-\u20F0\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D7F-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2DE0-\u2DFF\u2E2F\u3005-\u3007\u3021-\u302F\u3031-\u3035\u3038-\u303C\u3041-\u3096\u3099\u309A\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312E\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FEA\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA62B\uA640-\uA66F\uA674-\uA67D\uA67F-\uA6F1\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AE\uA7B0-\uA7B7\uA7F7-\uA827\uA840-\uA873\uA880-\uA8C5\uA8D0-\uA8D9\uA8E0-\uA8F7\uA8FB\uA8FD\uA900-\uA92D\uA930-\uA953\uA960-\uA97C\uA980-\uA9C0\uA9CF-\uA9D9\uA9E0-\uA9FE\uAA00-\uAA36\uAA40-\uAA4D\uAA50-\uAA59\uAA60-\uAA76\uAA7A-\uAAC2\uAADB-\uAADD\uAAE0-\uAAEF\uAAF2-\uAAF6\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABEA\uABEC\uABED\uABF0-\uABF9\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE00-\uFE0F\uFE20-\uFE2F\uFE33\uFE34\uFE4D-\uFE4F\uFE70-\uFE74\uFE76-\uFEFC\uFF10-\uFF19\uFF21-\uFF3A\uFF3F\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDDFD\uDE80-\uDE9C\uDEA0-\uDED0\uDEE0\uDF00-\uDF1F\uDF2D-\uDF4A\uDF50-\uDF7A\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCA0-\uDCA9\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00-\uDE03\uDE05\uDE06\uDE0C-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE38-\uDE3A\uDE3F\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE6\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC00-\uDC46\uDC66-\uDC6F\uDC7F-\uDCBA\uDCD0-\uDCE8\uDCF0-\uDCF9\uDD00-\uDD34\uDD36-\uDD3F\uDD50-\uDD73\uDD76\uDD80-\uDDC4\uDDCA-\uDDCC\uDDD0-\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE37\uDE3E\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEEA\uDEF0-\uDEF9\uDF00-\uDF03\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3C-\uDF44\uDF47\uDF48\uDF4B-\uDF4D\uDF50\uDF57\uDF5D-\uDF63\uDF66-\uDF6C\uDF70-\uDF74]|\uD805[\uDC00-\uDC4A\uDC50-\uDC59\uDC80-\uDCC5\uDCC7\uDCD0-\uDCD9\uDD80-\uDDB5\uDDB8-\uDDC0\uDDD8-\uDDDD\uDE00-\uDE40\uDE44\uDE50-\uDE59\uDE80-\uDEB7\uDEC0-\uDEC9\uDF00-\uDF19\uDF1D-\uDF2B\uDF30-\uDF39]|\uD806[\uDCA0-\uDCE9\uDCFF\uDE00-\uDE3E\uDE47\uDE50-\uDE83\uDE86-\uDE99\uDEC0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC36\uDC38-\uDC40\uDC50-\uDC59\uDC72-\uDC8F\uDC92-\uDCA7\uDCA9-\uDCB6\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD36\uDD3A\uDD3C\uDD3D\uDD3F-\uDD47\uDD50-\uDD59]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD81C-\uD820\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDE60-\uDE69\uDED0-\uDEED\uDEF0-\uDEF4\uDF00-\uDF36\uDF40-\uDF43\uDF50-\uDF59\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50-\uDF7E\uDF8F-\uDF9F\uDFE0\uDFE1]|\uD821[\uDC00-\uDFEC]|\uD822[\uDC00-\uDEF2]|\uD82C[\uDC00-\uDD1E\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99\uDC9D\uDC9E]|\uD834[\uDD65-\uDD69\uDD6D-\uDD72\uDD7B-\uDD82\uDD85-\uDD8B\uDDAA-\uDDAD\uDE42-\uDE44]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB\uDFCE-\uDFFF]|\uD836[\uDE00-\uDE36\uDE3B-\uDE6C\uDE75\uDE84\uDE9B-\uDE9F\uDEA1-\uDEAF]|\uD838[\uDC00-\uDC06\uDC08-\uDC18\uDC1B-\uDC21\uDC23\uDC24\uDC26-\uDC2A]|\uD83A[\uDC00-\uDCC4\uDCD0-\uDCD6\uDD00-\uDD4A\uDD50-\uDD59]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0]|\uD87E[\uDC00-\uDE1D]|\uDB40[\uDD00-\uDDEF]/;
344
- var unicode = {
345
- Space_Separator,
346
- ID_Start,
347
- ID_Continue
348
- };
349
- var util = {
350
- isSpaceSeparator: function isSpaceSeparator(c2) {
351
- return typeof c2 === "string" && unicode.Space_Separator.test(c2);
352
- },
353
- isIdStartChar: function isIdStartChar(c2) {
354
- return typeof c2 === "string" && (c2 >= "a" && c2 <= "z" || c2 >= "A" && c2 <= "Z" || c2 === "$" || c2 === "_" || unicode.ID_Start.test(c2));
355
- },
356
- isIdContinueChar: function isIdContinueChar(c2) {
357
- return typeof c2 === "string" && (c2 >= "a" && c2 <= "z" || c2 >= "A" && c2 <= "Z" || c2 >= "0" && c2 <= "9" || c2 === "$" || c2 === "_" || c2 === "\u200C" || c2 === "\u200D" || unicode.ID_Continue.test(c2));
358
- },
359
- isDigit: function isDigit2(c2) {
360
- return typeof c2 === "string" && /[0-9]/.test(c2);
361
- },
362
- isHexDigit: function isHexDigit(c2) {
363
- return typeof c2 === "string" && /[0-9A-Fa-f]/.test(c2);
364
- }
365
- };
366
- var source;
367
- var parseState;
368
- var stack;
369
- var pos;
370
- var line;
371
- var column;
372
- var token;
373
- var key;
374
- var root2;
375
- var parse = function parse2(text, reviver) {
376
- source = String(text);
377
- parseState = "start";
378
- stack = [];
379
- pos = 0;
380
- line = 1;
381
- column = 0;
382
- token = void 0;
383
- key = void 0;
384
- root2 = void 0;
385
- do {
386
- token = lex();
387
- parseStates[parseState]();
388
- } while (token.type !== "eof");
389
- if (typeof reviver === "function") {
390
- return internalize({ "": root2 }, "", reviver);
391
- }
392
- return root2;
393
- };
394
- function internalize(holder, name, reviver) {
395
- var value = holder[name];
396
- if (value != null && typeof value === "object") {
397
- if (Array.isArray(value)) {
398
- for (var i = 0; i < value.length; i++) {
399
- var key2 = String(i);
400
- var replacement = internalize(value, key2, reviver);
401
- if (replacement === void 0) {
402
- delete value[key2];
403
- } else {
404
- Object.defineProperty(value, key2, {
405
- value: replacement,
406
- writable: true,
407
- enumerable: true,
408
- configurable: true
409
- });
410
- }
411
- }
412
- } else {
413
- for (var key$1 in value) {
414
- var replacement$1 = internalize(value, key$1, reviver);
415
- if (replacement$1 === void 0) {
416
- delete value[key$1];
417
- } else {
418
- Object.defineProperty(value, key$1, {
419
- value: replacement$1,
420
- writable: true,
421
- enumerable: true,
422
- configurable: true
423
- });
424
- }
425
- }
426
- }
427
- }
428
- return reviver.call(holder, name, value);
429
- }
430
- var lexState;
431
- var buffer;
432
- var doubleQuote;
433
- var sign;
434
- var c;
435
- function lex() {
436
- lexState = "default";
437
- buffer = "";
438
- doubleQuote = false;
439
- sign = 1;
440
- for (; ; ) {
441
- c = peek();
442
- var token2 = lexStates[lexState]();
443
- if (token2) {
444
- return token2;
445
- }
446
- }
447
- }
448
- function peek() {
449
- if (source[pos]) {
450
- return String.fromCodePoint(source.codePointAt(pos));
451
- }
452
- }
453
- function read() {
454
- var c2 = peek();
455
- if (c2 === "\n") {
456
- line++;
457
- column = 0;
458
- } else if (c2) {
459
- column += c2.length;
460
- } else {
461
- column++;
462
- }
463
- if (c2) {
464
- pos += c2.length;
465
- }
466
- return c2;
467
- }
468
- var lexStates = {
469
- default: function default$1() {
470
- switch (c) {
471
- case " ":
472
- case "\v":
473
- case "\f":
474
- case " ":
475
- case "\xA0":
476
- case "\uFEFF":
477
- case "\n":
478
- case "\r":
479
- case "\u2028":
480
- case "\u2029":
481
- read();
482
- return;
483
- case "/":
484
- read();
485
- lexState = "comment";
486
- return;
487
- case void 0:
488
- read();
489
- return newToken("eof");
490
- }
491
- if (util.isSpaceSeparator(c)) {
492
- read();
493
- return;
494
- }
495
- return lexStates[parseState]();
496
- },
497
- comment: function comment() {
498
- switch (c) {
499
- case "*":
500
- read();
501
- lexState = "multiLineComment";
502
- return;
503
- case "/":
504
- read();
505
- lexState = "singleLineComment";
506
- return;
507
- }
508
- throw invalidChar(read());
509
- },
510
- multiLineComment: function multiLineComment() {
511
- switch (c) {
512
- case "*":
513
- read();
514
- lexState = "multiLineCommentAsterisk";
515
- return;
516
- case void 0:
517
- throw invalidChar(read());
518
- }
519
- read();
520
- },
521
- multiLineCommentAsterisk: function multiLineCommentAsterisk() {
522
- switch (c) {
523
- case "*":
524
- read();
525
- return;
526
- case "/":
527
- read();
528
- lexState = "default";
529
- return;
530
- case void 0:
531
- throw invalidChar(read());
532
- }
533
- read();
534
- lexState = "multiLineComment";
535
- },
536
- singleLineComment: function singleLineComment() {
537
- switch (c) {
538
- case "\n":
539
- case "\r":
540
- case "\u2028":
541
- case "\u2029":
542
- read();
543
- lexState = "default";
544
- return;
545
- case void 0:
546
- read();
547
- return newToken("eof");
548
- }
549
- read();
550
- },
551
- value: function value() {
552
- switch (c) {
553
- case "{":
554
- case "[":
555
- return newToken("punctuator", read());
556
- case "n":
557
- read();
558
- literal("ull");
559
- return newToken("null", null);
560
- case "t":
561
- read();
562
- literal("rue");
563
- return newToken("boolean", true);
564
- case "f":
565
- read();
566
- literal("alse");
567
- return newToken("boolean", false);
568
- case "-":
569
- case "+":
570
- if (read() === "-") {
571
- sign = -1;
572
- }
573
- lexState = "sign";
574
- return;
575
- case ".":
576
- buffer = read();
577
- lexState = "decimalPointLeading";
578
- return;
579
- case "0":
580
- buffer = read();
581
- lexState = "zero";
582
- return;
583
- case "1":
584
- case "2":
585
- case "3":
586
- case "4":
587
- case "5":
588
- case "6":
589
- case "7":
590
- case "8":
591
- case "9":
592
- buffer = read();
593
- lexState = "decimalInteger";
594
- return;
595
- case "I":
596
- read();
597
- literal("nfinity");
598
- return newToken("numeric", Infinity);
599
- case "N":
600
- read();
601
- literal("aN");
602
- return newToken("numeric", NaN);
603
- case '"':
604
- case "'":
605
- doubleQuote = read() === '"';
606
- buffer = "";
607
- lexState = "string";
608
- return;
609
- }
610
- throw invalidChar(read());
611
- },
612
- identifierNameStartEscape: function identifierNameStartEscape() {
613
- if (c !== "u") {
614
- throw invalidChar(read());
615
- }
616
- read();
617
- var u = unicodeEscape();
618
- switch (u) {
619
- case "$":
620
- case "_":
621
- break;
622
- default:
623
- if (!util.isIdStartChar(u)) {
624
- throw invalidIdentifier();
625
- }
626
- break;
627
- }
628
- buffer += u;
629
- lexState = "identifierName";
630
- },
631
- identifierName: function identifierName() {
632
- switch (c) {
633
- case "$":
634
- case "_":
635
- case "\u200C":
636
- case "\u200D":
637
- buffer += read();
638
- return;
639
- case "\\":
640
- read();
641
- lexState = "identifierNameEscape";
642
- return;
643
- }
644
- if (util.isIdContinueChar(c)) {
645
- buffer += read();
646
- return;
647
- }
648
- return newToken("identifier", buffer);
649
- },
650
- identifierNameEscape: function identifierNameEscape() {
651
- if (c !== "u") {
652
- throw invalidChar(read());
653
- }
654
- read();
655
- var u = unicodeEscape();
656
- switch (u) {
657
- case "$":
658
- case "_":
659
- case "\u200C":
660
- case "\u200D":
661
- break;
662
- default:
663
- if (!util.isIdContinueChar(u)) {
664
- throw invalidIdentifier();
665
- }
666
- break;
667
- }
668
- buffer += u;
669
- lexState = "identifierName";
670
- },
671
- sign: function sign$1() {
672
- switch (c) {
673
- case ".":
674
- buffer = read();
675
- lexState = "decimalPointLeading";
676
- return;
677
- case "0":
678
- buffer = read();
679
- lexState = "zero";
680
- return;
681
- case "1":
682
- case "2":
683
- case "3":
684
- case "4":
685
- case "5":
686
- case "6":
687
- case "7":
688
- case "8":
689
- case "9":
690
- buffer = read();
691
- lexState = "decimalInteger";
692
- return;
693
- case "I":
694
- read();
695
- literal("nfinity");
696
- return newToken("numeric", sign * Infinity);
697
- case "N":
698
- read();
699
- literal("aN");
700
- return newToken("numeric", NaN);
701
- }
702
- throw invalidChar(read());
703
- },
704
- zero: function zero() {
705
- switch (c) {
706
- case ".":
707
- buffer += read();
708
- lexState = "decimalPoint";
709
- return;
710
- case "e":
711
- case "E":
712
- buffer += read();
713
- lexState = "decimalExponent";
714
- return;
715
- case "x":
716
- case "X":
717
- buffer += read();
718
- lexState = "hexadecimal";
719
- return;
720
- }
721
- return newToken("numeric", sign * 0);
722
- },
723
- decimalInteger: function decimalInteger() {
724
- switch (c) {
725
- case ".":
726
- buffer += read();
727
- lexState = "decimalPoint";
728
- return;
729
- case "e":
730
- case "E":
731
- buffer += read();
732
- lexState = "decimalExponent";
733
- return;
734
- }
735
- if (util.isDigit(c)) {
736
- buffer += read();
737
- return;
738
- }
739
- return newToken("numeric", sign * Number(buffer));
740
- },
741
- decimalPointLeading: function decimalPointLeading() {
742
- if (util.isDigit(c)) {
743
- buffer += read();
744
- lexState = "decimalFraction";
745
- return;
746
- }
747
- throw invalidChar(read());
748
- },
749
- decimalPoint: function decimalPoint() {
750
- switch (c) {
751
- case "e":
752
- case "E":
753
- buffer += read();
754
- lexState = "decimalExponent";
755
- return;
756
- }
757
- if (util.isDigit(c)) {
758
- buffer += read();
759
- lexState = "decimalFraction";
760
- return;
761
- }
762
- return newToken("numeric", sign * Number(buffer));
763
- },
764
- decimalFraction: function decimalFraction() {
765
- switch (c) {
766
- case "e":
767
- case "E":
768
- buffer += read();
769
- lexState = "decimalExponent";
770
- return;
771
- }
772
- if (util.isDigit(c)) {
773
- buffer += read();
774
- return;
775
- }
776
- return newToken("numeric", sign * Number(buffer));
777
- },
778
- decimalExponent: function decimalExponent() {
779
- switch (c) {
780
- case "+":
781
- case "-":
782
- buffer += read();
783
- lexState = "decimalExponentSign";
784
- return;
785
- }
786
- if (util.isDigit(c)) {
787
- buffer += read();
788
- lexState = "decimalExponentInteger";
789
- return;
790
- }
791
- throw invalidChar(read());
792
- },
793
- decimalExponentSign: function decimalExponentSign() {
794
- if (util.isDigit(c)) {
795
- buffer += read();
796
- lexState = "decimalExponentInteger";
797
- return;
798
- }
799
- throw invalidChar(read());
800
- },
801
- decimalExponentInteger: function decimalExponentInteger() {
802
- if (util.isDigit(c)) {
803
- buffer += read();
804
- return;
805
- }
806
- return newToken("numeric", sign * Number(buffer));
807
- },
808
- hexadecimal: function hexadecimal() {
809
- if (util.isHexDigit(c)) {
810
- buffer += read();
811
- lexState = "hexadecimalInteger";
812
- return;
813
- }
814
- throw invalidChar(read());
815
- },
816
- hexadecimalInteger: function hexadecimalInteger() {
817
- if (util.isHexDigit(c)) {
818
- buffer += read();
819
- return;
820
- }
821
- return newToken("numeric", sign * Number(buffer));
822
- },
823
- string: function string() {
824
- switch (c) {
825
- case "\\":
826
- read();
827
- buffer += escape();
828
- return;
829
- case '"':
830
- if (doubleQuote) {
831
- read();
832
- return newToken("string", buffer);
833
- }
834
- buffer += read();
835
- return;
836
- case "'":
837
- if (!doubleQuote) {
838
- read();
839
- return newToken("string", buffer);
840
- }
841
- buffer += read();
842
- return;
843
- case "\n":
844
- case "\r":
845
- throw invalidChar(read());
846
- case "\u2028":
847
- case "\u2029":
848
- separatorChar(c);
849
- break;
850
- case void 0:
851
- throw invalidChar(read());
852
- }
853
- buffer += read();
854
- },
855
- start: function start() {
856
- switch (c) {
857
- case "{":
858
- case "[":
859
- return newToken("punctuator", read());
860
- }
861
- lexState = "value";
862
- },
863
- beforePropertyName: function beforePropertyName() {
864
- switch (c) {
865
- case "$":
866
- case "_":
867
- buffer = read();
868
- lexState = "identifierName";
869
- return;
870
- case "\\":
871
- read();
872
- lexState = "identifierNameStartEscape";
873
- return;
874
- case "}":
875
- return newToken("punctuator", read());
876
- case '"':
877
- case "'":
878
- doubleQuote = read() === '"';
879
- lexState = "string";
880
- return;
881
- }
882
- if (util.isIdStartChar(c)) {
883
- buffer += read();
884
- lexState = "identifierName";
885
- return;
886
- }
887
- throw invalidChar(read());
888
- },
889
- afterPropertyName: function afterPropertyName() {
890
- if (c === ":") {
891
- return newToken("punctuator", read());
892
- }
893
- throw invalidChar(read());
894
- },
895
- beforePropertyValue: function beforePropertyValue() {
896
- lexState = "value";
897
- },
898
- afterPropertyValue: function afterPropertyValue() {
899
- switch (c) {
900
- case ",":
901
- case "}":
902
- return newToken("punctuator", read());
903
- }
904
- throw invalidChar(read());
905
- },
906
- beforeArrayValue: function beforeArrayValue() {
907
- if (c === "]") {
908
- return newToken("punctuator", read());
909
- }
910
- lexState = "value";
911
- },
912
- afterArrayValue: function afterArrayValue() {
913
- switch (c) {
914
- case ",":
915
- case "]":
916
- return newToken("punctuator", read());
917
- }
918
- throw invalidChar(read());
919
- },
920
- end: function end() {
921
- throw invalidChar(read());
922
- }
923
- };
924
- function newToken(type, value) {
925
- return {
926
- type,
927
- value,
928
- line,
929
- column
930
- };
931
- }
932
- function literal(s) {
933
- for (var i = 0, list = s; i < list.length; i += 1) {
934
- var c2 = list[i];
935
- var p = peek();
936
- if (p !== c2) {
937
- throw invalidChar(read());
938
- }
939
- read();
940
- }
941
- }
942
- function escape() {
943
- var c2 = peek();
944
- switch (c2) {
945
- case "b":
946
- read();
947
- return "\b";
948
- case "f":
949
- read();
950
- return "\f";
951
- case "n":
952
- read();
953
- return "\n";
954
- case "r":
955
- read();
956
- return "\r";
957
- case "t":
958
- read();
959
- return " ";
960
- case "v":
961
- read();
962
- return "\v";
963
- case "0":
964
- read();
965
- if (util.isDigit(peek())) {
966
- throw invalidChar(read());
967
- }
968
- return "\0";
969
- case "x":
970
- read();
971
- return hexEscape();
972
- case "u":
973
- read();
974
- return unicodeEscape();
975
- case "\n":
976
- case "\u2028":
977
- case "\u2029":
978
- read();
979
- return "";
980
- case "\r":
981
- read();
982
- if (peek() === "\n") {
983
- read();
984
- }
985
- return "";
986
- case "1":
987
- case "2":
988
- case "3":
989
- case "4":
990
- case "5":
991
- case "6":
992
- case "7":
993
- case "8":
994
- case "9":
995
- throw invalidChar(read());
996
- case void 0:
997
- throw invalidChar(read());
998
- }
999
- return read();
1000
- }
1001
- function hexEscape() {
1002
- var buffer2 = "";
1003
- var c2 = peek();
1004
- if (!util.isHexDigit(c2)) {
1005
- throw invalidChar(read());
1006
- }
1007
- buffer2 += read();
1008
- c2 = peek();
1009
- if (!util.isHexDigit(c2)) {
1010
- throw invalidChar(read());
1011
- }
1012
- buffer2 += read();
1013
- return String.fromCodePoint(parseInt(buffer2, 16));
1014
- }
1015
- function unicodeEscape() {
1016
- var buffer2 = "";
1017
- var count = 4;
1018
- while (count-- > 0) {
1019
- var c2 = peek();
1020
- if (!util.isHexDigit(c2)) {
1021
- throw invalidChar(read());
1022
- }
1023
- buffer2 += read();
1024
- }
1025
- return String.fromCodePoint(parseInt(buffer2, 16));
1026
- }
1027
- var parseStates = {
1028
- start: function start() {
1029
- if (token.type === "eof") {
1030
- throw invalidEOF();
1031
- }
1032
- push();
1033
- },
1034
- beforePropertyName: function beforePropertyName() {
1035
- switch (token.type) {
1036
- case "identifier":
1037
- case "string":
1038
- key = token.value;
1039
- parseState = "afterPropertyName";
1040
- return;
1041
- case "punctuator":
1042
- pop();
1043
- return;
1044
- case "eof":
1045
- throw invalidEOF();
1046
- }
1047
- },
1048
- afterPropertyName: function afterPropertyName() {
1049
- if (token.type === "eof") {
1050
- throw invalidEOF();
1051
- }
1052
- parseState = "beforePropertyValue";
1053
- },
1054
- beforePropertyValue: function beforePropertyValue() {
1055
- if (token.type === "eof") {
1056
- throw invalidEOF();
1057
- }
1058
- push();
1059
- },
1060
- beforeArrayValue: function beforeArrayValue() {
1061
- if (token.type === "eof") {
1062
- throw invalidEOF();
1063
- }
1064
- if (token.type === "punctuator" && token.value === "]") {
1065
- pop();
1066
- return;
1067
- }
1068
- push();
1069
- },
1070
- afterPropertyValue: function afterPropertyValue() {
1071
- if (token.type === "eof") {
1072
- throw invalidEOF();
1073
- }
1074
- switch (token.value) {
1075
- case ",":
1076
- parseState = "beforePropertyName";
1077
- return;
1078
- case "}":
1079
- pop();
1080
- }
1081
- },
1082
- afterArrayValue: function afterArrayValue() {
1083
- if (token.type === "eof") {
1084
- throw invalidEOF();
1085
- }
1086
- switch (token.value) {
1087
- case ",":
1088
- parseState = "beforeArrayValue";
1089
- return;
1090
- case "]":
1091
- pop();
1092
- }
1093
- },
1094
- end: function end() {
1095
- }
1096
- };
1097
- function push() {
1098
- var value;
1099
- switch (token.type) {
1100
- case "punctuator":
1101
- switch (token.value) {
1102
- case "{":
1103
- value = {};
1104
- break;
1105
- case "[":
1106
- value = [];
1107
- break;
1108
- }
1109
- break;
1110
- case "null":
1111
- case "boolean":
1112
- case "numeric":
1113
- case "string":
1114
- value = token.value;
1115
- break;
1116
- }
1117
- if (root2 === void 0) {
1118
- root2 = value;
1119
- } else {
1120
- var parent = stack[stack.length - 1];
1121
- if (Array.isArray(parent)) {
1122
- parent.push(value);
1123
- } else {
1124
- Object.defineProperty(parent, key, {
1125
- value,
1126
- writable: true,
1127
- enumerable: true,
1128
- configurable: true
1129
- });
1130
- }
1131
- }
1132
- if (value !== null && typeof value === "object") {
1133
- stack.push(value);
1134
- if (Array.isArray(value)) {
1135
- parseState = "beforeArrayValue";
1136
- } else {
1137
- parseState = "beforePropertyName";
1138
- }
1139
- } else {
1140
- var current = stack[stack.length - 1];
1141
- if (current == null) {
1142
- parseState = "end";
1143
- } else if (Array.isArray(current)) {
1144
- parseState = "afterArrayValue";
1145
- } else {
1146
- parseState = "afterPropertyValue";
1147
- }
1148
- }
1149
- }
1150
- function pop() {
1151
- stack.pop();
1152
- var current = stack[stack.length - 1];
1153
- if (current == null) {
1154
- parseState = "end";
1155
- } else if (Array.isArray(current)) {
1156
- parseState = "afterArrayValue";
1157
- } else {
1158
- parseState = "afterPropertyValue";
1159
- }
1160
- }
1161
- function invalidChar(c2) {
1162
- if (c2 === void 0) {
1163
- return syntaxError("JSON5: invalid end of input at " + line + ":" + column);
1164
- }
1165
- return syntaxError("JSON5: invalid character '" + formatChar(c2) + "' at " + line + ":" + column);
1166
- }
1167
- function invalidEOF() {
1168
- return syntaxError("JSON5: invalid end of input at " + line + ":" + column);
1169
- }
1170
- function invalidIdentifier() {
1171
- column -= 5;
1172
- return syntaxError("JSON5: invalid identifier character at " + line + ":" + column);
1173
- }
1174
- function separatorChar(c2) {
1175
- console.warn("JSON5: '" + formatChar(c2) + "' in strings is not valid ECMAScript; consider escaping");
1176
- }
1177
- function formatChar(c2) {
1178
- var replacements = {
1179
- "'": "\\'",
1180
- '"': '\\"',
1181
- "\\": "\\\\",
1182
- "\b": "\\b",
1183
- "\f": "\\f",
1184
- "\n": "\\n",
1185
- "\r": "\\r",
1186
- " ": "\\t",
1187
- "\v": "\\v",
1188
- "\0": "\\0",
1189
- "\u2028": "\\u2028",
1190
- "\u2029": "\\u2029"
1191
- };
1192
- if (replacements[c2]) {
1193
- return replacements[c2];
1194
- }
1195
- if (c2 < " ") {
1196
- var hexString = c2.charCodeAt(0).toString(16);
1197
- return "\\x" + ("00" + hexString).substring(hexString.length);
1198
- }
1199
- return c2;
1200
- }
1201
- function syntaxError(message) {
1202
- var err = new SyntaxError(message);
1203
- err.lineNumber = line;
1204
- err.columnNumber = column;
1205
- return err;
1206
- }
1207
- var stringify2 = function stringify3(value, replacer, space) {
1208
- var stack2 = [];
1209
- var indent = "";
1210
- var propertyList;
1211
- var replacerFunc;
1212
- var gap = "";
1213
- var quote;
1214
- if (replacer != null && typeof replacer === "object" && !Array.isArray(replacer)) {
1215
- space = replacer.space;
1216
- quote = replacer.quote;
1217
- replacer = replacer.replacer;
1218
- }
1219
- if (typeof replacer === "function") {
1220
- replacerFunc = replacer;
1221
- } else if (Array.isArray(replacer)) {
1222
- propertyList = [];
1223
- for (var i = 0, list = replacer; i < list.length; i += 1) {
1224
- var v = list[i];
1225
- var item = void 0;
1226
- if (typeof v === "string") {
1227
- item = v;
1228
- } else if (typeof v === "number" || v instanceof String || v instanceof Number) {
1229
- item = String(v);
1230
- }
1231
- if (item !== void 0 && propertyList.indexOf(item) < 0) {
1232
- propertyList.push(item);
1233
- }
1234
- }
1235
- }
1236
- if (space instanceof Number) {
1237
- space = Number(space);
1238
- } else if (space instanceof String) {
1239
- space = String(space);
1240
- }
1241
- if (typeof space === "number") {
1242
- if (space > 0) {
1243
- space = Math.min(10, Math.floor(space));
1244
- gap = " ".substr(0, space);
1245
- }
1246
- } else if (typeof space === "string") {
1247
- gap = space.substr(0, 10);
1248
- }
1249
- return serializeProperty("", { "": value });
1250
- function serializeProperty(key2, holder) {
1251
- var value2 = holder[key2];
1252
- if (value2 != null) {
1253
- if (typeof value2.toJSON5 === "function") {
1254
- value2 = value2.toJSON5(key2);
1255
- } else if (typeof value2.toJSON === "function") {
1256
- value2 = value2.toJSON(key2);
1257
- }
1258
- }
1259
- if (replacerFunc) {
1260
- value2 = replacerFunc.call(holder, key2, value2);
1261
- }
1262
- if (value2 instanceof Number) {
1263
- value2 = Number(value2);
1264
- } else if (value2 instanceof String) {
1265
- value2 = String(value2);
1266
- } else if (value2 instanceof Boolean) {
1267
- value2 = value2.valueOf();
1268
- }
1269
- switch (value2) {
1270
- case null:
1271
- return "null";
1272
- case true:
1273
- return "true";
1274
- case false:
1275
- return "false";
1276
- }
1277
- if (typeof value2 === "string") {
1278
- return quoteString(value2, false);
1279
- }
1280
- if (typeof value2 === "number") {
1281
- return String(value2);
1282
- }
1283
- if (typeof value2 === "object") {
1284
- return Array.isArray(value2) ? serializeArray(value2) : serializeObject(value2);
1285
- }
1286
- return void 0;
1287
- }
1288
- function quoteString(value2) {
1289
- var quotes = {
1290
- "'": 0.1,
1291
- '"': 0.2
1292
- };
1293
- var replacements = {
1294
- "'": "\\'",
1295
- '"': '\\"',
1296
- "\\": "\\\\",
1297
- "\b": "\\b",
1298
- "\f": "\\f",
1299
- "\n": "\\n",
1300
- "\r": "\\r",
1301
- " ": "\\t",
1302
- "\v": "\\v",
1303
- "\0": "\\0",
1304
- "\u2028": "\\u2028",
1305
- "\u2029": "\\u2029"
1306
- };
1307
- var product = "";
1308
- for (var i2 = 0; i2 < value2.length; i2++) {
1309
- var c2 = value2[i2];
1310
- switch (c2) {
1311
- case "'":
1312
- case '"':
1313
- quotes[c2]++;
1314
- product += c2;
1315
- continue;
1316
- case "\0":
1317
- if (util.isDigit(value2[i2 + 1])) {
1318
- product += "\\x00";
1319
- continue;
1320
- }
1321
- }
1322
- if (replacements[c2]) {
1323
- product += replacements[c2];
1324
- continue;
1325
- }
1326
- if (c2 < " ") {
1327
- var hexString = c2.charCodeAt(0).toString(16);
1328
- product += "\\x" + ("00" + hexString).substring(hexString.length);
1329
- continue;
1330
- }
1331
- product += c2;
1332
- }
1333
- var quoteChar = quote || Object.keys(quotes).reduce(function(a, b) {
1334
- return quotes[a] < quotes[b] ? a : b;
1335
- });
1336
- product = product.replace(new RegExp(quoteChar, "g"), replacements[quoteChar]);
1337
- return quoteChar + product + quoteChar;
1338
- }
1339
- function serializeObject(value2) {
1340
- if (stack2.indexOf(value2) >= 0) {
1341
- throw TypeError("Converting circular structure to JSON5");
1342
- }
1343
- stack2.push(value2);
1344
- var stepback = indent;
1345
- indent = indent + gap;
1346
- var keys = propertyList || Object.keys(value2);
1347
- var partial = [];
1348
- for (var i2 = 0, list2 = keys; i2 < list2.length; i2 += 1) {
1349
- var key2 = list2[i2];
1350
- var propertyString = serializeProperty(key2, value2);
1351
- if (propertyString !== void 0) {
1352
- var member = serializeKey(key2) + ":";
1353
- if (gap !== "") {
1354
- member += " ";
1355
- }
1356
- member += propertyString;
1357
- partial.push(member);
1358
- }
1359
- }
1360
- var final;
1361
- if (partial.length === 0) {
1362
- final = "{}";
1363
- } else {
1364
- var properties;
1365
- if (gap === "") {
1366
- properties = partial.join(",");
1367
- final = "{" + properties + "}";
1368
- } else {
1369
- var separator = ",\n" + indent;
1370
- properties = partial.join(separator);
1371
- final = "{\n" + indent + properties + ",\n" + stepback + "}";
1372
- }
1373
- }
1374
- stack2.pop();
1375
- indent = stepback;
1376
- return final;
1377
- }
1378
- function serializeKey(key2) {
1379
- if (key2.length === 0) {
1380
- return quoteString(key2, true);
1381
- }
1382
- var firstChar = String.fromCodePoint(key2.codePointAt(0));
1383
- if (!util.isIdStartChar(firstChar)) {
1384
- return quoteString(key2, true);
1385
- }
1386
- for (var i2 = firstChar.length; i2 < key2.length; i2++) {
1387
- if (!util.isIdContinueChar(String.fromCodePoint(key2.codePointAt(i2)))) {
1388
- return quoteString(key2, true);
1389
- }
1390
- }
1391
- return key2;
1392
- }
1393
- function serializeArray(value2) {
1394
- if (stack2.indexOf(value2) >= 0) {
1395
- throw TypeError("Converting circular structure to JSON5");
1396
- }
1397
- stack2.push(value2);
1398
- var stepback = indent;
1399
- indent = indent + gap;
1400
- var partial = [];
1401
- for (var i2 = 0; i2 < value2.length; i2++) {
1402
- var propertyString = serializeProperty(String(i2), value2);
1403
- partial.push(propertyString !== void 0 ? propertyString : "null");
1404
- }
1405
- var final;
1406
- if (partial.length === 0) {
1407
- final = "[]";
1408
- } else {
1409
- if (gap === "") {
1410
- var properties = partial.join(",");
1411
- final = "[" + properties + "]";
1412
- } else {
1413
- var separator = ",\n" + indent;
1414
- var properties$1 = partial.join(separator);
1415
- final = "[\n" + indent + properties$1 + ",\n" + stepback + "]";
1416
- }
1417
- }
1418
- stack2.pop();
1419
- indent = stepback;
1420
- return final;
1421
- }
1422
- };
1423
- var JSON52 = {
1424
- parse,
1425
- stringify: stringify2
1426
- };
1427
- var lib = JSON52;
1428
- var es5 = lib;
1429
- return es5;
1430
- });
1431
- }
1432
- });
1433
-
1434
- // src/zai.ts
1435
- var import_zui3 = __require("@bpinternal/zui");
1436
- var import_wasm = __require("@botpress/wasm");
1437
-
1438
- // src/adapters/botpress-table.ts
1439
- var import_zui2 = __require("@bpinternal/zui");
1440
-
1441
- // src/utils.ts
1442
- var import_zui = __require("@bpinternal/zui");
1443
- var stringify = (input, beautify = true) => {
1444
- return typeof input === "string" && !!input.length ? input : input ? JSON.stringify(input, beautify ? null : void 0, beautify ? 2 : void 0) : "<input is null, false, undefined or empty>";
1445
- };
1446
- var BotpressClient = import_zui.z.custom(
1447
- (value) => typeof value === "object" && value !== null && "callAction" in value && typeof value.callAction === "function",
1448
- {
1449
- message: "Invalid Botpress Client. Make sure to pass an instance of @botpress/client"
1450
- }
1451
- );
1452
- function fastHash(str) {
1453
- let hash = 0;
1454
- for (let i = 0; i < str.length; i++) {
1455
- hash = (hash << 5) - hash + str.charCodeAt(i);
1456
- hash |= 0;
1457
- }
1458
- return (hash >>> 0).toString(16);
1459
- }
1460
- var takeUntilTokens = (arr, tokens, count) => {
1461
- const result = [];
1462
- let total = 0;
1463
- for (const value of arr) {
1464
- const valueTokens = count(value);
1465
- if (total + valueTokens > tokens) {
1466
- break;
1467
- }
1468
- total += valueTokens;
1469
- result.push(value);
1470
- }
1471
- return result;
1472
- };
1473
- var GenerationMetadata = import_zui.z.object({
1474
- model: import_zui.z.string(),
1475
- cost: import_zui.z.object({
1476
- input: import_zui.z.number(),
1477
- output: import_zui.z.number()
1478
- }).describe("Cost in $USD"),
1479
- latency: import_zui.z.number().describe("Latency in milliseconds"),
1480
- tokens: import_zui.z.object({
1481
- input: import_zui.z.number(),
1482
- output: import_zui.z.number()
1483
- }).describe("Number of tokens used")
1484
- });
1485
-
1486
- // src/adapters/adapter.ts
1487
- var Adapter = class {
1488
- };
1489
-
1490
- // src/adapters/botpress-table.ts
1491
- var CRITICAL_TAGS = {
1492
- system: "true",
1493
- "schema-purpose": "active-learning",
1494
- "schema-version": "Oct-2024"
1495
- };
1496
- var OPTIONAL_TAGS = {
1497
- "x-studio-title": "Active Learning",
1498
- "x-studio-description": "Table for storing active learning tasks and examples",
1499
- "x-studio-readonly": "true",
1500
- "x-studio-icon": "lucide://atom",
1501
- "x-studio-color": "green"
1502
- };
1503
- var FACTOR = 30;
1504
- var Props = import_zui2.z.object({
1505
- client: BotpressClient,
1506
- tableName: import_zui2.z.string().regex(
1507
- /^[a-zA-Z0-9_]{1,45}Table$/,
1508
- "Table name must be lowercase and contain only letters, numbers and underscores"
1509
- )
1510
- });
1511
- var TableSchema = import_zui2.z.object({
1512
- taskType: import_zui2.z.string().describe("The type of the task (filter, extract, etc.)"),
1513
- taskId: import_zui2.z.string(),
1514
- key: import_zui2.z.string().describe("A unique key for the task (e.g. a hash of the input, taskId, taskType and instructions)"),
1515
- instructions: import_zui2.z.string(),
1516
- input: import_zui2.z.object({}).passthrough().describe("The input to the task"),
1517
- output: import_zui2.z.object({}).passthrough().describe("The expected output"),
1518
- explanation: import_zui2.z.string().nullable(),
1519
- metadata: GenerationMetadata,
1520
- status: import_zui2.z.enum(["pending", "rejected", "approved"]),
1521
- feedback: import_zui2.z.object({
1522
- rating: import_zui2.z.enum(["very-bad", "bad", "good", "very-good"]),
1523
- comment: import_zui2.z.string().nullable()
1524
- }).nullable().default(null)
1525
- });
1526
- var searchableColumns = ["input"];
1527
- var TableJsonSchema = Object.entries(TableSchema.shape).reduce((acc, [key, value]) => {
1528
- var _a, _b;
1529
- acc[key] = value.toJsonSchema();
1530
- (_b = (_a = acc[key])["x-zui"]) != null ? _b : _a["x-zui"] = {};
1531
- acc[key]["x-zui"].searchable = searchableColumns.includes(key);
1532
- return acc;
1533
- }, {});
1534
- var TableAdapter = class extends Adapter {
1535
- constructor(props) {
1536
- super();
1537
- __publicField(this, "client");
1538
- __publicField(this, "tableName");
1539
- __publicField(this, "status");
1540
- props = Props.parse(props);
1541
- this.client = props.client;
1542
- this.tableName = props.tableName;
1543
- this.status = "ready";
1544
- }
1545
- async getExamples({ taskType, taskId, input }) {
1546
- await this.assertTableExists();
1547
- const { rows } = await this.client.findTableRows({
1548
- table: this.tableName,
1549
- search: JSON.stringify({ value: input }).substring(0, 1023),
1550
- // Search is limited to 1024 characters
1551
- limit: 10,
1552
- // TODO
1553
- filter: {
1554
- // Proximity match of approved examples
1555
- taskType,
1556
- taskId,
1557
- status: "approved"
1558
- }
1559
- }).catch((err) => {
1560
- console.error("Error fetching examples: ".concat(err.message));
1561
- return { rows: [] };
1562
- });
1563
- return rows.map((row) => {
1564
- var _a;
1565
- return {
1566
- key: row.key,
1567
- input: row.input.value,
1568
- output: row.output.value,
1569
- explanation: row.explanation,
1570
- similarity: (_a = row.similarity) != null ? _a : 0
1571
- };
1572
- });
1573
- }
1574
- async saveExample({
1575
- key,
1576
- taskType,
1577
- taskId,
1578
- instructions,
1579
- input,
1580
- output,
1581
- explanation,
1582
- metadata,
1583
- status = "pending"
1584
- }) {
1585
- await this.assertTableExists();
1586
- await this.client.upsertTableRows({
1587
- table: this.tableName,
1588
- keyColumn: "key",
1589
- rows: [
1590
- {
1591
- key,
1592
- taskType,
1593
- taskId,
1594
- instructions,
1595
- input: { value: input },
1596
- output: { value: output },
1597
- explanation: explanation != null ? explanation : null,
1598
- status,
1599
- metadata
1600
- }
1601
- ]
1602
- }).catch(() => {
1603
- });
1604
- }
1605
- async assertTableExists() {
1606
- var _a, _b, _c;
1607
- if (this.status !== "ready") {
1608
- return;
1609
- }
1610
- const { table, created } = await this.client.getOrCreateTable({
1611
- table: this.tableName,
1612
- factor: FACTOR,
1613
- frozen: true,
1614
- isComputeEnabled: false,
1615
- tags: __spreadValues(__spreadValues({}, CRITICAL_TAGS), OPTIONAL_TAGS),
1616
- schema: TableJsonSchema
1617
- }).catch(() => {
1618
- this.status = "error";
1619
- return { table: null, created: false };
1620
- });
1621
- if (!table) {
1622
- return;
1623
- }
1624
- if (!created) {
1625
- const issues = [];
1626
- if (table.factor !== FACTOR) {
1627
- issues.push("Factor is ".concat(table.factor, " instead of ").concat(FACTOR));
1628
- }
1629
- if (table.frozen !== true) {
1630
- issues.push("Table is not frozen");
1631
- }
1632
- for (const [key, value] of Object.entries(CRITICAL_TAGS)) {
1633
- if (((_a = table.tags) == null ? void 0 : _a[key]) !== value) {
1634
- issues.push("Tag ".concat(key, " is ").concat((_b = table.tags) == null ? void 0 : _b[key], " instead of ").concat(value));
1635
- }
1636
- }
1637
- for (const key of Object.keys(TableJsonSchema)) {
1638
- const column = (_c = table.schema) == null ? void 0 : _c.properties[key];
1639
- const expected = TableJsonSchema[key];
1640
- if (!column) {
1641
- issues.push("Column ".concat(key, " is missing"));
1642
- continue;
1643
- }
1644
- if (column.type !== expected.type) {
1645
- issues.push("Column ".concat(key, " has type ").concat(column.type, " instead of ").concat(expected.type));
1646
- }
1647
- if (expected["x-zui"].searchable && !column["x-zui"].searchable) {
1648
- issues.push("Column ".concat(key, " is not searchable but should be"));
1649
- }
1650
- }
1651
- if (issues.length) {
1652
- this.status = "error";
1653
- }
1654
- }
1655
- this.status = "initialized";
1656
- }
1657
- };
1658
-
1659
- // src/adapters/memory.ts
1660
- var MemoryAdapter = class extends Adapter {
1661
- constructor(examples) {
1662
- super();
1663
- this.examples = examples;
1664
- }
1665
- async getExamples() {
1666
- return this.examples;
1667
- }
1668
- async saveExample() {
1669
- }
1670
- };
1671
-
1672
- // src/models.ts
1673
- var Models = [
1674
- {
1675
- "id": "anthropic__claude-3-haiku-20240307",
1676
- "name": "Claude 3 Haiku",
1677
- "integration": "anthropic",
1678
- "input": {
1679
- "maxTokens": 2e5
1680
- },
1681
- "output": {
1682
- "maxTokens": 4096
1683
- }
1684
- },
1685
- {
1686
- "id": "anthropic__claude-3-5-sonnet-20240620",
1687
- "name": "Claude 3.5 Sonnet",
1688
- "integration": "anthropic",
1689
- "input": {
1690
- "maxTokens": 2e5
1691
- },
1692
- "output": {
1693
- "maxTokens": 4096
1694
- }
1695
- },
1696
- {
1697
- "id": "cerebras__llama3.1-70b",
1698
- "name": "Llama 3.1 70B",
1699
- "integration": "cerebras",
1700
- "input": {
1701
- "maxTokens": 8192
1702
- },
1703
- "output": {
1704
- "maxTokens": 8192
1705
- }
1706
- },
1707
- {
1708
- "id": "cerebras__llama3.1-8b",
1709
- "name": "Llama 3.1 8B",
1710
- "integration": "cerebras",
1711
- "input": {
1712
- "maxTokens": 8192
1713
- },
1714
- "output": {
1715
- "maxTokens": 8192
1716
- }
1717
- },
1718
- {
1719
- "id": "fireworks-ai__accounts/fireworks/models/deepseek-coder-v2-instruct",
1720
- "name": "DeepSeek Coder V2 Instruct",
1721
- "integration": "fireworks-ai",
1722
- "input": {
1723
- "maxTokens": 131072
1724
- },
1725
- "output": {
1726
- "maxTokens": 131072
1727
- }
1728
- },
1729
- {
1730
- "id": "fireworks-ai__accounts/fireworks/models/deepseek-coder-v2-lite-instruct",
1731
- "name": "DeepSeek Coder V2 Lite",
1732
- "integration": "fireworks-ai",
1733
- "input": {
1734
- "maxTokens": 163840
1735
- },
1736
- "output": {
1737
- "maxTokens": 163840
1738
- }
1739
- },
1740
- {
1741
- "id": "fireworks-ai__accounts/fireworks/models/firellava-13b",
1742
- "name": "FireLLaVA-13B",
1743
- "integration": "fireworks-ai",
1744
- "input": {
1745
- "maxTokens": 4096
1746
- },
1747
- "output": {
1748
- "maxTokens": 4096
1749
- }
1750
- },
1751
- {
1752
- "id": "fireworks-ai__accounts/fireworks/models/firefunction-v2",
1753
- "name": "Firefunction V2",
1754
- "integration": "fireworks-ai",
1755
- "input": {
1756
- "maxTokens": 8192
1757
- },
1758
- "output": {
1759
- "maxTokens": 8192
1760
- }
1761
- },
1762
- {
1763
- "id": "fireworks-ai__accounts/fireworks/models/gemma2-9b-it",
1764
- "name": "Gemma 2 9B Instruct",
1765
- "integration": "fireworks-ai",
1766
- "input": {
1767
- "maxTokens": 8192
1768
- },
1769
- "output": {
1770
- "maxTokens": 8192
1771
- }
1772
- },
1773
- {
1774
- "id": "fireworks-ai__accounts/fireworks/models/llama-v3p1-405b-instruct",
1775
- "name": "Llama 3.1 405B Instruct",
1776
- "integration": "fireworks-ai",
1777
- "input": {
1778
- "maxTokens": 131072
1779
- },
1780
- "output": {
1781
- "maxTokens": 131072
1782
- }
1783
- },
1784
- {
1785
- "id": "fireworks-ai__accounts/fireworks/models/llama-v3p1-70b-instruct",
1786
- "name": "Llama 3.1 70B Instruct",
1787
- "integration": "fireworks-ai",
1788
- "input": {
1789
- "maxTokens": 131072
1790
- },
1791
- "output": {
1792
- "maxTokens": 131072
1793
- }
1794
- },
1795
- {
1796
- "id": "fireworks-ai__accounts/fireworks/models/llama-v3p1-8b-instruct",
1797
- "name": "Llama 3.1 8B Instruct",
1798
- "integration": "fireworks-ai",
1799
- "input": {
1800
- "maxTokens": 131072
1801
- },
1802
- "output": {
1803
- "maxTokens": 131072
1804
- }
1805
- },
1806
- {
1807
- "id": "fireworks-ai__accounts/fireworks/models/mixtral-8x22b-instruct",
1808
- "name": "Mixtral MoE 8x22B Instruct",
1809
- "integration": "fireworks-ai",
1810
- "input": {
1811
- "maxTokens": 65536
1812
- },
1813
- "output": {
1814
- "maxTokens": 65536
1815
- }
1816
- },
1817
- {
1818
- "id": "fireworks-ai__accounts/fireworks/models/mixtral-8x7b-instruct",
1819
- "name": "Mixtral MoE 8x7B Instruct",
1820
- "integration": "fireworks-ai",
1821
- "input": {
1822
- "maxTokens": 32768
1823
- },
1824
- "output": {
1825
- "maxTokens": 32768
1826
- }
1827
- },
1828
- {
1829
- "id": "fireworks-ai__accounts/fireworks/models/mythomax-l2-13b",
1830
- "name": "MythoMax L2 13b",
1831
- "integration": "fireworks-ai",
1832
- "input": {
1833
- "maxTokens": 4096
1834
- },
1835
- "output": {
1836
- "maxTokens": 4096
1837
- }
1838
- },
1839
- {
1840
- "id": "fireworks-ai__accounts/fireworks/models/qwen2-72b-instruct",
1841
- "name": "Qwen2 72b Instruct",
1842
- "integration": "fireworks-ai",
1843
- "input": {
1844
- "maxTokens": 32768
1845
- },
1846
- "output": {
1847
- "maxTokens": 32768
1848
- }
1849
- },
1850
- {
1851
- "id": "groq__gemma2-9b-it",
1852
- "name": "Gemma2 9B",
1853
- "integration": "groq",
1854
- "input": {
1855
- "maxTokens": 8192
1856
- },
1857
- "output": {
1858
- "maxTokens": 8192
1859
- }
1860
- },
1861
- {
1862
- "id": "groq__llama3-70b-8192",
1863
- "name": "LLaMA 3 70B",
1864
- "integration": "groq",
1865
- "input": {
1866
- "maxTokens": 8192
1867
- },
1868
- "output": {
1869
- "maxTokens": 8192
1870
- }
1871
- },
1872
- {
1873
- "id": "groq__llama3-8b-8192",
1874
- "name": "LLaMA 3 8B",
1875
- "integration": "groq",
1876
- "input": {
1877
- "maxTokens": 8192
1878
- },
1879
- "output": {
1880
- "maxTokens": 8192
1881
- }
1882
- },
1883
- {
1884
- "id": "groq__llama-3.1-70b-versatile",
1885
- "name": "LLaMA 3.1 70B",
1886
- "integration": "groq",
1887
- "input": {
1888
- "maxTokens": 128e3
1889
- },
1890
- "output": {
1891
- "maxTokens": 8192
1892
- }
1893
- },
1894
- {
1895
- "id": "groq__llama-3.1-8b-instant",
1896
- "name": "LLaMA 3.1 8B",
1897
- "integration": "groq",
1898
- "input": {
1899
- "maxTokens": 128e3
1900
- },
1901
- "output": {
1902
- "maxTokens": 8192
1903
- }
1904
- },
1905
- {
1906
- "id": "groq__llama-3.2-11b-vision-preview",
1907
- "name": "LLaMA 3.2 11B Vision",
1908
- "integration": "groq",
1909
- "input": {
1910
- "maxTokens": 128e3
1911
- },
1912
- "output": {
1913
- "maxTokens": 8192
1914
- }
1915
- },
1916
- {
1917
- "id": "groq__llama-3.2-1b-preview",
1918
- "name": "LLaMA 3.2 1B",
1919
- "integration": "groq",
1920
- "input": {
1921
- "maxTokens": 128e3
1922
- },
1923
- "output": {
1924
- "maxTokens": 8192
1925
- }
1926
- },
1927
- {
1928
- "id": "groq__llama-3.2-3b-preview",
1929
- "name": "LLaMA 3.2 3B",
1930
- "integration": "groq",
1931
- "input": {
1932
- "maxTokens": 128e3
1933
- },
1934
- "output": {
1935
- "maxTokens": 8192
1936
- }
1937
- },
1938
- {
1939
- "id": "groq__llama-3.2-90b-vision-preview",
1940
- "name": "LLaMA 3.2 90B Vision",
1941
- "integration": "groq",
1942
- "input": {
1943
- "maxTokens": 128e3
1944
- },
1945
- "output": {
1946
- "maxTokens": 8192
1947
- }
1948
- },
1949
- {
1950
- "id": "groq__llama-3.3-70b-versatile",
1951
- "name": "LLaMA 3.3 70B",
1952
- "integration": "groq",
1953
- "input": {
1954
- "maxTokens": 128e3
1955
- },
1956
- "output": {
1957
- "maxTokens": 32768
1958
- }
1959
- },
1960
- {
1961
- "id": "groq__mixtral-8x7b-32768",
1962
- "name": "Mixtral 8x7B",
1963
- "integration": "groq",
1964
- "input": {
1965
- "maxTokens": 32768
1966
- },
1967
- "output": {
1968
- "maxTokens": 32768
1969
- }
1970
- },
1971
- {
1972
- "id": "openai__o1-2024-12-17",
1973
- "name": "GPT o1",
1974
- "integration": "openai",
1975
- "input": {
1976
- "maxTokens": 2e5
1977
- },
1978
- "output": {
1979
- "maxTokens": 1e5
1980
- }
1981
- },
1982
- {
1983
- "id": "openai__o1-mini-2024-09-12",
1984
- "name": "GPT o1-mini",
1985
- "integration": "openai",
1986
- "input": {
1987
- "maxTokens": 128e3
1988
- },
1989
- "output": {
1990
- "maxTokens": 65536
1991
- }
1992
- },
1993
- {
1994
- "id": "openai__gpt-3.5-turbo-0125",
1995
- "name": "GPT-3.5 Turbo",
1996
- "integration": "openai",
1997
- "input": {
1998
- "maxTokens": 128e3
1999
- },
2000
- "output": {
2001
- "maxTokens": 4096
2002
- }
2003
- },
2004
- {
2005
- "id": "openai__gpt-4-turbo-2024-04-09",
2006
- "name": "GPT-4 Turbo",
2007
- "integration": "openai",
2008
- "input": {
2009
- "maxTokens": 128e3
2010
- },
2011
- "output": {
2012
- "maxTokens": 4096
2013
- }
2014
- },
2015
- {
2016
- "id": "openai__gpt-4o-2024-08-06",
2017
- "name": "GPT-4o (August 2024)",
2018
- "integration": "openai",
2019
- "input": {
2020
- "maxTokens": 128e3
2021
- },
2022
- "output": {
2023
- "maxTokens": 16384
2024
- }
2025
- },
2026
- {
2027
- "id": "openai__gpt-4o-2024-05-13",
2028
- "name": "GPT-4o (May 2024)",
2029
- "integration": "openai",
2030
- "input": {
2031
- "maxTokens": 128e3
2032
- },
2033
- "output": {
2034
- "maxTokens": 4096
2035
- }
2036
- },
2037
- {
2038
- "id": "openai__gpt-4o-2024-11-20",
2039
- "name": "GPT-4o (November 2024)",
2040
- "integration": "openai",
2041
- "input": {
2042
- "maxTokens": 128e3
2043
- },
2044
- "output": {
2045
- "maxTokens": 16384
2046
- }
2047
- },
2048
- {
2049
- "id": "openai__gpt-4o-mini-2024-07-18",
2050
- "name": "GPT-4o Mini",
2051
- "integration": "openai",
2052
- "input": {
2053
- "maxTokens": 128e3
2054
- },
2055
- "output": {
2056
- "maxTokens": 16384
2057
- }
2058
- }
2059
- ];
2060
-
2061
- // src/zai.ts
2062
- var ActiveLearning = import_zui3.z.object({
2063
- enable: import_zui3.z.boolean().describe("Whether to enable active learning").default(false),
2064
- tableName: import_zui3.z.string().regex(
2065
- /^[A-Za-z0-9_/-]{1,100}Table$/,
2066
- "Namespace must be alphanumeric and contain only letters, numbers, underscores, hyphens and slashes"
2067
- ).describe("The name of the table to store active learning tasks").default("ActiveLearningTable"),
2068
- taskId: import_zui3.z.string().regex(
2069
- /^[A-Za-z0-9_/-]{1,100}$/,
2070
- "Namespace must be alphanumeric and contain only letters, numbers, underscores, hyphens and slashes"
2071
- ).describe("The ID of the task").default("default")
2072
- });
2073
- var ZaiConfig = import_zui3.z.object({
2074
- client: BotpressClient,
2075
- userId: import_zui3.z.string().describe("The ID of the user consuming the API").optional(),
2076
- retry: import_zui3.z.object({ maxRetries: import_zui3.z.number().min(0).max(100) }).default({ maxRetries: 3 }),
2077
- modelId: import_zui3.z.custom(
2078
- (value) => {
2079
- if (typeof value !== "string" || !value.includes("__")) {
2080
- return false;
2081
- }
2082
- return true;
2083
- },
2084
- {
2085
- message: "Invalid model ID"
2086
- }
2087
- ).describe("The ID of the model you want to use").default("openai__gpt-4o-mini-2024-07-18"),
2088
- activeLearning: ActiveLearning.default({ enable: false }),
2089
- namespace: import_zui3.z.string().regex(
2090
- /^[A-Za-z0-9_/-]{1,100}$/,
2091
- "Namespace must be alphanumeric and contain only letters, numbers, underscores, hyphens and slashes"
2092
- ).default("zai")
2093
- });
2094
- var _Zai = class _Zai {
2095
- constructor(config) {
2096
- __publicField(this, "client");
2097
- __publicField(this, "originalConfig");
2098
- __publicField(this, "userId");
2099
- __publicField(this, "integration");
2100
- __publicField(this, "model");
2101
- __publicField(this, "retry");
2102
- __publicField(this, "Model");
2103
- __publicField(this, "namespace");
2104
- __publicField(this, "adapter");
2105
- __publicField(this, "activeLearning");
2106
- var _a;
2107
- this.originalConfig = config;
2108
- const parsed = ZaiConfig.parse(config);
2109
- this.client = parsed.client;
2110
- const [integration, modelId] = parsed.modelId.split("__");
2111
- if (!(integration == null ? void 0 : integration.length) || !(modelId == null ? void 0 : modelId.length)) {
2112
- throw new Error("Invalid model ID: ".concat(parsed.modelId, ". Expected format: <integration>__<modelId>"));
2113
- }
2114
- this.integration = integration;
2115
- this.model = modelId;
2116
- this.namespace = parsed.namespace;
2117
- this.userId = parsed.userId;
2118
- this.retry = parsed.retry;
2119
- this.Model = Models.find((m) => m.id === parsed.modelId);
2120
- this.activeLearning = parsed.activeLearning;
2121
- this.adapter = ((_a = parsed.activeLearning) == null ? void 0 : _a.enable) ? new TableAdapter({ client: this.client, tableName: parsed.activeLearning.tableName }) : new MemoryAdapter([]);
2122
- }
2123
- /** @internal */
2124
- async callModel(props) {
2125
- let retries = this.retry.maxRetries;
2126
- while (retries-- >= 0) {
2127
- try {
2128
- return await this._callModel(props);
2129
- } catch (e) {
2130
- if (retries >= 0) {
2131
- await new Promise((resolve) => setTimeout(resolve, 1e3));
2132
- } else {
2133
- throw new Error("Failed to call model after multiple retries");
2134
- }
2135
- }
2136
- }
2137
- throw new Error("Failed to call model after multiple retries");
2138
- }
2139
- /** @internal */
2140
- async _callModel(props) {
2141
- let retries = this.retry.maxRetries;
2142
- do {
2143
- const start = Date.now();
2144
- const input = __spreadValues({
2145
- messages: [],
2146
- temperature: 0,
2147
- topP: 1,
2148
- model: { id: this.model },
2149
- userId: this.userId
2150
- }, props);
2151
- const { output } = await this.client.callAction({
2152
- type: "".concat(this.integration, ":generateContent"),
2153
- input
2154
- });
2155
- const latency = Date.now() - start;
2156
- return __spreadProps(__spreadValues({}, output), {
2157
- metadata: {
2158
- model: this.model,
2159
- latency,
2160
- cost: { input: output.usage.inputCost, output: output.usage.outputCost },
2161
- tokens: { input: output.usage.inputTokens, output: output.usage.outputTokens }
2162
- }
2163
- });
2164
- } while (--retries > 0);
2165
- }
2166
- async getTokenizer() {
2167
- var _a;
2168
- (_a = _Zai.tokenizer) != null ? _a : _Zai.tokenizer = await (async () => {
2169
- while (!import_wasm.getWasmTokenizer) {
2170
- await new Promise((resolve) => setTimeout(resolve, 25));
2171
- }
2172
- return (0, import_wasm.getWasmTokenizer)();
2173
- })();
2174
- return _Zai.tokenizer;
2175
- }
2176
- get taskId() {
2177
- if (!this.activeLearning.enable) {
2178
- return void 0;
2179
- }
2180
- return "".concat(this.namespace, "/").concat(this.activeLearning.taskId).replace(/\/+/g, "/");
2181
- }
2182
- with(options) {
2183
- return new _Zai(__spreadValues(__spreadValues({}, this.originalConfig), options));
2184
- }
2185
- learn(taskId) {
2186
- return new _Zai(__spreadProps(__spreadValues({}, this.originalConfig), {
2187
- activeLearning: __spreadProps(__spreadValues({}, this.activeLearning), { taskId, enable: true })
2188
- }));
2189
- }
2190
- };
2191
- __publicField(_Zai, "tokenizer", null);
2192
- var Zai = _Zai;
2193
-
2194
- // src/operations/text.ts
2195
- var import_zui4 = __require("@bpinternal/zui");
2196
-
2197
- // node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_freeGlobal.js
2198
- var freeGlobal = typeof global == "object" && global && global.Object === Object && global;
2199
- var freeGlobal_default = freeGlobal;
2200
-
2201
- // node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_root.js
2202
- var freeSelf = typeof self == "object" && self && self.Object === Object && self;
2203
- var root = freeGlobal_default || freeSelf || Function("return this")();
2204
- var root_default = root;
2205
-
2206
- // node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_Symbol.js
2207
- var Symbol2 = root_default.Symbol;
2208
- var Symbol_default = Symbol2;
2209
-
2210
- // node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_getRawTag.js
2211
- var objectProto = Object.prototype;
2212
- var hasOwnProperty = objectProto.hasOwnProperty;
2213
- var nativeObjectToString = objectProto.toString;
2214
- var symToStringTag = Symbol_default ? Symbol_default.toStringTag : void 0;
2215
- function getRawTag(value) {
2216
- var isOwn = hasOwnProperty.call(value, symToStringTag), tag = value[symToStringTag];
2217
- try {
2218
- value[symToStringTag] = void 0;
2219
- var unmasked = true;
2220
- } catch (e) {
2221
- }
2222
- var result = nativeObjectToString.call(value);
2223
- if (unmasked) {
2224
- if (isOwn) {
2225
- value[symToStringTag] = tag;
2226
- } else {
2227
- delete value[symToStringTag];
2228
- }
2229
- }
2230
- return result;
2231
- }
2232
- var getRawTag_default = getRawTag;
2233
-
2234
- // node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_objectToString.js
2235
- var objectProto2 = Object.prototype;
2236
- var nativeObjectToString2 = objectProto2.toString;
2237
- function objectToString(value) {
2238
- return nativeObjectToString2.call(value);
2239
- }
2240
- var objectToString_default = objectToString;
2241
-
2242
- // node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_baseGetTag.js
2243
- var nullTag = "[object Null]";
2244
- var undefinedTag = "[object Undefined]";
2245
- var symToStringTag2 = Symbol_default ? Symbol_default.toStringTag : void 0;
2246
- function baseGetTag(value) {
2247
- if (value == null) {
2248
- return value === void 0 ? undefinedTag : nullTag;
2249
- }
2250
- return symToStringTag2 && symToStringTag2 in Object(value) ? getRawTag_default(value) : objectToString_default(value);
2251
- }
2252
- var baseGetTag_default = baseGetTag;
2253
-
2254
- // node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isObjectLike.js
2255
- function isObjectLike(value) {
2256
- return value != null && typeof value == "object";
2257
- }
2258
- var isObjectLike_default = isObjectLike;
2259
-
2260
- // node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isSymbol.js
2261
- var symbolTag = "[object Symbol]";
2262
- function isSymbol(value) {
2263
- return typeof value == "symbol" || isObjectLike_default(value) && baseGetTag_default(value) == symbolTag;
2264
- }
2265
- var isSymbol_default = isSymbol;
2266
-
2267
- // node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isArray.js
2268
- var isArray = Array.isArray;
2269
- var isArray_default = isArray;
2270
-
2271
- // node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_trimmedEndIndex.js
2272
- var reWhitespace = /\s/;
2273
- function trimmedEndIndex(string) {
2274
- var index = string.length;
2275
- while (index-- && reWhitespace.test(string.charAt(index))) {
2276
- }
2277
- return index;
2278
- }
2279
- var trimmedEndIndex_default = trimmedEndIndex;
2280
-
2281
- // node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_baseTrim.js
2282
- var reTrimStart = /^\s+/;
2283
- function baseTrim(string) {
2284
- return string ? string.slice(0, trimmedEndIndex_default(string) + 1).replace(reTrimStart, "") : string;
2285
- }
2286
- var baseTrim_default = baseTrim;
2287
-
2288
- // node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isObject.js
2289
- function isObject(value) {
2290
- var type = typeof value;
2291
- return value != null && (type == "object" || type == "function");
2292
- }
2293
- var isObject_default = isObject;
2294
-
2295
- // node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/toNumber.js
2296
- var NAN = 0 / 0;
2297
- var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
2298
- var reIsBinary = /^0b[01]+$/i;
2299
- var reIsOctal = /^0o[0-7]+$/i;
2300
- var freeParseInt = parseInt;
2301
- function toNumber(value) {
2302
- if (typeof value == "number") {
2303
- return value;
2304
- }
2305
- if (isSymbol_default(value)) {
2306
- return NAN;
2307
- }
2308
- if (isObject_default(value)) {
2309
- var other = typeof value.valueOf == "function" ? value.valueOf() : value;
2310
- value = isObject_default(other) ? other + "" : other;
2311
- }
2312
- if (typeof value != "string") {
2313
- return value === 0 ? value : +value;
2314
- }
2315
- value = baseTrim_default(value);
2316
- var isBinary = reIsBinary.test(value);
2317
- return isBinary || reIsOctal.test(value) ? freeParseInt(value.slice(2), isBinary ? 2 : 8) : reIsBadHex.test(value) ? NAN : +value;
2318
- }
2319
- var toNumber_default = toNumber;
2320
-
2321
- // node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/toFinite.js
2322
- var INFINITY = 1 / 0;
2323
- var MAX_INTEGER = 17976931348623157e292;
2324
- function toFinite(value) {
2325
- if (!value) {
2326
- return value === 0 ? value : 0;
2327
- }
2328
- value = toNumber_default(value);
2329
- if (value === INFINITY || value === -INFINITY) {
2330
- var sign = value < 0 ? -1 : 1;
2331
- return sign * MAX_INTEGER;
2332
- }
2333
- return value === value ? value : 0;
2334
- }
2335
- var toFinite_default = toFinite;
2336
-
2337
- // node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/toInteger.js
2338
- function toInteger(value) {
2339
- var result = toFinite_default(value), remainder = result % 1;
2340
- return result === result ? remainder ? result - remainder : result : 0;
2341
- }
2342
- var toInteger_default = toInteger;
2343
-
2344
- // node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isFunction.js
2345
- var asyncTag = "[object AsyncFunction]";
2346
- var funcTag = "[object Function]";
2347
- var genTag = "[object GeneratorFunction]";
2348
- var proxyTag = "[object Proxy]";
2349
- function isFunction(value) {
2350
- if (!isObject_default(value)) {
2351
- return false;
2352
- }
2353
- var tag = baseGetTag_default(value);
2354
- return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
2355
- }
2356
- var isFunction_default = isFunction;
2357
-
2358
- // node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_isIndex.js
2359
- var MAX_SAFE_INTEGER = 9007199254740991;
2360
- var reIsUint = /^(?:0|[1-9]\d*)$/;
2361
- function isIndex(value, length) {
2362
- var type = typeof value;
2363
- length = length == null ? MAX_SAFE_INTEGER : length;
2364
- return !!length && (type == "number" || type != "symbol" && reIsUint.test(value)) && (value > -1 && value % 1 == 0 && value < length);
2365
- }
2366
- var isIndex_default = isIndex;
2367
-
2368
- // node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/eq.js
2369
- function eq(value, other) {
2370
- return value === other || value !== value && other !== other;
2371
- }
2372
- var eq_default = eq;
2373
-
2374
- // node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isLength.js
2375
- var MAX_SAFE_INTEGER2 = 9007199254740991;
2376
- function isLength(value) {
2377
- return typeof value == "number" && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER2;
2378
- }
2379
- var isLength_default = isLength;
2380
-
2381
- // node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isArrayLike.js
2382
- function isArrayLike(value) {
2383
- return value != null && isLength_default(value.length) && !isFunction_default(value);
2384
- }
2385
- var isArrayLike_default = isArrayLike;
2386
-
2387
- // node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_isIterateeCall.js
2388
- function isIterateeCall(value, index, object) {
2389
- if (!isObject_default(object)) {
2390
- return false;
2391
- }
2392
- var type = typeof index;
2393
- if (type == "number" ? isArrayLike_default(object) && isIndex_default(index, object.length) : type == "string" && index in object) {
2394
- return eq_default(object[index], value);
2395
- }
2396
- return false;
2397
- }
2398
- var isIterateeCall_default = isIterateeCall;
2399
-
2400
- // node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_baseSlice.js
2401
- function baseSlice(array, start, end) {
2402
- var index = -1, length = array.length;
2403
- if (start < 0) {
2404
- start = -start > length ? 0 : length + start;
2405
- }
2406
- end = end > length ? length : end;
2407
- if (end < 0) {
2408
- end += length;
2409
- }
2410
- length = start > end ? 0 : end - start >>> 0;
2411
- start >>>= 0;
2412
- var result = Array(length);
2413
- while (++index < length) {
2414
- result[index] = array[index + start];
2415
- }
2416
- return result;
2417
- }
2418
- var baseSlice_default = baseSlice;
2419
-
2420
- // node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/chunk.js
2421
- var nativeCeil = Math.ceil;
2422
- var nativeMax = Math.max;
2423
- function chunk(array, size, guard) {
2424
- if (guard ? isIterateeCall_default(array, size, guard) : size === void 0) {
2425
- size = 1;
2426
- } else {
2427
- size = nativeMax(toInteger_default(size), 0);
2428
- }
2429
- var length = array == null ? 0 : array.length;
2430
- if (!length || size < 1) {
2431
- return [];
2432
- }
2433
- var index = 0, resIndex = 0, result = Array(nativeCeil(length / size));
2434
- while (index < length) {
2435
- result[resIndex++] = baseSlice_default(array, index, index += size);
2436
- }
2437
- return result;
2438
- }
2439
- var chunk_default = chunk;
2440
-
2441
- // node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_baseClamp.js
2442
- function baseClamp(number, lower, upper) {
2443
- if (number === number) {
2444
- if (upper !== void 0) {
2445
- number = number <= upper ? number : upper;
2446
- }
2447
- if (lower !== void 0) {
2448
- number = number >= lower ? number : lower;
2449
- }
2450
- }
2451
- return number;
2452
- }
2453
- var baseClamp_default = baseClamp;
2454
-
2455
- // node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/clamp.js
2456
- function clamp(number, lower, upper) {
2457
- if (upper === void 0) {
2458
- upper = lower;
2459
- lower = void 0;
2460
- }
2461
- if (upper !== void 0) {
2462
- upper = toNumber_default(upper);
2463
- upper = upper === upper ? upper : 0;
2464
- }
2465
- if (lower !== void 0) {
2466
- lower = toNumber_default(lower);
2467
- lower = lower === lower ? lower : 0;
2468
- }
2469
- return baseClamp_default(toNumber_default(number), lower, upper);
2470
- }
2471
- var clamp_default = clamp;
2472
-
2473
- // src/operations/constants.ts
2474
- var PROMPT_INPUT_BUFFER = 1048;
2475
- var PROMPT_OUTPUT_BUFFER = 512;
2476
-
2477
- // src/operations/text.ts
2478
- var Options = import_zui4.z.object({
2479
- length: import_zui4.z.number().min(1).max(1e5).optional().describe("The maximum number of tokens to generate")
2480
- });
2481
- Zai.prototype.text = async function(prompt, _options) {
2482
- var _a, _b;
2483
- const options = Options.parse(_options != null ? _options : {});
2484
- const tokenizer = await this.getTokenizer();
2485
- prompt = tokenizer.truncate(prompt, Math.max(this.Model.input.maxTokens - PROMPT_INPUT_BUFFER, 100));
2486
- if (options.length) {
2487
- options.length = Math.min(this.Model.output.maxTokens - PROMPT_OUTPUT_BUFFER, options.length);
2488
- }
2489
- const instructions = [];
2490
- let chart = "";
2491
- if (options.length) {
2492
- const length = clamp_default(options.length * 0.75, 5, options.length);
2493
- instructions.push("IMPORTANT: Length constraint: ".concat(length, " tokens/words"));
2494
- instructions.push("The text must be standalone and complete in less than ".concat(length, " tokens/words"));
2495
- }
2496
- if (options.length && options.length <= 500) {
2497
- chart = "\n| Tokens | Text Length (approximate) |\n|-------------|--------------------------------------|\n| < 5 tokens | 1-3 words |\n| 5-10 tokens | 3-6 words |\n| 10-20 tokens| 6-15 words |\n| 20-50 tokens| A short sentence (15-30 words) |\n| 50-100 tokens| A medium sentence (30-70 words) |\n| 100-200 tokens| A short paragraph (70-150 words) |\n| 200-300 tokens| A medium paragraph (150-200 words) |\n| 300-500 tokens| A long paragraph (200-300 words) |".trim();
2498
- }
2499
- const output = await this.callModel({
2500
- systemPrompt: "\nGenerate a text that fulfills the user prompt below. Answer directly to the prompt, without any acknowledgements or fluff. Also, make sure the text is standalone and complete.\n".concat(instructions.map((x) => "- ".concat(x)).join("\n"), "\n").concat(chart, "\n").trim(),
2501
- temperature: 0.7,
2502
- messages: [{ type: "text", content: prompt, role: "user" }],
2503
- maxTokens: options.length
2504
- });
2505
- return (_b = (_a = output == null ? void 0 : output.choices) == null ? void 0 : _a[0]) == null ? void 0 : _b.content;
2506
- };
2507
-
2508
- // src/operations/rewrite.ts
2509
- var import_zui5 = __require("@bpinternal/zui");
2510
- var Example = import_zui5.z.object({
2511
- input: import_zui5.z.string(),
2512
- output: import_zui5.z.string()
2513
- });
2514
- var Options2 = import_zui5.z.object({
2515
- examples: import_zui5.z.array(Example).default([]),
2516
- length: import_zui5.z.number().min(10).max(16e3).optional().describe("The maximum number of tokens to generate")
2517
- });
2518
- var START = "\u25A0START\u25A0";
2519
- var END = "\u25A0END\u25A0";
2520
- Zai.prototype.rewrite = async function(original, prompt, _options) {
2521
- var _a;
2522
- const options = Options2.parse(_options != null ? _options : {});
2523
- const tokenizer = await this.getTokenizer();
2524
- const taskId = this.taskId;
2525
- const taskType = "zai.rewrite";
2526
- const INPUT_COMPONENT_SIZE = Math.max(100, (this.Model.input.maxTokens - PROMPT_INPUT_BUFFER) / 2);
2527
- prompt = tokenizer.truncate(prompt, INPUT_COMPONENT_SIZE);
2528
- const inputSize = tokenizer.count(original) + tokenizer.count(prompt);
2529
- const maxInputSize = this.Model.input.maxTokens - tokenizer.count(prompt) - PROMPT_INPUT_BUFFER;
2530
- if (inputSize > maxInputSize) {
2531
- throw new Error(
2532
- "The input size is ".concat(inputSize, " tokens long, which is more than the maximum of ").concat(maxInputSize, " tokens for this model (").concat(this.Model.name, " = ").concat(this.Model.input.maxTokens, " tokens)")
2533
- );
2534
- }
2535
- const instructions = [];
2536
- const originalSize = tokenizer.count(original);
2537
- if (options.length && originalSize > options.length) {
2538
- instructions.push("The original text is ".concat(originalSize, " tokens long \u2013 it should be less than ").concat(options.length));
2539
- instructions.push(
2540
- "The text must be standalone and complete in less than ".concat(options.length, " tokens, so it has to be shortened to fit the length as well")
2541
- );
2542
- }
2543
- const format = (before, prompt2) => {
2544
- return "\nPrompt: ".concat(prompt2, "\n\n").concat(START, "\n").concat(before, "\n").concat(END, "\n").trim();
2545
- };
2546
- const Key = fastHash(
2547
- stringify({
2548
- taskId,
2549
- taskType,
2550
- input: original,
2551
- prompt
2552
- })
2553
- );
2554
- const formatExample = ({ input, output: output2, instructions: instructions2 }) => {
2555
- return [
2556
- { type: "text", role: "user", content: format(input, instructions2 || prompt) },
2557
- { type: "text", role: "assistant", content: "".concat(START).concat(output2).concat(END) }
2558
- ];
2559
- };
2560
- const defaultExamples = [
2561
- { input: "Hello, how are you?", output: "Bonjour, comment \xE7a va?", instructions: "translate to French" },
2562
- { input: "1\n2\n3", output: "3\n2\n1", instructions: "reverse the order" }
2563
- ];
2564
- const tableExamples = taskId ? await this.adapter.getExamples({
2565
- input: original,
2566
- taskId,
2567
- taskType
2568
- }) : [];
2569
- const exactMatch = tableExamples.find((x) => x.key === Key);
2570
- if (exactMatch) {
2571
- return exactMatch.output;
2572
- }
2573
- const savedExamples = [
2574
- ...tableExamples.map((x) => ({ input: x.input, output: x.output })),
2575
- ...options.examples
2576
- ];
2577
- const REMAINING_TOKENS = this.Model.input.maxTokens - tokenizer.count(prompt) - PROMPT_INPUT_BUFFER;
2578
- const examples = takeUntilTokens(
2579
- savedExamples.length ? savedExamples : defaultExamples,
2580
- REMAINING_TOKENS,
2581
- (el) => tokenizer.count(stringify(el.input)) + tokenizer.count(stringify(el.output))
2582
- ).map(formatExample).flat();
2583
- const output = await this.callModel({
2584
- systemPrompt: "\nRewrite the text between the ".concat(START, " and ").concat(END, " tags to match the user prompt.\n").concat(instructions.map((x) => "\u2022 ".concat(x)).join("\n"), "\n").trim(),
2585
- messages: [...examples, { type: "text", content: format(original, prompt), role: "user" }],
2586
- maxTokens: options.length,
2587
- stopSequences: [END]
2588
- });
2589
- let result = (_a = output.choices[0]) == null ? void 0 : _a.content;
2590
- if (result.includes(START)) {
2591
- result = result.slice(result.indexOf(START) + START.length);
2592
- }
2593
- if (result.includes(END)) {
2594
- result = result.slice(0, result.indexOf(END));
2595
- }
2596
- if (taskId) {
2597
- await this.adapter.saveExample({
2598
- key: Key,
2599
- metadata: output.metadata,
2600
- instructions: prompt,
2601
- input: original,
2602
- output: result,
2603
- taskType,
2604
- taskId
2605
- });
2606
- }
2607
- return result;
2608
- };
2609
-
2610
- // src/operations/summarize.ts
2611
- var import_zui6 = __require("@bpinternal/zui");
2612
- var Options3 = import_zui6.z.object({
2613
- prompt: import_zui6.z.string().describe("What should the text be summarized to?").default("New information, concepts and ideas that are deemed important"),
2614
- format: import_zui6.z.string().describe("How to format the example text").default(
2615
- "A normal text with multiple sentences and paragraphs. Use markdown to format the text into sections. Use headings, lists, and other markdown features to make the text more readable. Do not include links, images, or other non-text elements."
2616
- ),
2617
- length: import_zui6.z.number().min(10).max(1e5).describe("The length of the summary in tokens").default(250),
2618
- intermediateFactor: import_zui6.z.number().min(1).max(10).describe("How many times longer (than final length) are the intermediate summaries generated").default(4),
2619
- maxIterations: import_zui6.z.number().min(1).default(100),
2620
- sliding: import_zui6.z.object({
2621
- window: import_zui6.z.number().min(10).max(1e5),
2622
- overlap: import_zui6.z.number().min(0).max(1e5)
2623
- }).describe("Sliding window options").default({ window: 5e4, overlap: 250 })
2624
- });
2625
- var START2 = "\u25A0START\u25A0";
2626
- var END2 = "\u25A0END\u25A0";
2627
- Zai.prototype.summarize = async function(original, _options) {
2628
- var _a;
2629
- const options = Options3.parse(_options != null ? _options : {});
2630
- const tokenizer = await this.getTokenizer();
2631
- const INPUT_COMPONENT_SIZE = Math.max(100, (this.Model.input.maxTokens - PROMPT_INPUT_BUFFER) / 4);
2632
- options.prompt = tokenizer.truncate(options.prompt, INPUT_COMPONENT_SIZE);
2633
- options.format = tokenizer.truncate(options.format, INPUT_COMPONENT_SIZE);
2634
- const maxOutputSize = this.Model.output.maxTokens - PROMPT_OUTPUT_BUFFER;
2635
- if (options.length > maxOutputSize) {
2636
- throw new Error(
2637
- "The desired output length is ".concat(maxOutputSize, " tokens long, which is more than the maximum of ").concat(this.Model.output.maxTokens, " tokens for this model (").concat(this.Model.name, ")")
2638
- );
2639
- }
2640
- options.sliding.window = Math.min(options.sliding.window, this.Model.input.maxTokens - PROMPT_INPUT_BUFFER);
2641
- options.sliding.overlap = Math.min(options.sliding.overlap, options.sliding.window - 3 * options.sliding.overlap);
2642
- const format = (summary, newText) => {
2643
- return "\n".concat(START2, "\n").concat(summary.length ? summary : "<summary still empty>", "\n").concat(END2, "\n\nPlease amend the summary between the ").concat(START2, " and ").concat(END2, " tags to accurately reflect the prompt and the additional text below.\n\n<|start_new_information|>\n").concat(newText, "\n<|new_information|>").trim();
2644
- };
2645
- const tokens = tokenizer.split(original);
2646
- const parts = Math.ceil(tokens.length / (options.sliding.window - options.sliding.overlap));
2647
- let iteration = 0;
2648
- const N = 2;
2649
- const useMergeSort = parts >= Math.pow(2, N);
2650
- const chunkSize = Math.ceil(tokens.length / (parts * N));
2651
- if (useMergeSort) {
2652
- const chunks = chunk_default(tokens, chunkSize).map((x) => x.join(""));
2653
- const allSummaries = await Promise.all(chunks.map((chunk2) => this.summarize(chunk2, options)));
2654
- return this.summarize(allSummaries.join("\n\n============\n\n"), options);
2655
- }
2656
- const summaries = [];
2657
- let currentSummary = "";
2658
- for (let i = 0; i < tokens.length; i += options.sliding.window) {
2659
- const from = Math.max(0, i - options.sliding.overlap);
2660
- const to = Math.min(tokens.length, i + options.sliding.window + options.sliding.overlap);
2661
- const isFirst = i === 0;
2662
- const isLast = to >= tokens.length;
2663
- const slice = tokens.slice(from, to).join("");
2664
- if (iteration++ >= options.maxIterations) {
2665
- break;
2666
- }
2667
- const instructions = [
2668
- "At each step, you will receive a part of the text to summarize. Make sure to reply with the new summary in the tags ".concat(START2, " and ").concat(END2, "."),
2669
- "Summarize the text and make sure that the main points are included.",
2670
- "Ignore any unnecessary details and focus on the main points.",
2671
- "Use short and concise sentences to increase readability and information density.",
2672
- "When looking at the new information, focus on: " + options.prompt
2673
- ];
2674
- if (isFirst) {
2675
- instructions.push(
2676
- "The current summary is empty. You need to generate a summary that covers the main points of the text."
2677
- );
2678
- }
2679
- let generationLength = options.length;
2680
- if (!isLast) {
2681
- generationLength = Math.min(
2682
- tokenizer.count(currentSummary) + options.length * options.intermediateFactor,
2683
- maxOutputSize
2684
- );
2685
- instructions.push(
2686
- "You need to amend the summary to include the new information. Make sure the summary is complete and covers all the main points."
2687
- );
2688
- instructions.push("The current summary is ".concat(currentSummary.length, " tokens long."));
2689
- instructions.push("You can amend the summary to be up to ".concat(generationLength, " tokens long."));
2690
- }
2691
- if (isLast) {
2692
- instructions.push(
2693
- "This is the last part you will have to summarize. Make sure the summary is complete and covers all the main points."
2694
- );
2695
- instructions.push(
2696
- "The current summary is ".concat(currentSummary.length, " tokens long. You need to make sure it is ").concat(options.length, " tokens or less.")
2697
- );
2698
- if (currentSummary.length > options.length) {
2699
- instructions.push(
2700
- "The current summary is already too long, so you need to shorten it to ".concat(options.length, " tokens while also including the new information.")
2701
- );
2702
- }
2703
- }
2704
- const output = await this.callModel({
2705
- systemPrompt: "\nYou are summarizing a text. The text is split into ".concat(parts, " parts, and you are currently working on part ").concat(iteration, ".\nAt every step, you will receive the current summary and a new part of the text. You need to amend the summary to include the new information (if needed).\nThe summary needs to cover the main points of the text and must be concise.\n\nIMPORTANT INSTRUCTIONS:\n").concat(instructions.map((x) => "- ".concat(x.trim())).join("\n"), "\n\nFORMAT OF THE SUMMARY:\n").concat(options.format, "\n").trim(),
2706
- messages: [{ type: "text", content: format(currentSummary, slice), role: "user" }],
2707
- maxTokens: generationLength,
2708
- stopSequences: [END2]
2709
- });
2710
- let result = (_a = output == null ? void 0 : output.choices[0]) == null ? void 0 : _a.content;
2711
- if (result.includes(START2)) {
2712
- result = result.slice(result.indexOf(START2) + START2.length);
2713
- }
2714
- if (result.includes("\u25A0")) {
2715
- result = result.slice(0, result.indexOf("\u25A0"));
2716
- }
2717
- summaries.push(result);
2718
- currentSummary = result;
2719
- }
2720
- return currentSummary.trim();
2721
- };
2722
-
2723
- // src/operations/check.ts
2724
- var import_zui7 = __require("@bpinternal/zui");
2725
- var Example2 = import_zui7.z.object({
2726
- input: import_zui7.z.any(),
2727
- check: import_zui7.z.boolean(),
2728
- reason: import_zui7.z.string().optional()
2729
- });
2730
- var Options4 = import_zui7.z.object({
2731
- examples: import_zui7.z.array(Example2).describe("Examples to check the condition against").default([])
2732
- });
2733
- var TRUE = "\u25A0TRUE\u25A0";
2734
- var FALSE = "\u25A0FALSE\u25A0";
2735
- var END3 = "\u25A0END\u25A0";
2736
- Zai.prototype.check = async function(input, condition, _options) {
2737
- var _a;
2738
- const options = Options4.parse(_options != null ? _options : {});
2739
- const tokenizer = await this.getTokenizer();
2740
- const PROMPT_COMPONENT = Math.max(this.Model.input.maxTokens - PROMPT_INPUT_BUFFER, 100);
2741
- const taskId = this.taskId;
2742
- const taskType = "zai.check";
2743
- const PROMPT_TOKENS = {
2744
- INPUT: Math.floor(0.5 * PROMPT_COMPONENT),
2745
- CONDITION: Math.floor(0.2 * PROMPT_COMPONENT)
2746
- };
2747
- const inputAsString = tokenizer.truncate(stringify(input), PROMPT_TOKENS.INPUT);
2748
- condition = tokenizer.truncate(condition, PROMPT_TOKENS.CONDITION);
2749
- const EXAMPLES_TOKENS = PROMPT_COMPONENT - tokenizer.count(inputAsString) - tokenizer.count(condition);
2750
- const Key = fastHash(
2751
- JSON.stringify({
2752
- taskType,
2753
- taskId,
2754
- input: inputAsString,
2755
- condition
2756
- })
2757
- );
2758
- const examples = taskId ? await this.adapter.getExamples({
2759
- input: inputAsString,
2760
- taskType,
2761
- taskId
2762
- }) : [];
2763
- const exactMatch = examples.find((x) => x.key === Key);
2764
- if (exactMatch) {
2765
- return exactMatch.output;
2766
- }
2767
- const defaultExamples = [
2768
- { input: "50 Cent", check: true, reason: "50 Cent is widely recognized as a public personality." },
2769
- {
2770
- input: ["apple", "banana", "carrot", "house"],
2771
- check: false,
2772
- reason: "The list contains a house, which is not a fruit. Also, the list contains a carrot, which is a vegetable."
2773
- }
2774
- ];
2775
- const userExamples = [
2776
- ...examples.map((e) => ({ input: e.input, check: e.output, reason: e.explanation })),
2777
- ...options.examples
2778
- ];
2779
- let exampleId = 1;
2780
- const formatInput = (input2, condition2) => {
2781
- const header = userExamples.length ? "Expert Example #".concat(exampleId++) : 'Example of condition: "'.concat(condition2, '"');
2782
- return "\n".concat(header, "\n<|start_input|>\n").concat(input2.trim(), "\n<|end_input|>\n").trim();
2783
- };
2784
- const formatOutput = (answer2, justification) => {
2785
- return "\nAnalysis: ".concat(justification, "\nFinal Answer: ").concat(answer2 ? TRUE : FALSE, "\n").concat(END3, "\n").trim();
2786
- };
2787
- const formatExample = (example) => {
2788
- var _a2, _b;
2789
- return [
2790
- { type: "text", content: formatInput(stringify((_a2 = example.input) != null ? _a2 : null), condition), role: "user" },
2791
- {
2792
- type: "text",
2793
- content: formatOutput(example.check, (_b = example.reason) != null ? _b : ""),
2794
- role: "assistant"
2795
- }
2796
- ];
2797
- };
2798
- const allExamples = takeUntilTokens(
2799
- userExamples.length ? userExamples : defaultExamples,
2800
- EXAMPLES_TOKENS,
2801
- (el) => {
2802
- var _a2;
2803
- return tokenizer.count(stringify(el.input)) + tokenizer.count((_a2 = el.reason) != null ? _a2 : "");
2804
- }
2805
- ).map(formatExample).flat();
2806
- const specialInstructions = userExamples.length ? "\n- You have been provided with examples from previous experts. Make sure to read them carefully before making your decision.\n- Make sure to refer to the examples provided by the experts to justify your decision (when applicable).\n- When in doubt, ground your decision on the examples provided by the experts instead of your own intuition.\n- When no example is similar to the input, make sure to provide a clear justification for your decision while inferring the decision-making process from the examples provided by the experts.\n".trim() : "";
2807
- const output = await this.callModel({
2808
- systemPrompt: "\nCheck if the following condition is true or false for the given input. Before answering, make sure to read the input and the condition carefully.\nJustify your answer, then answer with either ".concat(TRUE, " or ").concat(FALSE, " at the very end, then add ").concat(END3, " to finish the response.\nIMPORTANT: Make sure to answer with either ").concat(TRUE, " or ").concat(FALSE, " at the end of your response, but NOT both.\n---\nExpert Examples (#1 to #").concat(exampleId - 1, "):\n").concat(specialInstructions, "\n").trim(),
2809
- stopSequences: [END3],
2810
- messages: [
2811
- ...allExamples,
2812
- {
2813
- type: "text",
2814
- content: "\nConsidering the below input and above examples, is the following condition true or false?\n".concat(formatInput(inputAsString, condition), '\nIn your "Analysis", please refer to the Expert Examples # to justify your decision.').trim(),
2815
- role: "user"
2816
- }
2817
- ]
2818
- });
2819
- const answer = (_a = output.choices[0]) == null ? void 0 : _a.content;
2820
- const hasTrue = answer.includes(TRUE);
2821
- const hasFalse = answer.includes(FALSE);
2822
- if (!hasTrue && !hasFalse) {
2823
- throw new Error("The model did not return a valid answer. The response was: ".concat(answer));
2824
- }
2825
- let finalAnswer;
2826
- if (hasTrue && hasFalse) {
2827
- finalAnswer = answer.lastIndexOf(TRUE) > answer.lastIndexOf(FALSE);
2828
- } else {
2829
- finalAnswer = hasTrue;
2830
- }
2831
- if (taskId) {
2832
- await this.adapter.saveExample({
2833
- key: Key,
2834
- taskType,
2835
- taskId,
2836
- input: inputAsString,
2837
- instructions: condition,
2838
- metadata: output.metadata,
2839
- output: finalAnswer,
2840
- explanation: answer.replace(TRUE, "").replace(FALSE, "").replace(END3, "").replace("Final Answer:", "").trim()
2841
- });
2842
- }
2843
- return finalAnswer;
2844
- };
2845
-
2846
- // src/operations/filter.ts
2847
- var import_zui8 = __require("@bpinternal/zui");
2848
- var Example3 = import_zui8.z.object({
2849
- input: import_zui8.z.any(),
2850
- filter: import_zui8.z.boolean(),
2851
- reason: import_zui8.z.string().optional()
2852
- });
2853
- var Options5 = import_zui8.z.object({
2854
- tokensPerItem: import_zui8.z.number().min(1).max(1e5).optional().describe("The maximum number of tokens per item").default(250),
2855
- examples: import_zui8.z.array(Example3).describe("Examples to filter the condition against").default([])
2856
- });
2857
- var END4 = "\u25A0END\u25A0";
2858
- Zai.prototype.filter = async function(input, condition, _options) {
2859
- const options = Options5.parse(_options != null ? _options : {});
2860
- const tokenizer = await this.getTokenizer();
2861
- const taskId = this.taskId;
2862
- const taskType = "zai.filter";
2863
- const MAX_ITEMS_PER_CHUNK = 50;
2864
- const TOKENS_TOTAL_MAX = this.Model.input.maxTokens - PROMPT_INPUT_BUFFER - PROMPT_OUTPUT_BUFFER;
2865
- const TOKENS_EXAMPLES_MAX = Math.floor(Math.max(250, TOKENS_TOTAL_MAX * 0.5));
2866
- const TOKENS_CONDITION_MAX = clamp_default(TOKENS_TOTAL_MAX * 0.25, 250, tokenizer.count(condition));
2867
- const TOKENS_INPUT_ARRAY_MAX = TOKENS_TOTAL_MAX - TOKENS_EXAMPLES_MAX - TOKENS_CONDITION_MAX;
2868
- condition = tokenizer.truncate(condition, TOKENS_CONDITION_MAX);
2869
- let chunks = [];
2870
- let currentChunk = [];
2871
- let currentChunkTokens = 0;
2872
- for (const element of input) {
2873
- const elementAsString = tokenizer.truncate(stringify(element, false), options.tokensPerItem);
2874
- const elementTokens = tokenizer.count(elementAsString);
2875
- if (currentChunkTokens + elementTokens > TOKENS_INPUT_ARRAY_MAX || currentChunk.length >= MAX_ITEMS_PER_CHUNK) {
2876
- chunks.push(currentChunk);
2877
- currentChunk = [];
2878
- currentChunkTokens = 0;
2879
- }
2880
- currentChunk.push(element);
2881
- currentChunkTokens += elementTokens;
2882
- }
2883
- if (currentChunk.length > 0) {
2884
- chunks.push(currentChunk);
2885
- }
2886
- chunks = chunks.filter((x) => x.length > 0);
2887
- const formatInput = (input2, condition2) => {
2888
- return "\nCondition to check:\n".concat(condition2, "\n\nItems (from \u25A00 to \u25A0").concat(input2.length - 1, ")\n==============================\n").concat(input2.map((x, idx) => {
2889
- var _a;
2890
- return "\u25A0".concat(idx, " = ").concat(stringify((_a = x.input) != null ? _a : null, false));
2891
- }).join("\n"), "\n").trim();
2892
- };
2893
- const formatExamples = (examples) => {
2894
- return "\n".concat(examples.map((x, idx) => "\u25A0".concat(idx, ":").concat(!!x.filter ? "true" : "false")).join(""), "\n").concat(END4, "\n====\nHere's the reasoning behind each example:\n").concat(examples.map((x, idx) => {
2895
- var _a;
2896
- return "\u25A0".concat(idx, ":").concat(!!x.filter ? "true" : "false", ":").concat((_a = x.reason) != null ? _a : "No reason provided");
2897
- }).join("\n"), "\n").trim();
2898
- };
2899
- const genericExamples = [
2900
- {
2901
- input: "apple",
2902
- filter: true,
2903
- reason: "Apples are fruits"
2904
- },
2905
- {
2906
- input: "Apple Inc.",
2907
- filter: false,
2908
- reason: "Apple Inc. is a company, not a fruit"
2909
- },
2910
- {
2911
- input: "banana",
2912
- filter: true,
2913
- reason: "Bananas are fruits"
2914
- },
2915
- {
2916
- input: "potato",
2917
- filter: false,
2918
- reason: "Potatoes are vegetables"
2919
- }
2920
- ];
2921
- const genericExamplesMessages = [
2922
- {
2923
- type: "text",
2924
- content: formatInput(genericExamples, "is a fruit"),
2925
- role: "user"
2926
- },
2927
- {
2928
- type: "text",
2929
- content: formatExamples(genericExamples),
2930
- role: "assistant"
2931
- }
2932
- ];
2933
- const filterChunk = async (chunk2) => {
2934
- var _a, _b;
2935
- const examples = taskId ? await this.adapter.getExamples({
2936
- // The Table API can't search for a huge input string
2937
- input: JSON.stringify(chunk2).slice(0, 1e3),
2938
- taskType,
2939
- taskId
2940
- }).then(
2941
- (x) => x.map((y) => ({ filter: y.output, input: y.input, reason: y.explanation }))
2942
- ) : [];
2943
- const allExamples = takeUntilTokens(
2944
- [...examples, ...(_a = options.examples) != null ? _a : []],
2945
- TOKENS_EXAMPLES_MAX,
2946
- (el) => tokenizer.count(stringify(el.input))
2947
- );
2948
- const exampleMessages = [
2949
- {
2950
- type: "text",
2951
- content: formatInput(allExamples, condition),
2952
- role: "user"
2953
- },
2954
- {
2955
- type: "text",
2956
- content: formatExamples(allExamples),
2957
- role: "assistant"
2958
- }
2959
- ];
2960
- const output = await this.callModel({
2961
- systemPrompt: '\nYou are given a list of items. Your task is to filter out the items that meet the condition below.\nYou need to return the full list of items with the format:\n\u25A0x:true\u25A0y:false\u25A0z:true (where x, y, z are the indices of the items in the list)\nYou need to start with "\u25A00" and go up to the last index "\u25A0'.concat(chunk2.length - 1, '".\nIf an item meets the condition, you should return ":true", otherwise ":false".\n\nIMPORTANT: Make sure to read the condition and the examples carefully before making your decision.\nThe condition is: "').concat(condition, '"\n').trim(),
2962
- stopSequences: [END4],
2963
- messages: [
2964
- ...exampleMessages.length ? exampleMessages : genericExamplesMessages,
2965
- {
2966
- type: "text",
2967
- content: formatInput(
2968
- chunk2.map((x) => ({ input: x })),
2969
- condition
2970
- ),
2971
- role: "user"
2972
- }
2973
- ]
2974
- });
2975
- const answer = (_b = output.choices[0]) == null ? void 0 : _b.content;
2976
- const indices = answer.trim().split("\u25A0").filter((x) => x.length > 0).map((x) => {
2977
- var _a2;
2978
- const [idx, filter] = x.split(":");
2979
- return { idx: parseInt((_a2 = idx == null ? void 0 : idx.trim()) != null ? _a2 : ""), filter: (filter == null ? void 0 : filter.toLowerCase().trim()) === "true" };
2980
- });
2981
- const partial = chunk2.filter((_, idx) => {
2982
- var _a2, _b2;
2983
- return (_b2 = (_a2 = indices.find((x) => x.idx === idx)) == null ? void 0 : _a2.filter) != null ? _b2 : false;
2984
- });
2985
- if (taskId) {
2986
- const key = fastHash(
2987
- stringify({
2988
- taskId,
2989
- taskType,
2990
- input: JSON.stringify(chunk2),
2991
- condition
2992
- })
2993
- );
2994
- await this.adapter.saveExample({
2995
- key,
2996
- taskType,
2997
- taskId,
2998
- input: JSON.stringify(chunk2),
2999
- output: partial,
3000
- instructions: condition,
3001
- metadata: output.metadata
3002
- });
3003
- }
3004
- return partial;
3005
- };
3006
- const filteredChunks = await Promise.all(chunks.map(filterChunk));
3007
- return filteredChunks.flat();
3008
- };
3009
-
3010
- // src/operations/extract.ts
3011
- var import_zui9 = __require("@bpinternal/zui");
3012
- var import_json5 = __toESM(require_dist());
3013
-
3014
- // node_modules/.pnpm/jsonrepair@3.11.2/node_modules/jsonrepair/lib/esm/utils/JSONRepairError.js
3015
- var JSONRepairError = class extends Error {
3016
- constructor(message, position) {
3017
- super("".concat(message, " at position ").concat(position));
3018
- this.position = position;
3019
- }
3020
- };
3021
-
3022
- // node_modules/.pnpm/jsonrepair@3.11.2/node_modules/jsonrepair/lib/esm/utils/stringUtils.js
3023
- var codeBackslash = 92;
3024
- var codeSlash = 47;
3025
- var codeAsterisk = 42;
3026
- var codeOpeningBrace = 123;
3027
- var codeClosingBrace = 125;
3028
- var codeOpeningBracket = 91;
3029
- var codeClosingBracket = 93;
3030
- var codeCloseParenthesis = 41;
3031
- var codeSpace = 32;
3032
- var codeNewline = 10;
3033
- var codeTab = 9;
3034
- var codeReturn = 13;
3035
- var codeBackspace = 8;
3036
- var codeFormFeed = 12;
3037
- var codeDoubleQuote = 34;
3038
- var codePlus = 43;
3039
- var codeMinus = 45;
3040
- var codeQuote = 39;
3041
- var codeZero = 48;
3042
- var codeNine = 57;
3043
- var codeComma = 44;
3044
- var codeDot = 46;
3045
- var codeColon = 58;
3046
- var codeSemicolon = 59;
3047
- var codeUppercaseA = 65;
3048
- var codeLowercaseA = 97;
3049
- var codeUppercaseE = 69;
3050
- var codeLowercaseE = 101;
3051
- var codeUppercaseF = 70;
3052
- var codeLowercaseF = 102;
3053
- var codeNonBreakingSpace = 160;
3054
- var codeEnQuad = 8192;
3055
- var codeHairSpace = 8202;
3056
- var codeNarrowNoBreakSpace = 8239;
3057
- var codeMediumMathematicalSpace = 8287;
3058
- var codeIdeographicSpace = 12288;
3059
- var codeDoubleQuoteLeft = 8220;
3060
- var codeDoubleQuoteRight = 8221;
3061
- var codeQuoteLeft = 8216;
3062
- var codeQuoteRight = 8217;
3063
- var codeGraveAccent = 96;
3064
- var codeAcuteAccent = 180;
3065
- function isHex(code) {
3066
- return code >= codeZero && code <= codeNine || code >= codeUppercaseA && code <= codeUppercaseF || code >= codeLowercaseA && code <= codeLowercaseF;
3067
- }
3068
- function isDigit(code) {
3069
- return code >= codeZero && code <= codeNine;
3070
- }
3071
- function isValidStringCharacter(code) {
3072
- return code >= 32 && code <= 1114111;
3073
- }
3074
- function isDelimiter(char) {
3075
- return regexDelimiter.test(char);
3076
- }
3077
- var regexDelimiter = /^[,:[\]/{}()\n+]$/;
3078
- var regexUnquotedStringDelimiter = /^[,[\]/{}\n+]$/;
3079
- var regexFunctionNameCharStart = /^[a-zA-Z_$]$/;
3080
- var regexFunctionNameChar = /^[a-zA-Z_$0-9]$/;
3081
- var regexUrlStart = /^(http|https|ftp|mailto|file|data|irc):\/\/$/;
3082
- var regexUrlChar = /^[A-Za-z0-9-._~:/?#@!$&'()*+;=]$/;
3083
- function isUnquotedStringDelimiter(char) {
3084
- return regexUnquotedStringDelimiter.test(char);
3085
- }
3086
- function isStartOfValue(char) {
3087
- return regexStartOfValue.test(char) || char && isQuote(char.charCodeAt(0));
3088
- }
3089
- var regexStartOfValue = /^[[{\w-]$/;
3090
- function isControlCharacter(code) {
3091
- return code === codeNewline || code === codeReturn || code === codeTab || code === codeBackspace || code === codeFormFeed;
3092
- }
3093
- function isWhitespace(code) {
3094
- return code === codeSpace || code === codeNewline || code === codeTab || code === codeReturn;
3095
- }
3096
- function isWhitespaceExceptNewline(code) {
3097
- return code === codeSpace || code === codeTab || code === codeReturn;
3098
- }
3099
- function isSpecialWhitespace(code) {
3100
- return code === codeNonBreakingSpace || code >= codeEnQuad && code <= codeHairSpace || code === codeNarrowNoBreakSpace || code === codeMediumMathematicalSpace || code === codeIdeographicSpace;
3101
- }
3102
- function isQuote(code) {
3103
- return isDoubleQuoteLike(code) || isSingleQuoteLike(code);
3104
- }
3105
- function isDoubleQuoteLike(code) {
3106
- return code === codeDoubleQuote || code === codeDoubleQuoteLeft || code === codeDoubleQuoteRight;
3107
- }
3108
- function isDoubleQuote(code) {
3109
- return code === codeDoubleQuote;
3110
- }
3111
- function isSingleQuoteLike(code) {
3112
- return code === codeQuote || code === codeQuoteLeft || code === codeQuoteRight || code === codeGraveAccent || code === codeAcuteAccent;
3113
- }
3114
- function isSingleQuote(code) {
3115
- return code === codeQuote;
3116
- }
3117
- function stripLastOccurrence(text, textToStrip) {
3118
- let stripRemainingText = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
3119
- const index = text.lastIndexOf(textToStrip);
3120
- return index !== -1 ? text.substring(0, index) + (stripRemainingText ? "" : text.substring(index + 1)) : text;
3121
- }
3122
- function insertBeforeLastWhitespace(text, textToInsert) {
3123
- let index = text.length;
3124
- if (!isWhitespace(text.charCodeAt(index - 1))) {
3125
- return text + textToInsert;
3126
- }
3127
- while (isWhitespace(text.charCodeAt(index - 1))) {
3128
- index--;
3129
- }
3130
- return text.substring(0, index) + textToInsert + text.substring(index);
3131
- }
3132
- function removeAtIndex(text, start, count) {
3133
- return text.substring(0, start) + text.substring(start + count);
3134
- }
3135
- function endsWithCommaOrNewline(text) {
3136
- return /[,\n][ \t\r]*$/.test(text);
3137
- }
3138
-
3139
- // node_modules/.pnpm/jsonrepair@3.11.2/node_modules/jsonrepair/lib/esm/regular/jsonrepair.js
3140
- var controlCharacters = {
3141
- "\b": "\\b",
3142
- "\f": "\\f",
3143
- "\n": "\\n",
3144
- "\r": "\\r",
3145
- " ": "\\t"
3146
- };
3147
- var escapeCharacters = {
3148
- '"': '"',
3149
- "\\": "\\",
3150
- "/": "/",
3151
- b: "\b",
3152
- f: "\f",
3153
- n: "\n",
3154
- r: "\r",
3155
- t: " "
3156
- // note that \u is handled separately in parseString()
3157
- };
3158
- function jsonrepair(text) {
3159
- let i = 0;
3160
- let output = "";
3161
- const processed = parseValue();
3162
- if (!processed) {
3163
- throwUnexpectedEnd();
3164
- }
3165
- const processedComma = parseCharacter(codeComma);
3166
- if (processedComma) {
3167
- parseWhitespaceAndSkipComments();
3168
- }
3169
- if (isStartOfValue(text[i]) && endsWithCommaOrNewline(output)) {
3170
- if (!processedComma) {
3171
- output = insertBeforeLastWhitespace(output, ",");
3172
- }
3173
- parseNewlineDelimitedJSON();
3174
- } else if (processedComma) {
3175
- output = stripLastOccurrence(output, ",");
3176
- }
3177
- while (text.charCodeAt(i) === codeClosingBrace || text.charCodeAt(i) === codeClosingBracket) {
3178
- i++;
3179
- parseWhitespaceAndSkipComments();
3180
- }
3181
- if (i >= text.length) {
3182
- return output;
3183
- }
3184
- throwUnexpectedCharacter();
3185
- function parseValue() {
3186
- parseWhitespaceAndSkipComments();
3187
- const processed2 = parseObject() || parseArray() || parseString() || parseNumber() || parseKeywords() || parseUnquotedString(false) || parseRegex();
3188
- parseWhitespaceAndSkipComments();
3189
- return processed2;
3190
- }
3191
- function parseWhitespaceAndSkipComments() {
3192
- let skipNewline = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : true;
3193
- const start = i;
3194
- let changed = parseWhitespace(skipNewline);
3195
- do {
3196
- changed = parseComment();
3197
- if (changed) {
3198
- changed = parseWhitespace(skipNewline);
3199
- }
3200
- } while (changed);
3201
- return i > start;
3202
- }
3203
- function parseWhitespace(skipNewline) {
3204
- const _isWhiteSpace = skipNewline ? isWhitespace : isWhitespaceExceptNewline;
3205
- let whitespace = "";
3206
- while (true) {
3207
- const c = text.charCodeAt(i);
3208
- if (_isWhiteSpace(c)) {
3209
- whitespace += text[i];
3210
- i++;
3211
- } else if (isSpecialWhitespace(c)) {
3212
- whitespace += " ";
3213
- i++;
3214
- } else {
3215
- break;
3216
- }
3217
- }
3218
- if (whitespace.length > 0) {
3219
- output += whitespace;
3220
- return true;
3221
- }
3222
- return false;
3223
- }
3224
- function parseComment() {
3225
- if (text.charCodeAt(i) === codeSlash && text.charCodeAt(i + 1) === codeAsterisk) {
3226
- while (i < text.length && !atEndOfBlockComment(text, i)) {
3227
- i++;
3228
- }
3229
- i += 2;
3230
- return true;
3231
- }
3232
- if (text.charCodeAt(i) === codeSlash && text.charCodeAt(i + 1) === codeSlash) {
3233
- while (i < text.length && text.charCodeAt(i) !== codeNewline) {
3234
- i++;
3235
- }
3236
- return true;
3237
- }
3238
- return false;
3239
- }
3240
- function parseCharacter(code) {
3241
- if (text.charCodeAt(i) === code) {
3242
- output += text[i];
3243
- i++;
3244
- return true;
3245
- }
3246
- return false;
3247
- }
3248
- function skipCharacter(code) {
3249
- if (text.charCodeAt(i) === code) {
3250
- i++;
3251
- return true;
3252
- }
3253
- return false;
3254
- }
3255
- function skipEscapeCharacter() {
3256
- return skipCharacter(codeBackslash);
3257
- }
3258
- function skipEllipsis() {
3259
- parseWhitespaceAndSkipComments();
3260
- if (text.charCodeAt(i) === codeDot && text.charCodeAt(i + 1) === codeDot && text.charCodeAt(i + 2) === codeDot) {
3261
- i += 3;
3262
- parseWhitespaceAndSkipComments();
3263
- skipCharacter(codeComma);
3264
- return true;
3265
- }
3266
- return false;
3267
- }
3268
- function parseObject() {
3269
- if (text.charCodeAt(i) === codeOpeningBrace) {
3270
- output += "{";
3271
- i++;
3272
- parseWhitespaceAndSkipComments();
3273
- if (skipCharacter(codeComma)) {
3274
- parseWhitespaceAndSkipComments();
3275
- }
3276
- let initial = true;
3277
- while (i < text.length && text.charCodeAt(i) !== codeClosingBrace) {
3278
- let processedComma2;
3279
- if (!initial) {
3280
- processedComma2 = parseCharacter(codeComma);
3281
- if (!processedComma2) {
3282
- output = insertBeforeLastWhitespace(output, ",");
3283
- }
3284
- parseWhitespaceAndSkipComments();
3285
- } else {
3286
- processedComma2 = true;
3287
- initial = false;
3288
- }
3289
- skipEllipsis();
3290
- const processedKey = parseString() || parseUnquotedString(true);
3291
- if (!processedKey) {
3292
- if (text.charCodeAt(i) === codeClosingBrace || text.charCodeAt(i) === codeOpeningBrace || text.charCodeAt(i) === codeClosingBracket || text.charCodeAt(i) === codeOpeningBracket || text[i] === void 0) {
3293
- output = stripLastOccurrence(output, ",");
3294
- } else {
3295
- throwObjectKeyExpected();
3296
- }
3297
- break;
3298
- }
3299
- parseWhitespaceAndSkipComments();
3300
- const processedColon = parseCharacter(codeColon);
3301
- const truncatedText = i >= text.length;
3302
- if (!processedColon) {
3303
- if (isStartOfValue(text[i]) || truncatedText) {
3304
- output = insertBeforeLastWhitespace(output, ":");
3305
- } else {
3306
- throwColonExpected();
3307
- }
3308
- }
3309
- const processedValue = parseValue();
3310
- if (!processedValue) {
3311
- if (processedColon || truncatedText) {
3312
- output += "null";
3313
- } else {
3314
- throwColonExpected();
3315
- }
3316
- }
3317
- }
3318
- if (text.charCodeAt(i) === codeClosingBrace) {
3319
- output += "}";
3320
- i++;
3321
- } else {
3322
- output = insertBeforeLastWhitespace(output, "}");
3323
- }
3324
- return true;
3325
- }
3326
- return false;
3327
- }
3328
- function parseArray() {
3329
- if (text.charCodeAt(i) === codeOpeningBracket) {
3330
- output += "[";
3331
- i++;
3332
- parseWhitespaceAndSkipComments();
3333
- if (skipCharacter(codeComma)) {
3334
- parseWhitespaceAndSkipComments();
3335
- }
3336
- let initial = true;
3337
- while (i < text.length && text.charCodeAt(i) !== codeClosingBracket) {
3338
- if (!initial) {
3339
- const processedComma2 = parseCharacter(codeComma);
3340
- if (!processedComma2) {
3341
- output = insertBeforeLastWhitespace(output, ",");
3342
- }
3343
- } else {
3344
- initial = false;
3345
- }
3346
- skipEllipsis();
3347
- const processedValue = parseValue();
3348
- if (!processedValue) {
3349
- output = stripLastOccurrence(output, ",");
3350
- break;
3351
- }
3352
- }
3353
- if (text.charCodeAt(i) === codeClosingBracket) {
3354
- output += "]";
3355
- i++;
3356
- } else {
3357
- output = insertBeforeLastWhitespace(output, "]");
3358
- }
3359
- return true;
3360
- }
3361
- return false;
3362
- }
3363
- function parseNewlineDelimitedJSON() {
3364
- let initial = true;
3365
- let processedValue = true;
3366
- while (processedValue) {
3367
- if (!initial) {
3368
- const processedComma2 = parseCharacter(codeComma);
3369
- if (!processedComma2) {
3370
- output = insertBeforeLastWhitespace(output, ",");
3371
- }
3372
- } else {
3373
- initial = false;
3374
- }
3375
- processedValue = parseValue();
3376
- }
3377
- if (!processedValue) {
3378
- output = stripLastOccurrence(output, ",");
3379
- }
3380
- output = "[\n".concat(output, "\n]");
3381
- }
3382
- function parseString() {
3383
- let stopAtDelimiter = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : false;
3384
- let stopAtIndex = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : -1;
3385
- let skipEscapeChars = text.charCodeAt(i) === codeBackslash;
3386
- if (skipEscapeChars) {
3387
- i++;
3388
- skipEscapeChars = true;
3389
- }
3390
- if (isQuote(text.charCodeAt(i))) {
3391
- const isEndQuote = isDoubleQuote(text.charCodeAt(i)) ? isDoubleQuote : isSingleQuote(text.charCodeAt(i)) ? isSingleQuote : isSingleQuoteLike(text.charCodeAt(i)) ? isSingleQuoteLike : isDoubleQuoteLike;
3392
- const iBefore = i;
3393
- const oBefore = output.length;
3394
- let str = '"';
3395
- i++;
3396
- while (true) {
3397
- if (i >= text.length) {
3398
- const iPrev = prevNonWhitespaceIndex(i - 1);
3399
- if (!stopAtDelimiter && isDelimiter(text.charAt(iPrev))) {
3400
- i = iBefore;
3401
- output = output.substring(0, oBefore);
3402
- return parseString(true);
3403
- }
3404
- str = insertBeforeLastWhitespace(str, '"');
3405
- output += str;
3406
- return true;
3407
- } else if (i === stopAtIndex) {
3408
- str = insertBeforeLastWhitespace(str, '"');
3409
- output += str;
3410
- return true;
3411
- } else if (isEndQuote(text.charCodeAt(i))) {
3412
- const iQuote = i;
3413
- const oQuote = str.length;
3414
- str += '"';
3415
- i++;
3416
- output += str;
3417
- parseWhitespaceAndSkipComments(false);
3418
- if (stopAtDelimiter || i >= text.length || isDelimiter(text.charAt(i)) || isQuote(text.charCodeAt(i)) || isDigit(text.charCodeAt(i))) {
3419
- parseConcatenatedString();
3420
- return true;
3421
- }
3422
- const iPrevChar = prevNonWhitespaceIndex(iQuote - 1);
3423
- const prevChar = text.charAt(iPrevChar);
3424
- if (prevChar === ",") {
3425
- i = iBefore;
3426
- output = output.substring(0, oBefore);
3427
- return parseString(false, iPrevChar);
3428
- }
3429
- if (isDelimiter(prevChar)) {
3430
- i = iBefore;
3431
- output = output.substring(0, oBefore);
3432
- return parseString(true);
3433
- }
3434
- output = output.substring(0, oBefore);
3435
- i = iQuote + 1;
3436
- str = "".concat(str.substring(0, oQuote), "\\").concat(str.substring(oQuote));
3437
- } else if (stopAtDelimiter && isUnquotedStringDelimiter(text[i])) {
3438
- if (text.charCodeAt(i - 1) === codeColon && regexUrlStart.test(text.substring(iBefore + 1, i + 2))) {
3439
- while (i < text.length && regexUrlChar.test(text[i])) {
3440
- str += text[i];
3441
- i++;
3442
- }
3443
- }
3444
- str = insertBeforeLastWhitespace(str, '"');
3445
- output += str;
3446
- parseConcatenatedString();
3447
- return true;
3448
- } else if (text.charCodeAt(i) === codeBackslash) {
3449
- const char = text.charAt(i + 1);
3450
- const escapeChar = escapeCharacters[char];
3451
- if (escapeChar !== void 0) {
3452
- str += text.slice(i, i + 2);
3453
- i += 2;
3454
- } else if (char === "u") {
3455
- let j = 2;
3456
- while (j < 6 && isHex(text.charCodeAt(i + j))) {
3457
- j++;
3458
- }
3459
- if (j === 6) {
3460
- str += text.slice(i, i + 6);
3461
- i += 6;
3462
- } else if (i + j >= text.length) {
3463
- i = text.length;
3464
- } else {
3465
- throwInvalidUnicodeCharacter();
3466
- }
3467
- } else {
3468
- str += char;
3469
- i += 2;
3470
- }
3471
- } else {
3472
- const char = text.charAt(i);
3473
- const code = text.charCodeAt(i);
3474
- if (code === codeDoubleQuote && text.charCodeAt(i - 1) !== codeBackslash) {
3475
- str += "\\".concat(char);
3476
- i++;
3477
- } else if (isControlCharacter(code)) {
3478
- str += controlCharacters[char];
3479
- i++;
3480
- } else {
3481
- if (!isValidStringCharacter(code)) {
3482
- throwInvalidCharacter(char);
3483
- }
3484
- str += char;
3485
- i++;
3486
- }
3487
- }
3488
- if (skipEscapeChars) {
3489
- skipEscapeCharacter();
3490
- }
3491
- }
3492
- }
3493
- return false;
3494
- }
3495
- function parseConcatenatedString() {
3496
- let processed2 = false;
3497
- parseWhitespaceAndSkipComments();
3498
- while (text.charCodeAt(i) === codePlus) {
3499
- processed2 = true;
3500
- i++;
3501
- parseWhitespaceAndSkipComments();
3502
- output = stripLastOccurrence(output, '"', true);
3503
- const start = output.length;
3504
- const parsedStr = parseString();
3505
- if (parsedStr) {
3506
- output = removeAtIndex(output, start, 1);
3507
- } else {
3508
- output = insertBeforeLastWhitespace(output, '"');
3509
- }
3510
- }
3511
- return processed2;
3512
- }
3513
- function parseNumber() {
3514
- const start = i;
3515
- if (text.charCodeAt(i) === codeMinus) {
3516
- i++;
3517
- if (atEndOfNumber()) {
3518
- repairNumberEndingWithNumericSymbol(start);
3519
- return true;
3520
- }
3521
- if (!isDigit(text.charCodeAt(i))) {
3522
- i = start;
3523
- return false;
3524
- }
3525
- }
3526
- while (isDigit(text.charCodeAt(i))) {
3527
- i++;
3528
- }
3529
- if (text.charCodeAt(i) === codeDot) {
3530
- i++;
3531
- if (atEndOfNumber()) {
3532
- repairNumberEndingWithNumericSymbol(start);
3533
- return true;
3534
- }
3535
- if (!isDigit(text.charCodeAt(i))) {
3536
- i = start;
3537
- return false;
3538
- }
3539
- while (isDigit(text.charCodeAt(i))) {
3540
- i++;
3541
- }
3542
- }
3543
- if (text.charCodeAt(i) === codeLowercaseE || text.charCodeAt(i) === codeUppercaseE) {
3544
- i++;
3545
- if (text.charCodeAt(i) === codeMinus || text.charCodeAt(i) === codePlus) {
3546
- i++;
3547
- }
3548
- if (atEndOfNumber()) {
3549
- repairNumberEndingWithNumericSymbol(start);
3550
- return true;
3551
- }
3552
- if (!isDigit(text.charCodeAt(i))) {
3553
- i = start;
3554
- return false;
3555
- }
3556
- while (isDigit(text.charCodeAt(i))) {
3557
- i++;
3558
- }
3559
- }
3560
- if (!atEndOfNumber()) {
3561
- i = start;
3562
- return false;
3563
- }
3564
- if (i > start) {
3565
- const num = text.slice(start, i);
3566
- const hasInvalidLeadingZero = /^0\d/.test(num);
3567
- output += hasInvalidLeadingZero ? '"'.concat(num, '"') : num;
3568
- return true;
3569
- }
3570
- return false;
3571
- }
3572
- function parseKeywords() {
3573
- return parseKeyword("true", "true") || parseKeyword("false", "false") || parseKeyword("null", "null") || // repair Python keywords True, False, None
3574
- parseKeyword("True", "true") || parseKeyword("False", "false") || parseKeyword("None", "null");
3575
- }
3576
- function parseKeyword(name, value) {
3577
- if (text.slice(i, i + name.length) === name) {
3578
- output += value;
3579
- i += name.length;
3580
- return true;
3581
- }
3582
- return false;
3583
- }
3584
- function parseUnquotedString(isKey) {
3585
- const start = i;
3586
- if (regexFunctionNameCharStart.test(text[i])) {
3587
- while (i < text.length && regexFunctionNameChar.test(text[i])) {
3588
- i++;
3589
- }
3590
- let j = i;
3591
- while (isWhitespace(text.charCodeAt(j))) {
3592
- j++;
3593
- }
3594
- if (text[j] === "(") {
3595
- i = j + 1;
3596
- parseValue();
3597
- if (text.charCodeAt(i) === codeCloseParenthesis) {
3598
- i++;
3599
- if (text.charCodeAt(i) === codeSemicolon) {
3600
- i++;
3601
- }
3602
- }
3603
- return true;
3604
- }
3605
- }
3606
- while (i < text.length && !isUnquotedStringDelimiter(text[i]) && !isQuote(text.charCodeAt(i)) && (!isKey || text.charCodeAt(i) !== codeColon)) {
3607
- i++;
3608
- }
3609
- if (text.charCodeAt(i - 1) === codeColon && regexUrlStart.test(text.substring(start, i + 2))) {
3610
- while (i < text.length && regexUrlChar.test(text[i])) {
3611
- i++;
3612
- }
3613
- }
3614
- if (i > start) {
3615
- while (isWhitespace(text.charCodeAt(i - 1)) && i > 0) {
3616
- i--;
3617
- }
3618
- const symbol = text.slice(start, i);
3619
- output += symbol === "undefined" ? "null" : JSON.stringify(symbol);
3620
- if (text.charCodeAt(i) === codeDoubleQuote) {
3621
- i++;
3622
- }
3623
- return true;
3624
- }
3625
- }
3626
- function parseRegex() {
3627
- if (text[i] === "/") {
3628
- const start = i;
3629
- i++;
3630
- while (i < text.length && (text[i] !== "/" || text[i - 1] === "\\")) {
3631
- i++;
3632
- }
3633
- i++;
3634
- output += '"'.concat(text.substring(start, i), '"');
3635
- return true;
3636
- }
3637
- }
3638
- function prevNonWhitespaceIndex(start) {
3639
- let prev = start;
3640
- while (prev > 0 && isWhitespace(text.charCodeAt(prev))) {
3641
- prev--;
3642
- }
3643
- return prev;
3644
- }
3645
- function atEndOfNumber() {
3646
- return i >= text.length || isDelimiter(text[i]) || isWhitespace(text.charCodeAt(i));
3647
- }
3648
- function repairNumberEndingWithNumericSymbol(start) {
3649
- output += "".concat(text.slice(start, i), "0");
3650
- }
3651
- function throwInvalidCharacter(char) {
3652
- throw new JSONRepairError("Invalid character ".concat(JSON.stringify(char)), i);
3653
- }
3654
- function throwUnexpectedCharacter() {
3655
- throw new JSONRepairError("Unexpected character ".concat(JSON.stringify(text[i])), i);
3656
- }
3657
- function throwUnexpectedEnd() {
3658
- throw new JSONRepairError("Unexpected end of json string", text.length);
3659
- }
3660
- function throwObjectKeyExpected() {
3661
- throw new JSONRepairError("Object key expected", i);
3662
- }
3663
- function throwColonExpected() {
3664
- throw new JSONRepairError("Colon expected", i);
3665
- }
3666
- function throwInvalidUnicodeCharacter() {
3667
- const chars = text.slice(i, i + 6);
3668
- throw new JSONRepairError('Invalid unicode character "'.concat(chars, '"'), i);
3669
- }
3670
- }
3671
- function atEndOfBlockComment(text, i) {
3672
- return text[i] === "*" && text[i + 1] === "/";
3673
- }
3674
-
3675
- // src/operations/errors.ts
3676
- var JsonParsingError = class extends Error {
3677
- constructor(json, error) {
3678
- const message = "Error parsing JSON:\n\n---JSON---\n".concat(json, "\n\n---Error---\n\n ").concat(error);
3679
- super(message);
3680
- this.json = json;
3681
- this.error = error;
3682
- }
3683
- };
3684
-
3685
- // src/operations/extract.ts
3686
- var Options6 = import_zui9.z.object({
3687
- instructions: import_zui9.z.string().optional().describe("Instructions to guide the user on how to extract the data"),
3688
- chunkLength: import_zui9.z.number().min(100).max(1e5).optional().describe("The maximum number of tokens per chunk").default(16e3)
3689
- });
3690
- var START3 = "\u25A0json_start\u25A0";
3691
- var END5 = "\u25A0json_end\u25A0";
3692
- var NO_MORE = "\u25A0NO_MORE_ELEMENT\u25A0";
3693
- Zai.prototype.extract = async function(input, schema, _options) {
3694
- var _a, _b, _c;
3695
- const options = Options6.parse(_options != null ? _options : {});
3696
- const tokenizer = await this.getTokenizer();
3697
- const taskId = this.taskId;
3698
- const taskType = "zai.extract";
3699
- const PROMPT_COMPONENT = Math.max(this.Model.input.maxTokens - PROMPT_INPUT_BUFFER, 100);
3700
- let isArrayOfObjects = false;
3701
- const originalSchema = schema;
3702
- if (schema instanceof import_zui9.z.ZodObject) {
3703
- } else if (schema instanceof import_zui9.z.ZodArray) {
3704
- if (schema._def.type instanceof import_zui9.z.ZodObject) {
3705
- isArrayOfObjects = true;
3706
- schema = schema._def.type;
3707
- } else {
3708
- throw new Error("Schema must be a ZodObject or a ZodArray<ZodObject>");
3709
- }
3710
- } else {
3711
- throw new Error("Schema must be either a ZuiObject or a ZuiArray<ZuiObject>");
3712
- }
3713
- const schemaTypescript = schema.toTypescript({ declaration: false });
3714
- const schemaLength = tokenizer.count(schemaTypescript);
3715
- options.chunkLength = Math.min(options.chunkLength, this.Model.input.maxTokens - PROMPT_INPUT_BUFFER - schemaLength);
3716
- const keys = Object.keys(schema.shape);
3717
- let inputAsString = stringify(input);
3718
- if (tokenizer.count(inputAsString) > options.chunkLength) {
3719
- if (isArrayOfObjects) {
3720
- const tokens = tokenizer.split(inputAsString);
3721
- const chunks = chunk_default(tokens, options.chunkLength).map((x) => x.join(""));
3722
- const all = await Promise.all(chunks.map((chunk2) => this.extract(chunk2, originalSchema)));
3723
- return all.flat();
3724
- } else {
3725
- inputAsString = tokenizer.truncate(stringify(input), options.chunkLength);
3726
- }
3727
- }
3728
- const instructions = [];
3729
- if (options.instructions) {
3730
- instructions.push(options.instructions);
3731
- }
3732
- const shape = "{ ".concat(keys.map((key) => '"'.concat(key, '": ...')).join(", "), " }");
3733
- const abbv = "{ ... }";
3734
- if (isArrayOfObjects) {
3735
- instructions.push("You may have multiple elements, or zero elements in the input.");
3736
- instructions.push("You must extract each element separately.");
3737
- instructions.push("Each element must be a JSON object with exactly the format: ".concat(START3).concat(shape).concat(END5));
3738
- instructions.push('When you are done extracting all elements, type "'.concat(NO_MORE, '" to finish.'));
3739
- instructions.push("For example, if you have zero elements, the output should look like this: ".concat(NO_MORE));
3740
- instructions.push(
3741
- "For example, if you have two elements, the output should look like this: ".concat(START3).concat(abbv).concat(END5).concat(START3).concat(abbv).concat(END5).concat(NO_MORE)
3742
- );
3743
- } else {
3744
- instructions.push("You may have exactly one element in the input.");
3745
- instructions.push("The element must be a JSON object with exactly the format: ".concat(START3).concat(shape).concat(END5));
3746
- }
3747
- const EXAMPLES_TOKENS = PROMPT_COMPONENT - tokenizer.count(inputAsString) - tokenizer.count(instructions.join("\n"));
3748
- const Key = fastHash(
3749
- JSON.stringify({
3750
- taskType,
3751
- taskId,
3752
- input: inputAsString,
3753
- instructions: options.instructions
3754
- })
3755
- );
3756
- const examples = taskId ? await this.adapter.getExamples({
3757
- input: inputAsString,
3758
- taskType,
3759
- taskId
3760
- }) : [];
3761
- const exactMatch = examples.find((x) => x.key === Key);
3762
- if (exactMatch) {
3763
- return exactMatch.output;
3764
- }
3765
- const defaultExample = isArrayOfObjects ? {
3766
- input: "The story goes as follow.\nOnce upon a time, there was a person named Alice who was 30 years old.\nThen, there was a person named Bob who was 25 years old.\nThe end.",
3767
- schema: "Array<{ name: string, age: number }>",
3768
- instructions: "Extract all people",
3769
- extracted: [
3770
- {
3771
- name: "Alice",
3772
- age: 30
3773
- },
3774
- {
3775
- name: "Bob",
3776
- age: 25
3777
- }
3778
- ]
3779
- } : {
3780
- input: "The story goes as follow.\nOnce upon a time, there was a person named Alice who was 30 years old.\nThe end.",
3781
- schema: "{ name: string, age: number }",
3782
- instructions: "Extract the person",
3783
- extracted: { name: "Alice", age: 30 }
3784
- };
3785
- const userExamples = examples.map((e) => ({
3786
- input: e.input,
3787
- extracted: e.output,
3788
- schema: schemaTypescript,
3789
- instructions: options.instructions
3790
- }));
3791
- let exampleId = 1;
3792
- const formatInput = (input2, schema2, instructions2) => {
3793
- const header = userExamples.length ? "Expert Example #".concat(exampleId++) : "Here's an example to help you understand the format:";
3794
- return "\n".concat(header, "\n\n<|start_schema|>\n").concat(schema2, "\n<|end_schema|>\n\n<|start_instructions|>\n").concat(instructions2 != null ? instructions2 : "No specific instructions, just follow the schema above.", "\n<|end_instructions|>\n\n<|start_input|>\n").concat(input2.trim(), "\n<|end_input|>\n ").trim();
3795
- };
3796
- const formatOutput = (extracted) => {
3797
- extracted = isArray_default(extracted) ? extracted : [extracted];
3798
- return extracted.map(
3799
- (x) => "\n".concat(START3, "\n").concat(JSON.stringify(x, null, 2), "\n").concat(END5).trim()
3800
- ).join("\n") + NO_MORE;
3801
- };
3802
- const formatExample = (example) => {
3803
- var _a2;
3804
- return [
3805
- {
3806
- type: "text",
3807
- content: formatInput(stringify((_a2 = example.input) != null ? _a2 : null), example.schema, example.instructions),
3808
- role: "user"
3809
- },
3810
- {
3811
- type: "text",
3812
- content: formatOutput(example.extracted),
3813
- role: "assistant"
3814
- }
3815
- ];
3816
- };
3817
- const allExamples = takeUntilTokens(
3818
- userExamples.length ? userExamples : [defaultExample],
3819
- EXAMPLES_TOKENS,
3820
- (el) => tokenizer.count(stringify(el.input)) + tokenizer.count(stringify(el.extracted))
3821
- ).map(formatExample).flat();
3822
- const output = await this.callModel({
3823
- systemPrompt: "\nExtract the following information from the input:\n".concat(schemaTypescript, "\n====\n\n").concat(instructions.map((x) => "\u2022 ".concat(x)).join("\n"), "\n").trim(),
3824
- stopSequences: [isArrayOfObjects ? NO_MORE : END5],
3825
- messages: [
3826
- ...allExamples,
3827
- {
3828
- role: "user",
3829
- type: "text",
3830
- content: formatInput(inputAsString, schemaTypescript, (_a = options.instructions) != null ? _a : "")
3831
- }
3832
- ]
3833
- });
3834
- const answer = (_b = output.choices[0]) == null ? void 0 : _b.content;
3835
- const elements = answer.split(START3).filter((x) => x.trim().length > 0).map((x) => {
3836
- try {
3837
- const json = x.slice(0, x.indexOf(END5)).trim();
3838
- const repairedJson = jsonrepair(json);
3839
- const parsedJson = import_json5.default.parse(repairedJson);
3840
- return schema.parse(parsedJson);
3841
- } catch (error) {
3842
- throw new JsonParsingError(x, error instanceof Error ? error : new Error("Unknown error"));
3843
- }
3844
- }).filter((x) => x !== null);
3845
- let final;
3846
- if (isArrayOfObjects) {
3847
- final = elements;
3848
- } else if (elements.length === 0) {
3849
- final = schema.parse({});
3850
- } else {
3851
- final = elements[0];
3852
- }
3853
- if (taskId) {
3854
- await this.adapter.saveExample({
3855
- key: Key,
3856
- taskId: "zai/".concat(taskId),
3857
- taskType,
3858
- instructions: (_c = options.instructions) != null ? _c : "No specific instructions",
3859
- input: inputAsString,
3860
- output: final,
3861
- metadata: output.metadata
3862
- });
3863
- }
3864
- return final;
3865
- };
3866
-
3867
- // src/operations/label.ts
3868
- var import_zui10 = __require("@bpinternal/zui");
3869
- var LABELS = {
3870
- ABSOLUTELY_NOT: "ABSOLUTELY_NOT",
3871
- PROBABLY_NOT: "PROBABLY_NOT",
3872
- AMBIGUOUS: "AMBIGUOUS",
3873
- PROBABLY_YES: "PROBABLY_YES",
3874
- ABSOLUTELY_YES: "ABSOLUTELY_YES"
3875
- };
3876
- var ALL_LABELS = Object.values(LABELS).join(" | ");
3877
- var Options7 = import_zui10.z.object({
3878
- examples: import_zui10.z.array(
3879
- import_zui10.z.object({
3880
- input: import_zui10.z.any(),
3881
- labels: import_zui10.z.record(import_zui10.z.object({ label: import_zui10.z.enum(ALL_LABELS), explanation: import_zui10.z.string().optional() }))
3882
- })
3883
- ).default([]).describe("Examples to help the user make a decision"),
3884
- instructions: import_zui10.z.string().optional().describe("Instructions to guide the user on how to extract the data"),
3885
- chunkLength: import_zui10.z.number().min(100).max(1e5).optional().describe("The maximum number of tokens per chunk").default(16e3)
3886
- });
3887
- var Labels = import_zui10.z.record(import_zui10.z.string().min(1).max(250), import_zui10.z.string()).superRefine((labels, ctx) => {
3888
- const keys = Object.keys(labels);
3889
- for (const key of keys) {
3890
- if (key.length < 1 || key.length > 250) {
3891
- ctx.addIssue({ message: 'The label key "'.concat(key, '" must be between 1 and 250 characters long'), code: "custom" });
3892
- }
3893
- if (keys.lastIndexOf(key) !== keys.indexOf(key)) {
3894
- ctx.addIssue({ message: "Duplicate label: ".concat(labels[key]), code: "custom" });
3895
- }
3896
- if (/[^a-zA-Z0-9_]/.test(key)) {
3897
- ctx.addIssue({
3898
- message: 'The label key "'.concat(key, '" must only contain alphanumeric characters and underscores'),
3899
- code: "custom"
3900
- });
3901
- }
3902
- }
3903
- return true;
3904
- });
3905
- var parseLabel = (label) => {
3906
- label = label.toUpperCase().replace(/\s+/g, "_").replace(/_{2,}/g, "_").trim();
3907
- if (label.includes("ABSOLUTELY") && label.includes("NOT")) {
3908
- return LABELS.ABSOLUTELY_NOT;
3909
- } else if (label.includes("NOT")) {
3910
- return LABELS.PROBABLY_NOT;
3911
- } else if (label.includes("AMBIGUOUS")) {
3912
- return LABELS.AMBIGUOUS;
3913
- }
3914
- if (label.includes("YES")) {
3915
- return LABELS.PROBABLY_YES;
3916
- } else if (label.includes("ABSOLUTELY") && label.includes("YES")) {
3917
- return LABELS.ABSOLUTELY_YES;
3918
- }
3919
- return LABELS.AMBIGUOUS;
3920
- };
3921
- Zai.prototype.label = async function(input, _labels, _options) {
3922
- var _a, _b;
3923
- const options = Options7.parse(_options != null ? _options : {});
3924
- const labels = Labels.parse(_labels);
3925
- const tokenizer = await this.getTokenizer();
3926
- const taskId = this.taskId;
3927
- const taskType = "zai.label";
3928
- const TOTAL_MAX_TOKENS = clamp_default(options.chunkLength, 1e3, this.Model.input.maxTokens - PROMPT_INPUT_BUFFER);
3929
- const CHUNK_EXAMPLES_MAX_TOKENS = clamp_default(Math.floor(TOTAL_MAX_TOKENS * 0.5), 250, 1e4);
3930
- const CHUNK_INPUT_MAX_TOKENS = clamp_default(
3931
- TOTAL_MAX_TOKENS - CHUNK_EXAMPLES_MAX_TOKENS,
3932
- TOTAL_MAX_TOKENS * 0.5,
3933
- TOTAL_MAX_TOKENS
3934
- );
3935
- const inputAsString = stringify(input);
3936
- if (tokenizer.count(inputAsString) > CHUNK_INPUT_MAX_TOKENS) {
3937
- const tokens = tokenizer.split(inputAsString);
3938
- const chunks = chunk_default(tokens, CHUNK_INPUT_MAX_TOKENS).map((x) => x.join(""));
3939
- const allLabels = await Promise.all(chunks.map((chunk2) => this.label(chunk2, _labels)));
3940
- return allLabels.reduce((acc, x) => {
3941
- Object.keys(x).forEach((key) => {
3942
- if (acc[key] === true) {
3943
- acc[key] = true;
3944
- } else {
3945
- acc[key] = acc[key] || x[key];
3946
- }
3947
- });
3948
- return acc;
3949
- }, {});
3950
- }
3951
- const END6 = "\u25A0END\u25A0";
3952
- const Key = fastHash(
3953
- JSON.stringify({
3954
- taskType,
3955
- taskId,
3956
- input: inputAsString,
3957
- instructions: (_a = options.instructions) != null ? _a : ""
3958
- })
3959
- );
3960
- const convertToAnswer = (mapping) => {
3961
- return Object.keys(labels).reduce((acc, key) => {
3962
- var _a2, _b2;
3963
- acc[key] = ((_a2 = mapping[key]) == null ? void 0 : _a2.label) === "ABSOLUTELY_YES" || ((_b2 = mapping[key]) == null ? void 0 : _b2.label) === "PROBABLY_YES";
3964
- return acc;
3965
- }, {});
3966
- };
3967
- const examples = taskId ? await this.adapter.getExamples({
3968
- input: inputAsString,
3969
- taskType,
3970
- taskId
3971
- }) : [];
3972
- options.examples.forEach((example) => {
3973
- examples.push({
3974
- key: fastHash(JSON.stringify(example)),
3975
- input: example.input,
3976
- similarity: 1,
3977
- explanation: "",
3978
- output: example.labels
3979
- });
3980
- });
3981
- const exactMatch = examples.find((x) => x.key === Key);
3982
- if (exactMatch) {
3983
- return convertToAnswer(exactMatch.output);
3984
- }
3985
- const allExamples = takeUntilTokens(
3986
- examples,
3987
- CHUNK_EXAMPLES_MAX_TOKENS,
3988
- (el) => {
3989
- var _a2;
3990
- return tokenizer.count(stringify(el.input)) + tokenizer.count(stringify(el.output)) + tokenizer.count((_a2 = el.explanation) != null ? _a2 : "") + 100;
3991
- }
3992
- ).map((example, idx) => [
3993
- {
3994
- type: "text",
3995
- role: "user",
3996
- content: "\nExpert Example #".concat(idx + 1, "\n\n<|start_input|>\n").concat(stringify(example.input), "\n<|end_input|>").trim()
3997
- },
3998
- {
3999
- type: "text",
4000
- role: "assistant",
4001
- content: "\nExpert Example #".concat(idx + 1, "\n============\n").concat(Object.keys(example.output).map(
4002
- (key) => {
4003
- var _a2, _b2;
4004
- return "\n\u25A0".concat(key, ":\u3010").concat((_a2 = example.output[key]) == null ? void 0 : _a2.explanation, "\u3011:").concat((_b2 = example.output[key]) == null ? void 0 : _b2.label, "\u25A0\n").trim();
4005
- }
4006
- ).join("\n"), "\n").concat(END6, "\n").trim()
4007
- }
4008
- ]).flat();
4009
- const format = Object.keys(labels).map((key) => {
4010
- return "\n\u25A0".concat(key, ':\u3010explanation (where "explanation" is answering the question "').concat(labels[key], '")\u3011:x\u25A0 (where x is ').concat(ALL_LABELS, ")\n").trim();
4011
- }).join("\n\n");
4012
- const output = await this.callModel({
4013
- stopSequences: [END6],
4014
- systemPrompt: "\nYou need to tag the input with the following labels based on the question asked:\n".concat(LABELS.ABSOLUTELY_NOT, ': You are absolutely sure that the answer is "NO" to the question.\n').concat(LABELS.PROBABLY_NOT, ': You are leaning towards "NO" to the question.\n').concat(LABELS.AMBIGUOUS, ": You are unsure about the answer to the question.\n").concat(LABELS.PROBABLY_YES, ': You are leaning towards "YES" to the question.\n').concat(LABELS.ABSOLUTELY_YES, ': You are absolutely sure that the answer is "YES" to the question.\n\nYou need to return a mapping of the labels, an explanation and the answer for each label following the format below:\n```\n').concat(format, "\n").concat(END6, "\n```\n\n").concat(options.instructions, '\n\n===\nYou should consider the Expert Examples below to help you make your decision.\nIn your "Analysis", please refer to the Expert Examples # to justify your decision.\n').trim(),
4015
- messages: [
4016
- ...allExamples,
4017
- {
4018
- type: "text",
4019
- role: "user",
4020
- content: "\nInput to tag:\n<|start_input|>\n".concat(inputAsString, "\n<|end_input|>\n\nAnswer with this following format:\n```\n").concat(format, "\n").concat(END6, "\n```\n\nFormat cheatsheet:\n```\n\u25A0label:\u3010explanation\u3011:x\u25A0\n```\n\nWhere `x` is one of the following: ").concat(ALL_LABELS, '\n\nRemember: In your `explanation`, please refer to the Expert Examples # (and quote them) that are relevant to ground your decision-making process.\nThe Expert Examples are there to help you make your decision. They have been provided by experts in the field and their answers (and reasoning) are considered the ground truth and should be used as a reference to make your decision when applicable.\nFor example, you can say: "According to Expert Example #1, ..."').trim()
4021
- }
4022
- ]
4023
- });
4024
- const answer = output.choices[0].content;
4025
- const final = Object.keys(labels).reduce((acc, key) => {
4026
- const match = answer.match(new RegExp("\u25A0".concat(key, ":\u3010(.+)\u3011:(\\w{2,})\u25A0"), "i"));
4027
- if (match) {
4028
- const explanation = match[1].trim();
4029
- const label = parseLabel(match[2]);
4030
- acc[key] = {
4031
- explanation,
4032
- label
4033
- };
4034
- } else {
4035
- acc[key] = {
4036
- explanation: "",
4037
- label: LABELS.AMBIGUOUS
4038
- };
4039
- }
4040
- return acc;
4041
- }, {});
4042
- if (taskId) {
4043
- await this.adapter.saveExample({
4044
- key: Key,
4045
- taskType,
4046
- taskId,
4047
- instructions: (_b = options.instructions) != null ? _b : "",
4048
- metadata: output.metadata,
4049
- input: inputAsString,
4050
- output: final
4051
- });
4052
- }
4053
- return convertToAnswer(final);
4054
- };
4055
- })();
4056
- /*! Bundled license information:
4057
-
4058
- lodash-es/lodash.js:
4059
- (**
4060
- * @license
4061
- * Lodash (Custom Build) <https://lodash.com/>
4062
- * Build: `lodash modularize exports="es" -o ./`
4063
- * Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
4064
- * Released under MIT license <https://lodash.com/license>
4065
- * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
4066
- * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
4067
- *)
4068
- */