@cloudbase/js-sdk 3.0.4 → 3.0.5
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/CHANGELOG.md +107 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.esm.js +1 -1
- package/miniprogram_dist/ai.js +1 -1
- package/miniprogram_dist/analytics.js +1 -1
- package/miniprogram_dist/app.js +1 -1
- package/miniprogram_dist/auth.js +1 -1
- package/miniprogram_dist/cloudrun.js +1 -1
- package/miniprogram_dist/container.js +1 -1
- package/miniprogram_dist/functions.js +1 -1
- package/miniprogram_dist/index.js +1 -1
- package/miniprogram_dist/model.js +1 -1
- package/miniprogram_dist/oauth.js +1 -1
- package/miniprogram_dist/storage.js +1 -1
- package/package.json +17 -16
package/miniprogram_dist/ai.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/*! For license information please see ai.js.LICENSE.txt */
|
|
2
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("cloudbase_ai",[],t):"object"==typeof exports?exports.cloudbase_ai=t():e.cloudbase_ai=t()}("undefined"!=typeof window?window:this,(()=>(()=>{var e={639:function(e,t,r){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,o)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),o=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||n(t,e,r)};Object.defineProperty(t,"__esModule",{value:!0}),o(r(138),t)},877:function(e,t,r){var n,o;void 0===(o="function"==typeof(n=function(){"use strict";var e=void 0!==r.g?r.g:self;if(void 0!==e.TextEncoder&&void 0!==e.TextDecoder)return{TextEncoder:e.TextEncoder,TextDecoder:e.TextDecoder};var t=["utf8","utf-8","unicode-1-1-utf-8"];return{TextEncoder:function(e){if(t.indexOf(e)<0&&null!=e)throw new RangeError("Invalid encoding type. Only utf-8 is supported");this.encoding="utf-8",this.encode=function(e){if("string"!=typeof e)throw new TypeError("passed argument must be of type string");var t=unescape(encodeURIComponent(e)),r=new Uint8Array(t.length);return t.split("").forEach((function(e,t){r[t]=e.charCodeAt(0)})),r}},TextDecoder:function(e,r){if(t.indexOf(e)<0&&null!=e)throw new RangeError("Invalid encoding type. Only utf-8 is supported");if(this.encoding="utf-8",this.ignoreBOM=!1,this.fatal=void 0!==r&&"fatal"in r&&r.fatal,"boolean"!=typeof this.fatal)throw new TypeError("fatal flag must be boolean");this.decode=function(e,t){if(void 0===e)return"";if("boolean"!=typeof(void 0!==t&&"stream"in t&&t.stream))throw new TypeError("stream option must be boolean");if(ArrayBuffer.isView(e)){var r=new Uint8Array(e.buffer,e.byteOffset,e.byteLength),n=new Array(r.length);return r.forEach((function(e,t){n[t]=String.fromCharCode(e)})),decodeURIComponent(escape(n.join("")))}throw new TypeError("passed argument must be an array buffer view")}}}})?n.apply(t,[]):n)||(e.exports=o)},138:(e,t,r)=>{"use strict";r.r(t),r.d(t,{AI:()=>Fi,Bot:()=>Zn,SimpleChatModel:()=>Di,createAI:()=>Yi,createAi:()=>Ji,models:()=>Gi,registerAi:()=>Vi,utils:()=>n});var n={};r.r(n),r.d(n,{ReadableStream:()=>Bn,TextDecoderStream:()=>Fn,TransformStream:()=>Mn,createAsyncIterable:()=>Dn,createEventSourceParserTransformStream:()=>Ln,createPromise:()=>Hn,functionToolToModelTool:()=>Jn,intoStandardStream:()=>$n,intoTextStream:()=>Nn,isToolCallAssistantMessage:()=>Yn,readableStream2JsonObject:()=>Gn,toPolyfillReadable:()=>zn});var o={};function i(){}function a(e){return"object"==typeof e&&null!==e||"function"==typeof e}r.r(o),r.d(o,{ArkSimpleModel:()=>So,DSSimpleModel:()=>jo,DefaultImageModel:()=>ei,DefaultSimpleModel:()=>Zo,HunYuanBetaSimpleModel:()=>ho,HunYuanExpSimpleModel:()=>Fo,HunYuanOpenSimpleModel:()=>Go,HunYuanSimpleModel:()=>mo,MODELS:()=>hi,MoonshotSimpleModel:()=>Bo,ReactModel:()=>ai,YiSimpleModel:()=>xo,ZhiPuSimpleModel:()=>io,toolMap:()=>li});const s=i;function u(e,t){try{Object.defineProperty(e,"name",{value:t,configurable:!0})}catch(e){}}const l=Promise,c=Promise.resolve.bind(l),f=Promise.prototype.then,d=Promise.reject.bind(l),h=c;function p(e){return new l(e)}function b(e){return p((t=>t(e)))}function y(e){return d(e)}function m(e,t,r){return f.call(e,t,r)}function v(e,t,r){m(m(e,t,r),void 0,s)}function _(e,t){v(e,t)}function g(e,t){v(e,void 0,t)}function w(e,t,r){return m(e,t,r)}function S(e){m(e,void 0,s)}let R=e=>{if("function"==typeof queueMicrotask)R=queueMicrotask;else{const e=b(void 0);R=t=>m(e,t)}return R(e)};function T(e,t,r){if("function"!=typeof e)throw new TypeError("Argument is not a function");return Function.prototype.apply.call(e,t,r)}function P(e,t,r){try{return b(T(e,t,r))}catch(e){return y(e)}}class O{constructor(){this._cursor=0,this._size=0,this._front={_elements:[],_next:void 0},this._back=this._front,this._cursor=0,this._size=0}get length(){return this._size}push(e){const t=this._back;let r=t;16383===t._elements.length&&(r={_elements:[],_next:void 0}),t._elements.push(e),r!==t&&(this._back=r,t._next=r),++this._size}shift(){const e=this._front;let t=e;const r=this._cursor;let n=r+1;const o=e._elements,i=o[r];return 16384===n&&(t=e._next,n=0),--this._size,this._cursor=n,e!==t&&(this._front=t),o[r]=void 0,i}forEach(e){let t=this._cursor,r=this._front,n=r._elements;for(;!(t===n.length&&void 0===r._next||t===n.length&&(r=r._next,n=r._elements,t=0,0===n.length));)e(n[t]),++t}peek(){const e=this._front,t=this._cursor;return e._elements[t]}}const j=Symbol("[[AbortSteps]]"),q=Symbol("[[ErrorSteps]]"),k=Symbol("[[CancelSteps]]"),E=Symbol("[[PullSteps]]"),C=Symbol("[[ReleaseSteps]]");function x(e,t){e._ownerReadableStream=t,t._reader=e,"readable"===t._state?U(e):"closed"===t._state?function(e){U(e),L(e)}(e):B(e,t._storedError)}function A(e,t){return Fr(e._ownerReadableStream,t)}function I(e){const t=e._ownerReadableStream;"readable"===t._state?M(e,new TypeError("Reader was released and can no longer be used to monitor the stream's closedness")):function(e){B(e,new TypeError("Reader was released and can no longer be used to monitor the stream's closedness"))}(e),t._readableStreamController[C](),t._reader=void 0,e._ownerReadableStream=void 0}function W(e){return new TypeError("Cannot "+e+" a stream using a released reader")}function U(e){e._closedPromise=p(((t,r)=>{e._closedPromise_resolve=t,e._closedPromise_reject=r}))}function B(e,t){U(e),M(e,t)}function M(e,t){void 0!==e._closedPromise_reject&&(S(e._closedPromise),e._closedPromise_reject(t),e._closedPromise_resolve=void 0,e._closedPromise_reject=void 0)}function L(e){void 0!==e._closedPromise_resolve&&(e._closedPromise_resolve(void 0),e._closedPromise_resolve=void 0,e._closedPromise_reject=void 0)}const z=Number.isFinite||function(e){return"number"==typeof e&&isFinite(e)},F=Math.trunc||function(e){return e<0?Math.ceil(e):Math.floor(e)};function D(e,t){if(void 0!==e&&"object"!=typeof(r=e)&&"function"!=typeof r)throw new TypeError(`${t} is not an object.`);var r}function $(e,t){if("function"!=typeof e)throw new TypeError(`${t} is not a function.`)}function N(e,t){if(!function(e){return"object"==typeof e&&null!==e||"function"==typeof e}(e))throw new TypeError(`${t} is not an object.`)}function G(e,t,r){if(void 0===e)throw new TypeError(`Parameter ${t} is required in '${r}'.`)}function H(e,t,r){if(void 0===e)throw new TypeError(`${t} is required in '${r}'.`)}function Y(e){return Number(e)}function J(e){return 0===e?0:e}function Q(e,t){const r=Number.MAX_SAFE_INTEGER;let n=Number(e);if(n=J(n),!z(n))throw new TypeError(`${t} is not a finite number`);if(n=function(e){return J(F(e))}(n),n<0||n>r)throw new TypeError(`${t} is outside the accepted range of 0 to ${r}, inclusive`);return z(n)&&0!==n?n:0}function V(e,t){if(!Lr(e))throw new TypeError(`${t} is not a ReadableStream.`)}function X(e){return new re(e)}function K(e,t){e._reader._readRequests.push(t)}function Z(e,t,r){const n=e._reader._readRequests.shift();r?n._closeSteps():n._chunkSteps(t)}function ee(e){return e._reader._readRequests.length}function te(e){const t=e._reader;return void 0!==t&&!!ne(t)}class re{constructor(e){if(G(e,1,"ReadableStreamDefaultReader"),V(e,"First parameter"),zr(e))throw new TypeError("This stream has already been locked for exclusive reading by another reader");x(this,e),this._readRequests=new O}get closed(){return ne(this)?this._closedPromise:y(ae("closed"))}cancel(e=void 0){return ne(this)?void 0===this._ownerReadableStream?y(W("cancel")):A(this,e):y(ae("cancel"))}read(){if(!ne(this))return y(ae("read"));if(void 0===this._ownerReadableStream)return y(W("read from"));let e,t;const r=p(((r,n)=>{e=r,t=n}));return oe(this,{_chunkSteps:t=>e({value:t,done:!1}),_closeSteps:()=>e({value:void 0,done:!0}),_errorSteps:e=>t(e)}),r}releaseLock(){if(!ne(this))throw ae("releaseLock");void 0!==this._ownerReadableStream&&function(e){I(e),ie(e,new TypeError("Reader was released"))}(this)}}function ne(e){return!!a(e)&&!!Object.prototype.hasOwnProperty.call(e,"_readRequests")&&e instanceof re}function oe(e,t){const r=e._ownerReadableStream;r._disturbed=!0,"closed"===r._state?t._closeSteps():"errored"===r._state?t._errorSteps(r._storedError):r._readableStreamController[E](t)}function ie(e,t){const r=e._readRequests;e._readRequests=new O,r.forEach((e=>{e._errorSteps(t)}))}function ae(e){return new TypeError(`ReadableStreamDefaultReader.prototype.${e} can only be used on a ReadableStreamDefaultReader`)}var se,ue,le;function ce(e){return e.slice()}function fe(e,t,r,n,o){new Uint8Array(e).set(new Uint8Array(r,n,o),t)}Object.defineProperties(re.prototype,{cancel:{enumerable:!0},read:{enumerable:!0},releaseLock:{enumerable:!0},closed:{enumerable:!0}}),u(re.prototype.cancel,"cancel"),u(re.prototype.read,"read"),u(re.prototype.releaseLock,"releaseLock"),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(re.prototype,Symbol.toStringTag,{value:"ReadableStreamDefaultReader",configurable:!0});let de=e=>(de="function"==typeof e.transfer?e=>e.transfer():"function"==typeof structuredClone?e=>structuredClone(e,{transfer:[e]}):e=>e,de(e)),he=e=>(he="boolean"==typeof e.detached?e=>e.detached:e=>0===e.byteLength,he(e));function pe(e,t,r){if(e.slice)return e.slice(t,r);const n=r-t,o=new ArrayBuffer(n);return fe(o,0,e,t,n),o}function be(e,t){const r=e[t];if(null!=r){if("function"!=typeof r)throw new TypeError(`${String(t)} is not a function`);return r}}function ye(e){try{const t=e.done,r=e.value;return m(h(r),(e=>({done:t,value:e})))}catch(e){return y(e)}}const me=null!==(le=null!==(se=Symbol.asyncIterator)&&void 0!==se?se:null===(ue=Symbol.for)||void 0===ue?void 0:ue.call(Symbol,"Symbol.asyncIterator"))&&void 0!==le?le:"@@asyncIterator";function ve(e,t="sync",r){if(void 0===r)if("async"===t){if(void 0===(r=be(e,me)))return function(e){const t={next(){let t;try{t=_e(e)}catch(e){return y(e)}return ye(t)},return(t){let r;try{const n=be(e.iterator,"return");if(void 0===n)return b({done:!0,value:t});r=T(n,e.iterator,[t])}catch(e){return y(e)}return a(r)?ye(r):y(new TypeError("The iterator.return() method must return an object"))}};return{iterator:t,nextMethod:t.next,done:!1}}(ve(e,"sync",be(e,Symbol.iterator)))}else r=be(e,Symbol.iterator);if(void 0===r)throw new TypeError("The object is not iterable");const n=T(r,e,[]);if(!a(n))throw new TypeError("The iterator method must return an object");return{iterator:n,nextMethod:n.next,done:!1}}function _e(e){const t=T(e.nextMethod,e.iterator,[]);if(!a(t))throw new TypeError("The iterator.next() method must return an object");return t}class ge{constructor(e,t){this._ongoingPromise=void 0,this._isFinished=!1,this._reader=e,this._preventCancel=t}next(){const e=()=>this._nextSteps();return this._ongoingPromise=this._ongoingPromise?w(this._ongoingPromise,e,e):e(),this._ongoingPromise}return(e){const t=()=>this._returnSteps(e);return this._ongoingPromise?w(this._ongoingPromise,t,t):t()}_nextSteps(){if(this._isFinished)return Promise.resolve({value:void 0,done:!0});const e=this._reader;let t,r;const n=p(((e,n)=>{t=e,r=n}));return oe(e,{_chunkSteps:e=>{this._ongoingPromise=void 0,R((()=>t({value:e,done:!1})))},_closeSteps:()=>{this._ongoingPromise=void 0,this._isFinished=!0,I(e),t({value:void 0,done:!0})},_errorSteps:t=>{this._ongoingPromise=void 0,this._isFinished=!0,I(e),r(t)}}),n}_returnSteps(e){if(this._isFinished)return Promise.resolve({value:e,done:!0});this._isFinished=!0;const t=this._reader;if(!this._preventCancel){const r=A(t,e);return I(t),w(r,(()=>({value:e,done:!0})))}return I(t),b({value:e,done:!0})}}const we={next(){return Se(this)?this._asyncIteratorImpl.next():y(Re("next"))},return(e){return Se(this)?this._asyncIteratorImpl.return(e):y(Re("return"))},[me](){return this}};function Se(e){if(!a(e))return!1;if(!Object.prototype.hasOwnProperty.call(e,"_asyncIteratorImpl"))return!1;try{return e._asyncIteratorImpl instanceof ge}catch(e){return!1}}function Re(e){return new TypeError(`ReadableStreamAsyncIterator.${e} can only be used on a ReadableSteamAsyncIterator`)}Object.defineProperty(we,me,{enumerable:!1});const Te=Number.isNaN||function(e){return e!=e};function Pe(e){const t=pe(e.buffer,e.byteOffset,e.byteOffset+e.byteLength);return new Uint8Array(t)}function Oe(e){const t=e._queue.shift();return e._queueTotalSize-=t.size,e._queueTotalSize<0&&(e._queueTotalSize=0),t.value}function je(e,t,r){if("number"!=typeof(n=r)||Te(n)||n<0||r===1/0)throw new RangeError("Size must be a finite, non-NaN, non-negative number.");var n;e._queue.push({value:t,size:r}),e._queueTotalSize+=r}function qe(e){e._queue=new O,e._queueTotalSize=0}function ke(e){return e===DataView}class Ee{constructor(){throw new TypeError("Illegal constructor")}get view(){if(!Ae(this))throw ot("view");return this._view}respond(e){if(!Ae(this))throw ot("respond");if(G(e,1,"respond"),e=Q(e,"First parameter"),void 0===this._associatedReadableByteStreamController)throw new TypeError("This BYOB request has been invalidated");if(he(this._view.buffer))throw new TypeError("The BYOB request's buffer has been detached and so cannot be used as a response");tt(this._associatedReadableByteStreamController,e)}respondWithNewView(e){if(!Ae(this))throw ot("respondWithNewView");if(G(e,1,"respondWithNewView"),!ArrayBuffer.isView(e))throw new TypeError("You can only respond with array buffer views");if(void 0===this._associatedReadableByteStreamController)throw new TypeError("This BYOB request has been invalidated");if(he(e.buffer))throw new TypeError("The given view's buffer has been detached and so cannot be used as a response");rt(this._associatedReadableByteStreamController,e)}}Object.defineProperties(Ee.prototype,{respond:{enumerable:!0},respondWithNewView:{enumerable:!0},view:{enumerable:!0}}),u(Ee.prototype.respond,"respond"),u(Ee.prototype.respondWithNewView,"respondWithNewView"),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(Ee.prototype,Symbol.toStringTag,{value:"ReadableStreamBYOBRequest",configurable:!0});class Ce{constructor(){throw new TypeError("Illegal constructor")}get byobRequest(){if(!xe(this))throw it("byobRequest");return Ze(this)}get desiredSize(){if(!xe(this))throw it("desiredSize");return et(this)}close(){if(!xe(this))throw it("close");if(this._closeRequested)throw new TypeError("The stream has already been closed; do not close it again!");const e=this._controlledReadableByteStream._state;if("readable"!==e)throw new TypeError(`The stream (in ${e} state) is not in the readable state and cannot be closed`);Qe(this)}enqueue(e){if(!xe(this))throw it("enqueue");if(G(e,1,"enqueue"),!ArrayBuffer.isView(e))throw new TypeError("chunk must be an array buffer view");if(0===e.byteLength)throw new TypeError("chunk must have non-zero byteLength");if(0===e.buffer.byteLength)throw new TypeError("chunk's buffer must have non-zero byteLength");if(this._closeRequested)throw new TypeError("stream is closed or draining");const t=this._controlledReadableByteStream._state;if("readable"!==t)throw new TypeError(`The stream (in ${t} state) is not in the readable state and cannot be enqueued to`);Ve(this,e)}error(e=void 0){if(!xe(this))throw it("error");Xe(this,e)}[k](e){We(this),qe(this);const t=this._cancelAlgorithm(e);return Je(this),t}[E](e){const t=this._controlledReadableByteStream;if(this._queueTotalSize>0)return void Ke(this,e);const r=this._autoAllocateChunkSize;if(void 0!==r){let n;try{n=new ArrayBuffer(r)}catch(t){return void e._errorSteps(t)}const o={buffer:n,bufferByteLength:r,byteOffset:0,byteLength:r,bytesFilled:0,minimumFill:1,elementSize:1,viewConstructor:Uint8Array,readerType:"default"};this._pendingPullIntos.push(o)}K(t,e),Ie(this)}[C](){if(this._pendingPullIntos.length>0){const e=this._pendingPullIntos.peek();e.readerType="none",this._pendingPullIntos=new O,this._pendingPullIntos.push(e)}}}function xe(e){return!!a(e)&&!!Object.prototype.hasOwnProperty.call(e,"_controlledReadableByteStream")&&e instanceof Ce}function Ae(e){return!!a(e)&&!!Object.prototype.hasOwnProperty.call(e,"_associatedReadableByteStreamController")&&e instanceof Ee}function Ie(e){const t=function(e){const t=e._controlledReadableByteStream;return"readable"===t._state&&(!e._closeRequested&&(!!e._started&&(!!(te(t)&&ee(t)>0)||(!!(ct(t)&<(t)>0)||et(e)>0))))}(e);t&&(e._pulling?e._pullAgain=!0:(e._pulling=!0,v(e._pullAlgorithm(),(()=>(e._pulling=!1,e._pullAgain&&(e._pullAgain=!1,Ie(e)),null)),(t=>(Xe(e,t),null)))))}function We(e){Ne(e),e._pendingPullIntos=new O}function Ue(e,t){let r=!1;"closed"===e._state&&(r=!0);const n=Be(t);"default"===t.readerType?Z(e,n,r):function(e,t,r){const n=e._reader._readIntoRequests.shift();r?n._closeSteps(t):n._chunkSteps(t)}(e,n,r)}function Be(e){const t=e.bytesFilled,r=e.elementSize;return new e.viewConstructor(e.buffer,e.byteOffset,t/r)}function Me(e,t,r,n){e._queue.push({buffer:t,byteOffset:r,byteLength:n}),e._queueTotalSize+=n}function Le(e,t,r,n){let o;try{o=pe(t,r,r+n)}catch(t){throw Xe(e,t),t}Me(e,o,0,n)}function ze(e,t){t.bytesFilled>0&&Le(e,t.buffer,t.byteOffset,t.bytesFilled),Ye(e)}function Fe(e,t){const r=Math.min(e._queueTotalSize,t.byteLength-t.bytesFilled),n=t.bytesFilled+r;let o=r,i=!1;const a=n-n%t.elementSize;a>=t.minimumFill&&(o=a-t.bytesFilled,i=!0);const s=e._queue;for(;o>0;){const r=s.peek(),n=Math.min(o,r.byteLength),i=t.byteOffset+t.bytesFilled;fe(t.buffer,i,r.buffer,r.byteOffset,n),r.byteLength===n?s.shift():(r.byteOffset+=n,r.byteLength-=n),e._queueTotalSize-=n,De(0,n,t),o-=n}return i}function De(e,t,r){r.bytesFilled+=t}function $e(e){0===e._queueTotalSize&&e._closeRequested?(Je(e),Dr(e._controlledReadableByteStream)):Ie(e)}function Ne(e){null!==e._byobRequest&&(e._byobRequest._associatedReadableByteStreamController=void 0,e._byobRequest._view=null,e._byobRequest=null)}function Ge(e){for(;e._pendingPullIntos.length>0;){if(0===e._queueTotalSize)return;const t=e._pendingPullIntos.peek();Fe(e,t)&&(Ye(e),Ue(e._controlledReadableByteStream,t))}}function He(e,t){const r=e._pendingPullIntos.peek();Ne(e),"closed"===e._controlledReadableByteStream._state?function(e,t){"none"===t.readerType&&Ye(e);const r=e._controlledReadableByteStream;if(ct(r))for(;lt(r)>0;)Ue(r,Ye(e))}(e,r):function(e,t,r){if(De(0,t,r),"none"===r.readerType)return ze(e,r),void Ge(e);if(r.bytesFilled<r.minimumFill)return;Ye(e);const n=r.bytesFilled%r.elementSize;if(n>0){const t=r.byteOffset+r.bytesFilled;Le(e,r.buffer,t-n,n)}r.bytesFilled-=n,Ue(e._controlledReadableByteStream,r),Ge(e)}(e,t,r),Ie(e)}function Ye(e){return e._pendingPullIntos.shift()}function Je(e){e._pullAlgorithm=void 0,e._cancelAlgorithm=void 0}function Qe(e){const t=e._controlledReadableByteStream;if(!e._closeRequested&&"readable"===t._state)if(e._queueTotalSize>0)e._closeRequested=!0;else{if(e._pendingPullIntos.length>0){const t=e._pendingPullIntos.peek();if(t.bytesFilled%t.elementSize!=0){const t=new TypeError("Insufficient bytes to fill elements in the given buffer");throw Xe(e,t),t}}Je(e),Dr(t)}}function Ve(e,t){const r=e._controlledReadableByteStream;if(e._closeRequested||"readable"!==r._state)return;const{buffer:n,byteOffset:o,byteLength:i}=t;if(he(n))throw new TypeError("chunk's buffer is detached and so cannot be enqueued");const a=de(n);if(e._pendingPullIntos.length>0){const t=e._pendingPullIntos.peek();if(he(t.buffer))throw new TypeError("The BYOB request's buffer has been detached and so cannot be filled with an enqueued chunk");Ne(e),t.buffer=de(t.buffer),"none"===t.readerType&&ze(e,t)}te(r)?(function(e){const t=e._controlledReadableByteStream._reader;for(;t._readRequests.length>0;){if(0===e._queueTotalSize)return;Ke(e,t._readRequests.shift())}}(e),0===ee(r)?Me(e,a,o,i):(e._pendingPullIntos.length>0&&Ye(e),Z(r,new Uint8Array(a,o,i),!1))):ct(r)?(Me(e,a,o,i),Ge(e)):Me(e,a,o,i),Ie(e)}function Xe(e,t){const r=e._controlledReadableByteStream;"readable"===r._state&&(We(e),qe(e),Je(e),$r(r,t))}function Ke(e,t){const r=e._queue.shift();e._queueTotalSize-=r.byteLength,$e(e);const n=new Uint8Array(r.buffer,r.byteOffset,r.byteLength);t._chunkSteps(n)}function Ze(e){if(null===e._byobRequest&&e._pendingPullIntos.length>0){const t=e._pendingPullIntos.peek(),r=new Uint8Array(t.buffer,t.byteOffset+t.bytesFilled,t.byteLength-t.bytesFilled),n=Object.create(Ee.prototype);!function(e,t,r){e._associatedReadableByteStreamController=t,e._view=r}(n,e,r),e._byobRequest=n}return e._byobRequest}function et(e){const t=e._controlledReadableByteStream._state;return"errored"===t?null:"closed"===t?0:e._strategyHWM-e._queueTotalSize}function tt(e,t){const r=e._pendingPullIntos.peek();if("closed"===e._controlledReadableByteStream._state){if(0!==t)throw new TypeError("bytesWritten must be 0 when calling respond() on a closed stream")}else{if(0===t)throw new TypeError("bytesWritten must be greater than 0 when calling respond() on a readable stream");if(r.bytesFilled+t>r.byteLength)throw new RangeError("bytesWritten out of range")}r.buffer=de(r.buffer),He(e,t)}function rt(e,t){const r=e._pendingPullIntos.peek();if("closed"===e._controlledReadableByteStream._state){if(0!==t.byteLength)throw new TypeError("The view's length must be 0 when calling respondWithNewView() on a closed stream")}else if(0===t.byteLength)throw new TypeError("The view's length must be greater than 0 when calling respondWithNewView() on a readable stream");if(r.byteOffset+r.bytesFilled!==t.byteOffset)throw new RangeError("The region specified by view does not match byobRequest");if(r.bufferByteLength!==t.buffer.byteLength)throw new RangeError("The buffer of view has different capacity than byobRequest");if(r.bytesFilled+t.byteLength>r.byteLength)throw new RangeError("The region specified by view is larger than byobRequest");const n=t.byteLength;r.buffer=de(t.buffer),He(e,n)}function nt(e,t,r,n,o,i,a){t._controlledReadableByteStream=e,t._pullAgain=!1,t._pulling=!1,t._byobRequest=null,t._queue=t._queueTotalSize=void 0,qe(t),t._closeRequested=!1,t._started=!1,t._strategyHWM=i,t._pullAlgorithm=n,t._cancelAlgorithm=o,t._autoAllocateChunkSize=a,t._pendingPullIntos=new O,e._readableStreamController=t,v(b(r()),(()=>(t._started=!0,Ie(t),null)),(e=>(Xe(t,e),null)))}function ot(e){return new TypeError(`ReadableStreamBYOBRequest.prototype.${e} can only be used on a ReadableStreamBYOBRequest`)}function it(e){return new TypeError(`ReadableByteStreamController.prototype.${e} can only be used on a ReadableByteStreamController`)}function at(e,t){if("byob"!=(e=`${e}`))throw new TypeError(`${t} '${e}' is not a valid enumeration value for ReadableStreamReaderMode`);return e}function st(e){return new ft(e)}function ut(e,t){e._reader._readIntoRequests.push(t)}function lt(e){return e._reader._readIntoRequests.length}function ct(e){const t=e._reader;return void 0!==t&&!!dt(t)}Object.defineProperties(Ce.prototype,{close:{enumerable:!0},enqueue:{enumerable:!0},error:{enumerable:!0},byobRequest:{enumerable:!0},desiredSize:{enumerable:!0}}),u(Ce.prototype.close,"close"),u(Ce.prototype.enqueue,"enqueue"),u(Ce.prototype.error,"error"),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(Ce.prototype,Symbol.toStringTag,{value:"ReadableByteStreamController",configurable:!0});class ft{constructor(e){if(G(e,1,"ReadableStreamBYOBReader"),V(e,"First parameter"),zr(e))throw new TypeError("This stream has already been locked for exclusive reading by another reader");if(!xe(e._readableStreamController))throw new TypeError("Cannot construct a ReadableStreamBYOBReader for a stream not constructed with a byte source");x(this,e),this._readIntoRequests=new O}get closed(){return dt(this)?this._closedPromise:y(bt("closed"))}cancel(e=void 0){return dt(this)?void 0===this._ownerReadableStream?y(W("cancel")):A(this,e):y(bt("cancel"))}read(e,t={}){if(!dt(this))return y(bt("read"));if(!ArrayBuffer.isView(e))return y(new TypeError("view must be an array buffer view"));if(0===e.byteLength)return y(new TypeError("view must have non-zero byteLength"));if(0===e.buffer.byteLength)return y(new TypeError("view's buffer must have non-zero byteLength"));if(he(e.buffer))return y(new TypeError("view's buffer has been detached"));let r;try{r=function(e,t){var r;return D(e,t),{min:Q(null!==(r=null==e?void 0:e.min)&&void 0!==r?r:1,`${t} has member 'min' that`)}}(t,"options")}catch(e){return y(e)}const n=r.min;if(0===n)return y(new TypeError("options.min must be greater than 0"));if(function(e){return ke(e.constructor)}(e)){if(n>e.byteLength)return y(new RangeError("options.min must be less than or equal to view's byteLength"))}else if(n>e.length)return y(new RangeError("options.min must be less than or equal to view's length"));if(void 0===this._ownerReadableStream)return y(W("read from"));let o,i;const a=p(((e,t)=>{o=e,i=t}));return ht(this,e,n,{_chunkSteps:e=>o({value:e,done:!1}),_closeSteps:e=>o({value:e,done:!0}),_errorSteps:e=>i(e)}),a}releaseLock(){if(!dt(this))throw bt("releaseLock");void 0!==this._ownerReadableStream&&function(e){I(e),pt(e,new TypeError("Reader was released"))}(this)}}function dt(e){return!!a(e)&&!!Object.prototype.hasOwnProperty.call(e,"_readIntoRequests")&&e instanceof ft}function ht(e,t,r,n){const o=e._ownerReadableStream;o._disturbed=!0,"errored"===o._state?n._errorSteps(o._storedError):function(e,t,r,n){const o=e._controlledReadableByteStream,i=t.constructor,a=function(e){return ke(e)?1:e.BYTES_PER_ELEMENT}(i),{byteOffset:s,byteLength:u}=t,l=r*a;let c;try{c=de(t.buffer)}catch(e){return void n._errorSteps(e)}const f={buffer:c,bufferByteLength:c.byteLength,byteOffset:s,byteLength:u,bytesFilled:0,minimumFill:l,elementSize:a,viewConstructor:i,readerType:"byob"};if(e._pendingPullIntos.length>0)return e._pendingPullIntos.push(f),void ut(o,n);if("closed"!==o._state){if(e._queueTotalSize>0){if(Fe(e,f)){const t=Be(f);return $e(e),void n._chunkSteps(t)}if(e._closeRequested){const t=new TypeError("Insufficient bytes to fill elements in the given buffer");return Xe(e,t),void n._errorSteps(t)}}e._pendingPullIntos.push(f),ut(o,n),Ie(e)}else{const e=new i(f.buffer,f.byteOffset,0);n._closeSteps(e)}}(o._readableStreamController,t,r,n)}function pt(e,t){const r=e._readIntoRequests;e._readIntoRequests=new O,r.forEach((e=>{e._errorSteps(t)}))}function bt(e){return new TypeError(`ReadableStreamBYOBReader.prototype.${e} can only be used on a ReadableStreamBYOBReader`)}function yt(e,t){const{highWaterMark:r}=e;if(void 0===r)return t;if(Te(r)||r<0)throw new RangeError("Invalid highWaterMark");return r}function mt(e){const{size:t}=e;return t||(()=>1)}function vt(e,t){D(e,t);const r=null==e?void 0:e.highWaterMark,n=null==e?void 0:e.size;return{highWaterMark:void 0===r?void 0:Y(r),size:void 0===n?void 0:_t(n,`${t} has member 'size' that`)}}function _t(e,t){return $(e,t),t=>Y(e(t))}function gt(e,t,r){return $(e,r),r=>P(e,t,[r])}function wt(e,t,r){return $(e,r),()=>P(e,t,[])}function St(e,t,r){return $(e,r),r=>T(e,t,[r])}function Rt(e,t,r){return $(e,r),(r,n)=>P(e,t,[r,n])}function Tt(e,t){if(!kt(e))throw new TypeError(`${t} is not a WritableStream.`)}Object.defineProperties(ft.prototype,{cancel:{enumerable:!0},read:{enumerable:!0},releaseLock:{enumerable:!0},closed:{enumerable:!0}}),u(ft.prototype.cancel,"cancel"),u(ft.prototype.read,"read"),u(ft.prototype.releaseLock,"releaseLock"),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(ft.prototype,Symbol.toStringTag,{value:"ReadableStreamBYOBReader",configurable:!0});const Pt="function"==typeof AbortController;class Ot{constructor(e={},t={}){void 0===e?e=null:N(e,"First parameter");const r=vt(t,"Second parameter"),n=function(e,t){D(e,t);const r=null==e?void 0:e.abort,n=null==e?void 0:e.close,o=null==e?void 0:e.start,i=null==e?void 0:e.type,a=null==e?void 0:e.write;return{abort:void 0===r?void 0:gt(r,e,`${t} has member 'abort' that`),close:void 0===n?void 0:wt(n,e,`${t} has member 'close' that`),start:void 0===o?void 0:St(o,e,`${t} has member 'start' that`),write:void 0===a?void 0:Rt(a,e,`${t} has member 'write' that`),type:i}}(e,"First parameter");if(qt(this),void 0!==n.type)throw new RangeError("Invalid type is specified");const o=mt(r);!function(e,t,r,n){const o=Object.create(Ht.prototype);let i,a,s,u;i=void 0!==t.start?()=>t.start(o):()=>{},a=void 0!==t.write?e=>t.write(e,o):()=>b(void 0),s=void 0!==t.close?()=>t.close():()=>b(void 0),u=void 0!==t.abort?e=>t.abort(e):()=>b(void 0),Jt(e,o,i,a,s,u,r,n)}(this,n,yt(r,1),o)}get locked(){if(!kt(this))throw tr("locked");return Et(this)}abort(e=void 0){return kt(this)?Et(this)?y(new TypeError("Cannot abort a stream that already has a writer")):Ct(this,e):y(tr("abort"))}close(){return kt(this)?Et(this)?y(new TypeError("Cannot close a stream that already has a writer")):Ut(this)?y(new TypeError("Cannot close an already-closing stream")):xt(this):y(tr("close"))}getWriter(){if(!kt(this))throw tr("getWriter");return jt(this)}}function jt(e){return new Lt(e)}function qt(e){e._state="writable",e._storedError=void 0,e._writer=void 0,e._writableStreamController=void 0,e._writeRequests=new O,e._inFlightWriteRequest=void 0,e._closeRequest=void 0,e._inFlightCloseRequest=void 0,e._pendingAbortRequest=void 0,e._backpressure=!1}function kt(e){return!!a(e)&&!!Object.prototype.hasOwnProperty.call(e,"_writableStreamController")&&e instanceof Ot}function Et(e){return void 0!==e._writer}function Ct(e,t){var r;if("closed"===e._state||"errored"===e._state)return b(void 0);e._writableStreamController._abortReason=t,null===(r=e._writableStreamController._abortController)||void 0===r||r.abort(t);const n=e._state;if("closed"===n||"errored"===n)return b(void 0);if(void 0!==e._pendingAbortRequest)return e._pendingAbortRequest._promise;let o=!1;"erroring"===n&&(o=!0,t=void 0);const i=p(((r,n)=>{e._pendingAbortRequest={_promise:void 0,_resolve:r,_reject:n,_reason:t,_wasAlreadyErroring:o}}));return e._pendingAbortRequest._promise=i,o||It(e,t),i}function xt(e){const t=e._state;if("closed"===t||"errored"===t)return y(new TypeError(`The stream (in ${t} state) is not in the writable state and cannot be closed`));const r=p(((t,r)=>{const n={_resolve:t,_reject:r};e._closeRequest=n})),n=e._writer;var o;return void 0!==n&&e._backpressure&&"writable"===t&&hr(n),je(o=e._writableStreamController,Gt,0),Xt(o),r}function At(e,t){"writable"!==e._state?Wt(e):It(e,t)}function It(e,t){const r=e._writableStreamController;e._state="erroring",e._storedError=t;const n=e._writer;void 0!==n&&Dt(n,t),!function(e){return void 0!==e._inFlightWriteRequest||void 0!==e._inFlightCloseRequest}(e)&&r._started&&Wt(e)}function Wt(e){e._state="errored",e._writableStreamController[q]();const t=e._storedError;if(e._writeRequests.forEach((e=>{e._reject(t)})),e._writeRequests=new O,void 0===e._pendingAbortRequest)return void Bt(e);const r=e._pendingAbortRequest;if(e._pendingAbortRequest=void 0,r._wasAlreadyErroring)return r._reject(t),void Bt(e);v(e._writableStreamController[j](r._reason),(()=>(r._resolve(),Bt(e),null)),(t=>(r._reject(t),Bt(e),null)))}function Ut(e){return void 0!==e._closeRequest||void 0!==e._inFlightCloseRequest}function Bt(e){void 0!==e._closeRequest&&(e._closeRequest._reject(e._storedError),e._closeRequest=void 0);const t=e._writer;void 0!==t&&sr(t,e._storedError)}function Mt(e,t){const r=e._writer;void 0!==r&&t!==e._backpressure&&(t?function(e){lr(e)}(r):hr(r)),e._backpressure=t}Object.defineProperties(Ot.prototype,{abort:{enumerable:!0},close:{enumerable:!0},getWriter:{enumerable:!0},locked:{enumerable:!0}}),u(Ot.prototype.abort,"abort"),u(Ot.prototype.close,"close"),u(Ot.prototype.getWriter,"getWriter"),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(Ot.prototype,Symbol.toStringTag,{value:"WritableStream",configurable:!0});class Lt{constructor(e){if(G(e,1,"WritableStreamDefaultWriter"),Tt(e,"First parameter"),Et(e))throw new TypeError("This stream has already been locked for exclusive writing by another writer");this._ownerWritableStream=e,e._writer=this;const t=e._state;if("writable"===t)!Ut(e)&&e._backpressure?lr(this):fr(this),ir(this);else if("erroring"===t)cr(this,e._storedError),ir(this);else if("closed"===t)fr(this),ir(this),ur(this);else{const t=e._storedError;cr(this,t),ar(this,t)}}get closed(){return zt(this)?this._closedPromise:y(nr("closed"))}get desiredSize(){if(!zt(this))throw nr("desiredSize");if(void 0===this._ownerWritableStream)throw or("desiredSize");return function(e){const t=e._ownerWritableStream,r=t._state;return"errored"===r||"erroring"===r?null:"closed"===r?0:Vt(t._writableStreamController)}(this)}get ready(){return zt(this)?this._readyPromise:y(nr("ready"))}abort(e=void 0){return zt(this)?void 0===this._ownerWritableStream?y(or("abort")):function(e,t){return Ct(e._ownerWritableStream,t)}(this,e):y(nr("abort"))}close(){if(!zt(this))return y(nr("close"));const e=this._ownerWritableStream;return void 0===e?y(or("close")):Ut(e)?y(new TypeError("Cannot close an already-closing stream")):Ft(this)}releaseLock(){if(!zt(this))throw nr("releaseLock");void 0!==this._ownerWritableStream&&$t(this)}write(e=void 0){return zt(this)?void 0===this._ownerWritableStream?y(or("write to")):Nt(this,e):y(nr("write"))}}function zt(e){return!!a(e)&&!!Object.prototype.hasOwnProperty.call(e,"_ownerWritableStream")&&e instanceof Lt}function Ft(e){return xt(e._ownerWritableStream)}function Dt(e,t){"pending"===e._readyPromiseState?dr(e,t):function(e,t){cr(e,t)}(e,t)}function $t(e){const t=e._ownerWritableStream,r=new TypeError("Writer was released and can no longer be used to monitor the stream's closedness");Dt(e,r),function(e,t){"pending"===e._closedPromiseState?sr(e,t):function(e,t){ar(e,t)}(e,t)}(e,r),t._writer=void 0,e._ownerWritableStream=void 0}function Nt(e,t){const r=e._ownerWritableStream,n=r._writableStreamController,o=function(e,t){try{return e._strategySizeAlgorithm(t)}catch(t){return Kt(e,t),1}}(n,t);if(r!==e._ownerWritableStream)return y(or("write to"));const i=r._state;if("errored"===i)return y(r._storedError);if(Ut(r)||"closed"===i)return y(new TypeError("The stream is closing or closed and cannot be written to"));if("erroring"===i)return y(r._storedError);const a=function(e){return p(((t,r)=>{const n={_resolve:t,_reject:r};e._writeRequests.push(n)}))}(r);return function(e,t,r){try{je(e,t,r)}catch(t){return void Kt(e,t)}const n=e._controlledWritableStream;Ut(n)||"writable"!==n._state||Mt(n,Zt(e)),Xt(e)}(n,t,o),a}Object.defineProperties(Lt.prototype,{abort:{enumerable:!0},close:{enumerable:!0},releaseLock:{enumerable:!0},write:{enumerable:!0},closed:{enumerable:!0},desiredSize:{enumerable:!0},ready:{enumerable:!0}}),u(Lt.prototype.abort,"abort"),u(Lt.prototype.close,"close"),u(Lt.prototype.releaseLock,"releaseLock"),u(Lt.prototype.write,"write"),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(Lt.prototype,Symbol.toStringTag,{value:"WritableStreamDefaultWriter",configurable:!0});const Gt={};class Ht{constructor(){throw new TypeError("Illegal constructor")}get abortReason(){if(!Yt(this))throw rr("abortReason");return this._abortReason}get signal(){if(!Yt(this))throw rr("signal");if(void 0===this._abortController)throw new TypeError("WritableStreamDefaultController.prototype.signal is not supported");return this._abortController.signal}error(e=void 0){if(!Yt(this))throw rr("error");"writable"===this._controlledWritableStream._state&&er(this,e)}[j](e){const t=this._abortAlgorithm(e);return Qt(this),t}[q](){qe(this)}}function Yt(e){return!!a(e)&&!!Object.prototype.hasOwnProperty.call(e,"_controlledWritableStream")&&e instanceof Ht}function Jt(e,t,r,n,o,i,a,s){t._controlledWritableStream=e,e._writableStreamController=t,t._queue=void 0,t._queueTotalSize=void 0,qe(t),t._abortReason=void 0,t._abortController=function(){if(Pt)return new AbortController}(),t._started=!1,t._strategySizeAlgorithm=s,t._strategyHWM=a,t._writeAlgorithm=n,t._closeAlgorithm=o,t._abortAlgorithm=i;const u=Zt(t);Mt(e,u),v(b(r()),(()=>(t._started=!0,Xt(t),null)),(r=>(t._started=!0,At(e,r),null)))}function Qt(e){e._writeAlgorithm=void 0,e._closeAlgorithm=void 0,e._abortAlgorithm=void 0,e._strategySizeAlgorithm=void 0}function Vt(e){return e._strategyHWM-e._queueTotalSize}function Xt(e){const t=e._controlledWritableStream;if(!e._started)return;if(void 0!==t._inFlightWriteRequest)return;if("erroring"===t._state)return void Wt(t);if(0===e._queue.length)return;const r=e._queue.peek().value;r===Gt?function(e){const t=e._controlledWritableStream;(function(e){e._inFlightCloseRequest=e._closeRequest,e._closeRequest=void 0})(t),Oe(e);const r=e._closeAlgorithm();Qt(e),v(r,(()=>(function(e){e._inFlightCloseRequest._resolve(void 0),e._inFlightCloseRequest=void 0,"erroring"===e._state&&(e._storedError=void 0,void 0!==e._pendingAbortRequest&&(e._pendingAbortRequest._resolve(),e._pendingAbortRequest=void 0)),e._state="closed";const t=e._writer;void 0!==t&&ur(t)}(t),null)),(e=>(function(e,t){e._inFlightCloseRequest._reject(t),e._inFlightCloseRequest=void 0,void 0!==e._pendingAbortRequest&&(e._pendingAbortRequest._reject(t),e._pendingAbortRequest=void 0),At(e,t)}(t,e),null)))}(e):function(e,t){const r=e._controlledWritableStream;!function(e){e._inFlightWriteRequest=e._writeRequests.shift()}(r),v(e._writeAlgorithm(t),(()=>{!function(e){e._inFlightWriteRequest._resolve(void 0),e._inFlightWriteRequest=void 0}(r);const t=r._state;if(Oe(e),!Ut(r)&&"writable"===t){const t=Zt(e);Mt(r,t)}return Xt(e),null}),(t=>("writable"===r._state&&Qt(e),function(e,t){e._inFlightWriteRequest._reject(t),e._inFlightWriteRequest=void 0,At(e,t)}(r,t),null)))}(e,r)}function Kt(e,t){"writable"===e._controlledWritableStream._state&&er(e,t)}function Zt(e){return Vt(e)<=0}function er(e,t){const r=e._controlledWritableStream;Qt(e),It(r,t)}function tr(e){return new TypeError(`WritableStream.prototype.${e} can only be used on a WritableStream`)}function rr(e){return new TypeError(`WritableStreamDefaultController.prototype.${e} can only be used on a WritableStreamDefaultController`)}function nr(e){return new TypeError(`WritableStreamDefaultWriter.prototype.${e} can only be used on a WritableStreamDefaultWriter`)}function or(e){return new TypeError("Cannot "+e+" a stream using a released writer")}function ir(e){e._closedPromise=p(((t,r)=>{e._closedPromise_resolve=t,e._closedPromise_reject=r,e._closedPromiseState="pending"}))}function ar(e,t){ir(e),sr(e,t)}function sr(e,t){void 0!==e._closedPromise_reject&&(S(e._closedPromise),e._closedPromise_reject(t),e._closedPromise_resolve=void 0,e._closedPromise_reject=void 0,e._closedPromiseState="rejected")}function ur(e){void 0!==e._closedPromise_resolve&&(e._closedPromise_resolve(void 0),e._closedPromise_resolve=void 0,e._closedPromise_reject=void 0,e._closedPromiseState="resolved")}function lr(e){e._readyPromise=p(((t,r)=>{e._readyPromise_resolve=t,e._readyPromise_reject=r})),e._readyPromiseState="pending"}function cr(e,t){lr(e),dr(e,t)}function fr(e){lr(e),hr(e)}function dr(e,t){void 0!==e._readyPromise_reject&&(S(e._readyPromise),e._readyPromise_reject(t),e._readyPromise_resolve=void 0,e._readyPromise_reject=void 0,e._readyPromiseState="rejected")}function hr(e){void 0!==e._readyPromise_resolve&&(e._readyPromise_resolve(void 0),e._readyPromise_resolve=void 0,e._readyPromise_reject=void 0,e._readyPromiseState="fulfilled")}Object.defineProperties(Ht.prototype,{abortReason:{enumerable:!0},signal:{enumerable:!0},error:{enumerable:!0}}),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(Ht.prototype,Symbol.toStringTag,{value:"WritableStreamDefaultController",configurable:!0});const pr="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof global?global:void 0,br=function(){const e=null==pr?void 0:pr.DOMException;return function(e){if("function"!=typeof e&&"object"!=typeof e)return!1;if("DOMException"!==e.name)return!1;try{return new e,!0}catch(e){return!1}}(e)?e:void 0}()||function(){const e=function(e,t){this.message=e||"",this.name=t||"Error",Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)};return u(e,"DOMException"),e.prototype=Object.create(Error.prototype),Object.defineProperty(e.prototype,"constructor",{value:e,writable:!0,configurable:!0}),e}();function yr(e,t,r,n,o,a){const s=X(e),u=jt(t);e._disturbed=!0;let l=!1,c=b(void 0);return p(((f,d)=>{let h;if(void 0!==a){if(h=()=>{const r=void 0!==a.reason?a.reason:new br("Aborted","AbortError"),i=[];n||i.push((()=>"writable"===t._state?Ct(t,r):b(void 0))),o||i.push((()=>"readable"===e._state?Fr(e,r):b(void 0))),j((()=>Promise.all(i.map((e=>e())))),!0,r)},a.aborted)return void h();a.addEventListener("abort",h)}var w,R,T;if(O(e,s._closedPromise,(e=>(n?q(!0,e):j((()=>Ct(t,e)),!0,e),null))),O(t,u._closedPromise,(t=>(o?q(!0,t):j((()=>Fr(e,t)),!0,t),null))),w=e,R=s._closedPromise,T=()=>(r?q():j((()=>function(e){const t=e._ownerWritableStream,r=t._state;return Ut(t)||"closed"===r?b(void 0):"errored"===r?y(t._storedError):Ft(e)}(u))),null),"closed"===w._state?T():_(R,T),Ut(t)||"closed"===t._state){const t=new TypeError("the destination writable stream closed before all data could be piped to it");o?q(!0,t):j((()=>Fr(e,t)),!0,t)}function P(){const e=c;return m(c,(()=>e!==c?P():void 0))}function O(e,t,r){"errored"===e._state?r(e._storedError):g(t,r)}function j(e,r,n){function o(){return v(e(),(()=>k(r,n)),(e=>k(!0,e))),null}l||(l=!0,"writable"!==t._state||Ut(t)?o():_(P(),o))}function q(e,r){l||(l=!0,"writable"!==t._state||Ut(t)?k(e,r):_(P(),(()=>k(e,r))))}function k(e,t){return $t(u),I(s),void 0!==a&&a.removeEventListener("abort",h),e?d(t):f(void 0),null}S(p(((e,t)=>{!function r(n){n?e():m(l?b(!0):m(u._readyPromise,(()=>p(((e,t)=>{oe(s,{_chunkSteps:t=>{c=m(Nt(u,t),void 0,i),e(!1)},_closeSteps:()=>e(!0),_errorSteps:t})})))),r,t)}(!1)})))}))}class mr{constructor(){throw new TypeError("Illegal constructor")}get desiredSize(){if(!vr(this))throw qr("desiredSize");return Pr(this)}close(){if(!vr(this))throw qr("close");if(!Or(this))throw new TypeError("The stream is not in a state that permits close");Sr(this)}enqueue(e=void 0){if(!vr(this))throw qr("enqueue");if(!Or(this))throw new TypeError("The stream is not in a state that permits enqueue");return Rr(this,e)}error(e=void 0){if(!vr(this))throw qr("error");Tr(this,e)}[k](e){qe(this);const t=this._cancelAlgorithm(e);return wr(this),t}[E](e){const t=this._controlledReadableStream;if(this._queue.length>0){const r=Oe(this);this._closeRequested&&0===this._queue.length?(wr(this),Dr(t)):_r(this),e._chunkSteps(r)}else K(t,e),_r(this)}[C](){}}function vr(e){return!!a(e)&&!!Object.prototype.hasOwnProperty.call(e,"_controlledReadableStream")&&e instanceof mr}function _r(e){gr(e)&&(e._pulling?e._pullAgain=!0:(e._pulling=!0,v(e._pullAlgorithm(),(()=>(e._pulling=!1,e._pullAgain&&(e._pullAgain=!1,_r(e)),null)),(t=>(Tr(e,t),null)))))}function gr(e){const t=e._controlledReadableStream;return!!Or(e)&&!!e._started&&(!!(zr(t)&&ee(t)>0)||Pr(e)>0)}function wr(e){e._pullAlgorithm=void 0,e._cancelAlgorithm=void 0,e._strategySizeAlgorithm=void 0}function Sr(e){if(!Or(e))return;const t=e._controlledReadableStream;e._closeRequested=!0,0===e._queue.length&&(wr(e),Dr(t))}function Rr(e,t){if(!Or(e))return;const r=e._controlledReadableStream;if(zr(r)&&ee(r)>0)Z(r,t,!1);else{let r;try{r=e._strategySizeAlgorithm(t)}catch(t){throw Tr(e,t),t}try{je(e,t,r)}catch(t){throw Tr(e,t),t}}_r(e)}function Tr(e,t){const r=e._controlledReadableStream;"readable"===r._state&&(qe(e),wr(e),$r(r,t))}function Pr(e){const t=e._controlledReadableStream._state;return"errored"===t?null:"closed"===t?0:e._strategyHWM-e._queueTotalSize}function Or(e){const t=e._controlledReadableStream._state;return!e._closeRequested&&"readable"===t}function jr(e,t,r,n,o,i,a){t._controlledReadableStream=e,t._queue=void 0,t._queueTotalSize=void 0,qe(t),t._started=!1,t._closeRequested=!1,t._pullAgain=!1,t._pulling=!1,t._strategySizeAlgorithm=a,t._strategyHWM=i,t._pullAlgorithm=n,t._cancelAlgorithm=o,e._readableStreamController=t,v(b(r()),(()=>(t._started=!0,_r(t),null)),(e=>(Tr(t,e),null)))}function qr(e){return new TypeError(`ReadableStreamDefaultController.prototype.${e} can only be used on a ReadableStreamDefaultController`)}function kr(e){return a(t=e)&&void 0!==t.getReader?function(e){let t;return t=Ur(i,(function(){let r;try{r=e.read()}catch(r){return y(r)}return w(r,(e=>{if(!a(e))throw new TypeError("The promise returned by the reader.read() method must fulfill with an object");if(e.done)Sr(t._readableStreamController);else{const r=e.value;Rr(t._readableStreamController,r)}}))}),(function(t){try{return b(e.cancel(t))}catch(t){return y(t)}}),0),t}(e.getReader()):function(e){let t;const r=ve(e,"async");return t=Ur(i,(function(){let e;try{e=_e(r)}catch(e){return y(e)}return w(b(e),(e=>{if(!a(e))throw new TypeError("The promise returned by the iterator.next() method must fulfill with an object");if(e.done)Sr(t._readableStreamController);else{const r=e.value;Rr(t._readableStreamController,r)}}))}),(function(e){const t=r.iterator;let n;try{n=be(t,"return")}catch(e){return y(e)}return void 0===n?b(void 0):w(P(n,t,[e]),(e=>{if(!a(e))throw new TypeError("The promise returned by the iterator.return() method must fulfill with an object")}))}),0),t}(e);var t}function Er(e,t,r){return $(e,r),r=>P(e,t,[r])}function Cr(e,t,r){return $(e,r),r=>P(e,t,[r])}function xr(e,t,r){return $(e,r),r=>T(e,t,[r])}function Ar(e,t){if("bytes"!=(e=`${e}`))throw new TypeError(`${t} '${e}' is not a valid enumeration value for ReadableStreamType`);return e}function Ir(e,t){D(e,t);const r=null==e?void 0:e.preventAbort,n=null==e?void 0:e.preventCancel,o=null==e?void 0:e.preventClose,i=null==e?void 0:e.signal;return void 0!==i&&function(e,t){if(!function(e){if("object"!=typeof e||null===e)return!1;try{return"boolean"==typeof e.aborted}catch(e){return!1}}(e))throw new TypeError(`${t} is not an AbortSignal.`)}(i,`${t} has member 'signal' that`),{preventAbort:Boolean(r),preventCancel:Boolean(n),preventClose:Boolean(o),signal:i}}Object.defineProperties(mr.prototype,{close:{enumerable:!0},enqueue:{enumerable:!0},error:{enumerable:!0},desiredSize:{enumerable:!0}}),u(mr.prototype.close,"close"),u(mr.prototype.enqueue,"enqueue"),u(mr.prototype.error,"error"),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(mr.prototype,Symbol.toStringTag,{value:"ReadableStreamDefaultController",configurable:!0});class Wr{constructor(e={},t={}){void 0===e?e=null:N(e,"First parameter");const r=vt(t,"Second parameter"),n=function(e,t){D(e,t);const r=e,n=null==r?void 0:r.autoAllocateChunkSize,o=null==r?void 0:r.cancel,i=null==r?void 0:r.pull,a=null==r?void 0:r.start,s=null==r?void 0:r.type;return{autoAllocateChunkSize:void 0===n?void 0:Q(n,`${t} has member 'autoAllocateChunkSize' that`),cancel:void 0===o?void 0:Er(o,r,`${t} has member 'cancel' that`),pull:void 0===i?void 0:Cr(i,r,`${t} has member 'pull' that`),start:void 0===a?void 0:xr(a,r,`${t} has member 'start' that`),type:void 0===s?void 0:Ar(s,`${t} has member 'type' that`)}}(e,"First parameter");if(Mr(this),"bytes"===n.type){if(void 0!==r.size)throw new RangeError("The strategy for a byte stream cannot have a size function");!function(e,t,r){const n=Object.create(Ce.prototype);let o,i,a;o=void 0!==t.start?()=>t.start(n):()=>{},i=void 0!==t.pull?()=>t.pull(n):()=>b(void 0),a=void 0!==t.cancel?e=>t.cancel(e):()=>b(void 0);const s=t.autoAllocateChunkSize;if(0===s)throw new TypeError("autoAllocateChunkSize must be greater than 0");nt(e,n,o,i,a,r,s)}(this,n,yt(r,0))}else{const e=mt(r);!function(e,t,r,n){const o=Object.create(mr.prototype);let i,a,s;i=void 0!==t.start?()=>t.start(o):()=>{},a=void 0!==t.pull?()=>t.pull(o):()=>b(void 0),s=void 0!==t.cancel?e=>t.cancel(e):()=>b(void 0),jr(e,o,i,a,s,r,n)}(this,n,yt(r,1),e)}}get locked(){if(!Lr(this))throw Nr("locked");return zr(this)}cancel(e=void 0){return Lr(this)?zr(this)?y(new TypeError("Cannot cancel a stream that already has a reader")):Fr(this,e):y(Nr("cancel"))}getReader(e=void 0){if(!Lr(this))throw Nr("getReader");return void 0===function(e,t){D(e,t);const r=null==e?void 0:e.mode;return{mode:void 0===r?void 0:at(r,`${t} has member 'mode' that`)}}(e,"First parameter").mode?X(this):st(this)}pipeThrough(e,t={}){if(!Lr(this))throw Nr("pipeThrough");G(e,1,"pipeThrough");const r=function(e,t){D(e,t);const r=null==e?void 0:e.readable;H(r,"readable","ReadableWritablePair"),V(r,`${t} has member 'readable' that`);const n=null==e?void 0:e.writable;return H(n,"writable","ReadableWritablePair"),Tt(n,`${t} has member 'writable' that`),{readable:r,writable:n}}(e,"First parameter"),n=Ir(t,"Second parameter");if(zr(this))throw new TypeError("ReadableStream.prototype.pipeThrough cannot be used on a locked ReadableStream");if(Et(r.writable))throw new TypeError("ReadableStream.prototype.pipeThrough cannot be used on a locked WritableStream");return S(yr(this,r.writable,n.preventClose,n.preventAbort,n.preventCancel,n.signal)),r.readable}pipeTo(e,t={}){if(!Lr(this))return y(Nr("pipeTo"));if(void 0===e)return y("Parameter 1 is required in 'pipeTo'.");if(!kt(e))return y(new TypeError("ReadableStream.prototype.pipeTo's first argument must be a WritableStream"));let r;try{r=Ir(t,"Second parameter")}catch(e){return y(e)}return zr(this)?y(new TypeError("ReadableStream.prototype.pipeTo cannot be used on a locked ReadableStream")):Et(e)?y(new TypeError("ReadableStream.prototype.pipeTo cannot be used on a locked WritableStream")):yr(this,e,r.preventClose,r.preventAbort,r.preventCancel,r.signal)}tee(){if(!Lr(this))throw Nr("tee");return ce(function(e){return xe(e._readableStreamController)?function(e){let t,r,n,o,i,a=X(e),s=!1,u=!1,l=!1,c=!1,f=!1;const d=p((e=>{i=e}));function h(e){g(e._closedPromise,(t=>(e!==a||(Xe(n._readableStreamController,t),Xe(o._readableStreamController,t),c&&f||i(void 0)),null)))}function y(){dt(a)&&(I(a),a=X(e),h(a)),oe(a,{_chunkSteps:t=>{R((()=>{u=!1,l=!1;const r=t;let a=t;if(!c&&!f)try{a=Pe(t)}catch(t){return Xe(n._readableStreamController,t),Xe(o._readableStreamController,t),void i(Fr(e,t))}c||Ve(n._readableStreamController,r),f||Ve(o._readableStreamController,a),s=!1,u?v():l&&_()}))},_closeSteps:()=>{s=!1,c||Qe(n._readableStreamController),f||Qe(o._readableStreamController),n._readableStreamController._pendingPullIntos.length>0&&tt(n._readableStreamController,0),o._readableStreamController._pendingPullIntos.length>0&&tt(o._readableStreamController,0),c&&f||i(void 0)},_errorSteps:()=>{s=!1}})}function m(t,r){ne(a)&&(I(a),a=st(e),h(a));const d=r?o:n,p=r?n:o;ht(a,t,1,{_chunkSteps:t=>{R((()=>{u=!1,l=!1;const n=r?f:c;if(r?c:f)n||rt(d._readableStreamController,t);else{let r;try{r=Pe(t)}catch(t){return Xe(d._readableStreamController,t),Xe(p._readableStreamController,t),void i(Fr(e,t))}n||rt(d._readableStreamController,t),Ve(p._readableStreamController,r)}s=!1,u?v():l&&_()}))},_closeSteps:e=>{s=!1;const t=r?f:c,n=r?c:f;t||Qe(d._readableStreamController),n||Qe(p._readableStreamController),void 0!==e&&(t||rt(d._readableStreamController,e),!n&&p._readableStreamController._pendingPullIntos.length>0&&tt(p._readableStreamController,0)),t&&n||i(void 0)},_errorSteps:()=>{s=!1}})}function v(){if(s)return u=!0,b(void 0);s=!0;const e=Ze(n._readableStreamController);return null===e?y():m(e._view,!1),b(void 0)}function _(){if(s)return l=!0,b(void 0);s=!0;const e=Ze(o._readableStreamController);return null===e?y():m(e._view,!0),b(void 0)}function w(){}return n=Br(w,v,(function(n){if(c=!0,t=n,f){const n=ce([t,r]),o=Fr(e,n);i(o)}return d})),o=Br(w,_,(function(n){if(f=!0,r=n,c){const n=ce([t,r]),o=Fr(e,n);i(o)}return d})),h(a),[n,o]}(e):function(e){const t=X(e);let r,n,o,i,a,s=!1,u=!1,l=!1,c=!1;const f=p((e=>{a=e}));function d(){return s?(u=!0,b(void 0)):(s=!0,oe(t,{_chunkSteps:e=>{R((()=>{u=!1;const t=e,r=e;l||Rr(o._readableStreamController,t),c||Rr(i._readableStreamController,r),s=!1,u&&d()}))},_closeSteps:()=>{s=!1,l||Sr(o._readableStreamController),c||Sr(i._readableStreamController),l&&c||a(void 0)},_errorSteps:()=>{s=!1}}),b(void 0))}function h(){}return o=Ur(h,d,(function(t){if(l=!0,r=t,c){const t=ce([r,n]),o=Fr(e,t);a(o)}return f})),i=Ur(h,d,(function(t){if(c=!0,n=t,l){const t=ce([r,n]),o=Fr(e,t);a(o)}return f})),g(t._closedPromise,(e=>(Tr(o._readableStreamController,e),Tr(i._readableStreamController,e),l&&c||a(void 0),null))),[o,i]}(e)}(this))}values(e=void 0){if(!Lr(this))throw Nr("values");return function(e,t){const r=X(e),n=new ge(r,t),o=Object.create(we);return o._asyncIteratorImpl=n,o}(this,function(e){D(e,"First parameter");const t=null==e?void 0:e.preventCancel;return{preventCancel:Boolean(t)}}(e).preventCancel)}[me](e){return this.values(e)}static from(e){return kr(e)}}function Ur(e,t,r,n=1,o=()=>1){const i=Object.create(Wr.prototype);return Mr(i),jr(i,Object.create(mr.prototype),e,t,r,n,o),i}function Br(e,t,r){const n=Object.create(Wr.prototype);return Mr(n),nt(n,Object.create(Ce.prototype),e,t,r,0,void 0),n}function Mr(e){e._state="readable",e._reader=void 0,e._storedError=void 0,e._disturbed=!1}function Lr(e){return!!a(e)&&!!Object.prototype.hasOwnProperty.call(e,"_readableStreamController")&&e instanceof Wr}function zr(e){return void 0!==e._reader}function Fr(e,t){if(e._disturbed=!0,"closed"===e._state)return b(void 0);if("errored"===e._state)return y(e._storedError);Dr(e);const r=e._reader;if(void 0!==r&&dt(r)){const e=r._readIntoRequests;r._readIntoRequests=new O,e.forEach((e=>{e._closeSteps(void 0)}))}return w(e._readableStreamController[k](t),i)}function Dr(e){e._state="closed";const t=e._reader;if(void 0!==t&&(L(t),ne(t))){const e=t._readRequests;t._readRequests=new O,e.forEach((e=>{e._closeSteps()}))}}function $r(e,t){e._state="errored",e._storedError=t;const r=e._reader;void 0!==r&&(M(r,t),ne(r)?ie(r,t):pt(r,t))}function Nr(e){return new TypeError(`ReadableStream.prototype.${e} can only be used on a ReadableStream`)}function Gr(e,t){D(e,t);const r=null==e?void 0:e.highWaterMark;return H(r,"highWaterMark","QueuingStrategyInit"),{highWaterMark:Y(r)}}Object.defineProperties(Wr,{from:{enumerable:!0}}),Object.defineProperties(Wr.prototype,{cancel:{enumerable:!0},getReader:{enumerable:!0},pipeThrough:{enumerable:!0},pipeTo:{enumerable:!0},tee:{enumerable:!0},values:{enumerable:!0},locked:{enumerable:!0}}),u(Wr.from,"from"),u(Wr.prototype.cancel,"cancel"),u(Wr.prototype.getReader,"getReader"),u(Wr.prototype.pipeThrough,"pipeThrough"),u(Wr.prototype.pipeTo,"pipeTo"),u(Wr.prototype.tee,"tee"),u(Wr.prototype.values,"values"),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(Wr.prototype,Symbol.toStringTag,{value:"ReadableStream",configurable:!0}),Object.defineProperty(Wr.prototype,me,{value:Wr.prototype.values,writable:!0,configurable:!0});const Hr=e=>e.byteLength;u(Hr,"size");class Yr{constructor(e){G(e,1,"ByteLengthQueuingStrategy"),e=Gr(e,"First parameter"),this._byteLengthQueuingStrategyHighWaterMark=e.highWaterMark}get highWaterMark(){if(!Qr(this))throw Jr("highWaterMark");return this._byteLengthQueuingStrategyHighWaterMark}get size(){if(!Qr(this))throw Jr("size");return Hr}}function Jr(e){return new TypeError(`ByteLengthQueuingStrategy.prototype.${e} can only be used on a ByteLengthQueuingStrategy`)}function Qr(e){return!!a(e)&&!!Object.prototype.hasOwnProperty.call(e,"_byteLengthQueuingStrategyHighWaterMark")&&e instanceof Yr}Object.defineProperties(Yr.prototype,{highWaterMark:{enumerable:!0},size:{enumerable:!0}}),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(Yr.prototype,Symbol.toStringTag,{value:"ByteLengthQueuingStrategy",configurable:!0});const Vr=()=>1;u(Vr,"size");class Xr{constructor(e){G(e,1,"CountQueuingStrategy"),e=Gr(e,"First parameter"),this._countQueuingStrategyHighWaterMark=e.highWaterMark}get highWaterMark(){if(!Zr(this))throw Kr("highWaterMark");return this._countQueuingStrategyHighWaterMark}get size(){if(!Zr(this))throw Kr("size");return Vr}}function Kr(e){return new TypeError(`CountQueuingStrategy.prototype.${e} can only be used on a CountQueuingStrategy`)}function Zr(e){return!!a(e)&&!!Object.prototype.hasOwnProperty.call(e,"_countQueuingStrategyHighWaterMark")&&e instanceof Xr}function en(e,t,r){return $(e,r),r=>P(e,t,[r])}function tn(e,t,r){return $(e,r),r=>T(e,t,[r])}function rn(e,t,r){return $(e,r),(r,n)=>P(e,t,[r,n])}function nn(e,t,r){return $(e,r),r=>P(e,t,[r])}Object.defineProperties(Xr.prototype,{highWaterMark:{enumerable:!0},size:{enumerable:!0}}),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(Xr.prototype,Symbol.toStringTag,{value:"CountQueuingStrategy",configurable:!0});class on{constructor(e={},t={},r={}){void 0===e&&(e=null);const n=vt(t,"Second parameter"),o=vt(r,"Third parameter"),i=function(e,t){D(e,t);const r=null==e?void 0:e.cancel,n=null==e?void 0:e.flush,o=null==e?void 0:e.readableType,i=null==e?void 0:e.start,a=null==e?void 0:e.transform,s=null==e?void 0:e.writableType;return{cancel:void 0===r?void 0:nn(r,e,`${t} has member 'cancel' that`),flush:void 0===n?void 0:en(n,e,`${t} has member 'flush' that`),readableType:o,start:void 0===i?void 0:tn(i,e,`${t} has member 'start' that`),transform:void 0===a?void 0:rn(a,e,`${t} has member 'transform' that`),writableType:s}}(e,"First parameter");if(void 0!==i.readableType)throw new RangeError("Invalid readableType specified");if(void 0!==i.writableType)throw new RangeError("Invalid writableType specified");const a=yt(o,0),s=mt(o),u=yt(n,1),l=mt(n);let c;!function(e,t,r,n,o,i){function a(){return t}e._writable=function(e,t,r,n,o=1,i=()=>1){const a=Object.create(Ot.prototype);return qt(a),Jt(a,Object.create(Ht.prototype),e,t,r,n,o,i),a}(a,(function(t){return function(e,t){const r=e._transformStreamController;return e._backpressure?w(e._backpressureChangePromise,(()=>{const n=e._writable;if("erroring"===n._state)throw n._storedError;return bn(r,t)})):bn(r,t)}(e,t)}),(function(){return function(e){const t=e._transformStreamController;if(void 0!==t._finishPromise)return t._finishPromise;const r=e._readable;t._finishPromise=p(((e,r)=>{t._finishPromise_resolve=e,t._finishPromise_reject=r}));const n=t._flushAlgorithm();return hn(t),v(n,(()=>("errored"===r._state?vn(t,r._storedError):(Sr(r._readableStreamController),mn(t)),null)),(e=>(Tr(r._readableStreamController,e),vn(t,e),null))),t._finishPromise}(e)}),(function(t){return function(e,t){const r=e._transformStreamController;if(void 0!==r._finishPromise)return r._finishPromise;const n=e._readable;r._finishPromise=p(((e,t)=>{r._finishPromise_resolve=e,r._finishPromise_reject=t}));const o=r._cancelAlgorithm(t);return hn(r),v(o,(()=>("errored"===n._state?vn(r,n._storedError):(Tr(n._readableStreamController,t),mn(r)),null)),(e=>(Tr(n._readableStreamController,e),vn(r,e),null))),r._finishPromise}(e,t)}),r,n),e._readable=Ur(a,(function(){return function(e){return cn(e,!1),e._backpressureChangePromise}(e)}),(function(t){return function(e,t){const r=e._transformStreamController;if(void 0!==r._finishPromise)return r._finishPromise;const n=e._writable;r._finishPromise=p(((e,t)=>{r._finishPromise_resolve=e,r._finishPromise_reject=t}));const o=r._cancelAlgorithm(t);return hn(r),v(o,(()=>("errored"===n._state?vn(r,n._storedError):(Kt(n._writableStreamController,t),ln(e),mn(r)),null)),(t=>(Kt(n._writableStreamController,t),ln(e),vn(r,t),null))),r._finishPromise}(e,t)}),o,i),e._backpressure=void 0,e._backpressureChangePromise=void 0,e._backpressureChangePromise_resolve=void 0,cn(e,!0),e._transformStreamController=void 0}(this,p((e=>{c=e})),u,l,a,s),function(e,t){const r=Object.create(fn.prototype);let n,o,i;n=void 0!==t.transform?e=>t.transform(e,r):e=>{try{return pn(r,e),b(void 0)}catch(e){return y(e)}},o=void 0!==t.flush?()=>t.flush(r):()=>b(void 0),i=void 0!==t.cancel?e=>t.cancel(e):()=>b(void 0),function(e,t,r,n,o){t._controlledTransformStream=e,e._transformStreamController=t,t._transformAlgorithm=r,t._flushAlgorithm=n,t._cancelAlgorithm=o,t._finishPromise=void 0,t._finishPromise_resolve=void 0,t._finishPromise_reject=void 0}(e,r,n,o,i)}(this,i),void 0!==i.start?c(i.start(this._transformStreamController)):c(void 0)}get readable(){if(!an(this))throw _n("readable");return this._readable}get writable(){if(!an(this))throw _n("writable");return this._writable}}function an(e){return!!a(e)&&!!Object.prototype.hasOwnProperty.call(e,"_transformStreamController")&&e instanceof on}function sn(e,t){Tr(e._readable._readableStreamController,t),un(e,t)}function un(e,t){hn(e._transformStreamController),Kt(e._writable._writableStreamController,t),ln(e)}function ln(e){e._backpressure&&cn(e,!1)}function cn(e,t){void 0!==e._backpressureChangePromise&&e._backpressureChangePromise_resolve(),e._backpressureChangePromise=p((t=>{e._backpressureChangePromise_resolve=t})),e._backpressure=t}Object.defineProperties(on.prototype,{readable:{enumerable:!0},writable:{enumerable:!0}}),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(on.prototype,Symbol.toStringTag,{value:"TransformStream",configurable:!0});class fn{constructor(){throw new TypeError("Illegal constructor")}get desiredSize(){if(!dn(this))throw yn("desiredSize");return Pr(this._controlledTransformStream._readable._readableStreamController)}enqueue(e=void 0){if(!dn(this))throw yn("enqueue");pn(this,e)}error(e=void 0){if(!dn(this))throw yn("error");var t;t=e,sn(this._controlledTransformStream,t)}terminate(){if(!dn(this))throw yn("terminate");!function(e){const t=e._controlledTransformStream;Sr(t._readable._readableStreamController),un(t,new TypeError("TransformStream terminated"))}(this)}}function dn(e){return!!a(e)&&!!Object.prototype.hasOwnProperty.call(e,"_controlledTransformStream")&&e instanceof fn}function hn(e){e._transformAlgorithm=void 0,e._flushAlgorithm=void 0,e._cancelAlgorithm=void 0}function pn(e,t){const r=e._controlledTransformStream,n=r._readable._readableStreamController;if(!Or(n))throw new TypeError("Readable side is not in a state that permits enqueue");try{Rr(n,t)}catch(e){throw un(r,e),r._readable._storedError}const o=function(e){return!gr(e)}(n);o!==r._backpressure&&cn(r,!0)}function bn(e,t){return w(e._transformAlgorithm(t),void 0,(t=>{throw sn(e._controlledTransformStream,t),t}))}function yn(e){return new TypeError(`TransformStreamDefaultController.prototype.${e} can only be used on a TransformStreamDefaultController`)}function mn(e){void 0!==e._finishPromise_resolve&&(e._finishPromise_resolve(),e._finishPromise_resolve=void 0,e._finishPromise_reject=void 0)}function vn(e,t){void 0!==e._finishPromise_reject&&(S(e._finishPromise),e._finishPromise_reject(t),e._finishPromise_resolve=void 0,e._finishPromise_reject=void 0)}function _n(e){return new TypeError(`TransformStream.prototype.${e} can only be used on a TransformStream`)}Object.defineProperties(fn.prototype,{enqueue:{enumerable:!0},error:{enumerable:!0},terminate:{enumerable:!0},desiredSize:{enumerable:!0}}),u(fn.prototype.enqueue,"enqueue"),u(fn.prototype.error,"error"),u(fn.prototype.terminate,"terminate"),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(fn.prototype,Symbol.toStringTag,{value:"TransformStreamDefaultController",configurable:!0});var gn=function(e,t){return gn=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])},gn(e,t)};function wn(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function r(){this.constructor=e}gn(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}function Sn(e){if(!e)throw new TypeError("Assertion failed")}function Rn(){}function Tn(e){return!!function(e){return"object"==typeof e&&null!==e||"function"==typeof e}(e)&&"function"==typeof e.getReader}function Pn(e){try{return e.getReader({mode:"byob"}).releaseLock(),!0}catch(e){return!1}}function On(e,t){var r=(void 0===t?{}:t).type;return Sn(Tn(e)),Sn(!1===e.locked),"bytes"===(r=jn(r))?new Cn(e):new kn(e)}function jn(e){var t=String(e);if("bytes"===t)return t;if(void 0===e)return e;throw new RangeError("Invalid type is specified")}var qn=function(){function e(e){this._underlyingReader=void 0,this._readerMode=void 0,this._readableStreamController=void 0,this._pendingRead=void 0,this._underlyingStream=e,this._attachDefaultReader()}return e.prototype.start=function(e){this._readableStreamController=e},e.prototype.cancel=function(e){return Sn(void 0!==this._underlyingReader),this._underlyingReader.cancel(e)},e.prototype._attachDefaultReader=function(){if("default"!==this._readerMode){this._detachReader();var e=this._underlyingStream.getReader();this._readerMode="default",this._attachReader(e)}},e.prototype._attachReader=function(e){var t=this;Sn(void 0===this._underlyingReader),this._underlyingReader=e;var r=this._underlyingReader.closed;r&&r.then((function(){return t._finishPendingRead()})).then((function(){e===t._underlyingReader&&t._readableStreamController.close()}),(function(r){e===t._underlyingReader&&t._readableStreamController.error(r)})).catch(Rn)},e.prototype._detachReader=function(){void 0!==this._underlyingReader&&(this._underlyingReader.releaseLock(),this._underlyingReader=void 0,this._readerMode=void 0)},e.prototype._pullWithDefaultReader=function(){var e=this;this._attachDefaultReader();var t=this._underlyingReader.read().then((function(t){var r=e._readableStreamController;t.done?e._tryClose():r.enqueue(t.value)}));return this._setPendingRead(t),t},e.prototype._tryClose=function(){try{this._readableStreamController.close()}catch(e){}},e.prototype._setPendingRead=function(e){var t,r=this,n=function(){r._pendingRead===t&&(r._pendingRead=void 0)};this._pendingRead=t=e.then(n,n)},e.prototype._finishPendingRead=function(){var e=this;if(this._pendingRead){var t=function(){return e._finishPendingRead()};return this._pendingRead.then(t,t)}},e}(),kn=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return wn(t,e),t.prototype.pull=function(){return this._pullWithDefaultReader()},t}(qn);function En(e){return new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}var Cn=function(e){function t(t){var r=this,n=Pn(t);return(r=e.call(this,t)||this)._supportsByob=n,r}return wn(t,e),Object.defineProperty(t.prototype,"type",{get:function(){return"bytes"},enumerable:!1,configurable:!0}),t.prototype._attachByobReader=function(){if("byob"!==this._readerMode){Sn(this._supportsByob),this._detachReader();var e=this._underlyingStream.getReader({mode:"byob"});this._readerMode="byob",this._attachReader(e)}},t.prototype.pull=function(){if(this._supportsByob){var e=this._readableStreamController.byobRequest;if(e)return this._pullWithByobRequest(e)}return this._pullWithDefaultReader()},t.prototype._pullWithByobRequest=function(e){var t=this;this._attachByobReader();var r=new Uint8Array(e.view.byteLength),n=this._underlyingReader.read(r).then((function(r){t._readableStreamController,r.done?(t._tryClose(),e.respond(0)):(function(e,t){var r=En(e);En(t).set(r,0)}(r.value,e.view),e.respond(r.value.byteLength))}));return this._setPendingRead(n),n},t}(qn);!function(){function e(e){var t=this;this._writableStreamController=void 0,this._pendingWrite=void 0,this._state="writable",this._storedError=void 0,this._underlyingWriter=e,this._errorPromise=new Promise((function(e,r){t._errorPromiseReject=r})),this._errorPromise.catch(Rn)}e.prototype.start=function(e){var t=this;this._writableStreamController=e,this._underlyingWriter.closed.then((function(){t._state="closed"})).catch((function(e){return t._finishErroring(e)}))},e.prototype.write=function(e){var t=this,r=this._underlyingWriter;if(null===r.desiredSize)return r.ready;var n=r.write(e);n.catch((function(e){return t._finishErroring(e)})),r.ready.catch((function(e){return t._startErroring(e)}));var o=Promise.race([n,this._errorPromise]);return this._setPendingWrite(o),o},e.prototype.close=function(){var e=this;return void 0===this._pendingWrite?this._underlyingWriter.close():this._finishPendingWrite().then((function(){return e.close()}))},e.prototype.abort=function(e){if("errored"!==this._state)return this._underlyingWriter.abort(e)},e.prototype._setPendingWrite=function(e){var t,r=this,n=function(){r._pendingWrite===t&&(r._pendingWrite=void 0)};this._pendingWrite=t=e.then(n,n)},e.prototype._finishPendingWrite=function(){var e=this;if(void 0===this._pendingWrite)return Promise.resolve();var t=function(){return e._finishPendingWrite()};return this._pendingWrite.then(t,t)},e.prototype._startErroring=function(e){var t=this;if("writable"===this._state){this._state="erroring",this._storedError=e;var r=function(){return t._finishErroring(e)};void 0===this._pendingWrite?r():this._finishPendingWrite().then(r,r),this._writableStreamController.error(e)}},e.prototype._finishErroring=function(e){"writable"===this._state&&this._startErroring(e),"erroring"===this._state&&(this._state="errored",this._errorPromiseReject(this._storedError))}}(),function(){function e(e,t){var r=this;this._transformStreamController=void 0,this._onRead=function(e){if(!e.done)return r._transformStreamController.enqueue(e.value),r._reader.read().then(r._onRead)},this._onError=function(e){r._flushReject(e),r._transformStreamController.error(e),r._reader.cancel(e).catch(Rn),r._writer.abort(e).catch(Rn)},this._onTerminate=function(){r._flushResolve(),r._transformStreamController.terminate();var e=new TypeError("TransformStream terminated");r._writer.abort(e).catch(Rn)},this._reader=e,this._writer=t,this._flushPromise=new Promise((function(e,t){r._flushResolve=e,r._flushReject=t}))}e.prototype.start=function(e){this._transformStreamController=e,this._reader.read().then(this._onRead).then(this._onTerminate,this._onError);var t=this._reader.closed;t&&t.then(this._onTerminate,this._onError)},e.prototype.transform=function(e){return this._writer.write(e)},e.prototype.flush=function(){var e=this;return this._writer.close().then((function(){return e._flushPromise}))}}();var xn=[239,187,191],An=r(877),In=function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))},Wn=function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],n=0}finally{r=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}},Un=function(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t,r=e[Symbol.asyncIterator];return r?r.call(e):(e="function"==typeof __values?__values(e):e[Symbol.iterator](),t={},n("next"),n("throw"),n("return"),t[Symbol.asyncIterator]=function(){return this},t);function n(r){t[r]=e[r]&&function(t){return new Promise((function(n,o){!function(e,t,r,n){Promise.resolve(n).then((function(t){e({value:t,done:r})}),t)}(n,o,(t=e[r](t)).done,t.value)}))}}},Bn=Wr,Mn=on,Ln=function(){var e;return new Mn({start:function(t){e=function(e){var t,r,n,o,i,a,s;return u(),{feed:function(e){r=r?r+e:e,t&&function(e){return xn.every((function(t,r){return e.charCodeAt(r)===t}))}(r)&&(r=r.slice(xn.length)),t=!1;for(var i=r.length,a=0,s=!1;a<i;){s&&("\n"===r[a]&&(a+=1),s=!1);for(var u=-1,c=o,f=void 0,d=n;u<0&&d<i;d++)":"===(f=r[d])&&c<0?c=d-a:"\r"===f?(s=!0,u=d-a):"\n"===f&&(u=d-a);if(u<0){n=i-a,o=c;break}n=0,o=-1,l(r,a,c,u),a+=u+1}a===i?r="":a>0&&(r=r.slice(a))},reset:u};function u(){t=!0,r="",n=0,o=-1,i=void 0,a=void 0,s=""}function l(t,r,n,o){if(0===o)return s.length>0&&(e({type:"event",id:i,event:a||void 0,data:s.slice(0,-1)}),s="",i=void 0),void(a=void 0);var u,l=n<0,c=t.slice(r,r+(l?o:n)),f=r+(u=l?o:" "===t[r+n+1]?n+2:n+1),d=o-u,h=t.slice(f,f+d).toString();if("data"===c)s+=h?"".concat(h,"\n"):"\n";else if("event"===c)a=h;else if("id"!==c||h.includes("\0")){if("retry"===c){var p=parseInt(h,10);Number.isNaN(p)||e({type:"reconnect-interval",value:p})}}else i=h}}((function(e){"event"===e.type&&t.enqueue(e)}))},transform:function(t){e.feed(t)}})},zn=function(e){Sn(function(e){return!!function(e){if("function"!=typeof e)return!1;var t=!1;try{new e({start:function(){t=!0}})}catch(e){}return t}(e)&&!!Tn(new e)}(e));var t=function(e){try{return new e({type:"bytes"}),!0}catch(e){return!1}}(e);return function(r,n){var o=(void 0===n?{}:n).type;if("bytes"!==(o=jn(o))||t||(o=void 0),r.constructor===e&&("bytes"!==o||Pn(r)))return r;if("bytes"===o){var i=On(r,{type:o});return new e(i)}return i=On(r),new e(i)}}(Bn),Fn=function(){function e(e,t){void 0===e&&(e="utf-8"),void 0===t&&(t={});var r=this;this.transform=new Mn({transform:function(e,t){var n=r.handle.decode(new Uint8Array(e),{stream:!0});n&&t.enqueue(n)},flush:function(e){var t=r.handle.decode();t&&e.enqueue(t),e.terminate()}}),this.handle=new An.TextDecoder(e,t)}return Object.defineProperty(e.prototype,"encoding",{get:function(){return this.handle.encoding},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"fatal",{get:function(){return this.handle.fatal},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"ignoreBOM",{get:function(){return this.handle.ignoreBOM},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"readable",{get:function(){return this.transform.readable},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"writable",{get:function(){return this.transform.writable},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,Symbol.toStringTag,{get:function(){return"TextDecoderStream"},enumerable:!1,configurable:!0}),e}();function Dn(e){var t=e;return t[Symbol.asyncIterator]=function(){var t=e.getReader();return{next:function(){return In(this,void 0,void 0,(function(){var e,r,n;return Wn(this,(function(o){switch(o.label){case 0:return[4,t.read()];case 1:return e=o.sent(),r=e.done,n=e.value,[2,r?{done:!0,value:void 0}:{done:!1,value:n}]}}))}))}}},t}function $n(e){return Dn(e.pipeThrough(new Fn).pipeThrough(Ln()).pipeThrough(new Mn({transform:function(e,t){try{var r=JSON.parse(e.data);t.enqueue(r)}catch(r){"[DONE]"!==e.data?console.warn("Error when transforming event source data to json",r,e):t.terminate()}}})))}function Nn(e){return Dn(zn(e).pipeThrough(new Fn))}function Gn(e){var t,r,n,o;return In(this,void 0,void 0,(function(){var i,a,s,u,l,c;return Wn(this,(function(f){switch(f.label){case 0:i=Nn(e),a="",f.label=1;case 1:f.trys.push([1,6,7,12]),s=!0,u=Un(i),f.label=2;case 2:return[4,u.next()];case 3:if(l=f.sent(),t=l.done)return[3,5];o=l.value,s=!1;try{a+=o}finally{s=!0}f.label=4;case 4:return[3,2];case 5:return[3,12];case 6:return c=f.sent(),r={error:c},[3,12];case 7:return f.trys.push([7,,10,11]),s||t||!(n=u.return)?[3,9]:[4,n.call(u)];case 8:f.sent(),f.label=9;case 9:return[3,11];case 10:if(r)throw r.error;return[7];case 11:return[7];case 12:return[2,JSON.parse(a)]}}))}))}function Hn(){var e,t;return{promise:new Promise((function(r,n){e=r,t=n})),res:e,rej:t}}function Yn(e){var t;return"assistant"===e.role&&"tool_calls"in e&&null!=(null===(t=e.tool_calls)||void 0===t?void 0:t[0])}function Jn(e){return{type:"function",function:{description:e.description,name:e.name,parameters:e.parameters}}}var Qn=function(){return Qn=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},Qn.apply(this,arguments)},Vn=function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))},Xn=function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],n=0}finally{r=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}},Kn=function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(r[n[o]]=e[n[o]])}return r},Zn=function(){function e(e,t){this.baseUrl=t;var r=arguments[2];this.req="string"==typeof r?function(t){var n=t.headers,o=void 0===n?{}:n,i=Kn(t,["headers"]);return e(Qn(Qn({},i),{headers:Qn(Qn({},o),{Authorization:"Bearer ".concat(r)})}))}:e}return e.prototype.list=function(e,t){return this.req({method:"get",url:this.join("bots"),data:e,timeout:null==t?void 0:t.timeout})},e.prototype.create=function(e,t){var r=e.botInfo;return this.req({method:"post",url:this.join("bots"),data:r,timeout:null==t?void 0:t.timeout})},e.prototype.get=function(e,t){var r=e.botId;return this.req({method:"get",url:this.join("bots/".concat(r)),timeout:null==t?void 0:t.timeout})},e.prototype.update=function(e,t){var r=e.botId,n=e.botInfo;return this.req({method:"PATCH",url:this.join("bots/".concat(r)),data:n,timeout:null==t?void 0:t.timeout})},e.prototype.delete=function(e,t){var r=e.botId;return this.req({method:"delete",url:this.join("bots/".concat(r)),timeout:null==t?void 0:t.timeout})},e.prototype.getChatRecords=function(e,t){return this.req({method:"get",url:this.join("bots/".concat(e.botId,"/records")),data:e,timeout:null==t?void 0:t.timeout})},e.prototype.sendFeedback=function(e,t){var r=e.userFeedback;return this.req({method:"post",url:this.join("bots/".concat(r.botId,"/feedback")),data:r,timeout:null==t?void 0:t.timeout})},e.prototype.getFeedback=function(e,t){return this.req({method:"get",url:this.join("bots/".concat(e.botId,"/feedback")),data:e,timeout:null==t?void 0:t.timeout})},e.prototype.uploadFiles=function(e,t){return Vn(this,void 0,void 0,(function(){return Xn(this,(function(r){return[2,this.req({method:"post",url:this.join("bots/".concat(e.botId,"/files")),data:e,timeout:null==t?void 0:t.timeout})]}))}))},e.prototype.createConversation=function(e,t){var r=e.botId,n=Kn(e,["botId"]);return Vn(this,void 0,void 0,(function(){return Xn(this,(function(e){return[2,this.req({method:"post",url:this.join("bots/".concat(r,"/conversation")),data:n,timeout:null==t?void 0:t.timeout})]}))}))},e.prototype.getConversation=function(e,t){var r=e.pageSize,n=void 0===r?10:r,o=e.pageNumber,i=void 0===o?1:o,a=e.botId,s=Kn(e,["pageSize","pageNumber","botId"]);return Vn(this,void 0,void 0,(function(){var e,r;return Xn(this,(function(o){if(i<1)throw new Error("pageNumber must be greater than 0");return e=n*(i-1),r=n,[2,this.req({method:"get",url:this.join("bots/".concat(a,"/conversation")),data:Qn(Qn({},s),{offset:e,limit:r}),timeout:null==t?void 0:t.timeout})]}))}))},e.prototype.deleteConversation=function(e,t){var r=e.botId,n=e.conversationId,o=Kn(e,["botId","conversationId"]);return Vn(this,void 0,void 0,(function(){return Xn(this,(function(e){return[2,this.req({method:"delete",url:this.join("bots/".concat(r,"/conversation/").concat(n)),data:o,timeout:null==t?void 0:t.timeout})]}))}))},e.prototype.speechToText=function(e,t){return Vn(this,void 0,void 0,(function(){return Xn(this,(function(r){return[2,this.req({method:"post",url:this.join("bots/".concat(e.botId,"/speech-to-text")),data:e,timeout:null==t?void 0:t.timeout})]}))}))},e.prototype.textToSpeech=function(e,t){return Vn(this,void 0,void 0,(function(){return Xn(this,(function(r){return[2,this.req({method:"post",url:this.join("bots/".concat(e.botId,"/text-to-speech")),data:e,timeout:null==t?void 0:t.timeout})]}))}))},e.prototype.getTextToSpeechResult=function(e,t){return Vn(this,void 0,void 0,(function(){return Xn(this,(function(r){return[2,this.req({method:"get",url:this.join("bots/".concat(e.botId,"/text-to-speech")),data:e,timeout:null==t?void 0:t.timeout})]}))}))},e.prototype.getRecommendQuestions=function(e,t){return Vn(this,void 0,void 0,(function(){var r;return Xn(this,(function(n){switch(n.label){case 0:return[4,this.req({method:"post",url:this.join("bots/".concat(e.botId,"/recommend-questions")),data:e,stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return r=n.sent(),[2,new eo(r)]}}))}))},e.prototype.generateBot=function(e,t){return Vn(this,void 0,void 0,(function(){var r;return Xn(this,(function(n){switch(n.label){case 0:return[4,this.req({method:"post",url:this.join("generate-bot"),data:e,stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return r=n.sent(),[2,new eo(r)]}}))}))},e.prototype.getPreview=function(e,t){return Vn(this,void 0,void 0,(function(){var r;return Xn(this,(function(n){switch(n.label){case 0:return[4,this.req({method:"post",url:this.join("preview"),data:e,stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return r=n.sent(),[2,new eo(r)]}}))}))},e.prototype.generateImage=function(e,t){return this.req({method:"post",url:this.join("generate-image"),data:e,timeout:null==t?void 0:t.timeout})},e.prototype.sendMessage=function(e,t){return Vn(this,void 0,void 0,(function(){var r;return Xn(this,(function(n){switch(n.label){case 0:return[4,this.req({method:"post",url:this.join("bots/".concat(e.botId,"/send-message")),data:e,stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return r=n.sent(),[2,new eo(r)]}}))}))},e.prototype.join=function(e){return"".concat(this.baseUrl,"/").concat(e)},e}(),eo=function(){function e(e){var t=zn(e);this._eventSourceStream=t.pipeThrough(new Fn).pipeThrough(Ln())}return Object.defineProperty(e.prototype,"teeedStream",{get:function(){var e=this._eventSourceStream.tee(),t=e[0],r=e[1];return this._eventSourceStream=r,t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"eventSourceStream",{get:function(){return Dn(this.teeedStream)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"dataStream",{get:function(){return Dn(this.eventSourceStream.pipeThrough(new Mn({transform:function(e,t){try{var r=JSON.parse(e.data);t.enqueue(r)}catch(r){"[DONE]"!==e.data?console.warn("Error when transforming event source data to json",r,e):t.terminate()}}})))},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"textStream",{get:function(){return Dn(this.dataStream.pipeThrough(new Mn({transform:function(e,t){var r;t.enqueue(null!==(r=null==e?void 0:e.content)&&void 0!==r?r:"")}})))},enumerable:!1,configurable:!0}),e}(),to=function(){return to=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},to.apply(this,arguments)},ro=function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))},no=function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],n=0}finally{r=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}};function oo(e){var t=e.messages,r=e.model,n=e.temperature,o=e.tool_choice,i=e.tools,a=e.top_p;return to(to({},e),{messages:t,model:r,temperature:n,tool_choice:(o&&"auto"!==o&&console.warn("`tool_choice` is not 'auto'"),o),tools:i,top_p:a})}var io=function(){function e(e,t,r){this.req=e,this.baseUrl=t,this.subUrl="zhipu/api/paas/v4/chat/completions",null!=r&&(this.subUrl=r)}return Object.defineProperty(e.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),e.prototype.doGenerate=function(e,t){return ro(this,void 0,void 0,(function(){var r,n;return no(this,(function(o){switch(o.label){case 0:return r=oo(e),[4,this.req({url:this.url,data:to(to({},r),{stream:!1}),stream:!1,timeout:null==t?void 0:t.timeout})];case 1:return n=o.sent(),[2,to(to({},n),{rawResponse:n})]}}))}))},e.prototype.doStream=function(e,t){return ro(this,void 0,void 0,(function(){var r,n,o,i;return no(this,(function(a){switch(a.label){case 0:return r=oo(e),n=null,[4,this.req({url:this.url,data:to(to({},r),{stream:!0}),stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return o=a.sent(),i=zn(o),[2,Dn($n(i).pipeThrough(new Mn({transform:function(e,t){var r=e.choices.map((function(e){var t=e.delta;return null==n&&(n=Yn(t)),n?to(to({},e),{finish_reason:"tool_calls",delta:t}):e})),o=to(to({},e),{choices:r});t.enqueue(to(to({},o),{rawResponse:e}))}})))]}}))}))},e}(),ao=function(){return ao=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},ao.apply(this,arguments)};function so(e){var t=e.messages,r=e.model,n=e.temperature,o=e.tool_choice,i=e.tools,a=e.top_p;return ao(ao({},e),{messages:(t.forEach((function(e){"tool_calls"in e&&e.tool_calls.filter((function(e){return"function"!==e.type})).forEach((function(t){return console.warn("`type` in tool_call is not 'function'",t,e)}))})),t),model:r,tools:function(){if(i)return i.forEach((function(e){"function"!==e.type&&console.warn("`type` in tool is not 'function'",e)})),i}(),top_p:a,tool_choice:o,temperature:n})}function uo(e){return"object"!=typeof e||null==e?e:Array.isArray(e)?e.map((function(e){return uo(e)})):Object.entries(e).reduce((function(e,t){var r=t[0],n=t[1],o=function(e){var t=e.replace(/[A-Z]/g,(function(e){return"_".concat(e.toLowerCase())}));return"_"===t.charAt(0)?t.slice(1):t}(r);return e[o]="object"==typeof n?uo(n):n,e}),{})}var lo=function(){return lo=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},lo.apply(this,arguments)},co=function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))},fo=function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],n=0}finally{r=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}},ho=function(){function e(e,t,r){this.req=e,this.baseUrl=t,this.subUrl="hunyuan-beta/openapi/v1/chat/completions",null!=r&&(this.subUrl=r)}return Object.defineProperty(e.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),e.prototype.doGenerate=function(e,t){return co(this,void 0,void 0,(function(){var r;return fo(this,(function(n){switch(n.label){case 0:return[4,this.req({url:this.url,data:lo(lo({},so(e)),{stream:!1}),stream:!1,timeout:null==t?void 0:t.timeout})];case 1:return r=n.sent(),[2,lo(lo({},r),{rawResponse:r})]}}))}))},e.prototype.doStream=function(e,t){return co(this,void 0,void 0,(function(){var r,n,o;return fo(this,(function(i){switch(i.label){case 0:return r=null,[4,this.req({url:this.url,data:lo(lo({},so(e)),{stream:!0}),stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return n=i.sent(),o=zn(n),[2,Dn($n(o).pipeThrough(new Mn({transform:function(e,t){var n=e.choices.map((function(e){var t=e.delta;return null==r&&(r=Yn(t)),r?lo(lo({},e),{finish_reason:"tool_calls",delta:t}):e})),o=lo(lo({},e),{choices:n});t.enqueue(lo(lo({},o),{rawResponse:e}))}})))]}}))}))},e}(),po=function(){return po=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},po.apply(this,arguments)},bo=function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))},yo=function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],n=0}finally{r=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}},mo=function(){function e(e,t,r){this.req=e,this.baseUrl=t,this.subUrl="hunyuan",null!=r&&(this.subUrl=r)}return Object.defineProperty(e.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),e.prototype.doGenerate=function(e,t){return bo(this,void 0,void 0,(function(){var r,n;return yo(this,(function(o){switch(o.label){case 0:return[4,this.req({url:this.url,headers:{"X-Tc-Action":"ChatCompletions"},data:po(po({},so(e)),{stream:!1}),stream:!1,timeout:null==t?void 0:t.timeout})];case 1:return r=o.sent(),n=uo(r.Response),[2,po(po({},n),{rawResponse:r})]}}))}))},e.prototype.doStream=function(e,t){return bo(this,void 0,void 0,(function(){var r,n,o;return yo(this,(function(i){switch(i.label){case 0:return r=null,[4,this.req({url:this.url,headers:{"X-Tc-Action":"ChatCompletions"},data:po(po({},e),{stream:!0}),stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return n=i.sent(),o=zn(n),[2,Dn($n(o).pipeThrough(new Mn({transform:function(e,t){var n=uo(e),o=n.choices.map((function(e){var t=e.delta;return null==r&&(r=Yn(t)),r?po(po({},e),{finish_reason:"tool_calls",delta:t}):e})),i=po(po({},n),{choices:o});t.enqueue(po(po({},i),{rawResponse:e}))}})))]}}))}))},e}(),vo=function(){return vo=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},vo.apply(this,arguments)},_o=function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))},go=function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],n=0}finally{r=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}};function wo(e){var t=e.messages,r=e.model,n=e.temperature,o=e.tools,i=e.top_p;return vo(vo({},e),{messages:t,model:r,tools:o,top_p:i,temperature:n})}var So=function(){function e(e,t,r){this.req=e,this.baseUrl=t,this.subUrl="ark/api/v3/chat/completions",null!=r&&(this.subUrl=r)}return Object.defineProperty(e.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),e.prototype.doGenerate=function(e,t){return _o(this,void 0,void 0,(function(){var r;return go(this,(function(n){switch(n.label){case 0:return[4,this.req({url:this.url,data:vo(vo({},wo(e)),{stream:!1}),stream:!1,timeout:null==t?void 0:t.timeout})];case 1:return r=n.sent(),[2,vo(vo({},r),{rawResponse:r})]}}))}))},e.prototype.doStream=function(e,t){return _o(this,void 0,void 0,(function(){var r,n,o;return go(this,(function(i){switch(i.label){case 0:return r=null,[4,this.req({url:this.url,data:vo(vo({},wo(e)),{stream:!0}),stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return n=i.sent(),o=zn(n),[2,Dn($n(o).pipeThrough(new Mn({transform:function(e,t){var n=e.choices.map((function(e){var t=e.delta;return null==r&&(r=Yn(t)),r?vo(vo({},e),{finish_reason:"tool_calls",delta:t}):e})),o=vo(vo({},e),{choices:n});t.enqueue(vo(vo({},o),{rawResponse:e}))}})))]}}))}))},e}(),Ro=function(){return Ro=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},Ro.apply(this,arguments)},To=function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))},Po=function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],n=0}finally{r=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}};function Oo(e){var t=e.messages,r=e.model,n=e.temperature,o=e.tools,i=e.top_p;return Ro(Ro({},e),{messages:t,model:r,tools:o,top_p:i,temperature:n})}var jo=function(){function e(e,t,r){this.req=e,this.baseUrl=t,this.subUrl="dashscope/compatible-mode/v1/chat/completions",null!=r&&(this.subUrl=r)}return Object.defineProperty(e.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),e.prototype.doGenerate=function(e,t){return To(this,void 0,void 0,(function(){var r;return Po(this,(function(n){switch(n.label){case 0:return[4,this.req({url:this.url,data:Ro(Ro({},Oo(e)),{stream:!1}),stream:!1,timeout:null==t?void 0:t.timeout})];case 1:return r=n.sent(),[2,Ro(Ro({},r),{rawResponse:r})]}}))}))},e.prototype.doStream=function(e,t){return To(this,void 0,void 0,(function(){var r,n,o;return Po(this,(function(i){switch(i.label){case 0:return r=null,[4,this.req({url:this.url,data:Ro(Ro({},Oo(e)),{stream:!0}),stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return n=i.sent(),o=zn(n),[2,Dn($n(o).pipeThrough(new Mn({transform:function(e,t){var n=e.choices.map((function(e){var t=Object.assign(e.delta,{role:"assistant"});return null==r&&(r=Yn(t)),Ro(Ro({},e),r?{finish_reason:"tool_calls",delta:t}:{delta:t})})),o=Ro(Ro({},e),{choices:n});t.enqueue(Ro(Ro({},o),{rawResponse:e}))}})))]}}))}))},e}(),qo=function(){return qo=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},qo.apply(this,arguments)},ko=function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))},Eo=function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],n=0}finally{r=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}};function Co(e){var t=e.messages,r=e.model,n=e.temperature,o=e.tools,i=e.top_p;return qo(qo({},e),{messages:t,model:r,tools:o,top_p:i,temperature:n})}var xo=function(){function e(e,t,r){this.req=e,this.baseUrl=t,this.subUrl="01-ai/v1/chat/completions",null!=r&&(this.subUrl=r)}return Object.defineProperty(e.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),e.prototype.doGenerate=function(e,t){return ko(this,void 0,void 0,(function(){var r;return Eo(this,(function(n){switch(n.label){case 0:return[4,this.req({url:this.url,data:qo(qo({},Co(e)),{stream:!1}),stream:!1,timeout:null==t?void 0:t.timeout})];case 1:return r=n.sent(),[2,qo(qo({},r),{rawResponse:r})]}}))}))},e.prototype.doStream=function(e,t){return ko(this,void 0,void 0,(function(){var r,n,o,i,a;return Eo(this,(function(s){switch(s.label){case 0:return r=null,[4,this.req({url:this.url,data:qo(qo({},Co(e)),{stream:!0}),stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return n=s.sent(),o=zn(n),i=$n(o),a=i.pipeThrough(new Mn({transform:function(e,t){var n,o,i,a,s,u;if((null===(i=null===(o=null===(n=null==e?void 0:e.choices)||void 0===n?void 0:n[0])||void 0===o?void 0:o.delta)||void 0===i?void 0:i.content)||(null===(u=null===(s=null===(a=null==e?void 0:e.choices)||void 0===a?void 0:a[0])||void 0===s?void 0:s.delta)||void 0===u?void 0:u.tool_calls)){var l=e.choices.map((function(e){var t=Object.assign(e.delta,{role:"assistant"});return null==r&&(r=Yn(t)),qo(qo({},e),r?{finish_reason:"tool_calls",delta:t}:{delta:t})})),c=qo(qo({},e),{choices:l});t.enqueue(qo(qo({},c),{rawResponse:e}))}}})),[2,Dn(a)]}}))}))},e}(),Ao=function(){return Ao=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},Ao.apply(this,arguments)},Io=function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))},Wo=function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],n=0}finally{r=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}};function Uo(e){var t=e.messages,r=e.model,n=e.temperature,o=e.tools,i=e.top_p;return Ao(Ao({},e),{messages:t,model:r,tools:o,top_p:i,temperature:n})}var Bo=function(){function e(e,t,r){this.req=e,this.baseUrl=t,this.subUrl="moonshot/v1/chat/completions",null!=r&&(this.subUrl=r)}return Object.defineProperty(e.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),e.prototype.doGenerate=function(e,t){return Io(this,void 0,void 0,(function(){var r;return Wo(this,(function(n){switch(n.label){case 0:return[4,this.req({url:this.url,data:Ao(Ao({},Uo(e)),{stream:!1}),stream:!1,timeout:null==t?void 0:t.timeout})];case 1:return r=n.sent(),[2,Ao(Ao({},r),{rawResponse:r})]}}))}))},e.prototype.doStream=function(e,t){return Io(this,void 0,void 0,(function(){var r,n,o;return Wo(this,(function(i){switch(i.label){case 0:return r=null,[4,this.req({url:this.url,data:Ao(Ao({},Uo(e)),{stream:!0}),stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return n=i.sent(),o=zn(n),[2,Dn($n(o).pipeThrough(new Mn({transform:function(e,t){var n=e.choices.map((function(e){var t=e.delta;return null==r&&(r=Yn(t)),r?Ao(Ao({},e),{finish_reason:"tool_calls",delta:t}):e})),o=Ao(Ao({},e),{choices:n});t.enqueue(Ao(Ao({},o),{rawResponse:e}))}})))]}}))}))},e}(),Mo=function(){return Mo=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},Mo.apply(this,arguments)},Lo=function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))},zo=function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],n=0}finally{r=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}},Fo=function(){function e(e,t,r){this.req=e,this.baseUrl=t,this.subUrl="hunyuan-exp/chat/completions",null!=r&&(this.subUrl=r)}return Object.defineProperty(e.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),e.prototype.doGenerate=function(e){return Lo(this,void 0,void 0,(function(){var t;return zo(this,(function(r){switch(r.label){case 0:return[4,this.req({url:this.url,data:Mo(Mo({},so(e)),{stream:!1}),stream:!1})];case 1:return t=r.sent(),[2,Mo(Mo({},t),{rawResponse:t})]}}))}))},e.prototype.doStream=function(e){return Lo(this,void 0,void 0,(function(){var t,r,n;return zo(this,(function(o){switch(o.label){case 0:return t=null,[4,this.req({url:this.url,data:Mo(Mo({},so(e)),{stream:!0}),stream:!0})];case 1:return r=o.sent(),n=zn(r),[2,Dn($n(n).pipeThrough(new Mn({transform:function(e,r){var n=e.choices.map((function(e){var r=e.delta;return null==t&&(t=Yn(r)),t?Mo(Mo({},e),{finish_reason:"tool_calls",delta:r}):e})),o=Mo(Mo({},e),{choices:n});r.enqueue(Mo(Mo({},o),{rawResponse:e}))}})))]}}))}))},e}(),Do=function(){return Do=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},Do.apply(this,arguments)},$o=function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))},No=function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],n=0}finally{r=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}},Go=function(){function e(e,t,r){this.req=e,this.baseUrl=t,this.subUrl="hunyuan-open/v1/chat/completions",null!=r&&(this.subUrl=r)}return Object.defineProperty(e.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),e.prototype.doGenerate=function(e,t){return $o(this,void 0,void 0,(function(){var r;return No(this,(function(n){switch(n.label){case 0:return[4,this.req({url:this.url,data:Do(Do({},so(e)),{stream:!1}),stream:!1,timeout:null==t?void 0:t.timeout})];case 1:return r=n.sent(),[2,Do(Do({},r),{rawResponse:r})]}}))}))},e.prototype.doStream=function(e,t){return $o(this,void 0,void 0,(function(){var r,n,o;return No(this,(function(i){switch(i.label){case 0:return r=null,[4,this.req({url:this.url,data:Do(Do({},so(e)),{stream:!0}),stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return n=i.sent(),o=zn(n),[2,Dn($n(o).pipeThrough(new Mn({transform:function(e,t){var n=e.choices.map((function(e){var t=e.delta;return null==r&&(r=Yn(t)),r?Do(Do({},e),{finish_reason:"tool_calls",delta:t}):e})),o=Do(Do({},e),{choices:n});t.enqueue(Do(Do({},o),{rawResponse:e}))}})))]}}))}))},e}(),Ho=function(){return Ho=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},Ho.apply(this,arguments)},Yo=function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))},Jo=function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],n=0}finally{r=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}},Qo=function(){function e(e,t,r){this.req=e,this.baseUrl=t,this.subUrl="deepseek/chat/completions",null!=r&&(this.subUrl=r)}return Object.defineProperty(e.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),e.prototype.doGenerate=function(e,t){return Yo(this,void 0,void 0,(function(){var r;return Jo(this,(function(n){switch(n.label){case 0:return[4,this.req({url:this.url,data:Ho(Ho({},e),{stream:!1}),stream:!1,timeout:null==t?void 0:t.timeout})];case 1:return r=n.sent(),[2,Ho(Ho({},r),{rawResponse:r})]}}))}))},e.prototype.doStream=function(e,t){return Yo(this,void 0,void 0,(function(){var r,n,o;return Jo(this,(function(i){switch(i.label){case 0:return r=null,[4,this.req({url:this.url,data:Ho(Ho({},e),{stream:!0}),stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return n=i.sent(),o=zn(n),[2,Dn($n(o).pipeThrough(new Mn({transform:function(e,t){var n=e.choices.map((function(e){var t=e.delta;return null==r&&(r=Yn(t)),r?Ho(Ho({},e),{finish_reason:"tool_calls",delta:t}):e})),o=Ho(Ho({},e),{choices:n});t.enqueue(Ho(Ho({},o),{rawResponse:e}))}})))]}}))}))},e}(),Vo=function(){return Vo=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},Vo.apply(this,arguments)},Xo=function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))},Ko=function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],n=0}finally{r=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}},Zo=function(){function e(e,t,r){void 0===r&&(r=""),this.req=e,this.baseUrl=t,this.subUrl=r}return Object.defineProperty(e.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),e.prototype.doGenerate=function(e){return Xo(this,void 0,void 0,(function(){var t;return Ko(this,(function(r){switch(r.label){case 0:return[4,this.req({url:this.url,data:Vo(Vo({},e),{stream:!1}),stream:!1})];case 1:return t=r.sent(),[2,Vo(Vo({},t),{rawResponse:t})]}}))}))},e.prototype.doStream=function(e){return Xo(this,void 0,void 0,(function(){var t,r,n;return Ko(this,(function(o){switch(o.label){case 0:return t=null,[4,this.req({url:this.url,data:Vo(Vo({},e),{stream:!0}),stream:!0})];case 1:return r=o.sent(),n=zn(r),[2,Dn($n(n).pipeThrough(new Mn({transform:function(e,r){var n=e.choices.map((function(e){var r=e.delta;return null==t&&(t=Yn(r)),t?Vo(Vo({},e),{finish_reason:"tool_calls",delta:r}):e})),o=Vo(Vo({},e),{choices:n});r.enqueue(Vo(Vo({},o),{rawResponse:e}))}})))]}}))}))},e}(),ei=function(){function e(e,t,r){this.req=e,this.baseUrl=t,this.provider=r,this.defaultGenerateImageSubUrl="images/generations",this.generateImageSubUrlConfig={"hunyuan-image":{"hunyuan-image-v3.0-v1.0.4":"images/ar/generations","hunyuan-image-v3.0-v1.0.1":"images/ar/generations"}},this.generateImage=this.generateImageImpl.bind(this)}return e.prototype.generateImageImpl=function(e){var t;return function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))}(this,void 0,void 0,(function(){var r,n;return function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],n=0}finally{r=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}}(this,(function(o){switch(o.label){case 0:return r=this.defaultGenerateImageSubUrl,"object"==typeof e&&e&&"model"in e&&"string"==typeof e.model&&(n=null===(t=this.generateImageSubUrlConfig[this.provider])||void 0===t?void 0:t[e.model])&&(r=n),[4,this.req({url:this.getGenerateUrl(r),data:e,stream:!1})];case 1:return[2,o.sent()]}}))}))},e.prototype.getGenerateUrl=function(e){return"".concat(this.baseUrl,"/").concat(this.provider,"/").concat(e)},e}(),ti=function(){return ti=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},ti.apply(this,arguments)},ri=function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))},ni=function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],n=0}finally{r=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}},oi=function(e,t,r){if(r||2===arguments.length)for(var n,o=0,i=t.length;o<i;o++)!n&&o in t||(n||(n=Array.prototype.slice.call(t,0,o)),n[o]=t[o]);return e.concat(n||Array.prototype.slice.call(t))};function ii(e){var t,r=e.onStepFinish,n=e.abortSignal,o=e.maxSteps,i=e.topP,a=e.toolChoice,s=function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(r[n[o]]=e[n[o]])}return r}(e,["onStepFinish","abortSignal","maxSteps","topP","toolChoice"]);if(null!=o&&o<1)throw new Error("`maxSteps` muse be greater than 0.");return[{onStepFinish:r,abortSignal:n,maxSteps:o},ti(ti({},s),{tools:null===(t=s.tools)||void 0===t?void 0:t.map((function(e){return"fn"in e?Jn(e):e})),top_p:null!=i?i:s.top_p,tool_choice:null!=a?a:s.tool_choice})]}var ai=function(){function e(e){this.model=e}return e.prototype.generateText=function(e,t){var r,n;return ri(this,void 0,void 0,(function(){var o,i,a,s,u,l,c,f,d,h,p,b,y,m,v,_,g,w,S,R,T,P=this;return ni(this,(function(O){switch(O.label){case 0:return o=[],i={completion_tokens:0,prompt_tokens:0,total_tokens:0},a=ii(e),s=a[0],u=s.onStepFinish,l=s.maxSteps,c=void 0===l?10:l,f=a[1],[4,(d=function(){return P.model.doGenerate(f,t)})()];case 1:h=O.sent(),p=1,h.rawResponse&&o.push(h.rawResponse),b=null,O.label=2;case 2:if(!(p<c&&null!=(b=si(h))))return[3,9];y=fi(h.usage),di(i,y),O.label=3;case 3:return O.trys.push([3,7,,8]),[4,ci(b)];case 4:return m=O.sent(),v=h.choices[0],[4,null==u?void 0:u({finishReason:v.finish_reason,messages:f.messages.slice(),text:v.message.content,toolCall:b,toolResult:m,stepUsage:y,totalUsage:Object.assign({},i)})];case 5:return O.sent(),ui(f.messages,v.message,m),[4,d()];case 6:return(h=O.sent()).rawResponse&&o.push(h.rawResponse),p+=1,[3,8];case 7:return _=O.sent(),[2,{text:"",messages:f.messages,usage:i,error:_,rawResponses:o}];case 8:return[3,2];case 9:return g=null===(r=null==h?void 0:h.choices)||void 0===r?void 0:r[0],w=null==g?void 0:g.message,S=null!==(n=null==w?void 0:w.content)&&void 0!==n?n:"",R=w?oi(oi([],f.messages,!0),[w],!1):f.messages,T=fi(h.usage),di(i,T),[4,null==u?void 0:u({finishReason:g.finish_reason,messages:R.slice(),text:S,toolCall:si(h),toolResult:null,stepUsage:T,totalUsage:Object.assign({},i)})];case 10:return O.sent(),[2,{text:S,messages:R,usage:i,rawResponses:o}]}}))}))},e.prototype.streamText=function(e,t){var r;return ri(this,void 0,void 0,(function(){var n,o,i,a,s,u,l,c,f,d,h,p,b,y,m,v,_,g,w,S,R,T,P,O,j,q,k,E,C,x,A,I,W,U,B,M,L=this;return ni(this,(function(z){switch(z.label){case 0:return n={completion_tokens:0,prompt_tokens:0,total_tokens:0},o=ii(e),i=o[0],a=i.onStepFinish,s=i.maxSteps,u=void 0===s?10:s,l=o[1],[4,(c=function(){return L.model.doStream(l,t)})()];case 1:f=z.sent(),d=1,h=null,p=function(){var e=f.tee(),t=e[0],r=e[1];return f=Dn(t),function(e){var t,r,n,o,i,a,s,u,l,c;return ri(this,void 0,void 0,(function(){var f,d,h,p,b,y,m,v,_,g,w,S,R;return ni(this,(function(T){switch(T.label){case 0:f={completion_tokens:0,prompt_tokens:0,total_tokens:0},d=Dn(e),p={role:"assistant",content:"",tool_calls:[h={id:"",function:{name:"",arguments:""},type:""}]},T.label=1;case 1:T.trys.push([1,6,7,12]),b=!0,y=function(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t,r=e[Symbol.asyncIterator];return r?r.call(e):(e="function"==typeof __values?__values(e):e[Symbol.iterator](),t={},n("next"),n("throw"),n("return"),t[Symbol.asyncIterator]=function(){return this},t);function n(r){t[r]=e[r]&&function(t){return new Promise((function(n,o){!function(e,t,r,n){Promise.resolve(n).then((function(t){e({value:t,done:r})}),t)}(n,o,(t=e[r](t)).done,t.value)}))}}}(d),T.label=2;case 2:return[4,y.next()];case 3:if(m=T.sent(),t=m.done)return[3,5];o=m.value,b=!1;try{if(!(_=null==(v=o)?void 0:v.choices[0]))return[2,null];if(g=_.finish_reason,w=_.delta,"tool_calls"!==g)return[2,null];if(!w)return[3,4];if(w.content&&(p.content+=w.content),!("tool_calls"in w))return[3,4];(null==(S=null===(i=null==w?void 0:w.tool_calls)||void 0===i?void 0:i[0])?void 0:S.id)&&(h.id=S.id),(null==S?void 0:S.type)&&(h.type=S.type),(null===(a=null==S?void 0:S.function)||void 0===a?void 0:a.name)&&(h.function.name=S.function.name),(null===(s=null==S?void 0:S.function)||void 0===s?void 0:s.arguments)&&(h.function.arguments+=S.function.arguments),(null===(u=null==v?void 0:v.usage)||void 0===u?void 0:u.completion_tokens)&&(f.completion_tokens=v.usage.completion_tokens),(null===(l=null==v?void 0:v.usage)||void 0===l?void 0:l.prompt_tokens)&&(f.prompt_tokens=v.usage.prompt_tokens),(null===(c=null==v?void 0:v.usage)||void 0===c?void 0:c.total_tokens)&&(f.total_tokens=v.usage.total_tokens)}finally{b=!0}T.label=4;case 4:return[3,2];case 5:return[3,12];case 6:return R=T.sent(),r={error:R},[3,12];case 7:return T.trys.push([7,,10,11]),b||t||!(n=y.return)?[3,9]:[4,n.call(y)];case 8:T.sent(),T.label=9;case 9:return[3,11];case 10:if(r)throw r.error;return[7];case 11:return[7];case 12:return[2,{message:p,usage:f}]}}))}))}(r)},z.label=2;case 2:return(b=d<u)?[4,p()]:[3,4];case 3:b=null!=(h=z.sent()),z.label=4;case 4:if(!b)return[3,11];y=h.message,m=h.usage,di(n,m),v=null===(r=y.tool_calls)||void 0===r?void 0:r[0],z.label=5;case 5:return z.trys.push([5,9,,10]),[4,ci(v)];case 6:return _=z.sent(),[4,null==a?void 0:a({finishReason:"tool_calls",messages:l.messages.slice(),text:y.content,toolCall:v,toolResult:_,stepUsage:m,totalUsage:Object.assign({},n)})];case 7:return z.sent(),ui(l.messages,y,_),[4,c()];case 8:return f=z.sent(),[3,10];case 9:return g=z.sent(),w=f.tee(),S=w[0],R=w[1],[2,{messages:Promise.resolve(l.messages),dataStream:Dn(S),textStream:Dn(R.pipeThrough(new Mn({transform:function(e,t){var r,n,o,i=null===(o=null===(n=null===(r=null==e?void 0:e.choices)||void 0===r?void 0:r[0])||void 0===n?void 0:n.delta)||void 0===o?void 0:o.content;"string"==typeof i&&t.enqueue(i)}}))),usage:Promise.resolve(n),error:g}];case 10:return[3,2];case 11:return[4,p()];case 12:return(h=z.sent())?(T=h.message,P=h.usage,di(n,P),O=oi(oi([],l.messages,!0),[T],!1),a({messages:O.slice(),finishReason:"tool_call",stepUsage:P,text:T.content,toolCall:T.tool_calls[0],totalUsage:Object.assign({},n)}),j=f.tee(),q=j[0],k=j[1],[2,{messages:Promise.resolve(oi(oi([],l.messages,!0),[T],!1)),dataStream:Dn(q),textStream:Dn(k.pipeThrough(new Mn({transform:function(e,t){var r,n,o,i=null===(o=null===(n=null===(r=null==e?void 0:e.choices)||void 0===r?void 0:r[0])||void 0===n?void 0:n.delta)||void 0===o?void 0:o.content;"string"==typeof i&&t.enqueue(i)}}))),usage:Promise.resolve(n)}]):(E=Hn(),C=Hn(),x={role:"assistant",content:""},A="",I={completion_tokens:0,prompt_tokens:0,total_tokens:0},W=f.pipeThrough(new Mn({transform:function(e,t){var r,n,o,i,a,s,u,l,c=null===(o=null===(n=null===(r=null==e?void 0:e.choices)||void 0===r?void 0:r[0])||void 0===n?void 0:n.delta)||void 0===o?void 0:o.content;"string"==typeof c&&(x.content+=c);var f=null===(a=null===(i=null==e?void 0:e.choices)||void 0===i?void 0:i[0])||void 0===a?void 0:a.finish_reason;f&&(A=f),(null===(s=null==e?void 0:e.usage)||void 0===s?void 0:s.completion_tokens)&&(I.completion_tokens=e.usage.completion_tokens),(null===(u=null==e?void 0:e.usage)||void 0===u?void 0:u.prompt_tokens)&&(I.prompt_tokens=e.usage.prompt_tokens),(null===(l=null==e?void 0:e.usage)||void 0===l?void 0:l.total_tokens)&&(I.total_tokens=e.usage.total_tokens),t.enqueue(e)},flush:function(){E.res(oi(oi([],l.messages,!0),[x],!1)),di(n,I),C.res(Object.assign({},n)),null==a||a({messages:oi(oi([],l.messages,!0),[x],!1),finishReason:A,text:x.content,stepUsage:I,totalUsage:Object.assign({},n)})}})),U=W.tee(),B=U[0],M=U[1],[2,{messages:E.promise,dataStream:Dn(B),textStream:Dn(M.pipeThrough(new Mn({transform:function(e,t){var r,n,o,i=null===(o=null===(n=null===(r=null==e?void 0:e.choices)||void 0===r?void 0:r[0])||void 0===n?void 0:n.delta)||void 0===o?void 0:o.content;"string"==typeof i&&t.enqueue(i)}}))),usage:C.promise}])}}))}))},e}();function si(e){var t,r=null===(t=null==e?void 0:e.choices)||void 0===t?void 0:t[0];if(!r)return null;var n=r.finish_reason,o=r.message;return"tool_calls"!==n?null:o&&Yn(o)?o.tool_calls[0]:null}function ui(e,t,r){e.push(t,{role:"tool",tool_call_id:t.tool_calls[0].id,content:JSON.stringify(r)})}var li=new Map;function ci(e){return li.get(e.function.name)(JSON.parse(e.function.arguments))}function fi(e){var t,r,n;return{completion_tokens:null!==(t=null==e?void 0:e.completion_tokens)&&void 0!==t?t:0,prompt_tokens:null!==(r=null==e?void 0:e.prompt_tokens)&&void 0!==r?r:0,total_tokens:null!==(n=null==e?void 0:e.total_tokens)&&void 0!==n?n:0}}function di(e,t){e.completion_tokens+=t.completion_tokens,e.prompt_tokens+=t.prompt_tokens,e.total_tokens+=t.total_tokens}var hi={hunyuan:mo,"hunyuan-beta":ho,ark:So,dashscope:jo,"01-ai":xo,moonshot:Bo,zhipu:io,"hunyuan-exp":Fo,"hunyuan-open":Go,deepseek:Qo},pi="@cloudbase/js-sdk";function bi(){return pi}var yi,mi="INVALID_OPERATION",vi="OPERATION_FAIL";!function(e){e.local="local",e.none="none",e.session="session"}(yi||(yi={}));function _i(e,t){console.warn("[".concat(bi(),"][").concat(e,"]:").concat(t))}var gi,wi,Si=(gi=function(e,t){return gi=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])},gi(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function r(){this.constructor=e}gi(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}),Ri=function(){return Ri=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},Ri.apply(this,arguments)},Ti=function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))},Pi=function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],n=0}finally{r=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}};!function(e){function t(t){var r=e.call(this)||this,n=t.timeout,o=t.timeoutMsg,i=t.restrictedMethods;return r.timeout=n||0,r.timeoutMsg=o||"请求超时",r.restrictedMethods=i||["get","post","upload","download"],r}Si(t,e),t.prototype.get=function(e){return this.request(Ri(Ri({},e),{method:"get"}),this.restrictedMethods.includes("get"))},t.prototype.post=function(e){return this.request(Ri(Ri({},e),{method:"post"}),this.restrictedMethods.includes("post"))},t.prototype.put=function(e){return this.request(Ri(Ri({},e),{method:"put"}))},t.prototype.upload=function(e){var t=e.data,r=e.file,n=e.name,o=e.method,i=e.headers,a=void 0===i?{}:i,s={post:"post",put:"put"}[null==o?void 0:o.toLowerCase()]||"put",u=new FormData;return"post"===s?(Object.keys(t).forEach((function(e){u.append(e,t[e])})),u.append("key",n),u.append("file",r),this.request(Ri(Ri({},e),{data:u,method:s}),this.restrictedMethods.includes("upload"))):this.request(Ri(Ri({},e),{method:"put",headers:a,body:r}),this.restrictedMethods.includes("upload"))},t.prototype.download=function(e){return Ti(this,void 0,void 0,(function(){var t,r,n,o;return Pi(this,(function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,this.get(Ri(Ri({},e),{headers:{},responseType:"blob"}))];case 1:return t=i.sent().data,r=window.URL.createObjectURL(new Blob([t])),n=decodeURIComponent(new URL(e.url).pathname.split("/").pop()||""),(o=document.createElement("a")).href=r,o.setAttribute("download",n),o.style.display="none",document.body.appendChild(o),o.click(),window.URL.revokeObjectURL(r),document.body.removeChild(o),[3,3];case 2:return i.sent(),[3,3];case 3:return[2,new Promise((function(t){t({statusCode:200,tempFilePath:e.url})}))]}}))}))},t.prototype.fetch=function(e){var t;return Ti(this,void 0,void 0,(function(){var r,n,o,i,a,s,u,l,c,f,d,h,p,b=this;return Pi(this,(function(y){switch(y.label){case 0:return r=new AbortController,n=e.url,o=e.enableAbort,i=void 0!==o&&o,a=e.stream,s=void 0!==a&&a,u=e.signal,l=e.timeout,c=e.shouldThrowOnError,f=void 0===c||c,d=null!=l?l:this.timeout,u&&(u.aborted&&r.abort(),u.addEventListener("abort",(function(){return r.abort()}))),h=null,i&&d&&(h=setTimeout((function(){console.warn(b.timeoutMsg),r.abort(new Error(b.timeoutMsg))}),d)),[4,fetch(n,Ri(Ri({},e),{signal:r.signal})).then((function(e){return Ti(b,void 0,void 0,(function(){var t,r,n;return Pi(this,(function(o){switch(o.label){case 0:return clearTimeout(h),f?e.ok?(t=e,[3,3]):[3,1]:[3,4];case 1:return n=(r=Promise).reject,[4,e.json()];case 2:t=n.apply(r,[o.sent()]),o.label=3;case 3:return[2,t];case 4:return[2,e]}}))}))})).catch((function(e){if(clearTimeout(h),f)return Promise.reject(e)}))];case 1:return p=y.sent(),[2,{data:s?p.body:(null===(t=p.headers.get("content-type"))||void 0===t?void 0:t.includes("application/json"))?p.json():p.text(),statusCode:p.status,header:p.headers}]}}))}))},t.prototype.request=function(e,t){var r=this;void 0===t&&(t=!1);var n=String(e.method).toLowerCase()||"get";return new Promise((function(o){var i,a,s,u=e.url,l=e.headers,c=void 0===l?{}:l,f=e.data,d=e.responseType,h=e.withCredentials,p=e.body,b=e.onUploadProgress,y=function(e,t,r){void 0===r&&(r={});var n=/\?/.test(t),o="";return Object.keys(r).forEach((function(e){""===o?!n&&(t+="?"):o+="&",o+="".concat(e,"=").concat(encodeURIComponent(r[e]))})),/^http(s)?:\/\//.test(t+=o)?t:"".concat(e).concat(t)}("https:",u,"get"===n?f:{}),m=new XMLHttpRequest;m.open(n,y),d&&(m.responseType=d),Object.keys(c).forEach((function(e){m.setRequestHeader(e,c[e])})),b&&m.upload.addEventListener("progress",b),m.onreadystatechange=function(){var e={};if(4===m.readyState){var t=m.getAllResponseHeaders().trim().split(/[\r\n]+/),r={};t.forEach((function(e){var t=e.split(": "),n=t.shift().toLowerCase(),o=t.join(": ");r[n]=o})),e.header=r,e.statusCode=m.status;try{e.data="blob"===d?m.response:JSON.parse(m.responseText)}catch(t){e.data="blob"===d?m.response:m.responseText}clearTimeout(i),o(e)}},t&&r.timeout&&(i=setTimeout((function(){console.warn(r.timeoutMsg),m.abort()}),r.timeout)),s=f,a="[object FormData]"===Object.prototype.toString.call(s)?f:"application/x-www-form-urlencoded"===c["content-type"]?function(e){void 0===e&&(e={});var t=[];return Object.keys(e).forEach((function(r){t.push("".concat(r,"=").concat(encodeURIComponent(e[r])))})),t.join("&")}(f):p||(f?JSON.stringify(f):void 0),h&&(m.withCredentials=!0),m.send(a)}))}}((function(){})),function(e){e.WEB="web",e.WX_MP="wx_mp"}(wi||(wi={}));var Oi=function(){var e=function(t,r){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])},e(t,r)};return function(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),ji=function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))},qi=function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],n=0}finally{r=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}},ki=function(e){function t(t){var r=e.call(this)||this;return r.root=t,t.tcbCacheObject||(t.tcbCacheObject={}),r}return Oi(t,e),t.prototype.setItem=function(e,t){this.root.tcbCacheObject[e]=t},t.prototype.getItem=function(e){return this.root.tcbCacheObject[e]},t.prototype.removeItem=function(e){delete this.root.tcbCacheObject[e]},t.prototype.clear=function(){delete this.root.tcbCacheObject},t}((function(){}));!function(){function e(e){this.keys={};var t=e.persistence,r=e.platformInfo,n=void 0===r?{}:r,o=e.keys,i=void 0===o?{}:o;this.platformInfo=n,this.storage||(this.persistenceTag=this.platformInfo.adapter.primaryStorage||t,this.storage=function(e,t){switch(e){case"local":default:return t.localStorage?t.localStorage:(_i("INVALID_PARAMS","localStorage is not supported on current platform"),new ki(t.root));case"none":return new ki(t.root)}}(this.persistenceTag,this.platformInfo.adapter),this.keys=i)}Object.defineProperty(e.prototype,"mode",{get:function(){return this.storage.mode||"sync"},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"persistence",{get:function(){return this.persistenceTag},enumerable:!1,configurable:!0}),e.prototype.setStore=function(e,t,r){if("async"!==this.mode){if(this.storage)try{var n={version:r||"localCachev1",content:t};this.storage.setItem(e,JSON.stringify(n))}catch(e){throw new Error(JSON.stringify({code:vi,msg:"[".concat(bi(),"][").concat(vi,"]setStore failed"),info:e}))}}else _i(mi,"current platform's storage is asynchronous, please use setStoreAsync insteed")},e.prototype.setStoreAsync=function(e,t,r){return ji(this,void 0,void 0,(function(){var n;return qi(this,(function(o){switch(o.label){case 0:if(!this.storage)return[2];o.label=1;case 1:return o.trys.push([1,3,,4]),n={version:r||"localCachev1",content:t},[4,this.storage.setItem(e,JSON.stringify(n))];case 2:return o.sent(),[3,4];case 3:return o.sent(),[2];case 4:return[2]}}))}))},e.prototype.getStore=function(e,t){var r;if("async"!==this.mode){try{if("undefined"!=typeof process&&(null===(r={IS_MP_BUILD:!0})||void 0===r?void 0:r.tcb_token))return{IS_MP_BUILD:!0}.tcb_token;if(!this.storage)return""}catch(e){return""}t=t||"localCachev1";var n=this.storage.getItem(e);return n&&n.indexOf(t)>=0?JSON.parse(n).content:""}_i(mi,"current platform's storage is asynchronous, please use getStoreAsync insteed")},e.prototype.getStoreAsync=function(e,t){var r;return ji(this,void 0,void 0,(function(){var n;return qi(this,(function(o){switch(o.label){case 0:try{if("undefined"!=typeof process&&(null===(r={IS_MP_BUILD:!0})||void 0===r?void 0:r.tcb_token))return[2,{IS_MP_BUILD:!0}.tcb_token];if(!this.storage)return[2,""]}catch(e){return[2,""]}return t=t||"localCachev1",[4,this.storage.getItem(e)];case 1:return(n=o.sent())&&n.indexOf(t)>=0?[2,JSON.parse(n).content]:[2,""]}}))}))},e.prototype.removeStore=function(e){"async"!==this.mode?this.storage.removeItem(e):_i(mi,"current platform's storage is asynchronous, please use removeStoreAsync insteed")},e.prototype.removeStoreAsync=function(e){return ji(this,void 0,void 0,(function(){return qi(this,(function(t){switch(t.label){case 0:return[4,this.storage.removeItem(e)];case 1:return t.sent(),[2]}}))}))}}();var Ei=function(){var e=function(t,r){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])},e(t,r)};return function(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),Ci=function(e,t){this.data=t||null,this.name=e},xi=function(e){function t(t,r){var n=e.call(this,"error",{error:t,data:r})||this;return n.error=t,n}return Ei(t,e),t}(Ci),Ai=function(){function e(){this.listeners={}}return e.prototype.on=function(e,t){return function(e,t,r){r[e]=r[e]||[],r[e].push(t)}(e,t,this.listeners),this},e.prototype.off=function(e,t){return function(e,t,r){if(null==r?void 0:r[e]){var n=r[e].indexOf(t);-1!==n&&r[e].splice(n,1)}}(e,t,this.listeners),this},e.prototype.fire=function(e,t){if(e instanceof xi)return console.error(e.error),this;var r="string"==typeof e?new Ci(e,t||{}):e,n=r.name;if(this.listens(n)){r.target=this;for(var o=0,i=this.listeners[n]?function(e,t,r){if(r||2===arguments.length)for(var n,o=0,i=t.length;o<i;o++)!n&&o in t||(n||(n=Array.prototype.slice.call(t,0,o)),n[o]=t[o]);return e.concat(n||Array.prototype.slice.call(t))}([],this.listeners[n],!0):[];o<i.length;o++)i[o].call(this,r)}return this},e.prototype.listens=function(e){return this.listeners[e]&&this.listeners[e].length>0},e}();new Ai;var Ii=new Ai;function Wi(e){this.message=e}function Ui(e){this.message=e}"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.indexOf("Firefox"),Wi.prototype=new Error,Wi.prototype.name="InvalidCharacterError","undefined"!=typeof window&&window.atob&&window.atob.bind(window),Ui.prototype=new Error,Ui.prototype.name="InvalidTokenError";var Bi=function(){return Bi=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},Bi.apply(this,arguments)},Mi=function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))},Li=function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],n=0}finally{r=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}},zi=hi,Fi=function(){function e(e,t,r){var n=this;this.req=e,this.baseUrl=t,this.modelRequest=function(e){var t=e.url,r=e.data,o=e.headers,i=e.stream,a=e.timeout;return Mi(n,void 0,void 0,(function(){var e,n,s,u,l,c,f;return Li(this,(function(d){switch(d.label){case 0:return e={"Content-Type":"application/json"},i&&Object.assign(e,{Accept:"text/event-stream"}),[4,this.req.fetch({method:"post",headers:Bi(Bi((l={},l[null===(c=this.i18n)||void 0===c?void 0:c.LANG_HEADER_KEY]=null===(f=this.i18n)||void 0===f?void 0:f.lang,l),e),o),body:JSON.stringify(r),url:t,stream:i,timeout:a})];case 1:return n=d.sent(),s=n.data,u=n.header,[2,this.handleResponseData(s,u)]}}))}))},this.botRequest=function(e){var t=e.method,r=e.url,o=e.data,i=void 0===o?{}:o,a=e.headers,s=e.stream,u=e.timeout;return Mi(n,void 0,void 0,(function(){var e,n,o,l,c,f,d,h;return Li(this,(function(p){switch(p.label){case 0:return"get"!==t?[3,2]:(e=this.handleResponseData,[4,this.req.fetch({url:"".concat(r,"?").concat((b=i,Object.entries(b).map((function(e){var t=e[0],r=e[1];return"".concat(t,"=").concat(r)})).join("&"))),method:t,headers:a,stream:s,timeout:u})]);case 1:return[2,e.apply(this,[p.sent().data])];case 2:return n={"Content-Type":"application/json"},s&&Object.assign(n,{Accept:"text/event-stream"}),[4,this.req.fetch({url:r,body:JSON.stringify(i),headers:Bi(Bi((f={},f[null===(d=this.i18n)||void 0===d?void 0:d.LANG_HEADER_KEY]=null===(h=this.i18n)||void 0===h?void 0:h.lang,f),n),a),stream:s,method:t,timeout:u})];case 3:return o=p.sent(),l=o.data,c=o.header,[2,this.handleResponseData(l,c)]}var b}))}))},this.aiBaseUrl="".concat(t,"/ai"),this.aiBotBaseUrl="".concat(t,"/aibot"),this.bot=new Zn(this.botRequest,this.aiBotBaseUrl),this.i18n=r,Ii.on("lang_change",(function(e){var t;n.i18n=(null===(t=e.data)||void 0===t?void 0:t.i18n)||n.i18n}))}return e.prototype.handleResponseData=function(e,t){var r,n;return Mi(this,void 0,void 0,(function(){var o,i;return Li(this,(function(a){switch(a.label){case 0:return o="".concat(this.i18n.t("请检查调用方式,或前往云开发 AI+ 首页查看文档"),":https://tcb.cloud.tencent.com/dev#/ai"),"object"==typeof e&&e&&"then"in e?[4,e]:[3,2];case 1:if("object"==typeof(i=a.sent())&&i&&"code"in i&&"NORMAL"!==i.code)throw new Error("".concat(this.i18n.t("AI+ 请求出错,错误码"),":").concat(i.code,",").concat(this.i18n.t("错误信息"),":").concat(i.message,"\n").concat(o,"\n").concat(JSON.stringify(i,null,2)));return[2,e];case 2:return(null===(n=null===(r=null==t?void 0:t.get)||void 0===r?void 0:r.call(t,"content-type"))||void 0===n?void 0:n.includes("application/json"))?[4,Gn(e)]:[3,4];case 3:if("object"==typeof(i=a.sent())&&i&&"code"in i&&"NORMAL"!==i.code)throw new Error("".concat(this.i18n.t("AI+ 请求出错,错误码"),":").concat(i.code,",").concat(this.i18n.t("错误信息"),":").concat(i.message,"\n").concat(o,"\n").concat(JSON.stringify(i,null,2)));a.label=4;case 4:return[2,e]}}))}))},e.prototype.createModel=function(e,t){var r,n=zi[e];if(n)r=new n(this.modelRequest,this.aiBaseUrl);else{var o="string"==typeof(null==t?void 0:t.defaultModelSubUrl)?t.defaultModelSubUrl:"/chat/completions";r=new Zo(this.modelRequest,this.aiBaseUrl,"".concat(e).concat(o))}return new ai(r)},e.prototype.registerModel=function(e,t){null==zi[e]?zi[e]=t:console.warn("AI model ".concat(e," already exists!"))},e.prototype.createImageModel=function(e){return new ei(this.modelRequest,this.aiBaseUrl,e)},e.prototype.registerFunctionTool=function(e){li.has(e.name)&&console.warn("AI function tool ".concat(e.name," already exists and will be overwritten!")),li.set(e.name,e.fn)},e}(),Di=function(){},$i=function(){return $i=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},$i.apply(this,arguments)},Ni=function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(r[n[o]]=e[n[o]])}return r},Gi=Ni(o,["MODELS"]),Hi=function(e){var t=e.getAccessToken,r=e.req;return{download:r.download,post:r.post,upload:r.upload,fetch:function(e){return function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))}(void 0,void 0,void 0,(function(){var n,o,i,a,s;return function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],n=0}finally{r=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}}(this,(function(u){switch(u.label){case 0:if("function"!=typeof r.fetch)throw new Error("req.fetch is not a function");return n=e.token,o=e.headers,i=void 0===o?{}:o,a=Ni(e,["token","headers"]),null==n?[3,1]:(s=n,[3,3]);case 1:return[4,t()];case 2:s=u.sent().accessToken,u.label=3;case 3:return[2,r.fetch($i({headers:$i({Authorization:"Bearer ".concat(s)},i)},a))]}}))}))}}};function Yi(e){var t=e.env,r=e.baseUrl,n=e.req,o=e.getAccessToken,i=e.handleReqInstance,a=e.i18n;return new Fi(function(){if(null==i){if(null==o)throw new Error("`getAccessToken` is required when `handleReqInstance` is not provided!");return Hi({req:n,getAccessToken:o})}return i({req:n})}(),function(){if(null!=r)return r;if(null==t)throw new Error("`env` is required when `baseUrl` is not provided!");return"https://".concat(t,".api.tcloudbasegateway.com/v1")}(),a)}var Ji=Yi,Qi={name:"ai",entity:{ai:function(e){var t,r=this,n=this.request;if(null==n.fetch)throw new Error("cloudbase.request.fetch() unimplemented!");var o=null!==(t=null==e?void 0:e.baseUrl)&&void 0!==t?t:function(){var e=r.getEndPointWithKey("GATEWAY"),t=e.BASE_URL,n=e.PROTOCOL;return"".concat(n).concat(t)}();return Yi({req:n,baseUrl:o,handleReqInstance:function(e){return e.req},i18n:this.config.i18n})}}};function Vi(e){try{e.registerComponent(Qi)}catch(e){console.warn(e)}}try{window.registerAi=Vi}catch(i){}}},t={};function r(n){var o=t[n];if(void 0!==o)return o.exports;var i=t[n]={exports:{}};return e[n].call(i.exports,i,i.exports,r),i.exports}return r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r(639)})()));
|
|
2
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("cloudbase_ai",[],t):"object"==typeof exports?exports.cloudbase_ai=t():e.cloudbase_ai=t()}("undefined"!=typeof window?window:this,(()=>(()=>{var e={639:function(e,t,r){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,o)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),o=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||n(t,e,r)};Object.defineProperty(t,"__esModule",{value:!0}),o(r(138),t)},877:function(e,t,r){var n,o;void 0===(o="function"==typeof(n=function(){"use strict";var e=void 0!==r.g?r.g:self;if(void 0!==e.TextEncoder&&void 0!==e.TextDecoder)return{TextEncoder:e.TextEncoder,TextDecoder:e.TextDecoder};var t=["utf8","utf-8","unicode-1-1-utf-8"];return{TextEncoder:function(e){if(t.indexOf(e)<0&&null!=e)throw new RangeError("Invalid encoding type. Only utf-8 is supported");this.encoding="utf-8",this.encode=function(e){if("string"!=typeof e)throw new TypeError("passed argument must be of type string");var t=unescape(encodeURIComponent(e)),r=new Uint8Array(t.length);return t.split("").forEach((function(e,t){r[t]=e.charCodeAt(0)})),r}},TextDecoder:function(e,r){if(t.indexOf(e)<0&&null!=e)throw new RangeError("Invalid encoding type. Only utf-8 is supported");if(this.encoding="utf-8",this.ignoreBOM=!1,this.fatal=void 0!==r&&"fatal"in r&&r.fatal,"boolean"!=typeof this.fatal)throw new TypeError("fatal flag must be boolean");this.decode=function(e,t){if(void 0===e)return"";if("boolean"!=typeof(void 0!==t&&"stream"in t&&t.stream))throw new TypeError("stream option must be boolean");if(ArrayBuffer.isView(e)){var r=new Uint8Array(e.buffer,e.byteOffset,e.byteLength),n=new Array(r.length);return r.forEach((function(e,t){n[t]=String.fromCharCode(e)})),decodeURIComponent(escape(n.join("")))}throw new TypeError("passed argument must be an array buffer view")}}}})?n.apply(t,[]):n)||(e.exports=o)},138:(e,t,r)=>{"use strict";r.r(t),r.d(t,{AI:()=>Fi,Bot:()=>Zn,SimpleChatModel:()=>Di,createAI:()=>Yi,createAi:()=>Ji,models:()=>Gi,registerAi:()=>Vi,utils:()=>n});var n={};r.r(n),r.d(n,{ReadableStream:()=>Bn,TextDecoderStream:()=>Fn,TransformStream:()=>Mn,createAsyncIterable:()=>Dn,createEventSourceParserTransformStream:()=>Ln,createPromise:()=>Hn,functionToolToModelTool:()=>Jn,intoStandardStream:()=>$n,intoTextStream:()=>Nn,isToolCallAssistantMessage:()=>Yn,readableStream2JsonObject:()=>Gn,toPolyfillReadable:()=>zn});var o={};function i(){}function a(e){return"object"==typeof e&&null!==e||"function"==typeof e}r.r(o),r.d(o,{ArkSimpleModel:()=>So,DSSimpleModel:()=>jo,DefaultImageModel:()=>ei,DefaultSimpleModel:()=>Zo,HunYuanBetaSimpleModel:()=>ho,HunYuanExpSimpleModel:()=>Fo,HunYuanOpenSimpleModel:()=>Go,HunYuanSimpleModel:()=>mo,MODELS:()=>hi,MoonshotSimpleModel:()=>Bo,ReactModel:()=>ai,YiSimpleModel:()=>xo,ZhiPuSimpleModel:()=>io,toolMap:()=>li});const s=i;function u(e,t){try{Object.defineProperty(e,"name",{value:t,configurable:!0})}catch(e){}}const l=Promise,c=Promise.resolve.bind(l),f=Promise.prototype.then,d=Promise.reject.bind(l),h=c;function p(e){return new l(e)}function b(e){return p((t=>t(e)))}function y(e){return d(e)}function m(e,t,r){return f.call(e,t,r)}function v(e,t,r){m(m(e,t,r),void 0,s)}function _(e,t){v(e,t)}function g(e,t){v(e,void 0,t)}function w(e,t,r){return m(e,t,r)}function S(e){m(e,void 0,s)}let R=e=>{if("function"==typeof queueMicrotask)R=queueMicrotask;else{const e=b(void 0);R=t=>m(e,t)}return R(e)};function T(e,t,r){if("function"!=typeof e)throw new TypeError("Argument is not a function");return Function.prototype.apply.call(e,t,r)}function P(e,t,r){try{return b(T(e,t,r))}catch(e){return y(e)}}class O{constructor(){this._cursor=0,this._size=0,this._front={_elements:[],_next:void 0},this._back=this._front,this._cursor=0,this._size=0}get length(){return this._size}push(e){const t=this._back;let r=t;16383===t._elements.length&&(r={_elements:[],_next:void 0}),t._elements.push(e),r!==t&&(this._back=r,t._next=r),++this._size}shift(){const e=this._front;let t=e;const r=this._cursor;let n=r+1;const o=e._elements,i=o[r];return 16384===n&&(t=e._next,n=0),--this._size,this._cursor=n,e!==t&&(this._front=t),o[r]=void 0,i}forEach(e){let t=this._cursor,r=this._front,n=r._elements;for(;!(t===n.length&&void 0===r._next||t===n.length&&(r=r._next,n=r._elements,t=0,0===n.length));)e(n[t]),++t}peek(){const e=this._front,t=this._cursor;return e._elements[t]}}const j=Symbol("[[AbortSteps]]"),q=Symbol("[[ErrorSteps]]"),k=Symbol("[[CancelSteps]]"),E=Symbol("[[PullSteps]]"),C=Symbol("[[ReleaseSteps]]");function x(e,t){e._ownerReadableStream=t,t._reader=e,"readable"===t._state?U(e):"closed"===t._state?function(e){U(e),L(e)}(e):B(e,t._storedError)}function A(e,t){return Fr(e._ownerReadableStream,t)}function I(e){const t=e._ownerReadableStream;"readable"===t._state?M(e,new TypeError("Reader was released and can no longer be used to monitor the stream's closedness")):function(e){B(e,new TypeError("Reader was released and can no longer be used to monitor the stream's closedness"))}(e),t._readableStreamController[C](),t._reader=void 0,e._ownerReadableStream=void 0}function W(e){return new TypeError("Cannot "+e+" a stream using a released reader")}function U(e){e._closedPromise=p(((t,r)=>{e._closedPromise_resolve=t,e._closedPromise_reject=r}))}function B(e,t){U(e),M(e,t)}function M(e,t){void 0!==e._closedPromise_reject&&(S(e._closedPromise),e._closedPromise_reject(t),e._closedPromise_resolve=void 0,e._closedPromise_reject=void 0)}function L(e){void 0!==e._closedPromise_resolve&&(e._closedPromise_resolve(void 0),e._closedPromise_resolve=void 0,e._closedPromise_reject=void 0)}const z=Number.isFinite||function(e){return"number"==typeof e&&isFinite(e)},F=Math.trunc||function(e){return e<0?Math.ceil(e):Math.floor(e)};function D(e,t){if(void 0!==e&&"object"!=typeof(r=e)&&"function"!=typeof r)throw new TypeError(`${t} is not an object.`);var r}function $(e,t){if("function"!=typeof e)throw new TypeError(`${t} is not a function.`)}function N(e,t){if(!function(e){return"object"==typeof e&&null!==e||"function"==typeof e}(e))throw new TypeError(`${t} is not an object.`)}function G(e,t,r){if(void 0===e)throw new TypeError(`Parameter ${t} is required in '${r}'.`)}function H(e,t,r){if(void 0===e)throw new TypeError(`${t} is required in '${r}'.`)}function Y(e){return Number(e)}function J(e){return 0===e?0:e}function Q(e,t){const r=Number.MAX_SAFE_INTEGER;let n=Number(e);if(n=J(n),!z(n))throw new TypeError(`${t} is not a finite number`);if(n=function(e){return J(F(e))}(n),n<0||n>r)throw new TypeError(`${t} is outside the accepted range of 0 to ${r}, inclusive`);return z(n)&&0!==n?n:0}function V(e,t){if(!Lr(e))throw new TypeError(`${t} is not a ReadableStream.`)}function X(e){return new re(e)}function K(e,t){e._reader._readRequests.push(t)}function Z(e,t,r){const n=e._reader._readRequests.shift();r?n._closeSteps():n._chunkSteps(t)}function ee(e){return e._reader._readRequests.length}function te(e){const t=e._reader;return void 0!==t&&!!ne(t)}class re{constructor(e){if(G(e,1,"ReadableStreamDefaultReader"),V(e,"First parameter"),zr(e))throw new TypeError("This stream has already been locked for exclusive reading by another reader");x(this,e),this._readRequests=new O}get closed(){return ne(this)?this._closedPromise:y(ae("closed"))}cancel(e=void 0){return ne(this)?void 0===this._ownerReadableStream?y(W("cancel")):A(this,e):y(ae("cancel"))}read(){if(!ne(this))return y(ae("read"));if(void 0===this._ownerReadableStream)return y(W("read from"));let e,t;const r=p(((r,n)=>{e=r,t=n}));return oe(this,{_chunkSteps:t=>e({value:t,done:!1}),_closeSteps:()=>e({value:void 0,done:!0}),_errorSteps:e=>t(e)}),r}releaseLock(){if(!ne(this))throw ae("releaseLock");void 0!==this._ownerReadableStream&&function(e){I(e),ie(e,new TypeError("Reader was released"))}(this)}}function ne(e){return!!a(e)&&!!Object.prototype.hasOwnProperty.call(e,"_readRequests")&&e instanceof re}function oe(e,t){const r=e._ownerReadableStream;r._disturbed=!0,"closed"===r._state?t._closeSteps():"errored"===r._state?t._errorSteps(r._storedError):r._readableStreamController[E](t)}function ie(e,t){const r=e._readRequests;e._readRequests=new O,r.forEach((e=>{e._errorSteps(t)}))}function ae(e){return new TypeError(`ReadableStreamDefaultReader.prototype.${e} can only be used on a ReadableStreamDefaultReader`)}var se,ue,le;function ce(e){return e.slice()}function fe(e,t,r,n,o){new Uint8Array(e).set(new Uint8Array(r,n,o),t)}Object.defineProperties(re.prototype,{cancel:{enumerable:!0},read:{enumerable:!0},releaseLock:{enumerable:!0},closed:{enumerable:!0}}),u(re.prototype.cancel,"cancel"),u(re.prototype.read,"read"),u(re.prototype.releaseLock,"releaseLock"),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(re.prototype,Symbol.toStringTag,{value:"ReadableStreamDefaultReader",configurable:!0});let de=e=>(de="function"==typeof e.transfer?e=>e.transfer():"function"==typeof structuredClone?e=>structuredClone(e,{transfer:[e]}):e=>e,de(e)),he=e=>(he="boolean"==typeof e.detached?e=>e.detached:e=>0===e.byteLength,he(e));function pe(e,t,r){if(e.slice)return e.slice(t,r);const n=r-t,o=new ArrayBuffer(n);return fe(o,0,e,t,n),o}function be(e,t){const r=e[t];if(null!=r){if("function"!=typeof r)throw new TypeError(`${String(t)} is not a function`);return r}}function ye(e){try{const t=e.done,r=e.value;return m(h(r),(e=>({done:t,value:e})))}catch(e){return y(e)}}const me=null!==(le=null!==(se=Symbol.asyncIterator)&&void 0!==se?se:null===(ue=Symbol.for)||void 0===ue?void 0:ue.call(Symbol,"Symbol.asyncIterator"))&&void 0!==le?le:"@@asyncIterator";function ve(e,t="sync",r){if(void 0===r)if("async"===t){if(void 0===(r=be(e,me)))return function(e){const t={next(){let t;try{t=_e(e)}catch(e){return y(e)}return ye(t)},return(t){let r;try{const n=be(e.iterator,"return");if(void 0===n)return b({done:!0,value:t});r=T(n,e.iterator,[t])}catch(e){return y(e)}return a(r)?ye(r):y(new TypeError("The iterator.return() method must return an object"))}};return{iterator:t,nextMethod:t.next,done:!1}}(ve(e,"sync",be(e,Symbol.iterator)))}else r=be(e,Symbol.iterator);if(void 0===r)throw new TypeError("The object is not iterable");const n=T(r,e,[]);if(!a(n))throw new TypeError("The iterator method must return an object");return{iterator:n,nextMethod:n.next,done:!1}}function _e(e){const t=T(e.nextMethod,e.iterator,[]);if(!a(t))throw new TypeError("The iterator.next() method must return an object");return t}class ge{constructor(e,t){this._ongoingPromise=void 0,this._isFinished=!1,this._reader=e,this._preventCancel=t}next(){const e=()=>this._nextSteps();return this._ongoingPromise=this._ongoingPromise?w(this._ongoingPromise,e,e):e(),this._ongoingPromise}return(e){const t=()=>this._returnSteps(e);return this._ongoingPromise?w(this._ongoingPromise,t,t):t()}_nextSteps(){if(this._isFinished)return Promise.resolve({value:void 0,done:!0});const e=this._reader;let t,r;const n=p(((e,n)=>{t=e,r=n}));return oe(e,{_chunkSteps:e=>{this._ongoingPromise=void 0,R((()=>t({value:e,done:!1})))},_closeSteps:()=>{this._ongoingPromise=void 0,this._isFinished=!0,I(e),t({value:void 0,done:!0})},_errorSteps:t=>{this._ongoingPromise=void 0,this._isFinished=!0,I(e),r(t)}}),n}_returnSteps(e){if(this._isFinished)return Promise.resolve({value:e,done:!0});this._isFinished=!0;const t=this._reader;if(!this._preventCancel){const r=A(t,e);return I(t),w(r,(()=>({value:e,done:!0})))}return I(t),b({value:e,done:!0})}}const we={next(){return Se(this)?this._asyncIteratorImpl.next():y(Re("next"))},return(e){return Se(this)?this._asyncIteratorImpl.return(e):y(Re("return"))},[me](){return this}};function Se(e){if(!a(e))return!1;if(!Object.prototype.hasOwnProperty.call(e,"_asyncIteratorImpl"))return!1;try{return e._asyncIteratorImpl instanceof ge}catch(e){return!1}}function Re(e){return new TypeError(`ReadableStreamAsyncIterator.${e} can only be used on a ReadableSteamAsyncIterator`)}Object.defineProperty(we,me,{enumerable:!1});const Te=Number.isNaN||function(e){return e!=e};function Pe(e){const t=pe(e.buffer,e.byteOffset,e.byteOffset+e.byteLength);return new Uint8Array(t)}function Oe(e){const t=e._queue.shift();return e._queueTotalSize-=t.size,e._queueTotalSize<0&&(e._queueTotalSize=0),t.value}function je(e,t,r){if("number"!=typeof(n=r)||Te(n)||n<0||r===1/0)throw new RangeError("Size must be a finite, non-NaN, non-negative number.");var n;e._queue.push({value:t,size:r}),e._queueTotalSize+=r}function qe(e){e._queue=new O,e._queueTotalSize=0}function ke(e){return e===DataView}class Ee{constructor(){throw new TypeError("Illegal constructor")}get view(){if(!Ae(this))throw ot("view");return this._view}respond(e){if(!Ae(this))throw ot("respond");if(G(e,1,"respond"),e=Q(e,"First parameter"),void 0===this._associatedReadableByteStreamController)throw new TypeError("This BYOB request has been invalidated");if(he(this._view.buffer))throw new TypeError("The BYOB request's buffer has been detached and so cannot be used as a response");tt(this._associatedReadableByteStreamController,e)}respondWithNewView(e){if(!Ae(this))throw ot("respondWithNewView");if(G(e,1,"respondWithNewView"),!ArrayBuffer.isView(e))throw new TypeError("You can only respond with array buffer views");if(void 0===this._associatedReadableByteStreamController)throw new TypeError("This BYOB request has been invalidated");if(he(e.buffer))throw new TypeError("The given view's buffer has been detached and so cannot be used as a response");rt(this._associatedReadableByteStreamController,e)}}Object.defineProperties(Ee.prototype,{respond:{enumerable:!0},respondWithNewView:{enumerable:!0},view:{enumerable:!0}}),u(Ee.prototype.respond,"respond"),u(Ee.prototype.respondWithNewView,"respondWithNewView"),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(Ee.prototype,Symbol.toStringTag,{value:"ReadableStreamBYOBRequest",configurable:!0});class Ce{constructor(){throw new TypeError("Illegal constructor")}get byobRequest(){if(!xe(this))throw it("byobRequest");return Ze(this)}get desiredSize(){if(!xe(this))throw it("desiredSize");return et(this)}close(){if(!xe(this))throw it("close");if(this._closeRequested)throw new TypeError("The stream has already been closed; do not close it again!");const e=this._controlledReadableByteStream._state;if("readable"!==e)throw new TypeError(`The stream (in ${e} state) is not in the readable state and cannot be closed`);Qe(this)}enqueue(e){if(!xe(this))throw it("enqueue");if(G(e,1,"enqueue"),!ArrayBuffer.isView(e))throw new TypeError("chunk must be an array buffer view");if(0===e.byteLength)throw new TypeError("chunk must have non-zero byteLength");if(0===e.buffer.byteLength)throw new TypeError("chunk's buffer must have non-zero byteLength");if(this._closeRequested)throw new TypeError("stream is closed or draining");const t=this._controlledReadableByteStream._state;if("readable"!==t)throw new TypeError(`The stream (in ${t} state) is not in the readable state and cannot be enqueued to`);Ve(this,e)}error(e=void 0){if(!xe(this))throw it("error");Xe(this,e)}[k](e){We(this),qe(this);const t=this._cancelAlgorithm(e);return Je(this),t}[E](e){const t=this._controlledReadableByteStream;if(this._queueTotalSize>0)return void Ke(this,e);const r=this._autoAllocateChunkSize;if(void 0!==r){let n;try{n=new ArrayBuffer(r)}catch(t){return void e._errorSteps(t)}const o={buffer:n,bufferByteLength:r,byteOffset:0,byteLength:r,bytesFilled:0,minimumFill:1,elementSize:1,viewConstructor:Uint8Array,readerType:"default"};this._pendingPullIntos.push(o)}K(t,e),Ie(this)}[C](){if(this._pendingPullIntos.length>0){const e=this._pendingPullIntos.peek();e.readerType="none",this._pendingPullIntos=new O,this._pendingPullIntos.push(e)}}}function xe(e){return!!a(e)&&!!Object.prototype.hasOwnProperty.call(e,"_controlledReadableByteStream")&&e instanceof Ce}function Ae(e){return!!a(e)&&!!Object.prototype.hasOwnProperty.call(e,"_associatedReadableByteStreamController")&&e instanceof Ee}function Ie(e){const t=function(e){const t=e._controlledReadableByteStream;return"readable"===t._state&&(!e._closeRequested&&(!!e._started&&(!!(te(t)&&ee(t)>0)||(!!(ct(t)&<(t)>0)||et(e)>0))))}(e);t&&(e._pulling?e._pullAgain=!0:(e._pulling=!0,v(e._pullAlgorithm(),(()=>(e._pulling=!1,e._pullAgain&&(e._pullAgain=!1,Ie(e)),null)),(t=>(Xe(e,t),null)))))}function We(e){Ne(e),e._pendingPullIntos=new O}function Ue(e,t){let r=!1;"closed"===e._state&&(r=!0);const n=Be(t);"default"===t.readerType?Z(e,n,r):function(e,t,r){const n=e._reader._readIntoRequests.shift();r?n._closeSteps(t):n._chunkSteps(t)}(e,n,r)}function Be(e){const t=e.bytesFilled,r=e.elementSize;return new e.viewConstructor(e.buffer,e.byteOffset,t/r)}function Me(e,t,r,n){e._queue.push({buffer:t,byteOffset:r,byteLength:n}),e._queueTotalSize+=n}function Le(e,t,r,n){let o;try{o=pe(t,r,r+n)}catch(t){throw Xe(e,t),t}Me(e,o,0,n)}function ze(e,t){t.bytesFilled>0&&Le(e,t.buffer,t.byteOffset,t.bytesFilled),Ye(e)}function Fe(e,t){const r=Math.min(e._queueTotalSize,t.byteLength-t.bytesFilled),n=t.bytesFilled+r;let o=r,i=!1;const a=n-n%t.elementSize;a>=t.minimumFill&&(o=a-t.bytesFilled,i=!0);const s=e._queue;for(;o>0;){const r=s.peek(),n=Math.min(o,r.byteLength),i=t.byteOffset+t.bytesFilled;fe(t.buffer,i,r.buffer,r.byteOffset,n),r.byteLength===n?s.shift():(r.byteOffset+=n,r.byteLength-=n),e._queueTotalSize-=n,De(0,n,t),o-=n}return i}function De(e,t,r){r.bytesFilled+=t}function $e(e){0===e._queueTotalSize&&e._closeRequested?(Je(e),Dr(e._controlledReadableByteStream)):Ie(e)}function Ne(e){null!==e._byobRequest&&(e._byobRequest._associatedReadableByteStreamController=void 0,e._byobRequest._view=null,e._byobRequest=null)}function Ge(e){for(;e._pendingPullIntos.length>0;){if(0===e._queueTotalSize)return;const t=e._pendingPullIntos.peek();Fe(e,t)&&(Ye(e),Ue(e._controlledReadableByteStream,t))}}function He(e,t){const r=e._pendingPullIntos.peek();Ne(e),"closed"===e._controlledReadableByteStream._state?function(e,t){"none"===t.readerType&&Ye(e);const r=e._controlledReadableByteStream;if(ct(r))for(;lt(r)>0;)Ue(r,Ye(e))}(e,r):function(e,t,r){if(De(0,t,r),"none"===r.readerType)return ze(e,r),void Ge(e);if(r.bytesFilled<r.minimumFill)return;Ye(e);const n=r.bytesFilled%r.elementSize;if(n>0){const t=r.byteOffset+r.bytesFilled;Le(e,r.buffer,t-n,n)}r.bytesFilled-=n,Ue(e._controlledReadableByteStream,r),Ge(e)}(e,t,r),Ie(e)}function Ye(e){return e._pendingPullIntos.shift()}function Je(e){e._pullAlgorithm=void 0,e._cancelAlgorithm=void 0}function Qe(e){const t=e._controlledReadableByteStream;if(!e._closeRequested&&"readable"===t._state)if(e._queueTotalSize>0)e._closeRequested=!0;else{if(e._pendingPullIntos.length>0){const t=e._pendingPullIntos.peek();if(t.bytesFilled%t.elementSize!=0){const t=new TypeError("Insufficient bytes to fill elements in the given buffer");throw Xe(e,t),t}}Je(e),Dr(t)}}function Ve(e,t){const r=e._controlledReadableByteStream;if(e._closeRequested||"readable"!==r._state)return;const{buffer:n,byteOffset:o,byteLength:i}=t;if(he(n))throw new TypeError("chunk's buffer is detached and so cannot be enqueued");const a=de(n);if(e._pendingPullIntos.length>0){const t=e._pendingPullIntos.peek();if(he(t.buffer))throw new TypeError("The BYOB request's buffer has been detached and so cannot be filled with an enqueued chunk");Ne(e),t.buffer=de(t.buffer),"none"===t.readerType&&ze(e,t)}te(r)?(function(e){const t=e._controlledReadableByteStream._reader;for(;t._readRequests.length>0;){if(0===e._queueTotalSize)return;Ke(e,t._readRequests.shift())}}(e),0===ee(r)?Me(e,a,o,i):(e._pendingPullIntos.length>0&&Ye(e),Z(r,new Uint8Array(a,o,i),!1))):ct(r)?(Me(e,a,o,i),Ge(e)):Me(e,a,o,i),Ie(e)}function Xe(e,t){const r=e._controlledReadableByteStream;"readable"===r._state&&(We(e),qe(e),Je(e),$r(r,t))}function Ke(e,t){const r=e._queue.shift();e._queueTotalSize-=r.byteLength,$e(e);const n=new Uint8Array(r.buffer,r.byteOffset,r.byteLength);t._chunkSteps(n)}function Ze(e){if(null===e._byobRequest&&e._pendingPullIntos.length>0){const t=e._pendingPullIntos.peek(),r=new Uint8Array(t.buffer,t.byteOffset+t.bytesFilled,t.byteLength-t.bytesFilled),n=Object.create(Ee.prototype);!function(e,t,r){e._associatedReadableByteStreamController=t,e._view=r}(n,e,r),e._byobRequest=n}return e._byobRequest}function et(e){const t=e._controlledReadableByteStream._state;return"errored"===t?null:"closed"===t?0:e._strategyHWM-e._queueTotalSize}function tt(e,t){const r=e._pendingPullIntos.peek();if("closed"===e._controlledReadableByteStream._state){if(0!==t)throw new TypeError("bytesWritten must be 0 when calling respond() on a closed stream")}else{if(0===t)throw new TypeError("bytesWritten must be greater than 0 when calling respond() on a readable stream");if(r.bytesFilled+t>r.byteLength)throw new RangeError("bytesWritten out of range")}r.buffer=de(r.buffer),He(e,t)}function rt(e,t){const r=e._pendingPullIntos.peek();if("closed"===e._controlledReadableByteStream._state){if(0!==t.byteLength)throw new TypeError("The view's length must be 0 when calling respondWithNewView() on a closed stream")}else if(0===t.byteLength)throw new TypeError("The view's length must be greater than 0 when calling respondWithNewView() on a readable stream");if(r.byteOffset+r.bytesFilled!==t.byteOffset)throw new RangeError("The region specified by view does not match byobRequest");if(r.bufferByteLength!==t.buffer.byteLength)throw new RangeError("The buffer of view has different capacity than byobRequest");if(r.bytesFilled+t.byteLength>r.byteLength)throw new RangeError("The region specified by view is larger than byobRequest");const n=t.byteLength;r.buffer=de(t.buffer),He(e,n)}function nt(e,t,r,n,o,i,a){t._controlledReadableByteStream=e,t._pullAgain=!1,t._pulling=!1,t._byobRequest=null,t._queue=t._queueTotalSize=void 0,qe(t),t._closeRequested=!1,t._started=!1,t._strategyHWM=i,t._pullAlgorithm=n,t._cancelAlgorithm=o,t._autoAllocateChunkSize=a,t._pendingPullIntos=new O,e._readableStreamController=t,v(b(r()),(()=>(t._started=!0,Ie(t),null)),(e=>(Xe(t,e),null)))}function ot(e){return new TypeError(`ReadableStreamBYOBRequest.prototype.${e} can only be used on a ReadableStreamBYOBRequest`)}function it(e){return new TypeError(`ReadableByteStreamController.prototype.${e} can only be used on a ReadableByteStreamController`)}function at(e,t){if("byob"!=(e=`${e}`))throw new TypeError(`${t} '${e}' is not a valid enumeration value for ReadableStreamReaderMode`);return e}function st(e){return new ft(e)}function ut(e,t){e._reader._readIntoRequests.push(t)}function lt(e){return e._reader._readIntoRequests.length}function ct(e){const t=e._reader;return void 0!==t&&!!dt(t)}Object.defineProperties(Ce.prototype,{close:{enumerable:!0},enqueue:{enumerable:!0},error:{enumerable:!0},byobRequest:{enumerable:!0},desiredSize:{enumerable:!0}}),u(Ce.prototype.close,"close"),u(Ce.prototype.enqueue,"enqueue"),u(Ce.prototype.error,"error"),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(Ce.prototype,Symbol.toStringTag,{value:"ReadableByteStreamController",configurable:!0});class ft{constructor(e){if(G(e,1,"ReadableStreamBYOBReader"),V(e,"First parameter"),zr(e))throw new TypeError("This stream has already been locked for exclusive reading by another reader");if(!xe(e._readableStreamController))throw new TypeError("Cannot construct a ReadableStreamBYOBReader for a stream not constructed with a byte source");x(this,e),this._readIntoRequests=new O}get closed(){return dt(this)?this._closedPromise:y(bt("closed"))}cancel(e=void 0){return dt(this)?void 0===this._ownerReadableStream?y(W("cancel")):A(this,e):y(bt("cancel"))}read(e,t={}){if(!dt(this))return y(bt("read"));if(!ArrayBuffer.isView(e))return y(new TypeError("view must be an array buffer view"));if(0===e.byteLength)return y(new TypeError("view must have non-zero byteLength"));if(0===e.buffer.byteLength)return y(new TypeError("view's buffer must have non-zero byteLength"));if(he(e.buffer))return y(new TypeError("view's buffer has been detached"));let r;try{r=function(e,t){var r;return D(e,t),{min:Q(null!==(r=null==e?void 0:e.min)&&void 0!==r?r:1,`${t} has member 'min' that`)}}(t,"options")}catch(e){return y(e)}const n=r.min;if(0===n)return y(new TypeError("options.min must be greater than 0"));if(function(e){return ke(e.constructor)}(e)){if(n>e.byteLength)return y(new RangeError("options.min must be less than or equal to view's byteLength"))}else if(n>e.length)return y(new RangeError("options.min must be less than or equal to view's length"));if(void 0===this._ownerReadableStream)return y(W("read from"));let o,i;const a=p(((e,t)=>{o=e,i=t}));return ht(this,e,n,{_chunkSteps:e=>o({value:e,done:!1}),_closeSteps:e=>o({value:e,done:!0}),_errorSteps:e=>i(e)}),a}releaseLock(){if(!dt(this))throw bt("releaseLock");void 0!==this._ownerReadableStream&&function(e){I(e),pt(e,new TypeError("Reader was released"))}(this)}}function dt(e){return!!a(e)&&!!Object.prototype.hasOwnProperty.call(e,"_readIntoRequests")&&e instanceof ft}function ht(e,t,r,n){const o=e._ownerReadableStream;o._disturbed=!0,"errored"===o._state?n._errorSteps(o._storedError):function(e,t,r,n){const o=e._controlledReadableByteStream,i=t.constructor,a=function(e){return ke(e)?1:e.BYTES_PER_ELEMENT}(i),{byteOffset:s,byteLength:u}=t,l=r*a;let c;try{c=de(t.buffer)}catch(e){return void n._errorSteps(e)}const f={buffer:c,bufferByteLength:c.byteLength,byteOffset:s,byteLength:u,bytesFilled:0,minimumFill:l,elementSize:a,viewConstructor:i,readerType:"byob"};if(e._pendingPullIntos.length>0)return e._pendingPullIntos.push(f),void ut(o,n);if("closed"!==o._state){if(e._queueTotalSize>0){if(Fe(e,f)){const t=Be(f);return $e(e),void n._chunkSteps(t)}if(e._closeRequested){const t=new TypeError("Insufficient bytes to fill elements in the given buffer");return Xe(e,t),void n._errorSteps(t)}}e._pendingPullIntos.push(f),ut(o,n),Ie(e)}else{const e=new i(f.buffer,f.byteOffset,0);n._closeSteps(e)}}(o._readableStreamController,t,r,n)}function pt(e,t){const r=e._readIntoRequests;e._readIntoRequests=new O,r.forEach((e=>{e._errorSteps(t)}))}function bt(e){return new TypeError(`ReadableStreamBYOBReader.prototype.${e} can only be used on a ReadableStreamBYOBReader`)}function yt(e,t){const{highWaterMark:r}=e;if(void 0===r)return t;if(Te(r)||r<0)throw new RangeError("Invalid highWaterMark");return r}function mt(e){const{size:t}=e;return t||(()=>1)}function vt(e,t){D(e,t);const r=null==e?void 0:e.highWaterMark,n=null==e?void 0:e.size;return{highWaterMark:void 0===r?void 0:Y(r),size:void 0===n?void 0:_t(n,`${t} has member 'size' that`)}}function _t(e,t){return $(e,t),t=>Y(e(t))}function gt(e,t,r){return $(e,r),r=>P(e,t,[r])}function wt(e,t,r){return $(e,r),()=>P(e,t,[])}function St(e,t,r){return $(e,r),r=>T(e,t,[r])}function Rt(e,t,r){return $(e,r),(r,n)=>P(e,t,[r,n])}function Tt(e,t){if(!kt(e))throw new TypeError(`${t} is not a WritableStream.`)}Object.defineProperties(ft.prototype,{cancel:{enumerable:!0},read:{enumerable:!0},releaseLock:{enumerable:!0},closed:{enumerable:!0}}),u(ft.prototype.cancel,"cancel"),u(ft.prototype.read,"read"),u(ft.prototype.releaseLock,"releaseLock"),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(ft.prototype,Symbol.toStringTag,{value:"ReadableStreamBYOBReader",configurable:!0});const Pt="function"==typeof AbortController;class Ot{constructor(e={},t={}){void 0===e?e=null:N(e,"First parameter");const r=vt(t,"Second parameter"),n=function(e,t){D(e,t);const r=null==e?void 0:e.abort,n=null==e?void 0:e.close,o=null==e?void 0:e.start,i=null==e?void 0:e.type,a=null==e?void 0:e.write;return{abort:void 0===r?void 0:gt(r,e,`${t} has member 'abort' that`),close:void 0===n?void 0:wt(n,e,`${t} has member 'close' that`),start:void 0===o?void 0:St(o,e,`${t} has member 'start' that`),write:void 0===a?void 0:Rt(a,e,`${t} has member 'write' that`),type:i}}(e,"First parameter");if(qt(this),void 0!==n.type)throw new RangeError("Invalid type is specified");const o=mt(r);!function(e,t,r,n){const o=Object.create(Ht.prototype);let i,a,s,u;i=void 0!==t.start?()=>t.start(o):()=>{},a=void 0!==t.write?e=>t.write(e,o):()=>b(void 0),s=void 0!==t.close?()=>t.close():()=>b(void 0),u=void 0!==t.abort?e=>t.abort(e):()=>b(void 0),Jt(e,o,i,a,s,u,r,n)}(this,n,yt(r,1),o)}get locked(){if(!kt(this))throw tr("locked");return Et(this)}abort(e=void 0){return kt(this)?Et(this)?y(new TypeError("Cannot abort a stream that already has a writer")):Ct(this,e):y(tr("abort"))}close(){return kt(this)?Et(this)?y(new TypeError("Cannot close a stream that already has a writer")):Ut(this)?y(new TypeError("Cannot close an already-closing stream")):xt(this):y(tr("close"))}getWriter(){if(!kt(this))throw tr("getWriter");return jt(this)}}function jt(e){return new Lt(e)}function qt(e){e._state="writable",e._storedError=void 0,e._writer=void 0,e._writableStreamController=void 0,e._writeRequests=new O,e._inFlightWriteRequest=void 0,e._closeRequest=void 0,e._inFlightCloseRequest=void 0,e._pendingAbortRequest=void 0,e._backpressure=!1}function kt(e){return!!a(e)&&!!Object.prototype.hasOwnProperty.call(e,"_writableStreamController")&&e instanceof Ot}function Et(e){return void 0!==e._writer}function Ct(e,t){var r;if("closed"===e._state||"errored"===e._state)return b(void 0);e._writableStreamController._abortReason=t,null===(r=e._writableStreamController._abortController)||void 0===r||r.abort(t);const n=e._state;if("closed"===n||"errored"===n)return b(void 0);if(void 0!==e._pendingAbortRequest)return e._pendingAbortRequest._promise;let o=!1;"erroring"===n&&(o=!0,t=void 0);const i=p(((r,n)=>{e._pendingAbortRequest={_promise:void 0,_resolve:r,_reject:n,_reason:t,_wasAlreadyErroring:o}}));return e._pendingAbortRequest._promise=i,o||It(e,t),i}function xt(e){const t=e._state;if("closed"===t||"errored"===t)return y(new TypeError(`The stream (in ${t} state) is not in the writable state and cannot be closed`));const r=p(((t,r)=>{const n={_resolve:t,_reject:r};e._closeRequest=n})),n=e._writer;var o;return void 0!==n&&e._backpressure&&"writable"===t&&hr(n),je(o=e._writableStreamController,Gt,0),Xt(o),r}function At(e,t){"writable"!==e._state?Wt(e):It(e,t)}function It(e,t){const r=e._writableStreamController;e._state="erroring",e._storedError=t;const n=e._writer;void 0!==n&&Dt(n,t),!function(e){return void 0!==e._inFlightWriteRequest||void 0!==e._inFlightCloseRequest}(e)&&r._started&&Wt(e)}function Wt(e){e._state="errored",e._writableStreamController[q]();const t=e._storedError;if(e._writeRequests.forEach((e=>{e._reject(t)})),e._writeRequests=new O,void 0===e._pendingAbortRequest)return void Bt(e);const r=e._pendingAbortRequest;if(e._pendingAbortRequest=void 0,r._wasAlreadyErroring)return r._reject(t),void Bt(e);v(e._writableStreamController[j](r._reason),(()=>(r._resolve(),Bt(e),null)),(t=>(r._reject(t),Bt(e),null)))}function Ut(e){return void 0!==e._closeRequest||void 0!==e._inFlightCloseRequest}function Bt(e){void 0!==e._closeRequest&&(e._closeRequest._reject(e._storedError),e._closeRequest=void 0);const t=e._writer;void 0!==t&&sr(t,e._storedError)}function Mt(e,t){const r=e._writer;void 0!==r&&t!==e._backpressure&&(t?function(e){lr(e)}(r):hr(r)),e._backpressure=t}Object.defineProperties(Ot.prototype,{abort:{enumerable:!0},close:{enumerable:!0},getWriter:{enumerable:!0},locked:{enumerable:!0}}),u(Ot.prototype.abort,"abort"),u(Ot.prototype.close,"close"),u(Ot.prototype.getWriter,"getWriter"),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(Ot.prototype,Symbol.toStringTag,{value:"WritableStream",configurable:!0});class Lt{constructor(e){if(G(e,1,"WritableStreamDefaultWriter"),Tt(e,"First parameter"),Et(e))throw new TypeError("This stream has already been locked for exclusive writing by another writer");this._ownerWritableStream=e,e._writer=this;const t=e._state;if("writable"===t)!Ut(e)&&e._backpressure?lr(this):fr(this),ir(this);else if("erroring"===t)cr(this,e._storedError),ir(this);else if("closed"===t)fr(this),ir(this),ur(this);else{const t=e._storedError;cr(this,t),ar(this,t)}}get closed(){return zt(this)?this._closedPromise:y(nr("closed"))}get desiredSize(){if(!zt(this))throw nr("desiredSize");if(void 0===this._ownerWritableStream)throw or("desiredSize");return function(e){const t=e._ownerWritableStream,r=t._state;return"errored"===r||"erroring"===r?null:"closed"===r?0:Vt(t._writableStreamController)}(this)}get ready(){return zt(this)?this._readyPromise:y(nr("ready"))}abort(e=void 0){return zt(this)?void 0===this._ownerWritableStream?y(or("abort")):function(e,t){return Ct(e._ownerWritableStream,t)}(this,e):y(nr("abort"))}close(){if(!zt(this))return y(nr("close"));const e=this._ownerWritableStream;return void 0===e?y(or("close")):Ut(e)?y(new TypeError("Cannot close an already-closing stream")):Ft(this)}releaseLock(){if(!zt(this))throw nr("releaseLock");void 0!==this._ownerWritableStream&&$t(this)}write(e=void 0){return zt(this)?void 0===this._ownerWritableStream?y(or("write to")):Nt(this,e):y(nr("write"))}}function zt(e){return!!a(e)&&!!Object.prototype.hasOwnProperty.call(e,"_ownerWritableStream")&&e instanceof Lt}function Ft(e){return xt(e._ownerWritableStream)}function Dt(e,t){"pending"===e._readyPromiseState?dr(e,t):function(e,t){cr(e,t)}(e,t)}function $t(e){const t=e._ownerWritableStream,r=new TypeError("Writer was released and can no longer be used to monitor the stream's closedness");Dt(e,r),function(e,t){"pending"===e._closedPromiseState?sr(e,t):function(e,t){ar(e,t)}(e,t)}(e,r),t._writer=void 0,e._ownerWritableStream=void 0}function Nt(e,t){const r=e._ownerWritableStream,n=r._writableStreamController,o=function(e,t){try{return e._strategySizeAlgorithm(t)}catch(t){return Kt(e,t),1}}(n,t);if(r!==e._ownerWritableStream)return y(or("write to"));const i=r._state;if("errored"===i)return y(r._storedError);if(Ut(r)||"closed"===i)return y(new TypeError("The stream is closing or closed and cannot be written to"));if("erroring"===i)return y(r._storedError);const a=function(e){return p(((t,r)=>{const n={_resolve:t,_reject:r};e._writeRequests.push(n)}))}(r);return function(e,t,r){try{je(e,t,r)}catch(t){return void Kt(e,t)}const n=e._controlledWritableStream;Ut(n)||"writable"!==n._state||Mt(n,Zt(e)),Xt(e)}(n,t,o),a}Object.defineProperties(Lt.prototype,{abort:{enumerable:!0},close:{enumerable:!0},releaseLock:{enumerable:!0},write:{enumerable:!0},closed:{enumerable:!0},desiredSize:{enumerable:!0},ready:{enumerable:!0}}),u(Lt.prototype.abort,"abort"),u(Lt.prototype.close,"close"),u(Lt.prototype.releaseLock,"releaseLock"),u(Lt.prototype.write,"write"),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(Lt.prototype,Symbol.toStringTag,{value:"WritableStreamDefaultWriter",configurable:!0});const Gt={};class Ht{constructor(){throw new TypeError("Illegal constructor")}get abortReason(){if(!Yt(this))throw rr("abortReason");return this._abortReason}get signal(){if(!Yt(this))throw rr("signal");if(void 0===this._abortController)throw new TypeError("WritableStreamDefaultController.prototype.signal is not supported");return this._abortController.signal}error(e=void 0){if(!Yt(this))throw rr("error");"writable"===this._controlledWritableStream._state&&er(this,e)}[j](e){const t=this._abortAlgorithm(e);return Qt(this),t}[q](){qe(this)}}function Yt(e){return!!a(e)&&!!Object.prototype.hasOwnProperty.call(e,"_controlledWritableStream")&&e instanceof Ht}function Jt(e,t,r,n,o,i,a,s){t._controlledWritableStream=e,e._writableStreamController=t,t._queue=void 0,t._queueTotalSize=void 0,qe(t),t._abortReason=void 0,t._abortController=function(){if(Pt)return new AbortController}(),t._started=!1,t._strategySizeAlgorithm=s,t._strategyHWM=a,t._writeAlgorithm=n,t._closeAlgorithm=o,t._abortAlgorithm=i;const u=Zt(t);Mt(e,u),v(b(r()),(()=>(t._started=!0,Xt(t),null)),(r=>(t._started=!0,At(e,r),null)))}function Qt(e){e._writeAlgorithm=void 0,e._closeAlgorithm=void 0,e._abortAlgorithm=void 0,e._strategySizeAlgorithm=void 0}function Vt(e){return e._strategyHWM-e._queueTotalSize}function Xt(e){const t=e._controlledWritableStream;if(!e._started)return;if(void 0!==t._inFlightWriteRequest)return;if("erroring"===t._state)return void Wt(t);if(0===e._queue.length)return;const r=e._queue.peek().value;r===Gt?function(e){const t=e._controlledWritableStream;(function(e){e._inFlightCloseRequest=e._closeRequest,e._closeRequest=void 0})(t),Oe(e);const r=e._closeAlgorithm();Qt(e),v(r,(()=>(function(e){e._inFlightCloseRequest._resolve(void 0),e._inFlightCloseRequest=void 0,"erroring"===e._state&&(e._storedError=void 0,void 0!==e._pendingAbortRequest&&(e._pendingAbortRequest._resolve(),e._pendingAbortRequest=void 0)),e._state="closed";const t=e._writer;void 0!==t&&ur(t)}(t),null)),(e=>(function(e,t){e._inFlightCloseRequest._reject(t),e._inFlightCloseRequest=void 0,void 0!==e._pendingAbortRequest&&(e._pendingAbortRequest._reject(t),e._pendingAbortRequest=void 0),At(e,t)}(t,e),null)))}(e):function(e,t){const r=e._controlledWritableStream;!function(e){e._inFlightWriteRequest=e._writeRequests.shift()}(r),v(e._writeAlgorithm(t),(()=>{!function(e){e._inFlightWriteRequest._resolve(void 0),e._inFlightWriteRequest=void 0}(r);const t=r._state;if(Oe(e),!Ut(r)&&"writable"===t){const t=Zt(e);Mt(r,t)}return Xt(e),null}),(t=>("writable"===r._state&&Qt(e),function(e,t){e._inFlightWriteRequest._reject(t),e._inFlightWriteRequest=void 0,At(e,t)}(r,t),null)))}(e,r)}function Kt(e,t){"writable"===e._controlledWritableStream._state&&er(e,t)}function Zt(e){return Vt(e)<=0}function er(e,t){const r=e._controlledWritableStream;Qt(e),It(r,t)}function tr(e){return new TypeError(`WritableStream.prototype.${e} can only be used on a WritableStream`)}function rr(e){return new TypeError(`WritableStreamDefaultController.prototype.${e} can only be used on a WritableStreamDefaultController`)}function nr(e){return new TypeError(`WritableStreamDefaultWriter.prototype.${e} can only be used on a WritableStreamDefaultWriter`)}function or(e){return new TypeError("Cannot "+e+" a stream using a released writer")}function ir(e){e._closedPromise=p(((t,r)=>{e._closedPromise_resolve=t,e._closedPromise_reject=r,e._closedPromiseState="pending"}))}function ar(e,t){ir(e),sr(e,t)}function sr(e,t){void 0!==e._closedPromise_reject&&(S(e._closedPromise),e._closedPromise_reject(t),e._closedPromise_resolve=void 0,e._closedPromise_reject=void 0,e._closedPromiseState="rejected")}function ur(e){void 0!==e._closedPromise_resolve&&(e._closedPromise_resolve(void 0),e._closedPromise_resolve=void 0,e._closedPromise_reject=void 0,e._closedPromiseState="resolved")}function lr(e){e._readyPromise=p(((t,r)=>{e._readyPromise_resolve=t,e._readyPromise_reject=r})),e._readyPromiseState="pending"}function cr(e,t){lr(e),dr(e,t)}function fr(e){lr(e),hr(e)}function dr(e,t){void 0!==e._readyPromise_reject&&(S(e._readyPromise),e._readyPromise_reject(t),e._readyPromise_resolve=void 0,e._readyPromise_reject=void 0,e._readyPromiseState="rejected")}function hr(e){void 0!==e._readyPromise_resolve&&(e._readyPromise_resolve(void 0),e._readyPromise_resolve=void 0,e._readyPromise_reject=void 0,e._readyPromiseState="fulfilled")}Object.defineProperties(Ht.prototype,{abortReason:{enumerable:!0},signal:{enumerable:!0},error:{enumerable:!0}}),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(Ht.prototype,Symbol.toStringTag,{value:"WritableStreamDefaultController",configurable:!0});const pr="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof global?global:void 0,br=function(){const e=null==pr?void 0:pr.DOMException;return function(e){if("function"!=typeof e&&"object"!=typeof e)return!1;if("DOMException"!==e.name)return!1;try{return new e,!0}catch(e){return!1}}(e)?e:void 0}()||function(){const e=function(e,t){this.message=e||"",this.name=t||"Error",Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)};return u(e,"DOMException"),e.prototype=Object.create(Error.prototype),Object.defineProperty(e.prototype,"constructor",{value:e,writable:!0,configurable:!0}),e}();function yr(e,t,r,n,o,a){const s=X(e),u=jt(t);e._disturbed=!0;let l=!1,c=b(void 0);return p(((f,d)=>{let h;if(void 0!==a){if(h=()=>{const r=void 0!==a.reason?a.reason:new br("Aborted","AbortError"),i=[];n||i.push((()=>"writable"===t._state?Ct(t,r):b(void 0))),o||i.push((()=>"readable"===e._state?Fr(e,r):b(void 0))),j((()=>Promise.all(i.map((e=>e())))),!0,r)},a.aborted)return void h();a.addEventListener("abort",h)}var w,R,T;if(O(e,s._closedPromise,(e=>(n?q(!0,e):j((()=>Ct(t,e)),!0,e),null))),O(t,u._closedPromise,(t=>(o?q(!0,t):j((()=>Fr(e,t)),!0,t),null))),w=e,R=s._closedPromise,T=()=>(r?q():j((()=>function(e){const t=e._ownerWritableStream,r=t._state;return Ut(t)||"closed"===r?b(void 0):"errored"===r?y(t._storedError):Ft(e)}(u))),null),"closed"===w._state?T():_(R,T),Ut(t)||"closed"===t._state){const t=new TypeError("the destination writable stream closed before all data could be piped to it");o?q(!0,t):j((()=>Fr(e,t)),!0,t)}function P(){const e=c;return m(c,(()=>e!==c?P():void 0))}function O(e,t,r){"errored"===e._state?r(e._storedError):g(t,r)}function j(e,r,n){function o(){return v(e(),(()=>k(r,n)),(e=>k(!0,e))),null}l||(l=!0,"writable"!==t._state||Ut(t)?o():_(P(),o))}function q(e,r){l||(l=!0,"writable"!==t._state||Ut(t)?k(e,r):_(P(),(()=>k(e,r))))}function k(e,t){return $t(u),I(s),void 0!==a&&a.removeEventListener("abort",h),e?d(t):f(void 0),null}S(p(((e,t)=>{!function r(n){n?e():m(l?b(!0):m(u._readyPromise,(()=>p(((e,t)=>{oe(s,{_chunkSteps:t=>{c=m(Nt(u,t),void 0,i),e(!1)},_closeSteps:()=>e(!0),_errorSteps:t})})))),r,t)}(!1)})))}))}class mr{constructor(){throw new TypeError("Illegal constructor")}get desiredSize(){if(!vr(this))throw qr("desiredSize");return Pr(this)}close(){if(!vr(this))throw qr("close");if(!Or(this))throw new TypeError("The stream is not in a state that permits close");Sr(this)}enqueue(e=void 0){if(!vr(this))throw qr("enqueue");if(!Or(this))throw new TypeError("The stream is not in a state that permits enqueue");return Rr(this,e)}error(e=void 0){if(!vr(this))throw qr("error");Tr(this,e)}[k](e){qe(this);const t=this._cancelAlgorithm(e);return wr(this),t}[E](e){const t=this._controlledReadableStream;if(this._queue.length>0){const r=Oe(this);this._closeRequested&&0===this._queue.length?(wr(this),Dr(t)):_r(this),e._chunkSteps(r)}else K(t,e),_r(this)}[C](){}}function vr(e){return!!a(e)&&!!Object.prototype.hasOwnProperty.call(e,"_controlledReadableStream")&&e instanceof mr}function _r(e){gr(e)&&(e._pulling?e._pullAgain=!0:(e._pulling=!0,v(e._pullAlgorithm(),(()=>(e._pulling=!1,e._pullAgain&&(e._pullAgain=!1,_r(e)),null)),(t=>(Tr(e,t),null)))))}function gr(e){const t=e._controlledReadableStream;return!!Or(e)&&!!e._started&&(!!(zr(t)&&ee(t)>0)||Pr(e)>0)}function wr(e){e._pullAlgorithm=void 0,e._cancelAlgorithm=void 0,e._strategySizeAlgorithm=void 0}function Sr(e){if(!Or(e))return;const t=e._controlledReadableStream;e._closeRequested=!0,0===e._queue.length&&(wr(e),Dr(t))}function Rr(e,t){if(!Or(e))return;const r=e._controlledReadableStream;if(zr(r)&&ee(r)>0)Z(r,t,!1);else{let r;try{r=e._strategySizeAlgorithm(t)}catch(t){throw Tr(e,t),t}try{je(e,t,r)}catch(t){throw Tr(e,t),t}}_r(e)}function Tr(e,t){const r=e._controlledReadableStream;"readable"===r._state&&(qe(e),wr(e),$r(r,t))}function Pr(e){const t=e._controlledReadableStream._state;return"errored"===t?null:"closed"===t?0:e._strategyHWM-e._queueTotalSize}function Or(e){const t=e._controlledReadableStream._state;return!e._closeRequested&&"readable"===t}function jr(e,t,r,n,o,i,a){t._controlledReadableStream=e,t._queue=void 0,t._queueTotalSize=void 0,qe(t),t._started=!1,t._closeRequested=!1,t._pullAgain=!1,t._pulling=!1,t._strategySizeAlgorithm=a,t._strategyHWM=i,t._pullAlgorithm=n,t._cancelAlgorithm=o,e._readableStreamController=t,v(b(r()),(()=>(t._started=!0,_r(t),null)),(e=>(Tr(t,e),null)))}function qr(e){return new TypeError(`ReadableStreamDefaultController.prototype.${e} can only be used on a ReadableStreamDefaultController`)}function kr(e){return a(t=e)&&void 0!==t.getReader?function(e){let t;return t=Ur(i,(function(){let r;try{r=e.read()}catch(r){return y(r)}return w(r,(e=>{if(!a(e))throw new TypeError("The promise returned by the reader.read() method must fulfill with an object");if(e.done)Sr(t._readableStreamController);else{const r=e.value;Rr(t._readableStreamController,r)}}))}),(function(t){try{return b(e.cancel(t))}catch(t){return y(t)}}),0),t}(e.getReader()):function(e){let t;const r=ve(e,"async");return t=Ur(i,(function(){let e;try{e=_e(r)}catch(e){return y(e)}return w(b(e),(e=>{if(!a(e))throw new TypeError("The promise returned by the iterator.next() method must fulfill with an object");if(e.done)Sr(t._readableStreamController);else{const r=e.value;Rr(t._readableStreamController,r)}}))}),(function(e){const t=r.iterator;let n;try{n=be(t,"return")}catch(e){return y(e)}return void 0===n?b(void 0):w(P(n,t,[e]),(e=>{if(!a(e))throw new TypeError("The promise returned by the iterator.return() method must fulfill with an object")}))}),0),t}(e);var t}function Er(e,t,r){return $(e,r),r=>P(e,t,[r])}function Cr(e,t,r){return $(e,r),r=>P(e,t,[r])}function xr(e,t,r){return $(e,r),r=>T(e,t,[r])}function Ar(e,t){if("bytes"!=(e=`${e}`))throw new TypeError(`${t} '${e}' is not a valid enumeration value for ReadableStreamType`);return e}function Ir(e,t){D(e,t);const r=null==e?void 0:e.preventAbort,n=null==e?void 0:e.preventCancel,o=null==e?void 0:e.preventClose,i=null==e?void 0:e.signal;return void 0!==i&&function(e,t){if(!function(e){if("object"!=typeof e||null===e)return!1;try{return"boolean"==typeof e.aborted}catch(e){return!1}}(e))throw new TypeError(`${t} is not an AbortSignal.`)}(i,`${t} has member 'signal' that`),{preventAbort:Boolean(r),preventCancel:Boolean(n),preventClose:Boolean(o),signal:i}}Object.defineProperties(mr.prototype,{close:{enumerable:!0},enqueue:{enumerable:!0},error:{enumerable:!0},desiredSize:{enumerable:!0}}),u(mr.prototype.close,"close"),u(mr.prototype.enqueue,"enqueue"),u(mr.prototype.error,"error"),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(mr.prototype,Symbol.toStringTag,{value:"ReadableStreamDefaultController",configurable:!0});class Wr{constructor(e={},t={}){void 0===e?e=null:N(e,"First parameter");const r=vt(t,"Second parameter"),n=function(e,t){D(e,t);const r=e,n=null==r?void 0:r.autoAllocateChunkSize,o=null==r?void 0:r.cancel,i=null==r?void 0:r.pull,a=null==r?void 0:r.start,s=null==r?void 0:r.type;return{autoAllocateChunkSize:void 0===n?void 0:Q(n,`${t} has member 'autoAllocateChunkSize' that`),cancel:void 0===o?void 0:Er(o,r,`${t} has member 'cancel' that`),pull:void 0===i?void 0:Cr(i,r,`${t} has member 'pull' that`),start:void 0===a?void 0:xr(a,r,`${t} has member 'start' that`),type:void 0===s?void 0:Ar(s,`${t} has member 'type' that`)}}(e,"First parameter");if(Mr(this),"bytes"===n.type){if(void 0!==r.size)throw new RangeError("The strategy for a byte stream cannot have a size function");!function(e,t,r){const n=Object.create(Ce.prototype);let o,i,a;o=void 0!==t.start?()=>t.start(n):()=>{},i=void 0!==t.pull?()=>t.pull(n):()=>b(void 0),a=void 0!==t.cancel?e=>t.cancel(e):()=>b(void 0);const s=t.autoAllocateChunkSize;if(0===s)throw new TypeError("autoAllocateChunkSize must be greater than 0");nt(e,n,o,i,a,r,s)}(this,n,yt(r,0))}else{const e=mt(r);!function(e,t,r,n){const o=Object.create(mr.prototype);let i,a,s;i=void 0!==t.start?()=>t.start(o):()=>{},a=void 0!==t.pull?()=>t.pull(o):()=>b(void 0),s=void 0!==t.cancel?e=>t.cancel(e):()=>b(void 0),jr(e,o,i,a,s,r,n)}(this,n,yt(r,1),e)}}get locked(){if(!Lr(this))throw Nr("locked");return zr(this)}cancel(e=void 0){return Lr(this)?zr(this)?y(new TypeError("Cannot cancel a stream that already has a reader")):Fr(this,e):y(Nr("cancel"))}getReader(e=void 0){if(!Lr(this))throw Nr("getReader");return void 0===function(e,t){D(e,t);const r=null==e?void 0:e.mode;return{mode:void 0===r?void 0:at(r,`${t} has member 'mode' that`)}}(e,"First parameter").mode?X(this):st(this)}pipeThrough(e,t={}){if(!Lr(this))throw Nr("pipeThrough");G(e,1,"pipeThrough");const r=function(e,t){D(e,t);const r=null==e?void 0:e.readable;H(r,"readable","ReadableWritablePair"),V(r,`${t} has member 'readable' that`);const n=null==e?void 0:e.writable;return H(n,"writable","ReadableWritablePair"),Tt(n,`${t} has member 'writable' that`),{readable:r,writable:n}}(e,"First parameter"),n=Ir(t,"Second parameter");if(zr(this))throw new TypeError("ReadableStream.prototype.pipeThrough cannot be used on a locked ReadableStream");if(Et(r.writable))throw new TypeError("ReadableStream.prototype.pipeThrough cannot be used on a locked WritableStream");return S(yr(this,r.writable,n.preventClose,n.preventAbort,n.preventCancel,n.signal)),r.readable}pipeTo(e,t={}){if(!Lr(this))return y(Nr("pipeTo"));if(void 0===e)return y("Parameter 1 is required in 'pipeTo'.");if(!kt(e))return y(new TypeError("ReadableStream.prototype.pipeTo's first argument must be a WritableStream"));let r;try{r=Ir(t,"Second parameter")}catch(e){return y(e)}return zr(this)?y(new TypeError("ReadableStream.prototype.pipeTo cannot be used on a locked ReadableStream")):Et(e)?y(new TypeError("ReadableStream.prototype.pipeTo cannot be used on a locked WritableStream")):yr(this,e,r.preventClose,r.preventAbort,r.preventCancel,r.signal)}tee(){if(!Lr(this))throw Nr("tee");return ce(function(e){return xe(e._readableStreamController)?function(e){let t,r,n,o,i,a=X(e),s=!1,u=!1,l=!1,c=!1,f=!1;const d=p((e=>{i=e}));function h(e){g(e._closedPromise,(t=>(e!==a||(Xe(n._readableStreamController,t),Xe(o._readableStreamController,t),c&&f||i(void 0)),null)))}function y(){dt(a)&&(I(a),a=X(e),h(a)),oe(a,{_chunkSteps:t=>{R((()=>{u=!1,l=!1;const r=t;let a=t;if(!c&&!f)try{a=Pe(t)}catch(t){return Xe(n._readableStreamController,t),Xe(o._readableStreamController,t),void i(Fr(e,t))}c||Ve(n._readableStreamController,r),f||Ve(o._readableStreamController,a),s=!1,u?v():l&&_()}))},_closeSteps:()=>{s=!1,c||Qe(n._readableStreamController),f||Qe(o._readableStreamController),n._readableStreamController._pendingPullIntos.length>0&&tt(n._readableStreamController,0),o._readableStreamController._pendingPullIntos.length>0&&tt(o._readableStreamController,0),c&&f||i(void 0)},_errorSteps:()=>{s=!1}})}function m(t,r){ne(a)&&(I(a),a=st(e),h(a));const d=r?o:n,p=r?n:o;ht(a,t,1,{_chunkSteps:t=>{R((()=>{u=!1,l=!1;const n=r?f:c;if(r?c:f)n||rt(d._readableStreamController,t);else{let r;try{r=Pe(t)}catch(t){return Xe(d._readableStreamController,t),Xe(p._readableStreamController,t),void i(Fr(e,t))}n||rt(d._readableStreamController,t),Ve(p._readableStreamController,r)}s=!1,u?v():l&&_()}))},_closeSteps:e=>{s=!1;const t=r?f:c,n=r?c:f;t||Qe(d._readableStreamController),n||Qe(p._readableStreamController),void 0!==e&&(t||rt(d._readableStreamController,e),!n&&p._readableStreamController._pendingPullIntos.length>0&&tt(p._readableStreamController,0)),t&&n||i(void 0)},_errorSteps:()=>{s=!1}})}function v(){if(s)return u=!0,b(void 0);s=!0;const e=Ze(n._readableStreamController);return null===e?y():m(e._view,!1),b(void 0)}function _(){if(s)return l=!0,b(void 0);s=!0;const e=Ze(o._readableStreamController);return null===e?y():m(e._view,!0),b(void 0)}function w(){}return n=Br(w,v,(function(n){if(c=!0,t=n,f){const n=ce([t,r]),o=Fr(e,n);i(o)}return d})),o=Br(w,_,(function(n){if(f=!0,r=n,c){const n=ce([t,r]),o=Fr(e,n);i(o)}return d})),h(a),[n,o]}(e):function(e){const t=X(e);let r,n,o,i,a,s=!1,u=!1,l=!1,c=!1;const f=p((e=>{a=e}));function d(){return s?(u=!0,b(void 0)):(s=!0,oe(t,{_chunkSteps:e=>{R((()=>{u=!1;const t=e,r=e;l||Rr(o._readableStreamController,t),c||Rr(i._readableStreamController,r),s=!1,u&&d()}))},_closeSteps:()=>{s=!1,l||Sr(o._readableStreamController),c||Sr(i._readableStreamController),l&&c||a(void 0)},_errorSteps:()=>{s=!1}}),b(void 0))}function h(){}return o=Ur(h,d,(function(t){if(l=!0,r=t,c){const t=ce([r,n]),o=Fr(e,t);a(o)}return f})),i=Ur(h,d,(function(t){if(c=!0,n=t,l){const t=ce([r,n]),o=Fr(e,t);a(o)}return f})),g(t._closedPromise,(e=>(Tr(o._readableStreamController,e),Tr(i._readableStreamController,e),l&&c||a(void 0),null))),[o,i]}(e)}(this))}values(e=void 0){if(!Lr(this))throw Nr("values");return function(e,t){const r=X(e),n=new ge(r,t),o=Object.create(we);return o._asyncIteratorImpl=n,o}(this,function(e){D(e,"First parameter");const t=null==e?void 0:e.preventCancel;return{preventCancel:Boolean(t)}}(e).preventCancel)}[me](e){return this.values(e)}static from(e){return kr(e)}}function Ur(e,t,r,n=1,o=()=>1){const i=Object.create(Wr.prototype);return Mr(i),jr(i,Object.create(mr.prototype),e,t,r,n,o),i}function Br(e,t,r){const n=Object.create(Wr.prototype);return Mr(n),nt(n,Object.create(Ce.prototype),e,t,r,0,void 0),n}function Mr(e){e._state="readable",e._reader=void 0,e._storedError=void 0,e._disturbed=!1}function Lr(e){return!!a(e)&&!!Object.prototype.hasOwnProperty.call(e,"_readableStreamController")&&e instanceof Wr}function zr(e){return void 0!==e._reader}function Fr(e,t){if(e._disturbed=!0,"closed"===e._state)return b(void 0);if("errored"===e._state)return y(e._storedError);Dr(e);const r=e._reader;if(void 0!==r&&dt(r)){const e=r._readIntoRequests;r._readIntoRequests=new O,e.forEach((e=>{e._closeSteps(void 0)}))}return w(e._readableStreamController[k](t),i)}function Dr(e){e._state="closed";const t=e._reader;if(void 0!==t&&(L(t),ne(t))){const e=t._readRequests;t._readRequests=new O,e.forEach((e=>{e._closeSteps()}))}}function $r(e,t){e._state="errored",e._storedError=t;const r=e._reader;void 0!==r&&(M(r,t),ne(r)?ie(r,t):pt(r,t))}function Nr(e){return new TypeError(`ReadableStream.prototype.${e} can only be used on a ReadableStream`)}function Gr(e,t){D(e,t);const r=null==e?void 0:e.highWaterMark;return H(r,"highWaterMark","QueuingStrategyInit"),{highWaterMark:Y(r)}}Object.defineProperties(Wr,{from:{enumerable:!0}}),Object.defineProperties(Wr.prototype,{cancel:{enumerable:!0},getReader:{enumerable:!0},pipeThrough:{enumerable:!0},pipeTo:{enumerable:!0},tee:{enumerable:!0},values:{enumerable:!0},locked:{enumerable:!0}}),u(Wr.from,"from"),u(Wr.prototype.cancel,"cancel"),u(Wr.prototype.getReader,"getReader"),u(Wr.prototype.pipeThrough,"pipeThrough"),u(Wr.prototype.pipeTo,"pipeTo"),u(Wr.prototype.tee,"tee"),u(Wr.prototype.values,"values"),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(Wr.prototype,Symbol.toStringTag,{value:"ReadableStream",configurable:!0}),Object.defineProperty(Wr.prototype,me,{value:Wr.prototype.values,writable:!0,configurable:!0});const Hr=e=>e.byteLength;u(Hr,"size");class Yr{constructor(e){G(e,1,"ByteLengthQueuingStrategy"),e=Gr(e,"First parameter"),this._byteLengthQueuingStrategyHighWaterMark=e.highWaterMark}get highWaterMark(){if(!Qr(this))throw Jr("highWaterMark");return this._byteLengthQueuingStrategyHighWaterMark}get size(){if(!Qr(this))throw Jr("size");return Hr}}function Jr(e){return new TypeError(`ByteLengthQueuingStrategy.prototype.${e} can only be used on a ByteLengthQueuingStrategy`)}function Qr(e){return!!a(e)&&!!Object.prototype.hasOwnProperty.call(e,"_byteLengthQueuingStrategyHighWaterMark")&&e instanceof Yr}Object.defineProperties(Yr.prototype,{highWaterMark:{enumerable:!0},size:{enumerable:!0}}),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(Yr.prototype,Symbol.toStringTag,{value:"ByteLengthQueuingStrategy",configurable:!0});const Vr=()=>1;u(Vr,"size");class Xr{constructor(e){G(e,1,"CountQueuingStrategy"),e=Gr(e,"First parameter"),this._countQueuingStrategyHighWaterMark=e.highWaterMark}get highWaterMark(){if(!Zr(this))throw Kr("highWaterMark");return this._countQueuingStrategyHighWaterMark}get size(){if(!Zr(this))throw Kr("size");return Vr}}function Kr(e){return new TypeError(`CountQueuingStrategy.prototype.${e} can only be used on a CountQueuingStrategy`)}function Zr(e){return!!a(e)&&!!Object.prototype.hasOwnProperty.call(e,"_countQueuingStrategyHighWaterMark")&&e instanceof Xr}function en(e,t,r){return $(e,r),r=>P(e,t,[r])}function tn(e,t,r){return $(e,r),r=>T(e,t,[r])}function rn(e,t,r){return $(e,r),(r,n)=>P(e,t,[r,n])}function nn(e,t,r){return $(e,r),r=>P(e,t,[r])}Object.defineProperties(Xr.prototype,{highWaterMark:{enumerable:!0},size:{enumerable:!0}}),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(Xr.prototype,Symbol.toStringTag,{value:"CountQueuingStrategy",configurable:!0});class on{constructor(e={},t={},r={}){void 0===e&&(e=null);const n=vt(t,"Second parameter"),o=vt(r,"Third parameter"),i=function(e,t){D(e,t);const r=null==e?void 0:e.cancel,n=null==e?void 0:e.flush,o=null==e?void 0:e.readableType,i=null==e?void 0:e.start,a=null==e?void 0:e.transform,s=null==e?void 0:e.writableType;return{cancel:void 0===r?void 0:nn(r,e,`${t} has member 'cancel' that`),flush:void 0===n?void 0:en(n,e,`${t} has member 'flush' that`),readableType:o,start:void 0===i?void 0:tn(i,e,`${t} has member 'start' that`),transform:void 0===a?void 0:rn(a,e,`${t} has member 'transform' that`),writableType:s}}(e,"First parameter");if(void 0!==i.readableType)throw new RangeError("Invalid readableType specified");if(void 0!==i.writableType)throw new RangeError("Invalid writableType specified");const a=yt(o,0),s=mt(o),u=yt(n,1),l=mt(n);let c;!function(e,t,r,n,o,i){function a(){return t}e._writable=function(e,t,r,n,o=1,i=()=>1){const a=Object.create(Ot.prototype);return qt(a),Jt(a,Object.create(Ht.prototype),e,t,r,n,o,i),a}(a,(function(t){return function(e,t){const r=e._transformStreamController;return e._backpressure?w(e._backpressureChangePromise,(()=>{const n=e._writable;if("erroring"===n._state)throw n._storedError;return bn(r,t)})):bn(r,t)}(e,t)}),(function(){return function(e){const t=e._transformStreamController;if(void 0!==t._finishPromise)return t._finishPromise;const r=e._readable;t._finishPromise=p(((e,r)=>{t._finishPromise_resolve=e,t._finishPromise_reject=r}));const n=t._flushAlgorithm();return hn(t),v(n,(()=>("errored"===r._state?vn(t,r._storedError):(Sr(r._readableStreamController),mn(t)),null)),(e=>(Tr(r._readableStreamController,e),vn(t,e),null))),t._finishPromise}(e)}),(function(t){return function(e,t){const r=e._transformStreamController;if(void 0!==r._finishPromise)return r._finishPromise;const n=e._readable;r._finishPromise=p(((e,t)=>{r._finishPromise_resolve=e,r._finishPromise_reject=t}));const o=r._cancelAlgorithm(t);return hn(r),v(o,(()=>("errored"===n._state?vn(r,n._storedError):(Tr(n._readableStreamController,t),mn(r)),null)),(e=>(Tr(n._readableStreamController,e),vn(r,e),null))),r._finishPromise}(e,t)}),r,n),e._readable=Ur(a,(function(){return function(e){return cn(e,!1),e._backpressureChangePromise}(e)}),(function(t){return function(e,t){const r=e._transformStreamController;if(void 0!==r._finishPromise)return r._finishPromise;const n=e._writable;r._finishPromise=p(((e,t)=>{r._finishPromise_resolve=e,r._finishPromise_reject=t}));const o=r._cancelAlgorithm(t);return hn(r),v(o,(()=>("errored"===n._state?vn(r,n._storedError):(Kt(n._writableStreamController,t),ln(e),mn(r)),null)),(t=>(Kt(n._writableStreamController,t),ln(e),vn(r,t),null))),r._finishPromise}(e,t)}),o,i),e._backpressure=void 0,e._backpressureChangePromise=void 0,e._backpressureChangePromise_resolve=void 0,cn(e,!0),e._transformStreamController=void 0}(this,p((e=>{c=e})),u,l,a,s),function(e,t){const r=Object.create(fn.prototype);let n,o,i;n=void 0!==t.transform?e=>t.transform(e,r):e=>{try{return pn(r,e),b(void 0)}catch(e){return y(e)}},o=void 0!==t.flush?()=>t.flush(r):()=>b(void 0),i=void 0!==t.cancel?e=>t.cancel(e):()=>b(void 0),function(e,t,r,n,o){t._controlledTransformStream=e,e._transformStreamController=t,t._transformAlgorithm=r,t._flushAlgorithm=n,t._cancelAlgorithm=o,t._finishPromise=void 0,t._finishPromise_resolve=void 0,t._finishPromise_reject=void 0}(e,r,n,o,i)}(this,i),void 0!==i.start?c(i.start(this._transformStreamController)):c(void 0)}get readable(){if(!an(this))throw _n("readable");return this._readable}get writable(){if(!an(this))throw _n("writable");return this._writable}}function an(e){return!!a(e)&&!!Object.prototype.hasOwnProperty.call(e,"_transformStreamController")&&e instanceof on}function sn(e,t){Tr(e._readable._readableStreamController,t),un(e,t)}function un(e,t){hn(e._transformStreamController),Kt(e._writable._writableStreamController,t),ln(e)}function ln(e){e._backpressure&&cn(e,!1)}function cn(e,t){void 0!==e._backpressureChangePromise&&e._backpressureChangePromise_resolve(),e._backpressureChangePromise=p((t=>{e._backpressureChangePromise_resolve=t})),e._backpressure=t}Object.defineProperties(on.prototype,{readable:{enumerable:!0},writable:{enumerable:!0}}),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(on.prototype,Symbol.toStringTag,{value:"TransformStream",configurable:!0});class fn{constructor(){throw new TypeError("Illegal constructor")}get desiredSize(){if(!dn(this))throw yn("desiredSize");return Pr(this._controlledTransformStream._readable._readableStreamController)}enqueue(e=void 0){if(!dn(this))throw yn("enqueue");pn(this,e)}error(e=void 0){if(!dn(this))throw yn("error");var t;t=e,sn(this._controlledTransformStream,t)}terminate(){if(!dn(this))throw yn("terminate");!function(e){const t=e._controlledTransformStream;Sr(t._readable._readableStreamController),un(t,new TypeError("TransformStream terminated"))}(this)}}function dn(e){return!!a(e)&&!!Object.prototype.hasOwnProperty.call(e,"_controlledTransformStream")&&e instanceof fn}function hn(e){e._transformAlgorithm=void 0,e._flushAlgorithm=void 0,e._cancelAlgorithm=void 0}function pn(e,t){const r=e._controlledTransformStream,n=r._readable._readableStreamController;if(!Or(n))throw new TypeError("Readable side is not in a state that permits enqueue");try{Rr(n,t)}catch(e){throw un(r,e),r._readable._storedError}const o=function(e){return!gr(e)}(n);o!==r._backpressure&&cn(r,!0)}function bn(e,t){return w(e._transformAlgorithm(t),void 0,(t=>{throw sn(e._controlledTransformStream,t),t}))}function yn(e){return new TypeError(`TransformStreamDefaultController.prototype.${e} can only be used on a TransformStreamDefaultController`)}function mn(e){void 0!==e._finishPromise_resolve&&(e._finishPromise_resolve(),e._finishPromise_resolve=void 0,e._finishPromise_reject=void 0)}function vn(e,t){void 0!==e._finishPromise_reject&&(S(e._finishPromise),e._finishPromise_reject(t),e._finishPromise_resolve=void 0,e._finishPromise_reject=void 0)}function _n(e){return new TypeError(`TransformStream.prototype.${e} can only be used on a TransformStream`)}Object.defineProperties(fn.prototype,{enqueue:{enumerable:!0},error:{enumerable:!0},terminate:{enumerable:!0},desiredSize:{enumerable:!0}}),u(fn.prototype.enqueue,"enqueue"),u(fn.prototype.error,"error"),u(fn.prototype.terminate,"terminate"),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(fn.prototype,Symbol.toStringTag,{value:"TransformStreamDefaultController",configurable:!0});var gn=function(e,t){return gn=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])},gn(e,t)};function wn(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function r(){this.constructor=e}gn(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}function Sn(e){if(!e)throw new TypeError("Assertion failed")}function Rn(){}function Tn(e){return!!function(e){return"object"==typeof e&&null!==e||"function"==typeof e}(e)&&"function"==typeof e.getReader}function Pn(e){try{return e.getReader({mode:"byob"}).releaseLock(),!0}catch(e){return!1}}function On(e,t){var r=(void 0===t?{}:t).type;return Sn(Tn(e)),Sn(!1===e.locked),"bytes"===(r=jn(r))?new Cn(e):new kn(e)}function jn(e){var t=String(e);if("bytes"===t)return t;if(void 0===e)return e;throw new RangeError("Invalid type is specified")}var qn=function(){function e(e){this._underlyingReader=void 0,this._readerMode=void 0,this._readableStreamController=void 0,this._pendingRead=void 0,this._underlyingStream=e,this._attachDefaultReader()}return e.prototype.start=function(e){this._readableStreamController=e},e.prototype.cancel=function(e){return Sn(void 0!==this._underlyingReader),this._underlyingReader.cancel(e)},e.prototype._attachDefaultReader=function(){if("default"!==this._readerMode){this._detachReader();var e=this._underlyingStream.getReader();this._readerMode="default",this._attachReader(e)}},e.prototype._attachReader=function(e){var t=this;Sn(void 0===this._underlyingReader),this._underlyingReader=e;var r=this._underlyingReader.closed;r&&r.then((function(){return t._finishPendingRead()})).then((function(){e===t._underlyingReader&&t._readableStreamController.close()}),(function(r){e===t._underlyingReader&&t._readableStreamController.error(r)})).catch(Rn)},e.prototype._detachReader=function(){void 0!==this._underlyingReader&&(this._underlyingReader.releaseLock(),this._underlyingReader=void 0,this._readerMode=void 0)},e.prototype._pullWithDefaultReader=function(){var e=this;this._attachDefaultReader();var t=this._underlyingReader.read().then((function(t){var r=e._readableStreamController;t.done?e._tryClose():r.enqueue(t.value)}));return this._setPendingRead(t),t},e.prototype._tryClose=function(){try{this._readableStreamController.close()}catch(e){}},e.prototype._setPendingRead=function(e){var t,r=this,n=function(){r._pendingRead===t&&(r._pendingRead=void 0)};this._pendingRead=t=e.then(n,n)},e.prototype._finishPendingRead=function(){var e=this;if(this._pendingRead){var t=function(){return e._finishPendingRead()};return this._pendingRead.then(t,t)}},e}(),kn=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return wn(t,e),t.prototype.pull=function(){return this._pullWithDefaultReader()},t}(qn);function En(e){return new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}var Cn=function(e){function t(t){var r=this,n=Pn(t);return(r=e.call(this,t)||this)._supportsByob=n,r}return wn(t,e),Object.defineProperty(t.prototype,"type",{get:function(){return"bytes"},enumerable:!1,configurable:!0}),t.prototype._attachByobReader=function(){if("byob"!==this._readerMode){Sn(this._supportsByob),this._detachReader();var e=this._underlyingStream.getReader({mode:"byob"});this._readerMode="byob",this._attachReader(e)}},t.prototype.pull=function(){if(this._supportsByob){var e=this._readableStreamController.byobRequest;if(e)return this._pullWithByobRequest(e)}return this._pullWithDefaultReader()},t.prototype._pullWithByobRequest=function(e){var t=this;this._attachByobReader();var r=new Uint8Array(e.view.byteLength),n=this._underlyingReader.read(r).then((function(r){t._readableStreamController,r.done?(t._tryClose(),e.respond(0)):(function(e,t){var r=En(e);En(t).set(r,0)}(r.value,e.view),e.respond(r.value.byteLength))}));return this._setPendingRead(n),n},t}(qn);!function(){function e(e){var t=this;this._writableStreamController=void 0,this._pendingWrite=void 0,this._state="writable",this._storedError=void 0,this._underlyingWriter=e,this._errorPromise=new Promise((function(e,r){t._errorPromiseReject=r})),this._errorPromise.catch(Rn)}e.prototype.start=function(e){var t=this;this._writableStreamController=e,this._underlyingWriter.closed.then((function(){t._state="closed"})).catch((function(e){return t._finishErroring(e)}))},e.prototype.write=function(e){var t=this,r=this._underlyingWriter;if(null===r.desiredSize)return r.ready;var n=r.write(e);n.catch((function(e){return t._finishErroring(e)})),r.ready.catch((function(e){return t._startErroring(e)}));var o=Promise.race([n,this._errorPromise]);return this._setPendingWrite(o),o},e.prototype.close=function(){var e=this;return void 0===this._pendingWrite?this._underlyingWriter.close():this._finishPendingWrite().then((function(){return e.close()}))},e.prototype.abort=function(e){if("errored"!==this._state)return this._underlyingWriter.abort(e)},e.prototype._setPendingWrite=function(e){var t,r=this,n=function(){r._pendingWrite===t&&(r._pendingWrite=void 0)};this._pendingWrite=t=e.then(n,n)},e.prototype._finishPendingWrite=function(){var e=this;if(void 0===this._pendingWrite)return Promise.resolve();var t=function(){return e._finishPendingWrite()};return this._pendingWrite.then(t,t)},e.prototype._startErroring=function(e){var t=this;if("writable"===this._state){this._state="erroring",this._storedError=e;var r=function(){return t._finishErroring(e)};void 0===this._pendingWrite?r():this._finishPendingWrite().then(r,r),this._writableStreamController.error(e)}},e.prototype._finishErroring=function(e){"writable"===this._state&&this._startErroring(e),"erroring"===this._state&&(this._state="errored",this._errorPromiseReject(this._storedError))}}(),function(){function e(e,t){var r=this;this._transformStreamController=void 0,this._onRead=function(e){if(!e.done)return r._transformStreamController.enqueue(e.value),r._reader.read().then(r._onRead)},this._onError=function(e){r._flushReject(e),r._transformStreamController.error(e),r._reader.cancel(e).catch(Rn),r._writer.abort(e).catch(Rn)},this._onTerminate=function(){r._flushResolve(),r._transformStreamController.terminate();var e=new TypeError("TransformStream terminated");r._writer.abort(e).catch(Rn)},this._reader=e,this._writer=t,this._flushPromise=new Promise((function(e,t){r._flushResolve=e,r._flushReject=t}))}e.prototype.start=function(e){this._transformStreamController=e,this._reader.read().then(this._onRead).then(this._onTerminate,this._onError);var t=this._reader.closed;t&&t.then(this._onTerminate,this._onError)},e.prototype.transform=function(e){return this._writer.write(e)},e.prototype.flush=function(){var e=this;return this._writer.close().then((function(){return e._flushPromise}))}}();var xn=[239,187,191],An=r(877),In=function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))},Wn=function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],n=0}finally{r=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}},Un=function(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t,r=e[Symbol.asyncIterator];return r?r.call(e):(e="function"==typeof __values?__values(e):e[Symbol.iterator](),t={},n("next"),n("throw"),n("return"),t[Symbol.asyncIterator]=function(){return this},t);function n(r){t[r]=e[r]&&function(t){return new Promise((function(n,o){!function(e,t,r,n){Promise.resolve(n).then((function(t){e({value:t,done:r})}),t)}(n,o,(t=e[r](t)).done,t.value)}))}}},Bn=Wr,Mn=on,Ln=function(){var e;return new Mn({start:function(t){e=function(e){var t,r,n,o,i,a,s;return u(),{feed:function(e){r=r?r+e:e,t&&function(e){return xn.every((function(t,r){return e.charCodeAt(r)===t}))}(r)&&(r=r.slice(xn.length)),t=!1;for(var i=r.length,a=0,s=!1;a<i;){s&&("\n"===r[a]&&(a+=1),s=!1);for(var u=-1,c=o,f=void 0,d=n;u<0&&d<i;d++)":"===(f=r[d])&&c<0?c=d-a:"\r"===f?(s=!0,u=d-a):"\n"===f&&(u=d-a);if(u<0){n=i-a,o=c;break}n=0,o=-1,l(r,a,c,u),a+=u+1}a===i?r="":a>0&&(r=r.slice(a))},reset:u};function u(){t=!0,r="",n=0,o=-1,i=void 0,a=void 0,s=""}function l(t,r,n,o){if(0===o)return s.length>0&&(e({type:"event",id:i,event:a||void 0,data:s.slice(0,-1)}),s="",i=void 0),void(a=void 0);var u,l=n<0,c=t.slice(r,r+(l?o:n)),f=r+(u=l?o:" "===t[r+n+1]?n+2:n+1),d=o-u,h=t.slice(f,f+d).toString();if("data"===c)s+=h?"".concat(h,"\n"):"\n";else if("event"===c)a=h;else if("id"!==c||h.includes("\0")){if("retry"===c){var p=parseInt(h,10);Number.isNaN(p)||e({type:"reconnect-interval",value:p})}}else i=h}}((function(e){"event"===e.type&&t.enqueue(e)}))},transform:function(t){e.feed(t)}})},zn=function(e){Sn(function(e){return!!function(e){if("function"!=typeof e)return!1;var t=!1;try{new e({start:function(){t=!0}})}catch(e){}return t}(e)&&!!Tn(new e)}(e));var t=function(e){try{return new e({type:"bytes"}),!0}catch(e){return!1}}(e);return function(r,n){var o=(void 0===n?{}:n).type;if("bytes"!==(o=jn(o))||t||(o=void 0),r.constructor===e&&("bytes"!==o||Pn(r)))return r;if("bytes"===o){var i=On(r,{type:o});return new e(i)}return i=On(r),new e(i)}}(Bn),Fn=function(){function e(e,t){void 0===e&&(e="utf-8"),void 0===t&&(t={});var r=this;this.transform=new Mn({transform:function(e,t){var n=r.handle.decode(new Uint8Array(e),{stream:!0});n&&t.enqueue(n)},flush:function(e){var t=r.handle.decode();t&&e.enqueue(t),e.terminate()}}),this.handle=new An.TextDecoder(e,t)}return Object.defineProperty(e.prototype,"encoding",{get:function(){return this.handle.encoding},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"fatal",{get:function(){return this.handle.fatal},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"ignoreBOM",{get:function(){return this.handle.ignoreBOM},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"readable",{get:function(){return this.transform.readable},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"writable",{get:function(){return this.transform.writable},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,Symbol.toStringTag,{get:function(){return"TextDecoderStream"},enumerable:!1,configurable:!0}),e}();function Dn(e){var t=e;return t[Symbol.asyncIterator]=function(){var t=e.getReader();return{next:function(){return In(this,void 0,void 0,(function(){var e,r,n;return Wn(this,(function(o){switch(o.label){case 0:return[4,t.read()];case 1:return e=o.sent(),r=e.done,n=e.value,[2,r?{done:!0,value:void 0}:{done:!1,value:n}]}}))}))}}},t}function $n(e){return Dn(e.pipeThrough(new Fn).pipeThrough(Ln()).pipeThrough(new Mn({transform:function(e,t){try{var r=JSON.parse(e.data);t.enqueue(r)}catch(r){"[DONE]"!==e.data?console.warn("Error when transforming event source data to json",r,e):t.terminate()}}})))}function Nn(e){return Dn(zn(e).pipeThrough(new Fn))}function Gn(e){var t,r,n,o;return In(this,void 0,void 0,(function(){var i,a,s,u,l,c;return Wn(this,(function(f){switch(f.label){case 0:i=Nn(e),a="",f.label=1;case 1:f.trys.push([1,6,7,12]),s=!0,u=Un(i),f.label=2;case 2:return[4,u.next()];case 3:if(l=f.sent(),t=l.done)return[3,5];o=l.value,s=!1;try{a+=o}finally{s=!0}f.label=4;case 4:return[3,2];case 5:return[3,12];case 6:return c=f.sent(),r={error:c},[3,12];case 7:return f.trys.push([7,,10,11]),s||t||!(n=u.return)?[3,9]:[4,n.call(u)];case 8:f.sent(),f.label=9;case 9:return[3,11];case 10:if(r)throw r.error;return[7];case 11:return[7];case 12:return[2,JSON.parse(a)]}}))}))}function Hn(){var e,t;return{promise:new Promise((function(r,n){e=r,t=n})),res:e,rej:t}}function Yn(e){var t;return"assistant"===e.role&&"tool_calls"in e&&null!=(null===(t=e.tool_calls)||void 0===t?void 0:t[0])}function Jn(e){return{type:"function",function:{description:e.description,name:e.name,parameters:e.parameters}}}var Qn=function(){return Qn=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},Qn.apply(this,arguments)},Vn=function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))},Xn=function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],n=0}finally{r=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}},Kn=function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(r[n[o]]=e[n[o]])}return r},Zn=function(){function e(e,t){this.baseUrl=t;var r=arguments[2];this.req="string"==typeof r?function(t){var n=t.headers,o=void 0===n?{}:n,i=Kn(t,["headers"]);return e(Qn(Qn({},i),{headers:Qn(Qn({},o),{Authorization:"Bearer ".concat(r)})}))}:e}return e.prototype.list=function(e,t){return this.req({method:"get",url:this.join("bots"),data:e,timeout:null==t?void 0:t.timeout})},e.prototype.create=function(e,t){var r=e.botInfo;return this.req({method:"post",url:this.join("bots"),data:r,timeout:null==t?void 0:t.timeout})},e.prototype.get=function(e,t){var r=e.botId;return this.req({method:"get",url:this.join("bots/".concat(r)),timeout:null==t?void 0:t.timeout})},e.prototype.update=function(e,t){var r=e.botId,n=e.botInfo;return this.req({method:"PATCH",url:this.join("bots/".concat(r)),data:n,timeout:null==t?void 0:t.timeout})},e.prototype.delete=function(e,t){var r=e.botId;return this.req({method:"delete",url:this.join("bots/".concat(r)),timeout:null==t?void 0:t.timeout})},e.prototype.getChatRecords=function(e,t){return this.req({method:"get",url:this.join("bots/".concat(e.botId,"/records")),data:e,timeout:null==t?void 0:t.timeout})},e.prototype.sendFeedback=function(e,t){var r=e.userFeedback;return this.req({method:"post",url:this.join("bots/".concat(r.botId,"/feedback")),data:r,timeout:null==t?void 0:t.timeout})},e.prototype.getFeedback=function(e,t){return this.req({method:"get",url:this.join("bots/".concat(e.botId,"/feedback")),data:e,timeout:null==t?void 0:t.timeout})},e.prototype.uploadFiles=function(e,t){return Vn(this,void 0,void 0,(function(){return Xn(this,(function(r){return[2,this.req({method:"post",url:this.join("bots/".concat(e.botId,"/files")),data:e,timeout:null==t?void 0:t.timeout})]}))}))},e.prototype.createConversation=function(e,t){var r=e.botId,n=Kn(e,["botId"]);return Vn(this,void 0,void 0,(function(){return Xn(this,(function(e){return[2,this.req({method:"post",url:this.join("bots/".concat(r,"/conversation")),data:n,timeout:null==t?void 0:t.timeout})]}))}))},e.prototype.getConversation=function(e,t){var r=e.pageSize,n=void 0===r?10:r,o=e.pageNumber,i=void 0===o?1:o,a=e.botId,s=Kn(e,["pageSize","pageNumber","botId"]);return Vn(this,void 0,void 0,(function(){var e,r;return Xn(this,(function(o){if(i<1)throw new Error("pageNumber must be greater than 0");return e=n*(i-1),r=n,[2,this.req({method:"get",url:this.join("bots/".concat(a,"/conversation")),data:Qn(Qn({},s),{offset:e,limit:r}),timeout:null==t?void 0:t.timeout})]}))}))},e.prototype.deleteConversation=function(e,t){var r=e.botId,n=e.conversationId,o=Kn(e,["botId","conversationId"]);return Vn(this,void 0,void 0,(function(){return Xn(this,(function(e){return[2,this.req({method:"delete",url:this.join("bots/".concat(r,"/conversation/").concat(n)),data:o,timeout:null==t?void 0:t.timeout})]}))}))},e.prototype.speechToText=function(e,t){return Vn(this,void 0,void 0,(function(){return Xn(this,(function(r){return[2,this.req({method:"post",url:this.join("bots/".concat(e.botId,"/speech-to-text")),data:e,timeout:null==t?void 0:t.timeout})]}))}))},e.prototype.textToSpeech=function(e,t){return Vn(this,void 0,void 0,(function(){return Xn(this,(function(r){return[2,this.req({method:"post",url:this.join("bots/".concat(e.botId,"/text-to-speech")),data:e,timeout:null==t?void 0:t.timeout})]}))}))},e.prototype.getTextToSpeechResult=function(e,t){return Vn(this,void 0,void 0,(function(){return Xn(this,(function(r){return[2,this.req({method:"get",url:this.join("bots/".concat(e.botId,"/text-to-speech")),data:e,timeout:null==t?void 0:t.timeout})]}))}))},e.prototype.getRecommendQuestions=function(e,t){return Vn(this,void 0,void 0,(function(){var r;return Xn(this,(function(n){switch(n.label){case 0:return[4,this.req({method:"post",url:this.join("bots/".concat(e.botId,"/recommend-questions")),data:e,stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return r=n.sent(),[2,new eo(r)]}}))}))},e.prototype.generateBot=function(e,t){return Vn(this,void 0,void 0,(function(){var r;return Xn(this,(function(n){switch(n.label){case 0:return[4,this.req({method:"post",url:this.join("generate-bot"),data:e,stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return r=n.sent(),[2,new eo(r)]}}))}))},e.prototype.getPreview=function(e,t){return Vn(this,void 0,void 0,(function(){var r;return Xn(this,(function(n){switch(n.label){case 0:return[4,this.req({method:"post",url:this.join("preview"),data:e,stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return r=n.sent(),[2,new eo(r)]}}))}))},e.prototype.generateImage=function(e,t){return this.req({method:"post",url:this.join("generate-image"),data:e,timeout:null==t?void 0:t.timeout})},e.prototype.sendMessage=function(e,t){return Vn(this,void 0,void 0,(function(){var r;return Xn(this,(function(n){switch(n.label){case 0:return[4,this.req({method:"post",url:this.join("bots/".concat(e.botId,"/send-message")),data:e,stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return r=n.sent(),[2,new eo(r)]}}))}))},e.prototype.join=function(e){return"".concat(this.baseUrl,"/").concat(e)},e}(),eo=function(){function e(e){var t=zn(e);this._eventSourceStream=t.pipeThrough(new Fn).pipeThrough(Ln())}return Object.defineProperty(e.prototype,"teeedStream",{get:function(){var e=this._eventSourceStream.tee(),t=e[0],r=e[1];return this._eventSourceStream=r,t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"eventSourceStream",{get:function(){return Dn(this.teeedStream)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"dataStream",{get:function(){return Dn(this.eventSourceStream.pipeThrough(new Mn({transform:function(e,t){try{var r=JSON.parse(e.data);t.enqueue(r)}catch(r){"[DONE]"!==e.data?console.warn("Error when transforming event source data to json",r,e):t.terminate()}}})))},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"textStream",{get:function(){return Dn(this.dataStream.pipeThrough(new Mn({transform:function(e,t){var r;t.enqueue(null!==(r=null==e?void 0:e.content)&&void 0!==r?r:"")}})))},enumerable:!1,configurable:!0}),e}(),to=function(){return to=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},to.apply(this,arguments)},ro=function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))},no=function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],n=0}finally{r=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}};function oo(e){var t=e.messages,r=e.model,n=e.temperature,o=e.tool_choice,i=e.tools,a=e.top_p;return to(to({},e),{messages:t,model:r,temperature:n,tool_choice:(o&&"auto"!==o&&console.warn("`tool_choice` is not 'auto'"),o),tools:i,top_p:a})}var io=function(){function e(e,t,r){this.req=e,this.baseUrl=t,this.subUrl="zhipu/api/paas/v4/chat/completions",null!=r&&(this.subUrl=r)}return Object.defineProperty(e.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),e.prototype.doGenerate=function(e,t){return ro(this,void 0,void 0,(function(){var r,n;return no(this,(function(o){switch(o.label){case 0:return r=oo(e),[4,this.req({url:this.url,data:to(to({},r),{stream:!1}),stream:!1,timeout:null==t?void 0:t.timeout})];case 1:return n=o.sent(),[2,to(to({},n),{rawResponse:n})]}}))}))},e.prototype.doStream=function(e,t){return ro(this,void 0,void 0,(function(){var r,n,o,i;return no(this,(function(a){switch(a.label){case 0:return r=oo(e),n=null,[4,this.req({url:this.url,data:to(to({},r),{stream:!0}),stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return o=a.sent(),i=zn(o),[2,Dn($n(i).pipeThrough(new Mn({transform:function(e,t){var r=e.choices.map((function(e){var t=e.delta;return null==n&&(n=Yn(t)),n?to(to({},e),{finish_reason:"tool_calls",delta:t}):e})),o=to(to({},e),{choices:r});t.enqueue(to(to({},o),{rawResponse:e}))}})))]}}))}))},e}(),ao=function(){return ao=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},ao.apply(this,arguments)};function so(e){var t=e.messages,r=e.model,n=e.temperature,o=e.tool_choice,i=e.tools,a=e.top_p;return ao(ao({},e),{messages:(t.forEach((function(e){"tool_calls"in e&&e.tool_calls.filter((function(e){return"function"!==e.type})).forEach((function(t){return console.warn("`type` in tool_call is not 'function'",t,e)}))})),t),model:r,tools:function(){if(i)return i.forEach((function(e){"function"!==e.type&&console.warn("`type` in tool is not 'function'",e)})),i}(),top_p:a,tool_choice:o,temperature:n})}function uo(e){return"object"!=typeof e||null==e?e:Array.isArray(e)?e.map((function(e){return uo(e)})):Object.entries(e).reduce((function(e,t){var r=t[0],n=t[1],o=function(e){var t=e.replace(/[A-Z]/g,(function(e){return"_".concat(e.toLowerCase())}));return"_"===t.charAt(0)?t.slice(1):t}(r);return e[o]="object"==typeof n?uo(n):n,e}),{})}var lo=function(){return lo=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},lo.apply(this,arguments)},co=function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))},fo=function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],n=0}finally{r=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}},ho=function(){function e(e,t,r){this.req=e,this.baseUrl=t,this.subUrl="hunyuan-beta/openapi/v1/chat/completions",null!=r&&(this.subUrl=r)}return Object.defineProperty(e.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),e.prototype.doGenerate=function(e,t){return co(this,void 0,void 0,(function(){var r;return fo(this,(function(n){switch(n.label){case 0:return[4,this.req({url:this.url,data:lo(lo({},so(e)),{stream:!1}),stream:!1,timeout:null==t?void 0:t.timeout})];case 1:return r=n.sent(),[2,lo(lo({},r),{rawResponse:r})]}}))}))},e.prototype.doStream=function(e,t){return co(this,void 0,void 0,(function(){var r,n,o;return fo(this,(function(i){switch(i.label){case 0:return r=null,[4,this.req({url:this.url,data:lo(lo({},so(e)),{stream:!0}),stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return n=i.sent(),o=zn(n),[2,Dn($n(o).pipeThrough(new Mn({transform:function(e,t){var n=e.choices.map((function(e){var t=e.delta;return null==r&&(r=Yn(t)),r?lo(lo({},e),{finish_reason:"tool_calls",delta:t}):e})),o=lo(lo({},e),{choices:n});t.enqueue(lo(lo({},o),{rawResponse:e}))}})))]}}))}))},e}(),po=function(){return po=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},po.apply(this,arguments)},bo=function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))},yo=function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],n=0}finally{r=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}},mo=function(){function e(e,t,r){this.req=e,this.baseUrl=t,this.subUrl="hunyuan",null!=r&&(this.subUrl=r)}return Object.defineProperty(e.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),e.prototype.doGenerate=function(e,t){return bo(this,void 0,void 0,(function(){var r,n;return yo(this,(function(o){switch(o.label){case 0:return[4,this.req({url:this.url,headers:{"X-Tc-Action":"ChatCompletions"},data:po(po({},so(e)),{stream:!1}),stream:!1,timeout:null==t?void 0:t.timeout})];case 1:return r=o.sent(),n=uo(r.Response),[2,po(po({},n),{rawResponse:r})]}}))}))},e.prototype.doStream=function(e,t){return bo(this,void 0,void 0,(function(){var r,n,o;return yo(this,(function(i){switch(i.label){case 0:return r=null,[4,this.req({url:this.url,headers:{"X-Tc-Action":"ChatCompletions"},data:po(po({},e),{stream:!0}),stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return n=i.sent(),o=zn(n),[2,Dn($n(o).pipeThrough(new Mn({transform:function(e,t){var n=uo(e),o=n.choices.map((function(e){var t=e.delta;return null==r&&(r=Yn(t)),r?po(po({},e),{finish_reason:"tool_calls",delta:t}):e})),i=po(po({},n),{choices:o});t.enqueue(po(po({},i),{rawResponse:e}))}})))]}}))}))},e}(),vo=function(){return vo=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},vo.apply(this,arguments)},_o=function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))},go=function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],n=0}finally{r=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}};function wo(e){var t=e.messages,r=e.model,n=e.temperature,o=e.tools,i=e.top_p;return vo(vo({},e),{messages:t,model:r,tools:o,top_p:i,temperature:n})}var So=function(){function e(e,t,r){this.req=e,this.baseUrl=t,this.subUrl="ark/api/v3/chat/completions",null!=r&&(this.subUrl=r)}return Object.defineProperty(e.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),e.prototype.doGenerate=function(e,t){return _o(this,void 0,void 0,(function(){var r;return go(this,(function(n){switch(n.label){case 0:return[4,this.req({url:this.url,data:vo(vo({},wo(e)),{stream:!1}),stream:!1,timeout:null==t?void 0:t.timeout})];case 1:return r=n.sent(),[2,vo(vo({},r),{rawResponse:r})]}}))}))},e.prototype.doStream=function(e,t){return _o(this,void 0,void 0,(function(){var r,n,o;return go(this,(function(i){switch(i.label){case 0:return r=null,[4,this.req({url:this.url,data:vo(vo({},wo(e)),{stream:!0}),stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return n=i.sent(),o=zn(n),[2,Dn($n(o).pipeThrough(new Mn({transform:function(e,t){var n=e.choices.map((function(e){var t=e.delta;return null==r&&(r=Yn(t)),r?vo(vo({},e),{finish_reason:"tool_calls",delta:t}):e})),o=vo(vo({},e),{choices:n});t.enqueue(vo(vo({},o),{rawResponse:e}))}})))]}}))}))},e}(),Ro=function(){return Ro=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},Ro.apply(this,arguments)},To=function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))},Po=function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],n=0}finally{r=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}};function Oo(e){var t=e.messages,r=e.model,n=e.temperature,o=e.tools,i=e.top_p;return Ro(Ro({},e),{messages:t,model:r,tools:o,top_p:i,temperature:n})}var jo=function(){function e(e,t,r){this.req=e,this.baseUrl=t,this.subUrl="dashscope/compatible-mode/v1/chat/completions",null!=r&&(this.subUrl=r)}return Object.defineProperty(e.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),e.prototype.doGenerate=function(e,t){return To(this,void 0,void 0,(function(){var r;return Po(this,(function(n){switch(n.label){case 0:return[4,this.req({url:this.url,data:Ro(Ro({},Oo(e)),{stream:!1}),stream:!1,timeout:null==t?void 0:t.timeout})];case 1:return r=n.sent(),[2,Ro(Ro({},r),{rawResponse:r})]}}))}))},e.prototype.doStream=function(e,t){return To(this,void 0,void 0,(function(){var r,n,o;return Po(this,(function(i){switch(i.label){case 0:return r=null,[4,this.req({url:this.url,data:Ro(Ro({},Oo(e)),{stream:!0}),stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return n=i.sent(),o=zn(n),[2,Dn($n(o).pipeThrough(new Mn({transform:function(e,t){var n=e.choices.map((function(e){var t=Object.assign(e.delta,{role:"assistant"});return null==r&&(r=Yn(t)),Ro(Ro({},e),r?{finish_reason:"tool_calls",delta:t}:{delta:t})})),o=Ro(Ro({},e),{choices:n});t.enqueue(Ro(Ro({},o),{rawResponse:e}))}})))]}}))}))},e}(),qo=function(){return qo=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},qo.apply(this,arguments)},ko=function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))},Eo=function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],n=0}finally{r=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}};function Co(e){var t=e.messages,r=e.model,n=e.temperature,o=e.tools,i=e.top_p;return qo(qo({},e),{messages:t,model:r,tools:o,top_p:i,temperature:n})}var xo=function(){function e(e,t,r){this.req=e,this.baseUrl=t,this.subUrl="01-ai/v1/chat/completions",null!=r&&(this.subUrl=r)}return Object.defineProperty(e.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),e.prototype.doGenerate=function(e,t){return ko(this,void 0,void 0,(function(){var r;return Eo(this,(function(n){switch(n.label){case 0:return[4,this.req({url:this.url,data:qo(qo({},Co(e)),{stream:!1}),stream:!1,timeout:null==t?void 0:t.timeout})];case 1:return r=n.sent(),[2,qo(qo({},r),{rawResponse:r})]}}))}))},e.prototype.doStream=function(e,t){return ko(this,void 0,void 0,(function(){var r,n,o,i,a;return Eo(this,(function(s){switch(s.label){case 0:return r=null,[4,this.req({url:this.url,data:qo(qo({},Co(e)),{stream:!0}),stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return n=s.sent(),o=zn(n),i=$n(o),a=i.pipeThrough(new Mn({transform:function(e,t){var n,o,i,a,s,u;if((null===(i=null===(o=null===(n=null==e?void 0:e.choices)||void 0===n?void 0:n[0])||void 0===o?void 0:o.delta)||void 0===i?void 0:i.content)||(null===(u=null===(s=null===(a=null==e?void 0:e.choices)||void 0===a?void 0:a[0])||void 0===s?void 0:s.delta)||void 0===u?void 0:u.tool_calls)){var l=e.choices.map((function(e){var t=Object.assign(e.delta,{role:"assistant"});return null==r&&(r=Yn(t)),qo(qo({},e),r?{finish_reason:"tool_calls",delta:t}:{delta:t})})),c=qo(qo({},e),{choices:l});t.enqueue(qo(qo({},c),{rawResponse:e}))}}})),[2,Dn(a)]}}))}))},e}(),Ao=function(){return Ao=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},Ao.apply(this,arguments)},Io=function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))},Wo=function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],n=0}finally{r=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}};function Uo(e){var t=e.messages,r=e.model,n=e.temperature,o=e.tools,i=e.top_p;return Ao(Ao({},e),{messages:t,model:r,tools:o,top_p:i,temperature:n})}var Bo=function(){function e(e,t,r){this.req=e,this.baseUrl=t,this.subUrl="moonshot/v1/chat/completions",null!=r&&(this.subUrl=r)}return Object.defineProperty(e.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),e.prototype.doGenerate=function(e,t){return Io(this,void 0,void 0,(function(){var r;return Wo(this,(function(n){switch(n.label){case 0:return[4,this.req({url:this.url,data:Ao(Ao({},Uo(e)),{stream:!1}),stream:!1,timeout:null==t?void 0:t.timeout})];case 1:return r=n.sent(),[2,Ao(Ao({},r),{rawResponse:r})]}}))}))},e.prototype.doStream=function(e,t){return Io(this,void 0,void 0,(function(){var r,n,o;return Wo(this,(function(i){switch(i.label){case 0:return r=null,[4,this.req({url:this.url,data:Ao(Ao({},Uo(e)),{stream:!0}),stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return n=i.sent(),o=zn(n),[2,Dn($n(o).pipeThrough(new Mn({transform:function(e,t){var n=e.choices.map((function(e){var t=e.delta;return null==r&&(r=Yn(t)),r?Ao(Ao({},e),{finish_reason:"tool_calls",delta:t}):e})),o=Ao(Ao({},e),{choices:n});t.enqueue(Ao(Ao({},o),{rawResponse:e}))}})))]}}))}))},e}(),Mo=function(){return Mo=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},Mo.apply(this,arguments)},Lo=function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))},zo=function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],n=0}finally{r=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}},Fo=function(){function e(e,t,r){this.req=e,this.baseUrl=t,this.subUrl="hunyuan-exp/chat/completions",null!=r&&(this.subUrl=r)}return Object.defineProperty(e.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),e.prototype.doGenerate=function(e){return Lo(this,void 0,void 0,(function(){var t;return zo(this,(function(r){switch(r.label){case 0:return[4,this.req({url:this.url,data:Mo(Mo({},so(e)),{stream:!1}),stream:!1})];case 1:return t=r.sent(),[2,Mo(Mo({},t),{rawResponse:t})]}}))}))},e.prototype.doStream=function(e){return Lo(this,void 0,void 0,(function(){var t,r,n;return zo(this,(function(o){switch(o.label){case 0:return t=null,[4,this.req({url:this.url,data:Mo(Mo({},so(e)),{stream:!0}),stream:!0})];case 1:return r=o.sent(),n=zn(r),[2,Dn($n(n).pipeThrough(new Mn({transform:function(e,r){var n=e.choices.map((function(e){var r=e.delta;return null==t&&(t=Yn(r)),t?Mo(Mo({},e),{finish_reason:"tool_calls",delta:r}):e})),o=Mo(Mo({},e),{choices:n});r.enqueue(Mo(Mo({},o),{rawResponse:e}))}})))]}}))}))},e}(),Do=function(){return Do=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},Do.apply(this,arguments)},$o=function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))},No=function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],n=0}finally{r=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}},Go=function(){function e(e,t,r){this.req=e,this.baseUrl=t,this.subUrl="hunyuan-open/v1/chat/completions",null!=r&&(this.subUrl=r)}return Object.defineProperty(e.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),e.prototype.doGenerate=function(e,t){return $o(this,void 0,void 0,(function(){var r;return No(this,(function(n){switch(n.label){case 0:return[4,this.req({url:this.url,data:Do(Do({},so(e)),{stream:!1}),stream:!1,timeout:null==t?void 0:t.timeout})];case 1:return r=n.sent(),[2,Do(Do({},r),{rawResponse:r})]}}))}))},e.prototype.doStream=function(e,t){return $o(this,void 0,void 0,(function(){var r,n,o;return No(this,(function(i){switch(i.label){case 0:return r=null,[4,this.req({url:this.url,data:Do(Do({},so(e)),{stream:!0}),stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return n=i.sent(),o=zn(n),[2,Dn($n(o).pipeThrough(new Mn({transform:function(e,t){var n=e.choices.map((function(e){var t=e.delta;return null==r&&(r=Yn(t)),r?Do(Do({},e),{finish_reason:"tool_calls",delta:t}):e})),o=Do(Do({},e),{choices:n});t.enqueue(Do(Do({},o),{rawResponse:e}))}})))]}}))}))},e}(),Ho=function(){return Ho=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},Ho.apply(this,arguments)},Yo=function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))},Jo=function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],n=0}finally{r=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}},Qo=function(){function e(e,t,r){this.req=e,this.baseUrl=t,this.subUrl="deepseek/chat/completions",null!=r&&(this.subUrl=r)}return Object.defineProperty(e.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),e.prototype.doGenerate=function(e,t){return Yo(this,void 0,void 0,(function(){var r;return Jo(this,(function(n){switch(n.label){case 0:return[4,this.req({url:this.url,data:Ho(Ho({},e),{stream:!1}),stream:!1,timeout:null==t?void 0:t.timeout})];case 1:return r=n.sent(),[2,Ho(Ho({},r),{rawResponse:r})]}}))}))},e.prototype.doStream=function(e,t){return Yo(this,void 0,void 0,(function(){var r,n,o;return Jo(this,(function(i){switch(i.label){case 0:return r=null,[4,this.req({url:this.url,data:Ho(Ho({},e),{stream:!0}),stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return n=i.sent(),o=zn(n),[2,Dn($n(o).pipeThrough(new Mn({transform:function(e,t){var n=e.choices.map((function(e){var t=e.delta;return null==r&&(r=Yn(t)),r?Ho(Ho({},e),{finish_reason:"tool_calls",delta:t}):e})),o=Ho(Ho({},e),{choices:n});t.enqueue(Ho(Ho({},o),{rawResponse:e}))}})))]}}))}))},e}(),Vo=function(){return Vo=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},Vo.apply(this,arguments)},Xo=function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))},Ko=function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],n=0}finally{r=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}},Zo=function(){function e(e,t,r){void 0===r&&(r=""),this.req=e,this.baseUrl=t,this.subUrl=r}return Object.defineProperty(e.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),e.prototype.doGenerate=function(e){return Xo(this,void 0,void 0,(function(){var t;return Ko(this,(function(r){switch(r.label){case 0:return[4,this.req({url:this.url,data:Vo(Vo({},e),{stream:!1}),stream:!1})];case 1:return t=r.sent(),[2,Vo(Vo({},t),{rawResponse:t})]}}))}))},e.prototype.doStream=function(e){return Xo(this,void 0,void 0,(function(){var t,r,n;return Ko(this,(function(o){switch(o.label){case 0:return t=null,[4,this.req({url:this.url,data:Vo(Vo({},e),{stream:!0}),stream:!0})];case 1:return r=o.sent(),n=zn(r),[2,Dn($n(n).pipeThrough(new Mn({transform:function(e,r){var n=e.choices.map((function(e){var r=e.delta;return null==t&&(t=Yn(r)),t?Vo(Vo({},e),{finish_reason:"tool_calls",delta:r}):e})),o=Vo(Vo({},e),{choices:n});r.enqueue(Vo(Vo({},o),{rawResponse:e}))}})))]}}))}))},e}(),ei=function(){function e(e,t,r){this.req=e,this.baseUrl=t,this.provider=r,this.defaultGenerateImageSubUrl="images/generations",this.generateImageSubUrlConfig={"hunyuan-image":{"hunyuan-image-v3.0-v1.0.4":"images/ar/generations","hunyuan-image-v3.0-v1.0.1":"images/ar/generations"}},this.generateImage=this.generateImageImpl.bind(this)}return e.prototype.generateImageImpl=function(e){var t;return function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))}(this,void 0,void 0,(function(){var r,n;return function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],n=0}finally{r=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}}(this,(function(o){switch(o.label){case 0:return r=this.defaultGenerateImageSubUrl,"object"==typeof e&&e&&"model"in e&&"string"==typeof e.model&&(n=null===(t=this.generateImageSubUrlConfig[this.provider])||void 0===t?void 0:t[e.model])&&(r=n),[4,this.req({url:this.getGenerateUrl(r),data:e,stream:!1})];case 1:return[2,o.sent()]}}))}))},e.prototype.getGenerateUrl=function(e){return"".concat(this.baseUrl,"/").concat(this.provider,"/").concat(e)},e}(),ti=function(){return ti=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},ti.apply(this,arguments)},ri=function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))},ni=function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],n=0}finally{r=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}},oi=function(e,t,r){if(r||2===arguments.length)for(var n,o=0,i=t.length;o<i;o++)!n&&o in t||(n||(n=Array.prototype.slice.call(t,0,o)),n[o]=t[o]);return e.concat(n||Array.prototype.slice.call(t))};function ii(e){var t,r=e.onStepFinish,n=e.abortSignal,o=e.maxSteps,i=e.topP,a=e.toolChoice,s=function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(r[n[o]]=e[n[o]])}return r}(e,["onStepFinish","abortSignal","maxSteps","topP","toolChoice"]);if(null!=o&&o<1)throw new Error("`maxSteps` muse be greater than 0.");return[{onStepFinish:r,abortSignal:n,maxSteps:o},ti(ti({},s),{tools:null===(t=s.tools)||void 0===t?void 0:t.map((function(e){return"fn"in e?Jn(e):e})),top_p:null!=i?i:s.top_p,tool_choice:null!=a?a:s.tool_choice})]}var ai=function(){function e(e){this.model=e}return e.prototype.generateText=function(e,t){var r,n;return ri(this,void 0,void 0,(function(){var o,i,a,s,u,l,c,f,d,h,p,b,y,m,v,_,g,w,S,R,T,P=this;return ni(this,(function(O){switch(O.label){case 0:return o=[],i={completion_tokens:0,prompt_tokens:0,total_tokens:0},a=ii(e),s=a[0],u=s.onStepFinish,l=s.maxSteps,c=void 0===l?10:l,f=a[1],[4,(d=function(){return P.model.doGenerate(f,t)})()];case 1:h=O.sent(),p=1,h.rawResponse&&o.push(h.rawResponse),b=null,O.label=2;case 2:if(!(p<c&&null!=(b=si(h))))return[3,9];y=fi(h.usage),di(i,y),O.label=3;case 3:return O.trys.push([3,7,,8]),[4,ci(b)];case 4:return m=O.sent(),v=h.choices[0],[4,null==u?void 0:u({finishReason:v.finish_reason,messages:f.messages.slice(),text:v.message.content,toolCall:b,toolResult:m,stepUsage:y,totalUsage:Object.assign({},i)})];case 5:return O.sent(),ui(f.messages,v.message,m),[4,d()];case 6:return(h=O.sent()).rawResponse&&o.push(h.rawResponse),p+=1,[3,8];case 7:return _=O.sent(),[2,{text:"",messages:f.messages,usage:i,error:_,rawResponses:o}];case 8:return[3,2];case 9:return g=null===(r=null==h?void 0:h.choices)||void 0===r?void 0:r[0],w=null==g?void 0:g.message,S=null!==(n=null==w?void 0:w.content)&&void 0!==n?n:"",R=w?oi(oi([],f.messages,!0),[w],!1):f.messages,T=fi(h.usage),di(i,T),[4,null==u?void 0:u({finishReason:g.finish_reason,messages:R.slice(),text:S,toolCall:si(h),toolResult:null,stepUsage:T,totalUsage:Object.assign({},i)})];case 10:return O.sent(),[2,{text:S,messages:R,usage:i,rawResponses:o}]}}))}))},e.prototype.streamText=function(e,t){var r;return ri(this,void 0,void 0,(function(){var n,o,i,a,s,u,l,c,f,d,h,p,b,y,m,v,_,g,w,S,R,T,P,O,j,q,k,E,C,x,A,I,W,U,B,M,L=this;return ni(this,(function(z){switch(z.label){case 0:return n={completion_tokens:0,prompt_tokens:0,total_tokens:0},o=ii(e),i=o[0],a=i.onStepFinish,s=i.maxSteps,u=void 0===s?10:s,l=o[1],[4,(c=function(){return L.model.doStream(l,t)})()];case 1:f=z.sent(),d=1,h=null,p=function(){var e=f.tee(),t=e[0],r=e[1];return f=Dn(t),function(e){var t,r,n,o,i,a,s,u,l,c;return ri(this,void 0,void 0,(function(){var f,d,h,p,b,y,m,v,_,g,w,S,R;return ni(this,(function(T){switch(T.label){case 0:f={completion_tokens:0,prompt_tokens:0,total_tokens:0},d=Dn(e),p={role:"assistant",content:"",tool_calls:[h={id:"",function:{name:"",arguments:""},type:""}]},T.label=1;case 1:T.trys.push([1,6,7,12]),b=!0,y=function(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t,r=e[Symbol.asyncIterator];return r?r.call(e):(e="function"==typeof __values?__values(e):e[Symbol.iterator](),t={},n("next"),n("throw"),n("return"),t[Symbol.asyncIterator]=function(){return this},t);function n(r){t[r]=e[r]&&function(t){return new Promise((function(n,o){!function(e,t,r,n){Promise.resolve(n).then((function(t){e({value:t,done:r})}),t)}(n,o,(t=e[r](t)).done,t.value)}))}}}(d),T.label=2;case 2:return[4,y.next()];case 3:if(m=T.sent(),t=m.done)return[3,5];o=m.value,b=!1;try{if(!(_=null==(v=o)?void 0:v.choices[0]))return[2,null];if(g=_.finish_reason,w=_.delta,"tool_calls"!==g)return[2,null];if(!w)return[3,4];if(w.content&&(p.content+=w.content),!("tool_calls"in w))return[3,4];(null==(S=null===(i=null==w?void 0:w.tool_calls)||void 0===i?void 0:i[0])?void 0:S.id)&&(h.id=S.id),(null==S?void 0:S.type)&&(h.type=S.type),(null===(a=null==S?void 0:S.function)||void 0===a?void 0:a.name)&&(h.function.name=S.function.name),(null===(s=null==S?void 0:S.function)||void 0===s?void 0:s.arguments)&&(h.function.arguments+=S.function.arguments),(null===(u=null==v?void 0:v.usage)||void 0===u?void 0:u.completion_tokens)&&(f.completion_tokens=v.usage.completion_tokens),(null===(l=null==v?void 0:v.usage)||void 0===l?void 0:l.prompt_tokens)&&(f.prompt_tokens=v.usage.prompt_tokens),(null===(c=null==v?void 0:v.usage)||void 0===c?void 0:c.total_tokens)&&(f.total_tokens=v.usage.total_tokens)}finally{b=!0}T.label=4;case 4:return[3,2];case 5:return[3,12];case 6:return R=T.sent(),r={error:R},[3,12];case 7:return T.trys.push([7,,10,11]),b||t||!(n=y.return)?[3,9]:[4,n.call(y)];case 8:T.sent(),T.label=9;case 9:return[3,11];case 10:if(r)throw r.error;return[7];case 11:return[7];case 12:return[2,{message:p,usage:f}]}}))}))}(r)},z.label=2;case 2:return(b=d<u)?[4,p()]:[3,4];case 3:b=null!=(h=z.sent()),z.label=4;case 4:if(!b)return[3,11];y=h.message,m=h.usage,di(n,m),v=null===(r=y.tool_calls)||void 0===r?void 0:r[0],z.label=5;case 5:return z.trys.push([5,9,,10]),[4,ci(v)];case 6:return _=z.sent(),[4,null==a?void 0:a({finishReason:"tool_calls",messages:l.messages.slice(),text:y.content,toolCall:v,toolResult:_,stepUsage:m,totalUsage:Object.assign({},n)})];case 7:return z.sent(),ui(l.messages,y,_),[4,c()];case 8:return f=z.sent(),[3,10];case 9:return g=z.sent(),w=f.tee(),S=w[0],R=w[1],[2,{messages:Promise.resolve(l.messages),dataStream:Dn(S),textStream:Dn(R.pipeThrough(new Mn({transform:function(e,t){var r,n,o,i=null===(o=null===(n=null===(r=null==e?void 0:e.choices)||void 0===r?void 0:r[0])||void 0===n?void 0:n.delta)||void 0===o?void 0:o.content;"string"==typeof i&&t.enqueue(i)}}))),usage:Promise.resolve(n),error:g}];case 10:return[3,2];case 11:return[4,p()];case 12:return(h=z.sent())?(T=h.message,P=h.usage,di(n,P),O=oi(oi([],l.messages,!0),[T],!1),a({messages:O.slice(),finishReason:"tool_call",stepUsage:P,text:T.content,toolCall:T.tool_calls[0],totalUsage:Object.assign({},n)}),j=f.tee(),q=j[0],k=j[1],[2,{messages:Promise.resolve(oi(oi([],l.messages,!0),[T],!1)),dataStream:Dn(q),textStream:Dn(k.pipeThrough(new Mn({transform:function(e,t){var r,n,o,i=null===(o=null===(n=null===(r=null==e?void 0:e.choices)||void 0===r?void 0:r[0])||void 0===n?void 0:n.delta)||void 0===o?void 0:o.content;"string"==typeof i&&t.enqueue(i)}}))),usage:Promise.resolve(n)}]):(E=Hn(),C=Hn(),x={role:"assistant",content:""},A="",I={completion_tokens:0,prompt_tokens:0,total_tokens:0},W=f.pipeThrough(new Mn({transform:function(e,t){var r,n,o,i,a,s,u,l,c=null===(o=null===(n=null===(r=null==e?void 0:e.choices)||void 0===r?void 0:r[0])||void 0===n?void 0:n.delta)||void 0===o?void 0:o.content;"string"==typeof c&&(x.content+=c);var f=null===(a=null===(i=null==e?void 0:e.choices)||void 0===i?void 0:i[0])||void 0===a?void 0:a.finish_reason;f&&(A=f),(null===(s=null==e?void 0:e.usage)||void 0===s?void 0:s.completion_tokens)&&(I.completion_tokens=e.usage.completion_tokens),(null===(u=null==e?void 0:e.usage)||void 0===u?void 0:u.prompt_tokens)&&(I.prompt_tokens=e.usage.prompt_tokens),(null===(l=null==e?void 0:e.usage)||void 0===l?void 0:l.total_tokens)&&(I.total_tokens=e.usage.total_tokens),t.enqueue(e)},flush:function(){E.res(oi(oi([],l.messages,!0),[x],!1)),di(n,I),C.res(Object.assign({},n)),null==a||a({messages:oi(oi([],l.messages,!0),[x],!1),finishReason:A,text:x.content,stepUsage:I,totalUsage:Object.assign({},n)})}})),U=W.tee(),B=U[0],M=U[1],[2,{messages:E.promise,dataStream:Dn(B),textStream:Dn(M.pipeThrough(new Mn({transform:function(e,t){var r,n,o,i=null===(o=null===(n=null===(r=null==e?void 0:e.choices)||void 0===r?void 0:r[0])||void 0===n?void 0:n.delta)||void 0===o?void 0:o.content;"string"==typeof i&&t.enqueue(i)}}))),usage:C.promise}])}}))}))},e}();function si(e){var t,r=null===(t=null==e?void 0:e.choices)||void 0===t?void 0:t[0];if(!r)return null;var n=r.finish_reason,o=r.message;return"tool_calls"!==n?null:o&&Yn(o)?o.tool_calls[0]:null}function ui(e,t,r){e.push(t,{role:"tool",tool_call_id:t.tool_calls[0].id,content:JSON.stringify(r)})}var li=new Map;function ci(e){return li.get(e.function.name)(JSON.parse(e.function.arguments))}function fi(e){var t,r,n;return{completion_tokens:null!==(t=null==e?void 0:e.completion_tokens)&&void 0!==t?t:0,prompt_tokens:null!==(r=null==e?void 0:e.prompt_tokens)&&void 0!==r?r:0,total_tokens:null!==(n=null==e?void 0:e.total_tokens)&&void 0!==n?n:0}}function di(e,t){e.completion_tokens+=t.completion_tokens,e.prompt_tokens+=t.prompt_tokens,e.total_tokens+=t.total_tokens}var hi={hunyuan:mo,"hunyuan-beta":ho,ark:So,dashscope:jo,"01-ai":xo,moonshot:Bo,zhipu:io,"hunyuan-exp":Fo,"hunyuan-open":Go,deepseek:Qo},pi="@cloudbase/js-sdk";function bi(){return pi}var yi,mi="INVALID_OPERATION",vi="OPERATION_FAIL";!function(e){e.local="local",e.none="none",e.session="session"}(yi||(yi={}));function _i(e,t){console.warn("[".concat(bi(),"][").concat(e,"]:").concat(t))}var gi,wi,Si=(gi=function(e,t){return gi=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])},gi(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function r(){this.constructor=e}gi(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}),Ri=function(){return Ri=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},Ri.apply(this,arguments)},Ti=function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))},Pi=function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],n=0}finally{r=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}};!function(e){function t(t){var r=e.call(this)||this,n=t.timeout,o=t.timeoutMsg,i=t.restrictedMethods;return r.timeout=n||0,r.timeoutMsg=o||"请求超时",r.restrictedMethods=i||["get","post","upload","download"],r}Si(t,e),t.prototype.get=function(e){return this.request(Ri(Ri({},e),{method:"get"}),this.restrictedMethods.includes("get"))},t.prototype.post=function(e){return this.request(Ri(Ri({},e),{method:"post"}),this.restrictedMethods.includes("post"))},t.prototype.put=function(e){return this.request(Ri(Ri({},e),{method:"put"}))},t.prototype.upload=function(e){var t=e.data,r=e.file,n=e.name,o=e.method,i=e.headers,a=void 0===i?{}:i,s={post:"post",put:"put"}[null==o?void 0:o.toLowerCase()]||"put",u=new FormData;return"post"===s?(Object.keys(t).forEach((function(e){u.append(e,t[e])})),u.append("key",n),u.append("file",r),this.request(Ri(Ri({},e),{data:u,method:s}),this.restrictedMethods.includes("upload"))):this.request(Ri(Ri({},e),{method:"put",headers:a,body:r}),this.restrictedMethods.includes("upload"))},t.prototype.download=function(e){return Ti(this,void 0,void 0,(function(){var t,r,n,o;return Pi(this,(function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,this.get(Ri(Ri({},e),{headers:{},responseType:"blob"}))];case 1:return t=i.sent().data,r=window.URL.createObjectURL(new Blob([t])),n=decodeURIComponent(new URL(e.url).pathname.split("/").pop()||""),(o=document.createElement("a")).href=r,o.setAttribute("download",n),o.style.display="none",document.body.appendChild(o),o.click(),window.URL.revokeObjectURL(r),document.body.removeChild(o),[3,3];case 2:return i.sent(),[3,3];case 3:return[2,new Promise((function(t){t({statusCode:200,tempFilePath:e.url})}))]}}))}))},t.prototype.fetch=function(e){var t;return Ti(this,void 0,void 0,(function(){var r,n,o,i,a,s,u,l,c,f,d,h,p,b=this;return Pi(this,(function(y){switch(y.label){case 0:return r=new AbortController,n=e.url,o=e.enableAbort,i=void 0!==o&&o,a=e.stream,s=void 0!==a&&a,u=e.signal,l=e.timeout,c=e.shouldThrowOnError,f=void 0===c||c,d=null!=l?l:this.timeout,u&&(u.aborted&&r.abort(),u.addEventListener("abort",(function(){return r.abort()}))),h=null,i&&d&&(h=setTimeout((function(){console.warn(b.timeoutMsg),r.abort(new Error(b.timeoutMsg))}),d)),[4,fetch(n,Ri(Ri({},e),{signal:r.signal})).then((function(e){return Ti(b,void 0,void 0,(function(){var t,r,n;return Pi(this,(function(o){switch(o.label){case 0:return clearTimeout(h),f?e.ok?(t=e,[3,3]):[3,1]:[3,4];case 1:return n=(r=Promise).reject,[4,e.json()];case 2:t=n.apply(r,[o.sent()]),o.label=3;case 3:return[2,t];case 4:return[2,e]}}))}))})).catch((function(e){if(clearTimeout(h),f)return Promise.reject(e)}))];case 1:return p=y.sent(),[2,{data:s?p.body:(null===(t=p.headers.get("content-type"))||void 0===t?void 0:t.includes("application/json"))?p.json():p.text(),statusCode:p.status,header:p.headers}]}}))}))},t.prototype.request=function(e,t){var r=this;void 0===t&&(t=!1);var n=String(e.method).toLowerCase()||"get";return new Promise((function(o){var i,a,s,u=e.url,l=e.headers,c=void 0===l?{}:l,f=e.data,d=e.responseType,h=e.withCredentials,p=e.body,b=e.onUploadProgress,y=function(e,t,r){void 0===r&&(r={});var n=/\?/.test(t),o="";return Object.keys(r).forEach((function(e){""===o?!n&&(t+="?"):o+="&",o+="".concat(e,"=").concat(encodeURIComponent(r[e]))})),/^http(s)?:\/\//.test(t+=o)?t:"".concat(e).concat(t)}("https:",u,"get"===n?f:{}),m=new XMLHttpRequest;m.open(n,y),d&&(m.responseType=d),Object.keys(c).forEach((function(e){m.setRequestHeader(e,c[e])})),b&&m.upload.addEventListener("progress",b),m.onreadystatechange=function(){var e={};if(4===m.readyState){var t=m.getAllResponseHeaders().trim().split(/[\r\n]+/),r={};t.forEach((function(e){var t=e.split(": "),n=t.shift().toLowerCase(),o=t.join(": ");r[n]=o})),e.header=r,e.statusCode=m.status;try{e.data="blob"===d?m.response:JSON.parse(m.responseText)}catch(t){e.data="blob"===d?m.response:m.responseText}clearTimeout(i),o(e)}},t&&r.timeout&&(i=setTimeout((function(){console.warn(r.timeoutMsg),m.abort()}),r.timeout)),s=f,a="[object FormData]"===Object.prototype.toString.call(s)?f:"application/x-www-form-urlencoded"===c["content-type"]?function(e){void 0===e&&(e={});var t=[];return Object.keys(e).forEach((function(r){t.push("".concat(r,"=").concat(encodeURIComponent(e[r])))})),t.join("&")}(f):p||(f?JSON.stringify(f):void 0),h&&(m.withCredentials=!0),m.send(a)}))}}((function(){})),function(e){e.WEB="web",e.WX_MP="wx_mp"}(wi||(wi={}));var Oi=function(){var e=function(t,r){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])},e(t,r)};return function(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),ji=function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))},qi=function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],n=0}finally{r=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}},ki=function(e){function t(t){var r=e.call(this)||this;return r.root=t,t.tcbCacheObject||(t.tcbCacheObject={}),r}return Oi(t,e),t.prototype.setItem=function(e,t){this.root.tcbCacheObject[e]=t},t.prototype.getItem=function(e){return this.root.tcbCacheObject[e]},t.prototype.removeItem=function(e){delete this.root.tcbCacheObject[e]},t.prototype.clear=function(){delete this.root.tcbCacheObject},t}((function(){}));!function(){function e(e){this.keys={};var t=e.persistence,r=e.platformInfo,n=void 0===r?{}:r,o=e.keys,i=void 0===o?{}:o;this.platformInfo=n,this.storage||(this.persistenceTag=this.platformInfo.adapter.primaryStorage||t,this.storage=function(e,t){switch(e){case"local":default:return t.localStorage?t.localStorage:(_i("INVALID_PARAMS","localStorage is not supported on current platform"),new ki(t.root));case"none":return new ki(t.root)}}(this.persistenceTag,this.platformInfo.adapter),this.keys=i)}Object.defineProperty(e.prototype,"mode",{get:function(){return this.storage.mode||"sync"},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"persistence",{get:function(){return this.persistenceTag},enumerable:!1,configurable:!0}),e.prototype.setStore=function(e,t,r){if("async"!==this.mode){if(this.storage)try{var n={version:r||"localCachev1",content:t};this.storage.setItem(e,JSON.stringify(n))}catch(e){throw new Error(JSON.stringify({code:vi,msg:"[".concat(bi(),"][").concat(vi,"]setStore failed"),info:e}))}}else _i(mi,"current platform's storage is asynchronous, please use setStoreAsync insteed")},e.prototype.setStoreAsync=function(e,t,r){return ji(this,void 0,void 0,(function(){var n;return qi(this,(function(o){switch(o.label){case 0:if(!this.storage)return[2];o.label=1;case 1:return o.trys.push([1,3,,4]),n={version:r||"localCachev1",content:t},[4,this.storage.setItem(e,JSON.stringify(n))];case 2:return o.sent(),[3,4];case 3:return o.sent(),[2];case 4:return[2]}}))}))},e.prototype.getStore=function(e,t){var r;if("async"!==this.mode){try{if("undefined"!=typeof process&&(null===(r={IS_MP_BUILD:!0,IS_BROWSER_BUILD:!0})||void 0===r?void 0:r.tcb_token))return{IS_MP_BUILD:!0,IS_BROWSER_BUILD:!0}.tcb_token;if(!this.storage)return""}catch(e){return""}t=t||"localCachev1";var n=this.storage.getItem(e);return n&&n.indexOf(t)>=0?JSON.parse(n).content:""}_i(mi,"current platform's storage is asynchronous, please use getStoreAsync insteed")},e.prototype.getStoreAsync=function(e,t){var r;return ji(this,void 0,void 0,(function(){var n;return qi(this,(function(o){switch(o.label){case 0:try{if("undefined"!=typeof process&&(null===(r={IS_MP_BUILD:!0,IS_BROWSER_BUILD:!0})||void 0===r?void 0:r.tcb_token))return[2,{IS_MP_BUILD:!0,IS_BROWSER_BUILD:!0}.tcb_token];if(!this.storage)return[2,""]}catch(e){return[2,""]}return t=t||"localCachev1",[4,this.storage.getItem(e)];case 1:return(n=o.sent())&&n.indexOf(t)>=0?[2,JSON.parse(n).content]:[2,""]}}))}))},e.prototype.removeStore=function(e){"async"!==this.mode?this.storage.removeItem(e):_i(mi,"current platform's storage is asynchronous, please use removeStoreAsync insteed")},e.prototype.removeStoreAsync=function(e){return ji(this,void 0,void 0,(function(){return qi(this,(function(t){switch(t.label){case 0:return[4,this.storage.removeItem(e)];case 1:return t.sent(),[2]}}))}))}}();var Ei=function(){var e=function(t,r){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])},e(t,r)};return function(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),Ci=function(e,t){this.data=t||null,this.name=e},xi=function(e){function t(t,r){var n=e.call(this,"error",{error:t,data:r})||this;return n.error=t,n}return Ei(t,e),t}(Ci),Ai=function(){function e(){this.listeners={}}return e.prototype.on=function(e,t){return function(e,t,r){r[e]=r[e]||[],r[e].push(t)}(e,t,this.listeners),this},e.prototype.off=function(e,t){return function(e,t,r){if(null==r?void 0:r[e]){var n=r[e].indexOf(t);-1!==n&&r[e].splice(n,1)}}(e,t,this.listeners),this},e.prototype.fire=function(e,t){if(e instanceof xi)return console.error(e.error),this;var r="string"==typeof e?new Ci(e,t||{}):e,n=r.name;if(this.listens(n)){r.target=this;for(var o=0,i=this.listeners[n]?function(e,t,r){if(r||2===arguments.length)for(var n,o=0,i=t.length;o<i;o++)!n&&o in t||(n||(n=Array.prototype.slice.call(t,0,o)),n[o]=t[o]);return e.concat(n||Array.prototype.slice.call(t))}([],this.listeners[n],!0):[];o<i.length;o++)i[o].call(this,r)}return this},e.prototype.listens=function(e){return this.listeners[e]&&this.listeners[e].length>0},e}();new Ai;var Ii=new Ai;function Wi(e){this.message=e}function Ui(e){this.message=e}"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.indexOf("Firefox"),Wi.prototype=new Error,Wi.prototype.name="InvalidCharacterError","undefined"!=typeof window&&window.atob&&window.atob.bind(window),Ui.prototype=new Error,Ui.prototype.name="InvalidTokenError";var Bi=function(){return Bi=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},Bi.apply(this,arguments)},Mi=function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))},Li=function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],n=0}finally{r=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}},zi=hi,Fi=function(){function e(e,t,r){var n=this;this.req=e,this.baseUrl=t,this.modelRequest=function(e){var t=e.url,r=e.data,o=e.headers,i=e.stream,a=e.timeout;return Mi(n,void 0,void 0,(function(){var e,n,s,u,l,c,f;return Li(this,(function(d){switch(d.label){case 0:return e={"Content-Type":"application/json"},i&&Object.assign(e,{Accept:"text/event-stream"}),[4,this.req.fetch({method:"post",headers:Bi(Bi((l={},l[null===(c=this.i18n)||void 0===c?void 0:c.LANG_HEADER_KEY]=null===(f=this.i18n)||void 0===f?void 0:f.lang,l),e),o),body:JSON.stringify(r),url:t,stream:i,timeout:a})];case 1:return n=d.sent(),s=n.data,u=n.header,[2,this.handleResponseData(s,u)]}}))}))},this.botRequest=function(e){var t=e.method,r=e.url,o=e.data,i=void 0===o?{}:o,a=e.headers,s=e.stream,u=e.timeout;return Mi(n,void 0,void 0,(function(){var e,n,o,l,c,f,d,h;return Li(this,(function(p){switch(p.label){case 0:return"get"!==t?[3,2]:(e=this.handleResponseData,[4,this.req.fetch({url:"".concat(r,"?").concat((b=i,Object.entries(b).map((function(e){var t=e[0],r=e[1];return"".concat(t,"=").concat(r)})).join("&"))),method:t,headers:a,stream:s,timeout:u})]);case 1:return[2,e.apply(this,[p.sent().data])];case 2:return n={"Content-Type":"application/json"},s&&Object.assign(n,{Accept:"text/event-stream"}),[4,this.req.fetch({url:r,body:JSON.stringify(i),headers:Bi(Bi((f={},f[null===(d=this.i18n)||void 0===d?void 0:d.LANG_HEADER_KEY]=null===(h=this.i18n)||void 0===h?void 0:h.lang,f),n),a),stream:s,method:t,timeout:u})];case 3:return o=p.sent(),l=o.data,c=o.header,[2,this.handleResponseData(l,c)]}var b}))}))},this.aiBaseUrl="".concat(t,"/ai"),this.aiBotBaseUrl="".concat(t,"/aibot"),this.bot=new Zn(this.botRequest,this.aiBotBaseUrl),this.i18n=r,Ii.on("lang_change",(function(e){var t;n.i18n=(null===(t=e.data)||void 0===t?void 0:t.i18n)||n.i18n}))}return e.prototype.handleResponseData=function(e,t){var r,n;return Mi(this,void 0,void 0,(function(){var o,i;return Li(this,(function(a){switch(a.label){case 0:return o="".concat(this.i18n.t("请检查调用方式,或前往云开发 AI+ 首页查看文档"),":https://tcb.cloud.tencent.com/dev#/ai"),"object"==typeof e&&e&&"then"in e?[4,e]:[3,2];case 1:if("object"==typeof(i=a.sent())&&i&&"code"in i&&"NORMAL"!==i.code)throw new Error("".concat(this.i18n.t("AI+ 请求出错,错误码"),":").concat(i.code,",").concat(this.i18n.t("错误信息"),":").concat(i.message,"\n").concat(o,"\n").concat(JSON.stringify(i,null,2)));return[2,e];case 2:return(null===(n=null===(r=null==t?void 0:t.get)||void 0===r?void 0:r.call(t,"content-type"))||void 0===n?void 0:n.includes("application/json"))?[4,Gn(e)]:[3,4];case 3:if("object"==typeof(i=a.sent())&&i&&"code"in i&&"NORMAL"!==i.code)throw new Error("".concat(this.i18n.t("AI+ 请求出错,错误码"),":").concat(i.code,",").concat(this.i18n.t("错误信息"),":").concat(i.message,"\n").concat(o,"\n").concat(JSON.stringify(i,null,2)));a.label=4;case 4:return[2,e]}}))}))},e.prototype.createModel=function(e,t){var r,n=zi[e];if(n)r=new n(this.modelRequest,this.aiBaseUrl);else{var o="string"==typeof(null==t?void 0:t.defaultModelSubUrl)?t.defaultModelSubUrl:"/chat/completions";r=new Zo(this.modelRequest,this.aiBaseUrl,"".concat(e).concat(o))}return new ai(r)},e.prototype.registerModel=function(e,t){null==zi[e]?zi[e]=t:console.warn("AI model ".concat(e," already exists!"))},e.prototype.createImageModel=function(e){return new ei(this.modelRequest,this.aiBaseUrl,e)},e.prototype.registerFunctionTool=function(e){li.has(e.name)&&console.warn("AI function tool ".concat(e.name," already exists and will be overwritten!")),li.set(e.name,e.fn)},e}(),Di=function(){},$i=function(){return $i=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},$i.apply(this,arguments)},Ni=function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(r[n[o]]=e[n[o]])}return r},Gi=Ni(o,["MODELS"]),Hi=function(e){var t=e.getAccessToken,r=e.req;return{download:r.download,post:r.post,upload:r.upload,fetch:function(e){return function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))}(void 0,void 0,void 0,(function(){var n,o,i,a,s;return function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],n=0}finally{r=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}}(this,(function(u){switch(u.label){case 0:if("function"!=typeof r.fetch)throw new Error("req.fetch is not a function");return n=e.token,o=e.headers,i=void 0===o?{}:o,a=Ni(e,["token","headers"]),null==n?[3,1]:(s=n,[3,3]);case 1:return[4,t()];case 2:s=u.sent().accessToken,u.label=3;case 3:return[2,r.fetch($i({headers:$i({Authorization:"Bearer ".concat(s)},i)},a))]}}))}))}}};function Yi(e){var t=e.env,r=e.baseUrl,n=e.req,o=e.getAccessToken,i=e.handleReqInstance,a=e.i18n;return new Fi(function(){if(null==i){if(null==o)throw new Error("`getAccessToken` is required when `handleReqInstance` is not provided!");return Hi({req:n,getAccessToken:o})}return i({req:n})}(),function(){if(null!=r)return r;if(null==t)throw new Error("`env` is required when `baseUrl` is not provided!");return"https://".concat(t,".api.tcloudbasegateway.com/v1")}(),a)}var Ji=Yi,Qi={name:"ai",entity:{ai:function(e){var t,r=this,n=this.request;if(null==n.fetch)throw new Error("cloudbase.request.fetch() unimplemented!");var o=null!==(t=null==e?void 0:e.baseUrl)&&void 0!==t?t:function(){var e=r.getEndPointWithKey("GATEWAY"),t=e.BASE_URL,n=e.PROTOCOL;return"".concat(n).concat(t)}();return Yi({req:n,baseUrl:o,handleReqInstance:function(e){return e.req},i18n:this.config.i18n})}}};function Vi(e){try{e.registerComponent(Qi)}catch(e){console.warn(e)}}try{window.registerAi=Vi}catch(i){}}},t={};function r(n){var o=t[n];if(void 0!==o)return o.exports;var i=t[n]={exports:{}};return e[n].call(i.exports,i,i.exports,r),i.exports}return r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r(639)})()));
|