funda-ui 4.7.599 → 4.7.604
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.
- package/Chatbox/index.d.ts +1 -0
- package/Chatbox/index.js +1578 -508
- package/LiveSearch/index.js +341 -21
- package/MultipleCheckboxes/index.js +341 -21
- package/MultipleSelect/index.js +341 -21
- package/NativeSelect/index.js +341 -21
- package/Radio/index.js +341 -21
- package/Select/index.js +341 -21
- package/Utils/anim.js +338 -22
- package/Utils/initDefaultOptions.js +338 -22
- package/Utils/validate.d.ts +16 -6
- package/Utils/validate.js +338 -21
- package/lib/cjs/Chatbox/index.d.ts +1 -0
- package/lib/cjs/Chatbox/index.js +1578 -508
- package/lib/cjs/LiveSearch/index.js +341 -21
- package/lib/cjs/MultipleCheckboxes/index.js +341 -21
- package/lib/cjs/MultipleSelect/index.js +341 -21
- package/lib/cjs/NativeSelect/index.js +341 -21
- package/lib/cjs/Radio/index.js +341 -21
- package/lib/cjs/Select/index.js +341 -21
- package/lib/cjs/Utils/anim.js +338 -22
- package/lib/cjs/Utils/initDefaultOptions.js +338 -22
- package/lib/cjs/Utils/validate.d.ts +16 -6
- package/lib/cjs/Utils/validate.js +338 -21
- package/lib/esm/Chatbox/index.tsx +34 -13
- package/lib/esm/Chatbox/utils/func.ts +10 -10
- package/lib/esm/Utils/libs/validate.ts +367 -26
- package/package.json +1 -1
- package/lib/esm/Chatbox/useStreamController.tsx +0 -277
package/lib/cjs/Chatbox/index.js
CHANGED
|
@@ -3254,6 +3254,896 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
|
|
|
3254
3254
|
|
|
3255
3255
|
/***/ }),
|
|
3256
3256
|
|
|
3257
|
+
/***/ 829:
|
|
3258
|
+
/***/ (function(module, exports, __webpack_require__) {
|
|
3259
|
+
|
|
3260
|
+
/* module decorator */ module = __webpack_require__.nmd(module);
|
|
3261
|
+
var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;function _typeof2(obj) { "@babel/helpers - typeof"; return _typeof2 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof2(obj); }
|
|
3262
|
+
(function webpackUniversalModuleDefinition(root, factory) {
|
|
3263
|
+
if (( false ? 0 : _typeof2(exports)) === 'object' && ( false ? 0 : _typeof2(module)) === 'object') module.exports = factory(__webpack_require__(787));else if (true) !(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__(787)], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory),
|
|
3264
|
+
__WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ?
|
|
3265
|
+
(__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__),
|
|
3266
|
+
__WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));else {}
|
|
3267
|
+
})(this, function (__WEBPACK_EXTERNAL_MODULE__787__) {
|
|
3268
|
+
return (/******/function () {
|
|
3269
|
+
// webpackBootstrap
|
|
3270
|
+
/******/
|
|
3271
|
+
"use strict";
|
|
3272
|
+
|
|
3273
|
+
/******/
|
|
3274
|
+
var __webpack_modules__ = {
|
|
3275
|
+
/***/787: /***/function _(module) {
|
|
3276
|
+
module.exports = __WEBPACK_EXTERNAL_MODULE__787__;
|
|
3277
|
+
|
|
3278
|
+
/***/
|
|
3279
|
+
}
|
|
3280
|
+
|
|
3281
|
+
/******/
|
|
3282
|
+
};
|
|
3283
|
+
/************************************************************************/
|
|
3284
|
+
/******/ // The module cache
|
|
3285
|
+
/******/
|
|
3286
|
+
var __webpack_module_cache__ = {};
|
|
3287
|
+
/******/
|
|
3288
|
+
/******/ // The require function
|
|
3289
|
+
/******/
|
|
3290
|
+
function __nested_webpack_require_1471__(moduleId) {
|
|
3291
|
+
/******/ // Check if module is in cache
|
|
3292
|
+
/******/var cachedModule = __webpack_module_cache__[moduleId];
|
|
3293
|
+
/******/
|
|
3294
|
+
if (cachedModule !== undefined) {
|
|
3295
|
+
/******/return cachedModule.exports;
|
|
3296
|
+
/******/
|
|
3297
|
+
}
|
|
3298
|
+
/******/ // Create a new module (and put it into the cache)
|
|
3299
|
+
/******/
|
|
3300
|
+
var module = __webpack_module_cache__[moduleId] = {
|
|
3301
|
+
/******/ // no module.id needed
|
|
3302
|
+
/******/ // no module.loaded needed
|
|
3303
|
+
/******/exports: {}
|
|
3304
|
+
/******/
|
|
3305
|
+
};
|
|
3306
|
+
/******/
|
|
3307
|
+
/******/ // Execute the module function
|
|
3308
|
+
/******/
|
|
3309
|
+
__webpack_modules__[moduleId](module, module.exports, __nested_webpack_require_1471__);
|
|
3310
|
+
/******/
|
|
3311
|
+
/******/ // Return the exports of the module
|
|
3312
|
+
/******/
|
|
3313
|
+
return module.exports;
|
|
3314
|
+
/******/
|
|
3315
|
+
}
|
|
3316
|
+
/******/
|
|
3317
|
+
/************************************************************************/
|
|
3318
|
+
/******/ /* webpack/runtime/compat get default export */
|
|
3319
|
+
/******/
|
|
3320
|
+
(function () {
|
|
3321
|
+
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
|
3322
|
+
/******/__nested_webpack_require_1471__.n = function (module) {
|
|
3323
|
+
/******/var getter = module && module.__esModule ? /******/function () {
|
|
3324
|
+
return module['default'];
|
|
3325
|
+
} : /******/function () {
|
|
3326
|
+
return module;
|
|
3327
|
+
};
|
|
3328
|
+
/******/
|
|
3329
|
+
__nested_webpack_require_1471__.d(getter, {
|
|
3330
|
+
a: getter
|
|
3331
|
+
});
|
|
3332
|
+
/******/
|
|
3333
|
+
return getter;
|
|
3334
|
+
/******/
|
|
3335
|
+
};
|
|
3336
|
+
/******/
|
|
3337
|
+
})();
|
|
3338
|
+
/******/
|
|
3339
|
+
/******/ /* webpack/runtime/define property getters */
|
|
3340
|
+
/******/
|
|
3341
|
+
(function () {
|
|
3342
|
+
/******/ // define getter functions for harmony exports
|
|
3343
|
+
/******/__nested_webpack_require_1471__.d = function (exports, definition) {
|
|
3344
|
+
/******/for (var key in definition) {
|
|
3345
|
+
/******/if (__nested_webpack_require_1471__.o(definition, key) && !__nested_webpack_require_1471__.o(exports, key)) {
|
|
3346
|
+
/******/Object.defineProperty(exports, key, {
|
|
3347
|
+
enumerable: true,
|
|
3348
|
+
get: definition[key]
|
|
3349
|
+
});
|
|
3350
|
+
/******/
|
|
3351
|
+
}
|
|
3352
|
+
/******/
|
|
3353
|
+
}
|
|
3354
|
+
/******/
|
|
3355
|
+
};
|
|
3356
|
+
/******/
|
|
3357
|
+
})();
|
|
3358
|
+
/******/
|
|
3359
|
+
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
3360
|
+
/******/
|
|
3361
|
+
(function () {
|
|
3362
|
+
/******/__nested_webpack_require_1471__.o = function (obj, prop) {
|
|
3363
|
+
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
3364
|
+
};
|
|
3365
|
+
/******/
|
|
3366
|
+
})();
|
|
3367
|
+
/******/
|
|
3368
|
+
/******/ /* webpack/runtime/make namespace object */
|
|
3369
|
+
/******/
|
|
3370
|
+
(function () {
|
|
3371
|
+
/******/ // define __esModule on exports
|
|
3372
|
+
/******/__nested_webpack_require_1471__.r = function (exports) {
|
|
3373
|
+
/******/if (typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
3374
|
+
/******/Object.defineProperty(exports, Symbol.toStringTag, {
|
|
3375
|
+
value: 'Module'
|
|
3376
|
+
});
|
|
3377
|
+
/******/
|
|
3378
|
+
}
|
|
3379
|
+
/******/
|
|
3380
|
+
Object.defineProperty(exports, '__esModule', {
|
|
3381
|
+
value: true
|
|
3382
|
+
});
|
|
3383
|
+
/******/
|
|
3384
|
+
};
|
|
3385
|
+
/******/
|
|
3386
|
+
})();
|
|
3387
|
+
/******/
|
|
3388
|
+
/************************************************************************/
|
|
3389
|
+
var __webpack_exports__ = {};
|
|
3390
|
+
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
|
|
3391
|
+
(function () {
|
|
3392
|
+
__nested_webpack_require_1471__.r(__webpack_exports__);
|
|
3393
|
+
/* harmony export */
|
|
3394
|
+
__nested_webpack_require_1471__.d(__webpack_exports__, {
|
|
3395
|
+
/* harmony export */"default": function _default() {
|
|
3396
|
+
return __WEBPACK_DEFAULT_EXPORT__;
|
|
3397
|
+
},
|
|
3398
|
+
/* harmony export */"useStreamController": function useStreamController() {
|
|
3399
|
+
return (/* binding */_useStreamController
|
|
3400
|
+
);
|
|
3401
|
+
}
|
|
3402
|
+
/* harmony export */
|
|
3403
|
+
});
|
|
3404
|
+
/* harmony import */
|
|
3405
|
+
var react__WEBPACK_IMPORTED_MODULE_0__ = __nested_webpack_require_1471__(787);
|
|
3406
|
+
/* harmony import */
|
|
3407
|
+
var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__nested_webpack_require_1471__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
3408
|
+
function _typeof(obj) {
|
|
3409
|
+
"@babel/helpers - typeof";
|
|
3410
|
+
|
|
3411
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
|
|
3412
|
+
return typeof obj;
|
|
3413
|
+
} : function (obj) {
|
|
3414
|
+
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
3415
|
+
}, _typeof(obj);
|
|
3416
|
+
}
|
|
3417
|
+
function _regeneratorRuntime() {
|
|
3418
|
+
"use strict";
|
|
3419
|
+
|
|
3420
|
+
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
|
|
3421
|
+
_regeneratorRuntime = function _regeneratorRuntime() {
|
|
3422
|
+
return exports;
|
|
3423
|
+
};
|
|
3424
|
+
var exports = {},
|
|
3425
|
+
Op = Object.prototype,
|
|
3426
|
+
hasOwn = Op.hasOwnProperty,
|
|
3427
|
+
defineProperty = Object.defineProperty || function (obj, key, desc) {
|
|
3428
|
+
obj[key] = desc.value;
|
|
3429
|
+
},
|
|
3430
|
+
$Symbol = "function" == typeof Symbol ? Symbol : {},
|
|
3431
|
+
iteratorSymbol = $Symbol.iterator || "@@iterator",
|
|
3432
|
+
asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
|
|
3433
|
+
toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
|
|
3434
|
+
function define(obj, key, value) {
|
|
3435
|
+
return Object.defineProperty(obj, key, {
|
|
3436
|
+
value: value,
|
|
3437
|
+
enumerable: !0,
|
|
3438
|
+
configurable: !0,
|
|
3439
|
+
writable: !0
|
|
3440
|
+
}), obj[key];
|
|
3441
|
+
}
|
|
3442
|
+
try {
|
|
3443
|
+
define({}, "");
|
|
3444
|
+
} catch (err) {
|
|
3445
|
+
define = function define(obj, key, value) {
|
|
3446
|
+
return obj[key] = value;
|
|
3447
|
+
};
|
|
3448
|
+
}
|
|
3449
|
+
function wrap(innerFn, outerFn, self, tryLocsList) {
|
|
3450
|
+
var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
|
|
3451
|
+
generator = Object.create(protoGenerator.prototype),
|
|
3452
|
+
context = new Context(tryLocsList || []);
|
|
3453
|
+
return defineProperty(generator, "_invoke", {
|
|
3454
|
+
value: makeInvokeMethod(innerFn, self, context)
|
|
3455
|
+
}), generator;
|
|
3456
|
+
}
|
|
3457
|
+
function tryCatch(fn, obj, arg) {
|
|
3458
|
+
try {
|
|
3459
|
+
return {
|
|
3460
|
+
type: "normal",
|
|
3461
|
+
arg: fn.call(obj, arg)
|
|
3462
|
+
};
|
|
3463
|
+
} catch (err) {
|
|
3464
|
+
return {
|
|
3465
|
+
type: "throw",
|
|
3466
|
+
arg: err
|
|
3467
|
+
};
|
|
3468
|
+
}
|
|
3469
|
+
}
|
|
3470
|
+
exports.wrap = wrap;
|
|
3471
|
+
var ContinueSentinel = {};
|
|
3472
|
+
function Generator() {}
|
|
3473
|
+
function GeneratorFunction() {}
|
|
3474
|
+
function GeneratorFunctionPrototype() {}
|
|
3475
|
+
var IteratorPrototype = {};
|
|
3476
|
+
define(IteratorPrototype, iteratorSymbol, function () {
|
|
3477
|
+
return this;
|
|
3478
|
+
});
|
|
3479
|
+
var getProto = Object.getPrototypeOf,
|
|
3480
|
+
NativeIteratorPrototype = getProto && getProto(getProto(values([])));
|
|
3481
|
+
NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
|
|
3482
|
+
var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
|
|
3483
|
+
function defineIteratorMethods(prototype) {
|
|
3484
|
+
["next", "throw", "return"].forEach(function (method) {
|
|
3485
|
+
define(prototype, method, function (arg) {
|
|
3486
|
+
return this._invoke(method, arg);
|
|
3487
|
+
});
|
|
3488
|
+
});
|
|
3489
|
+
}
|
|
3490
|
+
function AsyncIterator(generator, PromiseImpl) {
|
|
3491
|
+
function invoke(method, arg, resolve, reject) {
|
|
3492
|
+
var record = tryCatch(generator[method], generator, arg);
|
|
3493
|
+
if ("throw" !== record.type) {
|
|
3494
|
+
var result = record.arg,
|
|
3495
|
+
value = result.value;
|
|
3496
|
+
return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
|
|
3497
|
+
invoke("next", value, resolve, reject);
|
|
3498
|
+
}, function (err) {
|
|
3499
|
+
invoke("throw", err, resolve, reject);
|
|
3500
|
+
}) : PromiseImpl.resolve(value).then(function (unwrapped) {
|
|
3501
|
+
result.value = unwrapped, resolve(result);
|
|
3502
|
+
}, function (error) {
|
|
3503
|
+
return invoke("throw", error, resolve, reject);
|
|
3504
|
+
});
|
|
3505
|
+
}
|
|
3506
|
+
reject(record.arg);
|
|
3507
|
+
}
|
|
3508
|
+
var previousPromise;
|
|
3509
|
+
defineProperty(this, "_invoke", {
|
|
3510
|
+
value: function value(method, arg) {
|
|
3511
|
+
function callInvokeWithMethodAndArg() {
|
|
3512
|
+
return new PromiseImpl(function (resolve, reject) {
|
|
3513
|
+
invoke(method, arg, resolve, reject);
|
|
3514
|
+
});
|
|
3515
|
+
}
|
|
3516
|
+
return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
|
|
3517
|
+
}
|
|
3518
|
+
});
|
|
3519
|
+
}
|
|
3520
|
+
function makeInvokeMethod(innerFn, self, context) {
|
|
3521
|
+
var state = "suspendedStart";
|
|
3522
|
+
return function (method, arg) {
|
|
3523
|
+
if ("executing" === state) throw new Error("Generator is already running");
|
|
3524
|
+
if ("completed" === state) {
|
|
3525
|
+
if ("throw" === method) throw arg;
|
|
3526
|
+
return doneResult();
|
|
3527
|
+
}
|
|
3528
|
+
for (context.method = method, context.arg = arg;;) {
|
|
3529
|
+
var delegate = context.delegate;
|
|
3530
|
+
if (delegate) {
|
|
3531
|
+
var delegateResult = maybeInvokeDelegate(delegate, context);
|
|
3532
|
+
if (delegateResult) {
|
|
3533
|
+
if (delegateResult === ContinueSentinel) continue;
|
|
3534
|
+
return delegateResult;
|
|
3535
|
+
}
|
|
3536
|
+
}
|
|
3537
|
+
if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
|
|
3538
|
+
if ("suspendedStart" === state) throw state = "completed", context.arg;
|
|
3539
|
+
context.dispatchException(context.arg);
|
|
3540
|
+
} else "return" === context.method && context.abrupt("return", context.arg);
|
|
3541
|
+
state = "executing";
|
|
3542
|
+
var record = tryCatch(innerFn, self, context);
|
|
3543
|
+
if ("normal" === record.type) {
|
|
3544
|
+
if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
|
|
3545
|
+
return {
|
|
3546
|
+
value: record.arg,
|
|
3547
|
+
done: context.done
|
|
3548
|
+
};
|
|
3549
|
+
}
|
|
3550
|
+
"throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
|
|
3551
|
+
}
|
|
3552
|
+
};
|
|
3553
|
+
}
|
|
3554
|
+
function maybeInvokeDelegate(delegate, context) {
|
|
3555
|
+
var methodName = context.method,
|
|
3556
|
+
method = delegate.iterator[methodName];
|
|
3557
|
+
if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel;
|
|
3558
|
+
var record = tryCatch(method, delegate.iterator, context.arg);
|
|
3559
|
+
if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
|
|
3560
|
+
var info = record.arg;
|
|
3561
|
+
return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel);
|
|
3562
|
+
}
|
|
3563
|
+
function pushTryEntry(locs) {
|
|
3564
|
+
var entry = {
|
|
3565
|
+
tryLoc: locs[0]
|
|
3566
|
+
};
|
|
3567
|
+
1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
|
|
3568
|
+
}
|
|
3569
|
+
function resetTryEntry(entry) {
|
|
3570
|
+
var record = entry.completion || {};
|
|
3571
|
+
record.type = "normal", delete record.arg, entry.completion = record;
|
|
3572
|
+
}
|
|
3573
|
+
function Context(tryLocsList) {
|
|
3574
|
+
this.tryEntries = [{
|
|
3575
|
+
tryLoc: "root"
|
|
3576
|
+
}], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
|
|
3577
|
+
}
|
|
3578
|
+
function values(iterable) {
|
|
3579
|
+
if (iterable) {
|
|
3580
|
+
var iteratorMethod = iterable[iteratorSymbol];
|
|
3581
|
+
if (iteratorMethod) return iteratorMethod.call(iterable);
|
|
3582
|
+
if ("function" == typeof iterable.next) return iterable;
|
|
3583
|
+
if (!isNaN(iterable.length)) {
|
|
3584
|
+
var i = -1,
|
|
3585
|
+
next = function next() {
|
|
3586
|
+
for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
|
|
3587
|
+
return next.value = undefined, next.done = !0, next;
|
|
3588
|
+
};
|
|
3589
|
+
return next.next = next;
|
|
3590
|
+
}
|
|
3591
|
+
}
|
|
3592
|
+
return {
|
|
3593
|
+
next: doneResult
|
|
3594
|
+
};
|
|
3595
|
+
}
|
|
3596
|
+
function doneResult() {
|
|
3597
|
+
return {
|
|
3598
|
+
value: undefined,
|
|
3599
|
+
done: !0
|
|
3600
|
+
};
|
|
3601
|
+
}
|
|
3602
|
+
return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", {
|
|
3603
|
+
value: GeneratorFunctionPrototype,
|
|
3604
|
+
configurable: !0
|
|
3605
|
+
}), defineProperty(GeneratorFunctionPrototype, "constructor", {
|
|
3606
|
+
value: GeneratorFunction,
|
|
3607
|
+
configurable: !0
|
|
3608
|
+
}), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
|
|
3609
|
+
var ctor = "function" == typeof genFun && genFun.constructor;
|
|
3610
|
+
return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
|
|
3611
|
+
}, exports.mark = function (genFun) {
|
|
3612
|
+
return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
|
|
3613
|
+
}, exports.awrap = function (arg) {
|
|
3614
|
+
return {
|
|
3615
|
+
__await: arg
|
|
3616
|
+
};
|
|
3617
|
+
}, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
|
|
3618
|
+
return this;
|
|
3619
|
+
}), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
|
|
3620
|
+
void 0 === PromiseImpl && (PromiseImpl = Promise);
|
|
3621
|
+
var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
|
|
3622
|
+
return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
|
|
3623
|
+
return result.done ? result.value : iter.next();
|
|
3624
|
+
});
|
|
3625
|
+
}, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
|
|
3626
|
+
return this;
|
|
3627
|
+
}), define(Gp, "toString", function () {
|
|
3628
|
+
return "[object Generator]";
|
|
3629
|
+
}), exports.keys = function (val) {
|
|
3630
|
+
var object = Object(val),
|
|
3631
|
+
keys = [];
|
|
3632
|
+
for (var key in object) keys.push(key);
|
|
3633
|
+
return keys.reverse(), function next() {
|
|
3634
|
+
for (; keys.length;) {
|
|
3635
|
+
var key = keys.pop();
|
|
3636
|
+
if (key in object) return next.value = key, next.done = !1, next;
|
|
3637
|
+
}
|
|
3638
|
+
return next.done = !0, next;
|
|
3639
|
+
};
|
|
3640
|
+
}, exports.values = values, Context.prototype = {
|
|
3641
|
+
constructor: Context,
|
|
3642
|
+
reset: function reset(skipTempReset) {
|
|
3643
|
+
if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined);
|
|
3644
|
+
},
|
|
3645
|
+
stop: function stop() {
|
|
3646
|
+
this.done = !0;
|
|
3647
|
+
var rootRecord = this.tryEntries[0].completion;
|
|
3648
|
+
if ("throw" === rootRecord.type) throw rootRecord.arg;
|
|
3649
|
+
return this.rval;
|
|
3650
|
+
},
|
|
3651
|
+
dispatchException: function dispatchException(exception) {
|
|
3652
|
+
if (this.done) throw exception;
|
|
3653
|
+
var context = this;
|
|
3654
|
+
function handle(loc, caught) {
|
|
3655
|
+
return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
|
|
3656
|
+
}
|
|
3657
|
+
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
3658
|
+
var entry = this.tryEntries[i],
|
|
3659
|
+
record = entry.completion;
|
|
3660
|
+
if ("root" === entry.tryLoc) return handle("end");
|
|
3661
|
+
if (entry.tryLoc <= this.prev) {
|
|
3662
|
+
var hasCatch = hasOwn.call(entry, "catchLoc"),
|
|
3663
|
+
hasFinally = hasOwn.call(entry, "finallyLoc");
|
|
3664
|
+
if (hasCatch && hasFinally) {
|
|
3665
|
+
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
|
|
3666
|
+
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
|
|
3667
|
+
} else if (hasCatch) {
|
|
3668
|
+
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
|
|
3669
|
+
} else {
|
|
3670
|
+
if (!hasFinally) throw new Error("try statement without catch or finally");
|
|
3671
|
+
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
|
|
3672
|
+
}
|
|
3673
|
+
}
|
|
3674
|
+
}
|
|
3675
|
+
},
|
|
3676
|
+
abrupt: function abrupt(type, arg) {
|
|
3677
|
+
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
3678
|
+
var entry = this.tryEntries[i];
|
|
3679
|
+
if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
|
|
3680
|
+
var finallyEntry = entry;
|
|
3681
|
+
break;
|
|
3682
|
+
}
|
|
3683
|
+
}
|
|
3684
|
+
finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
|
|
3685
|
+
var record = finallyEntry ? finallyEntry.completion : {};
|
|
3686
|
+
return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
|
|
3687
|
+
},
|
|
3688
|
+
complete: function complete(record, afterLoc) {
|
|
3689
|
+
if ("throw" === record.type) throw record.arg;
|
|
3690
|
+
return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel;
|
|
3691
|
+
},
|
|
3692
|
+
finish: function finish(finallyLoc) {
|
|
3693
|
+
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
3694
|
+
var entry = this.tryEntries[i];
|
|
3695
|
+
if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
|
|
3696
|
+
}
|
|
3697
|
+
},
|
|
3698
|
+
"catch": function _catch(tryLoc) {
|
|
3699
|
+
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
3700
|
+
var entry = this.tryEntries[i];
|
|
3701
|
+
if (entry.tryLoc === tryLoc) {
|
|
3702
|
+
var record = entry.completion;
|
|
3703
|
+
if ("throw" === record.type) {
|
|
3704
|
+
var thrown = record.arg;
|
|
3705
|
+
resetTryEntry(entry);
|
|
3706
|
+
}
|
|
3707
|
+
return thrown;
|
|
3708
|
+
}
|
|
3709
|
+
}
|
|
3710
|
+
throw new Error("illegal catch attempt");
|
|
3711
|
+
},
|
|
3712
|
+
delegateYield: function delegateYield(iterable, resultName, nextLoc) {
|
|
3713
|
+
return this.delegate = {
|
|
3714
|
+
iterator: values(iterable),
|
|
3715
|
+
resultName: resultName,
|
|
3716
|
+
nextLoc: nextLoc
|
|
3717
|
+
}, "next" === this.method && (this.arg = undefined), ContinueSentinel;
|
|
3718
|
+
}
|
|
3719
|
+
}, exports;
|
|
3720
|
+
}
|
|
3721
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
3722
|
+
try {
|
|
3723
|
+
var info = gen[key](arg);
|
|
3724
|
+
var value = info.value;
|
|
3725
|
+
} catch (error) {
|
|
3726
|
+
reject(error);
|
|
3727
|
+
return;
|
|
3728
|
+
}
|
|
3729
|
+
if (info.done) {
|
|
3730
|
+
resolve(value);
|
|
3731
|
+
} else {
|
|
3732
|
+
Promise.resolve(value).then(_next, _throw);
|
|
3733
|
+
}
|
|
3734
|
+
}
|
|
3735
|
+
function _asyncToGenerator(fn) {
|
|
3736
|
+
return function () {
|
|
3737
|
+
var self = this,
|
|
3738
|
+
args = arguments;
|
|
3739
|
+
return new Promise(function (resolve, reject) {
|
|
3740
|
+
var gen = fn.apply(self, args);
|
|
3741
|
+
function _next(value) {
|
|
3742
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
3743
|
+
}
|
|
3744
|
+
function _throw(err) {
|
|
3745
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
3746
|
+
}
|
|
3747
|
+
_next(undefined);
|
|
3748
|
+
});
|
|
3749
|
+
};
|
|
3750
|
+
}
|
|
3751
|
+
/**
|
|
3752
|
+
* Stream Controller
|
|
3753
|
+
*
|
|
3754
|
+
* @usage:
|
|
3755
|
+
|
|
3756
|
+
// Use in component
|
|
3757
|
+
const streamController = useStreamController({
|
|
3758
|
+
onChunk: async (chunk: string, index: number) => {
|
|
3759
|
+
// start (Execute it only once)
|
|
3760
|
+
if (index === 0) {
|
|
3761
|
+
|
|
3762
|
+
}
|
|
3763
|
+
|
|
3764
|
+
// Streaming data is JSON split by rows
|
|
3765
|
+
const lines = chunk.split("\n").filter(line => line.trim() !== "");
|
|
3766
|
+
|
|
3767
|
+
// Process each data chunk
|
|
3768
|
+
console.log('Received chunk:', chunk);
|
|
3769
|
+
},
|
|
3770
|
+
onComplete: async (lastContent: string) => {
|
|
3771
|
+
// Process when stream is completed
|
|
3772
|
+
console.log('Stream completed');
|
|
3773
|
+
|
|
3774
|
+
// Display AI reply
|
|
3775
|
+
console.log('AI reply:', lastContent);
|
|
3776
|
+
|
|
3777
|
+
},
|
|
3778
|
+
onError: (error) => {
|
|
3779
|
+
// Error handling
|
|
3780
|
+
console.error('Stream error:', error);
|
|
3781
|
+
},
|
|
3782
|
+
onAbort: () => {
|
|
3783
|
+
// Abort processing
|
|
3784
|
+
console.log('Stream aborted');
|
|
3785
|
+
}
|
|
3786
|
+
});
|
|
3787
|
+
|
|
3788
|
+
// Start stream
|
|
3789
|
+
const response = await fetch(url);
|
|
3790
|
+
await streamController.start(response);
|
|
3791
|
+
|
|
3792
|
+
// Pause stream
|
|
3793
|
+
streamController.pause();
|
|
3794
|
+
|
|
3795
|
+
// Resume stream
|
|
3796
|
+
streamController.resume();
|
|
3797
|
+
|
|
3798
|
+
// Abort stream
|
|
3799
|
+
streamController.abort();
|
|
3800
|
+
|
|
3801
|
+
// Check status
|
|
3802
|
+
const isActive = streamController.isActive();
|
|
3803
|
+
const isPaused = streamController.isPaused();
|
|
3804
|
+
|
|
3805
|
+
*/
|
|
3806
|
+
|
|
3807
|
+
var _useStreamController = function useStreamController() {
|
|
3808
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
3809
|
+
var streamController = (0, react__WEBPACK_IMPORTED_MODULE_0__.useRef)(null);
|
|
3810
|
+
var reader = (0, react__WEBPACK_IMPORTED_MODULE_0__.useRef)(null);
|
|
3811
|
+
var activeStream = (0, react__WEBPACK_IMPORTED_MODULE_0__.useRef)(null);
|
|
3812
|
+
var responseReader = (0, react__WEBPACK_IMPORTED_MODULE_0__.useRef)(null);
|
|
3813
|
+
var paused = (0, react__WEBPACK_IMPORTED_MODULE_0__.useRef)(false);
|
|
3814
|
+
var active = (0, react__WEBPACK_IMPORTED_MODULE_0__.useRef)(false);
|
|
3815
|
+
var abortController = (0, react__WEBPACK_IMPORTED_MODULE_0__.useRef)(new AbortController());
|
|
3816
|
+
var textDecoder = (0, react__WEBPACK_IMPORTED_MODULE_0__.useRef)(new TextDecoder("utf-8")); // Get the decoding of UTF8
|
|
3817
|
+
|
|
3818
|
+
// To avoid the "Uncaught (in promise) TypeError: Failed to execute 'cancel' on 'ReadableStream': Cannot cancel a locked stream" error,
|
|
3819
|
+
// (1) you need to safely release the reader.
|
|
3820
|
+
// (2) cleanup() also requires asynchronous state
|
|
3821
|
+
var releaseReader = (0, react__WEBPACK_IMPORTED_MODULE_0__.useCallback)( /*#__PURE__*/function () {
|
|
3822
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(readerRef) {
|
|
3823
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
3824
|
+
while (1) switch (_context.prev = _context.next) {
|
|
3825
|
+
case 0:
|
|
3826
|
+
if (!readerRef.current) {
|
|
3827
|
+
_context.next = 11;
|
|
3828
|
+
break;
|
|
3829
|
+
}
|
|
3830
|
+
_context.prev = 1;
|
|
3831
|
+
_context.next = 4;
|
|
3832
|
+
return readerRef.current.cancel();
|
|
3833
|
+
case 4:
|
|
3834
|
+
_context.next = 9;
|
|
3835
|
+
break;
|
|
3836
|
+
case 6:
|
|
3837
|
+
_context.prev = 6;
|
|
3838
|
+
_context.t0 = _context["catch"](1);
|
|
3839
|
+
console.warn('Error cancelling reader:', _context.t0);
|
|
3840
|
+
case 9:
|
|
3841
|
+
try {
|
|
3842
|
+
readerRef.current.releaseLock();
|
|
3843
|
+
} catch (e) {
|
|
3844
|
+
console.warn('Error releasing reader lock:', e);
|
|
3845
|
+
}
|
|
3846
|
+
readerRef.current = null;
|
|
3847
|
+
case 11:
|
|
3848
|
+
case "end":
|
|
3849
|
+
return _context.stop();
|
|
3850
|
+
}
|
|
3851
|
+
}, _callee, null, [[1, 6]]);
|
|
3852
|
+
}));
|
|
3853
|
+
return function (_x) {
|
|
3854
|
+
return _ref.apply(this, arguments);
|
|
3855
|
+
};
|
|
3856
|
+
}(), []);
|
|
3857
|
+
var cleanup = (0, react__WEBPACK_IMPORTED_MODULE_0__.useCallback)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
3858
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
3859
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
3860
|
+
case 0:
|
|
3861
|
+
_context2.next = 2;
|
|
3862
|
+
return releaseReader(reader);
|
|
3863
|
+
case 2:
|
|
3864
|
+
_context2.next = 4;
|
|
3865
|
+
return releaseReader(responseReader);
|
|
3866
|
+
case 4:
|
|
3867
|
+
if (!activeStream.current) {
|
|
3868
|
+
_context2.next = 14;
|
|
3869
|
+
break;
|
|
3870
|
+
}
|
|
3871
|
+
_context2.prev = 5;
|
|
3872
|
+
_context2.next = 8;
|
|
3873
|
+
return activeStream.current.cancel();
|
|
3874
|
+
case 8:
|
|
3875
|
+
_context2.next = 13;
|
|
3876
|
+
break;
|
|
3877
|
+
case 10:
|
|
3878
|
+
_context2.prev = 10;
|
|
3879
|
+
_context2.t0 = _context2["catch"](5);
|
|
3880
|
+
console.warn('Error cancelling stream:', _context2.t0);
|
|
3881
|
+
case 13:
|
|
3882
|
+
activeStream.current = null;
|
|
3883
|
+
case 14:
|
|
3884
|
+
streamController.current = null;
|
|
3885
|
+
active.current = false;
|
|
3886
|
+
paused.current = false;
|
|
3887
|
+
case 17:
|
|
3888
|
+
case "end":
|
|
3889
|
+
return _context2.stop();
|
|
3890
|
+
}
|
|
3891
|
+
}, _callee2, null, [[5, 10]]);
|
|
3892
|
+
})), [releaseReader]);
|
|
3893
|
+
|
|
3894
|
+
// Process chunks of data
|
|
3895
|
+
var processChunk = (0, react__WEBPACK_IMPORTED_MODULE_0__.useCallback)( /*#__PURE__*/function () {
|
|
3896
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(chunk, index) {
|
|
3897
|
+
var _options$onChunk, _options$onError;
|
|
3898
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
3899
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
3900
|
+
case 0:
|
|
3901
|
+
try {
|
|
3902
|
+
(_options$onChunk = options.onChunk) === null || _options$onChunk === void 0 ? void 0 : _options$onChunk.call(options, chunk, index);
|
|
3903
|
+
} catch (error) {
|
|
3904
|
+
(_options$onError = options.onError) === null || _options$onError === void 0 ? void 0 : _options$onError.call(options, error);
|
|
3905
|
+
}
|
|
3906
|
+
case 1:
|
|
3907
|
+
case "end":
|
|
3908
|
+
return _context3.stop();
|
|
3909
|
+
}
|
|
3910
|
+
}, _callee3);
|
|
3911
|
+
}));
|
|
3912
|
+
return function (_x2, _x3) {
|
|
3913
|
+
return _ref3.apply(this, arguments);
|
|
3914
|
+
};
|
|
3915
|
+
}(), [options]);
|
|
3916
|
+
|
|
3917
|
+
// Start processing the stream
|
|
3918
|
+
var startProcessing = (0, react__WEBPACK_IMPORTED_MODULE_0__.useCallback)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
|
|
3919
|
+
var counter, lastContent, _yield$reader$current, done, value, _options$onComplete, chunkStr, _options$onAbort, _options$onError2;
|
|
3920
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
3921
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
3922
|
+
case 0:
|
|
3923
|
+
if (!(!reader.current || !active.current)) {
|
|
3924
|
+
_context4.next = 2;
|
|
3925
|
+
break;
|
|
3926
|
+
}
|
|
3927
|
+
return _context4.abrupt("return");
|
|
3928
|
+
case 2:
|
|
3929
|
+
//
|
|
3930
|
+
counter = 0; // Store the final content and bind it to loading
|
|
3931
|
+
lastContent = '';
|
|
3932
|
+
case 4:
|
|
3933
|
+
if (!active.current) {
|
|
3934
|
+
_context4.next = 35;
|
|
3935
|
+
break;
|
|
3936
|
+
}
|
|
3937
|
+
_context4.prev = 5;
|
|
3938
|
+
if (!paused.current) {
|
|
3939
|
+
_context4.next = 10;
|
|
3940
|
+
break;
|
|
3941
|
+
}
|
|
3942
|
+
_context4.next = 9;
|
|
3943
|
+
return new Promise(function (resolve) {
|
|
3944
|
+
return setTimeout(resolve, 100);
|
|
3945
|
+
});
|
|
3946
|
+
case 9:
|
|
3947
|
+
return _context4.abrupt("continue", 4);
|
|
3948
|
+
case 10:
|
|
3949
|
+
_context4.next = 12;
|
|
3950
|
+
return reader.current.read();
|
|
3951
|
+
case 12:
|
|
3952
|
+
_yield$reader$current = _context4.sent;
|
|
3953
|
+
done = _yield$reader$current.done;
|
|
3954
|
+
value = _yield$reader$current.value;
|
|
3955
|
+
if (!done) {
|
|
3956
|
+
_context4.next = 20;
|
|
3957
|
+
break;
|
|
3958
|
+
}
|
|
3959
|
+
(_options$onComplete = options.onComplete) === null || _options$onComplete === void 0 ? void 0 : _options$onComplete.call(options, lastContent);
|
|
3960
|
+
_context4.next = 19;
|
|
3961
|
+
return cleanup();
|
|
3962
|
+
case 19:
|
|
3963
|
+
return _context4.abrupt("break", 35);
|
|
3964
|
+
case 20:
|
|
3965
|
+
// Decode the content
|
|
3966
|
+
chunkStr = textDecoder.current.decode(value, {
|
|
3967
|
+
stream: true
|
|
3968
|
+
});
|
|
3969
|
+
lastContent += chunkStr;
|
|
3970
|
+
_context4.next = 24;
|
|
3971
|
+
return processChunk(chunkStr, counter);
|
|
3972
|
+
case 24:
|
|
3973
|
+
counter++;
|
|
3974
|
+
_context4.next = 33;
|
|
3975
|
+
break;
|
|
3976
|
+
case 27:
|
|
3977
|
+
_context4.prev = 27;
|
|
3978
|
+
_context4.t0 = _context4["catch"](5);
|
|
3979
|
+
if (_context4.t0.name === 'AbortError') {
|
|
3980
|
+
(_options$onAbort = options.onAbort) === null || _options$onAbort === void 0 ? void 0 : _options$onAbort.call(options);
|
|
3981
|
+
} else {
|
|
3982
|
+
(_options$onError2 = options.onError) === null || _options$onError2 === void 0 ? void 0 : _options$onError2.call(options, _context4.t0);
|
|
3983
|
+
}
|
|
3984
|
+
_context4.next = 32;
|
|
3985
|
+
return cleanup();
|
|
3986
|
+
case 32:
|
|
3987
|
+
return _context4.abrupt("break", 35);
|
|
3988
|
+
case 33:
|
|
3989
|
+
_context4.next = 4;
|
|
3990
|
+
break;
|
|
3991
|
+
case 35:
|
|
3992
|
+
case "end":
|
|
3993
|
+
return _context4.stop();
|
|
3994
|
+
}
|
|
3995
|
+
}, _callee4, null, [[5, 27]]);
|
|
3996
|
+
})), [options, cleanup, processChunk]);
|
|
3997
|
+
|
|
3998
|
+
// Start streaming
|
|
3999
|
+
var start = (0, react__WEBPACK_IMPORTED_MODULE_0__.useCallback)( /*#__PURE__*/function () {
|
|
4000
|
+
var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(response) {
|
|
4001
|
+
var stream, _options$onError3;
|
|
4002
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
4003
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
4004
|
+
case 0:
|
|
4005
|
+
_context6.next = 2;
|
|
4006
|
+
return cleanup();
|
|
4007
|
+
case 2:
|
|
4008
|
+
// Get Reader
|
|
4009
|
+
reader.current = response.body.getReader();
|
|
4010
|
+
_context6.prev = 3;
|
|
4011
|
+
stream = new ReadableStream({
|
|
4012
|
+
start: function start(controller) {
|
|
4013
|
+
streamController.current = controller;
|
|
4014
|
+
},
|
|
4015
|
+
pull: function pull(controller) {
|
|
4016
|
+
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
|
|
4017
|
+
var _yield$read, done, value, chunkStr;
|
|
4018
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
4019
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
4020
|
+
case 0:
|
|
4021
|
+
_context5.prev = 0;
|
|
4022
|
+
_context5.next = 3;
|
|
4023
|
+
return reader.current.read();
|
|
4024
|
+
case 3:
|
|
4025
|
+
_yield$read = _context5.sent;
|
|
4026
|
+
done = _yield$read.done;
|
|
4027
|
+
value = _yield$read.value;
|
|
4028
|
+
if (!done) {
|
|
4029
|
+
_context5.next = 9;
|
|
4030
|
+
break;
|
|
4031
|
+
}
|
|
4032
|
+
controller.close();
|
|
4033
|
+
return _context5.abrupt("return");
|
|
4034
|
+
case 9:
|
|
4035
|
+
// Decode the content
|
|
4036
|
+
chunkStr = textDecoder.current.decode(value, {
|
|
4037
|
+
stream: true
|
|
4038
|
+
});
|
|
4039
|
+
controller.enqueue(chunkStr);
|
|
4040
|
+
_context5.next = 16;
|
|
4041
|
+
break;
|
|
4042
|
+
case 13:
|
|
4043
|
+
_context5.prev = 13;
|
|
4044
|
+
_context5.t0 = _context5["catch"](0);
|
|
4045
|
+
controller.error(_context5.t0);
|
|
4046
|
+
case 16:
|
|
4047
|
+
case "end":
|
|
4048
|
+
return _context5.stop();
|
|
4049
|
+
}
|
|
4050
|
+
}, _callee5, null, [[0, 13]]);
|
|
4051
|
+
}))();
|
|
4052
|
+
},
|
|
4053
|
+
cancel: function cancel() {
|
|
4054
|
+
var _response$body;
|
|
4055
|
+
(_response$body = response.body) === null || _response$body === void 0 ? void 0 : _response$body.cancel();
|
|
4056
|
+
}
|
|
4057
|
+
});
|
|
4058
|
+
activeStream.current = stream;
|
|
4059
|
+
active.current = true;
|
|
4060
|
+
paused.current = false;
|
|
4061
|
+
|
|
4062
|
+
// Start processing immediately
|
|
4063
|
+
_context6.next = 10;
|
|
4064
|
+
return startProcessing();
|
|
4065
|
+
case 10:
|
|
4066
|
+
_context6.next = 16;
|
|
4067
|
+
break;
|
|
4068
|
+
case 12:
|
|
4069
|
+
_context6.prev = 12;
|
|
4070
|
+
_context6.t0 = _context6["catch"](3);
|
|
4071
|
+
(_options$onError3 = options.onError) === null || _options$onError3 === void 0 ? void 0 : _options$onError3.call(options, _context6.t0);
|
|
4072
|
+
cleanup();
|
|
4073
|
+
case 16:
|
|
4074
|
+
case "end":
|
|
4075
|
+
return _context6.stop();
|
|
4076
|
+
}
|
|
4077
|
+
}, _callee6, null, [[3, 12]]);
|
|
4078
|
+
}));
|
|
4079
|
+
return function (_x4) {
|
|
4080
|
+
return _ref5.apply(this, arguments);
|
|
4081
|
+
};
|
|
4082
|
+
}(), [options, cleanup, startProcessing]);
|
|
4083
|
+
|
|
4084
|
+
// Pause streaming
|
|
4085
|
+
var pause = (0, react__WEBPACK_IMPORTED_MODULE_0__.useCallback)(function () {
|
|
4086
|
+
paused.current = true;
|
|
4087
|
+
}, []);
|
|
4088
|
+
|
|
4089
|
+
// Resume streaming
|
|
4090
|
+
var resume = (0, react__WEBPACK_IMPORTED_MODULE_0__.useCallback)(function () {
|
|
4091
|
+
paused.current = false;
|
|
4092
|
+
}, []);
|
|
4093
|
+
|
|
4094
|
+
// Abort streaming
|
|
4095
|
+
var abort = (0, react__WEBPACK_IMPORTED_MODULE_0__.useCallback)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
|
|
4096
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
4097
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
4098
|
+
case 0:
|
|
4099
|
+
abortController.current.abort();
|
|
4100
|
+
_context7.next = 3;
|
|
4101
|
+
return cleanup();
|
|
4102
|
+
case 3:
|
|
4103
|
+
case "end":
|
|
4104
|
+
return _context7.stop();
|
|
4105
|
+
}
|
|
4106
|
+
}, _callee7);
|
|
4107
|
+
})), [cleanup]);
|
|
4108
|
+
|
|
4109
|
+
// Check if stream is active
|
|
4110
|
+
var isActive = (0, react__WEBPACK_IMPORTED_MODULE_0__.useCallback)(function () {
|
|
4111
|
+
return active.current;
|
|
4112
|
+
}, []);
|
|
4113
|
+
|
|
4114
|
+
// Check if stream is paused
|
|
4115
|
+
var isPaused = (0, react__WEBPACK_IMPORTED_MODULE_0__.useCallback)(function () {
|
|
4116
|
+
return paused.current;
|
|
4117
|
+
}, []);
|
|
4118
|
+
|
|
4119
|
+
// Cleanup on unmount
|
|
4120
|
+
(0, react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(function () {
|
|
4121
|
+
return function () {
|
|
4122
|
+
cleanup()["catch"](console.error);
|
|
4123
|
+
};
|
|
4124
|
+
}, [cleanup]);
|
|
4125
|
+
return {
|
|
4126
|
+
start: start,
|
|
4127
|
+
pause: pause,
|
|
4128
|
+
resume: resume,
|
|
4129
|
+
abort: abort,
|
|
4130
|
+
isActive: isActive,
|
|
4131
|
+
isPaused: isPaused
|
|
4132
|
+
};
|
|
4133
|
+
};
|
|
4134
|
+
/* harmony default export */
|
|
4135
|
+
var __WEBPACK_DEFAULT_EXPORT__ = _useStreamController;
|
|
4136
|
+
})();
|
|
4137
|
+
|
|
4138
|
+
/******/
|
|
4139
|
+
return __webpack_exports__;
|
|
4140
|
+
/******/
|
|
4141
|
+
}()
|
|
4142
|
+
);
|
|
4143
|
+
});
|
|
4144
|
+
|
|
4145
|
+
/***/ }),
|
|
4146
|
+
|
|
3257
4147
|
/***/ 195:
|
|
3258
4148
|
/***/ (function(module, exports, __webpack_require__) {
|
|
3259
4149
|
|
|
@@ -3351,90 +4241,641 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
|
|
|
3351
4241
|
}
|
|
3352
4242
|
/******/
|
|
3353
4243
|
}
|
|
3354
|
-
/******/
|
|
3355
|
-
};
|
|
3356
|
-
/******/
|
|
3357
|
-
})();
|
|
3358
|
-
/******/
|
|
3359
|
-
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
3360
|
-
/******/
|
|
3361
|
-
(function () {
|
|
3362
|
-
/******/__nested_webpack_require_1465__.o = function (obj, prop) {
|
|
3363
|
-
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
3364
|
-
};
|
|
3365
|
-
/******/
|
|
3366
|
-
})();
|
|
3367
|
-
/******/
|
|
3368
|
-
/******/ /* webpack/runtime/make namespace object */
|
|
3369
|
-
/******/
|
|
3370
|
-
(function () {
|
|
3371
|
-
/******/ // define __esModule on exports
|
|
3372
|
-
/******/__nested_webpack_require_1465__.r = function (exports) {
|
|
3373
|
-
/******/if (typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
3374
|
-
/******/Object.defineProperty(exports, Symbol.toStringTag, {
|
|
3375
|
-
value: 'Module'
|
|
3376
|
-
});
|
|
3377
|
-
/******/
|
|
4244
|
+
/******/
|
|
4245
|
+
};
|
|
4246
|
+
/******/
|
|
4247
|
+
})();
|
|
4248
|
+
/******/
|
|
4249
|
+
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
4250
|
+
/******/
|
|
4251
|
+
(function () {
|
|
4252
|
+
/******/__nested_webpack_require_1465__.o = function (obj, prop) {
|
|
4253
|
+
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
4254
|
+
};
|
|
4255
|
+
/******/
|
|
4256
|
+
})();
|
|
4257
|
+
/******/
|
|
4258
|
+
/******/ /* webpack/runtime/make namespace object */
|
|
4259
|
+
/******/
|
|
4260
|
+
(function () {
|
|
4261
|
+
/******/ // define __esModule on exports
|
|
4262
|
+
/******/__nested_webpack_require_1465__.r = function (exports) {
|
|
4263
|
+
/******/if (typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
4264
|
+
/******/Object.defineProperty(exports, Symbol.toStringTag, {
|
|
4265
|
+
value: 'Module'
|
|
4266
|
+
});
|
|
4267
|
+
/******/
|
|
4268
|
+
}
|
|
4269
|
+
/******/
|
|
4270
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4271
|
+
value: true
|
|
4272
|
+
});
|
|
4273
|
+
/******/
|
|
4274
|
+
};
|
|
4275
|
+
/******/
|
|
4276
|
+
})();
|
|
4277
|
+
/******/
|
|
4278
|
+
/************************************************************************/
|
|
4279
|
+
var __webpack_exports__ = {};
|
|
4280
|
+
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
|
|
4281
|
+
(function () {
|
|
4282
|
+
__nested_webpack_require_1465__.r(__webpack_exports__);
|
|
4283
|
+
/* harmony export */
|
|
4284
|
+
__nested_webpack_require_1465__.d(__webpack_exports__, {
|
|
4285
|
+
/* harmony export */"default": function _default() {
|
|
4286
|
+
return __WEBPACK_DEFAULT_EXPORT__;
|
|
4287
|
+
}
|
|
4288
|
+
/* harmony export */
|
|
4289
|
+
});
|
|
4290
|
+
/* harmony import */
|
|
4291
|
+
var react__WEBPACK_IMPORTED_MODULE_0__ = __nested_webpack_require_1465__(787);
|
|
4292
|
+
/* harmony import */
|
|
4293
|
+
var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__nested_webpack_require_1465__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
4294
|
+
/**
|
|
4295
|
+
* Limiting the rate of execution
|
|
4296
|
+
*
|
|
4297
|
+
* @usage:
|
|
4298
|
+
|
|
4299
|
+
const App = () => {
|
|
4300
|
+
const [count, setCount] = useState(0);
|
|
4301
|
+
const handleClick = useThrottle(() => setCount(count + 1), 500, [count]);
|
|
4302
|
+
|
|
4303
|
+
return (
|
|
4304
|
+
<div className="app">
|
|
4305
|
+
<button onClick={handleClick}>click</button>
|
|
4306
|
+
<p>click {count} time</p>
|
|
4307
|
+
</div>
|
|
4308
|
+
);
|
|
4309
|
+
};
|
|
4310
|
+
|
|
4311
|
+
*/
|
|
4312
|
+
|
|
4313
|
+
var useThrottle = function useThrottle(fn, delay, dependence) {
|
|
4314
|
+
var ref = (0, react__WEBPACK_IMPORTED_MODULE_0__.useRef)({
|
|
4315
|
+
lastTime: 0
|
|
4316
|
+
});
|
|
4317
|
+
return (0, react__WEBPACK_IMPORTED_MODULE_0__.useCallback)(function () {
|
|
4318
|
+
var now = Date.now();
|
|
4319
|
+
if (now - ref.current.lastTime >= delay) {
|
|
4320
|
+
fn.apply(void 0, arguments);
|
|
4321
|
+
ref.current.lastTime = now;
|
|
4322
|
+
}
|
|
4323
|
+
}, dependence);
|
|
4324
|
+
};
|
|
4325
|
+
/* harmony default export */
|
|
4326
|
+
var __WEBPACK_DEFAULT_EXPORT__ = useThrottle;
|
|
4327
|
+
})();
|
|
4328
|
+
|
|
4329
|
+
/******/
|
|
4330
|
+
return __webpack_exports__;
|
|
4331
|
+
/******/
|
|
4332
|
+
}()
|
|
4333
|
+
);
|
|
4334
|
+
});
|
|
4335
|
+
|
|
4336
|
+
/***/ }),
|
|
4337
|
+
|
|
4338
|
+
/***/ 455:
|
|
4339
|
+
/***/ (function(module, exports, __webpack_require__) {
|
|
4340
|
+
|
|
4341
|
+
/* module decorator */ module = __webpack_require__.nmd(module);
|
|
4342
|
+
var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;function _typeof2(obj) { "@babel/helpers - typeof"; return _typeof2 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof2(obj); }
|
|
4343
|
+
(function webpackUniversalModuleDefinition(root, factory) {
|
|
4344
|
+
if (( false ? 0 : _typeof2(exports)) === 'object' && ( false ? 0 : _typeof2(module)) === 'object') module.exports = factory();else if (true) !(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory),
|
|
4345
|
+
__WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ?
|
|
4346
|
+
(__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__),
|
|
4347
|
+
__WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));else {}
|
|
4348
|
+
})(this, function () {
|
|
4349
|
+
return (/******/function () {
|
|
4350
|
+
// webpackBootstrap
|
|
4351
|
+
/******/
|
|
4352
|
+
"use strict";
|
|
4353
|
+
|
|
4354
|
+
/******/ // The require scope
|
|
4355
|
+
/******/
|
|
4356
|
+
var __nested_webpack_require_993__ = {};
|
|
4357
|
+
/******/
|
|
4358
|
+
/************************************************************************/
|
|
4359
|
+
/******/ /* webpack/runtime/define property getters */
|
|
4360
|
+
/******/
|
|
4361
|
+
(function () {
|
|
4362
|
+
/******/ // define getter functions for harmony exports
|
|
4363
|
+
/******/__nested_webpack_require_993__.d = function (exports, definition) {
|
|
4364
|
+
/******/for (var key in definition) {
|
|
4365
|
+
/******/if (__nested_webpack_require_993__.o(definition, key) && !__nested_webpack_require_993__.o(exports, key)) {
|
|
4366
|
+
/******/Object.defineProperty(exports, key, {
|
|
4367
|
+
enumerable: true,
|
|
4368
|
+
get: definition[key]
|
|
4369
|
+
});
|
|
4370
|
+
/******/
|
|
4371
|
+
}
|
|
4372
|
+
/******/
|
|
4373
|
+
}
|
|
4374
|
+
/******/
|
|
4375
|
+
};
|
|
4376
|
+
/******/
|
|
4377
|
+
})();
|
|
4378
|
+
/******/
|
|
4379
|
+
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
4380
|
+
/******/
|
|
4381
|
+
(function () {
|
|
4382
|
+
/******/__nested_webpack_require_993__.o = function (obj, prop) {
|
|
4383
|
+
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
4384
|
+
};
|
|
4385
|
+
/******/
|
|
4386
|
+
})();
|
|
4387
|
+
/******/
|
|
4388
|
+
/******/ /* webpack/runtime/make namespace object */
|
|
4389
|
+
/******/
|
|
4390
|
+
(function () {
|
|
4391
|
+
/******/ // define __esModule on exports
|
|
4392
|
+
/******/__nested_webpack_require_993__.r = function (exports) {
|
|
4393
|
+
/******/if (typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
4394
|
+
/******/Object.defineProperty(exports, Symbol.toStringTag, {
|
|
4395
|
+
value: 'Module'
|
|
4396
|
+
});
|
|
4397
|
+
/******/
|
|
4398
|
+
}
|
|
4399
|
+
/******/
|
|
4400
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4401
|
+
value: true
|
|
4402
|
+
});
|
|
4403
|
+
/******/
|
|
4404
|
+
};
|
|
4405
|
+
/******/
|
|
4406
|
+
})();
|
|
4407
|
+
/******/
|
|
4408
|
+
/************************************************************************/
|
|
4409
|
+
var __webpack_exports__ = {};
|
|
4410
|
+
__nested_webpack_require_993__.r(__webpack_exports__);
|
|
4411
|
+
/* harmony export */
|
|
4412
|
+
__nested_webpack_require_993__.d(__webpack_exports__, {
|
|
4413
|
+
/* harmony export */"fixAndParseJSON": function fixAndParseJSON() {
|
|
4414
|
+
return (/* binding */_fixAndParseJSON
|
|
4415
|
+
);
|
|
4416
|
+
},
|
|
4417
|
+
/* harmony export */"isEmail": function isEmail() {
|
|
4418
|
+
return (/* binding */_isEmail
|
|
4419
|
+
);
|
|
4420
|
+
},
|
|
4421
|
+
/* harmony export */"isEmpty": function isEmpty() {
|
|
4422
|
+
return (/* binding */_isEmpty
|
|
4423
|
+
);
|
|
4424
|
+
},
|
|
4425
|
+
/* harmony export */"isInt": function isInt() {
|
|
4426
|
+
return (/* binding */_isInt
|
|
4427
|
+
);
|
|
4428
|
+
},
|
|
4429
|
+
/* harmony export */"isJSON": function isJSON() {
|
|
4430
|
+
return (/* binding */_isJSON
|
|
4431
|
+
);
|
|
4432
|
+
},
|
|
4433
|
+
/* harmony export */"isMobile": function isMobile() {
|
|
4434
|
+
return (/* binding */_isMobile
|
|
4435
|
+
);
|
|
4436
|
+
},
|
|
4437
|
+
/* harmony export */"isNumber": function isNumber() {
|
|
4438
|
+
return (/* binding */_isNumber
|
|
4439
|
+
);
|
|
4440
|
+
},
|
|
4441
|
+
/* harmony export */"isTel": function isTel() {
|
|
4442
|
+
return (/* binding */_isTel
|
|
4443
|
+
);
|
|
4444
|
+
},
|
|
4445
|
+
/* harmony export */"isValidNumeric": function isValidNumeric() {
|
|
4446
|
+
return (/* binding */_isValidNumeric
|
|
4447
|
+
);
|
|
4448
|
+
}
|
|
4449
|
+
/* harmony export */
|
|
4450
|
+
});
|
|
4451
|
+
function _typeof(obj) {
|
|
4452
|
+
"@babel/helpers - typeof";
|
|
4453
|
+
|
|
4454
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
|
|
4455
|
+
return typeof obj;
|
|
4456
|
+
} : function (obj) {
|
|
4457
|
+
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
4458
|
+
}, _typeof(obj);
|
|
4459
|
+
}
|
|
4460
|
+
/**
|
|
4461
|
+
* Fix And Parse JSON (Support for handling complex escape JSON strings)
|
|
4462
|
+
* @private
|
|
4463
|
+
*/
|
|
4464
|
+
/*
|
|
4465
|
+
- Always try JSON.parse first;
|
|
4466
|
+
- If parsing fails, unescape \" → ";
|
|
4467
|
+
- Then process the outermost object or array key-by-key, value-by-value;
|
|
4468
|
+
- If a top-level value is an unquoted object or array (e.g. messages: [ {...} ]),
|
|
4469
|
+
recursively treat that value as a new root to repair;
|
|
4470
|
+
- For values wrapped in quotes ('...' or "..."), extract the inner text and
|
|
4471
|
+
re-encode it using JSON.stringify (ensures internal single/double quotes
|
|
4472
|
+
are not corrupted);
|
|
4473
|
+
- Set MAX_DEPTH to prevent infinite recursion.
|
|
4474
|
+
*/
|
|
4475
|
+
// fixAndParseJSON - recursively repairs top-level key/value
|
|
4476
|
+
// (when encountering outermost values that are objects/arrays, it recurses)
|
|
4477
|
+
|
|
4478
|
+
/*
|
|
4479
|
+
DEMO:
|
|
4480
|
+
|
|
4481
|
+
// ✅ Valid JSON (contains svg and single-quote content)
|
|
4482
|
+
const okJson = `{
|
|
4483
|
+
"label":"<svg width='16' height='16'><path fill='currentColor' d='M19 13h-6'/></svg> New Session",
|
|
4484
|
+
"value":"new",
|
|
4485
|
+
"onClick":"method.setVal(''); method.clearData();"
|
|
4486
|
+
}`;
|
|
4487
|
+
|
|
4488
|
+
// ❌ Single-quote JSON
|
|
4489
|
+
const badJson = "{'model':'{model}','messages':[{'role':'user','content':'{message}'}],'stream': true}";
|
|
4490
|
+
|
|
4491
|
+
// ❌ Escaped JSON
|
|
4492
|
+
const badJson2 = "{\\\"label\\\":\\\"<svg width='16' height='16' viewBox='0 0 24 24'><path fill='currentColor' d='M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z'/></svg> New Session\\\",\\\"value\\\":\\\"new\\\",\\\"onClick\\\":\\\"method.setVal(''); method.clearData();\\\"}";
|
|
4493
|
+
|
|
4494
|
+
const badJson3 = "{\"label\":\"<svg width='16' height='16' viewBox='0 0 24 24'><path fill='currentColor' d='M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z'/></svg> New Session\",\"value\":\"new\",\"onClick\":\"method.setVal(''); method.clearData();\"}";
|
|
4495
|
+
|
|
4496
|
+
const badJson4 = "[{\"label\":\"<svg fill='currentColor' width='12' height='12' viewBox='0 0 24 24'><path d='M20.5 9a3.49 3.49 0 0 0-3.45 3h-1.1a2.49 2.49 0 0 0-4.396-1.052L8.878 9.731l3.143-4.225a2.458 2.458 0 0 0 2.98-.019L17.339 8H16v1h3V6h-1v1.243l-2.336-2.512A2.473 2.473 0 0 0 16 3.5a2.5 2.5 0 0 0-5 0 2.474 2.474 0 0 0 .343 1.243L7.947 9.308 4.955 7.947a2.404 2.404 0 0 0-.161-1.438l3.704-1.385-.44 1.371.942.333L10 4 7.172 3l-.334.943 1.01.357-3.659 1.368a2.498 2.498 0 1 0-.682 4.117l2.085 2.688-2.053 2.76a2.5 2.5 0 1 0 .87 3.864l3.484 1.587-1.055.373.334.943L10 21l-1-2.828-.943.333.435 1.354-3.608-1.645A2.471 2.471 0 0 0 5 17.5a2.5 2.5 0 0 0-.058-.527l3.053-1.405 3.476 4.48a2.498 2.498 0 1 0 4.113.075L18 17.707V19h1v-3h-3v1h1.293l-2.416 2.416a2.466 2.466 0 0 0-2.667-.047l-3.283-4.23 2.554-1.176A2.494 2.494 0 0 0 15.95 13h1.1a3.493 3.493 0 1 0 3.45-4zm-7-7A1.5 1.5 0 1 1 12 3.5 1.502 1.502 0 0 1 13.5 2zm0 18a1.5 1.5 0 1 1-1.5 1.5 1.502 1.502 0 0 1 1.5-1.5zM1 7.5a1.5 1.5 0 1 1 2.457 1.145l-.144.112A1.496 1.496 0 0 1 1 7.5zm3.32 1.703a2.507 2.507 0 0 0 .264-.326l2.752 1.251-1.124 1.512zM2.5 19A1.5 1.5 0 1 1 4 17.5 1.502 1.502 0 0 1 2.5 19zm2.037-2.941a2.518 2.518 0 0 0-.193-.234l1.885-2.532 1.136 1.464zm3.76-1.731L6.849 12.46l1.42-1.908L11.1 11.84a2.29 2.29 0 0 0-.033 1.213zM13.5 14a1.5 1.5 0 1 1 1.5-1.5 1.502 1.502 0 0 1-1.5 1.5zm7 1a2.5 2.5 0 1 1 2.5-2.5 2.502 2.502 0 0 1-2.5 2.5zm1.5-2.5a1.5 1.5 0 1 1-1.5-1.5 1.502 1.502 0 0 1 1.5 1.5z'/><path fill='none' d='M0 0h24v24H0z'/></svg> Deep Thought","value":"brief","onClick":"if(isActive){method.executeCustomMethod('changeModel', true)}else{method.executeCustomMethod('changeModel', false)}"},{"label":"<svg fill='currentColor' width='12' height='12' viewBox='0 0 24 24'><path d='M19 2H5c-1.103 0-2 .897-2 2v12c0 1.103.897 2 2 2h3.586L12 21.414 15.414 18H19c1.103 0 2-.897 2-2V4c0-1.103-.897-2-2-2zm0 14h-4.414L12 18.586 9.414 16H5V4h14v12z'/></svg> Concise Answer","value":"brief","onClick":"if(isActive){method.setContextData({systemPrompt:'Please answer concisely, around 150 words, keep reasoning brief',mergedText:method.getContextData().mergedText,analyzeMetrics:method.getContextData().analyzeMetrics});}else{method.setContextData({mergedText:method.getContextData().mergedText,analyzeMetrics:method.getContextData().analyzeMetrics});}"},{"label":"<svg fill='none' width='12' height='12' viewBox='0 0 16 16'><path d='M7 0.0618896V9H15.9381C15.446 12.9463 12.0796 16 8 16C3.58172 16 0 12.4183 0 8C0 3.92038 3.05369 0.553988 7 0.0618896Z' fill='currentColor'/><path d='M9 0.0618897V7H15.9381C15.4869 3.38128 12.6187 0.513137 9 0.0618897Z' fill='currentColor'/></svg> Metrics Analysis","value":"lab","onClick":"return method.executeCustomMethod('getLibList')","isSelect":true,"dynamicOptions":true}]";
|
|
4497
|
+
|
|
4498
|
+
|
|
4499
|
+
console.log('okJson =>', fixAndParseJSON(okJson)); // parses correctly
|
|
4500
|
+
console.log('badJson =>', fixAndParseJSON(badJson)); // repaired and parsed
|
|
4501
|
+
console.log('badJson2 =>', fixAndParseJSON(badJson2)); // repaired and parsed
|
|
4502
|
+
console.log('badJson3 =>', fixAndParseJSON(badJson3)); // repaired and parsed
|
|
4503
|
+
console.log('badJson4 =>', fixAndParseJSON(badJson4)); // repaired and parsed
|
|
4504
|
+
*/
|
|
4505
|
+
function _fixAndParseJSON(input) {
|
|
4506
|
+
var MAX_DEPTH = 6;
|
|
4507
|
+
|
|
4508
|
+
// 1. Fast attempt
|
|
4509
|
+
try {
|
|
4510
|
+
return {
|
|
4511
|
+
success: true,
|
|
4512
|
+
data: JSON.parse(input)
|
|
4513
|
+
};
|
|
4514
|
+
} catch (e) {
|
|
4515
|
+
// continue to repair
|
|
4516
|
+
}
|
|
4517
|
+
|
|
4518
|
+
// 2. Simple unescape of \" (common when copied from JS literals)
|
|
4519
|
+
var s = input;
|
|
4520
|
+
if (s.includes('\\"')) s = s.replace(/\\"/g, '"');
|
|
4521
|
+
s = s.trim();
|
|
4522
|
+
try {
|
|
4523
|
+
if (s.startsWith('{')) {
|
|
4524
|
+
s = processTopObject(s, 0, MAX_DEPTH);
|
|
4525
|
+
} else if (s.startsWith('[')) {
|
|
4526
|
+
s = processTopArray(s, 0, MAX_DEPTH);
|
|
4527
|
+
} else {
|
|
4528
|
+
throw new Error('Input is not an object or array');
|
|
4529
|
+
}
|
|
4530
|
+
return {
|
|
4531
|
+
success: true,
|
|
4532
|
+
data: JSON.parse(s)
|
|
4533
|
+
};
|
|
4534
|
+
} catch (err) {
|
|
4535
|
+
return {
|
|
4536
|
+
success: false,
|
|
4537
|
+
error: 'Invalid JSON format',
|
|
4538
|
+
details: err instanceof Error ? err.message : String(err)
|
|
4539
|
+
};
|
|
4540
|
+
}
|
|
4541
|
+
}
|
|
4542
|
+
|
|
4543
|
+
/* ---------- Helper (recursive) functions ---------- */
|
|
4544
|
+
|
|
4545
|
+
function processTopObject(str, depth, MAX_DEPTH) {
|
|
4546
|
+
if (depth > MAX_DEPTH) return str;
|
|
4547
|
+
str = str.trim();
|
|
4548
|
+
// Ensure it is wrapped in { ... }
|
|
4549
|
+
if (!(str.startsWith('{') && str.endsWith('}'))) {
|
|
4550
|
+
var f = str.indexOf('{');
|
|
4551
|
+
var l = str.lastIndexOf('}');
|
|
4552
|
+
if (f === -1 || l === -1 || l <= f) return str;
|
|
4553
|
+
str = str.slice(f, l + 1);
|
|
4554
|
+
}
|
|
4555
|
+
var inner = str.slice(1, -1);
|
|
4556
|
+
var pairs = splitTopLevel(inner);
|
|
4557
|
+
var repairedPairs = pairs.map(function (pair) {
|
|
4558
|
+
if (!pair || pair.trim() === '') return '';
|
|
4559
|
+
var idx = findTopLevelColon(pair);
|
|
4560
|
+
if (idx === -1) {
|
|
4561
|
+
return pair; // Non key:value fragment, keep as is (rare case)
|
|
4562
|
+
}
|
|
4563
|
+
|
|
4564
|
+
var rawKey = pair.slice(0, idx).trim();
|
|
4565
|
+
var rawVal = pair.slice(idx + 1);
|
|
4566
|
+
var keyContent = extractKeyContent(rawKey);
|
|
4567
|
+
var keyJson = JSON.stringify(keyContent);
|
|
4568
|
+
var repairedValue = repairPossiblyQuotedValue(rawVal, depth + 1, MAX_DEPTH);
|
|
4569
|
+
return keyJson + ':' + repairedValue;
|
|
4570
|
+
});
|
|
4571
|
+
return '{' + repairedPairs.join(',') + '}';
|
|
4572
|
+
}
|
|
4573
|
+
function processTopArray(str, depth, MAX_DEPTH) {
|
|
4574
|
+
if (depth > MAX_DEPTH) return str;
|
|
4575
|
+
str = str.trim();
|
|
4576
|
+
if (!(str.startsWith('[') && str.endsWith(']'))) {
|
|
4577
|
+
var f = str.indexOf('[');
|
|
4578
|
+
var l = str.lastIndexOf(']');
|
|
4579
|
+
if (f === -1 || l === -1 || l <= f) return str;
|
|
4580
|
+
str = str.slice(f, l + 1);
|
|
4581
|
+
}
|
|
4582
|
+
var inner = str.slice(1, -1);
|
|
4583
|
+
var elements = splitTopLevel(inner);
|
|
4584
|
+
var processed = elements.map(function (el) {
|
|
4585
|
+
var t = el.trim();
|
|
4586
|
+
if (t === '') return '';
|
|
4587
|
+
if (t.startsWith('{')) return processTopObject(t, depth + 1, MAX_DEPTH);
|
|
4588
|
+
if (t.startsWith('[')) return processTopArray(t, depth + 1, MAX_DEPTH);
|
|
4589
|
+
return repairPossiblyQuotedValue(t, depth + 1, MAX_DEPTH);
|
|
4590
|
+
});
|
|
4591
|
+
return '[' + processed.join(',') + ']';
|
|
4592
|
+
}
|
|
4593
|
+
|
|
4594
|
+
// If value is quoted, extract inside and JSON.stringify again (safe escaping)
|
|
4595
|
+
// If value is unquoted object/array literal, recurse treating it as new root
|
|
4596
|
+
// Otherwise return as is (numbers, booleans, null, or raw expressions)
|
|
4597
|
+
function repairPossiblyQuotedValue(rawVal, depth, MAX_DEPTH) {
|
|
4598
|
+
var v = rawVal.trim();
|
|
4599
|
+
if (v === '') return v;
|
|
4600
|
+
if (v[0] === '"' || v[0] === "'") {
|
|
4601
|
+
var quote = v[0];
|
|
4602
|
+
// Find the last unescaped matching quote
|
|
4603
|
+
var lastPos = -1;
|
|
4604
|
+
for (var i = v.length - 1; i >= 0; i--) {
|
|
4605
|
+
if (v[i] === quote) {
|
|
4606
|
+
// check if escaped
|
|
4607
|
+
var bs = 0;
|
|
4608
|
+
var k = i - 1;
|
|
4609
|
+
while (k >= 0 && v[k] === '\\') {
|
|
4610
|
+
bs++;
|
|
4611
|
+
k--;
|
|
4612
|
+
}
|
|
4613
|
+
if (bs % 2 === 0) {
|
|
4614
|
+
lastPos = i;
|
|
4615
|
+
break;
|
|
4616
|
+
}
|
|
4617
|
+
}
|
|
4618
|
+
}
|
|
4619
|
+
var inner = lastPos > 0 ? v.slice(1, lastPos) : v.slice(1);
|
|
4620
|
+
return JSON.stringify(inner); // Generate valid JSON string (auto escape)
|
|
4621
|
+
}
|
|
4622
|
+
|
|
4623
|
+
// If unquoted object/array literal -> recurse
|
|
4624
|
+
if (v.startsWith('{')) {
|
|
4625
|
+
return processTopObject(v, depth, MAX_DEPTH);
|
|
4626
|
+
}
|
|
4627
|
+
if (v.startsWith('[')) {
|
|
4628
|
+
return processTopArray(v, depth, MAX_DEPTH);
|
|
4629
|
+
}
|
|
4630
|
+
|
|
4631
|
+
// Other (number, boolean, null, raw expression): return as is
|
|
4632
|
+
return v;
|
|
4633
|
+
}
|
|
4634
|
+
|
|
4635
|
+
/* --------- Utils: split by top-level commas, find colon, extract key --------- */
|
|
4636
|
+
|
|
4637
|
+
// Split string by top-level commas (ignores commas inside strings/objects/arrays/parentheses)
|
|
4638
|
+
function splitTopLevel(str) {
|
|
4639
|
+
var parts = [];
|
|
4640
|
+
var buf = '';
|
|
4641
|
+
var depthCurly = 0;
|
|
4642
|
+
var depthSquare = 0;
|
|
4643
|
+
var depthParen = 0;
|
|
4644
|
+
var inSingle = false;
|
|
4645
|
+
var inDouble = false;
|
|
4646
|
+
var esc = false;
|
|
4647
|
+
for (var i = 0; i < str.length; i++) {
|
|
4648
|
+
var ch = str[i];
|
|
4649
|
+
if (esc) {
|
|
4650
|
+
buf += ch;
|
|
4651
|
+
esc = false;
|
|
4652
|
+
continue;
|
|
4653
|
+
}
|
|
4654
|
+
if (ch === '\\') {
|
|
4655
|
+
buf += ch;
|
|
4656
|
+
esc = true;
|
|
4657
|
+
continue;
|
|
4658
|
+
}
|
|
4659
|
+
if (ch === "'" && !inDouble) {
|
|
4660
|
+
inSingle = !inSingle;
|
|
4661
|
+
buf += ch;
|
|
4662
|
+
continue;
|
|
4663
|
+
}
|
|
4664
|
+
if (ch === '"' && !inSingle) {
|
|
4665
|
+
inDouble = !inDouble;
|
|
4666
|
+
buf += ch;
|
|
4667
|
+
continue;
|
|
4668
|
+
}
|
|
4669
|
+
if (!inSingle && !inDouble) {
|
|
4670
|
+
if (ch === '{') {
|
|
4671
|
+
depthCurly++;
|
|
4672
|
+
buf += ch;
|
|
4673
|
+
continue;
|
|
4674
|
+
}
|
|
4675
|
+
if (ch === '}') {
|
|
4676
|
+
depthCurly--;
|
|
4677
|
+
buf += ch;
|
|
4678
|
+
continue;
|
|
4679
|
+
}
|
|
4680
|
+
if (ch === '[') {
|
|
4681
|
+
depthSquare++;
|
|
4682
|
+
buf += ch;
|
|
4683
|
+
continue;
|
|
4684
|
+
}
|
|
4685
|
+
if (ch === ']') {
|
|
4686
|
+
depthSquare--;
|
|
4687
|
+
buf += ch;
|
|
4688
|
+
continue;
|
|
4689
|
+
}
|
|
4690
|
+
if (ch === '(') {
|
|
4691
|
+
depthParen++;
|
|
4692
|
+
buf += ch;
|
|
4693
|
+
continue;
|
|
4694
|
+
}
|
|
4695
|
+
if (ch === ')') {
|
|
4696
|
+
depthParen--;
|
|
4697
|
+
buf += ch;
|
|
4698
|
+
continue;
|
|
4699
|
+
}
|
|
4700
|
+
if (ch === ',' && depthCurly === 0 && depthSquare === 0 && depthParen === 0) {
|
|
4701
|
+
parts.push(buf);
|
|
4702
|
+
buf = '';
|
|
4703
|
+
continue;
|
|
4704
|
+
}
|
|
4705
|
+
}
|
|
4706
|
+
buf += ch;
|
|
4707
|
+
}
|
|
4708
|
+
if (buf.trim() !== '') parts.push(buf);
|
|
4709
|
+
return parts;
|
|
4710
|
+
}
|
|
4711
|
+
|
|
4712
|
+
// Find the first top-level colon (ignores strings and nested structures)
|
|
4713
|
+
function findTopLevelColon(str) {
|
|
4714
|
+
var inSingle = false;
|
|
4715
|
+
var inDouble = false;
|
|
4716
|
+
var esc = false;
|
|
4717
|
+
var depthCurly = 0;
|
|
4718
|
+
var depthSquare = 0;
|
|
4719
|
+
var depthParen = 0;
|
|
4720
|
+
for (var i = 0; i < str.length; i++) {
|
|
4721
|
+
var ch = str[i];
|
|
4722
|
+
if (esc) {
|
|
4723
|
+
esc = false;
|
|
4724
|
+
continue;
|
|
4725
|
+
}
|
|
4726
|
+
if (ch === '\\') {
|
|
4727
|
+
esc = true;
|
|
4728
|
+
continue;
|
|
4729
|
+
}
|
|
4730
|
+
if (ch === "'" && !inDouble) {
|
|
4731
|
+
inSingle = !inSingle;
|
|
4732
|
+
continue;
|
|
3378
4733
|
}
|
|
3379
|
-
|
|
3380
|
-
|
|
3381
|
-
|
|
3382
|
-
});
|
|
3383
|
-
/******/
|
|
3384
|
-
};
|
|
3385
|
-
/******/
|
|
3386
|
-
})();
|
|
3387
|
-
/******/
|
|
3388
|
-
/************************************************************************/
|
|
3389
|
-
var __webpack_exports__ = {};
|
|
3390
|
-
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
|
|
3391
|
-
(function () {
|
|
3392
|
-
__nested_webpack_require_1465__.r(__webpack_exports__);
|
|
3393
|
-
/* harmony export */
|
|
3394
|
-
__nested_webpack_require_1465__.d(__webpack_exports__, {
|
|
3395
|
-
/* harmony export */"default": function _default() {
|
|
3396
|
-
return __WEBPACK_DEFAULT_EXPORT__;
|
|
4734
|
+
if (ch === '"' && !inSingle) {
|
|
4735
|
+
inDouble = !inDouble;
|
|
4736
|
+
continue;
|
|
3397
4737
|
}
|
|
3398
|
-
|
|
3399
|
-
|
|
3400
|
-
|
|
3401
|
-
|
|
3402
|
-
|
|
3403
|
-
|
|
3404
|
-
|
|
3405
|
-
|
|
3406
|
-
|
|
3407
|
-
|
|
3408
|
-
|
|
3409
|
-
|
|
3410
|
-
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
|
|
3415
|
-
|
|
3416
|
-
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
|
|
3420
|
-
|
|
3421
|
-
|
|
4738
|
+
if (!inSingle && !inDouble) {
|
|
4739
|
+
if (ch === '{') {
|
|
4740
|
+
depthCurly++;
|
|
4741
|
+
continue;
|
|
4742
|
+
}
|
|
4743
|
+
if (ch === '}') {
|
|
4744
|
+
depthCurly--;
|
|
4745
|
+
continue;
|
|
4746
|
+
}
|
|
4747
|
+
if (ch === '[') {
|
|
4748
|
+
depthSquare++;
|
|
4749
|
+
continue;
|
|
4750
|
+
}
|
|
4751
|
+
if (ch === ']') {
|
|
4752
|
+
depthSquare--;
|
|
4753
|
+
continue;
|
|
4754
|
+
}
|
|
4755
|
+
if (ch === '(') {
|
|
4756
|
+
depthParen++;
|
|
4757
|
+
continue;
|
|
4758
|
+
}
|
|
4759
|
+
if (ch === ')') {
|
|
4760
|
+
depthParen--;
|
|
4761
|
+
continue;
|
|
4762
|
+
}
|
|
4763
|
+
if (ch === ':' && depthCurly === 0 && depthSquare === 0 && depthParen === 0) {
|
|
4764
|
+
return i;
|
|
4765
|
+
}
|
|
4766
|
+
}
|
|
4767
|
+
}
|
|
4768
|
+
return -1;
|
|
4769
|
+
}
|
|
3422
4770
|
|
|
3423
|
-
|
|
3424
|
-
|
|
3425
|
-
|
|
4771
|
+
// Extract key content (supports "key", 'key', key) → returns pure string key
|
|
4772
|
+
function extractKeyContent(rawKey) {
|
|
4773
|
+
var r = rawKey.trim();
|
|
4774
|
+
if (r.startsWith('"') && r.endsWith('"') || r.startsWith("'") && r.endsWith("'")) {
|
|
4775
|
+
var inner = r.slice(1, -1).replace(/\\"/g, '"').replace(/\\'/g, "'");
|
|
4776
|
+
return inner;
|
|
4777
|
+
}
|
|
4778
|
+
return r;
|
|
4779
|
+
}
|
|
4780
|
+
|
|
4781
|
+
/**
|
|
4782
|
+
* Determine whether it is in JSON format
|
|
4783
|
+
* @private
|
|
4784
|
+
*/
|
|
4785
|
+
function _isJSON(input) {
|
|
4786
|
+
if (typeof input === 'string' && input.length > 0) {
|
|
4787
|
+
return _fixAndParseJSON(input).success;
|
|
4788
|
+
} else {
|
|
4789
|
+
if (_typeof(input) === 'object' && Object.prototype.toString.call(input) === '[object Object]' && !input.length) {
|
|
4790
|
+
return true;
|
|
4791
|
+
} else {
|
|
4792
|
+
return false;
|
|
4793
|
+
}
|
|
4794
|
+
}
|
|
4795
|
+
}
|
|
4796
|
+
|
|
4797
|
+
/**
|
|
4798
|
+
* Check if a string is a valid number
|
|
4799
|
+
* @param str - The string to check
|
|
4800
|
+
* @returns boolean indicating if the string is a valid number
|
|
4801
|
+
*/
|
|
4802
|
+
function _isValidNumeric(str) {
|
|
4803
|
+
if (typeof str !== "string") return false; // we only process strings!
|
|
4804
|
+
if (!isNaN(Number(str)) &&
|
|
4805
|
+
// use type coercion to parse the _entirety_ of the string
|
|
4806
|
+
!isNaN(parseFloat(str)) // ensure strings of whitespace fail
|
|
4807
|
+
) {
|
|
4808
|
+
return true;
|
|
4809
|
+
}
|
|
4810
|
+
return false;
|
|
4811
|
+
}
|
|
4812
|
+
|
|
4813
|
+
/**
|
|
4814
|
+
* Check if input is empty
|
|
4815
|
+
* @param input - The input to check (string or array of strings)
|
|
4816
|
+
* @returns boolean indicating if the input is empty
|
|
4817
|
+
*/
|
|
4818
|
+
function _isEmpty(input) {
|
|
4819
|
+
if (Array.isArray(input)) {
|
|
4820
|
+
return input.some(function (str) {
|
|
4821
|
+
return !str.replace(/\s/g, '').length === true;
|
|
3426
4822
|
});
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
|
|
3434
|
-
|
|
3435
|
-
|
|
3436
|
-
|
|
3437
|
-
|
|
4823
|
+
}
|
|
4824
|
+
return !input.replace(/\s/g, '').length === true;
|
|
4825
|
+
}
|
|
4826
|
+
|
|
4827
|
+
/**
|
|
4828
|
+
* Check if input is a valid number
|
|
4829
|
+
* @param input - The input to check
|
|
4830
|
+
* @returns boolean indicating if the input is a valid number
|
|
4831
|
+
*/
|
|
4832
|
+
function _isNumber(input) {
|
|
4833
|
+
var reg = /^[\d|\.|,]+$/;
|
|
4834
|
+
return reg.test(input);
|
|
4835
|
+
}
|
|
4836
|
+
|
|
4837
|
+
/**
|
|
4838
|
+
* Check if input is a valid integer
|
|
4839
|
+
* @param input - The input to check
|
|
4840
|
+
* @returns boolean indicating if the input is a valid integer
|
|
4841
|
+
*/
|
|
4842
|
+
function _isInt(input) {
|
|
4843
|
+
if (input === "") {
|
|
4844
|
+
return false;
|
|
4845
|
+
}
|
|
4846
|
+
var reg = /\D+/;
|
|
4847
|
+
return !reg.test(input);
|
|
4848
|
+
}
|
|
4849
|
+
|
|
4850
|
+
/**
|
|
4851
|
+
* Check if input is a valid email address
|
|
4852
|
+
* @param input - The input to check
|
|
4853
|
+
* @returns boolean indicating if the input is a valid email
|
|
4854
|
+
*/
|
|
4855
|
+
function _isEmail(input) {
|
|
4856
|
+
var reg = /^\s*([A-Za-z0-9_-]+(\.\w+)*@(\w+\.)+\w{2,3})\s*$/;
|
|
4857
|
+
return reg.test(input);
|
|
4858
|
+
}
|
|
4859
|
+
|
|
4860
|
+
/**
|
|
4861
|
+
* Check if input is a valid telephone number
|
|
4862
|
+
* @param input - The input to check
|
|
4863
|
+
* @returns boolean indicating if the input is a valid telephone number
|
|
4864
|
+
*/
|
|
4865
|
+
function _isTel(input) {
|
|
4866
|
+
var reg = /^[0-9- ]{7,20}$/;
|
|
4867
|
+
return reg.test(input);
|
|
4868
|
+
}
|
|
4869
|
+
|
|
4870
|
+
/**
|
|
4871
|
+
* Check if input is a valid mobile number
|
|
4872
|
+
* @param input - The input to check
|
|
4873
|
+
* @returns boolean indicating if the input is a valid mobile number
|
|
4874
|
+
*/
|
|
4875
|
+
function _isMobile(input) {
|
|
4876
|
+
var reg = /^1[0-9]{10}$/;
|
|
4877
|
+
return reg.test(input);
|
|
4878
|
+
}
|
|
3438
4879
|
|
|
3439
4880
|
/******/
|
|
3440
4881
|
return __webpack_exports__;
|
|
@@ -3574,8 +5015,13 @@ var useThrottle_default = /*#__PURE__*/__webpack_require__.n(useThrottle);
|
|
|
3574
5015
|
// EXTERNAL MODULE: ../Utils/dist/cjs/useClickOutside.js
|
|
3575
5016
|
var useClickOutside = __webpack_require__(761);
|
|
3576
5017
|
var useClickOutside_default = /*#__PURE__*/__webpack_require__.n(useClickOutside);
|
|
5018
|
+
// EXTERNAL MODULE: ../Utils/dist/cjs/useStreamController.js
|
|
5019
|
+
var useStreamController = __webpack_require__(829);
|
|
5020
|
+
var useStreamController_default = /*#__PURE__*/__webpack_require__.n(useStreamController);
|
|
3577
5021
|
// EXTERNAL MODULE: ../Utils/dist/cjs/sanitize.js
|
|
3578
5022
|
var sanitize = __webpack_require__(959);
|
|
5023
|
+
// EXTERNAL MODULE: ../Utils/dist/cjs/validate.js
|
|
5024
|
+
var validate = __webpack_require__(455);
|
|
3579
5025
|
;// CONCATENATED MODULE: ./src/PureLoader.tsx
|
|
3580
5026
|
|
|
3581
5027
|
var PureLoader = function PureLoader(props) {
|
|
@@ -3598,14 +5044,6 @@ var PureLoader = function PureLoader(props) {
|
|
|
3598
5044
|
;// CONCATENATED MODULE: ./src/utils/func.ts
|
|
3599
5045
|
// app.ts
|
|
3600
5046
|
|
|
3601
|
-
function isValidJSON(str) {
|
|
3602
|
-
try {
|
|
3603
|
-
JSON.parse(str);
|
|
3604
|
-
return true;
|
|
3605
|
-
} catch (error) {
|
|
3606
|
-
return false;
|
|
3607
|
-
}
|
|
3608
|
-
}
|
|
3609
5047
|
function formatLatestDisplayContent(str) {
|
|
3610
5048
|
// Regular expression to match <details> tags and their content
|
|
3611
5049
|
var output = str.replace(/<details class="think"[^>]*>([\s\S]*?)<\/details>/g, function (match, content) {
|
|
@@ -3746,6 +5184,13 @@ function extractHtmlTags(html) {
|
|
|
3746
5184
|
};
|
|
3747
5185
|
}
|
|
3748
5186
|
;
|
|
5187
|
+
function toBoolean(val) {
|
|
5188
|
+
if (typeof val === "boolean") return val;
|
|
5189
|
+
if (typeof val === "string") {
|
|
5190
|
+
return val.toLowerCase() === "true";
|
|
5191
|
+
}
|
|
5192
|
+
return Boolean(val);
|
|
5193
|
+
}
|
|
3749
5194
|
;// CONCATENATED MODULE: ./src/TypingEffect.tsx
|
|
3750
5195
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
3751
5196
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
@@ -3823,407 +5268,17 @@ var TypingEffect = function TypingEffect(_ref) {
|
|
|
3823
5268
|
});
|
|
3824
5269
|
};
|
|
3825
5270
|
/* harmony default export */ const src_TypingEffect = (TypingEffect);
|
|
3826
|
-
;// CONCATENATED MODULE: ./src/useStreamController.tsx
|
|
3827
|
-
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
3828
|
-
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
3829
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
3830
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
3831
|
-
/**
|
|
3832
|
-
* Stream Controller
|
|
3833
|
-
*
|
|
3834
|
-
* @usage:
|
|
3835
|
-
|
|
3836
|
-
// Use in component
|
|
3837
|
-
const streamController = useStreamController({
|
|
3838
|
-
onChunk: async (chunk: string, index: number) => {
|
|
3839
|
-
// start (Execute it only once)
|
|
3840
|
-
if (index === 0) {
|
|
3841
|
-
|
|
3842
|
-
}
|
|
3843
|
-
|
|
3844
|
-
// Streaming data is JSON split by rows
|
|
3845
|
-
const lines = chunk.split("\n").filter(line => line.trim() !== "");
|
|
3846
|
-
|
|
3847
|
-
// Process each data chunk
|
|
3848
|
-
console.log('Received chunk:', chunk);
|
|
3849
|
-
},
|
|
3850
|
-
onComplete: async (lastContent: string) => {
|
|
3851
|
-
// Process when stream is completed
|
|
3852
|
-
console.log('Stream completed');
|
|
3853
|
-
|
|
3854
|
-
// Display AI reply
|
|
3855
|
-
console.log('AI reply:', lastContent);
|
|
3856
|
-
|
|
3857
|
-
},
|
|
3858
|
-
onError: (error) => {
|
|
3859
|
-
// Error handling
|
|
3860
|
-
console.error('Stream error:', error);
|
|
3861
|
-
},
|
|
3862
|
-
onAbort: () => {
|
|
3863
|
-
// Abort processing
|
|
3864
|
-
console.log('Stream aborted');
|
|
3865
|
-
}
|
|
3866
|
-
});
|
|
3867
|
-
|
|
3868
|
-
// Start stream
|
|
3869
|
-
const response = await fetch(url);
|
|
3870
|
-
await streamController.start(response);
|
|
3871
|
-
|
|
3872
|
-
// Pause stream
|
|
3873
|
-
streamController.pause();
|
|
3874
|
-
|
|
3875
|
-
// Resume stream
|
|
3876
|
-
streamController.resume();
|
|
3877
|
-
|
|
3878
|
-
// Abort stream
|
|
3879
|
-
streamController.abort();
|
|
3880
|
-
|
|
3881
|
-
// Check status
|
|
3882
|
-
const isActive = streamController.isActive();
|
|
3883
|
-
const isPaused = streamController.isPaused();
|
|
3884
|
-
|
|
3885
|
-
*/
|
|
3886
|
-
|
|
3887
|
-
|
|
3888
|
-
var useStreamController = function useStreamController() {
|
|
3889
|
-
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
3890
|
-
var streamController = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)(null);
|
|
3891
|
-
var reader = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)(null);
|
|
3892
|
-
var activeStream = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)(null);
|
|
3893
|
-
var responseReader = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)(null);
|
|
3894
|
-
var paused = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)(false);
|
|
3895
|
-
var active = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)(false);
|
|
3896
|
-
var abortController = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)(new AbortController());
|
|
3897
|
-
var textDecoder = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)(new TextDecoder("utf-8")); // Get the decoding of UTF8
|
|
3898
|
-
|
|
3899
|
-
// To avoid the "Uncaught (in promise) TypeError: Failed to execute 'cancel' on 'ReadableStream': Cannot cancel a locked stream" error,
|
|
3900
|
-
// (1) you need to safely release the reader.
|
|
3901
|
-
// (2) cleanup() also requires asynchronous state
|
|
3902
|
-
var releaseReader = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useCallback)( /*#__PURE__*/function () {
|
|
3903
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(readerRef) {
|
|
3904
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
3905
|
-
while (1) switch (_context.prev = _context.next) {
|
|
3906
|
-
case 0:
|
|
3907
|
-
if (!readerRef.current) {
|
|
3908
|
-
_context.next = 11;
|
|
3909
|
-
break;
|
|
3910
|
-
}
|
|
3911
|
-
_context.prev = 1;
|
|
3912
|
-
_context.next = 4;
|
|
3913
|
-
return readerRef.current.cancel();
|
|
3914
|
-
case 4:
|
|
3915
|
-
_context.next = 9;
|
|
3916
|
-
break;
|
|
3917
|
-
case 6:
|
|
3918
|
-
_context.prev = 6;
|
|
3919
|
-
_context.t0 = _context["catch"](1);
|
|
3920
|
-
console.warn('Error cancelling reader:', _context.t0);
|
|
3921
|
-
case 9:
|
|
3922
|
-
try {
|
|
3923
|
-
readerRef.current.releaseLock();
|
|
3924
|
-
} catch (e) {
|
|
3925
|
-
console.warn('Error releasing reader lock:', e);
|
|
3926
|
-
}
|
|
3927
|
-
readerRef.current = null;
|
|
3928
|
-
case 11:
|
|
3929
|
-
case "end":
|
|
3930
|
-
return _context.stop();
|
|
3931
|
-
}
|
|
3932
|
-
}, _callee, null, [[1, 6]]);
|
|
3933
|
-
}));
|
|
3934
|
-
return function (_x) {
|
|
3935
|
-
return _ref.apply(this, arguments);
|
|
3936
|
-
};
|
|
3937
|
-
}(), []);
|
|
3938
|
-
var cleanup = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useCallback)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
3939
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
3940
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
3941
|
-
case 0:
|
|
3942
|
-
_context2.next = 2;
|
|
3943
|
-
return releaseReader(reader);
|
|
3944
|
-
case 2:
|
|
3945
|
-
_context2.next = 4;
|
|
3946
|
-
return releaseReader(responseReader);
|
|
3947
|
-
case 4:
|
|
3948
|
-
if (!activeStream.current) {
|
|
3949
|
-
_context2.next = 14;
|
|
3950
|
-
break;
|
|
3951
|
-
}
|
|
3952
|
-
_context2.prev = 5;
|
|
3953
|
-
_context2.next = 8;
|
|
3954
|
-
return activeStream.current.cancel();
|
|
3955
|
-
case 8:
|
|
3956
|
-
_context2.next = 13;
|
|
3957
|
-
break;
|
|
3958
|
-
case 10:
|
|
3959
|
-
_context2.prev = 10;
|
|
3960
|
-
_context2.t0 = _context2["catch"](5);
|
|
3961
|
-
console.warn('Error cancelling stream:', _context2.t0);
|
|
3962
|
-
case 13:
|
|
3963
|
-
activeStream.current = null;
|
|
3964
|
-
case 14:
|
|
3965
|
-
streamController.current = null;
|
|
3966
|
-
active.current = false;
|
|
3967
|
-
paused.current = false;
|
|
3968
|
-
case 17:
|
|
3969
|
-
case "end":
|
|
3970
|
-
return _context2.stop();
|
|
3971
|
-
}
|
|
3972
|
-
}, _callee2, null, [[5, 10]]);
|
|
3973
|
-
})), [releaseReader]);
|
|
3974
|
-
|
|
3975
|
-
// Process chunks of data
|
|
3976
|
-
var processChunk = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useCallback)( /*#__PURE__*/function () {
|
|
3977
|
-
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(chunk, index) {
|
|
3978
|
-
var _options$onChunk, _options$onError;
|
|
3979
|
-
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
3980
|
-
while (1) switch (_context3.prev = _context3.next) {
|
|
3981
|
-
case 0:
|
|
3982
|
-
try {
|
|
3983
|
-
(_options$onChunk = options.onChunk) === null || _options$onChunk === void 0 ? void 0 : _options$onChunk.call(options, chunk, index);
|
|
3984
|
-
} catch (error) {
|
|
3985
|
-
(_options$onError = options.onError) === null || _options$onError === void 0 ? void 0 : _options$onError.call(options, error);
|
|
3986
|
-
}
|
|
3987
|
-
case 1:
|
|
3988
|
-
case "end":
|
|
3989
|
-
return _context3.stop();
|
|
3990
|
-
}
|
|
3991
|
-
}, _callee3);
|
|
3992
|
-
}));
|
|
3993
|
-
return function (_x2, _x3) {
|
|
3994
|
-
return _ref3.apply(this, arguments);
|
|
3995
|
-
};
|
|
3996
|
-
}(), [options]);
|
|
3997
|
-
|
|
3998
|
-
// Start processing the stream
|
|
3999
|
-
var startProcessing = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useCallback)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
|
|
4000
|
-
var counter, lastContent, _yield$reader$current, done, value, _options$onComplete, chunkStr, _options$onAbort, _options$onError2;
|
|
4001
|
-
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
4002
|
-
while (1) switch (_context4.prev = _context4.next) {
|
|
4003
|
-
case 0:
|
|
4004
|
-
if (!(!reader.current || !active.current)) {
|
|
4005
|
-
_context4.next = 2;
|
|
4006
|
-
break;
|
|
4007
|
-
}
|
|
4008
|
-
return _context4.abrupt("return");
|
|
4009
|
-
case 2:
|
|
4010
|
-
//
|
|
4011
|
-
counter = 0; // Store the final content and bind it to loading
|
|
4012
|
-
lastContent = '';
|
|
4013
|
-
case 4:
|
|
4014
|
-
if (!active.current) {
|
|
4015
|
-
_context4.next = 35;
|
|
4016
|
-
break;
|
|
4017
|
-
}
|
|
4018
|
-
_context4.prev = 5;
|
|
4019
|
-
if (!paused.current) {
|
|
4020
|
-
_context4.next = 10;
|
|
4021
|
-
break;
|
|
4022
|
-
}
|
|
4023
|
-
_context4.next = 9;
|
|
4024
|
-
return new Promise(function (resolve) {
|
|
4025
|
-
return setTimeout(resolve, 100);
|
|
4026
|
-
});
|
|
4027
|
-
case 9:
|
|
4028
|
-
return _context4.abrupt("continue", 4);
|
|
4029
|
-
case 10:
|
|
4030
|
-
_context4.next = 12;
|
|
4031
|
-
return reader.current.read();
|
|
4032
|
-
case 12:
|
|
4033
|
-
_yield$reader$current = _context4.sent;
|
|
4034
|
-
done = _yield$reader$current.done;
|
|
4035
|
-
value = _yield$reader$current.value;
|
|
4036
|
-
if (!done) {
|
|
4037
|
-
_context4.next = 20;
|
|
4038
|
-
break;
|
|
4039
|
-
}
|
|
4040
|
-
(_options$onComplete = options.onComplete) === null || _options$onComplete === void 0 ? void 0 : _options$onComplete.call(options, lastContent);
|
|
4041
|
-
_context4.next = 19;
|
|
4042
|
-
return cleanup();
|
|
4043
|
-
case 19:
|
|
4044
|
-
return _context4.abrupt("break", 35);
|
|
4045
|
-
case 20:
|
|
4046
|
-
// Decode the content
|
|
4047
|
-
chunkStr = textDecoder.current.decode(value, {
|
|
4048
|
-
stream: true
|
|
4049
|
-
});
|
|
4050
|
-
lastContent += chunkStr;
|
|
4051
|
-
_context4.next = 24;
|
|
4052
|
-
return processChunk(chunkStr, counter);
|
|
4053
|
-
case 24:
|
|
4054
|
-
counter++;
|
|
4055
|
-
_context4.next = 33;
|
|
4056
|
-
break;
|
|
4057
|
-
case 27:
|
|
4058
|
-
_context4.prev = 27;
|
|
4059
|
-
_context4.t0 = _context4["catch"](5);
|
|
4060
|
-
if (_context4.t0.name === 'AbortError') {
|
|
4061
|
-
(_options$onAbort = options.onAbort) === null || _options$onAbort === void 0 ? void 0 : _options$onAbort.call(options);
|
|
4062
|
-
} else {
|
|
4063
|
-
(_options$onError2 = options.onError) === null || _options$onError2 === void 0 ? void 0 : _options$onError2.call(options, _context4.t0);
|
|
4064
|
-
}
|
|
4065
|
-
_context4.next = 32;
|
|
4066
|
-
return cleanup();
|
|
4067
|
-
case 32:
|
|
4068
|
-
return _context4.abrupt("break", 35);
|
|
4069
|
-
case 33:
|
|
4070
|
-
_context4.next = 4;
|
|
4071
|
-
break;
|
|
4072
|
-
case 35:
|
|
4073
|
-
case "end":
|
|
4074
|
-
return _context4.stop();
|
|
4075
|
-
}
|
|
4076
|
-
}, _callee4, null, [[5, 27]]);
|
|
4077
|
-
})), [options, cleanup, processChunk]);
|
|
4078
|
-
|
|
4079
|
-
// Start streaming
|
|
4080
|
-
var start = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useCallback)( /*#__PURE__*/function () {
|
|
4081
|
-
var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(response) {
|
|
4082
|
-
var stream, _options$onError3;
|
|
4083
|
-
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
4084
|
-
while (1) switch (_context6.prev = _context6.next) {
|
|
4085
|
-
case 0:
|
|
4086
|
-
_context6.next = 2;
|
|
4087
|
-
return cleanup();
|
|
4088
|
-
case 2:
|
|
4089
|
-
// Get Reader
|
|
4090
|
-
reader.current = response.body.getReader();
|
|
4091
|
-
_context6.prev = 3;
|
|
4092
|
-
stream = new ReadableStream({
|
|
4093
|
-
start: function start(controller) {
|
|
4094
|
-
streamController.current = controller;
|
|
4095
|
-
},
|
|
4096
|
-
pull: function pull(controller) {
|
|
4097
|
-
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
|
|
4098
|
-
var _yield$read, done, value, chunkStr;
|
|
4099
|
-
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
4100
|
-
while (1) switch (_context5.prev = _context5.next) {
|
|
4101
|
-
case 0:
|
|
4102
|
-
_context5.prev = 0;
|
|
4103
|
-
_context5.next = 3;
|
|
4104
|
-
return reader.current.read();
|
|
4105
|
-
case 3:
|
|
4106
|
-
_yield$read = _context5.sent;
|
|
4107
|
-
done = _yield$read.done;
|
|
4108
|
-
value = _yield$read.value;
|
|
4109
|
-
if (!done) {
|
|
4110
|
-
_context5.next = 9;
|
|
4111
|
-
break;
|
|
4112
|
-
}
|
|
4113
|
-
controller.close();
|
|
4114
|
-
return _context5.abrupt("return");
|
|
4115
|
-
case 9:
|
|
4116
|
-
// Decode the content
|
|
4117
|
-
chunkStr = textDecoder.current.decode(value, {
|
|
4118
|
-
stream: true
|
|
4119
|
-
});
|
|
4120
|
-
controller.enqueue(chunkStr);
|
|
4121
|
-
_context5.next = 16;
|
|
4122
|
-
break;
|
|
4123
|
-
case 13:
|
|
4124
|
-
_context5.prev = 13;
|
|
4125
|
-
_context5.t0 = _context5["catch"](0);
|
|
4126
|
-
controller.error(_context5.t0);
|
|
4127
|
-
case 16:
|
|
4128
|
-
case "end":
|
|
4129
|
-
return _context5.stop();
|
|
4130
|
-
}
|
|
4131
|
-
}, _callee5, null, [[0, 13]]);
|
|
4132
|
-
}))();
|
|
4133
|
-
},
|
|
4134
|
-
cancel: function cancel() {
|
|
4135
|
-
var _response$body;
|
|
4136
|
-
(_response$body = response.body) === null || _response$body === void 0 ? void 0 : _response$body.cancel();
|
|
4137
|
-
}
|
|
4138
|
-
});
|
|
4139
|
-
activeStream.current = stream;
|
|
4140
|
-
active.current = true;
|
|
4141
|
-
paused.current = false;
|
|
4142
|
-
|
|
4143
|
-
// Start processing immediately
|
|
4144
|
-
_context6.next = 10;
|
|
4145
|
-
return startProcessing();
|
|
4146
|
-
case 10:
|
|
4147
|
-
_context6.next = 16;
|
|
4148
|
-
break;
|
|
4149
|
-
case 12:
|
|
4150
|
-
_context6.prev = 12;
|
|
4151
|
-
_context6.t0 = _context6["catch"](3);
|
|
4152
|
-
(_options$onError3 = options.onError) === null || _options$onError3 === void 0 ? void 0 : _options$onError3.call(options, _context6.t0);
|
|
4153
|
-
cleanup();
|
|
4154
|
-
case 16:
|
|
4155
|
-
case "end":
|
|
4156
|
-
return _context6.stop();
|
|
4157
|
-
}
|
|
4158
|
-
}, _callee6, null, [[3, 12]]);
|
|
4159
|
-
}));
|
|
4160
|
-
return function (_x4) {
|
|
4161
|
-
return _ref5.apply(this, arguments);
|
|
4162
|
-
};
|
|
4163
|
-
}(), [options, cleanup, startProcessing]);
|
|
4164
|
-
|
|
4165
|
-
// Pause streaming
|
|
4166
|
-
var pause = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useCallback)(function () {
|
|
4167
|
-
paused.current = true;
|
|
4168
|
-
}, []);
|
|
4169
|
-
|
|
4170
|
-
// Resume streaming
|
|
4171
|
-
var resume = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useCallback)(function () {
|
|
4172
|
-
paused.current = false;
|
|
4173
|
-
}, []);
|
|
4174
|
-
|
|
4175
|
-
// Abort streaming
|
|
4176
|
-
var abort = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useCallback)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
|
|
4177
|
-
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
4178
|
-
while (1) switch (_context7.prev = _context7.next) {
|
|
4179
|
-
case 0:
|
|
4180
|
-
abortController.current.abort();
|
|
4181
|
-
_context7.next = 3;
|
|
4182
|
-
return cleanup();
|
|
4183
|
-
case 3:
|
|
4184
|
-
case "end":
|
|
4185
|
-
return _context7.stop();
|
|
4186
|
-
}
|
|
4187
|
-
}, _callee7);
|
|
4188
|
-
})), [cleanup]);
|
|
4189
|
-
|
|
4190
|
-
// Check if stream is active
|
|
4191
|
-
var isActive = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useCallback)(function () {
|
|
4192
|
-
return active.current;
|
|
4193
|
-
}, []);
|
|
4194
|
-
|
|
4195
|
-
// Check if stream is paused
|
|
4196
|
-
var isPaused = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useCallback)(function () {
|
|
4197
|
-
return paused.current;
|
|
4198
|
-
}, []);
|
|
4199
|
-
|
|
4200
|
-
// Cleanup on unmount
|
|
4201
|
-
(0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useEffect)(function () {
|
|
4202
|
-
return function () {
|
|
4203
|
-
cleanup()["catch"](console.error);
|
|
4204
|
-
};
|
|
4205
|
-
}, [cleanup]);
|
|
4206
|
-
return {
|
|
4207
|
-
start: start,
|
|
4208
|
-
pause: pause,
|
|
4209
|
-
resume: resume,
|
|
4210
|
-
abort: abort,
|
|
4211
|
-
isActive: isActive,
|
|
4212
|
-
isPaused: isPaused
|
|
4213
|
-
};
|
|
4214
|
-
};
|
|
4215
|
-
/* harmony default export */ const src_useStreamController = (useStreamController);
|
|
4216
5271
|
;// CONCATENATED MODULE: ./src/index.tsx
|
|
4217
|
-
function
|
|
5272
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
4218
5273
|
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = src_unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
4219
5274
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
4220
5275
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4221
5276
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
4222
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return
|
|
4223
|
-
function _toPrimitive(input, hint) { if (
|
|
4224
|
-
function src_regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ src_regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == src_typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
4225
|
-
function
|
|
4226
|
-
function
|
|
5277
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
5278
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
5279
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
5280
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
5281
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
4227
5282
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || src_unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
4228
5283
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4229
5284
|
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
@@ -4243,9 +5298,10 @@ function src_arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
|
4243
5298
|
|
|
4244
5299
|
|
|
4245
5300
|
|
|
4246
|
-
// loader
|
|
4247
5301
|
|
|
4248
5302
|
|
|
5303
|
+
// loader
|
|
5304
|
+
|
|
4249
5305
|
|
|
4250
5306
|
|
|
4251
5307
|
var Chatbox = function Chatbox(props) {
|
|
@@ -4264,6 +5320,16 @@ var Chatbox = function Chatbox(props) {
|
|
|
4264
5320
|
requestBody: "{\n \"model\": \"{model}\",\n \"messages\": [{\n \"role\": \"user\",\n \"content\": \"{message}\"\n }],\n \"stream\": true\n}",
|
|
4265
5321
|
responseExtractor: "data.choices.0.delta.content"
|
|
4266
5322
|
});
|
|
5323
|
+
var tokenFormat = function tokenFormat(inputTokenValue) {
|
|
5324
|
+
if (typeof inputTokenValue === 'undefined') return '';
|
|
5325
|
+
|
|
5326
|
+
// Resolve token value (string or function)
|
|
5327
|
+
if (typeof inputTokenValue === 'function') {
|
|
5328
|
+
return inputTokenValue();
|
|
5329
|
+
} else {
|
|
5330
|
+
return inputTokenValue || '';
|
|
5331
|
+
}
|
|
5332
|
+
};
|
|
4267
5333
|
|
|
4268
5334
|
//
|
|
4269
5335
|
var rootRef = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)(null);
|
|
@@ -4420,6 +5486,7 @@ var Chatbox = function Chatbox(props) {
|
|
|
4420
5486
|
model = currentProps.model,
|
|
4421
5487
|
baseUrl = currentProps.baseUrl,
|
|
4422
5488
|
apiKey = currentProps.apiKey,
|
|
5489
|
+
token = currentProps.token,
|
|
4423
5490
|
verbose = currentProps.verbose,
|
|
4424
5491
|
reasoningSwitchLabel = currentProps.reasoningSwitchLabel,
|
|
4425
5492
|
stopLabel = currentProps.stopLabel,
|
|
@@ -4465,18 +5532,20 @@ var Chatbox = function Chatbox(props) {
|
|
|
4465
5532
|
var requestApiUrl = apiUrl.replace(/\{baseUrl\}/g, baseUrl);
|
|
4466
5533
|
|
|
4467
5534
|
// header config
|
|
4468
|
-
var _headerConfig = headerConfig.replace(/\{apiKey\}/g, apiKey).replace(/\'/g, '"'); // !!! REQUIRED !!!
|
|
4469
|
-
var headerConfigRes = typeof _headerConfig !== 'undefined' ?
|
|
5535
|
+
var _headerConfig = headerConfig.replace(/\{apiKey\}/g, apiKey).replace(/\{token\}/g, tokenFormat(token)).replace(/\'/g, '"'); // !!! REQUIRED !!!
|
|
5536
|
+
var headerConfigRes = typeof _headerConfig !== 'undefined' ? (0,validate.isJSON)(_headerConfig) ? JSON.parse(_headerConfig) : undefined : {
|
|
4470
5537
|
'Content-Type': 'application/json'
|
|
4471
5538
|
};
|
|
4472
5539
|
|
|
4473
5540
|
// Determine whether it is in JSON format
|
|
4474
|
-
if (!
|
|
5541
|
+
if (!(0,validate.isJSON)(_requestBodyTmpl)) {
|
|
4475
5542
|
console.log('--> [ERROR] Wrong JSON format');
|
|
4476
5543
|
_requestBodyTmpl = '{}';
|
|
4477
5544
|
return {};
|
|
4478
5545
|
} else {
|
|
4479
|
-
|
|
5546
|
+
if (JSON.parse(_requestBodyTmpl).hasOwnProperty('stream')) {
|
|
5547
|
+
_isStream = toBoolean(JSON.parse(_requestBodyTmpl).stream) === true;
|
|
5548
|
+
}
|
|
4480
5549
|
}
|
|
4481
5550
|
|
|
4482
5551
|
// Whether or not to show reasoning
|
|
@@ -4496,6 +5565,7 @@ var Chatbox = function Chatbox(props) {
|
|
|
4496
5565
|
model: model,
|
|
4497
5566
|
baseUrl: baseUrl,
|
|
4498
5567
|
apiKey: apiKey,
|
|
5568
|
+
token: token,
|
|
4499
5569
|
verbose: verbose,
|
|
4500
5570
|
reasoningSwitchLabel: reasoningSwitchLabel,
|
|
4501
5571
|
stopLabel: stopLabel,
|
|
@@ -4544,9 +5614,9 @@ var Chatbox = function Chatbox(props) {
|
|
|
4544
5614
|
// Clipboard
|
|
4545
5615
|
//================================================================
|
|
4546
5616
|
var chatboxCopyToClipboard = /*#__PURE__*/function () {
|
|
4547
|
-
var _ref =
|
|
5617
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(text) {
|
|
4548
5618
|
var _content, _args$onCopyCallback, _args, textArea, _args$onCopyCallback2, _args2, _args$onCopyCallback3, _args3;
|
|
4549
|
-
return
|
|
5619
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
4550
5620
|
while (1) switch (_context.prev = _context.next) {
|
|
4551
5621
|
case 0:
|
|
4552
5622
|
_content = text;
|
|
@@ -4659,9 +5729,9 @@ var Chatbox = function Chatbox(props) {
|
|
|
4659
5729
|
|
|
4660
5730
|
// The onClick action specifically used to perform the default options
|
|
4661
5731
|
var executeDefaultOptionAction = /*#__PURE__*/function () {
|
|
4662
|
-
var _ref2 =
|
|
5732
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(actionStr, buttonId) {
|
|
4663
5733
|
var actionFn;
|
|
4664
|
-
return
|
|
5734
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
4665
5735
|
while (1) switch (_context2.prev = _context2.next) {
|
|
4666
5736
|
case 0:
|
|
4667
5737
|
_context2.prev = 0;
|
|
@@ -4686,9 +5756,9 @@ var Chatbox = function Chatbox(props) {
|
|
|
4686
5756
|
};
|
|
4687
5757
|
}();
|
|
4688
5758
|
var executeButtonAction = /*#__PURE__*/function () {
|
|
4689
|
-
var _ref3 =
|
|
5759
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(actionStr, buttonId, buttonElement) {
|
|
4690
5760
|
var actionFn, result, options, newState;
|
|
4691
|
-
return
|
|
5761
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
4692
5762
|
while (1) switch (_context3.prev = _context3.next) {
|
|
4693
5763
|
case 0:
|
|
4694
5764
|
_context3.prev = 0;
|
|
@@ -4868,9 +5938,9 @@ var Chatbox = function Chatbox(props) {
|
|
|
4868
5938
|
|
|
4869
5939
|
// parse chunk data
|
|
4870
5940
|
var parseChunkData = /*#__PURE__*/function () {
|
|
4871
|
-
var _ref4 =
|
|
5941
|
+
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(chunk, index, complete) {
|
|
4872
5942
|
var lastContent, _args$responseExtract, extractPath, lines, _iterator, _step, line, _content, result, _iterator2, _step2, path, content, parsedContent, latestRes;
|
|
4873
|
-
return
|
|
5943
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
4874
5944
|
while (1) switch (_context4.prev = _context4.next) {
|
|
4875
5945
|
case 0:
|
|
4876
5946
|
// Store the final content and bind it to loading
|
|
@@ -4904,7 +5974,7 @@ var Chatbox = function Chatbox(props) {
|
|
|
4904
5974
|
// ------
|
|
4905
5975
|
// Create a JSON string
|
|
4906
5976
|
_content = "".concat(line.replace(/^data:\s*/, '')); // Determine whether it is in JSON format
|
|
4907
|
-
if (
|
|
5977
|
+
if ((0,validate.isJSON)(_content)) {
|
|
4908
5978
|
_context4.next = 16;
|
|
4909
5979
|
break;
|
|
4910
5980
|
}
|
|
@@ -5061,12 +6131,12 @@ var Chatbox = function Chatbox(props) {
|
|
|
5061
6131
|
|
|
5062
6132
|
// Store the final content and bind it to loading
|
|
5063
6133
|
var tempLastContent = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)('');
|
|
5064
|
-
var streamController =
|
|
6134
|
+
var streamController = useStreamController_default()({
|
|
5065
6135
|
onChunk: function () {
|
|
5066
|
-
var _onChunk =
|
|
6136
|
+
var _onChunk = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(chunk, index) {
|
|
5067
6137
|
var _args$onChunk, _args9;
|
|
5068
6138
|
var res;
|
|
5069
|
-
return
|
|
6139
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
5070
6140
|
while (1) switch (_context5.prev = _context5.next) {
|
|
5071
6141
|
case 0:
|
|
5072
6142
|
// start (Execute it only once)
|
|
@@ -5094,10 +6164,10 @@ var Chatbox = function Chatbox(props) {
|
|
|
5094
6164
|
return onChunk;
|
|
5095
6165
|
}(),
|
|
5096
6166
|
onComplete: function () {
|
|
5097
|
-
var _onComplete =
|
|
6167
|
+
var _onComplete = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(lastContent) {
|
|
5098
6168
|
var _args$onComplete, _args11;
|
|
5099
6169
|
var res;
|
|
5100
|
-
return
|
|
6170
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
5101
6171
|
while (1) switch (_context6.prev = _context6.next) {
|
|
5102
6172
|
case 0:
|
|
5103
6173
|
console.log('--> Stream complete');
|
|
@@ -5173,9 +6243,9 @@ var Chatbox = function Chatbox(props) {
|
|
|
5173
6243
|
}
|
|
5174
6244
|
};
|
|
5175
6245
|
var sendMessage = /*#__PURE__*/function () {
|
|
5176
|
-
var _ref5 =
|
|
6246
|
+
var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
|
|
5177
6247
|
var messageInput, message, inputMsg, _res, _args$onChunk2, _args13, _args$onComplete2, _args14, reply, replyRes;
|
|
5178
|
-
return
|
|
6248
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
5179
6249
|
while (1) switch (_context7.prev = _context7.next) {
|
|
5180
6250
|
case 0:
|
|
5181
6251
|
if (!(rootRef.current === null || msgContainerRef.current === null || msInput.current === null)) {
|
|
@@ -5301,16 +6371,16 @@ var Chatbox = function Chatbox(props) {
|
|
|
5301
6371
|
setShow(false);
|
|
5302
6372
|
};
|
|
5303
6373
|
var mainRequest = /*#__PURE__*/function () {
|
|
5304
|
-
var _ref6 =
|
|
6374
|
+
var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(msg) {
|
|
5305
6375
|
var currentStreamMode, requestBodyRes, customResponse, content, isStream, contentRes, response, _errInfo, _args$responseExtract2, extractPath, _response, _errInfo2, jsonResponse, result, _iterator3, _step3, path, _content2, _err;
|
|
5306
|
-
return
|
|
6376
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
5307
6377
|
while (1) switch (_context8.prev = _context8.next) {
|
|
5308
6378
|
case 0:
|
|
5309
6379
|
currentStreamMode = args().isStream; // Update stream mode
|
|
5310
6380
|
setEnableStreamMode(currentStreamMode);
|
|
5311
6381
|
_context8.prev = 2;
|
|
5312
6382
|
// Parse and interpolate request body template
|
|
5313
|
-
requestBodyRes = JSON.parse((args().requestBodyTmpl || '{}').replace(/\{model\}/g, args().model).replace(/\{message\}/g, msg).replace(/\{
|
|
6383
|
+
requestBodyRes = JSON.parse((args().requestBodyTmpl || '{}').replace(/\{model\}/g, args().model).replace(/\{message\}/g, msg).replace(/\{chatId\}/g, chatId).replace(/\{token\}/g, tokenFormat(args().token))); //
|
|
5314
6384
|
// If a formatter function exists, it is used to process the request body
|
|
5315
6385
|
if (!(typeof args().requestBodyFormatter === 'function')) {
|
|
5316
6386
|
_context8.next = 8;
|