joytalk 0.0.16 → 0.0.17
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/index.cjs.js +6 -6
- package/dist/index.d.ts +1 -0
- package/dist/index.es.js +920 -897
- package/dist/index.umd.js +6 -6
- package/dist/lib/index.d.ts +2 -0
- package/dist/types/index.d.ts +13 -0
- package/dist/types/message.d.ts +5 -3
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});function Ze(e,t){return function(){return e.apply(t,arguments)}}const{toString:At}=Object.prototype,{getPrototypeOf:Ce}=Object,{iterator:he,toStringTag:et}=Symbol,pe=(e=>t=>{const n=At.call(t);return e[n]||(e[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),F=e=>(e=e.toLowerCase(),t=>pe(t)===e),me=e=>t=>typeof t===e,{isArray:V}=Array,W=me("undefined");function Z(e){return e!==null&&!W(e)&&e.constructor!==null&&!W(e.constructor)&&N(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const tt=F("ArrayBuffer");function gt(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&tt(e.buffer),t}const Nt=me("string"),N=me("function"),nt=me("number"),ee=e=>e!==null&&typeof e=="object",Ct=e=>e===!0||e===!1,ae=e=>{if(pe(e)!=="object")return!1;const t=Ce(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(et in e)&&!(he in e)},Ut=e=>{if(!ee(e)||Z(e))return!1;try{return Object.keys(e).length===0&&Object.getPrototypeOf(e)===Object.prototype}catch{return!1}},_t=F("Date"),Dt=F("File"),It=F("Blob"),Ft=F("FileList"),Lt=e=>ee(e)&&N(e.pipe),xt=e=>{let t;return e&&(typeof FormData=="function"&&e instanceof FormData||N(e.append)&&((t=pe(e))==="formdata"||t==="object"&&N(e.toString)&&e.toString()==="[object FormData]"))},Pt=F("URLSearchParams"),[kt,Bt,jt,Ht]=["ReadableStream","Request","Response","Headers"].map(F),vt=e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function te(e,t,{allOwnKeys:n=!1}={}){if(e===null||typeof e>"u")return;let s,r;if(typeof e!="object"&&(e=[e]),V(e))for(s=0,r=e.length;s<r;s++)t.call(null,e[s],s,e);else{if(Z(e))return;const o=n?Object.getOwnPropertyNames(e):Object.keys(e),i=o.length;let c;for(s=0;s<i;s++)c=o[s],t.call(null,e[c],c,e)}}function st(e,t){if(Z(e))return null;t=t.toLowerCase();const n=Object.keys(e);let s=n.length,r;for(;s-- >0;)if(r=n[s],t===r.toLowerCase())return r;return null}const q=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global,rt=e=>!W(e)&&e!==q;function Oe(){const{caseless:e,skipUndefined:t}=rt(this)&&this||{},n={},s=(r,o)=>{const i=e&&st(n,o)||o;ae(n[i])&&ae(r)?n[i]=Oe(n[i],r):ae(r)?n[i]=Oe({},r):V(r)?n[i]=r.slice():(!t||!W(r))&&(n[i]=r)};for(let r=0,o=arguments.length;r<o;r++)arguments[r]&&te(arguments[r],s);return n}const Mt=(e,t,n,{allOwnKeys:s}={})=>(te(t,(r,o)=>{n&&N(r)?e[o]=Ze(r,n):e[o]=r},{allOwnKeys:s}),e),qt=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),$t=(e,t,n,s)=>{e.prototype=Object.create(t.prototype,s),e.prototype.constructor=e,Object.defineProperty(e,"super",{value:t.prototype}),n&&Object.assign(e.prototype,n)},Jt=(e,t,n,s)=>{let r,o,i;const c={};if(t=t||{},e==null)return t;do{for(r=Object.getOwnPropertyNames(e),o=r.length;o-- >0;)i=r[o],(!s||s(i,e,t))&&!c[i]&&(t[i]=e[i],c[i]=!0);e=n!==!1&&Ce(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},zt=(e,t,n)=>{e=String(e),(n===void 0||n>e.length)&&(n=e.length),n-=t.length;const s=e.indexOf(t,n);return s!==-1&&s===n},Gt=e=>{if(!e)return null;if(V(e))return e;let t=e.length;if(!nt(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},Wt=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&Ce(Uint8Array)),Vt=(e,t)=>{const s=(e&&e[he]).call(e);let r;for(;(r=s.next())&&!r.done;){const o=r.value;t.call(e,o[0],o[1])}},Kt=(e,t)=>{let n;const s=[];for(;(n=e.exec(t))!==null;)s.push(n);return s},Xt=F("HTMLFormElement"),Qt=e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(n,s,r){return s.toUpperCase()+r}),Be=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),Yt=F("RegExp"),ot=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),s={};te(n,(r,o)=>{let i;(i=t(r,o,e))!==!1&&(s[o]=i||r)}),Object.defineProperties(e,s)},Zt=e=>{ot(e,(t,n)=>{if(N(e)&&["arguments","caller","callee"].indexOf(n)!==-1)return!1;const s=e[n];if(N(s)){if(t.enumerable=!1,"writable"in t){t.writable=!1;return}t.set||(t.set=()=>{throw Error("Can not rewrite read-only method '"+n+"'")})}})},en=(e,t)=>{const n={},s=r=>{r.forEach(o=>{n[o]=!0})};return V(e)?s(e):s(String(e).split(t)),n},tn=()=>{},nn=(e,t)=>e!=null&&Number.isFinite(e=+e)?e:t;function sn(e){return!!(e&&N(e.append)&&e[et]==="FormData"&&e[he])}const rn=e=>{const t=new Array(10),n=(s,r)=>{if(ee(s)){if(t.indexOf(s)>=0)return;if(Z(s))return s;if(!("toJSON"in s)){t[r]=s;const o=V(s)?[]:{};return te(s,(i,c)=>{const d=n(i,r+1);!W(d)&&(o[c]=d)}),t[r]=void 0,o}}return s};return n(e,0)},on=F("AsyncFunction"),an=e=>e&&(ee(e)||N(e))&&N(e.then)&&N(e.catch),it=((e,t)=>e?setImmediate:t?((n,s)=>(q.addEventListener("message",({source:r,data:o})=>{r===q&&o===n&&s.length&&s.shift()()},!1),r=>{s.push(r),q.postMessage(n,"*")}))(`axios@${Math.random()}`,[]):n=>setTimeout(n))(typeof setImmediate=="function",N(q.postMessage)),cn=typeof queueMicrotask<"u"?queueMicrotask.bind(q):typeof process<"u"&&process.nextTick||it,ln=e=>e!=null&&N(e[he]),a={isArray:V,isArrayBuffer:tt,isBuffer:Z,isFormData:xt,isArrayBufferView:gt,isString:Nt,isNumber:nt,isBoolean:Ct,isObject:ee,isPlainObject:ae,isEmptyObject:Ut,isReadableStream:kt,isRequest:Bt,isResponse:jt,isHeaders:Ht,isUndefined:W,isDate:_t,isFile:Dt,isBlob:It,isRegExp:Yt,isFunction:N,isStream:Lt,isURLSearchParams:Pt,isTypedArray:Wt,isFileList:Ft,forEach:te,merge:Oe,extend:Mt,trim:vt,stripBOM:qt,inherits:$t,toFlatObject:Jt,kindOf:pe,kindOfTest:F,endsWith:zt,toArray:Gt,forEachEntry:Vt,matchAll:Kt,isHTMLForm:Xt,hasOwnProperty:Be,hasOwnProp:Be,reduceDescriptors:ot,freezeMethods:Zt,toObjectSet:en,toCamelCase:Qt,noop:tn,toFiniteNumber:nn,findKey:st,global:q,isContextDefined:rt,isSpecCompliantForm:sn,toJSONObject:rn,isAsyncFn:on,isThenable:an,setImmediate:it,asap:cn,isIterable:ln};function E(e,t,n,s,r){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=new Error().stack,this.message=e,this.name="AxiosError",t&&(this.code=t),n&&(this.config=n),s&&(this.request=s),r&&(this.response=r,this.status=r.status?r.status:null)}a.inherits(E,Error,{toJSON:function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:a.toJSONObject(this.config),code:this.code,status:this.status}}});const at=E.prototype,ct={};["ERR_BAD_OPTION_VALUE","ERR_BAD_OPTION","ECONNABORTED","ETIMEDOUT","ERR_NETWORK","ERR_FR_TOO_MANY_REDIRECTS","ERR_DEPRECATED","ERR_BAD_RESPONSE","ERR_BAD_REQUEST","ERR_CANCELED","ERR_NOT_SUPPORT","ERR_INVALID_URL"].forEach(e=>{ct[e]={value:e}});Object.defineProperties(E,ct);Object.defineProperty(at,"isAxiosError",{value:!0});E.from=(e,t,n,s,r,o)=>{const i=Object.create(at);a.toFlatObject(e,i,function(l){return l!==Error.prototype},u=>u!=="isAxiosError");const c=e&&e.message?e.message:"Error",d=t==null&&e?e.code:t;return E.call(i,c,d,n,s,r),e&&i.cause==null&&Object.defineProperty(i,"cause",{value:e,configurable:!0}),i.name=e&&e.name||"Error",o&&Object.assign(i,o),i};const un=null;function Ae(e){return a.isPlainObject(e)||a.isArray(e)}function lt(e){return a.endsWith(e,"[]")?e.slice(0,-2):e}function je(e,t,n){return e?e.concat(t).map(function(r,o){return r=lt(r),!n&&o?"["+r+"]":r}).join(n?".":""):t}function fn(e){return a.isArray(e)&&!e.some(Ae)}const dn=a.toFlatObject(a,{},null,function(t){return/^is[A-Z]/.test(t)});function Ee(e,t,n){if(!a.isObject(e))throw new TypeError("target must be an object");t=t||new FormData,n=a.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,function(m,h){return!a.isUndefined(h[m])});const s=n.metaTokens,r=n.visitor||l,o=n.dots,i=n.indexes,d=(n.Blob||typeof Blob<"u"&&Blob)&&a.isSpecCompliantForm(t);if(!a.isFunction(r))throw new TypeError("visitor must be a function");function u(f){if(f===null)return"";if(a.isDate(f))return f.toISOString();if(a.isBoolean(f))return f.toString();if(!d&&a.isBlob(f))throw new E("Blob is not supported. Use a Buffer instead.");return a.isArrayBuffer(f)||a.isTypedArray(f)?d&&typeof Blob=="function"?new Blob([f]):Buffer.from(f):f}function l(f,m,h){let R=f;if(f&&!h&&typeof f=="object"){if(a.endsWith(m,"{}"))m=s?m:m.slice(0,-2),f=JSON.stringify(f);else if(a.isArray(f)&&fn(f)||(a.isFileList(f)||a.endsWith(m,"[]"))&&(R=a.toArray(f)))return m=lt(m),R.forEach(function(y,g){!(a.isUndefined(y)||y===null)&&t.append(i===!0?je([m],g,o):i===null?m:m+"[]",u(y))}),!1}return Ae(f)?!0:(t.append(je(h,m,o),u(f)),!1)}const p=[],S=Object.assign(dn,{defaultVisitor:l,convertValue:u,isVisitable:Ae});function w(f,m){if(!a.isUndefined(f)){if(p.indexOf(f)!==-1)throw Error("Circular reference detected in "+m.join("."));p.push(f),a.forEach(f,function(R,_){(!(a.isUndefined(R)||R===null)&&r.call(t,R,a.isString(_)?_.trim():_,m,S))===!0&&w(R,m?m.concat(_):[_])}),p.pop()}}if(!a.isObject(e))throw new TypeError("data must be an object");return w(e),t}function He(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(s){return t[s]})}function Ue(e,t){this._pairs=[],e&&Ee(e,this,t)}const ut=Ue.prototype;ut.append=function(t,n){this._pairs.push([t,n])};ut.toString=function(t){const n=t?function(s){return t.call(this,s,He)}:He;return this._pairs.map(function(r){return n(r[0])+"="+n(r[1])},"").join("&")};function hn(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+")}function ft(e,t,n){if(!t)return e;const s=n&&n.encode||hn;a.isFunction(n)&&(n={serialize:n});const r=n&&n.serialize;let o;if(r?o=r(t,n):o=a.isURLSearchParams(t)?t.toString():new Ue(t,n).toString(s),o){const i=e.indexOf("#");i!==-1&&(e=e.slice(0,i)),e+=(e.indexOf("?")===-1?"?":"&")+o}return e}class ve{constructor(){this.handlers=[]}use(t,n,s){return this.handlers.push({fulfilled:t,rejected:n,synchronous:s?s.synchronous:!1,runWhen:s?s.runWhen:null}),this.handlers.length-1}eject(t){this.handlers[t]&&(this.handlers[t]=null)}clear(){this.handlers&&(this.handlers=[])}forEach(t){a.forEach(this.handlers,function(s){s!==null&&t(s)})}}const dt={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},pn=typeof URLSearchParams<"u"?URLSearchParams:Ue,mn=typeof FormData<"u"?FormData:null,En=typeof Blob<"u"?Blob:null,Sn={isBrowser:!0,classes:{URLSearchParams:pn,FormData:mn,Blob:En},protocols:["http","https","file","blob","url","data"]},_e=typeof window<"u"&&typeof document<"u",ge=typeof navigator=="object"&&navigator||void 0,Tn=_e&&(!ge||["ReactNative","NativeScript","NS"].indexOf(ge.product)<0),Rn=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",yn=_e&&window.location.href||"http://localhost",wn=Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:_e,hasStandardBrowserEnv:Tn,hasStandardBrowserWebWorkerEnv:Rn,navigator:ge,origin:yn},Symbol.toStringTag,{value:"Module"})),O={...wn,...Sn};function bn(e,t){return Ee(e,new O.classes.URLSearchParams,{visitor:function(n,s,r,o){return O.isNode&&a.isBuffer(n)?(this.append(s,n.toString("base64")),!1):o.defaultVisitor.apply(this,arguments)},...t})}function On(e){return a.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function An(e){const t={},n=Object.keys(e);let s;const r=n.length;let o;for(s=0;s<r;s++)o=n[s],t[o]=e[o];return t}function ht(e){function t(n,s,r,o){let i=n[o++];if(i==="__proto__")return!0;const c=Number.isFinite(+i),d=o>=n.length;return i=!i&&a.isArray(r)?r.length:i,d?(a.hasOwnProp(r,i)?r[i]=[r[i],s]:r[i]=s,!c):((!r[i]||!a.isObject(r[i]))&&(r[i]=[]),t(n,s,r[i],o)&&a.isArray(r[i])&&(r[i]=An(r[i])),!c)}if(a.isFormData(e)&&a.isFunction(e.entries)){const n={};return a.forEachEntry(e,(s,r)=>{t(On(s),r,n,0)}),n}return null}function gn(e,t,n){if(a.isString(e))try{return(t||JSON.parse)(e),a.trim(e)}catch(s){if(s.name!=="SyntaxError")throw s}return(n||JSON.stringify)(e)}const ne={transitional:dt,adapter:["xhr","http","fetch"],transformRequest:[function(t,n){const s=n.getContentType()||"",r=s.indexOf("application/json")>-1,o=a.isObject(t);if(o&&a.isHTMLForm(t)&&(t=new FormData(t)),a.isFormData(t))return r?JSON.stringify(ht(t)):t;if(a.isArrayBuffer(t)||a.isBuffer(t)||a.isStream(t)||a.isFile(t)||a.isBlob(t)||a.isReadableStream(t))return t;if(a.isArrayBufferView(t))return t.buffer;if(a.isURLSearchParams(t))return n.setContentType("application/x-www-form-urlencoded;charset=utf-8",!1),t.toString();let c;if(o){if(s.indexOf("application/x-www-form-urlencoded")>-1)return bn(t,this.formSerializer).toString();if((c=a.isFileList(t))||s.indexOf("multipart/form-data")>-1){const d=this.env&&this.env.FormData;return Ee(c?{"files[]":t}:t,d&&new d,this.formSerializer)}}return o||r?(n.setContentType("application/json",!1),gn(t)):t}],transformResponse:[function(t){const n=this.transitional||ne.transitional,s=n&&n.forcedJSONParsing,r=this.responseType==="json";if(a.isResponse(t)||a.isReadableStream(t))return t;if(t&&a.isString(t)&&(s&&!this.responseType||r)){const i=!(n&&n.silentJSONParsing)&&r;try{return JSON.parse(t,this.parseReviver)}catch(c){if(i)throw c.name==="SyntaxError"?E.from(c,E.ERR_BAD_RESPONSE,this,null,this.response):c}}return t}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:O.classes.FormData,Blob:O.classes.Blob},validateStatus:function(t){return t>=200&&t<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};a.forEach(["delete","get","head","post","put","patch"],e=>{ne.headers[e]={}});const Nn=a.toObjectSet(["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"]),Cn=e=>{const t={};let n,s,r;return e&&e.split(`
|
|
2
|
-
`).forEach(function(i){r=i.indexOf(":"),n=i.substring(0,r).trim().toLowerCase(),s=i.substring(r+1).trim(),!(!n||t[n]&&
|
|
3
|
-
`)}getSetCookie(){return this.get("set-cookie")||[]}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(t){return t instanceof this?t:new this(t)}static concat(t,...n){const s=new this(t);return n.forEach(r=>s.set(r)),s}static accessor(t){const s=(this[Me]=this[Me]={accessors:{}}).accessors,r=this.prototype;function o(i){const c=Q(i);s[c]||(In(r,i),s[c]=!0)}return a.isArray(t)?t.forEach(o):o(t),this}};C.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]);a.reduceDescriptors(C.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(s){this[n]=s}}});a.freezeMethods(C);function we(e,t){const n=this||ne,s=t||n,r=C.from(s.headers);let o=s.data;return a.forEach(e,function(c){o=c.call(n,o,r.normalize(),t?t.status:void 0)}),r.normalize(),o}function pt(e){return!!(e&&e.__CANCEL__)}function K(e,t,n){E.call(this,e??"canceled",E.ERR_CANCELED,t,n),this.name="CanceledError"}a.inherits(K,E,{__CANCEL__:!0});function mt(e,t,n){const s=n.config.validateStatus;!n.status||!s||s(n.status)?e(n):t(new E("Request failed with status code "+n.status,[E.ERR_BAD_REQUEST,E.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))}function Fn(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function Ln(e,t){e=e||10;const n=new Array(e),s=new Array(e);let r=0,o=0,i;return t=t!==void 0?t:1e3,function(d){const u=Date.now(),l=s[o];i||(i=u),n[r]=d,s[r]=u;let p=o,S=0;for(;p!==r;)S+=n[p++],p=p%e;if(r=(r+1)%e,r===o&&(o=(o+1)%e),u-i<t)return;const w=l&&u-l;return w?Math.round(S*1e3/w):void 0}}function xn(e,t){let n=0,s=1e3/t,r,o;const i=(u,l=Date.now())=>{n=l,r=null,o&&(clearTimeout(o),o=null),e(...u)};return[(...u)=>{const l=Date.now(),p=l-n;p>=s?i(u,l):(r=u,o||(o=setTimeout(()=>{o=null,i(r)},s-p)))},()=>r&&i(r)]}const ue=(e,t,n=3)=>{let s=0;const r=Ln(50,250);return xn(o=>{const i=o.loaded,c=o.lengthComputable?o.total:void 0,d=i-s,u=r(d),l=i<=c;s=i;const p={loaded:i,total:c,progress:c?i/c:void 0,bytes:d,rate:u||void 0,estimated:u&&c&&l?(c-i)/u:void 0,event:o,lengthComputable:c!=null,[t?"download":"upload"]:!0};e(p)},n)},qe=(e,t)=>{const n=e!=null;return[s=>t[0]({lengthComputable:n,total:e,loaded:s}),t[1]]},$e=e=>(...t)=>a.asap(()=>e(...t)),Pn=O.hasStandardBrowserEnv?((e,t)=>n=>(n=new URL(n,O.origin),e.protocol===n.protocol&&e.host===n.host&&(t||e.port===n.port)))(new URL(O.origin),O.navigator&&/(msie|trident)/i.test(O.navigator.userAgent)):()=>!0,kn=O.hasStandardBrowserEnv?{write(e,t,n,s,r,o,i){if(typeof document>"u")return;const c=[`${e}=${encodeURIComponent(t)}`];a.isNumber(n)&&c.push(`expires=${new Date(n).toUTCString()}`),a.isString(s)&&c.push(`path=${s}`),a.isString(r)&&c.push(`domain=${r}`),o===!0&&c.push("secure"),a.isString(i)&&c.push(`SameSite=${i}`),document.cookie=c.join("; ")},read(e){if(typeof document>"u")return null;const t=document.cookie.match(new RegExp("(?:^|; )"+e+"=([^;]*)"));return t?decodeURIComponent(t[1]):null},remove(e){this.write(e,"",Date.now()-864e5,"/")}}:{write(){},read(){return null},remove(){}};function Bn(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function jn(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function Et(e,t,n){let s=!Bn(t);return e&&(s||n==!1)?jn(e,t):t}const Je=e=>e instanceof C?{...e}:e;function J(e,t){t=t||{};const n={};function s(u,l,p,S){return a.isPlainObject(u)&&a.isPlainObject(l)?a.merge.call({caseless:S},u,l):a.isPlainObject(l)?a.merge({},l):a.isArray(l)?l.slice():l}function r(u,l,p,S){if(a.isUndefined(l)){if(!a.isUndefined(u))return s(void 0,u,p,S)}else return s(u,l,p,S)}function o(u,l){if(!a.isUndefined(l))return s(void 0,l)}function i(u,l){if(a.isUndefined(l)){if(!a.isUndefined(u))return s(void 0,u)}else return s(void 0,l)}function c(u,l,p){if(p in t)return s(u,l);if(p in e)return s(void 0,u)}const d={url:o,method:o,data:o,baseURL:i,transformRequest:i,transformResponse:i,paramsSerializer:i,timeout:i,timeoutMessage:i,withCredentials:i,withXSRFToken:i,adapter:i,responseType:i,xsrfCookieName:i,xsrfHeaderName:i,onUploadProgress:i,onDownloadProgress:i,decompress:i,maxContentLength:i,maxBodyLength:i,beforeRedirect:i,transport:i,httpAgent:i,httpsAgent:i,cancelToken:i,socketPath:i,responseEncoding:i,validateStatus:c,headers:(u,l,p)=>r(Je(u),Je(l),p,!0)};return a.forEach(Object.keys({...e,...t}),function(l){const p=d[l]||r,S=p(e[l],t[l],l);a.isUndefined(S)&&p!==c||(n[l]=S)}),n}const St=e=>{const t=J({},e);let{data:n,withXSRFToken:s,xsrfHeaderName:r,xsrfCookieName:o,headers:i,auth:c}=t;if(t.headers=i=C.from(i),t.url=ft(Et(t.baseURL,t.url,t.allowAbsoluteUrls),e.params,e.paramsSerializer),c&&i.set("Authorization","Basic "+btoa((c.username||"")+":"+(c.password?unescape(encodeURIComponent(c.password)):""))),a.isFormData(n)){if(O.hasStandardBrowserEnv||O.hasStandardBrowserWebWorkerEnv)i.setContentType(void 0);else if(a.isFunction(n.getHeaders)){const d=n.getHeaders(),u=["content-type","content-length"];Object.entries(d).forEach(([l,p])=>{u.includes(l.toLowerCase())&&i.set(l,p)})}}if(O.hasStandardBrowserEnv&&(s&&a.isFunction(s)&&(s=s(t)),s||s!==!1&&Pn(t.url))){const d=r&&o&&kn.read(o);d&&i.set(r,d)}return t},Hn=typeof XMLHttpRequest<"u",vn=Hn&&function(e){return new Promise(function(n,s){const r=St(e);let o=r.data;const i=C.from(r.headers).normalize();let{responseType:c,onUploadProgress:d,onDownloadProgress:u}=r,l,p,S,w,f;function m(){w&&w(),f&&f(),r.cancelToken&&r.cancelToken.unsubscribe(l),r.signal&&r.signal.removeEventListener("abort",l)}let h=new XMLHttpRequest;h.open(r.method.toUpperCase(),r.url,!0),h.timeout=r.timeout;function R(){if(!h)return;const y=C.from("getAllResponseHeaders"in h&&h.getAllResponseHeaders()),I={data:!c||c==="text"||c==="json"?h.responseText:h.response,status:h.status,statusText:h.statusText,headers:y,config:e,request:h};mt(function(D){n(D),m()},function(D){s(D),m()},I),h=null}"onloadend"in h?h.onloadend=R:h.onreadystatechange=function(){!h||h.readyState!==4||h.status===0&&!(h.responseURL&&h.responseURL.indexOf("file:")===0)||setTimeout(R)},h.onabort=function(){h&&(s(new E("Request aborted",E.ECONNABORTED,e,h)),h=null)},h.onerror=function(g){const I=g&&g.message?g.message:"Network Error",v=new E(I,E.ERR_NETWORK,e,h);v.event=g||null,s(v),h=null},h.ontimeout=function(){let g=r.timeout?"timeout of "+r.timeout+"ms exceeded":"timeout exceeded";const I=r.transitional||dt;r.timeoutErrorMessage&&(g=r.timeoutErrorMessage),s(new E(g,I.clarifyTimeoutError?E.ETIMEDOUT:E.ECONNABORTED,e,h)),h=null},o===void 0&&i.setContentType(null),"setRequestHeader"in h&&a.forEach(i.toJSON(),function(g,I){h.setRequestHeader(I,g)}),a.isUndefined(r.withCredentials)||(h.withCredentials=!!r.withCredentials),c&&c!=="json"&&(h.responseType=r.responseType),u&&([S,f]=ue(u,!0),h.addEventListener("progress",S)),d&&h.upload&&([p,w]=ue(d),h.upload.addEventListener("progress",p),h.upload.addEventListener("loadend",w)),(r.cancelToken||r.signal)&&(l=y=>{h&&(s(!y||y.type?new K(null,e,h):y),h.abort(),h=null)},r.cancelToken&&r.cancelToken.subscribe(l),r.signal&&(r.signal.aborted?l():r.signal.addEventListener("abort",l)));const _=Fn(r.url);if(_&&O.protocols.indexOf(_)===-1){s(new E("Unsupported protocol "+_+":",E.ERR_BAD_REQUEST,e));return}h.send(o||null)})},Mn=(e,t)=>{const{length:n}=e=e?e.filter(Boolean):[];if(t||n){let s=new AbortController,r;const o=function(u){if(!r){r=!0,c();const l=u instanceof Error?u:this.reason;s.abort(l instanceof E?l:new K(l instanceof Error?l.message:l))}};let i=t&&setTimeout(()=>{i=null,o(new E(`timeout ${t} of ms exceeded`,E.ETIMEDOUT))},t);const c=()=>{e&&(i&&clearTimeout(i),i=null,e.forEach(u=>{u.unsubscribe?u.unsubscribe(o):u.removeEventListener("abort",o)}),e=null)};e.forEach(u=>u.addEventListener("abort",o));const{signal:d}=s;return d.unsubscribe=()=>a.asap(c),d}},qn=function*(e,t){let n=e.byteLength;if(n<t){yield e;return}let s=0,r;for(;s<n;)r=s+t,yield e.slice(s,r),s=r},$n=async function*(e,t){for await(const n of Jn(e))yield*qn(n,t)},Jn=async function*(e){if(e[Symbol.asyncIterator]){yield*e;return}const t=e.getReader();try{for(;;){const{done:n,value:s}=await t.read();if(n)break;yield s}}finally{await t.cancel()}},ze=(e,t,n,s)=>{const r=$n(e,t);let o=0,i,c=d=>{i||(i=!0,s&&s(d))};return new ReadableStream({async pull(d){try{const{done:u,value:l}=await r.next();if(u){c(),d.close();return}let p=l.byteLength;if(n){let S=o+=p;n(S)}d.enqueue(new Uint8Array(l))}catch(u){throw c(u),u}},cancel(d){return c(d),r.return()}},{highWaterMark:2})},Ge=64*1024,{isFunction:ie}=a,zn=(({Request:e,Response:t})=>({Request:e,Response:t}))(a.global),{ReadableStream:We,TextEncoder:Ve}=a.global,Ke=(e,...t)=>{try{return!!e(...t)}catch{return!1}},Gn=e=>{e=a.merge.call({skipUndefined:!0},zn,e);const{fetch:t,Request:n,Response:s}=e,r=t?ie(t):typeof fetch=="function",o=ie(n),i=ie(s);if(!r)return!1;const c=r&&ie(We),d=r&&(typeof Ve=="function"?(f=>m=>f.encode(m))(new Ve):async f=>new Uint8Array(await new n(f).arrayBuffer())),u=o&&c&&Ke(()=>{let f=!1;const m=new n(O.origin,{body:new We,method:"POST",get duplex(){return f=!0,"half"}}).headers.has("Content-Type");return f&&!m}),l=i&&c&&Ke(()=>a.isReadableStream(new s("").body)),p={stream:l&&(f=>f.body)};r&&["text","arrayBuffer","blob","formData","stream"].forEach(f=>{!p[f]&&(p[f]=(m,h)=>{let R=m&&m[f];if(R)return R.call(m);throw new E(`Response type '${f}' is not supported`,E.ERR_NOT_SUPPORT,h)})});const S=async f=>{if(f==null)return 0;if(a.isBlob(f))return f.size;if(a.isSpecCompliantForm(f))return(await new n(O.origin,{method:"POST",body:f}).arrayBuffer()).byteLength;if(a.isArrayBufferView(f)||a.isArrayBuffer(f))return f.byteLength;if(a.isURLSearchParams(f)&&(f=f+""),a.isString(f))return(await d(f)).byteLength},w=async(f,m)=>{const h=a.toFiniteNumber(f.getContentLength());return h??S(m)};return async f=>{let{url:m,method:h,data:R,signal:_,cancelToken:y,timeout:g,onDownloadProgress:I,onUploadProgress:v,responseType:D,headers:Te,withCredentials:se="same-origin",fetchOptions:Ie}=St(f),Fe=t||fetch;D=D?(D+"").toLowerCase():"text";let re=Mn([_,y&&y.toAbortSignal()],g),X=null;const M=re&&re.unsubscribe&&(()=>{re.unsubscribe()});let Le;try{if(v&&u&&h!=="get"&&h!=="head"&&(Le=await w(Te,R))!==0){let H=new n(m,{method:"POST",body:R,duplex:"half"}),G;if(a.isFormData(R)&&(G=H.headers.get("content-type"))&&Te.setContentType(G),H.body){const[Re,oe]=qe(Le,ue($e(v)));R=ze(H.body,Ge,Re,oe)}}a.isString(se)||(se=se?"include":"omit");const L=o&&"credentials"in n.prototype,xe={...Ie,signal:re,method:h.toUpperCase(),headers:Te.normalize().toJSON(),body:R,duplex:"half",credentials:L?se:void 0};X=o&&new n(m,xe);let j=await(o?Fe(X,Ie):Fe(m,xe));const Pe=l&&(D==="stream"||D==="response");if(l&&(I||Pe&&M)){const H={};["status","statusText","headers"].forEach(ke=>{H[ke]=j[ke]});const G=a.toFiniteNumber(j.headers.get("content-length")),[Re,oe]=I&&qe(G,ue($e(I),!0))||[];j=new s(ze(j.body,Ge,Re,()=>{oe&&oe(),M&&M()}),H)}D=D||"text";let Ot=await p[a.findKey(p,D)||"text"](j,f);return!Pe&&M&&M(),await new Promise((H,G)=>{mt(H,G,{data:Ot,headers:C.from(j.headers),status:j.status,statusText:j.statusText,config:f,request:X})})}catch(L){throw M&&M(),L&&L.name==="TypeError"&&/Load failed|fetch/i.test(L.message)?Object.assign(new E("Network Error",E.ERR_NETWORK,f,X),{cause:L.cause||L}):E.from(L,L&&L.code,f,X)}}},Wn=new Map,Tt=e=>{let t=e&&e.env||{};const{fetch:n,Request:s,Response:r}=t,o=[s,r,n];let i=o.length,c=i,d,u,l=Wn;for(;c--;)d=o[c],u=l.get(d),u===void 0&&l.set(d,u=c?new Map:Gn(t)),l=u;return u};Tt();const De={http:un,xhr:vn,fetch:{get:Tt}};a.forEach(De,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const Xe=e=>`- ${e}`,Vn=e=>a.isFunction(e)||e===null||e===!1;function Kn(e,t){e=a.isArray(e)?e:[e];const{length:n}=e;let s,r;const o={};for(let i=0;i<n;i++){s=e[i];let c;if(r=s,!Vn(s)&&(r=De[(c=String(s)).toLowerCase()],r===void 0))throw new E(`Unknown adapter '${c}'`);if(r&&(a.isFunction(r)||(r=r.get(t))))break;o[c||"#"+i]=r}if(!r){const i=Object.entries(o).map(([d,u])=>`adapter ${d} `+(u===!1?"is not supported by the environment":"is not available in the build"));let c=n?i.length>1?`since :
|
|
4
|
-
`+i.map(
|
|
5
|
-
`):" "+
|
|
6
|
-
`+o):s.stack=o}catch{}}throw s}}_request(t,n){typeof t=="string"?(n=n||{},n.url=t):n=t||{},n=J(this.defaults,n);const{transitional:s,paramsSerializer:r,headers:o}=n;s!==void 0&&le.assertOptions(s,{silentJSONParsing:x.transitional(x.boolean),forcedJSONParsing:x.transitional(x.boolean),clarifyTimeoutError:x.transitional(x.boolean)},!1),r!=null&&(a.isFunction(r)?n.paramsSerializer={serialize:r}:le.assertOptions(r,{encode:x.function,serialize:x.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),le.assertOptions(n,{baseUrl:x.spelling("baseURL"),withXsrfToken:x.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i=o&&a.merge(o.common,o[n.method]);o&&a.forEach(["delete","get","head","post","put","patch","common"],f=>{delete o[f]}),n.headers=C.concat(i,o);const c=[];let d=!0;this.interceptors.request.forEach(function(m){typeof m.runWhen=="function"&&m.runWhen(n)===!1||(d=d&&m.synchronous,c.unshift(m.fulfilled,m.rejected))});const u=[];this.interceptors.response.forEach(function(m){u.push(m.fulfilled,m.rejected)});let l,p=0,S;if(!d){const f=[Qe.bind(this),void 0];for(f.unshift(...c),f.push(...u),S=f.length,l=Promise.resolve(n);p<S;)l=l.then(f[p++],f[p++]);return l}S=c.length;let w=n;for(;p<S;){const f=c[p++],m=c[p++];try{w=f(w)}catch(h){m.call(this,h);break}}try{l=Qe.call(this,w)}catch(f){return Promise.reject(f)}for(p=0,S=u.length;p<S;)l=l.then(u[p++],u[p++]);return l}getUri(t){t=J(this.defaults,t);const n=Et(t.baseURL,t.url,t.allowAbsoluteUrls);return ft(n,t.params,t.paramsSerializer)}};a.forEach(["delete","get","head","options"],function(t){$.prototype[t]=function(n,s){return this.request(J(s||{},{method:t,url:n,data:(s||{}).data}))}});a.forEach(["post","put","patch"],function(t){function n(s){return function(o,i,c){return this.request(J(c||{},{method:t,headers:s?{"Content-Type":"multipart/form-data"}:{},url:o,data:i}))}}$.prototype[t]=n(),$.prototype[t+"Form"]=n(!0)});let Qn=class wt{constructor(t){if(typeof t!="function")throw new TypeError("executor must be a function.");let n;this.promise=new Promise(function(o){n=o});const s=this;this.promise.then(r=>{if(!s._listeners)return;let o=s._listeners.length;for(;o-- >0;)s._listeners[o](r);s._listeners=null}),this.promise.then=r=>{let o;const i=new Promise(c=>{s.subscribe(c),o=c}).then(r);return i.cancel=function(){s.unsubscribe(o)},i},t(function(o,i,c){s.reason||(s.reason=new K(o,i,c),n(s.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(t){if(this.reason){t(this.reason);return}this._listeners?this._listeners.push(t):this._listeners=[t]}unsubscribe(t){if(!this._listeners)return;const n=this._listeners.indexOf(t);n!==-1&&this._listeners.splice(n,1)}toAbortSignal(){const t=new AbortController,n=s=>{t.abort(s)};return this.subscribe(n),t.signal.unsubscribe=()=>this.unsubscribe(n),t.signal}static source(){let t;return{token:new wt(function(r){t=r}),cancel:t}}};function Yn(e){return function(n){return e.apply(null,n)}}function Zn(e){return a.isObject(e)&&e.isAxiosError===!0}const Ne={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511,WebServerIsDown:521,ConnectionTimedOut:522,OriginIsUnreachable:523,TimeoutOccurred:524,SslHandshakeFailed:525,InvalidSslCertificate:526};Object.entries(Ne).forEach(([e,t])=>{Ne[t]=e});function bt(e){const t=new $(e),n=Ze($.prototype.request,t);return a.extend(n,$.prototype,t,{allOwnKeys:!0}),a.extend(n,t,null,{allOwnKeys:!0}),n.create=function(r){return bt(J(e,r))},n}const T=bt(ne);T.Axios=$;T.CanceledError=K;T.CancelToken=Qn;T.isCancel=pt;T.VERSION=yt;T.toFormData=Ee;T.AxiosError=E;T.Cancel=T.CanceledError;T.all=function(t){return Promise.all(t)};T.spread=Yn;T.isAxiosError=Zn;T.mergeConfig=J;T.AxiosHeaders=C;T.formToJSON=e=>ht(a.isHTMLForm(e)?new FormData(e):e);T.getAdapter=Rt.getAdapter;T.HttpStatusCode=Ne;T.default=T;const{Axios:ds,AxiosError:hs,CanceledError:ps,isCancel:ms,CancelToken:Es,VERSION:Ss,all:Ts,Cancel:Rs,isAxiosError:ys,spread:ws,toFormData:bs,AxiosHeaders:Os,HttpStatusCode:As,formToJSON:gs,getAdapter:Ns,mergeConfig:Cs}=T,fe="JOYTALK_TOKEN";var k=(e=>(e.SEND="1",e.WITHDRAW="2",e.EDIT="3",e.SYSTEM_NOTICE="4",e.TRANSFER="5",e.INBOUND="6",e.REPLY="7",e.UNBIND="8",e))(k||{}),B=(e=>(e.TEXT="1",e.IMAGE="2",e.VIDEO="3",e.FILE="4",e.FAQ="5",e))(B||{}),P=(e=>(e[e.CONNECT_SUCCESS=200]="CONNECT_SUCCESS",e[e.CONNECT_FAILED=40001]="CONNECT_FAILED",e[e.TRANSFER_CUSTOMER_SUCCESS=201]="TRANSFER_CUSTOMER_SUCCESS",e[e.TRANSFER_TO_CUSTOMER_SUCCESS=202]="TRANSFER_TO_CUSTOMER_SUCCESS",e[e.TRANSFER_USER_SUCCESS=203]="TRANSFER_USER_SUCCESS",e[e.TRANSFER_FAIL=50001]="TRANSFER_FAIL",e[e.MATCH_FAIL=50002]="MATCH_FAIL",e[e.MATCH_INFO=50005]="MATCH_INFO",e[e.MATCH_SUCCESS=50006]="MATCH_SUCCESS",e[e.RETRACT=204]="RETRACT",e[e.RETRACT_FAIL=50003]="RETRACT_FAIL",e[e.EDIT=205]="EDIT",e[e.EDIT_FAIL=50004]="EDIT_FAIL",e[e.COMMON_FAIL=5e4]="COMMON_FAIL",e[e.SEND_SUCCESS=206]="SEND_SUCCESS",e[e.SEND_CALLBACK=207]="SEND_CALLBACK",e[e.CHANGE_CHAT_STATUS=208]="CHANGE_CHAT_STATUS",e))(P||{}),de=(e=>(e.CUSTOMER="1",e.USER="2",e.ANONYMOUS="3",e))(de||{}),A=(e=>(e.CONNECTED="connected",e.DISCONNECTED="disconnected",e.ERROR="error",e.MESSAGE="message",e.STATUS_CHANGE="status_change",e.HEARTBEAT_TIMEOUT="heartbeat_timeout",e))(A||{}),b=(e=>(e.DISCONNECTED="disconnected",e.CONNECTING="connecting",e.CONNECTED="connected",e.RECONNECTING="reconnecting",e.ERROR="error",e))(b||{});const U={UNINITIALIZED:{code:10001,msg:"未初始化"},DISCONNECTED:{code:10002,msg:"未连接"},NO_CUSTOMER_SERVICE:{code:10003,msg:"未分配客服"},MESSAGE_SEND_FAIL:{code:10004,msg:"消息发送失败"},DATA_PARSING_ERROR:{code:10005,msg:"数据解析异常"},FILE_NOT_EXIST:{code:10006,msg:"文件不存在"},FILE_PARSING_ERROR:{code:10007,msg:"文件解析异常"},AUTH_INFO_ERROR:{code:10008,msg:"授权信息错误"},FILE_UPLOAD_FAIL:{code:10009,msg:"文件上传失败"},PARAMETER_ERROR:{code:10010,msg:"参数异常"},EMPTY_DATA:{code:10011,msg:"数据为空"}},z=T.create({baseURL:"http://dev-joytalk-api.halaladmin.vip",timeout:6e5});z.interceptors.request.use(e=>{if(!e.noAuth){const t=localStorage.getItem(fe);if(!t)return Promise.reject(U.UNINITIALIZED);e.headers.Authorization=`Bearer ${t}`}return delete e.noAuth,e},e=>Promise.reject(e));z.interceptors.response.use(e=>e.data.code!==200?Promise.reject(e):Promise.resolve(e.data),e=>Promise.reject(e));const es=e=>z.post("/api/open-auth/obs/v1/ObsService/GetObsAuthInfo",e),ts=e=>T.post("https://joytalk-fat.obs.ap-southeast-1.myhuaweicloud.com",e,{headers:{"Content-Type":"multipart/form-data"}}),ns=e=>z.post("/api/open-auth/open_consultation/v1/OpenConsultationService/GetConsultationList",e),ss=e=>z.get("/api/open-auth/faq/v1/FaqService/GetFaqList",{params:e}),rs=()=>z.get("/api/open-auth/user/v1/UserService/GetUserInfo"),os=e=>z.post("/api/open-auth/user/v1/UserService/GetUserHistoryMessages",e);class is{events=new Map;on(t,n){this.events.has(t)||this.events.set(t,[]),this.events.get(t).push(n)}off(t,n){const s=this.events.get(t);if(s){const r=s.indexOf(n);r>-1&&s.splice(r,1)}}emit(t,n){const s=this.events.get(t);s&&s.forEach(r=>{try{r(n)}catch(o){console.error(`事件回调执行错误 [${t}]:`,o)}})}removeAllListeners(t){t?this.events.delete(t):this.events.clear()}once(t,n){const s=r=>{n(r),this.off(t,s)};this.on(t,s)}}function as(e){return`ws://dev-joytalk-api.halaladmin.vip/api/ws?Authorization=${e}`}function cs(){return Date.now().toString(36)+Math.random().toString(36).slice(2)}const ls="https://joytalk-fat.obs.ap-southeast-1.myhuaweicloud.com/";class Y extends is{config={token:"",autoReconnect:!0,reconnectInterval:3e3,maxReconnectAttempts:5,responseTimeout:1e4};ws=null;status=b.DISCONNECTED;reconnectTimer=null;reconnectAttempts=0;heartbeatTimeoutTimer=null;lastHeartbeatTime=0;consultationTypeId="";OBS_URL=ls;sessionData=null;userInfo=null;static instance=null;constructor(){if(super(),Y.instance)return Y.instance;Y.instance=this}async init(t){if(!t.token)return localStorage.removeItem(fe),Promise.reject(U.PARAMETER_ERROR);this.config=Object.assign(this.config,t),localStorage.setItem(fe,this.config.token)}connect(t){return this.consultationTypeId=t,new Promise((n,s)=>{if(!this.config.token)return s(U.UNINITIALIZED);if(this.status===b.CONNECTED)return n();if(this.status!==b.CONNECTING){this.setStatus(b.CONNECTING);try{const r=as(this.config.token);this.ws=new WebSocket(r),this.ws.onopen=()=>{this.reconnectAttempts=0,this.setStatus(b.CONNECTED),this.emit(A.CONNECTED),n()},this.ws.onmessage=o=>{try{this.handleMessage(o.data)}catch(i){console.error("解析消息失败:",i)}},this.ws.onerror=o=>{console.error("连接错误:",o),this.setStatus(b.ERROR),this.emit(A.ERROR,o),s(o)},this.ws.onclose=()=>{this.setStatus(b.DISCONNECTED),this.emit(A.DISCONNECTED),this.config.autoReconnect&&this.reconnectAttempts<this.config.maxReconnectAttempts&&this.scheduleReconnect()}}catch(r){this.setStatus(b.ERROR),this.emit(A.ERROR,r),s(r)}}})}disconnect(){this.config.autoReconnect=!1,this.sessionData=null,this.clearReconnectTimer(),this.heartbeatTimeoutTimer&&(clearTimeout(this.heartbeatTimeoutTimer),this.heartbeatTimeoutTimer=null),this.ws&&(this.ws.close(),this.ws=null),this.setStatus(b.DISCONNECTED)}async sendMessage(t,n,s=k.SEND){console.log("发送消息",{data:t,chatType:n,msgType:s,status:this.status,ws:this.ws});const r={msgType:s,data:t,toUid:this.sessionData?.cid,chatType:n,editId:void 0};if(this.status!==b.CONNECTED||!this.ws)if(this.ws&&this.status===b.DISCONNECTED){console.log("连接断开,尝试重新连接");try{await this.connect(this.consultationTypeId)}catch(o){throw console.error("重连失败:",o),U.DISCONNECTED}}else throw console.error(U.DISCONNECTED),U.DISCONNECTED;try{if(!this.ws)throw U.DISCONNECTED;return s===k.SEND?new Promise((o,i)=>{const c=cs();r.ext=c;const d=setTimeout(()=>{this.off(c,u),i(U.MESSAGE_SEND_FAIL)},this.config.responseTimeout),u=l=>{clearTimeout(d),o({messageId:l,data:t})};this.once(c,u),this.ws.send(JSON.stringify(r))}):(this.ws.send(JSON.stringify(r)),{data:t})}catch(o){throw console.error("发送消息失败:",o),U.MESSAGE_SEND_FAIL}}async sendText(t){if(!this.sessionData)throw console.error(U.NO_CUSTOMER_SERVICE),U.NO_CUSTOMER_SERVICE;return this.sendMessage(t,B.TEXT)}async sendFile({file:t,thumbnailFile:n,chatType:s}){try{if(!this.sessionData)throw console.error(U.NO_CUSTOMER_SERVICE),U.NO_CUSTOMER_SERVICE;const[r,o]=await Promise.all([this.handleUploadFile(t),n?this.handleUploadFile(n):Promise.resolve(void 0)]),i={fileName:t.name,fileUrl:r,thumbnailUrl:o,fileSize:t.size};return this.sendMessage(JSON.stringify(i),s)}catch(r){throw console.error("上传文件失败:",r),r}}getStatus(){return this.status}isConnected(){return this.status===b.CONNECTED}handleMessage(t){if(t==="ping"){this.lastHeartbeatTime=Date.now(),this.heartbeatTimeoutTimer&&(clearTimeout(this.heartbeatTimeoutTimer),this.heartbeatTimeoutTimer=null),this.sendHeartbeat();return}if(t=JSON.parse(t),this.isMessage(t))try{switch(t.code){case P.CONNECT_SUCCESS:if(this.sessionData)return;this.sendMessage(this.consultationTypeId,void 0,k.INBOUND);break;case P.MATCH_INFO:case P.MATCH_SUCCESS:if(this.sessionData)return;const n=JSON.parse(typeof t.data=="string"?t.data:JSON.stringify(t.data));this.sessionData=n,t.data=n,this.getFaqList(),this.emit(A.MESSAGE,t);break;case P.TRANSFER_USER_SUCCESS:const s=JSON.parse(typeof t.data=="string"?t.data:JSON.stringify(t.data));this.sessionData={...this.sessionData,cid:s.cid,customerAvatar:s.customerAvatar,customerName:s.customerName,groupId:s.groupId,segmentId:s.segmentId,sessionId:s.sessionId,uid:s.uid},t.data=this.sessionData,this.emit(A.MESSAGE,t);break;case P.SEND_SUCCESS:const r=JSON.parse(typeof t.data=="string"?t.data:JSON.stringify(t.data));if(r.sessionId!==this.sessionData?.sessionId)return;t.chatType!==B.TEXT&&typeof r.content=="string"&&(r.content=JSON.parse(r.content),r.content?.fileUrl?.startsWith("http")||(r.content.fileUrl=this.OBS_URL+r.content.fileUrl),r.content?.thumbnailUrl?.startsWith("http")||(r.content.thumbnailUrl=this.OBS_URL+r.content.thumbnailUrl)),t.data=r,this.emit(A.MESSAGE,t);break;case P.SEND_CALLBACK:const o=t.ext,c=JSON.parse(t.data).messageId;this.emit(o,c);break;default:this.emit(A.MESSAGE,t);break}}catch(n){console.error("解析消息失败:",n)}}isMessage(t){return typeof t=="object"&&t!==null&&"data"in t&&"msgType"in t&&"toUid"in t&&"chatType"in t&&"code"in t}setStatus(t){this.status!==t&&(this.status=t,this.emit(A.STATUS_CHANGE,t))}scheduleReconnect(){this.clearReconnectTimer(),this.reconnectAttempts++,this.setStatus(b.RECONNECTING),this.reconnectTimer=setTimeout(()=>{this.connect(this.consultationTypeId).catch(t=>{console.error("重连失败:",t)})},this.config.reconnectInterval)}clearReconnectTimer(){this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null)}sendHeartbeat(){if(!(this.status!==b.CONNECTED||!this.ws))try{this.ws.send("pong"),this.lastHeartbeatTime=Date.now(),this.heartbeatTimeoutTimer=setTimeout(()=>{Date.now()-this.lastHeartbeatTime>=this.config.responseTimeout&&(this.emit(A.HEARTBEAT_TIMEOUT),console.warn("心跳超时,尝试重连"),this.ws&&this.ws.close())},this.config.responseTimeout)}catch(t){console.error("发送心跳失败:",t)}}async getHistoryMessages({lastMsgId:t,size:n=50}){const s=await os({sessionId:this.sessionData?.sessionId,lastMsgId:t,size:n}),r=s.data.list.map(o=>{let i=o.content;return o.contentType===B.TEXT?i=o.content:(i=JSON.parse(o.content),i?.fileUrl?.startsWith("http")||(i.fileUrl=this.OBS_URL+i.fileUrl),i?.thumbnailUrl?.startsWith("http")||(i.thumbnailUrl=this.OBS_URL+i.thumbnailUrl)),{...o,content:i}});return{hasMore:s.data.hasMore,list:r}}getConsultationList(t){return ns({entranceId:t})}handleUploadFile(t){return new Promise(async(n,s)=>{const r=t.name.split(".").pop(),o=await es({ext:r||""}),{accessKeyId:i,signature:c,policy:d,key:u}=o.data,l=new FormData;l.append("key",u),l.append("AccessKeyId",i),l.append("signature",c),l.append("policy",d),l.append("file",t),(await ts(l)).status===204?n(this.OBS_URL+u):s(new Error("上传文件失败"))})}getVideoThumbnail=t=>new Promise((n,s)=>{const r=document.createElement("video"),o=document.createElement("canvas"),i=o.getContext("2d");if(!i){s(new Error("无法创建 canvas 上下文"));return}const c=URL.createObjectURL(t);r.preload="metadata",r.src=c,r.muted=!0,r.playsInline=!0,r.addEventListener("loadeddata",()=>{o.width=r.videoWidth,o.height=r.videoHeight,r.currentTime=0}),r.addEventListener("seeked",()=>{try{i.drawImage(r,0,0,o.width,o.height),o.toBlob(d=>{if(URL.revokeObjectURL(c),r.remove(),!d){s(new Error("无法生成缩略图"));return}const u=t.name.replace(/\.[^/.]+$/,"")+"_thumb.jpg",l=new File([d],u,{type:"image/jpeg",lastModified:Date.now()});n(l)},"image/jpeg",.6)}catch(d){URL.revokeObjectURL(c),r.remove(),s(d)}}),r.addEventListener("error",()=>{URL.revokeObjectURL(c),r.remove(),s(new Error("视频加载失败"))}),r.load()});async getFaqList(){const t=await ss({id:this.sessionData?.cid});if(!t.data?.topic?.length)return;const n={guideText:t.data.guideText,list:t.data.topic.map(s=>({...s,question:s.question}))};setTimeout(()=>{const s={code:P.SEND_SUCCESS,data:{content:n,contentType:B.FAQ,sendUserType:de.CUSTOMER,customerServiceAvatar:this.sessionData?.customerAvatar,customerServiceName:this.sessionData?.customerName,createTime:Date.now(),msgType:k.SEND},msgType:k.SEND,chatType:B.FAQ,toUid:this.sessionData?.uid};this.emit(A.MESSAGE,s)},t.data.showDelaySeconds*1e3)}sendFaq(t){const n={code:P.SEND_SUCCESS,data:{sendUserType:de.CUSTOMER,customerServiceAvatar:this.sessionData?.customerAvatar,customerServiceName:this.sessionData?.customerName,createTime:Date.now(),msgType:k.SEND,contentType:B.FAQ,content:{}},msgType:k.SEND,chatType:B.FAQ,toUid:this.sessionData?.uid};if(t.isMulti)n.data.content={list:t.item},this.emit(A.MESSAGE,n);else{const s=t.item?.[0]||t;s.imageUrl=s.imageUrl?.map(r=>r?.startsWith("http")?r:this.OBS_URL+r),n.data.content={answer:s},this.emit(A.MESSAGE,n)}}async getUserInfo(){if(this.userInfo)return this.userInfo;const t=await rs();return this.userInfo=t.data,this.userInfo}}exports.ChatType=B;exports.ConnectionStatus=b;exports.EventType=A;exports.MessageCode=P;exports.MessageType=k;exports.SendUserType=de;exports.TOKEN_KEY=fe;exports.default=Y;
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});function et(e,t){return function(){return e.apply(t,arguments)}}const{toString:At}=Object.prototype,{getPrototypeOf:Ue}=Object,{iterator:pe,toStringTag:tt}=Symbol,me=(e=>t=>{const n=At.call(t);return e[n]||(e[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),P=e=>(e=e.toLowerCase(),t=>me(t)===e),Ee=e=>t=>typeof t===e,{isArray:X}=Array,K=Ee("undefined");function ee(e){return e!==null&&!K(e)&&e.constructor!==null&&!K(e.constructor)&&_(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const nt=P("ArrayBuffer");function gt(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&nt(e.buffer),t}const Ct=Ee("string"),_=Ee("function"),st=Ee("number"),te=e=>e!==null&&typeof e=="object",Ut=e=>e===!0||e===!1,ce=e=>{if(me(e)!=="object")return!1;const t=Ue(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(tt in e)&&!(pe in e)},_t=e=>{if(!te(e)||ee(e))return!1;try{return Object.keys(e).length===0&&Object.getPrototypeOf(e)===Object.prototype}catch{return!1}},Dt=P("Date"),It=P("File"),Ft=P("Blob"),Lt=P("FileList"),xt=e=>te(e)&&_(e.pipe),Pt=e=>{let t;return e&&(typeof FormData=="function"&&e instanceof FormData||_(e.append)&&((t=me(e))==="formdata"||t==="object"&&_(e.toString)&&e.toString()==="[object FormData]"))},Bt=P("URLSearchParams"),[kt,Ht,jt,Mt]=["ReadableStream","Request","Response","Headers"].map(P),vt=e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function ne(e,t,{allOwnKeys:n=!1}={}){if(e===null||typeof e>"u")return;let s,r;if(typeof e!="object"&&(e=[e]),X(e))for(s=0,r=e.length;s<r;s++)t.call(null,e[s],s,e);else{if(ee(e))return;const o=n?Object.getOwnPropertyNames(e):Object.keys(e),i=o.length;let c;for(s=0;s<i;s++)c=o[s],t.call(null,e[c],c,e)}}function rt(e,t){if(ee(e))return null;t=t.toLowerCase();const n=Object.keys(e);let s=n.length,r;for(;s-- >0;)if(r=n[s],t===r.toLowerCase())return r;return null}const $=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global,ot=e=>!K(e)&&e!==$;function Ne(){const{caseless:e,skipUndefined:t}=ot(this)&&this||{},n={},s=(r,o)=>{const i=e&&rt(n,o)||o;ce(n[i])&&ce(r)?n[i]=Ne(n[i],r):ce(r)?n[i]=Ne({},r):X(r)?n[i]=r.slice():(!t||!K(r))&&(n[i]=r)};for(let r=0,o=arguments.length;r<o;r++)arguments[r]&&ne(arguments[r],s);return n}const qt=(e,t,n,{allOwnKeys:s}={})=>(ne(t,(r,o)=>{n&&_(r)?e[o]=et(r,n):e[o]=r},{allOwnKeys:s}),e),$t=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),Gt=(e,t,n,s)=>{e.prototype=Object.create(t.prototype,s),e.prototype.constructor=e,Object.defineProperty(e,"super",{value:t.prototype}),n&&Object.assign(e.prototype,n)},zt=(e,t,n,s)=>{let r,o,i;const c={};if(t=t||{},e==null)return t;do{for(r=Object.getOwnPropertyNames(e),o=r.length;o-- >0;)i=r[o],(!s||s(i,e,t))&&!c[i]&&(t[i]=e[i],c[i]=!0);e=n!==!1&&Ue(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},Jt=(e,t,n)=>{e=String(e),(n===void 0||n>e.length)&&(n=e.length),n-=t.length;const s=e.indexOf(t,n);return s!==-1&&s===n},Vt=e=>{if(!e)return null;if(X(e))return e;let t=e.length;if(!st(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},Wt=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&Ue(Uint8Array)),Kt=(e,t)=>{const s=(e&&e[pe]).call(e);let r;for(;(r=s.next())&&!r.done;){const o=r.value;t.call(e,o[0],o[1])}},Xt=(e,t)=>{let n;const s=[];for(;(n=e.exec(t))!==null;)s.push(n);return s},Qt=P("HTMLFormElement"),Yt=e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(n,s,r){return s.toUpperCase()+r}),He=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),Zt=P("RegExp"),it=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),s={};ne(n,(r,o)=>{let i;(i=t(r,o,e))!==!1&&(s[o]=i||r)}),Object.defineProperties(e,s)},en=e=>{it(e,(t,n)=>{if(_(e)&&["arguments","caller","callee"].indexOf(n)!==-1)return!1;const s=e[n];if(_(s)){if(t.enumerable=!1,"writable"in t){t.writable=!1;return}t.set||(t.set=()=>{throw Error("Can not rewrite read-only method '"+n+"'")})}})},tn=(e,t)=>{const n={},s=r=>{r.forEach(o=>{n[o]=!0})};return X(e)?s(e):s(String(e).split(t)),n},nn=()=>{},sn=(e,t)=>e!=null&&Number.isFinite(e=+e)?e:t;function rn(e){return!!(e&&_(e.append)&&e[tt]==="FormData"&&e[pe])}const on=e=>{const t=new Array(10),n=(s,r)=>{if(te(s)){if(t.indexOf(s)>=0)return;if(ee(s))return s;if(!("toJSON"in s)){t[r]=s;const o=X(s)?[]:{};return ne(s,(i,c)=>{const d=n(i,r+1);!K(d)&&(o[c]=d)}),t[r]=void 0,o}}return s};return n(e,0)},an=P("AsyncFunction"),cn=e=>e&&(te(e)||_(e))&&_(e.then)&&_(e.catch),at=((e,t)=>e?setImmediate:t?((n,s)=>($.addEventListener("message",({source:r,data:o})=>{r===$&&o===n&&s.length&&s.shift()()},!1),r=>{s.push(r),$.postMessage(n,"*")}))(`axios@${Math.random()}`,[]):n=>setTimeout(n))(typeof setImmediate=="function",_($.postMessage)),un=typeof queueMicrotask<"u"?queueMicrotask.bind($):typeof process<"u"&&process.nextTick||at,ln=e=>e!=null&&_(e[pe]),a={isArray:X,isArrayBuffer:nt,isBuffer:ee,isFormData:Pt,isArrayBufferView:gt,isString:Ct,isNumber:st,isBoolean:Ut,isObject:te,isPlainObject:ce,isEmptyObject:_t,isReadableStream:kt,isRequest:Ht,isResponse:jt,isHeaders:Mt,isUndefined:K,isDate:Dt,isFile:It,isBlob:Ft,isRegExp:Zt,isFunction:_,isStream:xt,isURLSearchParams:Bt,isTypedArray:Wt,isFileList:Lt,forEach:ne,merge:Ne,extend:qt,trim:vt,stripBOM:$t,inherits:Gt,toFlatObject:zt,kindOf:me,kindOfTest:P,endsWith:Jt,toArray:Vt,forEachEntry:Kt,matchAll:Xt,isHTMLForm:Qt,hasOwnProperty:He,hasOwnProp:He,reduceDescriptors:it,freezeMethods:en,toObjectSet:tn,toCamelCase:Yt,noop:nn,toFiniteNumber:sn,findKey:rt,global:$,isContextDefined:ot,isSpecCompliantForm:rn,toJSONObject:on,isAsyncFn:an,isThenable:cn,setImmediate:at,asap:un,isIterable:ln};function E(e,t,n,s,r){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=new Error().stack,this.message=e,this.name="AxiosError",t&&(this.code=t),n&&(this.config=n),s&&(this.request=s),r&&(this.response=r,this.status=r.status?r.status:null)}a.inherits(E,Error,{toJSON:function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:a.toJSONObject(this.config),code:this.code,status:this.status}}});const ct=E.prototype,ut={};["ERR_BAD_OPTION_VALUE","ERR_BAD_OPTION","ECONNABORTED","ETIMEDOUT","ERR_NETWORK","ERR_FR_TOO_MANY_REDIRECTS","ERR_DEPRECATED","ERR_BAD_RESPONSE","ERR_BAD_REQUEST","ERR_CANCELED","ERR_NOT_SUPPORT","ERR_INVALID_URL"].forEach(e=>{ut[e]={value:e}});Object.defineProperties(E,ut);Object.defineProperty(ct,"isAxiosError",{value:!0});E.from=(e,t,n,s,r,o)=>{const i=Object.create(ct);a.toFlatObject(e,i,function(u){return u!==Error.prototype},l=>l!=="isAxiosError");const c=e&&e.message?e.message:"Error",d=t==null&&e?e.code:t;return E.call(i,c,d,n,s,r),e&&i.cause==null&&Object.defineProperty(i,"cause",{value:e,configurable:!0}),i.name=e&&e.name||"Error",o&&Object.assign(i,o),i};const fn=null;function Ae(e){return a.isPlainObject(e)||a.isArray(e)}function lt(e){return a.endsWith(e,"[]")?e.slice(0,-2):e}function je(e,t,n){return e?e.concat(t).map(function(r,o){return r=lt(r),!n&&o?"["+r+"]":r}).join(n?".":""):t}function dn(e){return a.isArray(e)&&!e.some(Ae)}const hn=a.toFlatObject(a,{},null,function(t){return/^is[A-Z]/.test(t)});function Se(e,t,n){if(!a.isObject(e))throw new TypeError("target must be an object");t=t||new FormData,n=a.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,function(m,h){return!a.isUndefined(h[m])});const s=n.metaTokens,r=n.visitor||u,o=n.dots,i=n.indexes,d=(n.Blob||typeof Blob<"u"&&Blob)&&a.isSpecCompliantForm(t);if(!a.isFunction(r))throw new TypeError("visitor must be a function");function l(f){if(f===null)return"";if(a.isDate(f))return f.toISOString();if(a.isBoolean(f))return f.toString();if(!d&&a.isBlob(f))throw new E("Blob is not supported. Use a Buffer instead.");return a.isArrayBuffer(f)||a.isTypedArray(f)?d&&typeof Blob=="function"?new Blob([f]):Buffer.from(f):f}function u(f,m,h){let R=f;if(f&&!h&&typeof f=="object"){if(a.endsWith(m,"{}"))m=s?m:m.slice(0,-2),f=JSON.stringify(f);else if(a.isArray(f)&&dn(f)||(a.isFileList(f)||a.endsWith(m,"[]"))&&(R=a.toArray(f)))return m=lt(m),R.forEach(function(y,C){!(a.isUndefined(y)||y===null)&&t.append(i===!0?je([m],C,o):i===null?m:m+"[]",l(y))}),!1}return Ae(f)?!0:(t.append(je(h,m,o),l(f)),!1)}const p=[],S=Object.assign(hn,{defaultVisitor:u,convertValue:l,isVisitable:Ae});function N(f,m){if(!a.isUndefined(f)){if(p.indexOf(f)!==-1)throw Error("Circular reference detected in "+m.join("."));p.push(f),a.forEach(f,function(R,I){(!(a.isUndefined(R)||R===null)&&r.call(t,R,a.isString(I)?I.trim():I,m,S))===!0&&N(R,m?m.concat(I):[I])}),p.pop()}}if(!a.isObject(e))throw new TypeError("data must be an object");return N(e),t}function Me(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(s){return t[s]})}function _e(e,t){this._pairs=[],e&&Se(e,this,t)}const ft=_e.prototype;ft.append=function(t,n){this._pairs.push([t,n])};ft.toString=function(t){const n=t?function(s){return t.call(this,s,Me)}:Me;return this._pairs.map(function(r){return n(r[0])+"="+n(r[1])},"").join("&")};function pn(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+")}function dt(e,t,n){if(!t)return e;const s=n&&n.encode||pn;a.isFunction(n)&&(n={serialize:n});const r=n&&n.serialize;let o;if(r?o=r(t,n):o=a.isURLSearchParams(t)?t.toString():new _e(t,n).toString(s),o){const i=e.indexOf("#");i!==-1&&(e=e.slice(0,i)),e+=(e.indexOf("?")===-1?"?":"&")+o}return e}class ve{constructor(){this.handlers=[]}use(t,n,s){return this.handlers.push({fulfilled:t,rejected:n,synchronous:s?s.synchronous:!1,runWhen:s?s.runWhen:null}),this.handlers.length-1}eject(t){this.handlers[t]&&(this.handlers[t]=null)}clear(){this.handlers&&(this.handlers=[])}forEach(t){a.forEach(this.handlers,function(s){s!==null&&t(s)})}}const ht={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},mn=typeof URLSearchParams<"u"?URLSearchParams:_e,En=typeof FormData<"u"?FormData:null,Sn=typeof Blob<"u"?Blob:null,Tn={isBrowser:!0,classes:{URLSearchParams:mn,FormData:En,Blob:Sn},protocols:["http","https","file","blob","url","data"]},De=typeof window<"u"&&typeof document<"u",ge=typeof navigator=="object"&&navigator||void 0,Rn=De&&(!ge||["ReactNative","NativeScript","NS"].indexOf(ge.product)<0),bn=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",yn=De&&window.location.href||"http://localhost",wn=Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:De,hasStandardBrowserEnv:Rn,hasStandardBrowserWebWorkerEnv:bn,navigator:ge,origin:yn},Symbol.toStringTag,{value:"Module"})),g={...wn,...Tn};function On(e,t){return Se(e,new g.classes.URLSearchParams,{visitor:function(n,s,r,o){return g.isNode&&a.isBuffer(n)?(this.append(s,n.toString("base64")),!1):o.defaultVisitor.apply(this,arguments)},...t})}function Nn(e){return a.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function An(e){const t={},n=Object.keys(e);let s;const r=n.length;let o;for(s=0;s<r;s++)o=n[s],t[o]=e[o];return t}function pt(e){function t(n,s,r,o){let i=n[o++];if(i==="__proto__")return!0;const c=Number.isFinite(+i),d=o>=n.length;return i=!i&&a.isArray(r)?r.length:i,d?(a.hasOwnProp(r,i)?r[i]=[r[i],s]:r[i]=s,!c):((!r[i]||!a.isObject(r[i]))&&(r[i]=[]),t(n,s,r[i],o)&&a.isArray(r[i])&&(r[i]=An(r[i])),!c)}if(a.isFormData(e)&&a.isFunction(e.entries)){const n={};return a.forEachEntry(e,(s,r)=>{t(Nn(s),r,n,0)}),n}return null}function gn(e,t,n){if(a.isString(e))try{return(t||JSON.parse)(e),a.trim(e)}catch(s){if(s.name!=="SyntaxError")throw s}return(n||JSON.stringify)(e)}const se={transitional:ht,adapter:["xhr","http","fetch"],transformRequest:[function(t,n){const s=n.getContentType()||"",r=s.indexOf("application/json")>-1,o=a.isObject(t);if(o&&a.isHTMLForm(t)&&(t=new FormData(t)),a.isFormData(t))return r?JSON.stringify(pt(t)):t;if(a.isArrayBuffer(t)||a.isBuffer(t)||a.isStream(t)||a.isFile(t)||a.isBlob(t)||a.isReadableStream(t))return t;if(a.isArrayBufferView(t))return t.buffer;if(a.isURLSearchParams(t))return n.setContentType("application/x-www-form-urlencoded;charset=utf-8",!1),t.toString();let c;if(o){if(s.indexOf("application/x-www-form-urlencoded")>-1)return On(t,this.formSerializer).toString();if((c=a.isFileList(t))||s.indexOf("multipart/form-data")>-1){const d=this.env&&this.env.FormData;return Se(c?{"files[]":t}:t,d&&new d,this.formSerializer)}}return o||r?(n.setContentType("application/json",!1),gn(t)):t}],transformResponse:[function(t){const n=this.transitional||se.transitional,s=n&&n.forcedJSONParsing,r=this.responseType==="json";if(a.isResponse(t)||a.isReadableStream(t))return t;if(t&&a.isString(t)&&(s&&!this.responseType||r)){const i=!(n&&n.silentJSONParsing)&&r;try{return JSON.parse(t,this.parseReviver)}catch(c){if(i)throw c.name==="SyntaxError"?E.from(c,E.ERR_BAD_RESPONSE,this,null,this.response):c}}return t}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:g.classes.FormData,Blob:g.classes.Blob},validateStatus:function(t){return t>=200&&t<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};a.forEach(["delete","get","head","post","put","patch"],e=>{se.headers[e]={}});const Cn=a.toObjectSet(["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"]),Un=e=>{const t={};let n,s,r;return e&&e.split(`
|
|
2
|
+
`).forEach(function(i){r=i.indexOf(":"),n=i.substring(0,r).trim().toLowerCase(),s=i.substring(r+1).trim(),!(!n||t[n]&&Cn[n])&&(n==="set-cookie"?t[n]?t[n].push(s):t[n]=[s]:t[n]=t[n]?t[n]+", "+s:s)}),t},qe=Symbol("internals");function Z(e){return e&&String(e).trim().toLowerCase()}function ue(e){return e===!1||e==null?e:a.isArray(e)?e.map(ue):String(e)}function _n(e){const t=Object.create(null),n=/([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;let s;for(;s=n.exec(e);)t[s[1]]=s[2];return t}const Dn=e=>/^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(e.trim());function ye(e,t,n,s,r){if(a.isFunction(s))return s.call(this,t,n);if(r&&(t=n),!!a.isString(t)){if(a.isString(s))return t.indexOf(s)!==-1;if(a.isRegExp(s))return s.test(t)}}function In(e){return e.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,(t,n,s)=>n.toUpperCase()+s)}function Fn(e,t){const n=a.toCamelCase(" "+t);["get","set","has"].forEach(s=>{Object.defineProperty(e,s+n,{value:function(r,o,i){return this[s].call(this,t,r,o,i)},configurable:!0})})}let D=class{constructor(t){t&&this.set(t)}set(t,n,s){const r=this;function o(c,d,l){const u=Z(d);if(!u)throw new Error("header name must be a non-empty string");const p=a.findKey(r,u);(!p||r[p]===void 0||l===!0||l===void 0&&r[p]!==!1)&&(r[p||d]=ue(c))}const i=(c,d)=>a.forEach(c,(l,u)=>o(l,u,d));if(a.isPlainObject(t)||t instanceof this.constructor)i(t,n);else if(a.isString(t)&&(t=t.trim())&&!Dn(t))i(Un(t),n);else if(a.isObject(t)&&a.isIterable(t)){let c={},d,l;for(const u of t){if(!a.isArray(u))throw TypeError("Object iterator must return a key-value pair");c[l=u[0]]=(d=c[l])?a.isArray(d)?[...d,u[1]]:[d,u[1]]:u[1]}i(c,n)}else t!=null&&o(n,t,s);return this}get(t,n){if(t=Z(t),t){const s=a.findKey(this,t);if(s){const r=this[s];if(!n)return r;if(n===!0)return _n(r);if(a.isFunction(n))return n.call(this,r,s);if(a.isRegExp(n))return n.exec(r);throw new TypeError("parser must be boolean|regexp|function")}}}has(t,n){if(t=Z(t),t){const s=a.findKey(this,t);return!!(s&&this[s]!==void 0&&(!n||ye(this,this[s],s,n)))}return!1}delete(t,n){const s=this;let r=!1;function o(i){if(i=Z(i),i){const c=a.findKey(s,i);c&&(!n||ye(s,s[c],c,n))&&(delete s[c],r=!0)}}return a.isArray(t)?t.forEach(o):o(t),r}clear(t){const n=Object.keys(this);let s=n.length,r=!1;for(;s--;){const o=n[s];(!t||ye(this,this[o],o,t,!0))&&(delete this[o],r=!0)}return r}normalize(t){const n=this,s={};return a.forEach(this,(r,o)=>{const i=a.findKey(s,o);if(i){n[i]=ue(r),delete n[o];return}const c=t?In(o):String(o).trim();c!==o&&delete n[o],n[c]=ue(r),s[c]=!0}),this}concat(...t){return this.constructor.concat(this,...t)}toJSON(t){const n=Object.create(null);return a.forEach(this,(s,r)=>{s!=null&&s!==!1&&(n[r]=t&&a.isArray(s)?s.join(", "):s)}),n}[Symbol.iterator](){return Object.entries(this.toJSON())[Symbol.iterator]()}toString(){return Object.entries(this.toJSON()).map(([t,n])=>t+": "+n).join(`
|
|
3
|
+
`)}getSetCookie(){return this.get("set-cookie")||[]}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(t){return t instanceof this?t:new this(t)}static concat(t,...n){const s=new this(t);return n.forEach(r=>s.set(r)),s}static accessor(t){const s=(this[qe]=this[qe]={accessors:{}}).accessors,r=this.prototype;function o(i){const c=Z(i);s[c]||(Fn(r,i),s[c]=!0)}return a.isArray(t)?t.forEach(o):o(t),this}};D.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]);a.reduceDescriptors(D.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(s){this[n]=s}}});a.freezeMethods(D);function we(e,t){const n=this||se,s=t||n,r=D.from(s.headers);let o=s.data;return a.forEach(e,function(c){o=c.call(n,o,r.normalize(),t?t.status:void 0)}),r.normalize(),o}function mt(e){return!!(e&&e.__CANCEL__)}function Q(e,t,n){E.call(this,e??"canceled",E.ERR_CANCELED,t,n),this.name="CanceledError"}a.inherits(Q,E,{__CANCEL__:!0});function Et(e,t,n){const s=n.config.validateStatus;!n.status||!s||s(n.status)?e(n):t(new E("Request failed with status code "+n.status,[E.ERR_BAD_REQUEST,E.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))}function Ln(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function xn(e,t){e=e||10;const n=new Array(e),s=new Array(e);let r=0,o=0,i;return t=t!==void 0?t:1e3,function(d){const l=Date.now(),u=s[o];i||(i=l),n[r]=d,s[r]=l;let p=o,S=0;for(;p!==r;)S+=n[p++],p=p%e;if(r=(r+1)%e,r===o&&(o=(o+1)%e),l-i<t)return;const N=u&&l-u;return N?Math.round(S*1e3/N):void 0}}function Pn(e,t){let n=0,s=1e3/t,r,o;const i=(l,u=Date.now())=>{n=u,r=null,o&&(clearTimeout(o),o=null),e(...l)};return[(...l)=>{const u=Date.now(),p=u-n;p>=s?i(l,u):(r=l,o||(o=setTimeout(()=>{o=null,i(r)},s-p)))},()=>r&&i(r)]}const fe=(e,t,n=3)=>{let s=0;const r=xn(50,250);return Pn(o=>{const i=o.loaded,c=o.lengthComputable?o.total:void 0,d=i-s,l=r(d),u=i<=c;s=i;const p={loaded:i,total:c,progress:c?i/c:void 0,bytes:d,rate:l||void 0,estimated:l&&c&&u?(c-i)/l:void 0,event:o,lengthComputable:c!=null,[t?"download":"upload"]:!0};e(p)},n)},$e=(e,t)=>{const n=e!=null;return[s=>t[0]({lengthComputable:n,total:e,loaded:s}),t[1]]},Ge=e=>(...t)=>a.asap(()=>e(...t)),Bn=g.hasStandardBrowserEnv?((e,t)=>n=>(n=new URL(n,g.origin),e.protocol===n.protocol&&e.host===n.host&&(t||e.port===n.port)))(new URL(g.origin),g.navigator&&/(msie|trident)/i.test(g.navigator.userAgent)):()=>!0,kn=g.hasStandardBrowserEnv?{write(e,t,n,s,r,o,i){if(typeof document>"u")return;const c=[`${e}=${encodeURIComponent(t)}`];a.isNumber(n)&&c.push(`expires=${new Date(n).toUTCString()}`),a.isString(s)&&c.push(`path=${s}`),a.isString(r)&&c.push(`domain=${r}`),o===!0&&c.push("secure"),a.isString(i)&&c.push(`SameSite=${i}`),document.cookie=c.join("; ")},read(e){if(typeof document>"u")return null;const t=document.cookie.match(new RegExp("(?:^|; )"+e+"=([^;]*)"));return t?decodeURIComponent(t[1]):null},remove(e){this.write(e,"",Date.now()-864e5,"/")}}:{write(){},read(){return null},remove(){}};function Hn(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function jn(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function St(e,t,n){let s=!Hn(t);return e&&(s||n==!1)?jn(e,t):t}const ze=e=>e instanceof D?{...e}:e;function z(e,t){t=t||{};const n={};function s(l,u,p,S){return a.isPlainObject(l)&&a.isPlainObject(u)?a.merge.call({caseless:S},l,u):a.isPlainObject(u)?a.merge({},u):a.isArray(u)?u.slice():u}function r(l,u,p,S){if(a.isUndefined(u)){if(!a.isUndefined(l))return s(void 0,l,p,S)}else return s(l,u,p,S)}function o(l,u){if(!a.isUndefined(u))return s(void 0,u)}function i(l,u){if(a.isUndefined(u)){if(!a.isUndefined(l))return s(void 0,l)}else return s(void 0,u)}function c(l,u,p){if(p in t)return s(l,u);if(p in e)return s(void 0,l)}const d={url:o,method:o,data:o,baseURL:i,transformRequest:i,transformResponse:i,paramsSerializer:i,timeout:i,timeoutMessage:i,withCredentials:i,withXSRFToken:i,adapter:i,responseType:i,xsrfCookieName:i,xsrfHeaderName:i,onUploadProgress:i,onDownloadProgress:i,decompress:i,maxContentLength:i,maxBodyLength:i,beforeRedirect:i,transport:i,httpAgent:i,httpsAgent:i,cancelToken:i,socketPath:i,responseEncoding:i,validateStatus:c,headers:(l,u,p)=>r(ze(l),ze(u),p,!0)};return a.forEach(Object.keys({...e,...t}),function(u){const p=d[u]||r,S=p(e[u],t[u],u);a.isUndefined(S)&&p!==c||(n[u]=S)}),n}const Tt=e=>{const t=z({},e);let{data:n,withXSRFToken:s,xsrfHeaderName:r,xsrfCookieName:o,headers:i,auth:c}=t;if(t.headers=i=D.from(i),t.url=dt(St(t.baseURL,t.url,t.allowAbsoluteUrls),e.params,e.paramsSerializer),c&&i.set("Authorization","Basic "+btoa((c.username||"")+":"+(c.password?unescape(encodeURIComponent(c.password)):""))),a.isFormData(n)){if(g.hasStandardBrowserEnv||g.hasStandardBrowserWebWorkerEnv)i.setContentType(void 0);else if(a.isFunction(n.getHeaders)){const d=n.getHeaders(),l=["content-type","content-length"];Object.entries(d).forEach(([u,p])=>{l.includes(u.toLowerCase())&&i.set(u,p)})}}if(g.hasStandardBrowserEnv&&(s&&a.isFunction(s)&&(s=s(t)),s||s!==!1&&Bn(t.url))){const d=r&&o&&kn.read(o);d&&i.set(r,d)}return t},Mn=typeof XMLHttpRequest<"u",vn=Mn&&function(e){return new Promise(function(n,s){const r=Tt(e);let o=r.data;const i=D.from(r.headers).normalize();let{responseType:c,onUploadProgress:d,onDownloadProgress:l}=r,u,p,S,N,f;function m(){N&&N(),f&&f(),r.cancelToken&&r.cancelToken.unsubscribe(u),r.signal&&r.signal.removeEventListener("abort",u)}let h=new XMLHttpRequest;h.open(r.method.toUpperCase(),r.url,!0),h.timeout=r.timeout;function R(){if(!h)return;const y=D.from("getAllResponseHeaders"in h&&h.getAllResponseHeaders()),L={data:!c||c==="text"||c==="json"?h.responseText:h.response,status:h.status,statusText:h.statusText,headers:y,config:e,request:h};Et(function(F){n(F),m()},function(F){s(F),m()},L),h=null}"onloadend"in h?h.onloadend=R:h.onreadystatechange=function(){!h||h.readyState!==4||h.status===0&&!(h.responseURL&&h.responseURL.indexOf("file:")===0)||setTimeout(R)},h.onabort=function(){h&&(s(new E("Request aborted",E.ECONNABORTED,e,h)),h=null)},h.onerror=function(C){const L=C&&C.message?C.message:"Network Error",v=new E(L,E.ERR_NETWORK,e,h);v.event=C||null,s(v),h=null},h.ontimeout=function(){let C=r.timeout?"timeout of "+r.timeout+"ms exceeded":"timeout exceeded";const L=r.transitional||ht;r.timeoutErrorMessage&&(C=r.timeoutErrorMessage),s(new E(C,L.clarifyTimeoutError?E.ETIMEDOUT:E.ECONNABORTED,e,h)),h=null},o===void 0&&i.setContentType(null),"setRequestHeader"in h&&a.forEach(i.toJSON(),function(C,L){h.setRequestHeader(L,C)}),a.isUndefined(r.withCredentials)||(h.withCredentials=!!r.withCredentials),c&&c!=="json"&&(h.responseType=r.responseType),l&&([S,f]=fe(l,!0),h.addEventListener("progress",S)),d&&h.upload&&([p,N]=fe(d),h.upload.addEventListener("progress",p),h.upload.addEventListener("loadend",N)),(r.cancelToken||r.signal)&&(u=y=>{h&&(s(!y||y.type?new Q(null,e,h):y),h.abort(),h=null)},r.cancelToken&&r.cancelToken.subscribe(u),r.signal&&(r.signal.aborted?u():r.signal.addEventListener("abort",u)));const I=Ln(r.url);if(I&&g.protocols.indexOf(I)===-1){s(new E("Unsupported protocol "+I+":",E.ERR_BAD_REQUEST,e));return}h.send(o||null)})},qn=(e,t)=>{const{length:n}=e=e?e.filter(Boolean):[];if(t||n){let s=new AbortController,r;const o=function(l){if(!r){r=!0,c();const u=l instanceof Error?l:this.reason;s.abort(u instanceof E?u:new Q(u instanceof Error?u.message:u))}};let i=t&&setTimeout(()=>{i=null,o(new E(`timeout ${t} of ms exceeded`,E.ETIMEDOUT))},t);const c=()=>{e&&(i&&clearTimeout(i),i=null,e.forEach(l=>{l.unsubscribe?l.unsubscribe(o):l.removeEventListener("abort",o)}),e=null)};e.forEach(l=>l.addEventListener("abort",o));const{signal:d}=s;return d.unsubscribe=()=>a.asap(c),d}},$n=function*(e,t){let n=e.byteLength;if(n<t){yield e;return}let s=0,r;for(;s<n;)r=s+t,yield e.slice(s,r),s=r},Gn=async function*(e,t){for await(const n of zn(e))yield*$n(n,t)},zn=async function*(e){if(e[Symbol.asyncIterator]){yield*e;return}const t=e.getReader();try{for(;;){const{done:n,value:s}=await t.read();if(n)break;yield s}}finally{await t.cancel()}},Je=(e,t,n,s)=>{const r=Gn(e,t);let o=0,i,c=d=>{i||(i=!0,s&&s(d))};return new ReadableStream({async pull(d){try{const{done:l,value:u}=await r.next();if(l){c(),d.close();return}let p=u.byteLength;if(n){let S=o+=p;n(S)}d.enqueue(new Uint8Array(u))}catch(l){throw c(l),l}},cancel(d){return c(d),r.return()}},{highWaterMark:2})},Ve=64*1024,{isFunction:ae}=a,Jn=(({Request:e,Response:t})=>({Request:e,Response:t}))(a.global),{ReadableStream:We,TextEncoder:Ke}=a.global,Xe=(e,...t)=>{try{return!!e(...t)}catch{return!1}},Vn=e=>{e=a.merge.call({skipUndefined:!0},Jn,e);const{fetch:t,Request:n,Response:s}=e,r=t?ae(t):typeof fetch=="function",o=ae(n),i=ae(s);if(!r)return!1;const c=r&&ae(We),d=r&&(typeof Ke=="function"?(f=>m=>f.encode(m))(new Ke):async f=>new Uint8Array(await new n(f).arrayBuffer())),l=o&&c&&Xe(()=>{let f=!1;const m=new n(g.origin,{body:new We,method:"POST",get duplex(){return f=!0,"half"}}).headers.has("Content-Type");return f&&!m}),u=i&&c&&Xe(()=>a.isReadableStream(new s("").body)),p={stream:u&&(f=>f.body)};r&&["text","arrayBuffer","blob","formData","stream"].forEach(f=>{!p[f]&&(p[f]=(m,h)=>{let R=m&&m[f];if(R)return R.call(m);throw new E(`Response type '${f}' is not supported`,E.ERR_NOT_SUPPORT,h)})});const S=async f=>{if(f==null)return 0;if(a.isBlob(f))return f.size;if(a.isSpecCompliantForm(f))return(await new n(g.origin,{method:"POST",body:f}).arrayBuffer()).byteLength;if(a.isArrayBufferView(f)||a.isArrayBuffer(f))return f.byteLength;if(a.isURLSearchParams(f)&&(f=f+""),a.isString(f))return(await d(f)).byteLength},N=async(f,m)=>{const h=a.toFiniteNumber(f.getContentLength());return h??S(m)};return async f=>{let{url:m,method:h,data:R,signal:I,cancelToken:y,timeout:C,onDownloadProgress:L,onUploadProgress:v,responseType:F,headers:Re,withCredentials:re="same-origin",fetchOptions:Fe}=Tt(f),Le=t||fetch;F=F?(F+"").toLowerCase():"text";let oe=qn([I,y&&y.toAbortSignal()],C),Y=null;const q=oe&&oe.unsubscribe&&(()=>{oe.unsubscribe()});let xe;try{if(v&&l&&h!=="get"&&h!=="head"&&(xe=await N(Re,R))!==0){let M=new n(m,{method:"POST",body:R,duplex:"half"}),V;if(a.isFormData(R)&&(V=M.headers.get("content-type"))&&Re.setContentType(V),M.body){const[be,ie]=$e(xe,fe(Ge(v)));R=Je(M.body,Ve,be,ie)}}a.isString(re)||(re=re?"include":"omit");const B=o&&"credentials"in n.prototype,Pe={...Fe,signal:oe,method:h.toUpperCase(),headers:Re.normalize().toJSON(),body:R,duplex:"half",credentials:B?re:void 0};Y=o&&new n(m,Pe);let j=await(o?Le(Y,Fe):Le(m,Pe));const Be=u&&(F==="stream"||F==="response");if(u&&(L||Be&&q)){const M={};["status","statusText","headers"].forEach(ke=>{M[ke]=j[ke]});const V=a.toFiniteNumber(j.headers.get("content-length")),[be,ie]=L&&$e(V,fe(Ge(L),!0))||[];j=new s(Je(j.body,Ve,be,()=>{ie&&ie(),q&&q()}),M)}F=F||"text";let Nt=await p[a.findKey(p,F)||"text"](j,f);return!Be&&q&&q(),await new Promise((M,V)=>{Et(M,V,{data:Nt,headers:D.from(j.headers),status:j.status,statusText:j.statusText,config:f,request:Y})})}catch(B){throw q&&q(),B&&B.name==="TypeError"&&/Load failed|fetch/i.test(B.message)?Object.assign(new E("Network Error",E.ERR_NETWORK,f,Y),{cause:B.cause||B}):E.from(B,B&&B.code,f,Y)}}},Wn=new Map,Rt=e=>{let t=e&&e.env||{};const{fetch:n,Request:s,Response:r}=t,o=[s,r,n];let i=o.length,c=i,d,l,u=Wn;for(;c--;)d=o[c],l=u.get(d),l===void 0&&u.set(d,l=c?new Map:Vn(t)),u=l;return l};Rt();const Ie={http:fn,xhr:vn,fetch:{get:Rt}};a.forEach(Ie,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const Qe=e=>`- ${e}`,Kn=e=>a.isFunction(e)||e===null||e===!1;function Xn(e,t){e=a.isArray(e)?e:[e];const{length:n}=e;let s,r;const o={};for(let i=0;i<n;i++){s=e[i];let c;if(r=s,!Kn(s)&&(r=Ie[(c=String(s)).toLowerCase()],r===void 0))throw new E(`Unknown adapter '${c}'`);if(r&&(a.isFunction(r)||(r=r.get(t))))break;o[c||"#"+i]=r}if(!r){const i=Object.entries(o).map(([d,l])=>`adapter ${d} `+(l===!1?"is not supported by the environment":"is not available in the build"));let c=n?i.length>1?`since :
|
|
4
|
+
`+i.map(Qe).join(`
|
|
5
|
+
`):" "+Qe(i[0]):"as no adapter specified";throw new E("There is no suitable adapter to dispatch the request "+c,"ERR_NOT_SUPPORT")}return r}const bt={getAdapter:Xn,adapters:Ie};function Oe(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new Q(null,e)}function Ye(e){return Oe(e),e.headers=D.from(e.headers),e.data=we.call(e,e.transformRequest),["post","put","patch"].indexOf(e.method)!==-1&&e.headers.setContentType("application/x-www-form-urlencoded",!1),bt.getAdapter(e.adapter||se.adapter,e)(e).then(function(s){return Oe(e),s.data=we.call(e,e.transformResponse,s),s.headers=D.from(s.headers),s},function(s){return mt(s)||(Oe(e),s&&s.response&&(s.response.data=we.call(e,e.transformResponse,s.response),s.response.headers=D.from(s.response.headers))),Promise.reject(s)})}const yt="1.13.2",Te={};["object","boolean","number","function","string","symbol"].forEach((e,t)=>{Te[e]=function(s){return typeof s===e||"a"+(t<1?"n ":" ")+e}});const Ze={};Te.transitional=function(t,n,s){function r(o,i){return"[Axios v"+yt+"] Transitional option '"+o+"'"+i+(s?". "+s:"")}return(o,i,c)=>{if(t===!1)throw new E(r(i," has been removed"+(n?" in "+n:"")),E.ERR_DEPRECATED);return n&&!Ze[i]&&(Ze[i]=!0,console.warn(r(i," has been deprecated since v"+n+" and will be removed in the near future"))),t?t(o,i,c):!0}};Te.spelling=function(t){return(n,s)=>(console.warn(`${s} is likely a misspelling of ${t}`),!0)};function Qn(e,t,n){if(typeof e!="object")throw new E("options must be an object",E.ERR_BAD_OPTION_VALUE);const s=Object.keys(e);let r=s.length;for(;r-- >0;){const o=s[r],i=t[o];if(i){const c=e[o],d=c===void 0||i(c,o,e);if(d!==!0)throw new E("option "+o+" must be "+d,E.ERR_BAD_OPTION_VALUE);continue}if(n!==!0)throw new E("Unknown option "+o,E.ERR_BAD_OPTION)}}const le={assertOptions:Qn,validators:Te},k=le.validators;let G=class{constructor(t){this.defaults=t||{},this.interceptors={request:new ve,response:new ve}}async request(t,n){try{return await this._request(t,n)}catch(s){if(s instanceof Error){let r={};Error.captureStackTrace?Error.captureStackTrace(r):r=new Error;const o=r.stack?r.stack.replace(/^.+\n/,""):"";try{s.stack?o&&!String(s.stack).endsWith(o.replace(/^.+\n.+\n/,""))&&(s.stack+=`
|
|
6
|
+
`+o):s.stack=o}catch{}}throw s}}_request(t,n){typeof t=="string"?(n=n||{},n.url=t):n=t||{},n=z(this.defaults,n);const{transitional:s,paramsSerializer:r,headers:o}=n;s!==void 0&&le.assertOptions(s,{silentJSONParsing:k.transitional(k.boolean),forcedJSONParsing:k.transitional(k.boolean),clarifyTimeoutError:k.transitional(k.boolean)},!1),r!=null&&(a.isFunction(r)?n.paramsSerializer={serialize:r}:le.assertOptions(r,{encode:k.function,serialize:k.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),le.assertOptions(n,{baseUrl:k.spelling("baseURL"),withXsrfToken:k.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i=o&&a.merge(o.common,o[n.method]);o&&a.forEach(["delete","get","head","post","put","patch","common"],f=>{delete o[f]}),n.headers=D.concat(i,o);const c=[];let d=!0;this.interceptors.request.forEach(function(m){typeof m.runWhen=="function"&&m.runWhen(n)===!1||(d=d&&m.synchronous,c.unshift(m.fulfilled,m.rejected))});const l=[];this.interceptors.response.forEach(function(m){l.push(m.fulfilled,m.rejected)});let u,p=0,S;if(!d){const f=[Ye.bind(this),void 0];for(f.unshift(...c),f.push(...l),S=f.length,u=Promise.resolve(n);p<S;)u=u.then(f[p++],f[p++]);return u}S=c.length;let N=n;for(;p<S;){const f=c[p++],m=c[p++];try{N=f(N)}catch(h){m.call(this,h);break}}try{u=Ye.call(this,N)}catch(f){return Promise.reject(f)}for(p=0,S=l.length;p<S;)u=u.then(l[p++],l[p++]);return u}getUri(t){t=z(this.defaults,t);const n=St(t.baseURL,t.url,t.allowAbsoluteUrls);return dt(n,t.params,t.paramsSerializer)}};a.forEach(["delete","get","head","options"],function(t){G.prototype[t]=function(n,s){return this.request(z(s||{},{method:t,url:n,data:(s||{}).data}))}});a.forEach(["post","put","patch"],function(t){function n(s){return function(o,i,c){return this.request(z(c||{},{method:t,headers:s?{"Content-Type":"multipart/form-data"}:{},url:o,data:i}))}}G.prototype[t]=n(),G.prototype[t+"Form"]=n(!0)});let Yn=class wt{constructor(t){if(typeof t!="function")throw new TypeError("executor must be a function.");let n;this.promise=new Promise(function(o){n=o});const s=this;this.promise.then(r=>{if(!s._listeners)return;let o=s._listeners.length;for(;o-- >0;)s._listeners[o](r);s._listeners=null}),this.promise.then=r=>{let o;const i=new Promise(c=>{s.subscribe(c),o=c}).then(r);return i.cancel=function(){s.unsubscribe(o)},i},t(function(o,i,c){s.reason||(s.reason=new Q(o,i,c),n(s.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(t){if(this.reason){t(this.reason);return}this._listeners?this._listeners.push(t):this._listeners=[t]}unsubscribe(t){if(!this._listeners)return;const n=this._listeners.indexOf(t);n!==-1&&this._listeners.splice(n,1)}toAbortSignal(){const t=new AbortController,n=s=>{t.abort(s)};return this.subscribe(n),t.signal.unsubscribe=()=>this.unsubscribe(n),t.signal}static source(){let t;return{token:new wt(function(r){t=r}),cancel:t}}};function Zn(e){return function(n){return e.apply(null,n)}}function es(e){return a.isObject(e)&&e.isAxiosError===!0}const Ce={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511,WebServerIsDown:521,ConnectionTimedOut:522,OriginIsUnreachable:523,TimeoutOccurred:524,SslHandshakeFailed:525,InvalidSslCertificate:526};Object.entries(Ce).forEach(([e,t])=>{Ce[t]=e});function Ot(e){const t=new G(e),n=et(G.prototype.request,t);return a.extend(n,G.prototype,t,{allOwnKeys:!0}),a.extend(n,t,null,{allOwnKeys:!0}),n.create=function(r){return Ot(z(e,r))},n}const T=Ot(se);T.Axios=G;T.CanceledError=Q;T.CancelToken=Yn;T.isCancel=mt;T.VERSION=yt;T.toFormData=Se;T.AxiosError=E;T.Cancel=T.CanceledError;T.all=function(t){return Promise.all(t)};T.spread=Zn;T.isAxiosError=es;T.mergeConfig=z;T.AxiosHeaders=D;T.formToJSON=e=>pt(a.isHTMLForm(e)?new FormData(e):e);T.getAdapter=bt.getAdapter;T.HttpStatusCode=Ce;T.default=T;const{Axios:hs,AxiosError:ps,CanceledError:ms,isCancel:Es,CancelToken:Ss,VERSION:Ts,all:Rs,Cancel:bs,isAxiosError:ys,spread:ws,toFormData:Os,AxiosHeaders:Ns,HttpStatusCode:As,formToJSON:gs,getAdapter:Cs,mergeConfig:Us}=T,de="JOYTALK_TOKEN";var x=(e=>(e.SEND="1",e.WITHDRAW="2",e.EDIT="3",e.SYSTEM_NOTICE="4",e.TRANSFER="5",e.INBOUND="6",e.REPLY="7",e.UNBIND="8",e))(x||{}),H=(e=>(e.TEXT="1",e.IMAGE="2",e.VIDEO="3",e.FILE="4",e.FAQ="5",e))(H||{}),U=(e=>(e[e.CONNECT_SUCCESS=200]="CONNECT_SUCCESS",e[e.CONNECT_FAILED=40001]="CONNECT_FAILED",e[e.TRANSFER_CUSTOMER_SUCCESS=201]="TRANSFER_CUSTOMER_SUCCESS",e[e.TRANSFER_TO_CUSTOMER_SUCCESS=202]="TRANSFER_TO_CUSTOMER_SUCCESS",e[e.TRANSFER_USER_SUCCESS=203]="TRANSFER_USER_SUCCESS",e[e.TRANSFER_FAIL=50001]="TRANSFER_FAIL",e[e.MATCH_FAIL=50002]="MATCH_FAIL",e[e.MATCH_INFO=50005]="MATCH_INFO",e[e.MATCH_SUCCESS=50006]="MATCH_SUCCESS",e[e.RETRACT=204]="RETRACT",e[e.RETRACT_FAIL=50003]="RETRACT_FAIL",e[e.EDIT=205]="EDIT",e[e.EDIT_FAIL=50004]="EDIT_FAIL",e[e.COMMON_FAIL=5e4]="COMMON_FAIL",e[e.SEND_SUCCESS=206]="SEND_SUCCESS",e[e.SEND_CALLBACK=207]="SEND_CALLBACK",e[e.CHANGE_CHAT_STATUS=208]="CHANGE_CHAT_STATUS",e[e.REMATCH=60001]="REMATCH",e))(U||{}),he=(e=>(e.CUSTOMER="1",e.USER="2",e.ANONYMOUS="3",e))(he||{}),w=(e=>(e.CONNECTED="connected",e.DISCONNECTED="disconnected",e.ERROR="error",e.MESSAGE="message",e.STATUS_CHANGE="status_change",e.HEARTBEAT_TIMEOUT="heartbeat_timeout",e))(w||{}),A=(e=>(e.DISCONNECTED="disconnected",e.CONNECTING="connecting",e.CONNECTED="connected",e.RECONNECTING="reconnecting",e.ERROR="error",e))(A||{}),O=(e=>(e.UNBOUND="1",e.BINDING="2",e.BOUND="3",e.UNBIND="4",e))(O||{});const b={UNINITIALIZED:{code:10001,msg:"未初始化"},DISCONNECTED:{code:10002,msg:"未连接"},NO_CUSTOMER_SERVICE:{code:10003,msg:"未分配客服"},MESSAGE_SEND_FAIL:{code:10004,msg:"消息发送失败"},DATA_PARSING_ERROR:{code:10005,msg:"数据解析异常"},FILE_NOT_EXIST:{code:10006,msg:"文件不存在"},FILE_PARSING_ERROR:{code:10007,msg:"文件解析异常"},AUTH_INFO_ERROR:{code:10008,msg:"授权信息错误"},FILE_UPLOAD_FAIL:{code:10009,msg:"文件上传失败"},PARAMETER_ERROR:{code:10010,msg:"参数异常"},EMPTY_DATA:{code:10011,msg:"数据为空"}},J=T.create({baseURL:"http://dev-joytalk-api.halaladmin.vip",timeout:6e5});J.interceptors.request.use(e=>{if(!e.noAuth){const t=localStorage.getItem(de);if(!t)return Promise.reject(b.UNINITIALIZED);e.headers.Authorization=`Bearer ${t}`}return delete e.noAuth,e},e=>Promise.reject(e));J.interceptors.response.use(e=>e.data.code!==200?Promise.reject(e):Promise.resolve(e.data),e=>Promise.reject(e));const ts=e=>J.post("/api/open-auth/obs/v1/ObsService/GetObsAuthInfo",e),ns=e=>T.post("https://joytalk-fat.obs.ap-southeast-1.myhuaweicloud.com",e,{headers:{"Content-Type":"multipart/form-data"}}),ss=e=>J.post("/api/open-auth/open_consultation/v1/OpenConsultationService/GetConsultationList",e),rs=e=>J.get("/api/open-auth/faq/v1/FaqService/GetFaqList",{params:e}),os=()=>J.get("/api/open-auth/user/v1/UserService/GetUserInfo"),is=e=>J.post("/api/open-auth/user/v1/UserService/GetUserHistoryMessages",e);class as{events=new Map;on(t,n){this.events.has(t)||this.events.set(t,[]),this.events.get(t).push(n)}off(t,n){const s=this.events.get(t);if(s){const r=s.indexOf(n);r>-1&&s.splice(r,1)}}emit(t,n){const s=this.events.get(t);s&&s.forEach(r=>{try{r(n)}catch(o){console.error(`事件回调执行错误 [${t}]:`,o)}})}removeAllListeners(t){t?this.events.delete(t):this.events.clear()}once(t,n){const s=r=>{n(r),this.off(t,s)};this.on(t,s)}}function cs(e){return`ws://dev-joytalk-api.halaladmin.vip/api/ws?Authorization=${e}`}function us(){return Date.now().toString(36)+Math.random().toString(36).slice(2)}const ls="https://joytalk-fat.obs.ap-southeast-1.myhuaweicloud.com/";class W extends as{config={token:"",autoReconnect:!0,reconnectInterval:3e3,maxReconnectAttempts:5,responseTimeout:1e4};ws=null;status=A.DISCONNECTED;reconnectTimer=null;reconnectAttempts=0;heartbeatTimeoutTimer=null;lastHeartbeatTime=0;consultationTypeId="";OBS_URL=ls;sessionData=null;userInfo=null;static instance=null;bindStatus=O.UNBOUND;constructor(){if(super(),W.instance)return W.instance;W.instance=this}async init(t){if(!t.token)return localStorage.removeItem(de),Promise.reject(b.PARAMETER_ERROR);this.config=Object.assign(this.config,t),localStorage.setItem(de,this.config.token)}connect(t){return this.consultationTypeId=t,new Promise((n,s)=>{if(!this.config.token)return s(b.UNINITIALIZED);if(this.status===A.CONNECTED)return n();if(this.status!==A.CONNECTING){this.setStatus(A.CONNECTING);try{const r=cs(this.config.token);this.ws=new WebSocket(r),this.ws.onopen=()=>{this.reconnectAttempts=0,this.setStatus(A.CONNECTED),this.emit(w.CONNECTED),n()},this.ws.onmessage=o=>{try{this.handleMessage(o.data)}catch(i){console.error("解析消息失败:",i)}},this.ws.onerror=o=>{console.error("连接错误:",o),this.setStatus(A.ERROR),this.emit(w.ERROR,o),s(o)},this.ws.onclose=()=>{this.setStatus(A.DISCONNECTED),this.emit(w.DISCONNECTED),this.config.autoReconnect&&this.reconnectAttempts<this.config.maxReconnectAttempts&&this.scheduleReconnect()}}catch(r){this.setStatus(A.ERROR),this.emit(w.ERROR,r),s(r)}}})}disconnect(){this.config.autoReconnect=!1,this.sessionData=null,this.bindStatus=O.UNBOUND,this.clearReconnectTimer(),this.heartbeatTimeoutTimer&&(clearTimeout(this.heartbeatTimeoutTimer),this.heartbeatTimeoutTimer=null),this.ws&&(this.ws.close(),this.ws=null),this.setStatus(A.DISCONNECTED)}async sendMessage(t,n,s=x.SEND){const r={msgType:s,data:t,toUid:this.sessionData?.cid,chatType:n,editId:void 0};if(this.status!==A.CONNECTED||!this.ws)if(this.ws&&this.status===A.DISCONNECTED){console.log("连接断开,尝试重新连接");try{await this.connect(this.consultationTypeId)}catch(o){throw console.error("重连失败:",o),b.DISCONNECTED}}else throw console.error(b.DISCONNECTED),b.DISCONNECTED;try{if(!this.ws)throw b.DISCONNECTED;return s===x.SEND?new Promise((o,i)=>{const c=us();r.ext=c;const d=setTimeout(()=>{this.off(c,l),i(b.MESSAGE_SEND_FAIL)},this.config.responseTimeout),l=u=>{clearTimeout(d),o({messageId:u,data:t})};this.once(c,l),this.ws.send(JSON.stringify(r))}):(this.ws.send(JSON.stringify(r)),{data:t})}catch(o){throw console.error("发送消息失败:",o),b.MESSAGE_SEND_FAIL}}async sendText(t){if(this.bindStatus===O.UNBIND&&(await this.sendMessage(this.consultationTypeId,void 0,x.INBOUND),await new Promise((n,s)=>{const r=setTimeout(()=>{clearTimeout(r),s(b.MESSAGE_SEND_FAIL)},this.config.responseTimeout);this.once(w.MESSAGE,o=>{o.code===U.REMATCH&&(clearTimeout(r),n(!0))})})),this.bindStatus!==O.BOUND)throw console.error(b.NO_CUSTOMER_SERVICE),b.NO_CUSTOMER_SERVICE;return this.sendMessage(t,H.TEXT)}async sendFile({file:t,thumbnailFile:n,chatType:s}){try{if(this.bindStatus===O.UNBIND&&(await this.sendMessage(this.consultationTypeId,void 0,x.INBOUND),await new Promise((c,d)=>{const l=setTimeout(()=>{clearTimeout(l),d(b.MESSAGE_SEND_FAIL)},this.config.responseTimeout);this.once(w.MESSAGE,u=>{u.code===U.REMATCH&&(clearTimeout(l),c(!0))})})),this.bindStatus!==O.BOUND)throw console.error(b.NO_CUSTOMER_SERVICE),b.NO_CUSTOMER_SERVICE;const[r,o]=await Promise.all([this.handleUploadFile(t),n?this.handleUploadFile(n):Promise.resolve(void 0)]),i={fileName:t.name,fileUrl:r,thumbnailUrl:o,fileSize:t.size};return this.sendMessage(JSON.stringify(i),s)}catch(r){throw console.error("上传文件失败:",r),r}}getStatus(){return this.status}isConnected(){return this.status===A.CONNECTED}handleMessage(t){if(t==="ping"){this.lastHeartbeatTime=Date.now(),this.heartbeatTimeoutTimer&&(clearTimeout(this.heartbeatTimeoutTimer),this.heartbeatTimeoutTimer=null),this.sendHeartbeat();return}if(t=JSON.parse(t),this.isMessage(t))try{const n=t.data?JSON.parse(t.data):t.data;switch(t.data=n,t.code){case U.CONNECT_SUCCESS:if(this.bindStatus===O.BOUND||this.bindStatus===O.BINDING)return;this.bindStatus=O.BINDING,this.sendMessage(this.consultationTypeId,void 0,x.INBOUND);break;case U.MATCH_INFO:case U.MATCH_SUCCESS:if(this.bindStatus===O.BOUND)return;this.sessionData=t.data,this.bindStatus===O.UNBIND?(this.bindStatus=O.BOUND,this.emit(w.MESSAGE,{...t,code:U.REMATCH})):(this.bindStatus=O.BOUND,this.getFaqList(),this.emit(w.MESSAGE,t));break;case U.TRANSFER_USER_SUCCESS:const s=t.data;this.sessionData={...this.sessionData,cid:s.cid,customerAvatar:s.customerAvatar,customerName:s.customerName,groupId:s.groupId,segmentId:s.segmentId,sessionId:s.sessionId,uid:s.uid},this.emit(w.MESSAGE,t);break;case U.SEND_SUCCESS:case U.EDIT:console.log("收到消息",t.data);const r=t.data;if(r.sessionId!==this.sessionData?.sessionId)return;r.contentType!==H.TEXT&&typeof r.content=="string"&&(r.content=JSON.parse(r.content),r.content?.fileUrl?.startsWith("http")||(r.content.fileUrl=this.OBS_URL+r.content.fileUrl),r.content?.thumbnailUrl?.startsWith("http")||(r.content.thumbnailUrl=this.OBS_URL+r.content.thumbnailUrl)),this.emit(w.MESSAGE,t);break;case U.SEND_CALLBACK:const o=t.ext,c=t.data.messageId;this.emit(o,c);break;default:this.emit(w.MESSAGE,t);break}}catch(n){console.error("解析消息失败:",n)}}isMessage(t){return typeof t=="object"&&t!==null&&"data"in t&&"msgType"in t&&"toUid"in t&&"chatType"in t&&"code"in t}setStatus(t){this.status!==t&&(this.status=t,this.emit(w.STATUS_CHANGE,t))}scheduleReconnect(){this.clearReconnectTimer(),this.reconnectAttempts++,this.setStatus(A.RECONNECTING),this.reconnectTimer=setTimeout(()=>{this.connect(this.consultationTypeId).catch(t=>{console.error("重连失败:",t)})},this.config.reconnectInterval)}clearReconnectTimer(){this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null)}sendHeartbeat(){if(!(this.status!==A.CONNECTED||!this.ws))try{this.ws.send("pong"),this.lastHeartbeatTime=Date.now(),this.heartbeatTimeoutTimer=setTimeout(()=>{Date.now()-this.lastHeartbeatTime>=this.config.responseTimeout&&(this.emit(w.HEARTBEAT_TIMEOUT),console.warn("心跳超时,尝试重连"),this.ws&&this.ws.close())},this.config.responseTimeout)}catch(t){console.error("发送心跳失败:",t)}}async getHistoryMessages({lastMsgId:t,size:n=50}){if(this.bindStatus!==O.BOUND)return Promise.reject(b.NO_CUSTOMER_SERVICE);const s=await is({sessionId:this.sessionData?.sessionId,lastMsgId:t,size:n}),r=s.data.list.map(o=>{let i=o.content;return o.contentType===H.TEXT?i=o.content:(i=JSON.parse(o.content),i?.fileUrl?.startsWith("http")||(i.fileUrl=this.OBS_URL+i.fileUrl),i?.thumbnailUrl?.startsWith("http")||(i.thumbnailUrl=this.OBS_URL+i.thumbnailUrl)),{...o,content:i}});return{hasMore:s.data.hasMore,list:r}}getConsultationList(t){return ss({entranceId:t})}handleUploadFile(t){return new Promise(async(n,s)=>{const r=t.name.split(".").pop(),o=await ts({ext:r||""}),{accessKeyId:i,signature:c,policy:d,key:l}=o.data,u=new FormData;u.append("key",l),u.append("AccessKeyId",i),u.append("signature",c),u.append("policy",d),u.append("file",t);const p=await ns(u);p.status===204?n(this.OBS_URL+l):s(p.data)})}getVideoThumbnail=t=>new Promise((n,s)=>{const r=document.createElement("video"),o=document.createElement("canvas"),i=o.getContext("2d");if(!i){s(new Error("无法创建 canvas 上下文"));return}const c=URL.createObjectURL(t);r.preload="metadata",r.src=c,r.muted=!0,r.playsInline=!0,r.addEventListener("loadeddata",()=>{o.width=r.videoWidth,o.height=r.videoHeight,r.currentTime=0}),r.addEventListener("seeked",()=>{try{i.drawImage(r,0,0,o.width,o.height),o.toBlob(d=>{if(URL.revokeObjectURL(c),r.remove(),!d){s(b.FILE_PARSING_ERROR);return}const l=t.name.replace(/\.[^/.]+$/,"")+"_thumb.jpg",u=new File([d],l,{type:"image/jpeg",lastModified:Date.now()});n(u)},"image/jpeg",.6)}catch(d){URL.revokeObjectURL(c),r.remove(),s(d)}}),r.addEventListener("error",()=>{URL.revokeObjectURL(c),r.remove(),s(b.FILE_PARSING_ERROR)}),r.load()});async getFaqList(){if(this.bindStatus!==O.BOUND)return Promise.reject(b.NO_CUSTOMER_SERVICE);const t=await rs({id:this.sessionData?.cid});if(!t.data?.topic?.length)return;const n={guideText:t.data.guideText,list:t.data.topic.map(s=>({...s,question:s.question}))};setTimeout(()=>{const s={code:U.SEND_SUCCESS,data:{content:n,contentType:H.FAQ,sendUserType:he.CUSTOMER,customerServiceAvatar:this.sessionData?.customerAvatar,customerServiceName:this.sessionData?.customerName,createTime:Date.now(),msgType:x.SEND},msgType:x.SEND,chatType:H.FAQ,toUid:this.sessionData?.uid};this.emit(w.MESSAGE,s)},t.data.showDelaySeconds*1e3)}sendFaq(t){const n={code:U.SEND_SUCCESS,data:{sendUserType:he.CUSTOMER,customerServiceAvatar:this.sessionData?.customerAvatar,customerServiceName:this.sessionData?.customerName,createTime:Date.now(),msgType:x.SEND,contentType:H.FAQ,content:{}},msgType:x.SEND,chatType:H.FAQ,toUid:this.sessionData?.uid};if(t.isMulti)n.data.content={list:t.item},this.emit(w.MESSAGE,n);else{const s=t.item?.[0]||t;s.imageUrl=s.imageUrl?.map(r=>r?.startsWith("http")?r:this.OBS_URL+r),n.data.content={answer:s},this.emit(w.MESSAGE,n)}}async getUserInfo(){if(this.userInfo)return this.userInfo;const t=await os();return this.userInfo=t.data,this.userInfo}}exports.BindStatus=O;exports.ChatType=H;exports.ConnectionStatus=A;exports.EventType=w;exports.JoyTalk=W;exports.MessageCode=U;exports.MessageType=x;exports.SendUserType=he;exports.TOKEN_KEY=de;exports.default=W;
|