@cloudbase/ai 2.22.10 → 2.23.0
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/dist/cjs/AI.d.ts +1 -0
- package/dist/cjs/AI.js +4 -1
- package/dist/cjs/index.d.ts +5 -3
- package/dist/cjs/index.js +6 -4
- package/dist/cjs/models/image-model.d.ts +19 -0
- package/dist/cjs/models/image-model.js +91 -0
- package/dist/cjs/models/index.d.ts +2 -1
- package/dist/cjs/models/index.js +4 -2
- package/dist/cjs/type.d.ts +58 -0
- package/dist/cjs/type.js +1 -1
- package/dist/esm/AI.d.ts +1 -0
- package/dist/esm/AI.js +4 -1
- package/dist/esm/index.d.ts +5 -3
- package/dist/esm/index.js +5 -4
- package/dist/esm/models/image-model.d.ts +19 -0
- package/dist/esm/models/image-model.js +88 -0
- package/dist/esm/models/index.d.ts +2 -1
- package/dist/esm/models/index.js +3 -2
- package/dist/esm/type.d.ts +58 -0
- package/dist/esm/type.js +1 -1
- package/dist/miniprogram/index.js +1 -1
- package/package.json +4 -4
- package/src/AI.ts +9 -1
- package/src/index.ts +11 -5
- package/src/models/image-model.ts +74 -0
- package/src/models/index.ts +2 -0
- package/src/type.ts +177 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/*! For license information please see index.js.LICENSE.txt */
|
|
2
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("tcbauth",[],t):"object"==typeof exports?exports.tcbauth=t():e.tcbauth=t()}("undefined"!=typeof window?window:this,()=>(()=>{var e={410:function(e,t,r){var n,o,i;o=[],void 0===(i="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,o):n)||(e.exports=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}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})};var n={};return(()=>{"use strict";r.r(n),r.d(n,{AI:()=>Yi,Bot:()=>eo,SimpleChatModel:()=>Ji,createAi:()=>ea,models:()=>Zi,registerAi:()=>ra,utils:()=>e});var e={};r.r(e),r.d(e,{ReadableStream:()=>Mn,TextDecoderStream:()=>Dn,TransformStream:()=>Ln,createAsyncIterable:()=>Nn,createEventSourceParserTransformStream:()=>zn,createPromise:()=>Yn,functionToolToModelTool:()=>Qn,intoStandardStream:()=>Gn,intoTextStream:()=>$n,isToolCallAssistantMessage:()=>Jn,readableStream2JsonObject:()=>Hn,toPolyfillReadable:()=>Fn});var t={};function o(){}function i(e){return"object"==typeof e&&null!==e||"function"==typeof e}r.r(t),r.d(t,{ArkSimpleModel:()=>Ro,DSSimpleModel:()=>qo,DefaultSimpleModel:()=>ei,HunYuanBetaSimpleModel:()=>po,HunYuanExpSimpleModel:()=>Do,HunYuanOpenSimpleModel:()=>Ho,HunYuanSimpleModel:()=>vo,MODELS:()=>bi,MoonshotSimpleModel:()=>Mo,ReactModel:()=>ui,YiSimpleModel:()=>Ao,ZhiPuSimpleModel:()=>ao,toolMap:()=>fi});const a=o;function s(e,t){try{Object.defineProperty(e,"name",{value:t,configurable:!0})}catch(e){}}const u=Promise,l=Promise.resolve.bind(u),c=Promise.prototype.then,f=Promise.reject.bind(u),d=l;function h(e){return new u(e)}function p(e){return h(t=>t(e))}function b(e){return f(e)}function y(e,t,r){return c.call(e,t,r)}function m(e,t,r){y(y(e,t,r),void 0,a)}function v(e,t){m(e,t)}function _(e,t){m(e,void 0,t)}function g(e,t,r){return y(e,t,r)}function w(e){y(e,void 0,a)}let S=e=>{if("function"==typeof queueMicrotask)S=queueMicrotask;else{const e=p(void 0);S=t=>y(e,t)}return S(e)};function R(e,t,r){if("function"!=typeof e)throw new TypeError("Argument is not a function");return Function.prototype.apply.call(e,t,r)}function T(e,t,r){try{return p(R(e,t,r))}catch(e){return b(e)}}class P{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 O=Symbol("[[AbortSteps]]"),j=Symbol("[[ErrorSteps]]"),q=Symbol("[[CancelSteps]]"),k=Symbol("[[PullSteps]]"),E=Symbol("[[ReleaseSteps]]");function C(e,t){e._ownerReadableStream=t,t._reader=e,"readable"===t._state?W(e):"closed"===t._state?function(e){W(e),M(e)}(e):U(e,t._storedError)}function x(e,t){return Lr(e._ownerReadableStream,t)}function A(e){const t=e._ownerReadableStream;"readable"===t._state?B(e,new TypeError("Reader was released and can no longer be used to monitor the stream's closedness")):function(e,t){U(e,new TypeError("Reader was released and can no longer be used to monitor the stream's closedness"))}(e),t._readableStreamController[E](),t._reader=void 0,e._ownerReadableStream=void 0}function I(e){return new TypeError("Cannot "+e+" a stream using a released reader")}function W(e){e._closedPromise=h((t,r)=>{e._closedPromise_resolve=t,e._closedPromise_reject=r})}function U(e,t){W(e),B(e,t)}function B(e,t){void 0!==e._closedPromise_reject&&(w(e._closedPromise),e._closedPromise_reject(t),e._closedPromise_resolve=void 0,e._closedPromise_reject=void 0)}function M(e){void 0!==e._closedPromise_resolve&&(e._closedPromise_resolve(void 0),e._closedPromise_resolve=void 0,e._closedPromise_reject=void 0)}const L=Number.isFinite||function(e){return"number"==typeof e&&isFinite(e)},z=Math.trunc||function(e){return e<0?Math.ceil(e):Math.floor(e)};function F(e,t){if(void 0!==e&&"object"!=typeof(r=e)&&"function"!=typeof r)throw new TypeError(t+" is not an object.");var r}function D(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 $(e,t,r){if(void 0===e)throw new TypeError(`${t} is required in '${r}'.`)}function H(e){return Number(e)}function Y(e){return 0===e?0:e}function J(e,t){const r=Number.MAX_SAFE_INTEGER;let n=Number(e);if(n=Y(n),!L(n))throw new TypeError(t+" is not a finite number");if(n=function(e){return Y(z(e))}(n),n<0||n>r)throw new TypeError(`${t} is outside the accepted range of 0 to ${r}, inclusive`);return L(n)&&0!==n?n:0}function Q(e,t){if(!Br(e))throw new TypeError(t+" is not a ReadableStream.")}function V(e){return new te(e)}function X(e,t){e._reader._readRequests.push(t)}function K(e,t,r){const n=e._reader._readRequests.shift();r?n._closeSteps():n._chunkSteps(t)}function Z(e){return e._reader._readRequests.length}function ee(e){const t=e._reader;return void 0!==t&&!!re(t)}class te{constructor(e){if(G(e,1,"ReadableStreamDefaultReader"),Q(e,"First parameter"),Mr(e))throw new TypeError("This stream has already been locked for exclusive reading by another reader");C(this,e),this._readRequests=new P}get closed(){return re(this)?this._closedPromise:b(ie("closed"))}cancel(e){return re(this)?void 0===this._ownerReadableStream?b(I("cancel")):x(this,e):b(ie("cancel"))}read(){if(!re(this))return b(ie("read"));if(void 0===this._ownerReadableStream)return b(I("read from"));let e,t;const r=h((r,n)=>{e=r,t=n});return ne(this,{_chunkSteps:t=>e({value:t,done:!1}),_closeSteps:()=>e({value:void 0,done:!0}),_errorSteps:e=>t(e)}),r}releaseLock(){if(!re(this))throw ie("releaseLock");void 0!==this._ownerReadableStream&&function(e){A(e);oe(e,new TypeError("Reader was released"))}(this)}}function re(e){return!!i(e)&&!!Object.prototype.hasOwnProperty.call(e,"_readRequests")&&e instanceof te}function ne(e,t){const r=e._ownerReadableStream;r._disturbed=!0,"closed"===r._state?t._closeSteps():"errored"===r._state?t._errorSteps(r._storedError):r._readableStreamController[k](t)}function oe(e,t){const r=e._readRequests;e._readRequests=new P,r.forEach(e=>{e._errorSteps(t)})}function ie(e){return new TypeError(`ReadableStreamDefaultReader.prototype.${e} can only be used on a ReadableStreamDefaultReader`)}var ae,se,ue;function le(e){return e.slice()}function ce(e,t,r,n,o){new Uint8Array(e).set(new Uint8Array(r,n,o),t)}Object.defineProperties(te.prototype,{cancel:{enumerable:!0},read:{enumerable:!0},releaseLock:{enumerable:!0},closed:{enumerable:!0}}),s(te.prototype.cancel,"cancel"),s(te.prototype.read,"read"),s(te.prototype.releaseLock,"releaseLock"),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(te.prototype,Symbol.toStringTag,{value:"ReadableStreamDefaultReader",configurable:!0});let fe=e=>(fe="function"==typeof e.transfer?e=>e.transfer():"function"==typeof structuredClone?e=>structuredClone(e,{transfer:[e]}):e=>e,fe(e)),de=e=>(de="boolean"==typeof e.detached?e=>e.detached:e=>0===e.byteLength,de(e));function he(e,t,r){if(e.slice)return e.slice(t,r);const n=r-t,o=new ArrayBuffer(n);return ce(o,0,e,t,n),o}function pe(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 be(e){try{const t=e.done,r=e.value;return y(d(r),e=>({done:t,value:e}))}catch(e){return b(e)}}const ye=null!==(ue=null!==(ae=Symbol.asyncIterator)&&void 0!==ae?ae:null===(se=Symbol.for)||void 0===se?void 0:se.call(Symbol,"Symbol.asyncIterator"))&&void 0!==ue?ue:"@@asyncIterator";function me(e){const t=R(e.nextMethod,e.iterator,[]);if(!i(t))throw new TypeError("The iterator.next() method must return an object");return t}class ve{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?g(this._ongoingPromise,e,e):e(),this._ongoingPromise}return(e){const t=()=>this._returnSteps(e);return this._ongoingPromise?g(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=h((e,n)=>{t=e,r=n});return ne(e,{_chunkSteps:e=>{this._ongoingPromise=void 0,S(()=>t({value:e,done:!1}))},_closeSteps:()=>{this._ongoingPromise=void 0,this._isFinished=!0,A(e),t({value:void 0,done:!0})},_errorSteps:t=>{this._ongoingPromise=void 0,this._isFinished=!0,A(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=x(t,e);return A(t),g(r,()=>({value:e,done:!0}))}return A(t),p({value:e,done:!0})}}const _e={next(){return ge(this)?this._asyncIteratorImpl.next():b(we("next"))},return(e){return ge(this)?this._asyncIteratorImpl.return(e):b(we("return"))},[ye](){return this}};function ge(e){if(!i(e))return!1;if(!Object.prototype.hasOwnProperty.call(e,"_asyncIteratorImpl"))return!1;try{return e._asyncIteratorImpl instanceof ve}catch(e){return!1}}function we(e){return new TypeError(`ReadableStreamAsyncIterator.${e} can only be used on a ReadableSteamAsyncIterator`)}Object.defineProperty(_e,ye,{enumerable:!1});const Se=Number.isNaN||function(e){return e!=e};function Re(e){const t=he(e.buffer,e.byteOffset,e.byteOffset+e.byteLength);return new Uint8Array(t)}function Te(e){const t=e._queue.shift();return e._queueTotalSize-=t.size,e._queueTotalSize<0&&(e._queueTotalSize=0),t.value}function Pe(e,t,r){if("number"!=typeof(n=r)||Se(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 Oe(e){e._queue=new P,e._queueTotalSize=0}function je(e){return e===DataView}class qe{constructor(){throw new TypeError("Illegal constructor")}get view(){if(!Ce(this))throw rt("view");return this._view}respond(e){if(!Ce(this))throw rt("respond");if(G(e,1,"respond"),e=J(e,"First parameter"),void 0===this._associatedReadableByteStreamController)throw new TypeError("This BYOB request has been invalidated");if(de(this._view.buffer))throw new TypeError("The BYOB request's buffer has been detached and so cannot be used as a response");Ze(this._associatedReadableByteStreamController,e)}respondWithNewView(e){if(!Ce(this))throw rt("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(de(e.buffer))throw new TypeError("The given view's buffer has been detached and so cannot be used as a response");et(this._associatedReadableByteStreamController,e)}}Object.defineProperties(qe.prototype,{respond:{enumerable:!0},respondWithNewView:{enumerable:!0},view:{enumerable:!0}}),s(qe.prototype.respond,"respond"),s(qe.prototype.respondWithNewView,"respondWithNewView"),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(qe.prototype,Symbol.toStringTag,{value:"ReadableStreamBYOBRequest",configurable:!0});class ke{constructor(){throw new TypeError("Illegal constructor")}get byobRequest(){if(!Ee(this))throw nt("byobRequest");return Xe(this)}get desiredSize(){if(!Ee(this))throw nt("desiredSize");return Ke(this)}close(){if(!Ee(this))throw nt("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`);Ye(this)}enqueue(e){if(!Ee(this))throw nt("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`);Je(this,e)}error(e){if(!Ee(this))throw nt("error");Qe(this,e)}[q](e){Ae(this),Oe(this);const t=this._cancelAlgorithm(e);return He(this),t}[k](e){const t=this._controlledReadableByteStream;if(this._queueTotalSize>0)return void Ve(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)}X(t,e),xe(this)}[E](){if(this._pendingPullIntos.length>0){const e=this._pendingPullIntos.peek();e.readerType="none",this._pendingPullIntos=new P,this._pendingPullIntos.push(e)}}}function Ee(e){return!!i(e)&&!!Object.prototype.hasOwnProperty.call(e,"_controlledReadableByteStream")&&e instanceof ke}function Ce(e){return!!i(e)&&!!Object.prototype.hasOwnProperty.call(e,"_associatedReadableByteStreamController")&&e instanceof qe}function xe(e){(function(e){const t=e._controlledReadableByteStream;if("readable"!==t._state)return!1;if(e._closeRequested)return!1;if(!e._started)return!1;if(ee(t)&&Z(t)>0)return!0;if(ut(t)&&st(t)>0)return!0;return Ke(e)>0})(e)&&(e._pulling?e._pullAgain=!0:(e._pulling=!0,m(e._pullAlgorithm(),()=>(e._pulling=!1,e._pullAgain&&(e._pullAgain=!1,xe(e)),null),t=>(Qe(e,t),null))))}function Ae(e){De(e),e._pendingPullIntos=new P}function Ie(e,t){let r=!1;"closed"===e._state&&(r=!0);const n=We(t);"default"===t.readerType?K(e,n,r):function(e,t,r){const n=e._reader._readIntoRequests.shift();r?n._closeSteps(t):n._chunkSteps(t)}(e,n,r)}function We(e){const t=e.bytesFilled,r=e.elementSize;return new e.viewConstructor(e.buffer,e.byteOffset,t/r)}function Ue(e,t,r,n){e._queue.push({buffer:t,byteOffset:r,byteLength:n}),e._queueTotalSize+=n}function Be(e,t,r,n){let o;try{o=he(t,r,r+n)}catch(t){throw Qe(e,t),t}Ue(e,o,0,n)}function Me(e,t){t.bytesFilled>0&&Be(e,t.buffer,t.byteOffset,t.bytesFilled),$e(e)}function Le(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;ce(t.buffer,i,r.buffer,r.byteOffset,n),r.byteLength===n?s.shift():(r.byteOffset+=n,r.byteLength-=n),e._queueTotalSize-=n,ze(e,n,t),o-=n}return i}function ze(e,t,r){r.bytesFilled+=t}function Fe(e){0===e._queueTotalSize&&e._closeRequested?(He(e),zr(e._controlledReadableByteStream)):xe(e)}function De(e){null!==e._byobRequest&&(e._byobRequest._associatedReadableByteStreamController=void 0,e._byobRequest._view=null,e._byobRequest=null)}function Ne(e){for(;e._pendingPullIntos.length>0;){if(0===e._queueTotalSize)return;const t=e._pendingPullIntos.peek();Le(e,t)&&($e(e),Ie(e._controlledReadableByteStream,t))}}function Ge(e,t){const r=e._pendingPullIntos.peek();De(e),"closed"===e._controlledReadableByteStream._state?function(e,t){"none"===t.readerType&&$e(e);const r=e._controlledReadableByteStream;if(ut(r))for(;st(r)>0;)Ie(r,$e(e))}(e,r):function(e,t,r){if(ze(0,t,r),"none"===r.readerType)return Me(e,r),void Ne(e);if(r.bytesFilled<r.minimumFill)return;$e(e);const n=r.bytesFilled%r.elementSize;if(n>0){const t=r.byteOffset+r.bytesFilled;Be(e,r.buffer,t-n,n)}r.bytesFilled-=n,Ie(e._controlledReadableByteStream,r),Ne(e)}(e,t,r),xe(e)}function $e(e){return e._pendingPullIntos.shift()}function He(e){e._pullAlgorithm=void 0,e._cancelAlgorithm=void 0}function Ye(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 Qe(e,t),t}}He(e),zr(t)}}function Je(e,t){const r=e._controlledReadableByteStream;if(e._closeRequested||"readable"!==r._state)return;const{buffer:n,byteOffset:o,byteLength:i}=t;if(de(n))throw new TypeError("chunk's buffer is detached and so cannot be enqueued");const a=fe(n);if(e._pendingPullIntos.length>0){const t=e._pendingPullIntos.peek();if(de(t.buffer))throw new TypeError("The BYOB request's buffer has been detached and so cannot be filled with an enqueued chunk");De(e),t.buffer=fe(t.buffer),"none"===t.readerType&&Me(e,t)}ee(r)?(function(e){const t=e._controlledReadableByteStream._reader;for(;t._readRequests.length>0;){if(0===e._queueTotalSize)return;Ve(e,t._readRequests.shift())}}(e),0===Z(r)?Ue(e,a,o,i):(e._pendingPullIntos.length>0&&$e(e),K(r,new Uint8Array(a,o,i),!1))):ut(r)?(Ue(e,a,o,i),Ne(e)):Ue(e,a,o,i),xe(e)}function Qe(e,t){const r=e._controlledReadableByteStream;"readable"===r._state&&(Ae(e),Oe(e),He(e),Fr(r,t))}function Ve(e,t){const r=e._queue.shift();e._queueTotalSize-=r.byteLength,Fe(e);const n=new Uint8Array(r.buffer,r.byteOffset,r.byteLength);t._chunkSteps(n)}function Xe(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(qe.prototype);!function(e,t,r){e._associatedReadableByteStreamController=t,e._view=r}(n,e,r),e._byobRequest=n}return e._byobRequest}function Ke(e){const t=e._controlledReadableByteStream._state;return"errored"===t?null:"closed"===t?0:e._strategyHWM-e._queueTotalSize}function Ze(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=fe(r.buffer),Ge(e,t)}function et(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=fe(t.buffer),Ge(e,n)}function tt(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,Oe(t),t._closeRequested=!1,t._started=!1,t._strategyHWM=i,t._pullAlgorithm=n,t._cancelAlgorithm=o,t._autoAllocateChunkSize=a,t._pendingPullIntos=new P,e._readableStreamController=t,m(p(r()),()=>(t._started=!0,xe(t),null),e=>(Qe(t,e),null))}function rt(e){return new TypeError(`ReadableStreamBYOBRequest.prototype.${e} can only be used on a ReadableStreamBYOBRequest`)}function nt(e){return new TypeError(`ReadableByteStreamController.prototype.${e} can only be used on a ReadableByteStreamController`)}function ot(e,t){if("byob"!=(e=""+e))throw new TypeError(`${t} '${e}' is not a valid enumeration value for ReadableStreamReaderMode`);return e}function it(e){return new lt(e)}function at(e,t){e._reader._readIntoRequests.push(t)}function st(e){return e._reader._readIntoRequests.length}function ut(e){const t=e._reader;return void 0!==t&&!!ct(t)}Object.defineProperties(ke.prototype,{close:{enumerable:!0},enqueue:{enumerable:!0},error:{enumerable:!0},byobRequest:{enumerable:!0},desiredSize:{enumerable:!0}}),s(ke.prototype.close,"close"),s(ke.prototype.enqueue,"enqueue"),s(ke.prototype.error,"error"),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(ke.prototype,Symbol.toStringTag,{value:"ReadableByteStreamController",configurable:!0});class lt{constructor(e){if(G(e,1,"ReadableStreamBYOBReader"),Q(e,"First parameter"),Mr(e))throw new TypeError("This stream has already been locked for exclusive reading by another reader");if(!Ee(e._readableStreamController))throw new TypeError("Cannot construct a ReadableStreamBYOBReader for a stream not constructed with a byte source");C(this,e),this._readIntoRequests=new P}get closed(){return ct(this)?this._closedPromise:b(ht("closed"))}cancel(e){return ct(this)?void 0===this._ownerReadableStream?b(I("cancel")):x(this,e):b(ht("cancel"))}read(e,t={}){if(!ct(this))return b(ht("read"));if(!ArrayBuffer.isView(e))return b(new TypeError("view must be an array buffer view"));if(0===e.byteLength)return b(new TypeError("view must have non-zero byteLength"));if(0===e.buffer.byteLength)return b(new TypeError("view's buffer must have non-zero byteLength"));if(de(e.buffer))return b(new TypeError("view's buffer has been detached"));let r;try{r=function(e,t){var r;return F(e,t),{min:J(null!==(r=null==e?void 0:e.min)&&void 0!==r?r:1,t+" has member 'min' that")}}(t,"options")}catch(e){return b(e)}const n=r.min;if(0===n)return b(new TypeError("options.min must be greater than 0"));if(function(e){return je(e.constructor)}(e)){if(n>e.byteLength)return b(new RangeError("options.min must be less than or equal to view's byteLength"))}else if(n>e.length)return b(new RangeError("options.min must be less than or equal to view's length"));if(void 0===this._ownerReadableStream)return b(I("read from"));let o,i;const a=h((e,t)=>{o=e,i=t});return ft(this,e,n,{_chunkSteps:e=>o({value:e,done:!1}),_closeSteps:e=>o({value:e,done:!0}),_errorSteps:e=>i(e)}),a}releaseLock(){if(!ct(this))throw ht("releaseLock");void 0!==this._ownerReadableStream&&function(e){A(e);dt(e,new TypeError("Reader was released"))}(this)}}function ct(e){return!!i(e)&&!!Object.prototype.hasOwnProperty.call(e,"_readIntoRequests")&&e instanceof lt}function ft(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 je(e)?1:e.BYTES_PER_ELEMENT}(i),{byteOffset:s,byteLength:u}=t,l=r*a;let c;try{c=fe(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 at(o,n);if("closed"!==o._state){if(e._queueTotalSize>0){if(Le(e,f)){const t=We(f);return Fe(e),void n._chunkSteps(t)}if(e._closeRequested){const t=new TypeError("Insufficient bytes to fill elements in the given buffer");return Qe(e,t),void n._errorSteps(t)}}e._pendingPullIntos.push(f),at(o,n),xe(e)}else{const e=new i(f.buffer,f.byteOffset,0);n._closeSteps(e)}}(o._readableStreamController,t,r,n)}function dt(e,t){const r=e._readIntoRequests;e._readIntoRequests=new P,r.forEach(e=>{e._errorSteps(t)})}function ht(e){return new TypeError(`ReadableStreamBYOBReader.prototype.${e} can only be used on a ReadableStreamBYOBReader`)}function pt(e,t){const{highWaterMark:r}=e;if(void 0===r)return t;if(Se(r)||r<0)throw new RangeError("Invalid highWaterMark");return r}function bt(e){const{size:t}=e;return t||(()=>1)}function yt(e,t){F(e,t);const r=null==e?void 0:e.highWaterMark,n=null==e?void 0:e.size;return{highWaterMark:void 0===r?void 0:H(r),size:void 0===n?void 0:mt(n,t+" has member 'size' that")}}function mt(e,t){return D(e,t),t=>H(e(t))}function vt(e,t,r){return D(e,r),r=>T(e,t,[r])}function _t(e,t,r){return D(e,r),()=>T(e,t,[])}function gt(e,t,r){return D(e,r),r=>R(e,t,[r])}function wt(e,t,r){return D(e,r),(r,n)=>T(e,t,[r,n])}function St(e,t){if(!jt(e))throw new TypeError(t+" is not a WritableStream.")}Object.defineProperties(lt.prototype,{cancel:{enumerable:!0},read:{enumerable:!0},releaseLock:{enumerable:!0},closed:{enumerable:!0}}),s(lt.prototype.cancel,"cancel"),s(lt.prototype.read,"read"),s(lt.prototype.releaseLock,"releaseLock"),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(lt.prototype,Symbol.toStringTag,{value:"ReadableStreamBYOBReader",configurable:!0});const Rt="function"==typeof AbortController;class Tt{constructor(e={},t={}){void 0===e?e=null:N(e,"First parameter");const r=yt(t,"Second parameter"),n=function(e,t){F(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:vt(r,e,t+" has member 'abort' that"),close:void 0===n?void 0:_t(n,e,t+" has member 'close' that"),start:void 0===o?void 0:gt(o,e,t+" has member 'start' that"),write:void 0===a?void 0:wt(a,e,t+" has member 'write' that"),type:i}}(e,"First parameter");if(Ot(this),void 0!==n.type)throw new RangeError("Invalid type is specified");const o=bt(r);!function(e,t,r,n){const o=Object.create(Gt.prototype);let i,a,s,u;i=void 0!==t.start?()=>t.start(o):()=>{},a=void 0!==t.write?e=>t.write(e,o):()=>p(void 0),s=void 0!==t.close?()=>t.close():()=>p(void 0),u=void 0!==t.abort?e=>t.abort(e):()=>p(void 0),Ht(e,o,i,a,s,u,r,n)}(this,n,pt(r,1),o)}get locked(){if(!jt(this))throw Zt("locked");return qt(this)}abort(e){return jt(this)?qt(this)?b(new TypeError("Cannot abort a stream that already has a writer")):kt(this,e):b(Zt("abort"))}close(){return jt(this)?qt(this)?b(new TypeError("Cannot close a stream that already has a writer")):It(this)?b(new TypeError("Cannot close an already-closing stream")):Et(this):b(Zt("close"))}getWriter(){if(!jt(this))throw Zt("getWriter");return Pt(this)}}function Pt(e){return new Bt(e)}function Ot(e){e._state="writable",e._storedError=void 0,e._writer=void 0,e._writableStreamController=void 0,e._writeRequests=new P,e._inFlightWriteRequest=void 0,e._closeRequest=void 0,e._inFlightCloseRequest=void 0,e._pendingAbortRequest=void 0,e._backpressure=!1}function jt(e){return!!i(e)&&!!Object.prototype.hasOwnProperty.call(e,"_writableStreamController")&&e instanceof Tt}function qt(e){return void 0!==e._writer}function kt(e,t){var r;if("closed"===e._state||"errored"===e._state)return p(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 p(void 0);if(void 0!==e._pendingAbortRequest)return e._pendingAbortRequest._promise;let o=!1;"erroring"===n&&(o=!0,t=void 0);const i=h((r,n)=>{e._pendingAbortRequest={_promise:void 0,_resolve:r,_reject:n,_reason:t,_wasAlreadyErroring:o}});return e._pendingAbortRequest._promise=i,o||xt(e,t),i}function Et(e){const t=e._state;if("closed"===t||"errored"===t)return b(new TypeError(`The stream (in ${t} state) is not in the writable state and cannot be closed`));const r=h((t,r)=>{const n={_resolve:t,_reject:r};e._closeRequest=n}),n=e._writer;var o;return void 0!==n&&e._backpressure&&"writable"===t&&fr(n),Pe(o=e._writableStreamController,Nt,0),Qt(o),r}function Ct(e,t){"writable"!==e._state?At(e):xt(e,t)}function xt(e,t){const r=e._writableStreamController;e._state="erroring",e._storedError=t;const n=e._writer;void 0!==n&&zt(n,t),!function(e){return void 0!==e._inFlightWriteRequest||void 0!==e._inFlightCloseRequest}(e)&&r._started&&At(e)}function At(e){e._state="errored",e._writableStreamController[j]();const t=e._storedError;if(e._writeRequests.forEach(e=>{e._reject(t)}),e._writeRequests=new P,void 0===e._pendingAbortRequest)return void Wt(e);const r=e._pendingAbortRequest;if(e._pendingAbortRequest=void 0,r._wasAlreadyErroring)return r._reject(t),void Wt(e);m(e._writableStreamController[O](r._reason),()=>(r._resolve(),Wt(e),null),t=>(r._reject(t),Wt(e),null))}function It(e){return void 0!==e._closeRequest||void 0!==e._inFlightCloseRequest}function Wt(e){void 0!==e._closeRequest&&(e._closeRequest._reject(e._storedError),e._closeRequest=void 0);const t=e._writer;void 0!==t&&ir(t,e._storedError)}function Ut(e,t){const r=e._writer;void 0!==r&&t!==e._backpressure&&(t?function(e){sr(e)}(r):fr(r)),e._backpressure=t}Object.defineProperties(Tt.prototype,{abort:{enumerable:!0},close:{enumerable:!0},getWriter:{enumerable:!0},locked:{enumerable:!0}}),s(Tt.prototype.abort,"abort"),s(Tt.prototype.close,"close"),s(Tt.prototype.getWriter,"getWriter"),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(Tt.prototype,Symbol.toStringTag,{value:"WritableStream",configurable:!0});class Bt{constructor(e){if(G(e,1,"WritableStreamDefaultWriter"),St(e,"First parameter"),qt(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)!It(e)&&e._backpressure?sr(this):lr(this),nr(this);else if("erroring"===t)ur(this,e._storedError),nr(this);else if("closed"===t)lr(this),nr(this),ar(this);else{const t=e._storedError;ur(this,t),or(this,t)}}get closed(){return Mt(this)?this._closedPromise:b(tr("closed"))}get desiredSize(){if(!Mt(this))throw tr("desiredSize");if(void 0===this._ownerWritableStream)throw rr("desiredSize");return function(e){const t=e._ownerWritableStream,r=t._state;return"errored"===r||"erroring"===r?null:"closed"===r?0:Jt(t._writableStreamController)}(this)}get ready(){return Mt(this)?this._readyPromise:b(tr("ready"))}abort(e){return Mt(this)?void 0===this._ownerWritableStream?b(rr("abort")):function(e,t){return kt(e._ownerWritableStream,t)}(this,e):b(tr("abort"))}close(){if(!Mt(this))return b(tr("close"));const e=this._ownerWritableStream;return void 0===e?b(rr("close")):It(e)?b(new TypeError("Cannot close an already-closing stream")):Lt(this)}releaseLock(){if(!Mt(this))throw tr("releaseLock");void 0!==this._ownerWritableStream&&Ft(this)}write(e){return Mt(this)?void 0===this._ownerWritableStream?b(rr("write to")):Dt(this,e):b(tr("write"))}}function Mt(e){return!!i(e)&&!!Object.prototype.hasOwnProperty.call(e,"_ownerWritableStream")&&e instanceof Bt}function Lt(e){return Et(e._ownerWritableStream)}function zt(e,t){"pending"===e._readyPromiseState?cr(e,t):function(e,t){ur(e,t)}(e,t)}function Ft(e){const t=e._ownerWritableStream,r=new TypeError("Writer was released and can no longer be used to monitor the stream's closedness");zt(e,r),function(e,t){"pending"===e._closedPromiseState?ir(e,t):function(e,t){or(e,t)}(e,t)}(e,r),t._writer=void 0,e._ownerWritableStream=void 0}function Dt(e,t){const r=e._ownerWritableStream,n=r._writableStreamController,o=function(e,t){try{return e._strategySizeAlgorithm(t)}catch(t){return Vt(e,t),1}}(n,t);if(r!==e._ownerWritableStream)return b(rr("write to"));const i=r._state;if("errored"===i)return b(r._storedError);if(It(r)||"closed"===i)return b(new TypeError("The stream is closing or closed and cannot be written to"));if("erroring"===i)return b(r._storedError);const a=function(e){return h((t,r)=>{const n={_resolve:t,_reject:r};e._writeRequests.push(n)})}(r);return function(e,t,r){try{Pe(e,t,r)}catch(t){return void Vt(e,t)}const n=e._controlledWritableStream;It(n)||"writable"!==n._state||Ut(n,Xt(e)),Qt(e)}(n,t,o),a}Object.defineProperties(Bt.prototype,{abort:{enumerable:!0},close:{enumerable:!0},releaseLock:{enumerable:!0},write:{enumerable:!0},closed:{enumerable:!0},desiredSize:{enumerable:!0},ready:{enumerable:!0}}),s(Bt.prototype.abort,"abort"),s(Bt.prototype.close,"close"),s(Bt.prototype.releaseLock,"releaseLock"),s(Bt.prototype.write,"write"),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(Bt.prototype,Symbol.toStringTag,{value:"WritableStreamDefaultWriter",configurable:!0});const Nt={};class Gt{constructor(){throw new TypeError("Illegal constructor")}get abortReason(){if(!$t(this))throw er("abortReason");return this._abortReason}get signal(){if(!$t(this))throw er("signal");if(void 0===this._abortController)throw new TypeError("WritableStreamDefaultController.prototype.signal is not supported");return this._abortController.signal}error(e){if(!$t(this))throw er("error");"writable"===this._controlledWritableStream._state&&Kt(this,e)}[O](e){const t=this._abortAlgorithm(e);return Yt(this),t}[j](){Oe(this)}}function $t(e){return!!i(e)&&!!Object.prototype.hasOwnProperty.call(e,"_controlledWritableStream")&&e instanceof Gt}function Ht(e,t,r,n,o,i,a,s){t._controlledWritableStream=e,e._writableStreamController=t,t._queue=void 0,t._queueTotalSize=void 0,Oe(t),t._abortReason=void 0,t._abortController=function(){if(Rt)return new AbortController}(),t._started=!1,t._strategySizeAlgorithm=s,t._strategyHWM=a,t._writeAlgorithm=n,t._closeAlgorithm=o,t._abortAlgorithm=i;const u=Xt(t);Ut(e,u),m(p(r()),()=>(t._started=!0,Qt(t),null),r=>(t._started=!0,Ct(e,r),null))}function Yt(e){e._writeAlgorithm=void 0,e._closeAlgorithm=void 0,e._abortAlgorithm=void 0,e._strategySizeAlgorithm=void 0}function Jt(e){return e._strategyHWM-e._queueTotalSize}function Qt(e){const t=e._controlledWritableStream;if(!e._started)return;if(void 0!==t._inFlightWriteRequest)return;if("erroring"===t._state)return void At(t);if(0===e._queue.length)return;const r=e._queue.peek().value;r===Nt?function(e){const t=e._controlledWritableStream;(function(e){e._inFlightCloseRequest=e._closeRequest,e._closeRequest=void 0})(t),Te(e);const r=e._closeAlgorithm();Yt(e),m(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&&ar(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),Ct(e,t)}(t,e),null))}(e):function(e,t){const r=e._controlledWritableStream;!function(e){e._inFlightWriteRequest=e._writeRequests.shift()}(r);m(e._writeAlgorithm(t),()=>{!function(e){e._inFlightWriteRequest._resolve(void 0),e._inFlightWriteRequest=void 0}(r);const t=r._state;if(Te(e),!It(r)&&"writable"===t){const t=Xt(e);Ut(r,t)}return Qt(e),null},t=>("writable"===r._state&&Yt(e),function(e,t){e._inFlightWriteRequest._reject(t),e._inFlightWriteRequest=void 0,Ct(e,t)}(r,t),null))}(e,r)}function Vt(e,t){"writable"===e._controlledWritableStream._state&&Kt(e,t)}function Xt(e){return Jt(e)<=0}function Kt(e,t){const r=e._controlledWritableStream;Yt(e),xt(r,t)}function Zt(e){return new TypeError(`WritableStream.prototype.${e} can only be used on a WritableStream`)}function er(e){return new TypeError(`WritableStreamDefaultController.prototype.${e} can only be used on a WritableStreamDefaultController`)}function tr(e){return new TypeError(`WritableStreamDefaultWriter.prototype.${e} can only be used on a WritableStreamDefaultWriter`)}function rr(e){return new TypeError("Cannot "+e+" a stream using a released writer")}function nr(e){e._closedPromise=h((t,r)=>{e._closedPromise_resolve=t,e._closedPromise_reject=r,e._closedPromiseState="pending"})}function or(e,t){nr(e),ir(e,t)}function ir(e,t){void 0!==e._closedPromise_reject&&(w(e._closedPromise),e._closedPromise_reject(t),e._closedPromise_resolve=void 0,e._closedPromise_reject=void 0,e._closedPromiseState="rejected")}function ar(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 sr(e){e._readyPromise=h((t,r)=>{e._readyPromise_resolve=t,e._readyPromise_reject=r}),e._readyPromiseState="pending"}function ur(e,t){sr(e),cr(e,t)}function lr(e){sr(e),fr(e)}function cr(e,t){void 0!==e._readyPromise_reject&&(w(e._readyPromise),e._readyPromise_reject(t),e._readyPromise_resolve=void 0,e._readyPromise_reject=void 0,e._readyPromiseState="rejected")}function fr(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(Gt.prototype,{abortReason:{enumerable:!0},signal:{enumerable:!0},error:{enumerable:!0}}),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(Gt.prototype,Symbol.toStringTag,{value:"WritableStreamDefaultController",configurable:!0});const dr="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof global?global:void 0,hr=function(){const e=null==dr?void 0:dr.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 s(e,"DOMException"),e.prototype=Object.create(Error.prototype),Object.defineProperty(e.prototype,"constructor",{value:e,writable:!0,configurable:!0}),e}();function pr(e,t,r,n,i,a){const s=V(e),u=Pt(t);e._disturbed=!0;let l=!1,c=p(void 0);return h((f,d)=>{let g;if(void 0!==a){if(g=()=>{const r=void 0!==a.reason?a.reason:new hr("Aborted","AbortError"),o=[];n||o.push(()=>"writable"===t._state?kt(t,r):p(void 0)),i||o.push(()=>"readable"===e._state?Lr(e,r):p(void 0)),j(()=>Promise.all(o.map(e=>e())),!0,r)},a.aborted)return void g();a.addEventListener("abort",g)}var S,R,T;if(O(e,s._closedPromise,e=>(n?q(!0,e):j(()=>kt(t,e),!0,e),null)),O(t,u._closedPromise,t=>(i?q(!0,t):j(()=>Lr(e,t),!0,t),null)),S=e,R=s._closedPromise,T=()=>(r?q():j(()=>function(e){const t=e._ownerWritableStream,r=t._state;return It(t)||"closed"===r?p(void 0):"errored"===r?b(t._storedError):Lt(e)}(u)),null),"closed"===S._state?T():v(R,T),It(t)||"closed"===t._state){const t=new TypeError("the destination writable stream closed before all data could be piped to it");i?q(!0,t):j(()=>Lr(e,t),!0,t)}function P(){const e=c;return y(c,()=>e!==c?P():void 0)}function O(e,t,r){"errored"===e._state?r(e._storedError):_(t,r)}function j(e,r,n){function o(){return m(e(),()=>k(r,n),e=>k(!0,e)),null}l||(l=!0,"writable"!==t._state||It(t)?o():v(P(),o))}function q(e,r){l||(l=!0,"writable"!==t._state||It(t)?k(e,r):v(P(),()=>k(e,r)))}function k(e,t){return Ft(u),A(s),void 0!==a&&a.removeEventListener("abort",g),e?d(t):f(void 0),null}w(h((e,t)=>{!function r(n){n?e():y(l?p(!0):y(u._readyPromise,()=>h((e,t)=>{ne(s,{_chunkSteps:t=>{c=y(Dt(u,t),void 0,o),e(!1)},_closeSteps:()=>e(!0),_errorSteps:t})})),r,t)}(!1)}))})}class br{constructor(){throw new TypeError("Illegal constructor")}get desiredSize(){if(!yr(this))throw Or("desiredSize");return Rr(this)}close(){if(!yr(this))throw Or("close");if(!Tr(this))throw new TypeError("The stream is not in a state that permits close");gr(this)}enqueue(e){if(!yr(this))throw Or("enqueue");if(!Tr(this))throw new TypeError("The stream is not in a state that permits enqueue");return wr(this,e)}error(e){if(!yr(this))throw Or("error");Sr(this,e)}[q](e){Oe(this);const t=this._cancelAlgorithm(e);return _r(this),t}[k](e){const t=this._controlledReadableStream;if(this._queue.length>0){const r=Te(this);this._closeRequested&&0===this._queue.length?(_r(this),zr(t)):mr(this),e._chunkSteps(r)}else X(t,e),mr(this)}[E](){}}function yr(e){return!!i(e)&&!!Object.prototype.hasOwnProperty.call(e,"_controlledReadableStream")&&e instanceof br}function mr(e){vr(e)&&(e._pulling?e._pullAgain=!0:(e._pulling=!0,m(e._pullAlgorithm(),()=>(e._pulling=!1,e._pullAgain&&(e._pullAgain=!1,mr(e)),null),t=>(Sr(e,t),null))))}function vr(e){const t=e._controlledReadableStream;return!!Tr(e)&&(!!e._started&&(!!(Mr(t)&&Z(t)>0)||Rr(e)>0))}function _r(e){e._pullAlgorithm=void 0,e._cancelAlgorithm=void 0,e._strategySizeAlgorithm=void 0}function gr(e){if(!Tr(e))return;const t=e._controlledReadableStream;e._closeRequested=!0,0===e._queue.length&&(_r(e),zr(t))}function wr(e,t){if(!Tr(e))return;const r=e._controlledReadableStream;if(Mr(r)&&Z(r)>0)K(r,t,!1);else{let r;try{r=e._strategySizeAlgorithm(t)}catch(t){throw Sr(e,t),t}try{Pe(e,t,r)}catch(t){throw Sr(e,t),t}}mr(e)}function Sr(e,t){const r=e._controlledReadableStream;"readable"===r._state&&(Oe(e),_r(e),Fr(r,t))}function Rr(e){const t=e._controlledReadableStream._state;return"errored"===t?null:"closed"===t?0:e._strategyHWM-e._queueTotalSize}function Tr(e){const t=e._controlledReadableStream._state;return!e._closeRequested&&"readable"===t}function Pr(e,t,r,n,o,i,a){t._controlledReadableStream=e,t._queue=void 0,t._queueTotalSize=void 0,Oe(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,m(p(r()),()=>(t._started=!0,mr(t),null),e=>(Sr(t,e),null))}function Or(e){return new TypeError(`ReadableStreamDefaultController.prototype.${e} can only be used on a ReadableStreamDefaultController`)}function jr(e){return i(t=e)&&void 0!==t.getReader?function(e){let t;return t=Ir(o,(function(){let r;try{r=e.read()}catch(r){return b(r)}return g(r,e=>{if(!i(e))throw new TypeError("The promise returned by the reader.read() method must fulfill with an object");if(e.done)gr(t._readableStreamController);else{const r=e.value;wr(t._readableStreamController,r)}})}),(function(t){try{return p(e.cancel(t))}catch(t){return b(t)}}),0),t}(e.getReader()):function(e){let t;const r=function e(t,r="sync",n){if(void 0===n)if("async"===r){if(void 0===(n=pe(t,ye)))return function(e){const t={next(){let t;try{t=me(e)}catch(e){return b(e)}return be(t)},return(t){let r;try{const n=pe(e.iterator,"return");if(void 0===n)return p({done:!0,value:t});r=R(n,e.iterator,[t])}catch(e){return b(e)}return i(r)?be(r):b(new TypeError("The iterator.return() method must return an object"))}};return{iterator:t,nextMethod:t.next,done:!1}}(e(t,"sync",pe(t,Symbol.iterator)))}else n=pe(t,Symbol.iterator);if(void 0===n)throw new TypeError("The object is not iterable");const o=R(n,t,[]);if(!i(o))throw new TypeError("The iterator method must return an object");return{iterator:o,nextMethod:o.next,done:!1}}(e,"async");return t=Ir(o,(function(){let e;try{e=me(r)}catch(e){return b(e)}return g(p(e),e=>{if(!i(e))throw new TypeError("The promise returned by the iterator.next() method must fulfill with an object");if(e.done)gr(t._readableStreamController);else{const r=e.value;wr(t._readableStreamController,r)}})}),(function(e){const t=r.iterator;let n;try{n=pe(t,"return")}catch(e){return b(e)}return void 0===n?p(void 0):g(T(n,t,[e]),e=>{if(!i(e))throw new TypeError("The promise returned by the iterator.return() method must fulfill with an object")})}),0),t}(e);var t}function qr(e,t,r){return D(e,r),r=>T(e,t,[r])}function kr(e,t,r){return D(e,r),r=>T(e,t,[r])}function Er(e,t,r){return D(e,r),r=>R(e,t,[r])}function Cr(e,t){if("bytes"!=(e=""+e))throw new TypeError(`${t} '${e}' is not a valid enumeration value for ReadableStreamType`);return e}function xr(e,t){F(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(br.prototype,{close:{enumerable:!0},enqueue:{enumerable:!0},error:{enumerable:!0},desiredSize:{enumerable:!0}}),s(br.prototype.close,"close"),s(br.prototype.enqueue,"enqueue"),s(br.prototype.error,"error"),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(br.prototype,Symbol.toStringTag,{value:"ReadableStreamDefaultController",configurable:!0});class Ar{constructor(e={},t={}){void 0===e?e=null:N(e,"First parameter");const r=yt(t,"Second parameter"),n=function(e,t){F(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:J(n,t+" has member 'autoAllocateChunkSize' that"),cancel:void 0===o?void 0:qr(o,r,t+" has member 'cancel' that"),pull:void 0===i?void 0:kr(i,r,t+" has member 'pull' that"),start:void 0===a?void 0:Er(a,r,t+" has member 'start' that"),type:void 0===s?void 0:Cr(s,t+" has member 'type' that")}}(e,"First parameter");if(Ur(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(ke.prototype);let o,i,a;o=void 0!==t.start?()=>t.start(n):()=>{},i=void 0!==t.pull?()=>t.pull(n):()=>p(void 0),a=void 0!==t.cancel?e=>t.cancel(e):()=>p(void 0);const s=t.autoAllocateChunkSize;if(0===s)throw new TypeError("autoAllocateChunkSize must be greater than 0");tt(e,n,o,i,a,r,s)}(this,n,pt(r,0))}else{const e=bt(r);!function(e,t,r,n){const o=Object.create(br.prototype);let i,a,s;i=void 0!==t.start?()=>t.start(o):()=>{},a=void 0!==t.pull?()=>t.pull(o):()=>p(void 0),s=void 0!==t.cancel?e=>t.cancel(e):()=>p(void 0),Pr(e,o,i,a,s,r,n)}(this,n,pt(r,1),e)}}get locked(){if(!Br(this))throw Dr("locked");return Mr(this)}cancel(e){return Br(this)?Mr(this)?b(new TypeError("Cannot cancel a stream that already has a reader")):Lr(this,e):b(Dr("cancel"))}getReader(e){if(!Br(this))throw Dr("getReader");return void 0===function(e,t){F(e,t);const r=null==e?void 0:e.mode;return{mode:void 0===r?void 0:ot(r,t+" has member 'mode' that")}}(e,"First parameter").mode?V(this):it(this)}pipeThrough(e,t={}){if(!Br(this))throw Dr("pipeThrough");G(e,1,"pipeThrough");const r=function(e,t){F(e,t);const r=null==e?void 0:e.readable;$(r,"readable","ReadableWritablePair"),Q(r,t+" has member 'readable' that");const n=null==e?void 0:e.writable;return $(n,"writable","ReadableWritablePair"),St(n,t+" has member 'writable' that"),{readable:r,writable:n}}(e,"First parameter"),n=xr(t,"Second parameter");if(Mr(this))throw new TypeError("ReadableStream.prototype.pipeThrough cannot be used on a locked ReadableStream");if(qt(r.writable))throw new TypeError("ReadableStream.prototype.pipeThrough cannot be used on a locked WritableStream");return w(pr(this,r.writable,n.preventClose,n.preventAbort,n.preventCancel,n.signal)),r.readable}pipeTo(e,t={}){if(!Br(this))return b(Dr("pipeTo"));if(void 0===e)return b("Parameter 1 is required in 'pipeTo'.");if(!jt(e))return b(new TypeError("ReadableStream.prototype.pipeTo's first argument must be a WritableStream"));let r;try{r=xr(t,"Second parameter")}catch(e){return b(e)}return Mr(this)?b(new TypeError("ReadableStream.prototype.pipeTo cannot be used on a locked ReadableStream")):qt(e)?b(new TypeError("ReadableStream.prototype.pipeTo cannot be used on a locked WritableStream")):pr(this,e,r.preventClose,r.preventAbort,r.preventCancel,r.signal)}tee(){if(!Br(this))throw Dr("tee");return le(function(e,t){return Ee(e._readableStreamController)?function(e){let t,r,n,o,i,a=V(e),s=!1,u=!1,l=!1,c=!1,f=!1;const d=h(e=>{i=e});function b(e){_(e._closedPromise,t=>(e!==a||(Qe(n._readableStreamController,t),Qe(o._readableStreamController,t),c&&f||i(void 0)),null))}function y(){ct(a)&&(A(a),a=V(e),b(a)),ne(a,{_chunkSteps:t=>{S(()=>{u=!1,l=!1;const r=t;let a=t;if(!c&&!f)try{a=Re(t)}catch(t){return Qe(n._readableStreamController,t),Qe(o._readableStreamController,t),void i(Lr(e,t))}c||Je(n._readableStreamController,r),f||Je(o._readableStreamController,a),s=!1,u?v():l&&g()})},_closeSteps:()=>{s=!1,c||Ye(n._readableStreamController),f||Ye(o._readableStreamController),n._readableStreamController._pendingPullIntos.length>0&&Ze(n._readableStreamController,0),o._readableStreamController._pendingPullIntos.length>0&&Ze(o._readableStreamController,0),c&&f||i(void 0)},_errorSteps:()=>{s=!1}})}function m(t,r){re(a)&&(A(a),a=it(e),b(a));const d=r?o:n,h=r?n:o;ft(a,t,1,{_chunkSteps:t=>{S(()=>{u=!1,l=!1;const n=r?f:c;if(r?c:f)n||et(d._readableStreamController,t);else{let r;try{r=Re(t)}catch(t){return Qe(d._readableStreamController,t),Qe(h._readableStreamController,t),void i(Lr(e,t))}n||et(d._readableStreamController,t),Je(h._readableStreamController,r)}s=!1,u?v():l&&g()})},_closeSteps:e=>{s=!1;const t=r?f:c,n=r?c:f;t||Ye(d._readableStreamController),n||Ye(h._readableStreamController),void 0!==e&&(t||et(d._readableStreamController,e),!n&&h._readableStreamController._pendingPullIntos.length>0&&Ze(h._readableStreamController,0)),t&&n||i(void 0)},_errorSteps:()=>{s=!1}})}function v(){if(s)return u=!0,p(void 0);s=!0;const e=Xe(n._readableStreamController);return null===e?y():m(e._view,!1),p(void 0)}function g(){if(s)return l=!0,p(void 0);s=!0;const e=Xe(o._readableStreamController);return null===e?y():m(e._view,!0),p(void 0)}function w(){}return n=Wr(w,v,(function(n){if(c=!0,t=n,f){const n=le([t,r]),o=Lr(e,n);i(o)}return d})),o=Wr(w,g,(function(n){if(f=!0,r=n,c){const n=le([t,r]),o=Lr(e,n);i(o)}return d})),b(a),[n,o]}(e):function(e,t){const r=V(e);let n,o,i,a,s,u=!1,l=!1,c=!1,f=!1;const d=h(e=>{s=e});function b(){return u?(l=!0,p(void 0)):(u=!0,ne(r,{_chunkSteps:e=>{S(()=>{l=!1;const t=e,r=e;c||wr(i._readableStreamController,t),f||wr(a._readableStreamController,r),u=!1,l&&b()})},_closeSteps:()=>{u=!1,c||gr(i._readableStreamController),f||gr(a._readableStreamController),c&&f||s(void 0)},_errorSteps:()=>{u=!1}}),p(void 0))}function y(){}return i=Ir(y,b,(function(t){if(c=!0,n=t,f){const t=le([n,o]),r=Lr(e,t);s(r)}return d})),a=Ir(y,b,(function(t){if(f=!0,o=t,c){const t=le([n,o]),r=Lr(e,t);s(r)}return d})),_(r._closedPromise,e=>(Sr(i._readableStreamController,e),Sr(a._readableStreamController,e),c&&f||s(void 0),null)),[i,a]}(e)}(this))}values(e){if(!Br(this))throw Dr("values");return function(e,t){const r=V(e),n=new ve(r,t),o=Object.create(_e);return o._asyncIteratorImpl=n,o}(this,function(e,t){F(e,"First parameter");const r=null==e?void 0:e.preventCancel;return{preventCancel:Boolean(r)}}(e).preventCancel)}[ye](e){return this.values(e)}static from(e){return jr(e)}}function Ir(e,t,r,n=1,o=(()=>1)){const i=Object.create(Ar.prototype);return Ur(i),Pr(i,Object.create(br.prototype),e,t,r,n,o),i}function Wr(e,t,r){const n=Object.create(Ar.prototype);return Ur(n),tt(n,Object.create(ke.prototype),e,t,r,0,void 0),n}function Ur(e){e._state="readable",e._reader=void 0,e._storedError=void 0,e._disturbed=!1}function Br(e){return!!i(e)&&!!Object.prototype.hasOwnProperty.call(e,"_readableStreamController")&&e instanceof Ar}function Mr(e){return void 0!==e._reader}function Lr(e,t){if(e._disturbed=!0,"closed"===e._state)return p(void 0);if("errored"===e._state)return b(e._storedError);zr(e);const r=e._reader;if(void 0!==r&&ct(r)){const e=r._readIntoRequests;r._readIntoRequests=new P,e.forEach(e=>{e._closeSteps(void 0)})}return g(e._readableStreamController[q](t),o)}function zr(e){e._state="closed";const t=e._reader;if(void 0!==t&&(M(t),re(t))){const e=t._readRequests;t._readRequests=new P,e.forEach(e=>{e._closeSteps()})}}function Fr(e,t){e._state="errored",e._storedError=t;const r=e._reader;void 0!==r&&(B(r,t),re(r)?oe(r,t):dt(r,t))}function Dr(e){return new TypeError(`ReadableStream.prototype.${e} can only be used on a ReadableStream`)}function Nr(e,t){F(e,t);const r=null==e?void 0:e.highWaterMark;return $(r,"highWaterMark","QueuingStrategyInit"),{highWaterMark:H(r)}}Object.defineProperties(Ar,{from:{enumerable:!0}}),Object.defineProperties(Ar.prototype,{cancel:{enumerable:!0},getReader:{enumerable:!0},pipeThrough:{enumerable:!0},pipeTo:{enumerable:!0},tee:{enumerable:!0},values:{enumerable:!0},locked:{enumerable:!0}}),s(Ar.from,"from"),s(Ar.prototype.cancel,"cancel"),s(Ar.prototype.getReader,"getReader"),s(Ar.prototype.pipeThrough,"pipeThrough"),s(Ar.prototype.pipeTo,"pipeTo"),s(Ar.prototype.tee,"tee"),s(Ar.prototype.values,"values"),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(Ar.prototype,Symbol.toStringTag,{value:"ReadableStream",configurable:!0}),Object.defineProperty(Ar.prototype,ye,{value:Ar.prototype.values,writable:!0,configurable:!0});const Gr=e=>e.byteLength;s(Gr,"size");class $r{constructor(e){G(e,1,"ByteLengthQueuingStrategy"),e=Nr(e,"First parameter"),this._byteLengthQueuingStrategyHighWaterMark=e.highWaterMark}get highWaterMark(){if(!Yr(this))throw Hr("highWaterMark");return this._byteLengthQueuingStrategyHighWaterMark}get size(){if(!Yr(this))throw Hr("size");return Gr}}function Hr(e){return new TypeError(`ByteLengthQueuingStrategy.prototype.${e} can only be used on a ByteLengthQueuingStrategy`)}function Yr(e){return!!i(e)&&!!Object.prototype.hasOwnProperty.call(e,"_byteLengthQueuingStrategyHighWaterMark")&&e instanceof $r}Object.defineProperties($r.prototype,{highWaterMark:{enumerable:!0},size:{enumerable:!0}}),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty($r.prototype,Symbol.toStringTag,{value:"ByteLengthQueuingStrategy",configurable:!0});const Jr=()=>1;s(Jr,"size");class Qr{constructor(e){G(e,1,"CountQueuingStrategy"),e=Nr(e,"First parameter"),this._countQueuingStrategyHighWaterMark=e.highWaterMark}get highWaterMark(){if(!Xr(this))throw Vr("highWaterMark");return this._countQueuingStrategyHighWaterMark}get size(){if(!Xr(this))throw Vr("size");return Jr}}function Vr(e){return new TypeError(`CountQueuingStrategy.prototype.${e} can only be used on a CountQueuingStrategy`)}function Xr(e){return!!i(e)&&!!Object.prototype.hasOwnProperty.call(e,"_countQueuingStrategyHighWaterMark")&&e instanceof Qr}function Kr(e,t,r){return D(e,r),r=>T(e,t,[r])}function Zr(e,t,r){return D(e,r),r=>R(e,t,[r])}function en(e,t,r){return D(e,r),(r,n)=>T(e,t,[r,n])}function tn(e,t,r){return D(e,r),r=>T(e,t,[r])}Object.defineProperties(Qr.prototype,{highWaterMark:{enumerable:!0},size:{enumerable:!0}}),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(Qr.prototype,Symbol.toStringTag,{value:"CountQueuingStrategy",configurable:!0});class rn{constructor(e={},t={},r={}){void 0===e&&(e=null);const n=yt(t,"Second parameter"),o=yt(r,"Third parameter"),i=function(e,t){F(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:tn(r,e,t+" has member 'cancel' that"),flush:void 0===n?void 0:Kr(n,e,t+" has member 'flush' that"),readableType:o,start:void 0===i?void 0:Zr(i,e,t+" has member 'start' that"),transform:void 0===a?void 0:en(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=pt(o,0),s=bt(o),u=pt(n,1),l=bt(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(Tt.prototype);return Ot(a),Ht(a,Object.create(Gt.prototype),e,t,r,n,o,i),a}(a,(function(t){return function(e,t){const r=e._transformStreamController;return e._backpressure?g(e._backpressureChangePromise,()=>{const n=e._writable;if("erroring"===n._state)throw n._storedError;return hn(r,t)}):hn(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=h((e,r)=>{t._finishPromise_resolve=e,t._finishPromise_reject=r});const n=t._flushAlgorithm();return fn(t),m(n,()=>("errored"===r._state?yn(t,r._storedError):(gr(r._readableStreamController),bn(t)),null),e=>(Sr(r._readableStreamController,e),yn(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=h((e,t)=>{r._finishPromise_resolve=e,r._finishPromise_reject=t});const o=r._cancelAlgorithm(t);return fn(r),m(o,()=>("errored"===n._state?yn(r,n._storedError):(Sr(n._readableStreamController,t),bn(r)),null),e=>(Sr(n._readableStreamController,e),yn(r,e),null)),r._finishPromise}(e,t)}),r,n),e._readable=Ir(a,(function(){return function(e){return un(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=h((e,t)=>{r._finishPromise_resolve=e,r._finishPromise_reject=t});const o=r._cancelAlgorithm(t);return fn(r),m(o,()=>("errored"===n._state?yn(r,n._storedError):(Vt(n._writableStreamController,t),sn(e),bn(r)),null),t=>(Vt(n._writableStreamController,t),sn(e),yn(r,t),null)),r._finishPromise}(e,t)}),o,i),e._backpressure=void 0,e._backpressureChangePromise=void 0,e._backpressureChangePromise_resolve=void 0,un(e,!0),e._transformStreamController=void 0}(this,h(e=>{c=e}),u,l,a,s),function(e,t){const r=Object.create(ln.prototype);let n,o,i;n=void 0!==t.transform?e=>t.transform(e,r):e=>{try{return dn(r,e),p(void 0)}catch(e){return b(e)}},o=void 0!==t.flush?()=>t.flush(r):()=>p(void 0),i=void 0!==t.cancel?e=>t.cancel(e):()=>p(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(!nn(this))throw mn("readable");return this._readable}get writable(){if(!nn(this))throw mn("writable");return this._writable}}function nn(e){return!!i(e)&&!!Object.prototype.hasOwnProperty.call(e,"_transformStreamController")&&e instanceof rn}function on(e,t){Sr(e._readable._readableStreamController,t),an(e,t)}function an(e,t){fn(e._transformStreamController),Vt(e._writable._writableStreamController,t),sn(e)}function sn(e){e._backpressure&&un(e,!1)}function un(e,t){void 0!==e._backpressureChangePromise&&e._backpressureChangePromise_resolve(),e._backpressureChangePromise=h(t=>{e._backpressureChangePromise_resolve=t}),e._backpressure=t}Object.defineProperties(rn.prototype,{readable:{enumerable:!0},writable:{enumerable:!0}}),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(rn.prototype,Symbol.toStringTag,{value:"TransformStream",configurable:!0});class ln{constructor(){throw new TypeError("Illegal constructor")}get desiredSize(){if(!cn(this))throw pn("desiredSize");return Rr(this._controlledTransformStream._readable._readableStreamController)}enqueue(e){if(!cn(this))throw pn("enqueue");dn(this,e)}error(e){if(!cn(this))throw pn("error");var t;t=e,on(this._controlledTransformStream,t)}terminate(){if(!cn(this))throw pn("terminate");!function(e){const t=e._controlledTransformStream;gr(t._readable._readableStreamController);an(t,new TypeError("TransformStream terminated"))}(this)}}function cn(e){return!!i(e)&&!!Object.prototype.hasOwnProperty.call(e,"_controlledTransformStream")&&e instanceof ln}function fn(e){e._transformAlgorithm=void 0,e._flushAlgorithm=void 0,e._cancelAlgorithm=void 0}function dn(e,t){const r=e._controlledTransformStream,n=r._readable._readableStreamController;if(!Tr(n))throw new TypeError("Readable side is not in a state that permits enqueue");try{wr(n,t)}catch(e){throw an(r,e),r._readable._storedError}(function(e){return!vr(e)})(n)!==r._backpressure&&un(r,!0)}function hn(e,t){return g(e._transformAlgorithm(t),void 0,t=>{throw on(e._controlledTransformStream,t),t})}function pn(e){return new TypeError(`TransformStreamDefaultController.prototype.${e} can only be used on a TransformStreamDefaultController`)}function bn(e){void 0!==e._finishPromise_resolve&&(e._finishPromise_resolve(),e._finishPromise_resolve=void 0,e._finishPromise_reject=void 0)}function yn(e,t){void 0!==e._finishPromise_reject&&(w(e._finishPromise),e._finishPromise_reject(t),e._finishPromise_resolve=void 0,e._finishPromise_reject=void 0)}function mn(e){return new TypeError(`TransformStream.prototype.${e} can only be used on a TransformStream`)}Object.defineProperties(ln.prototype,{enqueue:{enumerable:!0},error:{enumerable:!0},terminate:{enumerable:!0},desiredSize:{enumerable:!0}}),s(ln.prototype.enqueue,"enqueue"),s(ln.prototype.error,"error"),s(ln.prototype.terminate,"terminate"),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(ln.prototype,Symbol.toStringTag,{value:"TransformStreamDefaultController",configurable:!0});var vn=function(e,t){return(vn=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)};function _n(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}vn(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}function gn(e){if(!e)throw new TypeError("Assertion failed")}function wn(){}function Sn(e){return"object"==typeof e&&null!==e||"function"==typeof e}function Rn(e){if("function"!=typeof e)return!1;var t=!1;try{new e({start:function(){t=!0}})}catch(e){}return t}function Tn(e){return!!Sn(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 gn(Tn(e)),gn(!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 gn(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;gn(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(wn)},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 _n(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 _n(t,e),Object.defineProperty(t.prototype,"type",{get:function(){return"bytes"},enumerable:!1,configurable:!0}),t.prototype._attachByobReader=function(){if("byob"!==this._readerMode){gn(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(wn)}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(wn),r._writer.abort(e).catch(wn)},this._onTerminate=function(){r._flushResolve(),r._transformStreamController.terminate();var e=new TypeError("TransformStream terminated");r._writer.abort(e).catch(wn)},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];function An(e){return xn.every((function(t,r){return e.charCodeAt(r)===t}))}var In=r(410),Wn=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())}))},Un=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=a.trys,(o=o.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])}}},Bn=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)}))}}},Mn=Ar,Ln=rn,zn=function(){var e;return new Ln({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&&An(r)&&(r=r.slice(xn.length));t=!1;var i=r.length,a=0,s=!1;for(;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=n<0,l=t.slice(r,r+(u?o:n)),c=0,f=r+(c=u?o:" "===t[r+n+1]?n+2:n+1),d=o-c,h=t.slice(f,f+d).toString();if("data"===l)s+=h?"".concat(h,"\n"):"\n";else if("event"===l)a=h;else if("id"!==l||h.includes("\0")){if("retry"===l){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)}})},Fn=function(e){gn(function(e){return!!Rn(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)}i=On(r);return new e(i)}}(Mn),Dn=function(){function e(e,t){void 0===e&&(e="utf-8"),void 0===t&&(t={});var r=this;this.transform=new Ln({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 In.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 Nn(e){var t=e;return t[Symbol.asyncIterator]=function(){var t=e.getReader();return{next:function(){return Wn(this,void 0,void 0,(function(){var e,r,n;return Un(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 Gn(e){return Nn(e.pipeThrough(new Dn).pipeThrough(zn()).pipeThrough(new Ln({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 $n(e){return Nn(Fn(e).pipeThrough(new Dn))}function Hn(e){var t,r,n,o;return Wn(this,void 0,void 0,(function(){var i,a,s,u,l,c;return Un(this,(function(f){switch(f.label){case 0:i=$n(e),a="",f.label=1;case 1:f.trys.push([1,6,7,12]),s=!0,u=Bn(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 Yn(){var e,t;return{promise:new Promise((function(r,n){e=r,t=n})),res:e,rej:t}}function Jn(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 Qn(e){return{type:"function",function:{description:e.description,name:e.name,parameters:e.parameters}}}var Vn=function(){return(Vn=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}).apply(this,arguments)},Xn=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())}))},Kn=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=a.trys,(o=o.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])}}},Zn=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},eo=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=Zn(t,["headers"]);return e(Vn(Vn({},i),{headers:Vn(Vn({},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 Xn(this,void 0,void 0,(function(){return Kn(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=Zn(e,["botId"]);return Xn(this,void 0,void 0,(function(){return Kn(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=Zn(e,["pageSize","pageNumber","botId"]);return Xn(this,void 0,void 0,(function(){var e,r;return Kn(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:Vn(Vn({},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=Zn(e,["botId","conversationId"]);return Xn(this,void 0,void 0,(function(){return Kn(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 Xn(this,void 0,void 0,(function(){return Kn(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 Xn(this,void 0,void 0,(function(){return Kn(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 Xn(this,void 0,void 0,(function(){return Kn(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 Xn(this,void 0,void 0,(function(){var r;return Kn(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 to(r)]}}))}))},e.prototype.generateBot=function(e,t){return Xn(this,void 0,void 0,(function(){var r;return Kn(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 to(r)]}}))}))},e.prototype.getPreview=function(e,t){return Xn(this,void 0,void 0,(function(){var r;return Kn(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 to(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 Xn(this,void 0,void 0,(function(){var r;return Kn(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 to(r)]}}))}))},e.prototype.join=function(e){return"".concat(this.baseUrl,"/").concat(e)},e}(),to=function(){function e(e){var t=Fn(e);this._eventSourceStream=t.pipeThrough(new Dn).pipeThrough(zn())}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 Nn(this.teeedStream)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"dataStream",{get:function(){return Nn(this.eventSourceStream.pipeThrough(new Ln({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 Nn(this.dataStream.pipeThrough(new Ln({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}(),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}).apply(this,arguments)},no=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())}))},oo=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=a.trys,(o=o.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 io(e){var t=e.messages,r=e.model,n=e.temperature,o=e.tool_choice,i=e.tools,a=e.top_p;return ro(ro({},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 ao=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 no(this,void 0,void 0,(function(){var r,n;return oo(this,(function(o){switch(o.label){case 0:return r=io(e),[4,this.req({url:this.url,data:ro(ro({},r),{stream:!1}),stream:!1,timeout:null==t?void 0:t.timeout})];case 1:return n=o.sent(),[2,ro(ro({},n),{rawResponse:n})]}}))}))},e.prototype.doStream=function(e,t){return no(this,void 0,void 0,(function(){var r,n,o,i,a;return oo(this,(function(s){switch(s.label){case 0:return r=io(e),n=null,[4,this.req({url:this.url,data:ro(ro({},r),{stream:!0}),stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return o=s.sent(),i=Fn(o),a=Gn(i),[2,Nn(a.pipeThrough(new Ln({transform:function(e,t){var r=e.choices.map((function(e){var t=e.delta;return null==n&&(n=Jn(t)),n?ro(ro({},e),{finish_reason:"tool_calls",delta:t}):e})),o=ro(ro({},e),{choices:r});t.enqueue(ro(ro({},o),{rawResponse:e}))}})))]}}))}))},e}(),so=function(){return(so=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}).apply(this,arguments)};function uo(e){var t=e.messages,r=e.model,n=e.temperature,o=e.tool_choice,i=e.tools,a=e.top_p;return so(so({},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 lo(e){return"object"!=typeof e||null==e?e:Array.isArray(e)?e.map((function(e){return lo(e)})):Object.entries(e).reduce((function(e,t){var r=t[0],n=t[1];return e[function(e){var t=e.replace(/[A-Z]/g,(function(e){return"_".concat(e.toLowerCase())}));return"_"===t.charAt(0)?t.slice(1):t}(r)]="object"==typeof n?lo(n):n,e}),{})}var co=function(){return(co=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}).apply(this,arguments)},fo=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())}))},ho=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=a.trys,(o=o.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])}}},po=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 fo(this,void 0,void 0,(function(){var r;return ho(this,(function(n){switch(n.label){case 0:return[4,this.req({url:this.url,data:co(co({},uo(e)),{stream:!1}),stream:!1,timeout:null==t?void 0:t.timeout})];case 1:return r=n.sent(),[2,co(co({},r),{rawResponse:r})]}}))}))},e.prototype.doStream=function(e,t){return fo(this,void 0,void 0,(function(){var r,n,o,i;return ho(this,(function(a){switch(a.label){case 0:return r=null,[4,this.req({url:this.url,data:co(co({},uo(e)),{stream:!0}),stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return n=a.sent(),o=Fn(n),i=Gn(o),[2,Nn(i.pipeThrough(new Ln({transform:function(e,t){var n=e.choices.map((function(e){var t=e.delta;return null==r&&(r=Jn(t)),r?co(co({},e),{finish_reason:"tool_calls",delta:t}):e})),o=co(co({},e),{choices:n});t.enqueue(co(co({},o),{rawResponse:e}))}})))]}}))}))},e}(),bo=function(){return(bo=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}).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())}))},mo=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=a.trys,(o=o.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])}}},vo=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 yo(this,void 0,void 0,(function(){var r,n;return mo(this,(function(o){switch(o.label){case 0:return[4,this.req({url:this.url,headers:{"X-Tc-Action":"ChatCompletions"},data:bo(bo({},uo(e)),{stream:!1}),stream:!1,timeout:null==t?void 0:t.timeout})];case 1:return r=o.sent(),n=lo(r.Response),[2,bo(bo({},n),{rawResponse:r})]}}))}))},e.prototype.doStream=function(e,t){return yo(this,void 0,void 0,(function(){var r,n,o,i;return mo(this,(function(a){switch(a.label){case 0:return r=null,[4,this.req({url:this.url,headers:{"X-Tc-Action":"ChatCompletions"},data:bo(bo({},e),{stream:!0}),stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return n=a.sent(),o=Fn(n),i=Gn(o),[2,Nn(i.pipeThrough(new Ln({transform:function(e,t){var n=lo(e),o=n.choices.map((function(e){var t=e.delta;return null==r&&(r=Jn(t)),r?bo(bo({},e),{finish_reason:"tool_calls",delta:t}):e})),i=bo(bo({},n),{choices:o});t.enqueue(bo(bo({},i),{rawResponse:e}))}})))]}}))}))},e}(),_o=function(){return(_o=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}).apply(this,arguments)},go=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=a.trys,(o=o.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 So(e){var t=e.messages,r=e.model,n=e.temperature,o=e.tools,i=e.top_p;return _o(_o({},e),{messages:t,model:r,tools:o,top_p:i,temperature:n})}var Ro=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 go(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:_o(_o({},So(e)),{stream:!1}),stream:!1,timeout:null==t?void 0:t.timeout})];case 1:return r=n.sent(),[2,_o(_o({},r),{rawResponse:r})]}}))}))},e.prototype.doStream=function(e,t){return go(this,void 0,void 0,(function(){var r,n,o,i;return wo(this,(function(a){switch(a.label){case 0:return r=null,[4,this.req({url:this.url,data:_o(_o({},So(e)),{stream:!0}),stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return n=a.sent(),o=Fn(n),i=Gn(o),[2,Nn(i.pipeThrough(new Ln({transform:function(e,t){var n=e.choices.map((function(e){var t=e.delta;return null==r&&(r=Jn(t)),r?_o(_o({},e),{finish_reason:"tool_calls",delta:t}):e})),o=_o(_o({},e),{choices:n});t.enqueue(_o(_o({},o),{rawResponse:e}))}})))]}}))}))},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}).apply(this,arguments)},Po=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())}))},Oo=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=a.trys,(o=o.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 jo(e){var t=e.messages,r=e.model,n=e.temperature,o=e.tools,i=e.top_p;return To(To({},e),{messages:t,model:r,tools:o,top_p:i,temperature:n})}var qo=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 Po(this,void 0,void 0,(function(){var r;return Oo(this,(function(n){switch(n.label){case 0:return[4,this.req({url:this.url,data:To(To({},jo(e)),{stream:!1}),stream:!1,timeout:null==t?void 0:t.timeout})];case 1:return r=n.sent(),[2,To(To({},r),{rawResponse:r})]}}))}))},e.prototype.doStream=function(e,t){return Po(this,void 0,void 0,(function(){var r,n,o,i;return Oo(this,(function(a){switch(a.label){case 0:return r=null,[4,this.req({url:this.url,data:To(To({},jo(e)),{stream:!0}),stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return n=a.sent(),o=Fn(n),i=Gn(o),[2,Nn(i.pipeThrough(new Ln({transform:function(e,t){var n=e.choices.map((function(e){var t=Object.assign(e.delta,{role:"assistant"});return null==r&&(r=Jn(t)),To(To({},e),r?{finish_reason:"tool_calls",delta:t}:{delta:t})})),o=To(To({},e),{choices:n});t.enqueue(To(To({},o),{rawResponse:e}))}})))]}}))}))},e}(),ko=function(){return(ko=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}).apply(this,arguments)},Eo=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())}))},Co=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=a.trys,(o=o.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 xo(e){var t=e.messages,r=e.model,n=e.temperature,o=e.tools,i=e.top_p;return ko(ko({},e),{messages:t,model:r,tools:o,top_p:i,temperature:n})}var Ao=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 Eo(this,void 0,void 0,(function(){var r;return Co(this,(function(n){switch(n.label){case 0:return[4,this.req({url:this.url,data:ko(ko({},xo(e)),{stream:!1}),stream:!1,timeout:null==t?void 0:t.timeout})];case 1:return r=n.sent(),[2,ko(ko({},r),{rawResponse:r})]}}))}))},e.prototype.doStream=function(e,t){return Eo(this,void 0,void 0,(function(){var r,n,o,i;return Co(this,(function(a){switch(a.label){case 0:return r=null,[4,this.req({url:this.url,data:ko(ko({},xo(e)),{stream:!0}),stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return n=a.sent(),o=Fn(n),i=Gn(o),[2,Nn(i.pipeThrough(new Ln({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=Jn(t)),ko(ko({},e),r?{finish_reason:"tool_calls",delta:t}:{delta:t})})),c=ko(ko({},e),{choices:l});t.enqueue(ko(ko({},c),{rawResponse:e}))}}})))]}}))}))},e}(),Io=function(){return(Io=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}).apply(this,arguments)},Wo=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())}))},Uo=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=a.trys,(o=o.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 Bo(e){var t=e.messages,r=e.model,n=e.temperature,o=e.tools,i=e.top_p;return Io(Io({},e),{messages:t,model:r,tools:o,top_p:i,temperature:n})}var Mo=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 Wo(this,void 0,void 0,(function(){var r;return Uo(this,(function(n){switch(n.label){case 0:return[4,this.req({url:this.url,data:Io(Io({},Bo(e)),{stream:!1}),stream:!1,timeout:null==t?void 0:t.timeout})];case 1:return r=n.sent(),[2,Io(Io({},r),{rawResponse:r})]}}))}))},e.prototype.doStream=function(e,t){return Wo(this,void 0,void 0,(function(){var r,n,o,i;return Uo(this,(function(a){switch(a.label){case 0:return r=null,[4,this.req({url:this.url,data:Io(Io({},Bo(e)),{stream:!0}),stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return n=a.sent(),o=Fn(n),i=Gn(o),[2,Nn(i.pipeThrough(new Ln({transform:function(e,t){var n=e.choices.map((function(e){var t=e.delta;return null==r&&(r=Jn(t)),r?Io(Io({},e),{finish_reason:"tool_calls",delta:t}):e})),o=Io(Io({},e),{choices:n});t.enqueue(Io(Io({},o),{rawResponse:e}))}})))]}}))}))},e}(),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}).apply(this,arguments)},zo=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=a.trys,(o=o.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])}}},Do=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 zo(this,void 0,void 0,(function(){var t;return Fo(this,(function(r){switch(r.label){case 0:return[4,this.req({url:this.url,data:Lo(Lo({},uo(e)),{stream:!1}),stream:!1})];case 1:return t=r.sent(),[2,Lo(Lo({},t),{rawResponse:t})]}}))}))},e.prototype.doStream=function(e){return zo(this,void 0,void 0,(function(){var t,r,n,o;return Fo(this,(function(i){switch(i.label){case 0:return t=null,[4,this.req({url:this.url,data:Lo(Lo({},uo(e)),{stream:!0}),stream:!0})];case 1:return r=i.sent(),n=Fn(r),o=Gn(n),[2,Nn(o.pipeThrough(new Ln({transform:function(e,r){var n=e.choices.map((function(e){var r=e.delta;return null==t&&(t=Jn(r)),t?Lo(Lo({},e),{finish_reason:"tool_calls",delta:r}):e})),o=Lo(Lo({},e),{choices:n});r.enqueue(Lo(Lo({},o),{rawResponse:e}))}})))]}}))}))},e}(),No=function(){return(No=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}).apply(this,arguments)},Go=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())}))},$o=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=a.trys,(o=o.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-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 Go(this,void 0,void 0,(function(){var r;return $o(this,(function(n){switch(n.label){case 0:return[4,this.req({url:this.url,data:No(No({},uo(e)),{stream:!1}),stream:!1,timeout:null==t?void 0:t.timeout})];case 1:return r=n.sent(),[2,No(No({},r),{rawResponse:r})]}}))}))},e.prototype.doStream=function(e,t){return Go(this,void 0,void 0,(function(){var r,n,o,i;return $o(this,(function(a){switch(a.label){case 0:return r=null,[4,this.req({url:this.url,data:No(No({},uo(e)),{stream:!0}),stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return n=a.sent(),o=Fn(n),i=Gn(o),[2,Nn(i.pipeThrough(new Ln({transform:function(e,t){var n=e.choices.map((function(e){var t=e.delta;return null==r&&(r=Jn(t)),r?No(No({},e),{finish_reason:"tool_calls",delta:t}):e})),o=No(No({},e),{choices:n});t.enqueue(No(No({},o),{rawResponse:e}))}})))]}}))}))},e}(),Yo=function(){return(Yo=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}).apply(this,arguments)},Jo=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())}))},Qo=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=a.trys,(o=o.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])}}},Vo=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 Jo(this,void 0,void 0,(function(){var r;return Qo(this,(function(n){switch(n.label){case 0:return[4,this.req({url:this.url,data:Yo(Yo({},e),{stream:!1}),stream:!1,timeout:null==t?void 0:t.timeout})];case 1:return r=n.sent(),[2,Yo(Yo({},r),{rawResponse:r})]}}))}))},e.prototype.doStream=function(e,t){return Jo(this,void 0,void 0,(function(){var r,n,o,i;return Qo(this,(function(a){switch(a.label){case 0:return r=null,[4,this.req({url:this.url,data:Yo(Yo({},e),{stream:!0}),stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return n=a.sent(),o=Fn(n),i=Gn(o),[2,Nn(i.pipeThrough(new Ln({transform:function(e,t){var n=e.choices.map((function(e){var t=e.delta;return null==r&&(r=Jn(t)),r?Yo(Yo({},e),{finish_reason:"tool_calls",delta:t}):e})),o=Yo(Yo({},e),{choices:n});t.enqueue(Yo(Yo({},o),{rawResponse:e}))}})))]}}))}))},e}(),Xo=function(){return(Xo=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}).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())}))},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=a.trys,(o=o.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])}}},ei=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 Ko(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:Xo(Xo({},e),{stream:!1}),stream:!1})];case 1:return t=r.sent(),[2,Xo(Xo({},t),{rawResponse:t})]}}))}))},e.prototype.doStream=function(e){return Ko(this,void 0,void 0,(function(){var t,r,n,o;return Zo(this,(function(i){switch(i.label){case 0:return t=null,[4,this.req({url:this.url,data:Xo(Xo({},e),{stream:!0}),stream:!0})];case 1:return r=i.sent(),n=Fn(r),o=Gn(n),[2,Nn(o.pipeThrough(new Ln({transform:function(e,r){var n=e.choices.map((function(e){var r=e.delta;return null==t&&(t=Jn(r)),t?Xo(Xo({},e),{finish_reason:"tool_calls",delta:r}):e})),o=Xo(Xo({},e),{choices:n});r.enqueue(Xo(Xo({},o),{rawResponse: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}).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=a.trys,(o=o.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){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},ii=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)}))}}},ai=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 si(e){var t,r=e.onStepFinish,n=e.abortSignal,o=e.maxSteps,i=e.topP,a=e.toolChoice,s=oi(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?Qn(e):e})),top_p:null!=i?i:s.top_p,tool_choice:null!=a?a:s.tool_choice})]}var ui=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=si(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=li(h))))return[3,9];y=hi(h.usage),pi(i,y),O.label=3;case 3:return O.trys.push([3,7,,8]),[4,di(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(),ci(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?ai(ai([],f.messages,!0),[w],!1):f.messages,T=hi(h.usage),pi(i,T),[4,null==u?void 0:u({finishReason:g.finish_reason,messages:R.slice(),text:S,toolCall:li(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=si(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=Nn(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=Nn(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=ii(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,pi(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,di(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(),ci(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:Nn(S),textStream:Nn(R.pipeThrough(new Ln({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,pi(n,P),O=ai(ai([],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(ai(ai([],l.messages,!0),[T],!1)),dataStream:Nn(q),textStream:Nn(k.pipeThrough(new Ln({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=Yn(),C=Yn(),x={role:"assistant",content:""},A="",I={completion_tokens:0,prompt_tokens:0,total_tokens:0},W=f.pipeThrough(new Ln({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(ai(ai([],l.messages,!0),[x],!1)),pi(n,I),C.res(Object.assign({},n)),null==a||a({messages:ai(ai([],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:Nn(B),textStream:Nn(M.pipeThrough(new Ln({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 li(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&&Jn(o)?o.tool_calls[0]:null}function ci(e,t,r){e.push(t,{role:"tool",tool_call_id:t.tool_calls[0].id,content:JSON.stringify(r)})}var fi=new Map;function di(e){return fi.get(e.function.name)(JSON.parse(e.function.arguments))}function hi(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 pi(e,t){e.completion_tokens+=t.completion_tokens,e.prompt_tokens+=t.prompt_tokens,e.total_tokens+=t.total_tokens}var bi={hunyuan:vo,"hunyuan-beta":po,ark:Ro,dashscope:qo,"01-ai":Ao,moonshot:Mo,zhipu:ao,"hunyuan-exp":Do,"hunyuan-open":Ho,deepseek:Vo},yi="@cloudbase/js-sdk";function mi(){return yi}var vi="https:";var _i,gi="INVALID_PARAMS",wi="INVALID_OPERATION",Si="OPERATION_FAIL";!function(e){e.local="local",e.none="none",e.session="session"}(_i||(_i={}));var Ri=function(){};function Ti(e,t){console.warn("[".concat(mi(),"][").concat(e,"]:").concat(t))}var Pi,Oi=(Pi=function(e,t){return(Pi=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)},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}Pi(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}),ji=function(){return(ji=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}).apply(this,arguments)},qi=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())}))},ki=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=a.trys,(o=o.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}Oi(t,e),t.prototype.get=function(e){return this.request(ji(ji({},e),{method:"get"}),this.restrictedMethods.includes("get"))},t.prototype.post=function(e){return this.request(ji(ji({},e),{method:"post"}),this.restrictedMethods.includes("post"))},t.prototype.put=function(e){return this.request(ji(ji({},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(ji(ji({},e),{data:u,method:s}),this.restrictedMethods.includes("upload"))):this.request(ji(ji({},e),{method:"put",headers:a,body:r}),this.restrictedMethods.includes("upload"))},t.prototype.download=function(e){return qi(this,void 0,void 0,(function(){var t,r,n,o;return ki(this,(function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,this.get(ji(ji({},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 qi(this,void 0,void 0,(function(){var r,n,o,i,a,s,u,l,c,f,d,h,p,b=this;return ki(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,ji(ji({},e),{signal:r.signal})).then((function(e){return qi(b,void 0,void 0,(function(){var t,r,n;return ki(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)}(vi,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(){}));var Ei;!function(e){e.WEB="web",e.WX_MP="wx_mp"}(Ei||(Ei={}));var Ci=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])})(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)}}(),xi=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())}))},Ai=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=a.trys,(o=o.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])}}},Ii=function(e){function t(t){var r=e.call(this)||this;return r.root=t,t.tcbCacheObject||(t.tcbCacheObject={}),r}return Ci(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}(Ri);!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":return t.localStorage?t.localStorage:(Ti(gi,"localStorage is not supported on current platform"),new Ii(t.root));case"none":return new Ii(t.root);default:return t.localStorage?t.localStorage:(Ti(gi,"localStorage is not supported on current platform"),new Ii(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:Si,msg:"[".concat(mi(),"][").concat(Si,"]setStore failed"),info:e}))}}else Ti(wi,"current platform's storage is asynchronous, please use setStoreAsync insteed")},e.prototype.setStoreAsync=function(e,t,r){return xi(this,void 0,void 0,(function(){var n;return Ai(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=process.env)||void 0===r?void 0:r.tcb_token))return process.env.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:""}Ti(wi,"current platform's storage is asynchronous, please use getStoreAsync insteed")},e.prototype.getStoreAsync=function(e,t){var r;return xi(this,void 0,void 0,(function(){var n;return Ai(this,(function(o){switch(o.label){case 0:try{if("undefined"!=typeof process&&(null===(r=process.env)||void 0===r?void 0:r.tcb_token))return[2,process.env.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):Ti(wi,"current platform's storage is asynchronous, please use removeStoreAsync insteed")},e.prototype.removeStoreAsync=function(e){return xi(this,void 0,void 0,(function(){return Ai(this,(function(t){switch(t.label){case 0:return[4,this.storage.removeItem(e)];case 1:return t.sent(),[2]}}))}))}}();var Wi=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])})(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)}}(),Ui=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))};var Bi=function(e,t){this.data=t||null,this.name=e},Mi=function(e){function t(t,r){var n=e.call(this,"error",{error:t,data:r})||this;return n.error=t,n}return Wi(t,e),t}(Bi),Li=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 Mi)return console.error(e.error),this;var r="string"==typeof e?new Bi(e,t||{}):e,n=r.name;if(this.listens(n)){r.target=this;for(var o=0,i=this.listeners[n]?Ui([],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 Li;var zi=new Li;"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.indexOf("Firefox");!function(){function e(){var e=this;this.listeners=[],this.signal={aborted:!1,addEventListener:function(t,r){"abort"===t&&e.listeners.push(r)}}}e.prototype.abort=function(){this.signal.aborted||(this.signal.aborted=!0,this.listeners.forEach((function(e){return e()})))}}();function Fi(e){this.message=e}Fi.prototype=new Error,Fi.prototype.name="InvalidCharacterError";"undefined"!=typeof window&&window.atob&&window.atob.bind(window);function Di(e){this.message=e}Di.prototype=new Error,Di.prototype.name="InvalidTokenError";var Ni=function(){return(Ni=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}).apply(this,arguments)},Gi=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())}))},$i=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=a.trys,(o=o.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])}}},Hi=bi,Yi=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 Gi(n,void 0,void 0,(function(){var e,n,s,u,l,c,f;return $i(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:Ni(Ni((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 Gi(n,void 0,void 0,(function(){var e,n,o,l,c,f,d,h;return $i(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:Ni(Ni((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 eo(this.botRequest,this.aiBotBaseUrl),this.i18n=r,zi.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 Gi(this,void 0,void 0,(function(){var o,i;return $i(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,Hn(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=Hi[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 ei(this.modelRequest,this.aiBaseUrl,"".concat(e).concat(o))}return new ui(r)},e.prototype.registerModel=function(e,t){null==Hi[e]?Hi[e]=t:console.warn("AI model ".concat(e," already exists!"))},e.prototype.registerFunctionTool=function(e){fi.has(e.name)&&console.warn("AI function tool ".concat(e.name," already exists and will be overwritten!")),fi.set(e.name,e.fn)},e}(),Ji=function(){},Qi=function(){return(Qi=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}).apply(this,arguments)},Vi=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())}))},Xi=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=a.trys,(o=o.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,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},Zi=Ki(t,["MODELS"]);function ea(e){var t=e.env,r=e.baseUrl,n=e.req,o=e.getAccessToken,i=e.handleReqInstance,a=e.i18n;return new Yi(function(){if(null==i){if(null==o)throw new Error("`getAccessToken` is required when `handleReqInstance` is not provided!");return function(e){var t=e.getAccessToken,r=e.req;return{download:r.download,post:r.post,upload:r.upload,fetch:function(e){return Vi(void 0,void 0,void 0,(function(){var n,o,i,a,s;return Xi(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=Ki(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(Qi({headers:Qi({Authorization:"Bearer ".concat(s)},i)},a))]}}))}))}}}({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 ta={name:"ai",entity:{ai:function(e){var t,r=this,n=this.request;if(null==n.fetch)throw new Error("cloudbase.request.fetch() unimplemented!");return ea({req:n,baseUrl: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)}(),handleReqInstance:function(e){return e.req},i18n:this.config.i18n})}}};function ra(e){try{e.registerComponent(ta)}catch(e){console.warn(e)}}try{window.registerAi=ra}catch(o){}})(),n})());
|
|
2
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("tcbauth",[],t):"object"==typeof exports?exports.tcbauth=t():e.tcbauth=t()}("undefined"!=typeof window?window:this,()=>(()=>{var e={410:function(e,t,r){var n,o,i;o=[],void 0===(i="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,o):n)||(e.exports=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}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})};var n={};return(()=>{"use strict";r.r(n),r.d(n,{AI:()=>Vi,Bot:()=>eo,SimpleChatModel:()=>Xi,createAI:()=>na,createAi:()=>oa,models:()=>ra,registerAi:()=>aa,utils:()=>e});var e={};r.r(e),r.d(e,{ReadableStream:()=>Mn,TextDecoderStream:()=>Dn,TransformStream:()=>Ln,createAsyncIterable:()=>Nn,createEventSourceParserTransformStream:()=>zn,createPromise:()=>Yn,functionToolToModelTool:()=>Qn,intoStandardStream:()=>Gn,intoTextStream:()=>$n,isToolCallAssistantMessage:()=>Jn,readableStream2JsonObject:()=>Hn,toPolyfillReadable:()=>Fn});var t={};function o(){}function i(e){return"object"==typeof e&&null!==e||"function"==typeof e}r.r(t),r.d(t,{ArkSimpleModel:()=>Ro,DSSimpleModel:()=>jo,DefaultImageModel:()=>ni,DefaultSimpleModel:()=>ei,HunYuanBetaSimpleModel:()=>po,HunYuanExpSimpleModel:()=>Do,HunYuanOpenSimpleModel:()=>Ho,HunYuanSimpleModel:()=>vo,MODELS:()=>vi,MoonshotSimpleModel:()=>Mo,ReactModel:()=>fi,YiSimpleModel:()=>Ao,ZhiPuSimpleModel:()=>ao,toolMap:()=>pi});const a=o;function s(e,t){try{Object.defineProperty(e,"name",{value:t,configurable:!0})}catch(e){}}const u=Promise,l=Promise.resolve.bind(u),c=Promise.prototype.then,f=Promise.reject.bind(u),d=l;function h(e){return new u(e)}function p(e){return h(t=>t(e))}function b(e){return f(e)}function y(e,t,r){return c.call(e,t,r)}function m(e,t,r){y(y(e,t,r),void 0,a)}function v(e,t){m(e,t)}function _(e,t){m(e,void 0,t)}function g(e,t,r){return y(e,t,r)}function w(e){y(e,void 0,a)}let S=e=>{if("function"==typeof queueMicrotask)S=queueMicrotask;else{const e=p(void 0);S=t=>y(e,t)}return S(e)};function R(e,t,r){if("function"!=typeof e)throw new TypeError("Argument is not a function");return Function.prototype.apply.call(e,t,r)}function T(e,t,r){try{return p(R(e,t,r))}catch(e){return b(e)}}class P{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 O=Symbol("[[AbortSteps]]"),q=Symbol("[[ErrorSteps]]"),j=Symbol("[[CancelSteps]]"),k=Symbol("[[PullSteps]]"),E=Symbol("[[ReleaseSteps]]");function C(e,t){e._ownerReadableStream=t,t._reader=e,"readable"===t._state?W(e):"closed"===t._state?function(e){W(e),M(e)}(e):U(e,t._storedError)}function x(e,t){return Lr(e._ownerReadableStream,t)}function A(e){const t=e._ownerReadableStream;"readable"===t._state?B(e,new TypeError("Reader was released and can no longer be used to monitor the stream's closedness")):function(e,t){U(e,new TypeError("Reader was released and can no longer be used to monitor the stream's closedness"))}(e),t._readableStreamController[E](),t._reader=void 0,e._ownerReadableStream=void 0}function I(e){return new TypeError("Cannot "+e+" a stream using a released reader")}function W(e){e._closedPromise=h((t,r)=>{e._closedPromise_resolve=t,e._closedPromise_reject=r})}function U(e,t){W(e),B(e,t)}function B(e,t){void 0!==e._closedPromise_reject&&(w(e._closedPromise),e._closedPromise_reject(t),e._closedPromise_resolve=void 0,e._closedPromise_reject=void 0)}function M(e){void 0!==e._closedPromise_resolve&&(e._closedPromise_resolve(void 0),e._closedPromise_resolve=void 0,e._closedPromise_reject=void 0)}const L=Number.isFinite||function(e){return"number"==typeof e&&isFinite(e)},z=Math.trunc||function(e){return e<0?Math.ceil(e):Math.floor(e)};function F(e,t){if(void 0!==e&&"object"!=typeof(r=e)&&"function"!=typeof r)throw new TypeError(t+" is not an object.");var r}function D(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 $(e,t,r){if(void 0===e)throw new TypeError(`${t} is required in '${r}'.`)}function H(e){return Number(e)}function Y(e){return 0===e?0:e}function J(e,t){const r=Number.MAX_SAFE_INTEGER;let n=Number(e);if(n=Y(n),!L(n))throw new TypeError(t+" is not a finite number");if(n=function(e){return Y(z(e))}(n),n<0||n>r)throw new TypeError(`${t} is outside the accepted range of 0 to ${r}, inclusive`);return L(n)&&0!==n?n:0}function Q(e,t){if(!Br(e))throw new TypeError(t+" is not a ReadableStream.")}function V(e){return new te(e)}function X(e,t){e._reader._readRequests.push(t)}function K(e,t,r){const n=e._reader._readRequests.shift();r?n._closeSteps():n._chunkSteps(t)}function Z(e){return e._reader._readRequests.length}function ee(e){const t=e._reader;return void 0!==t&&!!re(t)}class te{constructor(e){if(G(e,1,"ReadableStreamDefaultReader"),Q(e,"First parameter"),Mr(e))throw new TypeError("This stream has already been locked for exclusive reading by another reader");C(this,e),this._readRequests=new P}get closed(){return re(this)?this._closedPromise:b(ie("closed"))}cancel(e){return re(this)?void 0===this._ownerReadableStream?b(I("cancel")):x(this,e):b(ie("cancel"))}read(){if(!re(this))return b(ie("read"));if(void 0===this._ownerReadableStream)return b(I("read from"));let e,t;const r=h((r,n)=>{e=r,t=n});return ne(this,{_chunkSteps:t=>e({value:t,done:!1}),_closeSteps:()=>e({value:void 0,done:!0}),_errorSteps:e=>t(e)}),r}releaseLock(){if(!re(this))throw ie("releaseLock");void 0!==this._ownerReadableStream&&function(e){A(e);oe(e,new TypeError("Reader was released"))}(this)}}function re(e){return!!i(e)&&!!Object.prototype.hasOwnProperty.call(e,"_readRequests")&&e instanceof te}function ne(e,t){const r=e._ownerReadableStream;r._disturbed=!0,"closed"===r._state?t._closeSteps():"errored"===r._state?t._errorSteps(r._storedError):r._readableStreamController[k](t)}function oe(e,t){const r=e._readRequests;e._readRequests=new P,r.forEach(e=>{e._errorSteps(t)})}function ie(e){return new TypeError(`ReadableStreamDefaultReader.prototype.${e} can only be used on a ReadableStreamDefaultReader`)}var ae,se,ue;function le(e){return e.slice()}function ce(e,t,r,n,o){new Uint8Array(e).set(new Uint8Array(r,n,o),t)}Object.defineProperties(te.prototype,{cancel:{enumerable:!0},read:{enumerable:!0},releaseLock:{enumerable:!0},closed:{enumerable:!0}}),s(te.prototype.cancel,"cancel"),s(te.prototype.read,"read"),s(te.prototype.releaseLock,"releaseLock"),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(te.prototype,Symbol.toStringTag,{value:"ReadableStreamDefaultReader",configurable:!0});let fe=e=>(fe="function"==typeof e.transfer?e=>e.transfer():"function"==typeof structuredClone?e=>structuredClone(e,{transfer:[e]}):e=>e,fe(e)),de=e=>(de="boolean"==typeof e.detached?e=>e.detached:e=>0===e.byteLength,de(e));function he(e,t,r){if(e.slice)return e.slice(t,r);const n=r-t,o=new ArrayBuffer(n);return ce(o,0,e,t,n),o}function pe(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 be(e){try{const t=e.done,r=e.value;return y(d(r),e=>({done:t,value:e}))}catch(e){return b(e)}}const ye=null!==(ue=null!==(ae=Symbol.asyncIterator)&&void 0!==ae?ae:null===(se=Symbol.for)||void 0===se?void 0:se.call(Symbol,"Symbol.asyncIterator"))&&void 0!==ue?ue:"@@asyncIterator";function me(e){const t=R(e.nextMethod,e.iterator,[]);if(!i(t))throw new TypeError("The iterator.next() method must return an object");return t}class ve{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?g(this._ongoingPromise,e,e):e(),this._ongoingPromise}return(e){const t=()=>this._returnSteps(e);return this._ongoingPromise?g(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=h((e,n)=>{t=e,r=n});return ne(e,{_chunkSteps:e=>{this._ongoingPromise=void 0,S(()=>t({value:e,done:!1}))},_closeSteps:()=>{this._ongoingPromise=void 0,this._isFinished=!0,A(e),t({value:void 0,done:!0})},_errorSteps:t=>{this._ongoingPromise=void 0,this._isFinished=!0,A(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=x(t,e);return A(t),g(r,()=>({value:e,done:!0}))}return A(t),p({value:e,done:!0})}}const _e={next(){return ge(this)?this._asyncIteratorImpl.next():b(we("next"))},return(e){return ge(this)?this._asyncIteratorImpl.return(e):b(we("return"))},[ye](){return this}};function ge(e){if(!i(e))return!1;if(!Object.prototype.hasOwnProperty.call(e,"_asyncIteratorImpl"))return!1;try{return e._asyncIteratorImpl instanceof ve}catch(e){return!1}}function we(e){return new TypeError(`ReadableStreamAsyncIterator.${e} can only be used on a ReadableSteamAsyncIterator`)}Object.defineProperty(_e,ye,{enumerable:!1});const Se=Number.isNaN||function(e){return e!=e};function Re(e){const t=he(e.buffer,e.byteOffset,e.byteOffset+e.byteLength);return new Uint8Array(t)}function Te(e){const t=e._queue.shift();return e._queueTotalSize-=t.size,e._queueTotalSize<0&&(e._queueTotalSize=0),t.value}function Pe(e,t,r){if("number"!=typeof(n=r)||Se(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 Oe(e){e._queue=new P,e._queueTotalSize=0}function qe(e){return e===DataView}class je{constructor(){throw new TypeError("Illegal constructor")}get view(){if(!Ce(this))throw rt("view");return this._view}respond(e){if(!Ce(this))throw rt("respond");if(G(e,1,"respond"),e=J(e,"First parameter"),void 0===this._associatedReadableByteStreamController)throw new TypeError("This BYOB request has been invalidated");if(de(this._view.buffer))throw new TypeError("The BYOB request's buffer has been detached and so cannot be used as a response");Ze(this._associatedReadableByteStreamController,e)}respondWithNewView(e){if(!Ce(this))throw rt("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(de(e.buffer))throw new TypeError("The given view's buffer has been detached and so cannot be used as a response");et(this._associatedReadableByteStreamController,e)}}Object.defineProperties(je.prototype,{respond:{enumerable:!0},respondWithNewView:{enumerable:!0},view:{enumerable:!0}}),s(je.prototype.respond,"respond"),s(je.prototype.respondWithNewView,"respondWithNewView"),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(je.prototype,Symbol.toStringTag,{value:"ReadableStreamBYOBRequest",configurable:!0});class ke{constructor(){throw new TypeError("Illegal constructor")}get byobRequest(){if(!Ee(this))throw nt("byobRequest");return Xe(this)}get desiredSize(){if(!Ee(this))throw nt("desiredSize");return Ke(this)}close(){if(!Ee(this))throw nt("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`);Ye(this)}enqueue(e){if(!Ee(this))throw nt("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`);Je(this,e)}error(e){if(!Ee(this))throw nt("error");Qe(this,e)}[j](e){Ae(this),Oe(this);const t=this._cancelAlgorithm(e);return He(this),t}[k](e){const t=this._controlledReadableByteStream;if(this._queueTotalSize>0)return void Ve(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)}X(t,e),xe(this)}[E](){if(this._pendingPullIntos.length>0){const e=this._pendingPullIntos.peek();e.readerType="none",this._pendingPullIntos=new P,this._pendingPullIntos.push(e)}}}function Ee(e){return!!i(e)&&!!Object.prototype.hasOwnProperty.call(e,"_controlledReadableByteStream")&&e instanceof ke}function Ce(e){return!!i(e)&&!!Object.prototype.hasOwnProperty.call(e,"_associatedReadableByteStreamController")&&e instanceof je}function xe(e){(function(e){const t=e._controlledReadableByteStream;if("readable"!==t._state)return!1;if(e._closeRequested)return!1;if(!e._started)return!1;if(ee(t)&&Z(t)>0)return!0;if(ut(t)&&st(t)>0)return!0;return Ke(e)>0})(e)&&(e._pulling?e._pullAgain=!0:(e._pulling=!0,m(e._pullAlgorithm(),()=>(e._pulling=!1,e._pullAgain&&(e._pullAgain=!1,xe(e)),null),t=>(Qe(e,t),null))))}function Ae(e){De(e),e._pendingPullIntos=new P}function Ie(e,t){let r=!1;"closed"===e._state&&(r=!0);const n=We(t);"default"===t.readerType?K(e,n,r):function(e,t,r){const n=e._reader._readIntoRequests.shift();r?n._closeSteps(t):n._chunkSteps(t)}(e,n,r)}function We(e){const t=e.bytesFilled,r=e.elementSize;return new e.viewConstructor(e.buffer,e.byteOffset,t/r)}function Ue(e,t,r,n){e._queue.push({buffer:t,byteOffset:r,byteLength:n}),e._queueTotalSize+=n}function Be(e,t,r,n){let o;try{o=he(t,r,r+n)}catch(t){throw Qe(e,t),t}Ue(e,o,0,n)}function Me(e,t){t.bytesFilled>0&&Be(e,t.buffer,t.byteOffset,t.bytesFilled),$e(e)}function Le(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;ce(t.buffer,i,r.buffer,r.byteOffset,n),r.byteLength===n?s.shift():(r.byteOffset+=n,r.byteLength-=n),e._queueTotalSize-=n,ze(e,n,t),o-=n}return i}function ze(e,t,r){r.bytesFilled+=t}function Fe(e){0===e._queueTotalSize&&e._closeRequested?(He(e),zr(e._controlledReadableByteStream)):xe(e)}function De(e){null!==e._byobRequest&&(e._byobRequest._associatedReadableByteStreamController=void 0,e._byobRequest._view=null,e._byobRequest=null)}function Ne(e){for(;e._pendingPullIntos.length>0;){if(0===e._queueTotalSize)return;const t=e._pendingPullIntos.peek();Le(e,t)&&($e(e),Ie(e._controlledReadableByteStream,t))}}function Ge(e,t){const r=e._pendingPullIntos.peek();De(e),"closed"===e._controlledReadableByteStream._state?function(e,t){"none"===t.readerType&&$e(e);const r=e._controlledReadableByteStream;if(ut(r))for(;st(r)>0;)Ie(r,$e(e))}(e,r):function(e,t,r){if(ze(0,t,r),"none"===r.readerType)return Me(e,r),void Ne(e);if(r.bytesFilled<r.minimumFill)return;$e(e);const n=r.bytesFilled%r.elementSize;if(n>0){const t=r.byteOffset+r.bytesFilled;Be(e,r.buffer,t-n,n)}r.bytesFilled-=n,Ie(e._controlledReadableByteStream,r),Ne(e)}(e,t,r),xe(e)}function $e(e){return e._pendingPullIntos.shift()}function He(e){e._pullAlgorithm=void 0,e._cancelAlgorithm=void 0}function Ye(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 Qe(e,t),t}}He(e),zr(t)}}function Je(e,t){const r=e._controlledReadableByteStream;if(e._closeRequested||"readable"!==r._state)return;const{buffer:n,byteOffset:o,byteLength:i}=t;if(de(n))throw new TypeError("chunk's buffer is detached and so cannot be enqueued");const a=fe(n);if(e._pendingPullIntos.length>0){const t=e._pendingPullIntos.peek();if(de(t.buffer))throw new TypeError("The BYOB request's buffer has been detached and so cannot be filled with an enqueued chunk");De(e),t.buffer=fe(t.buffer),"none"===t.readerType&&Me(e,t)}ee(r)?(function(e){const t=e._controlledReadableByteStream._reader;for(;t._readRequests.length>0;){if(0===e._queueTotalSize)return;Ve(e,t._readRequests.shift())}}(e),0===Z(r)?Ue(e,a,o,i):(e._pendingPullIntos.length>0&&$e(e),K(r,new Uint8Array(a,o,i),!1))):ut(r)?(Ue(e,a,o,i),Ne(e)):Ue(e,a,o,i),xe(e)}function Qe(e,t){const r=e._controlledReadableByteStream;"readable"===r._state&&(Ae(e),Oe(e),He(e),Fr(r,t))}function Ve(e,t){const r=e._queue.shift();e._queueTotalSize-=r.byteLength,Fe(e);const n=new Uint8Array(r.buffer,r.byteOffset,r.byteLength);t._chunkSteps(n)}function Xe(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(je.prototype);!function(e,t,r){e._associatedReadableByteStreamController=t,e._view=r}(n,e,r),e._byobRequest=n}return e._byobRequest}function Ke(e){const t=e._controlledReadableByteStream._state;return"errored"===t?null:"closed"===t?0:e._strategyHWM-e._queueTotalSize}function Ze(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=fe(r.buffer),Ge(e,t)}function et(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=fe(t.buffer),Ge(e,n)}function tt(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,Oe(t),t._closeRequested=!1,t._started=!1,t._strategyHWM=i,t._pullAlgorithm=n,t._cancelAlgorithm=o,t._autoAllocateChunkSize=a,t._pendingPullIntos=new P,e._readableStreamController=t,m(p(r()),()=>(t._started=!0,xe(t),null),e=>(Qe(t,e),null))}function rt(e){return new TypeError(`ReadableStreamBYOBRequest.prototype.${e} can only be used on a ReadableStreamBYOBRequest`)}function nt(e){return new TypeError(`ReadableByteStreamController.prototype.${e} can only be used on a ReadableByteStreamController`)}function ot(e,t){if("byob"!=(e=""+e))throw new TypeError(`${t} '${e}' is not a valid enumeration value for ReadableStreamReaderMode`);return e}function it(e){return new lt(e)}function at(e,t){e._reader._readIntoRequests.push(t)}function st(e){return e._reader._readIntoRequests.length}function ut(e){const t=e._reader;return void 0!==t&&!!ct(t)}Object.defineProperties(ke.prototype,{close:{enumerable:!0},enqueue:{enumerable:!0},error:{enumerable:!0},byobRequest:{enumerable:!0},desiredSize:{enumerable:!0}}),s(ke.prototype.close,"close"),s(ke.prototype.enqueue,"enqueue"),s(ke.prototype.error,"error"),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(ke.prototype,Symbol.toStringTag,{value:"ReadableByteStreamController",configurable:!0});class lt{constructor(e){if(G(e,1,"ReadableStreamBYOBReader"),Q(e,"First parameter"),Mr(e))throw new TypeError("This stream has already been locked for exclusive reading by another reader");if(!Ee(e._readableStreamController))throw new TypeError("Cannot construct a ReadableStreamBYOBReader for a stream not constructed with a byte source");C(this,e),this._readIntoRequests=new P}get closed(){return ct(this)?this._closedPromise:b(ht("closed"))}cancel(e){return ct(this)?void 0===this._ownerReadableStream?b(I("cancel")):x(this,e):b(ht("cancel"))}read(e,t={}){if(!ct(this))return b(ht("read"));if(!ArrayBuffer.isView(e))return b(new TypeError("view must be an array buffer view"));if(0===e.byteLength)return b(new TypeError("view must have non-zero byteLength"));if(0===e.buffer.byteLength)return b(new TypeError("view's buffer must have non-zero byteLength"));if(de(e.buffer))return b(new TypeError("view's buffer has been detached"));let r;try{r=function(e,t){var r;return F(e,t),{min:J(null!==(r=null==e?void 0:e.min)&&void 0!==r?r:1,t+" has member 'min' that")}}(t,"options")}catch(e){return b(e)}const n=r.min;if(0===n)return b(new TypeError("options.min must be greater than 0"));if(function(e){return qe(e.constructor)}(e)){if(n>e.byteLength)return b(new RangeError("options.min must be less than or equal to view's byteLength"))}else if(n>e.length)return b(new RangeError("options.min must be less than or equal to view's length"));if(void 0===this._ownerReadableStream)return b(I("read from"));let o,i;const a=h((e,t)=>{o=e,i=t});return ft(this,e,n,{_chunkSteps:e=>o({value:e,done:!1}),_closeSteps:e=>o({value:e,done:!0}),_errorSteps:e=>i(e)}),a}releaseLock(){if(!ct(this))throw ht("releaseLock");void 0!==this._ownerReadableStream&&function(e){A(e);dt(e,new TypeError("Reader was released"))}(this)}}function ct(e){return!!i(e)&&!!Object.prototype.hasOwnProperty.call(e,"_readIntoRequests")&&e instanceof lt}function ft(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 qe(e)?1:e.BYTES_PER_ELEMENT}(i),{byteOffset:s,byteLength:u}=t,l=r*a;let c;try{c=fe(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 at(o,n);if("closed"!==o._state){if(e._queueTotalSize>0){if(Le(e,f)){const t=We(f);return Fe(e),void n._chunkSteps(t)}if(e._closeRequested){const t=new TypeError("Insufficient bytes to fill elements in the given buffer");return Qe(e,t),void n._errorSteps(t)}}e._pendingPullIntos.push(f),at(o,n),xe(e)}else{const e=new i(f.buffer,f.byteOffset,0);n._closeSteps(e)}}(o._readableStreamController,t,r,n)}function dt(e,t){const r=e._readIntoRequests;e._readIntoRequests=new P,r.forEach(e=>{e._errorSteps(t)})}function ht(e){return new TypeError(`ReadableStreamBYOBReader.prototype.${e} can only be used on a ReadableStreamBYOBReader`)}function pt(e,t){const{highWaterMark:r}=e;if(void 0===r)return t;if(Se(r)||r<0)throw new RangeError("Invalid highWaterMark");return r}function bt(e){const{size:t}=e;return t||(()=>1)}function yt(e,t){F(e,t);const r=null==e?void 0:e.highWaterMark,n=null==e?void 0:e.size;return{highWaterMark:void 0===r?void 0:H(r),size:void 0===n?void 0:mt(n,t+" has member 'size' that")}}function mt(e,t){return D(e,t),t=>H(e(t))}function vt(e,t,r){return D(e,r),r=>T(e,t,[r])}function _t(e,t,r){return D(e,r),()=>T(e,t,[])}function gt(e,t,r){return D(e,r),r=>R(e,t,[r])}function wt(e,t,r){return D(e,r),(r,n)=>T(e,t,[r,n])}function St(e,t){if(!qt(e))throw new TypeError(t+" is not a WritableStream.")}Object.defineProperties(lt.prototype,{cancel:{enumerable:!0},read:{enumerable:!0},releaseLock:{enumerable:!0},closed:{enumerable:!0}}),s(lt.prototype.cancel,"cancel"),s(lt.prototype.read,"read"),s(lt.prototype.releaseLock,"releaseLock"),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(lt.prototype,Symbol.toStringTag,{value:"ReadableStreamBYOBReader",configurable:!0});const Rt="function"==typeof AbortController;class Tt{constructor(e={},t={}){void 0===e?e=null:N(e,"First parameter");const r=yt(t,"Second parameter"),n=function(e,t){F(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:vt(r,e,t+" has member 'abort' that"),close:void 0===n?void 0:_t(n,e,t+" has member 'close' that"),start:void 0===o?void 0:gt(o,e,t+" has member 'start' that"),write:void 0===a?void 0:wt(a,e,t+" has member 'write' that"),type:i}}(e,"First parameter");if(Ot(this),void 0!==n.type)throw new RangeError("Invalid type is specified");const o=bt(r);!function(e,t,r,n){const o=Object.create(Gt.prototype);let i,a,s,u;i=void 0!==t.start?()=>t.start(o):()=>{},a=void 0!==t.write?e=>t.write(e,o):()=>p(void 0),s=void 0!==t.close?()=>t.close():()=>p(void 0),u=void 0!==t.abort?e=>t.abort(e):()=>p(void 0),Ht(e,o,i,a,s,u,r,n)}(this,n,pt(r,1),o)}get locked(){if(!qt(this))throw Zt("locked");return jt(this)}abort(e){return qt(this)?jt(this)?b(new TypeError("Cannot abort a stream that already has a writer")):kt(this,e):b(Zt("abort"))}close(){return qt(this)?jt(this)?b(new TypeError("Cannot close a stream that already has a writer")):It(this)?b(new TypeError("Cannot close an already-closing stream")):Et(this):b(Zt("close"))}getWriter(){if(!qt(this))throw Zt("getWriter");return Pt(this)}}function Pt(e){return new Bt(e)}function Ot(e){e._state="writable",e._storedError=void 0,e._writer=void 0,e._writableStreamController=void 0,e._writeRequests=new P,e._inFlightWriteRequest=void 0,e._closeRequest=void 0,e._inFlightCloseRequest=void 0,e._pendingAbortRequest=void 0,e._backpressure=!1}function qt(e){return!!i(e)&&!!Object.prototype.hasOwnProperty.call(e,"_writableStreamController")&&e instanceof Tt}function jt(e){return void 0!==e._writer}function kt(e,t){var r;if("closed"===e._state||"errored"===e._state)return p(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 p(void 0);if(void 0!==e._pendingAbortRequest)return e._pendingAbortRequest._promise;let o=!1;"erroring"===n&&(o=!0,t=void 0);const i=h((r,n)=>{e._pendingAbortRequest={_promise:void 0,_resolve:r,_reject:n,_reason:t,_wasAlreadyErroring:o}});return e._pendingAbortRequest._promise=i,o||xt(e,t),i}function Et(e){const t=e._state;if("closed"===t||"errored"===t)return b(new TypeError(`The stream (in ${t} state) is not in the writable state and cannot be closed`));const r=h((t,r)=>{const n={_resolve:t,_reject:r};e._closeRequest=n}),n=e._writer;var o;return void 0!==n&&e._backpressure&&"writable"===t&&fr(n),Pe(o=e._writableStreamController,Nt,0),Qt(o),r}function Ct(e,t){"writable"!==e._state?At(e):xt(e,t)}function xt(e,t){const r=e._writableStreamController;e._state="erroring",e._storedError=t;const n=e._writer;void 0!==n&&zt(n,t),!function(e){return void 0!==e._inFlightWriteRequest||void 0!==e._inFlightCloseRequest}(e)&&r._started&&At(e)}function At(e){e._state="errored",e._writableStreamController[q]();const t=e._storedError;if(e._writeRequests.forEach(e=>{e._reject(t)}),e._writeRequests=new P,void 0===e._pendingAbortRequest)return void Wt(e);const r=e._pendingAbortRequest;if(e._pendingAbortRequest=void 0,r._wasAlreadyErroring)return r._reject(t),void Wt(e);m(e._writableStreamController[O](r._reason),()=>(r._resolve(),Wt(e),null),t=>(r._reject(t),Wt(e),null))}function It(e){return void 0!==e._closeRequest||void 0!==e._inFlightCloseRequest}function Wt(e){void 0!==e._closeRequest&&(e._closeRequest._reject(e._storedError),e._closeRequest=void 0);const t=e._writer;void 0!==t&&ir(t,e._storedError)}function Ut(e,t){const r=e._writer;void 0!==r&&t!==e._backpressure&&(t?function(e){sr(e)}(r):fr(r)),e._backpressure=t}Object.defineProperties(Tt.prototype,{abort:{enumerable:!0},close:{enumerable:!0},getWriter:{enumerable:!0},locked:{enumerable:!0}}),s(Tt.prototype.abort,"abort"),s(Tt.prototype.close,"close"),s(Tt.prototype.getWriter,"getWriter"),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(Tt.prototype,Symbol.toStringTag,{value:"WritableStream",configurable:!0});class Bt{constructor(e){if(G(e,1,"WritableStreamDefaultWriter"),St(e,"First parameter"),jt(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)!It(e)&&e._backpressure?sr(this):lr(this),nr(this);else if("erroring"===t)ur(this,e._storedError),nr(this);else if("closed"===t)lr(this),nr(this),ar(this);else{const t=e._storedError;ur(this,t),or(this,t)}}get closed(){return Mt(this)?this._closedPromise:b(tr("closed"))}get desiredSize(){if(!Mt(this))throw tr("desiredSize");if(void 0===this._ownerWritableStream)throw rr("desiredSize");return function(e){const t=e._ownerWritableStream,r=t._state;return"errored"===r||"erroring"===r?null:"closed"===r?0:Jt(t._writableStreamController)}(this)}get ready(){return Mt(this)?this._readyPromise:b(tr("ready"))}abort(e){return Mt(this)?void 0===this._ownerWritableStream?b(rr("abort")):function(e,t){return kt(e._ownerWritableStream,t)}(this,e):b(tr("abort"))}close(){if(!Mt(this))return b(tr("close"));const e=this._ownerWritableStream;return void 0===e?b(rr("close")):It(e)?b(new TypeError("Cannot close an already-closing stream")):Lt(this)}releaseLock(){if(!Mt(this))throw tr("releaseLock");void 0!==this._ownerWritableStream&&Ft(this)}write(e){return Mt(this)?void 0===this._ownerWritableStream?b(rr("write to")):Dt(this,e):b(tr("write"))}}function Mt(e){return!!i(e)&&!!Object.prototype.hasOwnProperty.call(e,"_ownerWritableStream")&&e instanceof Bt}function Lt(e){return Et(e._ownerWritableStream)}function zt(e,t){"pending"===e._readyPromiseState?cr(e,t):function(e,t){ur(e,t)}(e,t)}function Ft(e){const t=e._ownerWritableStream,r=new TypeError("Writer was released and can no longer be used to monitor the stream's closedness");zt(e,r),function(e,t){"pending"===e._closedPromiseState?ir(e,t):function(e,t){or(e,t)}(e,t)}(e,r),t._writer=void 0,e._ownerWritableStream=void 0}function Dt(e,t){const r=e._ownerWritableStream,n=r._writableStreamController,o=function(e,t){try{return e._strategySizeAlgorithm(t)}catch(t){return Vt(e,t),1}}(n,t);if(r!==e._ownerWritableStream)return b(rr("write to"));const i=r._state;if("errored"===i)return b(r._storedError);if(It(r)||"closed"===i)return b(new TypeError("The stream is closing or closed and cannot be written to"));if("erroring"===i)return b(r._storedError);const a=function(e){return h((t,r)=>{const n={_resolve:t,_reject:r};e._writeRequests.push(n)})}(r);return function(e,t,r){try{Pe(e,t,r)}catch(t){return void Vt(e,t)}const n=e._controlledWritableStream;It(n)||"writable"!==n._state||Ut(n,Xt(e)),Qt(e)}(n,t,o),a}Object.defineProperties(Bt.prototype,{abort:{enumerable:!0},close:{enumerable:!0},releaseLock:{enumerable:!0},write:{enumerable:!0},closed:{enumerable:!0},desiredSize:{enumerable:!0},ready:{enumerable:!0}}),s(Bt.prototype.abort,"abort"),s(Bt.prototype.close,"close"),s(Bt.prototype.releaseLock,"releaseLock"),s(Bt.prototype.write,"write"),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(Bt.prototype,Symbol.toStringTag,{value:"WritableStreamDefaultWriter",configurable:!0});const Nt={};class Gt{constructor(){throw new TypeError("Illegal constructor")}get abortReason(){if(!$t(this))throw er("abortReason");return this._abortReason}get signal(){if(!$t(this))throw er("signal");if(void 0===this._abortController)throw new TypeError("WritableStreamDefaultController.prototype.signal is not supported");return this._abortController.signal}error(e){if(!$t(this))throw er("error");"writable"===this._controlledWritableStream._state&&Kt(this,e)}[O](e){const t=this._abortAlgorithm(e);return Yt(this),t}[q](){Oe(this)}}function $t(e){return!!i(e)&&!!Object.prototype.hasOwnProperty.call(e,"_controlledWritableStream")&&e instanceof Gt}function Ht(e,t,r,n,o,i,a,s){t._controlledWritableStream=e,e._writableStreamController=t,t._queue=void 0,t._queueTotalSize=void 0,Oe(t),t._abortReason=void 0,t._abortController=function(){if(Rt)return new AbortController}(),t._started=!1,t._strategySizeAlgorithm=s,t._strategyHWM=a,t._writeAlgorithm=n,t._closeAlgorithm=o,t._abortAlgorithm=i;const u=Xt(t);Ut(e,u),m(p(r()),()=>(t._started=!0,Qt(t),null),r=>(t._started=!0,Ct(e,r),null))}function Yt(e){e._writeAlgorithm=void 0,e._closeAlgorithm=void 0,e._abortAlgorithm=void 0,e._strategySizeAlgorithm=void 0}function Jt(e){return e._strategyHWM-e._queueTotalSize}function Qt(e){const t=e._controlledWritableStream;if(!e._started)return;if(void 0!==t._inFlightWriteRequest)return;if("erroring"===t._state)return void At(t);if(0===e._queue.length)return;const r=e._queue.peek().value;r===Nt?function(e){const t=e._controlledWritableStream;(function(e){e._inFlightCloseRequest=e._closeRequest,e._closeRequest=void 0})(t),Te(e);const r=e._closeAlgorithm();Yt(e),m(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&&ar(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),Ct(e,t)}(t,e),null))}(e):function(e,t){const r=e._controlledWritableStream;!function(e){e._inFlightWriteRequest=e._writeRequests.shift()}(r);m(e._writeAlgorithm(t),()=>{!function(e){e._inFlightWriteRequest._resolve(void 0),e._inFlightWriteRequest=void 0}(r);const t=r._state;if(Te(e),!It(r)&&"writable"===t){const t=Xt(e);Ut(r,t)}return Qt(e),null},t=>("writable"===r._state&&Yt(e),function(e,t){e._inFlightWriteRequest._reject(t),e._inFlightWriteRequest=void 0,Ct(e,t)}(r,t),null))}(e,r)}function Vt(e,t){"writable"===e._controlledWritableStream._state&&Kt(e,t)}function Xt(e){return Jt(e)<=0}function Kt(e,t){const r=e._controlledWritableStream;Yt(e),xt(r,t)}function Zt(e){return new TypeError(`WritableStream.prototype.${e} can only be used on a WritableStream`)}function er(e){return new TypeError(`WritableStreamDefaultController.prototype.${e} can only be used on a WritableStreamDefaultController`)}function tr(e){return new TypeError(`WritableStreamDefaultWriter.prototype.${e} can only be used on a WritableStreamDefaultWriter`)}function rr(e){return new TypeError("Cannot "+e+" a stream using a released writer")}function nr(e){e._closedPromise=h((t,r)=>{e._closedPromise_resolve=t,e._closedPromise_reject=r,e._closedPromiseState="pending"})}function or(e,t){nr(e),ir(e,t)}function ir(e,t){void 0!==e._closedPromise_reject&&(w(e._closedPromise),e._closedPromise_reject(t),e._closedPromise_resolve=void 0,e._closedPromise_reject=void 0,e._closedPromiseState="rejected")}function ar(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 sr(e){e._readyPromise=h((t,r)=>{e._readyPromise_resolve=t,e._readyPromise_reject=r}),e._readyPromiseState="pending"}function ur(e,t){sr(e),cr(e,t)}function lr(e){sr(e),fr(e)}function cr(e,t){void 0!==e._readyPromise_reject&&(w(e._readyPromise),e._readyPromise_reject(t),e._readyPromise_resolve=void 0,e._readyPromise_reject=void 0,e._readyPromiseState="rejected")}function fr(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(Gt.prototype,{abortReason:{enumerable:!0},signal:{enumerable:!0},error:{enumerable:!0}}),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(Gt.prototype,Symbol.toStringTag,{value:"WritableStreamDefaultController",configurable:!0});const dr="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof global?global:void 0,hr=function(){const e=null==dr?void 0:dr.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 s(e,"DOMException"),e.prototype=Object.create(Error.prototype),Object.defineProperty(e.prototype,"constructor",{value:e,writable:!0,configurable:!0}),e}();function pr(e,t,r,n,i,a){const s=V(e),u=Pt(t);e._disturbed=!0;let l=!1,c=p(void 0);return h((f,d)=>{let g;if(void 0!==a){if(g=()=>{const r=void 0!==a.reason?a.reason:new hr("Aborted","AbortError"),o=[];n||o.push(()=>"writable"===t._state?kt(t,r):p(void 0)),i||o.push(()=>"readable"===e._state?Lr(e,r):p(void 0)),q(()=>Promise.all(o.map(e=>e())),!0,r)},a.aborted)return void g();a.addEventListener("abort",g)}var S,R,T;if(O(e,s._closedPromise,e=>(n?j(!0,e):q(()=>kt(t,e),!0,e),null)),O(t,u._closedPromise,t=>(i?j(!0,t):q(()=>Lr(e,t),!0,t),null)),S=e,R=s._closedPromise,T=()=>(r?j():q(()=>function(e){const t=e._ownerWritableStream,r=t._state;return It(t)||"closed"===r?p(void 0):"errored"===r?b(t._storedError):Lt(e)}(u)),null),"closed"===S._state?T():v(R,T),It(t)||"closed"===t._state){const t=new TypeError("the destination writable stream closed before all data could be piped to it");i?j(!0,t):q(()=>Lr(e,t),!0,t)}function P(){const e=c;return y(c,()=>e!==c?P():void 0)}function O(e,t,r){"errored"===e._state?r(e._storedError):_(t,r)}function q(e,r,n){function o(){return m(e(),()=>k(r,n),e=>k(!0,e)),null}l||(l=!0,"writable"!==t._state||It(t)?o():v(P(),o))}function j(e,r){l||(l=!0,"writable"!==t._state||It(t)?k(e,r):v(P(),()=>k(e,r)))}function k(e,t){return Ft(u),A(s),void 0!==a&&a.removeEventListener("abort",g),e?d(t):f(void 0),null}w(h((e,t)=>{!function r(n){n?e():y(l?p(!0):y(u._readyPromise,()=>h((e,t)=>{ne(s,{_chunkSteps:t=>{c=y(Dt(u,t),void 0,o),e(!1)},_closeSteps:()=>e(!0),_errorSteps:t})})),r,t)}(!1)}))})}class br{constructor(){throw new TypeError("Illegal constructor")}get desiredSize(){if(!yr(this))throw Or("desiredSize");return Rr(this)}close(){if(!yr(this))throw Or("close");if(!Tr(this))throw new TypeError("The stream is not in a state that permits close");gr(this)}enqueue(e){if(!yr(this))throw Or("enqueue");if(!Tr(this))throw new TypeError("The stream is not in a state that permits enqueue");return wr(this,e)}error(e){if(!yr(this))throw Or("error");Sr(this,e)}[j](e){Oe(this);const t=this._cancelAlgorithm(e);return _r(this),t}[k](e){const t=this._controlledReadableStream;if(this._queue.length>0){const r=Te(this);this._closeRequested&&0===this._queue.length?(_r(this),zr(t)):mr(this),e._chunkSteps(r)}else X(t,e),mr(this)}[E](){}}function yr(e){return!!i(e)&&!!Object.prototype.hasOwnProperty.call(e,"_controlledReadableStream")&&e instanceof br}function mr(e){vr(e)&&(e._pulling?e._pullAgain=!0:(e._pulling=!0,m(e._pullAlgorithm(),()=>(e._pulling=!1,e._pullAgain&&(e._pullAgain=!1,mr(e)),null),t=>(Sr(e,t),null))))}function vr(e){const t=e._controlledReadableStream;return!!Tr(e)&&(!!e._started&&(!!(Mr(t)&&Z(t)>0)||Rr(e)>0))}function _r(e){e._pullAlgorithm=void 0,e._cancelAlgorithm=void 0,e._strategySizeAlgorithm=void 0}function gr(e){if(!Tr(e))return;const t=e._controlledReadableStream;e._closeRequested=!0,0===e._queue.length&&(_r(e),zr(t))}function wr(e,t){if(!Tr(e))return;const r=e._controlledReadableStream;if(Mr(r)&&Z(r)>0)K(r,t,!1);else{let r;try{r=e._strategySizeAlgorithm(t)}catch(t){throw Sr(e,t),t}try{Pe(e,t,r)}catch(t){throw Sr(e,t),t}}mr(e)}function Sr(e,t){const r=e._controlledReadableStream;"readable"===r._state&&(Oe(e),_r(e),Fr(r,t))}function Rr(e){const t=e._controlledReadableStream._state;return"errored"===t?null:"closed"===t?0:e._strategyHWM-e._queueTotalSize}function Tr(e){const t=e._controlledReadableStream._state;return!e._closeRequested&&"readable"===t}function Pr(e,t,r,n,o,i,a){t._controlledReadableStream=e,t._queue=void 0,t._queueTotalSize=void 0,Oe(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,m(p(r()),()=>(t._started=!0,mr(t),null),e=>(Sr(t,e),null))}function Or(e){return new TypeError(`ReadableStreamDefaultController.prototype.${e} can only be used on a ReadableStreamDefaultController`)}function qr(e){return i(t=e)&&void 0!==t.getReader?function(e){let t;return t=Ir(o,(function(){let r;try{r=e.read()}catch(r){return b(r)}return g(r,e=>{if(!i(e))throw new TypeError("The promise returned by the reader.read() method must fulfill with an object");if(e.done)gr(t._readableStreamController);else{const r=e.value;wr(t._readableStreamController,r)}})}),(function(t){try{return p(e.cancel(t))}catch(t){return b(t)}}),0),t}(e.getReader()):function(e){let t;const r=function e(t,r="sync",n){if(void 0===n)if("async"===r){if(void 0===(n=pe(t,ye)))return function(e){const t={next(){let t;try{t=me(e)}catch(e){return b(e)}return be(t)},return(t){let r;try{const n=pe(e.iterator,"return");if(void 0===n)return p({done:!0,value:t});r=R(n,e.iterator,[t])}catch(e){return b(e)}return i(r)?be(r):b(new TypeError("The iterator.return() method must return an object"))}};return{iterator:t,nextMethod:t.next,done:!1}}(e(t,"sync",pe(t,Symbol.iterator)))}else n=pe(t,Symbol.iterator);if(void 0===n)throw new TypeError("The object is not iterable");const o=R(n,t,[]);if(!i(o))throw new TypeError("The iterator method must return an object");return{iterator:o,nextMethod:o.next,done:!1}}(e,"async");return t=Ir(o,(function(){let e;try{e=me(r)}catch(e){return b(e)}return g(p(e),e=>{if(!i(e))throw new TypeError("The promise returned by the iterator.next() method must fulfill with an object");if(e.done)gr(t._readableStreamController);else{const r=e.value;wr(t._readableStreamController,r)}})}),(function(e){const t=r.iterator;let n;try{n=pe(t,"return")}catch(e){return b(e)}return void 0===n?p(void 0):g(T(n,t,[e]),e=>{if(!i(e))throw new TypeError("The promise returned by the iterator.return() method must fulfill with an object")})}),0),t}(e);var t}function jr(e,t,r){return D(e,r),r=>T(e,t,[r])}function kr(e,t,r){return D(e,r),r=>T(e,t,[r])}function Er(e,t,r){return D(e,r),r=>R(e,t,[r])}function Cr(e,t){if("bytes"!=(e=""+e))throw new TypeError(`${t} '${e}' is not a valid enumeration value for ReadableStreamType`);return e}function xr(e,t){F(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(br.prototype,{close:{enumerable:!0},enqueue:{enumerable:!0},error:{enumerable:!0},desiredSize:{enumerable:!0}}),s(br.prototype.close,"close"),s(br.prototype.enqueue,"enqueue"),s(br.prototype.error,"error"),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(br.prototype,Symbol.toStringTag,{value:"ReadableStreamDefaultController",configurable:!0});class Ar{constructor(e={},t={}){void 0===e?e=null:N(e,"First parameter");const r=yt(t,"Second parameter"),n=function(e,t){F(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:J(n,t+" has member 'autoAllocateChunkSize' that"),cancel:void 0===o?void 0:jr(o,r,t+" has member 'cancel' that"),pull:void 0===i?void 0:kr(i,r,t+" has member 'pull' that"),start:void 0===a?void 0:Er(a,r,t+" has member 'start' that"),type:void 0===s?void 0:Cr(s,t+" has member 'type' that")}}(e,"First parameter");if(Ur(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(ke.prototype);let o,i,a;o=void 0!==t.start?()=>t.start(n):()=>{},i=void 0!==t.pull?()=>t.pull(n):()=>p(void 0),a=void 0!==t.cancel?e=>t.cancel(e):()=>p(void 0);const s=t.autoAllocateChunkSize;if(0===s)throw new TypeError("autoAllocateChunkSize must be greater than 0");tt(e,n,o,i,a,r,s)}(this,n,pt(r,0))}else{const e=bt(r);!function(e,t,r,n){const o=Object.create(br.prototype);let i,a,s;i=void 0!==t.start?()=>t.start(o):()=>{},a=void 0!==t.pull?()=>t.pull(o):()=>p(void 0),s=void 0!==t.cancel?e=>t.cancel(e):()=>p(void 0),Pr(e,o,i,a,s,r,n)}(this,n,pt(r,1),e)}}get locked(){if(!Br(this))throw Dr("locked");return Mr(this)}cancel(e){return Br(this)?Mr(this)?b(new TypeError("Cannot cancel a stream that already has a reader")):Lr(this,e):b(Dr("cancel"))}getReader(e){if(!Br(this))throw Dr("getReader");return void 0===function(e,t){F(e,t);const r=null==e?void 0:e.mode;return{mode:void 0===r?void 0:ot(r,t+" has member 'mode' that")}}(e,"First parameter").mode?V(this):it(this)}pipeThrough(e,t={}){if(!Br(this))throw Dr("pipeThrough");G(e,1,"pipeThrough");const r=function(e,t){F(e,t);const r=null==e?void 0:e.readable;$(r,"readable","ReadableWritablePair"),Q(r,t+" has member 'readable' that");const n=null==e?void 0:e.writable;return $(n,"writable","ReadableWritablePair"),St(n,t+" has member 'writable' that"),{readable:r,writable:n}}(e,"First parameter"),n=xr(t,"Second parameter");if(Mr(this))throw new TypeError("ReadableStream.prototype.pipeThrough cannot be used on a locked ReadableStream");if(jt(r.writable))throw new TypeError("ReadableStream.prototype.pipeThrough cannot be used on a locked WritableStream");return w(pr(this,r.writable,n.preventClose,n.preventAbort,n.preventCancel,n.signal)),r.readable}pipeTo(e,t={}){if(!Br(this))return b(Dr("pipeTo"));if(void 0===e)return b("Parameter 1 is required in 'pipeTo'.");if(!qt(e))return b(new TypeError("ReadableStream.prototype.pipeTo's first argument must be a WritableStream"));let r;try{r=xr(t,"Second parameter")}catch(e){return b(e)}return Mr(this)?b(new TypeError("ReadableStream.prototype.pipeTo cannot be used on a locked ReadableStream")):jt(e)?b(new TypeError("ReadableStream.prototype.pipeTo cannot be used on a locked WritableStream")):pr(this,e,r.preventClose,r.preventAbort,r.preventCancel,r.signal)}tee(){if(!Br(this))throw Dr("tee");return le(function(e,t){return Ee(e._readableStreamController)?function(e){let t,r,n,o,i,a=V(e),s=!1,u=!1,l=!1,c=!1,f=!1;const d=h(e=>{i=e});function b(e){_(e._closedPromise,t=>(e!==a||(Qe(n._readableStreamController,t),Qe(o._readableStreamController,t),c&&f||i(void 0)),null))}function y(){ct(a)&&(A(a),a=V(e),b(a)),ne(a,{_chunkSteps:t=>{S(()=>{u=!1,l=!1;const r=t;let a=t;if(!c&&!f)try{a=Re(t)}catch(t){return Qe(n._readableStreamController,t),Qe(o._readableStreamController,t),void i(Lr(e,t))}c||Je(n._readableStreamController,r),f||Je(o._readableStreamController,a),s=!1,u?v():l&&g()})},_closeSteps:()=>{s=!1,c||Ye(n._readableStreamController),f||Ye(o._readableStreamController),n._readableStreamController._pendingPullIntos.length>0&&Ze(n._readableStreamController,0),o._readableStreamController._pendingPullIntos.length>0&&Ze(o._readableStreamController,0),c&&f||i(void 0)},_errorSteps:()=>{s=!1}})}function m(t,r){re(a)&&(A(a),a=it(e),b(a));const d=r?o:n,h=r?n:o;ft(a,t,1,{_chunkSteps:t=>{S(()=>{u=!1,l=!1;const n=r?f:c;if(r?c:f)n||et(d._readableStreamController,t);else{let r;try{r=Re(t)}catch(t){return Qe(d._readableStreamController,t),Qe(h._readableStreamController,t),void i(Lr(e,t))}n||et(d._readableStreamController,t),Je(h._readableStreamController,r)}s=!1,u?v():l&&g()})},_closeSteps:e=>{s=!1;const t=r?f:c,n=r?c:f;t||Ye(d._readableStreamController),n||Ye(h._readableStreamController),void 0!==e&&(t||et(d._readableStreamController,e),!n&&h._readableStreamController._pendingPullIntos.length>0&&Ze(h._readableStreamController,0)),t&&n||i(void 0)},_errorSteps:()=>{s=!1}})}function v(){if(s)return u=!0,p(void 0);s=!0;const e=Xe(n._readableStreamController);return null===e?y():m(e._view,!1),p(void 0)}function g(){if(s)return l=!0,p(void 0);s=!0;const e=Xe(o._readableStreamController);return null===e?y():m(e._view,!0),p(void 0)}function w(){}return n=Wr(w,v,(function(n){if(c=!0,t=n,f){const n=le([t,r]),o=Lr(e,n);i(o)}return d})),o=Wr(w,g,(function(n){if(f=!0,r=n,c){const n=le([t,r]),o=Lr(e,n);i(o)}return d})),b(a),[n,o]}(e):function(e,t){const r=V(e);let n,o,i,a,s,u=!1,l=!1,c=!1,f=!1;const d=h(e=>{s=e});function b(){return u?(l=!0,p(void 0)):(u=!0,ne(r,{_chunkSteps:e=>{S(()=>{l=!1;const t=e,r=e;c||wr(i._readableStreamController,t),f||wr(a._readableStreamController,r),u=!1,l&&b()})},_closeSteps:()=>{u=!1,c||gr(i._readableStreamController),f||gr(a._readableStreamController),c&&f||s(void 0)},_errorSteps:()=>{u=!1}}),p(void 0))}function y(){}return i=Ir(y,b,(function(t){if(c=!0,n=t,f){const t=le([n,o]),r=Lr(e,t);s(r)}return d})),a=Ir(y,b,(function(t){if(f=!0,o=t,c){const t=le([n,o]),r=Lr(e,t);s(r)}return d})),_(r._closedPromise,e=>(Sr(i._readableStreamController,e),Sr(a._readableStreamController,e),c&&f||s(void 0),null)),[i,a]}(e)}(this))}values(e){if(!Br(this))throw Dr("values");return function(e,t){const r=V(e),n=new ve(r,t),o=Object.create(_e);return o._asyncIteratorImpl=n,o}(this,function(e,t){F(e,"First parameter");const r=null==e?void 0:e.preventCancel;return{preventCancel:Boolean(r)}}(e).preventCancel)}[ye](e){return this.values(e)}static from(e){return qr(e)}}function Ir(e,t,r,n=1,o=(()=>1)){const i=Object.create(Ar.prototype);return Ur(i),Pr(i,Object.create(br.prototype),e,t,r,n,o),i}function Wr(e,t,r){const n=Object.create(Ar.prototype);return Ur(n),tt(n,Object.create(ke.prototype),e,t,r,0,void 0),n}function Ur(e){e._state="readable",e._reader=void 0,e._storedError=void 0,e._disturbed=!1}function Br(e){return!!i(e)&&!!Object.prototype.hasOwnProperty.call(e,"_readableStreamController")&&e instanceof Ar}function Mr(e){return void 0!==e._reader}function Lr(e,t){if(e._disturbed=!0,"closed"===e._state)return p(void 0);if("errored"===e._state)return b(e._storedError);zr(e);const r=e._reader;if(void 0!==r&&ct(r)){const e=r._readIntoRequests;r._readIntoRequests=new P,e.forEach(e=>{e._closeSteps(void 0)})}return g(e._readableStreamController[j](t),o)}function zr(e){e._state="closed";const t=e._reader;if(void 0!==t&&(M(t),re(t))){const e=t._readRequests;t._readRequests=new P,e.forEach(e=>{e._closeSteps()})}}function Fr(e,t){e._state="errored",e._storedError=t;const r=e._reader;void 0!==r&&(B(r,t),re(r)?oe(r,t):dt(r,t))}function Dr(e){return new TypeError(`ReadableStream.prototype.${e} can only be used on a ReadableStream`)}function Nr(e,t){F(e,t);const r=null==e?void 0:e.highWaterMark;return $(r,"highWaterMark","QueuingStrategyInit"),{highWaterMark:H(r)}}Object.defineProperties(Ar,{from:{enumerable:!0}}),Object.defineProperties(Ar.prototype,{cancel:{enumerable:!0},getReader:{enumerable:!0},pipeThrough:{enumerable:!0},pipeTo:{enumerable:!0},tee:{enumerable:!0},values:{enumerable:!0},locked:{enumerable:!0}}),s(Ar.from,"from"),s(Ar.prototype.cancel,"cancel"),s(Ar.prototype.getReader,"getReader"),s(Ar.prototype.pipeThrough,"pipeThrough"),s(Ar.prototype.pipeTo,"pipeTo"),s(Ar.prototype.tee,"tee"),s(Ar.prototype.values,"values"),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(Ar.prototype,Symbol.toStringTag,{value:"ReadableStream",configurable:!0}),Object.defineProperty(Ar.prototype,ye,{value:Ar.prototype.values,writable:!0,configurable:!0});const Gr=e=>e.byteLength;s(Gr,"size");class $r{constructor(e){G(e,1,"ByteLengthQueuingStrategy"),e=Nr(e,"First parameter"),this._byteLengthQueuingStrategyHighWaterMark=e.highWaterMark}get highWaterMark(){if(!Yr(this))throw Hr("highWaterMark");return this._byteLengthQueuingStrategyHighWaterMark}get size(){if(!Yr(this))throw Hr("size");return Gr}}function Hr(e){return new TypeError(`ByteLengthQueuingStrategy.prototype.${e} can only be used on a ByteLengthQueuingStrategy`)}function Yr(e){return!!i(e)&&!!Object.prototype.hasOwnProperty.call(e,"_byteLengthQueuingStrategyHighWaterMark")&&e instanceof $r}Object.defineProperties($r.prototype,{highWaterMark:{enumerable:!0},size:{enumerable:!0}}),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty($r.prototype,Symbol.toStringTag,{value:"ByteLengthQueuingStrategy",configurable:!0});const Jr=()=>1;s(Jr,"size");class Qr{constructor(e){G(e,1,"CountQueuingStrategy"),e=Nr(e,"First parameter"),this._countQueuingStrategyHighWaterMark=e.highWaterMark}get highWaterMark(){if(!Xr(this))throw Vr("highWaterMark");return this._countQueuingStrategyHighWaterMark}get size(){if(!Xr(this))throw Vr("size");return Jr}}function Vr(e){return new TypeError(`CountQueuingStrategy.prototype.${e} can only be used on a CountQueuingStrategy`)}function Xr(e){return!!i(e)&&!!Object.prototype.hasOwnProperty.call(e,"_countQueuingStrategyHighWaterMark")&&e instanceof Qr}function Kr(e,t,r){return D(e,r),r=>T(e,t,[r])}function Zr(e,t,r){return D(e,r),r=>R(e,t,[r])}function en(e,t,r){return D(e,r),(r,n)=>T(e,t,[r,n])}function tn(e,t,r){return D(e,r),r=>T(e,t,[r])}Object.defineProperties(Qr.prototype,{highWaterMark:{enumerable:!0},size:{enumerable:!0}}),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(Qr.prototype,Symbol.toStringTag,{value:"CountQueuingStrategy",configurable:!0});class rn{constructor(e={},t={},r={}){void 0===e&&(e=null);const n=yt(t,"Second parameter"),o=yt(r,"Third parameter"),i=function(e,t){F(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:tn(r,e,t+" has member 'cancel' that"),flush:void 0===n?void 0:Kr(n,e,t+" has member 'flush' that"),readableType:o,start:void 0===i?void 0:Zr(i,e,t+" has member 'start' that"),transform:void 0===a?void 0:en(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=pt(o,0),s=bt(o),u=pt(n,1),l=bt(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(Tt.prototype);return Ot(a),Ht(a,Object.create(Gt.prototype),e,t,r,n,o,i),a}(a,(function(t){return function(e,t){const r=e._transformStreamController;return e._backpressure?g(e._backpressureChangePromise,()=>{const n=e._writable;if("erroring"===n._state)throw n._storedError;return hn(r,t)}):hn(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=h((e,r)=>{t._finishPromise_resolve=e,t._finishPromise_reject=r});const n=t._flushAlgorithm();return fn(t),m(n,()=>("errored"===r._state?yn(t,r._storedError):(gr(r._readableStreamController),bn(t)),null),e=>(Sr(r._readableStreamController,e),yn(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=h((e,t)=>{r._finishPromise_resolve=e,r._finishPromise_reject=t});const o=r._cancelAlgorithm(t);return fn(r),m(o,()=>("errored"===n._state?yn(r,n._storedError):(Sr(n._readableStreamController,t),bn(r)),null),e=>(Sr(n._readableStreamController,e),yn(r,e),null)),r._finishPromise}(e,t)}),r,n),e._readable=Ir(a,(function(){return function(e){return un(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=h((e,t)=>{r._finishPromise_resolve=e,r._finishPromise_reject=t});const o=r._cancelAlgorithm(t);return fn(r),m(o,()=>("errored"===n._state?yn(r,n._storedError):(Vt(n._writableStreamController,t),sn(e),bn(r)),null),t=>(Vt(n._writableStreamController,t),sn(e),yn(r,t),null)),r._finishPromise}(e,t)}),o,i),e._backpressure=void 0,e._backpressureChangePromise=void 0,e._backpressureChangePromise_resolve=void 0,un(e,!0),e._transformStreamController=void 0}(this,h(e=>{c=e}),u,l,a,s),function(e,t){const r=Object.create(ln.prototype);let n,o,i;n=void 0!==t.transform?e=>t.transform(e,r):e=>{try{return dn(r,e),p(void 0)}catch(e){return b(e)}},o=void 0!==t.flush?()=>t.flush(r):()=>p(void 0),i=void 0!==t.cancel?e=>t.cancel(e):()=>p(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(!nn(this))throw mn("readable");return this._readable}get writable(){if(!nn(this))throw mn("writable");return this._writable}}function nn(e){return!!i(e)&&!!Object.prototype.hasOwnProperty.call(e,"_transformStreamController")&&e instanceof rn}function on(e,t){Sr(e._readable._readableStreamController,t),an(e,t)}function an(e,t){fn(e._transformStreamController),Vt(e._writable._writableStreamController,t),sn(e)}function sn(e){e._backpressure&&un(e,!1)}function un(e,t){void 0!==e._backpressureChangePromise&&e._backpressureChangePromise_resolve(),e._backpressureChangePromise=h(t=>{e._backpressureChangePromise_resolve=t}),e._backpressure=t}Object.defineProperties(rn.prototype,{readable:{enumerable:!0},writable:{enumerable:!0}}),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(rn.prototype,Symbol.toStringTag,{value:"TransformStream",configurable:!0});class ln{constructor(){throw new TypeError("Illegal constructor")}get desiredSize(){if(!cn(this))throw pn("desiredSize");return Rr(this._controlledTransformStream._readable._readableStreamController)}enqueue(e){if(!cn(this))throw pn("enqueue");dn(this,e)}error(e){if(!cn(this))throw pn("error");var t;t=e,on(this._controlledTransformStream,t)}terminate(){if(!cn(this))throw pn("terminate");!function(e){const t=e._controlledTransformStream;gr(t._readable._readableStreamController);an(t,new TypeError("TransformStream terminated"))}(this)}}function cn(e){return!!i(e)&&!!Object.prototype.hasOwnProperty.call(e,"_controlledTransformStream")&&e instanceof ln}function fn(e){e._transformAlgorithm=void 0,e._flushAlgorithm=void 0,e._cancelAlgorithm=void 0}function dn(e,t){const r=e._controlledTransformStream,n=r._readable._readableStreamController;if(!Tr(n))throw new TypeError("Readable side is not in a state that permits enqueue");try{wr(n,t)}catch(e){throw an(r,e),r._readable._storedError}(function(e){return!vr(e)})(n)!==r._backpressure&&un(r,!0)}function hn(e,t){return g(e._transformAlgorithm(t),void 0,t=>{throw on(e._controlledTransformStream,t),t})}function pn(e){return new TypeError(`TransformStreamDefaultController.prototype.${e} can only be used on a TransformStreamDefaultController`)}function bn(e){void 0!==e._finishPromise_resolve&&(e._finishPromise_resolve(),e._finishPromise_resolve=void 0,e._finishPromise_reject=void 0)}function yn(e,t){void 0!==e._finishPromise_reject&&(w(e._finishPromise),e._finishPromise_reject(t),e._finishPromise_resolve=void 0,e._finishPromise_reject=void 0)}function mn(e){return new TypeError(`TransformStream.prototype.${e} can only be used on a TransformStream`)}Object.defineProperties(ln.prototype,{enqueue:{enumerable:!0},error:{enumerable:!0},terminate:{enumerable:!0},desiredSize:{enumerable:!0}}),s(ln.prototype.enqueue,"enqueue"),s(ln.prototype.error,"error"),s(ln.prototype.terminate,"terminate"),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(ln.prototype,Symbol.toStringTag,{value:"TransformStreamDefaultController",configurable:!0});var vn=function(e,t){return(vn=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)};function _n(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}vn(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}function gn(e){if(!e)throw new TypeError("Assertion failed")}function wn(){}function Sn(e){return"object"==typeof e&&null!==e||"function"==typeof e}function Rn(e){if("function"!=typeof e)return!1;var t=!1;try{new e({start:function(){t=!0}})}catch(e){}return t}function Tn(e){return!!Sn(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 gn(Tn(e)),gn(!1===e.locked),"bytes"===(r=qn(r))?new Cn(e):new kn(e)}function qn(e){var t=String(e);if("bytes"===t)return t;if(void 0===e)return e;throw new RangeError("Invalid type is specified")}var jn=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 gn(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;gn(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(wn)},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 _n(t,e),t.prototype.pull=function(){return this._pullWithDefaultReader()},t}(jn);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 _n(t,e),Object.defineProperty(t.prototype,"type",{get:function(){return"bytes"},enumerable:!1,configurable:!0}),t.prototype._attachByobReader=function(){if("byob"!==this._readerMode){gn(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}(jn);!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(wn)}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(wn),r._writer.abort(e).catch(wn)},this._onTerminate=function(){r._flushResolve(),r._transformStreamController.terminate();var e=new TypeError("TransformStream terminated");r._writer.abort(e).catch(wn)},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];function An(e){return xn.every((function(t,r){return e.charCodeAt(r)===t}))}var In=r(410),Wn=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())}))},Un=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=a.trys,(o=o.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])}}},Bn=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)}))}}},Mn=Ar,Ln=rn,zn=function(){var e;return new Ln({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&&An(r)&&(r=r.slice(xn.length));t=!1;var i=r.length,a=0,s=!1;for(;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=n<0,l=t.slice(r,r+(u?o:n)),c=0,f=r+(c=u?o:" "===t[r+n+1]?n+2:n+1),d=o-c,h=t.slice(f,f+d).toString();if("data"===l)s+=h?"".concat(h,"\n"):"\n";else if("event"===l)a=h;else if("id"!==l||h.includes("\0")){if("retry"===l){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)}})},Fn=function(e){gn(function(e){return!!Rn(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=qn(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)}i=On(r);return new e(i)}}(Mn),Dn=function(){function e(e,t){void 0===e&&(e="utf-8"),void 0===t&&(t={});var r=this;this.transform=new Ln({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 In.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 Nn(e){var t=e;return t[Symbol.asyncIterator]=function(){var t=e.getReader();return{next:function(){return Wn(this,void 0,void 0,(function(){var e,r,n;return Un(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 Gn(e){return Nn(e.pipeThrough(new Dn).pipeThrough(zn()).pipeThrough(new Ln({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 $n(e){return Nn(Fn(e).pipeThrough(new Dn))}function Hn(e){var t,r,n,o;return Wn(this,void 0,void 0,(function(){var i,a,s,u,l,c;return Un(this,(function(f){switch(f.label){case 0:i=$n(e),a="",f.label=1;case 1:f.trys.push([1,6,7,12]),s=!0,u=Bn(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 Yn(){var e,t;return{promise:new Promise((function(r,n){e=r,t=n})),res:e,rej:t}}function Jn(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 Qn(e){return{type:"function",function:{description:e.description,name:e.name,parameters:e.parameters}}}var Vn=function(){return(Vn=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}).apply(this,arguments)},Xn=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())}))},Kn=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=a.trys,(o=o.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])}}},Zn=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},eo=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=Zn(t,["headers"]);return e(Vn(Vn({},i),{headers:Vn(Vn({},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 Xn(this,void 0,void 0,(function(){return Kn(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=Zn(e,["botId"]);return Xn(this,void 0,void 0,(function(){return Kn(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=Zn(e,["pageSize","pageNumber","botId"]);return Xn(this,void 0,void 0,(function(){var e,r;return Kn(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:Vn(Vn({},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=Zn(e,["botId","conversationId"]);return Xn(this,void 0,void 0,(function(){return Kn(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 Xn(this,void 0,void 0,(function(){return Kn(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 Xn(this,void 0,void 0,(function(){return Kn(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 Xn(this,void 0,void 0,(function(){return Kn(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 Xn(this,void 0,void 0,(function(){var r;return Kn(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 to(r)]}}))}))},e.prototype.generateBot=function(e,t){return Xn(this,void 0,void 0,(function(){var r;return Kn(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 to(r)]}}))}))},e.prototype.getPreview=function(e,t){return Xn(this,void 0,void 0,(function(){var r;return Kn(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 to(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 Xn(this,void 0,void 0,(function(){var r;return Kn(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 to(r)]}}))}))},e.prototype.join=function(e){return"".concat(this.baseUrl,"/").concat(e)},e}(),to=function(){function e(e){var t=Fn(e);this._eventSourceStream=t.pipeThrough(new Dn).pipeThrough(zn())}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 Nn(this.teeedStream)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"dataStream",{get:function(){return Nn(this.eventSourceStream.pipeThrough(new Ln({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 Nn(this.dataStream.pipeThrough(new Ln({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}(),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}).apply(this,arguments)},no=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())}))},oo=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=a.trys,(o=o.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 io(e){var t=e.messages,r=e.model,n=e.temperature,o=e.tool_choice,i=e.tools,a=e.top_p;return ro(ro({},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 ao=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 no(this,void 0,void 0,(function(){var r,n;return oo(this,(function(o){switch(o.label){case 0:return r=io(e),[4,this.req({url:this.url,data:ro(ro({},r),{stream:!1}),stream:!1,timeout:null==t?void 0:t.timeout})];case 1:return n=o.sent(),[2,ro(ro({},n),{rawResponse:n})]}}))}))},e.prototype.doStream=function(e,t){return no(this,void 0,void 0,(function(){var r,n,o,i,a;return oo(this,(function(s){switch(s.label){case 0:return r=io(e),n=null,[4,this.req({url:this.url,data:ro(ro({},r),{stream:!0}),stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return o=s.sent(),i=Fn(o),a=Gn(i),[2,Nn(a.pipeThrough(new Ln({transform:function(e,t){var r=e.choices.map((function(e){var t=e.delta;return null==n&&(n=Jn(t)),n?ro(ro({},e),{finish_reason:"tool_calls",delta:t}):e})),o=ro(ro({},e),{choices:r});t.enqueue(ro(ro({},o),{rawResponse:e}))}})))]}}))}))},e}(),so=function(){return(so=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}).apply(this,arguments)};function uo(e){var t=e.messages,r=e.model,n=e.temperature,o=e.tool_choice,i=e.tools,a=e.top_p;return so(so({},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 lo(e){return"object"!=typeof e||null==e?e:Array.isArray(e)?e.map((function(e){return lo(e)})):Object.entries(e).reduce((function(e,t){var r=t[0],n=t[1];return e[function(e){var t=e.replace(/[A-Z]/g,(function(e){return"_".concat(e.toLowerCase())}));return"_"===t.charAt(0)?t.slice(1):t}(r)]="object"==typeof n?lo(n):n,e}),{})}var co=function(){return(co=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}).apply(this,arguments)},fo=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())}))},ho=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=a.trys,(o=o.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])}}},po=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 fo(this,void 0,void 0,(function(){var r;return ho(this,(function(n){switch(n.label){case 0:return[4,this.req({url:this.url,data:co(co({},uo(e)),{stream:!1}),stream:!1,timeout:null==t?void 0:t.timeout})];case 1:return r=n.sent(),[2,co(co({},r),{rawResponse:r})]}}))}))},e.prototype.doStream=function(e,t){return fo(this,void 0,void 0,(function(){var r,n,o,i;return ho(this,(function(a){switch(a.label){case 0:return r=null,[4,this.req({url:this.url,data:co(co({},uo(e)),{stream:!0}),stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return n=a.sent(),o=Fn(n),i=Gn(o),[2,Nn(i.pipeThrough(new Ln({transform:function(e,t){var n=e.choices.map((function(e){var t=e.delta;return null==r&&(r=Jn(t)),r?co(co({},e),{finish_reason:"tool_calls",delta:t}):e})),o=co(co({},e),{choices:n});t.enqueue(co(co({},o),{rawResponse:e}))}})))]}}))}))},e}(),bo=function(){return(bo=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}).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())}))},mo=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=a.trys,(o=o.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])}}},vo=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 yo(this,void 0,void 0,(function(){var r,n;return mo(this,(function(o){switch(o.label){case 0:return[4,this.req({url:this.url,headers:{"X-Tc-Action":"ChatCompletions"},data:bo(bo({},uo(e)),{stream:!1}),stream:!1,timeout:null==t?void 0:t.timeout})];case 1:return r=o.sent(),n=lo(r.Response),[2,bo(bo({},n),{rawResponse:r})]}}))}))},e.prototype.doStream=function(e,t){return yo(this,void 0,void 0,(function(){var r,n,o,i;return mo(this,(function(a){switch(a.label){case 0:return r=null,[4,this.req({url:this.url,headers:{"X-Tc-Action":"ChatCompletions"},data:bo(bo({},e),{stream:!0}),stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return n=a.sent(),o=Fn(n),i=Gn(o),[2,Nn(i.pipeThrough(new Ln({transform:function(e,t){var n=lo(e),o=n.choices.map((function(e){var t=e.delta;return null==r&&(r=Jn(t)),r?bo(bo({},e),{finish_reason:"tool_calls",delta:t}):e})),i=bo(bo({},n),{choices:o});t.enqueue(bo(bo({},i),{rawResponse:e}))}})))]}}))}))},e}(),_o=function(){return(_o=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}).apply(this,arguments)},go=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=a.trys,(o=o.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 So(e){var t=e.messages,r=e.model,n=e.temperature,o=e.tools,i=e.top_p;return _o(_o({},e),{messages:t,model:r,tools:o,top_p:i,temperature:n})}var Ro=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 go(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:_o(_o({},So(e)),{stream:!1}),stream:!1,timeout:null==t?void 0:t.timeout})];case 1:return r=n.sent(),[2,_o(_o({},r),{rawResponse:r})]}}))}))},e.prototype.doStream=function(e,t){return go(this,void 0,void 0,(function(){var r,n,o,i;return wo(this,(function(a){switch(a.label){case 0:return r=null,[4,this.req({url:this.url,data:_o(_o({},So(e)),{stream:!0}),stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return n=a.sent(),o=Fn(n),i=Gn(o),[2,Nn(i.pipeThrough(new Ln({transform:function(e,t){var n=e.choices.map((function(e){var t=e.delta;return null==r&&(r=Jn(t)),r?_o(_o({},e),{finish_reason:"tool_calls",delta:t}):e})),o=_o(_o({},e),{choices:n});t.enqueue(_o(_o({},o),{rawResponse:e}))}})))]}}))}))},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}).apply(this,arguments)},Po=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())}))},Oo=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=a.trys,(o=o.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 qo(e){var t=e.messages,r=e.model,n=e.temperature,o=e.tools,i=e.top_p;return To(To({},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 Po(this,void 0,void 0,(function(){var r;return Oo(this,(function(n){switch(n.label){case 0:return[4,this.req({url:this.url,data:To(To({},qo(e)),{stream:!1}),stream:!1,timeout:null==t?void 0:t.timeout})];case 1:return r=n.sent(),[2,To(To({},r),{rawResponse:r})]}}))}))},e.prototype.doStream=function(e,t){return Po(this,void 0,void 0,(function(){var r,n,o,i;return Oo(this,(function(a){switch(a.label){case 0:return r=null,[4,this.req({url:this.url,data:To(To({},qo(e)),{stream:!0}),stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return n=a.sent(),o=Fn(n),i=Gn(o),[2,Nn(i.pipeThrough(new Ln({transform:function(e,t){var n=e.choices.map((function(e){var t=Object.assign(e.delta,{role:"assistant"});return null==r&&(r=Jn(t)),To(To({},e),r?{finish_reason:"tool_calls",delta:t}:{delta:t})})),o=To(To({},e),{choices:n});t.enqueue(To(To({},o),{rawResponse:e}))}})))]}}))}))},e}(),ko=function(){return(ko=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}).apply(this,arguments)},Eo=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())}))},Co=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=a.trys,(o=o.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 xo(e){var t=e.messages,r=e.model,n=e.temperature,o=e.tools,i=e.top_p;return ko(ko({},e),{messages:t,model:r,tools:o,top_p:i,temperature:n})}var Ao=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 Eo(this,void 0,void 0,(function(){var r;return Co(this,(function(n){switch(n.label){case 0:return[4,this.req({url:this.url,data:ko(ko({},xo(e)),{stream:!1}),stream:!1,timeout:null==t?void 0:t.timeout})];case 1:return r=n.sent(),[2,ko(ko({},r),{rawResponse:r})]}}))}))},e.prototype.doStream=function(e,t){return Eo(this,void 0,void 0,(function(){var r,n,o,i;return Co(this,(function(a){switch(a.label){case 0:return r=null,[4,this.req({url:this.url,data:ko(ko({},xo(e)),{stream:!0}),stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return n=a.sent(),o=Fn(n),i=Gn(o),[2,Nn(i.pipeThrough(new Ln({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=Jn(t)),ko(ko({},e),r?{finish_reason:"tool_calls",delta:t}:{delta:t})})),c=ko(ko({},e),{choices:l});t.enqueue(ko(ko({},c),{rawResponse:e}))}}})))]}}))}))},e}(),Io=function(){return(Io=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}).apply(this,arguments)},Wo=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())}))},Uo=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=a.trys,(o=o.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 Bo(e){var t=e.messages,r=e.model,n=e.temperature,o=e.tools,i=e.top_p;return Io(Io({},e),{messages:t,model:r,tools:o,top_p:i,temperature:n})}var Mo=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 Wo(this,void 0,void 0,(function(){var r;return Uo(this,(function(n){switch(n.label){case 0:return[4,this.req({url:this.url,data:Io(Io({},Bo(e)),{stream:!1}),stream:!1,timeout:null==t?void 0:t.timeout})];case 1:return r=n.sent(),[2,Io(Io({},r),{rawResponse:r})]}}))}))},e.prototype.doStream=function(e,t){return Wo(this,void 0,void 0,(function(){var r,n,o,i;return Uo(this,(function(a){switch(a.label){case 0:return r=null,[4,this.req({url:this.url,data:Io(Io({},Bo(e)),{stream:!0}),stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return n=a.sent(),o=Fn(n),i=Gn(o),[2,Nn(i.pipeThrough(new Ln({transform:function(e,t){var n=e.choices.map((function(e){var t=e.delta;return null==r&&(r=Jn(t)),r?Io(Io({},e),{finish_reason:"tool_calls",delta:t}):e})),o=Io(Io({},e),{choices:n});t.enqueue(Io(Io({},o),{rawResponse:e}))}})))]}}))}))},e}(),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}).apply(this,arguments)},zo=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=a.trys,(o=o.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])}}},Do=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 zo(this,void 0,void 0,(function(){var t;return Fo(this,(function(r){switch(r.label){case 0:return[4,this.req({url:this.url,data:Lo(Lo({},uo(e)),{stream:!1}),stream:!1})];case 1:return t=r.sent(),[2,Lo(Lo({},t),{rawResponse:t})]}}))}))},e.prototype.doStream=function(e){return zo(this,void 0,void 0,(function(){var t,r,n,o;return Fo(this,(function(i){switch(i.label){case 0:return t=null,[4,this.req({url:this.url,data:Lo(Lo({},uo(e)),{stream:!0}),stream:!0})];case 1:return r=i.sent(),n=Fn(r),o=Gn(n),[2,Nn(o.pipeThrough(new Ln({transform:function(e,r){var n=e.choices.map((function(e){var r=e.delta;return null==t&&(t=Jn(r)),t?Lo(Lo({},e),{finish_reason:"tool_calls",delta:r}):e})),o=Lo(Lo({},e),{choices:n});r.enqueue(Lo(Lo({},o),{rawResponse:e}))}})))]}}))}))},e}(),No=function(){return(No=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}).apply(this,arguments)},Go=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())}))},$o=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=a.trys,(o=o.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-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 Go(this,void 0,void 0,(function(){var r;return $o(this,(function(n){switch(n.label){case 0:return[4,this.req({url:this.url,data:No(No({},uo(e)),{stream:!1}),stream:!1,timeout:null==t?void 0:t.timeout})];case 1:return r=n.sent(),[2,No(No({},r),{rawResponse:r})]}}))}))},e.prototype.doStream=function(e,t){return Go(this,void 0,void 0,(function(){var r,n,o,i;return $o(this,(function(a){switch(a.label){case 0:return r=null,[4,this.req({url:this.url,data:No(No({},uo(e)),{stream:!0}),stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return n=a.sent(),o=Fn(n),i=Gn(o),[2,Nn(i.pipeThrough(new Ln({transform:function(e,t){var n=e.choices.map((function(e){var t=e.delta;return null==r&&(r=Jn(t)),r?No(No({},e),{finish_reason:"tool_calls",delta:t}):e})),o=No(No({},e),{choices:n});t.enqueue(No(No({},o),{rawResponse:e}))}})))]}}))}))},e}(),Yo=function(){return(Yo=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}).apply(this,arguments)},Jo=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())}))},Qo=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=a.trys,(o=o.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])}}},Vo=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 Jo(this,void 0,void 0,(function(){var r;return Qo(this,(function(n){switch(n.label){case 0:return[4,this.req({url:this.url,data:Yo(Yo({},e),{stream:!1}),stream:!1,timeout:null==t?void 0:t.timeout})];case 1:return r=n.sent(),[2,Yo(Yo({},r),{rawResponse:r})]}}))}))},e.prototype.doStream=function(e,t){return Jo(this,void 0,void 0,(function(){var r,n,o,i;return Qo(this,(function(a){switch(a.label){case 0:return r=null,[4,this.req({url:this.url,data:Yo(Yo({},e),{stream:!0}),stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return n=a.sent(),o=Fn(n),i=Gn(o),[2,Nn(i.pipeThrough(new Ln({transform:function(e,t){var n=e.choices.map((function(e){var t=e.delta;return null==r&&(r=Jn(t)),r?Yo(Yo({},e),{finish_reason:"tool_calls",delta:t}):e})),o=Yo(Yo({},e),{choices:n});t.enqueue(Yo(Yo({},o),{rawResponse:e}))}})))]}}))}))},e}(),Xo=function(){return(Xo=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}).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())}))},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=a.trys,(o=o.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])}}},ei=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 Ko(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:Xo(Xo({},e),{stream:!1}),stream:!1})];case 1:return t=r.sent(),[2,Xo(Xo({},t),{rawResponse:t})]}}))}))},e.prototype.doStream=function(e){return Ko(this,void 0,void 0,(function(){var t,r,n,o;return Zo(this,(function(i){switch(i.label){case 0:return t=null,[4,this.req({url:this.url,data:Xo(Xo({},e),{stream:!0}),stream:!0})];case 1:return r=i.sent(),n=Fn(r),o=Gn(n),[2,Nn(o.pipeThrough(new Ln({transform:function(e,r){var n=e.choices.map((function(e){var r=e.delta;return null==t&&(t=Jn(r)),t?Xo(Xo({},e),{finish_reason:"tool_calls",delta:r}):e})),o=Xo(Xo({},e),{choices:n});r.enqueue(Xo(Xo({},o),{rawResponse:e}))}})))]}}))}))},e}(),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())}))},ri=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=a.trys,(o=o.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])}}},ni=function(){function e(e,t,r){this.req=e,this.baseUrl=t,this.provider=r,this.generateImageSubUrl="images/generations",this.editImageSubUrl="images/edits"}return e.prototype.generateImage=function(e){return ti(this,void 0,void 0,(function(){return ri(this,(function(t){switch(t.label){case 0:return[4,this.req({url:this.getGenerateUrl(),data:e,stream:!1})];case 1:return[2,t.sent()]}}))}))},e.prototype.editImage=function(e){return ti(this,void 0,void 0,(function(){return ri(this,(function(t){switch(t.label){case 0:return[4,this.req({url:this.getEditUrl(),data:e,stream:!1})];case 1:return[2,t.sent()]}}))}))},e.prototype.getGenerateUrl=function(){return"".concat(this.baseUrl,"/").concat(this.provider,"/").concat(this.generateImageSubUrl)},e.prototype.getEditUrl=function(){return"".concat(this.baseUrl,"/").concat(this.provider,"/").concat(this.editImageSubUrl)},e}(),oi=function(){return(oi=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}).apply(this,arguments)},ii=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())}))},ai=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=a.trys,(o=o.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])}}},si=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},ui=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)}))}}},li=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 ci(e){var t,r=e.onStepFinish,n=e.abortSignal,o=e.maxSteps,i=e.topP,a=e.toolChoice,s=si(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},oi(oi({},s),{tools:null===(t=s.tools)||void 0===t?void 0:t.map((function(e){return"fn"in e?Qn(e):e})),top_p:null!=i?i:s.top_p,tool_choice:null!=a?a:s.tool_choice})]}var fi=function(){function e(e){this.model=e}return e.prototype.generateText=function(e,t){var r,n;return ii(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 ai(this,(function(O){switch(O.label){case 0:return o=[],i={completion_tokens:0,prompt_tokens:0,total_tokens:0},a=ci(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=di(h))))return[3,9];y=yi(h.usage),mi(i,y),O.label=3;case 3:return O.trys.push([3,7,,8]),[4,bi(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(),hi(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?li(li([],f.messages,!0),[w],!1):f.messages,T=yi(h.usage),mi(i,T),[4,null==u?void 0:u({finishReason:g.finish_reason,messages:R.slice(),text:S,toolCall:di(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 ii(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,q,j,k,E,C,x,A,I,W,U,B,M,L=this;return ai(this,(function(z){switch(z.label){case 0:return n={completion_tokens:0,prompt_tokens:0,total_tokens:0},o=ci(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=Nn(t),function(e){var t,r,n,o,i,a,s,u,l,c;return ii(this,void 0,void 0,(function(){var f,d,h,p,b,y,m,v,_,g,w,S,R;return ai(this,(function(T){switch(T.label){case 0:f={completion_tokens:0,prompt_tokens:0,total_tokens:0},d=Nn(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=ui(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,mi(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,bi(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(),hi(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:Nn(S),textStream:Nn(R.pipeThrough(new Ln({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,mi(n,P),O=li(li([],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)}),q=f.tee(),j=q[0],k=q[1],[2,{messages:Promise.resolve(li(li([],l.messages,!0),[T],!1)),dataStream:Nn(j),textStream:Nn(k.pipeThrough(new Ln({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=Yn(),C=Yn(),x={role:"assistant",content:""},A="",I={completion_tokens:0,prompt_tokens:0,total_tokens:0},W=f.pipeThrough(new Ln({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(li(li([],l.messages,!0),[x],!1)),mi(n,I),C.res(Object.assign({},n)),null==a||a({messages:li(li([],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:Nn(B),textStream:Nn(M.pipeThrough(new Ln({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 di(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&&Jn(o)?o.tool_calls[0]:null}function hi(e,t,r){e.push(t,{role:"tool",tool_call_id:t.tool_calls[0].id,content:JSON.stringify(r)})}var pi=new Map;function bi(e){return pi.get(e.function.name)(JSON.parse(e.function.arguments))}function yi(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 mi(e,t){e.completion_tokens+=t.completion_tokens,e.prompt_tokens+=t.prompt_tokens,e.total_tokens+=t.total_tokens}var vi={hunyuan:vo,"hunyuan-beta":po,ark:Ro,dashscope:jo,"01-ai":Ao,moonshot:Mo,zhipu:ao,"hunyuan-exp":Do,"hunyuan-open":Ho,deepseek:Vo},_i="@cloudbase/js-sdk";function gi(){return _i}var wi="https:";var Si,Ri="INVALID_PARAMS",Ti="INVALID_OPERATION",Pi="OPERATION_FAIL";!function(e){e.local="local",e.none="none",e.session="session"}(Si||(Si={}));var Oi=function(){};function qi(e,t){console.warn("[".concat(gi(),"][").concat(e,"]:").concat(t))}var ji,ki=(ji=function(e,t){return(ji=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)},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}ji(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}),Ei=function(){return(Ei=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}).apply(this,arguments)},Ci=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())}))},xi=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=a.trys,(o=o.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}ki(t,e),t.prototype.get=function(e){return this.request(Ei(Ei({},e),{method:"get"}),this.restrictedMethods.includes("get"))},t.prototype.post=function(e){return this.request(Ei(Ei({},e),{method:"post"}),this.restrictedMethods.includes("post"))},t.prototype.put=function(e){return this.request(Ei(Ei({},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(Ei(Ei({},e),{data:u,method:s}),this.restrictedMethods.includes("upload"))):this.request(Ei(Ei({},e),{method:"put",headers:a,body:r}),this.restrictedMethods.includes("upload"))},t.prototype.download=function(e){return Ci(this,void 0,void 0,(function(){var t,r,n,o;return xi(this,(function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,this.get(Ei(Ei({},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 Ci(this,void 0,void 0,(function(){var r,n,o,i,a,s,u,l,c,f,d,h,p,b=this;return xi(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,Ei(Ei({},e),{signal:r.signal})).then((function(e){return Ci(b,void 0,void 0,(function(){var t,r,n;return xi(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)}(wi,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(){}));var Ai;!function(e){e.WEB="web",e.WX_MP="wx_mp"}(Ai||(Ai={}));var Ii=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])})(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)}}(),Wi=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())}))},Ui=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=a.trys,(o=o.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])}}},Bi=function(e){function t(t){var r=e.call(this)||this;return r.root=t,t.tcbCacheObject||(t.tcbCacheObject={}),r}return Ii(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}(Oi);!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":return t.localStorage?t.localStorage:(qi(Ri,"localStorage is not supported on current platform"),new Bi(t.root));case"none":return new Bi(t.root);default:return t.localStorage?t.localStorage:(qi(Ri,"localStorage is not supported on current platform"),new Bi(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:Pi,msg:"[".concat(gi(),"][").concat(Pi,"]setStore failed"),info:e}))}}else qi(Ti,"current platform's storage is asynchronous, please use setStoreAsync insteed")},e.prototype.setStoreAsync=function(e,t,r){return Wi(this,void 0,void 0,(function(){var n;return Ui(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=process.env)||void 0===r?void 0:r.tcb_token))return process.env.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:""}qi(Ti,"current platform's storage is asynchronous, please use getStoreAsync insteed")},e.prototype.getStoreAsync=function(e,t){var r;return Wi(this,void 0,void 0,(function(){var n;return Ui(this,(function(o){switch(o.label){case 0:try{if("undefined"!=typeof process&&(null===(r=process.env)||void 0===r?void 0:r.tcb_token))return[2,process.env.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):qi(Ti,"current platform's storage is asynchronous, please use removeStoreAsync insteed")},e.prototype.removeStoreAsync=function(e){return Wi(this,void 0,void 0,(function(){return Ui(this,(function(t){switch(t.label){case 0:return[4,this.storage.removeItem(e)];case 1:return t.sent(),[2]}}))}))}}();var Mi=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])})(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)}}(),Li=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))};var zi=function(e,t){this.data=t||null,this.name=e},Fi=function(e){function t(t,r){var n=e.call(this,"error",{error:t,data:r})||this;return n.error=t,n}return Mi(t,e),t}(zi),Di=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 Fi)return console.error(e.error),this;var r="string"==typeof e?new zi(e,t||{}):e,n=r.name;if(this.listens(n)){r.target=this;for(var o=0,i=this.listeners[n]?Li([],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 Di;var Ni=new Di;"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.indexOf("Firefox");!function(){function e(){var e=this;this.listeners=[],this.signal={aborted:!1,addEventListener:function(t,r){"abort"===t&&e.listeners.push(r)}}}e.prototype.abort=function(){this.signal.aborted||(this.signal.aborted=!0,this.listeners.forEach((function(e){return e()})))}}();function Gi(e){this.message=e}Gi.prototype=new Error,Gi.prototype.name="InvalidCharacterError";"undefined"!=typeof window&&window.atob&&window.atob.bind(window);function $i(e){this.message=e}$i.prototype=new Error,$i.prototype.name="InvalidTokenError";var Hi=function(){return(Hi=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}).apply(this,arguments)},Yi=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())}))},Ji=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=a.trys,(o=o.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])}}},Qi=vi,Vi=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 Yi(n,void 0,void 0,(function(){var e,n,s,u,l,c,f;return Ji(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:Hi(Hi((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 Yi(n,void 0,void 0,(function(){var e,n,o,l,c,f,d,h;return Ji(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:Hi(Hi((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 eo(this.botRequest,this.aiBotBaseUrl),this.i18n=r,Ni.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 Yi(this,void 0,void 0,(function(){var o,i;return Ji(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,Hn(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=Qi[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 ei(this.modelRequest,this.aiBaseUrl,"".concat(e).concat(o))}return new fi(r)},e.prototype.registerModel=function(e,t){null==Qi[e]?Qi[e]=t:console.warn("AI model ".concat(e," already exists!"))},e.prototype.createImageModel=function(e){return new ni(this.modelRequest,this.aiBaseUrl,e)},e.prototype.registerFunctionTool=function(e){pi.has(e.name)&&console.warn("AI function tool ".concat(e.name," already exists and will be overwritten!")),pi.set(e.name,e.fn)},e}(),Xi=function(){},Ki=function(){return(Ki=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}).apply(this,arguments)},Zi=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())}))},ea=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=a.trys,(o=o.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])}}},ta=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},ra=ta(t,["MODELS"]);function na(e){var t=e.env,r=e.baseUrl,n=e.req,o=e.getAccessToken,i=e.handleReqInstance,a=e.i18n;return new Vi(function(){if(null==i){if(null==o)throw new Error("`getAccessToken` is required when `handleReqInstance` is not provided!");return function(e){var t=e.getAccessToken,r=e.req;return{download:r.download,post:r.post,upload:r.upload,fetch:function(e){return Zi(void 0,void 0,void 0,(function(){var n,o,i,a,s;return ea(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=ta(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(Ki({headers:Ki({Authorization:"Bearer ".concat(s)},i)},a))]}}))}))}}}({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 oa=na;var ia={name:"ai",entity:{ai:function(e){var t,r=this,n=this.request;if(null==n.fetch)throw new Error("cloudbase.request.fetch() unimplemented!");return na({req:n,baseUrl: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)}(),handleReqInstance:function(e){return e.req},i18n:this.config.i18n})}}};function aa(e){try{e.registerComponent(ia)}catch(e){console.warn(e)}}try{window.registerAi=aa}catch(o){}})(),n})());
|