@liuyuzhao/ai-chat
Version:
A Vue 3 AI chat component with TypeScript support for Web, H5, and UniApp
8 lines (7 loc) • 12.5 kB
JavaScript
;function e(e,t){for(var n=0;n<t.length;n++){const r=t[n];if("string"!=typeof r&&!Array.isArray(r))for(const t in r)if("default"!==t&&!(t in e)){const n=Object.getOwnPropertyDescriptor(r,t);n&&Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>r[t]})}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}var t,n,r="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},o={exports:{}};
/** @license
* eventsource.js
* Available under MIT License (MIT)
* https://github.com/Yaffle/EventSource/
*/
t=o,n=o.exports,function(e){var r=e.setTimeout,o=e.clearTimeout,i=e.XMLHttpRequest,a=e.XDomainRequest,s=e.ActiveXObject,l=e.EventSource,c=e.document,u=e.Promise,d=e.fetch,h=e.Response,f=e.TextDecoder,p=e.TextEncoder,y=e.AbortController;if("undefined"==typeof window||void 0===c||"readyState"in c||null!=c.body||(c.readyState="loading",window.addEventListener("load",function(e){c.readyState="complete"},!1)),null==i&&null!=s&&(i=function(){return new s("Microsoft.XMLHTTP")}),null==Object.create&&(Object.create=function(e){function t(){}return t.prototype=e,new t}),Date.now||(Date.now=function(){return(new Date).getTime()}),null==y){var v=d;d=function(e,t){var n=t.signal;return v(e,{headers:t.headers,credentials:t.credentials,cache:t.cache}).then(function(e){var t=e.body.getReader();return n._reader=t,n._aborted&&n._reader.cancel(),{status:e.status,statusText:e.statusText,headers:e.headers,body:{getReader:function(){return t}}}})},y=function(){this.signal={_reader:null,_aborted:!1},this.abort=function(){null!=this.signal._reader&&this.signal._reader.cancel(),this.signal._aborted=!0}}}function g(){this.bitsNeeded=0,this.codePoint=0}g.prototype.decode=function(e){function t(e,t,n){if(1===n)return e>=128>>t&&e<<t<=2047;if(2===n)return e>=2048>>t&&e<<t<=55295||e>=57344>>t&&e<<t<=65535;if(3===n)return e>=65536>>t&&e<<t<=1114111;throw new Error}function n(e,t){if(6===e)return t>>6>15?3:t>31?2:1;if(12===e)return t>15?3:2;if(18===e)return 3;throw new Error}for(var r=65533,o="",i=this.bitsNeeded,a=this.codePoint,s=0;s<e.length;s+=1){var l=e[s];0!==i&&(l<128||l>191||!t(a<<6|63&l,i-6,n(i,a)))&&(i=0,a=r,o+=String.fromCharCode(a)),0===i?(l>=0&&l<=127?(i=0,a=l):l>=192&&l<=223?(i=6,a=31&l):l>=224&&l<=239?(i=12,a=15&l):l>=240&&l<=247?(i=18,a=7&l):(i=0,a=r),0===i||t(a,i,n(i,a))||(i=0,a=r)):(i-=6,a=a<<6|63&l),0===i&&(a<=65535?o+=String.fromCharCode(a):(o+=String.fromCharCode(55296+(a-65535-1>>10)),o+=String.fromCharCode(56320+(a-65535-1&1023))))}return this.bitsNeeded=i,this.codePoint=a,o},null!=f&&null!=p&&function(){try{return"test"===(new f).decode((new p).encode("test"),{stream:!0})}catch(e){console.debug("TextDecoder does not support streaming option. Using polyfill instead: "+e)}return!1}()||(f=g);var w=function(){};function b(e){this.withCredentials=!1,this.readyState=0,this.status=0,this.statusText="",this.responseText="",this.onprogress=w,this.onload=w,this.onerror=w,this.onreadystatechange=w,this._contentType="",this._xhr=e,this._sendTimeout=0,this._abort=w}function T(e){return e.replace(/[A-Z]/g,function(e){return String.fromCharCode(e.charCodeAt(0)+32)})}function E(e){for(var t=Object.create(null),n=e.split("\r\n"),r=0;r<n.length;r+=1){var o=n[r].split(": "),i=o.shift(),a=o.join(": ");t[T(i)]=a}this._map=t}function C(){}function m(e){this._headers=e}function _(){}function S(){this._listeners=Object.create(null)}function x(e){r(function(){throw e},0)}function A(e){this.type=e,this.target=void 0}function O(e,t){A.call(this,e),this.data=t.data,this.lastEventId=t.lastEventId}function R(e,t){A.call(this,e),this.status=t.status,this.statusText=t.statusText,this.headers=t.headers}function D(e,t){A.call(this,e),this.error=t.error}b.prototype.open=function(e,t){this._abort(!0);var n=this,a=this._xhr,s=1,l=0;this._abort=function(e){0!==n._sendTimeout&&(o(n._sendTimeout),n._sendTimeout=0),1!==s&&2!==s&&3!==s||(s=4,a.onload=w,a.onerror=w,a.onabort=w,a.onprogress=w,a.onreadystatechange=w,a.abort(),0!==l&&(o(l),l=0),e||(n.readyState=4,n.onabort(null),n.onreadystatechange())),s=0};var c=function(){if(1===s){var e=0,t="",r=void 0;if("contentType"in a)e=200,t="OK",r=a.contentType;else try{e=a.status,t=a.statusText,r=a.getResponseHeader("Content-Type")}catch(o){e=0,t="",r=void 0}0!==e&&(s=2,n.readyState=2,n.status=e,n.statusText=t,n._contentType=r,n.onreadystatechange())}},u=function(){if(c(),2===s||3===s){s=3;var e="";try{e=a.responseText}catch(t){}n.readyState=3,n.responseText=e,n.onprogress()}},d=function(e,t){if(null!=t&&null!=t.preventDefault||(t={preventDefault:w}),u(),1===s||2===s||3===s){if(s=4,0!==l&&(o(l),l=0),n.readyState=4,"load"===e)n.onload(t);else if("error"===e)n.onerror(t);else{if("abort"!==e)throw new TypeError;n.onabort(t)}n.onreadystatechange()}},h=function(){l=r(function(){h()},500),3===a.readyState&&u()};"onload"in a&&(a.onload=function(e){d("load",e)}),"onerror"in a&&(a.onerror=function(e){d("error",e)}),"onabort"in a&&(a.onabort=function(e){d("abort",e)}),"onprogress"in a&&(a.onprogress=u),"onreadystatechange"in a&&(a.onreadystatechange=function(e){!function(e){null!=a&&(4===a.readyState?"onload"in a&&"onerror"in a&&"onabort"in a||d(""===a.responseText?"error":"load",e):3===a.readyState?"onprogress"in a||u():2===a.readyState&&c())}(e)}),!("contentType"in a)&&"ontimeout"in i.prototype||(t+=(-1===t.indexOf("?")?"?":"&")+"padding=true"),a.open(e,t,!0),"readyState"in a&&(l=r(function(){h()},0))},b.prototype.abort=function(){this._abort(!1)},b.prototype.getResponseHeader=function(e){return this._contentType},b.prototype.setRequestHeader=function(e,t){var n=this._xhr;"setRequestHeader"in n&&n.setRequestHeader(e,t)},b.prototype.getAllResponseHeaders=function(){return null!=this._xhr.getAllResponseHeaders&&this._xhr.getAllResponseHeaders()||""},b.prototype.send=function(){if("ontimeout"in i.prototype&&("sendAsBinary"in i.prototype||"mozAnon"in i.prototype)||null==c||null==c.readyState||"complete"===c.readyState){var e=this._xhr;"withCredentials"in e&&(e.withCredentials=this.withCredentials);try{e.send(void 0)}catch(n){throw n}}else{var t=this;t._sendTimeout=r(function(){t._sendTimeout=0,t.send()},4)}},E.prototype.get=function(e){return this._map[T(e)]},null!=i&&null==i.HEADERS_RECEIVED&&(i.HEADERS_RECEIVED=2),C.prototype.open=function(e,t,n,r,o,a,s){e.open("GET",o);var l=0;for(var c in e.onprogress=function(){var t=e.responseText.slice(l);l+=t.length,n(t)},e.onerror=function(e){e.preventDefault(),r(new Error("NetworkError"))},e.onload=function(){r(null)},e.onabort=function(){r(null)},e.onreadystatechange=function(){if(e.readyState===i.HEADERS_RECEIVED){var n=e.status,r=e.statusText,o=e.getResponseHeader("Content-Type"),a=e.getAllResponseHeaders();t(n,r,o,new E(a))}},e.withCredentials=a,s)Object.prototype.hasOwnProperty.call(s,c)&&e.setRequestHeader(c,s[c]);return e.send(),e},m.prototype.get=function(e){return this._headers.get(e)},_.prototype.open=function(e,t,n,r,o,i,a){var s=null,l=new y,c=l.signal,h=new f;return d(o,{headers:a,credentials:i?"include":"same-origin",signal:c,cache:"no-store"}).then(function(e){return s=e.body.getReader(),t(e.status,e.statusText,e.headers.get("Content-Type"),new m(e.headers)),new u(function(e,t){var r=function(){s.read().then(function(t){if(t.done)e(void 0);else{var o=h.decode(t.value,{stream:!0});n(o),r()}}).catch(function(e){t(e)})};r()})}).catch(function(e){return"AbortError"===e.name?void 0:e}).then(function(e){r(e)}),{abort:function(){null!=s&&s.cancel(),l.abort()}}},S.prototype.dispatchEvent=function(e){e.target=this;var t=this._listeners[e.type];if(null!=t)for(var n=t.length,r=0;r<n;r+=1){var o=t[r];try{"function"==typeof o.handleEvent?o.handleEvent(e):o.call(this,e)}catch(i){x(i)}}},S.prototype.addEventListener=function(e,t){e=String(e);var n=this._listeners,r=n[e];null==r&&(r=[],n[e]=r);for(var o=!1,i=0;i<r.length;i+=1)r[i]===t&&(o=!0);o||r.push(t)},S.prototype.removeEventListener=function(e,t){e=String(e);var n=this._listeners,r=n[e];if(null!=r){for(var o=[],i=0;i<r.length;i+=1)r[i]!==t&&o.push(r[i]);0===o.length?delete n[e]:n[e]=o}},O.prototype=Object.create(A.prototype),R.prototype=Object.create(A.prototype),D.prototype=Object.create(A.prototype);var j=-1,H=-1,N=/^text\/event\-stream(;.*)?$/i,P=function(e,t){var n=null==e?t:parseInt(e,10);return n!=n&&(n=t),I(n)},I=function(e){return Math.min(Math.max(e,1e3),18e6)},M=function(e,t,n){try{"function"==typeof t&&t.call(e,n)}catch(r){x(r)}};function L(e,t){S.call(this),t=t||{},this.onopen=void 0,this.onmessage=void 0,this.onerror=void 0,this.url=void 0,this.readyState=void 0,this.withCredentials=void 0,this.headers=void 0,this._close=void 0,function(e,t,n){t=String(t);var s=Boolean(n.withCredentials),l=n.lastEventIdQueryParameterName||"lastEventId",c=I(1e3),u=P(n.heartbeatTimeout,45e3),d="",h=c,f=!1,p=0,y=n.headers||{},v=n.Transport,g=q&&null==v?void 0:new b(null!=v?new v:null!=i&&"withCredentials"in i.prototype||null==a?new i:new a),w=null!=v&&"string"!=typeof v?new v:null==g?new _:new C,T=void 0,E=0,m=j,S="",x="",A="",L="",X=0,G=0,V=0,z=function(t,n,r,o){if(0===m)if(200===t&&null!=r&&N.test(r)){m=1,f=Date.now(),h=c,e.readyState=1;var i=new R("open",{status:t,statusText:n,headers:o});e.dispatchEvent(i),M(e,e.onopen,i)}else{var a="";200!==t?(n&&(n=n.replace(/\s+/g," ")),a="EventSource's response has a status "+t+" "+n+" that is not 200. Aborting the connection."):a="EventSource's response has a Content-Type specifying an unsupported type: "+(null==r?"-":r.replace(/\s+/g," "))+". Aborting the connection.",k(),i=new R("error",{status:t,statusText:n,headers:o}),e.dispatchEvent(i),M(e,e.onerror,i),console.error(a)}},B=function(t){if(1===m){for(var n=-1,i=0;i<t.length;i+=1)(l=t.charCodeAt(i))!=="\n".charCodeAt(0)&&l!=="\r".charCodeAt(0)||(n=i);var a=(-1!==n?L:"")+t.slice(0,n+1);L=(-1===n?L:"")+t.slice(n+1),""!==t&&(f=Date.now(),p+=t.length);for(var s=0;s<a.length;s+=1){var l=a.charCodeAt(s);if(X===H&&l==="\n".charCodeAt(0))X=0;else if(X===H&&(X=0),l==="\r".charCodeAt(0)||l==="\n".charCodeAt(0)){if(0!==X){1===X&&(V=s+1);var y=a.slice(G,V-1),v=a.slice(V+(V<s&&a.charCodeAt(V)===" ".charCodeAt(0)?1:0),s);"data"===y?(S+="\n",S+=v):"id"===y?x=v:"event"===y?A=v:"retry"===y?(c=P(v,c),h=c):"heartbeatTimeout"===y&&(u=P(v,u),0!==E&&(o(E),E=r(function(){K()},u)))}if(0===X){if(""!==S){d=x,""===A&&(A="message");var g=new O(A,{data:S.slice(1),lastEventId:x});if(e.dispatchEvent(g),"open"===A?M(e,e.onopen,g):"message"===A?M(e,e.onmessage,g):"error"===A&&M(e,e.onerror,g),2===m)return}S="",A=""}X=l==="\r".charCodeAt(0)?H:0}else 0===X&&(G=s,X=1),1===X?l===":".charCodeAt(0)&&(V=s+1,X=2):2===X&&(X=3)}}},U=function(t){if(1===m||0===m){m=j,0!==E&&(o(E),E=0),E=r(function(){K()},h),h=I(Math.min(16*c,2*h)),e.readyState=0;var n=new D("error",{error:t});e.dispatchEvent(n),M(e,e.onerror,n),null!=t&&console.error(t)}},k=function(){m=2,null!=T&&(T.abort(),T=void 0),0!==E&&(o(E),E=0),e.readyState=2},K=function(){if(E=0,m===j){f=!1,p=0,E=r(function(){K()},u),m=0,S="",A="",x=d,L="",G=0,V=0,X=0;var n=t;if("data:"!==t.slice(0,5)&&"blob:"!==t.slice(0,5)&&""!==d){var o=t.indexOf("?");n=-1===o?t:t.slice(0,o+1)+t.slice(o+1).replace(/(?:^|&)([^=&]*)(?:=[^&]*)?/g,function(e,t){return t===l?"":e}),n+=(-1===t.indexOf("?")?"?":"&")+l+"="+encodeURIComponent(d)}var i=e.withCredentials,a={Accept:"text/event-stream"},s=e.headers;if(null!=s)for(var c in s)Object.prototype.hasOwnProperty.call(s,c)&&(a[c]=s[c]);try{T=w.open(g,z,B,U,n,i,a)}catch(y){throw k(),y}}else if(f||null==T){var h=Math.max((f||Date.now())+u-Date.now(),1);f=!1,E=r(function(){K()},h)}else U(new Error("No activity within "+u+" milliseconds. "+(0===m?"No response received.":p+" chars received.")+" Reconnecting.")),null!=T&&(T.abort(),T=void 0)};e.url=t,e.readyState=0,e.withCredentials=s,e.headers=y,e._close=k,K()}(this,e,t)}var q=null!=d&&null!=h&&"body"in h.prototype;L.prototype=Object.create(S.prototype),L.prototype.CONNECTING=0,L.prototype.OPEN=1,L.prototype.CLOSED=2,L.prototype.close=function(){this._close()},L.CONNECTING=0,L.OPEN=1,L.CLOSED=2,L.prototype.withCredentials=void 0;var X,G,V=l;null==i||null!=l&&"withCredentials"in l.prototype||(V=L),(X=n).EventSourcePolyfill=L,X.NativeEventSource=l,void 0!==(G=void(X.EventSource=V))&&(t.exports=G)}("undefined"==typeof globalThis?"undefined"!=typeof window?window:"undefined"!=typeof self?self:r:globalThis);const i=e({__proto__:null},[o.exports]);exports.eventsource=i;