@cloudbase/ai 3.9.0 → 3.9.1

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.
@@ -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:()=>ha,Bot:()=>po,InvalidParamsError:()=>mi,SimpleChatModel:()=>pa,createAI:()=>ga,createAi:()=>wa,models:()=>_a,registerAi:()=>Ra,utils:()=>e});var e={};r.r(e),r.d(e,{ReadableStream:()=>Xn,TextDecoderStream:()=>to,TransformStream:()=>Kn,createAsyncIterable:()=>ro,createEventSourceParserTransformStream:()=>Zn,createPromise:()=>ao,functionToolToModelTool:()=>uo,intoStandardStream:()=>no,intoTextStream:()=>oo,isToolCallAssistantMessage:()=>so,readableStream2JsonObject:()=>io,toPolyfillReadable:()=>eo});var t={};function o(){}function i(e){return"object"==typeof e&&null!==e||"function"==typeof e}r.r(t),r.d(t,{ArkSimpleModel:()=>Uo,DSSimpleModel:()=>Fo,DefaultImageModel:()=>_i,DefaultSimpleModel:()=>pi,HunYuanBetaSimpleModel:()=>jo,HunYuanExpSimpleModel:()=>ri,HunYuanOpenSimpleModel:()=>ai,HunYuanSimpleModel:()=>Co,MODELS:()=>Ii,MoonshotSimpleModel:()=>Ko,ReactModel:()=>ji,YiSimpleModel:()=>Ho,ZhiPuSimpleModel:()=>go,toolMap:()=>Ei});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 m(e,t,r){return c.call(e,t,r)}function y(e,t,r){m(m(e,t,r),void 0,a)}function v(e,t){y(e,t)}function _(e,t){y(e,void 0,t)}function g(e,t,r){return m(e,t,r)}function w(e){m(e,void 0,a)}let S=e=>{if("function"==typeof queueMicrotask)S=queueMicrotask;else{const e=p(void 0);S=t=>m(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("[[CanPullSyncSteps]]"),C=Symbol("[[ReleaseSteps]]");function x(e,t){e._ownerReadableStream=t,t._reader=e,"readable"===t._state?U(e):"closed"===t._state?function(e){U(e),L(e)}(e):B(e,t._storedError)}function A(e,t){return Xr(e._ownerReadableStream,t)}function I(e){const t=e._ownerReadableStream;"readable"===t._state?M(e,new TypeError("Reader was released and can no longer be used to monitor the stream's closedness")):function(e,t){B(e,new TypeError("Reader was released and can no longer be used to monitor the stream's closedness"))}(e),t._readableStreamController[C](),t._reader=void 0,e._ownerReadableStream=void 0}function W(e){return new TypeError("Cannot "+e+" a stream using a released reader")}function U(e){e._closedPromise=h((t,r)=>{e._closedPromise_resolve=t,e._closedPromise_reject=r})}function B(e,t){U(e),M(e,t)}function M(e,t){void 0!==e._closedPromise_reject&&(w(e._closedPromise),e._closedPromise_reject(t),e._closedPromise_resolve=void 0,e._closedPromise_reject=void 0)}function L(e){void 0!==e._closedPromise_resolve&&(e._closedPromise_resolve(void 0),e._closedPromise_resolve=void 0,e._closedPromise_reject=void 0)}const z=Number.isFinite||function(e){return"number"==typeof e&&isFinite(e)},F=Math.trunc||function(e){return e<0?Math.ceil(e):Math.floor(e)};function D(e,t){if(void 0!==e&&"object"!=typeof(r=e)&&"function"!=typeof r)throw new TypeError(t+" is not an object.");var r}function N(e,t){if("function"!=typeof e)throw new TypeError(t+" is not a function.")}function G(e,t){if(!function(e){return"object"==typeof e&&null!==e||"function"==typeof e}(e))throw new TypeError(t+" is not an object.")}function $(e,t,r){if(void 0===e)throw new TypeError(`Parameter ${t} is required in '${r}'.`)}function H(e,t,r){if(void 0===e)throw new TypeError(`${t} is required in '${r}'.`)}function Y(e){return Number(e)}function J(e){return 0===e?0:e}function Q(e,t){const r=Number.MAX_SAFE_INTEGER;let n=Number(e);if(n=J(n),!z(n))throw new TypeError(t+" is not a finite number");if(n=function(e){return J(F(e))}(n),n<0||n>r)throw new TypeError(`${t} is outside the accepted range of 0 to ${r}, inclusive`);return z(n)&&0!==n?n:0}function V(e,t){if(!Qr(e))throw new TypeError(t+" is not a ReadableStream.")}function X(e){return new re(e)}function K(e,t){e._reader._readRequests.push(t)}function Z(e,t,r){const n=e._reader._readRequests.shift();r?n._closeSteps():n._chunkSteps(t)}function ee(e){return e._reader._readRequests.length}function te(e){const t=e._reader;return void 0!==t&&!!ie(t)}class re{constructor(e){if($(e,1,"ReadableStreamDefaultReader"),V(e,"First parameter"),Vr(e))throw new TypeError("This stream has already been locked for exclusive reading by another reader");x(this,e),this._readRequests=new P}get closed(){return ie(this)?this._closedPromise:b(le("closed"))}cancel(e){return ie(this)?void 0===this._ownerReadableStream?b(W("cancel")):A(this,e):b(le("cancel"))}read(){if(!ie(this))return b(le("read"));if(void 0===this._ownerReadableStream)return b(W("read from"));const e=se(this)?new oe:new ne;return ae(this,e),e._promise}releaseLock(){if(!ie(this))throw le("releaseLock");void 0!==this._ownerReadableStream&&function(e){I(e);ue(e,new TypeError("Reader was released"))}(this)}}Object.defineProperties(re.prototype,{cancel:{enumerable:!0},read:{enumerable:!0},releaseLock:{enumerable:!0},closed:{enumerable:!0}}),s(re.prototype.cancel,"cancel"),s(re.prototype.read,"read"),s(re.prototype.releaseLock,"releaseLock"),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(re.prototype,Symbol.toStringTag,{value:"ReadableStreamDefaultReader",configurable:!0});class ne{constructor(){this._promise=h((e,t)=>{this._resolvePromise=e,this._rejectPromise=t})}_chunkSteps(e){this._resolvePromise({value:e,done:!1})}_closeSteps(){this._resolvePromise({value:void 0,done:!0})}_errorSteps(e){this._rejectPromise(e)}}class oe{constructor(){this._promise=void 0}_chunkSteps(e){this._promise=d({value:e,done:!1})}_closeSteps(){this._promise=d({value:void 0,done:!0})}_errorSteps(e){this._promise=b(e)}}function ie(e){return!!i(e)&&!!Object.prototype.hasOwnProperty.call(e,"_readRequests")&&e instanceof re}function ae(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 se(e){const t=e._ownerReadableStream;return"closed"===t._state||"errored"===t._state||t._readableStreamController[E]()}function ue(e,t){const r=e._readRequests;e._readRequests=new P,r.forEach(e=>{e._errorSteps(t)})}function le(e){return new TypeError(`ReadableStreamDefaultReader.prototype.${e} can only be used on a ReadableStreamDefaultReader`)}var ce,fe,de;function he(e){return e.slice()}function pe(e,t,r,n,o){new Uint8Array(e).set(new Uint8Array(r,n,o),t)}let be=e=>(be="function"==typeof e.transfer?e=>e.transfer():"function"==typeof structuredClone?e=>structuredClone(e,{transfer:[e]}):e=>e,be(e)),me=e=>(me="boolean"==typeof e.detached?e=>e.detached:e=>0===e.byteLength,me(e));function ye(e,t,r){if(e.slice)return e.slice(t,r);const n=r-t,o=new ArrayBuffer(n);return pe(o,0,e,t,n),o}function ve(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 _e(e){try{const t=e.done,r=e.value;return m(d(r),e=>({done:t,value:e}))}catch(e){return b(e)}}const ge=null!==(de=null!==(ce=Symbol.asyncIterator)&&void 0!==ce?ce:null===(fe=Symbol.for)||void 0===fe?void 0:fe.call(Symbol,"Symbol.asyncIterator"))&&void 0!==de?de:"@@asyncIterator";function we(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 Se{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=this._ongoingPromise?g(this._ongoingPromise,t,t):t(),this._ongoingPromise}_nextSteps(){if(this._isFinished)return Promise.resolve({value:void 0,done:!0});const e=this._reader,t=new Re(this);return ae(e,t),t._promise}_returnSteps(e){if(this._isFinished)return Promise.resolve({value:e,done:!0});this._isFinished=!0;const t=this._reader;if(!this._preventCancel){const r=A(t,e);return I(t),g(r,()=>({value:e,done:!0}))}return I(t),p({value:e,done:!0})}}class Re{constructor(e){this._iterator=e,this._promise=h((e,t)=>{this._resolvePromise=e,this._rejectPromise=t})}_chunkSteps(e){this._iterator._ongoingPromise=void 0,S(()=>this._resolvePromise({value:e,done:!1}))}_closeSteps(){const e=this._iterator;e._ongoingPromise=void 0,e._isFinished=!0,I(e._reader),this._resolvePromise({value:void 0,done:!0})}_errorSteps(e){const t=this._iterator;t._ongoingPromise=void 0,t._isFinished=!0,I(t._reader),this._rejectPromise(e)}}const Te={next(){return Pe(this)?this._asyncIteratorImpl.next():b(Oe("next"))},return(e){return Pe(this)?this._asyncIteratorImpl.return(e):b(Oe("return"))},[ge](){return this}};function Pe(e){if(!i(e))return!1;if(!Object.prototype.hasOwnProperty.call(e,"_asyncIteratorImpl"))return!1;try{return e._asyncIteratorImpl instanceof Se}catch(e){return!1}}function Oe(e){return new TypeError(`ReadableStreamAsyncIterator.${e} can only be used on a ReadableSteamAsyncIterator`)}Object.defineProperty(Te,ge,{enumerable:!1});const je=Number.isNaN||function(e){return e!=e};function qe(e){const t=ye(e.buffer,e.byteOffset,e.byteOffset+e.byteLength);return new Uint8Array(t)}function ke(e){const t=e._queue.shift();return e._queueTotalSize-=t.size,e._queueTotalSize<0&&(e._queueTotalSize=0),t.value}function Ee(e,t,r){if("number"!=typeof(n=r)||je(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 Ce(e){e._queue=new P,e._queueTotalSize=0}function xe(e){return e===DataView}function Ae(e){return xe(e)?1:e.BYTES_PER_ELEMENT}class Ie{constructor(){throw new TypeError("Illegal constructor")}get view(){if(!Be(this))throw lt("view");return this._view}respond(e){if(!Be(this))throw lt("respond");if($(e,1,"respond"),e=Q(e,"First parameter"),void 0===this._associatedReadableByteStreamController)throw new TypeError("This BYOB request has been invalidated");if(me(this._view.buffer))throw new TypeError("The BYOB request's buffer has been detached and so cannot be used as a response");at(this._associatedReadableByteStreamController,e)}respondWithNewView(e){if(!Be(this))throw lt("respondWithNewView");if($(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(me(e.buffer))throw new TypeError("The given view's buffer has been detached and so cannot be used as a response");st(this._associatedReadableByteStreamController,e)}}Object.defineProperties(Ie.prototype,{respond:{enumerable:!0},respondWithNewView:{enumerable:!0},view:{enumerable:!0}}),s(Ie.prototype.respond,"respond"),s(Ie.prototype.respondWithNewView,"respondWithNewView"),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(Ie.prototype,Symbol.toStringTag,{value:"ReadableStreamBYOBRequest",configurable:!0});class We{constructor(){throw new TypeError("Illegal constructor")}get byobRequest(){if(!Ue(this))throw ct("byobRequest");return ot(this)}get desiredSize(){if(!Ue(this))throw ct("desiredSize");return it(this)}close(){if(!Ue(this))throw ct("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`);et(this)}enqueue(e){if(!Ue(this))throw ct("enqueue");if($(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`);tt(this,e)}error(e){if(!Ue(this))throw ct("error");rt(this,e)}[q](e){Le(this),Ce(this);const t=this._cancelAlgorithm(e);return Ze(this),t}[k](e){const t=this._controlledReadableByteStream;if(this._queueTotalSize>0)return void nt(this,e);const r=this._autoAllocateChunkSize;if(void 0!==r){let n;try{n=new ArrayBuffer(r)}catch(t){return void e._errorSteps(t)}const o={buffer:n,bufferByteLength:r,byteOffset:0,byteLength:r,bytesFilled:0,minimumFill:1,elementSize:1,viewConstructor:Uint8Array,readerType:"default"};this._pendingPullIntos.push(o)}K(t,e),Me(this)}[E](){return this._queueTotalSize>0}[C](){if(this._pendingPullIntos.length>0){const e=this._pendingPullIntos.peek();e.readerType="none",this._pendingPullIntos=new P,this._pendingPullIntos.push(e)}}}function Ue(e){return!!i(e)&&!!Object.prototype.hasOwnProperty.call(e,"_controlledReadableByteStream")&&e instanceof We}function Be(e){return!!i(e)&&!!Object.prototype.hasOwnProperty.call(e,"_associatedReadableByteStreamController")&&e instanceof Ie}function Me(e){(function(e){const t=e._controlledReadableByteStream;if("readable"!==t._state)return!1;if(e._closeRequested)return!1;if(!e._started)return!1;if(te(t)&&ee(t)>0)return!0;if(bt(t)&&pt(t)>0)return!0;return it(e)>0})(e)&&(e._pulling?e._pullAgain=!0:(e._pulling=!0,y(e._pullAlgorithm(),()=>(e._pulling=!1,e._pullAgain&&(e._pullAgain=!1,Me(e)),null),t=>(rt(e,t),null))))}function Le(e){Qe(e),e._pendingPullIntos=new P}function ze(e,t){let r=!1;"closed"===e._state&&(r=!0);const n=De(t);"default"===t.readerType?Z(e,n,r):function(e,t,r){const n=e._reader._readIntoRequests.shift();r?n._closeSteps(t):n._chunkSteps(t)}(e,n,r)}function Fe(e,t){for(let r=0;r<t.length;++r)ze(e,t[r])}function De(e){const t=e.bytesFilled,r=e.elementSize;return new e.viewConstructor(e.buffer,e.byteOffset,t/r)}function Ne(e,t,r,n){e._queue.push({buffer:t,byteOffset:r,byteLength:n}),e._queueTotalSize+=n}function Ge(e,t,r,n){let o;try{o=ye(t,r,r+n)}catch(t){throw rt(e,t),t}Ne(e,o,0,n)}function $e(e,t){t.bytesFilled>0&&Ge(e,t.buffer,t.byteOffset,t.bytesFilled),Ke(e)}function He(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;pe(t.buffer,i,r.buffer,r.byteOffset,n),r.byteLength===n?s.shift():(r.byteOffset+=n,r.byteLength-=n),e._queueTotalSize-=n,Ye(e,n,t),o-=n}return i}function Ye(e,t,r){r.bytesFilled+=t}function Je(e){0===e._queueTotalSize&&e._closeRequested?(Ze(e),Kr(e._controlledReadableByteStream)):Me(e)}function Qe(e){null!==e._byobRequest&&(e._byobRequest._associatedReadableByteStreamController=void 0,e._byobRequest._view=null,e._byobRequest=null)}function Ve(e){const t=[];for(;e._pendingPullIntos.length>0&&0!==e._queueTotalSize;){const r=e._pendingPullIntos.peek();He(e,r)&&(Ke(e),t.push(r))}return t}function Xe(e,t){const r=e._pendingPullIntos.peek();Qe(e),"closed"===e._controlledReadableByteStream._state?function(e,t){"none"===t.readerType&&Ke(e);const r=e._controlledReadableByteStream;if(bt(r)){const t=[];for(;t.length<pt(r);)t.push(Ke(e));Fe(r,t)}}(e,r):function(e,t,r){if(Ye(0,t,r),"none"===r.readerType){$e(e,r);const t=Ve(e);return void Fe(e._controlledReadableByteStream,t)}if(r.bytesFilled<r.minimumFill)return;Ke(e);const n=r.bytesFilled%r.elementSize;if(n>0){const t=r.byteOffset+r.bytesFilled;Ge(e,r.buffer,t-n,n)}r.bytesFilled-=n;const o=Ve(e);ze(e._controlledReadableByteStream,r),Fe(e._controlledReadableByteStream,o)}(e,t,r),Me(e)}function Ke(e){return e._pendingPullIntos.shift()}function Ze(e){e._pullAlgorithm=void 0,e._cancelAlgorithm=void 0}function et(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 rt(e,t),t}}Ze(e),Kr(t)}}function tt(e,t){const r=e._controlledReadableByteStream;if(e._closeRequested||"readable"!==r._state)return;const{buffer:n,byteOffset:o,byteLength:i}=t;if(me(n))throw new TypeError("chunk's buffer is detached and so cannot be enqueued");const a=be(n);if(e._pendingPullIntos.length>0){const t=e._pendingPullIntos.peek();if(me(t.buffer))throw new TypeError("The BYOB request's buffer has been detached and so cannot be filled with an enqueued chunk");Qe(e),t.buffer=be(t.buffer),"none"===t.readerType&&$e(e,t)}te(r)?(function(e){const t=e._controlledReadableByteStream._reader;for(;t._readRequests.length>0;){if(0===e._queueTotalSize)return;nt(e,t._readRequests.shift())}}(e),0===ee(r)?Ne(e,a,o,i):(e._pendingPullIntos.length>0&&Ke(e),Z(r,new Uint8Array(a,o,i),!1))):bt(r)?(Ne(e,a,o,i),Fe(r,Ve(e))):Ne(e,a,o,i),Me(e)}function rt(e,t){const r=e._controlledReadableByteStream;"readable"===r._state&&(Le(e),Ce(e),Ze(e),Zr(r,t))}function nt(e,t){const r=e._queue.shift();e._queueTotalSize-=r.byteLength,Je(e);const n=new Uint8Array(r.buffer,r.byteOffset,r.byteLength);t._chunkSteps(n)}function ot(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(Ie.prototype);!function(e,t,r){e._associatedReadableByteStreamController=t,e._view=r}(n,e,r),e._byobRequest=n}return e._byobRequest}function it(e){const t=e._controlledReadableByteStream._state;return"errored"===t?null:"closed"===t?0:e._strategyHWM-e._queueTotalSize}function at(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=be(r.buffer),Xe(e,t)}function st(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=be(t.buffer),Xe(e,n)}function ut(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,Ce(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,y(p(r()),()=>(t._started=!0,Me(t),null),e=>(rt(t,e),null))}function lt(e){return new TypeError(`ReadableStreamBYOBRequest.prototype.${e} can only be used on a ReadableStreamBYOBRequest`)}function ct(e){return new TypeError(`ReadableByteStreamController.prototype.${e} can only be used on a ReadableByteStreamController`)}function ft(e,t){if("byob"!=(e=""+e))throw new TypeError(`${t} '${e}' is not a valid enumeration value for ReadableStreamReaderMode`);return e}function dt(e){return new mt(e)}function ht(e,t){e._reader._readIntoRequests.push(t)}function pt(e){return e._reader._readIntoRequests.length}function bt(e){const t=e._reader;return void 0!==t&&!!_t(t)}Object.defineProperties(We.prototype,{close:{enumerable:!0},enqueue:{enumerable:!0},error:{enumerable:!0},byobRequest:{enumerable:!0},desiredSize:{enumerable:!0}}),s(We.prototype.close,"close"),s(We.prototype.enqueue,"enqueue"),s(We.prototype.error,"error"),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(We.prototype,Symbol.toStringTag,{value:"ReadableByteStreamController",configurable:!0});class mt{constructor(e){if($(e,1,"ReadableStreamBYOBReader"),V(e,"First parameter"),Vr(e))throw new TypeError("This stream has already been locked for exclusive reading by another reader");if(!Ue(e._readableStreamController))throw new TypeError("Cannot construct a ReadableStreamBYOBReader for a stream not constructed with a byte source");x(this,e),this._readIntoRequests=new P}get closed(){return _t(this)?this._closedPromise:b(St("closed"))}cancel(e){return _t(this)?void 0===this._ownerReadableStream?b(W("cancel")):A(this,e):b(St("cancel"))}read(e,t={}){if(!_t(this))return b(St("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(me(e.buffer))return b(new TypeError("view's buffer has been detached"));let r;try{r=function(e,t){var r;return D(e,t),{min:Q(null!==(r=null==e?void 0:e.min)&&void 0!==r?r:1,t+" has member 'min' that")}}(t,"options")}catch(e){return b(e)}const n=r.min;if(0===n)return b(new TypeError("options.min must be greater than 0"));if(function(e){return xe(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(W("read from"));const o=function(e,t,r){const n=e._ownerReadableStream;return"errored"===n._state||function(e,t,r){const n=e._controlledReadableByteStream,o=Ae(t.constructor),{byteLength:i}=t,a=r*o;return!(e._pendingPullIntos.length>0)&&("closed"===n._state||e._queueTotalSize>=a)}(n._readableStreamController,t,r)}(this,e,n)?new vt:new yt;return gt(this,e,n,o),o._promise}releaseLock(){if(!_t(this))throw St("releaseLock");void 0!==this._ownerReadableStream&&function(e){I(e);wt(e,new TypeError("Reader was released"))}(this)}}Object.defineProperties(mt.prototype,{cancel:{enumerable:!0},read:{enumerable:!0},releaseLock:{enumerable:!0},closed:{enumerable:!0}}),s(mt.prototype.cancel,"cancel"),s(mt.prototype.read,"read"),s(mt.prototype.releaseLock,"releaseLock"),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(mt.prototype,Symbol.toStringTag,{value:"ReadableStreamBYOBReader",configurable:!0});class yt{constructor(){this._promise=h((e,t)=>{this._resolvePromise=e,this._rejectPromise=t})}_chunkSteps(e){this._resolvePromise({value:e,done:!1})}_closeSteps(e){this._resolvePromise({value:e,done:!0})}_errorSteps(e){this._rejectPromise(e)}}class vt{constructor(){this._promise=void 0}_chunkSteps(e){this._promise=d({value:e,done:!1})}_closeSteps(e){this._promise=d({value:e,done:!0})}_errorSteps(e){this._promise=b(e)}}function _t(e){return!!i(e)&&!!Object.prototype.hasOwnProperty.call(e,"_readIntoRequests")&&e instanceof mt}function gt(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=Ae(i),{byteOffset:s,byteLength:u}=t,l=r*a;let c;try{c=be(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 ht(o,n);if("closed"!==o._state){if(e._queueTotalSize>0){if(He(e,f)){const t=De(f);return Je(e),void n._chunkSteps(t)}if(e._closeRequested){const t=new TypeError("Insufficient bytes to fill elements in the given buffer");return rt(e,t),void n._errorSteps(t)}}e._pendingPullIntos.push(f),ht(o,n),Me(e)}else{const e=new i(f.buffer,f.byteOffset,0);n._closeSteps(e)}}(o._readableStreamController,t,r,n)}function wt(e,t){const r=e._readIntoRequests;e._readIntoRequests=new P,r.forEach(e=>{e._errorSteps(t)})}function St(e){return new TypeError(`ReadableStreamBYOBReader.prototype.${e} can only be used on a ReadableStreamBYOBReader`)}function Rt(e,t){const{highWaterMark:r}=e;if(void 0===r)return t;if(je(r)||r<0)throw new RangeError("Invalid highWaterMark");return r}function Tt(e){const{size:t}=e;return t||(()=>1)}function Pt(e,t){D(e,t);const r=null==e?void 0:e.highWaterMark,n=null==e?void 0:e.size;return{highWaterMark:void 0===r?void 0:Y(r),size:void 0===n?void 0:Ot(n,t+" has member 'size' that")}}function Ot(e,t){return N(e,t),t=>Y(e(t))}function jt(e,t,r){return N(e,r),r=>T(e,t,[r])}function qt(e,t,r){return N(e,r),()=>T(e,t,[])}function kt(e,t,r){return N(e,r),r=>R(e,t,[r])}function Et(e,t,r){return N(e,r),(r,n)=>T(e,t,[r,n])}function Ct(e,t){if(!Wt(e))throw new TypeError(t+" is not a WritableStream.")}class xt{constructor(e={},t={}){void 0===e?e=null:G(e,"First parameter");const r=Pt(t,"Second parameter"),n=function(e,t){D(e,t);const r=null==e?void 0:e.abort,n=null==e?void 0:e.close,o=null==e?void 0:e.start,i=null==e?void 0:e.type,a=null==e?void 0:e.write;return{abort:void 0===r?void 0:jt(r,e,t+" has member 'abort' that"),close:void 0===n?void 0:qt(n,e,t+" has member 'close' that"),start:void 0===o?void 0:kt(o,e,t+" has member 'start' that"),write:void 0===a?void 0:Et(a,e,t+" has member 'write' that"),type:i}}(e,"First parameter");if(It(this),void 0!==n.type)throw new RangeError("Invalid type is specified");const o=Tt(r);!function(e,t,r,n){const o=Object.create(Kt.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),er(e,o,i,a,s,u,r,n)}(this,n,Rt(r,1),o)}get locked(){if(!Wt(this))throw sr("locked");return Ut(this)}abort(e){return Wt(this)?Ut(this)?b(new TypeError("Cannot abort a stream that already has a writer")):Bt(this,e):b(sr("abort"))}close(){return Wt(this)?Ut(this)?b(new TypeError("Cannot close a stream that already has a writer")):Dt(this)?b(new TypeError("Cannot close an already-closing stream")):Mt(this):b(sr("close"))}getWriter(){if(!Wt(this))throw sr("getWriter");return At(this)}}function At(e){return new $t(e)}function It(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 Wt(e){return!!i(e)&&!!Object.prototype.hasOwnProperty.call(e,"_writableStreamController")&&e instanceof xt}function Ut(e){return void 0!==e._writer}function Bt(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||zt(e,t),i}function Mt(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&&_r(n),Ee(o=e._writableStreamController,Xt,0),nr(o),r}function Lt(e,t){"writable"!==e._state?Ft(e):zt(e,t)}function zt(e,t){const r=e._writableStreamController;e._state="erroring",e._storedError=t;const n=e._writer;void 0!==n&&Jt(n,t),!function(e){return void 0!==e._inFlightWriteRequest||void 0!==e._inFlightCloseRequest}(e)&&r._started&&Ft(e)}function Ft(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 Nt(e);const r=e._pendingAbortRequest;if(e._pendingAbortRequest=void 0,r._wasAlreadyErroring)return r._reject(t),void Nt(e);y(e._writableStreamController[O](r._reason),()=>(r._resolve(),Nt(e),null),t=>(r._reject(t),Nt(e),null))}function Dt(e){return void 0!==e._closeRequest||void 0!==e._inFlightCloseRequest}function Nt(e){void 0!==e._closeRequest&&(e._closeRequest._reject(e._storedError),e._closeRequest=void 0);const t=e._writer;void 0!==t&&hr(t,e._storedError)}function Gt(e,t){const r=e._writer;void 0!==r&&t!==e._backpressure&&(t?function(e){br(e)}(r):_r(r)),e._backpressure=t}Object.defineProperties(xt.prototype,{abort:{enumerable:!0},close:{enumerable:!0},getWriter:{enumerable:!0},locked:{enumerable:!0}}),s(xt.prototype.abort,"abort"),s(xt.prototype.close,"close"),s(xt.prototype.getWriter,"getWriter"),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(xt.prototype,Symbol.toStringTag,{value:"WritableStream",configurable:!0});class $t{constructor(e){if($(e,1,"WritableStreamDefaultWriter"),Ct(e,"First parameter"),Ut(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)!Dt(e)&&e._backpressure?br(this):yr(this),fr(this);else if("erroring"===t)mr(this,e._storedError),fr(this);else if("closed"===t)yr(this),fr(this),pr(this);else{const t=e._storedError;mr(this,t),dr(this,t)}}get closed(){return Ht(this)?this._closedPromise:b(lr("closed"))}get desiredSize(){if(!Ht(this))throw lr("desiredSize");if(void 0===this._ownerWritableStream)throw cr("desiredSize");return function(e){const t=e._ownerWritableStream,r=t._state;return"errored"===r||"erroring"===r?null:"closed"===r?0:rr(t._writableStreamController)}(this)}get ready(){return Ht(this)?this._readyPromise:b(lr("ready"))}abort(e){return Ht(this)?void 0===this._ownerWritableStream?b(cr("abort")):function(e,t){return Bt(e._ownerWritableStream,t)}(this,e):b(lr("abort"))}close(){if(!Ht(this))return b(lr("close"));const e=this._ownerWritableStream;return void 0===e?b(cr("close")):Dt(e)?b(new TypeError("Cannot close an already-closing stream")):Yt(this)}releaseLock(){if(!Ht(this))throw lr("releaseLock");void 0!==this._ownerWritableStream&&Qt(this)}write(e){return Ht(this)?void 0===this._ownerWritableStream?b(cr("write to")):Vt(this,e):b(lr("write"))}}function Ht(e){return!!i(e)&&!!Object.prototype.hasOwnProperty.call(e,"_ownerWritableStream")&&e instanceof $t}function Yt(e){return Mt(e._ownerWritableStream)}function Jt(e,t){"pending"===e._readyPromiseState?vr(e,t):function(e,t){mr(e,t)}(e,t)}function Qt(e){const t=e._ownerWritableStream,r=new TypeError("Writer was released and can no longer be used to monitor the stream's closedness");Jt(e,r),function(e,t){"pending"===e._closedPromiseState?hr(e,t):function(e,t){dr(e,t)}(e,t)}(e,r),t._writer=void 0,e._ownerWritableStream=void 0}function Vt(e,t){const r=e._ownerWritableStream,n=r._writableStreamController,o=function(e,t){if(void 0===e._strategySizeAlgorithm)return 1;try{return e._strategySizeAlgorithm(t)}catch(t){return or(e,t),1}}(n,t);if(r!==e._ownerWritableStream)return b(cr("write to"));const i=r._state;if("errored"===i)return b(r._storedError);if(Dt(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{Ee(e,t,r)}catch(t){return void or(e,t)}const n=e._controlledWritableStream;Dt(n)||"writable"!==n._state||Gt(n,ir(e)),nr(e)}(n,t,o),a}Object.defineProperties($t.prototype,{abort:{enumerable:!0},close:{enumerable:!0},releaseLock:{enumerable:!0},write:{enumerable:!0},closed:{enumerable:!0},desiredSize:{enumerable:!0},ready:{enumerable:!0}}),s($t.prototype.abort,"abort"),s($t.prototype.close,"close"),s($t.prototype.releaseLock,"releaseLock"),s($t.prototype.write,"write"),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty($t.prototype,Symbol.toStringTag,{value:"WritableStreamDefaultWriter",configurable:!0});const Xt={};class Kt{constructor(){throw new TypeError("Illegal constructor")}get abortReason(){if(!Zt(this))throw ur("abortReason");return this._abortReason}get signal(){if(!Zt(this))throw ur("signal");if(void 0===this._abortController)throw new TypeError("WritableStreamDefaultController.prototype.signal is not supported");return this._abortController.signal}error(e){if(!Zt(this))throw ur("error");"writable"===this._controlledWritableStream._state&&ar(this,e)}[O](e){const t=this._abortAlgorithm(e);return tr(this),t}[j](){Ce(this)}}function Zt(e){return!!i(e)&&!!Object.prototype.hasOwnProperty.call(e,"_controlledWritableStream")&&e instanceof Kt}function er(e,t,r,n,o,i,a,s){t._controlledWritableStream=e,e._writableStreamController=t,t._queue=void 0,t._queueTotalSize=void 0,Ce(t),t._abortReason=void 0,t._abortController=function(){if("function"==typeof AbortController)return new AbortController}(),t._started=!1,t._strategySizeAlgorithm=s,t._strategyHWM=a,t._writeAlgorithm=n,t._closeAlgorithm=o,t._abortAlgorithm=i;const u=ir(t);Gt(e,u),y(p(r()),()=>(t._started=!0,nr(t),null),r=>(t._started=!0,Lt(e,r),null))}function tr(e){e._writeAlgorithm=void 0,e._closeAlgorithm=void 0,e._abortAlgorithm=void 0,e._strategySizeAlgorithm=void 0}function rr(e){return e._strategyHWM-e._queueTotalSize}function nr(e){const t=e._controlledWritableStream;if(!e._started)return;if(void 0!==t._inFlightWriteRequest)return;if("erroring"===t._state)return void Ft(t);if(0===e._queue.length)return;const r=e._queue.peek().value;r===Xt?function(e){const t=e._controlledWritableStream;(function(e){e._inFlightCloseRequest=e._closeRequest,e._closeRequest=void 0})(t),ke(e);const r=e._closeAlgorithm();tr(e),y(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&&pr(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),Lt(e,t)}(t,e),null))}(e):function(e,t){const r=e._controlledWritableStream;!function(e){e._inFlightWriteRequest=e._writeRequests.shift()}(r);y(e._writeAlgorithm(t),()=>{!function(e){e._inFlightWriteRequest._resolve(void 0),e._inFlightWriteRequest=void 0}(r);const t=r._state;if(ke(e),!Dt(r)&&"writable"===t){const t=ir(e);Gt(r,t)}return nr(e),null},t=>("writable"===r._state&&tr(e),function(e,t){e._inFlightWriteRequest._reject(t),e._inFlightWriteRequest=void 0,Lt(e,t)}(r,t),null))}(e,r)}function or(e,t){"writable"===e._controlledWritableStream._state&&ar(e,t)}function ir(e){return rr(e)<=0}function ar(e,t){const r=e._controlledWritableStream;tr(e),zt(r,t)}function sr(e){return new TypeError(`WritableStream.prototype.${e} can only be used on a WritableStream`)}function ur(e){return new TypeError(`WritableStreamDefaultController.prototype.${e} can only be used on a WritableStreamDefaultController`)}function lr(e){return new TypeError(`WritableStreamDefaultWriter.prototype.${e} can only be used on a WritableStreamDefaultWriter`)}function cr(e){return new TypeError("Cannot "+e+" a stream using a released writer")}function fr(e){e._closedPromise=h((t,r)=>{e._closedPromise_resolve=t,e._closedPromise_reject=r,e._closedPromiseState="pending"})}function dr(e,t){fr(e),hr(e,t)}function hr(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 pr(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 br(e){e._readyPromise=h((t,r)=>{e._readyPromise_resolve=t,e._readyPromise_reject=r}),e._readyPromiseState="pending"}function mr(e,t){br(e),vr(e,t)}function yr(e){br(e),_r(e)}function vr(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 _r(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(Kt.prototype,{abortReason:{enumerable:!0},signal:{enumerable:!0},error:{enumerable:!0}}),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(Kt.prototype,Symbol.toStringTag,{value:"WritableStreamDefaultController",configurable:!0});const gr="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof global?global:void 0,wr=function(){const e=null==gr?void 0:gr.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 Sr(e,t,r,n,o,i){const a=X(e),s=At(t);e._disturbed=!0;const u=new Rr(s),l=new Pr(u);return h((c,f)=>{let d;if(void 0!==i){if(d=()=>{const r=void 0!==i.reason?i.reason:new wr("Aborted","AbortError"),a=[];n||a.push(()=>"writable"===t._state?Bt(t,r):p(void 0)),o||a.push(()=>"readable"===e._state?Xr(e,r):p(void 0)),T(()=>Promise.all(a.map(e=>e())),!0,r)},i.aborted)return void d();i.addEventListener("abort",d)}function _(){for(;!u._shuttingDown&&!t._backpressure&&"writable"===t._state&&!Dt(t)&&"readable"===e._state&&se(a);)ae(a,l);if(u._shuttingDown)return p(!0);if(t._backpressure)return m(s._readyPromise,_);const r=new Tr(u);return ae(a,r),r._promise}var g,S,R;if(Or(e,a._closedPromise,e=>(n?P(!0,e):T(()=>Bt(t,e),!0,e),null)),Or(t,s._closedPromise,t=>(o?P(!0,t):T(()=>Xr(e,t),!0,t),null)),g=e,S=a._closedPromise,R=()=>(r?P():T(()=>function(e){const t=e._ownerWritableStream,r=t._state;return Dt(t)||"closed"===r?p(void 0):"errored"===r?b(t._storedError):Yt(e)}(s)),null),"closed"===g._state?R():v(S,R),Dt(t)||"closed"===t._state){const t=new TypeError("the destination writable stream closed before all data could be piped to it");o?P(!0,t):T(()=>Xr(e,t),!0,t)}function T(e,r,n){function o(){return y(e(),()=>O(r,n),e=>O(!0,e)),null}u._shuttingDown||(u._shuttingDown=!0,"writable"!==t._state||Dt(t)?o():v(u._waitForWritesToFinish(),o))}function P(e,r){u._shuttingDown||(u._shuttingDown=!0,"writable"!==t._state||Dt(t)?O(e,r):v(u._waitForWritesToFinish(),()=>O(e,r)))}function O(e,t){return Qt(s),I(a),void 0!==i&&i.removeEventListener("abort",d),e?f(t):c(void 0),null}w(h((e,t)=>{!function r(n){n?e():m(_(),r,t)}(!1)}))})}class Rr{constructor(e){this._writer=e,this._shuttingDown=!1,this._currentWrite=p(void 0)}_waitForWritesToFinish(){const e=this._currentWrite;return m(this._currentWrite,()=>e!==this._currentWrite?this._waitForWritesToFinish():void 0)}}class Tr{constructor(e){this._state=e,this._promise=h((e,t)=>{this._resolvePromise=e,this._rejectPromise=t})}_chunkSteps(e){this._state._currentWrite=m(Vt(this._state._writer,e),void 0,o),this._resolvePromise(!1)}_closeSteps(){this._resolvePromise(!0)}_errorSteps(e){this._rejectPromise(e)}}class Pr{constructor(e){this._state=e}_chunkSteps(e){this._state._currentWrite=m(Vt(this._state._writer,e),void 0,o)}_closeSteps(){}_errorSteps(e){}}function Or(e,t,r){"errored"===e._state?r(e._storedError):_(t,r)}class jr{constructor(){throw new TypeError("Illegal constructor")}get desiredSize(){if(!qr(this))throw Mr("desiredSize");return Wr(this)}close(){if(!qr(this))throw Mr("close");if(!Ur(this))throw new TypeError("The stream is not in a state that permits close");xr(this)}enqueue(e){if(!qr(this))throw Mr("enqueue");if(!Ur(this))throw new TypeError("The stream is not in a state that permits enqueue");return Ar(this,e)}error(e){if(!qr(this))throw Mr("error");Ir(this,e)}[q](e){Ce(this);const t=this._cancelAlgorithm(e);return Cr(this),t}[k](e){const t=this._controlledReadableStream;if(this._queue.length>0){const r=ke(this);this._closeRequested&&0===this._queue.length?(Cr(this),Kr(t)):kr(this),e._chunkSteps(r)}else K(t,e),kr(this)}[E](){return this._queue.length>0}[C](){}}function qr(e){return!!i(e)&&!!Object.prototype.hasOwnProperty.call(e,"_controlledReadableStream")&&e instanceof jr}function kr(e){Er(e)&&(e._pulling?e._pullAgain=!0:(e._pulling=!0,y(e._pullAlgorithm(),()=>(e._pulling=!1,e._pullAgain&&(e._pullAgain=!1,kr(e)),null),t=>(Ir(e,t),null))))}function Er(e){const t=e._controlledReadableStream;return!!Ur(e)&&(!!e._started&&(!!(Vr(t)&&ee(t)>0)||Wr(e)>0))}function Cr(e){e._pullAlgorithm=void 0,e._cancelAlgorithm=void 0,e._strategySizeAlgorithm=void 0}function xr(e){if(!Ur(e))return;const t=e._controlledReadableStream;e._closeRequested=!0,0===e._queue.length&&(Cr(e),Kr(t))}function Ar(e,t){if(!Ur(e))return;const r=e._controlledReadableStream;if(Vr(r)&&ee(r)>0)Z(r,t,!1);else{let r;try{r=e._strategySizeAlgorithm(t)}catch(t){throw Ir(e,t),t}try{Ee(e,t,r)}catch(t){throw Ir(e,t),t}}kr(e)}function Ir(e,t){const r=e._controlledReadableStream;"readable"===r._state&&(Ce(e),Cr(e),Zr(r,t))}function Wr(e){const t=e._controlledReadableStream._state;return"errored"===t?null:"closed"===t?0:e._strategyHWM-e._queueTotalSize}function Ur(e){const t=e._controlledReadableStream._state;return!e._closeRequested&&"readable"===t}function Br(e,t,r,n,o,i,a){t._controlledReadableStream=e,t._queue=void 0,t._queueTotalSize=void 0,Ce(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,y(p(r()),()=>(t._started=!0,kr(t),null),e=>(Ir(t,e),null))}function Mr(e){return new TypeError(`ReadableStreamDefaultController.prototype.${e} can only be used on a ReadableStreamDefaultController`)}function Lr(e){return i(t=e)&&void 0!==t.getReader?function(e){let t;return t=Hr(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)xr(t._readableStreamController);else{const r=e.value;Ar(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=ve(t,ge)))return function(e){const t={next(){let t;try{t=we(e)}catch(e){return b(e)}return _e(t)},return(t){let r;try{const n=ve(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)?_e(r):b(new TypeError("The iterator.return() method must return an object"))}};return{iterator:t,nextMethod:t.next,done:!1}}(e(t,"sync",ve(t,Symbol.iterator)))}else n=ve(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=Hr(o,(function(){let e;try{e=we(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)xr(t._readableStreamController);else{const r=e.value;Ar(t._readableStreamController,r)}})}),(function(e){const t=r.iterator;let n;try{n=ve(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 zr(e,t,r){return N(e,r),r=>T(e,t,[r])}function Fr(e,t,r){return N(e,r),r=>T(e,t,[r])}function Dr(e,t,r){return N(e,r),r=>R(e,t,[r])}function Nr(e,t){if("bytes"!=(e=""+e))throw new TypeError(`${t} '${e}' is not a valid enumeration value for ReadableStreamType`);return e}function Gr(e,t){D(e,t);const r=null==e?void 0:e.preventAbort,n=null==e?void 0:e.preventCancel,o=null==e?void 0:e.preventClose,i=null==e?void 0:e.signal;return void 0!==i&&function(e,t){if(!function(e){if("object"!=typeof e||null===e)return!1;try{return"boolean"==typeof e.aborted}catch(e){return!1}}(e))throw new TypeError(t+" is not an AbortSignal.")}(i,t+" has member 'signal' that"),{preventAbort:Boolean(r),preventCancel:Boolean(n),preventClose:Boolean(o),signal:i}}Object.defineProperties(jr.prototype,{close:{enumerable:!0},enqueue:{enumerable:!0},error:{enumerable:!0},desiredSize:{enumerable:!0}}),s(jr.prototype.close,"close"),s(jr.prototype.enqueue,"enqueue"),s(jr.prototype.error,"error"),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(jr.prototype,Symbol.toStringTag,{value:"ReadableStreamDefaultController",configurable:!0});class $r{constructor(e={},t={}){void 0===e?e=null:G(e,"First parameter");const r=Pt(t,"Second parameter"),n=function(e,t){D(e,t);const r=e,n=null==r?void 0:r.autoAllocateChunkSize,o=null==r?void 0:r.cancel,i=null==r?void 0:r.pull,a=null==r?void 0:r.start,s=null==r?void 0:r.type;return{autoAllocateChunkSize:void 0===n?void 0:Q(n,t+" has member 'autoAllocateChunkSize' that"),cancel:void 0===o?void 0:zr(o,r,t+" has member 'cancel' that"),pull:void 0===i?void 0:Fr(i,r,t+" has member 'pull' that"),start:void 0===a?void 0:Dr(a,r,t+" has member 'start' that"),type:void 0===s?void 0:Nr(s,t+" has member 'type' that")}}(e,"First parameter");if(Jr(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(We.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");ut(e,n,o,i,a,r,s)}(this,n,Rt(r,0))}else{const e=Tt(r);!function(e,t,r,n){const o=Object.create(jr.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),Br(e,o,i,a,s,r,n)}(this,n,Rt(r,1),e)}}get locked(){if(!Qr(this))throw en("locked");return Vr(this)}cancel(e){return Qr(this)?Vr(this)?b(new TypeError("Cannot cancel a stream that already has a reader")):Xr(this,e):b(en("cancel"))}getReader(e){if(!Qr(this))throw en("getReader");return void 0===function(e,t){D(e,t);const r=null==e?void 0:e.mode;return{mode:void 0===r?void 0:ft(r,t+" has member 'mode' that")}}(e,"First parameter").mode?X(this):dt(this)}pipeThrough(e,t={}){if(!Qr(this))throw en("pipeThrough");$(e,1,"pipeThrough");const r=function(e,t){D(e,t);const r=null==e?void 0:e.readable;H(r,"readable","ReadableWritablePair"),V(r,t+" has member 'readable' that");const n=null==e?void 0:e.writable;return H(n,"writable","ReadableWritablePair"),Ct(n,t+" has member 'writable' that"),{readable:r,writable:n}}(e,"First parameter"),n=Gr(t,"Second parameter");if(Vr(this))throw new TypeError("ReadableStream.prototype.pipeThrough cannot be used on a locked ReadableStream");if(Ut(r.writable))throw new TypeError("ReadableStream.prototype.pipeThrough cannot be used on a locked WritableStream");return w(Sr(this,r.writable,n.preventClose,n.preventAbort,n.preventCancel,n.signal)),r.readable}pipeTo(e,t={}){if(!Qr(this))return b(en("pipeTo"));if(void 0===e)return b("Parameter 1 is required in 'pipeTo'.");if(!Wt(e))return b(new TypeError("ReadableStream.prototype.pipeTo's first argument must be a WritableStream"));let r;try{r=Gr(t,"Second parameter")}catch(e){return b(e)}return Vr(this)?b(new TypeError("ReadableStream.prototype.pipeTo cannot be used on a locked ReadableStream")):Ut(e)?b(new TypeError("ReadableStream.prototype.pipeTo cannot be used on a locked WritableStream")):Sr(this,e,r.preventClose,r.preventAbort,r.preventCancel,r.signal)}tee(){if(!Qr(this))throw en("tee");return he(function(e,t){return Ue(e._readableStreamController)?function(e){let t,r,n,o,i,a=X(e),s=!1,u=!1,l=!1,c=!1,f=!1;const d=h(e=>{i=e});function b(e){_(e._closedPromise,t=>(e!==a||(rt(n._readableStreamController,t),rt(o._readableStreamController,t),c&&f||i(void 0)),null))}function m(){_t(a)&&(I(a),a=X(e),b(a)),ae(a,{_chunkSteps:t=>{S(()=>{u=!1,l=!1;const r=t;let a=t;if(!c&&!f)try{a=qe(t)}catch(t){return rt(n._readableStreamController,t),rt(o._readableStreamController,t),void i(Xr(e,t))}c||tt(n._readableStreamController,r),f||tt(o._readableStreamController,a),s=!1,u?v():l&&g()})},_closeSteps:()=>{s=!1,c||et(n._readableStreamController),f||et(o._readableStreamController),n._readableStreamController._pendingPullIntos.length>0&&at(n._readableStreamController,0),o._readableStreamController._pendingPullIntos.length>0&&at(o._readableStreamController,0),c&&f||i(void 0)},_errorSteps:()=>{s=!1}})}function y(t,r){ie(a)&&(I(a),a=dt(e),b(a));const d=r?o:n,h=r?n:o;gt(a,t,1,{_chunkSteps:t=>{S(()=>{u=!1,l=!1;const n=r?f:c;if(r?c:f)n||st(d._readableStreamController,t);else{let r;try{r=qe(t)}catch(t){return rt(d._readableStreamController,t),rt(h._readableStreamController,t),void i(Xr(e,t))}n||st(d._readableStreamController,t),tt(h._readableStreamController,r)}s=!1,u?v():l&&g()})},_closeSteps:e=>{s=!1;const t=r?f:c,n=r?c:f;t||et(d._readableStreamController),n||et(h._readableStreamController),void 0!==e&&(t||st(d._readableStreamController,e),!n&&h._readableStreamController._pendingPullIntos.length>0&&at(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=ot(n._readableStreamController);return null===e?m():y(e._view,!1),p(void 0)}function g(){if(s)return l=!0,p(void 0);s=!0;const e=ot(o._readableStreamController);return null===e?m():y(e._view,!0),p(void 0)}function w(){}return n=Yr(w,v,(function(n){if(c=!0,t=n,f){const n=he([t,r]),o=Xr(e,n);i(o)}return d})),o=Yr(w,g,(function(n){if(f=!0,r=n,c){const n=he([t,r]),o=Xr(e,n);i(o)}return d})),b(a),[n,o]}(e):function(e){const t=X(e);let r,n,o,i,a,s=!1,u=!1,l=!1,c=!1;const f=h(e=>{a=e});function d(){return s?(u=!0,p(void 0)):(s=!0,ae(t,{_chunkSteps:e=>{S(()=>{u=!1;const t=e,r=e;l||Ar(o._readableStreamController,t),c||Ar(i._readableStreamController,r),s=!1,u&&d()})},_closeSteps:()=>{s=!1,l||xr(o._readableStreamController),c||xr(i._readableStreamController),l&&c||a(void 0)},_errorSteps:()=>{s=!1}}),p(void 0))}function b(){}return o=Hr(b,d,(function(t){if(l=!0,r=t,c){const t=he([r,n]),o=Xr(e,t);a(o)}return f})),i=Hr(b,d,(function(t){if(c=!0,n=t,l){const t=he([r,n]),o=Xr(e,t);a(o)}return f})),_(t._closedPromise,e=>(Ir(o._readableStreamController,e),Ir(i._readableStreamController,e),l&&c||a(void 0),null)),[o,i]}(e)}(this))}values(e){if(!Qr(this))throw en("values");return function(e,t){const r=X(e),n=new Se(r,t),o=Object.create(Te);return o._asyncIteratorImpl=n,o}(this,function(e,t){D(e,"First parameter");const r=null==e?void 0:e.preventCancel;return{preventCancel:Boolean(r)}}(e).preventCancel)}[ge](e){return this.values(e)}static from(e){return Lr(e)}}function Hr(e,t,r,n=1,o=(()=>1)){const i=Object.create($r.prototype);return Jr(i),Br(i,Object.create(jr.prototype),e,t,r,n,o),i}function Yr(e,t,r){const n=Object.create($r.prototype);return Jr(n),ut(n,Object.create(We.prototype),e,t,r,0,void 0),n}function Jr(e){e._state="readable",e._reader=void 0,e._storedError=void 0,e._disturbed=!1}function Qr(e){return!!i(e)&&!!Object.prototype.hasOwnProperty.call(e,"_readableStreamController")&&e instanceof $r}function Vr(e){return void 0!==e._reader}function Xr(e,t){if(e._disturbed=!0,"closed"===e._state)return p(void 0);if("errored"===e._state)return b(e._storedError);Kr(e);const r=e._reader;if(void 0!==r&&_t(r)){const e=r._readIntoRequests;r._readIntoRequests=new P,e.forEach(e=>{e._closeSteps(void 0)})}return g(e._readableStreamController[q](t),o)}function Kr(e){e._state="closed";const t=e._reader;if(void 0!==t&&(L(t),ie(t))){const e=t._readRequests;t._readRequests=new P,e.forEach(e=>{e._closeSteps()})}}function Zr(e,t){e._state="errored",e._storedError=t;const r=e._reader;void 0!==r&&(M(r,t),ie(r)?ue(r,t):wt(r,t))}function en(e){return new TypeError(`ReadableStream.prototype.${e} can only be used on a ReadableStream`)}function tn(e,t){D(e,t);const r=null==e?void 0:e.highWaterMark;return H(r,"highWaterMark","QueuingStrategyInit"),{highWaterMark:Y(r)}}Object.defineProperties($r,{from:{enumerable:!0}}),Object.defineProperties($r.prototype,{cancel:{enumerable:!0},getReader:{enumerable:!0},pipeThrough:{enumerable:!0},pipeTo:{enumerable:!0},tee:{enumerable:!0},values:{enumerable:!0},locked:{enumerable:!0}}),s($r.from,"from"),s($r.prototype.cancel,"cancel"),s($r.prototype.getReader,"getReader"),s($r.prototype.pipeThrough,"pipeThrough"),s($r.prototype.pipeTo,"pipeTo"),s($r.prototype.tee,"tee"),s($r.prototype.values,"values"),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty($r.prototype,Symbol.toStringTag,{value:"ReadableStream",configurable:!0}),Object.defineProperty($r.prototype,ge,{value:$r.prototype.values,writable:!0,configurable:!0});const rn=e=>e.byteLength;s(rn,"size");class nn{constructor(e){$(e,1,"ByteLengthQueuingStrategy"),e=tn(e,"First parameter"),this._byteLengthQueuingStrategyHighWaterMark=e.highWaterMark}get highWaterMark(){if(!an(this))throw on("highWaterMark");return this._byteLengthQueuingStrategyHighWaterMark}get size(){if(!an(this))throw on("size");return rn}}function on(e){return new TypeError(`ByteLengthQueuingStrategy.prototype.${e} can only be used on a ByteLengthQueuingStrategy`)}function an(e){return!!i(e)&&!!Object.prototype.hasOwnProperty.call(e,"_byteLengthQueuingStrategyHighWaterMark")&&e instanceof nn}Object.defineProperties(nn.prototype,{highWaterMark:{enumerable:!0},size:{enumerable:!0}}),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(nn.prototype,Symbol.toStringTag,{value:"ByteLengthQueuingStrategy",configurable:!0});const sn=()=>1;s(sn,"size");class un{constructor(e){$(e,1,"CountQueuingStrategy"),e=tn(e,"First parameter"),this._countQueuingStrategyHighWaterMark=e.highWaterMark}get highWaterMark(){if(!cn(this))throw ln("highWaterMark");return this._countQueuingStrategyHighWaterMark}get size(){if(!cn(this))throw ln("size");return sn}}function ln(e){return new TypeError(`CountQueuingStrategy.prototype.${e} can only be used on a CountQueuingStrategy`)}function cn(e){return!!i(e)&&!!Object.prototype.hasOwnProperty.call(e,"_countQueuingStrategyHighWaterMark")&&e instanceof un}function fn(e,t,r){return N(e,r),r=>T(e,t,[r])}function dn(e,t,r){return N(e,r),r=>R(e,t,[r])}function hn(e,t,r){return N(e,r),(r,n)=>T(e,t,[r,n])}function pn(e,t,r){return N(e,r),r=>T(e,t,[r])}Object.defineProperties(un.prototype,{highWaterMark:{enumerable:!0},size:{enumerable:!0}}),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(un.prototype,Symbol.toStringTag,{value:"CountQueuingStrategy",configurable:!0});class bn{constructor(e={},t={},r={}){void 0===e&&(e=null);const n=Pt(t,"Second parameter"),o=Pt(r,"Third parameter"),i=function(e,t){D(e,t);const r=null==e?void 0:e.cancel,n=null==e?void 0:e.flush,o=null==e?void 0:e.readableType,i=null==e?void 0:e.start,a=null==e?void 0:e.transform,s=null==e?void 0:e.writableType;return{cancel:void 0===r?void 0:pn(r,e,t+" has member 'cancel' that"),flush:void 0===n?void 0:fn(n,e,t+" has member 'flush' that"),readableType:o,start:void 0===i?void 0:dn(i,e,t+" has member 'start' that"),transform:void 0===a?void 0:hn(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=Rt(o,0),s=Tt(o),u=Rt(n,1),l=Tt(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(xt.prototype);return It(a),er(a,Object.create(Kt.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 Pn(r,t)}):Pn(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 Rn(t),y(n,()=>("errored"===r._state?qn(t,r._storedError):(xr(r._readableStreamController),jn(t)),null),e=>(Ir(r._readableStreamController,e),qn(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 Rn(r),y(o,()=>("errored"===n._state?qn(r,n._storedError):(Ir(n._readableStreamController,t),jn(r)),null),e=>(Ir(n._readableStreamController,e),qn(r,e),null)),r._finishPromise}(e,t)}),r,n),e._readable=Hr(a,(function(){return function(e){return gn(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 Rn(r),y(o,()=>("errored"===n._state?qn(r,n._storedError):(or(n._writableStreamController,t),_n(e),jn(r)),null),t=>(or(n._writableStreamController,t),_n(e),qn(r,t),null)),r._finishPromise}(e,t)}),o,i),e._backpressure=void 0,e._backpressureChangePromise=void 0,e._backpressureChangePromise_resolve=void 0,gn(e,!0),e._transformStreamController=void 0}(this,h(e=>{c=e}),u,l,a,s),function(e,t){const r=Object.create(wn.prototype);let n,o,i;n=void 0!==t.transform?e=>t.transform(e,r):e=>{try{return Tn(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(!mn(this))throw kn("readable");return this._readable}get writable(){if(!mn(this))throw kn("writable");return this._writable}}function mn(e){return!!i(e)&&!!Object.prototype.hasOwnProperty.call(e,"_transformStreamController")&&e instanceof bn}function yn(e,t){Ir(e._readable._readableStreamController,t),vn(e,t)}function vn(e,t){Rn(e._transformStreamController),or(e._writable._writableStreamController,t),_n(e)}function _n(e){e._backpressure&&gn(e,!1)}function gn(e,t){void 0!==e._backpressureChangePromise&&e._backpressureChangePromise_resolve(),e._backpressureChangePromise=h(t=>{e._backpressureChangePromise_resolve=t}),e._backpressure=t}Object.defineProperties(bn.prototype,{readable:{enumerable:!0},writable:{enumerable:!0}}),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(bn.prototype,Symbol.toStringTag,{value:"TransformStream",configurable:!0});class wn{constructor(){throw new TypeError("Illegal constructor")}get desiredSize(){if(!Sn(this))throw On("desiredSize");return Wr(this._controlledTransformStream._readable._readableStreamController)}enqueue(e){if(!Sn(this))throw On("enqueue");Tn(this,e)}error(e){if(!Sn(this))throw On("error");var t;t=e,yn(this._controlledTransformStream,t)}terminate(){if(!Sn(this))throw On("terminate");!function(e){const t=e._controlledTransformStream;xr(t._readable._readableStreamController);vn(t,new TypeError("TransformStream terminated"))}(this)}}function Sn(e){return!!i(e)&&!!Object.prototype.hasOwnProperty.call(e,"_controlledTransformStream")&&e instanceof wn}function Rn(e){e._transformAlgorithm=void 0,e._flushAlgorithm=void 0,e._cancelAlgorithm=void 0}function Tn(e,t){const r=e._controlledTransformStream,n=r._readable._readableStreamController;if(!Ur(n))throw new TypeError("Readable side is not in a state that permits enqueue");try{Ar(n,t)}catch(e){throw vn(r,e),r._readable._storedError}(function(e){return!Er(e)})(n)!==r._backpressure&&gn(r,!0)}function Pn(e,t){return g(e._transformAlgorithm(t),void 0,t=>{throw yn(e._controlledTransformStream,t),t})}function On(e){return new TypeError(`TransformStreamDefaultController.prototype.${e} can only be used on a TransformStreamDefaultController`)}function jn(e){void 0!==e._finishPromise_resolve&&(e._finishPromise_resolve(),e._finishPromise_resolve=void 0,e._finishPromise_reject=void 0)}function qn(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 kn(e){return new TypeError(`TransformStream.prototype.${e} can only be used on a TransformStream`)}Object.defineProperties(wn.prototype,{enqueue:{enumerable:!0},error:{enumerable:!0},terminate:{enumerable:!0},desiredSize:{enumerable:!0}}),s(wn.prototype.enqueue,"enqueue"),s(wn.prototype.error,"error"),s(wn.prototype.terminate,"terminate"),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(wn.prototype,Symbol.toStringTag,{value:"TransformStreamDefaultController",configurable:!0});var En=function(e,t){return(En=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 Cn(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}En(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}function xn(e){if(!e)throw new TypeError("Assertion failed")}function An(){}function In(e){return"object"==typeof e&&null!==e||"function"==typeof e}function Wn(e){if("function"!=typeof e)return!1;var t=!1;try{new e({start:function(){t=!0}})}catch(e){}return t}function Un(e){return!!In(e)&&"function"==typeof e.getReader}function Bn(e){try{return e.getReader({mode:"byob"}).releaseLock(),!0}catch(e){return!1}}function Mn(e,t){var r=(void 0===t?{}:t).type;return xn(Un(e)),xn(!1===e.locked),"bytes"===(r=Ln(r))?new Nn(e):new Fn(e)}function Ln(e){var t=String(e);if("bytes"===t)return t;if(void 0===e)return e;throw new RangeError("Invalid type is specified")}var zn=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 xn(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;xn(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(An)},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}(),Fn=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return Cn(t,e),t.prototype.pull=function(){return this._pullWithDefaultReader()},t}(zn);function Dn(e){return new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}var Nn=function(e){function t(t){var r=this,n=Bn(t);return(r=e.call(this,t)||this)._supportsByob=n,r}return Cn(t,e),Object.defineProperty(t.prototype,"type",{get:function(){return"bytes"},enumerable:!1,configurable:!0}),t.prototype._attachByobReader=function(){if("byob"!==this._readerMode){xn(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=Dn(e);Dn(t).set(r,0)}(r.value,e.view),e.respond(r.value.byteLength))}));return this._setPendingRead(n),n},t}(zn);!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(An)}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(An),r._writer.abort(e).catch(An)},this._onTerminate=function(){r._flushResolve(),r._transformStreamController.terminate();var e=new TypeError("TransformStream terminated");r._writer.abort(e).catch(An)},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 Gn=[239,187,191];function $n(e){return Gn.every((function(t,r){return e.charCodeAt(r)===t}))}var Hn=r(410),Yn=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())}))},Jn=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])}}},Qn=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)}))}}},Vn="function"==typeof globalThis.ReadableStream&&"function"==typeof globalThis.TransformStream&&"function"==typeof globalThis.ReadableStream.prototype.pipeThrough,Xn=Vn?globalThis.ReadableStream:$r,Kn=Vn?globalThis.TransformStream:bn,Zn=function(){var e;return new Kn({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&&$n(r)&&(r=r.slice(Gn.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)}})},eo=Vn?function(e){return e}:function(e){xn(function(e){return!!Wn(e)&&!!Un(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=Ln(o))||t||(o=void 0),r.constructor===e&&("bytes"!==o||Bn(r)))return r;if("bytes"===o){var i=Mn(r,{type:o});return new e(i)}i=Mn(r);return new e(i)}}(Xn),to=function(){function e(e,t){void 0===e&&(e="utf-8"),void 0===t&&(t={});var r=this;this.transform=new Kn({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 Hn.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 ro(e){var t=e;return t[Symbol.asyncIterator]=function(){var t=e.getReader();return{next:function(){return Yn(this,void 0,void 0,(function(){var e,r,n;return Jn(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 no(e){return ro(e.pipeThrough(new to).pipeThrough(Zn()).pipeThrough(new Kn({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 oo(e){return ro(eo(e).pipeThrough(new to))}function io(e){var t,r,n,o;return Yn(this,void 0,void 0,(function(){var i,a,s,u,l,c;return Jn(this,(function(f){switch(f.label){case 0:i=oo(e),a="",f.label=1;case 1:f.trys.push([1,6,7,12]),s=!0,u=Qn(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 ao(){var e,t;return{promise:new Promise((function(r,n){e=r,t=n})),res:e,rej:t}}function so(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 uo(e){return{type:"function",function:{description:e.description,name:e.name,parameters:e.parameters}}}var lo=function(){return(lo=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)},co=function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))},fo=function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!(o=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(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},po=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=ho(t,["headers"]);return e(lo(lo({},i),{headers:lo(lo({},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 co(this,void 0,void 0,(function(){return fo(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=ho(e,["botId"]);return co(this,void 0,void 0,(function(){return fo(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=ho(e,["pageSize","pageNumber","botId"]);return co(this,void 0,void 0,(function(){var e,r;return fo(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:lo(lo({},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=ho(e,["botId","conversationId"]);return co(this,void 0,void 0,(function(){return fo(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 co(this,void 0,void 0,(function(){return fo(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 co(this,void 0,void 0,(function(){return fo(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 co(this,void 0,void 0,(function(){return fo(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 co(this,void 0,void 0,(function(){var r;return fo(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 bo(r)]}}))}))},e.prototype.generateBot=function(e,t){return co(this,void 0,void 0,(function(){var r;return fo(this,(function(n){switch(n.label){case 0:return[4,this.req({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 bo(r)]}}))}))},e.prototype.getPreview=function(e,t){return co(this,void 0,void 0,(function(){var r;return fo(this,(function(n){switch(n.label){case 0:return[4,this.req({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 bo(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 co(this,void 0,void 0,(function(){var r;return fo(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 bo(r)]}}))}))},e.prototype.join=function(e){return"".concat(this.baseUrl,"/").concat(e)},e}(),bo=function(){function e(e){var t=eo(e);this._eventSourceStream=t.pipeThrough(new to).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 ro(this.teeedStream)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"dataStream",{get:function(){return ro(this.eventSourceStream.pipeThrough(new Kn({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 ro(this.dataStream.pipeThrough(new Kn({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}(),mo=function(){return(mo=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).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())}))},vo=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 _o(e){var t=e.messages,r=e.model,n=e.temperature,o=e.tool_choice,i=e.tools,a=e.top_p;return mo(mo({},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 go=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 yo(this,void 0,void 0,(function(){var r,n;return vo(this,(function(o){switch(o.label){case 0:return r=_o(e),[4,this.req({url:this.url,data:mo(mo({},r),{stream:!1}),stream:!1,timeout:null==t?void 0:t.timeout})];case 1:return n=o.sent(),[2,mo(mo({},n),{rawResponse:n})]}}))}))},e.prototype.doStream=function(e,t){return yo(this,void 0,void 0,(function(){var r,n,o,i,a;return vo(this,(function(s){switch(s.label){case 0:return r=_o(e),n=null,[4,this.req({url:this.url,data:mo(mo({},r),{stream:!0}),stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return o=s.sent(),i=eo(o),a=no(i),[2,ro(a.pipeThrough(new Kn({transform:function(e,t){var r=e.choices.map((function(e){var t=e.delta;return null==n&&(n=so(t)),n?mo(mo({},e),{finish_reason:"tool_calls",delta:t}):e})),o=mo(mo({},e),{choices:r});t.enqueue(mo(mo({},o),{rawResponse:e}))}})))]}}))}))},e}(),wo=function(){return(wo=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 So(e){var t=e.messages,r=e.model,n=e.temperature,o=e.tool_choice,i=e.tools,a=e.top_p;return wo(wo({},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 Ro(e){return"object"!=typeof e||null==e?e:Array.isArray(e)?e.map((function(e){return Ro(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?Ro(n):n,e}),{})}var 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])}}},jo=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 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({},So(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({},So(e)),{stream:!0}),stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return n=a.sent(),o=eo(n),i=no(o),[2,ro(i.pipeThrough(new Kn({transform:function(e,t){var n=e.choices.map((function(e){var t=e.delta;return null==r&&(r=so(t)),r?To(To({},e),{finish_reason:"tool_calls",delta:t}):e})),o=To(To({},e),{choices:n});t.enqueue(To(To({},o),{rawResponse:e}))}})))]}}))}))},e}(),qo=function(){return(qo=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)},ko=function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))},Eo=function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!(o=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])}}},Co=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 ko(this,void 0,void 0,(function(){var r,n;return Eo(this,(function(o){switch(o.label){case 0:return[4,this.req({url:this.url,headers:{"X-Tc-Action":"ChatCompletions"},data:qo(qo({},So(e)),{stream:!1}),stream:!1,timeout:null==t?void 0:t.timeout})];case 1:return r=o.sent(),n=Ro(r.Response),[2,qo(qo({},n),{rawResponse:r})]}}))}))},e.prototype.doStream=function(e,t){return ko(this,void 0,void 0,(function(){var r,n,o,i;return Eo(this,(function(a){switch(a.label){case 0:return r=null,[4,this.req({url:this.url,headers:{"X-Tc-Action":"ChatCompletions"},data:qo(qo({},e),{stream:!0}),stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return n=a.sent(),o=eo(n),i=no(o),[2,ro(i.pipeThrough(new Kn({transform:function(e,t){var n=Ro(e),o=n.choices.map((function(e){var t=e.delta;return null==r&&(r=so(t)),r?qo(qo({},e),{finish_reason:"tool_calls",delta:t}):e})),i=qo(qo({},n),{choices:o});t.enqueue(qo(qo({},i),{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)},Ao=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())}))},Io=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 Wo(e){var t=e.messages,r=e.model,n=e.temperature,o=e.tools,i=e.top_p;return xo(xo({},e),{messages:t,model:r,tools:o,top_p:i,temperature:n})}var Uo=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 Ao(this,void 0,void 0,(function(){var r;return Io(this,(function(n){switch(n.label){case 0:return[4,this.req({url:this.url,data:xo(xo({},Wo(e)),{stream:!1}),stream:!1,timeout:null==t?void 0:t.timeout})];case 1:return r=n.sent(),[2,xo(xo({},r),{rawResponse:r})]}}))}))},e.prototype.doStream=function(e,t){return Ao(this,void 0,void 0,(function(){var r,n,o,i;return Io(this,(function(a){switch(a.label){case 0:return r=null,[4,this.req({url:this.url,data:xo(xo({},Wo(e)),{stream:!0}),stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return n=a.sent(),o=eo(n),i=no(o),[2,ro(i.pipeThrough(new Kn({transform:function(e,t){var n=e.choices.map((function(e){var t=e.delta;return null==r&&(r=so(t)),r?xo(xo({},e),{finish_reason:"tool_calls",delta:t}):e})),o=xo(xo({},e),{choices:n});t.enqueue(xo(xo({},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)},Mo=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())}))},Lo=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 zo(e){var t=e.messages,r=e.model,n=e.temperature,o=e.tools,i=e.top_p;return Bo(Bo({},e),{messages:t,model:r,tools:o,top_p:i,temperature:n})}var Fo=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 Mo(this,void 0,void 0,(function(){var r;return Lo(this,(function(n){switch(n.label){case 0:return[4,this.req({url:this.url,data:Bo(Bo({},zo(e)),{stream:!1}),stream:!1,timeout:null==t?void 0:t.timeout})];case 1:return r=n.sent(),[2,Bo(Bo({},r),{rawResponse:r})]}}))}))},e.prototype.doStream=function(e,t){return Mo(this,void 0,void 0,(function(){var r,n,o,i;return Lo(this,(function(a){switch(a.label){case 0:return r=null,[4,this.req({url:this.url,data:Bo(Bo({},zo(e)),{stream:!0}),stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return n=a.sent(),o=eo(n),i=no(o),[2,ro(i.pipeThrough(new Kn({transform:function(e,t){var n=e.choices.map((function(e){var t=Object.assign(e.delta,{role:"assistant"});return null==r&&(r=so(t)),Bo(Bo({},e),r?{finish_reason:"tool_calls",delta:t}:{delta:t})})),o=Bo(Bo({},e),{choices:n});t.enqueue(Bo(Bo({},o),{rawResponse:e}))}})))]}}))}))},e}(),Do=function(){return(Do=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).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())}))},Go=function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!(o=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 $o(e){var t=e.messages,r=e.model,n=e.temperature,o=e.tools,i=e.top_p;return Do(Do({},e),{messages:t,model:r,tools:o,top_p:i,temperature:n})}var Ho=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 No(this,void 0,void 0,(function(){var r;return Go(this,(function(n){switch(n.label){case 0:return[4,this.req({url:this.url,data:Do(Do({},$o(e)),{stream:!1}),stream:!1,timeout:null==t?void 0:t.timeout})];case 1:return r=n.sent(),[2,Do(Do({},r),{rawResponse:r})]}}))}))},e.prototype.doStream=function(e,t){return No(this,void 0,void 0,(function(){var r,n,o,i;return Go(this,(function(a){switch(a.label){case 0:return r=null,[4,this.req({url:this.url,data:Do(Do({},$o(e)),{stream:!0}),stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return n=a.sent(),o=eo(n),i=no(o),[2,ro(i.pipeThrough(new Kn({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=so(t)),Do(Do({},e),r?{finish_reason:"tool_calls",delta:t}:{delta:t})})),c=Do(Do({},e),{choices:l});t.enqueue(Do(Do({},c),{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])}}};function Vo(e){var t=e.messages,r=e.model,n=e.temperature,o=e.tools,i=e.top_p;return Yo(Yo({},e),{messages:t,model:r,tools:o,top_p:i,temperature:n})}var Xo,Ko=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 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({},Vo(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({},Vo(e)),{stream:!0}),stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return n=a.sent(),o=eo(n),i=no(o),[2,ro(i.pipeThrough(new Kn({transform:function(e,t){var n=e.choices.map((function(e){var t=e.delta;return null==r&&(r=so(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}(),Zo=function(){return(Zo=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)},ei=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())}))},ti=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])}}},ri=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 ei(this,void 0,void 0,(function(){var t;return ti(this,(function(r){switch(r.label){case 0:return[4,this.req({url:this.url,data:Zo(Zo({},So(e)),{stream:!1}),stream:!1})];case 1:return t=r.sent(),[2,Zo(Zo({},t),{rawResponse:t})]}}))}))},e.prototype.doStream=function(e){return ei(this,void 0,void 0,(function(){var t,r,n,o;return ti(this,(function(i){switch(i.label){case 0:return t=null,[4,this.req({url:this.url,data:Zo(Zo({},So(e)),{stream:!0}),stream:!0})];case 1:return r=i.sent(),n=eo(r),o=no(n),[2,ro(o.pipeThrough(new Kn({transform:function(e,r){var n=e.choices.map((function(e){var r=e.delta;return null==t&&(t=so(r)),t?Zo(Zo({},e),{finish_reason:"tool_calls",delta:r}):e})),o=Zo(Zo({},e),{choices:n});r.enqueue(Zo(Zo({},o),{rawResponse:e}))}})))]}}))}))},e}(),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)},oi=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())}))},ii=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])}}},ai=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 oi(this,void 0,void 0,(function(){var r;return ii(this,(function(n){switch(n.label){case 0:return[4,this.req({url:this.url,data:ni(ni({},So(e)),{stream:!1}),stream:!1,timeout:null==t?void 0:t.timeout})];case 1:return r=n.sent(),[2,ni(ni({},r),{rawResponse:r})]}}))}))},e.prototype.doStream=function(e,t){return oi(this,void 0,void 0,(function(){var r,n,o,i;return ii(this,(function(a){switch(a.label){case 0:return r=null,[4,this.req({url:this.url,data:ni(ni({},So(e)),{stream:!0}),stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return n=a.sent(),o=eo(n),i=no(o),[2,ro(i.pipeThrough(new Kn({transform:function(e,t){var n=e.choices.map((function(e){var t=e.delta;return null==r&&(r=so(t)),r?ni(ni({},e),{finish_reason:"tool_calls",delta:t}):e})),o=ni(ni({},e),{choices:n});t.enqueue(ni(ni({},o),{rawResponse:e}))}})))]}}))}))},e}(),si=function(){return(si=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)},ui=function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))},li=function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!(o=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])}}},ci=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 ui(this,void 0,void 0,(function(){var r;return li(this,(function(n){switch(n.label){case 0:return[4,this.req({url:this.url,data:si(si({},e),{stream:!1}),stream:!1,timeout:null==t?void 0:t.timeout})];case 1:return r=n.sent(),[2,si(si({},r),{rawResponse:r})]}}))}))},e.prototype.doStream=function(e,t){return ui(this,void 0,void 0,(function(){var r,n,o,i;return li(this,(function(a){switch(a.label){case 0:return r=null,[4,this.req({url:this.url,data:si(si({},e),{stream:!0}),stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return n=a.sent(),o=eo(n),i=no(o),[2,ro(i.pipeThrough(new Kn({transform:function(e,t){var n=e.choices.map((function(e){var t=e.delta;return null==r&&(r=so(t)),r?si(si({},e),{finish_reason:"tool_calls",delta:t}):e})),o=si(si({},e),{choices:n});t.enqueue(si(si({},o),{rawResponse:e}))}})))]}}))}))},e}(),fi=function(){return(fi=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)},di=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())}))},hi=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])}}},pi=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 di(this,void 0,void 0,(function(){var t;return hi(this,(function(r){switch(r.label){case 0:return[4,this.req({url:this.url,data:fi(fi({},e),{stream:!1}),stream:!1})];case 1:return t=r.sent(),[2,fi(fi({},t),{rawResponse:t})]}}))}))},e.prototype.doStream=function(e){return di(this,void 0,void 0,(function(){var t,r,n,o;return hi(this,(function(i){switch(i.label){case 0:return t=null,[4,this.req({url:this.url,data:fi(fi({},e),{stream:!0}),stream:!0})];case 1:return r=i.sent(),n=eo(r),o=no(n),[2,ro(o.pipeThrough(new Kn({transform:function(e,r){var n=e.choices.map((function(e){var r=e.delta;return null==t&&(t=so(r)),t?fi(fi({},e),{finish_reason:"tool_calls",delta:r}):e})),o=fi(fi({},e),{choices:n});r.enqueue(fi(fi({},o),{rawResponse:e}))}})))]}}))}))},e}(),bi=(Xo=function(e,t){return(Xo=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}Xo(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}),mi=function(e){function t(t,r){var n=e.call(this,t)||this;return n.name="InvalidParamsError",n.code="INVALID_PARAMS",n.field=r,n}return bi(t,e),t.prototype.toJSON=function(){return{code:this.code,message:this.message,field:this.field}},t}(Error),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())}))},vi=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])}}},_i=function(){function e(e,t,r){this.req=e,this.baseUrl=t,this.provider=r,this.defaultGenerateImageSubUrl="images/ar/generations",this.generateImageSubUrlConfig={"hunyuan-image":[[/^hunyuan-image(-v[12](\..*)?)?$/,"images/generations"]]},this.generateImage=this.generateImageImpl.bind(this)}return e.prototype.generateImageImpl=function(e){return yi(this,void 0,void 0,(function(){var t,r,n,o,i;return vi(this,(function(a){switch(a.label){case 0:if("object"==typeof e&&e&&"model"in e&&"HY-Image-v3.0-I2I-ToB-v1.0.1"===e.model&&(""===this.provider||"hunyuan-image"===this.provider)){if(r=(t=e).image_urls,n=t.images,r&&r.length>1)throw new mi("当模型为 HY-Image-v3.0-I2I-ToB-v1.0.1 时,image_urls 最多只能有 1 个元素","image_urls");if(n&&n.length>1)throw new mi("当模型为 HY-Image-v3.0-I2I-ToB-v1.0.1 时,images 最多只能有 1 个元素","images")}return o=this.defaultGenerateImageSubUrl,"object"==typeof e&&e&&"model"in e&&"string"==typeof e.model&&(i=this.getGenerateImageSubUrl(this.provider,e.model))&&(o=i),[4,this.req({url:this.getGenerateUrl(o),data:e,stream:!1})];case 1:return[2,a.sent()]}}))}))},e.prototype.getGenerateUrl=function(e){return"".concat(this.baseUrl,"/").concat(this.provider,"/").concat(e)},e.prototype.getGenerateImageSubUrl=function(e,t){var r=this.generateImageSubUrlConfig[e];if(r)for(var n=0,o=r;n<o.length;n++){var i=o[n],a=i[0],s=i[1];if(a.test(t))return s}},e}(),gi=function(){return(gi=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)},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())}))},Si=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])}}},Ri=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},Ti=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)}))}}},Pi=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 Oi(e){var t,r=e.onStepFinish,n=e.abortSignal,o=e.maxSteps,i=e.topP,a=e.toolChoice,s=Ri(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},gi(gi({},s),{tools:null===(t=s.tools)||void 0===t?void 0:t.map((function(e){return"fn"in e?uo(e):e})),top_p:null!=i?i:s.top_p,tool_choice:null!=a?a:s.tool_choice})]}var ji=function(){function e(e){this.model=e}return e.prototype.generateText=function(e,t){var r,n;return wi(this,void 0,void 0,(function(){var o,i,a,s,u,l,c,f,d,h,p,b,m,y,v,_,g,w,S,R,T,P=this;return Si(this,(function(O){switch(O.label){case 0:return o=[],i={completion_tokens:0,prompt_tokens:0,total_tokens:0},a=Oi(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=qi(h))))return[3,9];m=xi(h.usage),Ai(i,m),O.label=3;case 3:return O.trys.push([3,7,,8]),[4,Ci(b)];case 4:return y=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:y,stepUsage:m,totalUsage:Object.assign({},i)})];case 5:return O.sent(),ki(f.messages,v.message,y),[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?Pi(Pi([],f.messages,!0),[w],!1):f.messages,T=xi(h.usage),Ai(i,T),[4,null==u?void 0:u({finishReason:g.finish_reason,messages:R.slice(),text:S,toolCall:qi(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 wi(this,void 0,void 0,(function(){var n,o,i,a,s,u,l,c,f,d,h,p,b,m,y,v,_,g,w,S,R,T,P,O,j,q,k,E,C,x,A,I,W,U,B,M,L=this;return Si(this,(function(z){switch(z.label){case 0:return n={completion_tokens:0,prompt_tokens:0,total_tokens:0},o=Oi(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=ro(t),function(e){var t,r,n,o,i,a,s,u,l,c;return wi(this,void 0,void 0,(function(){var f,d,h,p,b,m,y,v,_,g,w,S,R;return Si(this,(function(T){switch(T.label){case 0:f={completion_tokens:0,prompt_tokens:0,total_tokens:0},d=ro(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,m=Ti(d),T.label=2;case 2:return[4,m.next()];case 3:if(y=T.sent(),t=y.done)return[3,5];o=y.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=m.return)?[3,9]:[4,n.call(m)];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];m=h.message,y=h.usage,Ai(n,y),v=null===(r=m.tool_calls)||void 0===r?void 0:r[0],z.label=5;case 5:return z.trys.push([5,9,,10]),[4,Ci(v)];case 6:return _=z.sent(),[4,null==a?void 0:a({finishReason:"tool_calls",messages:l.messages.slice(),text:m.content,toolCall:v,toolResult:_,stepUsage:y,totalUsage:Object.assign({},n)})];case 7:return z.sent(),ki(l.messages,m,_),[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:ro(S),textStream:ro(R.pipeThrough(new Kn({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,Ai(n,P),O=Pi(Pi([],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(Pi(Pi([],l.messages,!0),[T],!1)),dataStream:ro(q),textStream:ro(k.pipeThrough(new Kn({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=ao(),C=ao(),x={role:"assistant",content:""},A="",I={completion_tokens:0,prompt_tokens:0,total_tokens:0},W=f.pipeThrough(new Kn({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(Pi(Pi([],l.messages,!0),[x],!1)),Ai(n,I),C.res(Object.assign({},n)),null==a||a({messages:Pi(Pi([],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:ro(B),textStream:ro(M.pipeThrough(new Kn({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 qi(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&&so(o)?o.tool_calls[0]:null}function ki(e,t,r){e.push(t,{role:"tool",tool_call_id:t.tool_calls[0].id,content:JSON.stringify(r)})}var Ei=new Map;function Ci(e){return Ei.get(e.function.name)(JSON.parse(e.function.arguments))}function xi(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 Ai(e,t){e.completion_tokens+=t.completion_tokens,e.prompt_tokens+=t.prompt_tokens,e.total_tokens+=t.total_tokens}var Ii={hunyuan:Co,"hunyuan-beta":jo,ark:Uo,dashscope:Fo,"01-ai":Ho,moonshot:Ko,zhipu:go,"hunyuan-exp":ri,"hunyuan-open":ai,deepseek:ci},Wi="@cloudbase/js-sdk";function Ui(){return Wi}var Bi="https:";"undefined"==typeof process||process.env;var Mi,Li="INVALID_PARAMS",zi="INVALID_OPERATION",Fi="OPERATION_FAIL";!function(e){e.local="local",e.none="none",e.session="session"}(Mi||(Mi={}));var Di=function(){},Ni=function(){},Gi=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)}}();function $i(e,t){console.warn("[".concat(Ui(),"][").concat(e,"]:").concat(t))}!function(e){function t(t){var r=e.call(this,t.msg||t.message||"")||this;return r.code=t.code||"",r.requestId=t.requestId||"",Object.defineProperty(r,"message",{value:t.msg||t.message||"",enumerable:!0,writable:!0,configurable:!0}),r}Gi(t,e)}(Error);var Hi=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)}}(),Yi=function(){return(Yi=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)},Ji=function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))},Qi=function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!(o=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}Hi(t,e),t.prototype.get=function(e){return this.request(Yi(Yi({},e),{method:"get"}),this.restrictedMethods.includes("get"))},t.prototype.post=function(e){return this.request(Yi(Yi({},e),{method:"post"}),this.restrictedMethods.includes("post"))},t.prototype.put=function(e){return this.request(Yi(Yi({},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(Yi(Yi({},e),{data:u,method:s}),this.restrictedMethods.includes("upload"))):this.request(Yi(Yi({},e),{method:"put",headers:a,body:r}),this.restrictedMethods.includes("upload"))},t.prototype.download=function(e){return Ji(this,void 0,void 0,(function(){var t,r,n,o;return Qi(this,(function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,this.get(Yi(Yi({},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 Ji(this,void 0,void 0,(function(){var r,n,o,i,a,s,u,l,c,f,d,h,p,b=this;return Qi(this,(function(m){switch(m.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,Yi(Yi({},e),{signal:r.signal})).then((function(e){return Ji(b,void 0,void 0,(function(){var t,r,n;return Qi(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){return clearTimeout(h),Promise.reject(e)}))];case 1:return p=m.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,response:p}]}}))}))},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=e.url,a=e.headers,s=void 0===a?{}:a,u=e.data,l=e.responseType,c=e.withCredentials,f=e.body,d=e.onUploadProgress,h=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)}(Bi,i,"get"===n?u:{}),p=new XMLHttpRequest;p.open(n,h),l&&(p.responseType=l);var b,m,y,v=e.signal;v&&(v.aborted?p.abort():v.addEventListener("abort",(function(){return p.abort()}),{once:!0})),Object.keys(s).forEach((function(e){p.setRequestHeader(e,s[e])})),d&&p.upload.addEventListener("progress",d),p.onreadystatechange=function(){var e={};if(4===p.readyState){var t=p.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=p.status;try{e.data="blob"===l?p.response:JSON.parse(p.responseText)}catch(t){e.data="blob"===l?p.response:p.responseText}clearTimeout(b),o(e)}},t&&r.timeout&&(b=setTimeout((function(){console.warn(r.timeoutMsg),p.abort()}),r.timeout)),y=u,m="[object FormData]"===Object.prototype.toString.call(y)?u:"application/x-www-form-urlencoded"===s["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("&")}(u):f||(u?JSON.stringify(u):void 0),c&&(p.withCredentials=!0),p.send(m)}))}}(Di);var Vi;!function(e){e.WEB="web",e.WX_MP="wx_mp"}(Vi||(Vi={}));var Xi=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)}}(),Ki=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())}))},Zi=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])}}},ea=function(e){function t(t){var r=e.call(this)||this;return r.root=t,t.tcbCacheObject||(t.tcbCacheObject={}),r}return Xi(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}(Ni);!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:($i(Li,"localStorage is not supported on current platform"),new ea(t.root));case"none":return new ea(t.root);default:return t.localStorage?t.localStorage:($i(Li,"localStorage is not supported on current platform"),new ea(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:Fi,msg:"[".concat(Ui(),"][").concat(Fi,"]setStore failed"),info:e}))}}else $i(zi,"current platform's storage is asynchronous, please use setStoreAsync insteed")},e.prototype.setStoreAsync=function(e,t,r){return Ki(this,void 0,void 0,(function(){var n;return Zi(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:""}$i(zi,"current platform's storage is asynchronous, please use getStoreAsync insteed")},e.prototype.getStoreAsync=function(e,t){var r;return Ki(this,void 0,void 0,(function(){var n;return Zi(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):$i(zi,"current platform's storage is asynchronous, please use removeStoreAsync insteed")},e.prototype.removeStoreAsync=function(e){return Ki(this,void 0,void 0,(function(){return Zi(this,(function(t){switch(t.label){case 0:return[4,this.storage.removeItem(e)];case 1:return t.sent(),[2]}}))}))}}();var ta=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)}}(),ra=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 na=function(e,t){this.data=t||null,this.name=e},oa=function(e){function t(t,r){var n=e.call(this,"error",{error:t,data:r})||this;return n.error=t,n}return ta(t,e),t}(na),ia=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 oa)return console.error(e.error),this;var r="string"==typeof e?new na(e,t||{}):e,n=r.name;if(this.listens(n)){r.target=this;for(var o=0,i=this.listeners[n]?ra([],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 ia;var aa=new ia;"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 sa(e){this.message=e}sa.prototype=new Error,sa.prototype.name="InvalidCharacterError";"undefined"!=typeof window&&window.atob&&window.atob.bind(window);function ua(e){this.message=e}ua.prototype=new Error,ua.prototype.name="InvalidTokenError";var la=function(){return(la=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)},ca=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())}))},fa=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])}}},da=Ii,ha=function(){function e(e,t,r,n){var o=this;this.req=e,this.baseUrl=t,this.modelRequest=function(e){var t=e.url,r=e.data,n=e.headers,i=e.stream,a=e.timeout;return ca(o,void 0,void 0,(function(){var e,o,s,u,l,c,f;return fa(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:la(la((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),n),body:JSON.stringify(r),url:this.resolveUrl(t),stream:i,timeout:a})];case 1:return o=d.sent(),s=o.data,u=o.header,[2,this.handleResponseData(s,u)]}}))}))},this.botRequest=function(e){var t=e.method,r=e.url,n=e.data,i=void 0===n?{}:n,a=e.headers,s=e.stream,u=e.timeout;return ca(o,void 0,void 0,(function(){var e,n,o,l,c,f,d,h,p;return fa(this,(function(b){switch(b.label){case 0:return e=this.resolveUrl(r),"get"!==t?[3,2]:(n=this.handleResponseData,[4,this.req.fetch({url:"".concat(e,"?").concat((m=i,Object.entries(m).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,n.apply(this,[b.sent().data])];case 2:return o={"Content-Type":"application/json"},s&&Object.assign(o,{Accept:"text/event-stream"}),[4,this.req.fetch({url:e,body:JSON.stringify(i),headers:la(la((d={},d[null===(h=this.i18n)||void 0===h?void 0:h.LANG_HEADER_KEY]=null===(p=this.i18n)||void 0===p?void 0:p.lang,d),o),a),stream:s,method:t,timeout:u})];case 3:return l=b.sent(),c=l.data,f=l.header,[2,this.handleResponseData(c,f)]}var m}))}))},this._getBaseUrl=n,this.bot=new po(this.botRequest,this.aiBotBaseUrl),this.i18n=r,aa.on("lang_change",(function(e){var t;o.i18n=(null===(t=e.data)||void 0===t?void 0:t.i18n)||o.i18n}))}return Object.defineProperty(e.prototype,"aiBaseUrl",{get:function(){return"".concat(this._getBaseUrl?this._getBaseUrl():this.baseUrl,"/ai")},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"aiBotBaseUrl",{get:function(){return"".concat(this._getBaseUrl?this._getBaseUrl():this.baseUrl,"/aibot")},enumerable:!1,configurable:!0}),e.prototype.handleResponseData=function(e,t){var r,n;return ca(this,void 0,void 0,(function(){var o,i,a,s,u=this;return fa(this,(function(l){switch(l.label){case 0:return o="".concat(this.i18n.t("请检查调用方式,或前往云开发 AI+ 首页查看文档"),":https://tcb.cloud.tencent.com/dev#/ai"),i=function(e){if("object"==typeof e&&e&&"code"in e&&"NORMAL"!==e.code)throw new Error("".concat(u.i18n.t("AI+ 请求出错,错误码"),":").concat(e.code,",").concat(u.i18n.t("错误信息"),":").concat(e.message,"\n").concat(o,"\n").concat(JSON.stringify(e,null,2)))},"object"==typeof e&&e&&"function"!=typeof e.getReader?"then"in e?[4,e]:[3,2]:[3,4];case 1:return a=l.sent(),[3,3];case 2:a=e,l.label=3;case 3:return i(s=a),[2,e];case 4:if(!("function"==typeof(null==e?void 0:e.getReader))){if("object"==typeof(s=e)&&s&&"code"in s&&"NORMAL"!==s.code)throw new Error("".concat(this.i18n.t("AI+ 请求出错,错误码"),":").concat(s.code,",").concat(this.i18n.t("错误信息"),":").concat(s.message,"\n").concat(o,"\n").concat(JSON.stringify(s,null,2)));return[2,e]}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,io(e)]:[3,6];case 5:s=l.sent(),i(s),l.label=6;case 6:return[2,e]}}))}))},e.prototype.createModel=function(e,t){var r,n=da[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 pi(this.modelRequest,this.aiBaseUrl,"".concat(e).concat(o))}return new ji(r)},e.prototype.registerModel=function(e,t){null==da[e]?da[e]=t:console.warn("AI model ".concat(e," already exists!"))},e.prototype.createImageModel=function(e){return new _i(this.modelRequest,this.aiBaseUrl,e)},e.prototype.registerFunctionTool=function(e){Ei.has(e.name)&&console.warn("AI function tool ".concat(e.name," already exists and will be overwritten!")),Ei.set(e.name,e.fn)},e.prototype.resolveUrl=function(e){if(!this._getBaseUrl)return e;var t=this._getBaseUrl();return t!==this.baseUrl&&e.startsWith(this.baseUrl)?e.replace(this.baseUrl,t):e},e}(),pa=function(){},ba=function(){return(ba=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)},ma=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())}))},ya=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])}}},va=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},_a=va(t,["MODELS"]);function ga(e){var t=e.env,r=e.baseUrl,n=e.getBaseUrl,o=e.req,i=e.getAccessToken,a=e.handleReqInstance,s=e.i18n;return new ha(function(){if(null==a){if(null==i)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 ma(void 0,void 0,void 0,(function(){var n,o,i,a,s;return ya(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=va(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(ba({headers:ba({Authorization:"Bearer ".concat(s)},i)},a))]}}))}))}}}({req:o,getAccessToken:i})}return a({req:o})}(),function(){if(null!=n)return n();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")}(),s,n)}var wa=ga;var Sa={name:"ai",entity:{ai:function(e){var t=this,r=this.request;if(null==r.fetch)throw new Error("cloudbase.request.fetch() unimplemented!");var n=function(){var e=t.getEndPointWithKey("GATEWAY"),r=e.BASE_URL,n=e.PROTOCOL;return"".concat(n).concat(r)};return(null==e?void 0:e.baseUrl)?ga({req:r,baseUrl:e.baseUrl,handleReqInstance:function(e){return e.req},i18n:this.config.i18n}):ga({req:r,baseUrl:n(),getBaseUrl:n,handleReqInstance:function(e){return e.req},i18n:this.config.i18n})}}};function Ra(e){try{e.registerComponent(Sa)}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:()=>ha,Bot:()=>po,InvalidParamsError:()=>mi,SimpleChatModel:()=>pa,createAI:()=>ga,createAi:()=>wa,models:()=>_a,registerAi:()=>Ra,utils:()=>e});var e={};r.r(e),r.d(e,{ReadableStream:()=>Xn,TextDecoderStream:()=>to,TransformStream:()=>Kn,createAsyncIterable:()=>ro,createEventSourceParserTransformStream:()=>Zn,createPromise:()=>ao,functionToolToModelTool:()=>uo,intoStandardStream:()=>no,intoTextStream:()=>oo,isToolCallAssistantMessage:()=>so,readableStream2JsonObject:()=>io,toPolyfillReadable:()=>eo});var t={};function o(){}function i(e){return"object"==typeof e&&null!==e||"function"==typeof e}r.r(t),r.d(t,{ArkSimpleModel:()=>Uo,DSSimpleModel:()=>Fo,DefaultImageModel:()=>_i,DefaultSimpleModel:()=>pi,HunYuanBetaSimpleModel:()=>jo,HunYuanExpSimpleModel:()=>ri,HunYuanOpenSimpleModel:()=>ai,HunYuanSimpleModel:()=>Co,MODELS:()=>Ii,MoonshotSimpleModel:()=>Ko,ReactModel:()=>ji,YiSimpleModel:()=>Ho,ZhiPuSimpleModel:()=>go,toolMap:()=>Ei});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 m(e,t,r){return c.call(e,t,r)}function y(e,t,r){m(m(e,t,r),void 0,a)}function v(e,t){y(e,t)}function _(e,t){y(e,void 0,t)}function g(e,t,r){return m(e,t,r)}function w(e){m(e,void 0,a)}let S=e=>{if("function"==typeof queueMicrotask)S=queueMicrotask;else{const e=p(void 0);S=t=>m(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("[[CanPullSyncSteps]]"),C=Symbol("[[ReleaseSteps]]");function x(e,t){e._ownerReadableStream=t,t._reader=e,"readable"===t._state?U(e):"closed"===t._state?function(e){U(e),L(e)}(e):B(e,t._storedError)}function A(e,t){return Xr(e._ownerReadableStream,t)}function I(e){const t=e._ownerReadableStream;"readable"===t._state?M(e,new TypeError("Reader was released and can no longer be used to monitor the stream's closedness")):function(e,t){B(e,new TypeError("Reader was released and can no longer be used to monitor the stream's closedness"))}(e),t._readableStreamController[C](),t._reader=void 0,e._ownerReadableStream=void 0}function W(e){return new TypeError("Cannot "+e+" a stream using a released reader")}function U(e){e._closedPromise=h((t,r)=>{e._closedPromise_resolve=t,e._closedPromise_reject=r})}function B(e,t){U(e),M(e,t)}function M(e,t){void 0!==e._closedPromise_reject&&(w(e._closedPromise),e._closedPromise_reject(t),e._closedPromise_resolve=void 0,e._closedPromise_reject=void 0)}function L(e){void 0!==e._closedPromise_resolve&&(e._closedPromise_resolve(void 0),e._closedPromise_resolve=void 0,e._closedPromise_reject=void 0)}const z=Number.isFinite||function(e){return"number"==typeof e&&isFinite(e)},F=Math.trunc||function(e){return e<0?Math.ceil(e):Math.floor(e)};function D(e,t){if(void 0!==e&&"object"!=typeof(r=e)&&"function"!=typeof r)throw new TypeError(t+" is not an object.");var r}function N(e,t){if("function"!=typeof e)throw new TypeError(t+" is not a function.")}function G(e,t){if(!function(e){return"object"==typeof e&&null!==e||"function"==typeof e}(e))throw new TypeError(t+" is not an object.")}function $(e,t,r){if(void 0===e)throw new TypeError(`Parameter ${t} is required in '${r}'.`)}function H(e,t,r){if(void 0===e)throw new TypeError(`${t} is required in '${r}'.`)}function Y(e){return Number(e)}function J(e){return 0===e?0:e}function Q(e,t){const r=Number.MAX_SAFE_INTEGER;let n=Number(e);if(n=J(n),!z(n))throw new TypeError(t+" is not a finite number");if(n=function(e){return J(F(e))}(n),n<0||n>r)throw new TypeError(`${t} is outside the accepted range of 0 to ${r}, inclusive`);return z(n)&&0!==n?n:0}function V(e,t){if(!Qr(e))throw new TypeError(t+" is not a ReadableStream.")}function X(e){return new re(e)}function K(e,t){e._reader._readRequests.push(t)}function Z(e,t,r){const n=e._reader._readRequests.shift();r?n._closeSteps():n._chunkSteps(t)}function ee(e){return e._reader._readRequests.length}function te(e){const t=e._reader;return void 0!==t&&!!ie(t)}class re{constructor(e){if($(e,1,"ReadableStreamDefaultReader"),V(e,"First parameter"),Vr(e))throw new TypeError("This stream has already been locked for exclusive reading by another reader");x(this,e),this._readRequests=new P}get closed(){return ie(this)?this._closedPromise:b(le("closed"))}cancel(e){return ie(this)?void 0===this._ownerReadableStream?b(W("cancel")):A(this,e):b(le("cancel"))}read(){if(!ie(this))return b(le("read"));if(void 0===this._ownerReadableStream)return b(W("read from"));const e=se(this)?new oe:new ne;return ae(this,e),e._promise}releaseLock(){if(!ie(this))throw le("releaseLock");void 0!==this._ownerReadableStream&&function(e){I(e);ue(e,new TypeError("Reader was released"))}(this)}}Object.defineProperties(re.prototype,{cancel:{enumerable:!0},read:{enumerable:!0},releaseLock:{enumerable:!0},closed:{enumerable:!0}}),s(re.prototype.cancel,"cancel"),s(re.prototype.read,"read"),s(re.prototype.releaseLock,"releaseLock"),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(re.prototype,Symbol.toStringTag,{value:"ReadableStreamDefaultReader",configurable:!0});class ne{constructor(){this._promise=h((e,t)=>{this._resolvePromise=e,this._rejectPromise=t})}_chunkSteps(e){this._resolvePromise({value:e,done:!1})}_closeSteps(){this._resolvePromise({value:void 0,done:!0})}_errorSteps(e){this._rejectPromise(e)}}class oe{constructor(){this._promise=void 0}_chunkSteps(e){this._promise=d({value:e,done:!1})}_closeSteps(){this._promise=d({value:void 0,done:!0})}_errorSteps(e){this._promise=b(e)}}function ie(e){return!!i(e)&&!!Object.prototype.hasOwnProperty.call(e,"_readRequests")&&e instanceof re}function ae(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 se(e){const t=e._ownerReadableStream;return"closed"===t._state||"errored"===t._state||t._readableStreamController[E]()}function ue(e,t){const r=e._readRequests;e._readRequests=new P,r.forEach(e=>{e._errorSteps(t)})}function le(e){return new TypeError(`ReadableStreamDefaultReader.prototype.${e} can only be used on a ReadableStreamDefaultReader`)}var ce,fe,de;function he(e){return e.slice()}function pe(e,t,r,n,o){new Uint8Array(e).set(new Uint8Array(r,n,o),t)}let be=e=>(be="function"==typeof e.transfer?e=>e.transfer():"function"==typeof structuredClone?e=>structuredClone(e,{transfer:[e]}):e=>e,be(e)),me=e=>(me="boolean"==typeof e.detached?e=>e.detached:e=>0===e.byteLength,me(e));function ye(e,t,r){if(e.slice)return e.slice(t,r);const n=r-t,o=new ArrayBuffer(n);return pe(o,0,e,t,n),o}function ve(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 _e(e){try{const t=e.done,r=e.value;return m(d(r),e=>({done:t,value:e}))}catch(e){return b(e)}}const ge=null!==(de=null!==(ce=Symbol.asyncIterator)&&void 0!==ce?ce:null===(fe=Symbol.for)||void 0===fe?void 0:fe.call(Symbol,"Symbol.asyncIterator"))&&void 0!==de?de:"@@asyncIterator";function we(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 Se{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=this._ongoingPromise?g(this._ongoingPromise,t,t):t(),this._ongoingPromise}_nextSteps(){if(this._isFinished)return Promise.resolve({value:void 0,done:!0});const e=this._reader,t=new Re(this);return ae(e,t),t._promise}_returnSteps(e){if(this._isFinished)return Promise.resolve({value:e,done:!0});this._isFinished=!0;const t=this._reader;if(!this._preventCancel){const r=A(t,e);return I(t),g(r,()=>({value:e,done:!0}))}return I(t),p({value:e,done:!0})}}class Re{constructor(e){this._iterator=e,this._promise=h((e,t)=>{this._resolvePromise=e,this._rejectPromise=t})}_chunkSteps(e){this._iterator._ongoingPromise=void 0,S(()=>this._resolvePromise({value:e,done:!1}))}_closeSteps(){const e=this._iterator;e._ongoingPromise=void 0,e._isFinished=!0,I(e._reader),this._resolvePromise({value:void 0,done:!0})}_errorSteps(e){const t=this._iterator;t._ongoingPromise=void 0,t._isFinished=!0,I(t._reader),this._rejectPromise(e)}}const Te={next(){return Pe(this)?this._asyncIteratorImpl.next():b(Oe("next"))},return(e){return Pe(this)?this._asyncIteratorImpl.return(e):b(Oe("return"))},[ge](){return this}};function Pe(e){if(!i(e))return!1;if(!Object.prototype.hasOwnProperty.call(e,"_asyncIteratorImpl"))return!1;try{return e._asyncIteratorImpl instanceof Se}catch(e){return!1}}function Oe(e){return new TypeError(`ReadableStreamAsyncIterator.${e} can only be used on a ReadableSteamAsyncIterator`)}Object.defineProperty(Te,ge,{enumerable:!1});const je=Number.isNaN||function(e){return e!=e};function qe(e){const t=ye(e.buffer,e.byteOffset,e.byteOffset+e.byteLength);return new Uint8Array(t)}function ke(e){const t=e._queue.shift();return e._queueTotalSize-=t.size,e._queueTotalSize<0&&(e._queueTotalSize=0),t.value}function Ee(e,t,r){if("number"!=typeof(n=r)||je(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 Ce(e){e._queue=new P,e._queueTotalSize=0}function xe(e){return e===DataView}function Ae(e){return xe(e)?1:e.BYTES_PER_ELEMENT}class Ie{constructor(){throw new TypeError("Illegal constructor")}get view(){if(!Be(this))throw lt("view");return this._view}respond(e){if(!Be(this))throw lt("respond");if($(e,1,"respond"),e=Q(e,"First parameter"),void 0===this._associatedReadableByteStreamController)throw new TypeError("This BYOB request has been invalidated");if(me(this._view.buffer))throw new TypeError("The BYOB request's buffer has been detached and so cannot be used as a response");at(this._associatedReadableByteStreamController,e)}respondWithNewView(e){if(!Be(this))throw lt("respondWithNewView");if($(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(me(e.buffer))throw new TypeError("The given view's buffer has been detached and so cannot be used as a response");st(this._associatedReadableByteStreamController,e)}}Object.defineProperties(Ie.prototype,{respond:{enumerable:!0},respondWithNewView:{enumerable:!0},view:{enumerable:!0}}),s(Ie.prototype.respond,"respond"),s(Ie.prototype.respondWithNewView,"respondWithNewView"),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(Ie.prototype,Symbol.toStringTag,{value:"ReadableStreamBYOBRequest",configurable:!0});class We{constructor(){throw new TypeError("Illegal constructor")}get byobRequest(){if(!Ue(this))throw ct("byobRequest");return ot(this)}get desiredSize(){if(!Ue(this))throw ct("desiredSize");return it(this)}close(){if(!Ue(this))throw ct("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`);et(this)}enqueue(e){if(!Ue(this))throw ct("enqueue");if($(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`);tt(this,e)}error(e){if(!Ue(this))throw ct("error");rt(this,e)}[q](e){Le(this),Ce(this);const t=this._cancelAlgorithm(e);return Ze(this),t}[k](e){const t=this._controlledReadableByteStream;if(this._queueTotalSize>0)return void nt(this,e);const r=this._autoAllocateChunkSize;if(void 0!==r){let n;try{n=new ArrayBuffer(r)}catch(t){return void e._errorSteps(t)}const o={buffer:n,bufferByteLength:r,byteOffset:0,byteLength:r,bytesFilled:0,minimumFill:1,elementSize:1,viewConstructor:Uint8Array,readerType:"default"};this._pendingPullIntos.push(o)}K(t,e),Me(this)}[E](){return this._queueTotalSize>0}[C](){if(this._pendingPullIntos.length>0){const e=this._pendingPullIntos.peek();e.readerType="none",this._pendingPullIntos=new P,this._pendingPullIntos.push(e)}}}function Ue(e){return!!i(e)&&!!Object.prototype.hasOwnProperty.call(e,"_controlledReadableByteStream")&&e instanceof We}function Be(e){return!!i(e)&&!!Object.prototype.hasOwnProperty.call(e,"_associatedReadableByteStreamController")&&e instanceof Ie}function Me(e){(function(e){const t=e._controlledReadableByteStream;if("readable"!==t._state)return!1;if(e._closeRequested)return!1;if(!e._started)return!1;if(te(t)&&ee(t)>0)return!0;if(bt(t)&&pt(t)>0)return!0;return it(e)>0})(e)&&(e._pulling?e._pullAgain=!0:(e._pulling=!0,y(e._pullAlgorithm(),()=>(e._pulling=!1,e._pullAgain&&(e._pullAgain=!1,Me(e)),null),t=>(rt(e,t),null))))}function Le(e){Qe(e),e._pendingPullIntos=new P}function ze(e,t){let r=!1;"closed"===e._state&&(r=!0);const n=De(t);"default"===t.readerType?Z(e,n,r):function(e,t,r){const n=e._reader._readIntoRequests.shift();r?n._closeSteps(t):n._chunkSteps(t)}(e,n,r)}function Fe(e,t){for(let r=0;r<t.length;++r)ze(e,t[r])}function De(e){const t=e.bytesFilled,r=e.elementSize;return new e.viewConstructor(e.buffer,e.byteOffset,t/r)}function Ne(e,t,r,n){e._queue.push({buffer:t,byteOffset:r,byteLength:n}),e._queueTotalSize+=n}function Ge(e,t,r,n){let o;try{o=ye(t,r,r+n)}catch(t){throw rt(e,t),t}Ne(e,o,0,n)}function $e(e,t){t.bytesFilled>0&&Ge(e,t.buffer,t.byteOffset,t.bytesFilled),Ke(e)}function He(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;pe(t.buffer,i,r.buffer,r.byteOffset,n),r.byteLength===n?s.shift():(r.byteOffset+=n,r.byteLength-=n),e._queueTotalSize-=n,Ye(e,n,t),o-=n}return i}function Ye(e,t,r){r.bytesFilled+=t}function Je(e){0===e._queueTotalSize&&e._closeRequested?(Ze(e),Kr(e._controlledReadableByteStream)):Me(e)}function Qe(e){null!==e._byobRequest&&(e._byobRequest._associatedReadableByteStreamController=void 0,e._byobRequest._view=null,e._byobRequest=null)}function Ve(e){const t=[];for(;e._pendingPullIntos.length>0&&0!==e._queueTotalSize;){const r=e._pendingPullIntos.peek();He(e,r)&&(Ke(e),t.push(r))}return t}function Xe(e,t){const r=e._pendingPullIntos.peek();Qe(e),"closed"===e._controlledReadableByteStream._state?function(e,t){"none"===t.readerType&&Ke(e);const r=e._controlledReadableByteStream;if(bt(r)){const t=[];for(;t.length<pt(r);)t.push(Ke(e));Fe(r,t)}}(e,r):function(e,t,r){if(Ye(0,t,r),"none"===r.readerType){$e(e,r);const t=Ve(e);return void Fe(e._controlledReadableByteStream,t)}if(r.bytesFilled<r.minimumFill)return;Ke(e);const n=r.bytesFilled%r.elementSize;if(n>0){const t=r.byteOffset+r.bytesFilled;Ge(e,r.buffer,t-n,n)}r.bytesFilled-=n;const o=Ve(e);ze(e._controlledReadableByteStream,r),Fe(e._controlledReadableByteStream,o)}(e,t,r),Me(e)}function Ke(e){return e._pendingPullIntos.shift()}function Ze(e){e._pullAlgorithm=void 0,e._cancelAlgorithm=void 0}function et(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 rt(e,t),t}}Ze(e),Kr(t)}}function tt(e,t){const r=e._controlledReadableByteStream;if(e._closeRequested||"readable"!==r._state)return;const{buffer:n,byteOffset:o,byteLength:i}=t;if(me(n))throw new TypeError("chunk's buffer is detached and so cannot be enqueued");const a=be(n);if(e._pendingPullIntos.length>0){const t=e._pendingPullIntos.peek();if(me(t.buffer))throw new TypeError("The BYOB request's buffer has been detached and so cannot be filled with an enqueued chunk");Qe(e),t.buffer=be(t.buffer),"none"===t.readerType&&$e(e,t)}te(r)?(function(e){const t=e._controlledReadableByteStream._reader;for(;t._readRequests.length>0;){if(0===e._queueTotalSize)return;nt(e,t._readRequests.shift())}}(e),0===ee(r)?Ne(e,a,o,i):(e._pendingPullIntos.length>0&&Ke(e),Z(r,new Uint8Array(a,o,i),!1))):bt(r)?(Ne(e,a,o,i),Fe(r,Ve(e))):Ne(e,a,o,i),Me(e)}function rt(e,t){const r=e._controlledReadableByteStream;"readable"===r._state&&(Le(e),Ce(e),Ze(e),Zr(r,t))}function nt(e,t){const r=e._queue.shift();e._queueTotalSize-=r.byteLength,Je(e);const n=new Uint8Array(r.buffer,r.byteOffset,r.byteLength);t._chunkSteps(n)}function ot(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(Ie.prototype);!function(e,t,r){e._associatedReadableByteStreamController=t,e._view=r}(n,e,r),e._byobRequest=n}return e._byobRequest}function it(e){const t=e._controlledReadableByteStream._state;return"errored"===t?null:"closed"===t?0:e._strategyHWM-e._queueTotalSize}function at(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=be(r.buffer),Xe(e,t)}function st(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=be(t.buffer),Xe(e,n)}function ut(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,Ce(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,y(p(r()),()=>(t._started=!0,Me(t),null),e=>(rt(t,e),null))}function lt(e){return new TypeError(`ReadableStreamBYOBRequest.prototype.${e} can only be used on a ReadableStreamBYOBRequest`)}function ct(e){return new TypeError(`ReadableByteStreamController.prototype.${e} can only be used on a ReadableByteStreamController`)}function ft(e,t){if("byob"!=(e=""+e))throw new TypeError(`${t} '${e}' is not a valid enumeration value for ReadableStreamReaderMode`);return e}function dt(e){return new mt(e)}function ht(e,t){e._reader._readIntoRequests.push(t)}function pt(e){return e._reader._readIntoRequests.length}function bt(e){const t=e._reader;return void 0!==t&&!!_t(t)}Object.defineProperties(We.prototype,{close:{enumerable:!0},enqueue:{enumerable:!0},error:{enumerable:!0},byobRequest:{enumerable:!0},desiredSize:{enumerable:!0}}),s(We.prototype.close,"close"),s(We.prototype.enqueue,"enqueue"),s(We.prototype.error,"error"),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(We.prototype,Symbol.toStringTag,{value:"ReadableByteStreamController",configurable:!0});class mt{constructor(e){if($(e,1,"ReadableStreamBYOBReader"),V(e,"First parameter"),Vr(e))throw new TypeError("This stream has already been locked for exclusive reading by another reader");if(!Ue(e._readableStreamController))throw new TypeError("Cannot construct a ReadableStreamBYOBReader for a stream not constructed with a byte source");x(this,e),this._readIntoRequests=new P}get closed(){return _t(this)?this._closedPromise:b(St("closed"))}cancel(e){return _t(this)?void 0===this._ownerReadableStream?b(W("cancel")):A(this,e):b(St("cancel"))}read(e,t={}){if(!_t(this))return b(St("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(me(e.buffer))return b(new TypeError("view's buffer has been detached"));let r;try{r=function(e,t){var r;return D(e,t),{min:Q(null!==(r=null==e?void 0:e.min)&&void 0!==r?r:1,t+" has member 'min' that")}}(t,"options")}catch(e){return b(e)}const n=r.min;if(0===n)return b(new TypeError("options.min must be greater than 0"));if(function(e){return xe(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(W("read from"));const o=function(e,t,r){const n=e._ownerReadableStream;return"errored"===n._state||function(e,t,r){const n=e._controlledReadableByteStream,o=Ae(t.constructor),{byteLength:i}=t,a=r*o;return!(e._pendingPullIntos.length>0)&&("closed"===n._state||e._queueTotalSize>=a)}(n._readableStreamController,t,r)}(this,e,n)?new vt:new yt;return gt(this,e,n,o),o._promise}releaseLock(){if(!_t(this))throw St("releaseLock");void 0!==this._ownerReadableStream&&function(e){I(e);wt(e,new TypeError("Reader was released"))}(this)}}Object.defineProperties(mt.prototype,{cancel:{enumerable:!0},read:{enumerable:!0},releaseLock:{enumerable:!0},closed:{enumerable:!0}}),s(mt.prototype.cancel,"cancel"),s(mt.prototype.read,"read"),s(mt.prototype.releaseLock,"releaseLock"),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(mt.prototype,Symbol.toStringTag,{value:"ReadableStreamBYOBReader",configurable:!0});class yt{constructor(){this._promise=h((e,t)=>{this._resolvePromise=e,this._rejectPromise=t})}_chunkSteps(e){this._resolvePromise({value:e,done:!1})}_closeSteps(e){this._resolvePromise({value:e,done:!0})}_errorSteps(e){this._rejectPromise(e)}}class vt{constructor(){this._promise=void 0}_chunkSteps(e){this._promise=d({value:e,done:!1})}_closeSteps(e){this._promise=d({value:e,done:!0})}_errorSteps(e){this._promise=b(e)}}function _t(e){return!!i(e)&&!!Object.prototype.hasOwnProperty.call(e,"_readIntoRequests")&&e instanceof mt}function gt(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=Ae(i),{byteOffset:s,byteLength:u}=t,l=r*a;let c;try{c=be(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 ht(o,n);if("closed"!==o._state){if(e._queueTotalSize>0){if(He(e,f)){const t=De(f);return Je(e),void n._chunkSteps(t)}if(e._closeRequested){const t=new TypeError("Insufficient bytes to fill elements in the given buffer");return rt(e,t),void n._errorSteps(t)}}e._pendingPullIntos.push(f),ht(o,n),Me(e)}else{const e=new i(f.buffer,f.byteOffset,0);n._closeSteps(e)}}(o._readableStreamController,t,r,n)}function wt(e,t){const r=e._readIntoRequests;e._readIntoRequests=new P,r.forEach(e=>{e._errorSteps(t)})}function St(e){return new TypeError(`ReadableStreamBYOBReader.prototype.${e} can only be used on a ReadableStreamBYOBReader`)}function Rt(e,t){const{highWaterMark:r}=e;if(void 0===r)return t;if(je(r)||r<0)throw new RangeError("Invalid highWaterMark");return r}function Tt(e){const{size:t}=e;return t||(()=>1)}function Pt(e,t){D(e,t);const r=null==e?void 0:e.highWaterMark,n=null==e?void 0:e.size;return{highWaterMark:void 0===r?void 0:Y(r),size:void 0===n?void 0:Ot(n,t+" has member 'size' that")}}function Ot(e,t){return N(e,t),t=>Y(e(t))}function jt(e,t,r){return N(e,r),r=>T(e,t,[r])}function qt(e,t,r){return N(e,r),()=>T(e,t,[])}function kt(e,t,r){return N(e,r),r=>R(e,t,[r])}function Et(e,t,r){return N(e,r),(r,n)=>T(e,t,[r,n])}function Ct(e,t){if(!Wt(e))throw new TypeError(t+" is not a WritableStream.")}class xt{constructor(e={},t={}){void 0===e?e=null:G(e,"First parameter");const r=Pt(t,"Second parameter"),n=function(e,t){D(e,t);const r=null==e?void 0:e.abort,n=null==e?void 0:e.close,o=null==e?void 0:e.start,i=null==e?void 0:e.type,a=null==e?void 0:e.write;return{abort:void 0===r?void 0:jt(r,e,t+" has member 'abort' that"),close:void 0===n?void 0:qt(n,e,t+" has member 'close' that"),start:void 0===o?void 0:kt(o,e,t+" has member 'start' that"),write:void 0===a?void 0:Et(a,e,t+" has member 'write' that"),type:i}}(e,"First parameter");if(It(this),void 0!==n.type)throw new RangeError("Invalid type is specified");const o=Tt(r);!function(e,t,r,n){const o=Object.create(Kt.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),er(e,o,i,a,s,u,r,n)}(this,n,Rt(r,1),o)}get locked(){if(!Wt(this))throw sr("locked");return Ut(this)}abort(e){return Wt(this)?Ut(this)?b(new TypeError("Cannot abort a stream that already has a writer")):Bt(this,e):b(sr("abort"))}close(){return Wt(this)?Ut(this)?b(new TypeError("Cannot close a stream that already has a writer")):Dt(this)?b(new TypeError("Cannot close an already-closing stream")):Mt(this):b(sr("close"))}getWriter(){if(!Wt(this))throw sr("getWriter");return At(this)}}function At(e){return new $t(e)}function It(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 Wt(e){return!!i(e)&&!!Object.prototype.hasOwnProperty.call(e,"_writableStreamController")&&e instanceof xt}function Ut(e){return void 0!==e._writer}function Bt(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||zt(e,t),i}function Mt(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&&_r(n),Ee(o=e._writableStreamController,Xt,0),nr(o),r}function Lt(e,t){"writable"!==e._state?Ft(e):zt(e,t)}function zt(e,t){const r=e._writableStreamController;e._state="erroring",e._storedError=t;const n=e._writer;void 0!==n&&Jt(n,t),!function(e){return void 0!==e._inFlightWriteRequest||void 0!==e._inFlightCloseRequest}(e)&&r._started&&Ft(e)}function Ft(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 Nt(e);const r=e._pendingAbortRequest;if(e._pendingAbortRequest=void 0,r._wasAlreadyErroring)return r._reject(t),void Nt(e);y(e._writableStreamController[O](r._reason),()=>(r._resolve(),Nt(e),null),t=>(r._reject(t),Nt(e),null))}function Dt(e){return void 0!==e._closeRequest||void 0!==e._inFlightCloseRequest}function Nt(e){void 0!==e._closeRequest&&(e._closeRequest._reject(e._storedError),e._closeRequest=void 0);const t=e._writer;void 0!==t&&hr(t,e._storedError)}function Gt(e,t){const r=e._writer;void 0!==r&&t!==e._backpressure&&(t?function(e){br(e)}(r):_r(r)),e._backpressure=t}Object.defineProperties(xt.prototype,{abort:{enumerable:!0},close:{enumerable:!0},getWriter:{enumerable:!0},locked:{enumerable:!0}}),s(xt.prototype.abort,"abort"),s(xt.prototype.close,"close"),s(xt.prototype.getWriter,"getWriter"),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(xt.prototype,Symbol.toStringTag,{value:"WritableStream",configurable:!0});class $t{constructor(e){if($(e,1,"WritableStreamDefaultWriter"),Ct(e,"First parameter"),Ut(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)!Dt(e)&&e._backpressure?br(this):yr(this),fr(this);else if("erroring"===t)mr(this,e._storedError),fr(this);else if("closed"===t)yr(this),fr(this),pr(this);else{const t=e._storedError;mr(this,t),dr(this,t)}}get closed(){return Ht(this)?this._closedPromise:b(lr("closed"))}get desiredSize(){if(!Ht(this))throw lr("desiredSize");if(void 0===this._ownerWritableStream)throw cr("desiredSize");return function(e){const t=e._ownerWritableStream,r=t._state;return"errored"===r||"erroring"===r?null:"closed"===r?0:rr(t._writableStreamController)}(this)}get ready(){return Ht(this)?this._readyPromise:b(lr("ready"))}abort(e){return Ht(this)?void 0===this._ownerWritableStream?b(cr("abort")):function(e,t){return Bt(e._ownerWritableStream,t)}(this,e):b(lr("abort"))}close(){if(!Ht(this))return b(lr("close"));const e=this._ownerWritableStream;return void 0===e?b(cr("close")):Dt(e)?b(new TypeError("Cannot close an already-closing stream")):Yt(this)}releaseLock(){if(!Ht(this))throw lr("releaseLock");void 0!==this._ownerWritableStream&&Qt(this)}write(e){return Ht(this)?void 0===this._ownerWritableStream?b(cr("write to")):Vt(this,e):b(lr("write"))}}function Ht(e){return!!i(e)&&!!Object.prototype.hasOwnProperty.call(e,"_ownerWritableStream")&&e instanceof $t}function Yt(e){return Mt(e._ownerWritableStream)}function Jt(e,t){"pending"===e._readyPromiseState?vr(e,t):function(e,t){mr(e,t)}(e,t)}function Qt(e){const t=e._ownerWritableStream,r=new TypeError("Writer was released and can no longer be used to monitor the stream's closedness");Jt(e,r),function(e,t){"pending"===e._closedPromiseState?hr(e,t):function(e,t){dr(e,t)}(e,t)}(e,r),t._writer=void 0,e._ownerWritableStream=void 0}function Vt(e,t){const r=e._ownerWritableStream,n=r._writableStreamController,o=function(e,t){if(void 0===e._strategySizeAlgorithm)return 1;try{return e._strategySizeAlgorithm(t)}catch(t){return or(e,t),1}}(n,t);if(r!==e._ownerWritableStream)return b(cr("write to"));const i=r._state;if("errored"===i)return b(r._storedError);if(Dt(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{Ee(e,t,r)}catch(t){return void or(e,t)}const n=e._controlledWritableStream;Dt(n)||"writable"!==n._state||Gt(n,ir(e)),nr(e)}(n,t,o),a}Object.defineProperties($t.prototype,{abort:{enumerable:!0},close:{enumerable:!0},releaseLock:{enumerable:!0},write:{enumerable:!0},closed:{enumerable:!0},desiredSize:{enumerable:!0},ready:{enumerable:!0}}),s($t.prototype.abort,"abort"),s($t.prototype.close,"close"),s($t.prototype.releaseLock,"releaseLock"),s($t.prototype.write,"write"),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty($t.prototype,Symbol.toStringTag,{value:"WritableStreamDefaultWriter",configurable:!0});const Xt={};class Kt{constructor(){throw new TypeError("Illegal constructor")}get abortReason(){if(!Zt(this))throw ur("abortReason");return this._abortReason}get signal(){if(!Zt(this))throw ur("signal");if(void 0===this._abortController)throw new TypeError("WritableStreamDefaultController.prototype.signal is not supported");return this._abortController.signal}error(e){if(!Zt(this))throw ur("error");"writable"===this._controlledWritableStream._state&&ar(this,e)}[O](e){const t=this._abortAlgorithm(e);return tr(this),t}[j](){Ce(this)}}function Zt(e){return!!i(e)&&!!Object.prototype.hasOwnProperty.call(e,"_controlledWritableStream")&&e instanceof Kt}function er(e,t,r,n,o,i,a,s){t._controlledWritableStream=e,e._writableStreamController=t,t._queue=void 0,t._queueTotalSize=void 0,Ce(t),t._abortReason=void 0,t._abortController=function(){if("function"==typeof AbortController)return new AbortController}(),t._started=!1,t._strategySizeAlgorithm=s,t._strategyHWM=a,t._writeAlgorithm=n,t._closeAlgorithm=o,t._abortAlgorithm=i;const u=ir(t);Gt(e,u),y(p(r()),()=>(t._started=!0,nr(t),null),r=>(t._started=!0,Lt(e,r),null))}function tr(e){e._writeAlgorithm=void 0,e._closeAlgorithm=void 0,e._abortAlgorithm=void 0,e._strategySizeAlgorithm=void 0}function rr(e){return e._strategyHWM-e._queueTotalSize}function nr(e){const t=e._controlledWritableStream;if(!e._started)return;if(void 0!==t._inFlightWriteRequest)return;if("erroring"===t._state)return void Ft(t);if(0===e._queue.length)return;const r=e._queue.peek().value;r===Xt?function(e){const t=e._controlledWritableStream;(function(e){e._inFlightCloseRequest=e._closeRequest,e._closeRequest=void 0})(t),ke(e);const r=e._closeAlgorithm();tr(e),y(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&&pr(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),Lt(e,t)}(t,e),null))}(e):function(e,t){const r=e._controlledWritableStream;!function(e){e._inFlightWriteRequest=e._writeRequests.shift()}(r);y(e._writeAlgorithm(t),()=>{!function(e){e._inFlightWriteRequest._resolve(void 0),e._inFlightWriteRequest=void 0}(r);const t=r._state;if(ke(e),!Dt(r)&&"writable"===t){const t=ir(e);Gt(r,t)}return nr(e),null},t=>("writable"===r._state&&tr(e),function(e,t){e._inFlightWriteRequest._reject(t),e._inFlightWriteRequest=void 0,Lt(e,t)}(r,t),null))}(e,r)}function or(e,t){"writable"===e._controlledWritableStream._state&&ar(e,t)}function ir(e){return rr(e)<=0}function ar(e,t){const r=e._controlledWritableStream;tr(e),zt(r,t)}function sr(e){return new TypeError(`WritableStream.prototype.${e} can only be used on a WritableStream`)}function ur(e){return new TypeError(`WritableStreamDefaultController.prototype.${e} can only be used on a WritableStreamDefaultController`)}function lr(e){return new TypeError(`WritableStreamDefaultWriter.prototype.${e} can only be used on a WritableStreamDefaultWriter`)}function cr(e){return new TypeError("Cannot "+e+" a stream using a released writer")}function fr(e){e._closedPromise=h((t,r)=>{e._closedPromise_resolve=t,e._closedPromise_reject=r,e._closedPromiseState="pending"})}function dr(e,t){fr(e),hr(e,t)}function hr(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 pr(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 br(e){e._readyPromise=h((t,r)=>{e._readyPromise_resolve=t,e._readyPromise_reject=r}),e._readyPromiseState="pending"}function mr(e,t){br(e),vr(e,t)}function yr(e){br(e),_r(e)}function vr(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 _r(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(Kt.prototype,{abortReason:{enumerable:!0},signal:{enumerable:!0},error:{enumerable:!0}}),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(Kt.prototype,Symbol.toStringTag,{value:"WritableStreamDefaultController",configurable:!0});const gr="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof global?global:void 0,wr=function(){const e=null==gr?void 0:gr.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 Sr(e,t,r,n,o,i){const a=X(e),s=At(t);e._disturbed=!0;const u=new Rr(s),l=new Pr(u);return h((c,f)=>{let d;if(void 0!==i){if(d=()=>{const r=void 0!==i.reason?i.reason:new wr("Aborted","AbortError"),a=[];n||a.push(()=>"writable"===t._state?Bt(t,r):p(void 0)),o||a.push(()=>"readable"===e._state?Xr(e,r):p(void 0)),T(()=>Promise.all(a.map(e=>e())),!0,r)},i.aborted)return void d();i.addEventListener("abort",d)}function _(){for(;!u._shuttingDown&&!t._backpressure&&"writable"===t._state&&!Dt(t)&&"readable"===e._state&&se(a);)ae(a,l);if(u._shuttingDown)return p(!0);if(t._backpressure)return m(s._readyPromise,_);const r=new Tr(u);return ae(a,r),r._promise}var g,S,R;if(Or(e,a._closedPromise,e=>(n?P(!0,e):T(()=>Bt(t,e),!0,e),null)),Or(t,s._closedPromise,t=>(o?P(!0,t):T(()=>Xr(e,t),!0,t),null)),g=e,S=a._closedPromise,R=()=>(r?P():T(()=>function(e){const t=e._ownerWritableStream,r=t._state;return Dt(t)||"closed"===r?p(void 0):"errored"===r?b(t._storedError):Yt(e)}(s)),null),"closed"===g._state?R():v(S,R),Dt(t)||"closed"===t._state){const t=new TypeError("the destination writable stream closed before all data could be piped to it");o?P(!0,t):T(()=>Xr(e,t),!0,t)}function T(e,r,n){function o(){return y(e(),()=>O(r,n),e=>O(!0,e)),null}u._shuttingDown||(u._shuttingDown=!0,"writable"!==t._state||Dt(t)?o():v(u._waitForWritesToFinish(),o))}function P(e,r){u._shuttingDown||(u._shuttingDown=!0,"writable"!==t._state||Dt(t)?O(e,r):v(u._waitForWritesToFinish(),()=>O(e,r)))}function O(e,t){return Qt(s),I(a),void 0!==i&&i.removeEventListener("abort",d),e?f(t):c(void 0),null}w(h((e,t)=>{!function r(n){n?e():m(_(),r,t)}(!1)}))})}class Rr{constructor(e){this._writer=e,this._shuttingDown=!1,this._currentWrite=p(void 0)}_waitForWritesToFinish(){const e=this._currentWrite;return m(this._currentWrite,()=>e!==this._currentWrite?this._waitForWritesToFinish():void 0)}}class Tr{constructor(e){this._state=e,this._promise=h((e,t)=>{this._resolvePromise=e,this._rejectPromise=t})}_chunkSteps(e){this._state._currentWrite=m(Vt(this._state._writer,e),void 0,o),this._resolvePromise(!1)}_closeSteps(){this._resolvePromise(!0)}_errorSteps(e){this._rejectPromise(e)}}class Pr{constructor(e){this._state=e}_chunkSteps(e){this._state._currentWrite=m(Vt(this._state._writer,e),void 0,o)}_closeSteps(){}_errorSteps(e){}}function Or(e,t,r){"errored"===e._state?r(e._storedError):_(t,r)}class jr{constructor(){throw new TypeError("Illegal constructor")}get desiredSize(){if(!qr(this))throw Mr("desiredSize");return Wr(this)}close(){if(!qr(this))throw Mr("close");if(!Ur(this))throw new TypeError("The stream is not in a state that permits close");xr(this)}enqueue(e){if(!qr(this))throw Mr("enqueue");if(!Ur(this))throw new TypeError("The stream is not in a state that permits enqueue");return Ar(this,e)}error(e){if(!qr(this))throw Mr("error");Ir(this,e)}[q](e){Ce(this);const t=this._cancelAlgorithm(e);return Cr(this),t}[k](e){const t=this._controlledReadableStream;if(this._queue.length>0){const r=ke(this);this._closeRequested&&0===this._queue.length?(Cr(this),Kr(t)):kr(this),e._chunkSteps(r)}else K(t,e),kr(this)}[E](){return this._queue.length>0}[C](){}}function qr(e){return!!i(e)&&!!Object.prototype.hasOwnProperty.call(e,"_controlledReadableStream")&&e instanceof jr}function kr(e){Er(e)&&(e._pulling?e._pullAgain=!0:(e._pulling=!0,y(e._pullAlgorithm(),()=>(e._pulling=!1,e._pullAgain&&(e._pullAgain=!1,kr(e)),null),t=>(Ir(e,t),null))))}function Er(e){const t=e._controlledReadableStream;return!!Ur(e)&&(!!e._started&&(!!(Vr(t)&&ee(t)>0)||Wr(e)>0))}function Cr(e){e._pullAlgorithm=void 0,e._cancelAlgorithm=void 0,e._strategySizeAlgorithm=void 0}function xr(e){if(!Ur(e))return;const t=e._controlledReadableStream;e._closeRequested=!0,0===e._queue.length&&(Cr(e),Kr(t))}function Ar(e,t){if(!Ur(e))return;const r=e._controlledReadableStream;if(Vr(r)&&ee(r)>0)Z(r,t,!1);else{let r;try{r=e._strategySizeAlgorithm(t)}catch(t){throw Ir(e,t),t}try{Ee(e,t,r)}catch(t){throw Ir(e,t),t}}kr(e)}function Ir(e,t){const r=e._controlledReadableStream;"readable"===r._state&&(Ce(e),Cr(e),Zr(r,t))}function Wr(e){const t=e._controlledReadableStream._state;return"errored"===t?null:"closed"===t?0:e._strategyHWM-e._queueTotalSize}function Ur(e){const t=e._controlledReadableStream._state;return!e._closeRequested&&"readable"===t}function Br(e,t,r,n,o,i,a){t._controlledReadableStream=e,t._queue=void 0,t._queueTotalSize=void 0,Ce(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,y(p(r()),()=>(t._started=!0,kr(t),null),e=>(Ir(t,e),null))}function Mr(e){return new TypeError(`ReadableStreamDefaultController.prototype.${e} can only be used on a ReadableStreamDefaultController`)}function Lr(e){return i(t=e)&&void 0!==t.getReader?function(e){let t;return t=Hr(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)xr(t._readableStreamController);else{const r=e.value;Ar(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=ve(t,ge)))return function(e){const t={next(){let t;try{t=we(e)}catch(e){return b(e)}return _e(t)},return(t){let r;try{const n=ve(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)?_e(r):b(new TypeError("The iterator.return() method must return an object"))}};return{iterator:t,nextMethod:t.next,done:!1}}(e(t,"sync",ve(t,Symbol.iterator)))}else n=ve(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=Hr(o,(function(){let e;try{e=we(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)xr(t._readableStreamController);else{const r=e.value;Ar(t._readableStreamController,r)}})}),(function(e){const t=r.iterator;let n;try{n=ve(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 zr(e,t,r){return N(e,r),r=>T(e,t,[r])}function Fr(e,t,r){return N(e,r),r=>T(e,t,[r])}function Dr(e,t,r){return N(e,r),r=>R(e,t,[r])}function Nr(e,t){if("bytes"!=(e=""+e))throw new TypeError(`${t} '${e}' is not a valid enumeration value for ReadableStreamType`);return e}function Gr(e,t){D(e,t);const r=null==e?void 0:e.preventAbort,n=null==e?void 0:e.preventCancel,o=null==e?void 0:e.preventClose,i=null==e?void 0:e.signal;return void 0!==i&&function(e,t){if(!function(e){if("object"!=typeof e||null===e)return!1;try{return"boolean"==typeof e.aborted}catch(e){return!1}}(e))throw new TypeError(t+" is not an AbortSignal.")}(i,t+" has member 'signal' that"),{preventAbort:Boolean(r),preventCancel:Boolean(n),preventClose:Boolean(o),signal:i}}Object.defineProperties(jr.prototype,{close:{enumerable:!0},enqueue:{enumerable:!0},error:{enumerable:!0},desiredSize:{enumerable:!0}}),s(jr.prototype.close,"close"),s(jr.prototype.enqueue,"enqueue"),s(jr.prototype.error,"error"),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(jr.prototype,Symbol.toStringTag,{value:"ReadableStreamDefaultController",configurable:!0});class $r{constructor(e={},t={}){void 0===e?e=null:G(e,"First parameter");const r=Pt(t,"Second parameter"),n=function(e,t){D(e,t);const r=e,n=null==r?void 0:r.autoAllocateChunkSize,o=null==r?void 0:r.cancel,i=null==r?void 0:r.pull,a=null==r?void 0:r.start,s=null==r?void 0:r.type;return{autoAllocateChunkSize:void 0===n?void 0:Q(n,t+" has member 'autoAllocateChunkSize' that"),cancel:void 0===o?void 0:zr(o,r,t+" has member 'cancel' that"),pull:void 0===i?void 0:Fr(i,r,t+" has member 'pull' that"),start:void 0===a?void 0:Dr(a,r,t+" has member 'start' that"),type:void 0===s?void 0:Nr(s,t+" has member 'type' that")}}(e,"First parameter");if(Jr(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(We.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");ut(e,n,o,i,a,r,s)}(this,n,Rt(r,0))}else{const e=Tt(r);!function(e,t,r,n){const o=Object.create(jr.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),Br(e,o,i,a,s,r,n)}(this,n,Rt(r,1),e)}}get locked(){if(!Qr(this))throw en("locked");return Vr(this)}cancel(e){return Qr(this)?Vr(this)?b(new TypeError("Cannot cancel a stream that already has a reader")):Xr(this,e):b(en("cancel"))}getReader(e){if(!Qr(this))throw en("getReader");return void 0===function(e,t){D(e,t);const r=null==e?void 0:e.mode;return{mode:void 0===r?void 0:ft(r,t+" has member 'mode' that")}}(e,"First parameter").mode?X(this):dt(this)}pipeThrough(e,t={}){if(!Qr(this))throw en("pipeThrough");$(e,1,"pipeThrough");const r=function(e,t){D(e,t);const r=null==e?void 0:e.readable;H(r,"readable","ReadableWritablePair"),V(r,t+" has member 'readable' that");const n=null==e?void 0:e.writable;return H(n,"writable","ReadableWritablePair"),Ct(n,t+" has member 'writable' that"),{readable:r,writable:n}}(e,"First parameter"),n=Gr(t,"Second parameter");if(Vr(this))throw new TypeError("ReadableStream.prototype.pipeThrough cannot be used on a locked ReadableStream");if(Ut(r.writable))throw new TypeError("ReadableStream.prototype.pipeThrough cannot be used on a locked WritableStream");return w(Sr(this,r.writable,n.preventClose,n.preventAbort,n.preventCancel,n.signal)),r.readable}pipeTo(e,t={}){if(!Qr(this))return b(en("pipeTo"));if(void 0===e)return b("Parameter 1 is required in 'pipeTo'.");if(!Wt(e))return b(new TypeError("ReadableStream.prototype.pipeTo's first argument must be a WritableStream"));let r;try{r=Gr(t,"Second parameter")}catch(e){return b(e)}return Vr(this)?b(new TypeError("ReadableStream.prototype.pipeTo cannot be used on a locked ReadableStream")):Ut(e)?b(new TypeError("ReadableStream.prototype.pipeTo cannot be used on a locked WritableStream")):Sr(this,e,r.preventClose,r.preventAbort,r.preventCancel,r.signal)}tee(){if(!Qr(this))throw en("tee");return he(function(e,t){return Ue(e._readableStreamController)?function(e){let t,r,n,o,i,a=X(e),s=!1,u=!1,l=!1,c=!1,f=!1;const d=h(e=>{i=e});function b(e){_(e._closedPromise,t=>(e!==a||(rt(n._readableStreamController,t),rt(o._readableStreamController,t),c&&f||i(void 0)),null))}function m(){_t(a)&&(I(a),a=X(e),b(a)),ae(a,{_chunkSteps:t=>{S(()=>{u=!1,l=!1;const r=t;let a=t;if(!c&&!f)try{a=qe(t)}catch(t){return rt(n._readableStreamController,t),rt(o._readableStreamController,t),void i(Xr(e,t))}c||tt(n._readableStreamController,r),f||tt(o._readableStreamController,a),s=!1,u?v():l&&g()})},_closeSteps:()=>{s=!1,c||et(n._readableStreamController),f||et(o._readableStreamController),n._readableStreamController._pendingPullIntos.length>0&&at(n._readableStreamController,0),o._readableStreamController._pendingPullIntos.length>0&&at(o._readableStreamController,0),c&&f||i(void 0)},_errorSteps:()=>{s=!1}})}function y(t,r){ie(a)&&(I(a),a=dt(e),b(a));const d=r?o:n,h=r?n:o;gt(a,t,1,{_chunkSteps:t=>{S(()=>{u=!1,l=!1;const n=r?f:c;if(r?c:f)n||st(d._readableStreamController,t);else{let r;try{r=qe(t)}catch(t){return rt(d._readableStreamController,t),rt(h._readableStreamController,t),void i(Xr(e,t))}n||st(d._readableStreamController,t),tt(h._readableStreamController,r)}s=!1,u?v():l&&g()})},_closeSteps:e=>{s=!1;const t=r?f:c,n=r?c:f;t||et(d._readableStreamController),n||et(h._readableStreamController),void 0!==e&&(t||st(d._readableStreamController,e),!n&&h._readableStreamController._pendingPullIntos.length>0&&at(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=ot(n._readableStreamController);return null===e?m():y(e._view,!1),p(void 0)}function g(){if(s)return l=!0,p(void 0);s=!0;const e=ot(o._readableStreamController);return null===e?m():y(e._view,!0),p(void 0)}function w(){}return n=Yr(w,v,(function(n){if(c=!0,t=n,f){const n=he([t,r]),o=Xr(e,n);i(o)}return d})),o=Yr(w,g,(function(n){if(f=!0,r=n,c){const n=he([t,r]),o=Xr(e,n);i(o)}return d})),b(a),[n,o]}(e):function(e){const t=X(e);let r,n,o,i,a,s=!1,u=!1,l=!1,c=!1;const f=h(e=>{a=e});function d(){return s?(u=!0,p(void 0)):(s=!0,ae(t,{_chunkSteps:e=>{S(()=>{u=!1;const t=e,r=e;l||Ar(o._readableStreamController,t),c||Ar(i._readableStreamController,r),s=!1,u&&d()})},_closeSteps:()=>{s=!1,l||xr(o._readableStreamController),c||xr(i._readableStreamController),l&&c||a(void 0)},_errorSteps:()=>{s=!1}}),p(void 0))}function b(){}return o=Hr(b,d,(function(t){if(l=!0,r=t,c){const t=he([r,n]),o=Xr(e,t);a(o)}return f})),i=Hr(b,d,(function(t){if(c=!0,n=t,l){const t=he([r,n]),o=Xr(e,t);a(o)}return f})),_(t._closedPromise,e=>(Ir(o._readableStreamController,e),Ir(i._readableStreamController,e),l&&c||a(void 0),null)),[o,i]}(e)}(this))}values(e){if(!Qr(this))throw en("values");return function(e,t){const r=X(e),n=new Se(r,t),o=Object.create(Te);return o._asyncIteratorImpl=n,o}(this,function(e,t){D(e,"First parameter");const r=null==e?void 0:e.preventCancel;return{preventCancel:Boolean(r)}}(e).preventCancel)}[ge](e){return this.values(e)}static from(e){return Lr(e)}}function Hr(e,t,r,n=1,o=(()=>1)){const i=Object.create($r.prototype);return Jr(i),Br(i,Object.create(jr.prototype),e,t,r,n,o),i}function Yr(e,t,r){const n=Object.create($r.prototype);return Jr(n),ut(n,Object.create(We.prototype),e,t,r,0,void 0),n}function Jr(e){e._state="readable",e._reader=void 0,e._storedError=void 0,e._disturbed=!1}function Qr(e){return!!i(e)&&!!Object.prototype.hasOwnProperty.call(e,"_readableStreamController")&&e instanceof $r}function Vr(e){return void 0!==e._reader}function Xr(e,t){if(e._disturbed=!0,"closed"===e._state)return p(void 0);if("errored"===e._state)return b(e._storedError);Kr(e);const r=e._reader;if(void 0!==r&&_t(r)){const e=r._readIntoRequests;r._readIntoRequests=new P,e.forEach(e=>{e._closeSteps(void 0)})}return g(e._readableStreamController[q](t),o)}function Kr(e){e._state="closed";const t=e._reader;if(void 0!==t&&(L(t),ie(t))){const e=t._readRequests;t._readRequests=new P,e.forEach(e=>{e._closeSteps()})}}function Zr(e,t){e._state="errored",e._storedError=t;const r=e._reader;void 0!==r&&(M(r,t),ie(r)?ue(r,t):wt(r,t))}function en(e){return new TypeError(`ReadableStream.prototype.${e} can only be used on a ReadableStream`)}function tn(e,t){D(e,t);const r=null==e?void 0:e.highWaterMark;return H(r,"highWaterMark","QueuingStrategyInit"),{highWaterMark:Y(r)}}Object.defineProperties($r,{from:{enumerable:!0}}),Object.defineProperties($r.prototype,{cancel:{enumerable:!0},getReader:{enumerable:!0},pipeThrough:{enumerable:!0},pipeTo:{enumerable:!0},tee:{enumerable:!0},values:{enumerable:!0},locked:{enumerable:!0}}),s($r.from,"from"),s($r.prototype.cancel,"cancel"),s($r.prototype.getReader,"getReader"),s($r.prototype.pipeThrough,"pipeThrough"),s($r.prototype.pipeTo,"pipeTo"),s($r.prototype.tee,"tee"),s($r.prototype.values,"values"),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty($r.prototype,Symbol.toStringTag,{value:"ReadableStream",configurable:!0}),Object.defineProperty($r.prototype,ge,{value:$r.prototype.values,writable:!0,configurable:!0});const rn=e=>e.byteLength;s(rn,"size");class nn{constructor(e){$(e,1,"ByteLengthQueuingStrategy"),e=tn(e,"First parameter"),this._byteLengthQueuingStrategyHighWaterMark=e.highWaterMark}get highWaterMark(){if(!an(this))throw on("highWaterMark");return this._byteLengthQueuingStrategyHighWaterMark}get size(){if(!an(this))throw on("size");return rn}}function on(e){return new TypeError(`ByteLengthQueuingStrategy.prototype.${e} can only be used on a ByteLengthQueuingStrategy`)}function an(e){return!!i(e)&&!!Object.prototype.hasOwnProperty.call(e,"_byteLengthQueuingStrategyHighWaterMark")&&e instanceof nn}Object.defineProperties(nn.prototype,{highWaterMark:{enumerable:!0},size:{enumerable:!0}}),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(nn.prototype,Symbol.toStringTag,{value:"ByteLengthQueuingStrategy",configurable:!0});const sn=()=>1;s(sn,"size");class un{constructor(e){$(e,1,"CountQueuingStrategy"),e=tn(e,"First parameter"),this._countQueuingStrategyHighWaterMark=e.highWaterMark}get highWaterMark(){if(!cn(this))throw ln("highWaterMark");return this._countQueuingStrategyHighWaterMark}get size(){if(!cn(this))throw ln("size");return sn}}function ln(e){return new TypeError(`CountQueuingStrategy.prototype.${e} can only be used on a CountQueuingStrategy`)}function cn(e){return!!i(e)&&!!Object.prototype.hasOwnProperty.call(e,"_countQueuingStrategyHighWaterMark")&&e instanceof un}function fn(e,t,r){return N(e,r),r=>T(e,t,[r])}function dn(e,t,r){return N(e,r),r=>R(e,t,[r])}function hn(e,t,r){return N(e,r),(r,n)=>T(e,t,[r,n])}function pn(e,t,r){return N(e,r),r=>T(e,t,[r])}Object.defineProperties(un.prototype,{highWaterMark:{enumerable:!0},size:{enumerable:!0}}),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(un.prototype,Symbol.toStringTag,{value:"CountQueuingStrategy",configurable:!0});class bn{constructor(e={},t={},r={}){void 0===e&&(e=null);const n=Pt(t,"Second parameter"),o=Pt(r,"Third parameter"),i=function(e,t){D(e,t);const r=null==e?void 0:e.cancel,n=null==e?void 0:e.flush,o=null==e?void 0:e.readableType,i=null==e?void 0:e.start,a=null==e?void 0:e.transform,s=null==e?void 0:e.writableType;return{cancel:void 0===r?void 0:pn(r,e,t+" has member 'cancel' that"),flush:void 0===n?void 0:fn(n,e,t+" has member 'flush' that"),readableType:o,start:void 0===i?void 0:dn(i,e,t+" has member 'start' that"),transform:void 0===a?void 0:hn(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=Rt(o,0),s=Tt(o),u=Rt(n,1),l=Tt(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(xt.prototype);return It(a),er(a,Object.create(Kt.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 Pn(r,t)}):Pn(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 Rn(t),y(n,()=>("errored"===r._state?qn(t,r._storedError):(xr(r._readableStreamController),jn(t)),null),e=>(Ir(r._readableStreamController,e),qn(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 Rn(r),y(o,()=>("errored"===n._state?qn(r,n._storedError):(Ir(n._readableStreamController,t),jn(r)),null),e=>(Ir(n._readableStreamController,e),qn(r,e),null)),r._finishPromise}(e,t)}),r,n),e._readable=Hr(a,(function(){return function(e){return gn(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 Rn(r),y(o,()=>("errored"===n._state?qn(r,n._storedError):(or(n._writableStreamController,t),_n(e),jn(r)),null),t=>(or(n._writableStreamController,t),_n(e),qn(r,t),null)),r._finishPromise}(e,t)}),o,i),e._backpressure=void 0,e._backpressureChangePromise=void 0,e._backpressureChangePromise_resolve=void 0,gn(e,!0),e._transformStreamController=void 0}(this,h(e=>{c=e}),u,l,a,s),function(e,t){const r=Object.create(wn.prototype);let n,o,i;n=void 0!==t.transform?e=>t.transform(e,r):e=>{try{return Tn(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(!mn(this))throw kn("readable");return this._readable}get writable(){if(!mn(this))throw kn("writable");return this._writable}}function mn(e){return!!i(e)&&!!Object.prototype.hasOwnProperty.call(e,"_transformStreamController")&&e instanceof bn}function yn(e,t){Ir(e._readable._readableStreamController,t),vn(e,t)}function vn(e,t){Rn(e._transformStreamController),or(e._writable._writableStreamController,t),_n(e)}function _n(e){e._backpressure&&gn(e,!1)}function gn(e,t){void 0!==e._backpressureChangePromise&&e._backpressureChangePromise_resolve(),e._backpressureChangePromise=h(t=>{e._backpressureChangePromise_resolve=t}),e._backpressure=t}Object.defineProperties(bn.prototype,{readable:{enumerable:!0},writable:{enumerable:!0}}),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(bn.prototype,Symbol.toStringTag,{value:"TransformStream",configurable:!0});class wn{constructor(){throw new TypeError("Illegal constructor")}get desiredSize(){if(!Sn(this))throw On("desiredSize");return Wr(this._controlledTransformStream._readable._readableStreamController)}enqueue(e){if(!Sn(this))throw On("enqueue");Tn(this,e)}error(e){if(!Sn(this))throw On("error");var t;t=e,yn(this._controlledTransformStream,t)}terminate(){if(!Sn(this))throw On("terminate");!function(e){const t=e._controlledTransformStream;xr(t._readable._readableStreamController);vn(t,new TypeError("TransformStream terminated"))}(this)}}function Sn(e){return!!i(e)&&!!Object.prototype.hasOwnProperty.call(e,"_controlledTransformStream")&&e instanceof wn}function Rn(e){e._transformAlgorithm=void 0,e._flushAlgorithm=void 0,e._cancelAlgorithm=void 0}function Tn(e,t){const r=e._controlledTransformStream,n=r._readable._readableStreamController;if(!Ur(n))throw new TypeError("Readable side is not in a state that permits enqueue");try{Ar(n,t)}catch(e){throw vn(r,e),r._readable._storedError}(function(e){return!Er(e)})(n)!==r._backpressure&&gn(r,!0)}function Pn(e,t){return g(e._transformAlgorithm(t),void 0,t=>{throw yn(e._controlledTransformStream,t),t})}function On(e){return new TypeError(`TransformStreamDefaultController.prototype.${e} can only be used on a TransformStreamDefaultController`)}function jn(e){void 0!==e._finishPromise_resolve&&(e._finishPromise_resolve(),e._finishPromise_resolve=void 0,e._finishPromise_reject=void 0)}function qn(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 kn(e){return new TypeError(`TransformStream.prototype.${e} can only be used on a TransformStream`)}Object.defineProperties(wn.prototype,{enqueue:{enumerable:!0},error:{enumerable:!0},terminate:{enumerable:!0},desiredSize:{enumerable:!0}}),s(wn.prototype.enqueue,"enqueue"),s(wn.prototype.error,"error"),s(wn.prototype.terminate,"terminate"),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(wn.prototype,Symbol.toStringTag,{value:"TransformStreamDefaultController",configurable:!0});var En=function(e,t){return(En=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 Cn(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}En(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}function xn(e){if(!e)throw new TypeError("Assertion failed")}function An(){}function In(e){return"object"==typeof e&&null!==e||"function"==typeof e}function Wn(e){if("function"!=typeof e)return!1;var t=!1;try{new e({start:function(){t=!0}})}catch(e){}return t}function Un(e){return!!In(e)&&"function"==typeof e.getReader}function Bn(e){try{return e.getReader({mode:"byob"}).releaseLock(),!0}catch(e){return!1}}function Mn(e,t){var r=(void 0===t?{}:t).type;return xn(Un(e)),xn(!1===e.locked),"bytes"===(r=Ln(r))?new Nn(e):new Fn(e)}function Ln(e){var t=String(e);if("bytes"===t)return t;if(void 0===e)return e;throw new RangeError("Invalid type is specified")}var zn=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 xn(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;xn(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(An)},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}(),Fn=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return Cn(t,e),t.prototype.pull=function(){return this._pullWithDefaultReader()},t}(zn);function Dn(e){return new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}var Nn=function(e){function t(t){var r=this,n=Bn(t);return(r=e.call(this,t)||this)._supportsByob=n,r}return Cn(t,e),Object.defineProperty(t.prototype,"type",{get:function(){return"bytes"},enumerable:!1,configurable:!0}),t.prototype._attachByobReader=function(){if("byob"!==this._readerMode){xn(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=Dn(e);Dn(t).set(r,0)}(r.value,e.view),e.respond(r.value.byteLength))}));return this._setPendingRead(n),n},t}(zn);!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(An)}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(An),r._writer.abort(e).catch(An)},this._onTerminate=function(){r._flushResolve(),r._transformStreamController.terminate();var e=new TypeError("TransformStream terminated");r._writer.abort(e).catch(An)},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 Gn=[239,187,191];function $n(e){return Gn.every((function(t,r){return e.charCodeAt(r)===t}))}var Hn=r(410),Yn=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())}))},Jn=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])}}},Qn=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)}))}}},Vn="function"==typeof globalThis.ReadableStream&&"function"==typeof globalThis.TransformStream&&"function"==typeof globalThis.ReadableStream.prototype.pipeThrough,Xn=Vn?globalThis.ReadableStream:$r,Kn=Vn?globalThis.TransformStream:bn,Zn=function(){var e;return new Kn({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&&$n(r)&&(r=r.slice(Gn.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)}})},eo=Vn?function(e){return e}:function(e){xn(function(e){return!!Wn(e)&&!!Un(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=Ln(o))||t||(o=void 0),r.constructor===e&&("bytes"!==o||Bn(r)))return r;if("bytes"===o){var i=Mn(r,{type:o});return new e(i)}i=Mn(r);return new e(i)}}(Xn),to=function(){function e(e,t){void 0===e&&(e="utf-8"),void 0===t&&(t={});var r=this;this.transform=new Kn({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 Hn.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 ro(e){var t=e;return t[Symbol.asyncIterator]=function(){var t=e.getReader();return{next:function(){return Yn(this,void 0,void 0,(function(){var e,r,n;return Jn(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 no(e){return ro(e.pipeThrough(new to).pipeThrough(Zn()).pipeThrough(new Kn({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 oo(e){return ro(eo(e).pipeThrough(new to))}function io(e){var t,r,n,o;return Yn(this,void 0,void 0,(function(){var i,a,s,u,l,c;return Jn(this,(function(f){switch(f.label){case 0:i=oo(e),a="",f.label=1;case 1:f.trys.push([1,6,7,12]),s=!0,u=Qn(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 ao(){var e,t;return{promise:new Promise((function(r,n){e=r,t=n})),res:e,rej:t}}function so(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 uo(e){return{type:"function",function:{description:e.description,name:e.name,parameters:e.parameters}}}var lo=function(){return(lo=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)},co=function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))},fo=function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!(o=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(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},po=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=ho(t,["headers"]);return e(lo(lo({},i),{headers:lo(lo({},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 co(this,void 0,void 0,(function(){return fo(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=ho(e,["botId"]);return co(this,void 0,void 0,(function(){return fo(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=ho(e,["pageSize","pageNumber","botId"]);return co(this,void 0,void 0,(function(){var e,r;return fo(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:lo(lo({},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=ho(e,["botId","conversationId"]);return co(this,void 0,void 0,(function(){return fo(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 co(this,void 0,void 0,(function(){return fo(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 co(this,void 0,void 0,(function(){return fo(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 co(this,void 0,void 0,(function(){return fo(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 co(this,void 0,void 0,(function(){var r;return fo(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 bo(r)]}}))}))},e.prototype.generateBot=function(e,t){return co(this,void 0,void 0,(function(){var r;return fo(this,(function(n){switch(n.label){case 0:return[4,this.req({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 bo(r)]}}))}))},e.prototype.getPreview=function(e,t){return co(this,void 0,void 0,(function(){var r;return fo(this,(function(n){switch(n.label){case 0:return[4,this.req({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 bo(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 co(this,void 0,void 0,(function(){var r;return fo(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 bo(r)]}}))}))},e.prototype.join=function(e){return"".concat(this.baseUrl,"/").concat(e)},e}(),bo=function(){function e(e){var t=eo(e);this._eventSourceStream=t.pipeThrough(new to).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 ro(this.teeedStream)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"dataStream",{get:function(){return ro(this.eventSourceStream.pipeThrough(new Kn({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 ro(this.dataStream.pipeThrough(new Kn({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}(),mo=function(){return(mo=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).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())}))},vo=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 _o(e){var t=e.messages,r=e.model,n=e.temperature,o=e.tool_choice,i=e.tools,a=e.top_p;return mo(mo({},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 go=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 yo(this,void 0,void 0,(function(){var r,n;return vo(this,(function(o){switch(o.label){case 0:return r=_o(e),[4,this.req({url:this.url,data:mo(mo({},r),{stream:!1}),stream:!1,timeout:null==t?void 0:t.timeout})];case 1:return n=o.sent(),[2,mo(mo({},n),{rawResponse:n})]}}))}))},e.prototype.doStream=function(e,t){return yo(this,void 0,void 0,(function(){var r,n,o,i,a;return vo(this,(function(s){switch(s.label){case 0:return r=_o(e),n=null,[4,this.req({url:this.url,data:mo(mo({},r),{stream:!0}),stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return o=s.sent(),i=eo(o),a=no(i),[2,ro(a.pipeThrough(new Kn({transform:function(e,t){var r=e.choices.map((function(e){var t=e.delta;return null==n&&(n=so(t)),n?mo(mo({},e),{finish_reason:"tool_calls",delta:t}):e})),o=mo(mo({},e),{choices:r});t.enqueue(mo(mo({},o),{rawResponse:e}))}})))]}}))}))},e}(),wo=function(){return(wo=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 So(e){var t=e.messages,r=e.model,n=e.temperature,o=e.tool_choice,i=e.tools,a=e.top_p;return wo(wo({},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 Ro(e){return"object"!=typeof e||null==e?e:Array.isArray(e)?e.map((function(e){return Ro(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?Ro(n):n,e}),{})}var 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])}}},jo=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 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({},So(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({},So(e)),{stream:!0}),stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return n=a.sent(),o=eo(n),i=no(o),[2,ro(i.pipeThrough(new Kn({transform:function(e,t){var n=e.choices.map((function(e){var t=e.delta;return null==r&&(r=so(t)),r?To(To({},e),{finish_reason:"tool_calls",delta:t}):e})),o=To(To({},e),{choices:n});t.enqueue(To(To({},o),{rawResponse:e}))}})))]}}))}))},e}(),qo=function(){return(qo=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)},ko=function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))},Eo=function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!(o=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])}}},Co=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 ko(this,void 0,void 0,(function(){var r,n;return Eo(this,(function(o){switch(o.label){case 0:return[4,this.req({url:this.url,headers:{"X-Tc-Action":"ChatCompletions"},data:qo(qo({},So(e)),{stream:!1}),stream:!1,timeout:null==t?void 0:t.timeout})];case 1:return r=o.sent(),n=Ro(r.Response),[2,qo(qo({},n),{rawResponse:r})]}}))}))},e.prototype.doStream=function(e,t){return ko(this,void 0,void 0,(function(){var r,n,o,i;return Eo(this,(function(a){switch(a.label){case 0:return r=null,[4,this.req({url:this.url,headers:{"X-Tc-Action":"ChatCompletions"},data:qo(qo({},e),{stream:!0}),stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return n=a.sent(),o=eo(n),i=no(o),[2,ro(i.pipeThrough(new Kn({transform:function(e,t){var n=Ro(e),o=n.choices.map((function(e){var t=e.delta;return null==r&&(r=so(t)),r?qo(qo({},e),{finish_reason:"tool_calls",delta:t}):e})),i=qo(qo({},n),{choices:o});t.enqueue(qo(qo({},i),{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)},Ao=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())}))},Io=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 Wo(e){var t=e.messages,r=e.model,n=e.temperature,o=e.tools,i=e.top_p;return xo(xo({},e),{messages:t,model:r,tools:o,top_p:i,temperature:n})}var Uo=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 Ao(this,void 0,void 0,(function(){var r;return Io(this,(function(n){switch(n.label){case 0:return[4,this.req({url:this.url,data:xo(xo({},Wo(e)),{stream:!1}),stream:!1,timeout:null==t?void 0:t.timeout})];case 1:return r=n.sent(),[2,xo(xo({},r),{rawResponse:r})]}}))}))},e.prototype.doStream=function(e,t){return Ao(this,void 0,void 0,(function(){var r,n,o,i;return Io(this,(function(a){switch(a.label){case 0:return r=null,[4,this.req({url:this.url,data:xo(xo({},Wo(e)),{stream:!0}),stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return n=a.sent(),o=eo(n),i=no(o),[2,ro(i.pipeThrough(new Kn({transform:function(e,t){var n=e.choices.map((function(e){var t=e.delta;return null==r&&(r=so(t)),r?xo(xo({},e),{finish_reason:"tool_calls",delta:t}):e})),o=xo(xo({},e),{choices:n});t.enqueue(xo(xo({},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)},Mo=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())}))},Lo=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 zo(e){var t=e.messages,r=e.model,n=e.temperature,o=e.tools,i=e.top_p;return Bo(Bo({},e),{messages:t,model:r,tools:o,top_p:i,temperature:n})}var Fo=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 Mo(this,void 0,void 0,(function(){var r;return Lo(this,(function(n){switch(n.label){case 0:return[4,this.req({url:this.url,data:Bo(Bo({},zo(e)),{stream:!1}),stream:!1,timeout:null==t?void 0:t.timeout})];case 1:return r=n.sent(),[2,Bo(Bo({},r),{rawResponse:r})]}}))}))},e.prototype.doStream=function(e,t){return Mo(this,void 0,void 0,(function(){var r,n,o,i;return Lo(this,(function(a){switch(a.label){case 0:return r=null,[4,this.req({url:this.url,data:Bo(Bo({},zo(e)),{stream:!0}),stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return n=a.sent(),o=eo(n),i=no(o),[2,ro(i.pipeThrough(new Kn({transform:function(e,t){var n=e.choices.map((function(e){var t=Object.assign(e.delta,{role:"assistant"});return null==r&&(r=so(t)),Bo(Bo({},e),r?{finish_reason:"tool_calls",delta:t}:{delta:t})})),o=Bo(Bo({},e),{choices:n});t.enqueue(Bo(Bo({},o),{rawResponse:e}))}})))]}}))}))},e}(),Do=function(){return(Do=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).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())}))},Go=function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!(o=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 $o(e){var t=e.messages,r=e.model,n=e.temperature,o=e.tools,i=e.top_p;return Do(Do({},e),{messages:t,model:r,tools:o,top_p:i,temperature:n})}var Ho=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 No(this,void 0,void 0,(function(){var r;return Go(this,(function(n){switch(n.label){case 0:return[4,this.req({url:this.url,data:Do(Do({},$o(e)),{stream:!1}),stream:!1,timeout:null==t?void 0:t.timeout})];case 1:return r=n.sent(),[2,Do(Do({},r),{rawResponse:r})]}}))}))},e.prototype.doStream=function(e,t){return No(this,void 0,void 0,(function(){var r,n,o,i;return Go(this,(function(a){switch(a.label){case 0:return r=null,[4,this.req({url:this.url,data:Do(Do({},$o(e)),{stream:!0}),stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return n=a.sent(),o=eo(n),i=no(o),[2,ro(i.pipeThrough(new Kn({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=so(t)),Do(Do({},e),r?{finish_reason:"tool_calls",delta:t}:{delta:t})})),c=Do(Do({},e),{choices:l});t.enqueue(Do(Do({},c),{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])}}};function Vo(e){var t=e.messages,r=e.model,n=e.temperature,o=e.tools,i=e.top_p;return Yo(Yo({},e),{messages:t,model:r,tools:o,top_p:i,temperature:n})}var Xo,Ko=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 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({},Vo(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({},Vo(e)),{stream:!0}),stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return n=a.sent(),o=eo(n),i=no(o),[2,ro(i.pipeThrough(new Kn({transform:function(e,t){var n=e.choices.map((function(e){var t=e.delta;return null==r&&(r=so(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}(),Zo=function(){return(Zo=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)},ei=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())}))},ti=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])}}},ri=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 ei(this,void 0,void 0,(function(){var t;return ti(this,(function(r){switch(r.label){case 0:return[4,this.req({url:this.url,data:Zo(Zo({},So(e)),{stream:!1}),stream:!1})];case 1:return t=r.sent(),[2,Zo(Zo({},t),{rawResponse:t})]}}))}))},e.prototype.doStream=function(e){return ei(this,void 0,void 0,(function(){var t,r,n,o;return ti(this,(function(i){switch(i.label){case 0:return t=null,[4,this.req({url:this.url,data:Zo(Zo({},So(e)),{stream:!0}),stream:!0})];case 1:return r=i.sent(),n=eo(r),o=no(n),[2,ro(o.pipeThrough(new Kn({transform:function(e,r){var n=e.choices.map((function(e){var r=e.delta;return null==t&&(t=so(r)),t?Zo(Zo({},e),{finish_reason:"tool_calls",delta:r}):e})),o=Zo(Zo({},e),{choices:n});r.enqueue(Zo(Zo({},o),{rawResponse:e}))}})))]}}))}))},e}(),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)},oi=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())}))},ii=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])}}},ai=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 oi(this,void 0,void 0,(function(){var r;return ii(this,(function(n){switch(n.label){case 0:return[4,this.req({url:this.url,data:ni(ni({},So(e)),{stream:!1}),stream:!1,timeout:null==t?void 0:t.timeout})];case 1:return r=n.sent(),[2,ni(ni({},r),{rawResponse:r})]}}))}))},e.prototype.doStream=function(e,t){return oi(this,void 0,void 0,(function(){var r,n,o,i;return ii(this,(function(a){switch(a.label){case 0:return r=null,[4,this.req({url:this.url,data:ni(ni({},So(e)),{stream:!0}),stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return n=a.sent(),o=eo(n),i=no(o),[2,ro(i.pipeThrough(new Kn({transform:function(e,t){var n=e.choices.map((function(e){var t=e.delta;return null==r&&(r=so(t)),r?ni(ni({},e),{finish_reason:"tool_calls",delta:t}):e})),o=ni(ni({},e),{choices:n});t.enqueue(ni(ni({},o),{rawResponse:e}))}})))]}}))}))},e}(),si=function(){return(si=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)},ui=function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))},li=function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!(o=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])}}},ci=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 ui(this,void 0,void 0,(function(){var r;return li(this,(function(n){switch(n.label){case 0:return[4,this.req({url:this.url,data:si(si({},e),{stream:!1}),stream:!1,timeout:null==t?void 0:t.timeout})];case 1:return r=n.sent(),[2,si(si({},r),{rawResponse:r})]}}))}))},e.prototype.doStream=function(e,t){return ui(this,void 0,void 0,(function(){var r,n,o,i;return li(this,(function(a){switch(a.label){case 0:return r=null,[4,this.req({url:this.url,data:si(si({},e),{stream:!0}),stream:!0,timeout:null==t?void 0:t.timeout})];case 1:return n=a.sent(),o=eo(n),i=no(o),[2,ro(i.pipeThrough(new Kn({transform:function(e,t){var n=e.choices.map((function(e){var t=e.delta;return null==r&&(r=so(t)),r?si(si({},e),{finish_reason:"tool_calls",delta:t}):e})),o=si(si({},e),{choices:n});t.enqueue(si(si({},o),{rawResponse:e}))}})))]}}))}))},e}(),fi=function(){return(fi=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)},di=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())}))},hi=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])}}},pi=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 di(this,void 0,void 0,(function(){var t;return hi(this,(function(r){switch(r.label){case 0:return[4,this.req({url:this.url,data:fi(fi({},e),{stream:!1}),stream:!1})];case 1:return t=r.sent(),[2,fi(fi({},t),{rawResponse:t})]}}))}))},e.prototype.doStream=function(e){return di(this,void 0,void 0,(function(){var t,r,n,o;return hi(this,(function(i){switch(i.label){case 0:return t=null,[4,this.req({url:this.url,data:fi(fi({},e),{stream:!0}),stream:!0})];case 1:return r=i.sent(),n=eo(r),o=no(n),[2,ro(o.pipeThrough(new Kn({transform:function(e,r){var n=e.choices.map((function(e){var r=e.delta;return null==t&&(t=so(r)),t?fi(fi({},e),{finish_reason:"tool_calls",delta:r}):e})),o=fi(fi({},e),{choices:n});r.enqueue(fi(fi({},o),{rawResponse:e}))}})))]}}))}))},e}(),bi=(Xo=function(e,t){return(Xo=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}Xo(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}),mi=function(e){function t(t,r){var n=e.call(this,t)||this;return n.name="InvalidParamsError",n.code="INVALID_PARAMS",n.field=r,n}return bi(t,e),t.prototype.toJSON=function(){return{code:this.code,message:this.message,field:this.field}},t}(Error),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())}))},vi=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])}}},_i=function(){function e(e,t,r){this.req=e,this.baseUrl=t,this.provider=r,this.defaultGenerateImageSubUrl="images/ar/generations",this.generateImageSubUrlConfig={"hunyuan-image":[[/^hunyuan-image(-v[12](\..*)?)?$/,"images/generations"]]},this.generateImage=this.generateImageImpl.bind(this)}return e.prototype.generateImageImpl=function(e){return yi(this,void 0,void 0,(function(){var t,r,n,o,i;return vi(this,(function(a){switch(a.label){case 0:if("object"==typeof e&&e&&"model"in e&&"HY-Image-v3.0-I2I-ToB-v1.0.1"===e.model&&(""===this.provider||"hunyuan-image"===this.provider)){if(r=(t=e).image_urls,n=t.images,r&&r.length>1)throw new mi("当模型为 HY-Image-v3.0-I2I-ToB-v1.0.1 时,image_urls 最多只能有 1 个元素","image_urls");if(n&&n.length>1)throw new mi("当模型为 HY-Image-v3.0-I2I-ToB-v1.0.1 时,images 最多只能有 1 个元素","images")}return o=this.defaultGenerateImageSubUrl,"object"==typeof e&&e&&"model"in e&&"string"==typeof e.model&&(i=this.getGenerateImageSubUrl(this.provider,e.model))&&(o=i),[4,this.req({url:this.getGenerateUrl(o),data:e,stream:!1})];case 1:return[2,a.sent()]}}))}))},e.prototype.getGenerateUrl=function(e){return"".concat(this.baseUrl,"/").concat(this.provider,"/").concat(e)},e.prototype.getGenerateImageSubUrl=function(e,t){var r=this.generateImageSubUrlConfig[e];if(r)for(var n=0,o=r;n<o.length;n++){var i=o[n],a=i[0],s=i[1];if(a.test(t))return s}},e}(),gi=function(){return(gi=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)},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())}))},Si=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])}}},Ri=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},Ti=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)}))}}},Pi=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 Oi(e){var t,r=e.onStepFinish,n=e.abortSignal,o=e.maxSteps,i=e.topP,a=e.toolChoice,s=Ri(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},gi(gi({},s),{tools:null===(t=s.tools)||void 0===t?void 0:t.map((function(e){return"fn"in e?uo(e):e})),top_p:null!=i?i:s.top_p,tool_choice:null!=a?a:s.tool_choice})]}var ji=function(){function e(e){this.model=e}return e.prototype.generateText=function(e,t){var r,n;return wi(this,void 0,void 0,(function(){var o,i,a,s,u,l,c,f,d,h,p,b,m,y,v,_,g,w,S,R,T,P=this;return Si(this,(function(O){switch(O.label){case 0:return o=[],i={completion_tokens:0,prompt_tokens:0,total_tokens:0},a=Oi(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=qi(h))))return[3,9];m=xi(h.usage),Ai(i,m),O.label=3;case 3:return O.trys.push([3,7,,8]),[4,Ci(b)];case 4:return y=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:y,stepUsage:m,totalUsage:Object.assign({},i)})];case 5:return O.sent(),ki(f.messages,v.message,y),[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?Pi(Pi([],f.messages,!0),[w],!1):f.messages,T=xi(h.usage),Ai(i,T),[4,null==u?void 0:u({finishReason:g.finish_reason,messages:R.slice(),text:S,toolCall:qi(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 wi(this,void 0,void 0,(function(){var n,o,i,a,s,u,l,c,f,d,h,p,b,m,y,v,_,g,w,S,R,T,P,O,j,q,k,E,C,x,A,I,W,U,B,M,L=this;return Si(this,(function(z){switch(z.label){case 0:return n={completion_tokens:0,prompt_tokens:0,total_tokens:0},o=Oi(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=ro(t),function(e){var t,r,n,o,i,a,s,u,l,c;return wi(this,void 0,void 0,(function(){var f,d,h,p,b,m,y,v,_,g,w,S,R;return Si(this,(function(T){switch(T.label){case 0:f={completion_tokens:0,prompt_tokens:0,total_tokens:0},d=ro(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,m=Ti(d),T.label=2;case 2:return[4,m.next()];case 3:if(y=T.sent(),t=y.done)return[3,5];o=y.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=m.return)?[3,9]:[4,n.call(m)];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];m=h.message,y=h.usage,Ai(n,y),v=null===(r=m.tool_calls)||void 0===r?void 0:r[0],z.label=5;case 5:return z.trys.push([5,9,,10]),[4,Ci(v)];case 6:return _=z.sent(),[4,null==a?void 0:a({finishReason:"tool_calls",messages:l.messages.slice(),text:m.content,toolCall:v,toolResult:_,stepUsage:y,totalUsage:Object.assign({},n)})];case 7:return z.sent(),ki(l.messages,m,_),[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:ro(S),textStream:ro(R.pipeThrough(new Kn({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,Ai(n,P),O=Pi(Pi([],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(Pi(Pi([],l.messages,!0),[T],!1)),dataStream:ro(q),textStream:ro(k.pipeThrough(new Kn({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=ao(),C=ao(),x={role:"assistant",content:""},A="",I={completion_tokens:0,prompt_tokens:0,total_tokens:0},W=f.pipeThrough(new Kn({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(Pi(Pi([],l.messages,!0),[x],!1)),Ai(n,I),C.res(Object.assign({},n)),null==a||a({messages:Pi(Pi([],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:ro(B),textStream:ro(M.pipeThrough(new Kn({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 qi(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&&so(o)?o.tool_calls[0]:null}function ki(e,t,r){e.push(t,{role:"tool",tool_call_id:t.tool_calls[0].id,content:JSON.stringify(r)})}var Ei=new Map;function Ci(e){return Ei.get(e.function.name)(JSON.parse(e.function.arguments))}function xi(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 Ai(e,t){e.completion_tokens+=t.completion_tokens,e.prompt_tokens+=t.prompt_tokens,e.total_tokens+=t.total_tokens}var Ii={hunyuan:Co,"hunyuan-beta":jo,ark:Uo,dashscope:Fo,"01-ai":Ho,moonshot:Ko,zhipu:go,"hunyuan-exp":ri,"hunyuan-open":ai,deepseek:ci},Wi="@cloudbase/js-sdk";function Ui(){return Wi}var Bi="https:";"undefined"==typeof process||process.env;var Mi,Li="INVALID_PARAMS",zi="INVALID_OPERATION",Fi="OPERATION_FAIL";!function(e){e.local="local",e.none="none",e.session="session"}(Mi||(Mi={}));var Di=function(){},Ni=function(){},Gi=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)}}();function $i(e,t){console.warn("[".concat(Ui(),"][").concat(e,"]:").concat(t))}!function(e){function t(t){var r=e.call(this,t.msg||t.message||"")||this;return r.code=t.code||"",r.requestId=t.requestId||"",Object.defineProperty(r,"message",{value:t.msg||t.message||"",enumerable:!0,writable:!0,configurable:!0}),r}Gi(t,e)}(Error);var Hi=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)}}(),Yi=function(){return(Yi=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)},Ji=function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))},Qi=function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!(o=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}Hi(t,e),t.prototype.get=function(e){return this.request(Yi(Yi({},e),{method:"get"}),this.restrictedMethods.includes("get"))},t.prototype.post=function(e){return this.request(Yi(Yi({},e),{method:"post"}),this.restrictedMethods.includes("post"))},t.prototype.put=function(e){return this.request(Yi(Yi({},e),{method:"put"}))},t.prototype.upload=function(e){var t=e,r=t.data,n=t.file,o=t.fileContent,i=t.name,a=t.method,s=t.headers,u=void 0===s?{}:s,l=null!=n?n:o,c={post:"post",put:"put"}[null==a?void 0:a.toLowerCase()]||"put",f=new FormData;return"post"===c?(Object.keys(r).forEach((function(e){f.append(e,r[e])})),f.append("key",i),f.append("file",l instanceof Blob?l:new Blob([l])),this.request(Yi(Yi({},e),{data:f,method:c}),this.restrictedMethods.includes("upload"))):this.request(Yi(Yi({},e),{method:"put",headers:u,body:l}),this.restrictedMethods.includes("upload"))},t.prototype.download=function(e){return Ji(this,void 0,void 0,(function(){var t,r,n,o;return Qi(this,(function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,this.get(Yi(Yi({},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 Ji(this,void 0,void 0,(function(){var r,n,o,i,a,s,u,l,c,f,d,h,p,b=this;return Qi(this,(function(m){switch(m.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,Yi(Yi({},e),{signal:r.signal})).then((function(e){return Ji(b,void 0,void 0,(function(){var t,r,n;return Qi(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){return clearTimeout(h),Promise.reject(e)}))];case 1:return p=m.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,response:p}]}}))}))},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=e.url,a=e.headers,s=void 0===a?{}:a,u=e.data,l=e.responseType,c=e.withCredentials,f=e.body,d=e.onUploadProgress,h=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)}(Bi,i,"get"===n?u:{}),p=new XMLHttpRequest;p.open(n,h),l&&(p.responseType=l);var b,m,y,v=e.signal;v&&(v.aborted?p.abort():v.addEventListener("abort",(function(){return p.abort()}),{once:!0})),Object.keys(s).forEach((function(e){p.setRequestHeader(e,s[e])})),d&&p.upload.addEventListener("progress",d),p.onreadystatechange=function(){var e={};if(4===p.readyState){var t=p.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=p.status;try{e.data="blob"===l?p.response:JSON.parse(p.responseText)}catch(t){e.data="blob"===l?p.response:p.responseText}clearTimeout(b),o(e)}},t&&r.timeout&&(b=setTimeout((function(){console.warn(r.timeoutMsg),p.abort()}),r.timeout)),y=u,m="[object FormData]"===Object.prototype.toString.call(y)?u:"application/x-www-form-urlencoded"===s["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("&")}(u):f||(u?JSON.stringify(u):void 0),c&&(p.withCredentials=!0),p.send(m)}))}}(Di);var Vi;!function(e){e.WEB="web",e.WX_MP="wx_mp"}(Vi||(Vi={}));var Xi=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)}}(),Ki=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())}))},Zi=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])}}},ea=function(e){function t(t){var r=e.call(this)||this;return r.root=t,t.tcbCacheObject||(t.tcbCacheObject={}),r}return Xi(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}(Ni);!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:($i(Li,"localStorage is not supported on current platform"),new ea(t.root));case"none":return new ea(t.root);default:return t.localStorage?t.localStorage:($i(Li,"localStorage is not supported on current platform"),new ea(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:Fi,msg:"[".concat(Ui(),"][").concat(Fi,"]setStore failed"),info:e}))}}else $i(zi,"current platform's storage is asynchronous, please use setStoreAsync insteed")},e.prototype.setStoreAsync=function(e,t,r){return Ki(this,void 0,void 0,(function(){var n;return Zi(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:""}$i(zi,"current platform's storage is asynchronous, please use getStoreAsync insteed")},e.prototype.getStoreAsync=function(e,t){var r;return Ki(this,void 0,void 0,(function(){var n;return Zi(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):$i(zi,"current platform's storage is asynchronous, please use removeStoreAsync insteed")},e.prototype.removeStoreAsync=function(e){return Ki(this,void 0,void 0,(function(){return Zi(this,(function(t){switch(t.label){case 0:return[4,this.storage.removeItem(e)];case 1:return t.sent(),[2]}}))}))}}();var ta=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)}}(),ra=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 na=function(e,t){this.data=t||null,this.name=e},oa=function(e){function t(t,r){var n=e.call(this,"error",{error:t,data:r})||this;return n.error=t,n}return ta(t,e),t}(na),ia=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 oa)return console.error(e.error),this;var r="string"==typeof e?new na(e,t||{}):e,n=r.name;if(this.listens(n)){r.target=this;for(var o=0,i=this.listeners[n]?ra([],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 ia;var aa=new ia;"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 sa(e){this.message=e}sa.prototype=new Error,sa.prototype.name="InvalidCharacterError";"undefined"!=typeof window&&window.atob&&window.atob.bind(window);function ua(e){this.message=e}ua.prototype=new Error,ua.prototype.name="InvalidTokenError";var la=function(){return(la=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)},ca=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())}))},fa=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])}}},da=Ii,ha=function(){function e(e,t,r,n){var o=this;this.req=e,this.baseUrl=t,this.modelRequest=function(e){var t=e.url,r=e.data,n=e.headers,i=e.stream,a=e.timeout;return ca(o,void 0,void 0,(function(){var e,o,s,u,l,c,f;return fa(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:la(la((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),n),body:JSON.stringify(r),url:this.resolveUrl(t),stream:i,timeout:a})];case 1:return o=d.sent(),s=o.data,u=o.header,[2,this.handleResponseData(s,u)]}}))}))},this.botRequest=function(e){var t=e.method,r=e.url,n=e.data,i=void 0===n?{}:n,a=e.headers,s=e.stream,u=e.timeout;return ca(o,void 0,void 0,(function(){var e,n,o,l,c,f,d,h,p;return fa(this,(function(b){switch(b.label){case 0:return e=this.resolveUrl(r),"get"!==t?[3,2]:(n=this.handleResponseData,[4,this.req.fetch({url:"".concat(e,"?").concat((m=i,Object.entries(m).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,n.apply(this,[b.sent().data])];case 2:return o={"Content-Type":"application/json"},s&&Object.assign(o,{Accept:"text/event-stream"}),[4,this.req.fetch({url:e,body:JSON.stringify(i),headers:la(la((d={},d[null===(h=this.i18n)||void 0===h?void 0:h.LANG_HEADER_KEY]=null===(p=this.i18n)||void 0===p?void 0:p.lang,d),o),a),stream:s,method:t,timeout:u})];case 3:return l=b.sent(),c=l.data,f=l.header,[2,this.handleResponseData(c,f)]}var m}))}))},this._getBaseUrl=n,this.bot=new po(this.botRequest,this.aiBotBaseUrl),this.i18n=r,aa.on("lang_change",(function(e){var t;o.i18n=(null===(t=e.data)||void 0===t?void 0:t.i18n)||o.i18n}))}return Object.defineProperty(e.prototype,"aiBaseUrl",{get:function(){return"".concat(this._getBaseUrl?this._getBaseUrl():this.baseUrl,"/ai")},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"aiBotBaseUrl",{get:function(){return"".concat(this._getBaseUrl?this._getBaseUrl():this.baseUrl,"/aibot")},enumerable:!1,configurable:!0}),e.prototype.handleResponseData=function(e,t){var r,n;return ca(this,void 0,void 0,(function(){var o,i,a,s,u=this;return fa(this,(function(l){switch(l.label){case 0:return o="".concat(this.i18n.t("请检查调用方式,或前往云开发 AI+ 首页查看文档"),":https://tcb.cloud.tencent.com/dev#/ai"),i=function(e){if("object"==typeof e&&e&&"code"in e&&"NORMAL"!==e.code)throw new Error("".concat(u.i18n.t("AI+ 请求出错,错误码"),":").concat(e.code,",").concat(u.i18n.t("错误信息"),":").concat(e.message,"\n").concat(o,"\n").concat(JSON.stringify(e,null,2)))},"object"==typeof e&&e&&"function"!=typeof e.getReader?"then"in e?[4,e]:[3,2]:[3,4];case 1:return a=l.sent(),[3,3];case 2:a=e,l.label=3;case 3:return i(s=a),[2,e];case 4:if(!("function"==typeof(null==e?void 0:e.getReader))){if("object"==typeof(s=e)&&s&&"code"in s&&"NORMAL"!==s.code)throw new Error("".concat(this.i18n.t("AI+ 请求出错,错误码"),":").concat(s.code,",").concat(this.i18n.t("错误信息"),":").concat(s.message,"\n").concat(o,"\n").concat(JSON.stringify(s,null,2)));return[2,e]}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,io(e)]:[3,6];case 5:s=l.sent(),i(s),l.label=6;case 6:return[2,e]}}))}))},e.prototype.createModel=function(e,t){var r,n=da[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 pi(this.modelRequest,this.aiBaseUrl,"".concat(e).concat(o))}return new ji(r)},e.prototype.registerModel=function(e,t){null==da[e]?da[e]=t:console.warn("AI model ".concat(e," already exists!"))},e.prototype.createImageModel=function(e){return new _i(this.modelRequest,this.aiBaseUrl,e)},e.prototype.registerFunctionTool=function(e){Ei.has(e.name)&&console.warn("AI function tool ".concat(e.name," already exists and will be overwritten!")),Ei.set(e.name,e.fn)},e.prototype.resolveUrl=function(e){if(!this._getBaseUrl)return e;var t=this._getBaseUrl();return t!==this.baseUrl&&e.startsWith(this.baseUrl)?e.replace(this.baseUrl,t):e},e}(),pa=function(){},ba=function(){return(ba=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)},ma=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())}))},ya=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])}}},va=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},_a=va(t,["MODELS"]);function ga(e){var t=e.env,r=e.baseUrl,n=e.getBaseUrl,o=e.req,i=e.getAccessToken,a=e.handleReqInstance,s=e.i18n;return new ha(function(){if(null==a){if(null==i)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 ma(void 0,void 0,void 0,(function(){var n,o,i,a,s;return ya(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=va(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(ba({headers:ba({Authorization:"Bearer ".concat(s)},i)},a))]}}))}))}}}({req:o,getAccessToken:i})}return a({req:o})}(),function(){if(null!=n)return n();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")}(),s,n)}var wa=ga;var Sa={name:"ai",entity:{ai:function(e){var t=this,r=this.request;if(null==r.fetch)throw new Error("cloudbase.request.fetch() unimplemented!");var n=function(){var e=t.getEndPointWithKey("GATEWAY"),r=e.BASE_URL,n=e.PROTOCOL;return"".concat(n).concat(r)};return(null==e?void 0:e.baseUrl)?ga({req:r,baseUrl:e.baseUrl,handleReqInstance:function(e){return e.req},i18n:this.config.i18n}):ga({req:r,baseUrl:n(),getBaseUrl:n,handleReqInstance:function(e){return e.req},i18n:this.config.i18n})}}};function Ra(e){try{e.registerComponent(Sa)}catch(e){console.warn(e)}}try{window.registerAi=Ra}catch(o){}})(),n})());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/ai",
3
- "version": "3.9.0",
3
+ "version": "3.9.1",
4
4
  "description": "cloudbase js sdk ai module",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -30,14 +30,14 @@
30
30
  "author": "",
31
31
  "license": "Apache-2.0",
32
32
  "dependencies": {
33
- "@cloudbase/types": "3.9.0",
34
- "@cloudbase/utilities": "3.9.0",
33
+ "@cloudbase/types": "3.9.1",
34
+ "@cloudbase/utilities": "3.9.1",
35
35
  "@mattiasbuelens/web-streams-adapter": "^0.1.0",
36
36
  "text-encoding-shim": "^1.0.5",
37
37
  "web-streams-polyfill": "^4.0.0"
38
38
  },
39
39
  "devDependencies": {
40
- "@cloudbase/adapter-interface": "^0.7.1"
40
+ "@cloudbase/adapter-interface": "~0.7.1"
41
41
  },
42
- "gitHead": "a5f8d3ce881e02bf75d50a2b7d284eda6c31cade"
42
+ "gitHead": "764bee6945f3c65ec9b86e81ae474bef20807aea"
43
43
  }