ttp-agent-sdk 2.1.7 → 2.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,3 @@
1
1
  /*! For license information please see agent-widget.js.LICENSE.txt */
2
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.TTPAgentSDK=t():e.TTPAgentSDK=t()}(this,()=>(()=>{"use strict";var e={540:(e,t,n)=>{e.exports=n(869)},698:(e,t)=>{var n=Symbol.for("react.transitional.element");function o(e,t,o){var r=null;if(void 0!==o&&(r=""+o),void 0!==t.key&&(r=""+t.key),"key"in t)for(var i in o={},t)"key"!==i&&(o[i]=t[i]);else o=t;return t=o.ref,{$$typeof:n,type:e,key:r,ref:void 0!==t?t:null,props:o}}Symbol.for("react.fragment"),t.jsx=o,t.jsxs=o},848:(e,t,n)=>{e.exports=n(698)},869:(e,t)=>{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(e,t,o){this.props=e,this.context=t,this.refs=r,this.updater=o||n}function c(){}function a(e,t,o){this.props=e,this.context=t,this.refs=r,this.updater=o||n}i.prototype.isReactComponent={},i.prototype.setState=function(e,t){if("object"!=typeof e&&"function"!=typeof e&&null!=e)throw Error("takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,e,t,"setState")},i.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"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;t.useEffect=function(e,t){return u.H.useEffect(e,t)},t.useRef=function(e){return u.H.useRef(e)},t.useState=function(e){return u.H.useState(e)}}},t={};function n(o){var r=t[o];if(void 0!==r)return r.exports;var i=t[o]={exports:{}};return e[o](i,i.exports,n),i.exports}n.d=(e,t)=>{for(var o in t)n.o(t,o)&&!n.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};function r(e){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r(e)}function i(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,c(o.key),o)}}function c(e){var t=function(e){if("object"!=r(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=r(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==r(t)?t:t+""}n.r(o),n.d(o,{AgentSDK:()=>rt,AgentWidget:()=>it,AudioPlayer:()=>X,AudioRecorder:()=>G,EnhancedAgentWidget:()=>yt,EventEmitter:()=>a,VERSION:()=>bt,VanillaVoiceButton:()=>qe,VoiceButton:()=>We,VoiceSDK:()=>de,WebSocketManager:()=>Pe,WebSocketManagerV2:()=>I,default:()=>vt});var a=function(){return e=function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.events={}},t=[{key:"on",value:function(e,t){this.events[e]||(this.events[e]=[]),this.events[e].push(t)}},{key:"off",value:function(e,t){this.events[e]&&(this.events[e]=this.events[e].filter(function(e){return e!==t}))}},{key:"emit",value:function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),o=1;o<t;o++)n[o-1]=arguments[o];this.events[e]&&this.events[e].forEach(function(t){try{t.apply(void 0,n)}catch(t){console.error("Error in event listener for ".concat(e,":"),t)}})}},{key:"removeAllListeners",value:function(e){e?delete this.events[e]:this.events={}}}],t&&i(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t}();function s(e){return s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},s(e)}function u(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var o,r,i,c,a=[],s=!0,u=!1;try{if(i=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;s=!1}else for(;!(s=(o=i.call(n)).done)&&(a.push(o.value),a.length!==t);s=!0);}catch(e){u=!0,r=e}finally{try{if(!s&&null!=n.return&&(c=n.return(),Object(c)!==c))return}finally{if(u)throw r}}return a}}(e,t)||f(e,t)||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(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=f(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var o=0,r=function(){};return{s:r,n:function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},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(e)},n:function(){var e=n.next();return c=e.done,e},e:function(e){a=!0,i=e},f:function(){try{c||null==n.return||n.return()}finally{if(a)throw i}}}}function f(e,t){if(e){if("string"==typeof e)return d(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?d(e,t):void 0}}function d(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=Array(t);n<t;n++)o[n]=e[n];return o}function p(){var e,t,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 g(u,"_invoke",function(n,o,r){var i,a,s,u=0,l=r||[],f=!1,d={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,n){return i=t,a=0,s=e,d.n=n,c}};function p(n,o){for(a=n,s=o,t=0;!f&&u&&!r&&t<l.length;t++){var r,i=l[t],p=d.p,g=i[2];n>3?(r=g===o)&&(s=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=e):i[0]<=p&&((r=n<2&&p<i[1])?(a=0,d.v=o,d.n=i[1]):p<g&&(r=n<3||i[0]>o||o>g)&&(i[4]=n,i[5]=o,d.n=g,a=0))}if(r||n>1)return c;throw f=!0,o}return function(r,l,g){if(u>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,g),a=l,s=g;(t=a<2?e: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"),t=i[r]){if(!(t=t.call(i,s)))throw TypeError("iterator result is not an object");if(!t.done)return t;s=t.value,a<2&&(a=0)}else 1===a&&(t=i.return)&&t.call(i),a<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),a=1);i=e}else if((t=(f=d.n<0)?s:n.call(o,d))!==c)break}catch(t){i=e,a=1,s=t}finally{u=1}}return{value:t,done:f}}}(n,r,i),!0),u}var c={};function a(){}function s(){}function u(){}t=Object.getPrototypeOf;var l=[][o]?t(t([][o]())):(g(t={},o,function(){return this}),t),f=u.prototype=a.prototype=Object.create(l);function d(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,u):(e.__proto__=u,g(e,r,"GeneratorFunction")),e.prototype=Object.create(f),e}return s.prototype=u,g(f,"constructor",u),g(u,"constructor",s),s.displayName="GeneratorFunction",g(u,r,"GeneratorFunction"),g(f),g(f,r,"Generator"),g(f,o,function(){return this}),g(f,"toString",function(){return"[object Generator]"}),(p=function(){return{w:i,m:d}})()}function g(e,t,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}g=function(e,t,n,o){function i(t,n){g(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},g(e,t,n,o)}function h(e,t,n,o,r,i,c){try{var a=e[i](c),s=a.value}catch(e){return void n(e)}a.done?t(s):Promise.resolve(s).then(o,r)}function y(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,b(o.key),o)}}function b(e){var t=function(e){if("object"!=s(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=s(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==s(t)?t:t+""}function v(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(v=function(){return!!e})()}function m(e){return m=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},m(e)}function S(e,t){return S=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},S(e,t)}const w=new(function(e){function t(){var e;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),(e=function(e,t,n){return t=m(t),function(e,t){if(t&&("object"==s(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,v()?Reflect.construct(t,n||[],m(e).constructor):t.apply(e,n))}(this,t)).connections=new Map,e.connectionCounts=new Map,e.creatingConnections=new Set,e}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&S(e,t)}(t,e),n=t,o=[{key:"getConnection",value:(r=p().m(function e(t){var n,o,r=this;return p().w(function(e){for(;;)switch(e.n){case 0:if(!this.connections.has(t)){e.n=1;break}return n=this.connections.get(t),this.connectionCounts.set(t,(this.connectionCounts.get(t)||0)+1),console.log("🔌 WebSocketSingleton: Reusing existing connection for ".concat(t," (").concat(this.connectionCounts.get(t)," subscribers)")),e.a(2,n);case 1:if(!this.creatingConnections||!this.creatingConnections.has(t)){e.n=2;break}return console.log("🔌 WebSocketSingleton: Connection already being created for ".concat(t,", waiting...")),e.a(2,new Promise(function(e){var n=function(){if(r.connections.has(t)){var o=r.connections.get(t);r.connectionCounts.set(t,(r.connectionCounts.get(t)||0)+1),console.log("🔌 WebSocketSingleton: Got existing connection after wait for ".concat(t," (").concat(r.connectionCounts.get(t)," subscribers)")),e(o)}else setTimeout(n,50)};n()}));case 2:return console.log("🔌 WebSocketSingleton: Creating new connection for ".concat(t)),this.creatingConnections.add(t),o=new WebSocket(t),this.connections.set(t,o),this.connectionCounts.set(t,1),o.addEventListener("open",function(e){console.log("🔌 WebSocketSingleton: Connection opened for ".concat(t)),r.creatingConnections.delete(t),r.emit("open",e,t)}),o.addEventListener("close",function(e){console.log("🔌 WebSocketSingleton: Connection closed for ".concat(t," (Code: ").concat(e.code,")")),r.creatingConnections.delete(t),r.connections.delete(t),r.connectionCounts.delete(t),r.emit("close",e,t)}),o.addEventListener("error",function(e){console.log("🔌 WebSocketSingleton: Connection error for ".concat(t),e),r.creatingConnections.delete(t),r.emit("error",e,t)}),o.addEventListener("message",function(e){r.emit("message",e,t)}),e.a(2,o)}},e,this)}),i=function(){var e=this,t=arguments;return new Promise(function(n,o){var i=r.apply(e,t);function c(e){h(i,n,o,c,a,"next",e)}function a(e){h(i,n,o,c,a,"throw",e)}c(void 0)})},function(e){return i.apply(this,arguments)})},{key:"releaseConnection",value:function(e){if(this.connections.has(e)){var t=this.connectionCounts.get(e)||0,n=Math.max(0,t-1);if(this.connectionCounts.set(e,n),console.log("🔌 WebSocketSingleton: Released connection for ".concat(e," (").concat(n," subscribers remaining)")),0===n){var o=this.connections.get(e);o&&o.readyState===WebSocket.OPEN&&(console.log("🔌 WebSocketSingleton: Closing connection for ".concat(e," (no more subscribers)")),o.close(1e3,"No more subscribers")),this.connections.delete(e),this.connectionCounts.delete(e)}}else console.log("🔌 WebSocketSingleton: Attempted to release non-existent connection for ".concat(e))}},{key:"forceClose",value:function(e){if(this.connections.has(e)){var t=this.connections.get(e);t&&t.readyState===WebSocket.OPEN&&(console.log("🔌 WebSocketSingleton: Force closing connection for ".concat(e)),t.close(1e3,"Force close")),this.connections.delete(e),this.connectionCounts.delete(e)}}},{key:"getConnectionStatus",value:function(e){return this.connections.has(e)?{exists:!0,readyState:this.connections.get(e).readyState,subscribers:this.connectionCounts.get(e)||0}:{exists:!1,readyState:null,subscribers:0}}},{key:"getAllConnections",value:function(){var e,t={},n=l(this.connections.entries());try{for(n.s();!(e=n.n()).done;){var o=u(e.value,2),r=o[0],i=o[1];t[r]={readyState:i.readyState,subscribers:this.connectionCounts.get(r)||0}}}catch(e){n.e(e)}finally{n.f()}return t}},{key:"clearAll",value:function(){console.log("🔌 WebSocketSingleton: Clearing all connections");var e,t=l(this.connections.entries());try{for(t.s();!(e=t.n()).done;){var n=u(e.value,2),o=(n[0],n[1]);o&&o.readyState===WebSocket.OPEN&&o.close(1e3,"Clear all")}}catch(e){t.e(e)}finally{t.f()}this.connections.clear(),this.connectionCounts.clear(),this.creatingConnections.clear()}}],o&&y(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i}(a));function k(e){return k="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},k(e)}function O(){var e,t,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:e,a:p,f:p.bind(e,4),d:function(t,n){return i=t,a=0,s=e,d.n=n,c}};function p(n,o){for(a=n,s=o,t=0;!f&&u&&!r&&t<l.length;t++){var r,i=l[t],p=d.p,g=i[2];n>3?(r=g===o)&&(s=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=e):i[0]<=p&&((r=n<2&&p<i[1])?(a=0,d.v=o,d.n=i[1]):p<g&&(r=n<3||i[0]>o||o>g)&&(i[4]=n,i[5]=o,d.n=g,a=0))}if(r||n>1)return c;throw f=!0,o}return function(r,l,g){if(u>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,g),a=l,s=g;(t=a<2?e: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"),t=i[r]){if(!(t=t.call(i,s)))throw TypeError("iterator result is not an object");if(!t.done)return t;s=t.value,a<2&&(a=0)}else 1===a&&(t=i.return)&&t.call(i),a<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),a=1);i=e}else if((t=(f=d.n<0)?s:n.call(o,d))!==c)break}catch(t){i=e,a=1,s=t}finally{u=1}}return{value:t,done:f}}}(n,r,i),!0),u}var c={};function a(){}function s(){}function u(){}t=Object.getPrototypeOf;var l=[][o]?t(t([][o]())):(j(t={},o,function(){return this}),t),f=u.prototype=a.prototype=Object.create(l);function d(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,u):(e.__proto__=u,j(e,r,"GeneratorFunction")),e.prototype=Object.create(f),e}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(e,t,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}j=function(e,t,n,o){function i(t,n){j(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},j(e,t,n,o)}function C(e,t,n,o,r,i,c){try{var a=e[i](c),s=a.value}catch(e){return void n(e)}a.done?t(s):Promise.resolve(s).then(o,r)}function P(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,x(o.key),o)}}function x(e){var t=function(e){if("object"!=k(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=k(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==k(t)?t:t+""}function E(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(E=function(){return!!e})()}function T(e){return T=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},T(e)}function D(e,t){return D=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},D(e,t)}var I=function(e){function t(e){var n;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),(n=function(e,t,n){return t=T(t),function(e,t){if(t&&("object"==k(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,E()?Reflect.construct(t,n||[],T(e).constructor):t.apply(e,n))}(this,t)).config=e,n.ws=null,n.isConnected=!1,n.connectionId=null,n}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&D(e,t)}(t,e),n=t,o=[{key:"connect",value:(i=O().m(function e(){var t=this;return O().w(function(e){for(;;)if(0===e.n)return e.a(2,new Promise(function(e,n){try{t.connectionId=Date.now()+"_"+Math.random().toString(36).substr(2,9),console.log("🔌 WebSocketManagerV2: Requesting connection ".concat(t.connectionId," for ").concat(t.config.websocketUrl)),w.getConnection(t.config.websocketUrl,t.config).then(function(n){t.ws=n,console.log("🔌 WebSocketManagerV2: Got connection ".concat(t.connectionId)),t.setupEventListeners(),n.readyState===WebSocket.OPEN&&(t.isConnected=!0,t.emit("connected"),e())}).catch(function(e){console.error("🔌 WebSocketManagerV2: Connection failed ".concat(t.connectionId),e),n(e)})}catch(e){console.error("🔌 WebSocketManagerV2: Connection error ".concat(t.connectionId),e),n(e)}}))},e)}),c=function(){var e=this,t=arguments;return new Promise(function(n,o){var r=i.apply(e,t);function c(e){C(r,n,o,c,a,"next",e)}function a(e){C(r,n,o,c,a,"throw",e)}c(void 0)})},function(){return c.apply(this,arguments)})},{key:"setupEventListeners",value:function(){var e=this;if(this.ws){var t=function(t,n){n===e.config.websocketUrl&&(console.log("🔌 WebSocketManagerV2: Connection opened ".concat(e.connectionId)),e.isConnected=!0,e.emit("connected"))},n=function(t,n){n===e.config.websocketUrl&&(console.log("🔌 WebSocketManagerV2: Connection closed ".concat(e.connectionId," (Code: ").concat(t.code,")")),e.isConnected=!1,e.emit("disconnected",t))},o=function(t,n){n===e.config.websocketUrl&&(console.log("🔌 WebSocketManagerV2: Connection error ".concat(e.connectionId),t),e.emit("error",t))},r=function(t,n){n===e.config.websocketUrl&&e.handleMessage(t)};w.on("open",t),w.on("close",n),w.on("error",o),w.on("message",r),this.eventHandlers={open:t,close:n,error:o,message:r}}}},{key:"disconnect",value:function(){console.log("🔌 WebSocketManagerV2: Disconnecting ".concat(this.connectionId)),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&&(console.log("🔌 WebSocketManagerV2: Releasing connection ".concat(this.connectionId," from singleton")),w.releaseConnection(this.config.websocketUrl)),this.ws=null,this.isConnected=!1}},{key:"sendMessage",value:function(e){if(!this.isConnected||!this.ws)throw new Error("WebSocket not connected");this.ws.send(JSON.stringify(e))}},{key:"sendBinary",value:function(e){if(!this.isConnected||!this.ws)throw new Error("WebSocket not connected");this.ws.send(e)}},{key:"handleMessage",value:function(e){var t=this;if(e.data instanceof ArrayBuffer)this.emit("binaryAudio",e.data);else if(e.data instanceof Blob)e.data.arrayBuffer().then(function(e){t.emit("binaryAudio",e)}).catch(function(e){console.error("🔌 WebSocketManagerV2: Error converting Blob to ArrayBuffer:",e)});else try{var n=JSON.parse(e.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(e){this.emit("error",e)}}},{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&&P(n.prototype,o),r&&P(n,r),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i,c}(a);function R(e){return R="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},R(e)}function A(){var e,t,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 _(u,"_invoke",function(n,o,r){var i,a,s,u=0,l=r||[],f=!1,d={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,n){return i=t,a=0,s=e,d.n=n,c}};function p(n,o){for(a=n,s=o,t=0;!f&&u&&!r&&t<l.length;t++){var r,i=l[t],p=d.p,g=i[2];n>3?(r=g===o)&&(s=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=e):i[0]<=p&&((r=n<2&&p<i[1])?(a=0,d.v=o,d.n=i[1]):p<g&&(r=n<3||i[0]>o||o>g)&&(i[4]=n,i[5]=o,d.n=g,a=0))}if(r||n>1)return c;throw f=!0,o}return function(r,l,g){if(u>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,g),a=l,s=g;(t=a<2?e: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"),t=i[r]){if(!(t=t.call(i,s)))throw TypeError("iterator result is not an object");if(!t.done)return t;s=t.value,a<2&&(a=0)}else 1===a&&(t=i.return)&&t.call(i),a<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),a=1);i=e}else if((t=(f=d.n<0)?s:n.call(o,d))!==c)break}catch(t){i=e,a=1,s=t}finally{u=1}}return{value:t,done:f}}}(n,r,i),!0),u}var c={};function a(){}function s(){}function u(){}t=Object.getPrototypeOf;var l=[][o]?t(t([][o]())):(_(t={},o,function(){return this}),t),f=u.prototype=a.prototype=Object.create(l);function d(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,u):(e.__proto__=u,_(e,r,"GeneratorFunction")),e.prototype=Object.create(f),e}return s.prototype=u,_(f,"constructor",u),_(u,"constructor",s),s.displayName="GeneratorFunction",_(u,r,"GeneratorFunction"),_(f),_(f,r,"Generator"),_(f,o,function(){return this}),_(f,"toString",function(){return"[object Generator]"}),(A=function(){return{w:i,m:d}})()}function _(e,t,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}_=function(e,t,n,o){function i(t,n){_(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},_(e,t,n,o)}function M(e,t,n,o,r,i,c){try{var a=e[i](c),s=a.value}catch(e){return void n(e)}a.done?t(s):Promise.resolve(s).then(o,r)}function B(e){return function(){var t=this,n=arguments;return new Promise(function(o,r){var i=e.apply(t,n);function c(e){M(i,o,r,c,a,"next",e)}function a(e){M(i,o,r,c,a,"throw",e)}c(void 0)})}}function K(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,W(o.key),o)}}function W(e){var t=function(e){if("object"!=R(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=R(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==R(t)?t:t+""}function V(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(V=function(){return!!e})()}function U(e){return U=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},U(e)}function F(e,t){return F=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},F(e,t)}var G=function(e){function t(e){var n;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),(n=function(e,t,n){return t=U(t),function(e,t){if(t&&("object"==R(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,V()?Reflect.construct(t,n||[],U(e).constructor):t.apply(e,n))}(this,t)).config=e,n.audioContext=null,n.audioWorkletNode=null,n.mediaStream=null,n.isRecording=!1,n}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&F(e,t)}(t,e),n=t,o=[{key:"start",value:(i=B(A().m(function e(){var t,n=this;return A().w(function(e){for(;;)switch(e.p=e.n){case 0:return e.p=0,console.log("🎤 AudioRecorder: Requesting microphone access..."),e.n=1,navigator.mediaDevices.getUserMedia({audio:{sampleRate:this.config.sampleRate,channelCount:1,echoCancellation:!0,noiseSuppression:!0,autoGainControl:!0}});case 1:if(this.mediaStream=e.v,console.log("✅ AudioRecorder: Microphone access granted"),console.log("🎤 AudioRecorder: Creating AudioContext..."),this.audioContext=new(window.AudioContext||window.webkitAudioContext)({sampleRate:this.config.sampleRate}),"suspended"!==this.audioContext.state){e.n=2;break}return console.log("🎤 AudioRecorder: Resuming suspended AudioContext..."),e.n=2,this.audioContext.resume();case 2:return console.log("✅ AudioRecorder: AudioContext ready"),console.log("🎤 AudioRecorder: Loading AudioWorklet module..."),e.n=3,this.audioContext.audioWorklet.addModule("/audio-processor.js");case 3:console.log("✅ AudioRecorder: AudioWorklet module loaded"),console.log("🎤 AudioRecorder: Creating AudioWorklet node..."),this.audioWorkletNode=new AudioWorkletNode(this.audioContext,"audio-processor"),console.log("🎤 AudioRecorder: Connecting audio source..."),this.audioContext.createMediaStreamSource(this.mediaStream).connect(this.audioWorkletNode),this.audioWorkletNode.port.onmessage=function(e){var t=e.data,o=t.type,r=t.data;"pcm_audio_data"===o&&(console.log("🎵 AudioRecorder: Received audio data, length:",r.length),n.emit("audioData",r))},console.log("🎤 AudioRecorder: Enabling continuous mode..."),this.audioWorkletNode.port.postMessage({type:"setForceContinuous",data:{enabled:!0}}),this.isRecording=!0,console.log("✅ AudioRecorder: Recording started successfully"),this.emit("recordingStarted"),e.n=5;break;case 4:throw e.p=4,t=e.v,this.emit("error",t),t;case 5:return e.a(2)}},e,this,[[0,4]])})),function(){return i.apply(this,arguments)})},{key:"stop",value:(r=B(A().m(function e(){var t;return A().w(function(e){for(;;)switch(e.p=e.n){case 0:if(this.isRecording){e.n=1;break}return e.a(2);case 1:if(e.p=1,!this.audioWorkletNode){e.n=2;break}return this.audioWorkletNode.port.postMessage({type:"flush"}),e.n=2,new Promise(function(e){return setTimeout(e,100)});case 2:if(this.mediaStream&&(this.mediaStream.getTracks().forEach(function(e){return e.stop()}),this.mediaStream=null),!this.audioContext||"closed"===this.audioContext.state){e.n=4;break}return e.n=3,this.audioContext.close();case 3:this.audioContext=null;case 4:this.audioWorkletNode=null,this.isRecording=!1,this.emit("recordingStopped"),e.n=6;break;case 5:throw e.p=5,t=e.v,this.emit("error",t),t;case 6:return e.a(2)}},e,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 L(e){return L="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},L(e)}function N(){var e,t,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:e,a:p,f:p.bind(e,4),d:function(t,n){return i=t,a=0,s=e,d.n=n,c}};function p(n,o){for(a=n,s=o,t=0;!f&&u&&!r&&t<l.length;t++){var r,i=l[t],p=d.p,g=i[2];n>3?(r=g===o)&&(s=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=e):i[0]<=p&&((r=n<2&&p<i[1])?(a=0,d.v=o,d.n=i[1]):p<g&&(r=n<3||i[0]>o||o>g)&&(i[4]=n,i[5]=o,d.n=g,a=0))}if(r||n>1)return c;throw f=!0,o}return function(r,l,g){if(u>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,g),a=l,s=g;(t=a<2?e: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"),t=i[r]){if(!(t=t.call(i,s)))throw TypeError("iterator result is not an object");if(!t.done)return t;s=t.value,a<2&&(a=0)}else 1===a&&(t=i.return)&&t.call(i),a<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),a=1);i=e}else if((t=(f=d.n<0)?s:n.call(o,d))!==c)break}catch(t){i=e,a=1,s=t}finally{u=1}}return{value:t,done:f}}}(n,r,i),!0),u}var c={};function a(){}function s(){}function u(){}t=Object.getPrototypeOf;var l=[][o]?t(t([][o]())):(H(t={},o,function(){return this}),t),f=u.prototype=a.prototype=Object.create(l);function d(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,u):(e.__proto__=u,H(e,r,"GeneratorFunction")),e.prototype=Object.create(f),e}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]"}),(N=function(){return{w:i,m:d}})()}function H(e,t,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}H=function(e,t,n,o){function i(t,n){H(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},H(e,t,n,o)}function z(e,t,n,o,r,i,c){try{var a=e[i](c),s=a.value}catch(e){return void n(e)}a.done?t(s):Promise.resolve(s).then(o,r)}function Q(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,q(o.key),o)}}function q(e){var t=function(e){if("object"!=L(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=L(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==L(t)?t:t+""}function J(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(J=function(){return!!e})()}function $(e){return $=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},$(e)}function Y(e,t){return Y=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},Y(e,t)}var X=function(e){function t(e){var n;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),(n=function(e,t,n){return t=$(t),function(e,t){if(t&&("object"==L(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,J()?Reflect.construct(t,n||[],$(e).constructor):t.apply(e,n))}(this,t)).config=e,n.audioContext=null,n.audioQueue=[],n.isPlaying=!1,n.isProcessingQueue=!1,n.currentSource=null,n}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&Y(e,t)}(t,e),n=t,o=[{key:"playAudio",value:function(e){var t=this;try{var n=this.createAudioBlob(e);this.audioQueue.push(n),this.isPlaying||this.isProcessingQueue||setTimeout(function(){return t.processQueue()},50)}catch(e){this.emit("playbackError",e)}}},{key:"createAudioBlob",value:function(e){var t=new Uint8Array(e);if(t.length>=4){if(82===t[0]&&73===t[1]&&70===t[2]&&70===t[3])return new Blob([e],{type:"audio/wav"});if(255===t[0]&&!(224&~t[1]))return new Blob([e],{type:"audio/mpeg"});if(79===t[0]&&103===t[1]&&103===t[2]&&83===t[3])return new Blob([e],{type:"audio/ogg"})}return new Blob([e],{type:"audio/wav"})}},{key:"processQueue",value:(r=N().m(function e(){var t,n,o,r,i,c,a=this;return N().w(function(e){for(;;)switch(e.p=e.n){case 0:if(!this.isProcessingQueue&&!this.isPlaying&&0!==this.audioQueue.length){e.n=1;break}return e.a(2);case 1:if(this.isProcessingQueue=!0,t=this.audioQueue.shift()){e.n=2;break}return this.isProcessingQueue=!1,e.a(2);case 2:if(e.p=2,this.isPlaying=!0,this.emit("playbackStarted"),this.audioContext||(this.audioContext=new(window.AudioContext||window.webkitAudioContext)),"suspended"!==(n=this.audioContext).state){e.n=3;break}return e.n=3,n.resume();case 3:return e.n=4,t.arrayBuffer();case 4:return o=e.v,e.n=5,n.decodeAudioData(o);case 5:r=e.v,(i=n.createBufferSource()).buffer=r,i.connect(n.destination),this.currentSource=i,i.onended=function(){a.isPlaying=!1,a.isProcessingQueue=!1,a.currentSource=null,a.emit("playbackStopped"),a.audioQueue.length>0&&setTimeout(function(){return a.processQueue()},100)},i.start(),e.n=7;break;case 6:e.p=6,c=e.v,this.isPlaying=!1,this.isProcessingQueue=!1,this.currentSource=null,this.emit("playbackError",c),this.audioQueue.length>0&&setTimeout(function(){return a.processQueue()},100);case 7:return e.a(2)}},e,this,[[2,6]])}),i=function(){var e=this,t=arguments;return new Promise(function(n,o){var i=r.apply(e,t);function c(e){z(i,n,o,c,a,"next",e)}function a(e){z(i,n,o,c,a,"throw",e)}c(void 0)})},function(){return i.apply(this,arguments)})},{key:"stop",value:function(){this.stopImmediate()}},{key:"stopImmediate",value:function(){if(this.currentSource){try{this.currentSource.stop()}catch(e){}this.currentSource=null}this.isPlaying=!1,this.isProcessingQueue=!1,this.audioQueue=[],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(e){return Z="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Z(e)}function ee(){var e,t,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 te(u,"_invoke",function(n,o,r){var i,a,s,u=0,l=r||[],f=!1,d={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,n){return i=t,a=0,s=e,d.n=n,c}};function p(n,o){for(a=n,s=o,t=0;!f&&u&&!r&&t<l.length;t++){var r,i=l[t],p=d.p,g=i[2];n>3?(r=g===o)&&(s=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=e):i[0]<=p&&((r=n<2&&p<i[1])?(a=0,d.v=o,d.n=i[1]):p<g&&(r=n<3||i[0]>o||o>g)&&(i[4]=n,i[5]=o,d.n=g,a=0))}if(r||n>1)return c;throw f=!0,o}return function(r,l,g){if(u>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,g),a=l,s=g;(t=a<2?e: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"),t=i[r]){if(!(t=t.call(i,s)))throw TypeError("iterator result is not an object");if(!t.done)return t;s=t.value,a<2&&(a=0)}else 1===a&&(t=i.return)&&t.call(i),a<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),a=1);i=e}else if((t=(f=d.n<0)?s:n.call(o,d))!==c)break}catch(t){i=e,a=1,s=t}finally{u=1}}return{value:t,done:f}}}(n,r,i),!0),u}var c={};function a(){}function s(){}function u(){}t=Object.getPrototypeOf;var l=[][o]?t(t([][o]())):(te(t={},o,function(){return this}),t),f=u.prototype=a.prototype=Object.create(l);function d(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,u):(e.__proto__=u,te(e,r,"GeneratorFunction")),e.prototype=Object.create(f),e}return s.prototype=u,te(f,"constructor",u),te(u,"constructor",s),s.displayName="GeneratorFunction",te(u,r,"GeneratorFunction"),te(f),te(f,r,"Generator"),te(f,o,function(){return this}),te(f,"toString",function(){return"[object Generator]"}),(ee=function(){return{w:i,m:d}})()}function te(e,t,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}te=function(e,t,n,o){function i(t,n){te(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},te(e,t,n,o)}function ne(e,t,n,o,r,i,c){try{var a=e[i](c),s=a.value}catch(e){return void n(e)}a.done?t(s):Promise.resolve(s).then(o,r)}function oe(e){return function(){var t=this,n=arguments;return new Promise(function(o,r){var i=e.apply(t,n);function c(e){ne(i,o,r,c,a,"next",e)}function a(e){ne(i,o,r,c,a,"throw",e)}c(void 0)})}}function re(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,o)}return n}function ie(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?re(Object(n),!0).forEach(function(t){ce(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):re(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function ce(e,t,n){return(t=se(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function ae(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,se(o.key),o)}}function se(e){var t=function(e){if("object"!=Z(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=Z(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==Z(t)?t:t+""}function ue(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(ue=function(){return!!e})()}function le(e){return le=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},le(e)}function fe(e,t){return fe=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},fe(e,t)}var de=function(e){function t(){var e,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),(e=function(e,t,n){return t=le(t),function(e,t){if(t&&("object"==Z(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,ue()?Reflect.construct(t,n||[],le(e).constructor):t.apply(e,n))}(this,t)).config=ie({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),e.isConnected=!1,e.isRecording=!1,e.isPlaying=!1,e.isDestroyed=!1,e.webSocketManager=new I(ie(ie({},e.config),{},{autoReconnect:!1!==e.config.autoReconnect})),e.audioRecorder=new G(e.config),e.audioPlayer=new X(e.config),e.setupEventHandlers(),e}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&fe(e,t)}(t,e),n=t,o=[{key:"setupEventHandlers",value:function(){var e=this;this.webSocketManager.on("connected",function(){e.isConnected=!0,e.sendHelloMessage(),e.emit("connected")}),this.webSocketManager.on("disconnected",function(t){e.isConnected=!1,e.isRecording&&(console.log("🎤 VoiceSDK: Auto-stopping recording due to WebSocket disconnection"),e.stopRecording().catch(function(e){console.error("VoiceSDK: Error stopping recording on disconnect:",e)})),e.emit("disconnected",t)}),this.webSocketManager.on("error",function(t){e.emit("error",t)}),this.webSocketManager.on("message",function(t){if("greeting_audio"===t.t&&t.data)try{for(var n=atob(t.data),o=new Uint8Array(n.length),r=0;r<n.length;r++)o[r]=n.charCodeAt(r);console.log("🎵 VoiceSDK: Received greeting audio, playing..."),e.audioPlayer.playAudio(o),e.emit("greetingStarted")}catch(e){console.error("VoiceSDK: Error playing greeting audio:",e)}else e.emit("message",t)}),this.webSocketManager.on("binaryAudio",function(t){e.audioPlayer.playAudio(t)}),this.webSocketManager.on("bargeIn",function(t){e.emit("bargeIn",t)}),this.webSocketManager.on("stopPlaying",function(t){e.emit("stopPlaying",t),e.audioPlayer.stopImmediate()}),this.audioRecorder.on("recordingStarted",function(){e.isRecording=!0,e.emit("recordingStarted")}),this.audioRecorder.on("recordingStopped",function(){e.isRecording=!1,e.emit("recordingStopped")}),this.audioRecorder.on("audioData",function(t){e.isConnected&&e.webSocketManager.sendBinary(t)}),this.audioPlayer.on("playbackStarted",function(){e.isPlaying=!0,e.emit("playbackStarted")}),this.audioPlayer.on("playbackStopped",function(){e.isPlaying=!1,e.emit("playbackStopped")}),this.audioPlayer.on("playbackError",function(t){e.emit("playbackError",t)})}},{key:"connect",value:(u=oe(ee().m(function e(){var t,n;return ee().w(function(e){for(;;)switch(e.p=e.n){case 0:if(!this.isDestroyed){e.n=1;break}return console.warn("VoiceSDK: Cannot connect - SDK is destroyed"),e.a(2,!1);case 1:return e.p=1,t=this.buildWebSocketUrl(),console.log("🔌 VoiceSDK: Attempting connection to:",t),console.log("🔌 VoiceSDK: Config:",{agentId:this.config.agentId,appId:this.config.appId,language:this.config.language}),this.webSocketManager.config.websocketUrl=t,console.log("🔌 VoiceSDK: Calling webSocketManager.connect()..."),e.n=2,this.webSocketManager.connect();case 2:return console.log("🔌 VoiceSDK: webSocketManager.connect() completed successfully"),e.a(2,!0);case 3:return e.p=3,n=e.v,console.error("🔌 VoiceSDK: Connection failed with error:",n),this.emit("error",n),e.a(2,!1)}},e,this,[[1,3]])})),function(){return u.apply(this,arguments)})},{key:"buildWebSocketUrl",value:function(){var e=this.config.websocketUrl,t=new URLSearchParams;if(this.config.agentId&&(t.append("agentId",this.config.agentId),console.log("VoiceSDK: Adding agentId to URL:",this.config.agentId)),this.config.appId&&(t.append("appId",this.config.appId),console.log("VoiceSDK: Adding appId to URL:",this.config.appId)),this.config.voice&&"default"!==this.config.voice&&t.append("voice",this.config.voice),this.config.language&&"en"!==this.config.language&&t.append("language",this.config.language),t.toString()){var n=e.includes("?")?"&":"?";e+=n+t.toString()}return e}},{key:"disconnect",value:function(){this.isDestroyed?console.log("🎙️ VoiceSDK: Disconnect called but already destroyed"):(console.log("🎙️ VoiceSDK: Disconnecting from voice server"),this.stopRecording(),this.webSocketManager.disconnect())}},{key:"resetReconnectionAttempts",value:function(){this.isDestroyed||this.webSocketManager.resetReconnectionAttempts()}},{key:"reconnect",value:(s=oe(ee().m(function e(){return ee().w(function(e){for(;;)switch(e.n){case 0:if(!this.isDestroyed){e.n=1;break}return e.a(2,!1);case 1:return this.disconnect(),this.resetReconnectionAttempts(),e.n=2,this.connect();case 2:return e.a(2,e.v)}},e,this)})),function(){return s.apply(this,arguments)})},{key:"startRecording",value:(a=oe(ee().m(function e(){var t;return ee().w(function(e){for(;;)switch(e.p=e.n){case 0:if(this.isConnected){e.n=1;break}throw new Error("Not connected to voice server");case 1:return e.p=1,console.log("🎤 VoiceSDK: Starting continuous mode..."),this.webSocketManager.sendMessage({t:"start_continuous_mode",ttpId:this.generateTtpId(),voice:this.config.voice,language:this.config.language}),console.log("🎤 VoiceSDK: Starting audio recorder..."),e.n=2,this.audioRecorder.start();case 2:return console.log("✅ VoiceSDK: Audio recording started successfully"),e.a(2,!0);case 3:return e.p=3,t=e.v,console.error("❌ VoiceSDK: Failed to start recording:",t),this.emit("error",t),e.a(2,!1)}},e,this,[[1,3]])})),function(){return a.apply(this,arguments)})},{key:"stopRecording",value:(c=oe(ee().m(function e(){var t;return ee().w(function(e){for(;;)switch(e.p=e.n){case 0:if(this.isRecording){e.n=1;break}return e.a(2);case 1:return e.p=1,this.webSocketManager.sendMessage({t:"stop_continuous_mode",ttpId:this.generateTtpId()}),e.n=2,this.audioRecorder.stop();case 2:return this.audioPlayer.stopImmediate(),e.a(2,!0);case 3:return e.p=3,t=e.v,this.emit("error",t),e.a(2,!1)}},e,this,[[1,3]])})),function(){return c.apply(this,arguments)})},{key:"toggleRecording",value:(i=oe(ee().m(function e(){return ee().w(function(e){for(;;)switch(e.n){case 0:if(!this.isRecording){e.n=2;break}return e.n=1,this.stopRecording();case 1:case 3:return e.a(2,e.v);case 2:return e.n=3,this.startRecording();case 4:return e.a(2)}},e,this)})),function(){return i.apply(this,arguments)})},{key:"stopAudioPlayback",value:function(){this.audioPlayer.stopImmediate()}},{key:"handleBargeIn",value:(r=oe(ee().m(function e(){return ee().w(function(e){for(;;)switch(e.n){case 0:if(this.stopAudioPlayback(),this.isRecording){e.n=1;break}return e.n=1,this.startRecording();case 1:return e.a(2)}},e,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(e){this.config=ie(ie({},this.config),e)}},{key:"generateTtpId",value:function(){return"sdk_"+Math.random().toString(36).substr(2,9)+"_"+Date.now()}},{key:"sendHelloMessage",value:function(){if(this.isConnected){var e={t:"hello"};this.config.appId?(e.appId=this.config.appId,console.log("VoiceSDK: Sending hello message with appId (app-based authentication)")):this.config.ttpId?(e.ttpId=this.config.ttpId,console.log("VoiceSDK: Sending hello message with custom TTP ID (fallback method)")):(e.ttpId=this.generateTtpId(),console.log("VoiceSDK: Sending hello message with generated TTP ID (last resort)")),this.config.appId?console.log("VoiceSDK: Using app ID for authentication:",this.config.appId):this.config.ttpId?console.log("VoiceSDK: Using custom TTP ID:",this.config.ttpId):console.log("VoiceSDK: Using generated TTP ID:",e.ttpId);try{this.webSocketManager.sendMessage(e),console.log("VoiceSDK: Hello message sent:",e)}catch(e){console.error("VoiceSDK: Failed to send hello message:",e),this.emit("error",e)}}else console.warn("VoiceSDK: Cannot send hello message - not connected")}},{key:"destroy",value:function(){this.isDestroyed?console.log("🎙️ VoiceSDK: Destroy called but already destroyed"):(console.log("🎙️ VoiceSDK: Destroying VoiceSDK instance"),this.disconnect(),this.isDestroyed=!0,this.audioRecorder.destroy(),this.audioPlayer.destroy(),this.removeAllListeners(),console.log("🎙️ VoiceSDK: VoiceSDK instance destroyed"))}}],o&&ae(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i,c,a,s,u}(a);function pe(e){return pe="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},pe(e)}function ge(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,he(o.key),o)}}function he(e){var t=function(e){if("object"!=pe(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=pe(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==pe(t)?t:t+""}const ye=new(function(){return e=function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.connections=new Map},(t=[{key:"registerConnection",value:function(e,t){if(!this.connections.has(e))return this.connections.set(e,{connectionId:t,timestamp:Date.now(),count:1}),console.log("🔌 ConnectionManager: Registered connection ".concat(t," for ").concat(e)),!0;var n=this.connections.get(e),o=Date.now()-n.timestamp;return o>3e4?(this.connections.set(e,{connectionId:t,timestamp:Date.now(),count:1}),console.log("🔌 ConnectionManager: Allowed new connection ".concat(t," for ").concat(e," (old connection was ").concat(o,"ms ago)")),!0):(n.count++,console.log("🔌 ConnectionManager: Blocked connection ".concat(t," for ").concat(e," (").concat(n.count," attempts in ").concat(o,"ms)")),!1)}},{key:"unregisterConnection",value:function(e,t){var n=this.connections.get(e);n&&n.connectionId===t&&(this.connections.delete(e),console.log("🔌 ConnectionManager: Unregistered connection ".concat(t," for ").concat(e)))}},{key:"isConnectionAllowed",value:function(e){var t=this.connections.get(e);return!t||Date.now()-t.timestamp>3e4}},{key:"getConnectionInfo",value:function(e){return this.connections.get(e)}},{key:"clearAll",value:function(){this.connections.clear(),console.log("🔌 ConnectionManager: Cleared all connections")}}])&&ge(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t}());function be(e){return be="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},be(e)}function ve(){var e,t,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 me(u,"_invoke",function(n,o,r){var i,a,s,u=0,l=r||[],f=!1,d={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,n){return i=t,a=0,s=e,d.n=n,c}};function p(n,o){for(a=n,s=o,t=0;!f&&u&&!r&&t<l.length;t++){var r,i=l[t],p=d.p,g=i[2];n>3?(r=g===o)&&(s=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=e):i[0]<=p&&((r=n<2&&p<i[1])?(a=0,d.v=o,d.n=i[1]):p<g&&(r=n<3||i[0]>o||o>g)&&(i[4]=n,i[5]=o,d.n=g,a=0))}if(r||n>1)return c;throw f=!0,o}return function(r,l,g){if(u>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,g),a=l,s=g;(t=a<2?e: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"),t=i[r]){if(!(t=t.call(i,s)))throw TypeError("iterator result is not an object");if(!t.done)return t;s=t.value,a<2&&(a=0)}else 1===a&&(t=i.return)&&t.call(i),a<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),a=1);i=e}else if((t=(f=d.n<0)?s:n.call(o,d))!==c)break}catch(t){i=e,a=1,s=t}finally{u=1}}return{value:t,done:f}}}(n,r,i),!0),u}var c={};function a(){}function s(){}function u(){}t=Object.getPrototypeOf;var l=[][o]?t(t([][o]())):(me(t={},o,function(){return this}),t),f=u.prototype=a.prototype=Object.create(l);function d(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,u):(e.__proto__=u,me(e,r,"GeneratorFunction")),e.prototype=Object.create(f),e}return s.prototype=u,me(f,"constructor",u),me(u,"constructor",s),s.displayName="GeneratorFunction",me(u,r,"GeneratorFunction"),me(f),me(f,r,"Generator"),me(f,o,function(){return this}),me(f,"toString",function(){return"[object Generator]"}),(ve=function(){return{w:i,m:d}})()}function me(e,t,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}me=function(e,t,n,o){function i(t,n){me(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},me(e,t,n,o)}function Se(e,t,n,o,r,i,c){try{var a=e[i](c),s=a.value}catch(e){return void n(e)}a.done?t(s):Promise.resolve(s).then(o,r)}function we(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,ke(o.key),o)}}function ke(e){var t=function(e){if("object"!=be(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=be(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==be(t)?t:t+""}function Oe(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(Oe=function(){return!!e})()}function je(e){return je=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},je(e)}function Ce(e,t){return Ce=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},Ce(e,t)}var Pe=function(e){function t(e){var n;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),(n=function(e,t,n){return t=je(t),function(e,t){if(t&&("object"==be(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,Oe()?Reflect.construct(t,n||[],je(e).constructor):t.apply(e,n))}(this,t)).config=e,n.ws=null,n.isConnected=!1,n.reconnectAttempts=0,n.maxReconnectAttempts=!1!==e.autoReconnect?3:0,n.isReconnecting=!1,n.isConnecting=!1,n.connectionId=null,n}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&Ce(e,t)}(t,e),n=t,o=[{key:"connect",value:(i=ve().m(function e(){var t=this;return ve().w(function(e){for(;;)if(0===e.n)return e.a(2,new Promise(function(e,n){try{if(t.ws&&(t.ws.readyState===WebSocket.CONNECTING||t.ws.readyState===WebSocket.OPEN))return void e();if(t.isReconnecting)return void e();if(t.isConnecting)return void e();if(!ye.isConnectionAllowed(t.config.websocketUrl))return console.log("🔌 WebSocketManager: Connection blocked by global manager for ".concat(t.config.websocketUrl)),void e();if(t.isConnecting=!0,t.connectionId=Date.now()+"_"+Math.random().toString(36).substr(2,9),!ye.registerConnection(t.config.websocketUrl,t.connectionId))return console.log("🔌 WebSocketManager: Connection registration failed for ".concat(t.connectionId)),t.isConnecting=!1,void e();console.log("🔌 WebSocketManager: Starting connection attempt ".concat(t.connectionId)),t.ws=new WebSocket(t.config.websocketUrl),t.ws.onopen=function(){console.log("🔌 WebSocketManager: Connection successful ".concat(t.connectionId)),t.isConnected=!0,t.reconnectAttempts=0,t.isReconnecting=!1,t.isConnecting=!1,t.emit("connected"),e()},t.ws.onmessage=function(e){t.handleMessage(e)},t.ws.onclose=function(e){console.log("🔌 WebSocketManager: Connection closed ".concat(t.connectionId," (Code: ").concat(e.code,")")),t.isConnected=!1,t.isConnecting=!1,t.emit("disconnected",e),1e3!==e.code&&t.reconnectAttempts<t.maxReconnectAttempts&&!t.isReconnecting&&(t.isReconnecting=!0,t.reconnectAttempts++,console.log("🔌 WebSocketManager: Attempting reconnection ".concat(t.reconnectAttempts,"/").concat(t.maxReconnectAttempts)),setTimeout(function(){t.isReconnecting=!1,t.connect().catch(function(){})},1e3*t.reconnectAttempts))},t.ws.onerror=function(e){console.log("🔌 WebSocketManager: Connection error ".concat(t.connectionId),e),t.isConnecting=!1,t.emit("error",e),n(e)}}catch(e){console.log("🔌 WebSocketManager: Connection failed ".concat(t.connectionId),e),t.isConnecting=!1,n(e)}}))},e)}),c=function(){var e=this,t=arguments;return new Promise(function(n,o){var r=i.apply(e,t);function c(e){Se(r,n,o,c,a,"next",e)}function a(e){Se(r,n,o,c,a,"throw",e)}c(void 0)})},function(){return c.apply(this,arguments)})},{key:"disconnect",value:function(){this.isReconnecting=!1,this.reconnectAttempts=this.maxReconnectAttempts,this.connectionId&&ye.unregisterConnection(this.config.websocketUrl,this.connectionId),this.ws&&this.ws.readyState===WebSocket.OPEN&&this.ws.close(1e3,"Intentional disconnect"),this.ws=null,this.isConnected=!1,this.isConnecting=!1}},{key:"resetReconnectionAttempts",value:function(){this.reconnectAttempts=0,this.isReconnecting=!1}},{key:"sendMessage",value:function(e){if(!this.isConnected||!this.ws)throw new Error("WebSocket not connected");this.ws.send(JSON.stringify(e))}},{key:"sendBinary",value:function(e){if(!this.isConnected||!this.ws)throw new Error("WebSocket not connected");this.ws.send(e)}},{key:"handleMessage",value:function(e){var t=this;if(e.data instanceof ArrayBuffer)this.emit("binaryAudio",e.data);else if(e.data instanceof Blob)e.data.arrayBuffer().then(function(e){t.emit("binaryAudio",e)}).catch(function(e){t.emit("error",e)});else try{var n=JSON.parse(e.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(e){this.emit("error",e)}}},{key:"getStatus",value:function(){return{isConnected:this.isConnected,readyState:this.ws?this.ws.readyState:WebSocket.CLOSED}}}],r=[{key:"clearAllConnections",value:function(){ye.clearAll()}}],o&&we(n.prototype,o),r&&we(n,r),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i,c}(a),xe=n(540),Ee=n(848);function Te(e){return Te="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Te(e)}function De(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,o)}return n}function Ie(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?De(Object(n),!0).forEach(function(t){Re(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):De(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function Re(e,t,n){return(t=function(e){var t=function(e){if("object"!=Te(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=Te(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==Te(t)?t:t+""}(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Ae(){var e,t,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 _e(u,"_invoke",function(n,o,r){var i,a,s,u=0,l=r||[],f=!1,d={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,n){return i=t,a=0,s=e,d.n=n,c}};function p(n,o){for(a=n,s=o,t=0;!f&&u&&!r&&t<l.length;t++){var r,i=l[t],p=d.p,g=i[2];n>3?(r=g===o)&&(s=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=e):i[0]<=p&&((r=n<2&&p<i[1])?(a=0,d.v=o,d.n=i[1]):p<g&&(r=n<3||i[0]>o||o>g)&&(i[4]=n,i[5]=o,d.n=g,a=0))}if(r||n>1)return c;throw f=!0,o}return function(r,l,g){if(u>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,g),a=l,s=g;(t=a<2?e: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"),t=i[r]){if(!(t=t.call(i,s)))throw TypeError("iterator result is not an object");if(!t.done)return t;s=t.value,a<2&&(a=0)}else 1===a&&(t=i.return)&&t.call(i),a<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),a=1);i=e}else if((t=(f=d.n<0)?s:n.call(o,d))!==c)break}catch(t){i=e,a=1,s=t}finally{u=1}}return{value:t,done:f}}}(n,r,i),!0),u}var c={};function a(){}function s(){}function u(){}t=Object.getPrototypeOf;var l=[][o]?t(t([][o]())):(_e(t={},o,function(){return this}),t),f=u.prototype=a.prototype=Object.create(l);function d(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,u):(e.__proto__=u,_e(e,r,"GeneratorFunction")),e.prototype=Object.create(f),e}return s.prototype=u,_e(f,"constructor",u),_e(u,"constructor",s),s.displayName="GeneratorFunction",_e(u,r,"GeneratorFunction"),_e(f),_e(f,r,"Generator"),_e(f,o,function(){return this}),_e(f,"toString",function(){return"[object Generator]"}),(Ae=function(){return{w:i,m:d}})()}function _e(e,t,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}_e=function(e,t,n,o){function i(t,n){_e(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},_e(e,t,n,o)}function Me(e,t,n,o,r,i,c){try{var a=e[i](c),s=a.value}catch(e){return void n(e)}a.done?t(s):Promise.resolve(s).then(o,r)}function Be(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var o,r,i,c,a=[],s=!0,u=!1;try{if(i=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;s=!1}else for(;!(s=(o=i.call(n)).done)&&(a.push(o.value),a.length!==t);s=!0);}catch(e){u=!0,r=e}finally{try{if(!s&&null!=n.return&&(c=n.return(),Object(c)!==c))return}finally{if(u)throw r}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return Ke(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Ke(e,t):void 0}}(e,t)||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 Ke(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=Array(t);n<t;n++)o[n]=e[n];return o}const We=function(e){var t=e.websocketUrl,n=e.agentId,o=e.voice,r=void 0===o?"default":o,i=e.language,c=void 0===i?"en":i,a=e.autoReconnect,s=void 0===a||a,u=e.onConnected,l=e.onDisconnected,f=e.onRecordingStarted,d=e.onRecordingStopped,p=e.onPlaybackStarted,g=e.onPlaybackStopped,h=e.onError,y=e.onMessage,b=e.onBargeIn,v=e.onStopPlaying,m=e.className,S=void 0===m?"":m,w=e.style,k=void 0===w?{}:w,O=e.children,j=Be((0,xe.useState)(!1),2),C=j[0],P=j[1],x=Be((0,xe.useState)(!1),2),E=x[0],T=x[1],D=Be((0,xe.useState)(!1),2),I=(D[0],D[1]),R=Be((0,xe.useState)("Disconnected"),2),A=(R[0],R[1]),_=(0,xe.useRef)(null);(0,xe.useEffect)(function(){console.log("🎙️ VoiceButton: Creating VoiceSDK instance for ".concat(t)),_.current&&(console.log("🎙️ VoiceButton: Destroying existing VoiceSDK instance"),_.current.destroy(),_.current=null);var e=new de({websocketUrl:t,agentId:n,voice:r,language:c,autoReconnect:s});return e.on("connected",function(){P(!0),A("Connected"),null==u||u()}),e.on("disconnected",function(){P(!1),A("Disconnected"),null==l||l()}),e.on("recordingStarted",function(){T(!0),null==f||f()}),e.on("recordingStopped",function(){T(!1),null==d||d()}),e.on("playbackStarted",function(){I(!0),null==p||p()}),e.on("playbackStopped",function(){I(!1),null==g||g()}),e.on("error",function(e){null==h||h(e)}),e.on("message",function(e){null==y||y(e)}),e.on("bargeIn",function(e){null==b||b(e)}),e.on("stopPlaying",function(e){null==v||v(e)}),_.current=e,e.connect(),function(){console.log("🎙️ VoiceButton: Cleaning up VoiceSDK instance for ".concat(t)),_.current&&(_.current.destroy(),_.current=null)}},[t,n,r,c]);var M=function(){var e,t=(e=Ae().m(function e(){var t;return Ae().w(function(e){for(;;)switch(e.p=e.n){case 0:if(_.current){e.n=1;break}return e.a(2);case 1:return e.p=1,e.n=2,_.current.toggleRecording();case 2:e.n=4;break;case 3:e.p=3,t=e.v,console.error("Error toggling recording:",t);case 4:return e.a(2)}},e,null,[[1,3]])}),function(){var t=this,n=arguments;return new Promise(function(o,r){var i=e.apply(t,n);function c(e){Me(i,o,r,c,a,"next",e)}function a(e){Me(i,o,r,c,a,"throw",e)}c(void 0)})});return function(){return t.apply(this,arguments)}}(),B=(0,Ee.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[(0,Ee.jsx)("div",{style:{fontSize:"20px"},children:E?"🔴":"🎤"}),(0,Ee.jsx)("div",{children:E?"Stop Listening":"Start Listening"})]});return(0,Ee.jsx)("button",{className:"voice-button ".concat(E?"recording":""," ").concat(S),style:Ie({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:!C,children:O||B})};function Ve(e){return Ve="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Ve(e)}function Ue(){var e,t,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 Fe(u,"_invoke",function(n,o,r){var i,a,s,u=0,l=r||[],f=!1,d={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,n){return i=t,a=0,s=e,d.n=n,c}};function p(n,o){for(a=n,s=o,t=0;!f&&u&&!r&&t<l.length;t++){var r,i=l[t],p=d.p,g=i[2];n>3?(r=g===o)&&(s=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=e):i[0]<=p&&((r=n<2&&p<i[1])?(a=0,d.v=o,d.n=i[1]):p<g&&(r=n<3||i[0]>o||o>g)&&(i[4]=n,i[5]=o,d.n=g,a=0))}if(r||n>1)return c;throw f=!0,o}return function(r,l,g){if(u>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,g),a=l,s=g;(t=a<2?e: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"),t=i[r]){if(!(t=t.call(i,s)))throw TypeError("iterator result is not an object");if(!t.done)return t;s=t.value,a<2&&(a=0)}else 1===a&&(t=i.return)&&t.call(i),a<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),a=1);i=e}else if((t=(f=d.n<0)?s:n.call(o,d))!==c)break}catch(t){i=e,a=1,s=t}finally{u=1}}return{value:t,done:f}}}(n,r,i),!0),u}var c={};function a(){}function s(){}function u(){}t=Object.getPrototypeOf;var l=[][o]?t(t([][o]())):(Fe(t={},o,function(){return this}),t),f=u.prototype=a.prototype=Object.create(l);function d(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,u):(e.__proto__=u,Fe(e,r,"GeneratorFunction")),e.prototype=Object.create(f),e}return s.prototype=u,Fe(f,"constructor",u),Fe(u,"constructor",s),s.displayName="GeneratorFunction",Fe(u,r,"GeneratorFunction"),Fe(f),Fe(f,r,"Generator"),Fe(f,o,function(){return this}),Fe(f,"toString",function(){return"[object Generator]"}),(Ue=function(){return{w:i,m:d}})()}function Fe(e,t,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}Fe=function(e,t,n,o){function i(t,n){Fe(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},Fe(e,t,n,o)}function Ge(e,t,n,o,r,i,c){try{var a=e[i](c),s=a.value}catch(e){return void n(e)}a.done?t(s):Promise.resolve(s).then(o,r)}function Le(e){return function(){var t=this,n=arguments;return new Promise(function(o,r){var i=e.apply(t,n);function c(e){Ge(i,o,r,c,a,"next",e)}function a(e){Ge(i,o,r,c,a,"throw",e)}c(void 0)})}}function Ne(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,o)}return n}function He(e,t,n){return(t=Qe(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function ze(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,Qe(o.key),o)}}function Qe(e){var t=function(e){if("object"!=Ve(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=Ve(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==Ve(t)?t:t+""}var qe=function(){return e=function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.options=function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?Ne(Object(n),!0).forEach(function(t){He(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Ne(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}({websocketUrl:t.websocketUrl||"wss://speech.talktopc.com/ws/conv",agentId:t.agentId,voice:t.voice||"default",language:t.language||"en",container:t.container||document.body,buttonText:t.buttonText||"Start Listening",buttonClass:t.buttonClass||"voice-button"},t),this.isConnected=!1,this.isRecording=!1,this.isPlaying=!1,this.voiceSDK=new de({websocketUrl:this.options.websocketUrl,agentId:this.options.agentId,voice:this.options.voice,language:this.options.language}),this.setupEventListeners(),this.createButton(),this.connect()},t=[{key:"setupEventListeners",value:function(){var e=this;this.voiceSDK.on("connected",function(){var t,n;e.isConnected=!0,e.updateButton(),null===(t=(n=e.options).onConnected)||void 0===t||t.call(n)}),this.voiceSDK.on("disconnected",function(){var t,n;e.isConnected=!1,e.updateButton(),null===(t=(n=e.options).onDisconnected)||void 0===t||t.call(n)}),this.voiceSDK.on("recordingStarted",function(){var t,n;e.isRecording=!0,e.updateButton(),null===(t=(n=e.options).onRecordingStarted)||void 0===t||t.call(n)}),this.voiceSDK.on("recordingStopped",function(){var t,n;e.isRecording=!1,e.updateButton(),null===(t=(n=e.options).onRecordingStopped)||void 0===t||t.call(n)}),this.voiceSDK.on("playbackStarted",function(){var t,n;e.isPlaying=!0,null===(t=(n=e.options).onPlaybackStarted)||void 0===t||t.call(n)}),this.voiceSDK.on("playbackStopped",function(){var t,n;e.isPlaying=!1,null===(t=(n=e.options).onPlaybackStopped)||void 0===t||t.call(n)}),this.voiceSDK.on("error",function(t){var n,o;null===(n=(o=e.options).onError)||void 0===n||n.call(o,t)}),this.voiceSDK.on("message",function(t){var n,o;null===(n=(o=e.options).onMessage)||void 0===n||n.call(o,t)}),this.voiceSDK.on("bargeIn",function(t){var n,o;null===(n=(o=e.options).onBargeIn)||void 0===n||n.call(o,t)}),this.voiceSDK.on("stopPlaying",function(t){var n,o;null===(n=(o=e.options).onStopPlaying)||void 0===n||n.call(o,t)})}},{key:"createButton",value:function(){var e=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 e.toggleRecording()}),this.options.container.appendChild(this.button),this.updateButton()}},{key:"updateButton",value:function(){if(this.button){var e=this.isRecording?"🔴":"🎤",t=this.isRecording?"Stop Listening":"Start Listening";this.button.innerHTML='\n <span style="font-size: 20px;">'.concat(e,"</span>\n <span>").concat(t,"</span>\n "),this.button.disabled=!this.isConnected,this.button.style.backgroundColor=this.isRecording?"#dc3545":this.isConnected?"#007bff":"#6c757d"}}},{key:"connect",value:(o=Le(Ue().m(function e(){var t;return Ue().w(function(e){for(;;)switch(e.p=e.n){case 0:return e.p=0,e.n=1,this.voiceSDK.connect();case 1:e.n=3;break;case 2:e.p=2,t=e.v,console.error("Failed to connect:",t);case 3:return e.a(2)}},e,this,[[0,2]])})),function(){return o.apply(this,arguments)})},{key:"toggleRecording",value:(n=Le(Ue().m(function e(){var t;return Ue().w(function(e){for(;;)switch(e.p=e.n){case 0:if(this.voiceSDK){e.n=1;break}return e.a(2);case 1:return e.p=1,e.n=2,this.voiceSDK.toggleRecording();case 2:e.n=4;break;case 3:e.p=3,t=e.v,console.error("Error toggling recording:",t);case 4:return e.a(2)}},e,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(e){this.voiceSDK.updateConfig(e)}},{key:"destroy",value:function(){this.button&&this.button.parentNode&&this.button.parentNode.removeChild(this.button),this.voiceSDK&&this.voiceSDK.destroy()}}],t&&ze(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,n,o}();function Je(e){return Je="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Je(e)}function $e(){var e,t,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 Ye(u,"_invoke",function(n,o,r){var i,a,s,u=0,l=r||[],f=!1,d={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,n){return i=t,a=0,s=e,d.n=n,c}};function p(n,o){for(a=n,s=o,t=0;!f&&u&&!r&&t<l.length;t++){var r,i=l[t],p=d.p,g=i[2];n>3?(r=g===o)&&(s=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=e):i[0]<=p&&((r=n<2&&p<i[1])?(a=0,d.v=o,d.n=i[1]):p<g&&(r=n<3||i[0]>o||o>g)&&(i[4]=n,i[5]=o,d.n=g,a=0))}if(r||n>1)return c;throw f=!0,o}return function(r,l,g){if(u>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,g),a=l,s=g;(t=a<2?e: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"),t=i[r]){if(!(t=t.call(i,s)))throw TypeError("iterator result is not an object");if(!t.done)return t;s=t.value,a<2&&(a=0)}else 1===a&&(t=i.return)&&t.call(i),a<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),a=1);i=e}else if((t=(f=d.n<0)?s:n.call(o,d))!==c)break}catch(t){i=e,a=1,s=t}finally{u=1}}return{value:t,done:f}}}(n,r,i),!0),u}var c={};function a(){}function s(){}function u(){}t=Object.getPrototypeOf;var l=[][o]?t(t([][o]())):(Ye(t={},o,function(){return this}),t),f=u.prototype=a.prototype=Object.create(l);function d(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,u):(e.__proto__=u,Ye(e,r,"GeneratorFunction")),e.prototype=Object.create(f),e}return s.prototype=u,Ye(f,"constructor",u),Ye(u,"constructor",s),s.displayName="GeneratorFunction",Ye(u,r,"GeneratorFunction"),Ye(f),Ye(f,r,"Generator"),Ye(f,o,function(){return this}),Ye(f,"toString",function(){return"[object Generator]"}),($e=function(){return{w:i,m:d}})()}function Ye(e,t,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}Ye=function(e,t,n,o){function i(t,n){Ye(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},Ye(e,t,n,o)}function Xe(e,t,n,o,r,i,c){try{var a=e[i](c),s=a.value}catch(e){return void n(e)}a.done?t(s):Promise.resolve(s).then(o,r)}function Ze(e){return function(){var t=this,n=arguments;return new Promise(function(o,r){var i=e.apply(t,n);function c(e){Xe(i,o,r,c,a,"next",e)}function a(e){Xe(i,o,r,c,a,"throw",e)}c(void 0)})}}function et(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function tt(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,ot(o.key),o)}}function nt(e,t,n){return t&&tt(e.prototype,t),n&&tt(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function ot(e){var t=function(e){if("object"!=Je(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=Je(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==Je(t)?t:t+""}var rt=function(){return nt(function e(t){et(this,e),console.log("🚀 AgentSDK v2.1.7 initialized with config:",t),this.config=t,this.voiceSDK=null,this.isConnected=!1,this.isListening=!1,this.onConnected=function(){},this.onDisconnected=function(){},this.onError=function(e){return console.error("SDK Error:",e)},this.onTranscript=function(e){},this.onAgentSpeaking=function(e){}},[{key:"connect",value:(t=Ze($e().m(function e(t){var n,o=this;return $e().w(function(e){for(;;)switch(e.p=e.n){case 0:if(e.p=0,t){e.n=1;break}throw new Error("signedUrl is required");case 1:return this.voiceSDK=new de({websocketUrl:t,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(e){o.onError(e)}),this.voiceSDK.on("message",function(e){o.handleWebSocketMessage(e)}),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)}),e.n=2,this.voiceSDK.connect();case 2:e.n=4;break;case 3:throw e.p=3,n=e.v,this.onError(n),n;case 4:return e.a(2)}},e,this,[[0,3]])})),function(e){return t.apply(this,arguments)})},{key:"handleWebSocketMessage",value:function(e){switch(e.type){case"connected":console.log("Session started successfully");break;case"user_transcript":this.onTranscript(e.user_transcription||e.text);break;case"agent_response":case"barge_in":case"stop_playing":break;case"error":this.onError(new Error(e.message))}}},{key:"startListening",value:(e=Ze($e().m(function e(){var t;return $e().w(function(e){for(;;)switch(e.p=e.n){case 0:if(!this.voiceSDK){e.n=5;break}return e.p=1,console.log("🎤 AgentSDK: Starting recording..."),e.n=2,this.voiceSDK.startRecording();case 2:console.log("✅ AgentSDK: Recording started successfully"),e.n=4;break;case 3:throw e.p=3,t=e.v,console.error("❌ AgentSDK: Failed to start recording:",t),t;case 4:e.n=6;break;case 5:throw console.error("❌ AgentSDK: No voiceSDK instance available"),new Error("No voiceSDK instance available");case 6:return e.a(2)}},e,this,[[1,3]])})),function(){return e.apply(this,arguments)})},{key:"stopListening",value:function(){this.voiceSDK&&this.voiceSDK.stopRecording()}},{key:"updateVariables",value:function(e){this.voiceSDK&&this.isConnected&&this.voiceSDK.webSocketManager.sendMessage({t:"update_variables",variables:e})}},{key:"disconnect",value:function(){this.voiceSDK&&(this.voiceSDK.destroy(),this.voiceSDK=null),this.isConnected=!1,this.isListening=!1}}]);var e,t}(),it=function(){return nt(function e(t){et(this,e),console.log("🎯 AgentWidget v2.1.7 initialized with config:",t),this.config=t,this.sdk=new rt(t),this.isOpen=!1,this.isActive=!1,this.position=t.position||"bottom-right",this.primaryColor=t.primaryColor||"#4F46E5",this.setupEventHandlers(),this.createWidget()},[{key:"setupEventHandlers",value:function(){var e=this;this.sdk.onConnected=function(){console.log("✅ SDK connected"),e.updateStatus("connected")},this.sdk.onDisconnected=function(){console.log("❌ SDK disconnected"),e.updateStatus("disconnected"),e.isActive=!1,e.updateMicButtonState(!1)},this.sdk.onError=function(t){console.error("❌ SDK error:",t),e.showError(t.message)},this.sdk.onTranscript=function(t){console.log("📝 User transcript:",t),e.addMessage("user",t)},this.sdk.onAgentSpeaking=function(t){console.log("🤖 Agent speaking:",t),t?e.showAgentThinking():e.hideAgentThinking()}}},{key:"createWidget",value:function(){var e=this,t=document.createElement("div");t.id="agent-widget",t.innerHTML="\n <style>\n #agent-widget {\n position: fixed;\n ".concat(this.position.includes("bottom")?"bottom: 20px;":"top: 20px;","\n ").concat(this.position.includes("right")?"right: 20px;":"left: 20px;",'\n z-index: 9999;\n font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;\n }\n \n #agent-button {\n width: 60px;\n height: 60px;\n border-radius: 50%;\n background: ').concat(this.primaryColor,";\n border: none;\n cursor: pointer;\n box-shadow: 0 4px 12px rgba(0,0,0,0.15);\n display: flex;\n align-items: center;\n justify-content: center;\n transition: transform 0.2s;\n }\n \n #agent-button:hover {\n transform: scale(1.1);\n }\n \n #agent-button svg {\n width: 28px;\n height: 28px;\n fill: white;\n }\n \n #agent-panel {\n display: none;\n position: absolute;\n bottom: 80px;\n ").concat(this.position.includes("right")?"right: 0;":"left: 0;","\n width: 350px;\n height: 500px;\n background: white;\n border-radius: 12px;\n box-shadow: 0 8px 32px rgba(0,0,0,0.2);\n flex-direction: column;\n overflow: hidden;\n }\n \n #agent-panel.open {\n display: flex;\n }\n \n #agent-header {\n background: ").concat(this.primaryColor,";\n color: white;\n padding: 16px;\n display: flex;\n justify-content: space-between;\n align-items: center;\n }\n \n #agent-close {\n background: none;\n border: none;\n color: white;\n cursor: pointer;\n font-size: 24px;\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: 8px;\n max-width: 80%;\n }\n \n .message.user {\n background: #E5E7EB;\n align-self: flex-end;\n }\n \n .message.agent {\n background: #F3F4F6;\n align-self: flex-start;\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: 60px;\n height: 60px;\n border-radius: 50%;\n border: none;\n background: ").concat(this.primaryColor,';\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n transition: all 0.2s;\n }\n \n #agent-mic-button.active {\n background: #EF4444;\n animation: pulse 1.5s infinite;\n }\n \n #agent-mic-button svg {\n width: 28px;\n height: 28px;\n fill: white;\n }\n \n @keyframes pulse {\n 0%, 100% { transform: scale(1); }\n 50% { transform: scale(1.05); }\n }\n \n .agent-thinking {\n font-style: italic;\n color: #6B7280;\n }\n \n .error-message {\n background: #FEE2E2;\n color: #991B1B;\n padding: 12px;\n border-radius: 8px;\n margin: 8px;\n }\n </style>\n \n <button id="agent-button">\n <svg viewBox="0 0 24 24">\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>\n </button>\n \n <div id="agent-panel">\n <div id="agent-header">\n <h3 style="margin: 0;">Voice Assistant</h3>\n <button id="agent-close">&times;</button>\n </div>\n \n <div id="agent-messages"></div>\n \n <div id="agent-controls">\n <button id="agent-mic-button">\n <svg viewBox="0 0 24 24">\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>\n </button>\n </div>\n </div>\n '),document.body.appendChild(t),document.getElementById("agent-button").onclick=function(){return e.togglePanel()},document.getElementById("agent-close").onclick=function(){return e.togglePanel()},document.getElementById("agent-mic-button").onclick=function(){return e.toggleVoice()}}},{key:"togglePanel",value:function(){this.isOpen=!this.isOpen,document.getElementById("agent-panel").classList.toggle("open")}},{key:"toggleVoice",value:(t=Ze($e().m(function e(){var t,n;return $e().w(function(e){for(;;)switch(e.p=e.n){case 0:if(this.isActive){e.n=7;break}return e.p=1,console.log("🎤 Starting voice session..."),e.n=2,this.getSignedUrl();case 2:return t=e.v,console.log("🔗 Got signed URL:",t),e.n=3,this.sdk.connect(t);case 3:return console.log("✅ Connected to WebSocket"),e.n=4,this.sdk.startListening();case 4:console.log("🎤 Started listening"),this.isActive=!0,this.updateMicButtonState(!0),this.addMessage("system","🎤 Listening... Click mic to stop"),e.n=6;break;case 5:e.p=5,n=e.v,console.error("❌ Failed to start:",n),this.showError(n.message);case 6:e.n=8;break;case 7:console.log("🔇 Stopping voice session..."),this.sdk.stopListening(),this.sdk.disconnect(),this.isActive=!1,this.updateMicButtonState(!1),this.addMessage("system","🔇 Stopped listening");case 8:return e.a(2)}},e,this,[[1,5]])})),function(){return t.apply(this,arguments)})},{key:"updateMicButtonState",value:function(e){var t=document.getElementById("agent-mic-button"),n=t.querySelector("svg");e?(t.classList.add("active"),t.style.background="#EF4444",t.title="Click to stop listening",t.style.animation="pulse 1.5s infinite",n.innerHTML='\n <rect x="6" y="6" width="12" height="12" rx="2"/>\n <path d="M9 9h6"/>\n '):(t.classList.remove("active"),t.style.background=this.primaryColor,t.title="Click to start listening",t.style.animation="",n.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:(e=Ze($e().m(function e(){var t,n,o,r,i;return $e().w(function(e){for(;;)switch(e.n){case 0:if("string"!=typeof this.config.getSessionUrl){e.n=4;break}return t={agentId:this.config.agentId,variables:this.config.variables||{}},this.config.appId&&(t.appId=this.config.appId),e.n=1,fetch(this.config.getSessionUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});case 1:if((n=e.v).ok){e.n=2;break}throw new Error("Failed to get session URL: ".concat(n.statusText));case 2:return e.n=3,n.json();case 3:return o=e.v,e.a(2,o.signedUrl||o.wsUrl||o.url);case 4:if("function"!=typeof this.config.getSessionUrl){e.n=6;break}return r={agentId:this.config.agentId,variables:this.config.variables||{}},this.config.appId&&(r.appId=this.config.appId),e.n=5,this.config.getSessionUrl(r);case 5:return i=e.v,e.a(2,"string"==typeof i?i:i.signedUrl||i.wsUrl||i.url);case 6:throw new Error("getSessionUrl is required (URL string or function)");case 7:return e.a(2)}},e,this)})),function(){return e.apply(this,arguments)})},{key:"addMessage",value:function(e,t){var n=document.getElementById("agent-messages"),o=document.createElement("div");o.className="message ".concat(e),o.textContent=t,n.appendChild(o),n.scrollTop=n.scrollHeight}},{key:"showAgentThinking",value:function(){var e=document.getElementById("agent-messages"),t=document.createElement("div");t.className="message agent agent-thinking",t.id="thinking-indicator",t.textContent="Agent is speaking...",e.appendChild(t),e.scrollTop=e.scrollHeight}},{key:"hideAgentThinking",value:function(){var e=document.getElementById("thinking-indicator");e&&e.remove()}},{key:"showError",value:function(e){var t=document.getElementById("agent-messages"),n=document.createElement("div");n.className="error-message",n.textContent=e,t.appendChild(n)}},{key:"updateStatus",value:function(e){console.log("Widget status:",e)}}]);var e,t}();function ct(e){return ct="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},ct(e)}function at(){var e,t,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:e,a:p,f:p.bind(e,4),d:function(t,n){return i=t,a=0,s=e,d.n=n,c}};function p(n,o){for(a=n,s=o,t=0;!f&&u&&!r&&t<l.length;t++){var r,i=l[t],p=d.p,g=i[2];n>3?(r=g===o)&&(s=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=e):i[0]<=p&&((r=n<2&&p<i[1])?(a=0,d.v=o,d.n=i[1]):p<g&&(r=n<3||i[0]>o||o>g)&&(i[4]=n,i[5]=o,d.n=g,a=0))}if(r||n>1)return c;throw f=!0,o}return function(r,l,g){if(u>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,g),a=l,s=g;(t=a<2?e: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"),t=i[r]){if(!(t=t.call(i,s)))throw TypeError("iterator result is not an object");if(!t.done)return t;s=t.value,a<2&&(a=0)}else 1===a&&(t=i.return)&&t.call(i),a<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),a=1);i=e}else if((t=(f=d.n<0)?s:n.call(o,d))!==c)break}catch(t){i=e,a=1,s=t}finally{u=1}}return{value:t,done:f}}}(n,r,i),!0),u}var c={};function a(){}function s(){}function u(){}t=Object.getPrototypeOf;var l=[][o]?t(t([][o]())):(st(t={},o,function(){return this}),t),f=u.prototype=a.prototype=Object.create(l);function d(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,u):(e.__proto__=u,st(e,r,"GeneratorFunction")),e.prototype=Object.create(f),e}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]"}),(at=function(){return{w:i,m:d}})()}function st(e,t,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}st=function(e,t,n,o){function i(t,n){st(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},st(e,t,n,o)}function ut(e,t,n,o,r,i,c){try{var a=e[i](c),s=a.value}catch(e){return void n(e)}a.done?t(s):Promise.resolve(s).then(o,r)}function lt(e){return function(){var t=this,n=arguments;return new Promise(function(o,r){var i=e.apply(t,n);function c(e){ut(i,o,r,c,a,"next",e)}function a(e){ut(i,o,r,c,a,"throw",e)}c(void 0)})}}function ft(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,o)}return n}function dt(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?ft(Object(n),!0).forEach(function(t){pt(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ft(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function pt(e,t,n){return(t=ht(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function gt(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,ht(o.key),o)}}function ht(e){var t=function(e){if("object"!=ct(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=ct(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==ct(t)?t:t+""}var yt=function(){return e=function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.config=this.mergeWithDefaults(t),this.sdk=new AgentSDK,this.isOpen=!1,this.isActive=!1,this.setupEventHandlers(),this.createWidget()},t=[{key:"mergeWithDefaults",value:function(e){var t,n,o,r,i,c,a,s,u,l,f,d,p,g,h,y,b,v,m,S,w,k,O,j,C,P,x,E,T,D,I,R,A,_,M,B,K,W,V,U,F,G,L,N;return pt({agentId:e.agentId,getSessionUrl:e.getSessionUrl,icon:dt({type:(null===(t=e.icon)||void 0===t?void 0:t.type)||"microphone",customImage:(null===(n=e.icon)||void 0===n?void 0:n.customImage)||null,emoji:(null===(o=e.icon)||void 0===o?void 0:o.emoji)||"🎤",text:(null===(r=e.icon)||void 0===r?void 0:r.text)||"AI",size:(null===(i=e.icon)||void 0===i?void 0:i.size)||"medium"},e.icon),position:dt({vertical:(null===(c=e.position)||void 0===c?void 0:c.vertical)||"bottom",horizontal:(null===(a=e.position)||void 0===a?void 0:a.horizontal)||"right",offset:(null===(s=e.position)||void 0===s?void 0:s.offset)||{x:20,y:20}},e.position),button:dt({size:(null===(u=e.button)||void 0===u?void 0:u.size)||"medium",shape:(null===(l=e.button)||void 0===l?void 0:l.shape)||"circle",primaryColor:(null===(f=e.button)||void 0===f?void 0:f.primaryColor)||"#4F46E5",hoverColor:(null===(d=e.button)||void 0===d?void 0:d.hoverColor)||"#7C3AED",activeColor:(null===(p=e.button)||void 0===p?void 0:p.activeColor)||"#EF4444",shadow:(null===(g=e.button)||void 0===g?void 0:g.shadow)||!0,shadowColor:(null===(h=e.button)||void 0===h?void 0:h.shadowColor)||"rgba(0,0,0,0.15)"},e.button),panel:dt({width:(null===(y=e.panel)||void 0===y?void 0:y.width)||350,height:(null===(b=e.panel)||void 0===b?void 0:b.height)||500,borderRadius:(null===(v=e.panel)||void 0===v?void 0:v.borderRadius)||12,backgroundColor:(null===(m=e.panel)||void 0===m?void 0:m.backgroundColor)||"rgba(255,255,255,0.95)",backdropFilter:(null===(S=e.panel)||void 0===S?void 0:S.backdropFilter)||"blur(10px)",border:(null===(w=e.panel)||void 0===w?void 0:w.border)||"1px solid rgba(0,0,0,0.1)"},e.panel),header:dt({title:(null===(k=e.header)||void 0===k?void 0:k.title)||"Voice Assistant",showTitle:!1!==(null===(O=e.header)||void 0===O?void 0:O.showTitle),backgroundColor:(null===(j=e.header)||void 0===j?void 0:j.backgroundColor)||null,textColor:(null===(C=e.header)||void 0===C?void 0:C.textColor)||"#FFFFFF",showCloseButton:!1!==(null===(P=e.header)||void 0===P?void 0:P.showCloseButton)},e.header),messages:dt({userBackgroundColor:(null===(x=e.messages)||void 0===x?void 0:x.userBackgroundColor)||"#E5E7EB",agentBackgroundColor:(null===(E=e.messages)||void 0===E?void 0:E.agentBackgroundColor)||"#F3F4F6",systemBackgroundColor:(null===(T=e.messages)||void 0===T?void 0:T.systemBackgroundColor)||"#DCFCE7",errorBackgroundColor:(null===(D=e.messages)||void 0===D?void 0:D.errorBackgroundColor)||"#FEE2E2",textColor:(null===(I=e.messages)||void 0===I?void 0:I.textColor)||"#1F2937",fontSize:(null===(R=e.messages)||void 0===R?void 0:R.fontSize)||"14px",borderRadius:(null===(A=e.messages)||void 0===A?void 0:A.borderRadius)||8},e.messages),animation:dt({enableHover:!1!==(null===(_=e.animation)||void 0===_?void 0:_.enableHover),enablePulse:!1!==(null===(M=e.animation)||void 0===M?void 0:M.enablePulse),enableSlide:!1!==(null===(B=e.animation)||void 0===B?void 0:B.enableSlide),duration:(null===(K=e.animation)||void 0===K?void 0:K.duration)||.3},e.animation),behavior:dt({autoOpen:(null===(W=e.behavior)||void 0===W?void 0:W.autoOpen)||!1,autoConnect:(null===(V=e.behavior)||void 0===V?void 0:V.autoConnect)||!1,showWelcomeMessage:!1!==(null===(U=e.behavior)||void 0===U?void 0:U.showWelcomeMessage),welcomeMessage:(null===(F=e.behavior)||void 0===F?void 0:F.welcomeMessage)||"Hello! How can I help you today?"},e.behavior),accessibility:dt({ariaLabel:(null===(G=e.accessibility)||void 0===G?void 0:G.ariaLabel)||"Voice Assistant",ariaDescription:(null===(L=e.accessibility)||void 0===L?void 0:L.ariaDescription)||"Click to open voice assistant",keyboardNavigation:!1!==(null===(N=e.accessibility)||void 0===N?void 0:N.keyboardNavigation)},e.accessibility),customStyles:e.customStyles||"",variables:e.variables||{},primaryColor:e.primaryColor||"#4F46E5"},"position",e.position||"bottom-right")}},{key:"setupEventHandlers",value:function(){var e=this;this.sdk.onConnected=function(){e.updateStatus("connected"),e.config.behavior.showWelcomeMessage&&e.addMessage("system",e.config.behavior.welcomeMessage)},this.sdk.onDisconnected=function(){e.updateStatus("disconnected"),e.isActive=!1},this.sdk.onError=function(t){e.showError(t.message)},this.sdk.onTranscript=function(t){e.addMessage("user",t)},this.sdk.onAgentSpeaking=function(t){t?e.showAgentThinking():e.hideAgentThinking()}}},{key:"createWidget",value:function(){var e=this,t=document.createElement("div");t.id="enhanced-agent-widget",t.innerHTML=this.generateWidgetHTML(),document.body.appendChild(t),this.setupWidgetEvents(),this.config.behavior.autoOpen&&setTimeout(function(){return e.togglePanel()},1e3)}},{key:"generateWidgetHTML",value:function(){this.config.position;var e=this.config.button,t=this.config.icon,n=(this.config.panel,this.config.header),o=(this.config.messages,this.config.animation,{small:50,medium:60,large:70,xl:80}[e.size]||60),r={small:20,medium:28,large:36,xl:44}[t.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="enhanced-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="enhanced-agent-panel">\n ').concat(n.showTitle?'\n <div id="enhanced-agent-header">\n <h3 style="margin: 0; color: '.concat(n.textColor,';">').concat(n.title,"</h3>\n ").concat(n.showCloseButton?'<button id="enhanced-agent-close">&times;</button>':"","\n </div>\n "):"",'\n \n <div id="enhanced-agent-messages"></div>\n \n <div id="enhanced-agent-controls">\n <button id="enhanced-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 e=this.config.position,t=e.offset||{x:20,y:20},n="";return"top"===e.vertical?n+="top: ".concat(t.y,"px;"):"bottom"===e.vertical?n+="bottom: ".concat(t.y,"px;"):"center"===e.vertical&&(n+="top: 50%; transform: translateY(-50%);"),"left"===e.horizontal?n+="left: ".concat(t.x,"px;"):"right"===e.horizontal?n+="right: ".concat(t.x,"px;"):"center"===e.horizontal&&(n+="left: 50%; transform: translateX(-50%);"),n}},{key:"generateIconHTML",value:function(e){var t=this.config.icon;switch(t.type){case"custom":return'<img src="'.concat(t.customImage,'" alt="Voice Assistant" style="width: ').concat(e,"px; height: ").concat(e,'px; object-fit: contain;" />');case"emoji":return'<span style="font-size: '.concat(e,'px; line-height: 1;">').concat(t.emoji,"</span>");case"text":return'<span style="font-size: '.concat(Math.floor(.6*e),'px; font-weight: bold; color: white;">').concat(t.text,"</span>");default:return'<svg viewBox="0 0 24 24" style="width: '.concat(e,"px; height: ").concat(e,'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(e,t,n){var o=this.config.button,r=this.config.panel,i=this.config.header,c=this.config.messages,a=this.config.animation;return"\n #enhanced-agent-widget {\n position: fixed;\n ".concat(e,'\n z-index: 10000;\n font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;\n }\n \n #enhanced-agent-button {\n width: ').concat(t,"px;\n height: ").concat(t,"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 #enhanced-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 #enhanced-agent-panel {\n display: none;\n position: absolute;\n bottom: ").concat(t+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 #enhanced-agent-panel.open {\n display: flex;\n ").concat(a.enableSlide?"transform: translateY(0); opacity: 1;":"","\n }\n \n #enhanced-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 #enhanced-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 #enhanced-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 #enhanced-agent-controls {\n padding: 16px;\n border-top: 1px solid #E5E7EB;\n display: flex;\n justify-content: center;\n }\n \n #enhanced-agent-mic-button {\n width: ").concat(t,"px;\n height: ").concat(t,"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 #enhanced-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 e=this;document.getElementById("enhanced-agent-button").onclick=function(){return e.togglePanel()};var t=document.getElementById("enhanced-agent-close");t&&(t.onclick=function(){return e.togglePanel()}),document.getElementById("enhanced-agent-mic-button").onclick=function(){return e.toggleVoice()},this.config.accessibility.keyboardNavigation&&this.setupKeyboardNavigation()}},{key:"setupKeyboardNavigation",value:function(){var e=this;document.addEventListener("keydown",function(t){"Escape"===t.key&&e.isOpen&&e.togglePanel()})}},{key:"togglePanel",value:function(){this.isOpen=!this.isOpen,document.getElementById("enhanced-agent-panel").classList.toggle("open")}},{key:"toggleVoice",value:(o=lt(at().m(function e(){var t,n;return at().w(function(e){for(;;)switch(e.p=e.n){case 0:if(this.isActive){e.n=7;break}return e.p=1,e.n=2,this.getSignedUrl();case 2:return t=e.v,e.n=3,this.sdk.connect(t);case 3:return e.n=4,this.sdk.startListening();case 4:this.isActive=!0,document.getElementById("enhanced-agent-mic-button").classList.add("active"),this.addMessage("system","Listening..."),e.n=6;break;case 5:e.p=5,n=e.v,console.error("Failed to start:",n),this.showError(n.message);case 6:e.n=8;break;case 7:this.sdk.stopListening(),this.sdk.disconnect(),this.isActive=!1,document.getElementById("enhanced-agent-mic-button").classList.remove("active");case 8:return e.a(2)}},e,this,[[1,5]])})),function(){return o.apply(this,arguments)})},{key:"getSignedUrl",value:(n=lt(at().m(function e(){var t,n,o;return at().w(function(e){for(;;)switch(e.n){case 0:if("string"!=typeof this.config.getSessionUrl){e.n=4;break}return e.n=1,fetch(this.config.getSessionUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({agentId:this.config.agentId,variables:this.config.variables||{}})});case 1:if((t=e.v).ok){e.n=2;break}throw new Error("Failed to get session URL: ".concat(t.statusText));case 2:return e.n=3,t.json();case 3:return n=e.v,e.a(2,n.signedUrl||n.wsUrl||n.url);case 4:if("function"!=typeof this.config.getSessionUrl){e.n=6;break}return e.n=5,this.config.getSessionUrl({agentId:this.config.agentId,variables:this.config.variables||{}});case 5:return o=e.v,e.a(2,"string"==typeof o?o:o.signedUrl||o.wsUrl||o.url);case 6:throw new Error("getSessionUrl is required (URL string or function)");case 7:return e.a(2)}},e,this)})),function(){return n.apply(this,arguments)})},{key:"addMessage",value:function(e,t){var n=document.getElementById("enhanced-agent-messages"),o=document.createElement("div");o.className="message ".concat(e),o.textContent=t,n.appendChild(o),n.scrollTop=n.scrollHeight}},{key:"showAgentThinking",value:function(){var e=document.getElementById("enhanced-agent-messages"),t=document.createElement("div");t.className="message agent agent-thinking",t.id="thinking-indicator",t.textContent="Agent is speaking...",e.appendChild(t),e.scrollTop=e.scrollHeight}},{key:"hideAgentThinking",value:function(){var e=document.getElementById("thinking-indicator");e&&e.remove()}},{key:"showError",value:function(e){var t=document.getElementById("enhanced-agent-messages"),n=document.createElement("div");n.className="error-message",n.textContent=e,t.appendChild(n)}},{key:"updateStatus",value:function(e){console.log("Enhanced Widget status:",e)}},{key:"updateConfig",value:function(e){this.config=this.mergeWithDefaults(dt(dt({},this.config),e));var t=document.getElementById("enhanced-agent-widget");t&&t.remove(),this.createWidget()}},{key:"destroy",value:function(){var e=document.getElementById("enhanced-agent-widget");e&&e.remove(),this.sdk&&this.sdk.disconnect()}}],t&&gt(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,n,o}(),bt="2.0.0";const vt={VoiceSDK:de,WebSocketManager:Pe,WebSocketManagerV2:I,AudioRecorder:G,AudioPlayer:X,EventEmitter:a,VoiceButton:We,VanillaVoiceButton:qe,AgentSDK:rt,AgentWidget:it,EnhancedAgentWidget:yt,VERSION:bt};return o})());
2
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.TTPAgentSDK=t():e.TTPAgentSDK=t()}(this,()=>(()=>{"use strict";var e={540:(e,t,n)=>{e.exports=n(869)},698:(e,t)=>{var n=Symbol.for("react.transitional.element");function o(e,t,o){var r=null;if(void 0!==o&&(r=""+o),void 0!==t.key&&(r=""+t.key),"key"in t)for(var i in o={},t)"key"!==i&&(o[i]=t[i]);else o=t;return t=o.ref,{$$typeof:n,type:e,key:r,ref:void 0!==t?t:null,props:o}}Symbol.for("react.fragment"),t.jsx=o,t.jsxs=o},848:(e,t,n)=>{e.exports=n(698)},869:(e,t)=>{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(e,t,o){this.props=e,this.context=t,this.refs=r,this.updater=o||n}function c(){}function a(e,t,o){this.props=e,this.context=t,this.refs=r,this.updater=o||n}i.prototype.isReactComponent={},i.prototype.setState=function(e,t){if("object"!=typeof e&&"function"!=typeof e&&null!=e)throw Error("takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,e,t,"setState")},i.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"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;t.useEffect=function(e,t){return u.H.useEffect(e,t)},t.useRef=function(e){return u.H.useRef(e)},t.useState=function(e){return u.H.useState(e)}}},t={};function n(o){var r=t[o];if(void 0!==r)return r.exports;var i=t[o]={exports:{}};return e[o](i,i.exports,n),i.exports}n.d=(e,t)=>{for(var o in t)n.o(t,o)&&!n.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};function r(e){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r(e)}function i(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,c(o.key),o)}}function c(e){var t=function(e){if("object"!=r(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=r(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==r(t)?t:t+""}n.r(o),n.d(o,{AgentSDK:()=>rt,AgentWidget:()=>it,AudioPlayer:()=>X,AudioRecorder:()=>G,EnhancedAgentWidget:()=>yt,EventEmitter:()=>a,VERSION:()=>bt,VanillaVoiceButton:()=>qe,VoiceButton:()=>We,VoiceSDK:()=>de,WebSocketManager:()=>Pe,WebSocketManagerV2:()=>I,default:()=>vt});var a=function(){return e=function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.events={}},t=[{key:"on",value:function(e,t){this.events[e]||(this.events[e]=[]),this.events[e].push(t)}},{key:"off",value:function(e,t){this.events[e]&&(this.events[e]=this.events[e].filter(function(e){return e!==t}))}},{key:"emit",value:function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),o=1;o<t;o++)n[o-1]=arguments[o];this.events[e]&&this.events[e].forEach(function(t){try{t.apply(void 0,n)}catch(t){console.error("Error in event listener for ".concat(e,":"),t)}})}},{key:"removeAllListeners",value:function(e){e?delete this.events[e]:this.events={}}}],t&&i(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t}();function s(e){return s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},s(e)}function u(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var o,r,i,c,a=[],s=!0,u=!1;try{if(i=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;s=!1}else for(;!(s=(o=i.call(n)).done)&&(a.push(o.value),a.length!==t);s=!0);}catch(e){u=!0,r=e}finally{try{if(!s&&null!=n.return&&(c=n.return(),Object(c)!==c))return}finally{if(u)throw r}}return a}}(e,t)||f(e,t)||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(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=f(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var o=0,r=function(){};return{s:r,n:function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},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(e)},n:function(){var e=n.next();return c=e.done,e},e:function(e){a=!0,i=e},f:function(){try{c||null==n.return||n.return()}finally{if(a)throw i}}}}function f(e,t){if(e){if("string"==typeof e)return d(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?d(e,t):void 0}}function d(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=Array(t);n<t;n++)o[n]=e[n];return o}function p(){var e,t,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 g(u,"_invoke",function(n,o,r){var i,a,s,u=0,l=r||[],f=!1,d={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,n){return i=t,a=0,s=e,d.n=n,c}};function p(n,o){for(a=n,s=o,t=0;!f&&u&&!r&&t<l.length;t++){var r,i=l[t],p=d.p,g=i[2];n>3?(r=g===o)&&(s=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=e):i[0]<=p&&((r=n<2&&p<i[1])?(a=0,d.v=o,d.n=i[1]):p<g&&(r=n<3||i[0]>o||o>g)&&(i[4]=n,i[5]=o,d.n=g,a=0))}if(r||n>1)return c;throw f=!0,o}return function(r,l,g){if(u>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,g),a=l,s=g;(t=a<2?e: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"),t=i[r]){if(!(t=t.call(i,s)))throw TypeError("iterator result is not an object");if(!t.done)return t;s=t.value,a<2&&(a=0)}else 1===a&&(t=i.return)&&t.call(i),a<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),a=1);i=e}else if((t=(f=d.n<0)?s:n.call(o,d))!==c)break}catch(t){i=e,a=1,s=t}finally{u=1}}return{value:t,done:f}}}(n,r,i),!0),u}var c={};function a(){}function s(){}function u(){}t=Object.getPrototypeOf;var l=[][o]?t(t([][o]())):(g(t={},o,function(){return this}),t),f=u.prototype=a.prototype=Object.create(l);function d(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,u):(e.__proto__=u,g(e,r,"GeneratorFunction")),e.prototype=Object.create(f),e}return s.prototype=u,g(f,"constructor",u),g(u,"constructor",s),s.displayName="GeneratorFunction",g(u,r,"GeneratorFunction"),g(f),g(f,r,"Generator"),g(f,o,function(){return this}),g(f,"toString",function(){return"[object Generator]"}),(p=function(){return{w:i,m:d}})()}function g(e,t,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}g=function(e,t,n,o){function i(t,n){g(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},g(e,t,n,o)}function h(e,t,n,o,r,i,c){try{var a=e[i](c),s=a.value}catch(e){return void n(e)}a.done?t(s):Promise.resolve(s).then(o,r)}function y(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,b(o.key),o)}}function b(e){var t=function(e){if("object"!=s(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=s(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==s(t)?t:t+""}function v(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(v=function(){return!!e})()}function m(e){return m=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},m(e)}function S(e,t){return S=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},S(e,t)}const w=new(function(e){function t(){var e;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),(e=function(e,t,n){return t=m(t),function(e,t){if(t&&("object"==s(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,v()?Reflect.construct(t,n||[],m(e).constructor):t.apply(e,n))}(this,t)).connections=new Map,e.connectionCounts=new Map,e.creatingConnections=new Set,e}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&S(e,t)}(t,e),n=t,o=[{key:"getConnection",value:(r=p().m(function e(t){var n,o,r=this;return p().w(function(e){for(;;)switch(e.n){case 0:if(!this.connections.has(t)){e.n=1;break}return n=this.connections.get(t),this.connectionCounts.set(t,(this.connectionCounts.get(t)||0)+1),console.log("🔌 WebSocketSingleton: Reusing existing connection for ".concat(t," (").concat(this.connectionCounts.get(t)," subscribers)")),e.a(2,n);case 1:if(!this.creatingConnections||!this.creatingConnections.has(t)){e.n=2;break}return console.log("🔌 WebSocketSingleton: Connection already being created for ".concat(t,", waiting...")),e.a(2,new Promise(function(e){var n=function(){if(r.connections.has(t)){var o=r.connections.get(t);r.connectionCounts.set(t,(r.connectionCounts.get(t)||0)+1),console.log("🔌 WebSocketSingleton: Got existing connection after wait for ".concat(t," (").concat(r.connectionCounts.get(t)," subscribers)")),e(o)}else setTimeout(n,50)};n()}));case 2:return console.log("🔌 WebSocketSingleton: Creating new connection for ".concat(t)),this.creatingConnections.add(t),o=new WebSocket(t),this.connections.set(t,o),this.connectionCounts.set(t,1),o.addEventListener("open",function(e){console.log("🔌 WebSocketSingleton: Connection opened for ".concat(t)),r.creatingConnections.delete(t),r.emit("open",e,t)}),o.addEventListener("close",function(e){console.log("🔌 WebSocketSingleton: Connection closed for ".concat(t," (Code: ").concat(e.code,")")),r.creatingConnections.delete(t),r.connections.delete(t),r.connectionCounts.delete(t),r.emit("close",e,t)}),o.addEventListener("error",function(e){console.log("🔌 WebSocketSingleton: Connection error for ".concat(t),e),r.creatingConnections.delete(t),r.emit("error",e,t)}),o.addEventListener("message",function(e){r.emit("message",e,t)}),e.a(2,o)}},e,this)}),i=function(){var e=this,t=arguments;return new Promise(function(n,o){var i=r.apply(e,t);function c(e){h(i,n,o,c,a,"next",e)}function a(e){h(i,n,o,c,a,"throw",e)}c(void 0)})},function(e){return i.apply(this,arguments)})},{key:"releaseConnection",value:function(e){if(this.connections.has(e)){var t=this.connectionCounts.get(e)||0,n=Math.max(0,t-1);if(this.connectionCounts.set(e,n),console.log("🔌 WebSocketSingleton: Released connection for ".concat(e," (").concat(n," subscribers remaining)")),0===n){var o=this.connections.get(e);o&&o.readyState===WebSocket.OPEN&&(console.log("🔌 WebSocketSingleton: Closing connection for ".concat(e," (no more subscribers)")),o.close(1e3,"No more subscribers")),this.connections.delete(e),this.connectionCounts.delete(e)}}else console.log("🔌 WebSocketSingleton: Attempted to release non-existent connection for ".concat(e))}},{key:"forceClose",value:function(e){if(this.connections.has(e)){var t=this.connections.get(e);t&&t.readyState===WebSocket.OPEN&&(console.log("🔌 WebSocketSingleton: Force closing connection for ".concat(e)),t.close(1e3,"Force close")),this.connections.delete(e),this.connectionCounts.delete(e)}}},{key:"getConnectionStatus",value:function(e){return this.connections.has(e)?{exists:!0,readyState:this.connections.get(e).readyState,subscribers:this.connectionCounts.get(e)||0}:{exists:!1,readyState:null,subscribers:0}}},{key:"getAllConnections",value:function(){var e,t={},n=l(this.connections.entries());try{for(n.s();!(e=n.n()).done;){var o=u(e.value,2),r=o[0],i=o[1];t[r]={readyState:i.readyState,subscribers:this.connectionCounts.get(r)||0}}}catch(e){n.e(e)}finally{n.f()}return t}},{key:"clearAll",value:function(){console.log("🔌 WebSocketSingleton: Clearing all connections");var e,t=l(this.connections.entries());try{for(t.s();!(e=t.n()).done;){var n=u(e.value,2),o=(n[0],n[1]);o&&o.readyState===WebSocket.OPEN&&o.close(1e3,"Clear all")}}catch(e){t.e(e)}finally{t.f()}this.connections.clear(),this.connectionCounts.clear(),this.creatingConnections.clear()}}],o&&y(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i}(a));function k(e){return k="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},k(e)}function O(){var e,t,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:e,a:p,f:p.bind(e,4),d:function(t,n){return i=t,a=0,s=e,d.n=n,c}};function p(n,o){for(a=n,s=o,t=0;!f&&u&&!r&&t<l.length;t++){var r,i=l[t],p=d.p,g=i[2];n>3?(r=g===o)&&(s=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=e):i[0]<=p&&((r=n<2&&p<i[1])?(a=0,d.v=o,d.n=i[1]):p<g&&(r=n<3||i[0]>o||o>g)&&(i[4]=n,i[5]=o,d.n=g,a=0))}if(r||n>1)return c;throw f=!0,o}return function(r,l,g){if(u>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,g),a=l,s=g;(t=a<2?e: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"),t=i[r]){if(!(t=t.call(i,s)))throw TypeError("iterator result is not an object");if(!t.done)return t;s=t.value,a<2&&(a=0)}else 1===a&&(t=i.return)&&t.call(i),a<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),a=1);i=e}else if((t=(f=d.n<0)?s:n.call(o,d))!==c)break}catch(t){i=e,a=1,s=t}finally{u=1}}return{value:t,done:f}}}(n,r,i),!0),u}var c={};function a(){}function s(){}function u(){}t=Object.getPrototypeOf;var l=[][o]?t(t([][o]())):(j(t={},o,function(){return this}),t),f=u.prototype=a.prototype=Object.create(l);function d(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,u):(e.__proto__=u,j(e,r,"GeneratorFunction")),e.prototype=Object.create(f),e}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(e,t,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}j=function(e,t,n,o){function i(t,n){j(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},j(e,t,n,o)}function C(e,t,n,o,r,i,c){try{var a=e[i](c),s=a.value}catch(e){return void n(e)}a.done?t(s):Promise.resolve(s).then(o,r)}function P(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,x(o.key),o)}}function x(e){var t=function(e){if("object"!=k(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=k(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==k(t)?t:t+""}function E(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(E=function(){return!!e})()}function T(e){return T=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},T(e)}function D(e,t){return D=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},D(e,t)}var I=function(e){function t(e){var n;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),(n=function(e,t,n){return t=T(t),function(e,t){if(t&&("object"==k(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,E()?Reflect.construct(t,n||[],T(e).constructor):t.apply(e,n))}(this,t)).config=e,n.ws=null,n.isConnected=!1,n.connectionId=null,n}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&D(e,t)}(t,e),n=t,o=[{key:"connect",value:(i=O().m(function e(){var t=this;return O().w(function(e){for(;;)if(0===e.n)return e.a(2,new Promise(function(e,n){try{t.connectionId=Date.now()+"_"+Math.random().toString(36).substr(2,9),console.log("🔌 WebSocketManagerV2: Requesting connection ".concat(t.connectionId," for ").concat(t.config.websocketUrl)),w.getConnection(t.config.websocketUrl,t.config).then(function(n){t.ws=n,console.log("🔌 WebSocketManagerV2: Got connection ".concat(t.connectionId)),t.setupEventListeners(),n.readyState===WebSocket.OPEN&&(t.isConnected=!0,t.emit("connected"),e())}).catch(function(e){console.error("🔌 WebSocketManagerV2: Connection failed ".concat(t.connectionId),e),n(e)})}catch(e){console.error("🔌 WebSocketManagerV2: Connection error ".concat(t.connectionId),e),n(e)}}))},e)}),c=function(){var e=this,t=arguments;return new Promise(function(n,o){var r=i.apply(e,t);function c(e){C(r,n,o,c,a,"next",e)}function a(e){C(r,n,o,c,a,"throw",e)}c(void 0)})},function(){return c.apply(this,arguments)})},{key:"setupEventListeners",value:function(){var e=this;if(this.ws){var t=function(t,n){n===e.config.websocketUrl&&(console.log("🔌 WebSocketManagerV2: Connection opened ".concat(e.connectionId)),e.isConnected=!0,e.emit("connected"))},n=function(t,n){n===e.config.websocketUrl&&(console.log("🔌 WebSocketManagerV2: Connection closed ".concat(e.connectionId," (Code: ").concat(t.code,")")),e.isConnected=!1,e.emit("disconnected",t))},o=function(t,n){n===e.config.websocketUrl&&(console.log("🔌 WebSocketManagerV2: Connection error ".concat(e.connectionId),t),e.emit("error",t))},r=function(t,n){n===e.config.websocketUrl&&e.handleMessage(t)};w.on("open",t),w.on("close",n),w.on("error",o),w.on("message",r),this.eventHandlers={open:t,close:n,error:o,message:r}}}},{key:"disconnect",value:function(){console.log("🔌 WebSocketManagerV2: Disconnecting ".concat(this.connectionId)),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&&(console.log("🔌 WebSocketManagerV2: Releasing connection ".concat(this.connectionId," from singleton")),w.releaseConnection(this.config.websocketUrl)),this.ws=null,this.isConnected=!1}},{key:"sendMessage",value:function(e){if(!this.isConnected||!this.ws)throw new Error("WebSocket not connected");this.ws.send(JSON.stringify(e))}},{key:"sendBinary",value:function(e){if(!this.isConnected||!this.ws)throw new Error("WebSocket not connected");this.ws.send(e)}},{key:"handleMessage",value:function(e){var t=this;if(e.data instanceof ArrayBuffer)this.emit("binaryAudio",e.data);else if(e.data instanceof Blob)e.data.arrayBuffer().then(function(e){t.emit("binaryAudio",e)}).catch(function(e){console.error("🔌 WebSocketManagerV2: Error converting Blob to ArrayBuffer:",e)});else try{var n=JSON.parse(e.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(e){this.emit("error",e)}}},{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&&P(n.prototype,o),r&&P(n,r),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i,c}(a);function A(e){return A="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},A(e)}function R(){var e,t,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 _(u,"_invoke",function(n,o,r){var i,a,s,u=0,l=r||[],f=!1,d={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,n){return i=t,a=0,s=e,d.n=n,c}};function p(n,o){for(a=n,s=o,t=0;!f&&u&&!r&&t<l.length;t++){var r,i=l[t],p=d.p,g=i[2];n>3?(r=g===o)&&(s=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=e):i[0]<=p&&((r=n<2&&p<i[1])?(a=0,d.v=o,d.n=i[1]):p<g&&(r=n<3||i[0]>o||o>g)&&(i[4]=n,i[5]=o,d.n=g,a=0))}if(r||n>1)return c;throw f=!0,o}return function(r,l,g){if(u>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,g),a=l,s=g;(t=a<2?e: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"),t=i[r]){if(!(t=t.call(i,s)))throw TypeError("iterator result is not an object");if(!t.done)return t;s=t.value,a<2&&(a=0)}else 1===a&&(t=i.return)&&t.call(i),a<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),a=1);i=e}else if((t=(f=d.n<0)?s:n.call(o,d))!==c)break}catch(t){i=e,a=1,s=t}finally{u=1}}return{value:t,done:f}}}(n,r,i),!0),u}var c={};function a(){}function s(){}function u(){}t=Object.getPrototypeOf;var l=[][o]?t(t([][o]())):(_(t={},o,function(){return this}),t),f=u.prototype=a.prototype=Object.create(l);function d(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,u):(e.__proto__=u,_(e,r,"GeneratorFunction")),e.prototype=Object.create(f),e}return s.prototype=u,_(f,"constructor",u),_(u,"constructor",s),s.displayName="GeneratorFunction",_(u,r,"GeneratorFunction"),_(f),_(f,r,"Generator"),_(f,o,function(){return this}),_(f,"toString",function(){return"[object Generator]"}),(R=function(){return{w:i,m:d}})()}function _(e,t,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}_=function(e,t,n,o){function i(t,n){_(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},_(e,t,n,o)}function M(e,t,n,o,r,i,c){try{var a=e[i](c),s=a.value}catch(e){return void n(e)}a.done?t(s):Promise.resolve(s).then(o,r)}function B(e){return function(){var t=this,n=arguments;return new Promise(function(o,r){var i=e.apply(t,n);function c(e){M(i,o,r,c,a,"next",e)}function a(e){M(i,o,r,c,a,"throw",e)}c(void 0)})}}function K(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,W(o.key),o)}}function W(e){var t=function(e){if("object"!=A(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=A(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==A(t)?t:t+""}function V(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(V=function(){return!!e})()}function U(e){return U=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},U(e)}function F(e,t){return F=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},F(e,t)}var G=function(e){function t(e){var n;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),(n=function(e,t,n){return t=U(t),function(e,t){if(t&&("object"==A(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,V()?Reflect.construct(t,n||[],U(e).constructor):t.apply(e,n))}(this,t)).config=e,n.audioContext=null,n.audioWorkletNode=null,n.mediaStream=null,n.isRecording=!1,n}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&F(e,t)}(t,e),n=t,o=[{key:"start",value:(i=B(R().m(function e(){var t,n=this;return R().w(function(e){for(;;)switch(e.p=e.n){case 0:return e.p=0,console.log("🎤 AudioRecorder: Requesting microphone access..."),e.n=1,navigator.mediaDevices.getUserMedia({audio:{sampleRate:this.config.sampleRate,channelCount:1,echoCancellation:!0,noiseSuppression:!0,autoGainControl:!0}});case 1:if(this.mediaStream=e.v,console.log("✅ AudioRecorder: Microphone access granted"),console.log("🎤 AudioRecorder: Creating AudioContext..."),this.audioContext=new(window.AudioContext||window.webkitAudioContext)({sampleRate:this.config.sampleRate}),"suspended"!==this.audioContext.state){e.n=2;break}return console.log("🎤 AudioRecorder: Resuming suspended AudioContext..."),e.n=2,this.audioContext.resume();case 2:return console.log("✅ AudioRecorder: AudioContext ready"),console.log("🎤 AudioRecorder: Loading AudioWorklet module..."),e.n=3,this.audioContext.audioWorklet.addModule("/audio-processor.js");case 3:console.log("✅ AudioRecorder: AudioWorklet module loaded"),console.log("🎤 AudioRecorder: Creating AudioWorklet node..."),this.audioWorkletNode=new AudioWorkletNode(this.audioContext,"audio-processor"),console.log("🎤 AudioRecorder: Connecting audio source..."),this.audioContext.createMediaStreamSource(this.mediaStream).connect(this.audioWorkletNode),this.audioWorkletNode.port.onmessage=function(e){var t=e.data,o=t.type,r=t.data;"pcm_audio_data"===o&&(console.log("🎵 AudioRecorder: Received audio data, length:",r.length),n.emit("audioData",r))},console.log("🎤 AudioRecorder: Enabling continuous mode..."),this.audioWorkletNode.port.postMessage({type:"setForceContinuous",data:{enabled:!0}}),this.isRecording=!0,console.log("✅ AudioRecorder: Recording started successfully"),this.emit("recordingStarted"),e.n=5;break;case 4:throw e.p=4,t=e.v,this.emit("error",t),t;case 5:return e.a(2)}},e,this,[[0,4]])})),function(){return i.apply(this,arguments)})},{key:"stop",value:(r=B(R().m(function e(){var t;return R().w(function(e){for(;;)switch(e.p=e.n){case 0:if(this.isRecording){e.n=1;break}return e.a(2);case 1:if(e.p=1,!this.audioWorkletNode){e.n=2;break}return this.audioWorkletNode.port.postMessage({type:"flush"}),e.n=2,new Promise(function(e){return setTimeout(e,100)});case 2:if(this.mediaStream&&(this.mediaStream.getTracks().forEach(function(e){return e.stop()}),this.mediaStream=null),!this.audioContext||"closed"===this.audioContext.state){e.n=4;break}return e.n=3,this.audioContext.close();case 3:this.audioContext=null;case 4:this.audioWorkletNode=null,this.isRecording=!1,this.emit("recordingStopped"),e.n=6;break;case 5:throw e.p=5,t=e.v,this.emit("error",t),t;case 6:return e.a(2)}},e,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 L(e){return L="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},L(e)}function N(){var e,t,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:e,a:p,f:p.bind(e,4),d:function(t,n){return i=t,a=0,s=e,d.n=n,c}};function p(n,o){for(a=n,s=o,t=0;!f&&u&&!r&&t<l.length;t++){var r,i=l[t],p=d.p,g=i[2];n>3?(r=g===o)&&(s=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=e):i[0]<=p&&((r=n<2&&p<i[1])?(a=0,d.v=o,d.n=i[1]):p<g&&(r=n<3||i[0]>o||o>g)&&(i[4]=n,i[5]=o,d.n=g,a=0))}if(r||n>1)return c;throw f=!0,o}return function(r,l,g){if(u>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,g),a=l,s=g;(t=a<2?e: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"),t=i[r]){if(!(t=t.call(i,s)))throw TypeError("iterator result is not an object");if(!t.done)return t;s=t.value,a<2&&(a=0)}else 1===a&&(t=i.return)&&t.call(i),a<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),a=1);i=e}else if((t=(f=d.n<0)?s:n.call(o,d))!==c)break}catch(t){i=e,a=1,s=t}finally{u=1}}return{value:t,done:f}}}(n,r,i),!0),u}var c={};function a(){}function s(){}function u(){}t=Object.getPrototypeOf;var l=[][o]?t(t([][o]())):(H(t={},o,function(){return this}),t),f=u.prototype=a.prototype=Object.create(l);function d(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,u):(e.__proto__=u,H(e,r,"GeneratorFunction")),e.prototype=Object.create(f),e}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]"}),(N=function(){return{w:i,m:d}})()}function H(e,t,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}H=function(e,t,n,o){function i(t,n){H(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},H(e,t,n,o)}function z(e,t,n,o,r,i,c){try{var a=e[i](c),s=a.value}catch(e){return void n(e)}a.done?t(s):Promise.resolve(s).then(o,r)}function Q(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,q(o.key),o)}}function q(e){var t=function(e){if("object"!=L(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=L(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==L(t)?t:t+""}function J(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(J=function(){return!!e})()}function $(e){return $=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},$(e)}function Y(e,t){return Y=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},Y(e,t)}var X=function(e){function t(e){var n;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),(n=function(e,t,n){return t=$(t),function(e,t){if(t&&("object"==L(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,J()?Reflect.construct(t,n||[],$(e).constructor):t.apply(e,n))}(this,t)).config=e,n.audioContext=null,n.audioQueue=[],n.isPlaying=!1,n.isProcessingQueue=!1,n.currentSource=null,n}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&Y(e,t)}(t,e),n=t,o=[{key:"playAudio",value:function(e){var t=this;try{var n=this.createAudioBlob(e);this.audioQueue.push(n),this.isPlaying||this.isProcessingQueue||setTimeout(function(){return t.processQueue()},50)}catch(e){this.emit("playbackError",e)}}},{key:"createAudioBlob",value:function(e){var t=new Uint8Array(e);if(t.length>=4){if(82===t[0]&&73===t[1]&&70===t[2]&&70===t[3])return new Blob([e],{type:"audio/wav"});if(255===t[0]&&!(224&~t[1]))return new Blob([e],{type:"audio/mpeg"});if(79===t[0]&&103===t[1]&&103===t[2]&&83===t[3])return new Blob([e],{type:"audio/ogg"})}return new Blob([e],{type:"audio/wav"})}},{key:"processQueue",value:(r=N().m(function e(){var t,n,o,r,i,c,a=this;return N().w(function(e){for(;;)switch(e.p=e.n){case 0:if(!this.isProcessingQueue&&!this.isPlaying&&0!==this.audioQueue.length){e.n=1;break}return e.a(2);case 1:if(this.isProcessingQueue=!0,t=this.audioQueue.shift()){e.n=2;break}return this.isProcessingQueue=!1,e.a(2);case 2:if(e.p=2,this.isPlaying=!0,this.emit("playbackStarted"),this.audioContext||(this.audioContext=new(window.AudioContext||window.webkitAudioContext)),"suspended"!==(n=this.audioContext).state){e.n=3;break}return e.n=3,n.resume();case 3:return e.n=4,t.arrayBuffer();case 4:return o=e.v,e.n=5,n.decodeAudioData(o);case 5:r=e.v,(i=n.createBufferSource()).buffer=r,i.connect(n.destination),this.currentSource=i,i.onended=function(){a.isPlaying=!1,a.isProcessingQueue=!1,a.currentSource=null,a.emit("playbackStopped"),a.audioQueue.length>0&&setTimeout(function(){return a.processQueue()},100)},i.start(),e.n=7;break;case 6:e.p=6,c=e.v,this.isPlaying=!1,this.isProcessingQueue=!1,this.currentSource=null,this.emit("playbackError",c),this.audioQueue.length>0&&setTimeout(function(){return a.processQueue()},100);case 7:return e.a(2)}},e,this,[[2,6]])}),i=function(){var e=this,t=arguments;return new Promise(function(n,o){var i=r.apply(e,t);function c(e){z(i,n,o,c,a,"next",e)}function a(e){z(i,n,o,c,a,"throw",e)}c(void 0)})},function(){return i.apply(this,arguments)})},{key:"stop",value:function(){this.stopImmediate()}},{key:"stopImmediate",value:function(){if(this.currentSource){try{this.currentSource.stop()}catch(e){}this.currentSource=null}this.isPlaying=!1,this.isProcessingQueue=!1,this.audioQueue=[],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(e){return Z="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Z(e)}function ee(){var e,t,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 te(u,"_invoke",function(n,o,r){var i,a,s,u=0,l=r||[],f=!1,d={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,n){return i=t,a=0,s=e,d.n=n,c}};function p(n,o){for(a=n,s=o,t=0;!f&&u&&!r&&t<l.length;t++){var r,i=l[t],p=d.p,g=i[2];n>3?(r=g===o)&&(s=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=e):i[0]<=p&&((r=n<2&&p<i[1])?(a=0,d.v=o,d.n=i[1]):p<g&&(r=n<3||i[0]>o||o>g)&&(i[4]=n,i[5]=o,d.n=g,a=0))}if(r||n>1)return c;throw f=!0,o}return function(r,l,g){if(u>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,g),a=l,s=g;(t=a<2?e: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"),t=i[r]){if(!(t=t.call(i,s)))throw TypeError("iterator result is not an object");if(!t.done)return t;s=t.value,a<2&&(a=0)}else 1===a&&(t=i.return)&&t.call(i),a<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),a=1);i=e}else if((t=(f=d.n<0)?s:n.call(o,d))!==c)break}catch(t){i=e,a=1,s=t}finally{u=1}}return{value:t,done:f}}}(n,r,i),!0),u}var c={};function a(){}function s(){}function u(){}t=Object.getPrototypeOf;var l=[][o]?t(t([][o]())):(te(t={},o,function(){return this}),t),f=u.prototype=a.prototype=Object.create(l);function d(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,u):(e.__proto__=u,te(e,r,"GeneratorFunction")),e.prototype=Object.create(f),e}return s.prototype=u,te(f,"constructor",u),te(u,"constructor",s),s.displayName="GeneratorFunction",te(u,r,"GeneratorFunction"),te(f),te(f,r,"Generator"),te(f,o,function(){return this}),te(f,"toString",function(){return"[object Generator]"}),(ee=function(){return{w:i,m:d}})()}function te(e,t,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}te=function(e,t,n,o){function i(t,n){te(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},te(e,t,n,o)}function ne(e,t,n,o,r,i,c){try{var a=e[i](c),s=a.value}catch(e){return void n(e)}a.done?t(s):Promise.resolve(s).then(o,r)}function oe(e){return function(){var t=this,n=arguments;return new Promise(function(o,r){var i=e.apply(t,n);function c(e){ne(i,o,r,c,a,"next",e)}function a(e){ne(i,o,r,c,a,"throw",e)}c(void 0)})}}function re(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,o)}return n}function ie(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?re(Object(n),!0).forEach(function(t){ce(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):re(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function ce(e,t,n){return(t=se(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function ae(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,se(o.key),o)}}function se(e){var t=function(e){if("object"!=Z(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=Z(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==Z(t)?t:t+""}function ue(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(ue=function(){return!!e})()}function le(e){return le=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},le(e)}function fe(e,t){return fe=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},fe(e,t)}var de=function(e){function t(){var e,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),(e=function(e,t,n){return t=le(t),function(e,t){if(t&&("object"==Z(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,ue()?Reflect.construct(t,n||[],le(e).constructor):t.apply(e,n))}(this,t)).config=ie({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),e.isConnected=!1,e.isRecording=!1,e.isPlaying=!1,e.isDestroyed=!1,e.webSocketManager=new I(ie(ie({},e.config),{},{autoReconnect:!1!==e.config.autoReconnect})),e.audioRecorder=new G(e.config),e.audioPlayer=new X(e.config),e.setupEventHandlers(),e}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&fe(e,t)}(t,e),n=t,o=[{key:"setupEventHandlers",value:function(){var e=this;this.webSocketManager.on("connected",function(){e.isConnected=!0,e.sendHelloMessage(),e.emit("connected")}),this.webSocketManager.on("disconnected",function(t){e.isConnected=!1,e.isRecording&&(console.log("🎤 VoiceSDK: Auto-stopping recording due to WebSocket disconnection"),e.stopRecording().catch(function(e){console.error("VoiceSDK: Error stopping recording on disconnect:",e)})),e.emit("disconnected",t)}),this.webSocketManager.on("error",function(t){e.emit("error",t)}),this.webSocketManager.on("message",function(t){if("greeting_audio"===t.t&&t.data)try{for(var n=atob(t.data),o=new Uint8Array(n.length),r=0;r<n.length;r++)o[r]=n.charCodeAt(r);console.log("🎵 VoiceSDK: Received greeting audio, playing..."),e.audioPlayer.playAudio(o),e.emit("greetingStarted")}catch(e){console.error("VoiceSDK: Error playing greeting audio:",e)}else e.emit("message",t)}),this.webSocketManager.on("binaryAudio",function(t){e.audioPlayer.playAudio(t)}),this.webSocketManager.on("bargeIn",function(t){e.emit("bargeIn",t)}),this.webSocketManager.on("stopPlaying",function(t){e.emit("stopPlaying",t),e.audioPlayer.stopImmediate()}),this.audioRecorder.on("recordingStarted",function(){e.isRecording=!0,e.emit("recordingStarted")}),this.audioRecorder.on("recordingStopped",function(){e.isRecording=!1,e.emit("recordingStopped")}),this.audioRecorder.on("audioData",function(t){e.isConnected&&e.webSocketManager.sendBinary(t)}),this.audioPlayer.on("playbackStarted",function(){e.isPlaying=!0,e.emit("playbackStarted")}),this.audioPlayer.on("playbackStopped",function(){e.isPlaying=!1,e.emit("playbackStopped")}),this.audioPlayer.on("playbackError",function(t){e.emit("playbackError",t)})}},{key:"connect",value:(u=oe(ee().m(function e(){var t,n;return ee().w(function(e){for(;;)switch(e.p=e.n){case 0:if(!this.isDestroyed){e.n=1;break}return console.warn("VoiceSDK: Cannot connect - SDK is destroyed"),e.a(2,!1);case 1:return e.p=1,t=this.buildWebSocketUrl(),console.log("🔌 VoiceSDK: Attempting connection to:",t),console.log("🔌 VoiceSDK: Config:",{agentId:this.config.agentId,appId:this.config.appId,language:this.config.language}),this.webSocketManager.config.websocketUrl=t,console.log("🔌 VoiceSDK: Calling webSocketManager.connect()..."),e.n=2,this.webSocketManager.connect();case 2:return console.log("🔌 VoiceSDK: webSocketManager.connect() completed successfully"),e.a(2,!0);case 3:return e.p=3,n=e.v,console.error("🔌 VoiceSDK: Connection failed with error:",n),this.emit("error",n),e.a(2,!1)}},e,this,[[1,3]])})),function(){return u.apply(this,arguments)})},{key:"buildWebSocketUrl",value:function(){var e=this.config.websocketUrl,t=new URLSearchParams;if(this.config.agentId&&(t.append("agentId",this.config.agentId),console.log("VoiceSDK: Adding agentId to URL:",this.config.agentId)),this.config.appId&&(t.append("appId",this.config.appId),console.log("VoiceSDK: Adding appId to URL:",this.config.appId)),this.config.voice&&"default"!==this.config.voice&&t.append("voice",this.config.voice),this.config.language&&"en"!==this.config.language&&t.append("language",this.config.language),t.toString()){var n=e.includes("?")?"&":"?";e+=n+t.toString()}return e}},{key:"disconnect",value:function(){this.isDestroyed?console.log("🎙️ VoiceSDK: Disconnect called but already destroyed"):(console.log("🎙️ VoiceSDK: Disconnecting from voice server"),this.stopRecording(),this.webSocketManager.disconnect())}},{key:"resetReconnectionAttempts",value:function(){this.isDestroyed||this.webSocketManager.resetReconnectionAttempts()}},{key:"reconnect",value:(s=oe(ee().m(function e(){return ee().w(function(e){for(;;)switch(e.n){case 0:if(!this.isDestroyed){e.n=1;break}return e.a(2,!1);case 1:return this.disconnect(),this.resetReconnectionAttempts(),e.n=2,this.connect();case 2:return e.a(2,e.v)}},e,this)})),function(){return s.apply(this,arguments)})},{key:"startRecording",value:(a=oe(ee().m(function e(){var t;return ee().w(function(e){for(;;)switch(e.p=e.n){case 0:if(this.isConnected){e.n=1;break}throw new Error("Not connected to voice server");case 1:return e.p=1,console.log("🎤 VoiceSDK: Starting continuous mode..."),this.webSocketManager.sendMessage({t:"start_continuous_mode",ttpId:this.generateTtpId(),voice:this.config.voice,language:this.config.language}),console.log("🎤 VoiceSDK: Starting audio recorder..."),e.n=2,this.audioRecorder.start();case 2:return console.log("✅ VoiceSDK: Audio recording started successfully"),e.a(2,!0);case 3:return e.p=3,t=e.v,console.error("❌ VoiceSDK: Failed to start recording:",t),this.emit("error",t),e.a(2,!1)}},e,this,[[1,3]])})),function(){return a.apply(this,arguments)})},{key:"stopRecording",value:(c=oe(ee().m(function e(){var t;return ee().w(function(e){for(;;)switch(e.p=e.n){case 0:if(this.isRecording){e.n=1;break}return e.a(2);case 1:return e.p=1,this.webSocketManager.sendMessage({t:"stop_continuous_mode",ttpId:this.generateTtpId()}),e.n=2,this.audioRecorder.stop();case 2:return this.audioPlayer.stopImmediate(),e.a(2,!0);case 3:return e.p=3,t=e.v,this.emit("error",t),e.a(2,!1)}},e,this,[[1,3]])})),function(){return c.apply(this,arguments)})},{key:"toggleRecording",value:(i=oe(ee().m(function e(){return ee().w(function(e){for(;;)switch(e.n){case 0:if(!this.isRecording){e.n=2;break}return e.n=1,this.stopRecording();case 1:case 3:return e.a(2,e.v);case 2:return e.n=3,this.startRecording();case 4:return e.a(2)}},e,this)})),function(){return i.apply(this,arguments)})},{key:"stopAudioPlayback",value:function(){this.audioPlayer.stopImmediate()}},{key:"handleBargeIn",value:(r=oe(ee().m(function e(){return ee().w(function(e){for(;;)switch(e.n){case 0:if(this.stopAudioPlayback(),this.isRecording){e.n=1;break}return e.n=1,this.startRecording();case 1:return e.a(2)}},e,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(e){this.config=ie(ie({},this.config),e)}},{key:"generateTtpId",value:function(){return"sdk_"+Math.random().toString(36).substr(2,9)+"_"+Date.now()}},{key:"sendHelloMessage",value:function(){if(this.isConnected){var e={t:"hello"};this.config.appId?(e.appId=this.config.appId,console.log("VoiceSDK: Sending hello message with appId (app-based authentication)")):this.config.ttpId?(e.ttpId=this.config.ttpId,console.log("VoiceSDK: Sending hello message with custom TTP ID (fallback method)")):(e.ttpId=this.generateTtpId(),console.log("VoiceSDK: Sending hello message with generated TTP ID (last resort)")),this.config.appId?console.log("VoiceSDK: Using app ID for authentication:",this.config.appId):this.config.ttpId?console.log("VoiceSDK: Using custom TTP ID:",this.config.ttpId):console.log("VoiceSDK: Using generated TTP ID:",e.ttpId);try{this.webSocketManager.sendMessage(e),console.log("VoiceSDK: Hello message sent:",e)}catch(e){console.error("VoiceSDK: Failed to send hello message:",e),this.emit("error",e)}}else console.warn("VoiceSDK: Cannot send hello message - not connected")}},{key:"destroy",value:function(){this.isDestroyed?console.log("🎙️ VoiceSDK: Destroy called but already destroyed"):(console.log("🎙️ VoiceSDK: Destroying VoiceSDK instance"),this.disconnect(),this.isDestroyed=!0,this.audioRecorder.destroy(),this.audioPlayer.destroy(),this.removeAllListeners(),console.log("🎙️ VoiceSDK: VoiceSDK instance destroyed"))}}],o&&ae(n.prototype,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i,c,a,s,u}(a);function pe(e){return pe="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},pe(e)}function ge(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,he(o.key),o)}}function he(e){var t=function(e){if("object"!=pe(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=pe(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==pe(t)?t:t+""}const ye=new(function(){return e=function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.connections=new Map},(t=[{key:"registerConnection",value:function(e,t){if(!this.connections.has(e))return this.connections.set(e,{connectionId:t,timestamp:Date.now(),count:1}),console.log("🔌 ConnectionManager: Registered connection ".concat(t," for ").concat(e)),!0;var n=this.connections.get(e),o=Date.now()-n.timestamp;return o>3e4?(this.connections.set(e,{connectionId:t,timestamp:Date.now(),count:1}),console.log("🔌 ConnectionManager: Allowed new connection ".concat(t," for ").concat(e," (old connection was ").concat(o,"ms ago)")),!0):(n.count++,console.log("🔌 ConnectionManager: Blocked connection ".concat(t," for ").concat(e," (").concat(n.count," attempts in ").concat(o,"ms)")),!1)}},{key:"unregisterConnection",value:function(e,t){var n=this.connections.get(e);n&&n.connectionId===t&&(this.connections.delete(e),console.log("🔌 ConnectionManager: Unregistered connection ".concat(t," for ").concat(e)))}},{key:"isConnectionAllowed",value:function(e){var t=this.connections.get(e);return!t||Date.now()-t.timestamp>3e4}},{key:"getConnectionInfo",value:function(e){return this.connections.get(e)}},{key:"clearAll",value:function(){this.connections.clear(),console.log("🔌 ConnectionManager: Cleared all connections")}}])&&ge(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t}());function be(e){return be="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},be(e)}function ve(){var e,t,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 me(u,"_invoke",function(n,o,r){var i,a,s,u=0,l=r||[],f=!1,d={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,n){return i=t,a=0,s=e,d.n=n,c}};function p(n,o){for(a=n,s=o,t=0;!f&&u&&!r&&t<l.length;t++){var r,i=l[t],p=d.p,g=i[2];n>3?(r=g===o)&&(s=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=e):i[0]<=p&&((r=n<2&&p<i[1])?(a=0,d.v=o,d.n=i[1]):p<g&&(r=n<3||i[0]>o||o>g)&&(i[4]=n,i[5]=o,d.n=g,a=0))}if(r||n>1)return c;throw f=!0,o}return function(r,l,g){if(u>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,g),a=l,s=g;(t=a<2?e: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"),t=i[r]){if(!(t=t.call(i,s)))throw TypeError("iterator result is not an object");if(!t.done)return t;s=t.value,a<2&&(a=0)}else 1===a&&(t=i.return)&&t.call(i),a<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),a=1);i=e}else if((t=(f=d.n<0)?s:n.call(o,d))!==c)break}catch(t){i=e,a=1,s=t}finally{u=1}}return{value:t,done:f}}}(n,r,i),!0),u}var c={};function a(){}function s(){}function u(){}t=Object.getPrototypeOf;var l=[][o]?t(t([][o]())):(me(t={},o,function(){return this}),t),f=u.prototype=a.prototype=Object.create(l);function d(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,u):(e.__proto__=u,me(e,r,"GeneratorFunction")),e.prototype=Object.create(f),e}return s.prototype=u,me(f,"constructor",u),me(u,"constructor",s),s.displayName="GeneratorFunction",me(u,r,"GeneratorFunction"),me(f),me(f,r,"Generator"),me(f,o,function(){return this}),me(f,"toString",function(){return"[object Generator]"}),(ve=function(){return{w:i,m:d}})()}function me(e,t,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}me=function(e,t,n,o){function i(t,n){me(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},me(e,t,n,o)}function Se(e,t,n,o,r,i,c){try{var a=e[i](c),s=a.value}catch(e){return void n(e)}a.done?t(s):Promise.resolve(s).then(o,r)}function we(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,ke(o.key),o)}}function ke(e){var t=function(e){if("object"!=be(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=be(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==be(t)?t:t+""}function Oe(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(Oe=function(){return!!e})()}function je(e){return je=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},je(e)}function Ce(e,t){return Ce=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},Ce(e,t)}var Pe=function(e){function t(e){var n;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),(n=function(e,t,n){return t=je(t),function(e,t){if(t&&("object"==be(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,Oe()?Reflect.construct(t,n||[],je(e).constructor):t.apply(e,n))}(this,t)).config=e,n.ws=null,n.isConnected=!1,n.reconnectAttempts=0,n.maxReconnectAttempts=!1!==e.autoReconnect?3:0,n.isReconnecting=!1,n.isConnecting=!1,n.connectionId=null,n}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&Ce(e,t)}(t,e),n=t,o=[{key:"connect",value:(i=ve().m(function e(){var t=this;return ve().w(function(e){for(;;)if(0===e.n)return e.a(2,new Promise(function(e,n){try{if(t.ws&&(t.ws.readyState===WebSocket.CONNECTING||t.ws.readyState===WebSocket.OPEN))return void e();if(t.isReconnecting)return void e();if(t.isConnecting)return void e();if(!ye.isConnectionAllowed(t.config.websocketUrl))return console.log("🔌 WebSocketManager: Connection blocked by global manager for ".concat(t.config.websocketUrl)),void e();if(t.isConnecting=!0,t.connectionId=Date.now()+"_"+Math.random().toString(36).substr(2,9),!ye.registerConnection(t.config.websocketUrl,t.connectionId))return console.log("🔌 WebSocketManager: Connection registration failed for ".concat(t.connectionId)),t.isConnecting=!1,void e();console.log("🔌 WebSocketManager: Starting connection attempt ".concat(t.connectionId)),t.ws=new WebSocket(t.config.websocketUrl),t.ws.onopen=function(){console.log("🔌 WebSocketManager: Connection successful ".concat(t.connectionId)),t.isConnected=!0,t.reconnectAttempts=0,t.isReconnecting=!1,t.isConnecting=!1,t.emit("connected"),e()},t.ws.onmessage=function(e){t.handleMessage(e)},t.ws.onclose=function(e){console.log("🔌 WebSocketManager: Connection closed ".concat(t.connectionId," (Code: ").concat(e.code,")")),t.isConnected=!1,t.isConnecting=!1,t.emit("disconnected",e),1e3!==e.code&&t.reconnectAttempts<t.maxReconnectAttempts&&!t.isReconnecting&&(t.isReconnecting=!0,t.reconnectAttempts++,console.log("🔌 WebSocketManager: Attempting reconnection ".concat(t.reconnectAttempts,"/").concat(t.maxReconnectAttempts)),setTimeout(function(){t.isReconnecting=!1,t.connect().catch(function(){})},1e3*t.reconnectAttempts))},t.ws.onerror=function(e){console.log("🔌 WebSocketManager: Connection error ".concat(t.connectionId),e),t.isConnecting=!1,t.emit("error",e),n(e)}}catch(e){console.log("🔌 WebSocketManager: Connection failed ".concat(t.connectionId),e),t.isConnecting=!1,n(e)}}))},e)}),c=function(){var e=this,t=arguments;return new Promise(function(n,o){var r=i.apply(e,t);function c(e){Se(r,n,o,c,a,"next",e)}function a(e){Se(r,n,o,c,a,"throw",e)}c(void 0)})},function(){return c.apply(this,arguments)})},{key:"disconnect",value:function(){this.isReconnecting=!1,this.reconnectAttempts=this.maxReconnectAttempts,this.connectionId&&ye.unregisterConnection(this.config.websocketUrl,this.connectionId),this.ws&&this.ws.readyState===WebSocket.OPEN&&this.ws.close(1e3,"Intentional disconnect"),this.ws=null,this.isConnected=!1,this.isConnecting=!1}},{key:"resetReconnectionAttempts",value:function(){this.reconnectAttempts=0,this.isReconnecting=!1}},{key:"sendMessage",value:function(e){if(!this.isConnected||!this.ws)throw new Error("WebSocket not connected");this.ws.send(JSON.stringify(e))}},{key:"sendBinary",value:function(e){if(!this.isConnected||!this.ws)throw new Error("WebSocket not connected");this.ws.send(e)}},{key:"handleMessage",value:function(e){var t=this;if(e.data instanceof ArrayBuffer)this.emit("binaryAudio",e.data);else if(e.data instanceof Blob)e.data.arrayBuffer().then(function(e){t.emit("binaryAudio",e)}).catch(function(e){t.emit("error",e)});else try{var n=JSON.parse(e.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(e){this.emit("error",e)}}},{key:"getStatus",value:function(){return{isConnected:this.isConnected,readyState:this.ws?this.ws.readyState:WebSocket.CLOSED}}}],r=[{key:"clearAllConnections",value:function(){ye.clearAll()}}],o&&we(n.prototype,o),r&&we(n,r),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,o,r,i,c}(a),xe=n(540),Ee=n(848);function Te(e){return Te="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Te(e)}function De(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,o)}return n}function Ie(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?De(Object(n),!0).forEach(function(t){Ae(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):De(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function Ae(e,t,n){return(t=function(e){var t=function(e){if("object"!=Te(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=Te(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==Te(t)?t:t+""}(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Re(){var e,t,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 _e(u,"_invoke",function(n,o,r){var i,a,s,u=0,l=r||[],f=!1,d={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,n){return i=t,a=0,s=e,d.n=n,c}};function p(n,o){for(a=n,s=o,t=0;!f&&u&&!r&&t<l.length;t++){var r,i=l[t],p=d.p,g=i[2];n>3?(r=g===o)&&(s=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=e):i[0]<=p&&((r=n<2&&p<i[1])?(a=0,d.v=o,d.n=i[1]):p<g&&(r=n<3||i[0]>o||o>g)&&(i[4]=n,i[5]=o,d.n=g,a=0))}if(r||n>1)return c;throw f=!0,o}return function(r,l,g){if(u>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,g),a=l,s=g;(t=a<2?e: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"),t=i[r]){if(!(t=t.call(i,s)))throw TypeError("iterator result is not an object");if(!t.done)return t;s=t.value,a<2&&(a=0)}else 1===a&&(t=i.return)&&t.call(i),a<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),a=1);i=e}else if((t=(f=d.n<0)?s:n.call(o,d))!==c)break}catch(t){i=e,a=1,s=t}finally{u=1}}return{value:t,done:f}}}(n,r,i),!0),u}var c={};function a(){}function s(){}function u(){}t=Object.getPrototypeOf;var l=[][o]?t(t([][o]())):(_e(t={},o,function(){return this}),t),f=u.prototype=a.prototype=Object.create(l);function d(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,u):(e.__proto__=u,_e(e,r,"GeneratorFunction")),e.prototype=Object.create(f),e}return s.prototype=u,_e(f,"constructor",u),_e(u,"constructor",s),s.displayName="GeneratorFunction",_e(u,r,"GeneratorFunction"),_e(f),_e(f,r,"Generator"),_e(f,o,function(){return this}),_e(f,"toString",function(){return"[object Generator]"}),(Re=function(){return{w:i,m:d}})()}function _e(e,t,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}_e=function(e,t,n,o){function i(t,n){_e(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},_e(e,t,n,o)}function Me(e,t,n,o,r,i,c){try{var a=e[i](c),s=a.value}catch(e){return void n(e)}a.done?t(s):Promise.resolve(s).then(o,r)}function Be(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var o,r,i,c,a=[],s=!0,u=!1;try{if(i=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;s=!1}else for(;!(s=(o=i.call(n)).done)&&(a.push(o.value),a.length!==t);s=!0);}catch(e){u=!0,r=e}finally{try{if(!s&&null!=n.return&&(c=n.return(),Object(c)!==c))return}finally{if(u)throw r}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return Ke(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Ke(e,t):void 0}}(e,t)||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 Ke(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=Array(t);n<t;n++)o[n]=e[n];return o}const We=function(e){var t=e.websocketUrl,n=e.agentId,o=e.voice,r=void 0===o?"default":o,i=e.language,c=void 0===i?"en":i,a=e.autoReconnect,s=void 0===a||a,u=e.onConnected,l=e.onDisconnected,f=e.onRecordingStarted,d=e.onRecordingStopped,p=e.onPlaybackStarted,g=e.onPlaybackStopped,h=e.onError,y=e.onMessage,b=e.onBargeIn,v=e.onStopPlaying,m=e.className,S=void 0===m?"":m,w=e.style,k=void 0===w?{}:w,O=e.children,j=Be((0,xe.useState)(!1),2),C=j[0],P=j[1],x=Be((0,xe.useState)(!1),2),E=x[0],T=x[1],D=Be((0,xe.useState)(!1),2),I=(D[0],D[1]),A=Be((0,xe.useState)("Disconnected"),2),R=(A[0],A[1]),_=(0,xe.useRef)(null);(0,xe.useEffect)(function(){console.log("🎙️ VoiceButton: Creating VoiceSDK instance for ".concat(t)),_.current&&(console.log("🎙️ VoiceButton: Destroying existing VoiceSDK instance"),_.current.destroy(),_.current=null);var e=new de({websocketUrl:t,agentId:n,voice:r,language:c,autoReconnect:s});return e.on("connected",function(){P(!0),R("Connected"),null==u||u()}),e.on("disconnected",function(){P(!1),R("Disconnected"),null==l||l()}),e.on("recordingStarted",function(){T(!0),null==f||f()}),e.on("recordingStopped",function(){T(!1),null==d||d()}),e.on("playbackStarted",function(){I(!0),null==p||p()}),e.on("playbackStopped",function(){I(!1),null==g||g()}),e.on("error",function(e){null==h||h(e)}),e.on("message",function(e){null==y||y(e)}),e.on("bargeIn",function(e){null==b||b(e)}),e.on("stopPlaying",function(e){null==v||v(e)}),_.current=e,e.connect(),function(){console.log("🎙️ VoiceButton: Cleaning up VoiceSDK instance for ".concat(t)),_.current&&(_.current.destroy(),_.current=null)}},[t,n,r,c]);var M=function(){var e,t=(e=Re().m(function e(){var t;return Re().w(function(e){for(;;)switch(e.p=e.n){case 0:if(_.current){e.n=1;break}return e.a(2);case 1:return e.p=1,e.n=2,_.current.toggleRecording();case 2:e.n=4;break;case 3:e.p=3,t=e.v,console.error("Error toggling recording:",t);case 4:return e.a(2)}},e,null,[[1,3]])}),function(){var t=this,n=arguments;return new Promise(function(o,r){var i=e.apply(t,n);function c(e){Me(i,o,r,c,a,"next",e)}function a(e){Me(i,o,r,c,a,"throw",e)}c(void 0)})});return function(){return t.apply(this,arguments)}}(),B=(0,Ee.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[(0,Ee.jsx)("div",{style:{fontSize:"20px"},children:E?"🔴":"🎤"}),(0,Ee.jsx)("div",{children:E?"Stop Listening":"Start Listening"})]});return(0,Ee.jsx)("button",{className:"voice-button ".concat(E?"recording":""," ").concat(S),style:Ie({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:!C,children:O||B})};function Ve(e){return Ve="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Ve(e)}function Ue(){var e,t,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 Fe(u,"_invoke",function(n,o,r){var i,a,s,u=0,l=r||[],f=!1,d={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,n){return i=t,a=0,s=e,d.n=n,c}};function p(n,o){for(a=n,s=o,t=0;!f&&u&&!r&&t<l.length;t++){var r,i=l[t],p=d.p,g=i[2];n>3?(r=g===o)&&(s=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=e):i[0]<=p&&((r=n<2&&p<i[1])?(a=0,d.v=o,d.n=i[1]):p<g&&(r=n<3||i[0]>o||o>g)&&(i[4]=n,i[5]=o,d.n=g,a=0))}if(r||n>1)return c;throw f=!0,o}return function(r,l,g){if(u>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,g),a=l,s=g;(t=a<2?e: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"),t=i[r]){if(!(t=t.call(i,s)))throw TypeError("iterator result is not an object");if(!t.done)return t;s=t.value,a<2&&(a=0)}else 1===a&&(t=i.return)&&t.call(i),a<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),a=1);i=e}else if((t=(f=d.n<0)?s:n.call(o,d))!==c)break}catch(t){i=e,a=1,s=t}finally{u=1}}return{value:t,done:f}}}(n,r,i),!0),u}var c={};function a(){}function s(){}function u(){}t=Object.getPrototypeOf;var l=[][o]?t(t([][o]())):(Fe(t={},o,function(){return this}),t),f=u.prototype=a.prototype=Object.create(l);function d(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,u):(e.__proto__=u,Fe(e,r,"GeneratorFunction")),e.prototype=Object.create(f),e}return s.prototype=u,Fe(f,"constructor",u),Fe(u,"constructor",s),s.displayName="GeneratorFunction",Fe(u,r,"GeneratorFunction"),Fe(f),Fe(f,r,"Generator"),Fe(f,o,function(){return this}),Fe(f,"toString",function(){return"[object Generator]"}),(Ue=function(){return{w:i,m:d}})()}function Fe(e,t,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}Fe=function(e,t,n,o){function i(t,n){Fe(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},Fe(e,t,n,o)}function Ge(e,t,n,o,r,i,c){try{var a=e[i](c),s=a.value}catch(e){return void n(e)}a.done?t(s):Promise.resolve(s).then(o,r)}function Le(e){return function(){var t=this,n=arguments;return new Promise(function(o,r){var i=e.apply(t,n);function c(e){Ge(i,o,r,c,a,"next",e)}function a(e){Ge(i,o,r,c,a,"throw",e)}c(void 0)})}}function Ne(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,o)}return n}function He(e,t,n){return(t=Qe(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function ze(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,Qe(o.key),o)}}function Qe(e){var t=function(e){if("object"!=Ve(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=Ve(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==Ve(t)?t:t+""}var qe=function(){return e=function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.options=function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?Ne(Object(n),!0).forEach(function(t){He(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Ne(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}({websocketUrl:t.websocketUrl||"wss://speech.talktopc.com/ws/conv",agentId:t.agentId,voice:t.voice||"default",language:t.language||"en",container:t.container||document.body,buttonText:t.buttonText||"Start Listening",buttonClass:t.buttonClass||"voice-button"},t),this.isConnected=!1,this.isRecording=!1,this.isPlaying=!1,this.voiceSDK=new de({websocketUrl:this.options.websocketUrl,agentId:this.options.agentId,voice:this.options.voice,language:this.options.language}),this.setupEventListeners(),this.createButton(),this.connect()},t=[{key:"setupEventListeners",value:function(){var e=this;this.voiceSDK.on("connected",function(){var t,n;e.isConnected=!0,e.updateButton(),null===(t=(n=e.options).onConnected)||void 0===t||t.call(n)}),this.voiceSDK.on("disconnected",function(){var t,n;e.isConnected=!1,e.updateButton(),null===(t=(n=e.options).onDisconnected)||void 0===t||t.call(n)}),this.voiceSDK.on("recordingStarted",function(){var t,n;e.isRecording=!0,e.updateButton(),null===(t=(n=e.options).onRecordingStarted)||void 0===t||t.call(n)}),this.voiceSDK.on("recordingStopped",function(){var t,n;e.isRecording=!1,e.updateButton(),null===(t=(n=e.options).onRecordingStopped)||void 0===t||t.call(n)}),this.voiceSDK.on("playbackStarted",function(){var t,n;e.isPlaying=!0,null===(t=(n=e.options).onPlaybackStarted)||void 0===t||t.call(n)}),this.voiceSDK.on("playbackStopped",function(){var t,n;e.isPlaying=!1,null===(t=(n=e.options).onPlaybackStopped)||void 0===t||t.call(n)}),this.voiceSDK.on("error",function(t){var n,o;null===(n=(o=e.options).onError)||void 0===n||n.call(o,t)}),this.voiceSDK.on("message",function(t){var n,o;null===(n=(o=e.options).onMessage)||void 0===n||n.call(o,t)}),this.voiceSDK.on("bargeIn",function(t){var n,o;null===(n=(o=e.options).onBargeIn)||void 0===n||n.call(o,t)}),this.voiceSDK.on("stopPlaying",function(t){var n,o;null===(n=(o=e.options).onStopPlaying)||void 0===n||n.call(o,t)})}},{key:"createButton",value:function(){var e=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 e.toggleRecording()}),this.options.container.appendChild(this.button),this.updateButton()}},{key:"updateButton",value:function(){if(this.button){var e=this.isRecording?"🔴":"🎤",t=this.isRecording?"Stop Listening":"Start Listening";this.button.innerHTML='\n <span style="font-size: 20px;">'.concat(e,"</span>\n <span>").concat(t,"</span>\n "),this.button.disabled=!this.isConnected,this.button.style.backgroundColor=this.isRecording?"#dc3545":this.isConnected?"#007bff":"#6c757d"}}},{key:"connect",value:(o=Le(Ue().m(function e(){var t;return Ue().w(function(e){for(;;)switch(e.p=e.n){case 0:return e.p=0,e.n=1,this.voiceSDK.connect();case 1:e.n=3;break;case 2:e.p=2,t=e.v,console.error("Failed to connect:",t);case 3:return e.a(2)}},e,this,[[0,2]])})),function(){return o.apply(this,arguments)})},{key:"toggleRecording",value:(n=Le(Ue().m(function e(){var t;return Ue().w(function(e){for(;;)switch(e.p=e.n){case 0:if(this.voiceSDK){e.n=1;break}return e.a(2);case 1:return e.p=1,e.n=2,this.voiceSDK.toggleRecording();case 2:e.n=4;break;case 3:e.p=3,t=e.v,console.error("Error toggling recording:",t);case 4:return e.a(2)}},e,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(e){this.voiceSDK.updateConfig(e)}},{key:"destroy",value:function(){this.button&&this.button.parentNode&&this.button.parentNode.removeChild(this.button),this.voiceSDK&&this.voiceSDK.destroy()}}],t&&ze(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,n,o}();function Je(e){return Je="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Je(e)}function $e(){var e,t,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 Ye(u,"_invoke",function(n,o,r){var i,a,s,u=0,l=r||[],f=!1,d={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,n){return i=t,a=0,s=e,d.n=n,c}};function p(n,o){for(a=n,s=o,t=0;!f&&u&&!r&&t<l.length;t++){var r,i=l[t],p=d.p,g=i[2];n>3?(r=g===o)&&(s=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=e):i[0]<=p&&((r=n<2&&p<i[1])?(a=0,d.v=o,d.n=i[1]):p<g&&(r=n<3||i[0]>o||o>g)&&(i[4]=n,i[5]=o,d.n=g,a=0))}if(r||n>1)return c;throw f=!0,o}return function(r,l,g){if(u>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,g),a=l,s=g;(t=a<2?e: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"),t=i[r]){if(!(t=t.call(i,s)))throw TypeError("iterator result is not an object");if(!t.done)return t;s=t.value,a<2&&(a=0)}else 1===a&&(t=i.return)&&t.call(i),a<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),a=1);i=e}else if((t=(f=d.n<0)?s:n.call(o,d))!==c)break}catch(t){i=e,a=1,s=t}finally{u=1}}return{value:t,done:f}}}(n,r,i),!0),u}var c={};function a(){}function s(){}function u(){}t=Object.getPrototypeOf;var l=[][o]?t(t([][o]())):(Ye(t={},o,function(){return this}),t),f=u.prototype=a.prototype=Object.create(l);function d(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,u):(e.__proto__=u,Ye(e,r,"GeneratorFunction")),e.prototype=Object.create(f),e}return s.prototype=u,Ye(f,"constructor",u),Ye(u,"constructor",s),s.displayName="GeneratorFunction",Ye(u,r,"GeneratorFunction"),Ye(f),Ye(f,r,"Generator"),Ye(f,o,function(){return this}),Ye(f,"toString",function(){return"[object Generator]"}),($e=function(){return{w:i,m:d}})()}function Ye(e,t,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}Ye=function(e,t,n,o){function i(t,n){Ye(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},Ye(e,t,n,o)}function Xe(e,t,n,o,r,i,c){try{var a=e[i](c),s=a.value}catch(e){return void n(e)}a.done?t(s):Promise.resolve(s).then(o,r)}function Ze(e){return function(){var t=this,n=arguments;return new Promise(function(o,r){var i=e.apply(t,n);function c(e){Xe(i,o,r,c,a,"next",e)}function a(e){Xe(i,o,r,c,a,"throw",e)}c(void 0)})}}function et(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function tt(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,ot(o.key),o)}}function nt(e,t,n){return t&&tt(e.prototype,t),n&&tt(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function ot(e){var t=function(e){if("object"!=Je(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=Je(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==Je(t)?t:t+""}var rt=function(){return nt(function e(t){et(this,e),console.log("🚀 AgentSDK v2.1.8 initialized with config:",t),this.config=t,this.voiceSDK=null,this.isConnected=!1,this.isListening=!1,this.onConnected=function(){},this.onDisconnected=function(){},this.onError=function(e){return console.error("SDK Error:",e)},this.onTranscript=function(e){},this.onAgentSpeaking=function(e){}},[{key:"connect",value:(t=Ze($e().m(function e(t){var n,o=this;return $e().w(function(e){for(;;)switch(e.p=e.n){case 0:if(e.p=0,t){e.n=1;break}throw new Error("signedUrl is required");case 1:return this.voiceSDK=new de({websocketUrl:t,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(e){o.onError(e)}),this.voiceSDK.on("message",function(e){o.handleWebSocketMessage(e)}),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)}),e.n=2,this.voiceSDK.connect();case 2:e.n=4;break;case 3:throw e.p=3,n=e.v,this.onError(n),n;case 4:return e.a(2)}},e,this,[[0,3]])})),function(e){return t.apply(this,arguments)})},{key:"handleWebSocketMessage",value:function(e){switch(e.type){case"connected":console.log("Session started successfully");break;case"user_transcript":this.onTranscript(e.user_transcription||e.text);break;case"agent_response":case"barge_in":case"stop_playing":break;case"error":this.onError(new Error(e.message))}}},{key:"startListening",value:(e=Ze($e().m(function e(){var t;return $e().w(function(e){for(;;)switch(e.p=e.n){case 0:if(!this.voiceSDK){e.n=5;break}return e.p=1,console.log("🎤 AgentSDK: Starting recording..."),e.n=2,this.voiceSDK.startRecording();case 2:console.log("✅ AgentSDK: Recording started successfully"),e.n=4;break;case 3:throw e.p=3,t=e.v,console.error("❌ AgentSDK: Failed to start recording:",t),t;case 4:e.n=6;break;case 5:throw console.error("❌ AgentSDK: No voiceSDK instance available"),new Error("No voiceSDK instance available");case 6:return e.a(2)}},e,this,[[1,3]])})),function(){return e.apply(this,arguments)})},{key:"stopListening",value:function(){this.voiceSDK&&this.voiceSDK.stopRecording()}},{key:"updateVariables",value:function(e){this.voiceSDK&&this.isConnected&&this.voiceSDK.webSocketManager.sendMessage({t:"update_variables",variables:e})}},{key:"disconnect",value:function(){this.voiceSDK&&(this.voiceSDK.destroy(),this.voiceSDK=null),this.isConnected=!1,this.isListening=!1}}]);var e,t}(),it=function(){return nt(function e(t){et(this,e),console.log("🎯 AgentWidget v2.1.8 initialized with config:",t),this.config=t,this.sdk=new rt(t),this.isOpen=!1,this.isActive=!1,this.position=t.position||"bottom-right",this.primaryColor=t.primaryColor||"#4F46E5",this.setupEventHandlers(),this.createWidget()},[{key:"setupEventHandlers",value:function(){var e=this;this.sdk.onConnected=function(){console.log("✅ SDK connected"),e.updateStatus("connected")},this.sdk.onDisconnected=function(){console.log("❌ SDK disconnected"),e.updateStatus("disconnected"),e.isActive=!1,e.updateMicButtonState(!1)},this.sdk.onError=function(t){console.error("❌ SDK error:",t),e.showError(t.message)},this.sdk.onTranscript=function(t){console.log("📝 User transcript:",t),e.addMessage("user",t)},this.sdk.onAgentSpeaking=function(t){console.log("🤖 Agent speaking:",t),t?e.showAgentThinking():e.hideAgentThinking()}}},{key:"createWidget",value:function(){var e=this,t=document.createElement("div");t.id="agent-widget",t.innerHTML="\n <style>\n #agent-widget {\n position: fixed;\n ".concat(this.position.includes("bottom")?"bottom: 20px;":"top: 20px;","\n ").concat(this.position.includes("right")?"right: 20px;":"left: 20px;",'\n z-index: 9999;\n font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;\n }\n \n #agent-button {\n width: 60px;\n height: 60px;\n border-radius: 50%;\n background: ').concat(this.primaryColor,";\n border: none;\n cursor: pointer;\n box-shadow: 0 4px 12px rgba(0,0,0,0.15);\n display: flex;\n align-items: center;\n justify-content: center;\n transition: transform 0.2s;\n }\n \n #agent-button:hover {\n transform: scale(1.1);\n }\n \n #agent-button svg {\n width: 28px;\n height: 28px;\n fill: white;\n }\n \n #agent-panel {\n display: none;\n position: absolute;\n bottom: 80px;\n ").concat(this.position.includes("right")?"right: 0;":"left: 0;","\n width: 350px;\n height: 500px;\n background: white;\n border-radius: 12px;\n box-shadow: 0 8px 32px rgba(0,0,0,0.2);\n flex-direction: column;\n overflow: hidden;\n }\n \n #agent-panel.open {\n display: flex;\n }\n \n #agent-header {\n background: ").concat(this.primaryColor,";\n color: white;\n padding: 16px;\n display: flex;\n justify-content: space-between;\n align-items: center;\n }\n \n #agent-close {\n background: none;\n border: none;\n color: white;\n cursor: pointer;\n font-size: 24px;\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: 8px;\n max-width: 80%;\n }\n \n .message.user {\n background: #E5E7EB;\n align-self: flex-end;\n }\n \n .message.agent {\n background: #F3F4F6;\n align-self: flex-start;\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: 60px;\n height: 60px;\n border-radius: 50%;\n border: none;\n background: ").concat(this.primaryColor,';\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n transition: all 0.2s;\n }\n \n #agent-mic-button.active {\n background: #EF4444;\n animation: pulse 1.5s infinite;\n }\n \n #agent-mic-button svg {\n width: 28px;\n height: 28px;\n fill: white;\n }\n \n @keyframes pulse {\n 0%, 100% { transform: scale(1); }\n 50% { transform: scale(1.05); }\n }\n \n .agent-thinking {\n font-style: italic;\n color: #6B7280;\n }\n \n .error-message {\n background: #FEE2E2;\n color: #991B1B;\n padding: 12px;\n border-radius: 8px;\n margin: 8px;\n }\n </style>\n \n <button id="agent-button">\n <svg viewBox="0 0 24 24">\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>\n </button>\n \n <div id="agent-panel">\n <div id="agent-header">\n <h3 style="margin: 0;">Voice Assistant</h3>\n <button id="agent-close">&times;</button>\n </div>\n \n <div id="agent-messages"></div>\n \n <div id="agent-controls">\n <button id="agent-mic-button">\n <svg viewBox="0 0 24 24">\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>\n </button>\n </div>\n </div>\n '),document.body.appendChild(t),document.getElementById("agent-button").onclick=function(){return e.togglePanel()},document.getElementById("agent-close").onclick=function(){return e.togglePanel()},document.getElementById("agent-mic-button").onclick=function(){return e.toggleVoice()}}},{key:"togglePanel",value:function(){this.isOpen=!this.isOpen,document.getElementById("agent-panel").classList.toggle("open")}},{key:"toggleVoice",value:(t=Ze($e().m(function e(){var t,n;return $e().w(function(e){for(;;)switch(e.p=e.n){case 0:if(console.log("🎤 NODE_MODULES SDK: toggleVoice called - isActive:",this.isActive),this.isActive){e.n=7;break}return e.p=1,console.log("🎤 Starting voice session..."),e.n=2,this.getSignedUrl();case 2:return t=e.v,console.log("🔗 Got signed URL:",t),e.n=3,this.sdk.connect(t);case 3:return console.log("✅ Connected to WebSocket"),e.n=4,this.sdk.startListening();case 4:console.log("🎤 Started listening"),this.isActive=!0,this.updateMicButtonState(!0),this.addMessage("system","🎤 Listening... Click mic to stop"),e.n=6;break;case 5:e.p=5,n=e.v,console.error("❌ Failed to start:",n),this.showError(n.message);case 6:e.n=8;break;case 7:console.log("🔇 Stopping voice session..."),this.sdk.stopListening(),this.sdk.disconnect(),this.isActive=!1,this.updateMicButtonState(!1),this.addMessage("system","🔇 Stopped listening");case 8:return e.a(2)}},e,this,[[1,5]])})),function(){return t.apply(this,arguments)})},{key:"updateMicButtonState",value:function(e){var t=document.getElementById("agent-mic-button"),n=t.querySelector("svg");e?(t.classList.add("active"),t.style.background="#EF4444",t.title="Click to stop listening",t.style.animation="pulse 1.5s infinite",n.innerHTML='\n <rect x="6" y="6" width="12" height="12" rx="2"/>\n <path d="M9 9h6"/>\n '):(t.classList.remove("active"),t.style.background=this.primaryColor,t.title="Click to start listening",t.style.animation="",n.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:(e=Ze($e().m(function e(){var t,n,o,r,i;return $e().w(function(e){for(;;)switch(e.n){case 0:if("string"!=typeof this.config.getSessionUrl){e.n=4;break}return t={agentId:this.config.agentId,variables:this.config.variables||{}},this.config.appId&&(t.appId=this.config.appId),e.n=1,fetch(this.config.getSessionUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});case 1:if((n=e.v).ok){e.n=2;break}throw new Error("Failed to get session URL: ".concat(n.statusText));case 2:return e.n=3,n.json();case 3:return o=e.v,e.a(2,o.signedUrl||o.wsUrl||o.url);case 4:if("function"!=typeof this.config.getSessionUrl){e.n=6;break}return r={agentId:this.config.agentId,variables:this.config.variables||{}},this.config.appId&&(r.appId=this.config.appId),e.n=5,this.config.getSessionUrl(r);case 5:return i=e.v,e.a(2,"string"==typeof i?i:i.signedUrl||i.wsUrl||i.url);case 6:throw new Error("getSessionUrl is required (URL string or function)");case 7:return e.a(2)}},e,this)})),function(){return e.apply(this,arguments)})},{key:"addMessage",value:function(e,t){var n=document.getElementById("agent-messages"),o=document.createElement("div");o.className="message ".concat(e),o.textContent=t,n.appendChild(o),n.scrollTop=n.scrollHeight}},{key:"showAgentThinking",value:function(){var e=document.getElementById("agent-messages"),t=document.createElement("div");t.className="message agent agent-thinking",t.id="thinking-indicator",t.textContent="Agent is speaking...",e.appendChild(t),e.scrollTop=e.scrollHeight}},{key:"hideAgentThinking",value:function(){var e=document.getElementById("thinking-indicator");e&&e.remove()}},{key:"showError",value:function(e){var t=document.getElementById("agent-messages"),n=document.createElement("div");n.className="error-message",n.textContent=e,t.appendChild(n)}},{key:"updateStatus",value:function(e){console.log("Widget status:",e)}}]);var e,t}();function ct(e){return ct="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},ct(e)}function at(){var e,t,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:e,a:p,f:p.bind(e,4),d:function(t,n){return i=t,a=0,s=e,d.n=n,c}};function p(n,o){for(a=n,s=o,t=0;!f&&u&&!r&&t<l.length;t++){var r,i=l[t],p=d.p,g=i[2];n>3?(r=g===o)&&(s=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=e):i[0]<=p&&((r=n<2&&p<i[1])?(a=0,d.v=o,d.n=i[1]):p<g&&(r=n<3||i[0]>o||o>g)&&(i[4]=n,i[5]=o,d.n=g,a=0))}if(r||n>1)return c;throw f=!0,o}return function(r,l,g){if(u>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,g),a=l,s=g;(t=a<2?e: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"),t=i[r]){if(!(t=t.call(i,s)))throw TypeError("iterator result is not an object");if(!t.done)return t;s=t.value,a<2&&(a=0)}else 1===a&&(t=i.return)&&t.call(i),a<2&&(s=TypeError("The iterator does not provide a '"+r+"' method"),a=1);i=e}else if((t=(f=d.n<0)?s:n.call(o,d))!==c)break}catch(t){i=e,a=1,s=t}finally{u=1}}return{value:t,done:f}}}(n,r,i),!0),u}var c={};function a(){}function s(){}function u(){}t=Object.getPrototypeOf;var l=[][o]?t(t([][o]())):(st(t={},o,function(){return this}),t),f=u.prototype=a.prototype=Object.create(l);function d(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,u):(e.__proto__=u,st(e,r,"GeneratorFunction")),e.prototype=Object.create(f),e}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]"}),(at=function(){return{w:i,m:d}})()}function st(e,t,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}st=function(e,t,n,o){function i(t,n){st(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},st(e,t,n,o)}function ut(e,t,n,o,r,i,c){try{var a=e[i](c),s=a.value}catch(e){return void n(e)}a.done?t(s):Promise.resolve(s).then(o,r)}function lt(e){return function(){var t=this,n=arguments;return new Promise(function(o,r){var i=e.apply(t,n);function c(e){ut(i,o,r,c,a,"next",e)}function a(e){ut(i,o,r,c,a,"throw",e)}c(void 0)})}}function ft(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,o)}return n}function dt(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?ft(Object(n),!0).forEach(function(t){pt(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ft(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function pt(e,t,n){return(t=ht(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function gt(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,ht(o.key),o)}}function ht(e){var t=function(e){if("object"!=ct(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=ct(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==ct(t)?t:t+""}var yt=function(){return e=function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.config=this.mergeWithDefaults(t),this.sdk=new AgentSDK,this.isOpen=!1,this.isActive=!1,this.setupEventHandlers(),this.createWidget()},t=[{key:"mergeWithDefaults",value:function(e){var t,n,o,r,i,c,a,s,u,l,f,d,p,g,h,y,b,v,m,S,w,k,O,j,C,P,x,E,T,D,I,A,R,_,M,B,K,W,V,U,F,G,L,N;return pt({agentId:e.agentId,getSessionUrl:e.getSessionUrl,icon:dt({type:(null===(t=e.icon)||void 0===t?void 0:t.type)||"microphone",customImage:(null===(n=e.icon)||void 0===n?void 0:n.customImage)||null,emoji:(null===(o=e.icon)||void 0===o?void 0:o.emoji)||"🎤",text:(null===(r=e.icon)||void 0===r?void 0:r.text)||"AI",size:(null===(i=e.icon)||void 0===i?void 0:i.size)||"medium"},e.icon),position:dt({vertical:(null===(c=e.position)||void 0===c?void 0:c.vertical)||"bottom",horizontal:(null===(a=e.position)||void 0===a?void 0:a.horizontal)||"right",offset:(null===(s=e.position)||void 0===s?void 0:s.offset)||{x:20,y:20}},e.position),button:dt({size:(null===(u=e.button)||void 0===u?void 0:u.size)||"medium",shape:(null===(l=e.button)||void 0===l?void 0:l.shape)||"circle",primaryColor:(null===(f=e.button)||void 0===f?void 0:f.primaryColor)||"#4F46E5",hoverColor:(null===(d=e.button)||void 0===d?void 0:d.hoverColor)||"#7C3AED",activeColor:(null===(p=e.button)||void 0===p?void 0:p.activeColor)||"#EF4444",shadow:(null===(g=e.button)||void 0===g?void 0:g.shadow)||!0,shadowColor:(null===(h=e.button)||void 0===h?void 0:h.shadowColor)||"rgba(0,0,0,0.15)"},e.button),panel:dt({width:(null===(y=e.panel)||void 0===y?void 0:y.width)||350,height:(null===(b=e.panel)||void 0===b?void 0:b.height)||500,borderRadius:(null===(v=e.panel)||void 0===v?void 0:v.borderRadius)||12,backgroundColor:(null===(m=e.panel)||void 0===m?void 0:m.backgroundColor)||"rgba(255,255,255,0.95)",backdropFilter:(null===(S=e.panel)||void 0===S?void 0:S.backdropFilter)||"blur(10px)",border:(null===(w=e.panel)||void 0===w?void 0:w.border)||"1px solid rgba(0,0,0,0.1)"},e.panel),header:dt({title:(null===(k=e.header)||void 0===k?void 0:k.title)||"Voice Assistant",showTitle:!1!==(null===(O=e.header)||void 0===O?void 0:O.showTitle),backgroundColor:(null===(j=e.header)||void 0===j?void 0:j.backgroundColor)||null,textColor:(null===(C=e.header)||void 0===C?void 0:C.textColor)||"#FFFFFF",showCloseButton:!1!==(null===(P=e.header)||void 0===P?void 0:P.showCloseButton)},e.header),messages:dt({userBackgroundColor:(null===(x=e.messages)||void 0===x?void 0:x.userBackgroundColor)||"#E5E7EB",agentBackgroundColor:(null===(E=e.messages)||void 0===E?void 0:E.agentBackgroundColor)||"#F3F4F6",systemBackgroundColor:(null===(T=e.messages)||void 0===T?void 0:T.systemBackgroundColor)||"#DCFCE7",errorBackgroundColor:(null===(D=e.messages)||void 0===D?void 0:D.errorBackgroundColor)||"#FEE2E2",textColor:(null===(I=e.messages)||void 0===I?void 0:I.textColor)||"#1F2937",fontSize:(null===(A=e.messages)||void 0===A?void 0:A.fontSize)||"14px",borderRadius:(null===(R=e.messages)||void 0===R?void 0:R.borderRadius)||8},e.messages),animation:dt({enableHover:!1!==(null===(_=e.animation)||void 0===_?void 0:_.enableHover),enablePulse:!1!==(null===(M=e.animation)||void 0===M?void 0:M.enablePulse),enableSlide:!1!==(null===(B=e.animation)||void 0===B?void 0:B.enableSlide),duration:(null===(K=e.animation)||void 0===K?void 0:K.duration)||.3},e.animation),behavior:dt({autoOpen:(null===(W=e.behavior)||void 0===W?void 0:W.autoOpen)||!1,autoConnect:(null===(V=e.behavior)||void 0===V?void 0:V.autoConnect)||!1,showWelcomeMessage:!1!==(null===(U=e.behavior)||void 0===U?void 0:U.showWelcomeMessage),welcomeMessage:(null===(F=e.behavior)||void 0===F?void 0:F.welcomeMessage)||"Hello! How can I help you today?"},e.behavior),accessibility:dt({ariaLabel:(null===(G=e.accessibility)||void 0===G?void 0:G.ariaLabel)||"Voice Assistant",ariaDescription:(null===(L=e.accessibility)||void 0===L?void 0:L.ariaDescription)||"Click to open voice assistant",keyboardNavigation:!1!==(null===(N=e.accessibility)||void 0===N?void 0:N.keyboardNavigation)},e.accessibility),customStyles:e.customStyles||"",variables:e.variables||{},primaryColor:e.primaryColor||"#4F46E5"},"position",e.position||"bottom-right")}},{key:"setupEventHandlers",value:function(){var e=this;this.sdk.onConnected=function(){e.updateStatus("connected"),e.config.behavior.showWelcomeMessage&&e.addMessage("system",e.config.behavior.welcomeMessage)},this.sdk.onDisconnected=function(){e.updateStatus("disconnected"),e.isActive=!1},this.sdk.onError=function(t){e.showError(t.message)},this.sdk.onTranscript=function(t){e.addMessage("user",t)},this.sdk.onAgentSpeaking=function(t){t?e.showAgentThinking():e.hideAgentThinking()}}},{key:"createWidget",value:function(){var e=this,t=document.createElement("div");t.id="enhanced-agent-widget",t.innerHTML=this.generateWidgetHTML(),document.body.appendChild(t),this.setupWidgetEvents(),this.config.behavior.autoOpen&&setTimeout(function(){return e.togglePanel()},1e3)}},{key:"generateWidgetHTML",value:function(){this.config.position;var e=this.config.button,t=this.config.icon,n=(this.config.panel,this.config.header),o=(this.config.messages,this.config.animation,{small:50,medium:60,large:70,xl:80}[e.size]||60),r={small:20,medium:28,large:36,xl:44}[t.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="enhanced-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="enhanced-agent-panel">\n ').concat(n.showTitle?'\n <div id="enhanced-agent-header">\n <h3 style="margin: 0; color: '.concat(n.textColor,';">').concat(n.title,"</h3>\n ").concat(n.showCloseButton?'<button id="enhanced-agent-close">&times;</button>':"","\n </div>\n "):"",'\n \n <div id="enhanced-agent-messages"></div>\n \n <div id="enhanced-agent-controls">\n <button id="enhanced-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 e=this.config.position,t=e.offset||{x:20,y:20},n="";return"top"===e.vertical?n+="top: ".concat(t.y,"px;"):"bottom"===e.vertical?n+="bottom: ".concat(t.y,"px;"):"center"===e.vertical&&(n+="top: 50%; transform: translateY(-50%);"),"left"===e.horizontal?n+="left: ".concat(t.x,"px;"):"right"===e.horizontal?n+="right: ".concat(t.x,"px;"):"center"===e.horizontal&&(n+="left: 50%; transform: translateX(-50%);"),n}},{key:"generateIconHTML",value:function(e){var t=this.config.icon;switch(t.type){case"custom":return'<img src="'.concat(t.customImage,'" alt="Voice Assistant" style="width: ').concat(e,"px; height: ").concat(e,'px; object-fit: contain;" />');case"emoji":return'<span style="font-size: '.concat(e,'px; line-height: 1;">').concat(t.emoji,"</span>");case"text":return'<span style="font-size: '.concat(Math.floor(.6*e),'px; font-weight: bold; color: white;">').concat(t.text,"</span>");default:return'<svg viewBox="0 0 24 24" style="width: '.concat(e,"px; height: ").concat(e,'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(e,t,n){var o=this.config.button,r=this.config.panel,i=this.config.header,c=this.config.messages,a=this.config.animation;return"\n #enhanced-agent-widget {\n position: fixed;\n ".concat(e,'\n z-index: 10000;\n font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;\n }\n \n #enhanced-agent-button {\n width: ').concat(t,"px;\n height: ").concat(t,"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 #enhanced-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 #enhanced-agent-panel {\n display: none;\n position: absolute;\n bottom: ").concat(t+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 #enhanced-agent-panel.open {\n display: flex;\n ").concat(a.enableSlide?"transform: translateY(0); opacity: 1;":"","\n }\n \n #enhanced-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 #enhanced-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 #enhanced-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 #enhanced-agent-controls {\n padding: 16px;\n border-top: 1px solid #E5E7EB;\n display: flex;\n justify-content: center;\n }\n \n #enhanced-agent-mic-button {\n width: ").concat(t,"px;\n height: ").concat(t,"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 #enhanced-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 e=this;document.getElementById("enhanced-agent-button").onclick=function(){return e.togglePanel()};var t=document.getElementById("enhanced-agent-close");t&&(t.onclick=function(){return e.togglePanel()}),document.getElementById("enhanced-agent-mic-button").onclick=function(){return e.toggleVoice()},this.config.accessibility.keyboardNavigation&&this.setupKeyboardNavigation()}},{key:"setupKeyboardNavigation",value:function(){var e=this;document.addEventListener("keydown",function(t){"Escape"===t.key&&e.isOpen&&e.togglePanel()})}},{key:"togglePanel",value:function(){this.isOpen=!this.isOpen,document.getElementById("enhanced-agent-panel").classList.toggle("open")}},{key:"toggleVoice",value:(o=lt(at().m(function e(){var t,n;return at().w(function(e){for(;;)switch(e.p=e.n){case 0:if(this.isActive){e.n=7;break}return e.p=1,e.n=2,this.getSignedUrl();case 2:return t=e.v,e.n=3,this.sdk.connect(t);case 3:return e.n=4,this.sdk.startListening();case 4:this.isActive=!0,document.getElementById("enhanced-agent-mic-button").classList.add("active"),this.addMessage("system","Listening..."),e.n=6;break;case 5:e.p=5,n=e.v,console.error("Failed to start:",n),this.showError(n.message);case 6:e.n=8;break;case 7:this.sdk.stopListening(),this.sdk.disconnect(),this.isActive=!1,document.getElementById("enhanced-agent-mic-button").classList.remove("active");case 8:return e.a(2)}},e,this,[[1,5]])})),function(){return o.apply(this,arguments)})},{key:"getSignedUrl",value:(n=lt(at().m(function e(){var t,n,o;return at().w(function(e){for(;;)switch(e.n){case 0:if("string"!=typeof this.config.getSessionUrl){e.n=4;break}return e.n=1,fetch(this.config.getSessionUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({agentId:this.config.agentId,variables:this.config.variables||{}})});case 1:if((t=e.v).ok){e.n=2;break}throw new Error("Failed to get session URL: ".concat(t.statusText));case 2:return e.n=3,t.json();case 3:return n=e.v,e.a(2,n.signedUrl||n.wsUrl||n.url);case 4:if("function"!=typeof this.config.getSessionUrl){e.n=6;break}return e.n=5,this.config.getSessionUrl({agentId:this.config.agentId,variables:this.config.variables||{}});case 5:return o=e.v,e.a(2,"string"==typeof o?o:o.signedUrl||o.wsUrl||o.url);case 6:throw new Error("getSessionUrl is required (URL string or function)");case 7:return e.a(2)}},e,this)})),function(){return n.apply(this,arguments)})},{key:"addMessage",value:function(e,t){var n=document.getElementById("enhanced-agent-messages"),o=document.createElement("div");o.className="message ".concat(e),o.textContent=t,n.appendChild(o),n.scrollTop=n.scrollHeight}},{key:"showAgentThinking",value:function(){var e=document.getElementById("enhanced-agent-messages"),t=document.createElement("div");t.className="message agent agent-thinking",t.id="thinking-indicator",t.textContent="Agent is speaking...",e.appendChild(t),e.scrollTop=e.scrollHeight}},{key:"hideAgentThinking",value:function(){var e=document.getElementById("thinking-indicator");e&&e.remove()}},{key:"showError",value:function(e){var t=document.getElementById("enhanced-agent-messages"),n=document.createElement("div");n.className="error-message",n.textContent=e,t.appendChild(n)}},{key:"updateStatus",value:function(e){console.log("Enhanced Widget status:",e)}},{key:"updateConfig",value:function(e){this.config=this.mergeWithDefaults(dt(dt({},this.config),e));var t=document.getElementById("enhanced-agent-widget");t&&t.remove(),this.createWidget()}},{key:"destroy",value:function(){var e=document.getElementById("enhanced-agent-widget");e&&e.remove(),this.sdk&&this.sdk.disconnect()}}],t&&gt(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,n,o}(),bt="2.0.0";const vt={VoiceSDK:de,WebSocketManager:Pe,WebSocketManagerV2:I,AudioRecorder:G,AudioPlayer:X,EventEmitter:a,VoiceButton:We,VanillaVoiceButton:qe,AgentSDK:rt,AgentWidget:it,EnhancedAgentWidget:yt,VERSION:bt};return o})());
3
3
  //# sourceMappingURL=agent-widget.js.map