ttp-agent-sdk 2.1.13 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent-widget.js +1 -1
- package/dist/agent-widget.js.map +1 -1
- package/dist/examples/test-agent-app.html +586 -11
- package/examples/test-agent-app.html +586 -11
- package/package.json +1 -1
package/dist/agent-widget.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/*! For license information please see agent-widget.js.LICENSE.txt */
|
|
2
|
-
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.TTPAgentSDK=e():t.TTPAgentSDK=e()}(window,()=>(()=>{"use strict";var t={540:(t,e,n)=>{t.exports=n(869)},698:(t,e)=>{var n=Symbol.for("react.transitional.element");function o(t,e,o){var r=null;if(void 0!==o&&(r=""+o),void 0!==e.key&&(r=""+e.key),"key"in e)for(var i in o={},e)"key"!==i&&(o[i]=e[i]);else o=e;return e=o.ref,{$$typeof:n,type:t,key:r,ref:void 0!==e?e:null,props:o}}Symbol.for("react.fragment"),e.jsx=o,e.jsxs=o},848:(t,e,n)=>{t.exports=n(698)},869:(t,e)=>{Symbol.for("react.transitional.element"),Symbol.for("react.portal"),Symbol.for("react.fragment"),Symbol.for("react.strict_mode"),Symbol.for("react.profiler"),Symbol.for("react.consumer"),Symbol.for("react.context"),Symbol.for("react.forward_ref"),Symbol.for("react.suspense"),Symbol.for("react.memo"),Symbol.for("react.lazy"),Symbol.for("react.activity"),Symbol.iterator;var n={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},o=Object.assign,r={};function i(t,e,o){this.props=t,this.context=e,this.refs=r,this.updater=o||n}function c(){}function a(t,e,o){this.props=t,this.context=e,this.refs=r,this.updater=o||n}i.prototype.isReactComponent={},i.prototype.setState=function(t,e){if("object"!=typeof t&&"function"!=typeof t&&null!=t)throw Error("takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,t,e,"setState")},i.prototype.forceUpdate=function(t){this.updater.enqueueForceUpdate(this,t,"forceUpdate")},c.prototype=i.prototype;var s=a.prototype=new c;s.constructor=a,o(s,i.prototype),s.isPureReactComponent=!0;Array.isArray;var u={H:null,A:null,T:null,S:null};Object.prototype.hasOwnProperty;"function"==typeof reportError&&reportError;e.useEffect=function(t,e){return u.H.useEffect(t,e)},e.useRef=function(t){return u.H.useRef(t)},e.useState=function(t){return u.H.useState(t)}}},e={};function n(o){var r=e[o];if(void 0!==r)return r.exports;var i=e[o]={exports:{}};return t[o](i,i.exports,n),i.exports}n.d=(t,e)=>{for(var o in e)n.o(e,o)&&!n.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:e[o]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var o={};function r(t){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},r(t)}function i(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,c(o.key),o)}}function c(t){var e=function(t){if("object"!=r(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=r(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==r(e)?e:e+""}n.r(o),n.d(o,{AgentSDK:()=>Qt,AgentWidget:()=>qt,AudioPlayer:()=>X,AudioRecorder:()=>N,EventEmitter:()=>a,VERSION:()=>$t,VanillaVoiceButton:()=>Mt,VoiceButton:()=>jt,VoiceSDK:()=>dt,WebSocketManager:()=>D,default:()=>Jt});var a=function(){return t=function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.events={}},e=[{key:"on",value:function(t,e){this.events[t]||(this.events[t]=[]),this.events[t].push(e)}},{key:"off",value:function(t,e){this.events[t]&&(this.events[t]=this.events[t].filter(function(t){return t!==e}))}},{key:"emit",value:function(t){for(var e=arguments.length,n=new Array(e>1?e-1:0),o=1;o<e;o++)n[o-1]=arguments[o];this.events[t]&&this.events[t].forEach(function(e){try{e.apply(void 0,n)}catch(e){console.error("Error in event listener for ".concat(t,":"),e)}})}},{key:"removeAllListeners",value:function(t){t?delete this.events[t]:this.events={}}}],e&&i(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}();function s(t){return s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},s(t)}function u(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=n){var o,r,i,c,a=[],s=!0,u=!1;try{if(i=(n=n.call(t)).next,0===e){if(Object(n)!==n)return;s=!1}else for(;!(s=(o=i.call(n)).done)&&(a.push(o.value),a.length!==e);s=!0);}catch(t){u=!0,r=t}finally{try{if(!s&&null!=n.return&&(c=n.return(),Object(c)!==c))return}finally{if(u)throw r}}return a}}(t,e)||f(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function l(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=f(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var o=0,r=function(){};return{s:r,n:function(){return o>=t.length?{done:!0}:{done:!1,value:t[o++]}},e:function(t){throw t},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,c=!0,a=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return c=t.done,t},e:function(t){a=!0,i=t},f:function(){try{c||null==n.return||n.return()}finally{if(a)throw i}}}}function f(t,e){if(t){if("string"==typeof t)return d(t,e);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?d(t,e):void 0}}function d(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,o=Array(e);n<e;n++)o[n]=t[n];return o}function p(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof a?o:a,u=Object.create(s.prototype);return h(u,"_invoke",function(n,o,r){var i,a,s,u=0,l=r||[],f=!1,d={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,a=0,s=t,d.n=n,c}};function p(n,o){for(a=n,s=o,e=0;!f&&u&&!r&&e<l.length;e++){var r,i=l[e],p=d.p,h=i[2];n>3?(r=h===o)&&(s=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(a=0,d.v=o,d.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,d.n=h,a=0))}if(r||n>1)return c;throw f=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,h),a=l,s=h;(e=a<2?t:s)||!f;){i||(a?a<3?(a>1&&(d.n=-1),p(a,s)):d.n=s:d.v=s);try{if(u=2,i){if(a||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,a<2&&(a=0)}else 1===a&&(e=i.return)&&e.call(i),a<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),a=1);i=t}else if((e=(f=d.n<0)?s:n.call(o,d))!==c)break}catch(e){i=t,a=1,s=e}finally{u=1}}return{value:e,done:f}}}(n,r,i),!0),u}var c={};function a(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(h(e={},o,function(){return this}),e),f=u.prototype=a.prototype=Object.create(l);function d(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,h(t,r,"GeneratorFunction")),t.prototype=Object.create(f),t}return s.prototype=u,h(f,"constructor",u),h(u,"constructor",s),s.displayName="GeneratorFunction",h(u,r,"GeneratorFunction"),h(f),h(f,r,"Generator"),h(f,o,function(){return this}),h(f,"toString",function(){return"[object Generator]"}),(p=function(){return{w:i,m:d}})()}function h(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}h=function(t,e,n,o){function i(e,n){h(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},h(t,e,n,o)}function y(t,e,n,o,r,i,c){try{var a=t[i](c),s=a.value}catch(t){return void n(t)}a.done?e(s):Promise.resolve(s).then(o,r)}function g(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,v(o.key),o)}}function v(t){var e=function(t){if("object"!=s(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=s(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==s(e)?e:e+""}function b(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(b=function(){return!!t})()}function m(t){return m=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},m(t)}function S(t,e){return S=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},S(t,e)}const w=new(function(t){function e(){var t;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(t=function(t,e,n){return e=m(e),function(t,e){if(e&&("object"==s(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,b()?Reflect.construct(e,n||[],m(t).constructor):e.apply(t,n))}(this,e)).connections=new Map,t.connectionCounts=new Map,t.creatingConnections=new Set,t}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&S(t,e)}(e,t),n=e,o=[{key:"getConnection",value:(r=p().m(function t(e){var n,o,r=this;return p().w(function(t){for(;;)switch(t.n){case 0:if(!this.connections.has(e)){t.n=1;break}return n=this.connections.get(e),this.connectionCounts.set(e,(this.connectionCounts.get(e)||0)+1),t.a(2,n);case 1:if(!this.creatingConnections||!this.creatingConnections.has(e)){t.n=2;break}return t.a(2,new Promise(function(t){var n=function(){if(r.connections.has(e)){var o=r.connections.get(e);r.connectionCounts.set(e,(r.connectionCounts.get(e)||0)+1),t(o)}else setTimeout(n,50)};n()}));case 2:return this.creatingConnections.add(e),o=new WebSocket(e),this.connections.set(e,o),this.connectionCounts.set(e,1),o.addEventListener("open",function(t){r.creatingConnections.delete(e),r.emit("open",t,e)}),o.addEventListener("close",function(t){r.creatingConnections.delete(e),r.connections.delete(e),r.connectionCounts.delete(e),r.emit("close",t,e)}),o.addEventListener("error",function(t){r.creatingConnections.delete(e),r.emit("error",t,e)}),o.addEventListener("message",function(t){r.emit("message",t,e)}),t.a(2,o)}},t,this)}),i=function(){var t=this,e=arguments;return new Promise(function(n,o){var i=r.apply(t,e);function c(t){y(i,n,o,c,a,"next",t)}function a(t){y(i,n,o,c,a,"throw",t)}c(void 0)})},function(t){return i.apply(this,arguments)})},{key:"releaseConnection",value:function(t){if(this.connections.has(t)){var e=this.connectionCounts.get(t)||0,n=Math.max(0,e-1);if(this.connectionCounts.set(t,n),0===n){var o=this.connections.get(t);o&&o.readyState===WebSocket.OPEN&&o.close(1e3,"No more subscribers"),this.connections.delete(t),this.connectionCounts.delete(t)}}}},{key:"forceClose",value:function(t){if(this.connections.has(t)){var e=this.connections.get(t);e&&e.readyState===WebSocket.OPEN&&e.close(1e3,"Force close"),this.connections.delete(t),this.connectionCounts.delete(t)}}},{key:"getConnectionStatus",value:function(t){return this.connections.has(t)?{exists:!0,readyState:this.connections.get(t).readyState,subscribers:this.connectionCounts.get(t)||0}:{exists:!1,readyState:null,subscribers:0}}},{key:"getAllConnections",value:function(){var t,e={},n=l(this.connections.entries());try{for(n.s();!(t=n.n()).done;){var o=u(t.value,2),r=o[0],i=o[1];e[r]={readyState:i.readyState,subscribers:this.connectionCounts.get(r)||0}}}catch(t){n.e(t)}finally{n.f()}return e}},{key:"clearAll",value:function(){var t,e=l(this.connections.entries());try{for(e.s();!(t=e.n()).done;){var n=u(t.value,2),o=(n[0],n[1]);o&&o.readyState===WebSocket.OPEN&&o.close(1e3,"Clear all")}}catch(t){e.e(t)}finally{e.f()}this.connections.clear(),this.connectionCounts.clear(),this.creatingConnections.clear()}}],o&&g(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i}(a));function k(t){return k="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},k(t)}function O(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof a?o:a,u=Object.create(s.prototype);return j(u,"_invoke",function(n,o,r){var i,a,s,u=0,l=r||[],f=!1,d={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,a=0,s=t,d.n=n,c}};function p(n,o){for(a=n,s=o,e=0;!f&&u&&!r&&e<l.length;e++){var r,i=l[e],p=d.p,h=i[2];n>3?(r=h===o)&&(s=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(a=0,d.v=o,d.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,d.n=h,a=0))}if(r||n>1)return c;throw f=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,h),a=l,s=h;(e=a<2?t:s)||!f;){i||(a?a<3?(a>1&&(d.n=-1),p(a,s)):d.n=s:d.v=s);try{if(u=2,i){if(a||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,a<2&&(a=0)}else 1===a&&(e=i.return)&&e.call(i),a<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),a=1);i=t}else if((e=(f=d.n<0)?s:n.call(o,d))!==c)break}catch(e){i=t,a=1,s=e}finally{u=1}}return{value:e,done:f}}}(n,r,i),!0),u}var c={};function a(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(j(e={},o,function(){return this}),e),f=u.prototype=a.prototype=Object.create(l);function d(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,j(t,r,"GeneratorFunction")),t.prototype=Object.create(f),t}return s.prototype=u,j(f,"constructor",u),j(u,"constructor",s),s.displayName="GeneratorFunction",j(u,r,"GeneratorFunction"),j(f),j(f,r,"Generator"),j(f,o,function(){return this}),j(f,"toString",function(){return"[object Generator]"}),(O=function(){return{w:i,m:d}})()}function j(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}j=function(t,e,n,o){function i(e,n){j(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},j(t,e,n,o)}function P(t,e,n,o,r,i,c){try{var a=t[i](c),s=a.value}catch(t){return void n(t)}a.done?e(s):Promise.resolve(s).then(o,r)}function C(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,x(o.key),o)}}function x(t){var e=function(t){if("object"!=k(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=k(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==k(e)?e:e+""}function E(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(E=function(){return!!t})()}function T(t){return T=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},T(t)}function R(t,e){return R=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},R(t,e)}var D=function(t){function e(t){var n;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(n=function(t,e,n){return e=T(e),function(t,e){if(e&&("object"==k(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,E()?Reflect.construct(e,n||[],T(t).constructor):e.apply(t,n))}(this,e)).config=t,n.ws=null,n.isConnected=!1,n.connectionId=null,n}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&R(t,e)}(e,t),n=e,o=[{key:"connect",value:(i=O().m(function t(){var e=this;return O().w(function(t){for(;;)if(0===t.n)return t.a(2,new Promise(function(t,n){try{e.connectionId=Date.now()+"_"+Math.random().toString(36).substr(2,9),e.connectResolve=t,e.connectReject=n,w.getConnection(e.config.websocketUrl,e.config).then(function(n){e.ws=n,e.setupEventListeners(),n.readyState===WebSocket.OPEN&&(e.isConnected=!0,e.emit("connected"),t(),e.connectResolve=null,e.connectReject=null)}).catch(function(t){console.error("🔌 WebSocketManager: Connection failed ".concat(e.connectionId),t),n(t),e.connectResolve=null,e.connectReject=null})}catch(t){console.error("🔌 WebSocketManager: Connection error ".concat(e.connectionId),t),n(t),e.connectResolve=null,e.connectReject=null}}))},t)}),c=function(){var t=this,e=arguments;return new Promise(function(n,o){var r=i.apply(t,e);function c(t){P(r,n,o,c,a,"next",t)}function a(t){P(r,n,o,c,a,"throw",t)}c(void 0)})},function(){return c.apply(this,arguments)})},{key:"setupEventListeners",value:function(){var t=this;if(this.ws){var e=function(e,n){n===t.config.websocketUrl&&(t.isConnected=!0,t.emit("connected"),t.connectResolve&&(t.connectResolve(),t.connectResolve=null,t.connectReject=null))},n=function(e,n){n===t.config.websocketUrl&&(t.isConnected=!1,t.emit("disconnected",e))},o=function(e,n){n===t.config.websocketUrl&&(t.emit("error",e),t.connectReject&&(t.connectReject(e),t.connectResolve=null,t.connectReject=null))},r=function(e,n){n===t.config.websocketUrl&&t.handleMessage(e)};w.on("open",e),w.on("close",n),w.on("error",o),w.on("message",r),this.eventHandlers={open:e,close:n,error:o,message:r}}}},{key:"disconnect",value:function(){this.eventHandlers&&(w.off("open",this.eventHandlers.open),w.off("close",this.eventHandlers.close),w.off("error",this.eventHandlers.error),w.off("message",this.eventHandlers.message)),this.config.websocketUrl&&w.releaseConnection(this.config.websocketUrl),this.ws=null,this.isConnected=!1}},{key:"sendMessage",value:function(t){if(this.isConnected&&this.ws)try{this.ws.send(JSON.stringify(t))}catch(t){console.warn("🔌 WebSocketManager: Failed to send message:",t.message)}}},{key:"sendBinary",value:function(t){if(this.isConnected&&this.ws)try{this.ws.send(t)}catch(t){console.warn("🔌 WebSocketManager: Failed to send binary data:",t.message)}}},{key:"handleMessage",value:function(t){var e=this;if(t.data instanceof ArrayBuffer)this.emit("binaryAudio",t.data);else if(t.data instanceof Blob)t.data.arrayBuffer().then(function(t){e.emit("binaryAudio",t)}).catch(function(t){console.error("🔌 WebSocketManager: Error converting Blob to ArrayBuffer:",t)});else try{var n=JSON.parse(t.data);"barge_in_ack"!==n.t&&"stop_sending"!==n.t||this.emit("bargeIn",n),"stop_playing"===n.t&&this.emit("stopPlaying",n),this.emit("message",n)}catch(t){this.emit("error",t)}}},{key:"getStatus",value:function(){return{isConnected:this.isConnected,readyState:this.ws?this.ws.readyState:null,connectionId:this.connectionId}}}],r=[{key:"getSingletonStatus",value:function(){return w.getAllConnections()}},{key:"clearAllConnections",value:function(){w.clearAll()}}],o&&C(n.prototype,o),r&&C(n,r),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i,c}(a);function _(t){return _="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},_(t)}function I(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof a?o:a,u=Object.create(s.prototype);return M(u,"_invoke",function(n,o,r){var i,a,s,u=0,l=r||[],f=!1,d={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,a=0,s=t,d.n=n,c}};function p(n,o){for(a=n,s=o,e=0;!f&&u&&!r&&e<l.length;e++){var r,i=l[e],p=d.p,h=i[2];n>3?(r=h===o)&&(s=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(a=0,d.v=o,d.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,d.n=h,a=0))}if(r||n>1)return c;throw f=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,h),a=l,s=h;(e=a<2?t:s)||!f;){i||(a?a<3?(a>1&&(d.n=-1),p(a,s)):d.n=s:d.v=s);try{if(u=2,i){if(a||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,a<2&&(a=0)}else 1===a&&(e=i.return)&&e.call(i),a<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),a=1);i=t}else if((e=(f=d.n<0)?s:n.call(o,d))!==c)break}catch(e){i=t,a=1,s=e}finally{u=1}}return{value:e,done:f}}}(n,r,i),!0),u}var c={};function a(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(M(e={},o,function(){return this}),e),f=u.prototype=a.prototype=Object.create(l);function d(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,M(t,r,"GeneratorFunction")),t.prototype=Object.create(f),t}return s.prototype=u,M(f,"constructor",u),M(u,"constructor",s),s.displayName="GeneratorFunction",M(u,r,"GeneratorFunction"),M(f),M(f,r,"Generator"),M(f,o,function(){return this}),M(f,"toString",function(){return"[object Generator]"}),(I=function(){return{w:i,m:d}})()}function M(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}M=function(t,e,n,o){function i(e,n){M(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},M(t,e,n,o)}function A(t,e,n,o,r,i,c){try{var a=t[i](c),s=a.value}catch(t){return void n(t)}a.done?e(s):Promise.resolve(s).then(o,r)}function B(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function c(t){A(i,o,r,c,a,"next",t)}function a(t){A(i,o,r,c,a,"throw",t)}c(void 0)})}}function K(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,F(o.key),o)}}function F(t){var e=function(t){if("object"!=_(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=_(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==_(e)?e:e+""}function U(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(U=function(){return!!t})()}function G(t){return G=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},G(t)}function L(t,e){return L=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},L(t,e)}var N=function(t){function e(t){var n;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(n=function(t,e,n){return e=G(e),function(t,e){if(e&&("object"==_(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,U()?Reflect.construct(e,n||[],G(t).constructor):e.apply(t,n))}(this,e)).config=t,n.audioContext=null,n.audioWorkletNode=null,n.mediaStream=null,n.isRecording=!1,n}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&L(t,e)}(e,t),n=e,o=[{key:"start",value:(i=B(I().m(function t(){var e,n=this;return I().w(function(t){for(;;)switch(t.p=t.n){case 0:return t.p=0,t.n=1,navigator.mediaDevices.getUserMedia({audio:{sampleRate:this.config.sampleRate,channelCount:1,echoCancellation:!0,noiseSuppression:!0,autoGainControl:!0}});case 1:if(this.mediaStream=t.v,this.audioContext=new(window.AudioContext||window.webkitAudioContext)({sampleRate:this.config.sampleRate}),"suspended"!==this.audioContext.state){t.n=2;break}return t.n=2,this.audioContext.resume();case 2:return t.n=3,this.audioContext.audioWorklet.addModule("/audio-processor.js");case 3:this.audioWorkletNode=new AudioWorkletNode(this.audioContext,"audio-processor"),this.audioContext.createMediaStreamSource(this.mediaStream).connect(this.audioWorkletNode),this.audioWorkletNode.port.onmessage=function(t){var e=t.data,o=e.type,r=e.data;"pcm_audio_data"===o&&n.emit("audioData",r)},this.audioWorkletNode.port.postMessage({type:"setForceContinuous",data:{enabled:!0}}),this.isRecording=!0,this.emit("recordingStarted"),t.n=5;break;case 4:throw t.p=4,e=t.v,this.emit("error",e),e;case 5:return t.a(2)}},t,this,[[0,4]])})),function(){return i.apply(this,arguments)})},{key:"stop",value:(r=B(I().m(function t(){var e;return I().w(function(t){for(;;)switch(t.p=t.n){case 0:if(this.isRecording){t.n=1;break}return t.a(2);case 1:if(t.p=1,!this.audioWorkletNode){t.n=2;break}return this.audioWorkletNode.port.postMessage({type:"flush"}),t.n=2,new Promise(function(t){return setTimeout(t,100)});case 2:if(this.mediaStream&&(this.mediaStream.getTracks().forEach(function(t){return t.stop()}),this.mediaStream=null),!this.audioContext||"closed"===this.audioContext.state){t.n=4;break}return t.n=3,this.audioContext.close();case 3:this.audioContext=null;case 4:this.audioWorkletNode=null,this.isRecording=!1,this.emit("recordingStopped"),t.n=6;break;case 5:throw t.p=5,e=t.v,this.emit("error",e),e;case 6:return t.a(2)}},t,this,[[1,5]])})),function(){return r.apply(this,arguments)})},{key:"getStatus",value:function(){return{isRecording:this.isRecording,audioContextState:this.audioContext?this.audioContext.state:"closed"}}},{key:"destroy",value:function(){this.stop()}}],o&&K(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i}(a);function W(t){return W="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},W(t)}function V(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof a?o:a,u=Object.create(s.prototype);return H(u,"_invoke",function(n,o,r){var i,a,s,u=0,l=r||[],f=!1,d={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,a=0,s=t,d.n=n,c}};function p(n,o){for(a=n,s=o,e=0;!f&&u&&!r&&e<l.length;e++){var r,i=l[e],p=d.p,h=i[2];n>3?(r=h===o)&&(s=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(a=0,d.v=o,d.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,d.n=h,a=0))}if(r||n>1)return c;throw f=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,h),a=l,s=h;(e=a<2?t:s)||!f;){i||(a?a<3?(a>1&&(d.n=-1),p(a,s)):d.n=s:d.v=s);try{if(u=2,i){if(a||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,a<2&&(a=0)}else 1===a&&(e=i.return)&&e.call(i),a<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),a=1);i=t}else if((e=(f=d.n<0)?s:n.call(o,d))!==c)break}catch(e){i=t,a=1,s=e}finally{u=1}}return{value:e,done:f}}}(n,r,i),!0),u}var c={};function a(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(H(e={},o,function(){return this}),e),f=u.prototype=a.prototype=Object.create(l);function d(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,H(t,r,"GeneratorFunction")),t.prototype=Object.create(f),t}return s.prototype=u,H(f,"constructor",u),H(u,"constructor",s),s.displayName="GeneratorFunction",H(u,r,"GeneratorFunction"),H(f),H(f,r,"Generator"),H(f,o,function(){return this}),H(f,"toString",function(){return"[object Generator]"}),(V=function(){return{w:i,m:d}})()}function H(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}H=function(t,e,n,o){function i(e,n){H(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},H(t,e,n,o)}function z(t,e,n,o,r,i,c){try{var a=t[i](c),s=a.value}catch(t){return void n(t)}a.done?e(s):Promise.resolve(s).then(o,r)}function Q(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,q(o.key),o)}}function q(t){var e=function(t){if("object"!=W(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=W(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==W(e)?e:e+""}function $(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return($=function(){return!!t})()}function J(t){return J=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},J(t)}function Y(t,e){return Y=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},Y(t,e)}var X=function(t){function e(t){var n;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(n=function(t,e,n){return e=J(e),function(t,e){if(e&&("object"==W(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,$()?Reflect.construct(e,n||[],J(t).constructor):e.apply(t,n))}(this,e)).config=t,n.audioContext=null,n.audioQueue=[],n.isPlaying=!1,n.isProcessingQueue=!1,n.currentSource=null,n}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&Y(t,e)}(e,t),n=e,o=[{key:"playAudio",value:function(t){var e=this;try{var n=this.createAudioBlob(t);this.audioQueue.push(n),this.isPlaying||this.isProcessingQueue||this.currentSource||setTimeout(function(){return e.processQueue()},50)}catch(t){this.emit("playbackError",t)}}},{key:"createAudioBlob",value:function(t){var e=new Uint8Array(t);if(e.length>=4){if(82===e[0]&&73===e[1]&&70===e[2]&&70===e[3])return new Blob([t],{type:"audio/wav"});if(255===e[0]&&!(224&~e[1]))return new Blob([t],{type:"audio/mpeg"});if(79===e[0]&&103===e[1]&&103===e[2]&&83===e[3])return new Blob([t],{type:"audio/ogg"})}return new Blob([t],{type:"audio/wav"})}},{key:"processQueue",value:(r=V().m(function t(){var e,n,o,r,i,c,a,s,u=this;return V().w(function(t){for(;;)switch(t.p=t.n){case 0:if(!this.isProcessingQueue&&0!==this.audioQueue.length){t.n=1;break}return t.a(2);case 1:if(this.isProcessingQueue=!0,e=this.audioQueue.shift()){t.n=2;break}return this.isProcessingQueue=!1,t.a(2);case 2:if(t.p=2,n=!this.isPlaying&&null===this.currentSource,this.audioContext||(this.audioContext=new(window.AudioContext||window.webkitAudioContext)),"suspended"!==(o=this.audioContext).state){t.n=3;break}return t.n=3,o.resume();case 3:return t.n=4,e.arrayBuffer();case 4:return r=t.v,t.n=5,o.decodeAudioData(r);case 5:i=t.v,c=n&&!this.isPlaying&&null===this.currentSource,(a=o.createBufferSource()).buffer=i,a.connect(o.destination),this.currentSource=a,this.isPlaying=!0,c&&this.emit("playbackStarted"),a.onended=function(){u.currentSource=null,u.isProcessingQueue=!1,u.audioQueue.length>0?setTimeout(function(){return u.processQueue()},50):setTimeout(function(){0!==u.audioQueue.length||u.currentSource||(u.isPlaying=!1,u.emit("playbackStopped"))},100)},a.start(),t.n=7;break;case 6:t.p=6,s=t.v,this.currentSource=null,this.emit("playbackError",s),this.audioQueue.length>0?(this.isProcessingQueue=!1,setTimeout(function(){return u.processQueue()},100)):(this.isPlaying=!1,this.isProcessingQueue=!1,this.emit("playbackStopped"));case 7:return t.a(2)}},t,this,[[2,6]])}),i=function(){var t=this,e=arguments;return new Promise(function(n,o){var i=r.apply(t,e);function c(t){z(i,n,o,c,a,"next",t)}function a(t){z(i,n,o,c,a,"throw",t)}c(void 0)})},function(){return i.apply(this,arguments)})},{key:"stop",value:function(){this.stopImmediate()}},{key:"stopImmediate",value:function(){var t=this.isPlaying||null!==this.currentSource;if(this.currentSource){try{this.currentSource.stop()}catch(t){}this.currentSource=null}this.isPlaying=!1,this.isProcessingQueue=!1,this.audioQueue=[],t&&this.emit("playbackStopped")}},{key:"getStatus",value:function(){return{isPlaying:this.isPlaying,isProcessingQueue:this.isProcessingQueue,queueLength:this.audioQueue.length,audioContextState:this.audioContext?this.audioContext.state:"closed"}}},{key:"destroy",value:function(){this.stop(),this.audioContext&&"closed"!==this.audioContext.state&&(this.audioContext.close(),this.audioContext=null)}}],o&&Q(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i}(a);function Z(t){return Z="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Z(t)}function tt(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof a?o:a,u=Object.create(s.prototype);return et(u,"_invoke",function(n,o,r){var i,a,s,u=0,l=r||[],f=!1,d={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,a=0,s=t,d.n=n,c}};function p(n,o){for(a=n,s=o,e=0;!f&&u&&!r&&e<l.length;e++){var r,i=l[e],p=d.p,h=i[2];n>3?(r=h===o)&&(s=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(a=0,d.v=o,d.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,d.n=h,a=0))}if(r||n>1)return c;throw f=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,h),a=l,s=h;(e=a<2?t:s)||!f;){i||(a?a<3?(a>1&&(d.n=-1),p(a,s)):d.n=s:d.v=s);try{if(u=2,i){if(a||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,a<2&&(a=0)}else 1===a&&(e=i.return)&&e.call(i),a<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),a=1);i=t}else if((e=(f=d.n<0)?s:n.call(o,d))!==c)break}catch(e){i=t,a=1,s=e}finally{u=1}}return{value:e,done:f}}}(n,r,i),!0),u}var c={};function a(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(et(e={},o,function(){return this}),e),f=u.prototype=a.prototype=Object.create(l);function d(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,et(t,r,"GeneratorFunction")),t.prototype=Object.create(f),t}return s.prototype=u,et(f,"constructor",u),et(u,"constructor",s),s.displayName="GeneratorFunction",et(u,r,"GeneratorFunction"),et(f),et(f,r,"Generator"),et(f,o,function(){return this}),et(f,"toString",function(){return"[object Generator]"}),(tt=function(){return{w:i,m:d}})()}function et(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}et=function(t,e,n,o){function i(e,n){et(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},et(t,e,n,o)}function nt(t,e,n,o,r,i,c){try{var a=t[i](c),s=a.value}catch(t){return void n(t)}a.done?e(s):Promise.resolve(s).then(o,r)}function ot(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function c(t){nt(i,o,r,c,a,"next",t)}function a(t){nt(i,o,r,c,a,"throw",t)}c(void 0)})}}function rt(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,o)}return n}function it(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?rt(Object(n),!0).forEach(function(e){ct(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):rt(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function ct(t,e,n){return(e=st(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function at(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,st(o.key),o)}}function st(t){var e=function(t){if("object"!=Z(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=Z(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Z(e)?e:e+""}function ut(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(ut=function(){return!!t})()}function lt(t){return lt=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},lt(t)}function ft(t,e){return ft=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},ft(t,e)}var dt=function(t){function e(){var t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(t=function(t,e,n){return e=lt(e),function(t,e){if(e&&("object"==Z(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,ut()?Reflect.construct(e,n||[],lt(t).constructor):e.apply(t,n))}(this,e)).config=it({websocketUrl:n.websocketUrl||"wss://speech.talktopc.com/ws/conv",agentId:n.agentId,appId:n.appId,ttpId:n.ttpId,voice:n.voice||"default",language:n.language||"en",sampleRate:n.sampleRate||16e3},n),t.isConnected=!1,t.isRecording=!1,t.isPlaying=!1,t.isDestroyed=!1,t.webSocketManager=new D(it(it({},t.config),{},{autoReconnect:!1!==t.config.autoReconnect})),t.audioRecorder=new N(t.config),t.audioPlayer=new X(t.config),t.setupEventHandlers(),t}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&ft(t,e)}(e,t),n=e,o=[{key:"setupEventHandlers",value:function(){var t=this;this.webSocketManager.on("connected",function(){t.isConnected=!0,t.sendHelloMessage(),t.emit("connected")}),this.webSocketManager.on("disconnected",function(e){t.isConnected=!1,t.isRecording&&t.stopRecording().catch(function(t){console.error("VoiceSDK: Error stopping recording on disconnect:",t)}),t.emit("disconnected",e)}),this.webSocketManager.on("error",function(e){t.emit("error",e)}),this.webSocketManager.on("message",function(e){if("greeting_audio"===e.t&&e.data)try{for(var n=atob(e.data),o=new Uint8Array(n.length),r=0;r<n.length;r++)o[r]=n.charCodeAt(r);t.audioPlayer.playAudio(o),t.emit("greetingStarted")}catch(t){console.error("VoiceSDK: Error playing greeting audio:",t)}else t.emit("message",e)}),this.webSocketManager.on("binaryAudio",function(e){t.audioPlayer.playAudio(e)}),this.webSocketManager.on("bargeIn",function(e){t.emit("bargeIn",e)}),this.webSocketManager.on("stopPlaying",function(e){t.emit("stopPlaying",e),t.audioPlayer.stopImmediate()}),this.audioRecorder.on("recordingStarted",function(){t.isRecording=!0,t.isPlaying&&(t.audioPlayer.stopImmediate(),t.isConnected&&t.webSocketManager.sendMessage({t:"barge_in"})),t.emit("recordingStarted")}),this.audioRecorder.on("recordingStopped",function(){t.isRecording=!1,t.emit("recordingStopped")}),this.audioRecorder.on("audioData",function(e){t.isConnected&&t.webSocketManager.sendBinary(e)}),this.audioPlayer.on("playbackStarted",function(){t.isPlaying=!0,t.emit("playbackStarted"),t.isConnected&&t.webSocketManager.sendMessage({t:"audio_started_playing"})}),this.audioPlayer.on("playbackStopped",function(){t.isPlaying=!1,t.emit("playbackStopped"),t.isConnected&&t.webSocketManager.sendMessage({t:"audio_stopped_playing"})}),this.audioPlayer.on("playbackError",function(e){t.emit("playbackError",e)})}},{key:"connect",value:(u=ot(tt().m(function t(){var e,n;return tt().w(function(t){for(;;)switch(t.p=t.n){case 0:if(!this.isDestroyed){t.n=1;break}return console.warn("VoiceSDK: Cannot connect - SDK is destroyed"),t.a(2,!1);case 1:return t.p=1,e=this.buildWebSocketUrl(),this.webSocketManager.config.websocketUrl=e,t.n=2,this.webSocketManager.connect();case 2:return t.a(2,!0);case 3:return t.p=3,n=t.v,console.error("🔌 VoiceSDK: Connection failed with error:",n),this.emit("error",n),t.a(2,!1)}},t,this,[[1,3]])})),function(){return u.apply(this,arguments)})},{key:"buildWebSocketUrl",value:function(){var t=this.config.websocketUrl,e=new URLSearchParams;if(this.config.agentId&&e.append("agentId",this.config.agentId),this.config.appId&&e.append("appId",this.config.appId),this.config.voice&&"default"!==this.config.voice&&e.append("voice",this.config.voice),this.config.language&&"en"!==this.config.language&&e.append("language",this.config.language),e.toString()){var n=t.includes("?")?"&":"?";t+=n+e.toString()}return t}},{key:"disconnect",value:function(){this.isDestroyed||(this.stopRecording(),this.webSocketManager.disconnect())}},{key:"resetReconnectionAttempts",value:function(){this.isDestroyed||this.webSocketManager.resetReconnectionAttempts()}},{key:"reconnect",value:(s=ot(tt().m(function t(){return tt().w(function(t){for(;;)switch(t.n){case 0:if(!this.isDestroyed){t.n=1;break}return t.a(2,!1);case 1:return this.disconnect(),this.resetReconnectionAttempts(),t.n=2,this.connect();case 2:return t.a(2,t.v)}},t,this)})),function(){return s.apply(this,arguments)})},{key:"startRecording",value:(a=ot(tt().m(function t(){var e;return tt().w(function(t){for(;;)switch(t.p=t.n){case 0:if(this.isConnected){t.n=1;break}throw new Error("Not connected to voice server");case 1:return t.p=1,this.webSocketManager.sendMessage({t:"start_continuous_mode",ttpId:this.generateTtpId(),voice:this.config.voice,language:this.config.language}),t.n=2,this.audioRecorder.start();case 2:return t.a(2,!0);case 3:return t.p=3,e=t.v,console.error("❌ VoiceSDK: Failed to start recording:",e),this.emit("error",e),t.a(2,!1)}},t,this,[[1,3]])})),function(){return a.apply(this,arguments)})},{key:"stopRecording",value:(c=ot(tt().m(function t(){var e;return tt().w(function(t){for(;;)switch(t.p=t.n){case 0:if(this.isRecording){t.n=1;break}return t.a(2);case 1:return t.p=1,this.webSocketManager.sendMessage({t:"stop_continuous_mode",ttpId:this.generateTtpId()}),t.n=2,this.audioRecorder.stop();case 2:return this.audioPlayer.stopImmediate(),t.a(2,!0);case 3:return t.p=3,e=t.v,this.emit("error",e),t.a(2,!1)}},t,this,[[1,3]])})),function(){return c.apply(this,arguments)})},{key:"toggleRecording",value:(i=ot(tt().m(function t(){return tt().w(function(t){for(;;)switch(t.n){case 0:if(!this.isRecording){t.n=2;break}return t.n=1,this.stopRecording();case 1:case 3:return t.a(2,t.v);case 2:return t.n=3,this.startRecording();case 4:return t.a(2)}},t,this)})),function(){return i.apply(this,arguments)})},{key:"stopAudioPlayback",value:function(){this.audioPlayer.stopImmediate()}},{key:"handleBargeIn",value:(r=ot(tt().m(function t(){return tt().w(function(t){for(;;)switch(t.n){case 0:if(this.stopAudioPlayback(),this.isRecording){t.n=1;break}return t.n=1,this.startRecording();case 1:return t.a(2)}},t,this)})),function(){return r.apply(this,arguments)})},{key:"getStatus",value:function(){return{isConnected:this.isConnected,isRecording:this.isRecording,isPlaying:this.isPlaying}}},{key:"updateConfig",value:function(t){this.config=it(it({},this.config),t)}},{key:"generateTtpId",value:function(){return"sdk_"+Math.random().toString(36).substr(2,9)+"_"+Date.now()}},{key:"sendHelloMessage",value:function(){if(this.isConnected){var t={t:"hello"};this.config.appId?t.appId=this.config.appId:this.config.ttpId?t.ttpId=this.config.ttpId:t.ttpId=this.generateTtpId();try{this.webSocketManager.sendMessage(t)}catch(t){console.error("VoiceSDK: Failed to send hello message:",t),this.emit("error",t)}}else console.warn("VoiceSDK: Cannot send hello message - not connected")}},{key:"destroy",value:function(){this.isDestroyed||(this.disconnect(),this.isDestroyed=!0,this.audioRecorder.destroy(),this.audioPlayer.destroy(),this.removeAllListeners())}}],o&&at(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i,c,a,s,u}(a),pt=n(540),ht=n(848);function yt(t){return yt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},yt(t)}function gt(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,o)}return n}function vt(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?gt(Object(n),!0).forEach(function(e){bt(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):gt(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function bt(t,e,n){return(e=function(t){var e=function(t){if("object"!=yt(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=yt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==yt(e)?e:e+""}(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function mt(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof a?o:a,u=Object.create(s.prototype);return St(u,"_invoke",function(n,o,r){var i,a,s,u=0,l=r||[],f=!1,d={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,a=0,s=t,d.n=n,c}};function p(n,o){for(a=n,s=o,e=0;!f&&u&&!r&&e<l.length;e++){var r,i=l[e],p=d.p,h=i[2];n>3?(r=h===o)&&(s=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(a=0,d.v=o,d.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,d.n=h,a=0))}if(r||n>1)return c;throw f=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,h),a=l,s=h;(e=a<2?t:s)||!f;){i||(a?a<3?(a>1&&(d.n=-1),p(a,s)):d.n=s:d.v=s);try{if(u=2,i){if(a||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,a<2&&(a=0)}else 1===a&&(e=i.return)&&e.call(i),a<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),a=1);i=t}else if((e=(f=d.n<0)?s:n.call(o,d))!==c)break}catch(e){i=t,a=1,s=e}finally{u=1}}return{value:e,done:f}}}(n,r,i),!0),u}var c={};function a(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(St(e={},o,function(){return this}),e),f=u.prototype=a.prototype=Object.create(l);function d(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,St(t,r,"GeneratorFunction")),t.prototype=Object.create(f),t}return s.prototype=u,St(f,"constructor",u),St(u,"constructor",s),s.displayName="GeneratorFunction",St(u,r,"GeneratorFunction"),St(f),St(f,r,"Generator"),St(f,o,function(){return this}),St(f,"toString",function(){return"[object Generator]"}),(mt=function(){return{w:i,m:d}})()}function St(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}St=function(t,e,n,o){function i(e,n){St(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},St(t,e,n,o)}function wt(t,e,n,o,r,i,c){try{var a=t[i](c),s=a.value}catch(t){return void n(t)}a.done?e(s):Promise.resolve(s).then(o,r)}function kt(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=n){var o,r,i,c,a=[],s=!0,u=!1;try{if(i=(n=n.call(t)).next,0===e){if(Object(n)!==n)return;s=!1}else for(;!(s=(o=i.call(n)).done)&&(a.push(o.value),a.length!==e);s=!0);}catch(t){u=!0,r=t}finally{try{if(!s&&null!=n.return&&(c=n.return(),Object(c)!==c))return}finally{if(u)throw r}}return a}}(t,e)||function(t,e){if(t){if("string"==typeof t)return Ot(t,e);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Ot(t,e):void 0}}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function Ot(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,o=Array(e);n<e;n++)o[n]=t[n];return o}const jt=function(t){var e=t.websocketUrl,n=t.agentId,o=t.voice,r=void 0===o?"default":o,i=t.language,c=void 0===i?"en":i,a=t.autoReconnect,s=void 0===a||a,u=t.onConnected,l=t.onDisconnected,f=t.onRecordingStarted,d=t.onRecordingStopped,p=t.onPlaybackStarted,h=t.onPlaybackStopped,y=t.onError,g=t.onMessage,v=t.onBargeIn,b=t.onStopPlaying,m=t.className,S=void 0===m?"":m,w=t.style,k=void 0===w?{}:w,O=t.children,j=kt((0,pt.useState)(!1),2),P=j[0],C=j[1],x=kt((0,pt.useState)(!1),2),E=x[0],T=x[1],R=kt((0,pt.useState)(!1),2),D=(R[0],R[1]),_=kt((0,pt.useState)("Disconnected"),2),I=(_[0],_[1]),M=(0,pt.useRef)(null);(0,pt.useEffect)(function(){console.log("🎙️ VoiceButton: Creating VoiceSDK instance for ".concat(e)),M.current&&(console.log("🎙️ VoiceButton: Destroying existing VoiceSDK instance"),M.current.destroy(),M.current=null);var t=new dt({websocketUrl:e,agentId:n,voice:r,language:c,autoReconnect:s});return t.on("connected",function(){C(!0),I("Connected"),null==u||u()}),t.on("disconnected",function(){C(!1),I("Disconnected"),null==l||l()}),t.on("recordingStarted",function(){T(!0),null==f||f()}),t.on("recordingStopped",function(){T(!1),null==d||d()}),t.on("playbackStarted",function(){D(!0),null==p||p()}),t.on("playbackStopped",function(){D(!1),null==h||h()}),t.on("error",function(t){null==y||y(t)}),t.on("message",function(t){null==g||g(t)}),t.on("bargeIn",function(t){null==v||v(t)}),t.on("stopPlaying",function(t){null==b||b(t)}),M.current=t,t.connect(),function(){console.log("🎙️ VoiceButton: Cleaning up VoiceSDK instance for ".concat(e)),M.current&&(M.current.destroy(),M.current=null)}},[e,n,r,c]);var A=function(){var t,e=(t=mt().m(function t(){var e;return mt().w(function(t){for(;;)switch(t.p=t.n){case 0:if(M.current){t.n=1;break}return t.a(2);case 1:return t.p=1,t.n=2,M.current.toggleRecording();case 2:t.n=4;break;case 3:t.p=3,e=t.v,console.error("Error toggling recording:",e);case 4:return t.a(2)}},t,null,[[1,3]])}),function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function c(t){wt(i,o,r,c,a,"next",t)}function a(t){wt(i,o,r,c,a,"throw",t)}c(void 0)})});return function(){return e.apply(this,arguments)}}(),B=(0,ht.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[(0,ht.jsx)("div",{style:{fontSize:"20px"},children:E?"🔴":"🎤"}),(0,ht.jsx)("div",{children:E?"Stop Listening":"Start Listening"})]});return(0,ht.jsx)("button",{className:"voice-button ".concat(E?"recording":""," ").concat(S),style:vt({padding:"12px 24px",border:"none",borderRadius:"8px",backgroundColor:E?"#dc3545":"#007bff",color:"white",cursor:"pointer",fontSize:"16px",fontWeight:"500",transition:"all 0.2s ease"},k),onClick:A,disabled:!P,children:O||B})};function Pt(t){return Pt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Pt(t)}function Ct(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof a?o:a,u=Object.create(s.prototype);return xt(u,"_invoke",function(n,o,r){var i,a,s,u=0,l=r||[],f=!1,d={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,a=0,s=t,d.n=n,c}};function p(n,o){for(a=n,s=o,e=0;!f&&u&&!r&&e<l.length;e++){var r,i=l[e],p=d.p,h=i[2];n>3?(r=h===o)&&(s=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(a=0,d.v=o,d.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,d.n=h,a=0))}if(r||n>1)return c;throw f=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,h),a=l,s=h;(e=a<2?t:s)||!f;){i||(a?a<3?(a>1&&(d.n=-1),p(a,s)):d.n=s:d.v=s);try{if(u=2,i){if(a||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,a<2&&(a=0)}else 1===a&&(e=i.return)&&e.call(i),a<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),a=1);i=t}else if((e=(f=d.n<0)?s:n.call(o,d))!==c)break}catch(e){i=t,a=1,s=e}finally{u=1}}return{value:e,done:f}}}(n,r,i),!0),u}var c={};function a(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(xt(e={},o,function(){return this}),e),f=u.prototype=a.prototype=Object.create(l);function d(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,xt(t,r,"GeneratorFunction")),t.prototype=Object.create(f),t}return s.prototype=u,xt(f,"constructor",u),xt(u,"constructor",s),s.displayName="GeneratorFunction",xt(u,r,"GeneratorFunction"),xt(f),xt(f,r,"Generator"),xt(f,o,function(){return this}),xt(f,"toString",function(){return"[object Generator]"}),(Ct=function(){return{w:i,m:d}})()}function xt(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}xt=function(t,e,n,o){function i(e,n){xt(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},xt(t,e,n,o)}function Et(t,e,n,o,r,i,c){try{var a=t[i](c),s=a.value}catch(t){return void n(t)}a.done?e(s):Promise.resolve(s).then(o,r)}function Tt(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function c(t){Et(i,o,r,c,a,"next",t)}function a(t){Et(i,o,r,c,a,"throw",t)}c(void 0)})}}function Rt(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,o)}return n}function Dt(t,e,n){return(e=It(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function _t(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,It(o.key),o)}}function It(t){var e=function(t){if("object"!=Pt(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=Pt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Pt(e)?e:e+""}var Mt=function(){return t=function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.options=function(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?Rt(Object(n),!0).forEach(function(e){Dt(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Rt(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}({websocketUrl:e.websocketUrl||"wss://speech.talktopc.com/ws/conv",agentId:e.agentId,voice:e.voice||"default",language:e.language||"en",container:e.container||document.body,buttonText:e.buttonText||"Start Listening",buttonClass:e.buttonClass||"voice-button"},e),this.isConnected=!1,this.isRecording=!1,this.isPlaying=!1,this.voiceSDK=new dt({websocketUrl:this.options.websocketUrl,agentId:this.options.agentId,voice:this.options.voice,language:this.options.language}),this.setupEventListeners(),this.createButton(),this.connect()},e=[{key:"setupEventListeners",value:function(){var t=this;this.voiceSDK.on("connected",function(){var e,n;t.isConnected=!0,t.updateButton(),null===(e=(n=t.options).onConnected)||void 0===e||e.call(n)}),this.voiceSDK.on("disconnected",function(){var e,n;t.isConnected=!1,t.updateButton(),null===(e=(n=t.options).onDisconnected)||void 0===e||e.call(n)}),this.voiceSDK.on("recordingStarted",function(){var e,n;t.isRecording=!0,t.updateButton(),null===(e=(n=t.options).onRecordingStarted)||void 0===e||e.call(n)}),this.voiceSDK.on("recordingStopped",function(){var e,n;t.isRecording=!1,t.updateButton(),null===(e=(n=t.options).onRecordingStopped)||void 0===e||e.call(n)}),this.voiceSDK.on("playbackStarted",function(){var e,n;t.isPlaying=!0,null===(e=(n=t.options).onPlaybackStarted)||void 0===e||e.call(n)}),this.voiceSDK.on("playbackStopped",function(){var e,n;t.isPlaying=!1,null===(e=(n=t.options).onPlaybackStopped)||void 0===e||e.call(n)}),this.voiceSDK.on("error",function(e){var n,o;null===(n=(o=t.options).onError)||void 0===n||n.call(o,e)}),this.voiceSDK.on("message",function(e){var n,o;null===(n=(o=t.options).onMessage)||void 0===n||n.call(o,e)}),this.voiceSDK.on("bargeIn",function(e){var n,o;null===(n=(o=t.options).onBargeIn)||void 0===n||n.call(o,e)}),this.voiceSDK.on("stopPlaying",function(e){var n,o;null===(n=(o=t.options).onStopPlaying)||void 0===n||n.call(o,e)})}},{key:"createButton",value:function(){var t=this;this.button=document.createElement("button"),this.button.className=this.options.buttonClass,this.button.style.cssText="\n padding: 12px 24px;\n border: none;\n border-radius: 8px;\n background-color: #6c757d;\n color: white;\n cursor: pointer;\n font-size: 16px;\n font-weight: 500;\n transition: all 0.2s ease;\n display: flex;\n align-items: center;\n gap: 8px;\n ",this.button.addEventListener("click",function(){return t.toggleRecording()}),this.options.container.appendChild(this.button),this.updateButton()}},{key:"updateButton",value:function(){if(this.button){var t=this.isRecording?"🔴":"🎤",e=this.isRecording?"Stop Listening":"Start Listening";this.button.innerHTML='\n <span style="font-size: 20px;">'.concat(t,"</span>\n <span>").concat(e,"</span>\n "),this.button.disabled=!this.isConnected,this.button.style.backgroundColor=this.isRecording?"#dc3545":this.isConnected?"#007bff":"#6c757d"}}},{key:"connect",value:(o=Tt(Ct().m(function t(){var e;return Ct().w(function(t){for(;;)switch(t.p=t.n){case 0:return t.p=0,t.n=1,this.voiceSDK.connect();case 1:t.n=3;break;case 2:t.p=2,e=t.v,console.error("Failed to connect:",e);case 3:return t.a(2)}},t,this,[[0,2]])})),function(){return o.apply(this,arguments)})},{key:"toggleRecording",value:(n=Tt(Ct().m(function t(){var e;return Ct().w(function(t){for(;;)switch(t.p=t.n){case 0:if(this.voiceSDK){t.n=1;break}return t.a(2);case 1:return t.p=1,t.n=2,this.voiceSDK.toggleRecording();case 2:t.n=4;break;case 3:t.p=3,e=t.v,console.error("Error toggling recording:",e);case 4:return t.a(2)}},t,this,[[1,3]])})),function(){return n.apply(this,arguments)})},{key:"getStatus",value:function(){return{isConnected:this.isConnected,isRecording:this.isRecording,isPlaying:this.isPlaying}}},{key:"updateConfig",value:function(t){this.voiceSDK.updateConfig(t)}},{key:"destroy",value:function(){this.button&&this.button.parentNode&&this.button.parentNode.removeChild(this.button),this.voiceSDK&&this.voiceSDK.destroy()}}],e&&_t(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n,o}();function At(t){return At="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},At(t)}function Bt(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,o)}return n}function Kt(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?Bt(Object(n),!0).forEach(function(e){Ft(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Bt(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function Ft(t,e,n){return(e=zt(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function Ut(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof a?o:a,u=Object.create(s.prototype);return Gt(u,"_invoke",function(n,o,r){var i,a,s,u=0,l=r||[],f=!1,d={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,a=0,s=t,d.n=n,c}};function p(n,o){for(a=n,s=o,e=0;!f&&u&&!r&&e<l.length;e++){var r,i=l[e],p=d.p,h=i[2];n>3?(r=h===o)&&(s=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(a=0,d.v=o,d.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,d.n=h,a=0))}if(r||n>1)return c;throw f=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,h),a=l,s=h;(e=a<2?t:s)||!f;){i||(a?a<3?(a>1&&(d.n=-1),p(a,s)):d.n=s:d.v=s);try{if(u=2,i){if(a||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,a<2&&(a=0)}else 1===a&&(e=i.return)&&e.call(i),a<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),a=1);i=t}else if((e=(f=d.n<0)?s:n.call(o,d))!==c)break}catch(e){i=t,a=1,s=e}finally{u=1}}return{value:e,done:f}}}(n,r,i),!0),u}var c={};function a(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(Gt(e={},o,function(){return this}),e),f=u.prototype=a.prototype=Object.create(l);function d(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,Gt(t,r,"GeneratorFunction")),t.prototype=Object.create(f),t}return s.prototype=u,Gt(f,"constructor",u),Gt(u,"constructor",s),s.displayName="GeneratorFunction",Gt(u,r,"GeneratorFunction"),Gt(f),Gt(f,r,"Generator"),Gt(f,o,function(){return this}),Gt(f,"toString",function(){return"[object Generator]"}),(Ut=function(){return{w:i,m:d}})()}function Gt(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}Gt=function(t,e,n,o){function i(e,n){Gt(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},Gt(t,e,n,o)}function Lt(t,e,n,o,r,i,c){try{var a=t[i](c),s=a.value}catch(t){return void n(t)}a.done?e(s):Promise.resolve(s).then(o,r)}function Nt(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function c(t){Lt(i,o,r,c,a,"next",t)}function a(t){Lt(i,o,r,c,a,"throw",t)}c(void 0)})}}function Wt(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function Vt(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,zt(o.key),o)}}function Ht(t,e,n){return e&&Vt(t.prototype,e),n&&Vt(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function zt(t){var e=function(t){if("object"!=At(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=At(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==At(e)?e:e+""}var Qt=function(){return Ht(function t(e){Wt(this,t),console.log("🚀 AgentSDK v2.1.8 initialized with config:",e),this.config=e,this.voiceSDK=null,this.isConnected=!1,this.isListening=!1,this.onConnected=function(){},this.onDisconnected=function(){},this.onError=function(t){return console.error("SDK Error:",t)},this.onTranscript=function(t){},this.onAgentSpeaking=function(t){}},[{key:"connect",value:(e=Nt(Ut().m(function t(e){var n,o=this;return Ut().w(function(t){for(;;)switch(t.p=t.n){case 0:if(t.p=0,e){t.n=1;break}throw new Error("signedUrl is required");case 1:return this.voiceSDK&&(console.log("🔌 AgentSDK: Cleaning up existing connection"),this.voiceSDK.destroy(),this.voiceSDK=null),this.voiceSDK=new dt({websocketUrl:e,autoReconnect:!1,agentId:this.config.agentId,appId:this.config.appId,language:this.config.language||"en"}),this.voiceSDK.on("connected",function(){o.isConnected=!0,o.onConnected()}),this.voiceSDK.on("disconnected",function(){o.isConnected=!1,o.onDisconnected()}),this.voiceSDK.on("error",function(t){o.onError(t)}),this.voiceSDK.on("message",function(t){o.handleWebSocketMessage(t)}),this.voiceSDK.on("recordingStarted",function(){o.isListening=!0}),this.voiceSDK.on("recordingStopped",function(){o.isListening=!1}),this.voiceSDK.on("playbackStarted",function(){o.onAgentSpeaking(!0)}),this.voiceSDK.on("playbackStopped",function(){o.onAgentSpeaking(!1)}),t.n=2,this.voiceSDK.connect();case 2:t.n=4;break;case 3:throw t.p=3,n=t.v,this.onError(n),n;case 4:return t.a(2)}},t,this,[[0,3]])})),function(t){return e.apply(this,arguments)})},{key:"handleWebSocketMessage",value:function(t){switch(t.type){case"connected":console.log("Session started successfully");break;case"user_transcript":this.onTranscript(t.user_transcription||t.text);break;case"agent_response":case"barge_in":case"stop_playing":break;case"error":this.onError(new Error(t.message))}}},{key:"startListening",value:(t=Nt(Ut().m(function t(){var e;return Ut().w(function(t){for(;;)switch(t.p=t.n){case 0:if(console.log("🎤 AgentSDK: startListening() called"),!this.voiceSDK){t.n=5;break}return t.p=1,console.log("🎤 AgentSDK: Starting recording..."),t.n=2,this.voiceSDK.startRecording();case 2:console.log("✅ AgentSDK: Recording started successfully"),t.n=4;break;case 3:throw t.p=3,e=t.v,console.error("❌ AgentSDK: Failed to start recording:",e),e;case 4:t.n=6;break;case 5:throw console.error("❌ AgentSDK: No voiceSDK instance available"),new Error("No voiceSDK instance available");case 6:return t.a(2)}},t,this,[[1,3]])})),function(){return t.apply(this,arguments)})},{key:"stopListening",value:function(){this.voiceSDK&&this.voiceSDK.stopRecording()}},{key:"updateVariables",value:function(t){this.voiceSDK&&this.isConnected&&this.voiceSDK.webSocketManager.sendMessage({t:"update_variables",variables:t})}},{key:"disconnect",value:function(){this.voiceSDK&&(this.voiceSDK.destroy(),this.voiceSDK=null),this.isConnected=!1,this.isListening=!1}}]);var t,e}(),qt=function(){return Ht(function t(){var e=this,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};Wt(this,t),this.config=this.mergeWithDefaults(n),this.sdk=new Qt(this.config),this.isOpen=!1,this.isActive=!1,this.setupEventHandlers(),this.createWidget(),this.config.behavior.autoOpen&&setTimeout(function(){return e.togglePanel()},1e3)},[{key:"mergeWithDefaults",value:function(t){var e,n,o,r,i,c,a,s,u,l,f,d,p,h,y,g,v,b,m,S,w,k,O,j,P,C,x,E,T,R,D,_,I,M,A,B,K,F,U,G,L,N=t.position||"bottom-right";if("string"==typeof N){var W=N.split("-");N={vertical:W[0]||"bottom",horizontal:W[1]||"right",offset:t.positionOffset||{x:20,y:20}}}var V=t.primaryColor||(null===(e=t.button)||void 0===e?void 0:e.primaryColor)||"#4F46E5";return Kt({agentId:t.agentId,appId:t.appId,getSessionUrl:t.getSessionUrl,websocketUrl:t.websocketUrl,demo:!1!==t.demo,icon:Kt({type:(null===(n=t.icon)||void 0===n?void 0:n.type)||"microphone",customImage:(null===(o=t.icon)||void 0===o?void 0:o.customImage)||null,emoji:(null===(r=t.icon)||void 0===r?void 0:r.emoji)||"🎤",text:(null===(i=t.icon)||void 0===i?void 0:i.text)||"AI",size:(null===(c=t.icon)||void 0===c?void 0:c.size)||"medium"},t.icon),position:Kt({vertical:N.vertical||"bottom",horizontal:N.horizontal||"right",offset:N.offset||{x:20,y:20}},"object"===At(t.position)?t.position:{}),button:Kt({size:(null===(a=t.button)||void 0===a?void 0:a.size)||"medium",shape:(null===(s=t.button)||void 0===s?void 0:s.shape)||"circle",primaryColor:V,hoverColor:(null===(u=t.button)||void 0===u?void 0:u.hoverColor)||"#7C3AED",activeColor:(null===(l=t.button)||void 0===l?void 0:l.activeColor)||"#EF4444",shadow:!1!==(null===(f=t.button)||void 0===f?void 0:f.shadow),shadowColor:(null===(d=t.button)||void 0===d?void 0:d.shadowColor)||"rgba(0,0,0,0.15)"},t.button),panel:Kt({width:(null===(p=t.panel)||void 0===p?void 0:p.width)||350,height:(null===(h=t.panel)||void 0===h?void 0:h.height)||500,borderRadius:(null===(y=t.panel)||void 0===y?void 0:y.borderRadius)||12,backgroundColor:(null===(g=t.panel)||void 0===g?void 0:g.backgroundColor)||"rgba(255,255,255,0.95)",backdropFilter:(null===(v=t.panel)||void 0===v?void 0:v.backdropFilter)||null,border:(null===(b=t.panel)||void 0===b?void 0:b.border)||"1px solid rgba(0,0,0,0.1)"},t.panel),header:Kt({title:(null===(m=t.header)||void 0===m?void 0:m.title)||"Voice Assistant",showTitle:!1!==(null===(S=t.header)||void 0===S?void 0:S.showTitle),backgroundColor:(null===(w=t.header)||void 0===w?void 0:w.backgroundColor)||null,textColor:(null===(k=t.header)||void 0===k?void 0:k.textColor)||"#FFFFFF",showCloseButton:!1!==(null===(O=t.header)||void 0===O?void 0:O.showCloseButton)},t.header),messages:Kt({userBackgroundColor:(null===(j=t.messages)||void 0===j?void 0:j.userBackgroundColor)||"#E5E7EB",agentBackgroundColor:(null===(P=t.messages)||void 0===P?void 0:P.agentBackgroundColor)||"#F3F4F6",systemBackgroundColor:(null===(C=t.messages)||void 0===C?void 0:C.systemBackgroundColor)||"#DCFCE7",errorBackgroundColor:(null===(x=t.messages)||void 0===x?void 0:x.errorBackgroundColor)||"#FEE2E2",textColor:(null===(E=t.messages)||void 0===E?void 0:E.textColor)||"#1F2937",fontSize:(null===(T=t.messages)||void 0===T?void 0:T.fontSize)||"14px",borderRadius:(null===(R=t.messages)||void 0===R?void 0:R.borderRadius)||8},t.messages),animation:Kt({enableHover:!1!==(null===(D=t.animation)||void 0===D?void 0:D.enableHover),enablePulse:!1!==(null===(_=t.animation)||void 0===_?void 0:_.enablePulse),enableSlide:!1!==(null===(I=t.animation)||void 0===I?void 0:I.enableSlide),duration:(null===(M=t.animation)||void 0===M?void 0:M.duration)||.3},t.animation),behavior:Kt({autoOpen:(null===(A=t.behavior)||void 0===A?void 0:A.autoOpen)||!1,autoConnect:(null===(B=t.behavior)||void 0===B?void 0:B.autoConnect)||!1,showWelcomeMessage:!1!==(null===(K=t.behavior)||void 0===K?void 0:K.showWelcomeMessage),welcomeMessage:(null===(F=t.behavior)||void 0===F?void 0:F.welcomeMessage)||"Hello! How can I help you today?"},t.behavior),accessibility:Kt({ariaLabel:(null===(U=t.accessibility)||void 0===U?void 0:U.ariaLabel)||"Voice Assistant",ariaDescription:(null===(G=t.accessibility)||void 0===G?void 0:G.ariaDescription)||"Click to open voice assistant",keyboardNavigation:!1!==(null===(L=t.accessibility)||void 0===L?void 0:L.keyboardNavigation)},t.accessibility),customStyles:t.customStyles||"",variables:t.variables||{},primaryColor:V},"string"==typeof t.position?{positionString:t.position}:{})}},{key:"setupEventHandlers",value:function(){var t=this;this.sdk.onConnected=function(){t.updateStatus("connected"),t.config.behavior.showWelcomeMessage&&t.addMessage("system",t.config.behavior.welcomeMessage)},this.sdk.onDisconnected=function(){t.updateStatus("disconnected"),t.isActive=!1,t.updateMicButtonState(!1),t.showError("Conversation ended. Click to start a new conversation.")},this.sdk.onError=function(e){t.showError(e.message)},this.sdk.onTranscript=function(e){t.addMessage("user",e)},this.sdk.onAgentSpeaking=function(e){e?t.showAgentThinking():t.hideAgentThinking()}}},{key:"createWidget",value:function(){var t=this,e=document.createElement("div");e.id="agent-widget",e.innerHTML=this.generateWidgetHTML(),document.body.appendChild(e),this.setupWidgetEvents(),this.config.behavior.autoOpen&&setTimeout(function(){return t.togglePanel()},1e3)}},{key:"generateWidgetHTML",value:function(){this.config.position;var t=this.config.button,e=this.config.icon,n=(this.config.panel,this.config.header),o=(this.config.animation,{small:50,medium:60,large:70,xl:80}[t.size]||60),r={small:20,medium:28,large:36,xl:44}[e.size]||28,i=this.generatePositionStyles(),c=this.generateIconHTML(r);return"\n <style>\n ".concat(this.generateCSS(i,o,r),"\n ").concat(this.config.customStyles,'\n </style>\n \n <button id="agent-button" \n aria-label="').concat(this.config.accessibility.ariaLabel,'"\n aria-description="').concat(this.config.accessibility.ariaDescription,'">\n ').concat(c,'\n </button>\n \n <div id="agent-panel">\n ').concat(n.showTitle?'\n <div id="agent-header">\n <h3 style="margin: 0; color: '.concat(n.textColor,';">').concat(n.title,"</h3>\n ").concat(n.showCloseButton?'<button id="agent-close">×</button>':"","\n </div>\n "):"",'\n \n <div id="agent-messages"></div>\n \n <div id="agent-controls">\n <button id="agent-mic-button" \n aria-label="Start/Stop Voice Recording">\n ').concat(c,"\n </button>\n </div>\n </div>\n ")}},{key:"generatePositionStyles",value:function(){var t=this.config.position,e=t.offset||{x:20,y:20},n="";return"top"===t.vertical?n+="top: ".concat(e.y,"px;"):"bottom"===t.vertical?n+="bottom: ".concat(e.y,"px;"):"center"===t.vertical&&(n+="top: 50%; transform: translateY(-50%);"),"left"===t.horizontal?n+="left: ".concat(e.x,"px;"):"right"===t.horizontal?n+="right: ".concat(e.x,"px;"):"center"===t.horizontal&&(n+="left: 50%; transform: translateX(-50%);"),n}},{key:"generateIconHTML",value:function(t){var e=this.config.icon;switch(e.type){case"custom":return'<img src="'.concat(e.customImage,'" alt="Voice Assistant" style="width: ').concat(t,"px; height: ").concat(t,'px; object-fit: contain;" />');case"emoji":return'<span style="font-size: '.concat(t,'px; line-height: 1;">').concat(e.emoji,"</span>");case"text":return'<span style="font-size: '.concat(Math.floor(.6*t),'px; font-weight: bold; color: white;">').concat(e.text,"</span>");default:return'<svg viewBox="0 0 24 24" style="width: '.concat(t,"px; height: ").concat(t,'px; fill: white;">\n <path d="M12 14c1.66 0 3-1.34 3-3V5c0-1.66-1.34-3-3-3S9 3.34 9 5v6c0 1.66 1.34 3 3 3z"/>\n <path d="M17 11c0 2.76-2.24 5-5 5s-5-2.24-5-5H5c0 3.53 2.61 6.43 6 6.92V21h2v-3.08c3.39-.49 6-3.39 6-6.92h-2z"/>\n </svg>')}}},{key:"generateCSS",value:function(t,e,n){var o=this.config.button,r=this.config.panel,i=this.config.header,c=this.config.messages,a=this.config.animation;return"\n #agent-widget {\n position: fixed;\n ".concat(t,'\n z-index: 10000;\n font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;\n }\n \n #agent-button {\n width: ').concat(e,"px;\n height: ").concat(e,"px;\n border-radius: ").concat("circle"===o.shape?"50%":"square"===o.shape?"0":"12px",";\n background: ").concat(o.primaryColor,";\n border: none;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n transition: all ").concat(a.duration,"s ease;\n ").concat(o.shadow?"box-shadow: 0 4px 12px ".concat(o.shadowColor,";"):"","\n }\n \n ").concat(a.enableHover?"\n #agent-button:hover {\n background: ".concat(o.hoverColor,";\n transform: scale(1.05);\n ").concat(o.shadow?"box-shadow: 0 8px 20px ".concat(o.shadowColor,";"):"","\n }\n "):"","\n \n #agent-panel {\n display: none;\n position: absolute;\n bottom: ").concat(e+20,"px;\n ").concat("right"===this.config.position.horizontal?"right: 0;":"left: 0;","\n width: ").concat(r.width,"px;\n height: ").concat(r.height,"px;\n background: ").concat(r.backgroundColor,";\n border-radius: ").concat(r.borderRadius,"px;\n border: ").concat(r.border,";\n flex-direction: column;\n overflow: hidden;\n ").concat(r.backdropFilter?"backdrop-filter: ".concat(r.backdropFilter,";"):"","\n ").concat(a.enableSlide?"transition: all ".concat(a.duration,"s ease;"):"","\n }\n \n #agent-panel.open {\n display: flex;\n ").concat(a.enableSlide?"transform: translateY(0); opacity: 1;":"","\n }\n \n #agent-header {\n background: ").concat(i.backgroundColor||o.primaryColor,";\n color: ").concat(i.textColor,";\n padding: 16px;\n display: flex;\n justify-content: space-between;\n align-items: center;\n border-radius: ").concat(r.borderRadius,"px ").concat(r.borderRadius,"px 0 0;\n }\n \n #agent-close {\n background: none;\n border: none;\n color: ").concat(i.textColor,";\n cursor: pointer;\n font-size: 24px;\n padding: 0;\n width: 24px;\n height: 24px;\n display: flex;\n align-items: center;\n justify-content: center;\n }\n \n #agent-messages {\n flex: 1;\n overflow-y: auto;\n padding: 16px;\n display: flex;\n flex-direction: column;\n gap: 12px;\n }\n \n .message {\n padding: 12px;\n border-radius: ").concat(c.borderRadius,"px;\n max-width: 80%;\n font-size: ").concat(c.fontSize,";\n color: ").concat(c.textColor,";\n }\n \n .message.user {\n background: ").concat(c.userBackgroundColor,";\n align-self: flex-end;\n }\n \n .message.agent {\n background: ").concat(c.agentBackgroundColor,";\n align-self: flex-start;\n }\n \n .message.system {\n background: ").concat(c.systemBackgroundColor,";\n align-self: flex-start;\n font-style: italic;\n }\n \n .error-message {\n background: ").concat(c.errorBackgroundColor,";\n color: #991B1B;\n padding: 12px;\n border-radius: ").concat(c.borderRadius,"px;\n margin: 8px;\n }\n \n #agent-controls {\n padding: 16px;\n border-top: 1px solid #E5E7EB;\n display: flex;\n justify-content: center;\n }\n \n #agent-mic-button {\n width: ").concat(e,"px;\n height: ").concat(e,"px;\n border-radius: ").concat("circle"===o.shape?"50%":"square"===o.shape?"0":"12px",";\n border: none;\n background: ").concat(o.primaryColor,";\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n transition: all ").concat(a.duration,"s ease;\n }\n \n #agent-mic-button.active {\n background: ").concat(o.activeColor,";\n ").concat(a.enablePulse?"\n animation: pulse 1.5s infinite;\n ":"","\n }\n \n ").concat(a.enablePulse?"\n @keyframes pulse {\n 0%, 100% { transform: scale(1); }\n 50% { transform: scale(1.05); }\n }\n ":"","\n \n .agent-thinking {\n font-style: italic;\n color: #6B7280;\n }\n ")}},{key:"setupWidgetEvents",value:function(){var t=this;document.getElementById("agent-button").onclick=function(){return t.togglePanel()};var e=document.getElementById("agent-close");e&&(e.onclick=function(){return t.togglePanel()}),document.getElementById("agent-mic-button").onclick=function(){return t.toggleVoice()},this.config.accessibility.keyboardNavigation&&this.setupKeyboardNavigation()}},{key:"setupKeyboardNavigation",value:function(){var t=this;document.addEventListener("keydown",function(e){"Escape"===e.key&&t.isOpen&&t.togglePanel()})}},{key:"togglePanel",value:function(){this.isOpen=!this.isOpen,document.getElementById("agent-panel").classList.toggle("open")}},{key:"toggleVoice",value:(e=Nt(Ut().m(function t(){var e,n,o,r;return Ut().w(function(t){for(;;)switch(t.p=t.n){case 0:if(this.isActive){t.n=13;break}return t.p=1,console.log("🎤 Starting voice session..."),t.n=2,this.getSignedUrl();case 2:return e=t.v,console.log("🔗 Got signed URL:",e),t.n=3,this.sdk.connect(e);case 3:n=t.v,console.log("✅ Connected to WebSocket, connected:",n),o=0;case 4:if(this.sdk.isConnected||!(o<50)){t.n=6;break}return t.n=5,new Promise(function(t){return setTimeout(t,100)});case 5:o++,t.n=4;break;case 6:if(!this.sdk.isConnected){t.n=8;break}return console.log("✅ WebSocket ready, starting listening..."),t.n=7,this.sdk.startListening();case 7:console.log("🎤 Started listening"),this.isActive=!0,this.updateMicButtonState(!0),this.addMessage("system","🎤 Listening... Click mic to stop"),t.n=10;break;case 8:return console.warn("⚠️ Connection not fully ready, but trying to start listening anyway..."),t.n=9,this.sdk.startListening();case 9:console.log("🎤 Started listening"),this.isActive=!0,this.updateMicButtonState(!0),this.addMessage("system","🎤 Listening... Click mic to stop");case 10:t.n=12;break;case 11:t.p=11,r=t.v,console.error("❌ Failed to start:",r),this.showError(r.message);case 12:t.n=14;break;case 13:console.log("🔇 Stopping voice session..."),this.sdk.stopListening(),this.sdk.disconnect(),this.isActive=!1,this.updateMicButtonState(!1),this.addMessage("system","🔇 Stopped listening");case 14:return t.a(2)}},t,this,[[1,11]])})),function(){return e.apply(this,arguments)})},{key:"updateMicButtonState",value:function(t){var e=document.getElementById("agent-mic-button");if(e)if(this.config.icon.size,t){if(e.classList.add("active"),e.title="Click to stop listening","microphone"===this.config.icon.type||"custom"===this.config.icon.type){var n=e.querySelector("svg")||e.querySelector("img");n&&"svg"===n.tagName&&(n.innerHTML='\n <rect x="6" y="6" width="12" height="12" rx="2"/>\n <path d="M9 9h6"/>\n ')}}else if(e.classList.remove("active"),e.title="Click to start listening","microphone"===this.config.icon.type){var o=e.querySelector("svg");o&&(o.innerHTML='\n <path d="M12 14c1.66 0 3-1.34 3-3V5c0-1.66-1.34-3-3-3S9 3.34 9 5v6c0 1.66 1.34 3 3 3z"/>\n <path d="M17 11c0 2.76-2.24 5-5 5s-5-2.24-5-5H5c0 3.53 2.61 6.43 6 6.92V21h2v-3.08c3.39-.49 6-3.39 6-6.92h-2z"/>\n ')}}},{key:"getSignedUrl",value:(t=Nt(Ut().m(function t(){var e,n,o,r,i,c,a;return Ut().w(function(t){for(;;)switch(t.n){case 0:if(this.config.getSessionUrl){t.n=2;break}if(this.config.agentId){t.n=1;break}throw new Error("agentId is required");case 1:return e=this.config.websocketUrl||"wss://speech.talktopc.com/ws/conv",(n=new URLSearchParams).append("agentId",this.config.agentId),this.config.appId&&n.append("appId",this.config.appId),!1!==this.config.demo&&n.append("demo","true"),t.a(2,"".concat(e,"?").concat(n.toString()));case 2:if("string"!=typeof this.config.getSessionUrl){t.n=6;break}return o={agentId:this.config.agentId,variables:this.config.variables||{}},this.config.appId&&(o.appId=this.config.appId),t.n=3,fetch(this.config.getSessionUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)});case 3:if((r=t.v).ok){t.n=4;break}throw new Error("Failed to get session URL: ".concat(r.statusText));case 4:return t.n=5,r.json();case 5:return i=t.v,t.a(2,i.signedUrl||i.wsUrl||i.url);case 6:if("function"!=typeof this.config.getSessionUrl){t.n=8;break}return c={agentId:this.config.agentId,variables:this.config.variables||{}},this.config.appId&&(c.appId=this.config.appId),t.n=7,this.config.getSessionUrl(c);case 7:return a=t.v,t.a(2,"string"==typeof a?a:a.signedUrl||a.wsUrl||a.url);case 8:throw new Error("getSessionUrl must be a string (backend URL), a function, or omitted (for direct connection with agentId/appId)");case 9:return t.a(2)}},t,this)})),function(){return t.apply(this,arguments)})},{key:"addMessage",value:function(t,e){var n=document.getElementById("agent-messages"),o=document.createElement("div");o.className="message ".concat(t),o.textContent=e,n.appendChild(o),n.scrollTop=n.scrollHeight}},{key:"showAgentThinking",value:function(){var t=document.getElementById("agent-messages"),e=document.createElement("div");e.className="message agent agent-thinking",e.id="thinking-indicator",e.textContent="Agent is speaking...",t.appendChild(e),t.scrollTop=t.scrollHeight}},{key:"hideAgentThinking",value:function(){var t=document.getElementById("thinking-indicator");t&&t.remove()}},{key:"showError",value:function(t){var e=document.getElementById("agent-messages"),n=document.createElement("div");n.className="error-message",n.textContent=t,e.appendChild(n)}},{key:"updateStatus",value:function(t){}},{key:"updateConfig",value:function(t){this.config=this.mergeWithDefaults(Kt(Kt({},this.config),t));var e=document.getElementById("agent-widget");e&&e.remove(),this.createWidget()}},{key:"destroy",value:function(){var t=document.getElementById("agent-widget");t&&t.remove(),this.sdk&&this.sdk.disconnect()}}]);var t,e}(),$t="2.0.0";const Jt={VoiceSDK:dt,WebSocketManager:D,AudioRecorder:N,AudioPlayer:X,EventEmitter:a,VoiceButton:jt,VanillaVoiceButton:Mt,AgentSDK:Qt,AgentWidget:qt,VERSION:$t};return o})());
|
|
2
|
+
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.TTPAgentSDK=e():t.TTPAgentSDK=e()}(window,()=>(()=>{"use strict";var t={540:(t,e,n)=>{t.exports=n(869)},698:(t,e)=>{var n=Symbol.for("react.transitional.element");function o(t,e,o){var r=null;if(void 0!==o&&(r=""+o),void 0!==e.key&&(r=""+e.key),"key"in e)for(var i in o={},e)"key"!==i&&(o[i]=e[i]);else o=e;return e=o.ref,{$$typeof:n,type:t,key:r,ref:void 0!==e?e:null,props:o}}Symbol.for("react.fragment"),e.jsx=o,e.jsxs=o},848:(t,e,n)=>{t.exports=n(698)},869:(t,e)=>{Symbol.for("react.transitional.element"),Symbol.for("react.portal"),Symbol.for("react.fragment"),Symbol.for("react.strict_mode"),Symbol.for("react.profiler"),Symbol.for("react.consumer"),Symbol.for("react.context"),Symbol.for("react.forward_ref"),Symbol.for("react.suspense"),Symbol.for("react.memo"),Symbol.for("react.lazy"),Symbol.for("react.activity"),Symbol.iterator;var n={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},o=Object.assign,r={};function i(t,e,o){this.props=t,this.context=e,this.refs=r,this.updater=o||n}function c(){}function a(t,e,o){this.props=t,this.context=e,this.refs=r,this.updater=o||n}i.prototype.isReactComponent={},i.prototype.setState=function(t,e){if("object"!=typeof t&&"function"!=typeof t&&null!=t)throw Error("takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,t,e,"setState")},i.prototype.forceUpdate=function(t){this.updater.enqueueForceUpdate(this,t,"forceUpdate")},c.prototype=i.prototype;var s=a.prototype=new c;s.constructor=a,o(s,i.prototype),s.isPureReactComponent=!0;Array.isArray;var u={H:null,A:null,T:null,S:null};Object.prototype.hasOwnProperty;"function"==typeof reportError&&reportError;e.useEffect=function(t,e){return u.H.useEffect(t,e)},e.useRef=function(t){return u.H.useRef(t)},e.useState=function(t){return u.H.useState(t)}}},e={};function n(o){var r=e[o];if(void 0!==r)return r.exports;var i=e[o]={exports:{}};return t[o](i,i.exports,n),i.exports}n.d=(t,e)=>{for(var o in e)n.o(e,o)&&!n.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:e[o]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var o={};function r(t){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},r(t)}function i(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,c(o.key),o)}}function c(t){var e=function(t){if("object"!=r(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=r(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==r(e)?e:e+""}n.r(o),n.d(o,{AgentSDK:()=>Qt,AgentWidget:()=>qt,AudioPlayer:()=>X,AudioRecorder:()=>H,EventEmitter:()=>a,VERSION:()=>$t,VanillaVoiceButton:()=>Bt,VoiceButton:()=>jt,VoiceSDK:()=>dt,WebSocketManager:()=>D,default:()=>Jt});var a=function(){return t=function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.events={}},e=[{key:"on",value:function(t,e){this.events[t]||(this.events[t]=[]),this.events[t].push(e)}},{key:"off",value:function(t,e){this.events[t]&&(this.events[t]=this.events[t].filter(function(t){return t!==e}))}},{key:"emit",value:function(t){for(var e=arguments.length,n=new Array(e>1?e-1:0),o=1;o<e;o++)n[o-1]=arguments[o];this.events[t]&&this.events[t].forEach(function(e){try{e.apply(void 0,n)}catch(e){console.error("Error in event listener for ".concat(t,":"),e)}})}},{key:"removeAllListeners",value:function(t){t?delete this.events[t]:this.events={}}}],e&&i(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}();function s(t){return s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},s(t)}function u(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=n){var o,r,i,c,a=[],s=!0,u=!1;try{if(i=(n=n.call(t)).next,0===e){if(Object(n)!==n)return;s=!1}else for(;!(s=(o=i.call(n)).done)&&(a.push(o.value),a.length!==e);s=!0);}catch(t){u=!0,r=t}finally{try{if(!s&&null!=n.return&&(c=n.return(),Object(c)!==c))return}finally{if(u)throw r}}return a}}(t,e)||f(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function l(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=f(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var o=0,r=function(){};return{s:r,n:function(){return o>=t.length?{done:!0}:{done:!1,value:t[o++]}},e:function(t){throw t},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,c=!0,a=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return c=t.done,t},e:function(t){a=!0,i=t},f:function(){try{c||null==n.return||n.return()}finally{if(a)throw i}}}}function f(t,e){if(t){if("string"==typeof t)return d(t,e);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?d(t,e):void 0}}function d(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,o=Array(e);n<e;n++)o[n]=t[n];return o}function p(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof a?o:a,u=Object.create(s.prototype);return h(u,"_invoke",function(n,o,r){var i,a,s,u=0,l=r||[],f=!1,d={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,a=0,s=t,d.n=n,c}};function p(n,o){for(a=n,s=o,e=0;!f&&u&&!r&&e<l.length;e++){var r,i=l[e],p=d.p,h=i[2];n>3?(r=h===o)&&(s=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(a=0,d.v=o,d.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,d.n=h,a=0))}if(r||n>1)return c;throw f=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,h),a=l,s=h;(e=a<2?t:s)||!f;){i||(a?a<3?(a>1&&(d.n=-1),p(a,s)):d.n=s:d.v=s);try{if(u=2,i){if(a||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,a<2&&(a=0)}else 1===a&&(e=i.return)&&e.call(i),a<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),a=1);i=t}else if((e=(f=d.n<0)?s:n.call(o,d))!==c)break}catch(e){i=t,a=1,s=e}finally{u=1}}return{value:e,done:f}}}(n,r,i),!0),u}var c={};function a(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(h(e={},o,function(){return this}),e),f=u.prototype=a.prototype=Object.create(l);function d(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,h(t,r,"GeneratorFunction")),t.prototype=Object.create(f),t}return s.prototype=u,h(f,"constructor",u),h(u,"constructor",s),s.displayName="GeneratorFunction",h(u,r,"GeneratorFunction"),h(f),h(f,r,"Generator"),h(f,o,function(){return this}),h(f,"toString",function(){return"[object Generator]"}),(p=function(){return{w:i,m:d}})()}function h(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}h=function(t,e,n,o){function i(e,n){h(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},h(t,e,n,o)}function y(t,e,n,o,r,i,c){try{var a=t[i](c),s=a.value}catch(t){return void n(t)}a.done?e(s):Promise.resolve(s).then(o,r)}function g(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,v(o.key),o)}}function v(t){var e=function(t){if("object"!=s(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=s(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==s(e)?e:e+""}function b(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(b=function(){return!!t})()}function m(t){return m=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},m(t)}function S(t,e){return S=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},S(t,e)}const w=new(function(t){function e(){var t;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(t=function(t,e,n){return e=m(e),function(t,e){if(e&&("object"==s(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,b()?Reflect.construct(e,n||[],m(t).constructor):e.apply(t,n))}(this,e)).connections=new Map,t.connectionCounts=new Map,t.creatingConnections=new Set,t}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&S(t,e)}(e,t),n=e,o=[{key:"getConnection",value:(r=p().m(function t(e){var n,o,r=this;return p().w(function(t){for(;;)switch(t.n){case 0:if(!this.connections.has(e)){t.n=1;break}return n=this.connections.get(e),this.connectionCounts.set(e,(this.connectionCounts.get(e)||0)+1),t.a(2,n);case 1:if(!this.creatingConnections||!this.creatingConnections.has(e)){t.n=2;break}return t.a(2,new Promise(function(t){var n=function(){if(r.connections.has(e)){var o=r.connections.get(e);r.connectionCounts.set(e,(r.connectionCounts.get(e)||0)+1),t(o)}else setTimeout(n,50)};n()}));case 2:return this.creatingConnections.add(e),o=new WebSocket(e),this.connections.set(e,o),this.connectionCounts.set(e,1),o.addEventListener("open",function(t){r.creatingConnections.delete(e),r.emit("open",t,e)}),o.addEventListener("close",function(t){r.creatingConnections.delete(e),r.connections.delete(e),r.connectionCounts.delete(e),r.emit("close",t,e)}),o.addEventListener("error",function(t){r.creatingConnections.delete(e),r.emit("error",t,e)}),o.addEventListener("message",function(t){r.emit("message",t,e)}),t.a(2,o)}},t,this)}),i=function(){var t=this,e=arguments;return new Promise(function(n,o){var i=r.apply(t,e);function c(t){y(i,n,o,c,a,"next",t)}function a(t){y(i,n,o,c,a,"throw",t)}c(void 0)})},function(t){return i.apply(this,arguments)})},{key:"releaseConnection",value:function(t){if(this.connections.has(t)){var e=this.connectionCounts.get(t)||0,n=Math.max(0,e-1);if(this.connectionCounts.set(t,n),0===n){var o=this.connections.get(t);o&&o.readyState===WebSocket.OPEN&&o.close(1e3,"No more subscribers"),this.connections.delete(t),this.connectionCounts.delete(t)}}}},{key:"forceClose",value:function(t){if(this.connections.has(t)){var e=this.connections.get(t);e&&e.readyState===WebSocket.OPEN&&e.close(1e3,"Force close"),this.connections.delete(t),this.connectionCounts.delete(t)}}},{key:"getConnectionStatus",value:function(t){return this.connections.has(t)?{exists:!0,readyState:this.connections.get(t).readyState,subscribers:this.connectionCounts.get(t)||0}:{exists:!1,readyState:null,subscribers:0}}},{key:"getAllConnections",value:function(){var t,e={},n=l(this.connections.entries());try{for(n.s();!(t=n.n()).done;){var o=u(t.value,2),r=o[0],i=o[1];e[r]={readyState:i.readyState,subscribers:this.connectionCounts.get(r)||0}}}catch(t){n.e(t)}finally{n.f()}return e}},{key:"clearAll",value:function(){var t,e=l(this.connections.entries());try{for(e.s();!(t=e.n()).done;){var n=u(t.value,2),o=(n[0],n[1]);o&&o.readyState===WebSocket.OPEN&&o.close(1e3,"Clear all")}}catch(t){e.e(t)}finally{e.f()}this.connections.clear(),this.connectionCounts.clear(),this.creatingConnections.clear()}}],o&&g(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i}(a));function k(t){return k="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},k(t)}function O(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof a?o:a,u=Object.create(s.prototype);return j(u,"_invoke",function(n,o,r){var i,a,s,u=0,l=r||[],f=!1,d={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,a=0,s=t,d.n=n,c}};function p(n,o){for(a=n,s=o,e=0;!f&&u&&!r&&e<l.length;e++){var r,i=l[e],p=d.p,h=i[2];n>3?(r=h===o)&&(s=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(a=0,d.v=o,d.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,d.n=h,a=0))}if(r||n>1)return c;throw f=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,h),a=l,s=h;(e=a<2?t:s)||!f;){i||(a?a<3?(a>1&&(d.n=-1),p(a,s)):d.n=s:d.v=s);try{if(u=2,i){if(a||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,a<2&&(a=0)}else 1===a&&(e=i.return)&&e.call(i),a<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),a=1);i=t}else if((e=(f=d.n<0)?s:n.call(o,d))!==c)break}catch(e){i=t,a=1,s=e}finally{u=1}}return{value:e,done:f}}}(n,r,i),!0),u}var c={};function a(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(j(e={},o,function(){return this}),e),f=u.prototype=a.prototype=Object.create(l);function d(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,j(t,r,"GeneratorFunction")),t.prototype=Object.create(f),t}return s.prototype=u,j(f,"constructor",u),j(u,"constructor",s),s.displayName="GeneratorFunction",j(u,r,"GeneratorFunction"),j(f),j(f,r,"Generator"),j(f,o,function(){return this}),j(f,"toString",function(){return"[object Generator]"}),(O=function(){return{w:i,m:d}})()}function j(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}j=function(t,e,n,o){function i(e,n){j(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},j(t,e,n,o)}function P(t,e,n,o,r,i,c){try{var a=t[i](c),s=a.value}catch(t){return void n(t)}a.done?e(s):Promise.resolve(s).then(o,r)}function C(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,x(o.key),o)}}function x(t){var e=function(t){if("object"!=k(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=k(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==k(e)?e:e+""}function E(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(E=function(){return!!t})()}function T(t){return T=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},T(t)}function R(t,e){return R=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},R(t,e)}var D=function(t){function e(t){var n;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(n=function(t,e,n){return e=T(e),function(t,e){if(e&&("object"==k(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,E()?Reflect.construct(e,n||[],T(t).constructor):e.apply(t,n))}(this,e)).config=t,n.ws=null,n.isConnected=!1,n.connectionId=null,n}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&R(t,e)}(e,t),n=e,o=[{key:"connect",value:(i=O().m(function t(){var e=this;return O().w(function(t){for(;;)if(0===t.n)return t.a(2,new Promise(function(t,n){try{e.connectionId=Date.now()+"_"+Math.random().toString(36).substr(2,9),e.connectResolve=t,e.connectReject=n,w.getConnection(e.config.websocketUrl,e.config).then(function(n){e.ws=n,e.setupEventListeners(),n.readyState===WebSocket.OPEN&&(e.isConnected=!0,e.emit("connected"),t(),e.connectResolve=null,e.connectReject=null)}).catch(function(t){console.error("🔌 WebSocketManager: Connection failed ".concat(e.connectionId),t),n(t),e.connectResolve=null,e.connectReject=null})}catch(t){console.error("🔌 WebSocketManager: Connection error ".concat(e.connectionId),t),n(t),e.connectResolve=null,e.connectReject=null}}))},t)}),c=function(){var t=this,e=arguments;return new Promise(function(n,o){var r=i.apply(t,e);function c(t){P(r,n,o,c,a,"next",t)}function a(t){P(r,n,o,c,a,"throw",t)}c(void 0)})},function(){return c.apply(this,arguments)})},{key:"setupEventListeners",value:function(){var t=this;if(this.ws){var e=function(e,n){n===t.config.websocketUrl&&(t.isConnected=!0,t.emit("connected"),t.connectResolve&&(t.connectResolve(),t.connectResolve=null,t.connectReject=null))},n=function(e,n){n===t.config.websocketUrl&&(t.isConnected=!1,t.emit("disconnected",e))},o=function(e,n){n===t.config.websocketUrl&&(t.emit("error",e),t.connectReject&&(t.connectReject(e),t.connectResolve=null,t.connectReject=null))},r=function(e,n){n===t.config.websocketUrl&&t.handleMessage(e)};w.on("open",e),w.on("close",n),w.on("error",o),w.on("message",r),this.eventHandlers={open:e,close:n,error:o,message:r}}}},{key:"disconnect",value:function(){this.eventHandlers&&(w.off("open",this.eventHandlers.open),w.off("close",this.eventHandlers.close),w.off("error",this.eventHandlers.error),w.off("message",this.eventHandlers.message)),this.config.websocketUrl&&w.releaseConnection(this.config.websocketUrl),this.ws=null,this.isConnected=!1}},{key:"sendMessage",value:function(t){if(this.isConnected&&this.ws)try{this.ws.send(JSON.stringify(t))}catch(t){console.warn("🔌 WebSocketManager: Failed to send message:",t.message)}}},{key:"sendBinary",value:function(t){if(this.isConnected&&this.ws)try{this.ws.send(t)}catch(t){console.warn("🔌 WebSocketManager: Failed to send binary data:",t.message)}}},{key:"handleMessage",value:function(t){var e=this;if(t.data instanceof ArrayBuffer)this.emit("binaryAudio",t.data);else if(t.data instanceof Blob)t.data.arrayBuffer().then(function(t){e.emit("binaryAudio",t)}).catch(function(t){console.error("🔌 WebSocketManager: Error converting Blob to ArrayBuffer:",t)});else try{var n=JSON.parse(t.data);"barge_in_ack"!==n.t&&"stop_sending"!==n.t||this.emit("bargeIn",n),"stop_playing"===n.t&&this.emit("stopPlaying",n),this.emit("message",n)}catch(t){this.emit("error",t)}}},{key:"getStatus",value:function(){return{isConnected:this.isConnected,readyState:this.ws?this.ws.readyState:null,connectionId:this.connectionId}}}],r=[{key:"getSingletonStatus",value:function(){return w.getAllConnections()}},{key:"clearAllConnections",value:function(){w.clearAll()}}],o&&C(n.prototype,o),r&&C(n,r),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i,c}(a);function _(t){return _="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},_(t)}function I(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof a?o:a,u=Object.create(s.prototype);return B(u,"_invoke",function(n,o,r){var i,a,s,u=0,l=r||[],f=!1,d={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,a=0,s=t,d.n=n,c}};function p(n,o){for(a=n,s=o,e=0;!f&&u&&!r&&e<l.length;e++){var r,i=l[e],p=d.p,h=i[2];n>3?(r=h===o)&&(s=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(a=0,d.v=o,d.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,d.n=h,a=0))}if(r||n>1)return c;throw f=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,h),a=l,s=h;(e=a<2?t:s)||!f;){i||(a?a<3?(a>1&&(d.n=-1),p(a,s)):d.n=s:d.v=s);try{if(u=2,i){if(a||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,a<2&&(a=0)}else 1===a&&(e=i.return)&&e.call(i),a<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),a=1);i=t}else if((e=(f=d.n<0)?s:n.call(o,d))!==c)break}catch(e){i=t,a=1,s=e}finally{u=1}}return{value:e,done:f}}}(n,r,i),!0),u}var c={};function a(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(B(e={},o,function(){return this}),e),f=u.prototype=a.prototype=Object.create(l);function d(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,B(t,r,"GeneratorFunction")),t.prototype=Object.create(f),t}return s.prototype=u,B(f,"constructor",u),B(u,"constructor",s),s.displayName="GeneratorFunction",B(u,r,"GeneratorFunction"),B(f),B(f,r,"Generator"),B(f,o,function(){return this}),B(f,"toString",function(){return"[object Generator]"}),(I=function(){return{w:i,m:d}})()}function B(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}B=function(t,e,n,o){function i(e,n){B(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},B(t,e,n,o)}function M(t,e,n,o,r,i,c){try{var a=t[i](c),s=a.value}catch(t){return void n(t)}a.done?e(s):Promise.resolve(s).then(o,r)}function A(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function c(t){M(i,o,r,c,a,"next",t)}function a(t){M(i,o,r,c,a,"throw",t)}c(void 0)})}}function K(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,F(o.key),o)}}function F(t){var e=function(t){if("object"!=_(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=_(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==_(e)?e:e+""}function U(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(U=function(){return!!t})()}function G(t){return G=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},G(t)}function L(t,e){return L=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},L(t,e)}var H=function(t){function e(t){var n;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(n=function(t,e,n){return e=G(e),function(t,e){if(e&&("object"==_(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,U()?Reflect.construct(e,n||[],G(t).constructor):e.apply(t,n))}(this,e)).config=t,n.audioContext=null,n.audioWorkletNode=null,n.mediaStream=null,n.isRecording=!1,n}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&L(t,e)}(e,t),n=e,o=[{key:"start",value:(i=A(I().m(function t(){var e,n=this;return I().w(function(t){for(;;)switch(t.p=t.n){case 0:return t.p=0,t.n=1,navigator.mediaDevices.getUserMedia({audio:{sampleRate:this.config.sampleRate,channelCount:1,echoCancellation:!0,noiseSuppression:!0,autoGainControl:!0}});case 1:if(this.mediaStream=t.v,this.audioContext=new(window.AudioContext||window.webkitAudioContext)({sampleRate:this.config.sampleRate}),"suspended"!==this.audioContext.state){t.n=2;break}return t.n=2,this.audioContext.resume();case 2:return t.n=3,this.audioContext.audioWorklet.addModule("/audio-processor.js");case 3:this.audioWorkletNode=new AudioWorkletNode(this.audioContext,"audio-processor"),this.audioContext.createMediaStreamSource(this.mediaStream).connect(this.audioWorkletNode),this.audioWorkletNode.port.onmessage=function(t){var e=t.data,o=e.type,r=e.data;"pcm_audio_data"===o&&n.emit("audioData",r)},this.audioWorkletNode.port.postMessage({type:"setForceContinuous",data:{enabled:!0}}),this.isRecording=!0,this.emit("recordingStarted"),t.n=5;break;case 4:throw t.p=4,e=t.v,this.emit("error",e),e;case 5:return t.a(2)}},t,this,[[0,4]])})),function(){return i.apply(this,arguments)})},{key:"stop",value:(r=A(I().m(function t(){var e;return I().w(function(t){for(;;)switch(t.p=t.n){case 0:if(this.isRecording){t.n=1;break}return t.a(2);case 1:if(t.p=1,!this.audioWorkletNode){t.n=2;break}return this.audioWorkletNode.port.postMessage({type:"flush"}),t.n=2,new Promise(function(t){return setTimeout(t,100)});case 2:if(this.mediaStream&&(this.mediaStream.getTracks().forEach(function(t){return t.stop()}),this.mediaStream=null),!this.audioContext||"closed"===this.audioContext.state){t.n=4;break}return t.n=3,this.audioContext.close();case 3:this.audioContext=null;case 4:this.audioWorkletNode=null,this.isRecording=!1,this.emit("recordingStopped"),t.n=6;break;case 5:throw t.p=5,e=t.v,this.emit("error",e),e;case 6:return t.a(2)}},t,this,[[1,5]])})),function(){return r.apply(this,arguments)})},{key:"getStatus",value:function(){return{isRecording:this.isRecording,audioContextState:this.audioContext?this.audioContext.state:"closed"}}},{key:"destroy",value:function(){this.stop()}}],o&&K(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i}(a);function N(t){return N="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},N(t)}function W(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof a?o:a,u=Object.create(s.prototype);return z(u,"_invoke",function(n,o,r){var i,a,s,u=0,l=r||[],f=!1,d={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,a=0,s=t,d.n=n,c}};function p(n,o){for(a=n,s=o,e=0;!f&&u&&!r&&e<l.length;e++){var r,i=l[e],p=d.p,h=i[2];n>3?(r=h===o)&&(s=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(a=0,d.v=o,d.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,d.n=h,a=0))}if(r||n>1)return c;throw f=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,h),a=l,s=h;(e=a<2?t:s)||!f;){i||(a?a<3?(a>1&&(d.n=-1),p(a,s)):d.n=s:d.v=s);try{if(u=2,i){if(a||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,a<2&&(a=0)}else 1===a&&(e=i.return)&&e.call(i),a<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),a=1);i=t}else if((e=(f=d.n<0)?s:n.call(o,d))!==c)break}catch(e){i=t,a=1,s=e}finally{u=1}}return{value:e,done:f}}}(n,r,i),!0),u}var c={};function a(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(z(e={},o,function(){return this}),e),f=u.prototype=a.prototype=Object.create(l);function d(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,z(t,r,"GeneratorFunction")),t.prototype=Object.create(f),t}return s.prototype=u,z(f,"constructor",u),z(u,"constructor",s),s.displayName="GeneratorFunction",z(u,r,"GeneratorFunction"),z(f),z(f,r,"Generator"),z(f,o,function(){return this}),z(f,"toString",function(){return"[object Generator]"}),(W=function(){return{w:i,m:d}})()}function z(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}z=function(t,e,n,o){function i(e,n){z(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},z(t,e,n,o)}function V(t,e,n,o,r,i,c){try{var a=t[i](c),s=a.value}catch(t){return void n(t)}a.done?e(s):Promise.resolve(s).then(o,r)}function Q(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,q(o.key),o)}}function q(t){var e=function(t){if("object"!=N(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=N(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==N(e)?e:e+""}function $(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return($=function(){return!!t})()}function J(t){return J=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},J(t)}function Y(t,e){return Y=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},Y(t,e)}var X=function(t){function e(t){var n;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(n=function(t,e,n){return e=J(e),function(t,e){if(e&&("object"==N(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,$()?Reflect.construct(e,n||[],J(t).constructor):e.apply(t,n))}(this,e)).config=t,n.audioContext=null,n.audioQueue=[],n.isPlaying=!1,n.isProcessingQueue=!1,n.currentSource=null,n}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&Y(t,e)}(e,t),n=e,o=[{key:"playAudio",value:function(t){var e=this;try{var n=this.createAudioBlob(t);this.audioQueue.push(n),this.isPlaying||this.isProcessingQueue||this.currentSource||setTimeout(function(){return e.processQueue()},50)}catch(t){this.emit("playbackError",t)}}},{key:"createAudioBlob",value:function(t){var e=new Uint8Array(t);if(e.length>=4){if(82===e[0]&&73===e[1]&&70===e[2]&&70===e[3])return new Blob([t],{type:"audio/wav"});if(255===e[0]&&!(224&~e[1]))return new Blob([t],{type:"audio/mpeg"});if(79===e[0]&&103===e[1]&&103===e[2]&&83===e[3])return new Blob([t],{type:"audio/ogg"})}return new Blob([t],{type:"audio/wav"})}},{key:"processQueue",value:(r=W().m(function t(){var e,n,o,r,i,c,a,s,u=this;return W().w(function(t){for(;;)switch(t.p=t.n){case 0:if(!this.isProcessingQueue&&0!==this.audioQueue.length){t.n=1;break}return t.a(2);case 1:if(this.isProcessingQueue=!0,e=this.audioQueue.shift()){t.n=2;break}return this.isProcessingQueue=!1,t.a(2);case 2:if(t.p=2,n=!this.isPlaying&&null===this.currentSource,this.audioContext||(this.audioContext=new(window.AudioContext||window.webkitAudioContext)),"suspended"!==(o=this.audioContext).state){t.n=3;break}return t.n=3,o.resume();case 3:return t.n=4,e.arrayBuffer();case 4:return r=t.v,t.n=5,o.decodeAudioData(r);case 5:i=t.v,c=n&&!this.isPlaying&&null===this.currentSource,(a=o.createBufferSource()).buffer=i,a.connect(o.destination),this.currentSource=a,this.isPlaying=!0,c&&this.emit("playbackStarted"),a.onended=function(){u.currentSource=null,u.isProcessingQueue=!1,u.audioQueue.length>0?setTimeout(function(){return u.processQueue()},50):setTimeout(function(){0!==u.audioQueue.length||u.currentSource||(u.isPlaying=!1,u.emit("playbackStopped"))},100)},a.start(),t.n=7;break;case 6:t.p=6,s=t.v,this.currentSource=null,this.emit("playbackError",s),this.audioQueue.length>0?(this.isProcessingQueue=!1,setTimeout(function(){return u.processQueue()},100)):(this.isPlaying=!1,this.isProcessingQueue=!1,this.emit("playbackStopped"));case 7:return t.a(2)}},t,this,[[2,6]])}),i=function(){var t=this,e=arguments;return new Promise(function(n,o){var i=r.apply(t,e);function c(t){V(i,n,o,c,a,"next",t)}function a(t){V(i,n,o,c,a,"throw",t)}c(void 0)})},function(){return i.apply(this,arguments)})},{key:"stop",value:function(){this.stopImmediate()}},{key:"stopImmediate",value:function(){var t=this.isPlaying||null!==this.currentSource;if(this.currentSource){try{this.currentSource.stop()}catch(t){}this.currentSource=null}this.isPlaying=!1,this.isProcessingQueue=!1,this.audioQueue=[],t&&this.emit("playbackStopped")}},{key:"getStatus",value:function(){return{isPlaying:this.isPlaying,isProcessingQueue:this.isProcessingQueue,queueLength:this.audioQueue.length,audioContextState:this.audioContext?this.audioContext.state:"closed"}}},{key:"destroy",value:function(){this.stop(),this.audioContext&&"closed"!==this.audioContext.state&&(this.audioContext.close(),this.audioContext=null)}}],o&&Q(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i}(a);function Z(t){return Z="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Z(t)}function tt(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof a?o:a,u=Object.create(s.prototype);return et(u,"_invoke",function(n,o,r){var i,a,s,u=0,l=r||[],f=!1,d={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,a=0,s=t,d.n=n,c}};function p(n,o){for(a=n,s=o,e=0;!f&&u&&!r&&e<l.length;e++){var r,i=l[e],p=d.p,h=i[2];n>3?(r=h===o)&&(s=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(a=0,d.v=o,d.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,d.n=h,a=0))}if(r||n>1)return c;throw f=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,h),a=l,s=h;(e=a<2?t:s)||!f;){i||(a?a<3?(a>1&&(d.n=-1),p(a,s)):d.n=s:d.v=s);try{if(u=2,i){if(a||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,a<2&&(a=0)}else 1===a&&(e=i.return)&&e.call(i),a<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),a=1);i=t}else if((e=(f=d.n<0)?s:n.call(o,d))!==c)break}catch(e){i=t,a=1,s=e}finally{u=1}}return{value:e,done:f}}}(n,r,i),!0),u}var c={};function a(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(et(e={},o,function(){return this}),e),f=u.prototype=a.prototype=Object.create(l);function d(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,et(t,r,"GeneratorFunction")),t.prototype=Object.create(f),t}return s.prototype=u,et(f,"constructor",u),et(u,"constructor",s),s.displayName="GeneratorFunction",et(u,r,"GeneratorFunction"),et(f),et(f,r,"Generator"),et(f,o,function(){return this}),et(f,"toString",function(){return"[object Generator]"}),(tt=function(){return{w:i,m:d}})()}function et(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}et=function(t,e,n,o){function i(e,n){et(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},et(t,e,n,o)}function nt(t,e,n,o,r,i,c){try{var a=t[i](c),s=a.value}catch(t){return void n(t)}a.done?e(s):Promise.resolve(s).then(o,r)}function ot(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function c(t){nt(i,o,r,c,a,"next",t)}function a(t){nt(i,o,r,c,a,"throw",t)}c(void 0)})}}function rt(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,o)}return n}function it(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?rt(Object(n),!0).forEach(function(e){ct(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):rt(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function ct(t,e,n){return(e=st(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function at(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,st(o.key),o)}}function st(t){var e=function(t){if("object"!=Z(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=Z(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Z(e)?e:e+""}function ut(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(ut=function(){return!!t})()}function lt(t){return lt=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},lt(t)}function ft(t,e){return ft=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},ft(t,e)}var dt=function(t){function e(){var t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(t=function(t,e,n){return e=lt(e),function(t,e){if(e&&("object"==Z(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,ut()?Reflect.construct(e,n||[],lt(t).constructor):e.apply(t,n))}(this,e)).config=it({websocketUrl:n.websocketUrl||"wss://speech.talktopc.com/ws/conv",agentId:n.agentId,appId:n.appId,ttpId:n.ttpId,voice:n.voice||"default",language:n.language||"en",sampleRate:n.sampleRate||16e3},n),t.isConnected=!1,t.isRecording=!1,t.isPlaying=!1,t.isDestroyed=!1,t.webSocketManager=new D(it(it({},t.config),{},{autoReconnect:!1!==t.config.autoReconnect})),t.audioRecorder=new H(t.config),t.audioPlayer=new X(t.config),t.setupEventHandlers(),t}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&ft(t,e)}(e,t),n=e,o=[{key:"setupEventHandlers",value:function(){var t=this;this.webSocketManager.on("connected",function(){t.isConnected=!0,t.sendHelloMessage(),t.emit("connected")}),this.webSocketManager.on("disconnected",function(e){t.isConnected=!1,t.isRecording&&t.stopRecording().catch(function(t){console.error("VoiceSDK: Error stopping recording on disconnect:",t)}),t.emit("disconnected",e)}),this.webSocketManager.on("error",function(e){t.emit("error",e)}),this.webSocketManager.on("message",function(e){if("greeting_audio"===e.t&&e.data)try{for(var n=atob(e.data),o=new Uint8Array(n.length),r=0;r<n.length;r++)o[r]=n.charCodeAt(r);t.audioPlayer.playAudio(o),t.emit("greetingStarted")}catch(t){console.error("VoiceSDK: Error playing greeting audio:",t)}else t.emit("message",e)}),this.webSocketManager.on("binaryAudio",function(e){t.audioPlayer.playAudio(e)}),this.webSocketManager.on("bargeIn",function(e){t.emit("bargeIn",e)}),this.webSocketManager.on("stopPlaying",function(e){t.emit("stopPlaying",e),t.audioPlayer.stopImmediate()}),this.audioRecorder.on("recordingStarted",function(){t.isRecording=!0,t.isPlaying&&(t.audioPlayer.stopImmediate(),t.isConnected&&t.webSocketManager.sendMessage({t:"barge_in"})),t.emit("recordingStarted")}),this.audioRecorder.on("recordingStopped",function(){t.isRecording=!1,t.emit("recordingStopped")}),this.audioRecorder.on("audioData",function(e){t.isConnected&&t.webSocketManager.sendBinary(e)}),this.audioPlayer.on("playbackStarted",function(){t.isPlaying=!0,t.emit("playbackStarted"),t.isConnected&&t.webSocketManager.sendMessage({t:"audio_started_playing"})}),this.audioPlayer.on("playbackStopped",function(){t.isPlaying=!1,t.emit("playbackStopped"),t.isConnected&&t.webSocketManager.sendMessage({t:"audio_stopped_playing"})}),this.audioPlayer.on("playbackError",function(e){t.emit("playbackError",e)})}},{key:"connect",value:(u=ot(tt().m(function t(){var e,n;return tt().w(function(t){for(;;)switch(t.p=t.n){case 0:if(!this.isDestroyed){t.n=1;break}return console.warn("VoiceSDK: Cannot connect - SDK is destroyed"),t.a(2,!1);case 1:return t.p=1,e=this.buildWebSocketUrl(),this.webSocketManager.config.websocketUrl=e,t.n=2,this.webSocketManager.connect();case 2:return t.a(2,!0);case 3:return t.p=3,n=t.v,console.error("🔌 VoiceSDK: Connection failed with error:",n),this.emit("error",n),t.a(2,!1)}},t,this,[[1,3]])})),function(){return u.apply(this,arguments)})},{key:"buildWebSocketUrl",value:function(){var t=this.config.websocketUrl,e=new URLSearchParams;if(this.config.agentId&&e.append("agentId",this.config.agentId),this.config.appId&&e.append("appId",this.config.appId),this.config.voice&&"default"!==this.config.voice&&e.append("voice",this.config.voice),this.config.language&&"en"!==this.config.language&&e.append("language",this.config.language),e.toString()){var n=t.includes("?")?"&":"?";t+=n+e.toString()}return t}},{key:"disconnect",value:function(){this.isDestroyed||(this.stopRecording(),this.webSocketManager.disconnect())}},{key:"resetReconnectionAttempts",value:function(){this.isDestroyed||this.webSocketManager.resetReconnectionAttempts()}},{key:"reconnect",value:(s=ot(tt().m(function t(){return tt().w(function(t){for(;;)switch(t.n){case 0:if(!this.isDestroyed){t.n=1;break}return t.a(2,!1);case 1:return this.disconnect(),this.resetReconnectionAttempts(),t.n=2,this.connect();case 2:return t.a(2,t.v)}},t,this)})),function(){return s.apply(this,arguments)})},{key:"startRecording",value:(a=ot(tt().m(function t(){var e;return tt().w(function(t){for(;;)switch(t.p=t.n){case 0:if(this.isConnected){t.n=1;break}throw new Error("Not connected to voice server");case 1:return t.p=1,this.webSocketManager.sendMessage({t:"start_continuous_mode",ttpId:this.generateTtpId(),voice:this.config.voice,language:this.config.language}),t.n=2,this.audioRecorder.start();case 2:return t.a(2,!0);case 3:return t.p=3,e=t.v,console.error("❌ VoiceSDK: Failed to start recording:",e),this.emit("error",e),t.a(2,!1)}},t,this,[[1,3]])})),function(){return a.apply(this,arguments)})},{key:"stopRecording",value:(c=ot(tt().m(function t(){var e;return tt().w(function(t){for(;;)switch(t.p=t.n){case 0:if(this.isRecording){t.n=1;break}return t.a(2);case 1:return t.p=1,this.webSocketManager.sendMessage({t:"stop_continuous_mode",ttpId:this.generateTtpId()}),t.n=2,this.audioRecorder.stop();case 2:return this.audioPlayer.stopImmediate(),t.a(2,!0);case 3:return t.p=3,e=t.v,this.emit("error",e),t.a(2,!1)}},t,this,[[1,3]])})),function(){return c.apply(this,arguments)})},{key:"toggleRecording",value:(i=ot(tt().m(function t(){return tt().w(function(t){for(;;)switch(t.n){case 0:if(!this.isRecording){t.n=2;break}return t.n=1,this.stopRecording();case 1:case 3:return t.a(2,t.v);case 2:return t.n=3,this.startRecording();case 4:return t.a(2)}},t,this)})),function(){return i.apply(this,arguments)})},{key:"stopAudioPlayback",value:function(){this.audioPlayer.stopImmediate()}},{key:"handleBargeIn",value:(r=ot(tt().m(function t(){return tt().w(function(t){for(;;)switch(t.n){case 0:if(this.stopAudioPlayback(),this.isRecording){t.n=1;break}return t.n=1,this.startRecording();case 1:return t.a(2)}},t,this)})),function(){return r.apply(this,arguments)})},{key:"getStatus",value:function(){return{isConnected:this.isConnected,isRecording:this.isRecording,isPlaying:this.isPlaying}}},{key:"updateConfig",value:function(t){this.config=it(it({},this.config),t)}},{key:"generateTtpId",value:function(){return"sdk_"+Math.random().toString(36).substr(2,9)+"_"+Date.now()}},{key:"sendHelloMessage",value:function(){if(this.isConnected){var t={t:"hello"};this.config.appId?t.appId=this.config.appId:this.config.ttpId?t.ttpId=this.config.ttpId:t.ttpId=this.generateTtpId();try{this.webSocketManager.sendMessage(t)}catch(t){console.error("VoiceSDK: Failed to send hello message:",t),this.emit("error",t)}}else console.warn("VoiceSDK: Cannot send hello message - not connected")}},{key:"destroy",value:function(){this.isDestroyed||(this.disconnect(),this.isDestroyed=!0,this.audioRecorder.destroy(),this.audioPlayer.destroy(),this.removeAllListeners())}}],o&&at(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i,c,a,s,u}(a),pt=n(540),ht=n(848);function yt(t){return yt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},yt(t)}function gt(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,o)}return n}function vt(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?gt(Object(n),!0).forEach(function(e){bt(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):gt(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function bt(t,e,n){return(e=function(t){var e=function(t){if("object"!=yt(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=yt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==yt(e)?e:e+""}(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function mt(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof a?o:a,u=Object.create(s.prototype);return St(u,"_invoke",function(n,o,r){var i,a,s,u=0,l=r||[],f=!1,d={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,a=0,s=t,d.n=n,c}};function p(n,o){for(a=n,s=o,e=0;!f&&u&&!r&&e<l.length;e++){var r,i=l[e],p=d.p,h=i[2];n>3?(r=h===o)&&(s=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(a=0,d.v=o,d.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,d.n=h,a=0))}if(r||n>1)return c;throw f=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,h),a=l,s=h;(e=a<2?t:s)||!f;){i||(a?a<3?(a>1&&(d.n=-1),p(a,s)):d.n=s:d.v=s);try{if(u=2,i){if(a||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,a<2&&(a=0)}else 1===a&&(e=i.return)&&e.call(i),a<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),a=1);i=t}else if((e=(f=d.n<0)?s:n.call(o,d))!==c)break}catch(e){i=t,a=1,s=e}finally{u=1}}return{value:e,done:f}}}(n,r,i),!0),u}var c={};function a(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(St(e={},o,function(){return this}),e),f=u.prototype=a.prototype=Object.create(l);function d(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,St(t,r,"GeneratorFunction")),t.prototype=Object.create(f),t}return s.prototype=u,St(f,"constructor",u),St(u,"constructor",s),s.displayName="GeneratorFunction",St(u,r,"GeneratorFunction"),St(f),St(f,r,"Generator"),St(f,o,function(){return this}),St(f,"toString",function(){return"[object Generator]"}),(mt=function(){return{w:i,m:d}})()}function St(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}St=function(t,e,n,o){function i(e,n){St(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},St(t,e,n,o)}function wt(t,e,n,o,r,i,c){try{var a=t[i](c),s=a.value}catch(t){return void n(t)}a.done?e(s):Promise.resolve(s).then(o,r)}function kt(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=n){var o,r,i,c,a=[],s=!0,u=!1;try{if(i=(n=n.call(t)).next,0===e){if(Object(n)!==n)return;s=!1}else for(;!(s=(o=i.call(n)).done)&&(a.push(o.value),a.length!==e);s=!0);}catch(t){u=!0,r=t}finally{try{if(!s&&null!=n.return&&(c=n.return(),Object(c)!==c))return}finally{if(u)throw r}}return a}}(t,e)||function(t,e){if(t){if("string"==typeof t)return Ot(t,e);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Ot(t,e):void 0}}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function Ot(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,o=Array(e);n<e;n++)o[n]=t[n];return o}const jt=function(t){var e=t.websocketUrl,n=t.agentId,o=t.voice,r=void 0===o?"default":o,i=t.language,c=void 0===i?"en":i,a=t.autoReconnect,s=void 0===a||a,u=t.onConnected,l=t.onDisconnected,f=t.onRecordingStarted,d=t.onRecordingStopped,p=t.onPlaybackStarted,h=t.onPlaybackStopped,y=t.onError,g=t.onMessage,v=t.onBargeIn,b=t.onStopPlaying,m=t.className,S=void 0===m?"":m,w=t.style,k=void 0===w?{}:w,O=t.children,j=kt((0,pt.useState)(!1),2),P=j[0],C=j[1],x=kt((0,pt.useState)(!1),2),E=x[0],T=x[1],R=kt((0,pt.useState)(!1),2),D=(R[0],R[1]),_=kt((0,pt.useState)("Disconnected"),2),I=(_[0],_[1]),B=(0,pt.useRef)(null);(0,pt.useEffect)(function(){console.log("🎙️ VoiceButton: Creating VoiceSDK instance for ".concat(e)),B.current&&(console.log("🎙️ VoiceButton: Destroying existing VoiceSDK instance"),B.current.destroy(),B.current=null);var t=new dt({websocketUrl:e,agentId:n,voice:r,language:c,autoReconnect:s});return t.on("connected",function(){C(!0),I("Connected"),null==u||u()}),t.on("disconnected",function(){C(!1),I("Disconnected"),null==l||l()}),t.on("recordingStarted",function(){T(!0),null==f||f()}),t.on("recordingStopped",function(){T(!1),null==d||d()}),t.on("playbackStarted",function(){D(!0),null==p||p()}),t.on("playbackStopped",function(){D(!1),null==h||h()}),t.on("error",function(t){null==y||y(t)}),t.on("message",function(t){null==g||g(t)}),t.on("bargeIn",function(t){null==v||v(t)}),t.on("stopPlaying",function(t){null==b||b(t)}),B.current=t,t.connect(),function(){console.log("🎙️ VoiceButton: Cleaning up VoiceSDK instance for ".concat(e)),B.current&&(B.current.destroy(),B.current=null)}},[e,n,r,c]);var M=function(){var t,e=(t=mt().m(function t(){var e;return mt().w(function(t){for(;;)switch(t.p=t.n){case 0:if(B.current){t.n=1;break}return t.a(2);case 1:return t.p=1,t.n=2,B.current.toggleRecording();case 2:t.n=4;break;case 3:t.p=3,e=t.v,console.error("Error toggling recording:",e);case 4:return t.a(2)}},t,null,[[1,3]])}),function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function c(t){wt(i,o,r,c,a,"next",t)}function a(t){wt(i,o,r,c,a,"throw",t)}c(void 0)})});return function(){return e.apply(this,arguments)}}(),A=(0,ht.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[(0,ht.jsx)("div",{style:{fontSize:"20px"},children:E?"🔴":"🎤"}),(0,ht.jsx)("div",{children:E?"Stop Listening":"Start Listening"})]});return(0,ht.jsx)("button",{className:"voice-button ".concat(E?"recording":""," ").concat(S),style:vt({padding:"12px 24px",border:"none",borderRadius:"8px",backgroundColor:E?"#dc3545":"#007bff",color:"white",cursor:"pointer",fontSize:"16px",fontWeight:"500",transition:"all 0.2s ease"},k),onClick:M,disabled:!P,children:O||A})};function Pt(t){return Pt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Pt(t)}function Ct(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof a?o:a,u=Object.create(s.prototype);return xt(u,"_invoke",function(n,o,r){var i,a,s,u=0,l=r||[],f=!1,d={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,a=0,s=t,d.n=n,c}};function p(n,o){for(a=n,s=o,e=0;!f&&u&&!r&&e<l.length;e++){var r,i=l[e],p=d.p,h=i[2];n>3?(r=h===o)&&(s=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(a=0,d.v=o,d.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,d.n=h,a=0))}if(r||n>1)return c;throw f=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,h),a=l,s=h;(e=a<2?t:s)||!f;){i||(a?a<3?(a>1&&(d.n=-1),p(a,s)):d.n=s:d.v=s);try{if(u=2,i){if(a||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,a<2&&(a=0)}else 1===a&&(e=i.return)&&e.call(i),a<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),a=1);i=t}else if((e=(f=d.n<0)?s:n.call(o,d))!==c)break}catch(e){i=t,a=1,s=e}finally{u=1}}return{value:e,done:f}}}(n,r,i),!0),u}var c={};function a(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(xt(e={},o,function(){return this}),e),f=u.prototype=a.prototype=Object.create(l);function d(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,xt(t,r,"GeneratorFunction")),t.prototype=Object.create(f),t}return s.prototype=u,xt(f,"constructor",u),xt(u,"constructor",s),s.displayName="GeneratorFunction",xt(u,r,"GeneratorFunction"),xt(f),xt(f,r,"Generator"),xt(f,o,function(){return this}),xt(f,"toString",function(){return"[object Generator]"}),(Ct=function(){return{w:i,m:d}})()}function xt(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}xt=function(t,e,n,o){function i(e,n){xt(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},xt(t,e,n,o)}function Et(t,e,n,o,r,i,c){try{var a=t[i](c),s=a.value}catch(t){return void n(t)}a.done?e(s):Promise.resolve(s).then(o,r)}function Tt(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function c(t){Et(i,o,r,c,a,"next",t)}function a(t){Et(i,o,r,c,a,"throw",t)}c(void 0)})}}function Rt(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,o)}return n}function Dt(t,e,n){return(e=It(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function _t(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,It(o.key),o)}}function It(t){var e=function(t){if("object"!=Pt(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=Pt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Pt(e)?e:e+""}var Bt=function(){return t=function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.options=function(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?Rt(Object(n),!0).forEach(function(e){Dt(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Rt(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}({websocketUrl:e.websocketUrl||"wss://speech.talktopc.com/ws/conv",agentId:e.agentId,voice:e.voice||"default",language:e.language||"en",container:e.container||document.body,buttonText:e.buttonText||"Start Listening",buttonClass:e.buttonClass||"voice-button"},e),this.isConnected=!1,this.isRecording=!1,this.isPlaying=!1,this.voiceSDK=new dt({websocketUrl:this.options.websocketUrl,agentId:this.options.agentId,voice:this.options.voice,language:this.options.language}),this.setupEventListeners(),this.createButton(),this.connect()},e=[{key:"setupEventListeners",value:function(){var t=this;this.voiceSDK.on("connected",function(){var e,n;t.isConnected=!0,t.updateButton(),null===(e=(n=t.options).onConnected)||void 0===e||e.call(n)}),this.voiceSDK.on("disconnected",function(){var e,n;t.isConnected=!1,t.updateButton(),null===(e=(n=t.options).onDisconnected)||void 0===e||e.call(n)}),this.voiceSDK.on("recordingStarted",function(){var e,n;t.isRecording=!0,t.updateButton(),null===(e=(n=t.options).onRecordingStarted)||void 0===e||e.call(n)}),this.voiceSDK.on("recordingStopped",function(){var e,n;t.isRecording=!1,t.updateButton(),null===(e=(n=t.options).onRecordingStopped)||void 0===e||e.call(n)}),this.voiceSDK.on("playbackStarted",function(){var e,n;t.isPlaying=!0,null===(e=(n=t.options).onPlaybackStarted)||void 0===e||e.call(n)}),this.voiceSDK.on("playbackStopped",function(){var e,n;t.isPlaying=!1,null===(e=(n=t.options).onPlaybackStopped)||void 0===e||e.call(n)}),this.voiceSDK.on("error",function(e){var n,o;null===(n=(o=t.options).onError)||void 0===n||n.call(o,e)}),this.voiceSDK.on("message",function(e){var n,o;null===(n=(o=t.options).onMessage)||void 0===n||n.call(o,e)}),this.voiceSDK.on("bargeIn",function(e){var n,o;null===(n=(o=t.options).onBargeIn)||void 0===n||n.call(o,e)}),this.voiceSDK.on("stopPlaying",function(e){var n,o;null===(n=(o=t.options).onStopPlaying)||void 0===n||n.call(o,e)})}},{key:"createButton",value:function(){var t=this;this.button=document.createElement("button"),this.button.className=this.options.buttonClass,this.button.style.cssText="\n padding: 12px 24px;\n border: none;\n border-radius: 8px;\n background-color: #6c757d;\n color: white;\n cursor: pointer;\n font-size: 16px;\n font-weight: 500;\n transition: all 0.2s ease;\n display: flex;\n align-items: center;\n gap: 8px;\n ",this.button.addEventListener("click",function(){return t.toggleRecording()}),this.options.container.appendChild(this.button),this.updateButton()}},{key:"updateButton",value:function(){if(this.button){var t=this.isRecording?"🔴":"🎤",e=this.isRecording?"Stop Listening":"Start Listening";this.button.innerHTML='\n <span style="font-size: 20px;">'.concat(t,"</span>\n <span>").concat(e,"</span>\n "),this.button.disabled=!this.isConnected,this.button.style.backgroundColor=this.isRecording?"#dc3545":this.isConnected?"#007bff":"#6c757d"}}},{key:"connect",value:(o=Tt(Ct().m(function t(){var e;return Ct().w(function(t){for(;;)switch(t.p=t.n){case 0:return t.p=0,t.n=1,this.voiceSDK.connect();case 1:t.n=3;break;case 2:t.p=2,e=t.v,console.error("Failed to connect:",e);case 3:return t.a(2)}},t,this,[[0,2]])})),function(){return o.apply(this,arguments)})},{key:"toggleRecording",value:(n=Tt(Ct().m(function t(){var e;return Ct().w(function(t){for(;;)switch(t.p=t.n){case 0:if(this.voiceSDK){t.n=1;break}return t.a(2);case 1:return t.p=1,t.n=2,this.voiceSDK.toggleRecording();case 2:t.n=4;break;case 3:t.p=3,e=t.v,console.error("Error toggling recording:",e);case 4:return t.a(2)}},t,this,[[1,3]])})),function(){return n.apply(this,arguments)})},{key:"getStatus",value:function(){return{isConnected:this.isConnected,isRecording:this.isRecording,isPlaying:this.isPlaying}}},{key:"updateConfig",value:function(t){this.voiceSDK.updateConfig(t)}},{key:"destroy",value:function(){this.button&&this.button.parentNode&&this.button.parentNode.removeChild(this.button),this.voiceSDK&&this.voiceSDK.destroy()}}],e&&_t(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n,o}();function Mt(t){return Mt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Mt(t)}function At(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,o)}return n}function Kt(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?At(Object(n),!0).forEach(function(e){Ft(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):At(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function Ft(t,e,n){return(e=Vt(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function Ut(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function i(n,o,r,i){var s=o&&o.prototype instanceof a?o:a,u=Object.create(s.prototype);return Gt(u,"_invoke",function(n,o,r){var i,a,s,u=0,l=r||[],f=!1,d={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,n){return i=e,a=0,s=t,d.n=n,c}};function p(n,o){for(a=n,s=o,e=0;!f&&u&&!r&&e<l.length;e++){var r,i=l[e],p=d.p,h=i[2];n>3?(r=h===o)&&(s=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=t):i[0]<=p&&((r=n<2&&p<i[1])?(a=0,d.v=o,d.n=i[1]):p<h&&(r=n<3||i[0]>o||o>h)&&(i[4]=n,i[5]=o,d.n=h,a=0))}if(r||n>1)return c;throw f=!0,o}return function(r,l,h){if(u>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,h),a=l,s=h;(e=a<2?t:s)||!f;){i||(a?a<3?(a>1&&(d.n=-1),p(a,s)):d.n=s:d.v=s);try{if(u=2,i){if(a||(r="next"),e=i[r]){if(!(e=e.call(i,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,a<2&&(a=0)}else 1===a&&(e=i.return)&&e.call(i),a<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),a=1);i=t}else if((e=(f=d.n<0)?s:n.call(o,d))!==c)break}catch(e){i=t,a=1,s=e}finally{u=1}}return{value:e,done:f}}}(n,r,i),!0),u}var c={};function a(){}function s(){}function u(){}e=Object.getPrototypeOf;var l=[][o]?e(e([][o]())):(Gt(e={},o,function(){return this}),e),f=u.prototype=a.prototype=Object.create(l);function d(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,Gt(t,r,"GeneratorFunction")),t.prototype=Object.create(f),t}return s.prototype=u,Gt(f,"constructor",u),Gt(u,"constructor",s),s.displayName="GeneratorFunction",Gt(u,r,"GeneratorFunction"),Gt(f),Gt(f,r,"Generator"),Gt(f,o,function(){return this}),Gt(f,"toString",function(){return"[object Generator]"}),(Ut=function(){return{w:i,m:d}})()}function Gt(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}Gt=function(t,e,n,o){function i(e,n){Gt(t,e,function(t){return this._invoke(e,n,t)})}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},Gt(t,e,n,o)}function Lt(t,e,n,o,r,i,c){try{var a=t[i](c),s=a.value}catch(t){return void n(t)}a.done?e(s):Promise.resolve(s).then(o,r)}function Ht(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function c(t){Lt(i,o,r,c,a,"next",t)}function a(t){Lt(i,o,r,c,a,"throw",t)}c(void 0)})}}function Nt(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function Wt(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,Vt(o.key),o)}}function zt(t,e,n){return e&&Wt(t.prototype,e),n&&Wt(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function Vt(t){var e=function(t){if("object"!=Mt(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=Mt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==Mt(e)?e:e+""}var Qt=function(){return zt(function t(e){Nt(this,t),console.log("🚀 AgentSDK v2.1.8 initialized with config:",e),this.config=e,this.voiceSDK=null,this.isConnected=!1,this.isListening=!1,this.onConnected=function(){},this.onDisconnected=function(){},this.onError=function(t){return console.error("SDK Error:",t)},this.onTranscript=function(t){},this.onAgentSpeaking=function(t){}},[{key:"connect",value:(e=Ht(Ut().m(function t(e){var n,o=this;return Ut().w(function(t){for(;;)switch(t.p=t.n){case 0:if(t.p=0,e){t.n=1;break}throw new Error("signedUrl is required");case 1:return this.voiceSDK&&(console.log("🔌 AgentSDK: Cleaning up existing connection"),this.voiceSDK.destroy(),this.voiceSDK=null),this.voiceSDK=new dt({websocketUrl:e,autoReconnect:!1,agentId:this.config.agentId,appId:this.config.appId,language:this.config.language||"en"}),this.voiceSDK.on("connected",function(){o.isConnected=!0,o.onConnected()}),this.voiceSDK.on("disconnected",function(){o.isConnected=!1,o.onDisconnected()}),this.voiceSDK.on("error",function(t){o.onError(t)}),this.voiceSDK.on("message",function(t){o.handleWebSocketMessage(t)}),this.voiceSDK.on("recordingStarted",function(){o.isListening=!0}),this.voiceSDK.on("recordingStopped",function(){o.isListening=!1}),this.voiceSDK.on("playbackStarted",function(){o.onAgentSpeaking(!0)}),this.voiceSDK.on("playbackStopped",function(){o.onAgentSpeaking(!1)}),t.n=2,this.voiceSDK.connect();case 2:t.n=4;break;case 3:throw t.p=3,n=t.v,this.onError(n),n;case 4:return t.a(2)}},t,this,[[0,3]])})),function(t){return e.apply(this,arguments)})},{key:"handleWebSocketMessage",value:function(t){switch(t.type){case"connected":console.log("Session started successfully");break;case"user_transcript":this.onTranscript(t.user_transcription||t.text);break;case"agent_response":case"barge_in":case"stop_playing":break;case"error":this.onError(new Error(t.message))}}},{key:"startListening",value:(t=Ht(Ut().m(function t(){var e;return Ut().w(function(t){for(;;)switch(t.p=t.n){case 0:if(console.log("🎤 AgentSDK: startListening() called"),!this.voiceSDK){t.n=5;break}return t.p=1,console.log("🎤 AgentSDK: Starting recording..."),t.n=2,this.voiceSDK.startRecording();case 2:console.log("✅ AgentSDK: Recording started successfully"),t.n=4;break;case 3:throw t.p=3,e=t.v,console.error("❌ AgentSDK: Failed to start recording:",e),e;case 4:t.n=6;break;case 5:throw console.error("❌ AgentSDK: No voiceSDK instance available"),new Error("No voiceSDK instance available");case 6:return t.a(2)}},t,this,[[1,3]])})),function(){return t.apply(this,arguments)})},{key:"stopListening",value:function(){this.voiceSDK&&this.voiceSDK.stopRecording()}},{key:"updateVariables",value:function(t){this.voiceSDK&&this.isConnected&&this.voiceSDK.webSocketManager.sendMessage({t:"update_variables",variables:t})}},{key:"disconnect",value:function(){this.voiceSDK&&(this.voiceSDK.destroy(),this.voiceSDK=null),this.isConnected=!1,this.isListening=!1}}]);var t,e}(),qt=function(){return zt(function t(){var e=this,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};Nt(this,t),this.config=this.mergeWithDefaults(n),this.sdk=new Qt(this.config),this.isOpen=!1,this.isActive=!1,this.setupEventHandlers(),this.createWidget(),this.config.behavior.autoOpen&&setTimeout(function(){return e.togglePanel()},1e3)},[{key:"mergeWithDefaults",value:function(t){var e,n,o,r,i,c,a,s,u,l,f,d,p,h,y,g,v,b,m,S,w,k,O,j,P,C,x,E,T,R,D,_,I,B,M,A,K,F,U,G,L,H,N,W,z,V,Q,q,$,J,Y,X,Z=t.position||"bottom-right";if("string"==typeof Z){var tt=Z.split("-");Z={vertical:tt[0]||"bottom",horizontal:tt[1]||"right",offset:t.positionOffset||{x:20,y:20}}}var et=t.primaryColor||(null===(e=t.button)||void 0===e?void 0:e.primaryColor)||"#4F46E5";return Kt({agentId:t.agentId,appId:t.appId,getSessionUrl:t.getSessionUrl,websocketUrl:t.websocketUrl,demo:!1!==t.demo,direction:t.direction||"ltr",icon:Kt({type:(null===(n=t.icon)||void 0===n?void 0:n.type)||"microphone",customImage:(null===(o=t.icon)||void 0===o?void 0:o.customImage)||null,emoji:(null===(r=t.icon)||void 0===r?void 0:r.emoji)||"🎤",text:(null===(i=t.icon)||void 0===i?void 0:i.text)||"AI",size:(null===(c=t.icon)||void 0===c?void 0:c.size)||"medium",backgroundColor:(null===(a=t.icon)||void 0===a?void 0:a.backgroundColor)||null},t.icon),position:Kt({vertical:Z.vertical||"bottom",horizontal:Z.horizontal||"right",offset:Z.offset||{x:20,y:20}},"object"===Mt(t.position)?t.position:{}),button:Kt({size:(null===(s=t.button)||void 0===s?void 0:s.size)||"medium",shape:(null===(u=t.button)||void 0===u?void 0:u.shape)||"circle",backgroundColor:(null===(l=t.button)||void 0===l?void 0:l.backgroundColor)||(null===(f=t.icon)||void 0===f?void 0:f.backgroundColor)||et,hoverColor:(null===(d=t.button)||void 0===d?void 0:d.hoverColor)||"#7C3AED",shadow:!1!==(null===(p=t.button)||void 0===p?void 0:p.shadow),shadowColor:(null===(h=t.button)||void 0===h?void 0:h.shadowColor)||"rgba(0,0,0,0.15)",primaryColor:(null===(y=t.button)||void 0===y?void 0:y.backgroundColor)||(null===(g=t.icon)||void 0===g?void 0:g.backgroundColor)||et},t.button),panel:Kt({width:(null===(v=t.panel)||void 0===v?void 0:v.width)||350,height:(null===(b=t.panel)||void 0===b?void 0:b.height)||500,borderRadius:(null===(m=t.panel)||void 0===m?void 0:m.borderRadius)||12,backgroundColor:(null===(S=t.panel)||void 0===S?void 0:S.backgroundColor)||"#FFFFFF",backdropFilter:(null===(w=t.panel)||void 0===w?void 0:w.backdropFilter)||null,border:(null===(k=t.panel)||void 0===k?void 0:k.border)||"1px solid rgba(0,0,0,0.1)",micButtonColor:(null===(O=t.panel)||void 0===O?void 0:O.micButtonColor)||et,micButtonActiveColor:(null===(j=t.panel)||void 0===j?void 0:j.micButtonActiveColor)||"#EF4444",micButtonHint:Kt({text:(null===(P=t.panel)||void 0===P||null===(P=P.micButtonHint)||void 0===P?void 0:P.text)||"Click the button to start voice conversation",color:(null===(C=t.panel)||void 0===C||null===(C=C.micButtonHint)||void 0===C?void 0:C.color)||"#6B7280",fontSize:(null===(x=t.panel)||void 0===x||null===(x=x.micButtonHint)||void 0===x?void 0:x.fontSize)||"12px"},null===(E=t.panel)||void 0===E?void 0:E.micButtonHint)},t.panel),header:Kt({title:(null===(T=t.header)||void 0===T?void 0:T.title)||"Voice Assistant",showTitle:!1!==(null===(R=t.header)||void 0===R?void 0:R.showTitle),backgroundColor:(null===(D=t.header)||void 0===D?void 0:D.backgroundColor)||(null===(_=t.button)||void 0===_?void 0:_.backgroundColor)||et,textColor:(null===(I=t.header)||void 0===I?void 0:I.textColor)||"#FFFFFF",showCloseButton:!1!==(null===(B=t.header)||void 0===B?void 0:B.showCloseButton)},t.header),messages:Kt({userBackgroundColor:(null===(M=t.messages)||void 0===M?void 0:M.userBackgroundColor)||"#E5E7EB",agentBackgroundColor:(null===(A=t.messages)||void 0===A?void 0:A.agentBackgroundColor)||"#F3F4F6",systemBackgroundColor:(null===(K=t.messages)||void 0===K?void 0:K.systemBackgroundColor)||"#DCFCE7",errorBackgroundColor:(null===(F=t.messages)||void 0===F?void 0:F.errorBackgroundColor)||"#FEE2E2",textColor:(null===(U=t.messages)||void 0===U?void 0:U.textColor)||"#1F2937",fontSize:(null===(G=t.messages)||void 0===G?void 0:G.fontSize)||"14px",borderRadius:(null===(L=t.messages)||void 0===L?void 0:L.borderRadius)||8},t.messages),animation:Kt({enableHover:!1!==(null===(H=t.animation)||void 0===H?void 0:H.enableHover),enablePulse:!1!==(null===(N=t.animation)||void 0===N?void 0:N.enablePulse),enableSlide:!1!==(null===(W=t.animation)||void 0===W?void 0:W.enableSlide),duration:(null===(z=t.animation)||void 0===z?void 0:z.duration)||.3},t.animation),behavior:Kt({autoOpen:(null===(V=t.behavior)||void 0===V?void 0:V.autoOpen)||!1,autoConnect:(null===(Q=t.behavior)||void 0===Q?void 0:Q.autoConnect)||!1,showWelcomeMessage:!1!==(null===(q=t.behavior)||void 0===q?void 0:q.showWelcomeMessage),welcomeMessage:(null===($=t.behavior)||void 0===$?void 0:$.welcomeMessage)||"Hello! How can I help you today?"},t.behavior),accessibility:Kt({ariaLabel:(null===(J=t.accessibility)||void 0===J?void 0:J.ariaLabel)||"Voice Assistant",ariaDescription:(null===(Y=t.accessibility)||void 0===Y?void 0:Y.ariaDescription)||"Click to open voice assistant",keyboardNavigation:!1!==(null===(X=t.accessibility)||void 0===X?void 0:X.keyboardNavigation)},t.accessibility),customStyles:t.customStyles||"",variables:t.variables||{},primaryColor:et},"string"==typeof t.position?{positionString:t.position}:{})}},{key:"setupEventHandlers",value:function(){var t=this;this.sdk.onConnected=function(){t.updateStatus("connected"),t.config.behavior.showWelcomeMessage&&t.addMessage("system",t.config.behavior.welcomeMessage)},this.sdk.onDisconnected=function(){t.updateStatus("disconnected"),t.isActive=!1,t.updateMicButtonState(!1),t.showError("Conversation ended. Click to start a new conversation.")},this.sdk.onError=function(e){t.showError(e.message)},this.sdk.onTranscript=function(e){t.addMessage("user",e)},this.sdk.onAgentSpeaking=function(e){e?t.showAgentThinking():t.hideAgentThinking()}}},{key:"createWidget",value:function(){var t=this,e=document.createElement("div");e.id="agent-widget",e.innerHTML=this.generateWidgetHTML(),document.body.appendChild(e),this.setupWidgetEvents(),this.config.behavior.autoOpen&&setTimeout(function(){return t.togglePanel()},1e3)}},{key:"generateWidgetHTML",value:function(){this.config.position;var t=this.config.button,e=this.config.icon,n=this.config.panel,o=this.config.header,r=(this.config.animation,{small:50,medium:60,large:70,xl:80}[t.size]||60),i={small:20,medium:28,large:36,xl:44}[e.size]||28,c=this.generatePositionStyles(),a=this.generateIconHTML(i);return"\n <style>\n ".concat(this.generateCSS(c,r,i),"\n ").concat(this.config.customStyles,'\n </style>\n \n <button id="agent-button" \n aria-label="').concat(this.config.accessibility.ariaLabel,'"\n aria-description="').concat(this.config.accessibility.ariaDescription,'">\n ').concat(a,'\n </button>\n \n <div id="agent-panel">\n ').concat(o.showTitle?'\n <div id="agent-header" style="direction: '.concat(this.config.direction,';">\n ').concat("rtl"===this.config.direction?"\n ".concat(o.showCloseButton?'<button id="agent-close">×</button>':"",'\n <h3 style="margin: 0; color: ').concat(o.textColor,';">').concat(o.title,"</h3>\n "):'\n <h3 style="margin: 0; color: '.concat(o.textColor,';">').concat(o.title,"</h3>\n ").concat(o.showCloseButton?'<button id="agent-close">×</button>':"","\n "),"\n </div>\n "):"",'\n \n <div id="agent-messages"></div>\n \n <div id="agent-controls">\n <div style="display: flex; flex-direction: column; align-items: center; gap: 8px;">\n <button id="agent-mic-button" \n aria-label="Start/Stop Voice Recording">\n ').concat(a,"\n </button>\n ").concat(n.micButtonHint.text&&n.micButtonHint.text.trim()?'\n <div id="agent-mic-hint" style="color: '.concat(n.micButtonHint.color,"; font-size: ").concat(n.micButtonHint.fontSize,'; text-align: center; max-width: 200px;">\n ').concat(n.micButtonHint.text,"\n </div>\n "):"","\n </div>\n </div>\n </div>\n ")}},{key:"generatePositionStyles",value:function(){var t=this.config.position,e=t.offset||{x:20,y:20},n="";return"top"===t.vertical?n+="top: ".concat(e.y,"px;"):"bottom"===t.vertical?n+="bottom: ".concat(e.y,"px;"):"center"===t.vertical&&(n+="top: 50%; transform: translateY(-50%);"),"left"===t.horizontal?n+="left: ".concat(e.x,"px;"):"right"===t.horizontal?n+="right: ".concat(e.x,"px;"):"center"===t.horizontal&&(n+="left: 50%; transform: translateX(-50%);"),n}},{key:"generateIconHTML",value:function(t){var e=this.config.icon;switch(e.type){case"custom":return'<img src="'.concat(e.customImage,'" alt="Voice Assistant" style="width: ').concat(t,"px; height: ").concat(t,'px; object-fit: contain;" />');case"emoji":return'<span style="font-size: '.concat(t,'px; line-height: 1;">').concat(e.emoji,"</span>");case"text":return'<span style="font-size: '.concat(Math.floor(.6*t),'px; font-weight: bold; color: white;">').concat(e.text,"</span>");default:return'<svg viewBox="0 0 24 24" style="width: '.concat(t,"px; height: ").concat(t,'px; fill: white;">\n <path d="M12 14c1.66 0 3-1.34 3-3V5c0-1.66-1.34-3-3-3S9 3.34 9 5v6c0 1.66 1.34 3 3 3z"/>\n <path d="M17 11c0 2.76-2.24 5-5 5s-5-2.24-5-5H5c0 3.53 2.61 6.43 6 6.92V21h2v-3.08c3.39-.49 6-3.39 6-6.92h-2z"/>\n </svg>')}}},{key:"generateCSS",value:function(t,e,n){var o=this.config.button,r=this.config.panel,i=this.config.header,c=this.config.messages,a=this.config.animation,s=o.backgroundColor||o.primaryColor,u=i.backgroundColor,l=r.micButtonColor||o.primaryColor,f=r.micButtonActiveColor||"#EF4444";return"\n #agent-widget {\n position: fixed;\n ".concat(t,'\n z-index: 10000;\n font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;\n }\n \n #agent-button {\n width: ').concat(e,"px;\n height: ").concat(e,"px;\n border-radius: ").concat("circle"===o.shape?"50%":"square"===o.shape?"0":"12px",";\n background: ").concat(s,";\n border: none;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n transition: all ").concat(a.duration,"s ease;\n ").concat(o.shadow?"box-shadow: 0 4px 12px ".concat(o.shadowColor,";"):"","\n }\n \n ").concat(a.enableHover?"\n #agent-button:hover {\n background: ".concat(o.hoverColor,";\n transform: scale(1.05);\n ").concat(o.shadow?"box-shadow: 0 8px 20px ".concat(o.shadowColor,";"):"","\n }\n "):"","\n \n #agent-panel {\n display: none;\n position: absolute;\n bottom: ").concat(e+20,"px;\n ").concat("right"===this.config.position.horizontal?"right: 0;":"left: 0;","\n width: ").concat(r.width,"px;\n height: ").concat(r.height,"px;\n background: ").concat(r.backgroundColor,";\n border-radius: ").concat(r.borderRadius,"px;\n border: ").concat(r.border,";\n flex-direction: column;\n overflow: hidden;\n ").concat(r.backdropFilter?"backdrop-filter: ".concat(r.backdropFilter,";"):"","\n ").concat(a.enableSlide?"transition: all ".concat(a.duration,"s ease;"):"","\n }\n \n #agent-panel.open {\n display: flex;\n ").concat(a.enableSlide?"transform: translateY(0); opacity: 1;":"","\n }\n \n #agent-header {\n background: ").concat(u,";\n color: ").concat(i.textColor,";\n padding: 16px;\n display: flex;\n flex-direction: ").concat("rtl"===this.config.direction?"row-reverse":"row",";\n justify-content: space-between;\n align-items: center;\n border-radius: ").concat(r.borderRadius,"px ").concat(r.borderRadius,"px 0 0;\n direction: ").concat(this.config.direction,";\n }\n \n #agent-header h3 {\n margin: 0;\n flex: 1;\n text-align: ").concat("rtl"===this.config.direction?"right":"left",";\n }\n \n #agent-close {\n background: none;\n border: none;\n color: ").concat(i.textColor,";\n cursor: pointer;\n font-size: 24px;\n padding: 0;\n width: 24px;\n height: 24px;\n display: flex;\n align-items: center;\n justify-content: center;\n flex-shrink: 0;\n }\n \n #agent-messages {\n flex: 1;\n overflow-y: auto;\n padding: 16px;\n display: flex;\n flex-direction: column;\n gap: 12px;\n }\n \n .message {\n padding: 12px;\n border-radius: ").concat(c.borderRadius,"px;\n max-width: 80%;\n font-size: ").concat(c.fontSize,";\n color: ").concat(c.textColor,";\n }\n \n .message.user {\n background: ").concat(c.userBackgroundColor,";\n align-self: flex-end;\n }\n \n .message.agent {\n background: ").concat(c.agentBackgroundColor,";\n align-self: flex-start;\n }\n \n .message.system {\n background: ").concat(c.systemBackgroundColor,";\n align-self: flex-start;\n font-style: italic;\n }\n \n .error-message {\n background: ").concat(c.errorBackgroundColor,";\n color: #991B1B;\n padding: 12px;\n border-radius: ").concat(c.borderRadius,"px;\n margin: 8px;\n }\n \n #agent-controls {\n padding: 16px;\n border-top: 1px solid #E5E7EB;\n display: flex;\n justify-content: center;\n align-items: center;\n }\n \n #agent-controls > div {\n display: flex;\n flex-direction: column;\n align-items: center;\n gap: 8px;\n }\n \n #agent-mic-hint {\n text-align: center;\n line-height: 1.4;\n }\n \n #agent-mic-button {\n width: ").concat(e,"px;\n height: ").concat(e,"px;\n border-radius: ").concat("circle"===o.shape?"50%":"square"===o.shape?"0":"12px",";\n border: none;\n background: ").concat(l,";\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n transition: all ").concat(a.duration,"s ease;\n }\n \n #agent-mic-button.active {\n background: ").concat(f,";\n ").concat(a.enablePulse?"\n animation: pulse 1.5s infinite;\n ":"","\n }\n \n ").concat(a.enablePulse?"\n @keyframes pulse {\n 0%, 100% { transform: scale(1); }\n 50% { transform: scale(1.05); }\n }\n ":"","\n \n .agent-thinking {\n font-style: italic;\n color: #6B7280;\n }\n ")}},{key:"setupWidgetEvents",value:function(){var t=this;document.getElementById("agent-button").onclick=function(){return t.togglePanel()};var e=document.getElementById("agent-close");e&&(e.onclick=function(){return t.togglePanel()}),document.getElementById("agent-mic-button").onclick=function(){return t.toggleVoice()},this.config.accessibility.keyboardNavigation&&this.setupKeyboardNavigation()}},{key:"setupKeyboardNavigation",value:function(){var t=this;document.addEventListener("keydown",function(e){"Escape"===e.key&&t.isOpen&&t.togglePanel()})}},{key:"togglePanel",value:function(){this.isOpen=!this.isOpen,document.getElementById("agent-panel").classList.toggle("open")}},{key:"toggleVoice",value:(e=Ht(Ut().m(function t(){var e,n,o,r;return Ut().w(function(t){for(;;)switch(t.p=t.n){case 0:if(this.isActive){t.n=13;break}return t.p=1,console.log("🎤 Starting voice session..."),t.n=2,this.getSignedUrl();case 2:return e=t.v,console.log("🔗 Got signed URL:",e),t.n=3,this.sdk.connect(e);case 3:n=t.v,console.log("✅ Connected to WebSocket, connected:",n),o=0;case 4:if(this.sdk.isConnected||!(o<50)){t.n=6;break}return t.n=5,new Promise(function(t){return setTimeout(t,100)});case 5:o++,t.n=4;break;case 6:if(!this.sdk.isConnected){t.n=8;break}return console.log("✅ WebSocket ready, starting listening..."),t.n=7,this.sdk.startListening();case 7:console.log("🎤 Started listening"),this.isActive=!0,this.updateMicButtonState(!0),this.addMessage("system","🎤 Listening... Click mic to stop"),t.n=10;break;case 8:return console.warn("⚠️ Connection not fully ready, but trying to start listening anyway..."),t.n=9,this.sdk.startListening();case 9:console.log("🎤 Started listening"),this.isActive=!0,this.updateMicButtonState(!0),this.addMessage("system","🎤 Listening... Click mic to stop");case 10:t.n=12;break;case 11:t.p=11,r=t.v,console.error("❌ Failed to start:",r),this.showError(r.message);case 12:t.n=14;break;case 13:console.log("🔇 Stopping voice session..."),this.sdk.stopListening(),this.sdk.disconnect(),this.isActive=!1,this.updateMicButtonState(!1),this.addMessage("system","🔇 Stopped listening");case 14:return t.a(2)}},t,this,[[1,11]])})),function(){return e.apply(this,arguments)})},{key:"updateMicButtonState",value:function(t){var e=document.getElementById("agent-mic-button");if(e)if(this.config.icon.size,t){if(e.classList.add("active"),e.title="Click to stop listening","microphone"===this.config.icon.type||"custom"===this.config.icon.type){var n=e.querySelector("svg")||e.querySelector("img");n&&"svg"===n.tagName&&(n.innerHTML='\n <rect x="6" y="6" width="12" height="12" rx="2"/>\n <path d="M9 9h6"/>\n ')}}else if(e.classList.remove("active"),e.title="Click to start listening","microphone"===this.config.icon.type){var o=e.querySelector("svg");o&&(o.innerHTML='\n <path d="M12 14c1.66 0 3-1.34 3-3V5c0-1.66-1.34-3-3-3S9 3.34 9 5v6c0 1.66 1.34 3 3 3z"/>\n <path d="M17 11c0 2.76-2.24 5-5 5s-5-2.24-5-5H5c0 3.53 2.61 6.43 6 6.92V21h2v-3.08c3.39-.49 6-3.39 6-6.92h-2z"/>\n ')}}},{key:"getSignedUrl",value:(t=Ht(Ut().m(function t(){var e,n,o,r,i,c,a;return Ut().w(function(t){for(;;)switch(t.n){case 0:if(this.config.getSessionUrl){t.n=2;break}if(this.config.agentId){t.n=1;break}throw new Error("agentId is required");case 1:return e=this.config.websocketUrl||"wss://speech.talktopc.com/ws/conv",(n=new URLSearchParams).append("agentId",this.config.agentId),this.config.appId&&n.append("appId",this.config.appId),!1!==this.config.demo&&n.append("demo","true"),t.a(2,"".concat(e,"?").concat(n.toString()));case 2:if("string"!=typeof this.config.getSessionUrl){t.n=6;break}return o={agentId:this.config.agentId,variables:this.config.variables||{}},this.config.appId&&(o.appId=this.config.appId),t.n=3,fetch(this.config.getSessionUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)});case 3:if((r=t.v).ok){t.n=4;break}throw new Error("Failed to get session URL: ".concat(r.statusText));case 4:return t.n=5,r.json();case 5:return i=t.v,t.a(2,i.signedUrl||i.wsUrl||i.url);case 6:if("function"!=typeof this.config.getSessionUrl){t.n=8;break}return c={agentId:this.config.agentId,variables:this.config.variables||{}},this.config.appId&&(c.appId=this.config.appId),t.n=7,this.config.getSessionUrl(c);case 7:return a=t.v,t.a(2,"string"==typeof a?a:a.signedUrl||a.wsUrl||a.url);case 8:throw new Error("getSessionUrl must be a string (backend URL), a function, or omitted (for direct connection with agentId/appId)");case 9:return t.a(2)}},t,this)})),function(){return t.apply(this,arguments)})},{key:"addMessage",value:function(t,e){var n=document.getElementById("agent-messages"),o=document.createElement("div");o.className="message ".concat(t),o.textContent=e,n.appendChild(o),n.scrollTop=n.scrollHeight}},{key:"showAgentThinking",value:function(){var t=document.getElementById("agent-messages"),e=document.createElement("div");e.className="message agent agent-thinking",e.id="thinking-indicator",e.textContent="Agent is speaking...",t.appendChild(e),t.scrollTop=t.scrollHeight}},{key:"hideAgentThinking",value:function(){var t=document.getElementById("thinking-indicator");t&&t.remove()}},{key:"showError",value:function(t){var e=document.getElementById("agent-messages"),n=document.createElement("div");n.className="error-message",n.textContent=t,e.appendChild(n)}},{key:"updateStatus",value:function(t){}},{key:"updateConfig",value:function(t){var e,n=Kt({},this.config);t.panel&&(n.panel=Kt(Kt({},this.config.panel),t.panel),t.panel.micButtonHint&&(n.panel.micButtonHint=Kt(Kt({},null===(e=this.config.panel)||void 0===e?void 0:e.micButtonHint),t.panel.micButtonHint))),t.button&&(n.button=Kt(Kt({},this.config.button),t.button)),t.header&&(n.header=Kt(Kt({},this.config.header),t.header)),t.icon&&(n.icon=Kt(Kt({},this.config.icon),t.icon)),t.messages&&(n.messages=Kt(Kt({},this.config.messages),t.messages)),void 0!==t.direction&&(n.direction=t.direction),Object.keys(t).forEach(function(e){["panel","button","header","icon","messages","direction"].includes(e)||(n[e]=t[e])}),this.config=this.mergeWithDefaults(n);var o=document.getElementById("agent-widget");o&&o.remove(),this.createWidget()}},{key:"destroy",value:function(){var t=document.getElementById("agent-widget");t&&t.remove(),this.sdk&&this.sdk.disconnect()}}]);var t,e}(),$t="2.0.0";const Jt={VoiceSDK:dt,WebSocketManager:D,AudioRecorder:H,AudioPlayer:X,EventEmitter:a,VoiceButton:jt,VanillaVoiceButton:Bt,AgentSDK:Qt,AgentWidget:qt,VERSION:$t};return o})());
|
|
3
3
|
//# sourceMappingURL=agent-widget.js.map
|