xinyao-assistant-sdk 1.0.11 → 1.0.1111
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
"use strict";var t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function e(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var n,o
|
|
1
|
+
"use strict";var t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function e(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var n,r,o={exports:{}};
|
|
2
2
|
/** @license
|
|
3
3
|
* eventsource.js
|
|
4
4
|
* Available under MIT License (MIT)
|
|
5
5
|
* https://github.com/Yaffle/EventSource/
|
|
6
|
-
*/n=r,o=r.exports,function(t){var e=t.setTimeout,r=t.clearTimeout,i=t.XMLHttpRequest,s=t.XDomainRequest,a=t.ActiveXObject,u=t.EventSource,c=t.document,l=t.Promise,h=t.fetch,d=t.Response,f=t.TextDecoder,p=t.TextEncoder,y=t.AbortController;if("undefined"==typeof window||void 0===c||"readyState"in c||null!=c.body||(c.readyState="loading",window.addEventListener("load",function(t){c.readyState="complete"},!1)),null==i&&null!=a&&(i=function(){return new a("Microsoft.XMLHTTP")}),null==Object.create&&(Object.create=function(t){function e(){}return e.prototype=t,new e}),Date.now||(Date.now=function(){return(new Date).getTime()}),null==y){var g=h;h=function(t,e){var n=e.signal;return g(t,{headers:e.headers,credentials:e.credentials,cache:e.cache}).then(function(t){var e=t.body.getReader();return n._reader=e,n._aborted&&n._reader.cancel(),{status:t.status,statusText:t.statusText,headers:t.headers,body:{getReader:function(){return e}}}})},y=function(){this.signal={_reader:null,_aborted:!1},this.abort=function(){null!=this.signal._reader&&this.signal._reader.cancel(),this.signal._aborted=!0}}}function v(){this.bitsNeeded=0,this.codePoint=0}v.prototype.decode=function(t){function e(t,e,n){if(1===n)return t>=128>>e&&t<<e<=2047;if(2===n)return t>=2048>>e&&t<<e<=55295||t>=57344>>e&&t<<e<=65535;if(3===n)return t>=65536>>e&&t<<e<=1114111;throw new Error}function n(t,e){if(6===t)return e>>6>15?3:e>31?2:1;if(12===t)return e>15?3:2;if(18===t)return 3;throw new Error}for(var o=65533,r="",i=this.bitsNeeded,s=this.codePoint,a=0;a<t.length;a+=1){var u=t[a];0!==i&&(u<128||u>191||!e(s<<6|63&u,i-6,n(i,s)))&&(i=0,s=o,r+=String.fromCharCode(s)),0===i?(u>=0&&u<=127?(i=0,s=u):u>=192&&u<=223?(i=6,s=31&u):u>=224&&u<=239?(i=12,s=15&u):u>=240&&u<=247?(i=18,s=7&u):(i=0,s=o),0===i||e(s,i,n(i,s))||(i=0,s=o)):(i-=6,s=s<<6|63&u),0===i&&(s<=65535?r+=String.fromCharCode(s):(r+=String.fromCharCode(55296+(s-65535-1>>10)),r+=String.fromCharCode(56320+(s-65535-1&1023))))}return this.bitsNeeded=i,this.codePoint=s,r},null!=f&&null!=p&&function(){try{return"test"===(new f).decode((new p).encode("test"),{stream:!0})}catch(t){console.debug("TextDecoder does not support streaming option. Using polyfill instead: "+t)}return!1}()||(f=v);var S=function(){};function w(t){this.withCredentials=!1,this.readyState=0,this.status=0,this.statusText="",this.responseText="",this.onprogress=S,this.onload=S,this.onerror=S,this.onreadystatechange=S,this._contentType="",this._xhr=t,this._sendTimeout=0,this._abort=S}function T(t){return t.replace(/[A-Z]/g,function(t){return String.fromCharCode(t.charCodeAt(0)+32)})}function b(t){for(var e=Object.create(null),n=t.split("\r\n"),o=0;o<n.length;o+=1){var r=n[o].split(": "),i=r.shift(),s=r.join(": ");e[T(i)]=s}this._map=e}function E(){}function _(t){this._headers=t}function C(){}function m(){this._listeners=Object.create(null)}function A(t){e(function(){throw t},0)}function x(t){this.type=t,this.target=void 0}function R(t,e){x.call(this,t),this.data=e.data,this.lastEventId=e.lastEventId}function O(t,e){x.call(this,t),this.status=e.status,this.statusText=e.statusText,this.headers=e.headers}function N(t,e){x.call(this,t),this.error=e.error}w.prototype.open=function(t,n){this._abort(!0);var o=this,s=this._xhr,a=1,u=0;this._abort=function(t){0!==o._sendTimeout&&(r(o._sendTimeout),o._sendTimeout=0),1!==a&&2!==a&&3!==a||(a=4,s.onload=S,s.onerror=S,s.onabort=S,s.onprogress=S,s.onreadystatechange=S,s.abort(),0!==u&&(r(u),u=0),t||(o.readyState=4,o.onabort(null),o.onreadystatechange())),a=0};var c=function(){if(1===a){var t=0,e="",n=void 0;if("contentType"in s)t=200,e="OK",n=s.contentType;else try{t=s.status,e=s.statusText,n=s.getResponseHeader("Content-Type")}catch(r){t=0,e="",n=void 0}0!==t&&(a=2,o.readyState=2,o.status=t,o.statusText=e,o._contentType=n,o.onreadystatechange())}},l=function(){if(c(),2===a||3===a){a=3;var t="";try{t=s.responseText}catch(e){}o.readyState=3,o.responseText=t,o.onprogress()}},h=function(t,e){if(null!=e&&null!=e.preventDefault||(e={preventDefault:S}),l(),1===a||2===a||3===a){if(a=4,0!==u&&(r(u),u=0),o.readyState=4,"load"===t)o.onload(e);else if("error"===t)o.onerror(e);else{if("abort"!==t)throw new TypeError;o.onabort(e)}o.onreadystatechange()}},d=function(){u=e(function(){d()},500),3===s.readyState&&l()};"onload"in s&&(s.onload=function(t){h("load",t)}),"onerror"in s&&(s.onerror=function(t){h("error",t)}),"onabort"in s&&(s.onabort=function(t){h("abort",t)}),"onprogress"in s&&(s.onprogress=l),"onreadystatechange"in s&&(s.onreadystatechange=function(t){!function(t){null!=s&&(4===s.readyState?"onload"in s&&"onerror"in s&&"onabort"in s||h(""===s.responseText?"error":"load",t):3===s.readyState?"onprogress"in s||l():2===s.readyState&&c())}(t)}),!("contentType"in s)&&"ontimeout"in i.prototype||(n+=(-1===n.indexOf("?")?"?":"&")+"padding=true"),s.open(t,n,!0),"readyState"in s&&(u=e(function(){d()},0))},w.prototype.abort=function(){this._abort(!1)},w.prototype.getResponseHeader=function(t){return this._contentType},w.prototype.setRequestHeader=function(t,e){var n=this._xhr;"setRequestHeader"in n&&n.setRequestHeader(t,e)},w.prototype.getAllResponseHeaders=function(){return null!=this._xhr.getAllResponseHeaders&&this._xhr.getAllResponseHeaders()||""},w.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 t=this._xhr;"withCredentials"in t&&(t.withCredentials=this.withCredentials);try{t.send(void 0)}catch(o){throw o}}else{var n=this;n._sendTimeout=e(function(){n._sendTimeout=0,n.send()},4)}},b.prototype.get=function(t){return this._map[T(t)]},null!=i&&null==i.HEADERS_RECEIVED&&(i.HEADERS_RECEIVED=2),E.prototype.open=function(t,e,n,o,r,s,a){t.open("GET",r);var u=0;for(var c in t.onprogress=function(){var e=t.responseText.slice(u);u+=e.length,n(e)},t.onerror=function(t){t.preventDefault(),o(new Error("NetworkError"))},t.onload=function(){o(null)},t.onabort=function(){o(null)},t.onreadystatechange=function(){if(t.readyState===i.HEADERS_RECEIVED){var n=t.status,o=t.statusText,r=t.getResponseHeader("Content-Type"),s=t.getAllResponseHeaders();e(n,o,r,new b(s))}},t.withCredentials=s,a)Object.prototype.hasOwnProperty.call(a,c)&&t.setRequestHeader(c,a[c]);return t.send(),t},_.prototype.get=function(t){return this._headers.get(t)},C.prototype.open=function(t,e,n,o,r,i,s){var a=null,u=new y,c=u.signal,d=new f;return h(r,{headers:s,credentials:i?"include":"same-origin",signal:c,cache:"no-store"}).then(function(t){return a=t.body.getReader(),e(t.status,t.statusText,t.headers.get("Content-Type"),new _(t.headers)),new l(function(t,e){var o=function(){a.read().then(function(e){if(e.done)t(void 0);else{var r=d.decode(e.value,{stream:!0});n(r),o()}}).catch(function(t){e(t)})};o()})}).catch(function(t){return"AbortError"===t.name?void 0:t}).then(function(t){o(t)}),{abort:function(){null!=a&&a.cancel(),u.abort()}}},m.prototype.dispatchEvent=function(t){t.target=this;var e=this._listeners[t.type];if(null!=e)for(var n=e.length,o=0;o<n;o+=1){var r=e[o];try{"function"==typeof r.handleEvent?r.handleEvent(t):r.call(this,t)}catch(i){A(i)}}},m.prototype.addEventListener=function(t,e){t=String(t);var n=this._listeners,o=n[t];null==o&&(o=[],n[t]=o);for(var r=!1,i=0;i<o.length;i+=1)o[i]===e&&(r=!0);r||o.push(e)},m.prototype.removeEventListener=function(t,e){t=String(t);var n=this._listeners,o=n[t];if(null!=o){for(var r=[],i=0;i<o.length;i+=1)o[i]!==e&&r.push(o[i]);0===r.length?delete n[t]:n[t]=r}},R.prototype=Object.create(x.prototype),O.prototype=Object.create(x.prototype),N.prototype=Object.create(x.prototype);var D=-1,H=-1,j=/^text\/event\-stream(;.*)?$/i,B=function(t,e){var n=null==t?e:parseInt(t,10);return n!=n&&(n=e),I(n)},I=function(t){return Math.min(Math.max(t,1e3),18e6)},M=function(t,e,n){try{"function"==typeof e&&e.call(t,n)}catch(o){A(o)}};function $(t,n){m.call(this),n=n||{},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(t,n,o){n=String(n);var a=Boolean(o.withCredentials),u=o.lastEventIdQueryParameterName||"lastEventId",c=I(1e3),l=B(o.heartbeatTimeout,45e3),h="",d=c,f=!1,p=0,y=o.headers||{},g=o.Transport,v=P&&null==g?void 0:new w(null!=g?new g:null!=i&&"withCredentials"in i.prototype||null==s?new i:new s),S=null!=g&&"string"!=typeof g?new g:null==v?new C:new E,T=void 0,b=0,_=D,m="",A="",x="",$="",k=0,L=0,U=0,q=function(e,n,o,r){if(0===_)if(200===e&&null!=o&&j.test(o)){_=1,f=Date.now(),d=c,t.readyState=1;var i=new O("open",{status:e,statusText:n,headers:r});t.dispatchEvent(i),M(t,t.onopen,i)}else{var s="";200!==e?(n&&(n=n.replace(/\s+/g," ")),s="EventSource's response has a status "+e+" "+n+" that is not 200. Aborting the connection."):s="EventSource's response has a Content-Type specifying an unsupported type: "+(null==o?"-":o.replace(/\s+/g," "))+". Aborting the connection.",X(),i=new O("error",{status:e,statusText:n,headers:r}),t.dispatchEvent(i),M(t,t.onerror,i),console.error(s)}},W=function(n){if(1===_){for(var o=-1,i=0;i<n.length;i+=1)(u=n.charCodeAt(i))!=="\n".charCodeAt(0)&&u!=="\r".charCodeAt(0)||(o=i);var s=(-1!==o?$:"")+n.slice(0,o+1);$=(-1===o?$:"")+n.slice(o+1),""!==n&&(f=Date.now(),p+=n.length);for(var a=0;a<s.length;a+=1){var u=s.charCodeAt(a);if(k===H&&u==="\n".charCodeAt(0))k=0;else if(k===H&&(k=0),u==="\r".charCodeAt(0)||u==="\n".charCodeAt(0)){if(0!==k){1===k&&(U=a+1);var y=s.slice(L,U-1),g=s.slice(U+(U<a&&s.charCodeAt(U)===" ".charCodeAt(0)?1:0),a);"data"===y?(m+="\n",m+=g):"id"===y?A=g:"event"===y?x=g:"retry"===y?(c=B(g,c),d=c):"heartbeatTimeout"===y&&(l=B(g,l),0!==b&&(r(b),b=e(function(){G()},l)))}if(0===k){if(""!==m){h=A,""===x&&(x="message");var v=new R(x,{data:m.slice(1),lastEventId:A});if(t.dispatchEvent(v),"open"===x?M(t,t.onopen,v):"message"===x?M(t,t.onmessage,v):"error"===x&&M(t,t.onerror,v),2===_)return}m="",x=""}k=u==="\r".charCodeAt(0)?H:0}else 0===k&&(L=a,k=1),1===k?u===":".charCodeAt(0)&&(U=a+1,k=2):2===k&&(k=3)}}},z=function(n){if(1===_||0===_){_=D,0!==b&&(r(b),b=0),b=e(function(){G()},d),d=I(Math.min(16*c,2*d)),t.readyState=0;var o=new N("error",{error:n});t.dispatchEvent(o),M(t,t.onerror,o),null!=n&&console.error(n)}},X=function(){_=2,null!=T&&(T.abort(),T=void 0),0!==b&&(r(b),b=0),t.readyState=2},G=function(){if(b=0,_===D){f=!1,p=0,b=e(function(){G()},l),_=0,m="",x="",A=h,$="",L=0,U=0,k=0;var o=n;if("data:"!==n.slice(0,5)&&"blob:"!==n.slice(0,5)&&""!==h){var r=n.indexOf("?");o=-1===r?n:n.slice(0,r+1)+n.slice(r+1).replace(/(?:^|&)([^=&]*)(?:=[^&]*)?/g,function(t,e){return e===u?"":t}),o+=(-1===n.indexOf("?")?"?":"&")+u+"="+encodeURIComponent(h)}var i=t.withCredentials,s={Accept:"text/event-stream"},a=t.headers;if(null!=a)for(var c in a)Object.prototype.hasOwnProperty.call(a,c)&&(s[c]=a[c]);try{T=S.open(v,q,W,z,o,i,s)}catch(y){throw X(),y}}else if(f||null==T){var d=Math.max((f||Date.now())+l-Date.now(),1);f=!1,b=e(function(){G()},d)}else z(new Error("No activity within "+l+" milliseconds. "+(0===_?"No response received.":p+" chars received.")+" Reconnecting.")),null!=T&&(T.abort(),T=void 0)};t.url=n,t.readyState=0,t.withCredentials=a,t.headers=y,t._close=X,G()}(this,t,n)}var P=null!=h&&null!=d&&"body"in d.prototype;$.prototype=Object.create(m.prototype),$.prototype.CONNECTING=0,$.prototype.OPEN=1,$.prototype.CLOSED=2,$.prototype.close=function(){this._close()},$.CONNECTING=0,$.OPEN=1,$.CLOSED=2,$.prototype.withCredentials=void 0;var k,L,U=u;null==i||null!=u&&"withCredentials"in u.prototype||(U=$),(k=o).EventSourcePolyfill=$,k.NativeEventSource=u,void 0!==(L=void(k.EventSource=U))&&(n.exports=L)}("undefined"==typeof globalThis?"undefined"!=typeof window?window:"undefined"!=typeof self?self:t:globalThis);var i,s,a={exports:{}},u={exports:{}};i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s={rotl:function(t,e){return t<<e|t>>>32-e},rotr:function(t,e){return t<<32-e|t>>>e},endian:function(t){if(t.constructor==Number)return 16711935&s.rotl(t,8)|4278255360&s.rotl(t,24);for(var e=0;e<t.length;e++)t[e]=s.endian(t[e]);return t},randomBytes:function(t){for(var e=[];t>0;t--)e.push(Math.floor(256*Math.random()));return e},bytesToWords:function(t){for(var e=[],n=0,o=0;n<t.length;n++,o+=8)e[o>>>5]|=t[n]<<24-o%32;return e},wordsToBytes:function(t){for(var e=[],n=0;n<32*t.length;n+=8)e.push(t[n>>>5]>>>24-n%32&255);return e},bytesToHex:function(t){for(var e=[],n=0;n<t.length;n++)e.push((t[n]>>>4).toString(16)),e.push((15&t[n]).toString(16));return e.join("")},hexToBytes:function(t){for(var e=[],n=0;n<t.length;n+=2)e.push(parseInt(t.substr(n,2),16));return e},bytesToBase64:function(t){for(var e=[],n=0;n<t.length;n+=3)for(var o=t[n]<<16|t[n+1]<<8|t[n+2],r=0;r<4;r++)8*n+6*r<=8*t.length?e.push(i.charAt(o>>>6*(3-r)&63)):e.push("=");return e.join("")},base64ToBytes:function(t){t=t.replace(/[^A-Z0-9+\/]/gi,"");for(var e=[],n=0,o=0;n<t.length;o=++n%4)0!=o&&e.push((i.indexOf(t.charAt(n-1))&Math.pow(2,-2*o+8)-1)<<2*o|i.indexOf(t.charAt(n))>>>6-2*o);return e}},u.exports=s;var c,l,h,d,f,p=u.exports,y={utf8:{stringToBytes:function(t){return y.bin.stringToBytes(unescape(encodeURIComponent(t)))},bytesToString:function(t){return decodeURIComponent(escape(y.bin.bytesToString(t)))}},bin:{stringToBytes:function(t){for(var e=[],n=0;n<t.length;n++)e.push(255&t.charCodeAt(n));return e},bytesToString:function(t){for(var e=[],n=0;n<t.length;n++)e.push(String.fromCharCode(t[n]));return e.join("")}}},g=y,v=function(t){return null!=t&&(S(t)||function(t){return"function"==typeof t.readFloatLE&&"function"==typeof t.slice&&S(t.slice(0,0))}(t)||!!t._isBuffer)};function S(t){return!!t.constructor&&"function"==typeof t.constructor.isBuffer&&t.constructor.isBuffer(t)}c=p,l=g.utf8,h=v,d=g.bin,(f=function(t,e){t.constructor==String?t=e&&"binary"===e.encoding?d.stringToBytes(t):l.stringToBytes(t):h(t)?t=Array.prototype.slice.call(t,0):Array.isArray(t)||t.constructor===Uint8Array||(t=t.toString());for(var n=c.bytesToWords(t),o=8*t.length,r=1732584193,i=-271733879,s=-1732584194,a=271733878,u=0;u<n.length;u++)n[u]=16711935&(n[u]<<8|n[u]>>>24)|4278255360&(n[u]<<24|n[u]>>>8);n[o>>>5]|=128<<o%32,n[14+(o+64>>>9<<4)]=o;var p=f._ff,y=f._gg,g=f._hh,v=f._ii;for(u=0;u<n.length;u+=16){var S=r,w=i,T=s,b=a;r=p(r,i,s,a,n[u+0],7,-680876936),a=p(a,r,i,s,n[u+1],12,-389564586),s=p(s,a,r,i,n[u+2],17,606105819),i=p(i,s,a,r,n[u+3],22,-1044525330),r=p(r,i,s,a,n[u+4],7,-176418897),a=p(a,r,i,s,n[u+5],12,1200080426),s=p(s,a,r,i,n[u+6],17,-1473231341),i=p(i,s,a,r,n[u+7],22,-45705983),r=p(r,i,s,a,n[u+8],7,1770035416),a=p(a,r,i,s,n[u+9],12,-1958414417),s=p(s,a,r,i,n[u+10],17,-42063),i=p(i,s,a,r,n[u+11],22,-1990404162),r=p(r,i,s,a,n[u+12],7,1804603682),a=p(a,r,i,s,n[u+13],12,-40341101),s=p(s,a,r,i,n[u+14],17,-1502002290),r=y(r,i=p(i,s,a,r,n[u+15],22,1236535329),s,a,n[u+1],5,-165796510),a=y(a,r,i,s,n[u+6],9,-1069501632),s=y(s,a,r,i,n[u+11],14,643717713),i=y(i,s,a,r,n[u+0],20,-373897302),r=y(r,i,s,a,n[u+5],5,-701558691),a=y(a,r,i,s,n[u+10],9,38016083),s=y(s,a,r,i,n[u+15],14,-660478335),i=y(i,s,a,r,n[u+4],20,-405537848),r=y(r,i,s,a,n[u+9],5,568446438),a=y(a,r,i,s,n[u+14],9,-1019803690),s=y(s,a,r,i,n[u+3],14,-187363961),i=y(i,s,a,r,n[u+8],20,1163531501),r=y(r,i,s,a,n[u+13],5,-1444681467),a=y(a,r,i,s,n[u+2],9,-51403784),s=y(s,a,r,i,n[u+7],14,1735328473),r=g(r,i=y(i,s,a,r,n[u+12],20,-1926607734),s,a,n[u+5],4,-378558),a=g(a,r,i,s,n[u+8],11,-2022574463),s=g(s,a,r,i,n[u+11],16,1839030562),i=g(i,s,a,r,n[u+14],23,-35309556),r=g(r,i,s,a,n[u+1],4,-1530992060),a=g(a,r,i,s,n[u+4],11,1272893353),s=g(s,a,r,i,n[u+7],16,-155497632),i=g(i,s,a,r,n[u+10],23,-1094730640),r=g(r,i,s,a,n[u+13],4,681279174),a=g(a,r,i,s,n[u+0],11,-358537222),s=g(s,a,r,i,n[u+3],16,-722521979),i=g(i,s,a,r,n[u+6],23,76029189),r=g(r,i,s,a,n[u+9],4,-640364487),a=g(a,r,i,s,n[u+12],11,-421815835),s=g(s,a,r,i,n[u+15],16,530742520),r=v(r,i=g(i,s,a,r,n[u+2],23,-995338651),s,a,n[u+0],6,-198630844),a=v(a,r,i,s,n[u+7],10,1126891415),s=v(s,a,r,i,n[u+14],15,-1416354905),i=v(i,s,a,r,n[u+5],21,-57434055),r=v(r,i,s,a,n[u+12],6,1700485571),a=v(a,r,i,s,n[u+3],10,-1894986606),s=v(s,a,r,i,n[u+10],15,-1051523),i=v(i,s,a,r,n[u+1],21,-2054922799),r=v(r,i,s,a,n[u+8],6,1873313359),a=v(a,r,i,s,n[u+15],10,-30611744),s=v(s,a,r,i,n[u+6],15,-1560198380),i=v(i,s,a,r,n[u+13],21,1309151649),r=v(r,i,s,a,n[u+4],6,-145523070),a=v(a,r,i,s,n[u+11],10,-1120210379),s=v(s,a,r,i,n[u+2],15,718787259),i=v(i,s,a,r,n[u+9],21,-343485551),r=r+S>>>0,i=i+w>>>0,s=s+T>>>0,a=a+b>>>0}return c.endian([r,i,s,a])})._ff=function(t,e,n,o,r,i,s){var a=t+(e&n|~e&o)+(r>>>0)+s;return(a<<i|a>>>32-i)+e},f._gg=function(t,e,n,o,r,i,s){var a=t+(e&o|n&~o)+(r>>>0)+s;return(a<<i|a>>>32-i)+e},f._hh=function(t,e,n,o,r,i,s){var a=t+(e^n^o)+(r>>>0)+s;return(a<<i|a>>>32-i)+e},f._ii=function(t,e,n,o,r,i,s){var a=t+(n^(e|~o))+(r>>>0)+s;return(a<<i|a>>>32-i)+e},f._blocksize=16,f._digestsize=16,a.exports=function(t,e){if(null==t)throw new Error("Illegal argument "+t);var n=c.wordsToBytes(f(t,e));return e&&e.asBytes?n:e&&e.asString?d.bytesToString(n):c.bytesToHex(n)};const w=e(a.exports);module.exports=class{constructor(t={}){this.url=t.url,this.app_key=t.app_key,this.app_secret=t.app_secret,this.onMessage=t.onMessage||(()=>{}),this.onError=t.onError||(()=>{}),this.onOpen=t.onOpen||(()=>{}),this.onAudioData=t.onAudioData||(()=>{}),this.onAudioNegotiationSuccess=t.onAudioNegotiationSuccess||(()=>{}),this.onConnectSSE=t.onConnectSSE||(()=>{}),this.eventSource=null,this.negotiationResult=null}generateAuthToken(){const t=Math.floor(Date.now()/1e3);return`${this.app_key}:${t}:${w(`${this.app_secret}:${t}`)}`}getAuthHeaders(){return{Authorization:`${this.generateAuthToken()}`,"Content-Type":"application/json"}}async post(t,e){const n=this.generateAuthToken(),o=await fetch(`${this.url}${t}`,{method:"POST",headers:{Authorization:`${n}`,"Content-Type":"application/json","User-Agent":"XY-ASSIST-SDK"},body:JSON.stringify(e)});if(!o.ok){const t=await o.text();throw new Error(`HTTP error! status: ${o.status}, message: ${t}`)}return await o.json()}async audioNegotiation(t){const e=await this.post("/api/v1/agent/ccms/assist/audio-nego",t);return this.negotiationResult=e,this.onAudioNegotiationSuccess&&this.onAudioNegotiationSuccess(e),e}connectSSEWithNegotiationResult(){if(!this.negotiationResult||!this.negotiationResult.result)throw new Error("没有有效的协商结果,请先执行音频协商");const{sse_addr:t,client_id:e}=this.negotiationResult.result;if(!t||!e)throw new Error("协商结果中缺少sse_addr或client_id");const n=`http://${t}/sse?client_id=${e}`;this.connectSSEWithURL(n),this.onConnectSSE&&this.onConnectSSE({sseUrl:n,client_id:e,sse_addr:t})}connectSSEWithURL(t){this.eventSource=new EventSource(t),this.eventSource.onmessage=t=>{const e=JSON.parse(t.data);this.onMessage(e)},this.eventSource.onerror=t=>{this.onError(t)},this.eventSource.onopen=()=>{this.onOpen()}}connectSSE(t=!0){if(t&&this.negotiationResult&&this.negotiationResult.result&&this.negotiationResult.result.sse_addr)this.connectSSEWithNegotiationResult();else{const t=this.generateAuthToken(),e=`${this.url}/api/v1/agent/sse?auth=${t}`;this.eventSource=new EventSource(e),this.eventSource.onmessage=t=>{const e=JSON.parse(t.data);this.onMessage(e)},this.eventSource.onerror=t=>{this.onError(t)},this.eventSource.onopen=()=>{this.onOpen()}}}disconnectSSE(){this.eventSource&&(this.eventSource.close(),this.eventSource=null)}};
|
|
6
|
+
*/n=o,r=o.exports,function(t){var e=t.setTimeout,o=t.clearTimeout,i=t.XMLHttpRequest,s=t.XDomainRequest,a=t.ActiveXObject,c=t.EventSource,u=t.document,l=t.Promise,d=t.fetch,h=t.Response,f=t.TextDecoder,p=t.TextEncoder,y=t.AbortController;if("undefined"==typeof window||void 0===u||"readyState"in u||null!=u.body||(u.readyState="loading",window.addEventListener("load",function(t){u.readyState="complete"},!1)),null==i&&null!=a&&(i=function(){return new a("Microsoft.XMLHTTP")}),null==Object.create&&(Object.create=function(t){function e(){}return e.prototype=t,new e}),Date.now||(Date.now=function(){return(new Date).getTime()}),null==y){var g=d;d=function(t,e){var n=e.signal;return g(t,{headers:e.headers,credentials:e.credentials,cache:e.cache}).then(function(t){var e=t.body.getReader();return n._reader=e,n._aborted&&n._reader.cancel(),{status:t.status,statusText:t.statusText,headers:t.headers,body:{getReader:function(){return e}}}})},y=function(){this.signal={_reader:null,_aborted:!1},this.abort=function(){null!=this.signal._reader&&this.signal._reader.cancel(),this.signal._aborted=!0}}}function v(){this.bitsNeeded=0,this.codePoint=0}v.prototype.decode=function(t){function e(t,e,n){if(1===n)return t>=128>>e&&t<<e<=2047;if(2===n)return t>=2048>>e&&t<<e<=55295||t>=57344>>e&&t<<e<=65535;if(3===n)return t>=65536>>e&&t<<e<=1114111;throw new Error}function n(t,e){if(6===t)return e>>6>15?3:e>31?2:1;if(12===t)return e>15?3:2;if(18===t)return 3;throw new Error}for(var r=65533,o="",i=this.bitsNeeded,s=this.codePoint,a=0;a<t.length;a+=1){var c=t[a];0!==i&&(c<128||c>191||!e(s<<6|63&c,i-6,n(i,s)))&&(i=0,s=r,o+=String.fromCharCode(s)),0===i?(c>=0&&c<=127?(i=0,s=c):c>=192&&c<=223?(i=6,s=31&c):c>=224&&c<=239?(i=12,s=15&c):c>=240&&c<=247?(i=18,s=7&c):(i=0,s=r),0===i||e(s,i,n(i,s))||(i=0,s=r)):(i-=6,s=s<<6|63&c),0===i&&(s<=65535?o+=String.fromCharCode(s):(o+=String.fromCharCode(55296+(s-65535-1>>10)),o+=String.fromCharCode(56320+(s-65535-1&1023))))}return this.bitsNeeded=i,this.codePoint=s,o},null!=f&&null!=p&&function(){try{return"test"===(new f).decode((new p).encode("test"),{stream:!0})}catch(t){console.debug("TextDecoder does not support streaming option. Using polyfill instead: "+t)}return!1}()||(f=v);var w=function(){};function S(t){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=t,this._sendTimeout=0,this._abort=w}function _(t){return t.replace(/[A-Z]/g,function(t){return String.fromCharCode(t.charCodeAt(0)+32)})}function E(t){for(var e=Object.create(null),n=t.split("\r\n"),r=0;r<n.length;r+=1){var o=n[r].split(": "),i=o.shift(),s=o.join(": ");e[_(i)]=s}this._map=e}function b(){}function T(t){this._headers=t}function m(){}function C(){this._listeners=Object.create(null)}function A(t){e(function(){throw t},0)}function x(t){this.type=t,this.target=void 0}function R(t,e){x.call(this,t),this.data=e.data,this.lastEventId=e.lastEventId}function O(t,e){x.call(this,t),this.status=e.status,this.statusText=e.statusText,this.headers=e.headers}function N(t,e){x.call(this,t),this.error=e.error}S.prototype.open=function(t,n){this._abort(!0);var r=this,s=this._xhr,a=1,c=0;this._abort=function(t){0!==r._sendTimeout&&(o(r._sendTimeout),r._sendTimeout=0),1!==a&&2!==a&&3!==a||(a=4,s.onload=w,s.onerror=w,s.onabort=w,s.onprogress=w,s.onreadystatechange=w,s.abort(),0!==c&&(o(c),c=0),t||(r.readyState=4,r.onabort(null),r.onreadystatechange())),a=0};var u=function(){if(1===a){var t=0,e="",n=void 0;if("contentType"in s)t=200,e="OK",n=s.contentType;else try{t=s.status,e=s.statusText,n=s.getResponseHeader("Content-Type")}catch(o){t=0,e="",n=void 0}0!==t&&(a=2,r.readyState=2,r.status=t,r.statusText=e,r._contentType=n,r.onreadystatechange())}},l=function(){if(u(),2===a||3===a){a=3;var t="";try{t=s.responseText}catch(e){}r.readyState=3,r.responseText=t,r.onprogress()}},d=function(t,e){if(null!=e&&null!=e.preventDefault||(e={preventDefault:w}),l(),1===a||2===a||3===a){if(a=4,0!==c&&(o(c),c=0),r.readyState=4,"load"===t)r.onload(e);else if("error"===t)r.onerror(e);else{if("abort"!==t)throw new TypeError;r.onabort(e)}r.onreadystatechange()}},h=function(){c=e(function(){h()},500),3===s.readyState&&l()};"onload"in s&&(s.onload=function(t){d("load",t)}),"onerror"in s&&(s.onerror=function(t){d("error",t)}),"onabort"in s&&(s.onabort=function(t){d("abort",t)}),"onprogress"in s&&(s.onprogress=l),"onreadystatechange"in s&&(s.onreadystatechange=function(t){!function(t){null!=s&&(4===s.readyState?"onload"in s&&"onerror"in s&&"onabort"in s||d(""===s.responseText?"error":"load",t):3===s.readyState?"onprogress"in s||l():2===s.readyState&&u())}(t)}),!("contentType"in s)&&"ontimeout"in i.prototype||(n+=(-1===n.indexOf("?")?"?":"&")+"padding=true"),s.open(t,n,!0),"readyState"in s&&(c=e(function(){h()},0))},S.prototype.abort=function(){this._abort(!1)},S.prototype.getResponseHeader=function(t){return this._contentType},S.prototype.setRequestHeader=function(t,e){var n=this._xhr;"setRequestHeader"in n&&n.setRequestHeader(t,e)},S.prototype.getAllResponseHeaders=function(){return null!=this._xhr.getAllResponseHeaders&&this._xhr.getAllResponseHeaders()||""},S.prototype.send=function(){if("ontimeout"in i.prototype&&("sendAsBinary"in i.prototype||"mozAnon"in i.prototype)||null==u||null==u.readyState||"complete"===u.readyState){var t=this._xhr;"withCredentials"in t&&(t.withCredentials=this.withCredentials);try{t.send(void 0)}catch(r){throw r}}else{var n=this;n._sendTimeout=e(function(){n._sendTimeout=0,n.send()},4)}},E.prototype.get=function(t){return this._map[_(t)]},null!=i&&null==i.HEADERS_RECEIVED&&(i.HEADERS_RECEIVED=2),b.prototype.open=function(t,e,n,r,o,s,a){t.open("GET",o);var c=0;for(var u in t.onprogress=function(){var e=t.responseText.slice(c);c+=e.length,n(e)},t.onerror=function(t){t.preventDefault(),r(new Error("NetworkError"))},t.onload=function(){r(null)},t.onabort=function(){r(null)},t.onreadystatechange=function(){if(t.readyState===i.HEADERS_RECEIVED){var n=t.status,r=t.statusText,o=t.getResponseHeader("Content-Type"),s=t.getAllResponseHeaders();e(n,r,o,new E(s))}},t.withCredentials=s,a)Object.prototype.hasOwnProperty.call(a,u)&&t.setRequestHeader(u,a[u]);return t.send(),t},T.prototype.get=function(t){return this._headers.get(t)},m.prototype.open=function(t,e,n,r,o,i,s){var a=null,c=new y,u=c.signal,h=new f;return d(o,{headers:s,credentials:i?"include":"same-origin",signal:u,cache:"no-store"}).then(function(t){return a=t.body.getReader(),e(t.status,t.statusText,t.headers.get("Content-Type"),new T(t.headers)),new l(function(t,e){var r=function(){a.read().then(function(e){if(e.done)t(void 0);else{var o=h.decode(e.value,{stream:!0});n(o),r()}}).catch(function(t){e(t)})};r()})}).catch(function(t){return"AbortError"===t.name?void 0:t}).then(function(t){r(t)}),{abort:function(){null!=a&&a.cancel(),c.abort()}}},C.prototype.dispatchEvent=function(t){t.target=this;var e=this._listeners[t.type];if(null!=e)for(var n=e.length,r=0;r<n;r+=1){var o=e[r];try{"function"==typeof o.handleEvent?o.handleEvent(t):o.call(this,t)}catch(i){A(i)}}},C.prototype.addEventListener=function(t,e){t=String(t);var n=this._listeners,r=n[t];null==r&&(r=[],n[t]=r);for(var o=!1,i=0;i<r.length;i+=1)r[i]===e&&(o=!0);o||r.push(e)},C.prototype.removeEventListener=function(t,e){t=String(t);var n=this._listeners,r=n[t];if(null!=r){for(var o=[],i=0;i<r.length;i+=1)r[i]!==e&&o.push(r[i]);0===o.length?delete n[t]:n[t]=o}},R.prototype=Object.create(x.prototype),O.prototype=Object.create(x.prototype),N.prototype=Object.create(x.prototype);var D=-1,H=-1,j=/^text\/event\-stream(;.*)?$/i,B=function(t,e){var n=null==t?e:parseInt(t,10);return n!=n&&(n=e),I(n)},I=function(t){return Math.min(Math.max(t,1e3),18e6)},M=function(t,e,n){try{"function"==typeof e&&e.call(t,n)}catch(r){A(r)}};function P(t,n){C.call(this),n=n||{},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(t,n,r){n=String(n);var a=Boolean(r.withCredentials),c=r.lastEventIdQueryParameterName||"lastEventId",u=I(1e3),l=B(r.heartbeatTimeout,45e3),d="",h=u,f=!1,p=0,y=r.headers||{},g=r.Transport,v=$&&null==g?void 0:new S(null!=g?new g:null!=i&&"withCredentials"in i.prototype||null==s?new i:new s),w=null!=g&&"string"!=typeof g?new g:null==v?new m:new b,_=void 0,E=0,T=D,C="",A="",x="",P="",k=0,L=0,U=0,q=function(e,n,r,o){if(0===T)if(200===e&&null!=r&&j.test(r)){T=1,f=Date.now(),h=u,t.readyState=1;var i=new O("open",{status:e,statusText:n,headers:o});t.dispatchEvent(i),M(t,t.onopen,i)}else{var s="";200!==e?(n&&(n=n.replace(/\s+/g," ")),s="EventSource's response has a status "+e+" "+n+" that is not 200. Aborting the connection."):s="EventSource's response has a Content-Type specifying an unsupported type: "+(null==r?"-":r.replace(/\s+/g," "))+". Aborting the connection.",X(),i=new O("error",{status:e,statusText:n,headers:o}),t.dispatchEvent(i),M(t,t.onerror,i),console.error(s)}},W=function(n){if(1===T){for(var r=-1,i=0;i<n.length;i+=1)(c=n.charCodeAt(i))!=="\n".charCodeAt(0)&&c!=="\r".charCodeAt(0)||(r=i);var s=(-1!==r?P:"")+n.slice(0,r+1);P=(-1===r?P:"")+n.slice(r+1),""!==n&&(f=Date.now(),p+=n.length);for(var a=0;a<s.length;a+=1){var c=s.charCodeAt(a);if(k===H&&c==="\n".charCodeAt(0))k=0;else if(k===H&&(k=0),c==="\r".charCodeAt(0)||c==="\n".charCodeAt(0)){if(0!==k){1===k&&(U=a+1);var y=s.slice(L,U-1),g=s.slice(U+(U<a&&s.charCodeAt(U)===" ".charCodeAt(0)?1:0),a);"data"===y?(C+="\n",C+=g):"id"===y?A=g:"event"===y?x=g:"retry"===y?(u=B(g,u),h=u):"heartbeatTimeout"===y&&(l=B(g,l),0!==E&&(o(E),E=e(function(){G()},l)))}if(0===k){if(""!==C){d=A,""===x&&(x="message");var v=new R(x,{data:C.slice(1),lastEventId:A});if(t.dispatchEvent(v),"open"===x?M(t,t.onopen,v):"message"===x?M(t,t.onmessage,v):"error"===x&&M(t,t.onerror,v),2===T)return}C="",x=""}k=c==="\r".charCodeAt(0)?H:0}else 0===k&&(L=a,k=1),1===k?c===":".charCodeAt(0)&&(U=a+1,k=2):2===k&&(k=3)}}},z=function(n){if(1===T||0===T){T=D,0!==E&&(o(E),E=0),E=e(function(){G()},h),h=I(Math.min(16*u,2*h)),t.readyState=0;var r=new N("error",{error:n});t.dispatchEvent(r),M(t,t.onerror,r),null!=n&&console.error(n)}},X=function(){T=2,null!=_&&(_.abort(),_=void 0),0!==E&&(o(E),E=0),t.readyState=2},G=function(){if(E=0,T===D){f=!1,p=0,E=e(function(){G()},l),T=0,C="",x="",A=d,P="",L=0,U=0,k=0;var r=n;if("data:"!==n.slice(0,5)&&"blob:"!==n.slice(0,5)&&""!==d){var o=n.indexOf("?");r=-1===o?n:n.slice(0,o+1)+n.slice(o+1).replace(/(?:^|&)([^=&]*)(?:=[^&]*)?/g,function(t,e){return e===c?"":t}),r+=(-1===n.indexOf("?")?"?":"&")+c+"="+encodeURIComponent(d)}var i=t.withCredentials,s={Accept:"text/event-stream"},a=t.headers;if(null!=a)for(var u in a)Object.prototype.hasOwnProperty.call(a,u)&&(s[u]=a[u]);try{_=w.open(v,q,W,z,r,i,s)}catch(y){throw X(),y}}else if(f||null==_){var h=Math.max((f||Date.now())+l-Date.now(),1);f=!1,E=e(function(){G()},h)}else z(new Error("No activity within "+l+" milliseconds. "+(0===T?"No response received.":p+" chars received.")+" Reconnecting.")),null!=_&&(_.abort(),_=void 0)};t.url=n,t.readyState=0,t.withCredentials=a,t.headers=y,t._close=X,G()}(this,t,n)}var $=null!=d&&null!=h&&"body"in h.prototype;P.prototype=Object.create(C.prototype),P.prototype.CONNECTING=0,P.prototype.OPEN=1,P.prototype.CLOSED=2,P.prototype.close=function(){this._close()},P.CONNECTING=0,P.OPEN=1,P.CLOSED=2,P.prototype.withCredentials=void 0;var k,L,U=c;null==i||null!=c&&"withCredentials"in c.prototype||(U=P),(k=r).EventSourcePolyfill=P,k.NativeEventSource=c,void 0!==(L=void(k.EventSource=U))&&(n.exports=L)}("undefined"==typeof globalThis?"undefined"!=typeof window?window:"undefined"!=typeof self?self:t:globalThis);var i,s,a=o.exports,c={exports:{}},u={exports:{}};i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s={rotl:function(t,e){return t<<e|t>>>32-e},rotr:function(t,e){return t<<32-e|t>>>e},endian:function(t){if(t.constructor==Number)return 16711935&s.rotl(t,8)|4278255360&s.rotl(t,24);for(var e=0;e<t.length;e++)t[e]=s.endian(t[e]);return t},randomBytes:function(t){for(var e=[];t>0;t--)e.push(Math.floor(256*Math.random()));return e},bytesToWords:function(t){for(var e=[],n=0,r=0;n<t.length;n++,r+=8)e[r>>>5]|=t[n]<<24-r%32;return e},wordsToBytes:function(t){for(var e=[],n=0;n<32*t.length;n+=8)e.push(t[n>>>5]>>>24-n%32&255);return e},bytesToHex:function(t){for(var e=[],n=0;n<t.length;n++)e.push((t[n]>>>4).toString(16)),e.push((15&t[n]).toString(16));return e.join("")},hexToBytes:function(t){for(var e=[],n=0;n<t.length;n+=2)e.push(parseInt(t.substr(n,2),16));return e},bytesToBase64:function(t){for(var e=[],n=0;n<t.length;n+=3)for(var r=t[n]<<16|t[n+1]<<8|t[n+2],o=0;o<4;o++)8*n+6*o<=8*t.length?e.push(i.charAt(r>>>6*(3-o)&63)):e.push("=");return e.join("")},base64ToBytes:function(t){t=t.replace(/[^A-Z0-9+\/]/gi,"");for(var e=[],n=0,r=0;n<t.length;r=++n%4)0!=r&&e.push((i.indexOf(t.charAt(n-1))&Math.pow(2,-2*r+8)-1)<<2*r|i.indexOf(t.charAt(n))>>>6-2*r);return e}},u.exports=s;var l,d,h,f,p,y=u.exports,g={utf8:{stringToBytes:function(t){return g.bin.stringToBytes(unescape(encodeURIComponent(t)))},bytesToString:function(t){return decodeURIComponent(escape(g.bin.bytesToString(t)))}},bin:{stringToBytes:function(t){for(var e=[],n=0;n<t.length;n++)e.push(255&t.charCodeAt(n));return e},bytesToString:function(t){for(var e=[],n=0;n<t.length;n++)e.push(String.fromCharCode(t[n]));return e.join("")}}},v=g,w=function(t){return null!=t&&(S(t)||function(t){return"function"==typeof t.readFloatLE&&"function"==typeof t.slice&&S(t.slice(0,0))}(t)||!!t._isBuffer)};function S(t){return!!t.constructor&&"function"==typeof t.constructor.isBuffer&&t.constructor.isBuffer(t)}l=y,d=v.utf8,h=w,f=v.bin,(p=function(t,e){t.constructor==String?t=e&&"binary"===e.encoding?f.stringToBytes(t):d.stringToBytes(t):h(t)?t=Array.prototype.slice.call(t,0):Array.isArray(t)||t.constructor===Uint8Array||(t=t.toString());for(var n=l.bytesToWords(t),r=8*t.length,o=1732584193,i=-271733879,s=-1732584194,a=271733878,c=0;c<n.length;c++)n[c]=16711935&(n[c]<<8|n[c]>>>24)|4278255360&(n[c]<<24|n[c]>>>8);n[r>>>5]|=128<<r%32,n[14+(r+64>>>9<<4)]=r;var u=p._ff,y=p._gg,g=p._hh,v=p._ii;for(c=0;c<n.length;c+=16){var w=o,S=i,_=s,E=a;o=u(o,i,s,a,n[c+0],7,-680876936),a=u(a,o,i,s,n[c+1],12,-389564586),s=u(s,a,o,i,n[c+2],17,606105819),i=u(i,s,a,o,n[c+3],22,-1044525330),o=u(o,i,s,a,n[c+4],7,-176418897),a=u(a,o,i,s,n[c+5],12,1200080426),s=u(s,a,o,i,n[c+6],17,-1473231341),i=u(i,s,a,o,n[c+7],22,-45705983),o=u(o,i,s,a,n[c+8],7,1770035416),a=u(a,o,i,s,n[c+9],12,-1958414417),s=u(s,a,o,i,n[c+10],17,-42063),i=u(i,s,a,o,n[c+11],22,-1990404162),o=u(o,i,s,a,n[c+12],7,1804603682),a=u(a,o,i,s,n[c+13],12,-40341101),s=u(s,a,o,i,n[c+14],17,-1502002290),o=y(o,i=u(i,s,a,o,n[c+15],22,1236535329),s,a,n[c+1],5,-165796510),a=y(a,o,i,s,n[c+6],9,-1069501632),s=y(s,a,o,i,n[c+11],14,643717713),i=y(i,s,a,o,n[c+0],20,-373897302),o=y(o,i,s,a,n[c+5],5,-701558691),a=y(a,o,i,s,n[c+10],9,38016083),s=y(s,a,o,i,n[c+15],14,-660478335),i=y(i,s,a,o,n[c+4],20,-405537848),o=y(o,i,s,a,n[c+9],5,568446438),a=y(a,o,i,s,n[c+14],9,-1019803690),s=y(s,a,o,i,n[c+3],14,-187363961),i=y(i,s,a,o,n[c+8],20,1163531501),o=y(o,i,s,a,n[c+13],5,-1444681467),a=y(a,o,i,s,n[c+2],9,-51403784),s=y(s,a,o,i,n[c+7],14,1735328473),o=g(o,i=y(i,s,a,o,n[c+12],20,-1926607734),s,a,n[c+5],4,-378558),a=g(a,o,i,s,n[c+8],11,-2022574463),s=g(s,a,o,i,n[c+11],16,1839030562),i=g(i,s,a,o,n[c+14],23,-35309556),o=g(o,i,s,a,n[c+1],4,-1530992060),a=g(a,o,i,s,n[c+4],11,1272893353),s=g(s,a,o,i,n[c+7],16,-155497632),i=g(i,s,a,o,n[c+10],23,-1094730640),o=g(o,i,s,a,n[c+13],4,681279174),a=g(a,o,i,s,n[c+0],11,-358537222),s=g(s,a,o,i,n[c+3],16,-722521979),i=g(i,s,a,o,n[c+6],23,76029189),o=g(o,i,s,a,n[c+9],4,-640364487),a=g(a,o,i,s,n[c+12],11,-421815835),s=g(s,a,o,i,n[c+15],16,530742520),o=v(o,i=g(i,s,a,o,n[c+2],23,-995338651),s,a,n[c+0],6,-198630844),a=v(a,o,i,s,n[c+7],10,1126891415),s=v(s,a,o,i,n[c+14],15,-1416354905),i=v(i,s,a,o,n[c+5],21,-57434055),o=v(o,i,s,a,n[c+12],6,1700485571),a=v(a,o,i,s,n[c+3],10,-1894986606),s=v(s,a,o,i,n[c+10],15,-1051523),i=v(i,s,a,o,n[c+1],21,-2054922799),o=v(o,i,s,a,n[c+8],6,1873313359),a=v(a,o,i,s,n[c+15],10,-30611744),s=v(s,a,o,i,n[c+6],15,-1560198380),i=v(i,s,a,o,n[c+13],21,1309151649),o=v(o,i,s,a,n[c+4],6,-145523070),a=v(a,o,i,s,n[c+11],10,-1120210379),s=v(s,a,o,i,n[c+2],15,718787259),i=v(i,s,a,o,n[c+9],21,-343485551),o=o+w>>>0,i=i+S>>>0,s=s+_>>>0,a=a+E>>>0}return l.endian([o,i,s,a])})._ff=function(t,e,n,r,o,i,s){var a=t+(e&n|~e&r)+(o>>>0)+s;return(a<<i|a>>>32-i)+e},p._gg=function(t,e,n,r,o,i,s){var a=t+(e&r|n&~r)+(o>>>0)+s;return(a<<i|a>>>32-i)+e},p._hh=function(t,e,n,r,o,i,s){var a=t+(e^n^r)+(o>>>0)+s;return(a<<i|a>>>32-i)+e},p._ii=function(t,e,n,r,o,i,s){var a=t+(n^(e|~r))+(o>>>0)+s;return(a<<i|a>>>32-i)+e},p._blocksize=16,p._digestsize=16,c.exports=function(t,e){if(null==t)throw new Error("Illegal argument "+t);var n=l.wordsToBytes(p(t,e));return e&&e.asBytes?n:e&&e.asString?f.bytesToString(n):l.bytesToHex(n)};const _=e(c.exports);module.exports=class{constructor(t={}){this.url=t.url,this.app_key=t.app_key,this.app_secret=t.app_secret,this.onMessage=t.onMessage||(()=>{}),this.onError=t.onError||(()=>{}),this.onOpen=t.onOpen||(()=>{}),this.onAudioData=t.onAudioData||(()=>{}),this.onAudioNegotiationSuccess=t.onAudioNegotiationSuccess||(()=>{}),this.onConnectSSE=t.onConnectSSE||(()=>{}),this.eventSource=null,this.negotiationResult=null}generateAuthToken(){const t=Math.floor(Date.now()/1e3);return`${this.app_key}:${t}:${_(`${this.app_secret}:${t}`)}`}getAuthHeaders(){return{Authorization:`${this.generateAuthToken()}`,"Content-Type":"application/json"}}async post(t,e){const n=this.generateAuthToken(),r=await fetch(`${this.url}${t}`,{method:"POST",headers:{Authorization:`${n}`,"Content-Type":"application/json","User-Agent":"XY-ASSIST-SDK"},body:JSON.stringify(e)});if(!r.ok){const t=await r.text();throw new Error(`HTTP error! status: ${r.status}, message: ${t}`)}return await r.json()}async audioNegotiation(t){const e=await this.post("/api/v1/agent/ccms/assist/audio-nego",t);return this.negotiationResult=e,this.onAudioNegotiationSuccess&&this.onAudioNegotiationSuccess(e),e}connectSSEWithNegotiationResult(){if(!this.negotiationResult||!this.negotiationResult.result)throw new Error("没有有效的协商结果,请先执行音频协商");const{sse_addr:t,client_id:e}=this.negotiationResult.result;if(!t||!e)throw new Error("协商结果中缺少sse_addr或client_id");const n=`http://${t}/sse?client_id=${e}`;this.connectSSEWithURL(n),this.onConnectSSE&&this.onConnectSSE({sseUrl:n,client_id:e,sse_addr:t})}connectSSEWithURL(t){this.eventSource=new a.EventSourcePolyfill(t),this.eventSource.onmessage=t=>{const e=JSON.parse(t.data);this.onMessage(e)},this.eventSource.onerror=t=>{this.onError(t)},this.eventSource.onopen=()=>{this.onOpen()}}connectSSE(t=!0){if(t&&this.negotiationResult&&this.negotiationResult.result&&this.negotiationResult.result.sse_addr)this.connectSSEWithNegotiationResult();else{const t=this.generateAuthToken(),e=`${this.url}/api/v1/agent/sse?auth=${t}`;this.eventSource=new a.EventSourcePolyfill(e),this.eventSource.onmessage=t=>{const e=JSON.parse(t.data);this.onMessage(e)},this.eventSource.onerror=t=>{this.onError(t)},this.eventSource.onopen=()=>{this.onOpen()}}}disconnectSSE(){this.eventSource&&(this.eventSource.close(),this.eventSource=null)}async startAssistAudioStream(t){const{app_id:e,dest_addr:n,call_id:r,direction:o,caller:i,called:s,skill_id:a,agent_no:c}=t;if(!e)throw new Error("app_id 是必需的参数");if(!n)throw new Error("dest_addr 是必需的参数");if(!r)throw new Error("call_id 是必需的参数");if(!o)throw new Error("direction 是必需的参数");if(!i)throw new Error("caller 是必需的参数");if(!s)throw new Error("called 是必需的参数");if(!a)throw new Error("skill_id 是必需的参数");if(!c)throw new Error("agent_no 是必需的参数");const u={app_id:e,dest_addr:n,call_id:r,direction:o,caller:i,called:s,skill_id:a,agent_no:c};return await this.post("/v1/base/cti/assist/start",u)}async stopAssistAudioStream(t){const{app_id:e,call_id:n}=t;if(!e)throw new Error("app_id 是必需的参数");if(!n)throw new Error("call_id 是必需的参数");const r={app_id:e,call_id:n};return await this.post("/v1/base/cti/assist/stop",r)}};
|
|
@@ -910,6 +910,7 @@ var eventsource = { exports: {} };
|
|
|
910
910
|
});
|
|
911
911
|
})(typeof globalThis === "undefined" ? typeof window !== "undefined" ? window : typeof self !== "undefined" ? self : commonjsGlobal : globalThis);
|
|
912
912
|
})(eventsource, eventsource.exports);
|
|
913
|
+
var eventsourceExports = eventsource.exports;
|
|
913
914
|
var md5$1 = { exports: {} };
|
|
914
915
|
var crypt = { exports: {} };
|
|
915
916
|
(function() {
|
|
@@ -1228,7 +1229,7 @@ class AgentAssistantSDK {
|
|
|
1228
1229
|
}
|
|
1229
1230
|
// 使用指定URL连接SSE(辅助方法)
|
|
1230
1231
|
connectSSEWithURL(sseUrl) {
|
|
1231
|
-
this.eventSource = new
|
|
1232
|
+
this.eventSource = new eventsourceExports.EventSourcePolyfill(sseUrl);
|
|
1232
1233
|
this.eventSource.onmessage = (event) => {
|
|
1233
1234
|
const data = JSON.parse(event.data);
|
|
1234
1235
|
this.onMessage(data);
|
|
@@ -1248,7 +1249,7 @@ class AgentAssistantSDK {
|
|
|
1248
1249
|
} else {
|
|
1249
1250
|
const authToken = this.generateAuthToken();
|
|
1250
1251
|
const sseUrl = `${this.url}/api/v1/agent/sse?auth=${authToken}`;
|
|
1251
|
-
this.eventSource = new
|
|
1252
|
+
this.eventSource = new eventsourceExports.EventSourcePolyfill(sseUrl);
|
|
1252
1253
|
this.eventSource.onmessage = (event) => {
|
|
1253
1254
|
const data = JSON.parse(event.data);
|
|
1254
1255
|
this.onMessage(data);
|
|
@@ -1268,6 +1269,74 @@ class AgentAssistantSDK {
|
|
|
1268
1269
|
this.eventSource = null;
|
|
1269
1270
|
}
|
|
1270
1271
|
}
|
|
1272
|
+
// 开启坐席辅助音频流
|
|
1273
|
+
async startAssistAudioStream(params) {
|
|
1274
|
+
const {
|
|
1275
|
+
app_id,
|
|
1276
|
+
dest_addr,
|
|
1277
|
+
call_id,
|
|
1278
|
+
direction,
|
|
1279
|
+
caller,
|
|
1280
|
+
called,
|
|
1281
|
+
skill_id,
|
|
1282
|
+
agent_no
|
|
1283
|
+
} = params;
|
|
1284
|
+
if (!app_id) {
|
|
1285
|
+
throw new Error("app_id 是必需的参数");
|
|
1286
|
+
}
|
|
1287
|
+
if (!dest_addr) {
|
|
1288
|
+
throw new Error("dest_addr 是必需的参数");
|
|
1289
|
+
}
|
|
1290
|
+
if (!call_id) {
|
|
1291
|
+
throw new Error("call_id 是必需的参数");
|
|
1292
|
+
}
|
|
1293
|
+
if (!direction) {
|
|
1294
|
+
throw new Error("direction 是必需的参数");
|
|
1295
|
+
}
|
|
1296
|
+
if (!caller) {
|
|
1297
|
+
throw new Error("caller 是必需的参数");
|
|
1298
|
+
}
|
|
1299
|
+
if (!called) {
|
|
1300
|
+
throw new Error("called 是必需的参数");
|
|
1301
|
+
}
|
|
1302
|
+
if (!skill_id) {
|
|
1303
|
+
throw new Error("skill_id 是必需的参数");
|
|
1304
|
+
}
|
|
1305
|
+
if (!agent_no) {
|
|
1306
|
+
throw new Error("agent_no 是必需的参数");
|
|
1307
|
+
}
|
|
1308
|
+
const endpoint = "/v1/base/cti/assist/start";
|
|
1309
|
+
const data = {
|
|
1310
|
+
app_id,
|
|
1311
|
+
dest_addr,
|
|
1312
|
+
call_id,
|
|
1313
|
+
direction,
|
|
1314
|
+
caller,
|
|
1315
|
+
called,
|
|
1316
|
+
skill_id,
|
|
1317
|
+
agent_no
|
|
1318
|
+
};
|
|
1319
|
+
return await this.post(endpoint, data);
|
|
1320
|
+
}
|
|
1321
|
+
// 停止坐席辅助音频流
|
|
1322
|
+
async stopAssistAudioStream(params) {
|
|
1323
|
+
const {
|
|
1324
|
+
app_id,
|
|
1325
|
+
call_id
|
|
1326
|
+
} = params;
|
|
1327
|
+
if (!app_id) {
|
|
1328
|
+
throw new Error("app_id 是必需的参数");
|
|
1329
|
+
}
|
|
1330
|
+
if (!call_id) {
|
|
1331
|
+
throw new Error("call_id 是必需的参数");
|
|
1332
|
+
}
|
|
1333
|
+
const endpoint = "/v1/base/cti/assist/stop";
|
|
1334
|
+
const data = {
|
|
1335
|
+
app_id,
|
|
1336
|
+
call_id
|
|
1337
|
+
};
|
|
1338
|
+
return await this.post(endpoint, data);
|
|
1339
|
+
}
|
|
1271
1340
|
}
|
|
1272
1341
|
export {
|
|
1273
1342
|
AgentAssistantSDK as default
|
|
@@ -3,4 +3,4 @@
|
|
|
3
3
|
* eventsource.js
|
|
4
4
|
* Available under MIT License (MIT)
|
|
5
5
|
* https://github.com/Yaffle/EventSource/
|
|
6
|
-
*/n=r,o=r.exports,function(t){var e=t.setTimeout,r=t.clearTimeout,i=t.XMLHttpRequest,s=t.XDomainRequest,a=t.ActiveXObject,u=t.EventSource,c=t.document,l=t.Promise,h=t.fetch,d=t.Response,f=t.TextDecoder,p=t.TextEncoder,y=t.AbortController;if("undefined"==typeof window||void 0===c||"readyState"in c||null!=c.body||(c.readyState="loading",window.addEventListener("load",function(t){c.readyState="complete"},!1)),null==i&&null!=a&&(i=function(){return new a("Microsoft.XMLHTTP")}),null==Object.create&&(Object.create=function(t){function e(){}return e.prototype=t,new e}),Date.now||(Date.now=function(){return(new Date).getTime()}),null==y){var g=h;h=function(t,e){var n=e.signal;return g(t,{headers:e.headers,credentials:e.credentials,cache:e.cache}).then(function(t){var e=t.body.getReader();return n._reader=e,n._aborted&&n._reader.cancel(),{status:t.status,statusText:t.statusText,headers:t.headers,body:{getReader:function(){return e}}}})},y=function(){this.signal={_reader:null,_aborted:!1},this.abort=function(){null!=this.signal._reader&&this.signal._reader.cancel(),this.signal._aborted=!0}}}function v(){this.bitsNeeded=0,this.codePoint=0}v.prototype.decode=function(t){function e(t,e,n){if(1===n)return t>=128>>e&&t<<e<=2047;if(2===n)return t>=2048>>e&&t<<e<=55295||t>=57344>>e&&t<<e<=65535;if(3===n)return t>=65536>>e&&t<<e<=1114111;throw new Error}function n(t,e){if(6===t)return e>>6>15?3:e>31?2:1;if(12===t)return e>15?3:2;if(18===t)return 3;throw new Error}for(var o=65533,r="",i=this.bitsNeeded,s=this.codePoint,a=0;a<t.length;a+=1){var u=t[a];0!==i&&(u<128||u>191||!e(s<<6|63&u,i-6,n(i,s)))&&(i=0,s=o,r+=String.fromCharCode(s)),0===i?(u>=0&&u<=127?(i=0,s=u):u>=192&&u<=223?(i=6,s=31&u):u>=224&&u<=239?(i=12,s=15&u):u>=240&&u<=247?(i=18,s=7&u):(i=0,s=o),0===i||e(s,i,n(i,s))||(i=0,s=o)):(i-=6,s=s<<6|63&u),0===i&&(s<=65535?r+=String.fromCharCode(s):(r+=String.fromCharCode(55296+(s-65535-1>>10)),r+=String.fromCharCode(56320+(s-65535-1&1023))))}return this.bitsNeeded=i,this.codePoint=s,r},null!=f&&null!=p&&function(){try{return"test"===(new f).decode((new p).encode("test"),{stream:!0})}catch(t){console.debug("TextDecoder does not support streaming option. Using polyfill instead: "+t)}return!1}()||(f=v);var S=function(){};function w(t){this.withCredentials=!1,this.readyState=0,this.status=0,this.statusText="",this.responseText="",this.onprogress=S,this.onload=S,this.onerror=S,this.onreadystatechange=S,this._contentType="",this._xhr=t,this._sendTimeout=0,this._abort=S}function T(t){return t.replace(/[A-Z]/g,function(t){return String.fromCharCode(t.charCodeAt(0)+32)})}function b(t){for(var e=Object.create(null),n=t.split("\r\n"),o=0;o<n.length;o+=1){var r=n[o].split(": "),i=r.shift(),s=r.join(": ");e[T(i)]=s}this._map=e}function E(){}function _(t){this._headers=t}function m(){}function C(){this._listeners=Object.create(null)}function A(t){e(function(){throw t},0)}function x(t){this.type=t,this.target=void 0}function R(t,e){x.call(this,t),this.data=e.data,this.lastEventId=e.lastEventId}function O(t,e){x.call(this,t),this.status=e.status,this.statusText=e.statusText,this.headers=e.headers}function N(t,e){x.call(this,t),this.error=e.error}w.prototype.open=function(t,n){this._abort(!0);var o=this,s=this._xhr,a=1,u=0;this._abort=function(t){0!==o._sendTimeout&&(r(o._sendTimeout),o._sendTimeout=0),1!==a&&2!==a&&3!==a||(a=4,s.onload=S,s.onerror=S,s.onabort=S,s.onprogress=S,s.onreadystatechange=S,s.abort(),0!==u&&(r(u),u=0),t||(o.readyState=4,o.onabort(null),o.onreadystatechange())),a=0};var c=function(){if(1===a){var t=0,e="",n=void 0;if("contentType"in s)t=200,e="OK",n=s.contentType;else try{t=s.status,e=s.statusText,n=s.getResponseHeader("Content-Type")}catch(r){t=0,e="",n=void 0}0!==t&&(a=2,o.readyState=2,o.status=t,o.statusText=e,o._contentType=n,o.onreadystatechange())}},l=function(){if(c(),2===a||3===a){a=3;var t="";try{t=s.responseText}catch(e){}o.readyState=3,o.responseText=t,o.onprogress()}},h=function(t,e){if(null!=e&&null!=e.preventDefault||(e={preventDefault:S}),l(),1===a||2===a||3===a){if(a=4,0!==u&&(r(u),u=0),o.readyState=4,"load"===t)o.onload(e);else if("error"===t)o.onerror(e);else{if("abort"!==t)throw new TypeError;o.onabort(e)}o.onreadystatechange()}},d=function(){u=e(function(){d()},500),3===s.readyState&&l()};"onload"in s&&(s.onload=function(t){h("load",t)}),"onerror"in s&&(s.onerror=function(t){h("error",t)}),"onabort"in s&&(s.onabort=function(t){h("abort",t)}),"onprogress"in s&&(s.onprogress=l),"onreadystatechange"in s&&(s.onreadystatechange=function(t){!function(t){null!=s&&(4===s.readyState?"onload"in s&&"onerror"in s&&"onabort"in s||h(""===s.responseText?"error":"load",t):3===s.readyState?"onprogress"in s||l():2===s.readyState&&c())}(t)}),!("contentType"in s)&&"ontimeout"in i.prototype||(n+=(-1===n.indexOf("?")?"?":"&")+"padding=true"),s.open(t,n,!0),"readyState"in s&&(u=e(function(){d()},0))},w.prototype.abort=function(){this._abort(!1)},w.prototype.getResponseHeader=function(t){return this._contentType},w.prototype.setRequestHeader=function(t,e){var n=this._xhr;"setRequestHeader"in n&&n.setRequestHeader(t,e)},w.prototype.getAllResponseHeaders=function(){return null!=this._xhr.getAllResponseHeaders&&this._xhr.getAllResponseHeaders()||""},w.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 t=this._xhr;"withCredentials"in t&&(t.withCredentials=this.withCredentials);try{t.send(void 0)}catch(o){throw o}}else{var n=this;n._sendTimeout=e(function(){n._sendTimeout=0,n.send()},4)}},b.prototype.get=function(t){return this._map[T(t)]},null!=i&&null==i.HEADERS_RECEIVED&&(i.HEADERS_RECEIVED=2),E.prototype.open=function(t,e,n,o,r,s,a){t.open("GET",r);var u=0;for(var c in t.onprogress=function(){var e=t.responseText.slice(u);u+=e.length,n(e)},t.onerror=function(t){t.preventDefault(),o(new Error("NetworkError"))},t.onload=function(){o(null)},t.onabort=function(){o(null)},t.onreadystatechange=function(){if(t.readyState===i.HEADERS_RECEIVED){var n=t.status,o=t.statusText,r=t.getResponseHeader("Content-Type"),s=t.getAllResponseHeaders();e(n,o,r,new b(s))}},t.withCredentials=s,a)Object.prototype.hasOwnProperty.call(a,c)&&t.setRequestHeader(c,a[c]);return t.send(),t},_.prototype.get=function(t){return this._headers.get(t)},m.prototype.open=function(t,e,n,o,r,i,s){var a=null,u=new y,c=u.signal,d=new f;return h(r,{headers:s,credentials:i?"include":"same-origin",signal:c,cache:"no-store"}).then(function(t){return a=t.body.getReader(),e(t.status,t.statusText,t.headers.get("Content-Type"),new _(t.headers)),new l(function(t,e){var o=function(){a.read().then(function(e){if(e.done)t(void 0);else{var r=d.decode(e.value,{stream:!0});n(r),o()}}).catch(function(t){e(t)})};o()})}).catch(function(t){return"AbortError"===t.name?void 0:t}).then(function(t){o(t)}),{abort:function(){null!=a&&a.cancel(),u.abort()}}},C.prototype.dispatchEvent=function(t){t.target=this;var e=this._listeners[t.type];if(null!=e)for(var n=e.length,o=0;o<n;o+=1){var r=e[o];try{"function"==typeof r.handleEvent?r.handleEvent(t):r.call(this,t)}catch(i){A(i)}}},C.prototype.addEventListener=function(t,e){t=String(t);var n=this._listeners,o=n[t];null==o&&(o=[],n[t]=o);for(var r=!1,i=0;i<o.length;i+=1)o[i]===e&&(r=!0);r||o.push(e)},C.prototype.removeEventListener=function(t,e){t=String(t);var n=this._listeners,o=n[t];if(null!=o){for(var r=[],i=0;i<o.length;i+=1)o[i]!==e&&r.push(o[i]);0===r.length?delete n[t]:n[t]=r}},R.prototype=Object.create(x.prototype),O.prototype=Object.create(x.prototype),N.prototype=Object.create(x.prototype);var D=-1,j=-1,H=/^text\/event\-stream(;.*)?$/i,B=function(t,e){var n=null==t?e:parseInt(t,10);return n!=n&&(n=e),I(n)},I=function(t){return Math.min(Math.max(t,1e3),18e6)},M=function(t,e,n){try{"function"==typeof e&&e.call(t,n)}catch(o){A(o)}};function $(t,n){C.call(this),n=n||{},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(t,n,o){n=String(n);var a=Boolean(o.withCredentials),u=o.lastEventIdQueryParameterName||"lastEventId",c=I(1e3),l=B(o.heartbeatTimeout,45e3),h="",d=c,f=!1,p=0,y=o.headers||{},g=o.Transport,v=P&&null==g?void 0:new w(null!=g?new g:null!=i&&"withCredentials"in i.prototype||null==s?new i:new s),S=null!=g&&"string"!=typeof g?new g:null==v?new m:new E,T=void 0,b=0,_=D,C="",A="",x="",$="",k=0,L=0,U=0,q=function(e,n,o,r){if(0===_)if(200===e&&null!=o&&H.test(o)){_=1,f=Date.now(),d=c,t.readyState=1;var i=new O("open",{status:e,statusText:n,headers:r});t.dispatchEvent(i),M(t,t.onopen,i)}else{var s="";200!==e?(n&&(n=n.replace(/\s+/g," ")),s="EventSource's response has a status "+e+" "+n+" that is not 200. Aborting the connection."):s="EventSource's response has a Content-Type specifying an unsupported type: "+(null==o?"-":o.replace(/\s+/g," "))+". Aborting the connection.",X(),i=new O("error",{status:e,statusText:n,headers:r}),t.dispatchEvent(i),M(t,t.onerror,i),console.error(s)}},W=function(n){if(1===_){for(var o=-1,i=0;i<n.length;i+=1)(u=n.charCodeAt(i))!=="\n".charCodeAt(0)&&u!=="\r".charCodeAt(0)||(o=i);var s=(-1!==o?$:"")+n.slice(0,o+1);$=(-1===o?$:"")+n.slice(o+1),""!==n&&(f=Date.now(),p+=n.length);for(var a=0;a<s.length;a+=1){var u=s.charCodeAt(a);if(k===j&&u==="\n".charCodeAt(0))k=0;else if(k===j&&(k=0),u==="\r".charCodeAt(0)||u==="\n".charCodeAt(0)){if(0!==k){1===k&&(U=a+1);var y=s.slice(L,U-1),g=s.slice(U+(U<a&&s.charCodeAt(U)===" ".charCodeAt(0)?1:0),a);"data"===y?(C+="\n",C+=g):"id"===y?A=g:"event"===y?x=g:"retry"===y?(c=B(g,c),d=c):"heartbeatTimeout"===y&&(l=B(g,l),0!==b&&(r(b),b=e(function(){G()},l)))}if(0===k){if(""!==C){h=A,""===x&&(x="message");var v=new R(x,{data:C.slice(1),lastEventId:A});if(t.dispatchEvent(v),"open"===x?M(t,t.onopen,v):"message"===x?M(t,t.onmessage,v):"error"===x&&M(t,t.onerror,v),2===_)return}C="",x=""}k=u==="\r".charCodeAt(0)?j:0}else 0===k&&(L=a,k=1),1===k?u===":".charCodeAt(0)&&(U=a+1,k=2):2===k&&(k=3)}}},z=function(n){if(1===_||0===_){_=D,0!==b&&(r(b),b=0),b=e(function(){G()},d),d=I(Math.min(16*c,2*d)),t.readyState=0;var o=new N("error",{error:n});t.dispatchEvent(o),M(t,t.onerror,o),null!=n&&console.error(n)}},X=function(){_=2,null!=T&&(T.abort(),T=void 0),0!==b&&(r(b),b=0),t.readyState=2},G=function(){if(b=0,_===D){f=!1,p=0,b=e(function(){G()},l),_=0,C="",x="",A=h,$="",L=0,U=0,k=0;var o=n;if("data:"!==n.slice(0,5)&&"blob:"!==n.slice(0,5)&&""!==h){var r=n.indexOf("?");o=-1===r?n:n.slice(0,r+1)+n.slice(r+1).replace(/(?:^|&)([^=&]*)(?:=[^&]*)?/g,function(t,e){return e===u?"":t}),o+=(-1===n.indexOf("?")?"?":"&")+u+"="+encodeURIComponent(h)}var i=t.withCredentials,s={Accept:"text/event-stream"},a=t.headers;if(null!=a)for(var c in a)Object.prototype.hasOwnProperty.call(a,c)&&(s[c]=a[c]);try{T=S.open(v,q,W,z,o,i,s)}catch(y){throw X(),y}}else if(f||null==T){var d=Math.max((f||Date.now())+l-Date.now(),1);f=!1,b=e(function(){G()},d)}else z(new Error("No activity within "+l+" milliseconds. "+(0===_?"No response received.":p+" chars received.")+" Reconnecting.")),null!=T&&(T.abort(),T=void 0)};t.url=n,t.readyState=0,t.withCredentials=a,t.headers=y,t._close=X,G()}(this,t,n)}var P=null!=h&&null!=d&&"body"in d.prototype;$.prototype=Object.create(C.prototype),$.prototype.CONNECTING=0,$.prototype.OPEN=1,$.prototype.CLOSED=2,$.prototype.close=function(){this._close()},$.CONNECTING=0,$.OPEN=1,$.CLOSED=2,$.prototype.withCredentials=void 0;var k,L,U=u;null==i||null!=u&&"withCredentials"in u.prototype||(U=$),(k=o).EventSourcePolyfill=$,k.NativeEventSource=u,void 0!==(L=void(k.EventSource=U))&&(n.exports=L)}("undefined"==typeof globalThis?"undefined"!=typeof window?window:"undefined"!=typeof self?self:t:globalThis);var i,s,a={exports:{}},u={exports:{}};i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s={rotl:function(t,e){return t<<e|t>>>32-e},rotr:function(t,e){return t<<32-e|t>>>e},endian:function(t){if(t.constructor==Number)return 16711935&s.rotl(t,8)|4278255360&s.rotl(t,24);for(var e=0;e<t.length;e++)t[e]=s.endian(t[e]);return t},randomBytes:function(t){for(var e=[];t>0;t--)e.push(Math.floor(256*Math.random()));return e},bytesToWords:function(t){for(var e=[],n=0,o=0;n<t.length;n++,o+=8)e[o>>>5]|=t[n]<<24-o%32;return e},wordsToBytes:function(t){for(var e=[],n=0;n<32*t.length;n+=8)e.push(t[n>>>5]>>>24-n%32&255);return e},bytesToHex:function(t){for(var e=[],n=0;n<t.length;n++)e.push((t[n]>>>4).toString(16)),e.push((15&t[n]).toString(16));return e.join("")},hexToBytes:function(t){for(var e=[],n=0;n<t.length;n+=2)e.push(parseInt(t.substr(n,2),16));return e},bytesToBase64:function(t){for(var e=[],n=0;n<t.length;n+=3)for(var o=t[n]<<16|t[n+1]<<8|t[n+2],r=0;r<4;r++)8*n+6*r<=8*t.length?e.push(i.charAt(o>>>6*(3-r)&63)):e.push("=");return e.join("")},base64ToBytes:function(t){t=t.replace(/[^A-Z0-9+\/]/gi,"");for(var e=[],n=0,o=0;n<t.length;o=++n%4)0!=o&&e.push((i.indexOf(t.charAt(n-1))&Math.pow(2,-2*o+8)-1)<<2*o|i.indexOf(t.charAt(n))>>>6-2*o);return e}},u.exports=s;var c,l,h,d,f,p=u.exports,y={utf8:{stringToBytes:function(t){return y.bin.stringToBytes(unescape(encodeURIComponent(t)))},bytesToString:function(t){return decodeURIComponent(escape(y.bin.bytesToString(t)))}},bin:{stringToBytes:function(t){for(var e=[],n=0;n<t.length;n++)e.push(255&t.charCodeAt(n));return e},bytesToString:function(t){for(var e=[],n=0;n<t.length;n++)e.push(String.fromCharCode(t[n]));return e.join("")}}},g=y,v=function(t){return null!=t&&(S(t)||function(t){return"function"==typeof t.readFloatLE&&"function"==typeof t.slice&&S(t.slice(0,0))}(t)||!!t._isBuffer)};function S(t){return!!t.constructor&&"function"==typeof t.constructor.isBuffer&&t.constructor.isBuffer(t)}c=p,l=g.utf8,h=v,d=g.bin,(f=function(t,e){t.constructor==String?t=e&&"binary"===e.encoding?d.stringToBytes(t):l.stringToBytes(t):h(t)?t=Array.prototype.slice.call(t,0):Array.isArray(t)||t.constructor===Uint8Array||(t=t.toString());for(var n=c.bytesToWords(t),o=8*t.length,r=1732584193,i=-271733879,s=-1732584194,a=271733878,u=0;u<n.length;u++)n[u]=16711935&(n[u]<<8|n[u]>>>24)|4278255360&(n[u]<<24|n[u]>>>8);n[o>>>5]|=128<<o%32,n[14+(o+64>>>9<<4)]=o;var p=f._ff,y=f._gg,g=f._hh,v=f._ii;for(u=0;u<n.length;u+=16){var S=r,w=i,T=s,b=a;r=p(r,i,s,a,n[u+0],7,-680876936),a=p(a,r,i,s,n[u+1],12,-389564586),s=p(s,a,r,i,n[u+2],17,606105819),i=p(i,s,a,r,n[u+3],22,-1044525330),r=p(r,i,s,a,n[u+4],7,-176418897),a=p(a,r,i,s,n[u+5],12,1200080426),s=p(s,a,r,i,n[u+6],17,-1473231341),i=p(i,s,a,r,n[u+7],22,-45705983),r=p(r,i,s,a,n[u+8],7,1770035416),a=p(a,r,i,s,n[u+9],12,-1958414417),s=p(s,a,r,i,n[u+10],17,-42063),i=p(i,s,a,r,n[u+11],22,-1990404162),r=p(r,i,s,a,n[u+12],7,1804603682),a=p(a,r,i,s,n[u+13],12,-40341101),s=p(s,a,r,i,n[u+14],17,-1502002290),r=y(r,i=p(i,s,a,r,n[u+15],22,1236535329),s,a,n[u+1],5,-165796510),a=y(a,r,i,s,n[u+6],9,-1069501632),s=y(s,a,r,i,n[u+11],14,643717713),i=y(i,s,a,r,n[u+0],20,-373897302),r=y(r,i,s,a,n[u+5],5,-701558691),a=y(a,r,i,s,n[u+10],9,38016083),s=y(s,a,r,i,n[u+15],14,-660478335),i=y(i,s,a,r,n[u+4],20,-405537848),r=y(r,i,s,a,n[u+9],5,568446438),a=y(a,r,i,s,n[u+14],9,-1019803690),s=y(s,a,r,i,n[u+3],14,-187363961),i=y(i,s,a,r,n[u+8],20,1163531501),r=y(r,i,s,a,n[u+13],5,-1444681467),a=y(a,r,i,s,n[u+2],9,-51403784),s=y(s,a,r,i,n[u+7],14,1735328473),r=g(r,i=y(i,s,a,r,n[u+12],20,-1926607734),s,a,n[u+5],4,-378558),a=g(a,r,i,s,n[u+8],11,-2022574463),s=g(s,a,r,i,n[u+11],16,1839030562),i=g(i,s,a,r,n[u+14],23,-35309556),r=g(r,i,s,a,n[u+1],4,-1530992060),a=g(a,r,i,s,n[u+4],11,1272893353),s=g(s,a,r,i,n[u+7],16,-155497632),i=g(i,s,a,r,n[u+10],23,-1094730640),r=g(r,i,s,a,n[u+13],4,681279174),a=g(a,r,i,s,n[u+0],11,-358537222),s=g(s,a,r,i,n[u+3],16,-722521979),i=g(i,s,a,r,n[u+6],23,76029189),r=g(r,i,s,a,n[u+9],4,-640364487),a=g(a,r,i,s,n[u+12],11,-421815835),s=g(s,a,r,i,n[u+15],16,530742520),r=v(r,i=g(i,s,a,r,n[u+2],23,-995338651),s,a,n[u+0],6,-198630844),a=v(a,r,i,s,n[u+7],10,1126891415),s=v(s,a,r,i,n[u+14],15,-1416354905),i=v(i,s,a,r,n[u+5],21,-57434055),r=v(r,i,s,a,n[u+12],6,1700485571),a=v(a,r,i,s,n[u+3],10,-1894986606),s=v(s,a,r,i,n[u+10],15,-1051523),i=v(i,s,a,r,n[u+1],21,-2054922799),r=v(r,i,s,a,n[u+8],6,1873313359),a=v(a,r,i,s,n[u+15],10,-30611744),s=v(s,a,r,i,n[u+6],15,-1560198380),i=v(i,s,a,r,n[u+13],21,1309151649),r=v(r,i,s,a,n[u+4],6,-145523070),a=v(a,r,i,s,n[u+11],10,-1120210379),s=v(s,a,r,i,n[u+2],15,718787259),i=v(i,s,a,r,n[u+9],21,-343485551),r=r+S>>>0,i=i+w>>>0,s=s+T>>>0,a=a+b>>>0}return c.endian([r,i,s,a])})._ff=function(t,e,n,o,r,i,s){var a=t+(e&n|~e&o)+(r>>>0)+s;return(a<<i|a>>>32-i)+e},f._gg=function(t,e,n,o,r,i,s){var a=t+(e&o|n&~o)+(r>>>0)+s;return(a<<i|a>>>32-i)+e},f._hh=function(t,e,n,o,r,i,s){var a=t+(e^n^o)+(r>>>0)+s;return(a<<i|a>>>32-i)+e},f._ii=function(t,e,n,o,r,i,s){var a=t+(n^(e|~o))+(r>>>0)+s;return(a<<i|a>>>32-i)+e},f._blocksize=16,f._digestsize=16,a.exports=function(t,e){if(null==t)throw new Error("Illegal argument "+t);var n=c.wordsToBytes(f(t,e));return e&&e.asBytes?n:e&&e.asString?d.bytesToString(n):c.bytesToHex(n)};const w=e(a.exports);return class{constructor(t={}){this.url=t.url,this.app_key=t.app_key,this.app_secret=t.app_secret,this.onMessage=t.onMessage||(()=>{}),this.onError=t.onError||(()=>{}),this.onOpen=t.onOpen||(()=>{}),this.onAudioData=t.onAudioData||(()=>{}),this.onAudioNegotiationSuccess=t.onAudioNegotiationSuccess||(()=>{}),this.onConnectSSE=t.onConnectSSE||(()=>{}),this.eventSource=null,this.negotiationResult=null}generateAuthToken(){const t=Math.floor(Date.now()/1e3);return`${this.app_key}:${t}:${w(`${this.app_secret}:${t}`)}`}getAuthHeaders(){return{Authorization:`${this.generateAuthToken()}`,"Content-Type":"application/json"}}async post(t,e){const n=this.generateAuthToken(),o=await fetch(`${this.url}${t}`,{method:"POST",headers:{Authorization:`${n}`,"Content-Type":"application/json","User-Agent":"XY-ASSIST-SDK"},body:JSON.stringify(e)});if(!o.ok){const t=await o.text();throw new Error(`HTTP error! status: ${o.status}, message: ${t}`)}return await o.json()}async audioNegotiation(t){const e=await this.post("/api/v1/agent/ccms/assist/audio-nego",t);return this.negotiationResult=e,this.onAudioNegotiationSuccess&&this.onAudioNegotiationSuccess(e),e}connectSSEWithNegotiationResult(){if(!this.negotiationResult||!this.negotiationResult.result)throw new Error("没有有效的协商结果,请先执行音频协商");const{sse_addr:t,client_id:e}=this.negotiationResult.result;if(!t||!e)throw new Error("协商结果中缺少sse_addr或client_id");const n=`http://${t}/sse?client_id=${e}`;this.connectSSEWithURL(n),this.onConnectSSE&&this.onConnectSSE({sseUrl:n,client_id:e,sse_addr:t})}connectSSEWithURL(t){this.eventSource=new EventSource(t),this.eventSource.onmessage=t=>{const e=JSON.parse(t.data);this.onMessage(e)},this.eventSource.onerror=t=>{this.onError(t)},this.eventSource.onopen=()=>{this.onOpen()}}connectSSE(t=!0){if(t&&this.negotiationResult&&this.negotiationResult.result&&this.negotiationResult.result.sse_addr)this.connectSSEWithNegotiationResult();else{const t=this.generateAuthToken(),e=`${this.url}/api/v1/agent/sse?auth=${t}`;this.eventSource=new EventSource(e),this.eventSource.onmessage=t=>{const e=JSON.parse(t.data);this.onMessage(e)},this.eventSource.onerror=t=>{this.onError(t)},this.eventSource.onopen=()=>{this.onOpen()}}}disconnectSSE(){this.eventSource&&(this.eventSource.close(),this.eventSource=null)}}});
|
|
6
|
+
*/n=r,o=r.exports,function(t){var e=t.setTimeout,r=t.clearTimeout,i=t.XMLHttpRequest,s=t.XDomainRequest,a=t.ActiveXObject,u=t.EventSource,c=t.document,l=t.Promise,d=t.fetch,h=t.Response,f=t.TextDecoder,p=t.TextEncoder,y=t.AbortController;if("undefined"==typeof window||void 0===c||"readyState"in c||null!=c.body||(c.readyState="loading",window.addEventListener("load",function(t){c.readyState="complete"},!1)),null==i&&null!=a&&(i=function(){return new a("Microsoft.XMLHTTP")}),null==Object.create&&(Object.create=function(t){function e(){}return e.prototype=t,new e}),Date.now||(Date.now=function(){return(new Date).getTime()}),null==y){var g=d;d=function(t,e){var n=e.signal;return g(t,{headers:e.headers,credentials:e.credentials,cache:e.cache}).then(function(t){var e=t.body.getReader();return n._reader=e,n._aborted&&n._reader.cancel(),{status:t.status,statusText:t.statusText,headers:t.headers,body:{getReader:function(){return e}}}})},y=function(){this.signal={_reader:null,_aborted:!1},this.abort=function(){null!=this.signal._reader&&this.signal._reader.cancel(),this.signal._aborted=!0}}}function v(){this.bitsNeeded=0,this.codePoint=0}v.prototype.decode=function(t){function e(t,e,n){if(1===n)return t>=128>>e&&t<<e<=2047;if(2===n)return t>=2048>>e&&t<<e<=55295||t>=57344>>e&&t<<e<=65535;if(3===n)return t>=65536>>e&&t<<e<=1114111;throw new Error}function n(t,e){if(6===t)return e>>6>15?3:e>31?2:1;if(12===t)return e>15?3:2;if(18===t)return 3;throw new Error}for(var o=65533,r="",i=this.bitsNeeded,s=this.codePoint,a=0;a<t.length;a+=1){var u=t[a];0!==i&&(u<128||u>191||!e(s<<6|63&u,i-6,n(i,s)))&&(i=0,s=o,r+=String.fromCharCode(s)),0===i?(u>=0&&u<=127?(i=0,s=u):u>=192&&u<=223?(i=6,s=31&u):u>=224&&u<=239?(i=12,s=15&u):u>=240&&u<=247?(i=18,s=7&u):(i=0,s=o),0===i||e(s,i,n(i,s))||(i=0,s=o)):(i-=6,s=s<<6|63&u),0===i&&(s<=65535?r+=String.fromCharCode(s):(r+=String.fromCharCode(55296+(s-65535-1>>10)),r+=String.fromCharCode(56320+(s-65535-1&1023))))}return this.bitsNeeded=i,this.codePoint=s,r},null!=f&&null!=p&&function(){try{return"test"===(new f).decode((new p).encode("test"),{stream:!0})}catch(t){console.debug("TextDecoder does not support streaming option. Using polyfill instead: "+t)}return!1}()||(f=v);var w=function(){};function S(t){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=t,this._sendTimeout=0,this._abort=w}function _(t){return t.replace(/[A-Z]/g,function(t){return String.fromCharCode(t.charCodeAt(0)+32)})}function b(t){for(var e=Object.create(null),n=t.split("\r\n"),o=0;o<n.length;o+=1){var r=n[o].split(": "),i=r.shift(),s=r.join(": ");e[_(i)]=s}this._map=e}function E(){}function T(t){this._headers=t}function m(){}function C(){this._listeners=Object.create(null)}function A(t){e(function(){throw t},0)}function x(t){this.type=t,this.target=void 0}function R(t,e){x.call(this,t),this.data=e.data,this.lastEventId=e.lastEventId}function O(t,e){x.call(this,t),this.status=e.status,this.statusText=e.statusText,this.headers=e.headers}function N(t,e){x.call(this,t),this.error=e.error}S.prototype.open=function(t,n){this._abort(!0);var o=this,s=this._xhr,a=1,u=0;this._abort=function(t){0!==o._sendTimeout&&(r(o._sendTimeout),o._sendTimeout=0),1!==a&&2!==a&&3!==a||(a=4,s.onload=w,s.onerror=w,s.onabort=w,s.onprogress=w,s.onreadystatechange=w,s.abort(),0!==u&&(r(u),u=0),t||(o.readyState=4,o.onabort(null),o.onreadystatechange())),a=0};var c=function(){if(1===a){var t=0,e="",n=void 0;if("contentType"in s)t=200,e="OK",n=s.contentType;else try{t=s.status,e=s.statusText,n=s.getResponseHeader("Content-Type")}catch(r){t=0,e="",n=void 0}0!==t&&(a=2,o.readyState=2,o.status=t,o.statusText=e,o._contentType=n,o.onreadystatechange())}},l=function(){if(c(),2===a||3===a){a=3;var t="";try{t=s.responseText}catch(e){}o.readyState=3,o.responseText=t,o.onprogress()}},d=function(t,e){if(null!=e&&null!=e.preventDefault||(e={preventDefault:w}),l(),1===a||2===a||3===a){if(a=4,0!==u&&(r(u),u=0),o.readyState=4,"load"===t)o.onload(e);else if("error"===t)o.onerror(e);else{if("abort"!==t)throw new TypeError;o.onabort(e)}o.onreadystatechange()}},h=function(){u=e(function(){h()},500),3===s.readyState&&l()};"onload"in s&&(s.onload=function(t){d("load",t)}),"onerror"in s&&(s.onerror=function(t){d("error",t)}),"onabort"in s&&(s.onabort=function(t){d("abort",t)}),"onprogress"in s&&(s.onprogress=l),"onreadystatechange"in s&&(s.onreadystatechange=function(t){!function(t){null!=s&&(4===s.readyState?"onload"in s&&"onerror"in s&&"onabort"in s||d(""===s.responseText?"error":"load",t):3===s.readyState?"onprogress"in s||l():2===s.readyState&&c())}(t)}),!("contentType"in s)&&"ontimeout"in i.prototype||(n+=(-1===n.indexOf("?")?"?":"&")+"padding=true"),s.open(t,n,!0),"readyState"in s&&(u=e(function(){h()},0))},S.prototype.abort=function(){this._abort(!1)},S.prototype.getResponseHeader=function(t){return this._contentType},S.prototype.setRequestHeader=function(t,e){var n=this._xhr;"setRequestHeader"in n&&n.setRequestHeader(t,e)},S.prototype.getAllResponseHeaders=function(){return null!=this._xhr.getAllResponseHeaders&&this._xhr.getAllResponseHeaders()||""},S.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 t=this._xhr;"withCredentials"in t&&(t.withCredentials=this.withCredentials);try{t.send(void 0)}catch(o){throw o}}else{var n=this;n._sendTimeout=e(function(){n._sendTimeout=0,n.send()},4)}},b.prototype.get=function(t){return this._map[_(t)]},null!=i&&null==i.HEADERS_RECEIVED&&(i.HEADERS_RECEIVED=2),E.prototype.open=function(t,e,n,o,r,s,a){t.open("GET",r);var u=0;for(var c in t.onprogress=function(){var e=t.responseText.slice(u);u+=e.length,n(e)},t.onerror=function(t){t.preventDefault(),o(new Error("NetworkError"))},t.onload=function(){o(null)},t.onabort=function(){o(null)},t.onreadystatechange=function(){if(t.readyState===i.HEADERS_RECEIVED){var n=t.status,o=t.statusText,r=t.getResponseHeader("Content-Type"),s=t.getAllResponseHeaders();e(n,o,r,new b(s))}},t.withCredentials=s,a)Object.prototype.hasOwnProperty.call(a,c)&&t.setRequestHeader(c,a[c]);return t.send(),t},T.prototype.get=function(t){return this._headers.get(t)},m.prototype.open=function(t,e,n,o,r,i,s){var a=null,u=new y,c=u.signal,h=new f;return d(r,{headers:s,credentials:i?"include":"same-origin",signal:c,cache:"no-store"}).then(function(t){return a=t.body.getReader(),e(t.status,t.statusText,t.headers.get("Content-Type"),new T(t.headers)),new l(function(t,e){var o=function(){a.read().then(function(e){if(e.done)t(void 0);else{var r=h.decode(e.value,{stream:!0});n(r),o()}}).catch(function(t){e(t)})};o()})}).catch(function(t){return"AbortError"===t.name?void 0:t}).then(function(t){o(t)}),{abort:function(){null!=a&&a.cancel(),u.abort()}}},C.prototype.dispatchEvent=function(t){t.target=this;var e=this._listeners[t.type];if(null!=e)for(var n=e.length,o=0;o<n;o+=1){var r=e[o];try{"function"==typeof r.handleEvent?r.handleEvent(t):r.call(this,t)}catch(i){A(i)}}},C.prototype.addEventListener=function(t,e){t=String(t);var n=this._listeners,o=n[t];null==o&&(o=[],n[t]=o);for(var r=!1,i=0;i<o.length;i+=1)o[i]===e&&(r=!0);r||o.push(e)},C.prototype.removeEventListener=function(t,e){t=String(t);var n=this._listeners,o=n[t];if(null!=o){for(var r=[],i=0;i<o.length;i+=1)o[i]!==e&&r.push(o[i]);0===r.length?delete n[t]:n[t]=r}},R.prototype=Object.create(x.prototype),O.prototype=Object.create(x.prototype),N.prototype=Object.create(x.prototype);var D=-1,j=-1,H=/^text\/event\-stream(;.*)?$/i,B=function(t,e){var n=null==t?e:parseInt(t,10);return n!=n&&(n=e),I(n)},I=function(t){return Math.min(Math.max(t,1e3),18e6)},M=function(t,e,n){try{"function"==typeof e&&e.call(t,n)}catch(o){A(o)}};function P(t,n){C.call(this),n=n||{},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(t,n,o){n=String(n);var a=Boolean(o.withCredentials),u=o.lastEventIdQueryParameterName||"lastEventId",c=I(1e3),l=B(o.heartbeatTimeout,45e3),d="",h=c,f=!1,p=0,y=o.headers||{},g=o.Transport,v=$&&null==g?void 0:new S(null!=g?new g:null!=i&&"withCredentials"in i.prototype||null==s?new i:new s),w=null!=g&&"string"!=typeof g?new g:null==v?new m:new E,_=void 0,b=0,T=D,C="",A="",x="",P="",k=0,L=0,U=0,q=function(e,n,o,r){if(0===T)if(200===e&&null!=o&&H.test(o)){T=1,f=Date.now(),h=c,t.readyState=1;var i=new O("open",{status:e,statusText:n,headers:r});t.dispatchEvent(i),M(t,t.onopen,i)}else{var s="";200!==e?(n&&(n=n.replace(/\s+/g," ")),s="EventSource's response has a status "+e+" "+n+" that is not 200. Aborting the connection."):s="EventSource's response has a Content-Type specifying an unsupported type: "+(null==o?"-":o.replace(/\s+/g," "))+". Aborting the connection.",X(),i=new O("error",{status:e,statusText:n,headers:r}),t.dispatchEvent(i),M(t,t.onerror,i),console.error(s)}},W=function(n){if(1===T){for(var o=-1,i=0;i<n.length;i+=1)(u=n.charCodeAt(i))!=="\n".charCodeAt(0)&&u!=="\r".charCodeAt(0)||(o=i);var s=(-1!==o?P:"")+n.slice(0,o+1);P=(-1===o?P:"")+n.slice(o+1),""!==n&&(f=Date.now(),p+=n.length);for(var a=0;a<s.length;a+=1){var u=s.charCodeAt(a);if(k===j&&u==="\n".charCodeAt(0))k=0;else if(k===j&&(k=0),u==="\r".charCodeAt(0)||u==="\n".charCodeAt(0)){if(0!==k){1===k&&(U=a+1);var y=s.slice(L,U-1),g=s.slice(U+(U<a&&s.charCodeAt(U)===" ".charCodeAt(0)?1:0),a);"data"===y?(C+="\n",C+=g):"id"===y?A=g:"event"===y?x=g:"retry"===y?(c=B(g,c),h=c):"heartbeatTimeout"===y&&(l=B(g,l),0!==b&&(r(b),b=e(function(){G()},l)))}if(0===k){if(""!==C){d=A,""===x&&(x="message");var v=new R(x,{data:C.slice(1),lastEventId:A});if(t.dispatchEvent(v),"open"===x?M(t,t.onopen,v):"message"===x?M(t,t.onmessage,v):"error"===x&&M(t,t.onerror,v),2===T)return}C="",x=""}k=u==="\r".charCodeAt(0)?j:0}else 0===k&&(L=a,k=1),1===k?u===":".charCodeAt(0)&&(U=a+1,k=2):2===k&&(k=3)}}},z=function(n){if(1===T||0===T){T=D,0!==b&&(r(b),b=0),b=e(function(){G()},h),h=I(Math.min(16*c,2*h)),t.readyState=0;var o=new N("error",{error:n});t.dispatchEvent(o),M(t,t.onerror,o),null!=n&&console.error(n)}},X=function(){T=2,null!=_&&(_.abort(),_=void 0),0!==b&&(r(b),b=0),t.readyState=2},G=function(){if(b=0,T===D){f=!1,p=0,b=e(function(){G()},l),T=0,C="",x="",A=d,P="",L=0,U=0,k=0;var o=n;if("data:"!==n.slice(0,5)&&"blob:"!==n.slice(0,5)&&""!==d){var r=n.indexOf("?");o=-1===r?n:n.slice(0,r+1)+n.slice(r+1).replace(/(?:^|&)([^=&]*)(?:=[^&]*)?/g,function(t,e){return e===u?"":t}),o+=(-1===n.indexOf("?")?"?":"&")+u+"="+encodeURIComponent(d)}var i=t.withCredentials,s={Accept:"text/event-stream"},a=t.headers;if(null!=a)for(var c in a)Object.prototype.hasOwnProperty.call(a,c)&&(s[c]=a[c]);try{_=w.open(v,q,W,z,o,i,s)}catch(y){throw X(),y}}else if(f||null==_){var h=Math.max((f||Date.now())+l-Date.now(),1);f=!1,b=e(function(){G()},h)}else z(new Error("No activity within "+l+" milliseconds. "+(0===T?"No response received.":p+" chars received.")+" Reconnecting.")),null!=_&&(_.abort(),_=void 0)};t.url=n,t.readyState=0,t.withCredentials=a,t.headers=y,t._close=X,G()}(this,t,n)}var $=null!=d&&null!=h&&"body"in h.prototype;P.prototype=Object.create(C.prototype),P.prototype.CONNECTING=0,P.prototype.OPEN=1,P.prototype.CLOSED=2,P.prototype.close=function(){this._close()},P.CONNECTING=0,P.OPEN=1,P.CLOSED=2,P.prototype.withCredentials=void 0;var k,L,U=u;null==i||null!=u&&"withCredentials"in u.prototype||(U=P),(k=o).EventSourcePolyfill=P,k.NativeEventSource=u,void 0!==(L=void(k.EventSource=U))&&(n.exports=L)}("undefined"==typeof globalThis?"undefined"!=typeof window?window:"undefined"!=typeof self?self:t:globalThis);var i,s,a=r.exports,u={exports:{}},c={exports:{}};i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s={rotl:function(t,e){return t<<e|t>>>32-e},rotr:function(t,e){return t<<32-e|t>>>e},endian:function(t){if(t.constructor==Number)return 16711935&s.rotl(t,8)|4278255360&s.rotl(t,24);for(var e=0;e<t.length;e++)t[e]=s.endian(t[e]);return t},randomBytes:function(t){for(var e=[];t>0;t--)e.push(Math.floor(256*Math.random()));return e},bytesToWords:function(t){for(var e=[],n=0,o=0;n<t.length;n++,o+=8)e[o>>>5]|=t[n]<<24-o%32;return e},wordsToBytes:function(t){for(var e=[],n=0;n<32*t.length;n+=8)e.push(t[n>>>5]>>>24-n%32&255);return e},bytesToHex:function(t){for(var e=[],n=0;n<t.length;n++)e.push((t[n]>>>4).toString(16)),e.push((15&t[n]).toString(16));return e.join("")},hexToBytes:function(t){for(var e=[],n=0;n<t.length;n+=2)e.push(parseInt(t.substr(n,2),16));return e},bytesToBase64:function(t){for(var e=[],n=0;n<t.length;n+=3)for(var o=t[n]<<16|t[n+1]<<8|t[n+2],r=0;r<4;r++)8*n+6*r<=8*t.length?e.push(i.charAt(o>>>6*(3-r)&63)):e.push("=");return e.join("")},base64ToBytes:function(t){t=t.replace(/[^A-Z0-9+\/]/gi,"");for(var e=[],n=0,o=0;n<t.length;o=++n%4)0!=o&&e.push((i.indexOf(t.charAt(n-1))&Math.pow(2,-2*o+8)-1)<<2*o|i.indexOf(t.charAt(n))>>>6-2*o);return e}},c.exports=s;var l,d,h,f,p,y=c.exports,g={utf8:{stringToBytes:function(t){return g.bin.stringToBytes(unescape(encodeURIComponent(t)))},bytesToString:function(t){return decodeURIComponent(escape(g.bin.bytesToString(t)))}},bin:{stringToBytes:function(t){for(var e=[],n=0;n<t.length;n++)e.push(255&t.charCodeAt(n));return e},bytesToString:function(t){for(var e=[],n=0;n<t.length;n++)e.push(String.fromCharCode(t[n]));return e.join("")}}},v=g,w=function(t){return null!=t&&(S(t)||function(t){return"function"==typeof t.readFloatLE&&"function"==typeof t.slice&&S(t.slice(0,0))}(t)||!!t._isBuffer)};function S(t){return!!t.constructor&&"function"==typeof t.constructor.isBuffer&&t.constructor.isBuffer(t)}l=y,d=v.utf8,h=w,f=v.bin,(p=function(t,e){t.constructor==String?t=e&&"binary"===e.encoding?f.stringToBytes(t):d.stringToBytes(t):h(t)?t=Array.prototype.slice.call(t,0):Array.isArray(t)||t.constructor===Uint8Array||(t=t.toString());for(var n=l.bytesToWords(t),o=8*t.length,r=1732584193,i=-271733879,s=-1732584194,a=271733878,u=0;u<n.length;u++)n[u]=16711935&(n[u]<<8|n[u]>>>24)|4278255360&(n[u]<<24|n[u]>>>8);n[o>>>5]|=128<<o%32,n[14+(o+64>>>9<<4)]=o;var c=p._ff,y=p._gg,g=p._hh,v=p._ii;for(u=0;u<n.length;u+=16){var w=r,S=i,_=s,b=a;r=c(r,i,s,a,n[u+0],7,-680876936),a=c(a,r,i,s,n[u+1],12,-389564586),s=c(s,a,r,i,n[u+2],17,606105819),i=c(i,s,a,r,n[u+3],22,-1044525330),r=c(r,i,s,a,n[u+4],7,-176418897),a=c(a,r,i,s,n[u+5],12,1200080426),s=c(s,a,r,i,n[u+6],17,-1473231341),i=c(i,s,a,r,n[u+7],22,-45705983),r=c(r,i,s,a,n[u+8],7,1770035416),a=c(a,r,i,s,n[u+9],12,-1958414417),s=c(s,a,r,i,n[u+10],17,-42063),i=c(i,s,a,r,n[u+11],22,-1990404162),r=c(r,i,s,a,n[u+12],7,1804603682),a=c(a,r,i,s,n[u+13],12,-40341101),s=c(s,a,r,i,n[u+14],17,-1502002290),r=y(r,i=c(i,s,a,r,n[u+15],22,1236535329),s,a,n[u+1],5,-165796510),a=y(a,r,i,s,n[u+6],9,-1069501632),s=y(s,a,r,i,n[u+11],14,643717713),i=y(i,s,a,r,n[u+0],20,-373897302),r=y(r,i,s,a,n[u+5],5,-701558691),a=y(a,r,i,s,n[u+10],9,38016083),s=y(s,a,r,i,n[u+15],14,-660478335),i=y(i,s,a,r,n[u+4],20,-405537848),r=y(r,i,s,a,n[u+9],5,568446438),a=y(a,r,i,s,n[u+14],9,-1019803690),s=y(s,a,r,i,n[u+3],14,-187363961),i=y(i,s,a,r,n[u+8],20,1163531501),r=y(r,i,s,a,n[u+13],5,-1444681467),a=y(a,r,i,s,n[u+2],9,-51403784),s=y(s,a,r,i,n[u+7],14,1735328473),r=g(r,i=y(i,s,a,r,n[u+12],20,-1926607734),s,a,n[u+5],4,-378558),a=g(a,r,i,s,n[u+8],11,-2022574463),s=g(s,a,r,i,n[u+11],16,1839030562),i=g(i,s,a,r,n[u+14],23,-35309556),r=g(r,i,s,a,n[u+1],4,-1530992060),a=g(a,r,i,s,n[u+4],11,1272893353),s=g(s,a,r,i,n[u+7],16,-155497632),i=g(i,s,a,r,n[u+10],23,-1094730640),r=g(r,i,s,a,n[u+13],4,681279174),a=g(a,r,i,s,n[u+0],11,-358537222),s=g(s,a,r,i,n[u+3],16,-722521979),i=g(i,s,a,r,n[u+6],23,76029189),r=g(r,i,s,a,n[u+9],4,-640364487),a=g(a,r,i,s,n[u+12],11,-421815835),s=g(s,a,r,i,n[u+15],16,530742520),r=v(r,i=g(i,s,a,r,n[u+2],23,-995338651),s,a,n[u+0],6,-198630844),a=v(a,r,i,s,n[u+7],10,1126891415),s=v(s,a,r,i,n[u+14],15,-1416354905),i=v(i,s,a,r,n[u+5],21,-57434055),r=v(r,i,s,a,n[u+12],6,1700485571),a=v(a,r,i,s,n[u+3],10,-1894986606),s=v(s,a,r,i,n[u+10],15,-1051523),i=v(i,s,a,r,n[u+1],21,-2054922799),r=v(r,i,s,a,n[u+8],6,1873313359),a=v(a,r,i,s,n[u+15],10,-30611744),s=v(s,a,r,i,n[u+6],15,-1560198380),i=v(i,s,a,r,n[u+13],21,1309151649),r=v(r,i,s,a,n[u+4],6,-145523070),a=v(a,r,i,s,n[u+11],10,-1120210379),s=v(s,a,r,i,n[u+2],15,718787259),i=v(i,s,a,r,n[u+9],21,-343485551),r=r+w>>>0,i=i+S>>>0,s=s+_>>>0,a=a+b>>>0}return l.endian([r,i,s,a])})._ff=function(t,e,n,o,r,i,s){var a=t+(e&n|~e&o)+(r>>>0)+s;return(a<<i|a>>>32-i)+e},p._gg=function(t,e,n,o,r,i,s){var a=t+(e&o|n&~o)+(r>>>0)+s;return(a<<i|a>>>32-i)+e},p._hh=function(t,e,n,o,r,i,s){var a=t+(e^n^o)+(r>>>0)+s;return(a<<i|a>>>32-i)+e},p._ii=function(t,e,n,o,r,i,s){var a=t+(n^(e|~o))+(r>>>0)+s;return(a<<i|a>>>32-i)+e},p._blocksize=16,p._digestsize=16,u.exports=function(t,e){if(null==t)throw new Error("Illegal argument "+t);var n=l.wordsToBytes(p(t,e));return e&&e.asBytes?n:e&&e.asString?f.bytesToString(n):l.bytesToHex(n)};const _=e(u.exports);return class{constructor(t={}){this.url=t.url,this.app_key=t.app_key,this.app_secret=t.app_secret,this.onMessage=t.onMessage||(()=>{}),this.onError=t.onError||(()=>{}),this.onOpen=t.onOpen||(()=>{}),this.onAudioData=t.onAudioData||(()=>{}),this.onAudioNegotiationSuccess=t.onAudioNegotiationSuccess||(()=>{}),this.onConnectSSE=t.onConnectSSE||(()=>{}),this.eventSource=null,this.negotiationResult=null}generateAuthToken(){const t=Math.floor(Date.now()/1e3);return`${this.app_key}:${t}:${_(`${this.app_secret}:${t}`)}`}getAuthHeaders(){return{Authorization:`${this.generateAuthToken()}`,"Content-Type":"application/json"}}async post(t,e){const n=this.generateAuthToken(),o=await fetch(`${this.url}${t}`,{method:"POST",headers:{Authorization:`${n}`,"Content-Type":"application/json","User-Agent":"XY-ASSIST-SDK"},body:JSON.stringify(e)});if(!o.ok){const t=await o.text();throw new Error(`HTTP error! status: ${o.status}, message: ${t}`)}return await o.json()}async audioNegotiation(t){const e=await this.post("/api/v1/agent/ccms/assist/audio-nego",t);return this.negotiationResult=e,this.onAudioNegotiationSuccess&&this.onAudioNegotiationSuccess(e),e}connectSSEWithNegotiationResult(){if(!this.negotiationResult||!this.negotiationResult.result)throw new Error("没有有效的协商结果,请先执行音频协商");const{sse_addr:t,client_id:e}=this.negotiationResult.result;if(!t||!e)throw new Error("协商结果中缺少sse_addr或client_id");const n=`http://${t}/sse?client_id=${e}`;this.connectSSEWithURL(n),this.onConnectSSE&&this.onConnectSSE({sseUrl:n,client_id:e,sse_addr:t})}connectSSEWithURL(t){this.eventSource=new a.EventSourcePolyfill(t),this.eventSource.onmessage=t=>{const e=JSON.parse(t.data);this.onMessage(e)},this.eventSource.onerror=t=>{this.onError(t)},this.eventSource.onopen=()=>{this.onOpen()}}connectSSE(t=!0){if(t&&this.negotiationResult&&this.negotiationResult.result&&this.negotiationResult.result.sse_addr)this.connectSSEWithNegotiationResult();else{const t=this.generateAuthToken(),e=`${this.url}/api/v1/agent/sse?auth=${t}`;this.eventSource=new a.EventSourcePolyfill(e),this.eventSource.onmessage=t=>{const e=JSON.parse(t.data);this.onMessage(e)},this.eventSource.onerror=t=>{this.onError(t)},this.eventSource.onopen=()=>{this.onOpen()}}}disconnectSSE(){this.eventSource&&(this.eventSource.close(),this.eventSource=null)}async startAssistAudioStream(t){const{app_id:e,dest_addr:n,call_id:o,direction:r,caller:i,called:s,skill_id:a,agent_no:u}=t;if(!e)throw new Error("app_id 是必需的参数");if(!n)throw new Error("dest_addr 是必需的参数");if(!o)throw new Error("call_id 是必需的参数");if(!r)throw new Error("direction 是必需的参数");if(!i)throw new Error("caller 是必需的参数");if(!s)throw new Error("called 是必需的参数");if(!a)throw new Error("skill_id 是必需的参数");if(!u)throw new Error("agent_no 是必需的参数");const c={app_id:e,dest_addr:n,call_id:o,direction:r,caller:i,called:s,skill_id:a,agent_no:u};return await this.post("/v1/base/cti/assist/start",c)}async stopAssistAudioStream(t){const{app_id:e,call_id:n}=t;if(!e)throw new Error("app_id 是必需的参数");if(!n)throw new Error("call_id 是必需的参数");const o={app_id:e,call_id:n};return await this.post("/v1/base/cti/assist/stop",o)}}});
|
package/package.json
CHANGED
|
@@ -96,7 +96,7 @@ class AgentAssistantSDK {
|
|
|
96
96
|
|
|
97
97
|
// 使用指定URL连接SSE(辅助方法)
|
|
98
98
|
connectSSEWithURL(sseUrl) {
|
|
99
|
-
this.eventSource = new
|
|
99
|
+
this.eventSource = new EventSourcePolyfill(sseUrl);
|
|
100
100
|
|
|
101
101
|
this.eventSource.onmessage = (event) => {
|
|
102
102
|
const data = JSON.parse(event.data);
|
|
@@ -124,7 +124,7 @@ class AgentAssistantSDK {
|
|
|
124
124
|
// 根据您提供的代码片段,使用正确的SSE端点
|
|
125
125
|
const sseUrl = `${this.url}/api/v1/agent/sse?auth=${authToken}`;
|
|
126
126
|
|
|
127
|
-
this.eventSource = new
|
|
127
|
+
this.eventSource = new EventSourcePolyfill(sseUrl);
|
|
128
128
|
|
|
129
129
|
this.eventSource.onmessage = (event) => {
|
|
130
130
|
const data = JSON.parse(event.data);
|
|
@@ -148,6 +148,84 @@ class AgentAssistantSDK {
|
|
|
148
148
|
this.eventSource = null;
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
|
+
|
|
152
|
+
// 开启坐席辅助音频流
|
|
153
|
+
async startAssistAudioStream(params) {
|
|
154
|
+
const {
|
|
155
|
+
app_id,
|
|
156
|
+
dest_addr,
|
|
157
|
+
call_id,
|
|
158
|
+
direction,
|
|
159
|
+
caller,
|
|
160
|
+
called,
|
|
161
|
+
skill_id,
|
|
162
|
+
agent_no
|
|
163
|
+
} = params;
|
|
164
|
+
|
|
165
|
+
// 验证必需参数
|
|
166
|
+
if (!app_id) {
|
|
167
|
+
throw new Error('app_id 是必需的参数');
|
|
168
|
+
}
|
|
169
|
+
if (!dest_addr) {
|
|
170
|
+
throw new Error('dest_addr 是必需的参数');
|
|
171
|
+
}
|
|
172
|
+
if (!call_id) {
|
|
173
|
+
throw new Error('call_id 是必需的参数');
|
|
174
|
+
}
|
|
175
|
+
if (!direction) {
|
|
176
|
+
throw new Error('direction 是必需的参数');
|
|
177
|
+
}
|
|
178
|
+
if (!caller) {
|
|
179
|
+
throw new Error('caller 是必需的参数');
|
|
180
|
+
}
|
|
181
|
+
if (!called) {
|
|
182
|
+
throw new Error('called 是必需的参数');
|
|
183
|
+
}
|
|
184
|
+
if (!skill_id) {
|
|
185
|
+
throw new Error('skill_id 是必需的参数');
|
|
186
|
+
}
|
|
187
|
+
if (!agent_no) {
|
|
188
|
+
throw new Error('agent_no 是必需的参数');
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const endpoint = '/v1/base/cti/assist/start';
|
|
192
|
+
const data = {
|
|
193
|
+
app_id,
|
|
194
|
+
dest_addr,
|
|
195
|
+
call_id,
|
|
196
|
+
direction,
|
|
197
|
+
caller,
|
|
198
|
+
called,
|
|
199
|
+
skill_id,
|
|
200
|
+
agent_no
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
return await this.post(endpoint, data);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// 停止坐席辅助音频流
|
|
207
|
+
async stopAssistAudioStream(params) {
|
|
208
|
+
const {
|
|
209
|
+
app_id,
|
|
210
|
+
call_id
|
|
211
|
+
} = params;
|
|
212
|
+
|
|
213
|
+
// 验证必需参数
|
|
214
|
+
if (!app_id) {
|
|
215
|
+
throw new Error('app_id 是必需的参数');
|
|
216
|
+
}
|
|
217
|
+
if (!call_id) {
|
|
218
|
+
throw new Error('call_id 是必需的参数');
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const endpoint = '/v1/base/cti/assist/stop';
|
|
222
|
+
const data = {
|
|
223
|
+
app_id,
|
|
224
|
+
call_id
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
return await this.post(endpoint, data);
|
|
228
|
+
}
|
|
151
229
|
}
|
|
152
230
|
|
|
153
231
|
export default AgentAssistantSDK;
|