@glodon-aiot/agent-cli-sdk 3.0.6 → 3.0.7-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/agent-cli-sdk.js
CHANGED
|
@@ -32111,6 +32111,9 @@ class Vh {
|
|
|
32111
32111
|
get dataLoaded() {
|
|
32112
32112
|
return this._dataLoaded;
|
|
32113
32113
|
}
|
|
32114
|
+
get messagesLoading() {
|
|
32115
|
+
return this._loadingMessages;
|
|
32116
|
+
}
|
|
32114
32117
|
send(O) {
|
|
32115
32118
|
return Le(this, arguments, void 0, function* (L, Y = { stream: !1 }) {
|
|
32116
32119
|
var ut;
|
|
@@ -134,7 +134,7 @@ Source:
|
|
|
134
134
|
*
|
|
135
135
|
* @author Feross Aboukhadijeh <https://feross.org>
|
|
136
136
|
* @license MIT
|
|
137
|
-
*/(function(K){const O=fo,L=Za,Y=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;K.Buffer=_,K.SlowBuffer=g,K.INSPECT_MAX_BYTES=50;const ut=2147483647;K.kMaxLength=ut,_.TYPED_ARRAY_SUPPORT=ht(),!_.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function ht(){try{const F=new Uint8Array(1),H={foo:function(){return 42}};return Object.setPrototypeOf(H,Uint8Array.prototype),Object.setPrototypeOf(F,H),F.foo()===42}catch{return!1}}Object.defineProperty(_.prototype,"parent",{enumerable:!0,get:function(){if(_.isBuffer(this))return this.buffer}}),Object.defineProperty(_.prototype,"offset",{enumerable:!0,get:function(){if(_.isBuffer(this))return this.byteOffset}});function W(F){if(F>ut)throw new RangeError('The value "'+F+'" is invalid for option "size"');const H=new Uint8Array(F);return Object.setPrototypeOf(H,_.prototype),H}function _(F,H,U){if(typeof F=="number"){if(typeof H=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return m(F)}return y(F,H,U)}_.poolSize=8192;function y(F,H,U){if(typeof F=="string")return S(F,H);if(ArrayBuffer.isView(F))return p(F);if(F==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof F);if(Bt(F,ArrayBuffer)||F&&Bt(F.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(Bt(F,SharedArrayBuffer)||F&&Bt(F.buffer,SharedArrayBuffer)))return c(F,H,U);if(typeof F=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');const it=F.valueOf&&F.valueOf();if(it!=null&&it!==F)return _.from(it,H,U);const pt=l(F);if(pt)return pt;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof F[Symbol.toPrimitive]=="function")return _.from(F[Symbol.toPrimitive]("string"),H,U);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof F)}_.from=function(F,H,U){return y(F,H,U)},Object.setPrototypeOf(_.prototype,Uint8Array.prototype),Object.setPrototypeOf(_,Uint8Array);function x(F){if(typeof F!="number")throw new TypeError('"size" argument must be of type number');if(F<0)throw new RangeError('The value "'+F+'" is invalid for option "size"')}function v(F,H,U){return x(F),F<=0?W(F):H!==void 0?typeof U=="string"?W(F).fill(H,U):W(F).fill(H):W(F)}_.alloc=function(F,H,U){return v(F,H,U)};function m(F){return x(F),W(F<0?0:f(F)|0)}_.allocUnsafe=function(F){return m(F)},_.allocUnsafeSlow=function(F){return m(F)};function S(F,H){if((typeof H!="string"||H==="")&&(H="utf8"),!_.isEncoding(H))throw new TypeError("Unknown encoding: "+H);const U=h(F,H)|0;let it=W(U);const pt=it.write(F,H);return pt!==U&&(it=it.slice(0,pt)),it}function a(F){const H=F.length<0?0:f(F.length)|0,U=W(H);for(let it=0;it<H;it+=1)U[it]=F[it]&255;return U}function p(F){if(Bt(F,Uint8Array)){const H=new Uint8Array(F);return c(H.buffer,H.byteOffset,H.byteLength)}return a(F)}function c(F,H,U){if(H<0||F.byteLength<H)throw new RangeError('"offset" is outside of buffer bounds');if(F.byteLength<H+(U||0))throw new RangeError('"length" is outside of buffer bounds');let it;return H===void 0&&U===void 0?it=new Uint8Array(F):U===void 0?it=new Uint8Array(F,H):it=new Uint8Array(F,H,U),Object.setPrototypeOf(it,_.prototype),it}function l(F){if(_.isBuffer(F)){const H=f(F.length)|0,U=W(H);return U.length===0||F.copy(U,0,0,H),U}if(F.length!==void 0)return typeof F.length!="number"||Mt(F.length)?W(0):a(F);if(F.type==="Buffer"&&Array.isArray(F.data))return a(F.data)}function f(F){if(F>=ut)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+ut.toString(16)+" bytes");return F|0}function g(F){return+F!=F&&(F=0),_.alloc(+F)}_.isBuffer=function(H){return H!=null&&H._isBuffer===!0&&H!==_.prototype},_.compare=function(H,U){if(Bt(H,Uint8Array)&&(H=_.from(H,H.offset,H.byteLength)),Bt(U,Uint8Array)&&(U=_.from(U,U.offset,U.byteLength)),!_.isBuffer(H)||!_.isBuffer(U))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(H===U)return 0;let it=H.length,pt=U.length;for(let ft=0,mt=Math.min(it,pt);ft<mt;++ft)if(H[ft]!==U[ft]){it=H[ft],pt=U[ft];break}return it<pt?-1:pt<it?1:0},_.isEncoding=function(H){switch(String(H).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},_.concat=function(H,U){if(!Array.isArray(H))throw new TypeError('"list" argument must be an Array of Buffers');if(H.length===0)return _.alloc(0);let it;if(U===void 0)for(U=0,it=0;it<H.length;++it)U+=H[it].length;const pt=_.allocUnsafe(U);let ft=0;for(it=0;it<H.length;++it){let mt=H[it];if(Bt(mt,Uint8Array))ft+mt.length>pt.length?(_.isBuffer(mt)||(mt=_.from(mt)),mt.copy(pt,ft)):Uint8Array.prototype.set.call(pt,mt,ft);else if(_.isBuffer(mt))mt.copy(pt,ft);else throw new TypeError('"list" argument must be an Array of Buffers');ft+=mt.length}return pt};function h(F,H){if(_.isBuffer(F))return F.length;if(ArrayBuffer.isView(F)||Bt(F,ArrayBuffer))return F.byteLength;if(typeof F!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof F);const U=F.length,it=arguments.length>2&&arguments[2]===!0;if(!it&&U===0)return 0;let pt=!1;for(;;)switch(H){case"ascii":case"latin1":case"binary":return U;case"utf8":case"utf-8":return nt(F).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return U*2;case"hex":return U>>>1;case"base64":return gt(F).length;default:if(pt)return it?-1:nt(F).length;H=(""+H).toLowerCase(),pt=!0}}_.byteLength=h;function u(F,H,U){let it=!1;if((H===void 0||H<0)&&(H=0),H>this.length||((U===void 0||U>this.length)&&(U=this.length),U<=0)||(U>>>=0,H>>>=0,U<=H))return"";for(F||(F="utf8");;)switch(F){case"hex":return r(this,H,U);case"utf8":case"utf-8":return et(this,H,U);case"ascii":return t(this,H,U);case"latin1":case"binary":return n(this,H,U);case"base64":return $(this,H,U);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return i(this,H,U);default:if(it)throw new TypeError("Unknown encoding: "+F);F=(F+"").toLowerCase(),it=!0}}_.prototype._isBuffer=!0;function w(F,H,U){const it=F[H];F[H]=F[U],F[U]=it}_.prototype.swap16=function(){const H=this.length;if(H%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let U=0;U<H;U+=2)w(this,U,U+1);return this},_.prototype.swap32=function(){const H=this.length;if(H%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let U=0;U<H;U+=4)w(this,U,U+3),w(this,U+1,U+2);return this},_.prototype.swap64=function(){const H=this.length;if(H%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let U=0;U<H;U+=8)w(this,U,U+7),w(this,U+1,U+6),w(this,U+2,U+5),w(this,U+3,U+4);return this},_.prototype.toString=function(){const H=this.length;return H===0?"":arguments.length===0?et(this,0,H):u.apply(this,arguments)},_.prototype.toLocaleString=_.prototype.toString,_.prototype.equals=function(H){if(!_.isBuffer(H))throw new TypeError("Argument must be a Buffer");return this===H?!0:_.compare(this,H)===0},_.prototype.inspect=function(){let H="";const U=K.INSPECT_MAX_BYTES;return H=this.toString("hex",0,U).replace(/(.{2})/g,"$1 ").trim(),this.length>U&&(H+=" ... "),"<Buffer "+H+">"},Y&&(_.prototype[Y]=_.prototype.inspect),_.prototype.compare=function(H,U,it,pt,ft){if(Bt(H,Uint8Array)&&(H=_.from(H,H.offset,H.byteLength)),!_.isBuffer(H))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof H);if(U===void 0&&(U=0),it===void 0&&(it=H?H.length:0),pt===void 0&&(pt=0),ft===void 0&&(ft=this.length),U<0||it>H.length||pt<0||ft>this.length)throw new RangeError("out of range index");if(pt>=ft&&U>=it)return 0;if(pt>=ft)return-1;if(U>=it)return 1;if(U>>>=0,it>>>=0,pt>>>=0,ft>>>=0,this===H)return 0;let mt=ft-pt,re=it-U;const _t=Math.min(mt,re),At=this.slice(pt,ft),fe=H.slice(U,it);for(let kt=0;kt<_t;++kt)if(At[kt]!==fe[kt]){mt=At[kt],re=fe[kt];break}return mt<re?-1:re<mt?1:0};function b(F,H,U,it,pt){if(F.length===0)return-1;if(typeof U=="string"?(it=U,U=0):U>2147483647?U=2147483647:U<-2147483648&&(U=-2147483648),U=+U,Mt(U)&&(U=pt?0:F.length-1),U<0&&(U=F.length+U),U>=F.length){if(pt)return-1;U=F.length-1}else if(U<0)if(pt)U=0;else return-1;if(typeof H=="string"&&(H=_.from(H,it)),_.isBuffer(H))return H.length===0?-1:E(F,H,U,it,pt);if(typeof H=="number")return H=H&255,typeof Uint8Array.prototype.indexOf=="function"?pt?Uint8Array.prototype.indexOf.call(F,H,U):Uint8Array.prototype.lastIndexOf.call(F,H,U):E(F,[H],U,it,pt);throw new TypeError("val must be string, number or Buffer")}function E(F,H,U,it,pt){let ft=1,mt=F.length,re=H.length;if(it!==void 0&&(it=String(it).toLowerCase(),it==="ucs2"||it==="ucs-2"||it==="utf16le"||it==="utf-16le")){if(F.length<2||H.length<2)return-1;ft=2,mt/=2,re/=2,U/=2}function _t(fe,kt){return ft===1?fe[kt]:fe.readUInt16BE(kt*ft)}let At;if(pt){let fe=-1;for(At=U;At<mt;At++)if(_t(F,At)===_t(H,fe===-1?0:At-fe)){if(fe===-1&&(fe=At),At-fe+1===re)return fe*ft}else fe!==-1&&(At-=At-fe),fe=-1}else for(U+re>mt&&(U=mt-re),At=U;At>=0;At--){let fe=!0;for(let kt=0;kt<re;kt++)if(_t(F,At+kt)!==_t(H,kt)){fe=!1;break}if(fe)return At}return-1}_.prototype.includes=function(H,U,it){return this.indexOf(H,U,it)!==-1},_.prototype.indexOf=function(H,U,it){return b(this,H,U,it,!0)},_.prototype.lastIndexOf=function(H,U,it){return b(this,H,U,it,!1)};function I(F,H,U,it){U=Number(U)||0;const pt=F.length-U;it?(it=Number(it),it>pt&&(it=pt)):it=pt;const ft=H.length;it>ft/2&&(it=ft/2);let mt;for(mt=0;mt<it;++mt){const re=parseInt(H.substr(mt*2,2),16);if(Mt(re))return mt;F[U+mt]=re}return mt}function M(F,H,U,it){return bt(nt(H,F.length-U),F,U,it)}function B(F,H,U,it){return bt(lt(H),F,U,it)}function P(F,H,U,it){return bt(gt(H),F,U,it)}function N(F,H,U,it){return bt(Et(H,F.length-U),F,U,it)}_.prototype.write=function(H,U,it,pt){if(U===void 0)pt="utf8",it=this.length,U=0;else if(it===void 0&&typeof U=="string")pt=U,it=this.length,U=0;else if(isFinite(U))U=U>>>0,isFinite(it)?(it=it>>>0,pt===void 0&&(pt="utf8")):(pt=it,it=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");const ft=this.length-U;if((it===void 0||it>ft)&&(it=ft),H.length>0&&(it<0||U<0)||U>this.length)throw new RangeError("Attempt to write outside buffer bounds");pt||(pt="utf8");let mt=!1;for(;;)switch(pt){case"hex":return I(this,H,U,it);case"utf8":case"utf-8":return M(this,H,U,it);case"ascii":case"latin1":case"binary":return B(this,H,U,it);case"base64":return P(this,H,U,it);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return N(this,H,U,it);default:if(mt)throw new TypeError("Unknown encoding: "+pt);pt=(""+pt).toLowerCase(),mt=!0}},_.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function $(F,H,U){return H===0&&U===F.length?O.fromByteArray(F):O.fromByteArray(F.slice(H,U))}function et(F,H,U){U=Math.min(F.length,U);const it=[];let pt=H;for(;pt<U;){const ft=F[pt];let mt=null,re=ft>239?4:ft>223?3:ft>191?2:1;if(pt+re<=U){let _t,At,fe,kt;switch(re){case 1:ft<128&&(mt=ft);break;case 2:_t=F[pt+1],(_t&192)===128&&(kt=(ft&31)<<6|_t&63,kt>127&&(mt=kt));break;case 3:_t=F[pt+1],At=F[pt+2],(_t&192)===128&&(At&192)===128&&(kt=(ft&15)<<12|(_t&63)<<6|At&63,kt>2047&&(kt<55296||kt>57343)&&(mt=kt));break;case 4:_t=F[pt+1],At=F[pt+2],fe=F[pt+3],(_t&192)===128&&(At&192)===128&&(fe&192)===128&&(kt=(ft&15)<<18|(_t&63)<<12|(At&63)<<6|fe&63,kt>65535&&kt<1114112&&(mt=kt))}}mt===null?(mt=65533,re=1):mt>65535&&(mt-=65536,it.push(mt>>>10&1023|55296),mt=56320|mt&1023),it.push(mt),pt+=re}return ot(it)}const Q=4096;function ot(F){const H=F.length;if(H<=Q)return String.fromCharCode.apply(String,F);let U="",it=0;for(;it<H;)U+=String.fromCharCode.apply(String,F.slice(it,it+=Q));return U}function t(F,H,U){let it="";U=Math.min(F.length,U);for(let pt=H;pt<U;++pt)it+=String.fromCharCode(F[pt]&127);return it}function n(F,H,U){let it="";U=Math.min(F.length,U);for(let pt=H;pt<U;++pt)it+=String.fromCharCode(F[pt]);return it}function r(F,H,U){const it=F.length;(!H||H<0)&&(H=0),(!U||U<0||U>it)&&(U=it);let pt="";for(let ft=H;ft<U;++ft)pt+=It[F[ft]];return pt}function i(F,H,U){const it=F.slice(H,U);let pt="";for(let ft=0;ft<it.length-1;ft+=2)pt+=String.fromCharCode(it[ft]+it[ft+1]*256);return pt}_.prototype.slice=function(H,U){const it=this.length;H=~~H,U=U===void 0?it:~~U,H<0?(H+=it,H<0&&(H=0)):H>it&&(H=it),U<0?(U+=it,U<0&&(U=0)):U>it&&(U=it),U<H&&(U=H);const pt=this.subarray(H,U);return Object.setPrototypeOf(pt,_.prototype),pt};function e(F,H,U){if(F%1!==0||F<0)throw new RangeError("offset is not uint");if(F+H>U)throw new RangeError("Trying to access beyond buffer length")}_.prototype.readUintLE=_.prototype.readUIntLE=function(H,U,it){H=H>>>0,U=U>>>0,it||e(H,U,this.length);let pt=this[H],ft=1,mt=0;for(;++mt<U&&(ft*=256);)pt+=this[H+mt]*ft;return pt},_.prototype.readUintBE=_.prototype.readUIntBE=function(H,U,it){H=H>>>0,U=U>>>0,it||e(H,U,this.length);let pt=this[H+--U],ft=1;for(;U>0&&(ft*=256);)pt+=this[H+--U]*ft;return pt},_.prototype.readUint8=_.prototype.readUInt8=function(H,U){return H=H>>>0,U||e(H,1,this.length),this[H]},_.prototype.readUint16LE=_.prototype.readUInt16LE=function(H,U){return H=H>>>0,U||e(H,2,this.length),this[H]|this[H+1]<<8},_.prototype.readUint16BE=_.prototype.readUInt16BE=function(H,U){return H=H>>>0,U||e(H,2,this.length),this[H]<<8|this[H+1]},_.prototype.readUint32LE=_.prototype.readUInt32LE=function(H,U){return H=H>>>0,U||e(H,4,this.length),(this[H]|this[H+1]<<8|this[H+2]<<16)+this[H+3]*16777216},_.prototype.readUint32BE=_.prototype.readUInt32BE=function(H,U){return H=H>>>0,U||e(H,4,this.length),this[H]*16777216+(this[H+1]<<16|this[H+2]<<8|this[H+3])},_.prototype.readBigUInt64LE=J(function(H){H=H>>>0,G(H,"offset");const U=this[H],it=this[H+7];(U===void 0||it===void 0)&&z(H,this.length-8);const pt=U+this[++H]*2**8+this[++H]*2**16+this[++H]*2**24,ft=this[++H]+this[++H]*2**8+this[++H]*2**16+it*2**24;return BigInt(pt)+(BigInt(ft)<<BigInt(32))}),_.prototype.readBigUInt64BE=J(function(H){H=H>>>0,G(H,"offset");const U=this[H],it=this[H+7];(U===void 0||it===void 0)&&z(H,this.length-8);const pt=U*2**24+this[++H]*2**16+this[++H]*2**8+this[++H],ft=this[++H]*2**24+this[++H]*2**16+this[++H]*2**8+it;return(BigInt(pt)<<BigInt(32))+BigInt(ft)}),_.prototype.readIntLE=function(H,U,it){H=H>>>0,U=U>>>0,it||e(H,U,this.length);let pt=this[H],ft=1,mt=0;for(;++mt<U&&(ft*=256);)pt+=this[H+mt]*ft;return ft*=128,pt>=ft&&(pt-=Math.pow(2,8*U)),pt},_.prototype.readIntBE=function(H,U,it){H=H>>>0,U=U>>>0,it||e(H,U,this.length);let pt=U,ft=1,mt=this[H+--pt];for(;pt>0&&(ft*=256);)mt+=this[H+--pt]*ft;return ft*=128,mt>=ft&&(mt-=Math.pow(2,8*U)),mt},_.prototype.readInt8=function(H,U){return H=H>>>0,U||e(H,1,this.length),this[H]&128?(255-this[H]+1)*-1:this[H]},_.prototype.readInt16LE=function(H,U){H=H>>>0,U||e(H,2,this.length);const it=this[H]|this[H+1]<<8;return it&32768?it|4294901760:it},_.prototype.readInt16BE=function(H,U){H=H>>>0,U||e(H,2,this.length);const it=this[H+1]|this[H]<<8;return it&32768?it|4294901760:it},_.prototype.readInt32LE=function(H,U){return H=H>>>0,U||e(H,4,this.length),this[H]|this[H+1]<<8|this[H+2]<<16|this[H+3]<<24},_.prototype.readInt32BE=function(H,U){return H=H>>>0,U||e(H,4,this.length),this[H]<<24|this[H+1]<<16|this[H+2]<<8|this[H+3]},_.prototype.readBigInt64LE=J(function(H){H=H>>>0,G(H,"offset");const U=this[H],it=this[H+7];(U===void 0||it===void 0)&&z(H,this.length-8);const pt=this[H+4]+this[H+5]*2**8+this[H+6]*2**16+(it<<24);return(BigInt(pt)<<BigInt(32))+BigInt(U+this[++H]*2**8+this[++H]*2**16+this[++H]*2**24)}),_.prototype.readBigInt64BE=J(function(H){H=H>>>0,G(H,"offset");const U=this[H],it=this[H+7];(U===void 0||it===void 0)&&z(H,this.length-8);const pt=(U<<24)+this[++H]*2**16+this[++H]*2**8+this[++H];return(BigInt(pt)<<BigInt(32))+BigInt(this[++H]*2**24+this[++H]*2**16+this[++H]*2**8+it)}),_.prototype.readFloatLE=function(H,U){return H=H>>>0,U||e(H,4,this.length),L.read(this,H,!0,23,4)},_.prototype.readFloatBE=function(H,U){return H=H>>>0,U||e(H,4,this.length),L.read(this,H,!1,23,4)},_.prototype.readDoubleLE=function(H,U){return H=H>>>0,U||e(H,8,this.length),L.read(this,H,!0,52,8)},_.prototype.readDoubleBE=function(H,U){return H=H>>>0,U||e(H,8,this.length),L.read(this,H,!1,52,8)};function o(F,H,U,it,pt,ft){if(!_.isBuffer(F))throw new TypeError('"buffer" argument must be a Buffer instance');if(H>pt||H<ft)throw new RangeError('"value" argument is out of bounds');if(U+it>F.length)throw new RangeError("Index out of range")}_.prototype.writeUintLE=_.prototype.writeUIntLE=function(H,U,it,pt){if(H=+H,U=U>>>0,it=it>>>0,!pt){const re=Math.pow(2,8*it)-1;o(this,H,U,it,re,0)}let ft=1,mt=0;for(this[U]=H&255;++mt<it&&(ft*=256);)this[U+mt]=H/ft&255;return U+it},_.prototype.writeUintBE=_.prototype.writeUIntBE=function(H,U,it,pt){if(H=+H,U=U>>>0,it=it>>>0,!pt){const re=Math.pow(2,8*it)-1;o(this,H,U,it,re,0)}let ft=it-1,mt=1;for(this[U+ft]=H&255;--ft>=0&&(mt*=256);)this[U+ft]=H/mt&255;return U+it},_.prototype.writeUint8=_.prototype.writeUInt8=function(H,U,it){return H=+H,U=U>>>0,it||o(this,H,U,1,255,0),this[U]=H&255,U+1},_.prototype.writeUint16LE=_.prototype.writeUInt16LE=function(H,U,it){return H=+H,U=U>>>0,it||o(this,H,U,2,65535,0),this[U]=H&255,this[U+1]=H>>>8,U+2},_.prototype.writeUint16BE=_.prototype.writeUInt16BE=function(H,U,it){return H=+H,U=U>>>0,it||o(this,H,U,2,65535,0),this[U]=H>>>8,this[U+1]=H&255,U+2},_.prototype.writeUint32LE=_.prototype.writeUInt32LE=function(H,U,it){return H=+H,U=U>>>0,it||o(this,H,U,4,4294967295,0),this[U+3]=H>>>24,this[U+2]=H>>>16,this[U+1]=H>>>8,this[U]=H&255,U+4},_.prototype.writeUint32BE=_.prototype.writeUInt32BE=function(H,U,it){return H=+H,U=U>>>0,it||o(this,H,U,4,4294967295,0),this[U]=H>>>24,this[U+1]=H>>>16,this[U+2]=H>>>8,this[U+3]=H&255,U+4};function s(F,H,U,it,pt){D(H,it,pt,F,U,7);let ft=Number(H&BigInt(4294967295));F[U++]=ft,ft=ft>>8,F[U++]=ft,ft=ft>>8,F[U++]=ft,ft=ft>>8,F[U++]=ft;let mt=Number(H>>BigInt(32)&BigInt(4294967295));return F[U++]=mt,mt=mt>>8,F[U++]=mt,mt=mt>>8,F[U++]=mt,mt=mt>>8,F[U++]=mt,U}function A(F,H,U,it,pt){D(H,it,pt,F,U,7);let ft=Number(H&BigInt(4294967295));F[U+7]=ft,ft=ft>>8,F[U+6]=ft,ft=ft>>8,F[U+5]=ft,ft=ft>>8,F[U+4]=ft;let mt=Number(H>>BigInt(32)&BigInt(4294967295));return F[U+3]=mt,mt=mt>>8,F[U+2]=mt,mt=mt>>8,F[U+1]=mt,mt=mt>>8,F[U]=mt,U+8}_.prototype.writeBigUInt64LE=J(function(H,U=0){return s(this,H,U,BigInt(0),BigInt("0xffffffffffffffff"))}),_.prototype.writeBigUInt64BE=J(function(H,U=0){return A(this,H,U,BigInt(0),BigInt("0xffffffffffffffff"))}),_.prototype.writeIntLE=function(H,U,it,pt){if(H=+H,U=U>>>0,!pt){const _t=Math.pow(2,8*it-1);o(this,H,U,it,_t-1,-_t)}let ft=0,mt=1,re=0;for(this[U]=H&255;++ft<it&&(mt*=256);)H<0&&re===0&&this[U+ft-1]!==0&&(re=1),this[U+ft]=(H/mt>>0)-re&255;return U+it},_.prototype.writeIntBE=function(H,U,it,pt){if(H=+H,U=U>>>0,!pt){const _t=Math.pow(2,8*it-1);o(this,H,U,it,_t-1,-_t)}let ft=it-1,mt=1,re=0;for(this[U+ft]=H&255;--ft>=0&&(mt*=256);)H<0&&re===0&&this[U+ft+1]!==0&&(re=1),this[U+ft]=(H/mt>>0)-re&255;return U+it},_.prototype.writeInt8=function(H,U,it){return H=+H,U=U>>>0,it||o(this,H,U,1,127,-128),H<0&&(H=255+H+1),this[U]=H&255,U+1},_.prototype.writeInt16LE=function(H,U,it){return H=+H,U=U>>>0,it||o(this,H,U,2,32767,-32768),this[U]=H&255,this[U+1]=H>>>8,U+2},_.prototype.writeInt16BE=function(H,U,it){return H=+H,U=U>>>0,it||o(this,H,U,2,32767,-32768),this[U]=H>>>8,this[U+1]=H&255,U+2},_.prototype.writeInt32LE=function(H,U,it){return H=+H,U=U>>>0,it||o(this,H,U,4,2147483647,-2147483648),this[U]=H&255,this[U+1]=H>>>8,this[U+2]=H>>>16,this[U+3]=H>>>24,U+4},_.prototype.writeInt32BE=function(H,U,it){return H=+H,U=U>>>0,it||o(this,H,U,4,2147483647,-2147483648),H<0&&(H=4294967295+H+1),this[U]=H>>>24,this[U+1]=H>>>16,this[U+2]=H>>>8,this[U+3]=H&255,U+4},_.prototype.writeBigInt64LE=J(function(H,U=0){return s(this,H,U,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),_.prototype.writeBigInt64BE=J(function(H,U=0){return A(this,H,U,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function C(F,H,U,it,pt,ft){if(U+it>F.length)throw new RangeError("Index out of range");if(U<0)throw new RangeError("Index out of range")}function j(F,H,U,it,pt){return H=+H,U=U>>>0,pt||C(F,H,U,4),L.write(F,H,U,it,23,4),U+4}_.prototype.writeFloatLE=function(H,U,it){return j(this,H,U,!0,it)},_.prototype.writeFloatBE=function(H,U,it){return j(this,H,U,!1,it)};function T(F,H,U,it,pt){return H=+H,U=U>>>0,pt||C(F,H,U,8),L.write(F,H,U,it,52,8),U+8}_.prototype.writeDoubleLE=function(H,U,it){return T(this,H,U,!0,it)},_.prototype.writeDoubleBE=function(H,U,it){return T(this,H,U,!1,it)},_.prototype.copy=function(H,U,it,pt){if(!_.isBuffer(H))throw new TypeError("argument should be a Buffer");if(it||(it=0),!pt&&pt!==0&&(pt=this.length),U>=H.length&&(U=H.length),U||(U=0),pt>0&&pt<it&&(pt=it),pt===it||H.length===0||this.length===0)return 0;if(U<0)throw new RangeError("targetStart out of bounds");if(it<0||it>=this.length)throw new RangeError("Index out of range");if(pt<0)throw new RangeError("sourceEnd out of bounds");pt>this.length&&(pt=this.length),H.length-U<pt-it&&(pt=H.length-U+it);const ft=pt-it;return this===H&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(U,it,pt):Uint8Array.prototype.set.call(H,this.subarray(it,pt),U),ft},_.prototype.fill=function(H,U,it,pt){if(typeof H=="string"){if(typeof U=="string"?(pt=U,U=0,it=this.length):typeof it=="string"&&(pt=it,it=this.length),pt!==void 0&&typeof pt!="string")throw new TypeError("encoding must be a string");if(typeof pt=="string"&&!_.isEncoding(pt))throw new TypeError("Unknown encoding: "+pt);if(H.length===1){const mt=H.charCodeAt(0);(pt==="utf8"&&mt<128||pt==="latin1")&&(H=mt)}}else typeof H=="number"?H=H&255:typeof H=="boolean"&&(H=Number(H));if(U<0||this.length<U||this.length<it)throw new RangeError("Out of range index");if(it<=U)return this;U=U>>>0,it=it===void 0?this.length:it>>>0,H||(H=0);let ft;if(typeof H=="number")for(ft=U;ft<it;++ft)this[ft]=H;else{const mt=_.isBuffer(H)?H:_.from(H,pt),re=mt.length;if(re===0)throw new TypeError('The value "'+H+'" is invalid for argument "value"');for(ft=0;ft<it-U;++ft)this[ft+U]=mt[ft%re]}return this};const R={};function q(F,H,U){R[F]=class extends U{constructor(){super(),Object.defineProperty(this,"message",{value:H.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${F}]`,this.stack,delete this.name}get code(){return F}set code(pt){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:pt,writable:!0})}toString(){return`${this.name} [${F}]: ${this.message}`}}}q("ERR_BUFFER_OUT_OF_BOUNDS",function(F){return F?`${F} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),q("ERR_INVALID_ARG_TYPE",function(F,H){return`The "${F}" argument must be of type number. Received type ${typeof H}`},TypeError),q("ERR_OUT_OF_RANGE",function(F,H,U){let it=`The value of "${F}" is out of range.`,pt=U;return Number.isInteger(U)&&Math.abs(U)>2**32?pt=Z(String(U)):typeof U=="bigint"&&(pt=String(U),(U>BigInt(2)**BigInt(32)||U<-(BigInt(2)**BigInt(32)))&&(pt=Z(pt)),pt+="n"),it+=` It must be ${H}. Received ${pt}`,it},RangeError);function Z(F){let H="",U=F.length;const it=F[0]==="-"?1:0;for(;U>=it+4;U-=3)H=`_${F.slice(U-3,U)}${H}`;return`${F.slice(0,U)}${H}`}function rt(F,H,U){G(H,"offset"),(F[H]===void 0||F[H+U]===void 0)&&z(H,F.length-(U+1))}function D(F,H,U,it,pt,ft){if(F>U||F<H){const mt=typeof H=="bigint"?"n":"";let re;throw ft>3?H===0||H===BigInt(0)?re=`>= 0${mt} and < 2${mt} ** ${(ft+1)*8}${mt}`:re=`>= -(2${mt} ** ${(ft+1)*8-1}${mt}) and < 2 ** ${(ft+1)*8-1}${mt}`:re=`>= ${H}${mt} and <= ${U}${mt}`,new R.ERR_OUT_OF_RANGE("value",re,F)}rt(it,pt,ft)}function G(F,H){if(typeof F!="number")throw new R.ERR_INVALID_ARG_TYPE(H,"number",F)}function z(F,H,U){throw Math.floor(F)!==F?(G(F,U),new R.ERR_OUT_OF_RANGE(U||"offset","an integer",F)):H<0?new R.ERR_BUFFER_OUT_OF_BOUNDS:new R.ERR_OUT_OF_RANGE(U||"offset",`>= ${U?1:0} and <= ${H}`,F)}const X=/[^+/0-9A-Za-z-_]/g;function st(F){if(F=F.split("=")[0],F=F.trim().replace(X,""),F.length<2)return"";for(;F.length%4!==0;)F=F+"=";return F}function nt(F,H){H=H||1/0;let U;const it=F.length;let pt=null;const ft=[];for(let mt=0;mt<it;++mt){if(U=F.charCodeAt(mt),U>55295&&U<57344){if(!pt){if(U>56319){(H-=3)>-1&&ft.push(239,191,189);continue}else if(mt+1===it){(H-=3)>-1&&ft.push(239,191,189);continue}pt=U;continue}if(U<56320){(H-=3)>-1&&ft.push(239,191,189),pt=U;continue}U=(pt-55296<<10|U-56320)+65536}else pt&&(H-=3)>-1&&ft.push(239,191,189);if(pt=null,U<128){if((H-=1)<0)break;ft.push(U)}else if(U<2048){if((H-=2)<0)break;ft.push(U>>6|192,U&63|128)}else if(U<65536){if((H-=3)<0)break;ft.push(U>>12|224,U>>6&63|128,U&63|128)}else if(U<1114112){if((H-=4)<0)break;ft.push(U>>18|240,U>>12&63|128,U>>6&63|128,U&63|128)}else throw new Error("Invalid code point")}return ft}function lt(F){const H=[];for(let U=0;U<F.length;++U)H.push(F.charCodeAt(U)&255);return H}function Et(F,H){let U,it,pt;const ft=[];for(let mt=0;mt<F.length&&!((H-=2)<0);++mt)U=F.charCodeAt(mt),it=U>>8,pt=U%256,ft.push(pt),ft.push(it);return ft}function gt(F){return O.toByteArray(st(F))}function bt(F,H,U,it){let pt;for(pt=0;pt<it&&!(pt+U>=H.length||pt>=F.length);++pt)H[pt+U]=F[pt];return pt}function Bt(F,H){return F instanceof H||F!=null&&F.constructor!=null&&F.constructor.name!=null&&F.constructor.name===H.name}function Mt(F){return F!==F}const It=function(){const F="0123456789abcdef",H=new Array(256);for(let U=0;U<16;++U){const it=U*16;for(let pt=0;pt<16;++pt)H[it+pt]=F[U]+F[pt]}return H}();function J(F){return typeof BigInt>"u"?tt:F}function tt(){throw new Error("BigInt not supported")}})(Va),window.Buffer=Va.Buffer,globalThis.Buffer=Va.Buffer;var ve=(K,O,L)=>new Promise((Y,ut)=>{var ht=y=>{try{_(L.next(y))}catch(x){ut(x)}},W=y=>{try{_(L.throw(y))}catch(x){ut(x)}},_=y=>y.done?Y(y.value):Promise.resolve(y.value).then(ht,W);_((L=L.apply(K,O)).next())});class _p extends sp{constructor(O,L){super(O??oc.create(),L)}getKnowledge(O,L){return ve(this,null,function*(){return this.get("/knowledge",{docId:O,name:L})})}postKnowledge(O){return ve(this,null,function*(){return this.post("/knowledge",O)})}getKnowledgeId(O){return ve(this,null,function*(){return this.get(`/knowledge/${O}`)})}patchKnowledgeId(O,L){return ve(this,null,function*(){return this.patch(`/knowledge/${O}`,L)})}delKnowledgeId(O){return ve(this,null,function*(){return this.delete(`/knowledge/${O}`)})}getKnowledgeIdFile(O){return ve(this,null,function*(){return this.get(`/knowledge/${O}/file`)})}getKnowledgeIdFileList(O,L){return ve(this,null,function*(){return this.listPaged(`/knowledge/${O}/file`,L)})}postKnowledgeIdFile(O,L){return ve(this,null,function*(){return this.post(`/knowledge/${O}/file`,L)})}getUploadTicket(O){return ve(this,null,function*(){return this.get("/upload/ticket",O)})}delKnowledgeIdFileFid(O,L){return ve(this,null,function*(){return this.delete(`/knowledge/${O}/file/${L}`)})}patchKnowledgeIdFileFid(O,L,Y){return ve(this,null,function*(){return this.patch(`/knowledge/${O}/file/${L}`,Y)})}listSessions(O,L){return ve(this,null,function*(){return this.get(`/application/${O}/sessionsa`,L)})}postSession(O,L){return ve(this,null,function*(){return this.post(`/application/${O}/sessions`,L)})}getSession(O,L){return ve(this,null,function*(){return this.get(`/application/${O}/sessions/${L}`)})}patchSessionsId(O,L,Y){return ve(this,null,function*(){return this.patch(`/application/${O}/sessions/${L}`,Y)})}delSessionsId(O,L){return ve(this,null,function*(){return this.delete(`/application/${O}/sessions/${L}`)})}getSessionKnowledgeFile(O,L,Y){return ve(this,null,function*(){return this.get(`/application/${O}session/${L}/file/${Y}`)})}postSessionKnowledgeFile(O,L,Y){return ve(this,null,function*(){return this.post(`/application/${O}session/${L}/file`,Y)})}postComments(O,L,Y){return ve(this,null,function*(){return this.post(`/application/${O}/sessions/${L}/comments`,Y)})}getChatHistorySessionId(O,L,Y){return ve(this,null,function*(){return this.get(`application/${O}/chatHistory/${L}`,Y)})}postChatHistorySessionId(O,L){return ve(this,null,function*(){return this.post(`/chatHistory/${O}`,L)})}getApplications(O){return ve(this,null,function*(){return this.get("/applications",O)})}postApplication(O){return ve(this,null,function*(){return this.post("/applications",O)})}getApplicationId(O){return ve(this,null,function*(){return this.get(`/applications/${O}`)})}patchApplicationId(O,L){return ve(this,null,function*(){return this.patch(`/applications/${O}`,L)})}delApplicationId(O){return ve(this,null,function*(){return this.delete(`/applications/${O}`)})}getApplicationIdSessions(O){return ve(this,null,function*(){return this.get(`/applications/${O}/session`)})}patchFileId(O,L){return ve(this,null,function*(){return this.patch(`/file/${O}`,L)})}getCvforceResource(O){return ve(this,null,function*(){return this.get("/cvforce/resource",O)})}postKnowledgeIdComposedFiles(O,L){return ve(this,null,function*(){return this.post(`/knowledge/${O}/composedFiles`,L)})}getTokensApplicationId(O,L){return ve(this,null,function*(){return this.get(`/tokens/${O}`,L)})}getTokens(O){return ve(this,null,function*(){return this.get("/tokens",O)})}uploadMinioFile(O,L){return ve(this,null,function*(){return new Promise((Y,ut)=>{const ht=new FileReader;ht.readAsArrayBuffer(L),ht.onload=W=>{cc.initMinio({endPoint:O.endpoints[0],useSSL:O.useSSL,accessKey:O.accessKey,secretKey:O.secretKey});const _=Buffer.from(W.target.result),y={"Content-Type":"application/octet-stream"};cc.putObjectBuffer(O.bucket,O.fileKeys[0],_,y,x=>{if(x)throw console.error(x),Error(x);Y(O.fileKeys[0])})}})})}uploadFile(O,L){return ve(this,null,function*(){const Y={files:[L.name],isv:"minio",knowledgeId:O};return this.getUploadTicket(Y).then(ut=>this.uploadMinioFile(ut.minio,L)).catch(ut=>{throw Error(ut)})})}uploadFiles(O,L){return ve(this,null,function*(){const Y={files:L.map(ut=>ut.name),isv:"minio",knowledgeId:O};return this.getUploadTicket(Y).then(ut=>Promise.all(L.map(ht=>this.uploadMinioFile(ut.minio,ht)))).catch(ut=>{throw Error(ut)})})}getAecModels(){return ve(this,null,function*(){return this.get("/aecModels")})}postTextFilter(O){return ve(this,null,function*(){return this.post("/textFilter",O)})}getTenantModel(){return ve(this,null,function*(){return this.get("/tenantModel")})}getPrompts(O,L){return ve(this,null,function*(){return this.get(`application/${O}/promptVariables`,L)})}postPrompt(O,L){return ve(this,null,function*(){return this.post(`application/${O}/promptVariables`,L)})}patchPromptId(O,L,Y){return ve(this,null,function*(){return this.patch(`application/${O}/promptVariables/${L}`,Y)})}delPromptId(O,L){return ve(this,null,function*(){return this.delete(`application/${O}/promptVariables/${L}`)})}getSessionPrompts(O){return ve(this,null,function*(){return this.get(`session/${O}/promptVariables`)})}patchSessionPromptId(O,L,Y){return ve(this,null,function*(){return this.patch(`session/${L}/promptVariables/${O}`,Y)})}getApplicationIdSessionIdPromptVariables(O,L){return ve(this,null,function*(){return this.get(`/application/${O}/session/${L}/promptVariables`)})}patchApplicationIdSessionpromptVariablesId(O,L,Y,ut){return ve(this,null,function*(){return this.patch(`/application/${O}/session/${L}/promptVariables/${Y}`,ut)})}getPresetApplication(O){return ve(this,null,function*(){return this.get("presetApplication",O)})}postKnowledgeConfig(O){return ve(this,null,function*(){return this.post("/knowledgeConfig",O)})}getKnowledgeConfig(O){return ve(this,null,function*(){return this.get(`/knowledgeConfig/${O}`)})}patchKnowledgeConfig(O,L){return ve(this,null,function*(){return this.patch(`/knowledgeConfig/${O}`,L)})}getKnowledgeIdFileId(O,L){return ve(this,null,function*(){return this.get(`/knowledge/${O}/file/${L}`)})}getKnowledgeIdFileIdData(O,L,Y){return ve(this,null,function*(){return this.listPaged(`/knowledge/${O}/file/${L}/data`,Y)})}postKnowledgeIdFileIdData(O,L,Y){return ve(this,null,function*(){return this.post(`/knowledge/${O}/file/${L}/data`,{data:Y})})}patchKnowledgeIdFileIdData(O,L,Y,ut){return ve(this,null,function*(){return this.patch(`/knowledge/${O}/file/${L}/data/${Y}`,{data:ut})})}delKnowledgeIdFileIdDataDid(O,L,Y){return ve(this,null,function*(){return this.delete(`/knowledge/${O}/file/${L}/data/${Y}`)})}getPresetKnowledge(O){return ve(this,null,function*(){return this.get("/presetKnowledge",O)})}patchSessionsIdContext(O){return ve(this,null,function*(){return this.patch(`/sessions/${O}/context`,{})})}postResourceToken(O){return ve(this,null,function*(){return this.post("/resourceToken",O)})}getApplicationIdSession(O){return ve(this,null,function*(){return this.get(`/application/${O}/session`)})}patchApplicationIdSessionsIdContext(O,L){return ve(this,null,function*(){return this.patch(`/application/${O}/sessions/${L}/context`,{})})}postApplicationIdSessions(O,L){return ve(this,null,function*(){return this.post(`/application/${O}/sessions`,L)})}getApplicationIdChatHistorySessionId(O,L){return ve(this,null,function*(){return this.get(`/application/${O}/chatHistory/${L}`)})}postApplicationIdChatHistorySessionIdComments(O,L,Y){return ve(this,null,function*(){return this.post(`/application/${O}/sessions/${L}/comments`,Y)})}getApplicationIdPrompts(O,L){return ve(this,null,function*(){return this.get(`/application/${O}/promptVariables`,L)})}postKnowledgeSourceFile(O,L,Y){return ve(this,null,function*(){return this.post(`/knowledge/${O}/sourceFile/${L}`,Y)})}getMetadata(O){return ve(this,null,function*(){return this.get("/metadata",O)})}postGeneques(O){return ve(this,null,function*(){return this.post("/geneques",O)})}getBaseModel(O){return ve(this,null,function*(){return this.get("/baseModelInfo",{serviceId:O})})}}var vr=(K=>(K[K.Robot=1]="Robot",K[K.User=2]="User",K[K.System=3]="System",K))(vr||{}),pc=(K=>(K[K.Idle=0]="Idle",K[K.Quoted=1]="Quoted",K))(pc||{}),bn=(K=>(K[K.Dialog=0]="Dialog",K[K.Text=1]="Text",K[K.Agent=2]="Agent",K[K.All=3]="All",K))(bn||{});function dc(K,O,L){const Y=x=>{var v;return O&&(sf(O)&&L(403,"aiotToken is timeout"),x.headers=(v=x.headers)!==null&&v!==void 0?v:{},x.headers=Object.assign(Object.assign({},x.headers),{Authorization:O?`Bearer ${O}`:""})),x};function ut(x,v=!0){const m=`${K}${x}`,S=oc.create({baseURL:m});return v&&S.interceptors.request.use(Y),S}const ht=(x,v)=>{x===401&&L(x,"aiotToken is invalid")},W=(x,v)=>{x!==10001&&x!==10215&&L(x,v)},_=ut("/data/v1");return new _p(_,{onHttpStatusError:ht,onAppStatusError:W})}const kr=Object.create(null);kr.open="0",kr.close="1",kr.ping="2",kr.pong="3",kr.message="4",kr.upgrade="5",kr.noop="6";const po=Object.create(null);Object.keys(kr).forEach(K=>{po[kr[K]]=K});const Ka={type:"error",data:"parser error"},mc=typeof Blob=="function"||typeof Blob<"u"&&Object.prototype.toString.call(Blob)==="[object BlobConstructor]",gc=typeof ArrayBuffer=="function",vc=K=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(K):K&&K.buffer instanceof ArrayBuffer,Ja=({type:K,data:O},L,Y)=>mc&&O instanceof Blob?L?Y(O):yc(O,Y):gc&&(O instanceof ArrayBuffer||vc(O))?L?Y(O):yc(new Blob([O]),Y):Y(kr[K]+(O||"")),yc=(K,O)=>{const L=new FileReader;return L.onload=function(){const Y=L.result.split(",")[1];O("b"+(Y||""))},L.readAsDataURL(K)};function bc(K){return K instanceof Uint8Array?K:K instanceof ArrayBuffer?new Uint8Array(K):new Uint8Array(K.buffer,K.byteOffset,K.byteLength)}let Ga;function Sp(K,O){if(mc&&K.data instanceof Blob)return K.data.arrayBuffer().then(bc).then(O);if(gc&&(K.data instanceof ArrayBuffer||vc(K.data)))return O(bc(K.data));Ja(K,!1,L=>{Ga||(Ga=new TextEncoder),O(Ga.encode(L))})}const wc="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Cn=typeof Uint8Array>"u"?[]:new Uint8Array(256);for(let K=0;K<wc.length;K++)Cn[wc.charCodeAt(K)]=K;const Ep=K=>{let O=K.length*.75,L=K.length,Y,ut=0,ht,W,_,y;K[K.length-1]==="="&&(O--,K[K.length-2]==="="&&O--);const x=new ArrayBuffer(O),v=new Uint8Array(x);for(Y=0;Y<L;Y+=4)ht=Cn[K.charCodeAt(Y)],W=Cn[K.charCodeAt(Y+1)],_=Cn[K.charCodeAt(Y+2)],y=Cn[K.charCodeAt(Y+3)],v[ut++]=ht<<2|W>>4,v[ut++]=(W&15)<<4|_>>2,v[ut++]=(_&3)<<6|y&63;return x},kp=typeof ArrayBuffer=="function",Ya=(K,O)=>{if(typeof K!="string")return{type:"message",data:Mc(K,O)};const L=K.charAt(0);return L==="b"?{type:"message",data:Ip(K.substring(1),O)}:po[L]?K.length>1?{type:po[L],data:K.substring(1)}:{type:po[L]}:Ka},Ip=(K,O)=>{if(kp){const L=Ep(K);return Mc(L,O)}else return{base64:!0,data:K}},Mc=(K,O)=>{switch(O){case"blob":return K instanceof Blob?K:new Blob([K]);case"arraybuffer":default:return K instanceof ArrayBuffer?K:K.buffer}},xc=String.fromCharCode(30),Op=(K,O)=>{const L=K.length,Y=new Array(L);let ut=0;K.forEach((ht,W)=>{Ja(ht,!1,_=>{Y[W]=_,++ut===L&&O(Y.join(xc))})})},Ap=(K,O)=>{const L=K.split(xc),Y=[];for(let ut=0;ut<L.length;ut++){const ht=Ya(L[ut],O);if(Y.push(ht),ht.type==="error")break}return Y};function Tp(){return new TransformStream({transform(K,O){Sp(K,L=>{const Y=L.length;let ut;if(Y<126)ut=new Uint8Array(1),new DataView(ut.buffer).setUint8(0,Y);else if(Y<65536){ut=new Uint8Array(3);const ht=new DataView(ut.buffer);ht.setUint8(0,126),ht.setUint16(1,Y)}else{ut=new Uint8Array(9);const ht=new DataView(ut.buffer);ht.setUint8(0,127),ht.setBigUint64(1,BigInt(Y))}K.data&&typeof K.data!="string"&&(ut[0]|=128),O.enqueue(ut),O.enqueue(L)})}})}let Qa;function mo(K){return K.reduce((O,L)=>O+L.length,0)}function go(K,O){if(K[0].length===O)return K.shift();const L=new Uint8Array(O);let Y=0;for(let ut=0;ut<O;ut++)L[ut]=K[0][Y++],Y===K[0].length&&(K.shift(),Y=0);return K.length&&Y<K[0].length&&(K[0]=K[0].slice(Y)),L}function Bp(K,O){Qa||(Qa=new TextDecoder);const L=[];let Y=0,ut=-1,ht=!1;return new TransformStream({transform(W,_){for(L.push(W);;){if(Y===0){if(mo(L)<1)break;const y=go(L,1);ht=(y[0]&128)===128,ut=y[0]&127,ut<126?Y=3:ut===126?Y=1:Y=2}else if(Y===1){if(mo(L)<2)break;const y=go(L,2);ut=new DataView(y.buffer,y.byteOffset,y.length).getUint16(0),Y=3}else if(Y===2){if(mo(L)<8)break;const y=go(L,8),x=new DataView(y.buffer,y.byteOffset,y.length),v=x.getUint32(0);if(v>Math.pow(2,53-32)-1){_.enqueue(Ka);break}ut=v*Math.pow(2,32)+x.getUint32(4),Y=3}else{if(mo(L)<ut)break;const y=go(L,ut);_.enqueue(Ya(ht?y:Qa.decode(y),O)),Y=0}if(ut===0||ut>K){_.enqueue(Ka);break}}}})}const _c=4;function Bi(K){if(K)return jp(K)}function jp(K){for(var O in Bi.prototype)K[O]=Bi.prototype[O];return K}Bi.prototype.on=Bi.prototype.addEventListener=function(K,O){return this._callbacks=this._callbacks||{},(this._callbacks["$"+K]=this._callbacks["$"+K]||[]).push(O),this},Bi.prototype.once=function(K,O){function L(){this.off(K,L),O.apply(this,arguments)}return L.fn=O,this.on(K,L),this},Bi.prototype.off=Bi.prototype.removeListener=Bi.prototype.removeAllListeners=Bi.prototype.removeEventListener=function(K,O){if(this._callbacks=this._callbacks||{},arguments.length==0)return this._callbacks={},this;var L=this._callbacks["$"+K];if(!L)return this;if(arguments.length==1)return delete this._callbacks["$"+K],this;for(var Y,ut=0;ut<L.length;ut++)if(Y=L[ut],Y===O||Y.fn===O){L.splice(ut,1);break}return L.length===0&&delete this._callbacks["$"+K],this},Bi.prototype.emit=function(K){this._callbacks=this._callbacks||{};for(var O=new Array(arguments.length-1),L=this._callbacks["$"+K],Y=1;Y<arguments.length;Y++)O[Y-1]=arguments[Y];if(L){L=L.slice(0);for(var Y=0,ut=L.length;Y<ut;++Y)L[Y].apply(this,O)}return this},Bi.prototype.emitReserved=Bi.prototype.emit,Bi.prototype.listeners=function(K){return this._callbacks=this._callbacks||{},this._callbacks["$"+K]||[]},Bi.prototype.hasListeners=function(K){return!!this.listeners(K).length};const ur=(()=>typeof self<"u"?self:typeof window<"u"?window:Function("return this")())();function Sc(K,...O){return O.reduce((L,Y)=>(K.hasOwnProperty(Y)&&(L[Y]=K[Y]),L),{})}const Rp=ur.setTimeout,Np=ur.clearTimeout;function vo(K,O){O.useNativeTimers?(K.setTimeoutFn=Rp.bind(ur),K.clearTimeoutFn=Np.bind(ur)):(K.setTimeoutFn=ur.setTimeout.bind(ur),K.clearTimeoutFn=ur.clearTimeout.bind(ur))}const Cp=1.33;function Pp(K){return typeof K=="string"?Lp(K):Math.ceil((K.byteLength||K.size)*Cp)}function Lp(K){let O=0,L=0;for(let Y=0,ut=K.length;Y<ut;Y++)O=K.charCodeAt(Y),O<128?L+=1:O<2048?L+=2:O<55296||O>=57344?L+=3:(Y++,L+=4);return L}function Dp(K){let O="";for(let L in K)K.hasOwnProperty(L)&&(O.length&&(O+="&"),O+=encodeURIComponent(L)+"="+encodeURIComponent(K[L]));return O}function Up(K){let O={},L=K.split("&");for(let Y=0,ut=L.length;Y<ut;Y++){let ht=L[Y].split("=");O[decodeURIComponent(ht[0])]=decodeURIComponent(ht[1])}return O}class qp extends Error{constructor(O,L,Y){super(O),this.description=L,this.context=Y,this.type="TransportError"}}class ts extends Bi{constructor(O){super(),this.writable=!1,vo(this,O),this.opts=O,this.query=O.query,this.socket=O.socket}onError(O,L,Y){return super.emitReserved("error",new qp(O,L,Y)),this}open(){return this.readyState="opening",this.doOpen(),this}close(){return(this.readyState==="opening"||this.readyState==="open")&&(this.doClose(),this.onClose()),this}send(O){this.readyState==="open"&&this.write(O)}onOpen(){this.readyState="open",this.writable=!0,super.emitReserved("open")}onData(O){const L=Ya(O,this.socket.binaryType);this.onPacket(L)}onPacket(O){super.emitReserved("packet",O)}onClose(O){this.readyState="closed",super.emitReserved("close",O)}pause(O){}createUri(O,L={}){return O+"://"+this._hostname()+this._port()+this.opts.path+this._query(L)}_hostname(){const O=this.opts.hostname;return O.indexOf(":")===-1?O:"["+O+"]"}_port(){return this.opts.port&&(this.opts.secure&&+(this.opts.port!==443)||!this.opts.secure&&Number(this.opts.port)!==80)?":"+this.opts.port:""}_query(O){const L=Dp(O);return L.length?"?"+L:""}}const Ec="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_".split(""),es=64,Fp={};let kc=0,yo=0,Ic;function Oc(K){let O="";do O=Ec[K%es]+O,K=Math.floor(K/es);while(K>0);return O}function Ac(){const K=Oc(+new Date);return K!==Ic?(kc=0,Ic=K):K+"."+Oc(kc++)}for(;yo<es;yo++)Fp[Ec[yo]]=yo;let Tc=!1;try{Tc=typeof XMLHttpRequest<"u"&&"withCredentials"in new XMLHttpRequest}catch{}const zp=Tc;function Bc(K){const O=K.xdomain;try{if(typeof XMLHttpRequest<"u"&&(!O||zp))return new XMLHttpRequest}catch{}if(!O)try{return new ur[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP")}catch{}}function Lm(){}function $p(){}const Hp=function(){return new Bc({xdomain:!1}).responseType!=null}();class Wp extends ts{constructor(O){if(super(O),this.polling=!1,typeof location<"u"){const Y=location.protocol==="https:";let ut=location.port;ut||(ut=Y?"443":"80"),this.xd=typeof location<"u"&&O.hostname!==location.hostname||ut!==O.port}const L=O&&O.forceBase64;this.supportsBinary=Hp&&!L,this.opts.withCredentials&&(this.cookieJar=void 0)}get name(){return"polling"}doOpen(){this.poll()}pause(O){this.readyState="pausing";const L=()=>{this.readyState="paused",O()};if(this.polling||!this.writable){let Y=0;this.polling&&(Y++,this.once("pollComplete",function(){--Y||L()})),this.writable||(Y++,this.once("drain",function(){--Y||L()}))}else L()}poll(){this.polling=!0,this.doPoll(),this.emitReserved("poll")}onData(O){const L=Y=>{if(this.readyState==="opening"&&Y.type==="open"&&this.onOpen(),Y.type==="close")return this.onClose({description:"transport closed by the server"}),!1;this.onPacket(Y)};Ap(O,this.socket.binaryType).forEach(L),this.readyState!=="closed"&&(this.polling=!1,this.emitReserved("pollComplete"),this.readyState==="open"&&this.poll())}doClose(){const O=()=>{this.write([{type:"close"}])};this.readyState==="open"?O():this.once("open",O)}write(O){this.writable=!1,Op(O,L=>{this.doWrite(L,()=>{this.writable=!0,this.emitReserved("drain")})})}uri(){const O=this.opts.secure?"https":"http",L=this.query||{};return this.opts.timestampRequests!==!1&&(L[this.opts.timestampParam]=Ac()),!this.supportsBinary&&!L.sid&&(L.b64=1),this.createUri(O,L)}request(O={}){return Object.assign(O,{xd:this.xd,cookieJar:this.cookieJar},this.opts),new Ir(this.uri(),O)}doWrite(O,L){const Y=this.request({method:"POST",data:O});Y.on("success",L),Y.on("error",(ut,ht)=>{this.onError("xhr post error",ut,ht)})}doPoll(){const O=this.request();O.on("data",this.onData.bind(this)),O.on("error",(L,Y)=>{this.onError("xhr poll error",L,Y)}),this.pollXhr=O}}class Ir extends Bi{constructor(O,L){super(),vo(this,L),this.opts=L,this.method=L.method||"GET",this.uri=O,this.data=L.data!==void 0?L.data:null,this.create()}create(){var O;const L=Sc(this.opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");L.xdomain=!!this.opts.xd;const Y=this.xhr=new Bc(L);try{Y.open(this.method,this.uri,!0);try{if(this.opts.extraHeaders){Y.setDisableHeaderCheck&&Y.setDisableHeaderCheck(!0);for(let ut in this.opts.extraHeaders)this.opts.extraHeaders.hasOwnProperty(ut)&&Y.setRequestHeader(ut,this.opts.extraHeaders[ut])}}catch{}if(this.method==="POST")try{Y.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch{}try{Y.setRequestHeader("Accept","*/*")}catch{}(O=this.opts.cookieJar)===null||O===void 0||O.addCookies(Y),"withCredentials"in Y&&(Y.withCredentials=this.opts.withCredentials),this.opts.requestTimeout&&(Y.timeout=this.opts.requestTimeout),Y.onreadystatechange=()=>{var ut;Y.readyState===3&&((ut=this.opts.cookieJar)===null||ut===void 0||ut.parseCookies(Y)),Y.readyState===4&&(Y.status===200||Y.status===1223?this.onLoad():this.setTimeoutFn(()=>{this.onError(typeof Y.status=="number"?Y.status:0)},0))},Y.send(this.data)}catch(ut){this.setTimeoutFn(()=>{this.onError(ut)},0);return}typeof document<"u"&&(this.index=Ir.requestsCount++,Ir.requests[this.index]=this)}onError(O){this.emitReserved("error",O,this.xhr),this.cleanup(!0)}cleanup(O){if(!(typeof this.xhr>"u"||this.xhr===null)){if(this.xhr.onreadystatechange=$p,O)try{this.xhr.abort()}catch{}typeof document<"u"&&delete Ir.requests[this.index],this.xhr=null}}onLoad(){const O=this.xhr.responseText;O!==null&&(this.emitReserved("data",O),this.emitReserved("success"),this.cleanup())}abort(){this.cleanup()}}if(Ir.requestsCount=0,Ir.requests={},typeof document<"u"){if(typeof attachEvent=="function")attachEvent("onunload",jc);else if(typeof addEventListener=="function"){const K="onpagehide"in ur?"pagehide":"unload";addEventListener(K,jc,!1)}}function jc(){for(let K in Ir.requests)Ir.requests.hasOwnProperty(K)&&Ir.requests[K].abort()}const is=(()=>typeof Promise=="function"&&typeof Promise.resolve=="function"?O=>Promise.resolve().then(O):(O,L)=>L(O,0))(),bo=ur.WebSocket||ur.MozWebSocket,Rc=!0,Vp="arraybuffer",Nc=typeof navigator<"u"&&typeof navigator.product=="string"&&navigator.product.toLowerCase()==="reactnative";class Xp extends ts{constructor(O){super(O),this.supportsBinary=!O.forceBase64}get name(){return"websocket"}doOpen(){if(!this.check())return;const O=this.uri(),L=this.opts.protocols,Y=Nc?{}:Sc(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(Y.headers=this.opts.extraHeaders);try{this.ws=Rc&&!Nc?L?new bo(O,L):new bo(O):new bo(O,L,Y)}catch(ut){return this.emitReserved("error",ut)}this.ws.binaryType=this.socket.binaryType,this.addEventListeners()}addEventListeners(){this.ws.onopen=()=>{this.opts.autoUnref&&this.ws._socket.unref(),this.onOpen()},this.ws.onclose=O=>this.onClose({description:"websocket connection closed",context:O}),this.ws.onmessage=O=>this.onData(O.data),this.ws.onerror=O=>this.onError("websocket error",O)}write(O){this.writable=!1;for(let L=0;L<O.length;L++){const Y=O[L],ut=L===O.length-1;Ja(Y,this.supportsBinary,ht=>{const W={};try{Rc&&this.ws.send(ht)}catch{}ut&&is(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){typeof this.ws<"u"&&(this.ws.close(),this.ws=null)}uri(){const O=this.opts.secure?"wss":"ws",L=this.query||{};return this.opts.timestampRequests&&(L[this.opts.timestampParam]=Ac()),this.supportsBinary||(L.b64=1),this.createUri(O,L)}check(){return!!bo}}class Zp extends ts{get name(){return"webtransport"}doOpen(){typeof WebTransport=="function"&&(this.transport=new WebTransport(this.createUri("https"),this.opts.transportOptions[this.name]),this.transport.closed.then(()=>{this.onClose()}).catch(O=>{this.onError("webtransport error",O)}),this.transport.ready.then(()=>{this.transport.createBidirectionalStream().then(O=>{const L=Bp(Number.MAX_SAFE_INTEGER,this.socket.binaryType),Y=O.readable.pipeThrough(L).getReader(),ut=Tp();ut.readable.pipeTo(O.writable),this.writer=ut.writable.getWriter();const ht=()=>{Y.read().then(({done:_,value:y})=>{_||(this.onPacket(y),ht())}).catch(_=>{})};ht();const W={type:"open"};this.query.sid&&(W.data=`{"sid":"${this.query.sid}"}`),this.writer.write(W).then(()=>this.onOpen())})}))}write(O){this.writable=!1;for(let L=0;L<O.length;L++){const Y=O[L],ut=L===O.length-1;this.writer.write(Y).then(()=>{ut&&is(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){var O;(O=this.transport)===null||O===void 0||O.close()}}const Kp={websocket:Xp,webtransport:Zp,polling:Wp},Jp=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,Gp=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function rs(K){if(K.length>2e3)throw"URI too long";const O=K,L=K.indexOf("["),Y=K.indexOf("]");L!=-1&&Y!=-1&&(K=K.substring(0,L)+K.substring(L,Y).replace(/:/g,";")+K.substring(Y,K.length));let ut=Jp.exec(K||""),ht={},W=14;for(;W--;)ht[Gp[W]]=ut[W]||"";return L!=-1&&Y!=-1&&(ht.source=O,ht.host=ht.host.substring(1,ht.host.length-1).replace(/;/g,":"),ht.authority=ht.authority.replace("[","").replace("]","").replace(/;/g,":"),ht.ipv6uri=!0),ht.pathNames=Yp(ht,ht.path),ht.queryKey=Qp(ht,ht.query),ht}function Yp(K,O){const L=/\/{2,9}/g,Y=O.replace(L,"/").split("/");return(O.slice(0,1)=="/"||O.length===0)&&Y.splice(0,1),O.slice(-1)=="/"&&Y.splice(Y.length-1,1),Y}function Qp(K,O){const L={};return O.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(Y,ut,ht){ut&&(L[ut]=ht)}),L}let Cc=class Rn extends Bi{constructor(O,L={}){super(),this.binaryType=Vp,this.writeBuffer=[],O&&typeof O=="object"&&(L=O,O=null),O?(O=rs(O),L.hostname=O.host,L.secure=O.protocol==="https"||O.protocol==="wss",L.port=O.port,O.query&&(L.query=O.query)):L.host&&(L.hostname=rs(L.host).host),vo(this,L),this.secure=L.secure!=null?L.secure:typeof location<"u"&&location.protocol==="https:",L.hostname&&!L.port&&(L.port=this.secure?"443":"80"),this.hostname=L.hostname||(typeof location<"u"?location.hostname:"localhost"),this.port=L.port||(typeof location<"u"&&location.port?location.port:this.secure?"443":"80"),this.transports=L.transports||["polling","websocket","webtransport"],this.writeBuffer=[],this.prevBufferLen=0,this.opts=Object.assign({path:"/engine.io",agent:!1,withCredentials:!1,upgrade:!0,timestampParam:"t",rememberUpgrade:!1,addTrailingSlash:!0,rejectUnauthorized:!0,perMessageDeflate:{threshold:1024},transportOptions:{},closeOnBeforeunload:!1},L),this.opts.path=this.opts.path.replace(/\/$/,"")+(this.opts.addTrailingSlash?"/":""),typeof this.opts.query=="string"&&(this.opts.query=Up(this.opts.query)),this.id=null,this.upgrades=null,this.pingInterval=null,this.pingTimeout=null,this.pingTimeoutTimer=null,typeof addEventListener=="function"&&(this.opts.closeOnBeforeunload&&(this.beforeunloadEventListener=()=>{this.transport&&(this.transport.removeAllListeners(),this.transport.close())},addEventListener("beforeunload",this.beforeunloadEventListener,!1)),this.hostname!=="localhost"&&(this.offlineEventListener=()=>{this.onClose("transport close",{description:"network connection lost"})},addEventListener("offline",this.offlineEventListener,!1))),this.open()}createTransport(O){const L=Object.assign({},this.opts.query);L.EIO=_c,L.transport=O,this.id&&(L.sid=this.id);const Y=Object.assign({},this.opts,{query:L,socket:this,hostname:this.hostname,secure:this.secure,port:this.port},this.opts.transportOptions[O]);return new Kp[O](Y)}open(){let O;if(this.opts.rememberUpgrade&&Rn.priorWebsocketSuccess&&this.transports.indexOf("websocket")!==-1)O="websocket";else if(this.transports.length===0){this.setTimeoutFn(()=>{this.emitReserved("error","No transports available")},0);return}else O=this.transports[0];this.readyState="opening";try{O=this.createTransport(O)}catch{this.transports.shift(),this.open();return}O.open(),this.setTransport(O)}setTransport(O){this.transport&&this.transport.removeAllListeners(),this.transport=O,O.on("drain",this.onDrain.bind(this)).on("packet",this.onPacket.bind(this)).on("error",this.onError.bind(this)).on("close",L=>this.onClose("transport close",L))}probe(O){let L=this.createTransport(O),Y=!1;Rn.priorWebsocketSuccess=!1;const ut=()=>{Y||(L.send([{type:"ping",data:"probe"}]),L.once("packet",m=>{if(!Y)if(m.type==="pong"&&m.data==="probe"){if(this.upgrading=!0,this.emitReserved("upgrading",L),!L)return;Rn.priorWebsocketSuccess=L.name==="websocket",this.transport.pause(()=>{Y||this.readyState!=="closed"&&(v(),this.setTransport(L),L.send([{type:"upgrade"}]),this.emitReserved("upgrade",L),L=null,this.upgrading=!1,this.flush())})}else{const S=new Error("probe error");S.transport=L.name,this.emitReserved("upgradeError",S)}}))};function ht(){Y||(Y=!0,v(),L.close(),L=null)}const W=m=>{const S=new Error("probe error: "+m);S.transport=L.name,ht(),this.emitReserved("upgradeError",S)};function _(){W("transport closed")}function y(){W("socket closed")}function x(m){L&&m.name!==L.name&&ht()}const v=()=>{L.removeListener("open",ut),L.removeListener("error",W),L.removeListener("close",_),this.off("close",y),this.off("upgrading",x)};L.once("open",ut),L.once("error",W),L.once("close",_),this.once("close",y),this.once("upgrading",x),this.upgrades.indexOf("webtransport")!==-1&&O!=="webtransport"?this.setTimeoutFn(()=>{Y||L.open()},200):L.open()}onOpen(){if(this.readyState="open",Rn.priorWebsocketSuccess=this.transport.name==="websocket",this.emitReserved("open"),this.flush(),this.readyState==="open"&&this.opts.upgrade){let O=0;const L=this.upgrades.length;for(;O<L;O++)this.probe(this.upgrades[O])}}onPacket(O){if(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing")switch(this.emitReserved("packet",O),this.emitReserved("heartbeat"),this.resetPingTimeout(),O.type){case"open":this.onHandshake(JSON.parse(O.data));break;case"ping":this.sendPacket("pong"),this.emitReserved("ping"),this.emitReserved("pong");break;case"error":const L=new Error("server error");L.code=O.data,this.onError(L);break;case"message":this.emitReserved("data",O.data),this.emitReserved("message",O.data);break}}onHandshake(O){this.emitReserved("handshake",O),this.id=O.sid,this.transport.query.sid=O.sid,this.upgrades=this.filterUpgrades(O.upgrades),this.pingInterval=O.pingInterval,this.pingTimeout=O.pingTimeout,this.maxPayload=O.maxPayload,this.onOpen(),this.readyState!=="closed"&&this.resetPingTimeout()}resetPingTimeout(){this.clearTimeoutFn(this.pingTimeoutTimer),this.pingTimeoutTimer=this.setTimeoutFn(()=>{this.onClose("ping timeout")},this.pingInterval+this.pingTimeout),this.opts.autoUnref&&this.pingTimeoutTimer.unref()}onDrain(){this.writeBuffer.splice(0,this.prevBufferLen),this.prevBufferLen=0,this.writeBuffer.length===0?this.emitReserved("drain"):this.flush()}flush(){if(this.readyState!=="closed"&&this.transport.writable&&!this.upgrading&&this.writeBuffer.length){const O=this.getWritablePackets();this.transport.send(O),this.prevBufferLen=O.length,this.emitReserved("flush")}}getWritablePackets(){if(!(this.maxPayload&&this.transport.name==="polling"&&this.writeBuffer.length>1))return this.writeBuffer;let L=1;for(let Y=0;Y<this.writeBuffer.length;Y++){const ut=this.writeBuffer[Y].data;if(ut&&(L+=Pp(ut)),Y>0&&L>this.maxPayload)return this.writeBuffer.slice(0,Y);L+=2}return this.writeBuffer}write(O,L,Y){return this.sendPacket("message",O,L,Y),this}send(O,L,Y){return this.sendPacket("message",O,L,Y),this}sendPacket(O,L,Y,ut){if(typeof L=="function"&&(ut=L,L=void 0),typeof Y=="function"&&(ut=Y,Y=null),this.readyState==="closing"||this.readyState==="closed")return;Y=Y||{},Y.compress=Y.compress!==!1;const ht={type:O,data:L,options:Y};this.emitReserved("packetCreate",ht),this.writeBuffer.push(ht),ut&&this.once("flush",ut),this.flush()}close(){const O=()=>{this.onClose("forced close"),this.transport.close()},L=()=>{this.off("upgrade",L),this.off("upgradeError",L),O()},Y=()=>{this.once("upgrade",L),this.once("upgradeError",L)};return(this.readyState==="opening"||this.readyState==="open")&&(this.readyState="closing",this.writeBuffer.length?this.once("drain",()=>{this.upgrading?Y():O()}):this.upgrading?Y():O()),this}onError(O){Rn.priorWebsocketSuccess=!1,this.emitReserved("error",O),this.onClose("transport error",O)}onClose(O,L){(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing")&&(this.clearTimeoutFn(this.pingTimeoutTimer),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),typeof removeEventListener=="function"&&(removeEventListener("beforeunload",this.beforeunloadEventListener,!1),removeEventListener("offline",this.offlineEventListener,!1)),this.readyState="closed",this.id=null,this.emitReserved("close",O,L),this.writeBuffer=[],this.prevBufferLen=0)}filterUpgrades(O){const L=[];let Y=0;const ut=O.length;for(;Y<ut;Y++)~this.transports.indexOf(O[Y])&&L.push(O[Y]);return L}};Cc.protocol=_c;function td(K,O="",L){let Y=K;L=L||typeof location<"u"&&location,K==null&&(K=L.protocol+"//"+L.host),typeof K=="string"&&(K.charAt(0)==="/"&&(K.charAt(1)==="/"?K=L.protocol+K:K=L.host+K),/^(https?|wss?):\/\//.test(K)||(typeof L<"u"?K=L.protocol+"//"+K:K="https://"+K),Y=rs(K)),Y.port||(/^(http|ws)$/.test(Y.protocol)?Y.port="80":/^(http|ws)s$/.test(Y.protocol)&&(Y.port="443")),Y.path=Y.path||"/";const ht=Y.host.indexOf(":")!==-1?"["+Y.host+"]":Y.host;return Y.id=Y.protocol+"://"+ht+":"+Y.port+O,Y.href=Y.protocol+"://"+ht+(L&&L.port===Y.port?"":":"+Y.port),Y}const ed=typeof ArrayBuffer=="function",id=K=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(K):K.buffer instanceof ArrayBuffer,Pc=Object.prototype.toString,rd=typeof Blob=="function"||typeof Blob<"u"&&Pc.call(Blob)==="[object BlobConstructor]",nd=typeof File=="function"||typeof File<"u"&&Pc.call(File)==="[object FileConstructor]";function ns(K){return ed&&(K instanceof ArrayBuffer||id(K))||rd&&K instanceof Blob||nd&&K instanceof File}function wo(K,O){if(!K||typeof K!="object")return!1;if(Array.isArray(K)){for(let L=0,Y=K.length;L<Y;L++)if(wo(K[L]))return!0;return!1}if(ns(K))return!0;if(K.toJSON&&typeof K.toJSON=="function"&&arguments.length===1)return wo(K.toJSON(),!0);for(const L in K)if(Object.prototype.hasOwnProperty.call(K,L)&&wo(K[L]))return!0;return!1}function od(K){const O=[],L=K.data,Y=K;return Y.data=os(L,O),Y.attachments=O.length,{packet:Y,buffers:O}}function os(K,O){if(!K)return K;if(ns(K)){const L={_placeholder:!0,num:O.length};return O.push(K),L}else if(Array.isArray(K)){const L=new Array(K.length);for(let Y=0;Y<K.length;Y++)L[Y]=os(K[Y],O);return L}else if(typeof K=="object"&&!(K instanceof Date)){const L={};for(const Y in K)Object.prototype.hasOwnProperty.call(K,Y)&&(L[Y]=os(K[Y],O));return L}return K}function ad(K,O){return K.data=as(K.data,O),delete K.attachments,K}function as(K,O){if(!K)return K;if(K&&K._placeholder===!0){if(typeof K.num=="number"&&K.num>=0&&K.num<O.length)return O[K.num];throw new Error("illegal attachments")}else if(Array.isArray(K))for(let L=0;L<K.length;L++)K[L]=as(K[L],O);else if(typeof K=="object")for(const L in K)Object.prototype.hasOwnProperty.call(K,L)&&(K[L]=as(K[L],O));return K}const sd=["connect","connect_error","disconnect","disconnecting","newListener","removeListener"],ud=5;var ti;(function(K){K[K.CONNECT=0]="CONNECT",K[K.DISCONNECT=1]="DISCONNECT",K[K.EVENT=2]="EVENT",K[K.ACK=3]="ACK",K[K.CONNECT_ERROR=4]="CONNECT_ERROR",K[K.BINARY_EVENT=5]="BINARY_EVENT",K[K.BINARY_ACK=6]="BINARY_ACK"})(ti||(ti={}));class cd{constructor(O){this.replacer=O}encode(O){return(O.type===ti.EVENT||O.type===ti.ACK)&&wo(O)?this.encodeAsBinary({type:O.type===ti.EVENT?ti.BINARY_EVENT:ti.BINARY_ACK,nsp:O.nsp,data:O.data,id:O.id}):[this.encodeAsString(O)]}encodeAsString(O){let L=""+O.type;return(O.type===ti.BINARY_EVENT||O.type===ti.BINARY_ACK)&&(L+=O.attachments+"-"),O.nsp&&O.nsp!=="/"&&(L+=O.nsp+","),O.id!=null&&(L+=O.id),O.data!=null&&(L+=JSON.stringify(O.data,this.replacer)),L}encodeAsBinary(O){const L=od(O),Y=this.encodeAsString(L.packet),ut=L.buffers;return ut.unshift(Y),ut}}function Lc(K){return Object.prototype.toString.call(K)==="[object Object]"}class ss extends Bi{constructor(O){super(),this.reviver=O}add(O){let L;if(typeof O=="string"){if(this.reconstructor)throw new Error("got plaintext data when reconstructing a packet");L=this.decodeString(O);const Y=L.type===ti.BINARY_EVENT;Y||L.type===ti.BINARY_ACK?(L.type=Y?ti.EVENT:ti.ACK,this.reconstructor=new ld(L),L.attachments===0&&super.emitReserved("decoded",L)):super.emitReserved("decoded",L)}else if(ns(O)||O.base64)if(this.reconstructor)L=this.reconstructor.takeBinaryData(O),L&&(this.reconstructor=null,super.emitReserved("decoded",L));else throw new Error("got binary data when not reconstructing a packet");else throw new Error("Unknown type: "+O)}decodeString(O){let L=0;const Y={type:Number(O.charAt(0))};if(ti[Y.type]===void 0)throw new Error("unknown packet type "+Y.type);if(Y.type===ti.BINARY_EVENT||Y.type===ti.BINARY_ACK){const ht=L+1;for(;O.charAt(++L)!=="-"&&L!=O.length;);const W=O.substring(ht,L);if(W!=Number(W)||O.charAt(L)!=="-")throw new Error("Illegal attachments");Y.attachments=Number(W)}if(O.charAt(L+1)==="/"){const ht=L+1;for(;++L&&!(O.charAt(L)===","||L===O.length););Y.nsp=O.substring(ht,L)}else Y.nsp="/";const ut=O.charAt(L+1);if(ut!==""&&Number(ut)==ut){const ht=L+1;for(;++L;){const W=O.charAt(L);if(W==null||Number(W)!=W){--L;break}if(L===O.length)break}Y.id=Number(O.substring(ht,L+1))}if(O.charAt(++L)){const ht=this.tryParse(O.substr(L));if(ss.isPayloadValid(Y.type,ht))Y.data=ht;else throw new Error("invalid payload")}return Y}tryParse(O){try{return JSON.parse(O,this.reviver)}catch{return!1}}static isPayloadValid(O,L){switch(O){case ti.CONNECT:return Lc(L);case ti.DISCONNECT:return L===void 0;case ti.CONNECT_ERROR:return typeof L=="string"||Lc(L);case ti.EVENT:case ti.BINARY_EVENT:return Array.isArray(L)&&(typeof L[0]=="number"||typeof L[0]=="string"&&sd.indexOf(L[0])===-1);case ti.ACK:case ti.BINARY_ACK:return Array.isArray(L)}}destroy(){this.reconstructor&&(this.reconstructor.finishedReconstruction(),this.reconstructor=null)}}class ld{constructor(O){this.packet=O,this.buffers=[],this.reconPack=O}takeBinaryData(O){if(this.buffers.push(O),this.buffers.length===this.reconPack.attachments){const L=ad(this.reconPack,this.buffers);return this.finishedReconstruction(),L}return null}finishedReconstruction(){this.reconPack=null,this.buffers=[]}}const hd=Object.freeze(Object.defineProperty({__proto__:null,Decoder:ss,Encoder:cd,get PacketType(){return ti},protocol:ud},Symbol.toStringTag,{value:"Module"}));function yr(K,O,L){return K.on(O,L),function(){K.off(O,L)}}const fd=Object.freeze({connect:1,connect_error:1,disconnect:1,disconnecting:1,newListener:1,removeListener:1});class Dc extends Bi{constructor(O,L,Y){super(),this.connected=!1,this.recovered=!1,this.receiveBuffer=[],this.sendBuffer=[],this._queue=[],this._queueSeq=0,this.ids=0,this.acks={},this.flags={},this.io=O,this.nsp=L,Y&&Y.auth&&(this.auth=Y.auth),this._opts=Object.assign({},Y),this.io._autoConnect&&this.open()}get disconnected(){return!this.connected}subEvents(){if(this.subs)return;const O=this.io;this.subs=[yr(O,"open",this.onopen.bind(this)),yr(O,"packet",this.onpacket.bind(this)),yr(O,"error",this.onerror.bind(this)),yr(O,"close",this.onclose.bind(this))]}get active(){return!!this.subs}connect(){return this.connected?this:(this.subEvents(),this.io._reconnecting||this.io.open(),this.io._readyState==="open"&&this.onopen(),this)}open(){return this.connect()}send(...O){return O.unshift("message"),this.emit.apply(this,O),this}emit(O,...L){if(fd.hasOwnProperty(O))throw new Error('"'+O.toString()+'" is a reserved event name');if(L.unshift(O),this._opts.retries&&!this.flags.fromQueue&&!this.flags.volatile)return this._addToQueue(L),this;const Y={type:ti.EVENT,data:L};if(Y.options={},Y.options.compress=this.flags.compress!==!1,typeof L[L.length-1]=="function"){const W=this.ids++,_=L.pop();this._registerAckCallback(W,_),Y.id=W}const ut=this.io.engine&&this.io.engine.transport&&this.io.engine.transport.writable;return this.flags.volatile&&(!ut||!this.connected)||(this.connected?(this.notifyOutgoingListeners(Y),this.packet(Y)):this.sendBuffer.push(Y)),this.flags={},this}_registerAckCallback(O,L){var Y;const ut=(Y=this.flags.timeout)!==null&&Y!==void 0?Y:this._opts.ackTimeout;if(ut===void 0){this.acks[O]=L;return}const ht=this.io.setTimeoutFn(()=>{delete this.acks[O];for(let _=0;_<this.sendBuffer.length;_++)this.sendBuffer[_].id===O&&this.sendBuffer.splice(_,1);L.call(this,new Error("operation has timed out"))},ut),W=(..._)=>{this.io.clearTimeoutFn(ht),L.apply(this,_)};W.withError=!0,this.acks[O]=W}emitWithAck(O,...L){return new Promise((Y,ut)=>{const ht=(W,_)=>W?ut(W):Y(_);ht.withError=!0,L.push(ht),this.emit(O,...L)})}_addToQueue(O){let L;typeof O[O.length-1]=="function"&&(L=O.pop());const Y={id:this._queueSeq++,tryCount:0,pending:!1,args:O,flags:Object.assign({fromQueue:!0},this.flags)};O.push((ut,...ht)=>Y!==this._queue[0]?void 0:(ut!==null?Y.tryCount>this._opts.retries&&(this._queue.shift(),L&&L(ut)):(this._queue.shift(),L&&L(null,...ht)),Y.pending=!1,this._drainQueue())),this._queue.push(Y),this._drainQueue()}_drainQueue(O=!1){if(!this.connected||this._queue.length===0)return;const L=this._queue[0];L.pending&&!O||(L.pending=!0,L.tryCount++,this.flags=L.flags,this.emit.apply(this,L.args))}packet(O){O.nsp=this.nsp,this.io._packet(O)}onopen(){typeof this.auth=="function"?this.auth(O=>{this._sendConnectPacket(O)}):this._sendConnectPacket(this.auth)}_sendConnectPacket(O){this.packet({type:ti.CONNECT,data:this._pid?Object.assign({pid:this._pid,offset:this._lastOffset},O):O})}onerror(O){this.connected||this.emitReserved("connect_error",O)}onclose(O,L){this.connected=!1,delete this.id,this.emitReserved("disconnect",O,L),this._clearAcks()}_clearAcks(){Object.keys(this.acks).forEach(O=>{if(!this.sendBuffer.some(Y=>String(Y.id)===O)){const Y=this.acks[O];delete this.acks[O],Y.withError&&Y.call(this,new Error("socket has been disconnected"))}})}onpacket(O){if(O.nsp===this.nsp)switch(O.type){case ti.CONNECT:O.data&&O.data.sid?this.onconnect(O.data.sid,O.data.pid):this.emitReserved("connect_error",new Error("It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)"));break;case ti.EVENT:case ti.BINARY_EVENT:this.onevent(O);break;case ti.ACK:case ti.BINARY_ACK:this.onack(O);break;case ti.DISCONNECT:this.ondisconnect();break;case ti.CONNECT_ERROR:this.destroy();const Y=new Error(O.data.message);Y.data=O.data.data,this.emitReserved("connect_error",Y);break}}onevent(O){const L=O.data||[];O.id!=null&&L.push(this.ack(O.id)),this.connected?this.emitEvent(L):this.receiveBuffer.push(Object.freeze(L))}emitEvent(O){if(this._anyListeners&&this._anyListeners.length){const L=this._anyListeners.slice();for(const Y of L)Y.apply(this,O)}super.emit.apply(this,O),this._pid&&O.length&&typeof O[O.length-1]=="string"&&(this._lastOffset=O[O.length-1])}ack(O){const L=this;let Y=!1;return function(...ut){Y||(Y=!0,L.packet({type:ti.ACK,id:O,data:ut}))}}onack(O){const L=this.acks[O.id];typeof L=="function"&&(delete this.acks[O.id],L.withError&&O.data.unshift(null),L.apply(this,O.data))}onconnect(O,L){this.id=O,this.recovered=L&&this._pid===L,this._pid=L,this.connected=!0,this.emitBuffered(),this.emitReserved("connect"),this._drainQueue(!0)}emitBuffered(){this.receiveBuffer.forEach(O=>this.emitEvent(O)),this.receiveBuffer=[],this.sendBuffer.forEach(O=>{this.notifyOutgoingListeners(O),this.packet(O)}),this.sendBuffer=[]}ondisconnect(){this.destroy(),this.onclose("io server disconnect")}destroy(){this.subs&&(this.subs.forEach(O=>O()),this.subs=void 0),this.io._destroy(this)}disconnect(){return this.connected&&this.packet({type:ti.DISCONNECT}),this.destroy(),this.connected&&this.onclose("io client disconnect"),this}close(){return this.disconnect()}compress(O){return this.flags.compress=O,this}get volatile(){return this.flags.volatile=!0,this}timeout(O){return this.flags.timeout=O,this}onAny(O){return this._anyListeners=this._anyListeners||[],this._anyListeners.push(O),this}prependAny(O){return this._anyListeners=this._anyListeners||[],this._anyListeners.unshift(O),this}offAny(O){if(!this._anyListeners)return this;if(O){const L=this._anyListeners;for(let Y=0;Y<L.length;Y++)if(O===L[Y])return L.splice(Y,1),this}else this._anyListeners=[];return this}listenersAny(){return this._anyListeners||[]}onAnyOutgoing(O){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.push(O),this}prependAnyOutgoing(O){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.unshift(O),this}offAnyOutgoing(O){if(!this._anyOutgoingListeners)return this;if(O){const L=this._anyOutgoingListeners;for(let Y=0;Y<L.length;Y++)if(O===L[Y])return L.splice(Y,1),this}else this._anyOutgoingListeners=[];return this}listenersAnyOutgoing(){return this._anyOutgoingListeners||[]}notifyOutgoingListeners(O){if(this._anyOutgoingListeners&&this._anyOutgoingListeners.length){const L=this._anyOutgoingListeners.slice();for(const Y of L)Y.apply(this,O.data)}}}function wn(K){K=K||{},this.ms=K.min||100,this.max=K.max||1e4,this.factor=K.factor||2,this.jitter=K.jitter>0&&K.jitter<=1?K.jitter:0,this.attempts=0}wn.prototype.duration=function(){var K=this.ms*Math.pow(this.factor,this.attempts++);if(this.jitter){var O=Math.random(),L=Math.floor(O*this.jitter*K);K=Math.floor(O*10)&1?K+L:K-L}return Math.min(K,this.max)|0},wn.prototype.reset=function(){this.attempts=0},wn.prototype.setMin=function(K){this.ms=K},wn.prototype.setMax=function(K){this.max=K},wn.prototype.setJitter=function(K){this.jitter=K};class us extends Bi{constructor(O,L){var Y;super(),this.nsps={},this.subs=[],O&&typeof O=="object"&&(L=O,O=void 0),L=L||{},L.path=L.path||"/socket.io",this.opts=L,vo(this,L),this.reconnection(L.reconnection!==!1),this.reconnectionAttempts(L.reconnectionAttempts||1/0),this.reconnectionDelay(L.reconnectionDelay||1e3),this.reconnectionDelayMax(L.reconnectionDelayMax||5e3),this.randomizationFactor((Y=L.randomizationFactor)!==null&&Y!==void 0?Y:.5),this.backoff=new wn({min:this.reconnectionDelay(),max:this.reconnectionDelayMax(),jitter:this.randomizationFactor()}),this.timeout(L.timeout==null?2e4:L.timeout),this._readyState="closed",this.uri=O;const ut=L.parser||hd;this.encoder=new ut.Encoder,this.decoder=new ut.Decoder,this._autoConnect=L.autoConnect!==!1,this._autoConnect&&this.open()}reconnection(O){return arguments.length?(this._reconnection=!!O,this):this._reconnection}reconnectionAttempts(O){return O===void 0?this._reconnectionAttempts:(this._reconnectionAttempts=O,this)}reconnectionDelay(O){var L;return O===void 0?this._reconnectionDelay:(this._reconnectionDelay=O,(L=this.backoff)===null||L===void 0||L.setMin(O),this)}randomizationFactor(O){var L;return O===void 0?this._randomizationFactor:(this._randomizationFactor=O,(L=this.backoff)===null||L===void 0||L.setJitter(O),this)}reconnectionDelayMax(O){var L;return O===void 0?this._reconnectionDelayMax:(this._reconnectionDelayMax=O,(L=this.backoff)===null||L===void 0||L.setMax(O),this)}timeout(O){return arguments.length?(this._timeout=O,this):this._timeout}maybeReconnectOnOpen(){!this._reconnecting&&this._reconnection&&this.backoff.attempts===0&&this.reconnect()}open(O){if(~this._readyState.indexOf("open"))return this;this.engine=new Cc(this.uri,this.opts);const L=this.engine,Y=this;this._readyState="opening",this.skipReconnect=!1;const ut=yr(L,"open",function(){Y.onopen(),O&&O()}),ht=_=>{this.cleanup(),this._readyState="closed",this.emitReserved("error",_),O?O(_):this.maybeReconnectOnOpen()},W=yr(L,"error",ht);if(this._timeout!==!1){const _=this._timeout,y=this.setTimeoutFn(()=>{ut(),ht(new Error("timeout")),L.close()},_);this.opts.autoUnref&&y.unref(),this.subs.push(()=>{this.clearTimeoutFn(y)})}return this.subs.push(ut),this.subs.push(W),this}connect(O){return this.open(O)}onopen(){this.cleanup(),this._readyState="open",this.emitReserved("open");const O=this.engine;this.subs.push(yr(O,"ping",this.onping.bind(this)),yr(O,"data",this.ondata.bind(this)),yr(O,"error",this.onerror.bind(this)),yr(O,"close",this.onclose.bind(this)),yr(this.decoder,"decoded",this.ondecoded.bind(this)))}onping(){this.emitReserved("ping")}ondata(O){try{this.decoder.add(O)}catch(L){this.onclose("parse error",L)}}ondecoded(O){is(()=>{this.emitReserved("packet",O)},this.setTimeoutFn)}onerror(O){this.emitReserved("error",O)}socket(O,L){let Y=this.nsps[O];return Y?this._autoConnect&&!Y.active&&Y.connect():(Y=new Dc(this,O,L),this.nsps[O]=Y),Y}_destroy(O){const L=Object.keys(this.nsps);for(const Y of L)if(this.nsps[Y].active)return;this._close()}_packet(O){const L=this.encoder.encode(O);for(let Y=0;Y<L.length;Y++)this.engine.write(L[Y],O.options)}cleanup(){this.subs.forEach(O=>O()),this.subs.length=0,this.decoder.destroy()}_close(){this.skipReconnect=!0,this._reconnecting=!1,this.onclose("forced close"),this.engine&&this.engine.close()}disconnect(){return this._close()}onclose(O,L){this.cleanup(),this.backoff.reset(),this._readyState="closed",this.emitReserved("close",O,L),this._reconnection&&!this.skipReconnect&&this.reconnect()}reconnect(){if(this._reconnecting||this.skipReconnect)return this;const O=this;if(this.backoff.attempts>=this._reconnectionAttempts)this.backoff.reset(),this.emitReserved("reconnect_failed"),this._reconnecting=!1;else{const L=this.backoff.duration();this._reconnecting=!0;const Y=this.setTimeoutFn(()=>{O.skipReconnect||(this.emitReserved("reconnect_attempt",O.backoff.attempts),!O.skipReconnect&&O.open(ut=>{ut?(O._reconnecting=!1,O.reconnect(),this.emitReserved("reconnect_error",ut)):O.onreconnect()}))},L);this.opts.autoUnref&&Y.unref(),this.subs.push(()=>{this.clearTimeoutFn(Y)})}}onreconnect(){const O=this.backoff.attempts;this._reconnecting=!1,this.backoff.reset(),this.emitReserved("reconnect",O)}}const Pn={};function Mo(K,O){typeof K=="object"&&(O=K,K=void 0),O=O||{};const L=td(K,O.path||"/socket.io"),Y=L.source,ut=L.id,ht=L.path,W=Pn[ut]&&ht in Pn[ut].nsps,_=O.forceNew||O["force new connection"]||O.multiplex===!1||W;let y;return _?y=new us(Y,O):(Pn[ut]||(Pn[ut]=new us(Y,O)),y=Pn[ut]),L.query&&!O.query&&(O.query=L.queryKey),y.socket(L.path,O)}Object.assign(Mo,{Manager:us,Socket:Dc,io:Mo,connect:Mo});var nn;(function(K){K[K.Normal=0]="Normal",K[K.Debug=1]="Debug"})(nn||(nn={}));let xo;const pd=new Uint8Array(16);function dd(){if(!xo&&(xo=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!xo))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return xo(pd)}const Li=[];for(let K=0;K<256;++K)Li.push((K+256).toString(16).slice(1));function md(K,O=0){return Li[K[O+0]]+Li[K[O+1]]+Li[K[O+2]]+Li[K[O+3]]+"-"+Li[K[O+4]]+Li[K[O+5]]+"-"+Li[K[O+6]]+Li[K[O+7]]+"-"+Li[K[O+8]]+Li[K[O+9]]+"-"+Li[K[O+10]]+Li[K[O+11]]+Li[K[O+12]]+Li[K[O+13]]+Li[K[O+14]]+Li[K[O+15]]}const Uc={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function qc(K,O,L){if(Uc.randomUUID&&!O&&!K)return Uc.randomUUID();K=K||{};const Y=K.random||(K.rng||dd)();if(Y[6]=Y[6]&15|64,Y[8]=Y[8]&63|128,O){L=L||0;for(let ut=0;ut<16;++ut)O[L+ut]=Y[ut];return O}return md(Y)}const on=new Pi("[EventBus] ");class Fc{constructor(O=!1){Object.defineProperty(this,"eventListenerMap",{enumerable:!0,configurable:!0,writable:!0,value:{}}),O&&on.disable()}getEventListenerMap(){return Object.assign({},this.eventListenerMap)}on(O,L,Y=!1){this.eventListenerMap[O]||(this.eventListenerMap[O]=[]),Y?this.eventListenerMap[O].push({fn:L,once:!0}):this.eventListenerMap[O].push(L),on.log(`add event ${O} listener ${Y?", call once":""}`)}once(O,L){this.on(O,L,!0)}off(O,L){if(this.eventListenerMap[O]){const Y=this.eventListenerMap[O].findIndex(ut=>{if(typeof ut=="function"&&L===ut)return!0;if(ut=ut,ut.fn===L)return!0});Y<0?on.log(`event ${O} listener ${L.name} is not found`):(this.eventListenerMap[O].splice(Y,1),on.log(`remove event ${O} listener`))}else on.log(`event ${O} listeners is empty`)}emit(O,L){if(!this.eventListenerMap[O]){on.log(`event ${O} listeners is empty`);return}const Y=[];for(let ut=0;ut<this.eventListenerMap[O].length;ut++){const ht=this.eventListenerMap[O][ut];typeof ht=="function"?ht(L):Y.push(ht)}Y.forEach(ut=>{ut&&(ut.fn(L),this.off(O,ut.fn))}),on.log(`event ${O} is fired, has ${this.eventListenerMap[O].length} listeners`)}removeAllListeners(){this.eventListenerMap={}}}var _o;(function(K){K[K.enable=1]="enable",K[K.disable=2]="disable"})(_o||(_o={}));const zi=new Pi("[Session] ");var $i;(function(K){K.DataRequestFailed="data request error",K.SocketConnectionFailed="socket error",K.IdUndefined="session id is not defined",K.SendingEmptyContent="failed at sending empty content",K.Frozen="session is frozen",K.UserModeError="failed at setting socket user mode",K.Inactive="session is inactive"})($i||($i={})),$i.IdUndefined+"",$i.SendingEmptyContent+"",$i.Frozen+"";class cs{constructor(O,L="",Y,ut,ht,W){Object.defineProperty(this,"token",{enumerable:!0,configurable:!0,writable:!0,value:O}),Object.defineProperty(this,"lazyload",{enumerable:!0,configurable:!0,writable:!0,value:ut}),Object.defineProperty(this,"_id",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_frozen",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"inactivating",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_ready",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"event",{enumerable:!0,configurable:!0,writable:!0,value:new Fc}),Object.defineProperty(this,"_applicationId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_application",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"data",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"client",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"messages",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_loadingMessages",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_loadingMessagesSize",{enumerable:!0,configurable:!0,writable:!0,value:10}),Object.defineProperty(this,"cvforceApi",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"socket",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_promptVariables",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"active",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"activing",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_stopAnswer",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_dataLoading",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_dataLoaded",{enumerable:!0,configurable:!0,writable:!0,value:!1}),this.client=W||null,this._applicationId=oo(O).rid||Mi.configuration.applicationId,this.cvforceApi=this.getService(),ht&&(this._application=ht),this.event.emit("init",{applicationId:this._applicationId,sessionId:L}),this.loadApplicationInfo().then(()=>{var _;if(L)this._id=L,this.event.emit("data:loading"),Y?(this.data=Y,ut||(this._dataLoading=!0,this.cvforceApi.getSession(this.applicationId,L).then(y=>Le(this,void 0,void 0,function*(){this.data=y,this._promptVariables=yield this.cvforceApi.getApplicationIdSessionIdPromptVariables(this.applicationId,L)})).then(()=>Le(this,void 0,void 0,function*(){this.messages=[],yield this.fetchMessages(),this.event.emit("data:loaded",this.data),this.event.emit("data:updated",this.data)})))):(this._dataLoading=!0,this.cvforceApi.getSession(this.applicationId,L).then(y=>Le(this,void 0,void 0,function*(){this.data=y,this._promptVariables=yield this.cvforceApi.getApplicationIdSessionIdPromptVariables(this.applicationId,L)})).then(()=>Le(this,void 0,void 0,function*(){this.messages=[],yield this.fetchMessages(),this.event.emit("data:loaded",this.data),this.event.emit("data:updated",this.data),this._dataLoading=!1,this._dataLoaded=!0})));else{const y=(Y==null?void 0:Y.name)||"新建会话";this.event.emit("data:creating",{applicationId:this._applicationId,name:y}),this.event.emit("data:loading"),this.cvforceApi.postSession(this.applicationId,{name:y,netOpen:Y==null?void 0:Y.netOpen,knowledgeList:(_=Y==null?void 0:Y.knowledges)===null||_===void 0?void 0:_.map(x=>x.id),applicationId:this._applicationId}).then(x=>Le(this,void 0,void 0,function*(){this._id=x.id,this.data=x,this._promptVariables=yield this.cvforceApi.getApplicationIdSessionIdPromptVariables(this.applicationId,this._id),yield(()=>{if(Y!=null&&Y.knowledges)return this.setKnowledges((Y==null?void 0:Y.knowledges)||void 0)})(),yield(()=>{if(Y!=null&&Y.promptVariables){const v=this._promptVariables.map(m=>{var S,a;const p=((a=(S=Y.promptVariables)===null||S===void 0?void 0:S.find(c=>c.key===m.key))===null||a===void 0?void 0:a.value)||"";return Object.assign(Object.assign({},m),{value:p})}).sort((m,S)=>m.key.localeCompare(S.key));return this.setPromptVariables(v||[])}else return})(),this.event.emit("data:created",this.data),this.event.emit("data:loaded",this.data),this.event.emit("data:updated",this.data),this._ready=!0,this.event.emit("ready")}))}})}fetchData(){return Le(this,void 0,void 0,function*(){if(!this.data)throw Error("session data is not loaded");return yield this.cvforceApi.getSession(this.applicationId,this.data.id).then(O=>Le(this,void 0,void 0,function*(){return this.data=O,this.event.emit("data:updated",this.data),O}))})}get id(){var O;return this._id||((O=this.data)===null||O===void 0?void 0:O.id)||""}get applicationId(){return this._applicationId}get application(){return this._application}loadApplicationInfo(){if(this._application)return Promise.resolve(this._application);if(this._applicationId&&!this._application)return this.event.emit("application:data:loading"),this.cvforceApi.getApplicationId(this._applicationId).then(O=>(this._application=O,this.event.emit("application:data:loaded",O),O));throw Error("application id is not defined")}get ready(){return this._ready}get frozen(){return this._frozen}set frozen(O){O===!1&&this.inactivating&&this.socket&&(this.socket.disconnect(),this.socket=null,this.event.emit("inactivated")),this._frozen=O,this.event.emit("frozen",O)}get knowledges(){if(!this.data)throw Error("session data is not loaded");return this.data.knowledges||void 0}setKnowledges(O){return Le(this,void 0,void 0,function*(){var L;if(((L=this._application)===null||L===void 0?void 0:L.type)===bn.Agent){console.warn("Agent Application Sessions are disabled to setKnowledges.");return}if(!this.data)throw Error("session data is not loaded");return yield this.cvforceApi.patchSessionsId(this._applicationId,this.data.id,{knowledges:O}),this.data.knowledges=O,this.event.emit("data:updated",this.data),this.event.emit("data:updated:knowledges",{knowledges:O}),O})}validateConfigs(){if(!this._id)throw Error("session id is not defined");if(!this.data)throw Error("session data is not loaded");const O=this.promptVariables.filter(L=>L.status===pc.Quoted).filter(L=>!L.value);if(O.length)throw Error(`在提示词中被引用的变量值不能为空, 请检查以下变量: ${O.map(L=>L.key).join(", ")}`)}get promptVariables(){return this._promptVariables.filter(O=>O.key!=="query")}setPromptVariables(O){return Le(this,void 0,void 0,function*(){var L;if(((L=this._application)===null||L===void 0?void 0:L.type)===bn.Agent){console.warn("Agent Application Sessions are disabled to setPromptVariables.");return}const Y=this._promptVariables.map(ut=>{var ht;const W=((ht=O==null?void 0:O.find(_=>_.key===ut.key))===null||ht===void 0?void 0:ht.value)||ut.value;return Object.assign(Object.assign({},ut),{value:W})}).sort((ut,ht)=>ut.key.localeCompare(ht.key));if(yield Promise.all(Y.filter(ut=>ut.key!=="query").map(ut=>{if(!this.data)throw Error("session data is not loaded");if(!(!ut.id||!ut.key))return this.cvforceApi.patchApplicationIdSessionpromptVariablesId(this._applicationId,this.data.id,ut.id,{value:ut.value}).catch(console.error)})),!this.data)throw Error("session data is not loaded");return this._promptVariables=yield this.cvforceApi.getApplicationIdSessionIdPromptVariables(this.applicationId,this.data.id),this.event.emit("data:updated",this.data),this.event.emit("data:updated:promptVariables",{promptVariables:this._promptVariables}),this._promptVariables})}get netOpen(){if(!this.data)throw Error("session data is not loaded");return this.data.netOpen||!1}setNetOpen(O){return Le(this,void 0,void 0,function*(){var L,Y,ut;if(zi.log("setNetOpen:",O),zi.log("application arrange setting value: ",(L=this._application)===null||L===void 0?void 0:L.arrange[0].enableNetOpen),((Y=this._application)===null||Y===void 0?void 0:Y.type)===bn.Agent){console.warn("Agent Application Sessions are disabled to setNetOpen.");return}if(((ut=this._application)===null||ut===void 0?void 0:ut.arrange[0].enableNetOpen)===!1){console.warn("This Application is disabled to change netOpen.");return}if(!this.data)throw Error("session data is not loaded");return yield this.cvforceApi.patchSessionsId(this._applicationId,this.data.id,{netOpen:O?_o.enable:_o.disable}),this.data.netOpen=O,zi.log("data:updated",this.data),this.event.emit("data:updated",this.data),this.event.emit("data:updated:netOpen",{netOpen:O}),O})}getService(){return dc(Mi.configuration.apiRoot,this.token,(O,L)=>{const Y=new Error($i.DataRequestFailed);zi.error(Y),this.event.emit("error",Y)})}addEventListener(O,L,Y=!1){if(typeof L!="function")throw Error("event listener is not a function");if(Y){this.event.once(O,L);return}this.event.on(O,L)}removeEventListener(O,L){this.event.off(O,L)}fetchMessages(){return Le(this,arguments,void 0,function*(O={}){var L,Y;const ut={pageSize:this._loadingMessagesSize};if(this._id){O=Object.assign(Object.assign({},ut),O),this.event.emit("history:loading"),zi.log("history:loading"),(O.endTime||O.startTime)&&(this.event.emit("history:moreloading",O),zi.log("history:moreloading",O)),this._loadingMessages=!0;const ht=yield this.cvforceApi.getChatHistorySessionId(this._applicationId,this._id,O),W=ht.map((y,x)=>{var v,m;let S=[],a;return typeof((v=y.agentHistoryList)===null||v===void 0?void 0:v.agentList)=="string"&&(S=JSON.parse(y.agentHistoryList.agentList).reduce((c,l)=>(c[l.data.step-1]||(c[l.data.step-1]=[]),c[l.data.step-1].push(l),c),[])),x===ht.length-1&&(a=(m=this.data)===null||m===void 0?void 0:m.lastRelatedQuestion),Object.assign(Object.assign({},y),{actions:S,relatedQuesion:a})});if(!O.endTime&&!O.startTime){const y=this.messages[this.messages.length-1];y&&!y.relatedQuesion&&(y.relatedQuesion=(L=this.data)===null||L===void 0?void 0:L.lastRelatedQuestion),this.messages=[...W,...this.messages]}else if(O.endTime&&!O.startTime){const y=this.messages.findIndex(x=>x.ts===O.endTime);this.messages.splice(0,y+1),this.messages=[...W,...this.messages]}else if(!O.endTime&&O.startTime){const y=this.messages.findLastIndex(x=>x.ts===O.endTime);this.messages.splice(y,this.messages.length-y-1),this.messages=[...this.messages,...W]}else{const y=this.messages.findIndex(v=>v.ts===O.endTime),x=this.messages.findLastIndex(v=>v.ts===O.endTime);this.messages.splice(y,x-y+1,...W)}const _=this.messages[this.messages.length-1];return _&&!_.relatedQuesion&&(_.relatedQuesion=(Y=this.data)===null||Y===void 0?void 0:Y.lastRelatedQuestion),this.event.emit("history:moreloaded",W),zi.log("history:loaded",this.messages),this.event.emit("history:loaded",this.messages),this._loadingMessages=!1,W}else{const ht=new Error($i.IdUndefined);return zi.error(ht),this.event.emit("error",ht),!1}})}rename(O){return Le(this,void 0,void 0,function*(){if(!this._id)throw Error("session is not created yet");if(O.trim()==="")throw Error("name is empty");return this.data=yield this.cvforceApi.patchSessionsId(this.applicationId,this._id,{name:O}),zi.log("data:updated",this.messages),this.event.emit("data:updated",this.data),this.event.emit("data:updated:name",{name:O}),!0})}pushMessage(O){return Le(this,void 0,void 0,function*(){this.messages.push(O),zi.log("history:add",O),this.event.emit("history:add",O),this.event.emit("message:new",O),this.event.emit("message:updated",O)})}reloadSessionInfo(){if(!this._id)throw Error("session is not created yet");return this._dataLoading=!0,this.cvforceApi.getSession(this.applicationId,this._id).then(O=>Le(this,void 0,void 0,function*(){if(this.data=O,!this._id)throw Error("session is not created yet");return this._promptVariables=yield this.cvforceApi.getApplicationIdSessionIdPromptVariables(this.applicationId,this._id),zi.log("data:updated",this.data),this.event.emit("data:updated",this.data),this.data})).then(()=>Le(this,void 0,void 0,function*(){return this.messages=[],yield this.fetchMessages(),this._dataLoading=!1,this._dataLoaded=!0,this.event.emit("data:loaded",this.data),this}))}reload(){return Le(this,void 0,void 0,function*(){return yield this.reloadSessionInfo(),this.socket?(this.inactivate(!0),this.activate()):(this.inactivate(!0),this.activate())})}delete(){return Le(this,void 0,void 0,function*(){if(!this.id){const O=new Error($i.IdUndefined);return zi.error(O),this.event.emit("error",O),!1}return this.event.emit("data:deleting"),yield this.cvforceApi.delSessionsId(this.applicationId,this.id),this.event.emit("data:deleted"),this.destroy()})}activate(){return Le(this,void 0,void 0,function*(){if(this.activing)return new Promise(L=>{this.addEventListener("activated",()=>{L(!0)},!0)});if(!this._id)throw Error("session is not avalible. id is undefined");this.activing=!0;const O=this._id;return this._dataLoading=!0,this._dataLoaded=!1,this.data=yield this.cvforceApi.getSession(this.applicationId,O).then(L=>Le(this,void 0,void 0,function*(){return this._promptVariables=yield this.cvforceApi.getApplicationIdSessionIdPromptVariables(this.applicationId,O),L})),this.messages.length||(this.messages=[],yield this.fetchMessages()),this.event.emit("data:loaded",this.data),this.event.emit("data:updated",this.data),this._dataLoaded=!0,this._dataLoading=!1,this.inactivating=!1,this.frozen=!0,yield this.prepareConnection(),this.event.emit("activated",this.socket),this.active=!0,this.activing=!1,this})}inactivate(O=!1){return this.socket?this._frozen?(O||(this.inactivating=!0),this.activing=!1,!0):(this.socket.close(),this.socket=null,this.event.emit("inactivated"),this.active=!1,this.activing=!1,!0):(this.activing=!1,!0)}get dataLoaded(){return this._dataLoaded}send(O){return Le(this,arguments,void 0,function*(L,Y={stream:!1}){var ut;try{this.validateConfigs()}catch(a){console.error(a)}const{stream:ht=!1,referenceFirst:W=!1}=Y,_=L.uuid||qc(),y=((ut=L.text)===null||ut===void 0?void 0:ut.trim())||"",x=L.fileIds;if(!y&&!(x!=null&&x.length)){const a=new Error($i.SendingEmptyContent);return zi.error(a),this.event.emit("error",a),!1}if(!this._id){const a=new Error($i.IdUndefined);return zi.error(a),this.event.emit("error",a),!1}if(this.frozen){const a=new Error($i.Frozen);return zi.error(a),this.event.emit("error",a),!1}this.frozen=!0,this._stopAnswer=!1;const v={sessionId:this.id,role:2,content:y,messageId:_,reference:[],searchReference:[],messageTime:""},m={content:y,stream:ht,requestId:_,fileIds:x,referenceFirst:W};this.pushMessage(v),this.event.emit("question:content",y);const S=a=>Le(this,void 0,void 0,function*(){if(a.role!==vr.Robot)return;switch(this.removeEventListener("answer:finish",S),this._id&&a.content&&a.index&&a.index<0&&(this.data=yield this.cvforceApi.patchSessionsId(this.applicationId,this._id,{finialMessage:a.content}),this.event.emit("data:updated",this.data),this.event.emit("data:updated:finialMessage",{finialMessage:a.content})),yield this.fillMessageReference(a),a.code){case 11915:a.content="请您换个问题问我吧~",a.index=-1,a.isSensitive=!0,a.isLoading=!1,a.sessionId=this._id||"",this.event.emit("message:error",a);break;case 200:a.index=-1,a.isLoading=!1;break;default:a.content=a.message||"未知错误",a.isLoading=!1,a.index=-1,this.event.emit("message:error",a)}const p=yield this.getRelatedQuesion(a);a=Object.assign(Object.assign({},a),p),a.isLoading=!1;let c=this.messages[this.messages.length-1];if(c&&c.role===vr.Robot){const l=Object.assign(Object.assign({},c),a);this.messages[this.messages.length-1]=l,this.event.emit("message:updated",l)}else this.pushMessage(a);this.frozen=!1});return this.addEventListener("answer:finish",S),this.sendQuestion(m,Object.assign(Object.assign({},Y),{stream:ht,referenceFirst:W})),v})}getRelatedQuesion(O){return Le(this,void 0,void 0,function*(){var L;if(!O.content||O.isSensitive||O.code!==200)return O;this.event.emit("message:relatedQuesion:loading",O);const Y=yield this.cvforceApi.postGeneques({content:O.content}).catch(W=>null);if(!Y){const W=[],_=Object.assign(Object.assign({},O),{relatedQuesion:W,index:-3,isLoading:!1});return this.event.emit("message:relatedQuesion:loaded",{relatedQuesion:W}),_}const ut=(L=Y.content)===null||L===void 0?void 0:L.split("*").map(uf).map(cf).filter(W=>!!W);O.relatedQuesion=ut,O.index=-3,O.isLoading=!1;const ht=Object.assign(Object.assign({},O),{relatedQuesion:ut,index:-3,isLoading:!1});return this.event.emit("message:relatedQuesion:loaded",ht),this._id&&this.cvforceApi.patchSessionsId(this._applicationId,this._id,{lastRelatedQuestion:ut}),ht})}fillMessageReference(O){return Le(this,void 0,void 0,function*(){var L;return(L=O.reference)===null||L===void 0||L.forEach((Y,ut)=>Le(this,void 0,void 0,function*(){const ht=yield this.cvforceApi.getKnowledgeIdFileId(Y.knowledgeId,Y.docId);O.reference[ut]=Object.assign(Object.assign({},Y),ht)})),O})}answerAgain(){return Le(this,arguments,void 0,function*(O={stream:!1}){const L=this.messages[this.messages.length-1];if(!L)throw Error("message list is empty");this.frozen=!0,this._stopAnswer=!1;const{stream:Y=!1}=O;let ut;L.role!==vr.User&&(ut=O.oldMessageId||L.messageId,this.messages.splice(this.messages.length-1,1),this.event.emit("message:remove",L),this.event.emit("history:remove",L));const ht=this.messages[this.messages.length-1],W={content:ht.content,fileIds:ht.fileIds,requestId:ht.messageId,stream:Y,oldMessageId:ut},_=y=>Le(this,void 0,void 0,function*(){if(y.role===vr.Robot&&y.index===-1){switch(this._id&&y.content&&y.index&&y.index<0&&(this.data=yield this.cvforceApi.patchSessionsId(this.applicationId,this._id,{finialMessage:y.content}),this.event.emit("data:updated",this.data),this.event.emit("data:updated:finialMessage",{finialMessage:y.content})),yield this.fillMessageReference(y),y.code){case 11915:y.content="请您换个问题问我吧~",y.index=-1,y.isSensitive=!0,y.isLoading=!1,y.sessionId=this._id||"",this.event.emit("message:error",y);break;case 200:y.index=-1,y.isLoading=!1;break;default:y.content=y.message||"未知错误",y.isLoading=!1,y.index=-1,this.event.emit("message:error",y)}const x=yield this.getRelatedQuesion(y);this.event.emit("message:updated",x),this.removeEventListener("message:content",_),this.frozen=!1}});this.addEventListener("message:content",_),this.sendQuestion(W,Object.assign(Object.assign({},O),{stream:Y}))})}setTop(O){return Le(this,void 0,void 0,function*(){if(!this._id)throw Error("session is not avalible. id is undefined");this.data=yield this.cvforceApi.patchSessionsId(this._applicationId,this._id,{top:O}),this.event.emit("data:updated",this.data),this.event.emit("data:updated:top",{top:O})})}suspend(){var O;this.stopAnswer(),this.frozen=!1,this._stopAnswer=!0;let L=this.messages[this.messages.length-1];const Y={messageId:qc(),isLoading:!1,index:-2,messageTime:hc(new Date).format("YYYY-MM-DD HH:ss:mm"),content:"",role:vr.System,sessionId:this.id||"",reference:[],searchReference:[]};if(L&&!L.messageId){if(L.index===-2)return;if(L.actions){const ut=L.actions[((O=L.actions)===null||O===void 0?void 0:O.length)-1];if(ut){const ht=ut[ut.length-1];if(ht&&(ht.type==="BEFORE_CALL"||ht.type==="FUNCTION_CALL")){const{pluginName:W,pluginCode:_,funcCode:y,funcName:x}=ht.data;ut.push({data:{pluginName:W,pluginCode:_,funcCode:y,funcName:x,step:ht.data.step+1},type:"ABORT"}),this.event.emit("message:action",{messageId:L.messageId,action:ut})}}}L=Object.assign(Object.assign({},L),Y),this.event.emit("message:content",L),this.event.emit("message:updated",L)}else this.pushMessage(Y),this.event.emit("message:content",Y);return this}postMessageComment(O){return Le(this,void 0,void 0,function*(){if(!this._applicationId||!this._id)throw Error("session is not avalible. id is undefined");return this.cvforceApi.postComments(this._applicationId,this._id,O).then(L=>{const Y=this.messages.find(ut=>ut.messageId===O.messageId);return Y&&(Y.comment=O,this.event.emit("message:comment",Y)),L})})}clear(){if(!this._id)throw Error("session is not avalible. id is undefined");return this.cvforceApi.patchApplicationIdSessionsIdContext(this._applicationId,this._id).then(()=>(this.event.emit("context:clear"),!0))}destroy(){var O;return this._ready=!1,this.event.removeAllListeners(),(O=this.socket)===null||O===void 0||O.disconnect(),this.socket=null,this.event.emit("destroy",{applicationId:this._applicationId,sessionId:this._id}),this._id||""}}const $r=new Pi("[AgentSession] ");class gd extends cs{constructor(O,L="",Y,ut,ht,W){super(O,L,Y,ut,ht,W)}prepareConnection(){return new Promise(O=>Le(this,void 0,void 0,function*(){this.socket&&O(!0);const L={version:"1.0",stream:"false",appId:this._applicationId,sessionId:this.id,Authorization:`${this.token}`,userMode:Mi.configuration.debug?nn.Debug:nn.Normal},Y=new URL(Mi.configuration.apiRoot),ut=yield Mo(Y.origin,{path:Y.pathname.replace("api","socketio")+"/copilot",query:L,transports:["websocket"]});ut.on("connect",()=>{$r.log("socket:connect"),this.event.emit("socket:connect"),ut.emit("init")}),ut.on("disconnect",()=>{$r.log("socket:disconnect"),this.event.emit("socket:disconnect")}),ut.on("ready",ht=>{if(ht.code===200){$r.log("ready");const W=Mi.configuration.debug?nn.Debug:nn.Normal;W===nn.Debug&&ht.userMode,this._ready||(this._ready=!0,this.event.emit("ready")),this.frozen=!1,O(!0)}else{this._ready&&(this._ready=!1);const W=new Error($i.SocketConnectionFailed);$r.error("error",W),this.event.emit("error",W),O(!1)}}),ut.on("action",(ht,W)=>Le(this,void 0,void 0,function*(){if(this._stopAnswer||!this.id)return;const{type:_,data:{runnerIsClient:y,pluginCode:x,funcCode:v,parameters:m,requestBody:S}}=ht,a=this.messages[this.messages.length-1];if(!a.messageId)a.actions||(a.actions=[]),a.actions[ht.data.step-1]||(a.actions[ht.data.step-1]=[]),a.actions[ht.data.step-1].push(ht),this.event.emit("message:action",{messageId:a.messageId,action:ht}),this.event.emit("message:updated",a);else{const p={messageId:"",content:"",role:vr.Robot,sessionId:this.id,reference:[],searchReference:[],isLoading:!0,messageTime:"",actions:[[ht]],comment:{isAgree:0}};this.pushMessage(p),this.event.emit("message:action",{messageId:p.messageId,action:ht})}if(this.inactivating){const p=new Error($i.Inactive);$r.warn("error",p),this.event.emit("error",p)}else if(_==="FUNCTION_CALL"&&y){if($r.log(`calling function ${v} of plugin ${x} with argument:
|
|
137
|
+
*/(function(K){const O=fo,L=Za,Y=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;K.Buffer=_,K.SlowBuffer=g,K.INSPECT_MAX_BYTES=50;const ut=2147483647;K.kMaxLength=ut,_.TYPED_ARRAY_SUPPORT=ht(),!_.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function ht(){try{const F=new Uint8Array(1),H={foo:function(){return 42}};return Object.setPrototypeOf(H,Uint8Array.prototype),Object.setPrototypeOf(F,H),F.foo()===42}catch{return!1}}Object.defineProperty(_.prototype,"parent",{enumerable:!0,get:function(){if(_.isBuffer(this))return this.buffer}}),Object.defineProperty(_.prototype,"offset",{enumerable:!0,get:function(){if(_.isBuffer(this))return this.byteOffset}});function W(F){if(F>ut)throw new RangeError('The value "'+F+'" is invalid for option "size"');const H=new Uint8Array(F);return Object.setPrototypeOf(H,_.prototype),H}function _(F,H,U){if(typeof F=="number"){if(typeof H=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return m(F)}return y(F,H,U)}_.poolSize=8192;function y(F,H,U){if(typeof F=="string")return S(F,H);if(ArrayBuffer.isView(F))return p(F);if(F==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof F);if(Bt(F,ArrayBuffer)||F&&Bt(F.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(Bt(F,SharedArrayBuffer)||F&&Bt(F.buffer,SharedArrayBuffer)))return c(F,H,U);if(typeof F=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');const it=F.valueOf&&F.valueOf();if(it!=null&&it!==F)return _.from(it,H,U);const pt=l(F);if(pt)return pt;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof F[Symbol.toPrimitive]=="function")return _.from(F[Symbol.toPrimitive]("string"),H,U);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof F)}_.from=function(F,H,U){return y(F,H,U)},Object.setPrototypeOf(_.prototype,Uint8Array.prototype),Object.setPrototypeOf(_,Uint8Array);function x(F){if(typeof F!="number")throw new TypeError('"size" argument must be of type number');if(F<0)throw new RangeError('The value "'+F+'" is invalid for option "size"')}function v(F,H,U){return x(F),F<=0?W(F):H!==void 0?typeof U=="string"?W(F).fill(H,U):W(F).fill(H):W(F)}_.alloc=function(F,H,U){return v(F,H,U)};function m(F){return x(F),W(F<0?0:f(F)|0)}_.allocUnsafe=function(F){return m(F)},_.allocUnsafeSlow=function(F){return m(F)};function S(F,H){if((typeof H!="string"||H==="")&&(H="utf8"),!_.isEncoding(H))throw new TypeError("Unknown encoding: "+H);const U=h(F,H)|0;let it=W(U);const pt=it.write(F,H);return pt!==U&&(it=it.slice(0,pt)),it}function a(F){const H=F.length<0?0:f(F.length)|0,U=W(H);for(let it=0;it<H;it+=1)U[it]=F[it]&255;return U}function p(F){if(Bt(F,Uint8Array)){const H=new Uint8Array(F);return c(H.buffer,H.byteOffset,H.byteLength)}return a(F)}function c(F,H,U){if(H<0||F.byteLength<H)throw new RangeError('"offset" is outside of buffer bounds');if(F.byteLength<H+(U||0))throw new RangeError('"length" is outside of buffer bounds');let it;return H===void 0&&U===void 0?it=new Uint8Array(F):U===void 0?it=new Uint8Array(F,H):it=new Uint8Array(F,H,U),Object.setPrototypeOf(it,_.prototype),it}function l(F){if(_.isBuffer(F)){const H=f(F.length)|0,U=W(H);return U.length===0||F.copy(U,0,0,H),U}if(F.length!==void 0)return typeof F.length!="number"||Mt(F.length)?W(0):a(F);if(F.type==="Buffer"&&Array.isArray(F.data))return a(F.data)}function f(F){if(F>=ut)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+ut.toString(16)+" bytes");return F|0}function g(F){return+F!=F&&(F=0),_.alloc(+F)}_.isBuffer=function(H){return H!=null&&H._isBuffer===!0&&H!==_.prototype},_.compare=function(H,U){if(Bt(H,Uint8Array)&&(H=_.from(H,H.offset,H.byteLength)),Bt(U,Uint8Array)&&(U=_.from(U,U.offset,U.byteLength)),!_.isBuffer(H)||!_.isBuffer(U))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(H===U)return 0;let it=H.length,pt=U.length;for(let ft=0,mt=Math.min(it,pt);ft<mt;++ft)if(H[ft]!==U[ft]){it=H[ft],pt=U[ft];break}return it<pt?-1:pt<it?1:0},_.isEncoding=function(H){switch(String(H).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},_.concat=function(H,U){if(!Array.isArray(H))throw new TypeError('"list" argument must be an Array of Buffers');if(H.length===0)return _.alloc(0);let it;if(U===void 0)for(U=0,it=0;it<H.length;++it)U+=H[it].length;const pt=_.allocUnsafe(U);let ft=0;for(it=0;it<H.length;++it){let mt=H[it];if(Bt(mt,Uint8Array))ft+mt.length>pt.length?(_.isBuffer(mt)||(mt=_.from(mt)),mt.copy(pt,ft)):Uint8Array.prototype.set.call(pt,mt,ft);else if(_.isBuffer(mt))mt.copy(pt,ft);else throw new TypeError('"list" argument must be an Array of Buffers');ft+=mt.length}return pt};function h(F,H){if(_.isBuffer(F))return F.length;if(ArrayBuffer.isView(F)||Bt(F,ArrayBuffer))return F.byteLength;if(typeof F!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof F);const U=F.length,it=arguments.length>2&&arguments[2]===!0;if(!it&&U===0)return 0;let pt=!1;for(;;)switch(H){case"ascii":case"latin1":case"binary":return U;case"utf8":case"utf-8":return nt(F).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return U*2;case"hex":return U>>>1;case"base64":return gt(F).length;default:if(pt)return it?-1:nt(F).length;H=(""+H).toLowerCase(),pt=!0}}_.byteLength=h;function u(F,H,U){let it=!1;if((H===void 0||H<0)&&(H=0),H>this.length||((U===void 0||U>this.length)&&(U=this.length),U<=0)||(U>>>=0,H>>>=0,U<=H))return"";for(F||(F="utf8");;)switch(F){case"hex":return r(this,H,U);case"utf8":case"utf-8":return et(this,H,U);case"ascii":return t(this,H,U);case"latin1":case"binary":return n(this,H,U);case"base64":return $(this,H,U);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return i(this,H,U);default:if(it)throw new TypeError("Unknown encoding: "+F);F=(F+"").toLowerCase(),it=!0}}_.prototype._isBuffer=!0;function w(F,H,U){const it=F[H];F[H]=F[U],F[U]=it}_.prototype.swap16=function(){const H=this.length;if(H%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let U=0;U<H;U+=2)w(this,U,U+1);return this},_.prototype.swap32=function(){const H=this.length;if(H%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let U=0;U<H;U+=4)w(this,U,U+3),w(this,U+1,U+2);return this},_.prototype.swap64=function(){const H=this.length;if(H%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let U=0;U<H;U+=8)w(this,U,U+7),w(this,U+1,U+6),w(this,U+2,U+5),w(this,U+3,U+4);return this},_.prototype.toString=function(){const H=this.length;return H===0?"":arguments.length===0?et(this,0,H):u.apply(this,arguments)},_.prototype.toLocaleString=_.prototype.toString,_.prototype.equals=function(H){if(!_.isBuffer(H))throw new TypeError("Argument must be a Buffer");return this===H?!0:_.compare(this,H)===0},_.prototype.inspect=function(){let H="";const U=K.INSPECT_MAX_BYTES;return H=this.toString("hex",0,U).replace(/(.{2})/g,"$1 ").trim(),this.length>U&&(H+=" ... "),"<Buffer "+H+">"},Y&&(_.prototype[Y]=_.prototype.inspect),_.prototype.compare=function(H,U,it,pt,ft){if(Bt(H,Uint8Array)&&(H=_.from(H,H.offset,H.byteLength)),!_.isBuffer(H))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof H);if(U===void 0&&(U=0),it===void 0&&(it=H?H.length:0),pt===void 0&&(pt=0),ft===void 0&&(ft=this.length),U<0||it>H.length||pt<0||ft>this.length)throw new RangeError("out of range index");if(pt>=ft&&U>=it)return 0;if(pt>=ft)return-1;if(U>=it)return 1;if(U>>>=0,it>>>=0,pt>>>=0,ft>>>=0,this===H)return 0;let mt=ft-pt,re=it-U;const _t=Math.min(mt,re),At=this.slice(pt,ft),fe=H.slice(U,it);for(let kt=0;kt<_t;++kt)if(At[kt]!==fe[kt]){mt=At[kt],re=fe[kt];break}return mt<re?-1:re<mt?1:0};function b(F,H,U,it,pt){if(F.length===0)return-1;if(typeof U=="string"?(it=U,U=0):U>2147483647?U=2147483647:U<-2147483648&&(U=-2147483648),U=+U,Mt(U)&&(U=pt?0:F.length-1),U<0&&(U=F.length+U),U>=F.length){if(pt)return-1;U=F.length-1}else if(U<0)if(pt)U=0;else return-1;if(typeof H=="string"&&(H=_.from(H,it)),_.isBuffer(H))return H.length===0?-1:E(F,H,U,it,pt);if(typeof H=="number")return H=H&255,typeof Uint8Array.prototype.indexOf=="function"?pt?Uint8Array.prototype.indexOf.call(F,H,U):Uint8Array.prototype.lastIndexOf.call(F,H,U):E(F,[H],U,it,pt);throw new TypeError("val must be string, number or Buffer")}function E(F,H,U,it,pt){let ft=1,mt=F.length,re=H.length;if(it!==void 0&&(it=String(it).toLowerCase(),it==="ucs2"||it==="ucs-2"||it==="utf16le"||it==="utf-16le")){if(F.length<2||H.length<2)return-1;ft=2,mt/=2,re/=2,U/=2}function _t(fe,kt){return ft===1?fe[kt]:fe.readUInt16BE(kt*ft)}let At;if(pt){let fe=-1;for(At=U;At<mt;At++)if(_t(F,At)===_t(H,fe===-1?0:At-fe)){if(fe===-1&&(fe=At),At-fe+1===re)return fe*ft}else fe!==-1&&(At-=At-fe),fe=-1}else for(U+re>mt&&(U=mt-re),At=U;At>=0;At--){let fe=!0;for(let kt=0;kt<re;kt++)if(_t(F,At+kt)!==_t(H,kt)){fe=!1;break}if(fe)return At}return-1}_.prototype.includes=function(H,U,it){return this.indexOf(H,U,it)!==-1},_.prototype.indexOf=function(H,U,it){return b(this,H,U,it,!0)},_.prototype.lastIndexOf=function(H,U,it){return b(this,H,U,it,!1)};function I(F,H,U,it){U=Number(U)||0;const pt=F.length-U;it?(it=Number(it),it>pt&&(it=pt)):it=pt;const ft=H.length;it>ft/2&&(it=ft/2);let mt;for(mt=0;mt<it;++mt){const re=parseInt(H.substr(mt*2,2),16);if(Mt(re))return mt;F[U+mt]=re}return mt}function M(F,H,U,it){return bt(nt(H,F.length-U),F,U,it)}function B(F,H,U,it){return bt(lt(H),F,U,it)}function P(F,H,U,it){return bt(gt(H),F,U,it)}function N(F,H,U,it){return bt(Et(H,F.length-U),F,U,it)}_.prototype.write=function(H,U,it,pt){if(U===void 0)pt="utf8",it=this.length,U=0;else if(it===void 0&&typeof U=="string")pt=U,it=this.length,U=0;else if(isFinite(U))U=U>>>0,isFinite(it)?(it=it>>>0,pt===void 0&&(pt="utf8")):(pt=it,it=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");const ft=this.length-U;if((it===void 0||it>ft)&&(it=ft),H.length>0&&(it<0||U<0)||U>this.length)throw new RangeError("Attempt to write outside buffer bounds");pt||(pt="utf8");let mt=!1;for(;;)switch(pt){case"hex":return I(this,H,U,it);case"utf8":case"utf-8":return M(this,H,U,it);case"ascii":case"latin1":case"binary":return B(this,H,U,it);case"base64":return P(this,H,U,it);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return N(this,H,U,it);default:if(mt)throw new TypeError("Unknown encoding: "+pt);pt=(""+pt).toLowerCase(),mt=!0}},_.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function $(F,H,U){return H===0&&U===F.length?O.fromByteArray(F):O.fromByteArray(F.slice(H,U))}function et(F,H,U){U=Math.min(F.length,U);const it=[];let pt=H;for(;pt<U;){const ft=F[pt];let mt=null,re=ft>239?4:ft>223?3:ft>191?2:1;if(pt+re<=U){let _t,At,fe,kt;switch(re){case 1:ft<128&&(mt=ft);break;case 2:_t=F[pt+1],(_t&192)===128&&(kt=(ft&31)<<6|_t&63,kt>127&&(mt=kt));break;case 3:_t=F[pt+1],At=F[pt+2],(_t&192)===128&&(At&192)===128&&(kt=(ft&15)<<12|(_t&63)<<6|At&63,kt>2047&&(kt<55296||kt>57343)&&(mt=kt));break;case 4:_t=F[pt+1],At=F[pt+2],fe=F[pt+3],(_t&192)===128&&(At&192)===128&&(fe&192)===128&&(kt=(ft&15)<<18|(_t&63)<<12|(At&63)<<6|fe&63,kt>65535&&kt<1114112&&(mt=kt))}}mt===null?(mt=65533,re=1):mt>65535&&(mt-=65536,it.push(mt>>>10&1023|55296),mt=56320|mt&1023),it.push(mt),pt+=re}return ot(it)}const Q=4096;function ot(F){const H=F.length;if(H<=Q)return String.fromCharCode.apply(String,F);let U="",it=0;for(;it<H;)U+=String.fromCharCode.apply(String,F.slice(it,it+=Q));return U}function t(F,H,U){let it="";U=Math.min(F.length,U);for(let pt=H;pt<U;++pt)it+=String.fromCharCode(F[pt]&127);return it}function n(F,H,U){let it="";U=Math.min(F.length,U);for(let pt=H;pt<U;++pt)it+=String.fromCharCode(F[pt]);return it}function r(F,H,U){const it=F.length;(!H||H<0)&&(H=0),(!U||U<0||U>it)&&(U=it);let pt="";for(let ft=H;ft<U;++ft)pt+=It[F[ft]];return pt}function i(F,H,U){const it=F.slice(H,U);let pt="";for(let ft=0;ft<it.length-1;ft+=2)pt+=String.fromCharCode(it[ft]+it[ft+1]*256);return pt}_.prototype.slice=function(H,U){const it=this.length;H=~~H,U=U===void 0?it:~~U,H<0?(H+=it,H<0&&(H=0)):H>it&&(H=it),U<0?(U+=it,U<0&&(U=0)):U>it&&(U=it),U<H&&(U=H);const pt=this.subarray(H,U);return Object.setPrototypeOf(pt,_.prototype),pt};function e(F,H,U){if(F%1!==0||F<0)throw new RangeError("offset is not uint");if(F+H>U)throw new RangeError("Trying to access beyond buffer length")}_.prototype.readUintLE=_.prototype.readUIntLE=function(H,U,it){H=H>>>0,U=U>>>0,it||e(H,U,this.length);let pt=this[H],ft=1,mt=0;for(;++mt<U&&(ft*=256);)pt+=this[H+mt]*ft;return pt},_.prototype.readUintBE=_.prototype.readUIntBE=function(H,U,it){H=H>>>0,U=U>>>0,it||e(H,U,this.length);let pt=this[H+--U],ft=1;for(;U>0&&(ft*=256);)pt+=this[H+--U]*ft;return pt},_.prototype.readUint8=_.prototype.readUInt8=function(H,U){return H=H>>>0,U||e(H,1,this.length),this[H]},_.prototype.readUint16LE=_.prototype.readUInt16LE=function(H,U){return H=H>>>0,U||e(H,2,this.length),this[H]|this[H+1]<<8},_.prototype.readUint16BE=_.prototype.readUInt16BE=function(H,U){return H=H>>>0,U||e(H,2,this.length),this[H]<<8|this[H+1]},_.prototype.readUint32LE=_.prototype.readUInt32LE=function(H,U){return H=H>>>0,U||e(H,4,this.length),(this[H]|this[H+1]<<8|this[H+2]<<16)+this[H+3]*16777216},_.prototype.readUint32BE=_.prototype.readUInt32BE=function(H,U){return H=H>>>0,U||e(H,4,this.length),this[H]*16777216+(this[H+1]<<16|this[H+2]<<8|this[H+3])},_.prototype.readBigUInt64LE=J(function(H){H=H>>>0,G(H,"offset");const U=this[H],it=this[H+7];(U===void 0||it===void 0)&&z(H,this.length-8);const pt=U+this[++H]*2**8+this[++H]*2**16+this[++H]*2**24,ft=this[++H]+this[++H]*2**8+this[++H]*2**16+it*2**24;return BigInt(pt)+(BigInt(ft)<<BigInt(32))}),_.prototype.readBigUInt64BE=J(function(H){H=H>>>0,G(H,"offset");const U=this[H],it=this[H+7];(U===void 0||it===void 0)&&z(H,this.length-8);const pt=U*2**24+this[++H]*2**16+this[++H]*2**8+this[++H],ft=this[++H]*2**24+this[++H]*2**16+this[++H]*2**8+it;return(BigInt(pt)<<BigInt(32))+BigInt(ft)}),_.prototype.readIntLE=function(H,U,it){H=H>>>0,U=U>>>0,it||e(H,U,this.length);let pt=this[H],ft=1,mt=0;for(;++mt<U&&(ft*=256);)pt+=this[H+mt]*ft;return ft*=128,pt>=ft&&(pt-=Math.pow(2,8*U)),pt},_.prototype.readIntBE=function(H,U,it){H=H>>>0,U=U>>>0,it||e(H,U,this.length);let pt=U,ft=1,mt=this[H+--pt];for(;pt>0&&(ft*=256);)mt+=this[H+--pt]*ft;return ft*=128,mt>=ft&&(mt-=Math.pow(2,8*U)),mt},_.prototype.readInt8=function(H,U){return H=H>>>0,U||e(H,1,this.length),this[H]&128?(255-this[H]+1)*-1:this[H]},_.prototype.readInt16LE=function(H,U){H=H>>>0,U||e(H,2,this.length);const it=this[H]|this[H+1]<<8;return it&32768?it|4294901760:it},_.prototype.readInt16BE=function(H,U){H=H>>>0,U||e(H,2,this.length);const it=this[H+1]|this[H]<<8;return it&32768?it|4294901760:it},_.prototype.readInt32LE=function(H,U){return H=H>>>0,U||e(H,4,this.length),this[H]|this[H+1]<<8|this[H+2]<<16|this[H+3]<<24},_.prototype.readInt32BE=function(H,U){return H=H>>>0,U||e(H,4,this.length),this[H]<<24|this[H+1]<<16|this[H+2]<<8|this[H+3]},_.prototype.readBigInt64LE=J(function(H){H=H>>>0,G(H,"offset");const U=this[H],it=this[H+7];(U===void 0||it===void 0)&&z(H,this.length-8);const pt=this[H+4]+this[H+5]*2**8+this[H+6]*2**16+(it<<24);return(BigInt(pt)<<BigInt(32))+BigInt(U+this[++H]*2**8+this[++H]*2**16+this[++H]*2**24)}),_.prototype.readBigInt64BE=J(function(H){H=H>>>0,G(H,"offset");const U=this[H],it=this[H+7];(U===void 0||it===void 0)&&z(H,this.length-8);const pt=(U<<24)+this[++H]*2**16+this[++H]*2**8+this[++H];return(BigInt(pt)<<BigInt(32))+BigInt(this[++H]*2**24+this[++H]*2**16+this[++H]*2**8+it)}),_.prototype.readFloatLE=function(H,U){return H=H>>>0,U||e(H,4,this.length),L.read(this,H,!0,23,4)},_.prototype.readFloatBE=function(H,U){return H=H>>>0,U||e(H,4,this.length),L.read(this,H,!1,23,4)},_.prototype.readDoubleLE=function(H,U){return H=H>>>0,U||e(H,8,this.length),L.read(this,H,!0,52,8)},_.prototype.readDoubleBE=function(H,U){return H=H>>>0,U||e(H,8,this.length),L.read(this,H,!1,52,8)};function o(F,H,U,it,pt,ft){if(!_.isBuffer(F))throw new TypeError('"buffer" argument must be a Buffer instance');if(H>pt||H<ft)throw new RangeError('"value" argument is out of bounds');if(U+it>F.length)throw new RangeError("Index out of range")}_.prototype.writeUintLE=_.prototype.writeUIntLE=function(H,U,it,pt){if(H=+H,U=U>>>0,it=it>>>0,!pt){const re=Math.pow(2,8*it)-1;o(this,H,U,it,re,0)}let ft=1,mt=0;for(this[U]=H&255;++mt<it&&(ft*=256);)this[U+mt]=H/ft&255;return U+it},_.prototype.writeUintBE=_.prototype.writeUIntBE=function(H,U,it,pt){if(H=+H,U=U>>>0,it=it>>>0,!pt){const re=Math.pow(2,8*it)-1;o(this,H,U,it,re,0)}let ft=it-1,mt=1;for(this[U+ft]=H&255;--ft>=0&&(mt*=256);)this[U+ft]=H/mt&255;return U+it},_.prototype.writeUint8=_.prototype.writeUInt8=function(H,U,it){return H=+H,U=U>>>0,it||o(this,H,U,1,255,0),this[U]=H&255,U+1},_.prototype.writeUint16LE=_.prototype.writeUInt16LE=function(H,U,it){return H=+H,U=U>>>0,it||o(this,H,U,2,65535,0),this[U]=H&255,this[U+1]=H>>>8,U+2},_.prototype.writeUint16BE=_.prototype.writeUInt16BE=function(H,U,it){return H=+H,U=U>>>0,it||o(this,H,U,2,65535,0),this[U]=H>>>8,this[U+1]=H&255,U+2},_.prototype.writeUint32LE=_.prototype.writeUInt32LE=function(H,U,it){return H=+H,U=U>>>0,it||o(this,H,U,4,4294967295,0),this[U+3]=H>>>24,this[U+2]=H>>>16,this[U+1]=H>>>8,this[U]=H&255,U+4},_.prototype.writeUint32BE=_.prototype.writeUInt32BE=function(H,U,it){return H=+H,U=U>>>0,it||o(this,H,U,4,4294967295,0),this[U]=H>>>24,this[U+1]=H>>>16,this[U+2]=H>>>8,this[U+3]=H&255,U+4};function s(F,H,U,it,pt){D(H,it,pt,F,U,7);let ft=Number(H&BigInt(4294967295));F[U++]=ft,ft=ft>>8,F[U++]=ft,ft=ft>>8,F[U++]=ft,ft=ft>>8,F[U++]=ft;let mt=Number(H>>BigInt(32)&BigInt(4294967295));return F[U++]=mt,mt=mt>>8,F[U++]=mt,mt=mt>>8,F[U++]=mt,mt=mt>>8,F[U++]=mt,U}function A(F,H,U,it,pt){D(H,it,pt,F,U,7);let ft=Number(H&BigInt(4294967295));F[U+7]=ft,ft=ft>>8,F[U+6]=ft,ft=ft>>8,F[U+5]=ft,ft=ft>>8,F[U+4]=ft;let mt=Number(H>>BigInt(32)&BigInt(4294967295));return F[U+3]=mt,mt=mt>>8,F[U+2]=mt,mt=mt>>8,F[U+1]=mt,mt=mt>>8,F[U]=mt,U+8}_.prototype.writeBigUInt64LE=J(function(H,U=0){return s(this,H,U,BigInt(0),BigInt("0xffffffffffffffff"))}),_.prototype.writeBigUInt64BE=J(function(H,U=0){return A(this,H,U,BigInt(0),BigInt("0xffffffffffffffff"))}),_.prototype.writeIntLE=function(H,U,it,pt){if(H=+H,U=U>>>0,!pt){const _t=Math.pow(2,8*it-1);o(this,H,U,it,_t-1,-_t)}let ft=0,mt=1,re=0;for(this[U]=H&255;++ft<it&&(mt*=256);)H<0&&re===0&&this[U+ft-1]!==0&&(re=1),this[U+ft]=(H/mt>>0)-re&255;return U+it},_.prototype.writeIntBE=function(H,U,it,pt){if(H=+H,U=U>>>0,!pt){const _t=Math.pow(2,8*it-1);o(this,H,U,it,_t-1,-_t)}let ft=it-1,mt=1,re=0;for(this[U+ft]=H&255;--ft>=0&&(mt*=256);)H<0&&re===0&&this[U+ft+1]!==0&&(re=1),this[U+ft]=(H/mt>>0)-re&255;return U+it},_.prototype.writeInt8=function(H,U,it){return H=+H,U=U>>>0,it||o(this,H,U,1,127,-128),H<0&&(H=255+H+1),this[U]=H&255,U+1},_.prototype.writeInt16LE=function(H,U,it){return H=+H,U=U>>>0,it||o(this,H,U,2,32767,-32768),this[U]=H&255,this[U+1]=H>>>8,U+2},_.prototype.writeInt16BE=function(H,U,it){return H=+H,U=U>>>0,it||o(this,H,U,2,32767,-32768),this[U]=H>>>8,this[U+1]=H&255,U+2},_.prototype.writeInt32LE=function(H,U,it){return H=+H,U=U>>>0,it||o(this,H,U,4,2147483647,-2147483648),this[U]=H&255,this[U+1]=H>>>8,this[U+2]=H>>>16,this[U+3]=H>>>24,U+4},_.prototype.writeInt32BE=function(H,U,it){return H=+H,U=U>>>0,it||o(this,H,U,4,2147483647,-2147483648),H<0&&(H=4294967295+H+1),this[U]=H>>>24,this[U+1]=H>>>16,this[U+2]=H>>>8,this[U+3]=H&255,U+4},_.prototype.writeBigInt64LE=J(function(H,U=0){return s(this,H,U,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),_.prototype.writeBigInt64BE=J(function(H,U=0){return A(this,H,U,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function C(F,H,U,it,pt,ft){if(U+it>F.length)throw new RangeError("Index out of range");if(U<0)throw new RangeError("Index out of range")}function j(F,H,U,it,pt){return H=+H,U=U>>>0,pt||C(F,H,U,4),L.write(F,H,U,it,23,4),U+4}_.prototype.writeFloatLE=function(H,U,it){return j(this,H,U,!0,it)},_.prototype.writeFloatBE=function(H,U,it){return j(this,H,U,!1,it)};function T(F,H,U,it,pt){return H=+H,U=U>>>0,pt||C(F,H,U,8),L.write(F,H,U,it,52,8),U+8}_.prototype.writeDoubleLE=function(H,U,it){return T(this,H,U,!0,it)},_.prototype.writeDoubleBE=function(H,U,it){return T(this,H,U,!1,it)},_.prototype.copy=function(H,U,it,pt){if(!_.isBuffer(H))throw new TypeError("argument should be a Buffer");if(it||(it=0),!pt&&pt!==0&&(pt=this.length),U>=H.length&&(U=H.length),U||(U=0),pt>0&&pt<it&&(pt=it),pt===it||H.length===0||this.length===0)return 0;if(U<0)throw new RangeError("targetStart out of bounds");if(it<0||it>=this.length)throw new RangeError("Index out of range");if(pt<0)throw new RangeError("sourceEnd out of bounds");pt>this.length&&(pt=this.length),H.length-U<pt-it&&(pt=H.length-U+it);const ft=pt-it;return this===H&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(U,it,pt):Uint8Array.prototype.set.call(H,this.subarray(it,pt),U),ft},_.prototype.fill=function(H,U,it,pt){if(typeof H=="string"){if(typeof U=="string"?(pt=U,U=0,it=this.length):typeof it=="string"&&(pt=it,it=this.length),pt!==void 0&&typeof pt!="string")throw new TypeError("encoding must be a string");if(typeof pt=="string"&&!_.isEncoding(pt))throw new TypeError("Unknown encoding: "+pt);if(H.length===1){const mt=H.charCodeAt(0);(pt==="utf8"&&mt<128||pt==="latin1")&&(H=mt)}}else typeof H=="number"?H=H&255:typeof H=="boolean"&&(H=Number(H));if(U<0||this.length<U||this.length<it)throw new RangeError("Out of range index");if(it<=U)return this;U=U>>>0,it=it===void 0?this.length:it>>>0,H||(H=0);let ft;if(typeof H=="number")for(ft=U;ft<it;++ft)this[ft]=H;else{const mt=_.isBuffer(H)?H:_.from(H,pt),re=mt.length;if(re===0)throw new TypeError('The value "'+H+'" is invalid for argument "value"');for(ft=0;ft<it-U;++ft)this[ft+U]=mt[ft%re]}return this};const R={};function q(F,H,U){R[F]=class extends U{constructor(){super(),Object.defineProperty(this,"message",{value:H.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${F}]`,this.stack,delete this.name}get code(){return F}set code(pt){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:pt,writable:!0})}toString(){return`${this.name} [${F}]: ${this.message}`}}}q("ERR_BUFFER_OUT_OF_BOUNDS",function(F){return F?`${F} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),q("ERR_INVALID_ARG_TYPE",function(F,H){return`The "${F}" argument must be of type number. Received type ${typeof H}`},TypeError),q("ERR_OUT_OF_RANGE",function(F,H,U){let it=`The value of "${F}" is out of range.`,pt=U;return Number.isInteger(U)&&Math.abs(U)>2**32?pt=Z(String(U)):typeof U=="bigint"&&(pt=String(U),(U>BigInt(2)**BigInt(32)||U<-(BigInt(2)**BigInt(32)))&&(pt=Z(pt)),pt+="n"),it+=` It must be ${H}. Received ${pt}`,it},RangeError);function Z(F){let H="",U=F.length;const it=F[0]==="-"?1:0;for(;U>=it+4;U-=3)H=`_${F.slice(U-3,U)}${H}`;return`${F.slice(0,U)}${H}`}function rt(F,H,U){G(H,"offset"),(F[H]===void 0||F[H+U]===void 0)&&z(H,F.length-(U+1))}function D(F,H,U,it,pt,ft){if(F>U||F<H){const mt=typeof H=="bigint"?"n":"";let re;throw ft>3?H===0||H===BigInt(0)?re=`>= 0${mt} and < 2${mt} ** ${(ft+1)*8}${mt}`:re=`>= -(2${mt} ** ${(ft+1)*8-1}${mt}) and < 2 ** ${(ft+1)*8-1}${mt}`:re=`>= ${H}${mt} and <= ${U}${mt}`,new R.ERR_OUT_OF_RANGE("value",re,F)}rt(it,pt,ft)}function G(F,H){if(typeof F!="number")throw new R.ERR_INVALID_ARG_TYPE(H,"number",F)}function z(F,H,U){throw Math.floor(F)!==F?(G(F,U),new R.ERR_OUT_OF_RANGE(U||"offset","an integer",F)):H<0?new R.ERR_BUFFER_OUT_OF_BOUNDS:new R.ERR_OUT_OF_RANGE(U||"offset",`>= ${U?1:0} and <= ${H}`,F)}const X=/[^+/0-9A-Za-z-_]/g;function st(F){if(F=F.split("=")[0],F=F.trim().replace(X,""),F.length<2)return"";for(;F.length%4!==0;)F=F+"=";return F}function nt(F,H){H=H||1/0;let U;const it=F.length;let pt=null;const ft=[];for(let mt=0;mt<it;++mt){if(U=F.charCodeAt(mt),U>55295&&U<57344){if(!pt){if(U>56319){(H-=3)>-1&&ft.push(239,191,189);continue}else if(mt+1===it){(H-=3)>-1&&ft.push(239,191,189);continue}pt=U;continue}if(U<56320){(H-=3)>-1&&ft.push(239,191,189),pt=U;continue}U=(pt-55296<<10|U-56320)+65536}else pt&&(H-=3)>-1&&ft.push(239,191,189);if(pt=null,U<128){if((H-=1)<0)break;ft.push(U)}else if(U<2048){if((H-=2)<0)break;ft.push(U>>6|192,U&63|128)}else if(U<65536){if((H-=3)<0)break;ft.push(U>>12|224,U>>6&63|128,U&63|128)}else if(U<1114112){if((H-=4)<0)break;ft.push(U>>18|240,U>>12&63|128,U>>6&63|128,U&63|128)}else throw new Error("Invalid code point")}return ft}function lt(F){const H=[];for(let U=0;U<F.length;++U)H.push(F.charCodeAt(U)&255);return H}function Et(F,H){let U,it,pt;const ft=[];for(let mt=0;mt<F.length&&!((H-=2)<0);++mt)U=F.charCodeAt(mt),it=U>>8,pt=U%256,ft.push(pt),ft.push(it);return ft}function gt(F){return O.toByteArray(st(F))}function bt(F,H,U,it){let pt;for(pt=0;pt<it&&!(pt+U>=H.length||pt>=F.length);++pt)H[pt+U]=F[pt];return pt}function Bt(F,H){return F instanceof H||F!=null&&F.constructor!=null&&F.constructor.name!=null&&F.constructor.name===H.name}function Mt(F){return F!==F}const It=function(){const F="0123456789abcdef",H=new Array(256);for(let U=0;U<16;++U){const it=U*16;for(let pt=0;pt<16;++pt)H[it+pt]=F[U]+F[pt]}return H}();function J(F){return typeof BigInt>"u"?tt:F}function tt(){throw new Error("BigInt not supported")}})(Va),window.Buffer=Va.Buffer,globalThis.Buffer=Va.Buffer;var ve=(K,O,L)=>new Promise((Y,ut)=>{var ht=y=>{try{_(L.next(y))}catch(x){ut(x)}},W=y=>{try{_(L.throw(y))}catch(x){ut(x)}},_=y=>y.done?Y(y.value):Promise.resolve(y.value).then(ht,W);_((L=L.apply(K,O)).next())});class _p extends sp{constructor(O,L){super(O??oc.create(),L)}getKnowledge(O,L){return ve(this,null,function*(){return this.get("/knowledge",{docId:O,name:L})})}postKnowledge(O){return ve(this,null,function*(){return this.post("/knowledge",O)})}getKnowledgeId(O){return ve(this,null,function*(){return this.get(`/knowledge/${O}`)})}patchKnowledgeId(O,L){return ve(this,null,function*(){return this.patch(`/knowledge/${O}`,L)})}delKnowledgeId(O){return ve(this,null,function*(){return this.delete(`/knowledge/${O}`)})}getKnowledgeIdFile(O){return ve(this,null,function*(){return this.get(`/knowledge/${O}/file`)})}getKnowledgeIdFileList(O,L){return ve(this,null,function*(){return this.listPaged(`/knowledge/${O}/file`,L)})}postKnowledgeIdFile(O,L){return ve(this,null,function*(){return this.post(`/knowledge/${O}/file`,L)})}getUploadTicket(O){return ve(this,null,function*(){return this.get("/upload/ticket",O)})}delKnowledgeIdFileFid(O,L){return ve(this,null,function*(){return this.delete(`/knowledge/${O}/file/${L}`)})}patchKnowledgeIdFileFid(O,L,Y){return ve(this,null,function*(){return this.patch(`/knowledge/${O}/file/${L}`,Y)})}listSessions(O,L){return ve(this,null,function*(){return this.get(`/application/${O}/sessionsa`,L)})}postSession(O,L){return ve(this,null,function*(){return this.post(`/application/${O}/sessions`,L)})}getSession(O,L){return ve(this,null,function*(){return this.get(`/application/${O}/sessions/${L}`)})}patchSessionsId(O,L,Y){return ve(this,null,function*(){return this.patch(`/application/${O}/sessions/${L}`,Y)})}delSessionsId(O,L){return ve(this,null,function*(){return this.delete(`/application/${O}/sessions/${L}`)})}getSessionKnowledgeFile(O,L,Y){return ve(this,null,function*(){return this.get(`/application/${O}session/${L}/file/${Y}`)})}postSessionKnowledgeFile(O,L,Y){return ve(this,null,function*(){return this.post(`/application/${O}session/${L}/file`,Y)})}postComments(O,L,Y){return ve(this,null,function*(){return this.post(`/application/${O}/sessions/${L}/comments`,Y)})}getChatHistorySessionId(O,L,Y){return ve(this,null,function*(){return this.get(`application/${O}/chatHistory/${L}`,Y)})}postChatHistorySessionId(O,L){return ve(this,null,function*(){return this.post(`/chatHistory/${O}`,L)})}getApplications(O){return ve(this,null,function*(){return this.get("/applications",O)})}postApplication(O){return ve(this,null,function*(){return this.post("/applications",O)})}getApplicationId(O){return ve(this,null,function*(){return this.get(`/applications/${O}`)})}patchApplicationId(O,L){return ve(this,null,function*(){return this.patch(`/applications/${O}`,L)})}delApplicationId(O){return ve(this,null,function*(){return this.delete(`/applications/${O}`)})}getApplicationIdSessions(O){return ve(this,null,function*(){return this.get(`/applications/${O}/session`)})}patchFileId(O,L){return ve(this,null,function*(){return this.patch(`/file/${O}`,L)})}getCvforceResource(O){return ve(this,null,function*(){return this.get("/cvforce/resource",O)})}postKnowledgeIdComposedFiles(O,L){return ve(this,null,function*(){return this.post(`/knowledge/${O}/composedFiles`,L)})}getTokensApplicationId(O,L){return ve(this,null,function*(){return this.get(`/tokens/${O}`,L)})}getTokens(O){return ve(this,null,function*(){return this.get("/tokens",O)})}uploadMinioFile(O,L){return ve(this,null,function*(){return new Promise((Y,ut)=>{const ht=new FileReader;ht.readAsArrayBuffer(L),ht.onload=W=>{cc.initMinio({endPoint:O.endpoints[0],useSSL:O.useSSL,accessKey:O.accessKey,secretKey:O.secretKey});const _=Buffer.from(W.target.result),y={"Content-Type":"application/octet-stream"};cc.putObjectBuffer(O.bucket,O.fileKeys[0],_,y,x=>{if(x)throw console.error(x),Error(x);Y(O.fileKeys[0])})}})})}uploadFile(O,L){return ve(this,null,function*(){const Y={files:[L.name],isv:"minio",knowledgeId:O};return this.getUploadTicket(Y).then(ut=>this.uploadMinioFile(ut.minio,L)).catch(ut=>{throw Error(ut)})})}uploadFiles(O,L){return ve(this,null,function*(){const Y={files:L.map(ut=>ut.name),isv:"minio",knowledgeId:O};return this.getUploadTicket(Y).then(ut=>Promise.all(L.map(ht=>this.uploadMinioFile(ut.minio,ht)))).catch(ut=>{throw Error(ut)})})}getAecModels(){return ve(this,null,function*(){return this.get("/aecModels")})}postTextFilter(O){return ve(this,null,function*(){return this.post("/textFilter",O)})}getTenantModel(){return ve(this,null,function*(){return this.get("/tenantModel")})}getPrompts(O,L){return ve(this,null,function*(){return this.get(`application/${O}/promptVariables`,L)})}postPrompt(O,L){return ve(this,null,function*(){return this.post(`application/${O}/promptVariables`,L)})}patchPromptId(O,L,Y){return ve(this,null,function*(){return this.patch(`application/${O}/promptVariables/${L}`,Y)})}delPromptId(O,L){return ve(this,null,function*(){return this.delete(`application/${O}/promptVariables/${L}`)})}getSessionPrompts(O){return ve(this,null,function*(){return this.get(`session/${O}/promptVariables`)})}patchSessionPromptId(O,L,Y){return ve(this,null,function*(){return this.patch(`session/${L}/promptVariables/${O}`,Y)})}getApplicationIdSessionIdPromptVariables(O,L){return ve(this,null,function*(){return this.get(`/application/${O}/session/${L}/promptVariables`)})}patchApplicationIdSessionpromptVariablesId(O,L,Y,ut){return ve(this,null,function*(){return this.patch(`/application/${O}/session/${L}/promptVariables/${Y}`,ut)})}getPresetApplication(O){return ve(this,null,function*(){return this.get("presetApplication",O)})}postKnowledgeConfig(O){return ve(this,null,function*(){return this.post("/knowledgeConfig",O)})}getKnowledgeConfig(O){return ve(this,null,function*(){return this.get(`/knowledgeConfig/${O}`)})}patchKnowledgeConfig(O,L){return ve(this,null,function*(){return this.patch(`/knowledgeConfig/${O}`,L)})}getKnowledgeIdFileId(O,L){return ve(this,null,function*(){return this.get(`/knowledge/${O}/file/${L}`)})}getKnowledgeIdFileIdData(O,L,Y){return ve(this,null,function*(){return this.listPaged(`/knowledge/${O}/file/${L}/data`,Y)})}postKnowledgeIdFileIdData(O,L,Y){return ve(this,null,function*(){return this.post(`/knowledge/${O}/file/${L}/data`,{data:Y})})}patchKnowledgeIdFileIdData(O,L,Y,ut){return ve(this,null,function*(){return this.patch(`/knowledge/${O}/file/${L}/data/${Y}`,{data:ut})})}delKnowledgeIdFileIdDataDid(O,L,Y){return ve(this,null,function*(){return this.delete(`/knowledge/${O}/file/${L}/data/${Y}`)})}getPresetKnowledge(O){return ve(this,null,function*(){return this.get("/presetKnowledge",O)})}patchSessionsIdContext(O){return ve(this,null,function*(){return this.patch(`/sessions/${O}/context`,{})})}postResourceToken(O){return ve(this,null,function*(){return this.post("/resourceToken",O)})}getApplicationIdSession(O){return ve(this,null,function*(){return this.get(`/application/${O}/session`)})}patchApplicationIdSessionsIdContext(O,L){return ve(this,null,function*(){return this.patch(`/application/${O}/sessions/${L}/context`,{})})}postApplicationIdSessions(O,L){return ve(this,null,function*(){return this.post(`/application/${O}/sessions`,L)})}getApplicationIdChatHistorySessionId(O,L){return ve(this,null,function*(){return this.get(`/application/${O}/chatHistory/${L}`)})}postApplicationIdChatHistorySessionIdComments(O,L,Y){return ve(this,null,function*(){return this.post(`/application/${O}/sessions/${L}/comments`,Y)})}getApplicationIdPrompts(O,L){return ve(this,null,function*(){return this.get(`/application/${O}/promptVariables`,L)})}postKnowledgeSourceFile(O,L,Y){return ve(this,null,function*(){return this.post(`/knowledge/${O}/sourceFile/${L}`,Y)})}getMetadata(O){return ve(this,null,function*(){return this.get("/metadata",O)})}postGeneques(O){return ve(this,null,function*(){return this.post("/geneques",O)})}getBaseModel(O){return ve(this,null,function*(){return this.get("/baseModelInfo",{serviceId:O})})}}var vr=(K=>(K[K.Robot=1]="Robot",K[K.User=2]="User",K[K.System=3]="System",K))(vr||{}),pc=(K=>(K[K.Idle=0]="Idle",K[K.Quoted=1]="Quoted",K))(pc||{}),bn=(K=>(K[K.Dialog=0]="Dialog",K[K.Text=1]="Text",K[K.Agent=2]="Agent",K[K.All=3]="All",K))(bn||{});function dc(K,O,L){const Y=x=>{var v;return O&&(sf(O)&&L(403,"aiotToken is timeout"),x.headers=(v=x.headers)!==null&&v!==void 0?v:{},x.headers=Object.assign(Object.assign({},x.headers),{Authorization:O?`Bearer ${O}`:""})),x};function ut(x,v=!0){const m=`${K}${x}`,S=oc.create({baseURL:m});return v&&S.interceptors.request.use(Y),S}const ht=(x,v)=>{x===401&&L(x,"aiotToken is invalid")},W=(x,v)=>{x!==10001&&x!==10215&&L(x,v)},_=ut("/data/v1");return new _p(_,{onHttpStatusError:ht,onAppStatusError:W})}const kr=Object.create(null);kr.open="0",kr.close="1",kr.ping="2",kr.pong="3",kr.message="4",kr.upgrade="5",kr.noop="6";const po=Object.create(null);Object.keys(kr).forEach(K=>{po[kr[K]]=K});const Ka={type:"error",data:"parser error"},mc=typeof Blob=="function"||typeof Blob<"u"&&Object.prototype.toString.call(Blob)==="[object BlobConstructor]",gc=typeof ArrayBuffer=="function",vc=K=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(K):K&&K.buffer instanceof ArrayBuffer,Ja=({type:K,data:O},L,Y)=>mc&&O instanceof Blob?L?Y(O):yc(O,Y):gc&&(O instanceof ArrayBuffer||vc(O))?L?Y(O):yc(new Blob([O]),Y):Y(kr[K]+(O||"")),yc=(K,O)=>{const L=new FileReader;return L.onload=function(){const Y=L.result.split(",")[1];O("b"+(Y||""))},L.readAsDataURL(K)};function bc(K){return K instanceof Uint8Array?K:K instanceof ArrayBuffer?new Uint8Array(K):new Uint8Array(K.buffer,K.byteOffset,K.byteLength)}let Ga;function Sp(K,O){if(mc&&K.data instanceof Blob)return K.data.arrayBuffer().then(bc).then(O);if(gc&&(K.data instanceof ArrayBuffer||vc(K.data)))return O(bc(K.data));Ja(K,!1,L=>{Ga||(Ga=new TextEncoder),O(Ga.encode(L))})}const wc="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Cn=typeof Uint8Array>"u"?[]:new Uint8Array(256);for(let K=0;K<wc.length;K++)Cn[wc.charCodeAt(K)]=K;const Ep=K=>{let O=K.length*.75,L=K.length,Y,ut=0,ht,W,_,y;K[K.length-1]==="="&&(O--,K[K.length-2]==="="&&O--);const x=new ArrayBuffer(O),v=new Uint8Array(x);for(Y=0;Y<L;Y+=4)ht=Cn[K.charCodeAt(Y)],W=Cn[K.charCodeAt(Y+1)],_=Cn[K.charCodeAt(Y+2)],y=Cn[K.charCodeAt(Y+3)],v[ut++]=ht<<2|W>>4,v[ut++]=(W&15)<<4|_>>2,v[ut++]=(_&3)<<6|y&63;return x},kp=typeof ArrayBuffer=="function",Ya=(K,O)=>{if(typeof K!="string")return{type:"message",data:Mc(K,O)};const L=K.charAt(0);return L==="b"?{type:"message",data:Ip(K.substring(1),O)}:po[L]?K.length>1?{type:po[L],data:K.substring(1)}:{type:po[L]}:Ka},Ip=(K,O)=>{if(kp){const L=Ep(K);return Mc(L,O)}else return{base64:!0,data:K}},Mc=(K,O)=>{switch(O){case"blob":return K instanceof Blob?K:new Blob([K]);case"arraybuffer":default:return K instanceof ArrayBuffer?K:K.buffer}},xc=String.fromCharCode(30),Op=(K,O)=>{const L=K.length,Y=new Array(L);let ut=0;K.forEach((ht,W)=>{Ja(ht,!1,_=>{Y[W]=_,++ut===L&&O(Y.join(xc))})})},Ap=(K,O)=>{const L=K.split(xc),Y=[];for(let ut=0;ut<L.length;ut++){const ht=Ya(L[ut],O);if(Y.push(ht),ht.type==="error")break}return Y};function Tp(){return new TransformStream({transform(K,O){Sp(K,L=>{const Y=L.length;let ut;if(Y<126)ut=new Uint8Array(1),new DataView(ut.buffer).setUint8(0,Y);else if(Y<65536){ut=new Uint8Array(3);const ht=new DataView(ut.buffer);ht.setUint8(0,126),ht.setUint16(1,Y)}else{ut=new Uint8Array(9);const ht=new DataView(ut.buffer);ht.setUint8(0,127),ht.setBigUint64(1,BigInt(Y))}K.data&&typeof K.data!="string"&&(ut[0]|=128),O.enqueue(ut),O.enqueue(L)})}})}let Qa;function mo(K){return K.reduce((O,L)=>O+L.length,0)}function go(K,O){if(K[0].length===O)return K.shift();const L=new Uint8Array(O);let Y=0;for(let ut=0;ut<O;ut++)L[ut]=K[0][Y++],Y===K[0].length&&(K.shift(),Y=0);return K.length&&Y<K[0].length&&(K[0]=K[0].slice(Y)),L}function Bp(K,O){Qa||(Qa=new TextDecoder);const L=[];let Y=0,ut=-1,ht=!1;return new TransformStream({transform(W,_){for(L.push(W);;){if(Y===0){if(mo(L)<1)break;const y=go(L,1);ht=(y[0]&128)===128,ut=y[0]&127,ut<126?Y=3:ut===126?Y=1:Y=2}else if(Y===1){if(mo(L)<2)break;const y=go(L,2);ut=new DataView(y.buffer,y.byteOffset,y.length).getUint16(0),Y=3}else if(Y===2){if(mo(L)<8)break;const y=go(L,8),x=new DataView(y.buffer,y.byteOffset,y.length),v=x.getUint32(0);if(v>Math.pow(2,53-32)-1){_.enqueue(Ka);break}ut=v*Math.pow(2,32)+x.getUint32(4),Y=3}else{if(mo(L)<ut)break;const y=go(L,ut);_.enqueue(Ya(ht?y:Qa.decode(y),O)),Y=0}if(ut===0||ut>K){_.enqueue(Ka);break}}}})}const _c=4;function Bi(K){if(K)return jp(K)}function jp(K){for(var O in Bi.prototype)K[O]=Bi.prototype[O];return K}Bi.prototype.on=Bi.prototype.addEventListener=function(K,O){return this._callbacks=this._callbacks||{},(this._callbacks["$"+K]=this._callbacks["$"+K]||[]).push(O),this},Bi.prototype.once=function(K,O){function L(){this.off(K,L),O.apply(this,arguments)}return L.fn=O,this.on(K,L),this},Bi.prototype.off=Bi.prototype.removeListener=Bi.prototype.removeAllListeners=Bi.prototype.removeEventListener=function(K,O){if(this._callbacks=this._callbacks||{},arguments.length==0)return this._callbacks={},this;var L=this._callbacks["$"+K];if(!L)return this;if(arguments.length==1)return delete this._callbacks["$"+K],this;for(var Y,ut=0;ut<L.length;ut++)if(Y=L[ut],Y===O||Y.fn===O){L.splice(ut,1);break}return L.length===0&&delete this._callbacks["$"+K],this},Bi.prototype.emit=function(K){this._callbacks=this._callbacks||{};for(var O=new Array(arguments.length-1),L=this._callbacks["$"+K],Y=1;Y<arguments.length;Y++)O[Y-1]=arguments[Y];if(L){L=L.slice(0);for(var Y=0,ut=L.length;Y<ut;++Y)L[Y].apply(this,O)}return this},Bi.prototype.emitReserved=Bi.prototype.emit,Bi.prototype.listeners=function(K){return this._callbacks=this._callbacks||{},this._callbacks["$"+K]||[]},Bi.prototype.hasListeners=function(K){return!!this.listeners(K).length};const ur=(()=>typeof self<"u"?self:typeof window<"u"?window:Function("return this")())();function Sc(K,...O){return O.reduce((L,Y)=>(K.hasOwnProperty(Y)&&(L[Y]=K[Y]),L),{})}const Rp=ur.setTimeout,Np=ur.clearTimeout;function vo(K,O){O.useNativeTimers?(K.setTimeoutFn=Rp.bind(ur),K.clearTimeoutFn=Np.bind(ur)):(K.setTimeoutFn=ur.setTimeout.bind(ur),K.clearTimeoutFn=ur.clearTimeout.bind(ur))}const Cp=1.33;function Pp(K){return typeof K=="string"?Lp(K):Math.ceil((K.byteLength||K.size)*Cp)}function Lp(K){let O=0,L=0;for(let Y=0,ut=K.length;Y<ut;Y++)O=K.charCodeAt(Y),O<128?L+=1:O<2048?L+=2:O<55296||O>=57344?L+=3:(Y++,L+=4);return L}function Dp(K){let O="";for(let L in K)K.hasOwnProperty(L)&&(O.length&&(O+="&"),O+=encodeURIComponent(L)+"="+encodeURIComponent(K[L]));return O}function Up(K){let O={},L=K.split("&");for(let Y=0,ut=L.length;Y<ut;Y++){let ht=L[Y].split("=");O[decodeURIComponent(ht[0])]=decodeURIComponent(ht[1])}return O}class qp extends Error{constructor(O,L,Y){super(O),this.description=L,this.context=Y,this.type="TransportError"}}class ts extends Bi{constructor(O){super(),this.writable=!1,vo(this,O),this.opts=O,this.query=O.query,this.socket=O.socket}onError(O,L,Y){return super.emitReserved("error",new qp(O,L,Y)),this}open(){return this.readyState="opening",this.doOpen(),this}close(){return(this.readyState==="opening"||this.readyState==="open")&&(this.doClose(),this.onClose()),this}send(O){this.readyState==="open"&&this.write(O)}onOpen(){this.readyState="open",this.writable=!0,super.emitReserved("open")}onData(O){const L=Ya(O,this.socket.binaryType);this.onPacket(L)}onPacket(O){super.emitReserved("packet",O)}onClose(O){this.readyState="closed",super.emitReserved("close",O)}pause(O){}createUri(O,L={}){return O+"://"+this._hostname()+this._port()+this.opts.path+this._query(L)}_hostname(){const O=this.opts.hostname;return O.indexOf(":")===-1?O:"["+O+"]"}_port(){return this.opts.port&&(this.opts.secure&&+(this.opts.port!==443)||!this.opts.secure&&Number(this.opts.port)!==80)?":"+this.opts.port:""}_query(O){const L=Dp(O);return L.length?"?"+L:""}}const Ec="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_".split(""),es=64,Fp={};let kc=0,yo=0,Ic;function Oc(K){let O="";do O=Ec[K%es]+O,K=Math.floor(K/es);while(K>0);return O}function Ac(){const K=Oc(+new Date);return K!==Ic?(kc=0,Ic=K):K+"."+Oc(kc++)}for(;yo<es;yo++)Fp[Ec[yo]]=yo;let Tc=!1;try{Tc=typeof XMLHttpRequest<"u"&&"withCredentials"in new XMLHttpRequest}catch{}const zp=Tc;function Bc(K){const O=K.xdomain;try{if(typeof XMLHttpRequest<"u"&&(!O||zp))return new XMLHttpRequest}catch{}if(!O)try{return new ur[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP")}catch{}}function Lm(){}function $p(){}const Hp=function(){return new Bc({xdomain:!1}).responseType!=null}();class Wp extends ts{constructor(O){if(super(O),this.polling=!1,typeof location<"u"){const Y=location.protocol==="https:";let ut=location.port;ut||(ut=Y?"443":"80"),this.xd=typeof location<"u"&&O.hostname!==location.hostname||ut!==O.port}const L=O&&O.forceBase64;this.supportsBinary=Hp&&!L,this.opts.withCredentials&&(this.cookieJar=void 0)}get name(){return"polling"}doOpen(){this.poll()}pause(O){this.readyState="pausing";const L=()=>{this.readyState="paused",O()};if(this.polling||!this.writable){let Y=0;this.polling&&(Y++,this.once("pollComplete",function(){--Y||L()})),this.writable||(Y++,this.once("drain",function(){--Y||L()}))}else L()}poll(){this.polling=!0,this.doPoll(),this.emitReserved("poll")}onData(O){const L=Y=>{if(this.readyState==="opening"&&Y.type==="open"&&this.onOpen(),Y.type==="close")return this.onClose({description:"transport closed by the server"}),!1;this.onPacket(Y)};Ap(O,this.socket.binaryType).forEach(L),this.readyState!=="closed"&&(this.polling=!1,this.emitReserved("pollComplete"),this.readyState==="open"&&this.poll())}doClose(){const O=()=>{this.write([{type:"close"}])};this.readyState==="open"?O():this.once("open",O)}write(O){this.writable=!1,Op(O,L=>{this.doWrite(L,()=>{this.writable=!0,this.emitReserved("drain")})})}uri(){const O=this.opts.secure?"https":"http",L=this.query||{};return this.opts.timestampRequests!==!1&&(L[this.opts.timestampParam]=Ac()),!this.supportsBinary&&!L.sid&&(L.b64=1),this.createUri(O,L)}request(O={}){return Object.assign(O,{xd:this.xd,cookieJar:this.cookieJar},this.opts),new Ir(this.uri(),O)}doWrite(O,L){const Y=this.request({method:"POST",data:O});Y.on("success",L),Y.on("error",(ut,ht)=>{this.onError("xhr post error",ut,ht)})}doPoll(){const O=this.request();O.on("data",this.onData.bind(this)),O.on("error",(L,Y)=>{this.onError("xhr poll error",L,Y)}),this.pollXhr=O}}class Ir extends Bi{constructor(O,L){super(),vo(this,L),this.opts=L,this.method=L.method||"GET",this.uri=O,this.data=L.data!==void 0?L.data:null,this.create()}create(){var O;const L=Sc(this.opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");L.xdomain=!!this.opts.xd;const Y=this.xhr=new Bc(L);try{Y.open(this.method,this.uri,!0);try{if(this.opts.extraHeaders){Y.setDisableHeaderCheck&&Y.setDisableHeaderCheck(!0);for(let ut in this.opts.extraHeaders)this.opts.extraHeaders.hasOwnProperty(ut)&&Y.setRequestHeader(ut,this.opts.extraHeaders[ut])}}catch{}if(this.method==="POST")try{Y.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch{}try{Y.setRequestHeader("Accept","*/*")}catch{}(O=this.opts.cookieJar)===null||O===void 0||O.addCookies(Y),"withCredentials"in Y&&(Y.withCredentials=this.opts.withCredentials),this.opts.requestTimeout&&(Y.timeout=this.opts.requestTimeout),Y.onreadystatechange=()=>{var ut;Y.readyState===3&&((ut=this.opts.cookieJar)===null||ut===void 0||ut.parseCookies(Y)),Y.readyState===4&&(Y.status===200||Y.status===1223?this.onLoad():this.setTimeoutFn(()=>{this.onError(typeof Y.status=="number"?Y.status:0)},0))},Y.send(this.data)}catch(ut){this.setTimeoutFn(()=>{this.onError(ut)},0);return}typeof document<"u"&&(this.index=Ir.requestsCount++,Ir.requests[this.index]=this)}onError(O){this.emitReserved("error",O,this.xhr),this.cleanup(!0)}cleanup(O){if(!(typeof this.xhr>"u"||this.xhr===null)){if(this.xhr.onreadystatechange=$p,O)try{this.xhr.abort()}catch{}typeof document<"u"&&delete Ir.requests[this.index],this.xhr=null}}onLoad(){const O=this.xhr.responseText;O!==null&&(this.emitReserved("data",O),this.emitReserved("success"),this.cleanup())}abort(){this.cleanup()}}if(Ir.requestsCount=0,Ir.requests={},typeof document<"u"){if(typeof attachEvent=="function")attachEvent("onunload",jc);else if(typeof addEventListener=="function"){const K="onpagehide"in ur?"pagehide":"unload";addEventListener(K,jc,!1)}}function jc(){for(let K in Ir.requests)Ir.requests.hasOwnProperty(K)&&Ir.requests[K].abort()}const is=(()=>typeof Promise=="function"&&typeof Promise.resolve=="function"?O=>Promise.resolve().then(O):(O,L)=>L(O,0))(),bo=ur.WebSocket||ur.MozWebSocket,Rc=!0,Vp="arraybuffer",Nc=typeof navigator<"u"&&typeof navigator.product=="string"&&navigator.product.toLowerCase()==="reactnative";class Xp extends ts{constructor(O){super(O),this.supportsBinary=!O.forceBase64}get name(){return"websocket"}doOpen(){if(!this.check())return;const O=this.uri(),L=this.opts.protocols,Y=Nc?{}:Sc(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(Y.headers=this.opts.extraHeaders);try{this.ws=Rc&&!Nc?L?new bo(O,L):new bo(O):new bo(O,L,Y)}catch(ut){return this.emitReserved("error",ut)}this.ws.binaryType=this.socket.binaryType,this.addEventListeners()}addEventListeners(){this.ws.onopen=()=>{this.opts.autoUnref&&this.ws._socket.unref(),this.onOpen()},this.ws.onclose=O=>this.onClose({description:"websocket connection closed",context:O}),this.ws.onmessage=O=>this.onData(O.data),this.ws.onerror=O=>this.onError("websocket error",O)}write(O){this.writable=!1;for(let L=0;L<O.length;L++){const Y=O[L],ut=L===O.length-1;Ja(Y,this.supportsBinary,ht=>{const W={};try{Rc&&this.ws.send(ht)}catch{}ut&&is(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){typeof this.ws<"u"&&(this.ws.close(),this.ws=null)}uri(){const O=this.opts.secure?"wss":"ws",L=this.query||{};return this.opts.timestampRequests&&(L[this.opts.timestampParam]=Ac()),this.supportsBinary||(L.b64=1),this.createUri(O,L)}check(){return!!bo}}class Zp extends ts{get name(){return"webtransport"}doOpen(){typeof WebTransport=="function"&&(this.transport=new WebTransport(this.createUri("https"),this.opts.transportOptions[this.name]),this.transport.closed.then(()=>{this.onClose()}).catch(O=>{this.onError("webtransport error",O)}),this.transport.ready.then(()=>{this.transport.createBidirectionalStream().then(O=>{const L=Bp(Number.MAX_SAFE_INTEGER,this.socket.binaryType),Y=O.readable.pipeThrough(L).getReader(),ut=Tp();ut.readable.pipeTo(O.writable),this.writer=ut.writable.getWriter();const ht=()=>{Y.read().then(({done:_,value:y})=>{_||(this.onPacket(y),ht())}).catch(_=>{})};ht();const W={type:"open"};this.query.sid&&(W.data=`{"sid":"${this.query.sid}"}`),this.writer.write(W).then(()=>this.onOpen())})}))}write(O){this.writable=!1;for(let L=0;L<O.length;L++){const Y=O[L],ut=L===O.length-1;this.writer.write(Y).then(()=>{ut&&is(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){var O;(O=this.transport)===null||O===void 0||O.close()}}const Kp={websocket:Xp,webtransport:Zp,polling:Wp},Jp=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,Gp=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function rs(K){if(K.length>2e3)throw"URI too long";const O=K,L=K.indexOf("["),Y=K.indexOf("]");L!=-1&&Y!=-1&&(K=K.substring(0,L)+K.substring(L,Y).replace(/:/g,";")+K.substring(Y,K.length));let ut=Jp.exec(K||""),ht={},W=14;for(;W--;)ht[Gp[W]]=ut[W]||"";return L!=-1&&Y!=-1&&(ht.source=O,ht.host=ht.host.substring(1,ht.host.length-1).replace(/;/g,":"),ht.authority=ht.authority.replace("[","").replace("]","").replace(/;/g,":"),ht.ipv6uri=!0),ht.pathNames=Yp(ht,ht.path),ht.queryKey=Qp(ht,ht.query),ht}function Yp(K,O){const L=/\/{2,9}/g,Y=O.replace(L,"/").split("/");return(O.slice(0,1)=="/"||O.length===0)&&Y.splice(0,1),O.slice(-1)=="/"&&Y.splice(Y.length-1,1),Y}function Qp(K,O){const L={};return O.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(Y,ut,ht){ut&&(L[ut]=ht)}),L}let Cc=class Rn extends Bi{constructor(O,L={}){super(),this.binaryType=Vp,this.writeBuffer=[],O&&typeof O=="object"&&(L=O,O=null),O?(O=rs(O),L.hostname=O.host,L.secure=O.protocol==="https"||O.protocol==="wss",L.port=O.port,O.query&&(L.query=O.query)):L.host&&(L.hostname=rs(L.host).host),vo(this,L),this.secure=L.secure!=null?L.secure:typeof location<"u"&&location.protocol==="https:",L.hostname&&!L.port&&(L.port=this.secure?"443":"80"),this.hostname=L.hostname||(typeof location<"u"?location.hostname:"localhost"),this.port=L.port||(typeof location<"u"&&location.port?location.port:this.secure?"443":"80"),this.transports=L.transports||["polling","websocket","webtransport"],this.writeBuffer=[],this.prevBufferLen=0,this.opts=Object.assign({path:"/engine.io",agent:!1,withCredentials:!1,upgrade:!0,timestampParam:"t",rememberUpgrade:!1,addTrailingSlash:!0,rejectUnauthorized:!0,perMessageDeflate:{threshold:1024},transportOptions:{},closeOnBeforeunload:!1},L),this.opts.path=this.opts.path.replace(/\/$/,"")+(this.opts.addTrailingSlash?"/":""),typeof this.opts.query=="string"&&(this.opts.query=Up(this.opts.query)),this.id=null,this.upgrades=null,this.pingInterval=null,this.pingTimeout=null,this.pingTimeoutTimer=null,typeof addEventListener=="function"&&(this.opts.closeOnBeforeunload&&(this.beforeunloadEventListener=()=>{this.transport&&(this.transport.removeAllListeners(),this.transport.close())},addEventListener("beforeunload",this.beforeunloadEventListener,!1)),this.hostname!=="localhost"&&(this.offlineEventListener=()=>{this.onClose("transport close",{description:"network connection lost"})},addEventListener("offline",this.offlineEventListener,!1))),this.open()}createTransport(O){const L=Object.assign({},this.opts.query);L.EIO=_c,L.transport=O,this.id&&(L.sid=this.id);const Y=Object.assign({},this.opts,{query:L,socket:this,hostname:this.hostname,secure:this.secure,port:this.port},this.opts.transportOptions[O]);return new Kp[O](Y)}open(){let O;if(this.opts.rememberUpgrade&&Rn.priorWebsocketSuccess&&this.transports.indexOf("websocket")!==-1)O="websocket";else if(this.transports.length===0){this.setTimeoutFn(()=>{this.emitReserved("error","No transports available")},0);return}else O=this.transports[0];this.readyState="opening";try{O=this.createTransport(O)}catch{this.transports.shift(),this.open();return}O.open(),this.setTransport(O)}setTransport(O){this.transport&&this.transport.removeAllListeners(),this.transport=O,O.on("drain",this.onDrain.bind(this)).on("packet",this.onPacket.bind(this)).on("error",this.onError.bind(this)).on("close",L=>this.onClose("transport close",L))}probe(O){let L=this.createTransport(O),Y=!1;Rn.priorWebsocketSuccess=!1;const ut=()=>{Y||(L.send([{type:"ping",data:"probe"}]),L.once("packet",m=>{if(!Y)if(m.type==="pong"&&m.data==="probe"){if(this.upgrading=!0,this.emitReserved("upgrading",L),!L)return;Rn.priorWebsocketSuccess=L.name==="websocket",this.transport.pause(()=>{Y||this.readyState!=="closed"&&(v(),this.setTransport(L),L.send([{type:"upgrade"}]),this.emitReserved("upgrade",L),L=null,this.upgrading=!1,this.flush())})}else{const S=new Error("probe error");S.transport=L.name,this.emitReserved("upgradeError",S)}}))};function ht(){Y||(Y=!0,v(),L.close(),L=null)}const W=m=>{const S=new Error("probe error: "+m);S.transport=L.name,ht(),this.emitReserved("upgradeError",S)};function _(){W("transport closed")}function y(){W("socket closed")}function x(m){L&&m.name!==L.name&&ht()}const v=()=>{L.removeListener("open",ut),L.removeListener("error",W),L.removeListener("close",_),this.off("close",y),this.off("upgrading",x)};L.once("open",ut),L.once("error",W),L.once("close",_),this.once("close",y),this.once("upgrading",x),this.upgrades.indexOf("webtransport")!==-1&&O!=="webtransport"?this.setTimeoutFn(()=>{Y||L.open()},200):L.open()}onOpen(){if(this.readyState="open",Rn.priorWebsocketSuccess=this.transport.name==="websocket",this.emitReserved("open"),this.flush(),this.readyState==="open"&&this.opts.upgrade){let O=0;const L=this.upgrades.length;for(;O<L;O++)this.probe(this.upgrades[O])}}onPacket(O){if(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing")switch(this.emitReserved("packet",O),this.emitReserved("heartbeat"),this.resetPingTimeout(),O.type){case"open":this.onHandshake(JSON.parse(O.data));break;case"ping":this.sendPacket("pong"),this.emitReserved("ping"),this.emitReserved("pong");break;case"error":const L=new Error("server error");L.code=O.data,this.onError(L);break;case"message":this.emitReserved("data",O.data),this.emitReserved("message",O.data);break}}onHandshake(O){this.emitReserved("handshake",O),this.id=O.sid,this.transport.query.sid=O.sid,this.upgrades=this.filterUpgrades(O.upgrades),this.pingInterval=O.pingInterval,this.pingTimeout=O.pingTimeout,this.maxPayload=O.maxPayload,this.onOpen(),this.readyState!=="closed"&&this.resetPingTimeout()}resetPingTimeout(){this.clearTimeoutFn(this.pingTimeoutTimer),this.pingTimeoutTimer=this.setTimeoutFn(()=>{this.onClose("ping timeout")},this.pingInterval+this.pingTimeout),this.opts.autoUnref&&this.pingTimeoutTimer.unref()}onDrain(){this.writeBuffer.splice(0,this.prevBufferLen),this.prevBufferLen=0,this.writeBuffer.length===0?this.emitReserved("drain"):this.flush()}flush(){if(this.readyState!=="closed"&&this.transport.writable&&!this.upgrading&&this.writeBuffer.length){const O=this.getWritablePackets();this.transport.send(O),this.prevBufferLen=O.length,this.emitReserved("flush")}}getWritablePackets(){if(!(this.maxPayload&&this.transport.name==="polling"&&this.writeBuffer.length>1))return this.writeBuffer;let L=1;for(let Y=0;Y<this.writeBuffer.length;Y++){const ut=this.writeBuffer[Y].data;if(ut&&(L+=Pp(ut)),Y>0&&L>this.maxPayload)return this.writeBuffer.slice(0,Y);L+=2}return this.writeBuffer}write(O,L,Y){return this.sendPacket("message",O,L,Y),this}send(O,L,Y){return this.sendPacket("message",O,L,Y),this}sendPacket(O,L,Y,ut){if(typeof L=="function"&&(ut=L,L=void 0),typeof Y=="function"&&(ut=Y,Y=null),this.readyState==="closing"||this.readyState==="closed")return;Y=Y||{},Y.compress=Y.compress!==!1;const ht={type:O,data:L,options:Y};this.emitReserved("packetCreate",ht),this.writeBuffer.push(ht),ut&&this.once("flush",ut),this.flush()}close(){const O=()=>{this.onClose("forced close"),this.transport.close()},L=()=>{this.off("upgrade",L),this.off("upgradeError",L),O()},Y=()=>{this.once("upgrade",L),this.once("upgradeError",L)};return(this.readyState==="opening"||this.readyState==="open")&&(this.readyState="closing",this.writeBuffer.length?this.once("drain",()=>{this.upgrading?Y():O()}):this.upgrading?Y():O()),this}onError(O){Rn.priorWebsocketSuccess=!1,this.emitReserved("error",O),this.onClose("transport error",O)}onClose(O,L){(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing")&&(this.clearTimeoutFn(this.pingTimeoutTimer),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),typeof removeEventListener=="function"&&(removeEventListener("beforeunload",this.beforeunloadEventListener,!1),removeEventListener("offline",this.offlineEventListener,!1)),this.readyState="closed",this.id=null,this.emitReserved("close",O,L),this.writeBuffer=[],this.prevBufferLen=0)}filterUpgrades(O){const L=[];let Y=0;const ut=O.length;for(;Y<ut;Y++)~this.transports.indexOf(O[Y])&&L.push(O[Y]);return L}};Cc.protocol=_c;function td(K,O="",L){let Y=K;L=L||typeof location<"u"&&location,K==null&&(K=L.protocol+"//"+L.host),typeof K=="string"&&(K.charAt(0)==="/"&&(K.charAt(1)==="/"?K=L.protocol+K:K=L.host+K),/^(https?|wss?):\/\//.test(K)||(typeof L<"u"?K=L.protocol+"//"+K:K="https://"+K),Y=rs(K)),Y.port||(/^(http|ws)$/.test(Y.protocol)?Y.port="80":/^(http|ws)s$/.test(Y.protocol)&&(Y.port="443")),Y.path=Y.path||"/";const ht=Y.host.indexOf(":")!==-1?"["+Y.host+"]":Y.host;return Y.id=Y.protocol+"://"+ht+":"+Y.port+O,Y.href=Y.protocol+"://"+ht+(L&&L.port===Y.port?"":":"+Y.port),Y}const ed=typeof ArrayBuffer=="function",id=K=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(K):K.buffer instanceof ArrayBuffer,Pc=Object.prototype.toString,rd=typeof Blob=="function"||typeof Blob<"u"&&Pc.call(Blob)==="[object BlobConstructor]",nd=typeof File=="function"||typeof File<"u"&&Pc.call(File)==="[object FileConstructor]";function ns(K){return ed&&(K instanceof ArrayBuffer||id(K))||rd&&K instanceof Blob||nd&&K instanceof File}function wo(K,O){if(!K||typeof K!="object")return!1;if(Array.isArray(K)){for(let L=0,Y=K.length;L<Y;L++)if(wo(K[L]))return!0;return!1}if(ns(K))return!0;if(K.toJSON&&typeof K.toJSON=="function"&&arguments.length===1)return wo(K.toJSON(),!0);for(const L in K)if(Object.prototype.hasOwnProperty.call(K,L)&&wo(K[L]))return!0;return!1}function od(K){const O=[],L=K.data,Y=K;return Y.data=os(L,O),Y.attachments=O.length,{packet:Y,buffers:O}}function os(K,O){if(!K)return K;if(ns(K)){const L={_placeholder:!0,num:O.length};return O.push(K),L}else if(Array.isArray(K)){const L=new Array(K.length);for(let Y=0;Y<K.length;Y++)L[Y]=os(K[Y],O);return L}else if(typeof K=="object"&&!(K instanceof Date)){const L={};for(const Y in K)Object.prototype.hasOwnProperty.call(K,Y)&&(L[Y]=os(K[Y],O));return L}return K}function ad(K,O){return K.data=as(K.data,O),delete K.attachments,K}function as(K,O){if(!K)return K;if(K&&K._placeholder===!0){if(typeof K.num=="number"&&K.num>=0&&K.num<O.length)return O[K.num];throw new Error("illegal attachments")}else if(Array.isArray(K))for(let L=0;L<K.length;L++)K[L]=as(K[L],O);else if(typeof K=="object")for(const L in K)Object.prototype.hasOwnProperty.call(K,L)&&(K[L]=as(K[L],O));return K}const sd=["connect","connect_error","disconnect","disconnecting","newListener","removeListener"],ud=5;var ti;(function(K){K[K.CONNECT=0]="CONNECT",K[K.DISCONNECT=1]="DISCONNECT",K[K.EVENT=2]="EVENT",K[K.ACK=3]="ACK",K[K.CONNECT_ERROR=4]="CONNECT_ERROR",K[K.BINARY_EVENT=5]="BINARY_EVENT",K[K.BINARY_ACK=6]="BINARY_ACK"})(ti||(ti={}));class cd{constructor(O){this.replacer=O}encode(O){return(O.type===ti.EVENT||O.type===ti.ACK)&&wo(O)?this.encodeAsBinary({type:O.type===ti.EVENT?ti.BINARY_EVENT:ti.BINARY_ACK,nsp:O.nsp,data:O.data,id:O.id}):[this.encodeAsString(O)]}encodeAsString(O){let L=""+O.type;return(O.type===ti.BINARY_EVENT||O.type===ti.BINARY_ACK)&&(L+=O.attachments+"-"),O.nsp&&O.nsp!=="/"&&(L+=O.nsp+","),O.id!=null&&(L+=O.id),O.data!=null&&(L+=JSON.stringify(O.data,this.replacer)),L}encodeAsBinary(O){const L=od(O),Y=this.encodeAsString(L.packet),ut=L.buffers;return ut.unshift(Y),ut}}function Lc(K){return Object.prototype.toString.call(K)==="[object Object]"}class ss extends Bi{constructor(O){super(),this.reviver=O}add(O){let L;if(typeof O=="string"){if(this.reconstructor)throw new Error("got plaintext data when reconstructing a packet");L=this.decodeString(O);const Y=L.type===ti.BINARY_EVENT;Y||L.type===ti.BINARY_ACK?(L.type=Y?ti.EVENT:ti.ACK,this.reconstructor=new ld(L),L.attachments===0&&super.emitReserved("decoded",L)):super.emitReserved("decoded",L)}else if(ns(O)||O.base64)if(this.reconstructor)L=this.reconstructor.takeBinaryData(O),L&&(this.reconstructor=null,super.emitReserved("decoded",L));else throw new Error("got binary data when not reconstructing a packet");else throw new Error("Unknown type: "+O)}decodeString(O){let L=0;const Y={type:Number(O.charAt(0))};if(ti[Y.type]===void 0)throw new Error("unknown packet type "+Y.type);if(Y.type===ti.BINARY_EVENT||Y.type===ti.BINARY_ACK){const ht=L+1;for(;O.charAt(++L)!=="-"&&L!=O.length;);const W=O.substring(ht,L);if(W!=Number(W)||O.charAt(L)!=="-")throw new Error("Illegal attachments");Y.attachments=Number(W)}if(O.charAt(L+1)==="/"){const ht=L+1;for(;++L&&!(O.charAt(L)===","||L===O.length););Y.nsp=O.substring(ht,L)}else Y.nsp="/";const ut=O.charAt(L+1);if(ut!==""&&Number(ut)==ut){const ht=L+1;for(;++L;){const W=O.charAt(L);if(W==null||Number(W)!=W){--L;break}if(L===O.length)break}Y.id=Number(O.substring(ht,L+1))}if(O.charAt(++L)){const ht=this.tryParse(O.substr(L));if(ss.isPayloadValid(Y.type,ht))Y.data=ht;else throw new Error("invalid payload")}return Y}tryParse(O){try{return JSON.parse(O,this.reviver)}catch{return!1}}static isPayloadValid(O,L){switch(O){case ti.CONNECT:return Lc(L);case ti.DISCONNECT:return L===void 0;case ti.CONNECT_ERROR:return typeof L=="string"||Lc(L);case ti.EVENT:case ti.BINARY_EVENT:return Array.isArray(L)&&(typeof L[0]=="number"||typeof L[0]=="string"&&sd.indexOf(L[0])===-1);case ti.ACK:case ti.BINARY_ACK:return Array.isArray(L)}}destroy(){this.reconstructor&&(this.reconstructor.finishedReconstruction(),this.reconstructor=null)}}class ld{constructor(O){this.packet=O,this.buffers=[],this.reconPack=O}takeBinaryData(O){if(this.buffers.push(O),this.buffers.length===this.reconPack.attachments){const L=ad(this.reconPack,this.buffers);return this.finishedReconstruction(),L}return null}finishedReconstruction(){this.reconPack=null,this.buffers=[]}}const hd=Object.freeze(Object.defineProperty({__proto__:null,Decoder:ss,Encoder:cd,get PacketType(){return ti},protocol:ud},Symbol.toStringTag,{value:"Module"}));function yr(K,O,L){return K.on(O,L),function(){K.off(O,L)}}const fd=Object.freeze({connect:1,connect_error:1,disconnect:1,disconnecting:1,newListener:1,removeListener:1});class Dc extends Bi{constructor(O,L,Y){super(),this.connected=!1,this.recovered=!1,this.receiveBuffer=[],this.sendBuffer=[],this._queue=[],this._queueSeq=0,this.ids=0,this.acks={},this.flags={},this.io=O,this.nsp=L,Y&&Y.auth&&(this.auth=Y.auth),this._opts=Object.assign({},Y),this.io._autoConnect&&this.open()}get disconnected(){return!this.connected}subEvents(){if(this.subs)return;const O=this.io;this.subs=[yr(O,"open",this.onopen.bind(this)),yr(O,"packet",this.onpacket.bind(this)),yr(O,"error",this.onerror.bind(this)),yr(O,"close",this.onclose.bind(this))]}get active(){return!!this.subs}connect(){return this.connected?this:(this.subEvents(),this.io._reconnecting||this.io.open(),this.io._readyState==="open"&&this.onopen(),this)}open(){return this.connect()}send(...O){return O.unshift("message"),this.emit.apply(this,O),this}emit(O,...L){if(fd.hasOwnProperty(O))throw new Error('"'+O.toString()+'" is a reserved event name');if(L.unshift(O),this._opts.retries&&!this.flags.fromQueue&&!this.flags.volatile)return this._addToQueue(L),this;const Y={type:ti.EVENT,data:L};if(Y.options={},Y.options.compress=this.flags.compress!==!1,typeof L[L.length-1]=="function"){const W=this.ids++,_=L.pop();this._registerAckCallback(W,_),Y.id=W}const ut=this.io.engine&&this.io.engine.transport&&this.io.engine.transport.writable;return this.flags.volatile&&(!ut||!this.connected)||(this.connected?(this.notifyOutgoingListeners(Y),this.packet(Y)):this.sendBuffer.push(Y)),this.flags={},this}_registerAckCallback(O,L){var Y;const ut=(Y=this.flags.timeout)!==null&&Y!==void 0?Y:this._opts.ackTimeout;if(ut===void 0){this.acks[O]=L;return}const ht=this.io.setTimeoutFn(()=>{delete this.acks[O];for(let _=0;_<this.sendBuffer.length;_++)this.sendBuffer[_].id===O&&this.sendBuffer.splice(_,1);L.call(this,new Error("operation has timed out"))},ut),W=(..._)=>{this.io.clearTimeoutFn(ht),L.apply(this,_)};W.withError=!0,this.acks[O]=W}emitWithAck(O,...L){return new Promise((Y,ut)=>{const ht=(W,_)=>W?ut(W):Y(_);ht.withError=!0,L.push(ht),this.emit(O,...L)})}_addToQueue(O){let L;typeof O[O.length-1]=="function"&&(L=O.pop());const Y={id:this._queueSeq++,tryCount:0,pending:!1,args:O,flags:Object.assign({fromQueue:!0},this.flags)};O.push((ut,...ht)=>Y!==this._queue[0]?void 0:(ut!==null?Y.tryCount>this._opts.retries&&(this._queue.shift(),L&&L(ut)):(this._queue.shift(),L&&L(null,...ht)),Y.pending=!1,this._drainQueue())),this._queue.push(Y),this._drainQueue()}_drainQueue(O=!1){if(!this.connected||this._queue.length===0)return;const L=this._queue[0];L.pending&&!O||(L.pending=!0,L.tryCount++,this.flags=L.flags,this.emit.apply(this,L.args))}packet(O){O.nsp=this.nsp,this.io._packet(O)}onopen(){typeof this.auth=="function"?this.auth(O=>{this._sendConnectPacket(O)}):this._sendConnectPacket(this.auth)}_sendConnectPacket(O){this.packet({type:ti.CONNECT,data:this._pid?Object.assign({pid:this._pid,offset:this._lastOffset},O):O})}onerror(O){this.connected||this.emitReserved("connect_error",O)}onclose(O,L){this.connected=!1,delete this.id,this.emitReserved("disconnect",O,L),this._clearAcks()}_clearAcks(){Object.keys(this.acks).forEach(O=>{if(!this.sendBuffer.some(Y=>String(Y.id)===O)){const Y=this.acks[O];delete this.acks[O],Y.withError&&Y.call(this,new Error("socket has been disconnected"))}})}onpacket(O){if(O.nsp===this.nsp)switch(O.type){case ti.CONNECT:O.data&&O.data.sid?this.onconnect(O.data.sid,O.data.pid):this.emitReserved("connect_error",new Error("It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)"));break;case ti.EVENT:case ti.BINARY_EVENT:this.onevent(O);break;case ti.ACK:case ti.BINARY_ACK:this.onack(O);break;case ti.DISCONNECT:this.ondisconnect();break;case ti.CONNECT_ERROR:this.destroy();const Y=new Error(O.data.message);Y.data=O.data.data,this.emitReserved("connect_error",Y);break}}onevent(O){const L=O.data||[];O.id!=null&&L.push(this.ack(O.id)),this.connected?this.emitEvent(L):this.receiveBuffer.push(Object.freeze(L))}emitEvent(O){if(this._anyListeners&&this._anyListeners.length){const L=this._anyListeners.slice();for(const Y of L)Y.apply(this,O)}super.emit.apply(this,O),this._pid&&O.length&&typeof O[O.length-1]=="string"&&(this._lastOffset=O[O.length-1])}ack(O){const L=this;let Y=!1;return function(...ut){Y||(Y=!0,L.packet({type:ti.ACK,id:O,data:ut}))}}onack(O){const L=this.acks[O.id];typeof L=="function"&&(delete this.acks[O.id],L.withError&&O.data.unshift(null),L.apply(this,O.data))}onconnect(O,L){this.id=O,this.recovered=L&&this._pid===L,this._pid=L,this.connected=!0,this.emitBuffered(),this.emitReserved("connect"),this._drainQueue(!0)}emitBuffered(){this.receiveBuffer.forEach(O=>this.emitEvent(O)),this.receiveBuffer=[],this.sendBuffer.forEach(O=>{this.notifyOutgoingListeners(O),this.packet(O)}),this.sendBuffer=[]}ondisconnect(){this.destroy(),this.onclose("io server disconnect")}destroy(){this.subs&&(this.subs.forEach(O=>O()),this.subs=void 0),this.io._destroy(this)}disconnect(){return this.connected&&this.packet({type:ti.DISCONNECT}),this.destroy(),this.connected&&this.onclose("io client disconnect"),this}close(){return this.disconnect()}compress(O){return this.flags.compress=O,this}get volatile(){return this.flags.volatile=!0,this}timeout(O){return this.flags.timeout=O,this}onAny(O){return this._anyListeners=this._anyListeners||[],this._anyListeners.push(O),this}prependAny(O){return this._anyListeners=this._anyListeners||[],this._anyListeners.unshift(O),this}offAny(O){if(!this._anyListeners)return this;if(O){const L=this._anyListeners;for(let Y=0;Y<L.length;Y++)if(O===L[Y])return L.splice(Y,1),this}else this._anyListeners=[];return this}listenersAny(){return this._anyListeners||[]}onAnyOutgoing(O){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.push(O),this}prependAnyOutgoing(O){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.unshift(O),this}offAnyOutgoing(O){if(!this._anyOutgoingListeners)return this;if(O){const L=this._anyOutgoingListeners;for(let Y=0;Y<L.length;Y++)if(O===L[Y])return L.splice(Y,1),this}else this._anyOutgoingListeners=[];return this}listenersAnyOutgoing(){return this._anyOutgoingListeners||[]}notifyOutgoingListeners(O){if(this._anyOutgoingListeners&&this._anyOutgoingListeners.length){const L=this._anyOutgoingListeners.slice();for(const Y of L)Y.apply(this,O.data)}}}function wn(K){K=K||{},this.ms=K.min||100,this.max=K.max||1e4,this.factor=K.factor||2,this.jitter=K.jitter>0&&K.jitter<=1?K.jitter:0,this.attempts=0}wn.prototype.duration=function(){var K=this.ms*Math.pow(this.factor,this.attempts++);if(this.jitter){var O=Math.random(),L=Math.floor(O*this.jitter*K);K=Math.floor(O*10)&1?K+L:K-L}return Math.min(K,this.max)|0},wn.prototype.reset=function(){this.attempts=0},wn.prototype.setMin=function(K){this.ms=K},wn.prototype.setMax=function(K){this.max=K},wn.prototype.setJitter=function(K){this.jitter=K};class us extends Bi{constructor(O,L){var Y;super(),this.nsps={},this.subs=[],O&&typeof O=="object"&&(L=O,O=void 0),L=L||{},L.path=L.path||"/socket.io",this.opts=L,vo(this,L),this.reconnection(L.reconnection!==!1),this.reconnectionAttempts(L.reconnectionAttempts||1/0),this.reconnectionDelay(L.reconnectionDelay||1e3),this.reconnectionDelayMax(L.reconnectionDelayMax||5e3),this.randomizationFactor((Y=L.randomizationFactor)!==null&&Y!==void 0?Y:.5),this.backoff=new wn({min:this.reconnectionDelay(),max:this.reconnectionDelayMax(),jitter:this.randomizationFactor()}),this.timeout(L.timeout==null?2e4:L.timeout),this._readyState="closed",this.uri=O;const ut=L.parser||hd;this.encoder=new ut.Encoder,this.decoder=new ut.Decoder,this._autoConnect=L.autoConnect!==!1,this._autoConnect&&this.open()}reconnection(O){return arguments.length?(this._reconnection=!!O,this):this._reconnection}reconnectionAttempts(O){return O===void 0?this._reconnectionAttempts:(this._reconnectionAttempts=O,this)}reconnectionDelay(O){var L;return O===void 0?this._reconnectionDelay:(this._reconnectionDelay=O,(L=this.backoff)===null||L===void 0||L.setMin(O),this)}randomizationFactor(O){var L;return O===void 0?this._randomizationFactor:(this._randomizationFactor=O,(L=this.backoff)===null||L===void 0||L.setJitter(O),this)}reconnectionDelayMax(O){var L;return O===void 0?this._reconnectionDelayMax:(this._reconnectionDelayMax=O,(L=this.backoff)===null||L===void 0||L.setMax(O),this)}timeout(O){return arguments.length?(this._timeout=O,this):this._timeout}maybeReconnectOnOpen(){!this._reconnecting&&this._reconnection&&this.backoff.attempts===0&&this.reconnect()}open(O){if(~this._readyState.indexOf("open"))return this;this.engine=new Cc(this.uri,this.opts);const L=this.engine,Y=this;this._readyState="opening",this.skipReconnect=!1;const ut=yr(L,"open",function(){Y.onopen(),O&&O()}),ht=_=>{this.cleanup(),this._readyState="closed",this.emitReserved("error",_),O?O(_):this.maybeReconnectOnOpen()},W=yr(L,"error",ht);if(this._timeout!==!1){const _=this._timeout,y=this.setTimeoutFn(()=>{ut(),ht(new Error("timeout")),L.close()},_);this.opts.autoUnref&&y.unref(),this.subs.push(()=>{this.clearTimeoutFn(y)})}return this.subs.push(ut),this.subs.push(W),this}connect(O){return this.open(O)}onopen(){this.cleanup(),this._readyState="open",this.emitReserved("open");const O=this.engine;this.subs.push(yr(O,"ping",this.onping.bind(this)),yr(O,"data",this.ondata.bind(this)),yr(O,"error",this.onerror.bind(this)),yr(O,"close",this.onclose.bind(this)),yr(this.decoder,"decoded",this.ondecoded.bind(this)))}onping(){this.emitReserved("ping")}ondata(O){try{this.decoder.add(O)}catch(L){this.onclose("parse error",L)}}ondecoded(O){is(()=>{this.emitReserved("packet",O)},this.setTimeoutFn)}onerror(O){this.emitReserved("error",O)}socket(O,L){let Y=this.nsps[O];return Y?this._autoConnect&&!Y.active&&Y.connect():(Y=new Dc(this,O,L),this.nsps[O]=Y),Y}_destroy(O){const L=Object.keys(this.nsps);for(const Y of L)if(this.nsps[Y].active)return;this._close()}_packet(O){const L=this.encoder.encode(O);for(let Y=0;Y<L.length;Y++)this.engine.write(L[Y],O.options)}cleanup(){this.subs.forEach(O=>O()),this.subs.length=0,this.decoder.destroy()}_close(){this.skipReconnect=!0,this._reconnecting=!1,this.onclose("forced close"),this.engine&&this.engine.close()}disconnect(){return this._close()}onclose(O,L){this.cleanup(),this.backoff.reset(),this._readyState="closed",this.emitReserved("close",O,L),this._reconnection&&!this.skipReconnect&&this.reconnect()}reconnect(){if(this._reconnecting||this.skipReconnect)return this;const O=this;if(this.backoff.attempts>=this._reconnectionAttempts)this.backoff.reset(),this.emitReserved("reconnect_failed"),this._reconnecting=!1;else{const L=this.backoff.duration();this._reconnecting=!0;const Y=this.setTimeoutFn(()=>{O.skipReconnect||(this.emitReserved("reconnect_attempt",O.backoff.attempts),!O.skipReconnect&&O.open(ut=>{ut?(O._reconnecting=!1,O.reconnect(),this.emitReserved("reconnect_error",ut)):O.onreconnect()}))},L);this.opts.autoUnref&&Y.unref(),this.subs.push(()=>{this.clearTimeoutFn(Y)})}}onreconnect(){const O=this.backoff.attempts;this._reconnecting=!1,this.backoff.reset(),this.emitReserved("reconnect",O)}}const Pn={};function Mo(K,O){typeof K=="object"&&(O=K,K=void 0),O=O||{};const L=td(K,O.path||"/socket.io"),Y=L.source,ut=L.id,ht=L.path,W=Pn[ut]&&ht in Pn[ut].nsps,_=O.forceNew||O["force new connection"]||O.multiplex===!1||W;let y;return _?y=new us(Y,O):(Pn[ut]||(Pn[ut]=new us(Y,O)),y=Pn[ut]),L.query&&!O.query&&(O.query=L.queryKey),y.socket(L.path,O)}Object.assign(Mo,{Manager:us,Socket:Dc,io:Mo,connect:Mo});var nn;(function(K){K[K.Normal=0]="Normal",K[K.Debug=1]="Debug"})(nn||(nn={}));let xo;const pd=new Uint8Array(16);function dd(){if(!xo&&(xo=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!xo))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return xo(pd)}const Li=[];for(let K=0;K<256;++K)Li.push((K+256).toString(16).slice(1));function md(K,O=0){return Li[K[O+0]]+Li[K[O+1]]+Li[K[O+2]]+Li[K[O+3]]+"-"+Li[K[O+4]]+Li[K[O+5]]+"-"+Li[K[O+6]]+Li[K[O+7]]+"-"+Li[K[O+8]]+Li[K[O+9]]+"-"+Li[K[O+10]]+Li[K[O+11]]+Li[K[O+12]]+Li[K[O+13]]+Li[K[O+14]]+Li[K[O+15]]}const Uc={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function qc(K,O,L){if(Uc.randomUUID&&!O&&!K)return Uc.randomUUID();K=K||{};const Y=K.random||(K.rng||dd)();if(Y[6]=Y[6]&15|64,Y[8]=Y[8]&63|128,O){L=L||0;for(let ut=0;ut<16;++ut)O[L+ut]=Y[ut];return O}return md(Y)}const on=new Pi("[EventBus] ");class Fc{constructor(O=!1){Object.defineProperty(this,"eventListenerMap",{enumerable:!0,configurable:!0,writable:!0,value:{}}),O&&on.disable()}getEventListenerMap(){return Object.assign({},this.eventListenerMap)}on(O,L,Y=!1){this.eventListenerMap[O]||(this.eventListenerMap[O]=[]),Y?this.eventListenerMap[O].push({fn:L,once:!0}):this.eventListenerMap[O].push(L),on.log(`add event ${O} listener ${Y?", call once":""}`)}once(O,L){this.on(O,L,!0)}off(O,L){if(this.eventListenerMap[O]){const Y=this.eventListenerMap[O].findIndex(ut=>{if(typeof ut=="function"&&L===ut)return!0;if(ut=ut,ut.fn===L)return!0});Y<0?on.log(`event ${O} listener ${L.name} is not found`):(this.eventListenerMap[O].splice(Y,1),on.log(`remove event ${O} listener`))}else on.log(`event ${O} listeners is empty`)}emit(O,L){if(!this.eventListenerMap[O]){on.log(`event ${O} listeners is empty`);return}const Y=[];for(let ut=0;ut<this.eventListenerMap[O].length;ut++){const ht=this.eventListenerMap[O][ut];typeof ht=="function"?ht(L):Y.push(ht)}Y.forEach(ut=>{ut&&(ut.fn(L),this.off(O,ut.fn))}),on.log(`event ${O} is fired, has ${this.eventListenerMap[O].length} listeners`)}removeAllListeners(){this.eventListenerMap={}}}var _o;(function(K){K[K.enable=1]="enable",K[K.disable=2]="disable"})(_o||(_o={}));const zi=new Pi("[Session] ");var $i;(function(K){K.DataRequestFailed="data request error",K.SocketConnectionFailed="socket error",K.IdUndefined="session id is not defined",K.SendingEmptyContent="failed at sending empty content",K.Frozen="session is frozen",K.UserModeError="failed at setting socket user mode",K.Inactive="session is inactive"})($i||($i={})),$i.IdUndefined+"",$i.SendingEmptyContent+"",$i.Frozen+"";class cs{constructor(O,L="",Y,ut,ht,W){Object.defineProperty(this,"token",{enumerable:!0,configurable:!0,writable:!0,value:O}),Object.defineProperty(this,"lazyload",{enumerable:!0,configurable:!0,writable:!0,value:ut}),Object.defineProperty(this,"_id",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_frozen",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"inactivating",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_ready",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"event",{enumerable:!0,configurable:!0,writable:!0,value:new Fc}),Object.defineProperty(this,"_applicationId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_application",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"data",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"client",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"messages",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_loadingMessages",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_loadingMessagesSize",{enumerable:!0,configurable:!0,writable:!0,value:10}),Object.defineProperty(this,"cvforceApi",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"socket",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_promptVariables",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"active",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"activing",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_stopAnswer",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_dataLoading",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_dataLoaded",{enumerable:!0,configurable:!0,writable:!0,value:!1}),this.client=W||null,this._applicationId=oo(O).rid||Mi.configuration.applicationId,this.cvforceApi=this.getService(),ht&&(this._application=ht),this.event.emit("init",{applicationId:this._applicationId,sessionId:L}),this.loadApplicationInfo().then(()=>{var _;if(L)this._id=L,this.event.emit("data:loading"),Y?(this.data=Y,ut||(this._dataLoading=!0,this.cvforceApi.getSession(this.applicationId,L).then(y=>Le(this,void 0,void 0,function*(){this.data=y,this._promptVariables=yield this.cvforceApi.getApplicationIdSessionIdPromptVariables(this.applicationId,L)})).then(()=>Le(this,void 0,void 0,function*(){this.messages=[],yield this.fetchMessages(),this.event.emit("data:loaded",this.data),this.event.emit("data:updated",this.data)})))):(this._dataLoading=!0,this.cvforceApi.getSession(this.applicationId,L).then(y=>Le(this,void 0,void 0,function*(){this.data=y,this._promptVariables=yield this.cvforceApi.getApplicationIdSessionIdPromptVariables(this.applicationId,L)})).then(()=>Le(this,void 0,void 0,function*(){this.messages=[],yield this.fetchMessages(),this.event.emit("data:loaded",this.data),this.event.emit("data:updated",this.data),this._dataLoading=!1,this._dataLoaded=!0})));else{const y=(Y==null?void 0:Y.name)||"新建会话";this.event.emit("data:creating",{applicationId:this._applicationId,name:y}),this.event.emit("data:loading"),this.cvforceApi.postSession(this.applicationId,{name:y,netOpen:Y==null?void 0:Y.netOpen,knowledgeList:(_=Y==null?void 0:Y.knowledges)===null||_===void 0?void 0:_.map(x=>x.id),applicationId:this._applicationId}).then(x=>Le(this,void 0,void 0,function*(){this._id=x.id,this.data=x,this._promptVariables=yield this.cvforceApi.getApplicationIdSessionIdPromptVariables(this.applicationId,this._id),yield(()=>{if(Y!=null&&Y.knowledges)return this.setKnowledges((Y==null?void 0:Y.knowledges)||void 0)})(),yield(()=>{if(Y!=null&&Y.promptVariables){const v=this._promptVariables.map(m=>{var S,a;const p=((a=(S=Y.promptVariables)===null||S===void 0?void 0:S.find(c=>c.key===m.key))===null||a===void 0?void 0:a.value)||"";return Object.assign(Object.assign({},m),{value:p})}).sort((m,S)=>m.key.localeCompare(S.key));return this.setPromptVariables(v||[])}else return})(),this.event.emit("data:created",this.data),this.event.emit("data:loaded",this.data),this.event.emit("data:updated",this.data),this._ready=!0,this.event.emit("ready")}))}})}fetchData(){return Le(this,void 0,void 0,function*(){if(!this.data)throw Error("session data is not loaded");return yield this.cvforceApi.getSession(this.applicationId,this.data.id).then(O=>Le(this,void 0,void 0,function*(){return this.data=O,this.event.emit("data:updated",this.data),O}))})}get id(){var O;return this._id||((O=this.data)===null||O===void 0?void 0:O.id)||""}get applicationId(){return this._applicationId}get application(){return this._application}loadApplicationInfo(){if(this._application)return Promise.resolve(this._application);if(this._applicationId&&!this._application)return this.event.emit("application:data:loading"),this.cvforceApi.getApplicationId(this._applicationId).then(O=>(this._application=O,this.event.emit("application:data:loaded",O),O));throw Error("application id is not defined")}get ready(){return this._ready}get frozen(){return this._frozen}set frozen(O){O===!1&&this.inactivating&&this.socket&&(this.socket.disconnect(),this.socket=null,this.event.emit("inactivated")),this._frozen=O,this.event.emit("frozen",O)}get knowledges(){if(!this.data)throw Error("session data is not loaded");return this.data.knowledges||void 0}setKnowledges(O){return Le(this,void 0,void 0,function*(){var L;if(((L=this._application)===null||L===void 0?void 0:L.type)===bn.Agent){console.warn("Agent Application Sessions are disabled to setKnowledges.");return}if(!this.data)throw Error("session data is not loaded");return yield this.cvforceApi.patchSessionsId(this._applicationId,this.data.id,{knowledges:O}),this.data.knowledges=O,this.event.emit("data:updated",this.data),this.event.emit("data:updated:knowledges",{knowledges:O}),O})}validateConfigs(){if(!this._id)throw Error("session id is not defined");if(!this.data)throw Error("session data is not loaded");const O=this.promptVariables.filter(L=>L.status===pc.Quoted).filter(L=>!L.value);if(O.length)throw Error(`在提示词中被引用的变量值不能为空, 请检查以下变量: ${O.map(L=>L.key).join(", ")}`)}get promptVariables(){return this._promptVariables.filter(O=>O.key!=="query")}setPromptVariables(O){return Le(this,void 0,void 0,function*(){var L;if(((L=this._application)===null||L===void 0?void 0:L.type)===bn.Agent){console.warn("Agent Application Sessions are disabled to setPromptVariables.");return}const Y=this._promptVariables.map(ut=>{var ht;const W=((ht=O==null?void 0:O.find(_=>_.key===ut.key))===null||ht===void 0?void 0:ht.value)||ut.value;return Object.assign(Object.assign({},ut),{value:W})}).sort((ut,ht)=>ut.key.localeCompare(ht.key));if(yield Promise.all(Y.filter(ut=>ut.key!=="query").map(ut=>{if(!this.data)throw Error("session data is not loaded");if(!(!ut.id||!ut.key))return this.cvforceApi.patchApplicationIdSessionpromptVariablesId(this._applicationId,this.data.id,ut.id,{value:ut.value}).catch(console.error)})),!this.data)throw Error("session data is not loaded");return this._promptVariables=yield this.cvforceApi.getApplicationIdSessionIdPromptVariables(this.applicationId,this.data.id),this.event.emit("data:updated",this.data),this.event.emit("data:updated:promptVariables",{promptVariables:this._promptVariables}),this._promptVariables})}get netOpen(){if(!this.data)throw Error("session data is not loaded");return this.data.netOpen||!1}setNetOpen(O){return Le(this,void 0,void 0,function*(){var L,Y,ut;if(zi.log("setNetOpen:",O),zi.log("application arrange setting value: ",(L=this._application)===null||L===void 0?void 0:L.arrange[0].enableNetOpen),((Y=this._application)===null||Y===void 0?void 0:Y.type)===bn.Agent){console.warn("Agent Application Sessions are disabled to setNetOpen.");return}if(((ut=this._application)===null||ut===void 0?void 0:ut.arrange[0].enableNetOpen)===!1){console.warn("This Application is disabled to change netOpen.");return}if(!this.data)throw Error("session data is not loaded");return yield this.cvforceApi.patchSessionsId(this._applicationId,this.data.id,{netOpen:O?_o.enable:_o.disable}),this.data.netOpen=O,zi.log("data:updated",this.data),this.event.emit("data:updated",this.data),this.event.emit("data:updated:netOpen",{netOpen:O}),O})}getService(){return dc(Mi.configuration.apiRoot,this.token,(O,L)=>{const Y=new Error($i.DataRequestFailed);zi.error(Y),this.event.emit("error",Y)})}addEventListener(O,L,Y=!1){if(typeof L!="function")throw Error("event listener is not a function");if(Y){this.event.once(O,L);return}this.event.on(O,L)}removeEventListener(O,L){this.event.off(O,L)}fetchMessages(){return Le(this,arguments,void 0,function*(O={}){var L,Y;const ut={pageSize:this._loadingMessagesSize};if(this._id){O=Object.assign(Object.assign({},ut),O),this.event.emit("history:loading"),zi.log("history:loading"),(O.endTime||O.startTime)&&(this.event.emit("history:moreloading",O),zi.log("history:moreloading",O)),this._loadingMessages=!0;const ht=yield this.cvforceApi.getChatHistorySessionId(this._applicationId,this._id,O),W=ht.map((y,x)=>{var v,m;let S=[],a;return typeof((v=y.agentHistoryList)===null||v===void 0?void 0:v.agentList)=="string"&&(S=JSON.parse(y.agentHistoryList.agentList).reduce((c,l)=>(c[l.data.step-1]||(c[l.data.step-1]=[]),c[l.data.step-1].push(l),c),[])),x===ht.length-1&&(a=(m=this.data)===null||m===void 0?void 0:m.lastRelatedQuestion),Object.assign(Object.assign({},y),{actions:S,relatedQuesion:a})});if(!O.endTime&&!O.startTime){const y=this.messages[this.messages.length-1];y&&!y.relatedQuesion&&(y.relatedQuesion=(L=this.data)===null||L===void 0?void 0:L.lastRelatedQuestion),this.messages=[...W,...this.messages]}else if(O.endTime&&!O.startTime){const y=this.messages.findIndex(x=>x.ts===O.endTime);this.messages.splice(0,y+1),this.messages=[...W,...this.messages]}else if(!O.endTime&&O.startTime){const y=this.messages.findLastIndex(x=>x.ts===O.endTime);this.messages.splice(y,this.messages.length-y-1),this.messages=[...this.messages,...W]}else{const y=this.messages.findIndex(v=>v.ts===O.endTime),x=this.messages.findLastIndex(v=>v.ts===O.endTime);this.messages.splice(y,x-y+1,...W)}const _=this.messages[this.messages.length-1];return _&&!_.relatedQuesion&&(_.relatedQuesion=(Y=this.data)===null||Y===void 0?void 0:Y.lastRelatedQuestion),this.event.emit("history:moreloaded",W),zi.log("history:loaded",this.messages),this.event.emit("history:loaded",this.messages),this._loadingMessages=!1,W}else{const ht=new Error($i.IdUndefined);return zi.error(ht),this.event.emit("error",ht),!1}})}rename(O){return Le(this,void 0,void 0,function*(){if(!this._id)throw Error("session is not created yet");if(O.trim()==="")throw Error("name is empty");return this.data=yield this.cvforceApi.patchSessionsId(this.applicationId,this._id,{name:O}),zi.log("data:updated",this.messages),this.event.emit("data:updated",this.data),this.event.emit("data:updated:name",{name:O}),!0})}pushMessage(O){return Le(this,void 0,void 0,function*(){this.messages.push(O),zi.log("history:add",O),this.event.emit("history:add",O),this.event.emit("message:new",O),this.event.emit("message:updated",O)})}reloadSessionInfo(){if(!this._id)throw Error("session is not created yet");return this._dataLoading=!0,this.cvforceApi.getSession(this.applicationId,this._id).then(O=>Le(this,void 0,void 0,function*(){if(this.data=O,!this._id)throw Error("session is not created yet");return this._promptVariables=yield this.cvforceApi.getApplicationIdSessionIdPromptVariables(this.applicationId,this._id),zi.log("data:updated",this.data),this.event.emit("data:updated",this.data),this.data})).then(()=>Le(this,void 0,void 0,function*(){return this.messages=[],yield this.fetchMessages(),this._dataLoading=!1,this._dataLoaded=!0,this.event.emit("data:loaded",this.data),this}))}reload(){return Le(this,void 0,void 0,function*(){return yield this.reloadSessionInfo(),this.socket?(this.inactivate(!0),this.activate()):(this.inactivate(!0),this.activate())})}delete(){return Le(this,void 0,void 0,function*(){if(!this.id){const O=new Error($i.IdUndefined);return zi.error(O),this.event.emit("error",O),!1}return this.event.emit("data:deleting"),yield this.cvforceApi.delSessionsId(this.applicationId,this.id),this.event.emit("data:deleted"),this.destroy()})}activate(){return Le(this,void 0,void 0,function*(){if(this.activing)return new Promise(L=>{this.addEventListener("activated",()=>{L(!0)},!0)});if(!this._id)throw Error("session is not avalible. id is undefined");this.activing=!0;const O=this._id;return this._dataLoading=!0,this._dataLoaded=!1,this.data=yield this.cvforceApi.getSession(this.applicationId,O).then(L=>Le(this,void 0,void 0,function*(){return this._promptVariables=yield this.cvforceApi.getApplicationIdSessionIdPromptVariables(this.applicationId,O),L})),this.messages.length||(this.messages=[],yield this.fetchMessages()),this.event.emit("data:loaded",this.data),this.event.emit("data:updated",this.data),this._dataLoaded=!0,this._dataLoading=!1,this.inactivating=!1,this.frozen=!0,yield this.prepareConnection(),this.event.emit("activated",this.socket),this.active=!0,this.activing=!1,this})}inactivate(O=!1){return this.socket?this._frozen?(O||(this.inactivating=!0),this.activing=!1,!0):(this.socket.close(),this.socket=null,this.event.emit("inactivated"),this.active=!1,this.activing=!1,!0):(this.activing=!1,!0)}get dataLoaded(){return this._dataLoaded}get messagesLoading(){return this._loadingMessages}send(O){return Le(this,arguments,void 0,function*(L,Y={stream:!1}){var ut;try{this.validateConfigs()}catch(a){console.error(a)}const{stream:ht=!1,referenceFirst:W=!1}=Y,_=L.uuid||qc(),y=((ut=L.text)===null||ut===void 0?void 0:ut.trim())||"",x=L.fileIds;if(!y&&!(x!=null&&x.length)){const a=new Error($i.SendingEmptyContent);return zi.error(a),this.event.emit("error",a),!1}if(!this._id){const a=new Error($i.IdUndefined);return zi.error(a),this.event.emit("error",a),!1}if(this.frozen){const a=new Error($i.Frozen);return zi.error(a),this.event.emit("error",a),!1}this.frozen=!0,this._stopAnswer=!1;const v={sessionId:this.id,role:2,content:y,messageId:_,reference:[],searchReference:[],messageTime:""},m={content:y,stream:ht,requestId:_,fileIds:x,referenceFirst:W};this.pushMessage(v),this.event.emit("question:content",y);const S=a=>Le(this,void 0,void 0,function*(){if(a.role!==vr.Robot)return;switch(this.removeEventListener("answer:finish",S),this._id&&a.content&&a.index&&a.index<0&&(this.data=yield this.cvforceApi.patchSessionsId(this.applicationId,this._id,{finialMessage:a.content}),this.event.emit("data:updated",this.data),this.event.emit("data:updated:finialMessage",{finialMessage:a.content})),yield this.fillMessageReference(a),a.code){case 11915:a.content="请您换个问题问我吧~",a.index=-1,a.isSensitive=!0,a.isLoading=!1,a.sessionId=this._id||"",this.event.emit("message:error",a);break;case 200:a.index=-1,a.isLoading=!1;break;default:a.content=a.message||"未知错误",a.isLoading=!1,a.index=-1,this.event.emit("message:error",a)}const p=yield this.getRelatedQuesion(a);a=Object.assign(Object.assign({},a),p),a.isLoading=!1;let c=this.messages[this.messages.length-1];if(c&&c.role===vr.Robot){const l=Object.assign(Object.assign({},c),a);this.messages[this.messages.length-1]=l,this.event.emit("message:updated",l)}else this.pushMessage(a);this.frozen=!1});return this.addEventListener("answer:finish",S),this.sendQuestion(m,Object.assign(Object.assign({},Y),{stream:ht,referenceFirst:W})),v})}getRelatedQuesion(O){return Le(this,void 0,void 0,function*(){var L;if(!O.content||O.isSensitive||O.code!==200)return O;this.event.emit("message:relatedQuesion:loading",O);const Y=yield this.cvforceApi.postGeneques({content:O.content}).catch(W=>null);if(!Y){const W=[],_=Object.assign(Object.assign({},O),{relatedQuesion:W,index:-3,isLoading:!1});return this.event.emit("message:relatedQuesion:loaded",{relatedQuesion:W}),_}const ut=(L=Y.content)===null||L===void 0?void 0:L.split("*").map(uf).map(cf).filter(W=>!!W);O.relatedQuesion=ut,O.index=-3,O.isLoading=!1;const ht=Object.assign(Object.assign({},O),{relatedQuesion:ut,index:-3,isLoading:!1});return this.event.emit("message:relatedQuesion:loaded",ht),this._id&&this.cvforceApi.patchSessionsId(this._applicationId,this._id,{lastRelatedQuestion:ut}),ht})}fillMessageReference(O){return Le(this,void 0,void 0,function*(){var L;return(L=O.reference)===null||L===void 0||L.forEach((Y,ut)=>Le(this,void 0,void 0,function*(){const ht=yield this.cvforceApi.getKnowledgeIdFileId(Y.knowledgeId,Y.docId);O.reference[ut]=Object.assign(Object.assign({},Y),ht)})),O})}answerAgain(){return Le(this,arguments,void 0,function*(O={stream:!1}){const L=this.messages[this.messages.length-1];if(!L)throw Error("message list is empty");this.frozen=!0,this._stopAnswer=!1;const{stream:Y=!1}=O;let ut;L.role!==vr.User&&(ut=O.oldMessageId||L.messageId,this.messages.splice(this.messages.length-1,1),this.event.emit("message:remove",L),this.event.emit("history:remove",L));const ht=this.messages[this.messages.length-1],W={content:ht.content,fileIds:ht.fileIds,requestId:ht.messageId,stream:Y,oldMessageId:ut},_=y=>Le(this,void 0,void 0,function*(){if(y.role===vr.Robot&&y.index===-1){switch(this._id&&y.content&&y.index&&y.index<0&&(this.data=yield this.cvforceApi.patchSessionsId(this.applicationId,this._id,{finialMessage:y.content}),this.event.emit("data:updated",this.data),this.event.emit("data:updated:finialMessage",{finialMessage:y.content})),yield this.fillMessageReference(y),y.code){case 11915:y.content="请您换个问题问我吧~",y.index=-1,y.isSensitive=!0,y.isLoading=!1,y.sessionId=this._id||"",this.event.emit("message:error",y);break;case 200:y.index=-1,y.isLoading=!1;break;default:y.content=y.message||"未知错误",y.isLoading=!1,y.index=-1,this.event.emit("message:error",y)}const x=yield this.getRelatedQuesion(y);this.event.emit("message:updated",x),this.removeEventListener("message:content",_),this.frozen=!1}});this.addEventListener("message:content",_),this.sendQuestion(W,Object.assign(Object.assign({},O),{stream:Y}))})}setTop(O){return Le(this,void 0,void 0,function*(){if(!this._id)throw Error("session is not avalible. id is undefined");this.data=yield this.cvforceApi.patchSessionsId(this._applicationId,this._id,{top:O}),this.event.emit("data:updated",this.data),this.event.emit("data:updated:top",{top:O})})}suspend(){var O;this.stopAnswer(),this.frozen=!1,this._stopAnswer=!0;let L=this.messages[this.messages.length-1];const Y={messageId:qc(),isLoading:!1,index:-2,messageTime:hc(new Date).format("YYYY-MM-DD HH:ss:mm"),content:"",role:vr.System,sessionId:this.id||"",reference:[],searchReference:[]};if(L&&!L.messageId){if(L.index===-2)return;if(L.actions){const ut=L.actions[((O=L.actions)===null||O===void 0?void 0:O.length)-1];if(ut){const ht=ut[ut.length-1];if(ht&&(ht.type==="BEFORE_CALL"||ht.type==="FUNCTION_CALL")){const{pluginName:W,pluginCode:_,funcCode:y,funcName:x}=ht.data;ut.push({data:{pluginName:W,pluginCode:_,funcCode:y,funcName:x,step:ht.data.step+1},type:"ABORT"}),this.event.emit("message:action",{messageId:L.messageId,action:ut})}}}L=Object.assign(Object.assign({},L),Y),this.event.emit("message:content",L),this.event.emit("message:updated",L)}else this.pushMessage(Y),this.event.emit("message:content",Y);return this}postMessageComment(O){return Le(this,void 0,void 0,function*(){if(!this._applicationId||!this._id)throw Error("session is not avalible. id is undefined");return this.cvforceApi.postComments(this._applicationId,this._id,O).then(L=>{const Y=this.messages.find(ut=>ut.messageId===O.messageId);return Y&&(Y.comment=O,this.event.emit("message:comment",Y)),L})})}clear(){if(!this._id)throw Error("session is not avalible. id is undefined");return this.cvforceApi.patchApplicationIdSessionsIdContext(this._applicationId,this._id).then(()=>(this.event.emit("context:clear"),!0))}destroy(){var O;return this._ready=!1,this.event.removeAllListeners(),(O=this.socket)===null||O===void 0||O.disconnect(),this.socket=null,this.event.emit("destroy",{applicationId:this._applicationId,sessionId:this._id}),this._id||""}}const $r=new Pi("[AgentSession] ");class gd extends cs{constructor(O,L="",Y,ut,ht,W){super(O,L,Y,ut,ht,W)}prepareConnection(){return new Promise(O=>Le(this,void 0,void 0,function*(){this.socket&&O(!0);const L={version:"1.0",stream:"false",appId:this._applicationId,sessionId:this.id,Authorization:`${this.token}`,userMode:Mi.configuration.debug?nn.Debug:nn.Normal},Y=new URL(Mi.configuration.apiRoot),ut=yield Mo(Y.origin,{path:Y.pathname.replace("api","socketio")+"/copilot",query:L,transports:["websocket"]});ut.on("connect",()=>{$r.log("socket:connect"),this.event.emit("socket:connect"),ut.emit("init")}),ut.on("disconnect",()=>{$r.log("socket:disconnect"),this.event.emit("socket:disconnect")}),ut.on("ready",ht=>{if(ht.code===200){$r.log("ready");const W=Mi.configuration.debug?nn.Debug:nn.Normal;W===nn.Debug&&ht.userMode,this._ready||(this._ready=!0,this.event.emit("ready")),this.frozen=!1,O(!0)}else{this._ready&&(this._ready=!1);const W=new Error($i.SocketConnectionFailed);$r.error("error",W),this.event.emit("error",W),O(!1)}}),ut.on("action",(ht,W)=>Le(this,void 0,void 0,function*(){if(this._stopAnswer||!this.id)return;const{type:_,data:{runnerIsClient:y,pluginCode:x,funcCode:v,parameters:m,requestBody:S}}=ht,a=this.messages[this.messages.length-1];if(!a.messageId)a.actions||(a.actions=[]),a.actions[ht.data.step-1]||(a.actions[ht.data.step-1]=[]),a.actions[ht.data.step-1].push(ht),this.event.emit("message:action",{messageId:a.messageId,action:ht}),this.event.emit("message:updated",a);else{const p={messageId:"",content:"",role:vr.Robot,sessionId:this.id,reference:[],searchReference:[],isLoading:!0,messageTime:"",actions:[[ht]],comment:{isAgree:0}};this.pushMessage(p),this.event.emit("message:action",{messageId:p.messageId,action:ht})}if(this.inactivating){const p=new Error($i.Inactive);$r.warn("error",p),this.event.emit("error",p)}else if(_==="FUNCTION_CALL"&&y){if($r.log(`calling function ${v} of plugin ${x} with argument:
|
|
138
138
|
${JSON.stringify(m)}`),!Mi.configuration.plugins[x]){W({code:404,message:"对不起,没有找到插件。"});return}const p=Mi.configuration.plugins[x][v];typeof p!="function"&&W({code:404,message:"对不起,没有找到插件方法。"});let c=m==null?void 0:m.query;try{c=JSON.parse(m==null?void 0:m.query)}catch{}p(c,(...l)=>{this._stopAnswer||W(...l)})}})),ut.on("answer",ht=>{if(!this._stopAnswer)if(ht.data.code!==200&&(ht.data.index=-1,this.event.emit("error",ht.data)),ht.data.index===-1){let W=this.messages[this.messages.length-1];if(W&&!W.messageId)W=Object.assign(Object.assign({},W),ht.data),this.event.emit("message:content",W),this.event.emit("message:updated",W),this.event.emit("answer:finish",W);else{const _=Object.assign({messageId:"",content:"",role:vr.Robot,sessionId:this.id,reference:[],searchReference:[],isLoading:!1,messageTime:"",actions:[],comment:{isAgree:0}},ht.data);this.event.emit("message:content",_),this.pushMessage(_),this.event.emit("answer:finish",_)}}else{let W=this.messages[this.messages.length-1];W&&!W.messageId?(W=Object.assign(Object.assign({},W),ht.data),this.messages[this.messages.length-1]=W,this.event.emit("message:content",W),this.event.emit("message:updated",W)):(this.pushMessage(ht.data),this.event.emit("message:content",ht.data))}}),ut.on("reference",ht=>Le(this,void 0,void 0,function*(){if(this._stopAnswer)return;if(!this.id){const m=new Error($i.IdUndefined);$r.error(m),this.event.emit("error",m),this.frozen=!1;return}const{type:W,data:_,requestId:y}=ht,x=this.messages.findIndex(m=>m.messageId===y&&m.role===vr.User);if(x<0)return;const v=x+1;if(v>=this.messages.length){const m={messageId:"",content:"",role:vr.Robot,sessionId:this.id,reference:[],searchReference:[],isLoading:!0,messageTime:"",actions:[],comment:{isAgree:0}};this.pushMessage(m)}W==="KG"?(this.messages[v]=Object.assign(Object.assign({},this.messages[v]),{reference:_.knowledgeReference}),yield this.fillMessageReference(this.messages[v]),this.event.emit("message:reference",_.knowledgeReference),this.event.emit("message:updated",this.messages[v])):W==="WEB_SEARCH"&&(this.messages[v]=Object.assign(Object.assign({},this.messages[v]),{searchReference:_.knowledgeReference}),this.event.emit("message:searchreference",_.searchReference),this.event.emit("message:updated",this.messages[v]))})),this.socket=ut,ut.open()}))}sendQuestion(O,L){return Le(this,void 0,void 0,function*(){var Y,ut;if(!this.active){if(yield this.activate(),!this.socket){const ht=new Error($i.SocketConnectionFailed);return $r.warn("error",ht),this.event.emit("error",ht),!1}(Y=this.socket)===null||Y===void 0||Y.emit("question",O);return}(ut=this.socket)===null||ut===void 0||ut.emit("question",O)})}stopAnswer(){var O;(O=this.socket)===null||O===void 0||O.emit("stop_answer")}}function vd(K,O){return Le(this,void 0,void 0,function*(){const L=K.getReader();let Y;for(;!(Y=yield L.read()).done;)O(Y.value)})}var br;(function(K){K[K.NewLine=10]="NewLine",K[K.CarriageReturn=13]="CarriageReturn",K[K.Space=32]="Space",K[K.Colon=58]="Colon"})(br||(br={}));function yd(K){let O,L,Y,ut=!1,ht;return function(_){O===void 0?(O=_,L=0,Y=-1,ht=!1):O=wd(O,_);const y=O.length;let x=0;for(;L<y;){ut&&(O[L]===br.NewLine&&(x=++L),ut=!1);let v=-1;for(;L<y&&v===-1;++L)switch(O[L]){case br.Colon:Y===-1&&(Y=L-x);break;case br.CarriageReturn:ut=!1,L+4<y&&O[L+1]===br.NewLine&&O[L+2]!==br.CarriageReturn&&O[L-1]!==br.NewLine&&O[L-2]!==br.CarriageReturn&&(ht=!0);case br.NewLine:v=L;break}if(v===-1)break;K(O.subarray(x,v),Y,ht),x=L,Y=-1,ht=!1}x===y?O=void 0:x!==0&&(O=O.subarray(x),L-=x)}}function bd(K,O,L){let Y=zc();const ut=new TextDecoder;return function(W,_,y){if(W.length===0)L==null||L(Y),Y=zc();else if(_>0){const x=ut.decode(W.subarray(0,_)),v=_+(W[_+1]===br.Space?2:1);let m=ut.decode(W.subarray(v));switch(y&&(m+=`
|
|
139
139
|
`),x){case"data":Y.data=Y.data?Y.data+`
|
|
140
140
|
`+m:m;break;case"event":Y.event=m;break;case"id":K(Y.id=m);break;case"retry":const S=parseInt(m,10);isNaN(S)||O(Y.retry=S);break}}}}function wd(K,O){const L=new Uint8Array(K.length+O.length);return L.set(K),L.set(O,K.length),L}function zc(){return{data:"",event:"",id:"",retry:void 0}}const ls="text/event-stream",Md=1e3,$c="last-event-id";function Hc(K,O){var{signal:L,headers:Y,onopen:ut,onmessage:ht,onclose:W,onerror:_,openWhenHidden:y,fetch:x}=O,v=Kh(O,["signal","headers","onopen","onmessage","onclose","onerror","openWhenHidden","fetch"]);return new Promise((m,S)=>{const a=Object.assign({},Y);a.accept||(a.accept=ls);let p;function c(){p.abort(),document.hidden||w()}y||document.addEventListener("visibilitychange",c);let l=Md,f=0;function g(){document.removeEventListener("visibilitychange",c),window.clearTimeout(f),p.abort()}L==null||L.addEventListener("abort",()=>{g(),m()});const h=x??window.fetch,u=ut??xd;function w(){return Le(this,void 0,void 0,function*(){var b;p=new AbortController;try{const E=yield h(K,Object.assign(Object.assign({},v),{headers:a,signal:p.signal}));yield u(E),yield vd(E.body,yd(bd(I=>{I?a[$c]=I:delete a[$c]},I=>{l=I},ht))),W==null||W(),g(),m()}catch(E){if(!p.signal.aborted)try{const I=(b=_==null?void 0:_(E))!==null&&b!==void 0?b:l;window.clearTimeout(f),f=window.setTimeout(w,I)}catch(I){g(),S(I)}}})}w()})}function xd(K){const O=K.headers.get("content-type");if(!(O!=null&&O.startsWith(ls)))throw new Error(`Expected content-type to be ${ls}, Actual: ${O}`)}const Wc=new Pi("[DialogSession] ");class _d extends cs{constructor(O,L="",Y,ut,ht,W){super(O,L,Y,ut,ht,W),Object.defineProperty(this,"ctrl",{enumerable:!0,configurable:!0,writable:!0,value:new AbortController})}prepareConnection(){return new Promise(O=>Le(this,void 0,void 0,function*(){this._ready=!0,this.event.emit("ready"),this.frozen=!1,O(!0)}))}postChatV2EventSource(O,L,Y,ut,ht,W){return Le(this,void 0,void 0,function*(){const _={code:0,content:"",role:Wa.Robot,sessionId:L,reference:[],searchReference:[],messageTime:"",llmModel:"",comment:{isAgree:0},isReplying:!1},y=Object.assign(Object.assign({},Y),{stream:!0});Hc(`${Mi.configuration.apiRoot}/chat/v2/chat?applicationId=${O}&sessionId=${L}`,{method:"POST",headers:{Authorization:`Bearer ${this.token}`,"Content-Type":"application/json"},body:JSON.stringify(y),openWhenHidden:!0,signal:ut,onopen(x){return x.ok&&ht!=null&&ht.onopen&&ht.onopen(),Promise.resolve()},onmessage(x){if(!x.data.includes('{"code": ')){let m={};try{m=JSON.parse(x.data)}catch{}(m==null?void 0:m.mtype)==="search"?_.searchReference.push(m):_.content=_.content+x.data;const S={content:_.content,role:1,reference:_.reference,searchReference:_.searchReference,messageId:_.messageId,sessionId:L,messageTime:hc(new Date).format("YYYY-MM-DD HH:mm:ss"),comment:{isAgree:0},isReplying:!0};return(ht==null?void 0:ht.onmessage)&&ht.onmessage(S)}const v=JSON.parse(x.data);if(_.reference=v.data.reference,_.searchReference=v.data.searchReference,_.messageTime=v.data.messageTime,_.messageId=v.data.messageId,_.llmModel=v.data.llmModel,_.content=v.data.content,_.code=v.code,v.code===200){const m={code:_.code,content:_.content,role:1,reference:_.reference,searchReference:_.searchReference,messageId:_.messageId,sessionId:L,messageTime:_.messageTime,isReplying:!0};ht!=null&&ht.onmessage&&ht.onmessage(m)}else return ht!=null&&ht.onclose&&ht.onclose(_),W&&W({code:_.code,message:_.message})},onerror(){ht!=null&&ht.onerror&&ht.onerror()},onclose(){const x={code:_.code,content:_.content,role:1,reference:_.reference,searchReference:_.searchReference,messageId:_.messageId,sessionId:L,messageTime:_.messageTime,comment:{isAgree:0},isReplying:!1,index:-1};ht!=null&&ht.onclose&&ht.onclose(x)}})})}postChatV3EventSource(O,L,Y,ut,ht,W){return Le(this,void 0,void 0,function*(){const _={code:0,content:"",role:Wa.Robot,sessionId:L,reference:[],searchReference:[],messageTime:"",llmModel:"",comment:{isAgree:0},isReplying:!1,reasoningContent:"",thinkingSecs:"",thinkingStatus:""},y=Object.assign(Object.assign({},Y),{stream:!0});Hc(`${Mi.configuration.apiRoot}/chat/v3/chat?applicationId=${O}&sessionId=${L}`,{method:"POST",headers:{Authorization:`Bearer ${this.token}`,"Content-Type":"application/json"},body:JSON.stringify(y),openWhenHidden:!0,signal:ut,onopen(x){return x.ok&&ht!=null&&ht.onopen&&ht.onopen(),Promise.resolve()},onmessage(x){if(!x.data&&!x.event&&!x.id&&!x.retry)return;let v={};try{v=JSON.parse(x.data)}catch{console.error("parse eventData to JSON failed. ",x.data)}if(v.code!==200)return _.index=-1,_.code=v.code,_.message=v.message,ht!=null&&ht.onmessage&&ht.onmessage(_),W&&W({code:v.code,message:v.message});const m=v.data.type,S=v.data.payload;if(_.isReplying=!0,m==="search"&&_.searchReference.push(S),m==="thinking"){_.thinkingStatus="start";const p=S.choices[0];_.reasoningContent=_.reasoningContent+p.delta.reasoningContent}if(m==="thinkingOver"){_.thinkingStatus="end";const a=S.thinkingSecs;_.thinkingSecs=a}if(m==="text"){const p=S.choices[0];_.content=_.content+p.delta.content}if(m==="reference"&&(_.reference=S),m==="result"){const a=S.messageId,p=S.llmModel,c=S.messageTime;_.messageId=a,_.llmModel=p,_.messageTime=c,_.sessionId=L}m==="over"?_.index=-1:(_.code=v.code,_.message=v.message),ht!=null&&ht.onmessage&&ht.onmessage(_)},onerror(){ht!=null&&ht.onerror&&ht.onerror()},onclose(){const x=Object.assign(Object.assign({},_),{isReplying:!1});ht!=null&&ht.onclose&&ht.onclose(x)}})})}sendQuestion(O,L){return Le(this,void 0,void 0,function*(){var Y;const{content:ut,fileIds:ht,oldMessageId:W}=O,{stream:_,referenceFirst:y}=L;if(this.active||(yield this.activate()),this._id){let x={content:ut,fileIds:ht,referenceFirst:y,oldMessageId:W,promptVariables:this.promptVariables.reduce((v,m)=>Object.assign(Object.assign({},v),{[m.key]:m.value}),{}),knowledges:(Y=this.knowledges)===null||Y===void 0?void 0:Y.map(v=>v.id)};this.ctrl=new AbortController,this.postChatV3EventSource(this._applicationId,this._id,x,this.ctrl.signal,{onopen:()=>{Wc.log("open",this.ctrl)},onmessage:v=>{if(this._stopAnswer)return;let m=this.messages[this.messages.length-1];m&&m.role===vr.Robot?(m=Object.assign(Object.assign({},m),v),this.messages[this.messages.length-1]=m,this.event.emit("message:content",m),this.event.emit("message:updated",m)):(this.pushMessage(v),this.event.emit("message:content",v))},onclose:v=>Le(this,void 0,void 0,function*(){this._stopAnswer||(Wc.log(v,"onclose"),this.event.emit("answer:finish",v))}),onerror:()=>{this._stopAnswer||(this.event.emit("message:error",""),this.frozen=!1)}})}})}stopAnswer(){this.ctrl.abort()}}const Sd=new Pi("[BotClient] ");class Ed{constructor(O,L,Y=!0){if(Object.defineProperty(this,"_token",{enumerable:!0,configurable:!0,writable:!0,value:O}),Object.defineProperty(this,"lazyload",{enumerable:!0,configurable:!0,writable:!0,value:Y}),Object.defineProperty(this,"event",{enumerable:!0,configurable:!0,writable:!0,value:new Fc}),Object.defineProperty(this,"cvforceApi",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_applicationId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_application",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_sessions",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_activeSession",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_ready",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_questionContextMaxLength",{enumerable:!0,configurable:!0,writable:!0,value:4e3}),Object.defineProperty(this,"_promptVariables",{enumerable:!0,configurable:!0,writable:!0,value:[]}),yu(L),this._applicationId=oo(O).rid||Mi.configuration.applicationId,!this._applicationId)throw"token is not vaild";this.cvforceApi=this.getService(),this.loadApplication().then(()=>{this.event.emit("ready")})}checkReady(){if(!this.ready)throw Error("client is not ready.")}get ready(){return this._ready}set ready(O){this._ready=O}get questionContextMaxLength(){return this.checkReady(),this._questionContextMaxLength}get promptVariables(){return this.checkReady(),this._promptVariables}get knowledges(){var O;return this.checkReady(),(O=this._application)===null||O===void 0?void 0:O.arrange[0].knowledges}get sessions(){return this.checkReady(),this._sessions}set sessions(O){this.checkReady(),this._sessions=O,this.event.emit("sessions:updated",O)}loadApplication(){return Le(this,void 0,void 0,function*(){var O,L;this._application=yield this.cvforceApi.getApplicationId(this._applicationId);const Y=(L=(O=this._application.arrange)===null||O===void 0?void 0:O[0])===null||L===void 0?void 0:L.llmModel;return Y&&(this._questionContextMaxLength=yield this.cvforceApi.getBaseModel(Y).then(ut=>ut.maxModelLength)),this._promptVariables=yield this.cvforceApi.getPrompts(this._applicationId),this._ready=!0,this.event.emit("application:loaded"),this._application})}getService(){return this.cvforceApi?this.cvforceApi:dc(Mi.configuration.apiRoot,this.token,(O,L)=>Sd.error(L))}get token(){return this._token}set token(O){this.checkReady(),this._token=O,this.ready=!1;const L=oo(O).rid;this._applicationId!==L&&(this._applicationId=L,this._application=null,this.loadApplication().then(()=>{this.event.emit("ready")}),this.clean())}get applicationId(){return this._applicationId}get application(){return this.checkReady(),this._application}get activeSession(){var O;return this.checkReady(),((O=this._activeSession)===null||O===void 0?void 0:O.id)||""}set activeSession(O){this.checkReady(),this.loadSession(O).then(L=>{this._activeSession&&this._activeSession.id!==O&&this._activeSession.inactivate(),this._activeSession=L})}createSession(O,L,Y,ut,ht){return Le(this,void 0,void 0,function*(){const W=this;return new Promise((_,y)=>{const x=v=>Le(this,void 0,void 0,function*(){if(v===bn.Agent)_(new gd(O,L,Y,ut,ht,W));else if(v===bn.Dialog)_(new _d(O,L,Y,ut,ht,W));else throw Error(`不支持的应用类型:${v}`)});if(this.ready){if(!this._application)throw Error("client is not ready");x(this._application.type)}else this.event.on("ready",()=>{if(!this._application)throw Error("_application is null");x(this._application.type)},!0)})})}getSessions(O){return Le(this,void 0,void 0,function*(){return new Promise((L,Y)=>{const ut=()=>this.cvforceApi.listSessions(this._applicationId,O).then(ht=>{const W=[];return ht.forEach(_=>Le(this,void 0,void 0,function*(){const y=this._sessions.find(x=>_.id===x.id);if(y)y.data=_,W.push(y);else{const x=yield this.createSession(this.token,_.id,_,this.lazyload,this._application||void 0);W.push(x)}})),this.sessions=W,W});if(this.ready){if(!this._application)throw Error("_application is null");L(ut())}else this.event.on("ready",()=>{if(!this._application)throw Error("_application is null");L(ut())},!0)})})}loadSession(){return Le(this,arguments,void 0,function*(O="",L){this.checkReady();let Y=this.sessions.find(ut=>ut.id===O);if(Y||(Y=yield this.createSession(this.token,O,L),this._sessions.push(Y)),this._activeSession){if(this._activeSession===Y)return Y;this._activeSession.inactivate()}return Y.id?(yield Y.activate(),this._activeSession=Y):Y.addEventListener("data:loaded",()=>{this._activeSession!==Y&&(Y==null||Y.activate(),this._activeSession=Y)},!0),Y})}reload(){return this.loadApplication().then(()=>Le(this,void 0,void 0,function*(){return yield this.getSessions(),this.event.emit("ready"),this}))}reloadSession(O){return Le(this,void 0,void 0,function*(){yield this.reload();let L=this._sessions.find(Y=>Y.id===O)||this._activeSession;if(!L){console.warn("reloadSession session failed.");return}return yield L.reload(),L})}setTop(O,L){return Le(this,arguments,void 0,function*(Y,ut,ht="top_time desc, sort_status desc, updated_at desc"){let W=Y?this._sessions.find(_=>_.id===Y):this._activeSession;if(!W){console.warn("setTop session failed.");return}return yield W.setTop(ut),this.getSessions({order:ht})})}addEventListener(O,L,Y=!1){if(typeof L!="function")throw Error("event listener is not a function");if(Y){this.event.once(O,L);return}this.event.on(O,L)}removeEventListener(O,L){this.event.off(O,L)}removeSession(O,L){return Le(this,void 0,void 0,function*(){this.checkReady();let Y=-1;if(typeof O=="string"?Y=this._sessions.findIndex(ut=>ut.id===O):Y=this._sessions.findIndex(ut=>ut.id===O.id),Y>-1){const ut=this._sessions[Y];L&&(yield ut.delete()),this._sessions.splice(Y,1)}else console.warn("session delete failed, session is not exist.")})}clean(){this._sessions.forEach(O=>O.destroy()),this.sessions=[]}}class kd{constructor(O,L={},Y){Object.defineProperty(this,"code",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"description",{enumerable:!0,configurable:!0,writable:!0,value:""}),Object.defineProperty(this,"loaded",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"functions",{enumerable:!0,configurable:!0,writable:!0,value:{}}),this.code=O,L&&(this.functions=L)}fetchData(){this.description="描述",this.loaded=!0}checkFunctions(){}}Mi.AgentPlugin=kd,Mi.BotClient=Ed,Mi.Session=cs,Mi.configure=yu,Object.defineProperty(Mi,Symbol.toStringTag,{value:"Module"})});
|
package/dist/src/Session.d.ts
CHANGED
|
@@ -163,6 +163,7 @@ export default abstract class Session {
|
|
|
163
163
|
abstract sendQuestion(params: QuestionBody, configs: QuestionConfig): any;
|
|
164
164
|
abstract stopAnswer(): any;
|
|
165
165
|
get dataLoaded(): boolean;
|
|
166
|
+
get messagesLoading(): boolean;
|
|
166
167
|
send(params: {
|
|
167
168
|
text?: string;
|
|
168
169
|
uuid?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@glodon-aiot/agent-cli-sdk",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.7-beta.0",
|
|
4
4
|
"author": "glodoncv",
|
|
5
5
|
"description": "aiot agent client js sdk",
|
|
6
6
|
"type": "module",
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"registry": "https://registry.npmjs.org/"
|
|
82
82
|
},
|
|
83
83
|
"dependencies": {
|
|
84
|
-
"@glodon-aiot/apis": "^3.0.
|
|
84
|
+
"@glodon-aiot/apis": "^3.0.7-beta.0",
|
|
85
85
|
"axios": "0.24.0",
|
|
86
86
|
"buffer": "^6.0.3",
|
|
87
87
|
"dayjs": "^1.11.13",
|